Debian Codegraph @

benchmarks/rnrs-benchmarks/triangl.ss

raw
1 ;;; TRIANGL -- Board game benchmark.
2
3 (library (rnrs-benchmarks triangl)
4 (export main)
5 (import (rnrs) (rnrs-benchmarks))
6
7 (define *board*
8 (list->vector '(1 1 1 1 1 0 1 1 1 1 1 1 1 1 1 1)))
9
10 (define *sequence*
11 (list->vector '(0 0 0 0 0 0 0 0 0 0 0 0 0 0)))
12
13 (define *a*
14 (list->vector '(1 2 4 3 5 6 1 3 6 2 5 4 11 12
15 13 7 8 4 4 7 11 8 12 13 6 10
16 15 9 14 13 13 14 15 9 10
17 6 6)))
18
19 (define *b*
20 (list->vector '(2 4 7 5 8 9 3 6 10 5 9 8
21 12 13 14 8 9 5 2 4 7 5 8
22 9 3 6 10 5 9 8 12 13 14
23 8 9 5 5)))
24
25 (define *c*
26 (list->vector '(4 7 11 8 12 13 6 10 15 9 14 13
27 13 14 15 9 10 6 1 2 4 3 5 6 1
28 3 6 2 5 4 11 12 13 7 8 4 4)))
29
30 (define *answer* '())
31
32 (define (attempt i depth)
33 (cond ((= depth 14)
34 (set! *answer*
35 (cons (cdr (vector->list *sequence*)) *answer*))
36 #t)
37 ((and (= 1 (vector-ref *board* (vector-ref *a* i)))
38 (= 1 (vector-ref *board* (vector-ref *b* i)))
39 (= 0 (vector-ref *board* (vector-ref *c* i))))
40 (vector-set! *board* (vector-ref *a* i) 0)
41 (vector-set! *board* (vector-ref *b* i) 0)
42 (vector-set! *board* (vector-ref *c* i) 1)
43 (vector-set! *sequence* depth i)
44 (do ((j 0 (+ j 1))
45 (depth (+ depth 1)))
46 ((or (= j 36) (attempt j depth)) #f))
47 (vector-set! *board* (vector-ref *a* i) 1)
48 (vector-set! *board* (vector-ref *b* i) 1)
49 (vector-set! *board* (vector-ref *c* i) 0) #f)
50 (else #f)))
51
52 (define (test i depth)
53 (set! *answer* '())
54 (attempt i depth)
55 (car *answer*))
56
57 (define (main . args)
58 (run-benchmark
59 "triangl"
60 triangl-iters
61 (lambda (result) (equal? result '(22 34 31 15 7 1 20 17 25 6 5 13 32)))
62 (lambda (i depth) (lambda () (test i depth)))
63 22
64 1)))