advent2015

advent of code 2015 (c++)
git clone git://bsandro.tech/advent2015
Log | Files | Refs

commit 62dd24a32f9a14bab9541c9766a1a7feb653218f
parent 0616279c31a13ddbcdd59a79b775390565160d1d
Author: bsandro <email@bsandro.tech>
Date:   Sat, 30 Nov 2024 11:40:36 +0200

new day gen script and basic template

Diffstat:
Amakenew.sh | 5+++++
Atpl/Makefile | 28++++++++++++++++++++++++++++
Atpl/main.cpp | 45+++++++++++++++++++++++++++++++++++++++++++++
3 files changed, 78 insertions(+), 0 deletions(-)

diff --git a/makenew.sh b/makenew.sh @@ -0,0 +1,5 @@ +#!/bin/sh +DAY=$1 +echo "AoC day $DAY" +cp -r tpl "day$DAY" +sed -i "s/\\\$DAY/$DAY/" day$DAY/main.cpp diff --git a/tpl/Makefile b/tpl/Makefile @@ -0,0 +1,28 @@ +NAME=$(shell basename ${PWD}) +SRC=$(wildcard *.cpp) +DEPS:=$(wildcard *.hpp) +OBJ:=$(SRC:.cpp=.o) +CXXFLAGS=-O2 -std=c++17 -Werror -Wall -Wextra -I. +LDFLAGS=-lstdc++ + +all: $(NAME) + +.PHONY: clean run + +clean: + rm -f $(OBJ) $(NAME) + +%.o : %.c $(DEPS) + @$(CC) $(CFLAGS) -c $< -o $@ + +$(NAME): $(OBJ) + @$(CC) $(OBJ) -o $@ $(LDFLAGS) + +run: $(NAME) + @./$(NAME) input.txt + +test1: $(NAME) + @./$(NAME) test1.txt + +test2: $(NAME) + @./$(NAME) test2.txt diff --git a/tpl/main.cpp b/tpl/main.cpp @@ -0,0 +1,45 @@ +#include <iostream> +#include <filesystem> +#include <fstream> +#include <vector> +#include <cstring> +#include <cstdio> +#include <tuple> +#include <algorithm> + +template<typename T> +T read_file(const std::string &path) { + std::ifstream ifs(path, std::ios::binary); + if (!ifs.is_open()) { + throw std::runtime_error(path+":"+std::strerror(errno)); + } + //std::uintmax_t size = std::filesystem::file_size(path); + T buf; + /*while (1) { + std::string str; + std::getline(ifs, str); + if (!str.empty()) buf.push_back(Box(str)); + if (!ifs) break; + }*/ + /*if (!ifs.read((char *)buf.data(), buf.size())) { + throw std::runtime_error(path+":"+std::strerror(errno)); + }*/ + return buf; +} + +int part1(Data &input) { + return 0; +} +int part2(Data &input) { + return 0; +} + +int main(int argc, char **argv) { + const std::string fname = argc>1 ? argv[1] : "test1.txt"; + std::cout << "AoC 2015 day $DAY " << fname << std::endl; + Data input = read_file<Data>(fname); + std::cout << "part1: " << part1(input) << std::endl; + std::cout << "part2: " << part2(input) << std::endl; + + return 0; +}