Skip to content

Commit

Permalink
Merge pull request #413 from toclean/master
Browse files Browse the repository at this point in the history
#9 Ported hot_potato to typescript and c++
  • Loading branch information
OtacilioN authored Oct 29, 2019
2 parents 44ef647 + ff2b485 commit ca98ce5
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 0 deletions.
30 changes: 30 additions & 0 deletions Hot Potato/hot_potato.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
#include <iostream>
#include <string.h>
#include <queue>

using namespace std;

string hot_potato(queue<string> names, int repetitions) {
for (int i = 0; i < repetitions; i++) {
string person = names.front();
names.pop();
names.push(person);
}

string personWhoGotCaught = names.front();
names.pop();
return personWhoGotCaught;
}

int main() {
queue<string> names;
names.push("Nick");
names.push("John");
names.push("Connor");
names.push("Mike");
names.push("Paul");

cout << hot_potato(names, 12);

return 0;
}
11 changes: 11 additions & 0 deletions Hot Potato/hot_potato.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
function hot_potato_game(names: string[], repetitions: number): string {
for (let i = 0; i < repetitions; i++) {
const person = names.pop();
names = [person, ...names];
}

return names.pop();
}

const loser = hot_potato_game(['Nick', 'John', 'Connor', 'Mike', 'Paul'], 12);
console.log(loser);

0 comments on commit ca98ce5

Please sign in to comment.