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: Yuki on December 03, 2015, 03:17:53 AM
Oh, nice, I'm gonna try that.
Title: Re: Advent of Code
Post by: Dream of 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, webmaster@localhost 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, webmaster@localhost 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: Dream of 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: Yuki 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: Yuki 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.

(http://img.codewalr.us/Capture%20d%E2%80%99e%CC%81cran%202015-12-04%20a%CC%80%2000.22.26.png)
Title: Re: Advent of Code
Post by: Dream of 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: Yuki 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]$i = 0;
while (strpos(md5('ckczppom' . ++$i), '00000') !== 0);
echo $i;
[/spoiler]

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: Dream of 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]    $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";
[/spoiler]

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]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;
}
[/spoiler]
Title: Re: Advent of Code
Post by: Yuki on December 06, 2015, 05:29:13 AM
Damn you, I only ranked 43th.
Title: Re: Advent of Code
Post by: Dream of 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: Dream of Omnimaga on December 13, 2015, 03:08:45 AM
Cool, hopefully they help :)
Title: Re: Advent of Code
Post by: Yuki 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: Yuki 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: Dream of 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: Yuki 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: Yuki 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: Dream of 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: Yuki 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: Dream of 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. :)