A 03.01/main.c => 03.01/main.c +62 -0
@@ 0,0 1,62 @@
+#include <stdio.h>
+#define STR_MAX_SIZE 256
+
+int
+slen(char *s)
+{
+ int n = 0;
+ while(s[n] != '\0' && s[++n])
+ ;
+ return n;
+}
+
+int
+loadtxt(FILE *f)
+{
+ char line[BUFSIZ];
+ char c = 0;
+ int x = 0;
+ int y = 0;
+ int acc = 0;
+ int len = 0;
+
+ if(!f) {
+ printf("No file \n");
+ return acc;
+ }
+
+ while(fgets(line, BUFSIZ, f)) {
+ if(len == 0) {
+ len = slen(line) - 1;
+ }
+ c = line[x];
+ if(c == '#') {
+ acc++;
+ }
+ printf("[%d,%d]=>%c\n", x, y, c);
+ printf("\n");
+ x += 3;
+ x = x % len;
+ y++;
+ }
+
+ fclose(f);
+ return acc;
+}
+
+int
+main(int argc, char *argv[])
+{
+ int c;
+ if(argc < 1) {
+ printf("No input file");
+ return 0;
+ }
+
+ printf("-- Day 03.01 \n\n");
+
+ c = loadtxt(fopen(argv[1], "r"));
+ printf("\n--\nResult: %d\n", c);
+
+ return (0);
+}
A 03.02/main.c => 03.02/main.c +78 -0
@@ 0,0 1,78 @@
+#include <stdio.h>
+#define STR_MAX_SIZE 256
+
+int
+slen(char *s)
+{
+ int n = 0;
+ while(s[n] != '\0' && s[++n])
+ ;
+ return n;
+}
+
+int
+loadtxt(FILE *f, int deltax, int deltay)
+{
+ char line[BUFSIZ];
+ char c = 0;
+ int x = 0;
+ int y = 0;
+ int acc = 0;
+ int len = 0;
+
+ if(!f) {
+ printf("No file \n");
+ return acc;
+ }
+
+ while(fgets(line, BUFSIZ, f)) {
+
+ if(y % deltay != 0) {
+ /* printf("%d-%d-%d\n", y, deltay, y % deltay); */
+ y++;
+ continue;
+ }
+
+ if(len == 0) {
+ len = slen(line) - 1;
+ }
+ c = line[x];
+ if(c == '#') {
+ acc++;
+ }
+ printf("[%d,%d]=>%c\n", x, y, c);
+ x += deltax;
+ x = x % len;
+ y++;
+ }
+
+ fclose(f);
+ return acc;
+}
+
+int
+main(int argc, char *argv[])
+{
+ int c;
+ int acc = 1;
+ int i = 0;
+ int x[] = {1, 3, 5, 7, 1};
+ int y[] = {1, 1, 1, 1, 2};
+
+ if(argc < 1) {
+ printf("No input file");
+ return 0;
+ }
+
+ printf("-- Day 03.01 \n\n");
+
+ for(i = 0; i < 5; ++i) {
+ c = loadtxt(fopen(argv[1], "r"), x[i], y[i]);
+ acc *= c;
+ printf("--\nAcc: %d\n--\n", c);
+ }
+
+ printf("--\nResult: %d\n--\n", acc);
+
+ return (0);
+}
M 05.01/main.c => 05.01/main.c +0 -1
@@ 1,5 1,4 @@
#include <stdio.h>
-#include <string.h>
#define INPUT_SIZE 2160
#define STR_MAX_SIZE 256
A bin/03.01 => bin/03.01 +0 -0
A bin/03.02 => bin/03.02 +0 -0
A input/03-test.txt => input/03-test.txt +11 -0
@@ 0,0 1,11 @@
+..##.......
+#...#...#..
+.#....#..#.
+..#.#...#.#
+.#...##..#.
+..#.##.....
+.#.#.#....#
+.#........#
+#.##...#...
+#...##....#
+.#..#...#.#
A input/03.01.txt => input/03.01.txt +324 -0
@@ 0,0 1,324 @@
+.........###......#...#.......#
+.#.#...........#..#..#.........
+#.......#.................#....
+.........#.#.........#......###
+.....#......##...##............
+...##...#......#.....#.....##..
+#.#..#....#...#....#......#....
+........##.....#.....#.#.......
+......#.....#......#...##.#....
+...####...#.......##.....#.#...
+.........#....#......##........
+..##...........###.#...........
+.....#............#............
+#.#..#..##........#.....#..#...
+.....................#....##..#
+...........##.....###...#.#.#..
+..#......#...........#.........
+.##.##...#...#......##.#.......
+......#..#......#.#.#..#.#.....
+........#.#..#..........#...#.#
+...........##...........#....#.
+...........#...##.#............
+.......#...........#...........
+.......#......#..#...#....#..#.
+..#.....#.#....#.#......#...#.#
+.#..........###..#....#........
+........##..#..#...#..#....#..#
+#..........#...#..#.#........#.
+..#.#........##.##....##.#.....
+#.##....#...#.......#.#..#....#
+......##...#.#.#.#.....#....#..
+..........#..............#.....
+....................###.#......
+#.....#...#...#.#.......#....#.
+.......#..#...................#
+........##.##........#......#..
+...#...##.#...#...........#....
+..#.........#...#....##......#.
+......#..............#..#..#.#.
+.....##...#...#...##....#......
+#.#....#...#......##.....#...##
+.#...#.#..................#....
+#.##.....#......#..........#...
+..#..#.......#.................
+..#.....#.........#........#...
+.......#...##.##.#..#..##.#..#.
+#.............#.........#.#....
+..#..##..........#..#..##.#.#..
+.#......#.......#...#.....##.#.
+.....#......#...#...........###
+..........#.........#.....#....
+.....#..........#.......##...#.
+......#..#..#..............#...
+.#.####..#...##...#.#..........
+..#....#.......#........#.....#
+....#.##.....#..#.....#.#.#..#.
+.......#..#..##.......#........
+.#.....#...........#.....#.....
+........#..........##..##.#....
+.#.....#........#.....#..#.....
+..#..........#...#......##..#..
+.#............#.........#....#.
+........#..###.......#.....###.
+##.#...#.#..#..#..#.#.##...#...
+.#....#...#..#......##.........
+.............##.....##.........
+.....##.#..###.#....#...#...#.#
+#........#...#......#...#.##...
+#....#......#.....###.##.#.....
+.....#..#.#.##....#..##.....##.
+....#...#...#..........##......
+..........#......#...#.....##..
+.....##....##.#.............#.#
+#.........#.##.............#..#
+.....#.........##.#...#.#.#....
+..........#..#......#..#.....#.
+....#....#....#....#.......###.
+....#...#..##....#..##..#...##.
+.###......#...........###......
+#..................####.#....#.
+#....#.#.....#.#....#..#.......
+...#......#....##......#..#..#.
+#.#...#.##.....#.#.......##..#.
+.........##.................#..
+#..##.#....#.#.............#...
+....................####.#.#..#
+.......#..#...#..#..#.....#...#
+.....#.#.#........#....#...##..
+......#..#....#......#..##.....
+............#......##.#....#..#
+...#..........#..#...........#.
+..........#.............###....
+....##.#.#......#.#..#....##..#
+..#..........#........#......#.
+..#...........####......##..#.#
+...##......##...#..#.##........
+.....#...#.....##.....###..##..
+.#.##.....#....##....#.........
+#....##..#.....#.#......#.#....
+..#.......#...#....#...#.#.....
+...........#.........#.........
+..#..#....##..#....#....#.....#
+.......#..#....##....#.........
+#.........#...........##....##.
+#........#.#...............##..
+#...##.#...............#.......
+#....#..#......#..#.###...##..#
+..#.........#.#......#.....#..#
+......#...........##........##.
+.#.........#................#..
+#...#...............#...#....#.
+.#.#......##.........#.#.......
+..........#....................
+.#.....#..#...#.#.#.......#...#
+..#..........#.................
+.#.#.....#.#......#...#.....##.
+.....#.#..##...##..#..###...#..
+......#......#.#......#.##.....
+#.#......#...#.......#....#....
+..........#....#.#..#.....##...
+#...........#.#....#.##....#.#.
+#.#....#..#.........###....#...
+..............#..##.......#....
+.......................#.##.#..
+##...............##....#..#.#..
+.#.#..#.##...#.............#...
+...#...........#............#..
+..#......#........##....#.#.##.
+.#.#..#........#....#....#....#
+.#.....#.##....#.....#..#...#..
+......#...#..........#..###....
+..#.#.......#........#........#
+.......##.####..........#......
+.#.#..#......##..#.........#..#
+..#...##.#.......#...#.##...#.#
+#.#..........#..#.#.#..........
+.....#......#............#.....
+........###...#.......#........
+.....#.##....#....#............
+...#.#....##.....#.....#.......
+..#.............#......#.......
+.#....#...#....##..#......#....
+..#.....#.#............#.......
+......#........##.........#...#
+.......#........#..#.#.#...##.#
+#....#...#..#.......#....##....
+#...##.#.#.....#.......#.......
+.....#........#.#.....#...##...
+..#....#..##......#.#.....#...#
+....#.....#......#.....#.......
+#.#....#......#...##...........
+..#.......#...#...............#
+........#........#.............
+#.#.#......#...#..#..........#.
+.##...#.........#........#..#..
+#.#.#...#.#.......#.....#...#..
+...#..............#..........#.
+#.#...#.###.............#......
+................#.....###.##.#.
+.......#..........#....#..#....
+......##....#..#..##...........
+...#...#.....######.......#....
+..##.....##.#...#.........#.#.#
+.......#...#..#.#.#...........#
+........###.............#...#.#
+#.....#.........#.............#
+..#...#.....#..................
+.....#....#.....#......#.#....#
+...#....#........##...#.......#
+...##.#...#.....#..............
+..#.##....##..#.........#......
+.....#..#.#....#...#......#.#..
+...........##..##...#..#..###..
+#...........#.........####....#
+.#...........#...........###...
+........#................#.....
+.....#....#............#....#.#
+...#...#.......#...............
+#.....##.#.......#.#...........
+#.......#.#.#.#..#...#.........
+....####.#...#.#......#.....##.
+...##...#.....#.#......#..#....
+..........#..#....#......###...
+...................#....##...#.
+....#......#........#...##..#..
+##...#.........#.#......#......
+#........#...#....#......#.....
+#..#.......#...............##..
+......##......#...........##.#.
+......#..#....#....#.##........
+..#....#..#.#.###....#.........
+.#......#..#..............#....
+.#..........#...#..#.#...#.....
+....#......#..#......#....#....
+...##.....#............####..#.
+......#.#...#....#..#...#..#.#.
+......##.......................
+#.##........#...........####..#
+.....#......#.......#.#....#...
+#.......#....#.....#....#...##.
+.....#..##.#...........#..#...#
+...........#.##.#.#...#.#..#...
+..#.......#.#....#..#..........
+...#.......##..#.............#.
+....#..#....#....#...#....#....
+#......#.#...##..........#..#..
+..#.#.......#.........#......#.
+#...............#.............#
+....##..#......................
+.##....#............#......#...
+.......#....#..##......##......
+#..##.....#..#..........#......
+...#.........#.......#..##.....
+....#.##.....#.#...#...#.....#.
+##...........#.#..#...#.#......
+....#.............##...#.#..#..
+...#....#......................
+#..#...##.#.......#.##..#.###..
+...##.#.#...##........##...#...
+......##..#..#.....#..#.#..#...
+#.......##...............##.#..
+.##......#..#....#...##..#..#.#
+##.........##..#...#.....##....
+...#..........#...#..##.#......
+..##.#........#...#..........##
+.......................##.#....
+....#...#...#..###.#.......#.##
+....#....#.#..........#.##.....
+..#..........##...#....#.......
+.....#.....#.....#..#.........#
+..##..##..#..#....#..#.......##
+.............#............##...
+....#.#.#.......###.........#..
+...##.#..........#.#...#.#.....
+.#........#..#.#.#..#..........
+...##...#.....##.......#..#..#.
+...#......#..#.......##.#.#....
+.........#.........##........#.
+.........##..................##
+....##.....#................#..
+....#..................##...#.#
+.........#..............#......
+...#......#..#..#....#..#...##.
+.#.##......##...#.#......#.#...
+...#.#...###....#...#.#..#....#
+....#..#.......#.....#..##.#.#.
+#.#.#..#.......#####.#..##..#..
+#..........#.....#..#.#..#.....
+.#......#...#..#.#..#..#.......
+...#....##...#..........#.##.#.
+#.##..#...#..................#.
+......#.###..#..#..#.......#...
+...#....#...#..#............###
+#.........#........#.......#...
+...#..#.................#....##
+...#.#.............##......#...
+##....#.##.............##......
+#............#..#..#.....#.....
+....#........#...#.....#.#...##
+..#.##..#.....................#
+#.#........#...#..#...#.#......
+...#..#...........##.....#.....
+......#.#....#..##...#.....#...
+......#......#.###..##.........
+....#.......#...##.##.....#....
+#.....##....#........#..##.....
+.#..#..#..#..#.#...#...#.......
+.......##...#......#.........#.
+.#..##....#.....#...........##.
+.......##....#.#........#......
+..#.#.#....#...................
+.#...#.......#...#.#......#....
+..##.##..##...........###......
+#...#......#.......#...........
+#....##.#.......#.........#....
+.............##.#.#..#...#...#.
+..##.##...........#.........##.
+#.#...#..........#.#....#....##
+.....#.....#..##..#............
+#.........#.........#.#...##..#
+...#.#.....#.........###..#....
+..#.#.##.#...................#.
+......####....#.......#.......#
+.........#..#..#....#..##......
+....#..........#...##........#.
+..........#..#....#.....#....#.
+.#.#.................#....#....
+.......#......#.....#...##.....
+....#..............#...........
+###...........##.#...........#.
+...####.......#...#....#.#...#.
+..##.#................#........
+...#..#....#.....#.....##..#...
+##.#....#....##..........#.#..#
+...#....#.....#................
+..#...#....#..#..#.##.##..#....
+....#....#.##.....#...#......#.
+......#................#..#..#.
+...##..#...#....#.#.....#..#...
+#...#..............#.#.....#.#.
+....#.........#.##...#.#....#..
+..................#..##.#......
+.#.....#.....#.............#..#
+..........####....###..##...#..
+......#........#...#......##..#
+#......#.#..........#....#.#...
+###................#.#....#....
+#..#.##.#.............#..#.....
+.....#............#.....##.....
+....#.....#....#.........#.....
+#..#...........###.#....#......
+..#............##...#........##
+..#....#..#....#.....#.......#.
+..#..#.#.#.##.#..#...#.....#...
+..........#..#.................
+...#.#......#..##........#.....
+...............#...............
+#.......#.......#....#.........
+#...........#....#.............
+....#..#..........#....#..##...
+.........#.#.#.........#......#
+.....#...##.....#.#.......#...#
+.........#....#...#.......#....
+