HackerRank aims to build a fun place for programmers to hang out
hackerrank.com
hackerrank.com
* I'm having issues with the terminal where what I type is not always on the bottom line. Also, the up/down arrows for getting command history don't always show what I would expect and I get latency fairly frequently.
Also spoiler here's an algorithm that will let you win every time where it is possible to win. I debated a bit about posting this, but if I didn't I'm sure somebody else would.
1. If number is divisible by 6, do not play since you'll always lose.
2. If the number is less than 6, do not play since it doesn't allow you to take them all in the first move, despite what the instructions suggest.
3. Otherwise, your first pick should be a number that takes the remaining number to a multiple of six (see rule #1). Then, you should look at what number the computer picks and subtract it from six when you pick your number.
Getting to the top of the leaderboard is dependent on understanding this and how much time you're willing to spend playing.
Or you could write a bot that plays the game for you. Then getting to the top of the leaderboard depends on who started their bot first and the quality of bots' network connections.
First it seemed to not be taking any input, and let me enter about 10 different numbers without response. Then, it showed me the back and forth between me and the computer for about half of those numbers, but the total never changed after that.
A few observations:
- If you start <= 6, you will always lose, since you have to choose 1 less than the starting number.
- Whoever gets 6 on their turn will always lose.
- If you start between 7 and 11, you'll always win.
- If you start at 12 or higher, you'll usually lose, since the computer will try to get you to 6.
Still fun for a few minutes atleast. No idea how people are winning 20+ games.
Ah, but you can also try to get the computer to 6 ;).
I won over 20 games by just spending a few minutes manually running the algorithm described elsewhere here and I imagine anyone who hasn't won hundreds or thousands of games probably did the same. (If you're going to write a bot, might as well let it run for awhile and see if you can max out the leaderboard.)
If you start with 61 pick one and the computer has 60, say it picks 4 and you have 56 pick 2 so you hand it 54. Repeat until you win.
recursive@hackerrank:~$ challenge 1
Playing a game for N: 1
Please provide a number between 1 or 0.
How many candies you want to pick?:
At this point, I get stuck in a loop that I've only been able to get out of with f5.Would more seasoned people out there agree that a clean slate is better than a low ranking on sites like InterviewStreet (or HackerRank if it gets big)?
How do you script something like this? I tried looking at the source and then using the chrome console to input jQuery commands, but something really weird happened. I could replace just about any element on the screen except the one that mattered!
I could type "challenge 8" into the console and then running a $('tester').text() would return "challenge 8" as expected. But $('tester').text('challenge 9') wouldn't update the screen. I tried for a good hour to find a way to update the text in that element, with no luck (short of removing the whole thing from the dom).
(see http://postimage.org/image/c3xkrg8y3/ )
Also how do you send a carriage return? Inserting a newline didn't seem to do the trick. Anyone? As much as I love a challenge, beating my head against this one issue doesn't yield much education / time spent.
I'm not familiar with sending keystrokes in JavaScript (from some brief searching I think it is possible; I just don't know the best practice), but for something like this, you could just do it at the operating system level. A long time ago I automated an annoying user interface for a program we had to use at work by writing some vbscript that changes windows and does a combination of sendkeys and sleep.
Unfortunately, just sending keystrokes isn't very robust since it isn't reading what is going on in the UI and if something random happens (the site behaves other than expected, you touch a key / move the mouse, a scheduled program runs, etc) the script could get out of sync. Fortunately, the consequences of an error are so low here that such a solution would be good enough.
--------- 403 Forbidden
This Web site is blocked: http://hackerrank.com/ As part of our ongoing effort to protect the bank and its information, the Web site you are trying to reach is blocked because it is classified in a category the bank considers to have certain risks. The bank blocks access to a number of Web site classifications including but not limited to Web mail sites, Personal Network Storage, and other categories to comply with regulations, protect customer and company information, and to be consistent with industry standards and practices.
This Web site is categorized as Games. ---------
Hope this will be fix soon, cool idea
Did you not test this at all before promoting it? I am brand new to programming and even I know that testing is important.
Resulting in a negative.
== apply: Apply to join our awesome team.
Usage: apply <a profile url> <why do you want to apply>
Does it have anything to do with my mad skillz in solving the puzzle perhaps? ;-)TypeError: Cannot call method 'toLowerCase' of undefined [http://www.hackerrank.com/assets/application-18e8ea124a72677...]
but I can't believe I just spent 20 minutes trying to come up with a scripted solution. Nerd sniped again!
Is there a login link I can visit?
Playing a game for N: 10 Your move: '4'. Computer's move: '1'. Remaining candies: '5' Please provide a number between 1 or 5. Your move: '5'. Computer's move: '5'. Sorry! You lost the game.
I also write new bot by python for hackerrank challenge. Check out my code at https://github.com/kiennt/hackerrank-bot
Happy hacking :)
However, not to be a wet blanket, but it's rather simple to construct a winning algorithm, particularly if you can both choose the same starting number and always go first (and choose the same starting number multiple times). If I had a few extra minutes at work right now, I'd take a stab at it.
...That is, unless that's the entire point?