πŸ’Ύ Archived View for blitter.com β€Ί apl-examples β€Ί armstrong-numbers β€Ί armstrong-numbers-example.apl.t… captured on 2023-05-24 at 17:49:19.

View Raw

More Information

-=-=-=-=-=-=-

#!/usr/bin/env apl --script

⍝⍝ Determine if a number _n_ is an Armstrong number

βŽ•ex 'digitsOf'
βˆ‡r ← digitsOf n;digitList
digitList ← ⍬
loop:β†’((⌊n)=0)/done
  digitList ← digitList,(⌊n|⍨10)
  n ← nΓ·10
β†’loop
done: r ← βŠ–digitList
βˆ‡

βŽ•ex 'isArmstrongNumber'
βˆ‡r ← isArmstrongNumber n;digits;nd     
  digits ← digitsOf n
  nd ← β‰’ digits
  r ← n = +/digits * nd
βˆ‡

⍝      isArmstrongNumber 9
⍝1
⍝      isArmstrongNumber 10
⍝0
⍝      isArmstrongNumber 153
⍝1