Project Euler Problem 45
Note: all hexagonal numbers are triangle numbers. The function typep is used to see if the formula in the function pentagonal? is a natural number (integer). Function problem45 increments up from 144, because the problem statement for Project Euler 45 already provides a hexagonal number 40755 (that's also a pentagonal and triangle number) using the integer 143.
(defun pentagonal? (num)
(typep
(/ (1+ (sqrt (1+ (* 24 num)))) 6)
'integer))
(defun problem45 ()
(loop for i upfrom 144
for hex = (- (* 2 i i) i)
when (pentagonal? hex) return hex))
No comments:
Post a Comment