Happy numbers: Difference between revisions

Added Uiua solution
(Add ABC)
(Added Uiua solution)
Line 7,286:
31 is a happy number
</pre>
 
=={{header|Uiua}}==
{{works with|Uiua|0.10.0-dev.1}}
<syntaxhighlight lang="Uiua">
HC ← /+ⁿ2≡⋕°⋕ # Happiness calc = sum of squares of digits
IH ← |2 memo⟨IH ⊙⊂.|=1⟩∊,, HC # Apply HC until seen value recurs
Happy ← ⟨0◌|∘⟩IH : [1] . # Pre-load `seen` with 1. Return start number or 0
 
# Brute force approach isn't too bad with memoisation even for high bounds.
↙8⊚>0≡Happy⇡10000
 
# But iterative approach with short-cut is still much faster
⊙◌⍢(⟨◌|⊂:⟩>0.:⊙(⊃(Happy ⊢)(↘1)))(<8⧻.) []⇡10000
</syntaxhighlight>
 
=={{header|UNIX Shell}}==
88

edits