6 kyu

Shortest Code : Guess the Hat

Description:

Shortest Code : Guess the Hat
(Code length limit: 80 chars)

This is the challenge version of coding 3min series. If you feel difficult, please complete the simple version

Task

Maybe you know such a game (or a magic), there are three hats (or cups, or other containers) on the table, one of them put in a thing(A ball, or a coin, or other small things), at this time quickly moving three hats(exchange their position), After stop moving, Let the player guess which hat has something in it.

Let's us play the game in this kata.

Suppose we have three hats on the table, Their positions are 1, 2 and 3. Put a thing in the middle of the hat(position 2), and then begin moving...

Give you a string array exchange, Array elements are similar to "1-2"(it means 1 and 2 exchange position),"3-1"(1 and 3 exchange position)...

Finally, please return the position of the hat (which one hidden something), "1", "2", or "3"(String form)

Examples

example1:
exchange=["1-2","1-3","2-3"]
at the beginning, put a ball into a hat at position 2
"1-2"==> exchange 1 and 2, then the ball move to position 1
"1-3"==> exchange 1 and 3, then the ball move to position 3
"2-3"==> exchange 2 and 3, then the ball move to position 2
the exchange ends, and finally, the ball at position 2.
So, sc(["1-2","1-3","2-3"]) should return "2"

example2:
exchange=["1-2","2-3","1-3"]
at the beginning, put a ball into a hat at position 2
"1-2"==> exchange 1 and 2, then the ball move to position 1
"2-3"==> exchange 2 and 3, then the ball still at position 1
"1-3"==> exchange 1 and 3, then the ball move to position 3
the exchange ends, and finally, the ball at position 3.
So, sc(["1-2","1-3","2-3"]) should return "3"

example3:
exchange=["1-2","1-3","2-3","2-1","3-1","3-2"]
ball moving: 2-->1-->3-->2-->1-->3--2
finally, the ball at position 2.
sc(["1-2","1-3","2-3","1-2","1-3","2-3"]) should return "2"

Code length calculation

In javascript, we can't get the user's real code, we can only get the system compiled code. Code length calculation is based the compiled code.

For example:

If you typed sc=x=>x+1
after compile, it will be:sc=function(x){return x+1;}

Series

Puzzles
Games
Restricted

Stats:

CreatedApr 13, 2016
PublishedApr 14, 2016
Warriors Trained227
Total Skips2
Total Code Submissions835
Total Times Completed124
JavaScript Completions124
Total Stars6
% of votes with a positive feedback rating94% of 64
Total "Very Satisfied" Votes56
Total "Somewhat Satisfied" Votes8
Total "Not Satisfied" Votes0
Ad
Contributors
  • myjinxin2015 Avatar
  • smile67 Avatar
  • kazk Avatar
Ad