aoc-2020/jour5/main.c

48 lines
1,001 B
C
Raw Normal View History

2020-12-13 15:10:11 +00:00
#include <stdio.h>
#include <string.h>
void premPartie(FILE *ptr)
{
int bornSupR, bornInfR, bornSupC, bornInfC, column, row, newId;
int idMax = 0;
char str[10];
fscanf(ptr, "%s", str);
while (!feof(ptr))
{
bornSupR = 127, bornSupC = 7;
bornInfR = 0; bornInfC = 0;
2020-12-15 17:41:27 +00:00
for (int i = 0; i < (int) strlen(str); i++)
2020-12-13 15:10:11 +00:00
{
switch(str[i])
{
case 'F': bornSupR = (bornSupR + bornInfR)/2; break;
case 'B': bornInfR = (bornSupR + bornInfR + 1)/2; break;
case 'R': bornInfC = (bornSupC + bornInfC + 1)/2; break;
case 'L': bornSupC = (bornSupC + bornInfC)/2; break;
default: break;
}
if (i == 6)
row = str[i] == 'F' ? bornInfR : bornSupR;
else if (i == 9)
column = str[i] == 'L' ? bornInfC : bornSupC;
}
newId = row * 8 + column;
if (newId > idMax)
idMax = newId;
fscanf(ptr, "%s", str);
}
printf("Lid max est %d.\n", idMax);
}
void deuxPartie(FILE *ptr)
{
int i;
}