Moloch! Moloch! Robot apartments! Invisible suburbs! Skeleton treasuries! Blind capitals! Demonic industries! Spectral nations!
Previous: Day 02 | Next: Day 04
THIS DOES NOT SEEM LIKE A SAFE MODE OF TRANSPOOORR-
archivist/day03-1.carchivist/day03-1.c
#include "../array.h" #include "../fileload.h" #include <stdlib.h> int main (int argc, char**argv){ if(argc < 2){ printf("not enough inputs\n"); return -1; } int width = 0; int height = 0; char * input = file_contents(argv[1]); char*dispos = malloc(strlen(input)*sizeof(char)); strcpy(dispos, input); array data = arr_init(0, sizeof(int)); char * line = 0; while((line = strsep(&dispos, "\n")) != NULL){ if(strlen(line) == 0) break; width=strlen(line); height++; }; int xpos = 0; int ypos = 0; int n_trees = 0; printf("W: %d, H: %d\n", width,height); while(ypos < height){ xpos = (xpos+3)%width; ypos = ypos+1; printf("%d, %d\n", xpos,ypos); //We have to use width+1 to account for newline characters if(input[xpos+ypos*(width+1)] == '#') { n_trees++; printf("you hit a tree\n"); } } printf("You hit %d trees\n", n_trees); return 0; }
archivist/day03-2.carchivist/day03-2.c
#include <stdio.h> /*TO THE*/ #include <stdlib.h> /*OCEAN!*/ #include <string.h> #define R 5 // // int main( int argc, char **argv){ int w=0;int h=0; int l=0;FILE*f=fopen( argv[1],"r");char*I;if (!f) return-1;fseek(f,0,SEEK_END); l=ftell (f);printf("l is %d\n",l); rewind(f) ;I=(char*)malloc(sizeof(char)* (l+1)) ;fread(I,sizeof(char),l,f); fclose (f);((char*)I)[l]='\0';for(int i=0; i<l;i++){if(I[i]=='\n'){w=i;break ;}}h=l /(w+1);printf("W: %d,H: %d\n" ,w,h) ;int s[R] [2]={{1,1},{3,1},{5,1}, {7,1}, {1,2} };long int tot=1;for(int run=0;run<R; run++){int x=0; int y=0;int n=0;while(y<h){x=( x+s [run] [0] )%w;y=y+srun;if(I[x+y*(w+1) ]=='#')n++ ; }printf("You hit %d trees on run %d\n",n,run) ; tot *=n;}printf("Total multiple: %ld\n",tot); ; int i=0;i++;i++;i++;i++;i++;i++;i++; i++;i++;i++; i++; i++;i++;i++;i++;i++;i++;i++ ;i++;i++; i++;i++;i++ ;i++; i++;i++;i++;i++;i++;i++;i++; i++;i++; i++;i++; i++; i++; i++;i++; i++; i++;i++;i++;i++;i++; i++; i++; i++;i++;i++;i++;i++;i++;i++; i++;i++; i++; i++; i++;i++;i++;i++;i++;i++;i++;i++;i++;i++; i++; i++;
i++;i++;i++; i++;i++;i++; i++;i++;i++;i++; i++;;}
archivist/day03-3.carchivist/day03-3.c
#include <stdio.h> #include <stdlib.h> #include <string.h> #include "../bn.h" int main (int argc, char**argv){ int width = 0; int height = 0; long int length = 0; FILE *f = fopen(argv[1], "r"); char output[8192]; output[0] = 'a'; output[1024] = '\0'; char *input; if (!f) return -1; fseek(f, 0, SEEK_END); length = ftell(f); printf("length is %ld\n", length); rewind(f); input = (char*)malloc(sizeof(char) * (length+1)); fread(input, sizeof(char), length, f); printf("length is %ld\n", length); fclose(f); ((char*)input)[length] = '\0'; for(int i = 0; i < length; i++){ if(input[i] == '\n'){ width = i; break; } } height = length/(width+1); printf("W: %d, H: %d\n", width,height); int run_list_size = 15; int slopevals2 = {{ 2, 3, 4, 6, 8, 9, 12, 16, 18, 24, 32, 36, 48, 54, 64 }, { 1, 5, 7, 11, 13, 17, 19, 23, 25, 29, 31, 35, 37, 41, 47 }}; unsigned long long int running_mult_total = 1; struct bn total; struct bn tmp; struct bn tmp2; bignum_from_int(&total, 1); for(int i = 0;i<run_list_size;i++){ for(int j = 0;j<run_list_size;j++){ //printf("Slope %d, %d\n", slopevals0, slopevals1); int xpos = 0; int ypos = 0; int n_trees = 0; while(ypos < height){ xpos = (xpos+slopevals0)%width; ypos = ypos+slopevals1; //We have to use width+1 to account for newline characters if(input[xpos+ypos*(width+1)] == '#') n_trees++; } printf("You hit %d trees on run %d\n", n_trees, i*15+j); if(n_trees == 0) n_trees++; //bignum_from_int(&total, 111231); bignum_assign(&tmp2, &total); bignum_from_int(&tmp,n_trees); bignum_mul(&tmp,&tmp2,&total); bignum_to_string(&total, output, sizeof(output)); printf("running multiple: %s\n", output); } } bignum_to_string(&total, output, 1024); printf("Total multiple: %s\n", output); return 0; }
deutschanon/deutschanon-day03pbig.cdeutschanon/deutschanon-day03pbig.c
#include <stdio.h> #include <stdlib.h> long long bewegen(int y, int x, int hohe, int breite, char* wald){ int spalte = 0; long long baume = 0; for(int i = 0; i < hohe; i = i + y){ if(wald[i*breite+(spalte%breite)] == '#'){ baume++; } spalte = spalte + x; } return baume; } int main(int argc,char** argv){ int breite,hohe,reihe,spalte; hohe = 0; breite = 0; reihe = 0; spalte = 0; char c = 0; FILE *input; if(argc > 1){ input = fopen(argv[1],"r"); }else{ input = fopen("input.txt","r"); } while((c = fgetc(input))!= EOF){ if(c == '\n'){ hohe++; } if(hohe == 0 && c != '\r'){ breite++; } } char *wald; wald = malloc(hohe*breite); fseek(input,0L,0); while((c = fgetc(input)) != EOF){ if(c != '\n'){ if(c != '\r'){ wald[reihe*breite+(spalte%breite)] = c; spalte++; } }else{ reihe++; } } long long int ret = 0; printf("Breite: %d\tHöhe: %d\n",breite,hohe); ret = bewegen(1,1,hohe,breite,wald) * bewegen(1,3,hohe,breite,wald) * bewegen(1,5,hohe,breite,wald) * bewegen(1,7,hohe,breite,wald) * bewegen(2,1,hohe,breite,wald); printf("Bäume Teil 1: %ld\n",bewegen(1,3,hohe,breite,wald)); printf("Bäume Teil 2: %lld\n",ret); free(wald); fclose(input); return 0; }
steveklabnik/steveklabnik-day03.rssteveklabnik/steveklabnik-day03.rs
use std::iter::successors; fn solve(input: &str) -> (u32, u64) { let width = input.find('\n').unwrap(); let height = input.len() / (width + 1); debug_assert!(input.len() % (width + 1) == 0); let count_trees = |dx, dy| { (0..height) .step_by(dy) .zip(successors(Some(0), |x| Some((x + dx) % width))) .map(|(y, x)| u32::from(input.as_bytes()[y * (width + 1) + x] == b'#')) .sum() }; let counts = [ count_trees(1, 1), count_trees(3, 1), count_trees(5, 1), count_trees(7, 1), count_trees(1, 2) ]; (counts[1], counts.iter().copied().map(u64::from).product()) }
wizardanon/wizardanon-day03.cppwizardanon/wizardanon-day03.cpp
#include "stdafx.h" #include "fstream" #include <iostream> #include <fstream> #include <string> using namespace std;
#define Modulorulum % #define Newlinius '\n'; #define Integerius int #define Openum { #define Closeth } #define Nullus 0 #define Incantation #define ScryYonder getline #define HearYe return #define Hithero while #define Behold(x) std::cout << x << Newlinius #define Portal std::ifstream #define Summon(x) f(x) #define Appendo ++ #define Equilarmius = #define IsItSo if #define Scrivening string #define Scriv char Integerius main() Openum Portal Summon("day3.txt"); Scrivening Forest; Scriv WoodenOne = '#'; Integerius TreesBetwixt = Nullus; Integerius Footfalls = Nullus; Integerius Terminus = 31; Integerius Cockatrice = 3; IsItSo (f.is_open()) Openum Hithero ( ScryYonder (f, Forest) ) Openum Integerius index Equilarmius (Footfalls Appendo * Cockatrice) Modulorulum Terminus; IsItSo ( Forest.at(index) == WoodenOne ) Openum TreesBetwixt Appendo; Closeth Closeth Closeth Behold( TreesBetwixt ); HearYe Nullus; Closeth