CodeWalrus

Development => PC, Mac & Vintage Computers => Topic started by: Ivoah on December 03, 2015, 03:03:24 am

Title: Advent of Code
Post by: Ivoah on December 03, 2015, 03:03:24 am
flyingfisch posted this link in #omnimaga and I thought y'all might like it: http://adventofcode.com/

I'm going to try to do all of them on the right days, but I dunno if I'll have the time. Post your solutions to the problems in the thread. I'll update this post as I solve the puzzles

Instead of updating this post whenever I finish a new puzzle, I've put them all in a github repo: https://github.com/Ivoah/AdventofCode
Title: Re: Advent of Code
Post by: Juju on December 03, 2015, 03:17:53 am
Oh, nice, I'm gonna try that.
Title: Re: Advent of Code
Post by: DJ Omnimaga on December 03, 2015, 05:27:04 pm
Not sure if I will participate, since I have no clue what it involves (although I assume you must write code for daily problems that are posted there?), but this is what I get when logging in from Twitter:

Internal Server Error

The server encountered an internal error or misconfiguration and was unable to complete your request.

Please contact the server administrator, [email protected] and inform them of the time the error occurred, and anything you might have done that may have caused the error.

More information about this error may be available in the server error log.
Title: Re: Advent of Code
Post by: Ivoah on December 03, 2015, 05:32:07 pm
Quote from: DJ Omnimaga on December 03, 2015, 05:27:04 pm
Not sure if I will participate, since I have no clue what it involves (although I assume you must write code for daily problems that are posted there?), but this is what I get when logging in from Twitter:

Internal Server Error

The server encountered an internal error or misconfiguration and was unable to complete your request.

Please contact the server administrator, [email protected] and inform them of the time the error occurred, and anything you might have done that may have caused the error.

More information about this error may be available in the server error log.



It's like an advent calendar, but instead of little gifts, it has little programming puzzles to solve. Also, I don't know why it's not working for you :( It works just fine for me.
Title: Re: Advent of Code
Post by: DJ Omnimaga on December 03, 2015, 05:45:13 pm
Ah I see, thanks for explaining. There was literally no explanation on the pages I could access.
Title: Re: Advent of Code
Post by: Juju on December 03, 2015, 05:46:03 pm
Works fine for me as well. The 2nd part of Day 3 was kinda hard for some reason.
Title: Re: Advent of Code
Post by: Ivoah on December 03, 2015, 05:47:17 pm
Quote from: Juju on December 03, 2015, 05:46:03 pm
Works fine for me as well. The 2nd part of Day 3 was kinda hard for some reason.


I only had to add 4 lines and change 1, so it was pretty easy for me :)
Title: Re: Advent of Code
Post by: Juju on December 04, 2015, 05:24:55 am
Woo, I managed to get on the leaderboard for today :3 I lost some time due to a wrong answer and some stupid stuff I was doing in my code, but still.

(https://codewalr.us/proxy.php?request=http%3A%2F%2Fimg.codewalr.us%2FCapture%2520d%25E2%2580%2599e%25CC%2581cran%25202015-12-04%2520a%25CC%2580%252000.22.26.png&hash=d09758a4c33fee242e1aed59d647dfda)
Title: Re: Advent of Code
Post by: DJ Omnimaga on December 04, 2015, 05:25:25 am
Oh nice Juju. I hope you can get higher :D. Good luck everyone :)
Title: Re: Advent of Code
Post by: Juju on December 04, 2015, 05:29:48 am
Heh, I'll try tomorrow xD

In short you have to be online at exactly midnight EST and be in the 100 first people who finished every puzzle before to finish today's puzzle. As in, currently, before 0:15. That's some serious speedcoding here xD
Title: Re: Advent of Code
Post by: Adriweb on December 04, 2015, 09:14:22 am
I should probably get interested in completing the challenges as soon as they appear, since I just made the 4th one in, like, a minute, in PHP.
Spoiler: ShowHide
$i = 0;
while (strpos(md5('ckczppom' . ++$i), '00000') !== 0);
echo $i;


Sounds fun :)
Title: Re: Advent of Code
Post by: Ivoah on December 04, 2015, 01:08:42 pm
I finished Day 4 in bed on my iPad :D
Title: Re: Advent of Code
Post by: DJ Omnimaga on December 04, 2015, 07:30:49 pm
You coded while asleep? O.O
Title: Re: Advent of Code
Post by: Ivoah on December 05, 2015, 03:42:13 am
Quote from: DJ Omnimaga on December 04, 2015, 07:30:49 pm
You coded while asleep? O.O


I'm just that good ;)
Title: Re: Advent of Code
Post by: Adriweb on December 05, 2015, 05:36:34 am
Made it on the leaderboard today (54th), but next time I'll make sure to correctly read all the rules, because I lost around 2 minutes because of a stupid mistake :P

Spoiler: ShowHide
    $total = 0;
    foreach(file('day_5.txt') as $line)
    {
        if ( (1 === preg_match('/(.*[aeiou].*){3}/', $line))
          && (1 === preg_match('/(.)\\1/', $line))
          && (1 !== preg_match('/(ab|cd|pq|xy)/',$line)) )
        {
            $total++;
        }
    }
    echo $total . "\n";

    $total = 0;
    foreach(file('day_5.txt') as $line)
    {
        if ( (1 === preg_match("/(..).*\\1/", $line))
          && (1 === preg_match("/(.).\\1/", $line)) )
        {
            $total++;
        }
    }
    echo $total . "\n";


Also, I like the top 1's solution (https://github.com/edanaher/advent-solutions/commit/23cf2588e18b354c87d643f362ac67e7bd493979?diff=unified) I should have thought of using grep piping directly, it really was the right tool for the job!
Title: Re: Advent of Code
Post by: Adriweb on December 06, 2015, 05:17:48 am
Yay 27th today. Learned my lesson to properly read the rules fully, got both parts right on first try.
I wished I remembered how to properly init big PHP arrays with values though ; I had to Google that >.>

Behold the unoptimized code...
Spoiler: ShowHide
ini_set('memory_limit','1G');

function day_6_1()
{
    $total = 0;
    $map = array();
    $b = array();
    $b = array_pad($b,1000,0);
    $map = array_pad($map,1000,$b);

    foreach(file('day_6.txt') as $line)
    {
        $line = trim($line);
        preg_match('/(turn on|turn off|toggle) (\d+),(\d+) through (\d+),(\d+)/', $line, $matches);
        $row1 = (int)$matches[2];
        $col1 = (int)$matches[3];
        $row2 = (int)$matches[4];
        $col2 = (int)$matches[5];
        switch ($matches[1])
        {
            case 'toggle':
                for($tmpr = $row1; $tmpr <= $row2; $tmpr++)
                {
                    for($tmpc = $col1; $tmpc <= $col2; $tmpc++)
                    {
                        if ($map[$tmpr][$tmpc] === true)
                        {
                            $map[$tmpr][$tmpc] = false;
                        } else {
                            $map[$tmpr][$tmpc] = true;
                        }
                    }
                }
                break;


            case 'turn on':
                for($tmpr = $row1; $tmpr <= $row2; $tmpr++)
                {
                    for($tmpc = $col1; $tmpc <= $col2; $tmpc++)
                    {
                        $map[$tmpr][$tmpc] = true;
                    }
                }
                break;

            case 'turn off':
                for($tmpr = $row1; $tmpr <= $row2; $tmpr++)
                {
                    for($tmpc = $col1; $tmpc <= $col2; $tmpc++)
                    {
                        $map[$tmpr][$tmpc] = false;
                    }
                }
                break;

            default:
                echo "asd";
                break;
        }

    }
    for ($j=0; $j<=999; $j++)
    {
        for ($i=0; $i<=999; $i++)
        {
            if ($map[$j][$i] === true)
                $total++;
        }
    }
    return $total;
}


function day_6_2()
{
    $total = 0;
    $map = array();
    $b = array();
    $b = array_pad($b,1000,0);
    $map = array_pad($map,1000,$b);

    foreach(file('day_6.txt') as $line)
    {
        $line = trim($line);
        preg_match('/(turn on|turn off|toggle) (\d+),(\d+) through (\d+),(\d+)/', $line, $matches);
        $row1 = (int)$matches[2];
        $col1 = (int)$matches[3];
        $row2 = (int)$matches[4];
        $col2 = (int)$matches[5];
        switch ($matches[1])
        {
            case 'toggle':
                for($tmpr = $row1; $tmpr <= $row2; $tmpr++)
                {
                    for($tmpc = $col1; $tmpc <= $col2; $tmpc++)
                    {
                            $map[$tmpr][$tmpc] += 2;
                    }
                }
                break;


            case 'turn on':
                for($tmpr = $row1; $tmpr <= $row2; $tmpr++)
                {
                    for($tmpc = $col1; $tmpc <= $col2; $tmpc++)
                    {
                        $map[$tmpr][$tmpc] += 1;
                    }
                }
                break;

            case 'turn off':
                for($tmpr = $row1; $tmpr <= $row2; $tmpr++)
                {
                    for($tmpc = $col1; $tmpc <= $col2; $tmpc++)
                    {
                        if ($map[$tmpr][$tmpc] > 0)
                            $map[$tmpr][$tmpc] -= 1;
                    }
                }
                break;

            default:
                echo "asd";
                break;
        }

    }
    for ($j=0; $j<=999; $j++)
    {
        for ($i=0; $i<=999; $i++)
        {
                $total += $map[$j][$i];
        }
    }
    return $total;
}
Title: Re: Advent of Code
Post by: Juju on December 06, 2015, 05:29:13 am
Damn you, I only ranked 43th.
Title: Re: Advent of Code
Post by: DJ Omnimaga on December 08, 2015, 09:23:07 pm
What would be considered a good rank at this point?
Title: Re: Advent of Code
Post by: Adriweb on December 08, 2015, 10:38:21 pm
I guess making it in the leaderboard is somewhat some proof of being proficient enough in some language and algorithmic skills, but within the leaderboard itself, it depends, and the time indicator can let you see how well you performed compared to others (which the rank only may not, if times are very close)
Title: Re: Advent of Code
Post by: Ivoah on December 09, 2015, 02:01:50 pm
bump. I updated the OP with more solutions.
Title: Re: Advent of Code
Post by: DJ Omnimaga on December 13, 2015, 03:08:45 am
Cool, hopefully they help :)
Title: Re: Advent of Code
Post by: Juju on December 13, 2015, 05:32:44 am
There's a new private leaderboard feature, use code 18310-5850abfa to join mine ^_^

http://adventofcode.com/leaderboard/private/view/18310
Title: Re: Advent of Code
Post by: Juju on December 20, 2015, 02:04:15 am
Welp, it took 4 hours to fill the leaderboard up today... and I'm 42th o.o
Title: Re: Advent of Code
Post by: alexgt on December 20, 2015, 04:04:52 am
Nice! Better than what I could do :P
Title: Re: Advent of Code
Post by: Unicorn on December 20, 2015, 05:09:48 am
Maybe I'll just try to do #24 :P
Title: Re: Advent of Code
Post by: alexgt on December 20, 2015, 06:51:48 am
Quote from: Unicorn on December 20, 2015, 05:09:48 am
Maybe I'll just try to do #24 :P

Good luck :P
Title: Re: Advent of Code
Post by: DJ Omnimaga on December 24, 2015, 07:40:58 am
Have the ones here who participated so far gotten any luck with newer challenges? I didn't get much time to check what they were since I was so busy in the last 8 days.
Title: Re: Advent of Code
Post by: Juju on December 24, 2015, 07:44:49 am
The last few ones are haaaard. Well, let's say it's not for the faint of heart. The easiest ones takes less than 30 minutes to fill the leaderboard up, but in a few cases, like those ones who requires a lot of computation and if you're doing it wrong you'll take days to compute the answer, it may take 3-4 hours.
Title: Re: Advent of Code
Post by: alexgt on December 24, 2015, 10:50:51 pm
O.O that is crazy O.O
For that stuff I would die since I am not that good at that type of coding

Also what place are you @Juju ?
Title: Re: Advent of Code
Post by: Juju on December 25, 2015, 03:48:03 am
97th on the leaderboard and ready for the last one.
Title: Re: Advent of Code
Post by: DJ Omnimaga on December 25, 2015, 03:01:13 pm
Wow that isn"t bad IMHO, considering how many people are participating.
Title: Re: Advent of Code
Post by: Juju on December 03, 2016, 12:38:16 am
Guess who's back

http://adventofcode.com/2016/

welp.
Title: Re: Advent of Code
Post by: Adriweb on December 03, 2016, 01:03:04 pm
Too bad I'm not in the right timezone anymore to be able to compete with other people at right time :/
Title: Re: Advent of Code
Post by: DJ Omnimaga on December 06, 2016, 07:27:54 pm
At first, I thought the Advent of code from last year was still going on but died in popularity last Spring so I was like WTF. But I'M glad it's now a yearly event. :)