Anonymous user
Combinations with repetitions/Square digit chain: Difference between revisions
Combinations with repetitions/Square digit chain (view source)
Revision as of 09:45, 8 September 2016
, 7 years ago→{{header|zkl}}: get lazy
(→{{header|Ruby}}: added zkl) |
(→{{header|zkl}}: get lazy) |
||
Line 192:
N:=n.pump(List,'wrap(n){ n=g(n); while(n>1){ n=G[n] } n });
var z=0; #Running count of numbers translating to 1
[0..9].pump(List,fcn(n){ n*n }):Utils.Helpers.
.pump(Void,'wrap(ds){ #Iterate over unique digit combinations
if(N[ds.sum(0)]==0) return(); #Count only ones
Line 203:
println("%,d numbers produce 1 and %,d numbers produce 89".fmt(z,(10).pow(K)-1-z));
}</lang>
<lang zkl>foreach K in (T(7,8,11,14,17)){ countNumberChains(K) }</lang>
{{out}}
<pre>
Line 217:
k=(14) in the range 1 to 99,999,999,999,999
13,785,960,153,559 numbers produce 1 and 86,214,039,846,440 numbers produce 89
k=(17) in the range 1 to 99,999,999,999,999,999
12,038,482,364,921,583 numbers produce 1 and 87,961,517,635,078,416 numbers produce 89
</pre>
|