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
- Bug in Apple
- Father and Son
- Jumping Dutch act
- Planting Trees
- Reading a Book
- Eat watermelon
- Special factor
- Symmetric Sort
- Are they symmetrical?
- Guess the Hat
- Find the murderer
- Give me the equation
- Balance Attraction
- Max Value
- Regular expression compression
- Remove screws I
- Remove screws II
- Collatz Array(Split or merge)
- Trypophobia
- Virus in Apple
- Waiting for a Bus
- Tidy up the room
Similar Kata:
Stats:
Created | Apr 13, 2016 |
Published | Apr 14, 2016 |
Warriors Trained | 227 |
Total Skips | 2 |
Total Code Submissions | 835 |
Total Times Completed | 124 |
JavaScript Completions | 124 |
Total Stars | 6 |
% of votes with a positive feedback rating | 94% of 64 |
Total "Very Satisfied" Votes | 56 |
Total "Somewhat Satisfied" Votes | 8 |
Total "Not Satisfied" Votes | 0 |