Penholodigital squares: Difference between revisions

→‎{{header|Wren}}: Optimized - about 7 x speed up.
(→‎{{header|Wren}}: Optimized - about 7 x speed up.)
Line 763:
{{libheader|Wren-fmt}}
This is limited to base 14 as base 15 would overflow Wren's safe integer limit of 2^53.
 
Although I'm not quite sure why, it appears that a necessary condition for a number to be a penholodigital square is for its square root to be exactly divisible by the highest prime factor of (base - 1).
<syntaxhighlight lang="ecmascript">import "./math" for Int
import "./fmt" for Conv, Fmt
Line 775 ⟶ 777:
var min = Conv.atoi(digits[0..(b-2)], b).sqrt.ceil
var max = Conv.atoi(digits[(b-2)..0], b).sqrt.floor
var div = Int.primeFactors(b-1)[-1]
for (i in min..max) {
if (b == 10 && (sqi % 3div) != 0) continue
var sq = i * i
if (b == 10 && (sq % 3) != 0) continue
var digs = Int.digits(sq, b)
if (digs.contains(0)) continue
9,482

edits