-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtier-list.rkt
55 lines (40 loc) · 1003 Bytes
/
tier-list.rkt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
#lang racket
(define allCols '(client initiative rebator))
;
;(define (tier-list list len)
; (cond
; ((cons (take len)
(define (take n list)
(cond
((eq? list null)(quote()))
((= n 0)(quote()))
(else(cons (car list)(take (- n 1) (cdr list))))))
(define (add1 n)
(+ n 1))
(define (len list)
(cond
((eq? list null)0)
(else(add1 (len (cdr list))))))
(len allCols)
(take 3 allCols)
;(define (tier list)
; (let ((n (len list)))
; (cond
; ((= n 0)(quote()))
; (else(cons(take n list)(tier (cdr list)))))))
; implementation seems to be inefficient because it calculates length every time
(define (tier list)
(define n(len list))
(define (tier-helper n list)
(cond
((= n 0)(quote()))
(else(cons(take n list)(tier-helper (- n 1)(cdr list))))))
(tier-helper n list))
(tier allCols)
(define (square n)(* n n))
(define (f x y)
(let ((a (+ 1 (* x y)))
(b (- 1 y)))
(+ (* x (square a))
(* y b)
(* a b))))