Day 17: Add C solution
This commit is contained in:
parent
9272608cc9
commit
24d7d1b2bd
2 changed files with 23 additions and 0 deletions
1
17/input.txt
Normal file
1
17/input.txt
Normal file
|
@ -0,0 +1 @@
|
||||||
|
target area: x=153..199, y=-114..-75
|
22
17/solution.c
Normal file
22
17/solution.c
Normal file
|
@ -0,0 +1,22 @@
|
||||||
|
#include <math.h>
|
||||||
|
#include <stdint.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
|
||||||
|
int main(
|
||||||
|
){int C=0,a ,b,c,d,X,Y;scanf("%*[^=]=%i..%i, "
|
||||||
|
"y=%i..%i",&a,&b ,&c,&d);for(X=sqrt(a*2);X<=b;X++){
|
||||||
|
#pragma omp parallel for schedule (static\
|
||||||
|
,256) reduction (+:C)
|
||||||
|
for(Y= c;Y<-c
|
||||||
|
;Y++){ int x=0
|
||||||
|
,y=0,v =X,V=Y
|
||||||
|
;while (x<b
|
||||||
|
&&y>c &&(x<a
|
||||||
|
||y>d) ){x+=v
|
||||||
|
;y+=V; v=v>0?
|
||||||
|
v-1:0; V--;}C
|
||||||
|
+=(x>= a&&x<=b
|
||||||
|
&&y>=c&&y <=d);}}
|
||||||
|
printf("Silver: %lld\nGo" "ld: %d"
|
||||||
|
"\n",(llabs(c)-1)*llabs(c) /2,C);}
|
Loading…
Reference in a new issue