init
commit
cf61ecf2ab
@ -0,0 +1,2 @@
|
||||
.vscode
|
||||
*.txt
|
@ -0,0 +1,2 @@
|
||||
Attempts at the Advent of Code daily challenges in C++/Go/JS.
|
||||
Boilerplate code for reading in input files in boilerplate/ for each language.
|
@ -0,0 +1,46 @@
|
||||
#include "boilerplate.hh"
|
||||
|
||||
// newline separated split
|
||||
std::vector<std::string> readFile(std::string file){
|
||||
std::vector<std::string> outputVec;
|
||||
|
||||
std::ifstream inputFile(file);
|
||||
if (!inputFile.is_open()){
|
||||
std::cerr << "File " << file << "not found";
|
||||
exit(1);
|
||||
}
|
||||
|
||||
std::string line;
|
||||
while(getline(inputFile, line)){
|
||||
outputVec.push_back(line);
|
||||
}
|
||||
return outputVec;
|
||||
}
|
||||
|
||||
// newline, and delimited split
|
||||
InputArrays readFile(std::string file, char delim){
|
||||
InputArrays outputVec;
|
||||
|
||||
std::ifstream inputFile(file);
|
||||
if (!inputFile.is_open()){
|
||||
std::cerr << "File " << file << "not found";
|
||||
exit(1);
|
||||
}
|
||||
|
||||
std::string line;
|
||||
while(getline(inputFile, line)){
|
||||
outputVec.push_back(ssplit(line, delim));
|
||||
}
|
||||
return outputVec;
|
||||
}
|
||||
|
||||
std::vector<std::string> ssplit(std::string str, char delimiter){
|
||||
std::vector<std::string> output;
|
||||
std::istringstream iss(str);
|
||||
|
||||
std::string split;
|
||||
while(getline(iss, split, delimiter)){
|
||||
output.push_back(split);
|
||||
}
|
||||
return output;
|
||||
}
|
@ -0,0 +1,15 @@
|
||||
#ifndef BOILERPLATE_HH
|
||||
#define BOILERPLATE_HH
|
||||
|
||||
#include <iostream>
|
||||
#include <fstream>
|
||||
#include <sstream>
|
||||
#include <vector>
|
||||
|
||||
using InputArrays = std::vector<std::vector<std::string>>;
|
||||
|
||||
InputArrays readFile(std::string, char);
|
||||
std::vector<std::string> readFile(std::string);
|
||||
std::vector<std::string> ssplit(std::string, char);
|
||||
|
||||
#endif
|
@ -0,0 +1,30 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"bufio"
|
||||
"log"
|
||||
"os"
|
||||
)
|
||||
|
||||
func readFile(filename string) []string {
|
||||
file, err := os.Open(filename)
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
defer file.Close()
|
||||
|
||||
scanner := bufio.NewScanner(file)
|
||||
scanner.Split(bufio.ScanLines)
|
||||
|
||||
var ret []string
|
||||
|
||||
for scanner.Scan() {
|
||||
ret = append(ret, scanner.Text())
|
||||
}
|
||||
|
||||
return ret
|
||||
}
|
||||
|
||||
func main() {
|
||||
|
||||
}
|
@ -0,0 +1,8 @@
|
||||
const fs = require("fs")
|
||||
|
||||
const input = fs.readFileSync("input.txt", "utf-8", (err, data) => {
|
||||
if (err) {
|
||||
console.error(err)
|
||||
return
|
||||
}
|
||||
}).split("\n").map(line => line.split(","))
|
Loading…
Reference in New Issue