Skip to content

Instantly share code, notes, and snippets.

@jeremyBanks
Created August 22, 2008 22:01
Show Gist options
  • Save jeremyBanks/6862 to your computer and use it in GitHub Desktop.
Save jeremyBanks/6862 to your computer and use it in GitHub Desktop.
[2010-01] some project euler stuff in sbcl
#!/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