Advertisement
Guest User

Untitled

a guest
Nov 6th, 2018
103
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Racket 0.36 KB | None | 0 0
  1. (define (extract-nth-digit a n current)
  2.   (if (= current n)
  3.       (modulo a 10)
  4.       (extract-nth-digit (quotient a 10) n (+ 1 current))))
  5.  
  6.    
  7. (define (length a)
  8.   (if (and (< 0 a) (< a 10))
  9.       1
  10.       (+ 1 (length (/ a 10)))))
  11.  
  12. (define (middle-digit a)
  13.   (if (even? (length a))
  14.       -1
  15.       (extract-nth-digit a (ceiling (/ (length a) 2)) 1)))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement