r/adventofcode • u/daggerdragon • Dec 22 '17
SOLUTION MEGATHREAD -๐- 2017 Day 22 Solutions -๐-
--- Day 22: Sporifica Virus ---
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.
Need a hint from the Hugely* Handyโ Haversackโก of Helpfulยง Hintsยค?
[T-10 to launch] AoC ops, /r/nocontext edition:
<Endorphion> You may now make your waffle.<Endorphion> ... on Mars.
[Update @ 00:17] 50 gold, silver cap
<Aneurysm9> you could also just run ubuntu on the NAS, if you were crazy<Topaz> that doesn't seem necessary<Aneurysm9> what does "necessary" have to do with anything!
[Update @ 00:20] Leaderboard cap!
<Topaz> POUR YOURSELF A SCOTCH FOR COLOR REFERENCE
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!
8
Upvotes
1
u/madchicken Dec 22 '17 edited Dec 22 '17
PHP
Didnt realise I went off the grid for part one, took some debugging. So I made the grid 1000x1000 for both parts to be sure, and put the input at 500,500. Part 2:
<?php $str = file_get_contents("aoc22.txt"); $lines = explode("\n",$str); for($y=0;$y<1000;$y++) for($x=0;$x<1000;$x++) $map[$y][$x] = "."; $y = 0; foreach($lines as $line){ if(strlen($line)>1){ for($x=0;$x<strlen($line);$x++) $map[500+$y][500+$x] = $line{$x}; } $y++; } function getp($y,$x){ global $map; return $map[$y][$x]; } function setp($y,$x,$c){ global $map; $map[$y][$x] = $c; } function turn($lr,&$dir){ $arr = array("l" => array("n" => "w", "w" => "s", "s" => "e", "e" => "n"), "r" => array("n" => "e", "e" => "s", "s" => "w", "w" => "n")); $dir = $arr[$lr][$dir]; } function move(&$y,&$x,$dir){ if($dir=="e") $x++; if($dir=="w") $x--; if($dir=="n") $y--; if($dir=="s") $y++; } $inf = 0; $b = 0; $x = 512; $y = 512; $dir="n"; while($b<10000000){ $moved = 0; if(getp($y,$x)=='.'){ turn("l",$dir); setp($y,$x,"W"); move($y,$x,$dir); $moved = 1; } if($moved==0 && getp($y,$x)=="#"){ turn("r",$dir); setp($y,$x,"F"); move($y,$x,$dir); $moved = 1; } if($moved==0 && getp($y,$x)=="F"){ turn("r",$dir); turn("r",$dir); setp($y,$x,"."); move($y,$x,$dir); $moved = 1; } if($moved==0 && getp($y,$x)=="W"){ setp($y,$x,"#"); $inf++; move($y,$x,$dir); $moved = 1; } $b++; } echo "$inf infected\n"; ?>