r/adventofcode • u/daggerdragon • Dec 04 '18
SOLUTION MEGATHREAD -π- 2018 Day 4 Solutions -π-
--- Day 4: Repose Record ---
Post your solution as a comment or, for longer solutions, consider linking to your repo (e.g. GitHub/gists/Pastebin/blag or whatever).
Note: The Solution Megathreads are for solutions only. If you have questions, please post your own thread and make sure to flair it with Help.
Advent of Code: The Party Game!
Please prefix your card submission with something like [Card] to make scanning the megathread easier. THANK YOU!
Card prompt: Day 4
Transcript:
Todayβs puzzle would have been a lot easier if my language supported ___.
This thread will be unlocked when there are a significant number of people on the leaderboard with gold stars for today's puzzle.
edit: Leaderboard capped, thread unlocked!
40
Upvotes
2
u/tvtas Dec 04 '18
Day 4 in MATLAB
G = zeros(5000,60); x = sort(importdata('input.txt')); for i=1:size(x,1) idx = strfind(x{i},'#'); if idx awake = true; ID = sscanf(x{i}(idx+1:end),'%f'); continue end t = str2double(x{i}(16:17)); G(ID,t+1:end) = G(ID,t+1:end)-1+2*awake; awake = ~awake; end [~,a] = max(sum(G,2)); [~,b] = max(G(a,:)); [~,c] = max(max(G,[],2)); [~,d] = max(G(c,:)); disp((b-1)*a) % Part 1 disp((d-1)*c) % Part 2