Browse Source

Complete day 3

Frans Bergman 4 năm trước cách đây
mục cha
commit
fc43c98d2a
2 tập tin đã thay đổi với 361 bổ sung0 xóa
  1. 38 0
      3.c
  2. 323 0
      3.input

+ 38 - 0
3.c

@@ -0,0 +1,38 @@
+#include "stdio.h"
+
+int tree_count(char[323][31], int, int);
+
+int main() {
+    char lines[323][31];
+
+    int i = 0;
+    while (scanf("%s", lines[i++]) == 1)
+        ;
+
+    long product = 1;
+    product *= tree_count(lines, 3, 1);
+    printf("Answer 1: %ld\n", product);
+
+    product *= tree_count(lines, 1, 1);
+    product *= tree_count(lines, 5, 1);
+    product *= tree_count(lines, 7, 1);
+    product *= tree_count(lines, 1, 2);
+
+    printf("Answer 2: %ld\n", product);
+}
+
+int tree_count(char lines[323][31], int x_inc, int y_inc) {
+
+    int x = 0, y = 0;
+    int trees = 0;
+
+    while (y < 323) {
+        if (lines[y][x] == '#')
+            trees++;
+
+        y += y_inc; x += x_inc;
+        x %= 31;
+    }
+
+    return trees;
+}

+ 323 - 0
3.input

@@ -0,0 +1,323 @@
+....#...#####..##.#..##..#....#
+..##.#.#.........#.#......##...
+#.#.#.##.##...#.......#...#..#.
+..##.............#.#.##.....#..
+##......#.............#....#...
+.....##..#.....##.#.......##..#
+.##.....#........##...##.#....#
+.##......#.#......#.....#..##.#
+##....#..#...#...#...##.#...##.
+##........##.#...##......#.#.#.
+..#.#........#...##.....#.....#
+..#.......####.#....#..#####...
+.##..#..#..##.#.....###.#..#...
+......###..##.....#.#.#..###.#.
+..#.#...#..##.....#....#.#.....
+.....#.#...#.###.#..#..........
+##.....#...#.#....#..#.#.......
+..#...#...#.........##......#..
+......#.#...#...#..#...##.#...#
+....#.................##.##....
+...#......#.............#....##
+##..#..#..........#...##.#.#...
+....#...##....#..#.#...........
+##.#.#.#...#....#........#..#.#
+...###..........#...#...#..##.#
+..##.......###.#......##.##....
+...........#.#....#.....#.#...#
+..#......##.#...##.#.#......#.#
+..........#.#....#.#..#....#...
+##..##...##.......#.#....#.#.##
+.##..#.#..#...........#.#...#.#
+#......##......#....####.#....#
+..###......##...#...#.#.......#
+.#.##.##....##..#..##...#......
+.#....#..#........#..#.##.#.#..
+..#.........#.#.###....###.#...
+..#..#.#.#..#..#.##.##...####..
+#..#..#......#..#.#....#.#.#.##
+..#.........#...#..#.#.#..#...#
+#..#......###.....##....##.....
+#..#.....#.#.#.##.....##...#.#.
+##..#.#...#.........#.#........
+#....#.......#.....#..#..#.#...
+...###.##.###.###.#####..#...#.
+.....#..#.#..##...............#
+..#.....###.###.#.....#.#....##
+###.#.........#..#.#.#..#.#..#.
+.##.........#..#..##....#.#...#
+.#...#........#...#.....#....#.
+####..........###....#.#.#....#
+....##..###....#....#.#...#....
+..............##......##..#.###
+.#...........###.#.#....#......
+###.#..#..#...#.........##.....
+..#.....##...#.#.....##...#.##.
+.###.#........#..#.#...#.#..##.
+.......##....##.........##.#..#
+#....#...#...##...#.#..#..#..##
+...#...##..#...#...#.#....#.#.#
+#.#......#.#...##......#.#...##
+.#.###..#.###.#.....#.##.##.#.#
+#...#............#...#.##..##..
+....#..###.......#.....##....#.
+.#####..#.....#.....#...#.....#
+..##..#..###.......##.#........
+.#...##.##.....#.##...##...#..#
+......###...#....#....#........
+....#...#.#....#...#.#.#......#
+....#..##...##.#..#....###.....
+...#...#..#.#...#....#.#..#####
+####....#.....#.........#.#....
+...###.#.#..#.#..##............
+.##..#####..#...#..#..#.......#
+.###......#.#.#..#....#.....#..
+#....##.##..#.#...............#
+...#.#..#........#......#....#.
+#.....#....###....#..#.#.#.....
+.#..#....#...#.#.....##....#...
+..#.##.#.##.#..#.##.#.....#.#..
+.......#.......###..###..#...#.
+.#.......#..#........#.#.......
+.#.#...#.....#.##..##.....#....
+#.......##....#......#.....##..
+.#.....#...##...#..##.....#....
+....#..#.#.......#.#.#.........
+..#....#....##.##..#..##.##.#..
+.#...#....##...#........#....#.
+#.#......#...#....#...........#
+.#....#..#..###.#.....#..#.....
+..#..................#.....#...
+..#...###..#..####.#..#.#.#.#..
+...#........##...##..##..#....#
+...#.....#........##..#.....#.#
+#....#.....##.##......#...##...
+...#####....#..##..##...#.#....
+###.........#.#..#..#..##.#...#
+##...#..##...#.##.#........#...
+.#....#.#...#..#...#..#.#......
+.#......##.#...#...#..#....#...
+#..#.#.#......##.##.####..#....
+.#...#.#.##...##.#...#...#.....
+####.#.........#...##..##....##
+.....###........###.##...#.#...
+.##.....#.....#....##.....##...
+.#.#...#####....##...##.....#..
+....###..........#......##..#.#
+..#.....#....#..#...#.....##..#
+...##.##.#.######....#.#....##.
+...#.#.#...#..#....##.........#
+.#.#...##...#....#.#....##.....
+...#..#.....#.....#.##.....#...
+.#.#.#.....#.##.#....#.#....##.
+#...#......###...#..###...#....
+...##.#.#..#........##.......#.
+.####.####......#........#.....
+....#..#####....#......####....
+#...##.#..#..#####.#...#......#
+#.#....#..#.........###........
+.##.........#....#......#.#....
+...###.........####.#........##
+..#..#........#.#..##......#..#
+.##..#....#...##.####.#...#....
+......#.......#..#..#.#.##.#...
+.###....#.#...#.#.......##..#.#
+#...#....#............#####....
+...#.##......#####..#........#.
+..#...##.....#...#..#.#........
+...#.#...#...##...#..#....#....
+..#..##.....#....#.#.###.......
+.......##..#...#.............##
+.....#.....#..##.##.....#......
+.....##...#......#..##....#.###
+.#...#.#.#.#.##.....##..###..#.
+....##..........#.....###......
+....#...#.#.#..#.......#....#..
+..###...#...........##..###....
+...#.##.......#....#....#.#....
+##...#..##..#.##..........##..#
+.##.....#..#......##..####.#.##
+....##..#.#.###......#..#...#..
+####..#.#....#...#....###.#.#..
+###......#...##.##..#.##..#..#.
+..#.#..#.#.#.....#...#..#.####.
+.###.#...##...##....##......#.#
+..#............#.##..#....#..#.
+###.......#......###..#........
+....##......###.....#.#..###...
+..#...##...#......#..#.........
+#..####.#....#.....###....#.#..
+.#.#.#.......##....###.........
+.......#.##.#####....#.#...####
+.#...#....#....#.###..#.....#..
+.###.#.#.###.###.#..####.##.#..
+....#.........#.#.......##.....
+#..#..#.#...........#.#.##..#.#
+.#.....#..#...#.....#.##......#
+..###.#............#.....####..
+#.....##..##...#....####....#..
+...#.....#..................#..
+....#.###.#..#..#..##..#..##...
+...##.#........#......#...##...
+#................##....#...#...
+..##......##.#.##..#....#.....#
+.#..#.....#..........##.#.#....
+.....#...####....#..#......#...
+..#......###.#.#.#.#.......#..#
+.##......#.......#....###.#....
+#..#.#.#..#...#.#.##..##..#....
+....#...##..#.#......#.##...#..
+...###...#.##..#...#....#......
+##......#.#...#.#.#.........#..
+..#..........#...###.#.##....#.
+...##.....#.....#...###..#.....
+..####.#.....#.#.....#..#.#....
+.#.....##...##.##.#.....#.####.
+.......#.....#...##..........#.
+.#...#.#....#####....###.#..#.#
+.##.##....##...##.#.....#......
+#......#.##..#..##.#.#.......#.
+.#..#....###..#........##...#..
+..#......##.......###..##...#..
+.#..........#.#.......##.....#.
+....##.....##.#.#.##........##.
+..#.#..###..#..##...#.##...#...
+.......#.....#..#...#...#.....#
+##.#...#.#.#.##........#......#
+..###.....##..#....#.......##..
+#####..####...#.#..##.#...#..#.
+#...####....#........#....#....
+.#.#.#..#...##....#.......#.#..
+...#....##..##..#..#..#####.###
+...#......#.#..#......#...####.
+.##.....##.##.#.####.#..##...#.
+....#..#..##..##....#....#...##
+##.###........#...##....#.....#
+..#.#.#.......#....#..#....#...
+......##.....##....#...#.....#.
+#.#..#.#.......#....#.#.#......
+.....###..#...#.....#..##..#...
+......###.....#.#.#...#...##..#
+.#..#.#....##...#...#........#.
+#..###.#...####.#...#..........
+.#.##.#..#..##..#..###..##...#.
+.......#.#..........#.........#
+#......###..##..#....###.......
+..#............#.#........#...#
+..##.#.............#......#..##
+.#....#..#.#..#....###..#...#..
+....##....#..##...###....#....#
+.#....###.............#........
+#..#...#..#....#.##.#.....##...
+...........#.....#....#....#...
+.##.##.#...#....##......##..##.
+......#.#.##.#..##........#...#
+....##...##...#...#...#.#......
+.#...#....#...#......#.#...#..#
+........##.....#.#..#...##..##.
+##...#.....#.....####...#..#...
+.#.#..##.##......#...#.#...#...
+##...##.#......#....#.######.#.
+##.....####.###......#.##.#....
+.#.##....##........#...#..####.
+.......#..#....##...#.#...#..#.
+...##..........#..#........#..#
+.##.....#...#...#.##.###.......
+.##....#...#.#..#.....#...#....
+..#...#.....#.####.#.........#.
+#...#.##...#.#..#.#..#.###.#..#
+.##..#.#.##.........####....###
+.#..##........#..#.......#.....
+......#.#####.#.........#.#...#
+......#....#.#####...........#.
+..##....##..#.#..#....#......##
+#.#......#.##.#.##....#....#.#.
+..#..##.#...#.......##.........
+.....##.#...#..........#.......
+...#........#..#...#.....##.###
+....##.........#...#.#.....#...
+.......#.#....#...#.......#...#
+.#..#...##....#..#...........#.
+.#....##.##.#..#..####.#.#.....
+.##........#.....#..#......##..
+.#..##......#......#..##..#....
+###.....##.......#..##.#.......
+.....##......#.#...##...##.....
+.##....##..#..#####...#...#.##.
+##...##.#....##.#.#.#....##....
+.#.....#...#......#......##....
+##.#............#...#....#.....
+#..#.....#.....##.##.##..#..##.
+......#..............#..#...#.#
+....#.#....##......#..#...#....
+.#...#..#...#......#..##....#.#
+.....#......#..##...#.#....#...
+#...............#.##..#......#.
+.....#..##.#..#.#...###.....#..
+...#..#..#...#....#..#..##.#...
+.#...#...#..#......##...#......
+....###............#.#.#....#..
+#.#...#..#..#.#....#........#..
+....#.#.#..#..#....#..#...##.#.
+.#....#.#...#....#......#.#...#
+##..#.#.#..#.....#...###....#.#
+.##.....#.#...#..........#..#.#
+#....#......#....#.#.#...#.....
+#.#.....#.###.......#..#..#.#..
+#.....##..#.###...#...##...#.##
+.#.##....#.#.....##......###...
+.#.......##................#...
+.........#........####......#..
+...##.###..#.....#.#.....##.#..
+..#....#.#.#.##..........#.....
+#..##.....#.............##.....
+.##...#..#.......#.......#..#..
+...#.................#......##.
+....#....#.....#..###.#....###.
+..#.#..#...#..#.....###....#.#.
+.....###...#....#....#.#.##..##
+...#...#.........####........#.
+.......#..##.........#.........
+.#......##.....#.#####...##....
+....#.###...#.#....##..#......#
+.##..#....#.#....#..#.###.....#
+..#...#.#...#.##.....#.#....##.
+#.#.#.#.....##...#.#..##..#....
+.#............#.#.#..#...#...#.
+...##.#..#..####.#.###..##.....
+.##.....#.......#..##.#...##.#.
+#.#...#..#.##...##...####..#..#
+...##.......#.#.#.#.#.#...#..##
+...#.#.##..##..............###.
+.....#...#........#...#......#.
+..#..#..##....#..##.#.....#....
+#.....##........#.........##.#.
+###..#....#.##..##.............
+.#..#...#.#......#..#..##.....#
+...#.#.#............##........#
+..#.#....#..#....##....#...##.#
+...##...#...#..........##.#####
+....#..#.#.......##....#.#.###.
+##..#..#..#...###.#.....#......
+....###.#.#.#.##..##.#...#.....
+.....####..#.#..#.#......#.#.#.
+#.....#...#..#.#.........#..#..
+.##....#.#.####......##..#..##.
+......#.##.#.#..#..#....#.#....
+.#..#...#...#...#..#.....#.....
+..##.#..............#......#...
+.....###.##.......#.....#..#...
+..#.#..#..#.......#...##.##..#.
+##.###......#......#.#..#..##..
+..##.....#..#..#......#..#.....
+...##.......#.#..#.........#.#.
+......##.##.#.......#..#.#.....
+#......#........##..#.......#.#
+###....#...#...#.#...#..#..#...
+#..###....#....####..#...#.....
+....##..#.##.#....#..##...#.#..
+#.##..#....##..#...#..#.#.#..#.
+#.........#.....#...#.......#..
+...#.....#.#.....#........##...
+..#.##..#......#...#.....##.#..
+...###....#.....#...#..#.##..#.