Skip to content

Commit 6b80cc9

Browse files
committed
Make sure to pick four different numbers for 22.2
1 parent 6c40530 commit 6b80cc9

File tree

2 files changed

+10
-4
lines changed

2 files changed

+10
-4
lines changed

day22/experiments/day22.cpp

+3
Original file line numberDiff line numberDiff line change
@@ -57,10 +57,13 @@ int64_t findBestScore(std::vector<int64_t> input) {
5757
int64_t bound = 9;
5858
for (int64_t x1 = -bound; x1 <= bound; x1++) {
5959
for (int64_t x2 = -bound; x2 <= bound; x2++) {
60+
if (x1 == x2) continue;
6061
std::cout << "Searching (" << x1 << ", " << x2 << ")" << std::endl;
6162
#pragma omp parallel for
6263
for (int64_t x3 = -bound; x3 <= bound; x3++) {
64+
if (x3 == x2 || x3 == x1) continue;
6365
for (int64_t x4 = -bound; x4 <= bound; x4++) {
66+
if (x4 == x3 || x4 == x2 || x4 == x1) continue;
6467
int64_t n = score(input, x1, x2, x3, x4);
6568
if (n > bestScore) {
6669
std::cout << "New best: (" << x1 << ", " << x2 << ", " << x3 << ", " << x4 << ") -> " << n << std::endl;

day22/src/day22.dart

+7-4
Original file line numberDiff line numberDiff line change
@@ -48,11 +48,14 @@ int score(List<int> input, int x1, int x2, int x3, int x4) {
4848
int findBestScore(List<int> input) {
4949
int bestScore = 0;
5050
int bound = 9;
51-
for (var x1 = -bound; x1 <= bound; x1++) {
52-
for (var x2 = -bound; x2 <= bound; x2++) {
51+
for (int x1 = -bound; x1 <= bound; x1++) {
52+
for (int x2 = -bound; x2 <= bound; x2++) {
53+
if (x1 == x2) continue;
5354
print("Searching ($x1, $x2, ...)");
54-
for (var x3 = -bound; x3 <= bound; x3++) {
55-
for (var x4 = -bound; x4 <= bound; x4++) {
55+
for (int x3 = -bound; x3 <= bound; x3++) {
56+
if (x3 == x2 || x3 == x1) continue;
57+
for (int x4 = -bound; x4 <= bound; x4++) {
58+
if (x4 == x3 || x4 == x2 || x4 == x1) continue;
5659
int n = score(input, x1, x2, x3, x4);
5760
if (n > bestScore) {
5861
bestScore = n;

0 commit comments

Comments
 (0)