Join us on Discord!
You can help CodeWalrus stay online by donating here.

Advent of Code

Started by Ivoah, December 03, 2015, 03:03:24 AM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

Adriweb

#15
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;
}
[close]
  • Calculators owned: TI-Nspire CX CAS, TI-Nspire CX, TI-Nspire CAS (x3), TI-Nspire (x2), TI-Nspire CM-C CAS, TI-Nspire CAS+, TI-80, TI-82 Stats.fr, TI-82 Plus, TI-83 Plus, TI-83 Plus.fr USB, TI-84+, TI-84+ Pocket SE, TI-84+ C Silver Edition, TI-84 Plus CE, TI-89 Titanium, TI-86, TI-Voyage 200, TI-Collège Plus, TI-Collège Plus Solaire, 3 HP, some Casios
Co-founder & co-administrator of TI-Planet and Inspired-Lua

Yuki

Damn you, I only ranked 43th.
  • Calculators owned: TI-83+ (dead?), Casio Prizm (also dead???)
  • Consoles, mobile devices and vintage computers owned: A lot
Read Zarmina!
YUKI-CHAAAANNNN
In the beginning there was walrii. In the end there will be walrii. All hail our supreme leader :walrii: --Snektron

if you wanna throw money at me and/or CodeWalrus monthly it's here

Dream of Omnimaga

What would be considered a good rank at this point?
  • Calculators owned: TI-82 Advanced Edition Python TI-84+ TI-84+CSE TI-84+CE TI-84+CEP TI-86 TI-89T cfx-9940GT fx-7400G+ fx 1.0+ fx-9750G+ fx-9860G fx-CG10 HP 49g+ HP 39g+ HP 39gs (bricked) HP 39gII HP Prime G1 HP Prime G2 Sharp EL-9600C
  • Consoles, mobile devices and vintage computers owned: Huawei P30 Lite, Moto G 5G, Nintendo 64 (broken), Playstation, Wii U

Adriweb

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)
  • Calculators owned: TI-Nspire CX CAS, TI-Nspire CX, TI-Nspire CAS (x3), TI-Nspire (x2), TI-Nspire CM-C CAS, TI-Nspire CAS+, TI-80, TI-82 Stats.fr, TI-82 Plus, TI-83 Plus, TI-83 Plus.fr USB, TI-84+, TI-84+ Pocket SE, TI-84+ C Silver Edition, TI-84 Plus CE, TI-89 Titanium, TI-86, TI-Voyage 200, TI-Collège Plus, TI-Collège Plus Solaire, 3 HP, some Casios
Co-founder & co-administrator of TI-Planet and Inspired-Lua

Ivoah

bump. I updated the OP with more solutions.
  • Calculators owned: TI-86 (now broken), TI SR-56, TI-Nspire CX CAS, TI-84+ SE, TI-84+ SE, TI-85, TI-73 Explorer VS, ViewScreen, TI-84+ CSE, TI-83+ SE

Dream of Omnimaga

Cool, hopefully they help :)
  • Calculators owned: TI-82 Advanced Edition Python TI-84+ TI-84+CSE TI-84+CE TI-84+CEP TI-86 TI-89T cfx-9940GT fx-7400G+ fx 1.0+ fx-9750G+ fx-9860G fx-CG10 HP 49g+ HP 39g+ HP 39gs (bricked) HP 39gII HP Prime G1 HP Prime G2 Sharp EL-9600C
  • Consoles, mobile devices and vintage computers owned: Huawei P30 Lite, Moto G 5G, Nintendo 64 (broken), Playstation, Wii U

Yuki

There's a new private leaderboard feature, use code 18310-5850abfa to join mine ^_^

http://adventofcode.com/leaderboard/private/view/18310
  • Calculators owned: TI-83+ (dead?), Casio Prizm (also dead???)
  • Consoles, mobile devices and vintage computers owned: A lot
Read Zarmina!
YUKI-CHAAAANNNN
In the beginning there was walrii. In the end there will be walrii. All hail our supreme leader :walrii: --Snektron

if you wanna throw money at me and/or CodeWalrus monthly it's here

Yuki

Welp, it took 4 hours to fill the leaderboard up today... and I'm 42th o.o
  • Calculators owned: TI-83+ (dead?), Casio Prizm (also dead???)
  • Consoles, mobile devices and vintage computers owned: A lot
Read Zarmina!
YUKI-CHAAAANNNN
In the beginning there was walrii. In the end there will be walrii. All hail our supreme leader :walrii: --Snektron

if you wanna throw money at me and/or CodeWalrus monthly it's here

alexgt

Nice! Better than what I could do :P
  • Calculators owned: Ti-84+, Ti-Nspire, Hp Prime, Broken HP Prime, HP 48SX

Unicorn

Maybe I'll just try to do #24 :P
  • Calculators owned: I own all of them: PICKACHUP TI 84+ CSE TI 83+ SE TI something something ??? ??? ??? ??? ???
  • Consoles, mobile devices and vintage computers owned: PICKACHUP ??? ??? ??? ??? ???



??? ??? ??? ??? ???

alexgt

  • Calculators owned: Ti-84+, Ti-Nspire, Hp Prime, Broken HP Prime, HP 48SX

Dream of Omnimaga

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.
  • Calculators owned: TI-82 Advanced Edition Python TI-84+ TI-84+CSE TI-84+CE TI-84+CEP TI-86 TI-89T cfx-9940GT fx-7400G+ fx 1.0+ fx-9750G+ fx-9860G fx-CG10 HP 49g+ HP 39g+ HP 39gs (bricked) HP 39gII HP Prime G1 HP Prime G2 Sharp EL-9600C
  • Consoles, mobile devices and vintage computers owned: Huawei P30 Lite, Moto G 5G, Nintendo 64 (broken), Playstation, Wii U

Yuki

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.
  • Calculators owned: TI-83+ (dead?), Casio Prizm (also dead???)
  • Consoles, mobile devices and vintage computers owned: A lot
Read Zarmina!
YUKI-CHAAAANNNN
In the beginning there was walrii. In the end there will be walrii. All hail our supreme leader :walrii: --Snektron

if you wanna throw money at me and/or CodeWalrus monthly it's here

alexgt

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 ?
  • Calculators owned: Ti-84+, Ti-Nspire, Hp Prime, Broken HP Prime, HP 48SX

Yuki

97th on the leaderboard and ready for the last one.
  • Calculators owned: TI-83+ (dead?), Casio Prizm (also dead???)
  • Consoles, mobile devices and vintage computers owned: A lot
Read Zarmina!
YUKI-CHAAAANNNN
In the beginning there was walrii. In the end there will be walrii. All hail our supreme leader :walrii: --Snektron

if you wanna throw money at me and/or CodeWalrus monthly it's here

Powered by EzPortal