Skip to main content
Prettify hints
Source Link
Toby Speight
  • 6.5k
  • 1
  • 24
  • 41

#dc, 12 bytes

  
[5/dd0<f+]sf

This defines a function f which consumes its input from top of stack, and leaves its output at top of stack. See my C answer for the mathematical basis. We repeatedly divide by 5, accumulating the values on the stack, then add all the results:

5/d   # divide by 5, and leave a copy behind
d0<   # still greater than zero?
f+    # if so, apply f to the new value and add
5/d   # divide by 5, and leave a copy behind
d0<   # still greater than zero?
f+    # if so, apply f to the new value and add

##Test program # read input values ? # print prefix [ # for each value # print prefix [> ]ndn[ ==> ]n # call f(n) lfx # print suffix n[
]n # repeat for each value on stack z0<t ] # define and run test function 't' dstx

##Test output

$ ./79762.dc <<<'1234567891011121314151617181920 2016 666 125 124 25 24 5 4 1' 1 ==> 0
4 ==> 0
5 ==> 1
24 ==> 4
25 ==> 6
124 ==> 28
125 ==> 31
666 ==> 165
2016 ==> 502
1234567891011121314151617181920 ==> 308641972752780328537904295461

./79762.dc <<<'1234567891011121314151617181920 2016 666 125 124 25 24 5 4 1'
1 ==> 0  
4 ==> 0  
5 ==> 1  
24 ==> 4  
25 ==> 6  
124 ==> 28  
125 ==> 31  
666 ==> 165  
2016 ==> 502  
1234567891011121314151617181920 ==> 308641972752780328537904295461  

#dc, 12 bytes

 
[5/dd0<f+]sf

This defines a function f which consumes its input from top of stack, and leaves its output at top of stack. See my C answer for the mathematical basis. We repeatedly divide by 5, accumulating the values on the stack, then add all the results:

5/d   # divide by 5, and leave a copy behind
d0<   # still greater than zero?
f+    # if so, apply f to the new value and add

##Test program # read input values ? # print prefix [ # for each value # print prefix [> ]ndn[ ==> ]n # call f(n) lfx # print suffix n[
]n # repeat for each value on stack z0<t ] # define and run test function 't' dstx

##Test output

$ ./79762.dc <<<'1234567891011121314151617181920 2016 666 125 124 25 24 5 4 1' 1 ==> 0
4 ==> 0
5 ==> 1
24 ==> 4
25 ==> 6
124 ==> 28
125 ==> 31
666 ==> 165
2016 ==> 502
1234567891011121314151617181920 ==> 308641972752780328537904295461

#dc, 12 bytes

 
[5/dd0<f+]sf

This defines a function f which consumes its input from top of stack, and leaves its output at top of stack. See my C answer for the mathematical basis. We repeatedly divide by 5, accumulating the values on the stack, then add all the results:

5/d   # divide by 5, and leave a copy behind
d0<   # still greater than zero?
f+    # if so, apply f to the new value and add

##Test program # read input values ? # print prefix [ # for each value # print prefix [> ]ndn[ ==> ]n # call f(n) lfx # print suffix n[
]n # repeat for each value on stack z0<t ] # define and run test function 't' dstx

##Test output

./79762.dc <<<'1234567891011121314151617181920 2016 666 125 124 25 24 5 4 1'
1 ==> 0  
4 ==> 0  
5 ==> 1  
24 ==> 4  
25 ==> 6  
124 ==> 28  
125 ==> 31  
666 ==> 165  
2016 ==> 502  
1234567891011121314151617181920 ==> 308641972752780328537904295461  
Source Link
Toby Speight
  • 6.5k
  • 1
  • 24
  • 41

#dc, 12 bytes

[5/dd0<f+]sf

This defines a function f which consumes its input from top of stack, and leaves its output at top of stack. See my C answer for the mathematical basis. We repeatedly divide by 5, accumulating the values on the stack, then add all the results:

5/d   # divide by 5, and leave a copy behind
d0<   # still greater than zero?
f+    # if so, apply f to the new value and add

##Test program # read input values ? # print prefix [ # for each value # print prefix [> ]ndn[ ==> ]n # call f(n) lfx # print suffix n[
]n # repeat for each value on stack z0<t ] # define and run test function 't' dstx

##Test output

$ ./79762.dc <<<'1234567891011121314151617181920 2016 666 125 124 25 24 5 4 1' 1 ==> 0
4 ==> 0
5 ==> 1
24 ==> 4
25 ==> 6
124 ==> 28
125 ==> 31
666 ==> 165
2016 ==> 502
1234567891011121314151617181920 ==> 308641972752780328537904295461