Steady squares: Difference between revisions

→‎{{header|Fe}}: Much faster mod calculation
(Added Fe)
(→‎{{header|Fe}}: Much faster mod calculation)
Line 794:
<syntaxhighlight lang="clojure">
(= steadySquares
(fn (maxNumber) ; max number to consider - must be a power of 10
(let powerOfTen 10) ; 10^(one more than 10^(the number of digits in n)
(let maxSquare (* maxNumber maxNumber)) ; largest square to consider
(let lastDigit (list 1 5 6)); a steady square must end with 1, 5 or 6
(let lastResult (cons 0 nil)); latest steady square start with a dummy 0
Line 812 ⟶ 813:
; Fe doesn't have a mod operator, integer division or a way
; to truncate a float to an integer, so we calculate
; n2 mod powerOfTen using repeated subtraction - but see
(let; n2%p10FizzBuzz n2)for ;an seeexample FizzBuzz forof doing it with a C function
(while (<= powerOfTenlet n2%p10 n2)
(= n2%p10 (-let n2%p10mDivisor powerOfTen)maxSquare)
(while (<= powerOfTen mDivisor)
(while (<= mDivisor n2%p10)
(= n2%p10 (- n2%p10 mDivisor))
)
(= mDivisor (/ mDivisor 10))
)
(if (is nd n2%p10)
3,021

edits