💾 Archived View for blitter.com › apl-examples › armstrong-numbers › armstrong-numbers-example.apl.t… captured on 2024-05-26 at 14:43:05.

View Raw

More Information

⬅️ Previous capture (2023-05-24)

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

#!/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