Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit da87247

Browse files
Solve day 25 2015: Let It Snow
1 parent 4b7d419 commit da87247

File tree

1 file changed

+32
-3
lines changed
  • src/main/java/com/sbaars/adventofcode/year15/days

1 file changed

+32
-3
lines changed

‎src/main/java/com/sbaars/adventofcode/year15/days/Day25.java‎

Lines changed: 32 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,21 +3,50 @@
33
import com.sbaars.adventofcode.year15.Day2015;
44

55
public class Day25 extends Day2015 {
6+
private static final long FIRST_CODE = 20151125L;
7+
private static final long MULTIPLIER = 252533L;
8+
private static final long DIVISOR = 33554393L;
9+
610
public Day25() {
711
super(25);
812
}
913

1014
public static void main(String[] args) {
11-
new Day25().printParts();
15+
Day25 day = new Day25();
16+
day.printParts();
17+
new com.sbaars.adventofcode.network.Submit().submit(day.part1(), 2015, 25, 1);
1218
}
1319

1420
@Override
1521
public Object part1() {
16-
return "";
22+
String input = day().trim();
23+
int targetRow = Integer.parseInt(input.replaceAll(".*row (\\d+).*", "1ドル"));
24+
int targetCol = Integer.parseInt(input.replaceAll(".*column (\\d+).*", "1ドル"));
25+
return findCode(targetRow, targetCol);
1726
}
1827

1928
@Override
2029
public Object part2() {
21-
return "";
30+
return "Merry Christmas!"; // There is no part 2 for Day 25
31+
}
32+
33+
private long findCode(int targetRow, int targetCol) {
34+
// Calculate the position in the sequence
35+
int position = getPositionInSequence(targetRow, targetCol);
36+
37+
// Calculate the code at that position
38+
long code = FIRST_CODE;
39+
for (int i = 1; i < position; i++) {
40+
code = (code * MULTIPLIER) % DIVISOR;
41+
}
42+
return code;
43+
}
44+
45+
private int getPositionInSequence(int row, int col) {
46+
// The position is the sum of all numbers in the diagonal before the target position
47+
// plus the position in the current diagonal
48+
int diagonalNum = row + col - 1;
49+
int positionsBeforeDiagonal = (diagonalNum * (diagonalNum - 1)) / 2;
50+
return positionsBeforeDiagonal + col;
2251
}
2352
}

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /