Happy numbers: Difference between revisions

→‎{{header|Lambdatalk}}: adding lambdatalk task
(→‎{{header|Lambdatalk}}: adding lambdatalk task)
Line 4,072:
First 8 happy numbers : 1, 7, 10, 13, 19, 23, 28, 31
</pre>
 
=={{header|Lambdatalk}}==
<syntaxhighlight lang="scheme">
{def happy
{def happy.sum
{lambda {:n}
{if {= {W.length :n} 1}
then {pow {W.first :n} 2}
else {+ {pow {W.first :n} 2}
{happy.sum {W.rest :n}}}}}}
{def happy.is
{lambda {:x :a}
{if {= :x 1}
then true
else {if {> {A.in? :x :a} -1}
then false
else {happy.is {happy.sum :x}
{A.addlast! :x :a}}}}}}
{def happy.rec
{lambda {:n :a :i}
{if {= {A.length :a} :n}
then :a
else {happy.rec :n
{if {happy.is :i {A.new}}
then {A.addlast! :i :a}
else :a}
{+ :i 1}}}}}
{lambda {:n}
{happy.rec :n {A.new} 0}}}
-> happy
 
{happy 8}
-> [1,7,10,13,19,23,28,31]
</syntaxhighlight>
 
=={{header|Lasso}}==
99

edits