Skip to content

Instantly share code, notes, and snippets.

@kamath
Created April 24, 2018 19:54
Show Gist options
  • Select an option

  • Save kamath/badbd082423b0de2f39f4bc63e219e24 to your computer and use it in GitHub Desktop.

Select an option

Save kamath/badbd082423b0de2f39f4bc63e219e24 to your computer and use it in GitHub Desktop.
#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