Skip to content

Commit

Permalink
added day three
Browse files Browse the repository at this point in the history
  • Loading branch information
ajnadel committed Jan 25, 2016
1 parent 2087ca2 commit a033dd9
Showing 1 changed file with 44 additions and 0 deletions.
44 changes: 44 additions & 0 deletions daythree.rkt
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
#lang racket

(define (square x)
(* x x))

;; more obfuscated functions, please
(define (head x) (car x))
(define (tail x) (cdr x))

(define (foldr func arr val)
(if (null? arr)
val
(foldl func (cdr arr) (func (car arr) val))))

; (define (foldr func arr val)
; (if (null? arr)
; val
; (foldr func (cdr arr) (func val (car arr)))))

;; won't work because there's no difference between 0-10-5-1 and 0-1-5-10
; (define (foldr-cheating func arr starting-value) (foldl func (reverse arr) starting-value))


;; not working yet
; (define (foldr-helper func old-arr new-value)
; (if (null? old-arr)
; new-value

; (define (foldr func arr starting-value)
; (foldr-helper func arr (list starting-value)))
; (println "(foldl - '(10 5 1) 0)")
(foldr - '(10 5) 0)

;; not sure if there is a preferred way to do this
(define (fib n)
(if (< n 1)
0
(if (= n 1)
1
(+ (fib (- n 1)) (fib (- n 2))))))

(println "fib(0-10)")
(for ([i (in-range 10)])
(println (fib i)))

0 comments on commit a033dd9

Please sign in to comment.