Skip to content

Commit

Permalink
Solved coin problem
Browse files Browse the repository at this point in the history
Teleporter had code 6
  • Loading branch information
Gyebro committed Jan 8, 2018
1 parent cf60edf commit 17751d6
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 0 deletions.
1 change: 1 addition & 0 deletions code6.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
yjdhyEgpXPgW
52 changes: 52 additions & 0 deletions main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -290,6 +290,35 @@ void add_input(string line) {
}
}

const string coins[] = {"red", "corroded", "shiny", "concave", "blue"};
vector<int> values = {2, 3, 5, 7, 9};

void permute(vector<int> a, int i, int n, vector<int>& s) {
int j;
if (i == n) {
if (a[0]+a[1]*a[2]*a[2]+a[3]*a[3]*a[3]-a[4] == 399) {
s = a;
}
} else {
for (j = i; j <= n; j++) {
swap(a[i], a[j]);
permute(a, i+1, n, s);
swap(a[i], a[j]);
}
}
}

void solve_coin_problem() {
vector<int> solution;
permute(values, 0, 4, solution);
for (int v : solution) {
for (size_t i=0; i<values.size(); i++) {
if (values[i] == v) add_input("use "+coins[i]+" coin\n");
}
}
}


int main() {
// Initialize registers and memory
cout << "Initializing registers and memory\n";
Expand Down Expand Up @@ -329,7 +358,30 @@ int main() {
"take can\n"
"use can\n"
"use lantern\n"
"west\n"
"ladder\n"
"darkness\n"
"continue\n"
"west\nwest\nwest\nwest\n"
"north\n"
"take red coin\n"
"north\n"
"west\n"
"take blue coin\n"
"up\n"
"take shiny coin\n"
"down\neast\neast\n"
"take concave coin\n"
"down\n"
"take corroded coin\n"
"up\nwest\n"
);

solve_coin_problem();

add_input("north\n"
"take teleporter\n"
"use teleporter\n" /* Code 6 */
);

// Run the program
Expand Down

0 comments on commit 17751d6

Please sign in to comment.