master
Avril 4 years ago
commit 444efd5878
Signed by: flanchan
GPG Key ID: 284488987C31F630

3
.gitignore vendored

@ -0,0 +1,3 @@
input*
part1*
part2*

@ -0,0 +1,10 @@
DAYS= day1
.PHONY: all
day%/part2: day%
cd $< && $(MAKE)
all: $(addsuffix /part2,$(DAYS))

@ -0,0 +1,43 @@
OPT_FLAGS?= -march=native -fgraphite -fopenmp -floop-parallelize-all -ftree-parallelize-loops=4 \
-floop-interchange -ftree-loop-distribution -floop-strip-mine -floop-block \
-fno-stack-check -fno-strict-aliasing
.PHONY: all
all: part1 part2
.PHONY: big
big: part1-big part2-big
input.h: input
@rm -f $@
while read line; do \
echo "$$line," >> $@; \
done < $<
input-big.h: input-big
@rm -f $@
while read line; do \
echo "$${line}ul," >> $@; \
done < $<
part1: input.h
gcc day1.c -O3 -flto $(OPT_FLAGS) -o $@ -O3 -flto
strip $@
part2: input.h
gcc day1.c -DPART2 -O3 -flto $(OPT_FLAGS) -o $@ -O3 -flto
strip $@
part1-big: input-big.h
gcc day1.c -DBIG -O3 -flto $(OPT_FLAGS) -o $@ -O3 -flto
strip $@
part2-big: input-big.h
gcc day1.c -DBIG -DPART2 -O3 -flto $(OPT_FLAGS) -o $@ -O3 -flto
strip $@
clean:
rm -f part{1,2}
rm -f input.h

@ -0,0 +1,40 @@
#include <stddef.h>
#include <stdio.h>
typedef unsigned long u64;
#ifdef BIG
#define TARGET 99920044
#else
#define TARGET 2020
#endif
const u64 input[] = {
#ifdef BIG
#include "input-big.h"
#else
#include "input.h"
#endif
};
const size_t input_sz = sizeof(input)/sizeof(u64);
int main()
{
for(register u64 i=0;i<input_sz;i++)
for(register u64 j=i;j<input_sz;j++)
#ifdef PART2
for(register u64 k=j;k<input_sz;k++)
if(input[i] + input[j] + input[k] == TARGET)
{
printf("%lu\n", input[i] * input[j] * input[k]);
return 0;
}
#else
if (input[i] + input[j] == TARGET)
{
printf("%lu\n", input[i] * input[j]);
return 0;
}
#endif
return 1;
}
Loading…
Cancel
Save