숫자를 분해하십시오! 목록은 임의의 순서로있을 수 있습니다. 0 제외하거나

당신의 임무는 아래 형식을 사용하여 숫자를 분해하는 것입니다.

이것은 기본 변환과 유사, 대신을 나열하는 것을 제외시켰다 digits기본에, 당신은 목록 values목록 입력까지 추가하도록.

주어진베이스 인 경우 n, 다음 목록의 각 수의 형식이어야합니다 k*(n**m), 0<=k<n그리고 m목록에서 고유합니다.

명세서

  • 합리적인 입 / 출력 형식 프로그램 / 기능은 2 개의 입력을 받아서 목록을 출력합니다.
  • 출력 목록은 임의의 순서로있을 수 있습니다.
  • 0 제외하거나 포함 할 수 있습니다.
  • 선행 0이 허용됩니다.
  • 내장이 허용 됩니다.

테스트 케이스

number base   converted list
input1 input2 output
123456 10     [100000,20000,3000,400,50,6] or [6,50,400,3000,20000,100000]
11     2      [8,2,1] or [0,0,0,0,8,0,2,1]
727    20     [400,320,7]
101    10     [100,1] or [100,0,1]

채점

이것은 입니다. 바이트 단위의 최단 솔루션이 승리합니다.



답변

젤리 , 7 바이트

lr0⁹*×b

온라인으로 사용해보십시오! 또는 모든 테스트 사례를 확인하십시오 .

작동 원리

lr0⁹*×b  Main link. Arguments: x (integer), n (base)

l        Compute the logarithm of x to base n.
 r0      Range; yield all non-negative integers less than the logarithm, in
         decreasing order.
   ⁹*    Elevate n to all integers in that range.
      b  Yield the list of base-n digits of x.
     ×   Multiply each digit by the corresponding power of n.


답변

자바 스크립트 (ES6), 47 바이트

f=(n,b,p=1,q=b*p)=>[...n<q?[]:f(n,b,q),n%q-n%p]
document.write("<pre>"+
[ [ 123456, 10 ], [ 11, 2 ], [ 727, 20 ], [ 101, 10 ] ]
.map(c=>c+" => "+f(...c)).join`\n`)


답변

젤리, 12 바이트

bLR’*@€U
b×ç

더 짧아 질 수 있습니다 …

온라인으로 사용해보십시오!


답변

Pyth- 12 11 바이트

FGITW 만 짧을 수 있습니다.

.e*b^Qk_jEQ

테스트 스위트 .


답변

J, 20 19 바이트

[(]*(^<:@#\.))#.inv

용법

   f =: [(]*(^<:@#\.))#.inv
   10 f 123456
100000 20000 3000 400 50 6
   2 f 11
8 0 2 1
   20 f 727
400 320 7
   10 f 101
100 0 1

설명

[(]*(^<:@#\.))#.inv
              #.      Given a base and list of digits in that base,
                      converts it to an integer in base 10
                inv   Power conjunction by -1, creates an inverse
                      Now, this becomes a verb that given a base and an integer in base 10,
                      creates a list of digits in that base representing it
[                     Select the base and pass it along
         #\.          Tally each suffix of the list of base digits,
                      Counts down from n to 1
      <:              Decrements each value
        @             More specifically, decrement is composed with the tally and applied
                      together on each suffix
     ^                Raises each value x using base^x
  ]                   Selects the list of base digits
   *                  Multiply elementwise between each base power and base digit


답변

CJam, 16 바이트

{1$b\1$,,f#W%.*}

이름이없는 블록은 스택의 맨 위에있는 기본과 숫자 (순서대로)를 예상하고 숫자 목록 (앞의 0이없는 내부 0 포함)으로 대체합니다.

여기에서 테스트하십시오.

설명

1$  e# Copy base b.
b   e# Compute base-b digits of input number.
\   e# Swap digit list with other copy of b.
1$  e# Copy digit list.
,   e# Get number of digits M.
,   e# Turn into range [0 1 ... M-1].
f#  e# Map b^() over this range, computing all necessary powers of b.
W%  e# Reverse the list of powers.
.*  e# Multiply each digit by the corresponding power.


답변

TSQL, 68 바이트

DECLARE @ INT=123456,@z INT=10
DECLARE @l INT=1WHILE
@>0BEGIN PRINT @%@z*@l SELECT @/=@z,@l*=@z END