Scheme Challenge
1
Name:
Anonymous
2009-06-19 22:40
Write a scheme program that does anything that would be significantly more verbose if coded in another language.
Size should be measured in characters (wc -m), non-signficant white space should not be counted.
2
Name:
Anonymous
2009-06-19 22:56
>>1
Am I to assume we disallow Common Lisp as the other language?
3
Name:
Anonymous
2009-06-19 23:06
>>1
Are we disallowing APL and Factor as well? Forth?
4
Name:
Anonymous
2009-06-19 23:06
>>2
Yes. If your preference is to use another lisp dialect feel free to use that to.
5
Name:
Anonymous
2009-06-19 23:12
>>4
That was not the question!
6
Name:
Anonymous
2009-06-20 0:39
Haskell:
subsets = filterM (const [True,False])
Scheme:
(define (subsets s)
(if (null? s)
(list (list))
(let ((rest (subsets (cdr s))))
(append rest (map (lambda (x) (cons (car s) x))
rest)))))(SICP Exercise 2.32)
7
Name:
Anonymous
2009-06-20 2:03
Conway's Game of Life
Next generation in Lisp:
(defun live (cur)
(let* ((w (array-dimension cur 0))
(h (array-dimension cur 1))
(next (make-array (list w h) :initial-element nil)))
(labels ((neighbors (x y)
(count-if 'identity
(mapcar (lambda (d)
(aref cur
(mod (- x (car d)) w)
(mod (- y (cdr d)) h)))
'((-1 . -1) ( 0 . -1) ( 1 . -1)
(-1 . 0) ( 1 . 0)
(-1 . 1) ( 0 . 1) ( 1 . 1)))))
(lives (x y)
(let ((ns (neighbors x y)))
(if (or (= ns 3)
(and (aref cur x y) (= ns 2)))
t nil))))
(dotimes (i w)
(dotimes (j h)
(setf (aref next i j) (lives i j)))))
next))
In APL: life←{↑1 ⍵∨.^3 4=+/,¯1 0 1∘.⊖¯1 0 1∘.⌽⊂⍵}
8
Name:
Anonymous
2009-06-20 3:01
{↑1 ⍵ 1↑}
9
Name:
Anonymous
2009-06-20 3:07
>>8
Invalid APL code. Valid Perl.
10
Name:
Anonymous
2009-06-20 3:28
11
Name:
Anonymous
2009-06-20 4:16
Scheme, 24 chars
(display "Hello World!")
HTML, 13 chars
Hello World!
Almost twice as long....
12
Name:
Anonymous
2009-06-20 4:26
>>11
Your HTML doesn't compile.
13
Name:
Anonymous
2009-06-20 4:44
>>12
what about .chm files?
14
Name:
Anonymous
2009-06-20 9:22
//Conway's game of life
void life(int[][] cur){
int[][] next=new int[w][h];
for(int i=0;i<w;i++)
for(int j=0;j<h;h++){
int n=0;
for(int a=-1;a<2;a++)
for(int b=-1;b<2;b++){
n+=cur[(a+i)%w][(b+j)%h];
}
if(cur[i][j]==1&&n==4||n==3)
next[i][j]=1;
}
life(next);
}
15
Name:
Anonymous
2009-06-20 19:06
16
Name:
Anonymous
2009-06-20 19:40
>>14
this indentation transcends space and time
17
Name:
Anonymous
2009-06-20 20:36
// Conways game of dicks
10 PRINT "DICKS"
20 GOTO 10
18
Name:
Anonymous
2009-06-21 4:58
19
Name:
!4SUSsmAnSA
2009-06-21 5:01
test
20
Name:
Anonymous
2009-06-21 6:04
>>17
(define (fix f)
(f (fix f)))
(fix (lambda (f) (display "DICKS") (f)))
21
Name:
Anonymous
2009-06-21 13:28
22
Name:
Anonymous
2011-01-31 21:10
<-- check em dubz
23
Name:
tray
2012-03-14 23:12