Skip to content

Instantly share code, notes, and snippets.

@Munksgaard
Created October 8, 2010 12:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Munksgaard/616724 to your computer and use it in GitHub Desktop.
Save Munksgaard/616724 to your computer and use it in GitHub Desktop.
(defun isInteger (n)
(= (round n) n))
(defun isPentagonalNumber (p)
(let ((solution (/ (+ 1 (sqrt (+ 1 (* 24 p)))) 6)))
(isInteger solution)))
(defun test (p)
(/ (+ 1 (sqrt (+ 1 (* 24 p)))) 6))
(defun PentagonalNumber (n)
(* n (/ (- (* 3 n) 1) 2)))
(defun isHexagonalNumber (h)
(let ((solution (/ (+ 1 (sqrt (+ 1 (* 8 h)))) 4)))
(isInteger solution)))
(defun HexagonalNumber (n)
(* n (- (* 2 n) 1)))
(defun TriangleNumber (n)
(* (/ n 2) (+ n 1)))
(defun problem45 (n)
(let ((trinum (triangleNumber n)))
(if (and (isPentagonalNumber2 trinum)
(isHexagonalNumber trinum))
(list trinum n)
(problem45 (1+ n)))))
(problem45 300)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment