codepad
[
create a new paste
]
login
|
about
Language:
C
C++
D
Haskell
Lua
OCaml
PHP
Perl
Plain Text
Python
Ruby
Scheme
Tcl
; three interview questions (define (subtract-first-half xs) (let loop ((front xs) (back (reverse xs)) (hare xs) (out (list))) (if (or (null? hare) (null? (cdr hare))) (append (reverse out) front) (loop (cdr front) (cdr back) (cddr front) (cons (- (car front) (car back)) out))))) (display (subtract-first-half '(5 4 3 2 1))) (newline) (display (subtract-first-half '(4 3 2 1))) (newline) (define (trailing-zeros n) (let loop ((k 5) (z 0)) (if (< n k) z (loop (* k 5) (+ z (quotient n k)))))) (display (trailing-zeros 487)) (newline)
Private
[
?
]
Run code
Submit