day 1 in the books
This commit is contained in:
@@ -5,8 +5,25 @@ import java.util.Scanner;
|
||||
|
||||
public class Day00 {
|
||||
public static void main(String[] args) {
|
||||
try (Scanner scanner = new Scanner(new FileReader("resources/00/input")).useDelimiter("\\R")) {
|
||||
StringBuilder sb = new StringBuilder();
|
||||
part1();
|
||||
part2();
|
||||
}
|
||||
|
||||
private static void part1() {
|
||||
try (Scanner scanner = new Scanner(new FileReader("resources/inputs/00/input")).useDelimiter("\\R")) {
|
||||
while (scanner.hasNext()) {
|
||||
sb.append(scanner.next());
|
||||
sb.append("\n");
|
||||
}
|
||||
String input = sb.toString();
|
||||
System.out.println(input);
|
||||
} catch (Exception e) {
|
||||
System.out.println(e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
private static void part2() {
|
||||
try (Scanner scanner = new Scanner(new FileReader("resources/inputs/00/input")).useDelimiter("\\R")) {
|
||||
while (scanner.hasNext()) {
|
||||
sb.append(scanner.next());
|
||||
sb.append("\n");
|
||||
|
||||
69
src/Day01.java
Normal file
69
src/Day01.java
Normal file
@@ -0,0 +1,69 @@
|
||||
package src;
|
||||
|
||||
import java.io.FileReader;
|
||||
import java.util.Scanner;
|
||||
|
||||
public class Day01 {
|
||||
public static void main(String[] args) {
|
||||
part1();
|
||||
part2();
|
||||
}
|
||||
|
||||
private static void part1() {
|
||||
try (Scanner scanner = new Scanner(new FileReader("resources/inputs/01/input")).useDelimiter("\\R")) {
|
||||
int dial = 50;
|
||||
int password = 0;
|
||||
while (scanner.hasNext()) {
|
||||
String instruction = scanner.next();
|
||||
int change = Integer.parseInt(instruction.substring(1));
|
||||
switch (instruction.charAt(0)) {
|
||||
case 'L' -> {
|
||||
dial = (dial - change + 100) % 100;
|
||||
}
|
||||
case 'R' -> {
|
||||
dial = (dial + change) % 100;
|
||||
}
|
||||
}
|
||||
if (dial == 0) {
|
||||
password += 1;
|
||||
}
|
||||
}
|
||||
System.out.println(password);
|
||||
} catch (Exception e) {
|
||||
System.out.println(e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
// this is the inefficient way to do it, but it's also accurate!
|
||||
private static void part2() {
|
||||
try (Scanner scanner = new Scanner(new FileReader("resources/inputs/01/input")).useDelimiter("\\R")) {
|
||||
int dial = 50;
|
||||
int password = 0;
|
||||
while (scanner.hasNext()) {
|
||||
String instruction = scanner.next();
|
||||
int change = Integer.parseInt(instruction.substring(1));
|
||||
switch (instruction.charAt(0)) {
|
||||
case 'L' -> {
|
||||
for (int i = 0; i < change; i++) {
|
||||
dial = (dial - 101) % 100;
|
||||
if (dial == 0) {
|
||||
password += 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
case 'R' -> {
|
||||
for (int i = 0; i < change; i++) {
|
||||
dial = (dial + 1) % 100;
|
||||
if (dial == 0) {
|
||||
password += 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
System.out.println(password);
|
||||
} catch (Exception e) {
|
||||
System.out.println(e.getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
10
today.sh
10
today.sh
@@ -1,6 +1,6 @@
|
||||
#!/bin/bash
|
||||
|
||||
__year=2024
|
||||
__year=2025
|
||||
|
||||
__day="${1}"
|
||||
if [ "${__day}" == "" ]; then
|
||||
@@ -8,15 +8,15 @@ if [ "${__day}" == "" ]; then
|
||||
fi
|
||||
|
||||
padded=$(printf "%02g" ${__day})
|
||||
mkdir -p ${padded}/inputs
|
||||
touch ${padded}/inputs/testinput
|
||||
if [ ! -f "${padded}/inputs/input" ]; then
|
||||
mkdir -p src/resources/inputs/${padded}
|
||||
touch src/resources/inputs/${padded}/testinput
|
||||
if [ ! -f "src/resources/inputs/${padded}/input" ]; then
|
||||
curl -s \
|
||||
-A "https://git.yetaga.in/alazyreader/AdventOfCode${__year}/" \
|
||||
-H "Cookie: session=`cat .cookie`" https://adventofcode.com/${__year}/day/${__day##0}/input > "src/resources/inputs/${padded}/input"
|
||||
fi
|
||||
if [ ! -f "src/Day${padded}.java" ]; then
|
||||
cp main.java.tmpl src/Day${padded}.java
|
||||
gsed -i '' "s/00/${padded}/g" src/Day${padded}.java
|
||||
sed -i '' "s/00/${padded}/g" src/Day${padded}.java
|
||||
fi
|
||||
open "https://adventofcode.com/${__year}/day/${__day##0}"
|
||||
|
||||
Reference in New Issue
Block a user