mirror of
https://github.com/bertptrs/adventofcode.git
synced 2025-12-25 21:00:31 +01:00
Solution for day 6 in matlab.
This commit is contained in:
20
2017/day-06/solution.m
Normal file
20
2017/day-06/solution.m
Normal file
@@ -0,0 +1,20 @@
|
||||
function [cycles,repeat] = solution (division)
|
||||
division = vec(division);
|
||||
states = zeros(0, size(division)(1));
|
||||
|
||||
while ! ismember(transpose(division), states, "rows")
|
||||
states = [states; transpose(division)];
|
||||
|
||||
[maxval, maxindex] = max(division);
|
||||
division(maxindex) = 0;
|
||||
|
||||
for i = 1:maxval
|
||||
targetIndex = mod(maxindex + i - 1, size(division)(1)) + 1;
|
||||
division(targetIndex) += 1;
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
cycles = size(states)(1);
|
||||
repeat = division;
|
||||
endfunction
|
||||
Reference in New Issue
Block a user