Too optimized for you?
1
Name:
Anonymous
2009-11-02 17:04
(define (prime? x)
(define (inner i)
(cond ((> i (sqrt x)) #t)
((= (remainder x i) 0) #f)
(else (inner (+ i 1)))))
(inner 2))
(define (factor x)
(define (times x i)
(define (inner x n)
(if (= (remainder x i) 0)
(inner (/ x i) (+ n 1))
n))
(inner x 0))
(define (inner x i l)
(cond ((= 1 x) l)
((not (prime? i)) (inner x (+ i 1) l))
((not (= (times x i) 0)) (inner (/ x (expt i (times x i))) (+ i 1) (cons (list i (times x i)) l)))
(else (inner x (+ i 1) l))))
(inner x 2 '()))
(define (pprint-factor lst)
(define (inner l)
(if (null? l) #f
(begin
(display (car (car l)))(display "^")(display (cadar l))(display " ")
(inner (cdr l)))))
(inner lst))
(display "Enter number to prime factorize:")(newline)
(pprint-factor (factor (read)))
2
Name:
Anonymous
2009-11-02 17:06
Too optimized for you?
Using a O(n) prime number test
Not in the slightest, bro
3
Name:
Anonymous
2009-11-02 19:17
fucking unreadable piece of shit
4
Name:
Anonymous
2009-11-02 19:40
>>3
))))))))))()()()((((())((()))()()))))))))))))))))))
lisp
No shit.
5
Name:
Anonymous
2009-11-03 1:32
sorry lost track of the parens
please use a real language
kthxbai
6
Name:
Anonymous
2009-11-03 1:44
omg parens what do i do there's no way lispers actually look at indentation and thus lisp is perfectly readable despite all its parens oh shit ihbt
7
Name:
Anonymous
2009-11-03 2:08
What are you guys talking about? I don't see any parens. Just some lists.
8
Name:
Anonymous
2009-11-03 9:59
Nice toy program.
9
Name:
Anonymous
2009-11-03 10:14
Write this in C and enjoy your 500+ lines of code.
10
Name:
Anonymous
2009-11-03 10:34
11
Name:
Anonymous
2009-11-03 11:00
I don't even see the parenthesii anymore; just blonde, brunette, redhead...
12
Name:
Anonymous
2009-11-03 11:04
13
Name:
Anonymous
2009-11-03 11:27
))))))))))))))))))))))))))))))))))))))
))(())))))))(())))))((((())))((((())))
))(())))))))(()))))()))))))))(()))()))
))(())))))))(())))))((((())))((((())))
))(())))))))(()))))))))))()))(()))))))
))((((((()))(())))))((((())))(()))))))
))))))))))))))))))))))))))))))))))))))
14
Name:
Anonymous
2009-11-03 11:35
It's nice to see that people are reading their SICP.
15
Name:
Anonymous
2009-11-03 13:45
16
Name:
Anonymous
2009-11-03 13:58
17
Name:
Anonymous
2009-11-03 14:04
>>14
If
>>1 had read his SICP he would have used the fermat primality test
18
Name:
Anonymous
2011-02-04 18:55