-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
ad2c46f
commit b32dad5
Showing
1 changed file
with
68 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
#lang racket | ||
(require rackunit) | ||
|
||
(define (atom? x) | ||
(and | ||
(not (pair? x)) | ||
(not (null? x)))) | ||
|
||
(check-equal? (atom? '()) #f) | ||
|
||
(define (add1 n) | ||
(+ n 1)) | ||
|
||
(define (sub1 n) | ||
(- n 1)) | ||
|
||
(define (member? a lat) | ||
(cond | ||
((null? lat) #f) | ||
(else (or | ||
(eq? a (car lat)) | ||
(member? a (cdr lat)))))) | ||
|
||
(check-equal? | ||
(member? 'sardines '(italian sardines spaghetti parsley)) | ||
#t) | ||
|
||
(define (two-in-a-row? lat) | ||
(cond | ||
((null? lat) #f) | ||
(else | ||
(is-first-b? (car lat) (cdr lat))))) | ||
|
||
(define (is-first-b? a lat) | ||
(cond | ||
((null? lat) #f) | ||
(else | ||
(or | ||
(eq? a (car lat)) | ||
(two-in-a-row? lat))))) | ||
|
||
(check-equal? | ||
(two-in-a-row? '(italian sardines spaghetti parsley)) | ||
#f) | ||
(check-equal? | ||
(two-in-a-row? '(italian sardines sardines spaghetti parsley)) | ||
#t) | ||
|
||
(define (two-in-a-row-b? preceeding lat) | ||
(cond | ||
((null? lat) #f) | ||
(else | ||
(or | ||
(two-in-a-row-b? (car lat) (cdr lat)) | ||
(eq? preceeding (car lat)))))) | ||
|
||
(define (two-in-a-row-final? lat) | ||
(cond | ||
((null? lat) #f) | ||
(else | ||
(two-in-a-row-b? (car lat) (cdr lat))))) | ||
|
||
(check-equal? | ||
(two-in-a-row-final? '(italian sardines spaghetti parsley)) | ||
#f) | ||
(check-equal? | ||
(two-in-a-row-final? '(italian sardines sardines spaghetti parsley)) | ||
#t) |