Correct Answer in Turing
Expand|Select|Wrap|Line Numbers
- function between (a, b, c : int) : boolean
- result a <= b and b <= c
- end between
- % this recursively tries every route to the end (7000)
- procedure findPath (distance : int)
- if distance = 7000 then
- % made it to the end!
- % One more way to get there
- ways := ways + 1
- put ways
- else
- % recursively try all motels that you can get to
- for i : 1 .. size
- put i
- if between (minn, motel (i) - distance, maax) then
- findPath (motel (i))
- end if
- end for
- end if
- end findPath
Expand|Select|Wrap|Line Numbers
- int truck(int distance)
- {if (distance == 7000)
- { pos=pos+1; cout<< pos << "pos"; }
- else
- for (int i=1;i<=motels.size();i++)
- {
- cout << i;
- if(minn <= motels[i] - distance && maxx >= motels[i] - distance)
- {truck(motels[i]);}
- }