codepad | about

 Link:

C, pasted on Jul 16:
 ```1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 ``` ```/** * An absent minded professor designed a house of 27 floors * but forgot to build any staircaes. * Now he has 4 very light weight ladders of length 1, 4, 13 and 14 floors. * To go to any floor he use any ladder to climb up and bring other * ladders with him. The he uses rest of the ladders to go up or down. * (He can not use the already used ladder) * Which floors are not accessible to him. */ int reachable[28] = {1}; void go(int r, int *arr, int n) { if(0 == n) { if(1 <= r && r <= 27) reachable[r] = 1; } else { int *next = arr+1; int rem = n-1; go(r, next, rem); go(r+arr[0], next, rem); go(r-arr[0], next, rem); } } int main() { int i; int arr[] = {1, 4, 13, 14}; go(0, arr, 4); for(i = 1; i <= 27; ++i) { if( !reachable[i] ) printf("%d\n", i); } return 0; } /* EOF */ ```

Output:
 ```1 2 3 4 ``` ```7 20 21 25 ```

Comments:

Bonus question: What is the minimum length of extra fifth ladder after which at least one floor is still inaccessible. (Ans. is 4)