Sum to 100: Difference between revisions

→‎{{header|zkl}}: redo to task
(→‎{{header|zkl}}: added code)
(→‎{{header|zkl}}: redo to task)
Line 309:
 
=={{header|zkl}}==
<lang zkl>fcn sumToN(N=100,printSolutions=True2){
fcn(N,n,nstr,soFar,r){
foreach b in (split(nstr)){ // split("")-->()
Line 322:
}
}(N,0,"123456789","",r:=List());
if(printSolutions) println("%d solutions for N=%d".fmt(r.len(),N));
if(printSolutions==2) println(r.concat("\n"));
r.len()
}
// "123" --> (1,12,123)
fcn split(nstr){ (1).pump(nstr.len(),List,nstr.get.fp(0),"toInt") }</lang>
<lang zkl>sumToN();
sumToN(9,False1);
println("Smallest postive integer with no solution: ",
sumToN(211,False);</lang>
[1..].filter1(fcn(n){ sumToN(n,0)==0 }));</lang>
No "to infinity and beyond", zkl too slow.
{{out}}
<pre>
Line 346 ⟶ 349:
+123-45-67+89
46 solutions for N=9
Smallest postive integer with no solution: 211
0 solutions for N=211
</pre>
Anonymous user