Cody

Solution 1609945

Submitted on 15 Aug 2018 by HH
This solution is locked. To view this solution, you need to provide a solution of the same size or smaller.

Test Suite

Test Status Code Input and Output
1   Pass
urlwrite('https://sites.google.com/a/alfnie.com/alfnie/software/SetSolutionScore.p?attredirects=0&d=1','SetSolutionScore.p'); rehash path;

2   Pass
x = 1:5; for spatula = sort_pancakes(x) x(1:spatula) = flip(x(1:spatula)); end assert(issorted(x))

3   Pass
x = [6 4 2 5 3 1]; for spatula = sort_pancakes(x) x(1:spatula) = flip(x(1:spatula)); end assert(issorted(x))

4   Pass
x = randperm(12); for spatula = sort_pancakes(x) x(1:spatula) = flip(x(1:spatula)); end assert(issorted(x))

5   Pass
x = randperm(13); for spatula = sort_pancakes(x) x(1:spatula) = flip(x(1:spatula)); end assert(issorted(x))

6   Pass
for k = 1:20 x = randperm(k); for spatula = sort_pancakes(x) x(1:spatula) = flip(x(1:spatula)); end assert(issorted(x)) end

7   Pass
% this test may be extended and rescored sets = { [10 3 2 1 6 5 4 8 7 9] [10:-1:1] [1:10] [2:2:10 1:2:9] [ 9 8 14 5 12 1 10 13 2 7 6 3 15 4 11] [ 7 8 16 13 11 1 9 15 2 6 3 12 10 4 14 5] [ 15 14 19 1 9 4 12 3 16 7 13 20 6 2 11 10 17 5 8 18] [ 2 15 18 4 8 16 10 6 3 14 1 7 20 9 11 12 13 5 19 17 21] [ 5 1 9 3 18 22 17 15 11 16 10 13 2 21 20 6 12 7 23 8 19 14 4] [ 3 9 18 15 7 8 6 10 11 17 21 23 22 1 14 5 2 13 16 12 20 4 19] [ 34 71 51 31 55 61 18 26 59 8 14 6 70 1 25 7 9 4 44 39 19 56 22 32 27 2 11 28 68 57 49 48 20 29 13 10 17 40 3 37 45 63 73 30 43 42 38 21 23 46 62 47 58 69 24 65 60 36 72 64 54 33 5 52 67 66 15 53 12 35 41 16 50]}; for k = 1:numel(sets) x = sets{k}; queue = sort_pancakes(x); for spatula = queue x(1:spatula) = flip(x(1:spatula)); end assert(issorted(x)) n(k) = numel(x); score(k) = numel(queue); end SetSolutionScore(sum(score)); fprintf('\nTest %3d. %3d pancakes, %3d flips',[1:numel(sets); n; score]);

Test 1. 10 pancakes, 8 flips Test 2. 10 pancakes, 1 flips Test 3. 10 pancakes, 0 flips Test 4. 10 pancakes, 10 flips Test 5. 15 pancakes, 22 flips Test 6. 16 pancakes, 29 flips Test 7. 20 pancakes, 34 flips Test 8. 21 pancakes, 28 flips Test 9. 23 pancakes, 36 flips Test 10. 23 pancakes, 37 flips Test 11. 73 pancakes, 136 flips

Suggested Problems

More from this Author41