did it in c++

This commit is contained in:
Seth Samuel 2024-12-02 10:52:22 +13:00
parent 38ec2988c9
commit 885e836f74
7 changed files with 1086 additions and 2 deletions

1000
1/input.txt Normal file

File diff suppressed because it is too large Load diff

BIN
1/puzzle1 Executable file

Binary file not shown.

40
1/puzzle1.c Normal file
View file

@ -0,0 +1,40 @@
#include <stdbool.h>
#include <stdio.h>
#include <string.h>
#define stringSize 20
int listSize = 0;
char readChar = '0';
char stringOne[stringSize];
char stringTwo[stringSize];
int readIntoList(char *stringList) {
int index = 0;
while (1) {
char next = getchar();
if (next == '.') {
break;
} else if (next != '\n') {
stringList[index] = next;
index++;
}
}
}
int main() {
printf("enter list size: \n");
scanf("%i", &listSize);
int listOne[listSize];
int listTwo[listSize];
memset(listOne, '\0', listSize);
memset(listTwo, '\0', listSize);
printf("enter list 1: \n");
readIntoList(stringOne);
printf("enter list 2: \n");
readIntoList(stringTwo);
printf("one: %s \ntwo: %s ", stringOne, stringTwo);
}

37
1/puzzle1.cpp Normal file
View file

@ -0,0 +1,37 @@
#include <stdio.h>
#include <list>
#include <iostream>
#include <fstream>
using namespace std;
list<int> listOne{};
list<int> listTwo{};
int totalDistance = 0;
int main(){
ifstream puzzle("input.txt");
int tempOne, tempTwo;
while (puzzle >> tempOne >> tempTwo)
{
listOne.push_back(tempOne);
listTwo.push_back(tempTwo);
}
puzzle.close();
listOne.sort();
listTwo.sort();
for (int x=0; !listOne.empty();x++){
totalDistance += listOne.front() + listTwo.front();
listOne.pop_front();
listTwo.pop_front();
}
printf("total distance: %i\n", totalDistance);
}