Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon.

Pages: 1-

Too optimized for you?

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)))

Name: Anonymous 2009-11-02 17:06

Too optimized for you?
Using a O(n) prime number test
Not in the slightest, bro

Name: Anonymous 2009-11-02 19:17

fucking unreadable piece of shit

Name: Anonymous 2009-11-02 19:40

>>3
))))))))))()()()((((())((()))()()))))))))))))))))))
lisp
No shit.

Name: Anonymous 2009-11-03 1:32

sorry lost track of the parens
please use a real language
kthxbai

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

Name: Anonymous 2009-11-03 2:08

What are you guys talking about? I don't see any parens. Just some lists.

Name: Anonymous 2009-11-03 9:59

Nice toy program.

Name: Anonymous 2009-11-03 10:14

Write this in C and enjoy your 500+ lines of code.

Name: Anonymous 2009-11-03 10:34

>>9

*5 lines of code.

Name: Anonymous 2009-11-03 11:00

I don't even see the parenthesii anymore; just blonde, brunette, redhead...

Name: Anonymous 2009-11-03 11:04

>>11
I don't get it.

Name: Anonymous 2009-11-03 11:27


))))))))))))))))))))))))))))))))))))))
))(())))))))(())))))((((())))((((())))
))(())))))))(()))))()))))))))(()))()))
))(())))))))(())))))((((())))((((())))
))(())))))))(()))))))))))()))(()))))))
))((((((()))(())))))((((())))(()))))))
))))))))))))))))))))))))))))))))))))))

Name: Anonymous 2009-11-03 11:35

It's nice to see that people are reading their SICP.

Name: Anonymous 2009-11-03 13:45

>>13
:D

Name: Anonymous 2009-11-03 13:58

>>13
I 's/)/ /g''d.
:(

Name: Anonymous 2009-11-03 14:04

>>14
If >>1 had read his SICP he would have used the fermat primality test

Name: Anonymous 2011-02-04 18:55

Don't change these.
Name: Email:
Entire Thread Thread List