Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions src/main/java/com/aoc/days/Day1.java
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.aoc.days;
//package com.aoc.days;
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why have you commented this?


import java.io.IOException;
//import java.net.URISyntaxException;
Expand All @@ -12,9 +12,9 @@
public class Day1 {

public static void main(String[] args) throws IOException { //}, URISyntaxException {
Stream<String> lines = Files.lines(Path.of("src/main/resources/day1.txt"));
// Stream<String> lines = Files.lines(Path.of(Day1.class.getClassLoader().getResource("day1.txt").toURI()));
// lines.forEach(System.out::println);
Stream<String> lines = Files.lines(Path.of("day1.txt"));
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why this is done?

//Stream<String> lines = Files.lines(Path.of(Day1.class.getClassLoader().getResource("day1.txt").toURI()));
//lines.forEach(System.out::println);

List<Long> calories = new ArrayList<>();
AtomicLong tempCalorie = new AtomicLong();
Expand All @@ -32,4 +32,4 @@ public static void main(String[] args) throws IOException { //}, URISyntaxExcept
System.out.println(calories.stream().max(Long::compare));

}
}
}
39 changes: 39 additions & 0 deletions src/main/java/com/aoc/days/Day1a.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.concurrent.atomic.AtomicLong;
import java.util.stream.Stream;

public class Day1a {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is this part 2? then use a better class name: Day1P2 or Day1Part2 etc.

public static void main(String args[]) throws IOException{
Stream<String> lines = Files.lines(Path.of("day1.txt"));
//lines.forEach(System.out::println); // to print input.
int sum =0;
List<Long> calories = new ArrayList<>(); // so that not need to define size in list
AtomicLong tempCalories = new AtomicLong();
tempCalories.set(0);
lines.forEach(line -> {
if(line.isBlank()) {
calories.add(tempCalories.get());
tempCalories.set(0);
}
else {
int n = Integer.parseInt(line);
tempCalories.set(n+tempCalories.get());
}
});
System.out.println(calories.stream().max(Long::compare));
Collections.sort(calories);
System.out.println(calories);
System.out.println(calories.size());
for(int i=calories.size();i<238;i--) {
//calories = new List<Long>();
sum += calories.get(i);
}
System.out.println(sum);

}
}
99 changes: 99 additions & 0 deletions src/main/java/com/aoc/days/Day2.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.ArrayList;
import java.util.List;
import java.util.function.Consumer;
import java.util.stream.Stream;

// rock paper siccisor
// a = x = rock = 1
//b = y = papr = 2 win = 6 and loosse = 0
//c = z = scissior = 3 draw =3

public class Day2 {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  1. draw = true -> end
  2. draw = false -> win = false -> user wins

static int score1=0; static int score2 = 0;

static boolean win(char c,char d) {
if(c==('A')) {
return (d==('Z'));
}
else if (c==('B')) {
return d==('X');
}
else {
return d==('Y');
}
}

static boolean draw(char c, char d) {
if(c==('A')) {
return (d==('X'));
}
else if (c==('B')) {
return d==('Y');
}
else {
return d==('Z');
}
}


static public void main(String args[]) throws IOException {
Stream<String> lines = Files.lines(Path.of("day2.txt"));

lines.forEach(line -> {
if (line.length() == 3) {
char p1 = line.charAt(0);
char p2 = line.charAt(2);
if(win(p1,p2)) {
//System.out.println("Player 1 win");
if(p1=='A' && p2=='Z') {
score1+=7;
score2+=3;
}
else if(p1=='B' && p2=='X') {
score1+=8;
score2+=1;
}
else {
score1+=9;
score2+=2;
}

}
else if(draw(p1, p2)) {
//System.out.println("Draw");
score1+=3;
score2+=3;

}
else {
//System.out.println("player 2 win");
if(p1=='C' && p2=='X'){
score1+=3;
score2+=7;
}
else if(p1=='A' && p2=='Y'){
score1+=1;
score2+=8;
}
else {
score1+=2;
score2+=9;
}
}


} else {
System.out.println("Not a valid input!");
}
});
System.out.println(score1+" "+score2);
}
}