Skip to content

Commit

Permalink
moar
Browse files Browse the repository at this point in the history
  • Loading branch information
danwhitford committed Nov 26, 2023
1 parent b32dad5 commit c4f8b55
Showing 1 changed file with 55 additions and 3 deletions.
58 changes: 55 additions & 3 deletions seasoning.rkt
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,9 @@
(cond
((null? lat) #f)
(else
(or
(two-in-a-row-b? (car lat) (cdr lat))
(eq? preceeding (car lat))))))
(or
(eq? preceeding (car lat))
(two-in-a-row-b? (car lat) (cdr lat))))))

(define (two-in-a-row-final? lat)
(cond
Expand All @@ -66,3 +66,55 @@
(check-equal?
(two-in-a-row-final? '(italian sardines sardines spaghetti parsley))
#t)
(check-equal?
(two-in-a-row-final? '(d e i i a g))
#t)

(define (sum-of-prefixes lat)
(cond
((null? lat) '())
(else
(sum-of-prefixes-b 0 lat))))

(define (sum-of-prefixes-b sumsofar tup)
(cond
((null? tup) '())
(else
(cons
(+ sumsofar (car tup))
(sum-of-prefixes-b
(+ sumsofar (car tup))
(cdr tup))))))

(check-equal?
(sum-of-prefixes '(2 1 9 17 0))
'(2 3 12 29 29))
(check-equal?
(sum-of-prefixes '(1 1 1 1 1))
'(1 2 3 4 5))

(define (pick n lat)
(cond
((eq? n 1) (car lat))
(else (pick (sub1 n) (cdr lat)))))

(check-equal? (pick 1 '(1 2 3 4 5)) 1)
(check-equal? (pick 3 '(1 2 3 4 5)) 3)
(check-equal? (pick 5 '(1 2 3 4 5)) 5)

(define (scramble tup)
(cond
((null? tup) '())
(else (scramble-b tup '()))))

(define (scramble-b tup reversed-prefix)
(cond
((null? tup) '())
(else
(cons
(pick (car tup) (cons (car tup) reversed-prefix))
(scramble-b (cdr tup) (cons (car tup) reversed-prefix))))))

(check-equal? (scramble '(1 1 1 3 4 2 1 1 9 2)) '(1 1 1 1 1 4 1 1 1 9))
(check-equal? (scramble '(1 2 3 4 5 6 7 8 9)) '(1 1 1 1 1 1 1 1 1))
(check-equal? (scramble '(1 2 3 1 2 3 4 1 8 2 10)) '(1 1 1 1 1 1 1 1 2 8 2))

0 comments on commit c4f8b55

Please sign in to comment.