Created
April 24, 2018 19:54
-
-
Save kamath/badbd082423b0de2f39f4bc63e219e24 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| #lang racket | |
| ; Enter your code here. Read input from STDIN. Print output to STDOUT | |
| ; Func : None -> None | |
| ; Reads a list with variable inputs | |
| (define (func) | |
| (let ([num (read)]) | |
| (cond | |
| [(number? num) (cons num (func))] | |
| [else '()]))) | |
| (define arr (func)) | |
| ; remove-odd : [List-of X] -> [List-of X] | |
| ; Removes elements at odd positions | |
| (define (remove-odd arr) | |
| (local ((define (remove n l) | |
| (cond | |
| [(empty? l) '()] | |
| [(= (modulo n 2) 0) (remove (+ 1 n) (rest l))] | |
| [else (cons (first l) (remove (+ 1 n) (rest l)))]))) | |
| (remove 0 arr))) | |
| ; p: [List-of X] -> Console | |
| ; Prints out a list line by line | |
| (define (p l) | |
| (cond | |
| [(empty? l) (printf "")] | |
| [else (print (first l)) | |
| (printf "\n") | |
| (p (rest l))])) | |
| (p (remove-odd arr)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment