[Previous entry: "Quake"] [Main Index] [Next entry: "Severe Acute Respiratory Syndrome"]

04/03/2003 Entry: "scheme sucks"

Warning, do not click!

Yeah, so I had to write something that could check if lines connecting dots could be colored in with two colors, uh, it's kinda tough to explain, but like, what you do is assemble a 'graph' from a list, so a list ((1 2) (2 3) (3 1) (1 4)) would make the following graph:


scheme sucks

So then each list in the list represents a line. A graph can be colored with two colors if you can have each circle not be connected to a circle of the same color, so essentially you need to find triangles. The one above is not two-colorable. Anyway, I wrote most of the code in like two hours or so on Monday and then didn't touch it on Tuesday or Wednesday and I came back to it just now and I totally forgot how it works. After looking it over for a bit I figured it out, but it's pretty goddamn confusing, especially the second function. Yeah, so now you all can like see it because I'm a nice guy like that! nerd++

(define (search ls ls2)
(if (null? ls)
'()
(if (equal? (sort (car ls) >) (sort ls2 >))
#t
(search (cdr ls) ls2)
)
)
)

;car car ls is the first element of the first thing in the list ((1 2)... <- 1
;car cdr car ls is the second element in the first node ((1 2)... <- 2
(define (check-search ls ls2)
(if (null? ls)
'()
(cond
((equal? (car (car ls)) (car ls2)) ;first == first
(search (cdr ls) (list (car (cdr (car ls))) (car (cdr ls2))))
)
((equal? (car (car ls)) (car (cdr ls2))) ;first == second
(search (cdr ls) (list (car (cdr (car ls))) (car ls2)))
)
((equal? (car (cdr (car ls))) (car ls2)) ;second == first
(search (cdr ls) (list (car (car ls)) (car (cdr ls2))))
)
((equal? (car (cdr (car ls))) (car (cdr ls2))) ;second == second
(search (cdr ls) (list (car (car ls)) (car ls2)))
)
(else (check-search (cdr ls) ls2))
)
)
)

(define (two-colorable? ls)
(if (null? ls)
#t
(if (equal? #t (check-search (cdr ls) (car ls)))
'()
(two-colorable? (cdr ls))
)
)
)

I'm not quite sure what the purpose of this was tho, but I expect negative karma straight away!


Replies: 2 comments

You need to use more comments, I guess. That happens to me a lot too.

Posted by Jon from 62.31.255.83 @ 04/04/2003 11:01 AM CST

Yeah, I'm fairly good with commenting C/++ and even ACS (hah) but for some reason I never comment scheme...

Posted by Cyb from 169.226.79.99 @ 04/04/2003 11:36 AM CST

Powered By Greymatter