solved day 6 a

This commit is contained in:
kirreen 2023-12-08 01:12:14 +01:00
parent ac39960ba3
commit bb849bc054
3 changed files with 32 additions and 0 deletions

30
day6/day6a.c Normal file
View file

@ -0,0 +1,30 @@
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <limits.h>
#include <math.h>
#include <ctype.h>
#define RACES 4
int main()
{
// unsigned long int times[RACES] = {7, 15, 30};
// unsigned long int distances[RACES] = {9, 40, 200};
unsigned long int times[RACES] = {44, 80, 65, 72};
unsigned long int distances[RACES] = {208, 1581, 1050, 1102};
unsigned long int numWins[RACES] = {0};
unsigned long int range = 0;
unsigned long int sum = 1;
for (unsigned long int i = 0; i < RACES; i++) {
for (unsigned long int j = 0; j < times[i]; j++) {
range = j * (times[i] - j);
printf("%d = %d * (%d - %d)\n", range, j, times[i], j);
if (range > distances[i]) numWins[i]++;
}
if (numWins[i] > 0) sum *= numWins[i];
}
printf("sum: %d\n", sum);
}

2
day6/input Normal file
View file

@ -0,0 +1,2 @@
Time: 7 15 30
Distance: 9 40 200

BIN
day6/run Executable file

Binary file not shown.