RosettaCodeData/Task/Happy-numbers/APL/happy-numbers-1.apl
2023-07-01 13:44:08 -04:00

20 lines
931 B
APL
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

HappyNumbers arg;⎕IO;∆roof;∆first;bin;iroof
[1] ⍝0: Happy number
[2] ⍝1: http://rosettacode.org/wiki/Happy_numbers
[3] ⎕IO1 ⍝ Index origin
[4] ∆roof ∆first2arg,10
[5]
[6] bin{
[7] ⍝ Default left arg
[8] =1:1 ⍝ Always happy!
[9]
[10] numbers¨1 ⍝ Split numbers into parts
[11] next+/{*2}¨numbers ⍝ Sum and square of numbers
[12]
[13] next:0 ⍝ Return 0, if already exists
[14] (,next) next ⍝ Check next number (recursive)
[15]
[16] }¨iroof∆roof ⍝ Does all numbers upto ∆root smiles?
[17]
[18] ~0¨∆firstbin/iroof ⍝ Show ∆first numbers, but not 0