15
2
Every player has a number. Can yours be the farthest from them all?
Requirements
Write a Java, Python 2, or Ruby function named choose()
that accepts three arguments:
- an integer - the number of rounds already completed
- an integer - the number of players
- an array of strings - the results of each previous round
- each string is a space-separated list of integers, sorted from lowest to highest
For example, choose(2, 4, ["4 93 93 174", "1 84 234 555"])
means:
- there were already two rounds (this is the third round)
- there are a total of four players
- in the first round, the numbers chosen were 4, 93, 93, 174
- in the second round, the numbers chosen were 1, 84, 234, 555
You must return a whole number from 1 to 999 (inclusive).
For each other player, your score is the square root of the distance between your number and theirs. Your score for the round is the total of all of these scores.
100 rounds will be played. The highest total score wins!
Rules
- Your code may not use any I/O, including console, files, network, etc.
- You may not interfere with the control program or any other players.
- Programs which look like they violate the above rules will be excluded.
- Each call of a function should take under five seconds on my computer (Intel Core i5 2450M with 8GB of RAM).
- If a program throws an exception or returns an invalid value, it will be treated as if it returned 1.
- Each user may submit at most one program.
Miscellaneous
- The control program is on GitHub.
- There are three built-in players. They can be found in this answer.
- The winner will be chosen on January 28.
Leaderboard
The winner is Conservator.
Honorable mention to Gustav, the highest scoring player with a non-constant strategy.
- Conservator - 36226
- High - 36115
- FloorHugger - 35880
- NumberOne - 35791
- Overestimator - 35791
- Gustav - 35484
- Historian - 35201
- Sampler - 34960
- Incrementer - 34351
- JumpRightIn - 34074
- Vickrey - 34020
- Teenager - 33907
- Randu - 33891
- Weightlifter - 33682
- Middleman - 33647
- BounceInwards - 33529
- NastyMathematician - 33292
- Jumper - 33244
- Copycat - 33049
The full results can be found here. (I recommend disabling text wrapping.)
Do I have any way of telling which was my own number in those previous rounds? – Martin Ender – 2015-01-21T21:43:37.223
@MartinBüttner No. – Ypnypn – 2015-01-21T21:44:09.977
I'm trying to compile the controller, and I have no clue how to get org.python.core and the org.ruby. A quick google search gave me some links to jython. Is the code written in jython or something? Can you give me some links? Thanks. – Maltysen – 2015-01-22T00:49:14.480
@Maltysen It uses the Jython and JRuby jar files. I'll mention this in the GitHub readme. – Ypnypn – 2015-01-22T02:39:00.407
Cool. Thanks for the links. – Maltysen – 2015-01-22T02:54:34.780
Wait. I ran the installers but its still not working. Can't find either python or java. BTW the command I'm running is javac *.java since jruby/jython is in my path. Any clue to what I'm doing wrong? Maybe I need the standalone? – Maltysen – 2015-01-22T02:59:56.707
1I don't know any of those languages :( Could you add JavaScript? Like, run it with node.js? – Cilan – 2015-01-22T03:16:00.597
1@TheWobbuffet, I don't know any of them either. Didn't stop me from making a Python entry. – Mark – 2015-01-22T03:21:15.173
@Mark Sometimes I want to start learning a new language, but then I remind myself I'm not even intermediate in any of the languages I do know. I would be able to do this because I know the basic syntax of python, but I don't know anything about return statements and I'm too lazy to search the doc... yeah... there's also the fact that I don't know which version of python I want to learn. – Cilan – 2015-01-22T03:25:23.260
@Maltysen I'm not sure. (I used NetBeans to write, compile, and run everything.) If the Java can't be found, check to make sure the folders are correct - all players should be in KotH/src/Players/ , and the code in KotH/src/koth/ . What are the exact error messages you're facing? – Ypnypn – 2015-01-22T14:34:36.290
It gives me "PythonPlayer.java:4: error: package org.python.core does not exist" for all of them and the ruby equivelant. I'm using javac -cp jruby.jar:jythonn.jar *.java – Maltysen – 2015-01-22T23:54:16.480
Wow. Based on the current leaderboard it looks like it's just best to pick 1 or 999 all the time. – Sp3000 – 2015-01-23T00:21:20.170
Holy moly, I thought it was not a bad choice, but wow :) – clabacchio – 2015-01-23T08:49:54.200
7I think it would have been more interesting if the space was a circle/loop so that the distance between 1 and 999 is 1. That would keep the "guess a single number every turn" from dominating, since there aren't "edges" to park on. Obviously too late to change now though ;) – Geobits – 2015-01-23T14:30:31.140
@Geobits, perhaps "Keep your distance on a circle" could be a separate question. The results would be much more interesting. – Logic Knight – 2015-01-29T07:16:53.907
@CarpetPython Someone should ask that. I thought it seemed pretty obvious that picking 1 or 999 every time would be the best strategy. – KSFT – 2015-01-30T21:25:20.837
@CarpetPython Mind if I post that challenge? – KSFT – 2015-01-31T01:06:58.453
@KSFT, please do. If the "duplicate police" don't get you, I will be posting an answer for sure. – Logic Knight – 2015-01-31T04:26:00.903
@CarpetPython Why? Is it a duplicate of something else, or do you just mean this? – KSFT – 2015-01-31T04:36:19.910
I meant this. Some people may say the "circle" variant to too much like this challenge. You may have to describe how the circular aspect makes it a different puzzle needing different answers. I don't much like the duplicate rules here (as long as credit is given to earlier work), but we have inherited them from the Q&A format where it is a very good rule. – Logic Knight – 2015-01-31T06:55:53.227
@CarpetPython I just started writing the question when I realized that I don't have a controller. I don't know Java very well, so I guess I'll just write a new one in Python. Is it just supposed to take the names of files containing two programs as input and output the winner? – KSFT – 2015-01-31T14:46:38.390
@KSFT I think you only need to change line 45 of Contest.java – kaine – 2015-01-31T18:23:06.543
@CarpetPython/kaine/anyone else I'm about to post it. Am I supposed to run the control program to determine scores? Should I run it with every pair of programs? Also, I can't figure out how to compile the control program. – KSFT – 2015-01-31T19:18:57.863
Okay, I figured out how to compile the control program, but I'm still not sure what I'm supposed to do and what people who write submissions are supposed to do. – KSFT – 2015-01-31T19:48:44.180
I posted it here: https://codegolf.stackexchange.com/questions/45216/keep-your-distance-on-a-circle
– KSFT – 2015-01-31T19:56:05.797I can't get the control program to work. Do the Java submissions need to be surrounded with class declarations? – KSFT – 2015-02-01T18:15:03.443
@KSFT Yes. Use
package Players; class ProgramName {public static int choose(int ...
– Ypnypn – 2015-02-01T20:33:30.957Why only Python 2? Is there something wrong with Python 3? – ASCIIThenANSI – 2015-04-07T17:39:18.170