Jump to content

Zumkeller numbers: Difference between revisions

m
→‎{{header|AppleScript}}: Subset-sum matching handler relabelled, reparametered, and made partly iterative.
m (→‎{{header|AppleScript}}: Pulled out the subtotal check to a separate handler. Slight speed improvement by only getting proper divisors and knowing the missing one.)
m (→‎{{header|AppleScript}}: Subset-sum matching handler relabelled, reparametered, and made partly iterative.)
Line 574:
end properDivisors
 
on containsSubtotalcanSumTo(lst, subtotal, i, jtarget)
script o
property l : lst
on cscst(subtotaltarget, ji)
set n to item j of my lrepeat
if ( set n =to item subtotal)i thenof returnmy truel
if (jn = itarget) then return falsetrue
set j to j -if (i = 1) then return false
set i to i - 1
return if (((subtotaln >< ntarget) and (cscst(subtotaltarget - n, ji))) orthen (cs(subtotal,return j)))true
end repeat
end cs
end script
return o's cscst(subtotaltarget, jcount o's l)
end canSumTo
end containsSubtotal
 
on isZumkeller(n)
Line 602 ⟶ 603:
set halfSum to sum / 2
return ((halfSum ≥ n) and (halfSum as integer = halfSum) and (containsSubtotalcanSumTo(o's divisors, halfSum, 1, (count o's divisors))))
end isZumkeller
 
557

edits

Cookies help us deliver our services. By using our services, you agree to our use of cookies.