573
\$\begingroup\$

This "sandbox" is a place where Code Golf users can get feedback on prospective challenges they wish to post to main. This is useful because writing a clear and fully specified challenge on your first try can be difficult, and there is a much better chance of your challenge being well received if you post it in the sandbox first.

Sandbox FAQ

Posting

To post to the sandbox, scroll to the bottom of this page and click "Answer This Question". Click "OK" when it asks if you really want to add another answer.

Write your challenge just as you would when actually posting it, though you can optionally add a title at the top. You may also add some notes about specific things you would like to clarify before posting it. Other users will help you improve your challenge by rating and discussing it.

When you think your challenge is ready for the public, go ahead and post it, and replace the post here with a link to the challenge and delete the sandbox post.

Discussion

The purpose of the sandbox is to give and receive feedback on posts. If you want to, feel free to give feedback to any posts you see here. Important things to comment about can include:

  • Parts of the challenge you found unclear
  • Comments addressing specific points mentioned in the proposal
  • Problems that could make the challenge uninteresting or unfit for the site

You don't need any qualifications to review sandbox posts. The target audience of most of these challenges is code golfers like you, so anything you find unclear will probably be unclear to others.

If you think one of your posts requires more feedback, but it's been ignored, you can ask for feedback in The Nineteenth Byte. It's not only allowed, but highly recommended! Be patient and try not to nag people though, you might have to ask multiple times.

It is recommended to leave your posts in the sandbox for at least several days, and until it receives upvotes and any feedback has been addressed.

Other

Search the sandbox / Browse your pending proposals

The sandbox works best if you sort posts by active.

To add an inline tag to a proposal, use shortcut link syntax with a prefix: [tag:king-of-the-hill]. To search for posts with a certain tag, include the name in quotes: "king-of-the-hill".

\$\endgroup\$
2
  • \$\begingroup\$ What if I posted on the sandbox a long time ago and get no response? \$\endgroup\$
    – None1
    Commented May 15 at 14:05
  • \$\begingroup\$ @None1 If you don't get feedback for a while you can ask in the nineteenth byte \$\endgroup\$
    – mousetail
    Commented May 29 at 13:27

4761 Answers 4761

1
90 91
92
93 94
159
0
\$\begingroup\$

Factorize any number using a set of predetermined random numbers

For instance:

With the randomly generated set [1,2,3,5,8], factorizing 10 would give the result [2,5] as in 2*5=10.

  • If a number can not be factorized using the provided set, indicate so. Using the same set, factorizing 13 would show an error or an empty list.

  • Generated sets should contain less than 64 numbers.

Bonuses

The score is given by floor (code length * (1 - 0,1 * # of bonuses))

  • If a number can not be factorized, try to fix it using addition. In the previous example, factorizing 13 could give [2,5] and [3] as in 2*5+3=13.

  • If a number can not be factorized, try to fix it using subtraction. In the previous example, factorizing 14 could give [3,5] and [1] as in 3*5-1=14.

  • When generating a set, filter out primes and powers of 2.

\$\endgroup\$
2
  • 2
    \$\begingroup\$ If posted like this, I would vote to close as not clear what you're asking. At the very least you need to specify what the input and output are. Then either ditch the bonuses or make them clearer: what exactly does "fix it using addition" mean? E.g. with [2,3] 17 do we get 2*2*3+2+3? \$\endgroup\$ Commented Jun 10, 2014 at 15:48
  • \$\begingroup\$ Test comment, ignore. math \$\endgroup\$
    – gxtaillon
    Commented Jul 22, 2014 at 0:05
0
\$\begingroup\$

Find the a Strong Prime

What's a String Prime? Wikipedia:

In cryptography, a prime number p is strong if the following conditions are satisfied.[1]

  • p is sufficiently large to be useful in cryptography; typically this requires p to be too large for plausible computational resources to enable a cryptanalyst to factorise products of p multiplied by other strong primes.
  • p-1 has large prime factors. That is, p = a_1 q_1 + 1 for some integer a_1 and large prime q_1.
  • q_1-1 has large prime factors. That is, q_1 = a_2 q_2 + 1 for some integer a_2 and large prime q_2.
  • p+1 has large prime factors. That is, p = a_3 q_3 - 1 for some integer a_3 and large prime q_3.

Input

Your program must receive a number of bits 16 <= x <= 60. This can be a method definition, command line argument, or stdin.

Output

Print and/or return a strong prime of exactly the given bit length.

Other rules:

  • All variables in the below conditions refer to the wikipedia variables.
  • Do not worry about condition 1 from wikipedia.
  • For the rest of these rules, the notation |x| means the number of bits in x.
  • |q_2| >= 0.4 |p|.
  • You may not use any external tools. Other input data or precalculation counts against the length of your program even if it's in a different file or command line.
  • You are allowed (and even encouraged) to use the algorithms in this paper (thanks @PeterTaylor!) but it is not a requirement.

\$\endgroup\$
7
  • \$\begingroup\$ Three things. 1. 10 minutes is probably not enough for even good implementations of basic sieves. Are you expecting people to implement sophisticated sieves, or did you intend to allow probabilistic primality testing? 2. Why the "no more than 3 bits" constraints? There are plenty of definitions going around, but from cursory reading it seems that most of them would consider |q_2| >= 0.4 |p| to be sufficient. 3. Have you done a reference implementation to test that strong primes by your definition are sufficiently frequent for the time constraint to be feasible? \$\endgroup\$ Commented Jun 17, 2014 at 16:15
  • \$\begingroup\$ In my above comment, || should be taken to mean length in bits rather than absolute value. \$\endgroup\$ Commented Jun 17, 2014 at 19:29
  • \$\begingroup\$ @PeterTaylor how's that? \$\endgroup\$
    – durron597
    Commented Jun 17, 2014 at 20:13
  • \$\begingroup\$ Is "other external tools" meant to include IsPrime functions? \$\endgroup\$ Commented Jun 17, 2014 at 20:38
  • \$\begingroup\$ @PeterTaylor yes. but maybe that's not a good rule in this case? \$\endgroup\$
    – durron597
    Commented Jun 17, 2014 at 20:46
  • \$\begingroup\$ Probably needs some input from Mathematica users, or you risk creating a restriction which they can waltz straight past. \$\endgroup\$ Commented Jun 17, 2014 at 21:10
  • \$\begingroup\$ According to the OEIS, Miller-Rabin can be relied on to give accurate results for numbers up to at least 2^61 when tested with the first 9 prime numbers (i.e., a(9)>2^61). If the limit for p is extended to 2^64, then the first 12 primes will have to be tested. This shouldn't take long. \$\endgroup\$
    – r3mainer
    Commented Jun 18, 2014 at 14:40
0
\$\begingroup\$

Code Looking For 0x6C, 0x6F, 0x76, and 0x65 In All the Wrong Places

Write the shortest code that finds all instances of love" on the system. For this challenge love shall be defined as the bytes 0x6C, 0x6F, 0x76, and 0x65 in sequential order. It should look for love within files, in memory, and in file names. The code should run on Ubuntu to be tested. Assume you have whatever access you need to perform these operations.

Winning Criteria

The code will be run under a Ubuntu 12.04 instance that is hosted on a dual boot Windows 8.1 machine. There will be 1 file on each of the hard drives named love. The grub loader has a configuration called love. A program will be running in the background. If you find all the instances and have the shortest code. You will win. The contest will close XX/XX/YYYY.

\$\endgroup\$
4
  • 2
    \$\begingroup\$ What's the winning criterion? How do you even test that submissions actually do find every single occurrence of his byte sequence? \$\endgroup\$ Commented Jun 2, 2014 at 9:01
  • \$\begingroup\$ Will this question be open in a browser, and hence held in memory, when you run the programs? Will the rival programs all be present on your machine while they are being run? I guess at least some of them will contain love... \$\endgroup\$ Commented Jun 4, 2014 at 21:02
  • 1
    \$\begingroup\$ What does it mean to "find" it? Does a memory/file/offset location need to be output for each one? \$\endgroup\$
    – Geobits
    Commented Jun 4, 2014 at 21:45
  • \$\begingroup\$ That's a really good call out. I will have to think a little. \$\endgroup\$
    – ojblass
    Commented Jun 4, 2014 at 21:52
0
\$\begingroup\$

Saving Eve

Background

In the year 1946 the organisation Illuminati launched their first intelligence collecting satellite - called Eve - into orbit around the earth. Onboard it contains a highly sophisticated set of sensors capable of eavesdropping on every telephone call in the world. All suspicious calls are recorded along with all ascertainable information about the caller and receiver. Eve then relays everything to Illuminati's office in Venice.

However, recently the growing amount of radio communication in space and on earth has started to interfere with Eve's downlink and uplink to and from the Venice office, which has resulted in spurious intermixing of the recordings of suspicious calls with the local weather report.

...we are to drop the bomb ... ...sunny and 28 degrees! In fair Verona... ...shoot them down...

Seeing as this interferes with Illuminati's ability to control all governments of the world, the error correction encoding firmware of Eve must be upgraded.

Objective

You have been hired to write the new firmware for Eve. You have realised that the only sufficiently robust and efficient encoding is to use the extended binary Golay code, which encodes 12-bits into 24-bits of data. Luckily Eve was built in the 40's, before the 8-bit byte convention, so all the data that Eve processes is already in 12-bit chunks.

So you have to write a function or a program that takes one 12-bit chunk (as an integer) and outputs or returns a 24-bit chunk (again as an integer) according to the extended binary Golay code.

And you have to write a decoding function or program that takes one 24-bit chunk (again as a an integer) and outputs the decoded 12-bits, with a 16th bit set (2^15) if any correctable errors were detected, and a 20th bit set (2^19) if any uncorrectable errors were detected.

But since the uplink to Eve is unstable you must write the functions or programs in the least amount of characters possible, so that it takes a minimal amount of time to upload.

Winning criteria

The least amount of characters in the source code of the encoding and decoding functions or programs.

Note

The exact details of the output of the encoding is not that important, as long as the solution can correct any error up to 3 bits and detect any error up to 7 bits.

\$\endgroup\$
1
  • 3
    \$\begingroup\$ Could do with a link to a good description of the code. \$\endgroup\$ Commented Jul 3, 2014 at 21:07
0
\$\begingroup\$

Meta Code-golf


Golfing code can be slightly annoying[citation needed]. There are some things that can be automatically be applied to every golfing problem (e. g. remove all newlines). So what do you do? Automate it!

Your task is to write a program that will golf another program. Naturally, your program must be also be golfed, otherwise this wouldn't be a question, would it?

The following rules apply to your program:

  • All the code must be in one file, except for that of the program your program is golfing.
  • You may assume that the code of the program to be golfed is contained in a string. That string will not be counted towards your score.
  • The output of the golfed program must be identical to that of the original program.
  • Your program need only golf programs in it's own language. For example, a Python code-golfer-bot-thing need only successfully golf Python code, it can break all the Java code it wants.

Sandbox note: I'm not sure how to score this. The length of the golfer should be factored in, as should the difference between an ungolfed and golfed program. I'm thinking something like (ungolfed - golfed) / chars in answer, but this would require a way of finding the average number of characters removed. This suggests something of a , with random programs being chosen and passed to the bots to be golfed, but I would probably have to limit that to Python because that's to only language for which I have a bunch of random programs lying around on my box. However, I have no idea how to implement this and I don't want to spend a while looking through 100+ programs looking for sensitive information (passwords, email addresses, names). Anyway, in this case, score would probably be (average ungolfed - golfed) / chars in answer. Any thoughts? Side note to the sandbox note: sorry for the convoluted state of the note. I was basically just vomiting all my thoughts onto the page as they came to me.

\$\endgroup\$
2
  • \$\begingroup\$ There's an entire tag for that. Are you sure your challenge adds anything new to this? \$\endgroup\$ Commented Jul 8, 2014 at 7:42
  • \$\begingroup\$ Essentially this idea has been proposed twice on the sandbox, and neither time has it prospered. It's very hard to write a good spec for it. I suggest that you look through the old sandboxes for the previous versions and read their comment threads. \$\endgroup\$ Commented Jul 8, 2014 at 8:20
0
\$\begingroup\$

Reve's puzzle

From The Canterbury Puzzles:

When the pilgrims were stopping at a wayside tavern, a number of cheeses of varying sizes caught his alert eye; and calling for four stools, he told the company that he would show them a puzzle of his own that would keep them amused during their rest. He then placed n cheeses of graduating sizes on one of the end stools, the smallest cheese being at the top (and no cheese resting on a smaller one.) 'This is the riddle', quoth he, 'that I did once set before my fellow townsmen at Baldeswell, that is in Norfolk, and, by Saint Joce, there was no man among them that could rede it aright. And yet it is withal fully easy, for all that I do desire is that, by the moving of one cheese at a time from one stool unto another, ye shall remove all the cheeses to the stool at the other end without ever putting any cheese on one that is smaller than itself. To him that will perform this feat in the least moves that be possible will I give a draught of the best that our good host can provide.'

Write a function called reve that takes five arguments — the number of cheeses n >= 0 and labels for four stools (the source, two intermediaries, and the destination) — and outputs the minimum set of moves necessary to solve Reve's puzzle.

For example, the original puzzle is posed with n = 8, 10, and 21 cheeses, so running reve 8 "A" "B" "C" "D" should return the following 33 moves:

[("A","C"),("A","B"),("A","D"),("B","D"),("A","B"),("D","A"),("D","B"),("A","B"),("C","B"),("A","C"),("A","D"),("C","D"),("A","C"),("D","A"),("D","C"),("A","C"),("A","D"),("C","D"),("C","A"),("D","A"),("C","D"),("A","C"),("A","D"),("C","D"),("B","A"),("B","D"),("B","C"),("D","C"),("B","D"),("C","B"),("C","D"),("B","D"),("A","D")]

reve 10 "A" "B" "C" "D" (49 moves)

[("A","D"),("A","B"),("A","C"),("B","C"),("D","C"),("A","B"),("A","D"),("B","D"),("A","B"),("D","A"),("D","B"),("A","B"),("C","A"),("C","D"),("C","B"),("D","B"),("A","B"),("A","C"),("A","D"),("C","D"),("A","C"),("D","A"),("D","C"),("A","C"),("A","D"),("C","D"),("C","A"),("D","A"),("C","D"),("A","C"),("A","D"),("C","D"),("B","C"),("B","D"),("B","A"),("D","A"),("C","A"),("B","D"),("B","C"),("D","C"),("B","D"),("C","B"),("C","D"),("B","D"),("A","B"),("A","C"),("A","D"),("C","D"),("B","D")]

reve 21 "A" "B" "C" "D" (321 moves)

[("A","C"),("A","D"),("A","B"),("D","B"),("C","B"),("A","D"),("A","C"),("D","C"),("A","D"),("C","A"),("C","D"),("A","D"),("B","A"),("B","C"),("B","D"),("C","D"),("A","D"),("A","B"),("A","C"),("B","C"),("A","B"),("C","A"),("C","B"),("A","B"),("A","C"),("B","C"),("B","A"),("C","A"),("B","C"),("A","B"),("A","C"),("B","C"),("D","B"),("D","C"),("D","A"),("C","A"),("B","A"),("D","C"),("D","B"),("C","B"),("D","C"),("B","D"),("B","C"),("D","C"),("A","D"),("A","B"),("A","C"),("B","C"),("D","C"),("A","B"),("A","D"),("B","D"),("A","B"),("D","A"),("D","B"),("A","B"),("A","D"),("B","D"),("B","A"),("D","A"),("B","D"),("A","B"),("A","D"),("B","D"),("A","B"),("D","A"),("D","B"),("A","B"),("D","A"),("B","D"),("B","A"),("D","A"),("D","B"),("A","B"),("A","D"),("B","D"),("A","B"),("D","A"),("D","B"),("A","B"),("C","B"),("C","A"),("C","D"),("A","D"),("B","D"),("C","A"),("C","B"),("A","B"),("C","A"),("B","C"),("B","A"),("C","A"),("D","C"),("D","B"),("D","A"),("B","A"),("C","A"),("C","D"),("C","B"),("D","B"),("C","D"),("B","C"),("B","D"),("C","D"),("C","B"),("D","B"),("D","C"),("B","C"),("D","B"),("C","D"),("C","B"),("D","B"),("A","D"),("A","B"),("A","C"),("B","C"),("D","C"),("A","B"),("A","D"),("B","D"),("A","B"),("D","A"),("D","B"),("A","B"),("C","A"),("C","D"),("C","B"),("D","B"),("A","B"),("A","C"),("A","D"),("C","D"),("A","C"),("D","A"),("D","C"),("A","C"),("A","D"),("C","D"),("C","A"),("D","A"),("C","D"),("A","C"),("A","D"),("C","D"),("A","C"),("D","A"),("D","C"),("A","C"),("D","A"),("C","D"),("C","A"),("D","A"),("D","C"),("A","C"),("A","D"),("C","D"),("A","C"),("D","A"),("D","C"),("A","C"),("A","D"),("C","D"),("C","A"),("D","A"),("C","D"),("A","C"),("A","D"),("C","D"),("C","A"),("D","A"),("D","C"),("A","C"),("D","A"),("C","D"),("C","A"),("D","A"),("C","D"),("A","C"),("A","D"),("C","D"),("A","C"),("D","A"),("D","C"),("A","C"),("A","D"),("C","D"),("C","A"),("D","A"),("C","D"),("A","C"),("A","D"),("C","D"),("B","A"),("B","C"),("B","D"),("C","D"),("A","D"),("B","C"),("B","A"),("C","A"),("B","C"),("A","B"),("A","C"),("B","C"),("D","B"),("D","A"),("D","C"),("A","C"),("B","C"),("B","D"),("B","A"),("D","A"),("B","D"),("A","B"),("A","D"),("B","D"),("B","A"),("D","A"),("D","B"),("A","B"),("D","A"),("B","D"),("B","A"),("D","A"),("C","D"),("C","A"),("C","B"),("A","B"),("D","B"),("C","A"),("C","D"),("A","D"),("C","A"),("D","C"),("D","A"),("C","A"),("B","C"),("B","D"),("B","A"),("D","A"),("C","A"),("B","D"),("B","C"),("D","C"),("B","D"),("C","B"),("C","D"),("B","D"),("B","C"),("D","C"),("D","B"),("C","B"),("D","C"),("B","D"),("B","C"),("D","C"),("B","D"),("C","B"),("C","D"),("B","D"),("C","B"),("D","C"),("D","B"),("C","B"),("C","D"),("B","D"),("B","C"),("D","C"),("B","D"),("C","B"),("C","D"),("B","D"),("A","D"),("A","B"),("A","C"),("B","C"),("D","C"),("A","B"),("A","D"),("B","D"),("A","B"),("D","A"),("D","B"),("A","B"),("C","A"),("C","D"),("C","B"),("D","B"),("A","B"),("A","C"),("A","D"),("C","D"),("A","C"),("D","A"),("D","C"),("A","C"),("A","D"),("C","D"),("C","A"),("D","A"),("C","D"),("A","C"),("A","D"),("C","D"),("B","C"),("B","D"),("B","A"),("D","A"),("C","A"),("B","D"),("B","C"),("D","C"),("B","D"),("C","B"),("C","D"),("B","D"),("A","B"),("A","C"),("A","D"),("C","D"),("B","D")]

An up vote for all successful attempts. Shortest solution by character count wins. Sorry, no beer. Although if you're ever in the Boston area, it's on me.

Questions

  • Is this a suitable question for code golf?
  • Is it clear what I'm asking? Do I need to be more specific about input/output, etc.?
  • Any other suggestions?
\$\endgroup\$
7
  • \$\begingroup\$ Is this a duplicate of Tower of Hanoi Solver? \$\endgroup\$
    – Rainbolt
    Commented Jul 9, 2014 at 0:56
  • \$\begingroup\$ @Rusher The only difference between this and the Tower of Hanoi is that this uses 4 stacks instead of 3. I'm not sure that's enough different, though it would defeat most Tower of Hanoi solutions, which are typically recursive, while this seems more brute-force. \$\endgroup\$
    – isaacg
    Commented Jul 9, 2014 at 4:54
  • \$\begingroup\$ The input/output spec is certainly unclear. You ask for a function, and then give examples of program invocation. The other thing which isn't clear is whether you want "pure" code golf (ignoring realistic feasibility assumptions) or whether you want a program which can actually execute for 21 discs with only e.g. 2GB of RAM, explicitly using disk as a backing store. \$\endgroup\$ Commented Jul 9, 2014 at 10:02
  • \$\begingroup\$ I think the T(4,n) case of Tower of Hanoi is sufficiently different from T(3,n) and is the subject of many interesting papers. This does not require brute force. Frame-Stewart will solve this recursively, though it is still an open question whether the algorithm is optimal for all values of n and k in T(n,k). There are several papers that have popped on arXiv in the last few years that argue Frame-Stewart is optimal for T(4,k). \$\endgroup\$
    – O-I
    Commented Jul 9, 2014 at 13:57
  • \$\begingroup\$ @PeterTaylor I agree the input/output is unclear. Any suggestions on improving this? I wrote my solver in Haskell, hence the term 'function' and the lack of commas/parentheses for invocation. I'm fairly certain this is feasible — my function works and it will spit out reve 100 "A" "B" "C" "D" with little fuss (172033 moves). Perhaps I have made some mistake in my implementation? I can post the code if you would like to test. Regardless, I think this is a really interesting problem. Yes, it is 'just' Tower of Hanoi with 4 pegs, but a solution — let alone an optimal one — isn't obvious. \$\endgroup\$
    – O-I
    Commented Jul 9, 2014 at 14:08
  • \$\begingroup\$ It's an interesting problem, yes, but mainly because it's not clear that Frame-Stewart is optimal. The well-known 3-tower implementation is a special case of Frame-Stewart, and a fully general implementation isn't much more interesting. If we can assume optimality of Frame-Stewart, then I would vote to close as duplicate of the 3-tower question. If we can't, issues of performance (or of its irrelevance) need addressing. \$\endgroup\$ Commented Jul 9, 2014 at 14:25
  • \$\begingroup\$ Understood. I guess it should be closed then. \$\endgroup\$
    – O-I
    Commented Jul 9, 2014 at 15:00
0
\$\begingroup\$

Type me out.

Your task (related to this question) is to translate any text (in a file, or simply input) into the input of a telephone keypad.

enter image description here

and provide a keypress score.

As the keypad has a limited set of keys you have to 'encode' your non-alphanumerics with their ASCii hexadecimal encoding; e.g. to type ~ (which is hexidecimal ASCII land is 7e) you press the hash key once, the 7 key (once to get a seven) and then 3 three times to cycle through the digits 3, 'd', and finally 'e'. This gives the code #7e which corresponds to ~ (for a total number of key presses of 5). Spaces and capitals have to be accessed via hex code (so MY_CONST (#4d #59 #53def #43 #4f #4e #53 #54 - 27 presses) costs you less than my_const (6m 9wxy #53def 2bc 6mno 6mn 7pqrs 8t - 29), but more than myconst (6m 9wxy 2bc 6mno 6mn 7pqrs 8t - 23)).

For instance If your code had print() that would cost 15 for the print (7p 7pqr 4ghi 6mn 8t) plus 6 for the () (#28 #29)

To be clear with just the input print() the output is:

7p 7pqr 4ghi 6mn 8t #28 #29
21

(Note however the hex codes for c f i r s v y z are shorter (correspondingly #63 #66 #69 #72 #73 #76 #79 #7a) than long hand key presses. It's perfectly allowed to score print() as 19:

7p #72 #69 6mn 8t #28 #29
19

)

This is Code Golf, so feed your code into the finished program - shortest answer (in keypresses) wins.

\$\endgroup\$
3
  • \$\begingroup\$ Migrated from previous sandbox \$\endgroup\$ Commented Jul 16, 2014 at 7:33
  • \$\begingroup\$ So we enter 'print()' as our input and the output is the second code block? and our answer needs to be processed by the program we wrote, and the shorted processed answer wins? 2 questions: 1) is ~ 3 or 5 characters? because we need to press 3 three times. 2) is our score the bytelength or the keypress score? \$\endgroup\$
    – Nzall
    Commented Jul 17, 2014 at 11:09
  • \$\begingroup\$ @NateKerkhofs 1) it's 5 2) it's key presses. \$\endgroup\$ Commented Jul 17, 2014 at 11:11
0
\$\begingroup\$

I'm posting here first so I don't clutter up the site in case people are tired of pi questions. Thoughts?

Yet Another Pi Question

Today (actually tomorrow as I post this) is Pi Approximation Day (22/7), so here is a variant of the "compute pi" golf that I don't think has been seen before.

Write a program that accepts a number, either on standard input or as a command line argument, and prints that many digits of pi to standard output.

Details, for the nitpicky:

  • You may write the program to accept its input as the ASCII characters representing the number of digits, in either decimal or hexadecimal (preceded by 0x), or as a sequence of bytes representing that value. For example, if I want to tell your program to compute 65535 digits of pi, I would invoke it in your choice of one of the following six ways (using bash syntax):

    program 65535
    program 0xffff
    program $'\xff\xff'
    echo 65535 | program
    echo 0xffff | program
    echo $'\xff\xff' | program
    
  • The program must produce no output on standard output other than the required decimal digits of pi, and the decimal point. There are no constraints on what it may write to standard error or to any files.

  • The leading 3 may count toward your number of digits, or not; your call. (It has to be printed either way.)
  • Standard loopholes apply, including using a builtin constant to supply the value of pi. (I'm looking at you Mathematica)
  • You may assume that the value passed in will be small enough not to exceed resource limits in your program (recursion depth, memory allotment, integer overflow, etc.). Your program should be written in such a way that increasing these resource limits will allow it to compute more digits.
\$\endgroup\$
10
  • \$\begingroup\$ You might want to do something about a Mathematica answer along the lines of π~N~n, where n is the input number. ;) That is, you should probably restrict access to built-in π, trigonometric functions, etc. \$\endgroup\$ Commented Jul 21, 2014 at 15:44
  • 2
    \$\begingroup\$ Seems similar to codegolf.stackexchange.com/questions/506/… \$\endgroup\$
    – Kyle Kanos
    Commented Jul 21, 2014 at 15:46
  • \$\begingroup\$ @KyleKanos that one has some fairly arbitrary restrictions on it, and besides it's about printing a fixed number of digits rather than an arbitrary number. Similar, yes, in the sense that many questions asking some variant of "print pi" are similar, but not the same IMO. \$\endgroup\$
    – David Z
    Commented Jul 21, 2014 at 16:18
  • \$\begingroup\$ @MartinBüttner that's one of the standard loopholes but I could make it explicit. \$\endgroup\$
    – David Z
    Commented Jul 21, 2014 at 16:18
  • 1
    \$\begingroup\$ @DavidZ: I think the general consensus is that if answers can be taken from one question and modified slightly for another, it's a duplicate. I do see the difference between this Q and the one I linked to, I'm just kinda giving heads-up to a good friend that some on this site might not see enough of a difference. \$\endgroup\$
    – Kyle Kanos
    Commented Jul 21, 2014 at 16:25
  • \$\begingroup\$ Yeah, of course I do see your point. I figured I'd put up the suggestion anyway, just in case. \$\endgroup\$
    – David Z
    Commented Jul 21, 2014 at 16:27
  • \$\begingroup\$ @DavidZ That is one of the most disputed loopholes though, so it might be worth mentioning it explicitly. \$\endgroup\$ Commented Jul 21, 2014 at 16:31
  • \$\begingroup\$ Calculating pi in decimal has been thoroughly mined, hexadecimal has been done, rational approximation has been done, trig function evaluation has been done. If you're looking for a question which won't be closed as a duplicate then you need to be much more inventive. Perhaps use Euler's evaluation of the Riemann zeta function at positive integers in terms of pi as an excuse to ask a question about numerical evaluation of the non-trivial zeroes of zeta. \$\endgroup\$ Commented Jul 21, 2014 at 16:45
  • \$\begingroup\$ @PeterTaylor of course the specific numerical constant is irrelevant; I could just as well ask the same question for e, or the golden ratio, or a zero of the zeta function, but that wouldn't change whether it's a duplicate or not. I'm getting the sense this whole area of computing numerical constants is overdone. \$\endgroup\$
    – David Z
    Commented Jul 21, 2014 at 16:50
  • 1
    \$\begingroup\$ Different constants have different formulae available for calculation; the golden ratio admits an extremely short program by virtue of its continued fraction representation (which is probably equivalent to finding it by Newton-Raphson) whereas short formulae for pi use other types of infinite series or product. The interesting thing about pi is how many formulae for it are known, and that might partly be why it has been done to death already. \$\endgroup\$ Commented Jul 21, 2014 at 16:54
0
\$\begingroup\$

Note: This challenge might not work out on this site, please down vote this answer if you feel like it won't work and up vote if you think it could. If you down vote, a comment would be appreciated. I don't see the point in limiting the freedom of the participants since I think it will make things less fun/interesting.

Your love you want to show 'em, generate them a poem.

Poetry is not easy;
Rhyming is too hard.
Generate me a poem that's not too cheesy.
If it's good enough we'll call it art.

In all honesty, poetry really is tough beans. So for this challenge I ask you to write some code in the language of your choice that will generate poetry.

Restrictions

Your program has to be able to output a large amount of generated poetry of reasonable quality. This means that you can't write code that tries to 'generate' a poem that already exists. You also can't sample parts of existing poetry (this includes poetry invented by you). It is okay if some (or even most) of your code's poems make no sense and there are only a small percentage of good poems. I'm sure that code that consistently generates good poetry will be more popular though. Other than that there are no restrictions, you can use dictionaries, you can use the internet, you can strive for a certain rhyming scheme or several. It's poetry, get creative.

Your answer

Your answer should include:

  • Your full code or a link to it.
  • An explanation of your strategy.
  • Some of your favorite poems generated by your code.

The winner

This is a , so the answer with the most votes wins.

But what's a poem?

I see where you're going with this. You could output a list of words and claim it's poetry. I fear the other users won't be too impressed with that though and you won't get many votes (if you can avoid down votes). However, that doesn't mean it absolutely has to rhyme, there are plenty of ways of making poetry interesting and if you can have your code generate non-rhyming poetry that other people like, you deserve those votes. Explaining your strategy will also help people see why what you did is interesting.

\$\endgroup\$
9
  • 1
    \$\begingroup\$ This seems to be a bit too broad. What classifies as "poetry" for this challenge? Poetry doesn't necessarily need to rhyme, or follow any form or rhythm. I could claim for almost any text that it's poetry of some weird abstract form. You might want to place some restrictions on that. Also, if you're disallowing sampling parts of existing poetry, does that mean I can't submit a solution which just fills in blanks in a fixed structure or randomly combines a predetermined set of lines? Where do you draw the line between sampling a dictionary and sampling existing poetry? \$\endgroup\$ Commented Jul 27, 2014 at 15:38
  • \$\begingroup\$ @Martin I would say that taking combinations of words from existing poetry is sampling, filling in a structure wouldn't be. As for it being too broad, I feel like making it less broad would make the challenge less fun. Since the quality of the output is subjective, should we really be putting strict restrictions on what we want as an output? Or is this explicitly against the rules of SE? Maybe the poems should have a minimum length though. \$\endgroup\$
    – overactor
    Commented Jul 27, 2014 at 15:48
  • \$\begingroup\$ It's not necessarily against the rules, but there's a close-vote reason for questions being "too broad", and I could see this being closed as it stands. You'll just get people producing completely random chains of words and claiming that they are poetry. \$\endgroup\$ Commented Jul 27, 2014 at 15:51
  • \$\begingroup\$ @Martin Those should get downvoted though. Poetry is hard to define and I don't want to restrict people's creativity by failing to define it. If people like the output of a program, who's to say it's not poetry? \$\endgroup\$
    – overactor
    Commented Jul 27, 2014 at 15:54
  • 3
    \$\begingroup\$ I get your point, I'm just saying people are still very likely to close your challenge. The question isn't whether there are too many possible answers which would be upvoted but too many possible valid answers. And in fact I even think there might be too many possible answers that could be upvoted. There are just so many different kinds of (more or less weird) poetry. \$\endgroup\$ Commented Jul 27, 2014 at 15:58
  • \$\begingroup\$ Do you think that means the challenge isn't a good challenge or not a good fit for SE? \$\endgroup\$
    – overactor
    Commented Jul 27, 2014 at 16:03
  • \$\begingroup\$ It's certainly a very interesting challenge, but as it stands too broad for SE, I think. \$\endgroup\$ Commented Jul 27, 2014 at 16:05
  • 3
    \$\begingroup\$ There are many subclasses of poetry already well defined. Often a restricted format leads to more creativity, not less (both in writing poetry and in writing code). \$\endgroup\$ Commented Aug 10, 2014 at 2:07
  • \$\begingroup\$ I, for one, find this a perfectly fine challenge. \$\endgroup\$ Commented Mar 15, 2015 at 22:19
0
\$\begingroup\$

Program calculating its own length

Task

Your task is simple: write a program that produces its own length, without using any literals or built-in constants other than 0 (or its equivalents in your language).

Rules

  1. Your code must print its own length in bytes when run, followed by a single newline.
  2. Your code cannot use any literals other than 0 (or whatever equivalents your language might have). This includes string and character literals.
  3. Your code cannot use any built-in constants of your language, unless these are guaranteed to always have the value 0.
  4. Any functions and operators provided by your language can be used.
  5. You're not allowed to use any external libraries or external resources in your program.

Scoring

The score of a valid program is its length in bytes. The score of an invalid program is ∞.
As this is code golf, lowest score wins.

\$\endgroup\$
5
  • \$\begingroup\$ Does "any literals" include the more involved ones like function, array and object literals? Apart from this restriction, I'm pretty sure this has been asked before. \$\endgroup\$ Commented Aug 3, 2014 at 17:54
  • 3
    \$\begingroup\$ @MartinBüttner Probably a dupe: codegolf.stackexchange.com/q/27079/16402 \$\endgroup\$
    – user16402
    Commented Aug 3, 2014 at 17:58
  • 1
    \$\begingroup\$ Would this Python entry be valid (not golfed)? It uses only globals. text = open(__file__, 'rb').read(); length = len(text); print(length) \$\endgroup\$
    – Claudia
    Commented Aug 12, 2014 at 5:41
  • \$\begingroup\$ May we use built-in lists that are guaranteed to be []? \$\endgroup\$
    – Adám
    Commented Feb 8, 2019 at 8:28
  • \$\begingroup\$ In Jelly (and likely much more esolangs), a empty program outputs 0, producing an answer that is very hard to beat; Try it online! \$\endgroup\$ Commented May 24, 2019 at 8:44
0
\$\begingroup\$

Find a multiple of 42 that is spelled with all of the characters that make up the word "forty-two".

Rules:

  1. All of the characters in "forty-two" must be included at least once. Dashes count as characters, and each character must be used cumulatively (dog doesn't contain all of the characters that make up the word dogg, for example).
  2. The result can be any multiple of 42 that meets the defined criteria, presented in numerical form.
  3. Result must be multiple of greater than 1 (or less than -1). In other words, 42 and -42 are not allowed.
  4. Additional characters not in the word "forty-two" are O.K.
  5. The program must calculate its result without utilizing prior knowledge of a multiple known to include the right letters. Clarification:

    • This means that self trivial solutions such as hard-coding the program to print 42,000 are not allowed.
    • As an exception to this rule, prior knowledge of the maximum result possibility (42,000, for example) may be used to define the program's ability to name numbers up to the necessary size.

The shortest code (counting in bytes) to do so in any language wins.

\$\endgroup\$
3
  • \$\begingroup\$ This was down-voted in the original post, so I've improved it and posted here to see if it might be further improved to the point of liking. It seems to me like a nice challenge. \$\endgroup\$
    – J.Todd
    Commented Aug 4, 2014 at 20:30
  • 1
    \$\begingroup\$ I think that the specification are good now and the challenge would be fun, but this seems to be pretty much a duplicate of Converting integers to English words just with an added loop and comparison. There are some more questions like that here already, which can be found searching for site:codegolf.stackexchange.com english number \$\endgroup\$
    – tim
    Commented Aug 4, 2014 at 22:45
  • \$\begingroup\$ @tim perhaps a small creative twist, then? \$\endgroup\$
    – J.Todd
    Commented Aug 5, 2014 at 1:32
0
\$\begingroup\$

Dining Philosophers (Incomplete)

Please do not vote or comment yet.


Introduction

Cooperate with other Philosophers in order to eat your dinner as quickly as possible.

Game

You will be randomly paired with two other philosophers. Each philosopher begins with one fork. A philosopher needs two forks to eat his dinner. Each round you may take one of six actions:

  • Take the fork on your left
  • Take the fork on your right
  • Place a fork to your left
  • Place a fork to your right
  • Eat
  • Wait

The following behaviors will cause you to wait by default.

  • Attempting to take a fork that is not there
  • Attempting to place a fork you do not have
  • Attempting to eat with less than two forks
  • Attempting to take a fork when you are already holding two

Once every philosopher has successfully eaten, the trial is completed. Each participant is scored according to how long it took all three participants to eat.

Input

Input description here.

For Java submissions, input will be passed via parameter. For non-Java submissions, input will be provided via a command argument.

Output

Output description here.

Deliverables

Java Submissions

You must submit a unique title and a Java class that extends the abstract Philosopher class written below.

public abstract class Human {
    public abstract String takeAction(String arg);
}

Non-Java Submissions

You must submit a unique title, a program, and a Windows command line string that will run your program. Remember that an argument may be appended to that string. For example:

  • python Aristotle.py
    • Note that this one has no args. This is round one! Be prepared for this.
  • python Aristotle.py args

Scoring

Your final score will be the median of your scores across ____ trials.


\$\endgroup\$
0
0
\$\begingroup\$

Tennis Tournament (Incomplete)

Please do not vote or comment yet.


Introduction

Insert tennis themed introduction here.

Game

Insert description of the tournament hierarchy, player seeding, and program flow.

Input

You will be passed the current set of matches. Matches will be comma (,) delimited. Players within a match will be dash (-) delimited. Players will be represented by ID and strength in the format <ID>$<Strength>. Byes will be represented by 0$0.

Java submissions will be supplied input via argument to the takeAction() function. Non-Java submissions will be supplied input via command line argument.

Example

The following input represents a three player tournament. The players' IDs are 2, 1, and 3. Their strengths are 1, 2, and 2, respectively. Player 3 has a bye.

2$1-1$2,0$0-3$2

Output

Return the string "play" if you want to play. Return the string "concede" if you want to concede.

Deliverables

Java Submissions

You must submit a unique title and a Java class that extends the abstract Athlete class written below.

public abstract class Athlete {
    public abstract String takeAction(String arg);
}

Non-Java Submissions

You must submit a unique title, a program, and a Windows command line string that will run your program. Remember that an argument will be appended to that string. For example:

  • python RafaelNadal.py args

Scoring

Your final score will be the median of your scores across ____ trials.


\$\endgroup\$
0
\$\begingroup\$

Teach me to play clarinet

(might be an optimization problem for )

This is mostly a work in progress until I figure out the best input and output notation/formatting.


The clarinet is a very complicated instrument, as there are more keys than I have fingers. Additionally, there may be multiple ways to play the same note. I dream of becoming a professional clarinetist one day, but I am very lazy at everything I do. When playing music, I try to move my fingers as little as possible.*

The input will be a series of musical notes, which each note consisting of a note name (like E or G#) and a number which represents which octave of the clarinet is being discussed.

Examples:

E1 - low E, the bottom note
C1 - C below the staff
E2 - E at the bottom of the staff
F#3 - F# at the top line of the staff
G4 - G that is 4 ledger lines above the staff, the highest note needed

An example input might be

Eb2 D2 F#3 F3 F#3 G3 F#3

From this list of notes, your program should determine which fingerings I should use to play these notes in the easiest way possible. "Easiest" means that the total number of finger movements should be minimized (how to explain?).

The output should describe my finger position for each note in terms of the location of each of my fingers.


One problem I see is that there is no standardized fingering chart for clarinet. Furthermore, no fingering charts actually specify which fingers are used to play which keys. One thing I would have to do is create a list of all possible positions for each finger. Then, a single fingering "diagram" would consist of the list of keys, telling which are open/closed/either. There would be multiple fingering diagrams for each note.

The next problem is that the number of distinct fingerings can grow to be quite large when certain tricks are taken into account such as "leaving the right hand down while playing throat tones." This would be the reason for adding the "either" option to the fingering charts.

I must figure out how to notate the fingering charts and format the output.


*this is actually a good thing and not lazy

\$\endgroup\$
1
  • \$\begingroup\$ As for the fingering charts, my clarinet book has a chart labeling each key with a character, A-Q, I think. The holes could be 1-6. Would this be helpful? \$\endgroup\$
    – user10766
    Commented Sep 18, 2014 at 2:19
0
\$\begingroup\$

Chess: End Game KOTH

Task

You design a bot that plays the final moves of a chess game against other bots. The chess board will be in the end game stage (relatively few pieces) with either a winning position for white, or a force draw. Points will be scored on the outcome of the game in each board situation. Bots will play both the black and white sides for each position (10 unique positions, 20 games in total).

Rules

  1. Basic chess rules apply

  2. No outside help whatsoever (chess engines, endgame tablebases, stored patterns)

  3. Notation will be in the ICCF numeric notation format
  4. Round-robin tournament setup (see scoring below)
  5. 20 games per match (1 match is one bot-to-bot pairing)

    • Each bot plays 10 games as white and 10 games as black
    • 8 of these games will be force wins for white, the remaining 2 are force draws (but winnable by either player)
    • The same 10 games will be repeated, so each bot will play the same position as both colors.
  6. Time limit of 1 minute per match? (very flexibly here)

    • Maximum time per move is X seconds (possible Fischer Delay bonus?)
    • Failure to move in the time limit per move will result in a loss for the current game

Scoring

These values will surely change

+---------------------+------------+------------+-------------+-------------+
| Board Situation     | White Wins | Black Wins | Black Draws | White Draws |
+---------------------+------------+------------+-------------+-------------+
| Force Win for White | 100        | 500        | 250         | -50         |
| Force Draw          | 250        | 350        | 50          | 50          |
+---------------------+------------+------------+-------------+-------------+
  1. Need to figure in number of moves into points
  2. Overall winner is the bot with the most points at the end of the round-robin

How To Play

  1. Controller will be written in python and will communicate to bots via STDIN/STDOUT

    • Bots can be programmed in any language that support persistent polling of STDIN and STDOUT
  2. A board will be generated by the controller and sent to both players at the same time (will include information for castling in a TBD format). Each bot will be given ~50 ms to process the board information, but they don't know what side they are playing.

  3. Following the short pause, each of the bots will be sent either B or W character to indicate which side they will play for the next game. At this time, the white bot timer is activated and it can return his move any time afterwards.

  4. The bot will response via its STDOUT the move in ICCF numeric notation

5453

  1. After the move has been validated by the controller, the time remaining for both opponents and the move history will be sent to the each bot, and then the other bot begins their turn. Time will be outputted in ms in the following format WXXXXX BXXXXX. The following is the output given to each bot after each ply.
W54000 B60000 1) 5453
W54000 B48000 1) 5453 7872
W52000 B48000 1) 5453 7872 2) 6512
  1. This will repeat (steps 4&5) until the game is won, drawn, or time runs out, after which the bots will be sent the final score of the game and time remaining for the next game of the match
W35000 B47000 W+300 B+50

Things that might be a problem

  1. The efficiency of the language (i.e., C++ vs perl) might bias towards language used instead of algorithm developed
  2. Generating board situations (could grab them through an online DB automatically)
  3. Too hard/easy to program?
\$\endgroup\$
2
  • \$\begingroup\$ Do you want to accept or exclude the approach of exhaustively evaluating all future moves? I guess this will affect how long you give per move, and per match (as future moves calculated in the previous turn can be stored and added to on each new turn). For example, if you're near enough to the end of the game that it takes 30 seconds to evaluate all possibilities, then a few moves in a bot could have full knowledge, as some futures will be trimmed by the moves taken so far. \$\endgroup\$ Commented Aug 11, 2014 at 21:45
  • \$\begingroup\$ This won't apply if you choose end games that still have a lot of options open - I don't know if you mean 2 pieces left each or several. \$\endgroup\$ Commented Aug 11, 2014 at 21:48
0
\$\begingroup\$

Tetromino Game

(name suggestions?)

This game is based off of L game, an abstract puzzle game by Edward de Bono.

Rules

Every player is assigned a random position in the list of players. Every round, each player gets a turn, in the order defined by the list of players. The game is over once only 1 player remains.

The board is a 2-dimensional grid containing the tetrominoes, as well as 1x1 neutral pieces. It does not wrap. It is generated randomly and all of the pieces are placed on it, with a good amount of neutral pieces (should equal roughly half the amount of empty blocks, and just over 2/3 the total amount of players).

On each turn, the player must move their piece to another position on the board, and optionally a single neutral piece. This can be anywhere, however, no pieces can intersect.

The player loses if they cannot move their tetromino anywhere; they are no longer given any turns, but their tetromino stays.

After 20 rounds, on every round, a neutral piece will be placed randomly on the board.

A player's score is equal to the amount of turns that they have played.

Submissions

Communication with the controller is done through STDIN and STDOUT. Your submission will run for the entire length of the game. If your program is expected to produce output and doesn't within 4 seconds, you will lose.

At the start of the game, your submission will be launched and you are expected to produce a tetromino to play with. You should output a number from 0 to 4, corresponding to these tetrominoes:

Tetrominoes

(modified version of this)

They are in order of strategical complexity; 4 is the most complex.

Then, the initial game data will be passed to your game.

The first line contains 3 space-separated integers: your position in the list (starting with 0), board width, and board height.

The rest is a rendering of the board: A player's tetromino is made of the last digit of the base-93 number (ascii 33 to 125) of their position in the list. A space is an empty space, and ~ is a neutral piece.

On every turn except your own, your bot will receive information about the turn. The first line can be one of either M 0 0 0 or L; the first is for motion (see next paragraph), and L is for that player being unable to make any moves and losing.

The motion line is in the format M x y r f, where x and y is the new position of the upper-left block in the bounding box of that player's tetromino, and r is the amount of rotation (0 for 0 degrees, 1 for 90, 2 for 180, 3 for 270, clockwise).

f is either 0 or 1; 1 if the player flipped their piece along the x axis (this happens before rotation). Optionally x y x y could also be on the end of the line, the first pair of coords being that of a neutral piece, and the next being its target location. It is followed by the new board.

On your turn, GO will be given to you on STDIN and you will be expected to produce a string x y r f and optionally x y x y, similar to the one in the paragraphs just above this. The controller will evaluate whether or not there are possible moves for you just before your turn, and will eliminate you automatically if necessary.

If your output is invalid, you will receive ERROR on STDIN and you will be expected to produce a new output. If this happens 5 times in a row, you lose.

Submissions are allowed to store data in files, and initial data for the file can be included with the submission.

Scoring

Each player's score is equal to the amount of turns they play; however the submission's final score is the sum of all their scores in multiple trials. Trials will be run until the leading submission is 5 points away from the runner-up.

Name?

Ideas: "Tetromeano" (suggested as a joke on chat), "Space Tetris".

Discuss the game here.

\$\endgroup\$
0
\$\begingroup\$

This is a rough idea for a challenge, if possible I would like someone else to help me with it and possibly host the challenge (and consequently getting all of the up votes :] ).

Pecking Birds - input wanted

You're a bird and birds need to eat. There's not all that much food, so you might need to fight for it.

Haven't you heard about the bird?

Birds live on a continuous torus where food drops at random places at an increasingly slow rate. They can only see food from a certain distance, they can see all other birds on the torus though. Birds can only move over a limited distance at a time and can peck at either birds, food or nothing within a certain radius. Birds can see a bird's last action, but they can't distinguish between pecks at food and pecks at nothing if they're too far away. Birds that are pecked to death, turn into food. Food disappears after a fixed amount of birds have taken a peck at it. Birds' health goes down every turn, but get refilled a bit if they peck at food.

Input and Output

If I end up hosting this challenge myself, the controller will be in Java and submissions will be either a java class or a program in another language. Both types of answers will be allowed to persist between turns. Java submissions will have the state of the game copied into global variables and be called to act through a method and send their output as a return value. There will also likely be helper functions available for java submissions. Other submissions will get their info through STDIN and asked to send their output to STDOUT. There will be two actions every turn, a pecking action and a moving action. before being asked what to do, you will get the position of each bird, their last pecking action and the position and plentitude of all food withing your sight. On your pecking turn you will be asked to either peck at food, peck at a bird, peck at nothing or not peck at all. On the movement turn you will asked to return a position within your movement radius to move to. All birds peck at the same time and then move at the same time alternately. the winner is the last bird standing.

The competition

Each player will start with 10(?) birds on a sqrt(n)*50(?) sized torus, where n is the amount of entries. Your score will be determined by the amount of rounds your last bird died before the last bird standing. Obviously a lower score is better. The simulation will be run several times and some sort of average will be taken to determine the overall winner.

\$\endgroup\$
0
\$\begingroup\$

Jenga code

I think everyone knows what Jenga is.

As per Wikipedia:

Jenga is a game of physical and mental skill [...] During the game, players take turns removing one block at a time from a tower constructed of 54 blocks. Each block removed is then balanced on top of the tower, creating a progressively taller but less stable structure.

enter image description here

Challenge

Write a program that behaves as a Jenga tower. Every time a randomly chosen piece of code is removed and placed at the bottom of your program, the code should re-run. Goal is to achieve the tallest running code tower.

Rules

  • The starting tower (or source code) must be of exactly 15 lines of code. Such lines must be divisible by 3 forming a 15x3n grid composed by 15 lines of 1xn bricks.
  • A brick is removed randomly from the code and placed at the bottom from left to right until the 3n block line is complete. The process goes on at the bottom of the new formed line.
  • If a brick has strictly more consecutive whitespaces than any consecutive characters in it its considered broken and fails to sustain the tower.
  • A brick must always be present for each row (2 holes and 1 brick), but its position in the row is not important.
  • A tower is tall 20 lines if the 20th line tower runs with no errors.
  • A brick cannot start nor end with comment start or end tags of your chosen language (e.g /* or //)

Output

Each tower must output its own height.

Scoring system

Your score is simply the avarage tower height for your program:

SCORE = (MAX TOWER + MIN TOWER) / 2

Where MIN TOWER refers to the minimun non-running tower while MAX TOWER refers to the maximum running tower.

(It would be nice if in the answer both towers are shown)

Proposed tag:

\$\endgroup\$
20
  • \$\begingroup\$ I think the basic idea is good, but it lacks some definition; you should probably specify that a line has to be more than just a comment and does something related to the rest of the program. What prevents me from declaring a new variable on every line and then printing a hardcoded string on one line? I'm not sure if thsi idea could work, but it certainly doesn't work like this. \$\endgroup\$
    – overactor
    Commented Aug 18, 2014 at 12:25
  • \$\begingroup\$ Maybe the randomly picked rule is also not beneficial. I believe that if people can specify the order in which the lines are picked, they can get more creative. \$\endgroup\$
    – overactor
    Commented Aug 18, 2014 at 12:26
  • \$\begingroup\$ Can't understand your point on the comment line. If the middle brick is taken from that line and placed at the bottom, the code shoulnd't work, right? Or you mean that every single brick has/is a comment? \$\endgroup\$
    – Narmer
    Commented Aug 18, 2014 at 12:28
  • \$\begingroup\$ For the line picking I can add the rule to choose a integer sequence of choice and use the sequence to choose the line (starting again from top when end is reached while counting). \$\endgroup\$
    – Narmer
    Commented Aug 18, 2014 at 12:35
  • \$\begingroup\$ @Narmer What overactor is referring to is that any brick could be /* my comment */ which could be removed and moved anywhere without breaking the program. But there are other ways. It is trivial to get the maximum score of 50 in many languages by writing 44 bricks of the form someVariableName = 0; and one brick of the form print "I win!". (That was overactor's other point in his first comment.) I agree that the idea is interesting but it needs some work. \$\endgroup\$ Commented Aug 18, 2014 at 12:38
  • \$\begingroup\$ @MartinBüttner I see your point now. First is easily avoidable removing comments, but the second one is tough. I'll think for a solution. \$\endgroup\$
    – Narmer
    Commented Aug 18, 2014 at 12:41
  • \$\begingroup\$ The only thing I can think of is using the output. Something like "every compiled tower must output its height". \$\endgroup\$
    – Narmer
    Commented Aug 18, 2014 at 12:45
  • \$\begingroup\$ In no particular order, I see the following problems. 1. Is "compiled" intended to exclude interpreted languages (in as much as that distinction makes sense nowadays)? 2. The stuff about holes makes no sense to me. In particular, a) there's nothing stopping a brick from containing a hole; b) the number 4 appears from nowhere and doesn't fit with n-char bricks. 3. What are MIN TOWER and MAX TOWER in the scoring? 4. I can easily write code which does absolutely nothing but compiles. E.g. make each brick for(;;)break;. \$\endgroup\$ Commented Aug 18, 2014 at 12:55
  • \$\begingroup\$ Edited to match the comments. Ugh, just seen @PeterTaylor comment. \$\endgroup\$
    – Narmer
    Commented Aug 18, 2014 at 12:55
  • \$\begingroup\$ Making each tower output its height is easy: just make each brick end in a // / # as appropriate to comment out the remaining bricks on the line. E.g. in GolfScript making each brick 0or)# would achieve that. \$\endgroup\$ Commented Aug 18, 2014 at 12:56
  • \$\begingroup\$ @PeterTaylor for your last comment, see my edit. Min tower refers to the minimum non compiling tower, while max tower is for the maximum compiling tower. I'll clear that out. \$\endgroup\$
    – Narmer
    Commented Aug 18, 2014 at 12:57
  • \$\begingroup\$ For the hole part I was trying to avoid trivial solution where a brick is composed by only < 4 chars (and the line by more than 12), making the tower almost "brickless". I'm still trying to figure out how to make that clear, maybe I should change it in a more clear "if a brick has more whitespaces than characters in it its considered broken and fails to sustain the tower" \$\endgroup\$
    – Narmer
    Commented Aug 18, 2014 at 13:05
  • \$\begingroup\$ And last but not least for compiling I mean "working with no errors, regardless they are compile or runtime". Don't know why I used such a silly word. \$\endgroup\$
    – Narmer
    Commented Aug 18, 2014 at 13:18
  • \$\begingroup\$ Pretty much any language which can do a cheat quine by reading its own source can do that and print the newline count in one block, and then do nothing useful in all the other blocks, achieving a perfect score. (I can also see how to get a perfect score in GolfScript by counting newlines without reading the source, but that's actually an interesting answer. OTOH it does mean that the question would be pretty much killed once someone posts it). \$\endgroup\$ Commented Aug 19, 2014 at 9:21
  • \$\begingroup\$ I think that's unavoidable. A single block has to have the possibilty to live on its own, otherwise a single brick line in not possible. I think I have to exploit again the output to alter the program code. Maybe instead of simply the height the program should output an ascii representation of the tower, with XXX for brick and void for hole. Let me know what you think. \$\endgroup\$
    – Narmer
    Commented Aug 19, 2014 at 10:16
0
\$\begingroup\$

Analyze Tonguetwisters

Your task is to write a program which will accept an English tonguetwister, search for commonly used sounds and decide why it is difficult to pronounce.

  1. Calculate the frequency of every sound used in the input sentence.
  2. Count identical sounds (for example, ea and ee) as the same thing.
  3. Ignore those sound groups (see below) which occur less than 0.1 times per character of the input.
  4. From the sounds that remain, group members of the same group together and separate by a forward slash (/).
  5. Arrange the groups by decreasing number of occurences.
  6. Separate groups by commas.
  7. Output.

Identical Sounds [under construction]

ee = ea (in step 2, replace ea by ee)

Sound Groups [under construction]

e,ee
s,sh,c,ch
f,th,ph

Examples

Input: She sells sea-shells on the sea-shore.

Output: s/sh,e/ee

Input: The seething sea ceaseth and thus the seething sea sufficeth us.

Output: s/c,e/ee

Rules

  • Receive input on STDIN, as command-line arguments or otherwise. You may not expect it to be stored in a variable.
  • Output to STDOUT or equivalent.
  • Standard loopholes are banned.
\$\endgroup\$
3
  • 2
    \$\begingroup\$ Are you going to provide a data file which maps words to the pronunciations in a standardised format? \$\endgroup\$ Commented Aug 21, 2014 at 13:37
  • \$\begingroup\$ @PeterTaylor It wasn't in my original plan (which was just to assume that c,sh,s, and ch are always similar, which is not the case as c can be pronounced s or k), but if there is such a file somewhere I can alter the challenge for it to be used \$\endgroup\$
    – user16402
    Commented Aug 21, 2014 at 14:08
  • 1
    \$\begingroup\$ An earlier question uses the CMU Sphinx pronunciation dictionary. \$\endgroup\$ Commented Aug 21, 2014 at 14:13
0
\$\begingroup\$

Gun Fight at High Noon

Gameplay

This will be a 5 or 4 stage (the decision will be explained later) tournament where programs are pitched against each other to solve an integration problem faster than the other. The fastest will then go on to the next round.

Number of rounds: Due to tournament bracketing, the number of rounds will be decided by the reception of the challenge. For four rounds, sixteen entrants are needed. For five rounds, thirty two entrants are needed.

The controller

The controller will be written in Python, using time.time() as the timer. When run, it will time one entrant, print the output and time the other entrant and print the output. I will then put the results into a text file and post the results on the question.

The problem

The problem will be a simple elementary function integration problem with long numbers included. These will be generated randomly when the controller is initiated and both entrants will be given the same problem.

Rules

  1. No inbuilt functions can be used to solve the problems
  2. If you fail to calculate the problem correctly, you will lose immediately
  3. In event of a tie, the match will be replayed with a different problem

Inbuilt Functions

Inbuilt functions include functions that solve integration problems themselves you must have a hand written integral solving algorithm in your code.

Example and Arguments

All information will be transferred via stdout and stdin. The integral will be in the following format:

Integral http://upload.wikimedia.org/math/0/3/4/034cf496a9d3026984fcae6cfa58608a.png

And f(x) being like where a and n will be replaced for integers when passed to your program:

f of x

With arguments being passed like so:

programname a b f(x)

The reply will be stdout as a floating point integer to a precision of 5 decimal points. An example from one of my tests:

~$ python3 showdowncontroller.py Test1 'python3 int1.py' Test2 'python3 int2.py'
A,B:        3,36
Function:   10*x**3
Result:     4199187.88575

Test1: 0.04052305221557617 True 4199187.88575 <- name time correct? output

Test2: 0.04041910171508789 True 4199187.88575


Win: Test2

The command run for each program was:

python3 [program name].py 3 36 10*x**36

And the response was:

4199187.88575

Other

In your answer you will need the following:

  • Name of your program
  • Command to compile your program (if necessary)
  • Command to run your program
  • Your code
  • A short description of your integration method

Your program can be in any language as long as I can compile and run it on Ubuntu 12.04 Precise.

There will be a 0.00005 error tolerance: any more or any less and your program will lose the match. The controller uses Simpson's Rule.

# Generate numbers
a=random.randint(1, 50)
n=random.randint(1, 10)
b=random.randint(1, 50)
c=random.randint(1, 50)

# Integration using the Simpson method
def integrate(f, a, b):
   h = (b-a)/100
   meth = lambda f,x,h: (f(x) + f(x+h))/2.0
   ival = Decimal(h * sum(meth(f, a+i*h, h) for i in range(100)))
   return ival 

# Call function
func = lambda x: eval(str(a)+'*x**'+str(n))
result = round(integrate(func, c, b), 5)

Test programs will be posted with their running times so people can tell how fast my computer is. I will post no hardware specifications (processor type, speed) though - that will remain a mystery.

Controller code

# Gun Fight at High Noon
import subprocess, random, time, sys
from decimal import Decimal

# Get program names
prog1 = sys.argv[1]
prog1command = sys.argv[2]
prog2 = sys.argv[3]
prog2command = sys.argv[4]

# Generate numbers
a=random.randint(1, 50)
n=random.randint(1, 10)
b=random.randint(1, 50)
c=random.randint(1, 50)

# Integration using the Simpson method
def integrate(f, a, b):
   h = (b-a)/100
   meth = lambda f,x,h: (f(x) + f(x+h))/2.0
   ival = Decimal(h * sum(meth(f, a+i*h, h) for i in range(100)))
   return ival 

# Call function
func = lambda x: eval(str(a)+'*x**'+str(n))
result = round(integrate(func, c, b), 5)
function=str(a)+'*x**'+str(n)

print('A,B:     '+str(c)+','+str(b))
print('Function:    '+function)
print('Result:      '+str(result))

# Run program and evaluate output
def runprog(command, result, f, a, b):
    start = time.time()
    answer = subprocess.Popen(command+' '+str(a)+' '+str(b)+' '+f, stdout=subprocess.PIPE, shell=True).communicate()[0].decode('utf-8')
    end = time.time()
    elapsed = end-start

    if Decimal(answer) > result-Decimal(0.00005) and Decimal(answer) < result+Decimal(0.00005):
        correct = True
    else:
        correct = False

    return elapsed, correct, answer

p1time, p1correct, p1answer = runprog(prog1command, result, function, c, b)
p2time, p2correct, p2answer = runprog(prog2command, result, function, c, b)

print('\n'+prog1+': '+str(p1time)+' '+str(p1correct)+' '+p1answer)
print(prog2+': '+str(p2time)+' '+str(p2correct)+' '+p2answer)

if p1correct:
    if p2correct:
        if p1time < p2time:
            print('\nWin: '+prog1)
        elif p1time == p2time:
            print('\nTie')
        else:
            print('\nWin: '+prog2)
    else:
        print('\nWin: '+prog1)
else:
    if p2correct:
        print('\nWin: '+prog2)
    else:
        print('\nTie')
\$\endgroup\$
7
  • \$\begingroup\$ To be properly specified you need to define a) the class of functions which should be integrated; b) the I/O format; c) the error tolerance (and the method of computing the reference value against which you'll check). As a separate issue, what do you mean by "credentials" in the last sentence? \$\endgroup\$ Commented Aug 22, 2014 at 10:27
  • \$\begingroup\$ @PeterTaylor My answer has been edited to incorporate all of your suggestions \$\endgroup\$
    – Beta Decay
    Commented Aug 22, 2014 at 14:48
  • \$\begingroup\$ I don't see point a) addressed anywhere, and the part of point b) which relates to how the formula is serialised is also unaddressed. And on the basis of the example, no-one should waste their time answering. The spec allows "a 0.005 error tolerance" but the error in the controller's calculation is apparently 350.38575. I think the standard English term for processor type, speed, etc. would be "hardware specifications". "Credentials" in the context of computing generally means either username+password or a cryptographic token serving a similar purpose. \$\endgroup\$ Commented Aug 22, 2014 at 15:10
  • \$\begingroup\$ @PeterTaylor What do you mean by class of functions then? \$\endgroup\$
    – Beta Decay
    Commented Aug 22, 2014 at 15:16
  • \$\begingroup\$ Are answers supposed to integrate polynomials, rational polynomials, hypergeometrics, the closure under field operations of elementary functions, ...? \$\endgroup\$ Commented Aug 22, 2014 at 15:51
  • \$\begingroup\$ @PeterTaylor Elementary functions \$\endgroup\$
    – Beta Decay
    Commented Aug 22, 2014 at 15:57
  • \$\begingroup\$ How is this significantly different than if it was simply a [fastest-code] problem instead of having a tournament set up? You could just give a large set of test cases, and the fastest code would still win, right? \$\endgroup\$
    – Geobits
    Commented Aug 22, 2014 at 17:56
0
\$\begingroup\$

Rubik's Cube Simulator

I had posted a rubik's cube question a few days back which turned out to be quite close to an existing one although I made a few amendments. This is a different question altogether.

The idea is to simulate operation of a rubik's cube.

INPUT: Take a preset sticker configuration for each face as input

Your program must interpret the configuration and suggest a list of moves to generate the said configuration from a perfect Rubik's cube.

Your program must also check if the sticker combination is an invalid one, and print an error message saying that it is not possible to generate such a configuration.

Question should probably be used as a popularity contest given the length and complexity of code, but based on response, a code golf follow-up is on the cards.

Suggestions are most welcome.

\$\endgroup\$
4
  • 3
    \$\begingroup\$ I don't know a whole lot about Rubik's cube, but going from state Finish to In-between any different than In-between to Finish? \$\endgroup\$ Commented Aug 25, 2014 at 12:42
  • \$\begingroup\$ I don't think using [popularity-contest] is a good idea if there are better alternatives. That should be reserved for cases, when it's hard to make the validation criteria objective. In your case [code-golf] seems fine. Alternatively, you could think about a [code-challenge] for returning the smallest number of moves. \$\endgroup\$ Commented Aug 25, 2014 at 12:43
  • \$\begingroup\$ Okay, will do. Code-challenge seems more accurate. \$\endgroup\$
    – CrazyMod
    Commented Aug 25, 2014 at 12:45
  • \$\begingroup\$ ...awaiting response... \$\endgroup\$
    – CrazyMod
    Commented Aug 26, 2014 at 14:18
0
\$\begingroup\$

American Roulette

Roulette is one of the simplest casino games to understand, so I invite you all to see who gets the most money.

Coding

You will be supplied with a singe argument via the command line. This argument will be the amount of money you have.

[command to run your code] [arg1]

Your output must be in the following format:

[bet]|[amount of money you bet]

The following is a list of valid bets:

http://www.predictem.com/images/roulette.gif

Name                   | Example
-----------------------+-----------------------
Any number of numbers  | 12|100 or 36,19,18|100
00                     | 00|1000
0                      | 0|126
1st 12 (see image)     | 1st12|100
2nd 12 (see image)     | 2nd12|439
3rd 12 (see image)     | 3rd12|679
1 to 18                | 1-18|8
19-36                  | 19-36|10000
Red numbers            | red|1722
Black numbers          | black|1384
Odd numbers            | odd|100
Even numbers           | even|21900

Payout will be calculated using the following equation where n is the number of squares your bet will win on:

http://upload.wikimedia.org/math/6/6/9/66946b321361a701f6b6903d5eae4b44.png

In your answer, I need the name of your program, your code and a command to run it.

Winning

When enough people enter, I will run the controller twice a week. After four weeks, I will announce the winner (the person with the most money).

I realise that is may be ambiguous and/or poorly worded so any feedback on how to pad this question out would be helpful.

\$\endgroup\$
10
  • \$\begingroup\$ 1. This is not a king-of-the-hill challenge, due to the lack of interaction. This is basically just a code-challenge. 2. "n is the number of squares" should probable be "...the number of squares your bet will win on". 3. In roulette, can you actually bet on "any number of numbers"? I thought only the groups indicated on the mat are possible. 4. You might want to specify "American Roulette" because of the 00. 5. 5. How much money do we start with? 6. I guess you won't be just doing a single test for each bot, so how many trials will there be and how is the overall score determined? \$\endgroup\$ Commented Sep 1, 2014 at 15:55
  • \$\begingroup\$ How can the bots interact? It looks to random and too "player versus environment"-y. \$\endgroup\$
    – Vi.
    Commented Sep 1, 2014 at 15:55
  • \$\begingroup\$ Casino? The best strategy is not to play at all... \$\endgroup\$
    – Vi.
    Commented Sep 1, 2014 at 15:57
  • \$\begingroup\$ @MartinBüttner I know that any number of numbers violates the conventional rules, but I'll keep it just so I don't need to code the layout of a roulette table. \$\endgroup\$
    – Beta Decay
    Commented Sep 1, 2014 at 16:07
  • 1
    \$\begingroup\$ @Vi. Depends on the game, but in the case of Roulette you can't win in the long run. So I guess a reasonable winning criterion would be "most rounds until bankrupt". Still, I'm not sure Roulette provides enough strategical depth to be interesting. \$\endgroup\$ Commented Sep 1, 2014 at 16:10
  • \$\begingroup\$ @MartinBüttner, but this isn't normal roulette. If you bet 0,00,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36|all-your-money you make a guaranteed profit of (38/36 - 1)*all-your-money. \$\endgroup\$ Commented Sep 1, 2014 at 17:13
  • \$\begingroup\$ @PeterTaylor lol, good point, although I don't see how that provides "enough strategical depth to be interesting" :P \$\endgroup\$ Commented Sep 1, 2014 at 17:16
  • \$\begingroup\$ @PeterTaylor You would make a guaranteed loss with that. yourmoney -= bet; yourmoney += (38/36)-1 \$\endgroup\$
    – Beta Decay
    Commented Sep 1, 2014 at 17:20
  • \$\begingroup\$ @BetaDecay wait what, your payout is not multiplied by your bet? o.O \$\endgroup\$ Commented Sep 1, 2014 at 18:11
  • \$\begingroup\$ @MartinBüttner Oh yeah... I should add that... \$\endgroup\$
    – Beta Decay
    Commented Sep 1, 2014 at 18:28
0
\$\begingroup\$

Print the Constitutional Amendment

Given a number from 1 to 27, print the appropriate amendment to the US Constitution, using this text.

Your score is the byte count of your source code, divided by the byte count of the best answer to this question in the same language. Therefore, you must use a language which had an answer to that question before September 1, 2014.

Question

Is this too similar to existing Kolmogorov-complexity challenges?

\$\endgroup\$
1
  • 1
    \$\begingroup\$ Hm, I think there's little regularity to the output which could be exploited, so this seems to boil down to just using any plain compression. \$\endgroup\$ Commented Sep 5, 2014 at 8:19
0
\$\begingroup\$

Capture the flag

Basic rules

There is a rectangular map of cells, each bot has current cell. Bots compete 1 vs 1 at a time, let's call them red and blue. There are N instances of red bot and N instances of the blue bot on the map. Additionally, there is unmovable red base and blue base, both having initially the red flag and blue flag respectively. Bot instances can move around, supress enemy bot instances, capture the enemy's flag. The goal is to bring enemy's flag to the base (which should have the flag). The flag can be returned back to the base. Bots can pass the flag around.

Selectable rules (to be decided)

Map style

  • 2D, 3D or 2.5D;
  • Wrapped-around or not;
  • With walls (destructible, indestructible, buildable by bots) or without;
  • Bases positions and bots initial positions: random, selectable by player, hardcoded in a map?
  • Random-generated, pre-programmed, partially selectable by the player?

Bot capabilities

  • Moving diagonally? Dodging?
  • Seeing the entire map or only surroundings?

Intra-team bot communication

  • Uninhibited
  • Only using messages that takes a move to create or read and that travel not too fast;
  • Inhibited (only indirect by observing positions);

Prior knowledge

  • Should bots know the walls of the map from the beginning?
  • Should bots know the bases posisions from the beginning?
  • Should bots know enemy bots positions from the beginning?
  • If communication between bots is not free, should bots know initial frindly bots position from the beginning?

Attacking

  • Only nearby bots or also "shooting"?
  • Multiple weapons or not?
  • Dodge/protect move?
  • One-hit or health points?

Abandoned flag

  • Is reset to the appropriate base after timeout;
  • Is reset to the appropriate base instantly;
  • Needs to be carried by the bot manually;

Scoring

  • Reset the game after each flag score or continue the game for N moves or N scores?
  • What to do in case of stalemate?

Questions

  1. Is this challenge a good idea?
  2. Which set of proposed rule variants to choose?

My current choice is:

  • Rectangular 2D map without wraparound, with big walls pre-programmed, random single wall-lets placed randomly;
  • Bases positions are pre-defined and known in advance to all bots;
  • Bots having 10 health points, carrying chainsaw (5 damage, 1 distance) and a gun (2 damage, 10 distance);
  • Bots can stay&defend (half of received damage), move 1 cell to 8 directions, attack (without moving); build up to 8 pieces of wall in neighbouring cell, destroy 1 piece of neighbouring wall, capture the flag, score the goal, send a message.
  • Bots can cee a 11x11 rectangle, centered around them, including through walls;
  • Bots are stateful, but can't communicate with other instances directly. They can observe movements of other bots in the vision field or receive messages (if any). The message is a 4 bytes of data (i.e. a number from 0 to 2^32-1) + 1 byte of signal strength, it travels 5 cells per move, decreasing signal strength by one. Message gets received (including the current "signal strength" parameter) by all bots (including enemy ones). Bots reads the message (if any) before making a move. If there are multiple messages, only one with larger signal strength gets received. Hovewer if signal strengths differ only by 1, contect gets XORed.
  • Player choses initial positions (relative to own base) of all his bots;
  • All bots know the initial walls in the map;
  • While the bots stays close to own base, it's health gets recovered by 1 point per move, up to 10, if the flag is present.
  • Each round gets until one of the team scores 5 goals. This team wins (5-x) points, where x is number of opposin team's goals.
  • Abandoned flag can be picked up by either team. All bots know relative position of the own flag at any moment.
\$\endgroup\$
0
\$\begingroup\$

A game of chance

Hello! Thought I would try out the sandbox, a rather useful tool that I haven't utilized yet! This is a game I thought up with some colleagues, basic in theory but has some deeper algorithms to win. I'm thinking of tagging this as code-challenge, any opinions welcome, especially a better name.

How to Play

Every turn, you get one number, pseudo-randomly generated, you need to put this number in a list. The list must always be in numerical order, from lowest to highest, and cannot be changed after the turn has ended. If you can no longer put the number anywhere, where it will still be in numerical order, you lose.

The list is 100 entries, which start as empty slots (seen as "-" or unique characters for your language) and slowly becomes a list of numbers (example that just lost).

Rules

  • You cannot edit the position of a value in the list.
  • The value will be inputted every turn.
  • The random numbers are X-Y. Both X and Y will always be positive and from 0 to 65535.
  • I'm willing to input the number in most ways
  • Any language that I can run! I have both Windows 7 and Linux Mint + VMs for other versions.

Scoring

You get 1 point for every round you last. There are 10 (TBD) rounds for each score, resulting in a maximum score of 1000 (which is very unlikely to ever get).

\$\endgroup\$
11
  • \$\begingroup\$ Assuming your PRNG is uniform, how could there be a better strategy than just mapping 1 to 100 to the range the PRNG can produce and then rounding to the nearest empty cell? Or is the range of the PRNG unknown and different for each game? \$\endgroup\$ Commented Sep 4, 2014 at 16:47
  • \$\begingroup\$ Assuming the PRNG has an even chance to spit out any number in the range, the challenge can be solved optimally, so scoring by rounds lasted is not a good idea. \$\endgroup\$
    – Rainbolt
    Commented Sep 4, 2014 at 16:48
  • \$\begingroup\$ Assume you get the answer 99, would it be best to put it in the 99th slot or the 98th slot? If you put it in the 99th slot, and you get 100 twice - you lose. However if you put it in the 98th, you don't. It's not to get all 100 slots filled, it's to get as far as possible. It's a better game with the random numbers out of 1000, which I have just changed. \$\endgroup\$ Commented Sep 4, 2014 at 16:51
  • \$\begingroup\$ @PopeyGilbert I don't think it makes sense on average to leave that extra room for a second 100, because you might as well get more numbers below 99 than you have space there. I do believe this becomes a lot more interesting, if we're talking about an unknown PRNG range though. You'd need the first few moves to decide how much you'll spread out the numbers. \$\endgroup\$ Commented Sep 4, 2014 at 16:54
  • \$\begingroup\$ @MartinBüttner That's actually a very good idea. Do people suggest that I do that? \$\endgroup\$ Commented Sep 4, 2014 at 16:55
  • \$\begingroup\$ @PopeyGilbert At the same time, in order not to make it too complicated, a good compromise might be to choose the endpoints of the range randomly from some small finite known set. \$\endgroup\$ Commented Sep 4, 2014 at 17:04
  • \$\begingroup\$ @PopeyGilbert I should have said "An optimal guess exists" instead of "An optimal solution exists". This is basically just building a tree and then taking the path that gives you the best odds. Making the endpoints variable just means you have to guess at that too. It might be so hard to guess that you can't make an optimal guess in a reasonable amount of time, so you may want to add a time restriction. When you add a time restriction, things get hairy and people want to know what machine they'll be running on. \$\endgroup\$
    – Rainbolt
    Commented Sep 4, 2014 at 17:13
  • \$\begingroup\$ @MartinBüttner I'm taking your suggestion, and I'll make the points random! RainBolt, you have some very good points, I think I do understand what your saying =) I'm already understanding how amazingly useful "The Sandbox" is. \$\endgroup\$ Commented Sep 4, 2014 at 17:16
  • 1
    \$\begingroup\$ If the deeper problems can be fixed, there are some minor changes which I think would make it easier to understand. I would talk about an array rather than a list, because I think it has stronger connotations of being a fixed size. I would clarify whether the - in X-Y is a subtraction or giving bounds of a range. And I would ask the program to give output of the array index every time it receives an input, so that your control program can validate its moves. \$\endgroup\$ Commented Sep 5, 2014 at 22:47
  • \$\begingroup\$ You refer to both numerical order and alphabetical order. Are these meant to both say numerical order, or is there an extra challenge that I have missed? \$\endgroup\$ Commented Sep 5, 2014 at 23:04
  • \$\begingroup\$ @PeterTaylor Thanks for the advice! I'll fix them tomorrow. Also, GithubPhagocyte, they're both meant to be numerical order =) Will correct too :D \$\endgroup\$ Commented Sep 6, 2014 at 21:16
0
\$\begingroup\$

Finding repeated words in a passage

This challenge is inspired by a question on the Software Recommendations website.

Write a program that outputs the repeated words in a passage on a paragraph by paragraph basis.

The program should take three text files as input:

  • passage: contains the paragraphs to be analyzed
  • blacklist: contains a list of additional pairs that should be considered as repetitions, such as: eat, ate; begin, began, begun
  • whitelist: contains a list of exceptions that should not be flagged, such as the, a, an, to, for

Specifications:

  • In each paragraph, find the repeated words that are not in the whitelist. The keywords in the whitelist file may be separated with commas or line breaks. You are free to choose the one that best suits your needs.
  • The repetitions should be allowed to differ in case, prefixes, suffixes, declension or in grammatical number. For example: allow and Allowed, friend and friends, eat and eaten should count as pairs of repetition
  • Each pair specified in the blacklist should also be considered as a repetition. You are also free to choose how the words in the blacklist are separated. Ideally, these would be copied from a table of irregularites found by a simple online search
  • It should support alternate spellings of German umlauts and the "double s" character in the list files. For example: Fränze and Fraenze, Jörg and Joerg, Müller and Mueller, Gauß and Gauss. The list need only contain one of these words, but both spellings should be searched
  • The output should write the paragraph number, then list the repeated words and their count. For example: 2: eat*3 + however*5 4: moreover*4 + despite*2 5: began/begun*3

    or any representation that is just as readable

Rules:

  • This is a code golf challenge; lowest byte count wins
  • The input file names are excluded from the byte count
\$\endgroup\$
5
  • 2
    \$\begingroup\$ How are we supposed to deal with the grammatical variation? We can't possibly implement every single declension/conjugation of all words. Could you provide a list of words/forms which are to be treated as identical? \$\endgroup\$ Commented Sep 13, 2014 at 9:03
  • \$\begingroup\$ @MartinBüttner Good idea! I should add a blacklist file \$\endgroup\$
    – Tymric
    Commented Sep 13, 2014 at 13:43
  • \$\begingroup\$ Few people write both the "umlauted" and "non-umlauted" spellings in the same piece of text. One writes, say, "Mueller" because one's environment does not support umlauts. \$\endgroup\$ Commented Sep 23, 2014 at 10:23
  • \$\begingroup\$ @SohamChowdhury True, but I am assuming that the person who writes the lists is not necessarily the same as the person writing the texts (student/teacher for example). Also, some people still prefer one spelling to another even when the environment supports it (For example, "dass" is much more common than "daß", even though they are both used) \$\endgroup\$
    – Tymric
    Commented Sep 23, 2014 at 10:31
  • \$\begingroup\$ @Timmy I agree with your first point. \$\endgroup\$ Commented Sep 24, 2014 at 2:17
0
\$\begingroup\$

I liked my first idea, maybe changing the game helps.

Sliding Code

A sliding puzzle, sliding block puzzle, or sliding tile puzzle is a puzzle that challenges a player to slide usually flat pieces along certain routes (usually on a board) to establish a certain end-configuration.

The fifteen puzzle is the oldest type of sliding block puzzle.

enter image description here

The challenge

Write a code that behaves as a sliding board. Given a configuration it should run when such configuration is solvable and not run (aka have compile/runtime errors) if the configuration is not solvable.

Rules

  • The board is your code. It is a 4x4 grid with a total of 15 square tiles with side length >= 1.
  • Each tile, taken alone, should output it's number in the board (from k + 1 to k + 15 with int k of your choice).

Output

Each tile should output its static value (not the actual value). The tile that outputs 13 will output 13 in every different configuration.

The whole board should output true (or 1 or whatever while it express a truthy value) if the configuration can reach the final state: ascending tile numbers on the board from left to right, up to down and the k void tile in the bottom right position.

Score

This is tile , the minimum tile side length wins, meaning a minimum score of 1 can be achieved. If a tie, the greatest k value serves as tie-breaker.

\$\endgroup\$
2
  • \$\begingroup\$ The tiles should be squares. side*side = side^2 thus the score only depends by the side. I'll remove code-challenge tag. \$\endgroup\$
    – Narmer
    Commented Sep 16, 2014 at 14:55
  • \$\begingroup\$ Oh okay, that makes sense then. \$\endgroup\$ Commented Sep 16, 2014 at 14:56
0
\$\begingroup\$

Facing a martian fractal

Fractals are awesome.

They can be used for a very large number of pratical purposes, from antennas to self-similarity of complex networks.

One of the most fantastic uses of fractals tough remains 3D terrain landscaping.

weee! awesome

With such technique you can create awesome landscapes:

This is actually computer generated


Mars is awesome.

The red planet is surrounded in a veil of mistery for its early earth-like life.

Also, as you know, is full of martians:

enter image description here

In this photo we are facing a martian face on mars.


The Challenge

Your task is to create a fractal landscape which resembles the martian face.

  • The prospective can be the most convinient for you as long as the face and the landscape are recognizable.
  • The output should be a few frames GIF of landcape creation, to ensure that fractal approach has been used (just like the one above).
  • You don't need to use the martian face, another landscape can be used as model as long as it has a pareidolic effect of a face in it. You can also not use a model and "draw" the face yourself.
  • Colors are optional. Obviously they will give a greater chance to get more votes.

Here are some other models if you are a bit short of ideas: enter image description here enter image description here enter image description here

\$\endgroup\$
6
  • \$\begingroup\$ While this sounds quite fun, I'm not entirely sure where the programming challenge is in that. In the end it just comes down to who finds the best parameters for the fractal they use. Moreover, it should be possible to automate this by restricting oneself to using octaves of sines and figuring out which ones to use by Fourier transforming the desired output. \$\endgroup\$ Commented Sep 18, 2014 at 10:31
  • 2
    \$\begingroup\$ At the moment this is too broad and set up as an art contest. You need to define what qualifies as a "fractal approach": saying that you'll eyeball a gif is neither objective nor accurate, because I could just hard-code a mesh, run some simplification, and output the frames in reverse order. And allowing the use of any target model whatsoever means it will be judged on those models. This could be reworked into a programming contest if the program has to search a parameter space to find parameters which make a specific fractal generation technique generate the best approximation to Cydonia. \$\endgroup\$ Commented Sep 18, 2014 at 10:35
  • \$\begingroup\$ Although that does still leave an issue of hard-coding, as Martin alludes to. \$\endgroup\$ Commented Sep 18, 2014 at 10:35
  • \$\begingroup\$ I think this slips into the implementation vs output in popularity contests diatribe. In the challenge there is no input, I can't understand how restricting oneself to using octaves of sines and figuring out which ones to use by Fourier transforming the desired output is considered hard coding. Isn't it the point of the challenge? Moreover a fractal approach is self explanatory: generate random fractal terrain, explaining why is fractal and which algorithm was used is answerer's task. \$\endgroup\$
    – Narmer
    Commented Sep 18, 2014 at 10:48
  • \$\begingroup\$ I should add that standard loopholes doesn't apply, but at this point I tought it to be paid. \$\endgroup\$
    – Narmer
    Commented Sep 18, 2014 at 10:49
  • \$\begingroup\$ It is most certainly not self-explanatory that "a fractal approach" means that randomness is involved. Most of the best known fractals have no randomness whatsoever. The defining attribute of a fractal is debated, so if the spec requires a fractal you should give a working definition, and if you use a common one such as a non-integral Hausdorff dimension then ideally you should provide a link to some kind of tool for estimating it. \$\endgroup\$ Commented Sep 19, 2014 at 19:52
0
\$\begingroup\$

Position the Border Guard

[Currently INCOMPLETE. Posting here to save.]

You are in charge of defending an island from an invasion force. To do this, you decide to place n guard posts around the perimeter of your island. You decide that the most effective way to ensure that the whole island is equally guarded is to equally distribute your guard posts around the perimeter of the island. In other words, if someone went around the perimeter your island with a surveyor's wheel, measuring the distance between guard posts walking on the perimeter, it would be equal for every guard post. For instance, if the island were a perfect circle, and I had to place 2 guard posts, they would be placed opposite to each other.

Of course, the island is not a perfect circle. We can describe the shape of the island as sequence of arcs joined together as one cohesive shape, like the clouds in this question. The one difference is that in this question, there will never be a hole in the island. Given an input in the form

n island

Where n is the number of guard posts to place and island is a space separated list of comma separated tuples x,y,r indicating the x position, y position, and radius of the circles that construct the island, output n 2-tuples indicating the x and y positions to place the guard posts in.

\$\endgroup\$
0
\$\begingroup\$

Make a Ray Tracer

A ray tracer is a program which, for each pixel in an virtual screen, traces a path from an imaginary eye through that pixel and calculates the color of the object visible through it.

enter image description here

Ray tracers are famously small enough to fit on a business card! Code and explanation here.

Tired of seeing ray tracers that just render a spheres or a sphere and a box and, if you're lucky, a torus? This challenge addresses this.

This task is to a ray tracer that renders a true color scene specified by arguments. The arguments are:

  1. A triangle mesh, specified by the filename of an .obj mesh file
  2. The diffuse, ambient and specular (more) colors for the entire mesh
  3. A camera, specified by position, direction, up and field-of-view in degrees
  4. A point light source, specified by position and color
  5. A directional light source, specified by direction and color

The output shall be a .ppm file, which can be converted to jpg for inclusion in the answer.

There are lots of .obj files available on the Internet e.g. a teapot, cow and teddy bear and these standard test meshes.

\$\endgroup\$
8
  • \$\begingroup\$ Very much related: codegolf.stackexchange.com/questions/17270/… ... Also you might want to include a bit more about ambient, diffuse and specular materials, or ray tracing in general. The current spec basically assumes that everyone knows how a ray tracer works. \$\endgroup\$ Commented Sep 20, 2014 at 18:14
  • \$\begingroup\$ Requiring loading an obj and mtl file is a stretch for a codegolf. \$\endgroup\$
    – Sparr
    Commented Sep 20, 2014 at 18:23
  • \$\begingroup\$ @Sparr I strip the mtl but the obj is just a few lines, at least in Python. This is codegolf but C and Java etc are going to stand a chance and, by making the input external, entrants cannot try and golf the scene itself. \$\endgroup\$
    – Will
    Commented Sep 20, 2014 at 19:31
  • \$\begingroup\$ I don't know what the "normal" of a camera is, but to properly specify a camera takes three vectors, typically position, look, and up. (And some clipping planes, and a width of field). \$\endgroup\$ Commented Sep 20, 2014 at 20:46
  • \$\begingroup\$ @Will if you're allowing a python library that loads obj files to be used, that's even worse. that puts any language without an obj library at a debilitating disadvantage \$\endgroup\$
    – Sparr
    Commented Sep 20, 2014 at 21:58
  • \$\begingroup\$ @Sparr no, I meant loading obj in pure python is not many lines. I picked it as the simplest mesh format out there. The key thing is, if people embed the scene in the code then this becomes an art contest, which is hated with a passion on this site. \$\endgroup\$
    – Will
    Commented Sep 21, 2014 at 6:24
  • \$\begingroup\$ @Will You could provide a heightmap as textual input. That would be a suitably simple input case for a code golf, imho \$\endgroup\$
    – Sparr
    Commented Sep 21, 2014 at 15:38
  • \$\begingroup\$ @Sparr to convince myself that parsing an obj file is super trivial, here's the pure Python, not even golfed: gist.github.com/williame/5799b75baf6bff3137ba ; obj is just a list of vertices and a list of faces. \$\endgroup\$
    – Will
    Commented Sep 21, 2014 at 16:20
1
90 91
92
93 94
159

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .