main
Brett 2024-12-09 02:07:28 -05:00
parent b7c8125094
commit 06636ea2a8
34 changed files with 742 additions and 169 deletions

View File

@ -1,5 +1,5 @@
cmake_minimum_required(VERSION 3.25) cmake_minimum_required(VERSION 3.25)
project(Advent-Of-Code-2024 VERSION 0.0.8) project(Advent-Of-Code-2024 VERSION 0.0.9)
option(ENABLE_ADDRSAN "Enable the address sanitizer" OFF) option(ENABLE_ADDRSAN "Enable the address sanitizer" OFF)
option(ENABLE_UBSAN "Enable the ub sanitizer" OFF) option(ENABLE_UBSAN "Enable the ub sanitizer" OFF)

View File

@ -1,24 +0,0 @@
#pragma once
/*
* Copyright (C) 2024 Brett Terpstra
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
#ifndef DAY5_H
#define DAY5_H
void run_day5();
#endif //DAY5_H

View File

@ -1,24 +0,0 @@
#pragma once
/*
* Copyright (C) 2024 Brett Terpstra
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
#ifndef DAY6_H
#define DAY6_H
void run_day6();
#endif //DAY6_H

View File

@ -1,24 +0,0 @@
#pragma once
/*
* Copyright (C) 2024 Brett Terpstra
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
#ifndef DAY7_H
#define DAY7_H
void run_day7();
#endif //DAY7_H

View File

@ -1,24 +0,0 @@
#pragma once
/*
* Copyright (C) 2024 Brett Terpstra
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
#ifndef DAY8_H
#define DAY8_H
void run_day8();
#endif //DAY8_H

View File

@ -1,24 +0,0 @@
#pragma once
/*
* Copyright (C) 2024 Brett Terpstra
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
#ifndef DAY9_H
#define DAY9_H
void run_day9();
#endif //DAY9_H

47
include/days.h Normal file
View File

@ -0,0 +1,47 @@
#pragma once
/*
* Copyright (C) 2024 Brett Terpstra
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
#ifndef DAYS_H
#define DAYS_H
void run_day1();
void run_day2();
void run_day3();
void run_day4();
void run_day5();
void run_day6();
void run_day7();
void run_day8();
void run_day9();
void run_day10();
void run_day11();
void run_day12();
void run_day13();
void run_day14();
void run_day15();
void run_day16();
void run_day17();
void run_day18();
void run_day19();
void run_day20();
void run_day21();
void run_day22();
void run_day23();
void run_day24();
#endif //DAYS_H

1
problems/day9/example Normal file
View File

@ -0,0 +1 @@
2333133121414131402

1
problems/day9/input Normal file

File diff suppressed because one or more lines are too long

View File

@ -15,7 +15,7 @@
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>. * along with this program. If not, see <https://www.gnu.org/licenses/>.
*/ */
#include <day1.h> #include <days.h>
#include <vector> #include <vector>
#include <limits> #include <limits>
#include <algorithm> #include <algorithm>

View File

@ -1,5 +1,5 @@
#pragma once
/* /*
* <Short Description>
* Copyright (C) 2024 Brett Terpstra * Copyright (C) 2024 Brett Terpstra
* *
* This program is free software: you can redistribute it and/or modify * This program is free software: you can redistribute it and/or modify
@ -15,10 +15,19 @@
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>. * along with this program. If not, see <https://www.gnu.org/licenses/>.
*/ */
#include <days.h>
#include <blt/math/log_util.h>
#include <vector>
#include <limits>
#include <algorithm>
#include <blt/fs/loader.h>
#include <blt/iterator/enumerate.h>
#include <blt/iterator/iterator.h>
#include <blt/iterator/zip.h>
#include <blt/std/hashmap.h>
#include <blt/math/vectors.h>
#include <blt/std/assert.h>
#ifndef DAY1_H void run_day10()
#define DAY1_H {
}
void run_day1();
#endif //DAY1_H

View File

@ -1,5 +1,5 @@
#pragma once
/* /*
* <Short Description>
* Copyright (C) 2024 Brett Terpstra * Copyright (C) 2024 Brett Terpstra
* *
* This program is free software: you can redistribute it and/or modify * This program is free software: you can redistribute it and/or modify
@ -15,10 +15,19 @@
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>. * along with this program. If not, see <https://www.gnu.org/licenses/>.
*/ */
#include <days.h>
#include <blt/math/log_util.h>
#include <vector>
#include <limits>
#include <algorithm>
#include <blt/fs/loader.h>
#include <blt/iterator/enumerate.h>
#include <blt/iterator/iterator.h>
#include <blt/iterator/zip.h>
#include <blt/std/hashmap.h>
#include <blt/math/vectors.h>
#include <blt/std/assert.h>
#ifndef DAY2_H void run_day11()
#define DAY2_H {
}
void run_day2();
#endif //DAY2_H

View File

@ -1,5 +1,5 @@
#pragma once
/* /*
* <Short Description>
* Copyright (C) 2024 Brett Terpstra * Copyright (C) 2024 Brett Terpstra
* *
* This program is free software: you can redistribute it and/or modify * This program is free software: you can redistribute it and/or modify
@ -15,10 +15,19 @@
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>. * along with this program. If not, see <https://www.gnu.org/licenses/>.
*/ */
#include <days.h>
#include <blt/math/log_util.h>
#include <vector>
#include <limits>
#include <algorithm>
#include <blt/fs/loader.h>
#include <blt/iterator/enumerate.h>
#include <blt/iterator/iterator.h>
#include <blt/iterator/zip.h>
#include <blt/std/hashmap.h>
#include <blt/math/vectors.h>
#include <blt/std/assert.h>
#ifndef DAY3_H void run_day12()
#define DAY3_H {
}
void run_day3();
#endif //DAY3_H

View File

@ -1,5 +1,5 @@
#pragma once
/* /*
* <Short Description>
* Copyright (C) 2024 Brett Terpstra * Copyright (C) 2024 Brett Terpstra
* *
* This program is free software: you can redistribute it and/or modify * This program is free software: you can redistribute it and/or modify
@ -15,10 +15,19 @@
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>. * along with this program. If not, see <https://www.gnu.org/licenses/>.
*/ */
#include <days.h>
#include <blt/math/log_util.h>
#include <vector>
#include <limits>
#include <algorithm>
#include <blt/fs/loader.h>
#include <blt/iterator/enumerate.h>
#include <blt/iterator/iterator.h>
#include <blt/iterator/zip.h>
#include <blt/std/hashmap.h>
#include <blt/math/vectors.h>
#include <blt/std/assert.h>
#ifndef DAY4_H void run_day13()
#define DAY4_H {
}
void run_day4();
#endif //DAY4_H

33
src/day14.cpp Normal file
View File

@ -0,0 +1,33 @@
/*
* <Short Description>
* Copyright (C) 2024 Brett Terpstra
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
#include <days.h>
#include <blt/math/log_util.h>
#include <vector>
#include <limits>
#include <algorithm>
#include <blt/fs/loader.h>
#include <blt/iterator/enumerate.h>
#include <blt/iterator/iterator.h>
#include <blt/iterator/zip.h>
#include <blt/std/hashmap.h>
#include <blt/math/vectors.h>
#include <blt/std/assert.h>
void run_day14()
{
}

33
src/day15.cpp Normal file
View File

@ -0,0 +1,33 @@
/*
* <Short Description>
* Copyright (C) 2024 Brett Terpstra
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
#include <days.h>
#include <blt/math/log_util.h>
#include <vector>
#include <limits>
#include <algorithm>
#include <blt/fs/loader.h>
#include <blt/iterator/enumerate.h>
#include <blt/iterator/iterator.h>
#include <blt/iterator/zip.h>
#include <blt/std/hashmap.h>
#include <blt/math/vectors.h>
#include <blt/std/assert.h>
void run_day15()
{
}

33
src/day16.cpp Normal file
View File

@ -0,0 +1,33 @@
/*
* <Short Description>
* Copyright (C) 2024 Brett Terpstra
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
#include <days.h>
#include <blt/math/log_util.h>
#include <vector>
#include <limits>
#include <algorithm>
#include <blt/fs/loader.h>
#include <blt/iterator/enumerate.h>
#include <blt/iterator/iterator.h>
#include <blt/iterator/zip.h>
#include <blt/std/hashmap.h>
#include <blt/math/vectors.h>
#include <blt/std/assert.h>
void run_day16()
{
}

33
src/day17.cpp Normal file
View File

@ -0,0 +1,33 @@
/*
* <Short Description>
* Copyright (C) 2024 Brett Terpstra
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
#include <days.h>
#include <blt/math/log_util.h>
#include <vector>
#include <limits>
#include <algorithm>
#include <blt/fs/loader.h>
#include <blt/iterator/enumerate.h>
#include <blt/iterator/iterator.h>
#include <blt/iterator/zip.h>
#include <blt/std/hashmap.h>
#include <blt/math/vectors.h>
#include <blt/std/assert.h>
void run_day17()
{
}

33
src/day18.cpp Normal file
View File

@ -0,0 +1,33 @@
/*
* <Short Description>
* Copyright (C) 2024 Brett Terpstra
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
#include <days.h>
#include <blt/math/log_util.h>
#include <vector>
#include <limits>
#include <algorithm>
#include <blt/fs/loader.h>
#include <blt/iterator/enumerate.h>
#include <blt/iterator/iterator.h>
#include <blt/iterator/zip.h>
#include <blt/std/hashmap.h>
#include <blt/math/vectors.h>
#include <blt/std/assert.h>
void run_day18()
{
}

33
src/day19.cpp Normal file
View File

@ -0,0 +1,33 @@
/*
* <Short Description>
* Copyright (C) 2024 Brett Terpstra
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
#include <days.h>
#include <blt/math/log_util.h>
#include <vector>
#include <limits>
#include <algorithm>
#include <blt/fs/loader.h>
#include <blt/iterator/enumerate.h>
#include <blt/iterator/iterator.h>
#include <blt/iterator/zip.h>
#include <blt/std/hashmap.h>
#include <blt/math/vectors.h>
#include <blt/std/assert.h>
void run_day19()
{
}

View File

@ -15,7 +15,7 @@
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>. * along with this program. If not, see <https://www.gnu.org/licenses/>.
*/ */
#include <day2.h> #include <days.h>
#include <vector> #include <vector>
#include <limits> #include <limits>
#include <algorithm> #include <algorithm>

33
src/day20.cpp Normal file
View File

@ -0,0 +1,33 @@
/*
* <Short Description>
* Copyright (C) 2024 Brett Terpstra
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
#include <days.h>
#include <blt/math/log_util.h>
#include <vector>
#include <limits>
#include <algorithm>
#include <blt/fs/loader.h>
#include <blt/iterator/enumerate.h>
#include <blt/iterator/iterator.h>
#include <blt/iterator/zip.h>
#include <blt/std/hashmap.h>
#include <blt/math/vectors.h>
#include <blt/std/assert.h>
void run_day20()
{
}

33
src/day21.cpp Normal file
View File

@ -0,0 +1,33 @@
/*
* <Short Description>
* Copyright (C) 2024 Brett Terpstra
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
#include <days.h>
#include <blt/math/log_util.h>
#include <vector>
#include <limits>
#include <algorithm>
#include <blt/fs/loader.h>
#include <blt/iterator/enumerate.h>
#include <blt/iterator/iterator.h>
#include <blt/iterator/zip.h>
#include <blt/std/hashmap.h>
#include <blt/math/vectors.h>
#include <blt/std/assert.h>
void run_day21()
{
}

33
src/day22.cpp Normal file
View File

@ -0,0 +1,33 @@
/*
* <Short Description>
* Copyright (C) 2024 Brett Terpstra
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
#include <days.h>
#include <blt/math/log_util.h>
#include <vector>
#include <limits>
#include <algorithm>
#include <blt/fs/loader.h>
#include <blt/iterator/enumerate.h>
#include <blt/iterator/iterator.h>
#include <blt/iterator/zip.h>
#include <blt/std/hashmap.h>
#include <blt/math/vectors.h>
#include <blt/std/assert.h>
void run_day22()
{
}

33
src/day23.cpp Normal file
View File

@ -0,0 +1,33 @@
/*
* <Short Description>
* Copyright (C) 2024 Brett Terpstra
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
#include <days.h>
#include <blt/math/log_util.h>
#include <vector>
#include <limits>
#include <algorithm>
#include <blt/fs/loader.h>
#include <blt/iterator/enumerate.h>
#include <blt/iterator/iterator.h>
#include <blt/iterator/zip.h>
#include <blt/std/hashmap.h>
#include <blt/math/vectors.h>
#include <blt/std/assert.h>
void run_day23()
{
}

33
src/day24.cpp Normal file
View File

@ -0,0 +1,33 @@
/*
* <Short Description>
* Copyright (C) 2024 Brett Terpstra
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
#include <days.h>
#include <blt/math/log_util.h>
#include <vector>
#include <limits>
#include <algorithm>
#include <blt/fs/loader.h>
#include <blt/iterator/enumerate.h>
#include <blt/iterator/iterator.h>
#include <blt/iterator/zip.h>
#include <blt/std/hashmap.h>
#include <blt/math/vectors.h>
#include <blt/std/assert.h>
void run_day24()
{
}

View File

@ -15,7 +15,7 @@
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>. * along with this program. If not, see <https://www.gnu.org/licenses/>.
*/ */
#include <day3.h> #include <days.h>
#include <vector> #include <vector>
#include <limits> #include <limits>
#include <algorithm> #include <algorithm>

View File

@ -15,7 +15,7 @@
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>. * along with this program. If not, see <https://www.gnu.org/licenses/>.
*/ */
#include <day4.h> #include <days.h>
#include <vector> #include <vector>
#include <limits> #include <limits>
#include <algorithm> #include <algorithm>

View File

@ -15,7 +15,7 @@
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>. * along with this program. If not, see <https://www.gnu.org/licenses/>.
*/ */
#include <day5.h> #include <days.h>
#include <vector> #include <vector>
#include <limits> #include <limits>
#include <algorithm> #include <algorithm>

View File

@ -15,7 +15,7 @@
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>. * along with this program. If not, see <https://www.gnu.org/licenses/>.
*/ */
#include <day6.h> #include <days.h>
#include <blt/math/log_util.h> #include <blt/math/log_util.h>
#include <vector> #include <vector>
#include <limits> #include <limits>

View File

@ -15,7 +15,7 @@
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>. * along with this program. If not, see <https://www.gnu.org/licenses/>.
*/ */
#include <day7.h> #include <days.h>
#include <blt/math/log_util.h> #include <blt/math/log_util.h>
#include <vector> #include <vector>
#include <limits> #include <limits>

View File

@ -15,7 +15,7 @@
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>. * along with this program. If not, see <https://www.gnu.org/licenses/>.
*/ */
#include <day8.h> #include <days.h>
#include <blt/math/log_util.h> #include <blt/math/log_util.h>
#include <vector> #include <vector>
#include <limits> #include <limits>

View File

@ -15,7 +15,7 @@
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>. * along with this program. If not, see <https://www.gnu.org/licenses/>.
*/ */
#include <day9.h> #include <days.h>
#include <blt/math/log_util.h> #include <blt/math/log_util.h>
#include <vector> #include <vector>
#include <limits> #include <limits>
@ -28,6 +28,214 @@
#include <blt/math/vectors.h> #include <blt/math/vectors.h>
#include <blt/std/assert.h> #include <blt/std/assert.h>
void run_day9(){ struct data_t
{
int id;
int size;
};
} struct free_space_t
{
int size;
};
using var_v = std::variant<data_t, free_space_t>;
void print(std::vector<var_v>& vec)
{
for (const auto& v : vec)
{
std::visit(blt::lambda_visitor{
[](const data_t& data)
{
for (int i = 0; i < data.size; i++)
std::cout << data.id;
},
[](const free_space_t& free)
{
for (int i = 0; i < free.size; i++)
std::cout << '.';
}
}, v);
}
std::cout << '\n';
}
blt::size_t check_sum(const std::vector<var_v>& processed_file)
{
blt::size_t total = 0;
blt::size_t position = 0;
for (auto& i : processed_file)
{
blt::lambda_visitor visit{
[&total, &position](const data_t& data)
{
for (int j = 0; j < data.size; j++)
{
total += data.id * position++;
}
},
[&total, &position](const free_space_t& free)
{
for (int j = 0; j < free.size; j++)
position++;
}
};
std::visit(visit, i);
}
return total;
}
void part1(std::vector<var_v> processed_file)
{
while (true)
{
auto& top = processed_file.back();
if (std::holds_alternative<free_space_t>(top))
{
processed_file.pop_back();
continue;
}
auto& data = std::get<data_t>(top);
bool found = false;
for (auto it = processed_file.begin(); it != processed_file.end(); ++it)
{
if (std::holds_alternative<free_space_t>(*it))
{
auto& place = std::get<free_space_t>(*it);
auto remain = static_cast<blt::ptrdiff_t>(place.size) - static_cast<blt::ptrdiff_t>(data.size);
// BLT_TRACE("id: %d;; %d - %d = %ld", data.id, data.size, place.size, remain);
if (remain < 0)
{
data.size -= place.size;
processed_file.insert(processed_file.erase(it), data_t{data.id, place.size});
}
else if (remain > 0)
{
place.size -= data.size;
processed_file.insert(it, data_t{data.id, data.size});
processed_file.pop_back();
}
else
{
processed_file.insert(processed_file.erase(it), data);
processed_file.pop_back();
}
found = true;
break;
}
}
if (!found)
break;
}
std::cout << "Checksum " << check_sum(processed_file) << " " << processed_file.size() << "\n";
}
void part2(std::vector<var_v> processed_file)
{
int last_id = std::numeric_limits<int>::max();
do
{
for (const auto& val : blt::iterate(processed_file).rev())
{
if (std::holds_alternative<data_t>(val))
{
if (const auto id = std::get<data_t>(val).id; id < last_id)
{
last_id = id;
break;
}
}
}
auto dv = processed_file.end();
do
{
--dv;
if (std::holds_alternative<data_t>(*dv))
{
if (std::get<data_t>(*dv).id == last_id)
break;
}
}
while (true);
auto data = std::get<data_t>(*dv);
bool found = false;
for (auto fs = processed_file.begin(); fs != processed_file.end(); ++fs)
{
// no free space left
if (last_id == 0 && fs == dv)
goto exit;
if (std::holds_alternative<free_space_t>(*fs))
{
auto& space = std::get<free_space_t>(*fs);
if (data.size < space.size)
{
space.size -= data.size;
processed_file.insert(fs, data);
found = true;
break;
}
if (data.size == space.size)
{
processed_file.insert(processed_file.erase(fs), data);
found = true;
break;
}
}
}
if (found)
{
for (auto it = processed_file.end() - 1; it != processed_file.begin() - 1; --it)
{
if (std::holds_alternative<data_t>(*it))
{
if (std::get<data_t>(*it).id == last_id)
{
processed_file.insert(processed_file.erase(it), free_space_t{data.size});
break;
}
}
}
}
}
while (true);
exit:
// print(processed_file);
std::cout << "Checksum2 " << check_sum(processed_file) << " " << processed_file.size() << "\n";
}
void run_day9()
{
const auto file = blt::fs::getFile("../problems/day9/input");
std::vector<var_v> processed_file;
int id = 0;
for (blt::size_t i = 0; i < file.size(); i++)
{
const auto blocks = file[i] - '0';
processed_file.emplace_back(data_t{id, blocks});
id++;
if (i < file.size() - 1)
{
i++;
const auto free = file[i] - '0';
processed_file.emplace_back(free_space_t{free});
}
}
BLT_TRACE(processed_file.size());
// print(processed_file);
part1(processed_file);
part2(processed_file);
}

View File

@ -1,14 +1,6 @@
#include <blt/parse/argparse.h> #include <blt/parse/argparse.h>
#include <blt/std/logging.h> #include <blt/std/logging.h>
#include <day1.h> #include <days.h>
#include <day2.h>
#include <day3.h>
#include <day4.h>
#include <day5.h>
#include <day6.h>
#include <day7.h>
#include <day8.h>
#include <day9.h>
int main(const int argc, const char** argv) int main(const int argc, const char** argv)
{ {
@ -53,6 +45,51 @@ int main(const int argc, const char** argv)
case 9: case 9:
run_day9(); run_day9();
break; break;
case 10:
run_day10();
break;
case 11:
run_day11();
break;
case 12:
run_day12();
break;
case 13:
run_day13();
break;
case 14:
run_day14();
break;
case 15:
run_day15();
break;
case 16:
run_day16();
break;
case 17:
run_day17();
break;
case 18:
run_day18();
break;
case 19:
run_day19();
break;
case 20:
run_day20();
break;
case 21:
run_day21();
break;
case 22:
run_day22();
break;
case 23:
run_day23();
break;
case 24:
run_day24();
break;
default: default:
BLT_INFO("%d is not a day", day); BLT_INFO("%d is not a day", day);
break; break;