Product of min and max prime factors: Difference between revisions

m
→‎{{header|AppleScript}}: Dedicated primeFactors handler. Multiplications moved to task code.
m (→‎{{header| Haskell}}: Added a draft in Haskell)
m (→‎{{header|AppleScript}}: Dedicated primeFactors handler. Multiplications moved to task code.)
Line 78:
end isPrime
 
on primeFactors(n)
on productOfMinAndMaxPrimeFactors(n)
if ((isPrime(n)) or (n is 1)) then return {n * n}
set output to {}
repeatset withsqrt ito from (n ^ 0.5 div 1) to 2 by -1
if ((sqrt = sqrt div 1) and (isPrime(sqrt))) then
set end of output to sqrt div 1
set sqrt to sqrt - 1
end if
repeat with i from (sqrt div 1) to 2 by -1
if (n mod i is 0) then
if (isPrime(i)) then set output's beginning of output to i
if (isPrime(n div i)) then set output's end of output to n div i
end if
end repeat
return (output's beginning) * (output's end)
end primeFactors
end productOfMinAndMaxPrimeFactors
 
on join(lst, delim)
Line 99 ⟶ 104:
end join
 
on demotask()
set output to {""}
set thisLine to {" 1"}
repeat with n from 12 to 100
tell primeFactors(n) to set product to (its end) * (its beginning)
set thisLine's end of thisLine to text -6 thru -1end of (" " & productOfMinAndMaxPrimeFactors(n)product)
if (n mod 10 is 0) then
set output's end of output to join(thisLine, "")
set thisLine to {}
end if
end repeat
return join(output, linefeed)
end demotask
 
demotask()</syntaxhighlight>
 
{{output}}
557

edits