Created
August 22, 2008 22:01
-
-
Save jeremyBanks/6862 to your computer and use it in GitHub Desktop.
[2010-01] some project euler stuff in sbcl
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env sbclx | |
; I actually might want to use a function? Goodie! | |
(defun isPrime (n) ; a crude brute-force prime check | |
(do | |
( | |
(limit (ceiling (sqrt n))) ; maximum requred to determine if it is prime | |
(i 2 (1+ i)) | |
) | |
((> i limit)) | |
(if | |
(= | |
0 | |
(mod n i) | |
) | |
(return-from isPrime nil) | |
) | |
) | |
(return-from isPrime T) | |
) | |
(let | |
( | |
(n 600851475143) ; the number we're factoring - for real | |
) | |
(do | |
( | |
(factor 1 (1+ factor)) | |
(limit (ceiling (/ n 2))) | |
) | |
((> factor limit)) | |
(if | |
(and | |
(= 0 (mod n factor)) ; it's a factor | |
(isPrime (/ n factor)) | |
) | |
(progn | |
(print (/ n factor)) | |
(return) | |
) | |
) | |
) | |
) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment