I'd like to start off by saying this is homework; so I'm not asking for a solution, just some tips. I've been ruminating on this for about a week now. Every solution I come up with doesn't do it recursively, seeing as I can't manage to wrap my head around doing it recursively with the list as the only parameter. My professor said they were able to do it with about 6 helper functions.
As mentioned, I have to solve the problem taking taking the list as the only parameter. Here's an example of what I've got on my latest attempt.
(define (sumSublists lst)
(if (= (length lst) 0)
0
(+ (length (car lst)) (sumSublists (cdr lst)))
)
)
(define (hanoi towersNum)
(sub1 (sumSublists towersNum))
(if (= (sumSublists towersNum) 1)
(print towersNum)
(begin (if (= (sumSublists towersNum) 1)
(print towersNum)
(hanoi '((car towersNum) (cddr towersNum) (cadr towersNum)))
)
(if (= (sub1 (sumSublists towersNum)) 1)
(print towersNum)
(hanoi '((car towersNum) (cadr towersNum) (cddr towersNum)))
)
(if (= (sub1 (sumSublists towersNum)) 1)
(print towersNum)
(hanoi '((cddr towersNum) (cadr towersNum) (car towersNum)))
)
)
)
)
sumSublists returns how many disks there are in the game. I'm getting an infinite loop since every time it gets used it takes the same value, thus not ever reducing the value. My problem with that, is I'm so used to imperative and OOP with the use of variables that I'm not sure how I can do this when Hanoi only takes one parameter.
The code for Hanoi is my attempt to turn my project from C++ into Scheme.
Any help is appreciated. I'm using Dr. Racket as my IDE by the way.