Skip to content

Commit

Permalink
day24 and 25 completed.
Browse files Browse the repository at this point in the history
  • Loading branch information
AlieNiT committed Feb 11, 2022
1 parent a60f443 commit 5da5c63
Show file tree
Hide file tree
Showing 3 changed files with 114 additions and 0 deletions.
74 changes: 74 additions & 0 deletions day24/part1&2.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
package code;

import java.math.BigInteger;

public class Main {
static int[] dxs = new int[]{13, 15, 15, 11, -7, 10, 10, -5, 15, -3, 0, -5, -9, 0}; // add x < >
static int[] dys = new int[]{6, 7, 10, 2, 15, 8, 1, 10, 5, 3, 5, 11, 12, 10};// add y < >
static int[] bs = new int[]{0, 0, 0, 0, 1, 0, 0, 1, 0, 1, 1, 1, 1, 1};// /1(0) or /26(1)

public static void main(String[] args) {
System.out.println(computeW(0, 0));
printZ(computeW(0, 0));
}
private static void printZ(String W) {
int z = 0;
for (int i = 0; i < 14; i++) {
z = next(z, W.charAt(i), dxs[i], dys[i], bs[i]);
System.out.println(z);
}
}
private static int next(int z, int w, int dx, int dy, int b) {
if (((z % 26) + dx) == w) {
return z / 26;
}
if (b == 0) {
return w + dy + 26 * z;
}
return -1;
}

private static int nextW(int z, int dx) {
int res = (z % 26) + dx;
if (res < 1 | res > 9)
return -1;
return (z % 26) + dx;
}

private static String computeW(int z, int i) {
int w;
if (i == 14) {
return "";
}
if (bs[i] == 1) {
w = nextW(z, dxs[i]);
if (w == -1)
return null;
z = next(z, w, dxs[i], dys[i], 1);
if (z == -1)
return null;
String nextWs = computeW(z, i + 1);
if (nextWs == null)
return null;
return w + nextWs;
}
BigInteger W = null;
int tmp;
for (int j = 1; j < 10; j++) {
w = j;
tmp = next(z, w, dxs[i], dys[i], 0);
if (tmp == -1)
continue;
String nextWs = computeW(tmp, i + 1);
if (nextWs == null)
continue;
if (W == null) {
W = new BigInteger(j + nextWs);
} else if (W.compareTo(new BigInteger(j + nextWs)) > 0) // part 1: <, part 2: >
W = new BigInteger(j + nextWs);
}
if (W == null)
return null;
return W.toString();
}
}
40 changes: 40 additions & 0 deletions day25/part1.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
field = []
next_field = []
while True:
inp = input()
if inp == "end":
break
field.append(list(inp))
next_field.append(['.'] * len(inp))


def check(f1, f2):
for i in range(len(f1)):
for j in range(len(f1[i])):
if f1[i][j] != f2[i][j]:
return False
return True


count = 0
n = len(field)
m = len(field[0])
while True:
for i in range(n):
for j in range(m):
if field[i][j] == '>' and field[i][(j + 1) % m] == '.':
next_field[i][(j + 1) % m] = '>'
elif field[i][j] == '>':
next_field[i][j] = '>'
for i in range(n):
for j in range(m):
if field[i][j] == 'v' and next_field[(i + 1) % n][j] == '.' and field[ (i + 1) % n][j] != 'v':
next_field[(i + 1) % n][j] = 'v'
elif field[i][j] == 'v':
next_field[i][j] = 'v'
count += 1
if check(field, next_field):
break
field = next_field
next_field = [['.' for _ in range(m)] for _ in range(n)]
print(count)
Binary file modified img.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 5da5c63

Please sign in to comment.