2
1
Fork 0

Day 17: Add C solution

This commit is contained in:
Mia Herkt 2021-12-17 13:54:18 +01:00
parent 9272608cc9
commit 24d7d1b2bd
Signed by: mia
GPG Key ID: 72E154B8622EC191
2 changed files with 23 additions and 0 deletions

1
17/input.txt Normal file
View File

@ -0,0 +1 @@
target area: x=153..199, y=-114..-75

22
17/solution.c Normal file
View 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);}