Advertisement
Guest User

Untitled

a guest
Nov 27th, 2018
96
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Racket 0.98 KB | None | 0 0
  1. (define (real-task my-list)
  2.   (define (task numbers last flag ans it)
  3.     (cond
  4.       [(empty? numbers) ans]
  5.       [(and (= 2 flag) (< last (car numbers))) (task (cdr numbers) (car numbers) 1 ans (+ 1 it))]
  6.       [(and (= 2 flag) (> last (car numbers))) (task (cdr numbers) (car numbers) 0 ans (+ 1 it))]
  7.       [(and (= 1 flag) (< last (car numbers))) (task (cdr numbers) (car numbers) 1 ans (+ 1 it))]
  8.       [(and (= 1 flag) (> last (car numbers))) (task (cdr numbers) (car numbers) 0 (cons ans it) (+ 1 it))]
  9.       [(and (= 0 flag) (> last (car numbers))) (task (cdr numbers) (car numbers) 0 ans (+ 1 it))]
  10.       [(and (= 0 flag) (< last (car numbers))) (task (cdr numbers) (car numbers) 1 (cons ans it) (+ 1 it))]
  11.     )
  12.   )
  13.  
  14.   (if (empty? my-list)
  15.       '()
  16.       (flatten (task (cdr my-list) (car my-list) 2 '() 2))
  17.   )
  18. )
  19.  
  20. ;'(1 3 5 6 4 2 1 9 12 16 14 13 10 16 18 20 22)
  21. ;  1 2 3 4 5 6 7 8 9  10 11 12 13 14 15 16 17
  22.  
  23. (real-task '(1 3 5 6 4 2 1 9 12 16 14 13 10 16 18 20 22))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement