Skip to content

Instantly share code, notes, and snippets.

@bunnylab
Created December 23, 2020 23:30
Show Gist options
  • Save bunnylab/2381877093a672deb8b0e4e9b179f68b to your computer and use it in GitHub Desktop.
Save bunnylab/2381877093a672deb8b0e4e9b179f68b to your computer and use it in GitHub Desktop.
#include <stdio.h>
#define INPUT_LEN 200
// Get the three numbers from a list of INPUT_LEN that sum to 2020
// and return their product
int main(){
FILE *fp;
int nums[INPUT_LEN];
fp = fopen("input.txt", "r");
int i = 0;
while(fscanf(fp, "%d", &nums[i]) != EOF)
++i;
// all the nested loops
for(int x = 0; x<INPUT_LEN-1; ++x){
for(int y=x+1; y<INPUT_LEN; ++y){
for(int z=0; z<INPUT_LEN; ++z){
if(nums[x] + nums[y] + nums[z] == 2020 && z != y && x != z){
printf("answer: %d\n", nums[x] * nums[y] * nums[z]);
}
}
}
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment