Piss poor attempt at AoC 2021 and I'm 3 years late publishing it :/

This commit is contained in:
Gnarwhal 2024-10-06 21:15:16 +00:00
parent c5b4f835c5
commit b9cc49459b
Signed by: Gnarwhal
GPG key ID: 0989A73D8C421174
8 changed files with 344 additions and 0 deletions

17
2021/Makefile Normal file
View file

@ -0,0 +1,17 @@
day%.out: out/types.o misc/main.cpp days/day%.cpp
g++ -O3 -std=c++2a $(flags) -Dcurrent_day=$(@:.out=) days/$(@:out=cpp) misc/main.cpp out/types.o -o $@
day%_test.out: out/types.o misc/main_test.cpp days/day%.cpp
g++ -O3 -std=c++2a $(flags) -DTEST_BUILD -Dcurrent_day=$(@:_test.out=) days/$(@:_test.out=.cpp) misc/main_test.cpp out/types.o -o $@
days/day%.cpp:
cp 'misc/day.cpp.template' $@
sed -i -e "s/current_day/$(shell basename $@ | cut -f 1 -d '.')/g" $@
out/types.o: misc/types.hpp misc/types.cpp
mkdir -p out/
g++ -std=c++2a $(flags) -c misc/types.cpp -o $@
.PHONY: clean
clean:
rm -f out/* day*.out day*.output

54
2021/days/day1.cpp Normal file
View file

@ -0,0 +1,54 @@
/*****************************
*
* Copyright (c) 2021 Gnarwhal
*
*****************************/
#include <vector>
#include <string>
#include <iostream>
#include <fstream>
#include "../misc/types.hpp"
#include "../misc/print.hpp"
auto current_day() -> void {
{
auto line = std::string();
auto file = std::ifstream("inputs/day1.input");
getline(file, line);
auto value = stoi(line);
auto increases = 0;
while (getline(file, line)) {
auto new_value = stoi(line);
increases += new_value > value;
value = new_value;
}
std::cout << increases << std::endl;
}
{
auto line = std::string();
auto file = std::ifstream("inputs/day1.input");
getline(file, line);
auto index = 2;
auto values = std::vector<i32>{ 0, 0 };
while (getline(file, line)) {
auto new_value = stoi(line);
values.push_back(0);
values[index - 2] += new_value;
values[index - 1] += new_value;
values[index ] += new_value;
++index;
}
auto increases = 0;
for (auto i = 3; i < values.size(); ++i) {
increases += values[i - 1] < values[i];
}
std::cout << increases << std::endl;
}
}

View file

@ -0,0 +1,23 @@
/*****************************
*
* Copyright (c) 2020 Gnarwhal
*
*****************************/
#include <vector>
#include <string>
#include <iostream>
#include <fstream>
#include "../misc/types.hpp"
#include "../misc/print.hpp"
auto current_day() -> void {
{
auto line = std::string();
auto file = std::ifstream("inputs/current_day.input");
while (getline(file, line)) {
}
}
}

36
2021/misc/main.cpp Normal file
View file

@ -0,0 +1,36 @@
/*******************************************************************************
*
* Copyright (c) 2020 Gnarwhal
*
* -----------------------------------------------------------------------------
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files(the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*
*******************************************************************************/
#include "types.hpp"
extern auto current_day() -> void;
auto main(i32 argc, char * argv[]) -> i32 {
current_day();
return 0;
}

66
2021/misc/main_test.cpp Normal file
View file

@ -0,0 +1,66 @@
/*******************************************************************************
*
* Copyright (c) 2020 Gnarwhal
*
* -----------------------------------------------------------------------------
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files(the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*
*******************************************************************************/
#include <iostream>
#include <string>
#include <chrono>
#include "types.hpp"
extern auto current_day() -> void;
auto main(i32 argc, char * argv[]) -> i32 {
auto TEST_CYCLES = 1;
if (argc >= 2) {
TEST_CYCLES = std::stoi(argv[1]);
}
std::cout << "Starting test with " << TEST_CYCLES << " iterations..." << std::endl;
auto begin1 = std::chrono::high_resolution_clock::now();
for (auto i = usize(0); i < TEST_CYCLES; ++i) {
current_day();
}
auto end1 = std::chrono::high_resolution_clock::now();
if (argc >= 3) {
if (argv[2] == std::string("millis")) {
std::cout << "Tests completed in " << std::chrono::duration_cast<std::chrono::milliseconds>(end1 - begin1).count() << " milliseconds"<< std::endl;
} else if (argv[2] == std::string("nanos")) {
std::cout << "Tests completed in " << std::chrono::duration_cast<std::chrono::nanoseconds>(end1 - begin1).count() << " nanoseconds"<< std::endl;
} else if (argv[2] == std::string("micros")) {
std::cout << "Tests completed in " << std::chrono::duration_cast<std::chrono::microseconds>(end1 - begin1).count() << " microsenconds"<< std::endl;
} else {
std::cout << "Unkown time scale '" << argv[2] << "'" << std::endl;
}
} else {
std::cout << "Tests completed in " << std::chrono::duration_cast<std::chrono::microseconds>(end1 - begin1).count() << " microseconds"<< std::endl;
}
return 0;
}

31
2021/misc/print.hpp Normal file
View file

@ -0,0 +1,31 @@
/*******************************************************************************
*
* Copyright (c) 2020 Gnarwhal
*
* -----------------------------------------------------------------------------
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files(the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*
*******************************************************************************/
#ifndef TEST_BUILD
#define print(x) std::cout << (x) << std::endl
#else
#define print(x)
#endif

47
2021/misc/types.cpp Normal file
View file

@ -0,0 +1,47 @@
/*******************************************************************************
*
* Copyright (c) 2020 Gnarwhal
*
* -----------------------------------------------------------------------------
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files(the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*
*******************************************************************************/
#include "types.hpp"
constexpr auto operator "" _u8 (unsigned long long int num) noexcept -> u8 { return u8(num); }
constexpr auto operator "" _i8 (unsigned long long int num) noexcept -> i8 { return u8(num); }
constexpr auto operator "" _u16 (unsigned long long int num) noexcept -> u16 { return u16(num); }
constexpr auto operator "" _i16 (unsigned long long int num) noexcept -> i16 { return i16(num); }
constexpr auto operator "" _u32 (unsigned long long int num) noexcept -> u32 { return u32(num); }
constexpr auto operator "" _i32 (unsigned long long int num) noexcept -> i32 { return i32(num); }
constexpr auto operator "" _u64 (unsigned long long int num) noexcept -> u64 { return u64(num); }
constexpr auto operator "" _i64 (unsigned long long int num) noexcept -> i64 { return i64(num); }
constexpr auto operator "" _usize(unsigned long long int num) noexcept -> usize { return usize(num); }
constexpr auto operator "" _c8 (char c) noexcept -> c8 { return c8(c); }
constexpr auto operator "" _c16(char c) noexcept -> c16 { return c16(c); }
constexpr auto operator "" _c32(char c) noexcept -> c32 { return c32(c); }
constexpr auto operator "" _c8 (unsigned long long int c) noexcept -> c8 { return c8(c); }
constexpr auto operator "" _c16(unsigned long long int c) noexcept -> c16 { return c16(c); }
constexpr auto operator "" _c32(unsigned long long int c) noexcept -> c32 { return c32(c); }
constexpr auto operator "" _f32(long double num) noexcept -> f32 { return (f32) num; }
constexpr auto operator "" _f64(long double num) noexcept -> f64 { return (f64) num; }

70
2021/misc/types.hpp Normal file
View file

@ -0,0 +1,70 @@
/*******************************************************************************
*
* Copyright (c) 2020 Gnarwhal
*
* -----------------------------------------------------------------------------
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files(the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*
*******************************************************************************/
#ifndef GNARWHAL_REDWOOD_TYPES
#define GNARWHAL_REDWOOD_TYPES
#include <cstddef>
#include <cstdint>
using u8 = std::uint8_t;
using i8 = std::int8_t;
using u16 = std::uint16_t;
using i16 = std::int16_t;
using u32 = std::uint32_t;
using i32 = std::int32_t;
using u64 = std::uint64_t;
using i64 = std::int64_t;
using usize = std::size_t;
constexpr auto operator "" _u8 (unsigned long long int num) noexcept -> u8;
constexpr auto operator "" _i8 (unsigned long long int num) noexcept -> i8;
constexpr auto operator "" _u16 (unsigned long long int num) noexcept -> u16;
constexpr auto operator "" _i16 (unsigned long long int num) noexcept -> i16;
constexpr auto operator "" _u32 (unsigned long long int num) noexcept -> u32;
constexpr auto operator "" _i32 (unsigned long long int num) noexcept -> i32;
constexpr auto operator "" _u64 (unsigned long long int num) noexcept -> u64;
constexpr auto operator "" _i64 (unsigned long long int num) noexcept -> i64;
constexpr auto operator "" _usize(unsigned long long int num) noexcept -> usize;
using c8 = u8;
using c16 = u16;
using c32 = u32;
constexpr auto operator "" _c8 (char c) noexcept -> c8;
constexpr auto operator "" _c16(char c) noexcept -> c16;
constexpr auto operator "" _c32(char c) noexcept -> c32;
constexpr auto operator "" _c8 (unsigned long long int c) noexcept -> c8;
constexpr auto operator "" _c16(unsigned long long int c) noexcept -> c16;
constexpr auto operator "" _c32(unsigned long long int c) noexcept -> c32;
using f32 = float;
using f64 = double;
constexpr auto operator "" _f32(long double num) noexcept -> f32;
constexpr auto operator "" _f64(long double num) noexcept -> f64;
#endif // GNARWHAL_REDWOOD_TYPES