[ art /
civ /
cult /
cyb /
diy /
drg /
feels /
layer /
lit /
λ /
q /
r /
sci /
sec /
tech /
w /
zzz ]
archive provided by **lainchan.jp**

[ Return /
Go to bottom ]

File: 1480631549461.png (2.37 KB, 226x138, aoc.png)

It's back, it's better than ever, and you can join the fun at http://adventofcode.com/. Are you in?

Feel free to share your answers here (or on the subreddit, like everyone else on the internet).

For the uninitiated, the Advent of Code is an annual programming challenge designed and Eric Wastl, the man behind The Synacor Challenge (among other things). It's fun, and if you suck (like me) and don't know your algorithms, you'll likely learn a lot.

Feel free to share your answers here (or on the subreddit, like everyone else on the internet).

For the uninitiated, the Advent of Code is an annual programming challenge designed and Eric Wastl, the man behind The Synacor Challenge (among other things). It's fun, and if you suck (like me) and don't know your algorithms, you'll likely learn a lot.

File: 1480632010529.png (220.94 KB, 198x200, life-is-sour.png)

>To play, please identify yourself via one of these services:

> [GitHub] [Google] [Twitter] [Reddit]

> [GitHub] [Google] [Twitter] [Reddit]

I'm participating. Doing it in Haskell, as last year. I might also do it in Javascript, as I have an interview next week where they'd prefer me to use that or Ruby (which is basically gibberish to me).

>>20599

Did you attempt a cleverer solution for day 1 part 2 than just keeping a list of points visited? In principle you could do it by just keeping track of the line segment endpoints and checking for intersections, but that seems significantly tricker. I'm "cheating" and just using laziness to avoid the need for a clever approach.

>>20599

Did you attempt a cleverer solution for day 1 part 2 than just keeping a list of points visited? In principle you could do it by just keeping track of the line segment endpoints and checking for intersections, but that seems significantly tricker. I'm "cheating" and just using laziness to avoid the need for a clever approach.

Day 3, Part 1, in AWK:

`{if(($1+$2>$3)&&($1+$3>$2)&&($2+$3>$1)) count++;} END {print count}`

Did mine using Agda. This is a super lazy implementation

`Matrix : Set -> Nat * Nat -> Set`

Matrix X (h , w) = Vec (Vec X w) h

tri : forall {h} -> Matrix Nat (h , 3) -> Nat

tri [] = zero

tri ((f :: s :: t :: x) :: xs) with ((((f +N s) > t) && ((f +N t) > s)) && ((t +N s) > f))

tri ((f :: s :: t :: x) :: xs) | tt = 1 +N tri xs

tri ((f :: s :: t :: x) :: xs) | ff = tri xs

triTest : Nat -> Nat -> Nat -> Nat

triTest f s t with ((((f +N s) > t) && ((f +N t) > s)) && ((t +N s) > f))

triTest f s t | tt = 1

triTest f s t | ff = zero

tri2 : forall {h} -> Matrix Nat (h , 3) -> Nat

tri2 [] = zero

tri2 (x :: []) = zero

tri2 (x :: s :: []) = zero

tri2 ((f :: s :: t :: fff) :: (f2 :: s2 :: t2 :: sss) :: (f3 :: s3 :: t3 :: ttt) :: xs) = triTest f f2 f3 +N triTest s s2 s3 +N triTest t t2 t3 +N tri2 xs

>>20725

Never saw any agda before and it's perfectly readable and understandable to me.

Problem must be on your end.

Did the first five yesterday in Ruby after seeing this thread, other than the second part of the first one (doing it with vector intersections rather than storing every visited point), I was really underwhelmed by the difficulty, but oh well, still fun little puzzles.

Never saw any agda before and it's perfectly readable and understandable to me.

Problem must be on your end.

Did the first five yesterday in Ruby after seeing this thread, other than the second part of the first one (doing it with vector intersections rather than storing every visited point), I was really underwhelmed by the difficulty, but oh well, still fun little puzzles.

I just started and it took a while to do day 1. i did the first part in a weird way and had to rewrite it to be able to do part 2. Have my poop code since i'm still a novice:

`void one() {`

struct node {

int x;

int y;

struct node *next;

};

FILE *file = fopen("input1.txt", "r");

char buffer[8];

char one, two;

int num, direction = 0, i,x,y,length=1;

struct node *head = malloc(sizeof (struct node));

struct node *current = head, *loop;

head->x = 0;

head->y = 0;

while (fscanf(file, "%c%d, ", &one, &num)) {

if (one != 'R' && one != 'L')

break;

direction = one == 'R' ? (direction + 1) % 4 : (direction + 3) % 4;

for (i = 0; i < num; i++) {

current->next = malloc(sizeof (struct node));

length++;

switch (direction){

case 0:

x=0;

y=1;

break;

case 1:

x=1;

y=0;

break;

case 2:

x=0;

y=-1;

break;

case 3:

x=-1;

y=0;

break;

}

current->next->x = current->x + x;

current->next->y = current->y + y;

current = current->next;

}

}

printf("(%d, %d)\n", current->x,current->y);

loop=head;

for(i=0; i<length; i++){

current=head;

for(x=0;x<i;x++){

if(current->x==loop->x && current->y==loop->y){

printf("(%d, %d)\n",current->x, current->y);

return;

}

current = current->next;

}

loop=loop->next;

}

}

>>20921

That's actually *not* awful. it could be better, but, y'know, but terrible.

I'd start by cleaning up the "magic" direction numbers, and maybe even finding a cleaner, way to rotate than casing everything (there might be one: I found one, but my implementation was quite different).

And do *try* to free(2) you data...

That's actually *not* awful. it could be better, but, y'know, but terrible.

I'd start by cleaning up the "magic" direction numbers, and maybe even finding a cleaner, way to rotate than casing everything (there might be one: I found one, but my implementation was quite different).

And do *try* to free(2) you data...

>>20921

You could also use redirection for reading and writing files, so instead of fscanf(file... you could just simply read from stdin.

and execute your program like so:

./yourprogram < input1.txt

http://sc.tamu.edu/help/general/unix/redirection.html

You could also use redirection for reading and writing files, so instead of fscanf(file... you could just simply read from stdin.

and execute your program like so:

./yourprogram < input1.txt

http://sc.tamu.edu/help/general/unix/redirection.html