aboutsummaryrefslogtreecommitdiff
path: root/0003
diff options
context:
space:
mode:
authorMistivia <i@mistivia.com>2024-11-09 23:49:08 +0800
committerMistivia <i@mistivia.com>2024-11-09 23:49:08 +0800
commite685ad97fa257e2d6186eab66dc151f02ddc698c (patch)
treeceb256a537156c8ff4394a04f76c4e11c4cb89d7 /0003
parent37be9418ad8f5bbde5f7b703115a2d4fb5d6185e (diff)
3 Largest Prime Factor
Diffstat (limited to '0003')
-rw-r--r--0003/main.lisp16
1 files changed, 16 insertions, 0 deletions
diff --git a/0003/main.lisp b/0003/main.lisp
new file mode 100644
index 0000000..b2ba414
--- /dev/null
+++ b/0003/main.lisp
@@ -0,0 +1,16 @@
+(defun my-reduce (x y)
+ (if (= 0 (mod x y))
+ (my-reduce (/ x y) y)
+ x))
+
+(defun max-factor-impl (x cur)
+ (let ((next-x (my-reduce x cur)))
+ (if (= 1 next-x)
+ cur
+ (max-factor-impl next-x (+ 1 cur)))))
+
+(defun max-factor (x)
+ (max-factor-impl x 2))
+
+(format t "~&~S~%" (max-factor 600851475143))
+