-
Notifications
You must be signed in to change notification settings - Fork 704
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #413 from toclean/master
#9 Ported hot_potato to typescript and c++
- Loading branch information
Showing
2 changed files
with
41 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); |