Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- (define (not_ item)
- (
- cond ((EQ? item #f) #t)
- ( #t #f)
- )
- )
- (define (and_ item1 item2)
- (cond ((EQ? item1 #f) #f)
- ((EQ? item2 #f) #f)
- (#t #t)
- )
- )
- (define (or_ item1 item2)
- ( not_ (and_ (not_ item1) (not_ item2) ) )
- )
- (define (reverse_ list_ result position )
- (cond ((EQ? list_ '()) result )
- ( (and_ (= position 1 ) (and_ (PAIR? list_) (LIST? list_)) )
- (cons (car list_) result ) )
- ( ( and_ (= position 1 ) (and_ (PAIR? list_) (not_ (LIST? list_)) ) )
- (cons list_ result ) )
- ( (= 1 1)
- (reverse_ (cdr list_) (cons (car list_) result ) ( - position 1) )
- )
- )
- )
- (define (count1 lst len)
- (cond ((EQ? lst '() ) len )
- ((not_ (PAIR? lst)) len )
- (else (
- count1 (cdr lst ) (+ len 1)
- ))))
- ( define (level input_list output_list deep length)
- ( cond ( ( and ( < deep length) (> deep 0) )
- ;(display output_list)
- ; (display (car input_list))
- ; (display (cons (car input_list) '() ) )
- ; (display "\n")
- (level (cdr input_list) (cons output_list (cons (car input_list) '() ) ) (+ deep 1) length)
- )
- (( and ( < deep length) (= deep 0))
- (level (cdr input_list) (cons (car input_list) '() ) (+ deep 1) length)
- )
- ((= 1 1) output_list)
- )
- )
- (define (make_level list)
- (level (reverse_ list '() (count1 list 0) ) '() 0 (count1 list 0) )
- )
- (make_level '(4 2 4 4 1) )
- (make_level '(4 2 4 4 1 . 5) )
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement