1
0
mirror of https://gitlab.com/camelot/kickc.git synced 2025-08-09 20:25:17 +00:00
Files
kickc/src/test/kc/adventofcode/2020-03.c

367 lines
12 KiB
C

// https://adventofcode.com/2020/day/3
#pragma target(atarixl)
#include <stdio.h>
#include <conio.h>
#define MAP_WIDTH 31
#define MAP_HEIGHT 323
extern char *map;
void main () {
clrscr();
// Puzzle part 1
printf("1: encountered %u trees\n",test_slope(3,1));
printf("2a: encountered %u trees\n",test_slope(1,1));
printf("2b: encountered %u trees\n",test_slope(3,1));
printf("2c: encountered %u trees\n",test_slope(5,1));
printf("2d: encountered %u trees\n",test_slope(7,1));
printf("2e: encountered %u trees\n",test_slope(1,2));
for(;;) ;
}
// Count the number of trees on a specific slope
unsigned int test_slope(char x_inc, char y_inc) {
char x=0;
unsigned int trees=0;
char* mapline = map;
for(unsigned int y=0; y<MAP_HEIGHT; y+=y_inc) {
if(mapline[x]=='#')
trees++;
x += x_inc;
if(x>=MAP_WIDTH) x -= MAP_WIDTH;
mapline += y_inc*MAP_WIDTH;
}
return trees;
}
char *map =
".#......##..#.....#....#.#.#..."
".#.#...#.##.#..........#...##.."
".........#.....#.####........#."
".......#.#...#.#..............."
"..#....#...#.#...#.#...#.#....."
"...#...........#..#.........#.#"
"....#..#....#..#..#.#...#..##.."
"#...........#..#.....#.......#."
"#..#...#...#.###...#...#.#...#."
"#...#.#.......#...#...#...##.##"
"..#..................#.#.#....#"
"..#.##....#........##.........."
".....#....#....#.#.......#....."
"##.#..##.#.....###.......#....."
"......#...###....#..#.#...#...."
"..............#.........#.##..."
"#......#.............#....#...#"
".#..#......#.###....#...#.....#"
"..#........#.....#.....#...#..#"
".......#...#..............#..#."
"..#...#........#...##........#."
".#........#....#......#......#."
"....#..#.###.......##....#.#..#"
"..#..###..#...................."
"......#...#....#.........#.#..."
"....#.##................#..#..."
"....#......######.....#........"
".#......##.......#....#..##.###"
"..#...##.###..#.......#....#..."
"....#.###...#.#.#........#....."
"...###...#.......#..........#.#"
"..........#...#..........##.#.."
"..#....#........#.....#....#..#"
"..#...#.#....##..#...##....#..."
"........##...#..##.....#......."
"###.......#.#...#...#.......#.#"
"....#.#....##.###........#....."
".....#..............#....##..##"
"#......#.#....#.#......#.....##"
".....#....#..#......#...#......"
"..#.##..#.....#..#....#......#."
".....#.#.#..........##....#...."
".........#..#..........#.#....."
".##..#...#......#.#..#....#...."
"#.#..##.......#.#......##......"
"..#.#....#.#.....#............."
".#.........#.......#..#.#......"
"##.........#..##.#......#......"
"#..#.....#...#.....#.........#."
"..........#..##..##.#..##...###"
"..##.....#...#..##...##.#.#...."
"..#..........#.#.....##.#....#."
".##..#..#.........###.......#.."
"......##....#...##....##......."
".....#.#.##...............#...."
"#..#......#.....#..#..#.#.....#"
".....##.#....#.#.....#.#.#....."
"....#..#.#..##....#.....#....#."
"#...#.....#....#....#.#.#......"
".....#................#.......#"
".......#..#.#...#.#......#..#.#"
"...........#....#....###...#.#."
"#.##....##..###.#.#......#.##.#"
"..##...#.#..#..#...#.....#.#.#."
"#.....###.#..#.#...#.#......#.#"
"..##.#...#...#.#.....#.#......."
"#....#...#.##......#.#......#.."
"..#.....##.....#..............."
".....###...##.#...........#...."
"...#..##.....##....#..........."
".....#..#......#..........#...."
"....##..##.#...#...#.#.....#.##"
".#.....###..###.#...#.#..#....#"
".#..........#...#..#.#.#..#...#"
".##.##..#..#....#....####......"
"....#..#.#..........#.........."
"###...#.#..#..#...#..###......."
"####.#...#....#..#...#..#......"
".....##....#.#...#....##....##."
"....#.#.##....#.##..#....#.#.#."
"#......#..#.###....#####.##...."
"..##..#.#.#..#........##.##..##"
"#.#...#..#..#......#..#.....#.."
".###.....#.#....#.#..##.....#.#"
"....#......#.#...#...#.#....#.#"
".....#.###.##.................."
".#..........#........#.#...##.#"
".##......#.#.#..#....##.###..#."
"..#.##....#....#.........#.#..#"
"........#..#..#.#.####.....##.."
"#..#.##.#......#.#..##.#...#..#"
"..#.#.##..#.##..........#......"
"##.#.....#.#.##..#..##.....##.#"
".##........#..#.....#...#.##.##"
"...#....#.#.#.........##.....#."
"...#....#.#....#...#..#........"
".....#...#..#...#.##......##..."
"##.........#......#..........##"
".#......#.....##....#.#.#.....#"
"..#.###......#..#.#....#.....#."
".#.......#...#...#.#.#.#..##..."
"...#..............#...###.....#"
"...##......#.#..#.#........#.#."
"..##.#....#..........##...#.#.."
"..#...#.....#.######...##...#.."
"#...#...#............#.....#..."
".###..###.##..#.........#......"
".#........##..#....#...#.#..##."
"#.#.##.#.#...###..............."
"..#.#.#......#.#.#....#.....#.#"
".#...........#.##.#..#.###....."
".###.#....#...........##.#.#..."
".#...#...........#..##........."
".#...#.#...........#..###....#."
".##.......#.....#.....##....#.."
"#.......#........#...##.##..#.#"
"....#..###..#.....##.......#..."
"......###.#...#..#....#.#...#.."
"..#..#.......##...#.#.#...#...."
"......#..#.......#.......##.#.."
"#.#....###.....#...#..#...#...."
"#...#.##.#........#..........##"
".....#.#.##.#.#..#..##.......##"
".#.#.......##....#.#..........."
"#..##.............##...#.#..#.."
"#...........#.#......#.##.##..#"
"...#...#...........#....###.#.#"
".##..#.#.#....#....#####......."
"..#...#.....#.#....#..........."
".#..#........#.....#.#......#.."
".#.........#...#...#.#.#..#...."
".##.##......#.#...#.......#...#"
".##...#..#..........#...#.....#"
"#..........#..#...#.#......#..."
"....##......#...##..##..#....#."
".##.......#...#.#..##..#..#...."
".#.#................#....#....."
"..#..#..###.......#............"
"...##.....#..#......#....#....."
"....#...###...#....#..##...#.#."
"#.........#.......#...#....#..."
".#.#...#.#....##....#.#..##.#.."
"...#..#..#....#..#.#..##.....##"
"..#..#.#.#....#...#....#..#...."
"......###.....#...##.#..#.#...#"
".#.#.#..#.##........#.#....#..."
".#..........#....#.#.......#..."
"#.....#........#........#....#."
".#.#..#...#...................#"
"....####..#..#..#..#....#..#.#."
"..##.#..........#.##..#.....##."
"..................##..........#"
"....##....###.....#..#...#.#..."
".##.........#..#..............."
"....##..###....#.##............"
"#.#...###.#..##...#...........#"
".....#..#......#.....#........."
"..#..##...#.....#.....#.#......"
"......#....###.#..#.#.#....#..#"
"#...#.......#.##.....#........."
".#.#..#...#.............##....."
"......#..............#.....#..#"
"......#......###....#...#......"
".....#.....#...#.......###....."
"#..........##......##.#.#.....#"
"....#.......#..#......#.......#"
"..#...#.###...........#..#.###."
".....#...#.#...........#.#...##"
"........#.#.#........#.#.....#."
"....##..##.#.#..#.#....#.#.##.."
"..#.#.#......##.....#...#.#...#"
"##...#..#......#.#.#..#...#...."
"....#..##...........#..#..#..#."
".#..##...#...#...##.#..#.#....#"
".#.....####.#..#..#....##..#.#."
".#....#..#......#.....#.#.#...."
"....#..#.....#......#.........."
"..#.#..###.....#...#...#.....##"
"..#.#...##..#...........####..."
".#.##....##.#......#.....##.#.."
"#.##..#....#.###..........##..."
".###...#......#.#....##........"
"...................#..#.....#.."
"#.#...#.#..#.....#...#..####.##"
"....#.##..##...##.##.....#....."
".#...#.##...........#.......##."
"###..#.....##...#.........##..."
".###....##...###..............."
".#....#####........#.#.#.##...."
".#.#....####.##........#......."
".....#......#.................."
"......###.....##......#..##.#.."
"....#.#...........##.#....##.#."
"...................#.#.#......."
"#.#.#........#..#.......##....."
"..#...#...#....#......#....##.#"
"#..#..............#......#....#"
"......#.........##............."
".....#.#....##..#.......#......"
"......#.......#...........#...."
"....#....#.#..##.#....#...#...."
"#.#.#..#..#.#.#.#...#....#....#"
".#.#....#...#.#..#......#.....#"
".#...........#.#....##.....#..."
"........#...#....#....##.....##"
"#..#..........#..#..#.....#...."
"#.#.###..........#.##....#...##"
"..#................#.##.##....."
"..#...#.##...##...#.........#.."
"#....#......#......#.........#."
"##...#...##.#.........#......#."
".......#.....#................."
"...#...#.....##.........#.#..#."
"..#......#...#.......#......#.#"
"#.......#...#.##.#..##..#......"
".#.#............#...###..#....."
"...#.......##.......#....#..#.."
".....#..#.#....#.#............."
"#....#...##.##....#....##......"
"........#......#.......#....#.."
"..#..#..##......##.#..#.#..##.."
"....##......#.##.##......#....."
"........##.#...#.....#.......#."
"..##.#....#..#......#.##......."
"..##.####.#...#.#....#........."
".#........#.....#..#....#...#.#"
"###....##......#..#..#.##..#..."
"..........###.#..#..#....#....."
"..#.........#....#.....#....#.#"
".#...#.#.....##.#...#...#.#..#."
"....##......##.##.#.....#..#..."
"....#.##...##.......#..##......"
"#..........#..#....#.......#.#."
"..#.....#.................#...."
"..........#.#.#.....#.#....#..#"
".......#..........#.##....#...."
"#..#.....#.......#........#...."
"#.....##..#.........##..#..#.#."
".##.#...#..........#....#......"
"....#..#.#......#.##..#..#.##.."
"...##.####....#.....#.#...##..."
"..#.#....#.#........#.........."
"#...#.#.##.##....##..#...#...#."
"...#.#.......#..#...#..#..##..#"
".....#....#........###.....#..."
".......#..#.##....#.#.....#...."
"....##....#....#.......#.....#."
".........#........###...##....."
"#.#..#...##.........#.#..#....#"
"...##...........#.........#...#"
"......#.#.#.........#..#.#.#..."
"........##.###....#..#.......#."
"....#.#...#......#..#........##"
".#....##....#...#.##.........#."
"####.#..#...........##.#.#....."
"...#....#..#.....#..##.####.#.."
".##...#...........#.#.........#"
"#.#..#..#...#.#.#.........#..#."
"#......###............#...#...."
"..#.......#....#...#...#..#...#"
"#.#.#...##..#...#...#.......##."
"......#.#.......#..........#.#."
"...............#...#..#...#.#.."
".#.#...##.####..##.##....#..##."
"#..####.......##.#........#...#"
"......###....##...#.#..#.##...."
".##.....###..#...#.###.###....."
"..#...#.....#...#..#..##..#...."
"...#...##.....##........#.#.##."
".#...#..#....#....#..###....#.#"
"..#.#.#.#.#..........#.#..#..##"
".......###....................."
"##.#......#.##.....#.........#."
"......................#.#.....#"
"#..#........##.......#..##..#.#"
"#.#.#.....##.#.##.##.#....##..."
".#...#.....#.........#.....#..."
"..#.........#.##.#.###.#......#"
".........#..#.##...#.......###."
".....##........#......#........"
"...#.#...##...#........#.##...."
".........##............#.####.."
"#....#...#...#..#....#..#.#.#.#"
"..#.........#......#.##........"
"....#.....#........#........#.#"
".##.#..#.#..#..###......###...."
"#.###.....#.#.#.##........#..##"
"#.#..#...##.....#....#...#.#..."
"......#....#.....#...#........."
"...#........##.......#.##..####"
"..#..#....#....#..#..#...#.##.."
".##.....#............#...#....."
"......#.......#.....#...#.#.#.."
".........#.....#...##.........."
".....#........##...........#..."
"#.#..##.#...#....#....#........"
"#.##..#.#.......#...#......#..."
"...........#.#..#..#.....##.#.."
"#....#.##.......#......#.##..#."
".....#........#.##.#...#.....#."
".....###..#.......##..........."
".........#.#.#.....#.##.......#"
".......#....#......#.#.....#..."
"##........#...#..#.#.........#."
"##...........#.##...##......#.."
"..#.###.#.#.#...####..#....###."
".........#...#.....##....#.#.##"
".###..###.#.#.....#.##........."
"#..#...#.#.................##.#"
"##.........#.#....#.#...#.###.."
"#.#....#..............#.##.#..."
"...#..#....##.#..#.......#..##."
".#..#.###......##..........#..#"
".##....#.#....#....#.#..#......"
".......#.....#..#....#.##...#.."
"#.#.#.........###..#..#.....#.."
"...##..##...##....#..#......#.."
"..........#....#..........#...."
"#..##..#...#......#.....#.#...."
"#..##..#....#.#.#...#.........."
"......##..#.........#........#."
".##..#..#......###.....#..#...."
".....#..#.##..........#.#..#..."
;