Happy numbers: Difference between revisions
Content deleted Content added
→{{header|Liberty BASIC}}: Add Logo |
→{{header|Logo}}: Add implementation. |
||
Line 1,014: | Line 1,014: | ||
=={{header|Logo}}== |
=={{header|Logo}}== |
||
to sum_of_square_digits :number |
|||
output (apply "sum (map [[d] d*d] ` :number)) |
|||
end |
|||
to is_happy? :number [:seen []] |
|||
output cond [ |
|||
[ [:number = 1] "true ] |
|||
[ [member? :number :seen] "false ] |
|||
[ else (is_happy? (sum_of_square_digits :number) (lput :number :seen))] |
|||
] |
|||
end |
|||
to n_happy :count [:start 1] [:result []] |
|||
output cond [ |
|||
[ [:count <= 0] :result ] |
|||
[ [is_happy? :start] |
|||
(n_happy_from (:count-1) (:start+1) (lput :start :result)) ] |
|||
[ else |
|||
(n_happy_from :count (:start+1) :result) ] |
|||
] |
|||
end |
|||
print n_happy 8 |
|||
=={{header|Liberty BASIC}}== |
=={{header|Liberty BASIC}}== |
||
<lang lb> |
<lang lb> |