--- /dev/null
+
+#include <stdlib.h>
+#include <fcntl.h>
+#include <unistd.h>
+#include <math.h>
+#include "libft.h"
+
+int special_is_whole(int time, int record)
+{
+ int n;
+
+ n = 1;
+ while (n <= time / 2)
+ {
+ if (record == n * (time - n))
+ return (1);
+ ++n;
+ }
+ return (0);
+}
+
+int ways_of_winning(int time, int record)
+{
+ double special;
+ int correction;
+
+ correction = 0;
+ special = sqrt(time * time / 4. - record);
+ if (isnan(special))
+ return (0);
+ if (special_is_whole(time, record))
+ {
+ if (special < 1)
+ return (0);
+ correction = 2;
+ }
+ if (time % 2 == 0)
+ return (2 * floor(special) + 1 - correction);
+ if (fmod(special, 1.) < 0.5)
+ return (2 * floor(special) - correction);
+ return (2 * floor(special) + 2 - correction);
+}
+
+int main(int argc, char **argv)
+{
+ int fd;
+ int result;
+ char *times;
+ char *records;
+ size_t t;
+ size_t r;
+
+ fd = open(argv[1], O_RDONLY);
+ times = get_next_line(fd);
+ records = get_next_line(fd);
+ t = 0;
+ r = 0;
+ result = 1;
+ while (times[t] != '\n' && records[r] != '\n')
+ {
+ while (!ft_isdigit(times[t]))
+ ++t;
+ while (!ft_isdigit(records[r]))
+ ++r;
+ result *= ways_of_winning(ft_atoi(times + t), ft_atoi(records + r));
+ while (ft_isdigit(times[t]))
+ ++t;
+ while (ft_isdigit(records[r]))
+ ++r;
+ }
+ ft_printf("The resulting product is %i.\n", result);
+ get_next_line(fd);
+ close(fd);
+ free(times);
+ free(records);
+ return (0);
+}