Skip to content

Instantly share code, notes, and snippets.

@JonTanS
Created November 25, 2013 18:35
Show Gist options
  • Save JonTanS/7646272 to your computer and use it in GitHub Desktop.
Save JonTanS/7646272 to your computer and use it in GitHub Desktop.
Practice 1
;list number -> list
;given a list and number, returns a list length of the given number. The length of the list will always be greater than the number.
(define (numlist litt number)
(cond [(= 0 number) empty]
[else (cons (first litt) (numlist (rest litt) (- number 1)))]))
(check-expect (numlist (list 1 2 3 4 5) 2) (list 1 2))
(check-expect (numlist (list "cat" "dog" "chicken") 3) (list "cat" "dog" "chicken"))
(check-expect (numlist (list 1 2 3 4 1) 0) empty)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment