461
\$\begingroup\$

What is the Sandbox?

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

To post to the Sandbox, scroll to the bottom of this page or click on the "Add Proposal" link below, 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. 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, replace the post here with a link to the challenge and delete it.

See the Sandbox FAQ for more information on how to use the Sandbox.

The Sandbox works best if you sort posts by "active".

Add Proposal

Search the Sandbox

Browse your pending proposals

Get the Sandbox Viewer to view the sandbox more easily

To add an inline tag to a proposal use shortcut link syntax with a prefix: [tag:king-of-the-hill]

\$\endgroup\$
  • \$\begingroup\$ How are tags added to questions? \$\endgroup\$ – guest271314 Jan 9 at 7:51
  • \$\begingroup\$ @guest271314 You can use this markup to create a tag in a draft: [tag:code-golf] \$\endgroup\$ – DJMcMayhem Aug 29 at 15:19
  • \$\begingroup\$ Why no featured anymore? Can't we have it auto-added or something? \$\endgroup\$ – JL2210 Sep 26 at 15:57
  • 1
    \$\begingroup\$ @JL2210 We now have a permanent info box that links to the Sandbox, so the featured tag isn't necessary \$\endgroup\$ – caird coinheringaahing Sep 29 at 13:43

2622 Answers 2622

0
\$\begingroup\$

Define the finite field GF(9)

\$GF(9)\$ or \$GF(3^2)\$ is the smallest finite field whose order isn't a prime or a power of two. Finite fields of prime order aren't particurlarly interesting and there are already challenges for \$GF(2^8)\$ and \$GF(2^{64})\$.

Challenge

First define nine elements of the field. These don't have to be integers. You can use any nine distinct objects of your language.

Then define two binary operations, addition and multiplication, satisfying the field axioms:

  • Both operations must be commutative and associative.
  • Addition has the identity element \$0\$ and an additive inverse for each element.
  • Multiplication has the identity element \$1\$ and a multiplicative inverse for each element except \$0\$.
  • Multiplication distributes over addition: \$a·(b+c) = (a·b)+(a·c)\$

Since the field is really small, you can test the axioms exhaustively to check your implementation or print the addition and multiplication tables.

Mathematical construction

Elements of \$GF(3^2)\$ can be interpreted as polynomials of the form \$P(x)=a x+b\$ over \$GF(3)\$. (Addition and multiplication in \$GF(3)=\{0,1,2\}\$ are the standard integer operations modulo 3.)

Then addition in \$GF(3^2)\$ is simply the addition of two polynomials. Multiplication is defined by the product of two polynomials, reduced modulo a polynomial of degree 2 which is irreducible over \$GF(3)\$.

Example

Mapping polynomials to integers with \$n=3a+b\$ and using the irreducible polynomial \$x^2+1\$ yields the following addition and multiplication tables. Note that there are other possible isomorphisms of these tables.

+   0 1 2 3 4 5 6 7 8   *   0 1 2 3 4 5 6 7 8
   ------------------      ------------------
0 | 0 1 2 3 4 5 6 7 8   0 | 0 0 0 0 0 0 0 0 0
1 | 1 2 0 4 5 3 7 8 6   1 | 0 1 2 3 4 5 6 7 8
2 | 2 0 1 5 3 4 8 6 7   2 | 0 2 1 6 8 7 3 5 4
3 | 3 4 5 6 7 8 0 1 2   3 | 0 3 6 2 5 8 1 4 7
4 | 4 5 3 7 8 6 1 2 0   4 | 0 4 8 5 6 1 7 2 3
5 | 5 3 4 8 6 7 2 0 1   5 | 0 5 7 8 1 3 4 6 2
6 | 6 7 8 0 1 2 3 4 5   6 | 0 6 3 1 7 4 2 8 5
7 | 7 8 6 1 2 0 4 5 3   7 | 0 7 5 4 2 6 8 3 1
8 | 8 6 7 2 0 1 5 3 4   8 | 0 8 4 7 3 2 5 1 6

Test of distributivity using the tables above:

$$5 · (2 + 7) = 5 · 6 = 4$$ $$(5 · 2) + (5 · 7) = 7 + 6 = 4$$

Scoring

This is code golf. Your score is the sum of bytes of the functions (or programs) for addition and multiplication. Lowest number of bytes wins.

Sandbox notes

  • Each finite field has a unique structure, so I wouldn't consider this question a duplicate.
  • I think it's a good idea to post an example of addition and multiplication tables to help people who aren't mathematically inclined.
\$\endgroup\$
  • \$\begingroup\$ Looks like a solid challenge. I like that the field size here is not a power of two so that bit encoding won't be useful, and 3^2 looks like a good small choice. About "You can use any nine distinct objects of your language", I'd suggest restricting this to prevent something cheesy like having the objects be ones pre-made to implement the operation or be strings that can be executed as code. In a similar style challenge, I allowed any one-byte numbers or characters. \$\endgroup\$ – xnor Dec 7 at 10:35
  • \$\begingroup\$ It might also be good to warn people that it won't work to do usual addition and multiplication modulo 9, since I think that's a common misconception. \$\endgroup\$ – xnor Dec 7 at 10:37
0
\$\begingroup\$

Next Shared Totient

\$\endgroup\$
  • \$\begingroup\$ Adding bounds is not generally necessary: the usual assumption on this site is if a solution breaks for memory / data type reasons that aren't intentional abuse then the solution is still valid. \$\endgroup\$ – FryAmTheEggman Dec 4 at 18:48
0
\$\begingroup\$

Round up my number

Given two positive nonzero integers (a and b), output the result of this operation: repeatedly increment the given number a by 1 until it becomes a multiple of b, or is already a multiple of b.

Examples

Definitions: true = is a multiple of b, false = is not a multiple of b.

  • f(1,3) = 3 because 1 is false, 1+1 is false, but 1+1+1 is true. Therefore 3 is returned.

  • f(5,3) = 6 because 5 is false, but 5+1 is true. Therefore 6 is returned.

  • f(9,3) = 9 because 9 is already a multiple of 3.

  • f(12,5) = 15 because 12 is false, 12+1 is false, 12+2 is false, but 12+3 is true. Therefore 15 is returned.

Rules

  • Input/output can be given by any convenient method.
  • You can print it to STDOUT or return it as a function result.
  • Either a full program or a function are acceptable.
  • Any amount of extraneous whitespace is permitted, provided the characters line up appropriately.
  • Standard loopholes are forbidden.
  • This is so all usual golfing rules apply, and the shortest code (in bytes) wins.
\$\endgroup\$
  • 3
    \$\begingroup\$ I'm not great at modular arithmetic, but \$ a + (b - a \bmod{b}) \bmod {b} \$ doesn't seem particularly interesting to golf. \$\endgroup\$ – FryAmTheEggman Dec 5 at 15:20
  • \$\begingroup\$ Really just a+-a%b assuming your language isn't weird with modulo of negatives. \$\endgroup\$ – xnor Dec 5 at 23:44
0
\$\begingroup\$

What's that frequency?

This is my first code-golf challenge, so apologies if it is a little unclear/already has been done. I gave the past challenges a good look over, but I may have missed something.

Create a function or a full program which accepts a frequency value, and then outputs the closest musical note, and the octave, this frequency corresponds to.

This function/program should support eight full octaves worth of notes, starting from C0 up to and including B8.

Test cases:

440.00 -> A4
466.16 -> A#4
466.20 -> A#4
261.63 -> C4
16.35 -> C0
0.00 -> C0
7902.13 -> B8
10000.00 -> B8

A full list of frequencies and notes they correspond to can be found here: https://pages.mtu.edu/~suits/notefreqs.html

This is a code golf, so shortest code wins!

\$\endgroup\$
  • 1
    \$\begingroup\$ Thanks for using the sandbox! :) I found the inverse challenge. I feel as though I've reviewed this version as well, but perhaps it never left the sandbox. In any case, you should include a method by which to classify the frequencies, and what precisely you mean by closeness in the body of your challenge. External links are nice but not enough! \$\endgroup\$ – FryAmTheEggman Dec 5 at 14:58
0
\$\begingroup\$

A game of putting lines through dots.

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

Get to my destination

Given the speed of the car, the length of the road, and the position of my destination, output the fewest possible steps I need to get to my destination.

How does the car move?

This car that I rode in the morning has a weird feature: after the driver presses break, the car's speed gets halved and rounded down. So if the car's initial speed is 3, it produces 1.5 rounded down, which becomes 1. The symbol for this is B.

An alternate decision for what the driver should do in a second is to not press brake. The symbol for this decision is ..

If the car gets out of the road it bounces back in the opposite direction (similar to Backhand).

An example

The length of the road is 10. Let's draw it:

C000000000

The C character is the car. Now we know that the car goes right 2 blocks per second:

000C000000

But my destination is the second position. I need to press brake.

After pressing brake the car's speed is 1 block backwards per second.

00C0000000
0C00000000

And now I've got to my destination. But I couldn't stop without pressing brake, so I need another brake.

The produces the output code B.B.

Test cases

3 10 2 -> B.B
\$\endgroup\$
0
\$\begingroup\$

Rate your brevity

This challenge is to produce some code that will generate a score for itself based on the number of unique characters used, and the repetitions of those unique characters within the code itself.

The first scoring system

Each additional unique character has an escalating penalty to your score.

The first unique character is worth -1
The second unique character is worth -2
The third unique character is worth -3
etc...

The second scoring system

Each repetition of a given character incurs a further escalating penalty to your score.

The first usage of a given character incurs no additional penalty
The second usage of a given character incurs an additional penalty of -1
The third usage of a given character incurs an additional penalty of -2
The fourth usage of a given character incurs an additional penalty of -3
etc...

e.g.

  • The code abc would have a score of -6
  • The code aabc would have a score of -7
  • The code aaaabc would have a score of -12

Rules

  • Your score starts at 0
  • The code must actually parse itself - I thought of print -45 before you did.
  • You may pass the code into your function any way you see fit - be it reading a file, using STDIN, passing it as an argument, or any other means.
  • The highest score for a given language wins.

Test

The below Stack snippet will parse your code and produce a score based on the scoring systems defined above:

function testScore() {
  var score = 0,
    counter = 0,
    input = document.getElementById('code').value,
    x,
    y,
    instances = {},
    keys;
    
  input = input.split('');

  for(x = 0; x < input.length; x++) {
    if(typeof instances[input[x]] == 'undefined') {
      instances[input[x]] = 0;
      score -= ++counter;
    }
    
    instances[input[x]]++;
  }

  keys = Object.keys(instances);
  for(x = 0; x < keys.length; x++) {
    for(y = 0; y < instances[keys[x]]; y++) {
      score -= y;
    }
  }

  alert('Your score is:\n' + String(score));
  
  return false;
}
<form onsubmit="return testScore(this);">
  <div>
    <textarea id="code" style="width: 100%; height: 150px;"></textarea>
  </div>
  <div>
    <button type="submit">Generate score</button>
  </div>
</form>

\$\endgroup\$
  • \$\begingroup\$ I'd appreciate some pointers on what tags to use for this one - it's similar to code golf but isn't quite code golf. \$\endgroup\$ – Scoots 2 days ago
  • \$\begingroup\$ Similar but a slightly different scoring system \$\endgroup\$ – Veskah 2 days ago
  • \$\begingroup\$ This is two challenges: First, reading your own source code. Second, creating the score for an input string. In addition, the condition of "Parse yourself" is a non-observable requirement. In this case, it's definetly bad because it forces the two separate challenges approach onto people. I understand why you want to exclude print -45, but right now, the whole quine-except-not-really thing doesn't seem helpful. \$\endgroup\$ – AlienAtSystem 2 hours ago
  • \$\begingroup\$ @AlienAtSystem Respectfully I disagree with your assertion that reading the source code is a challenge; I'm very explicit that any means of getting your source code in is acceptable, even copy/pasting it as a command line argument. The parsing of your own code - I thought it might encourage people to golf in a way they may not be used to due to the escalating penalties involved in the scoring system. \$\endgroup\$ – Scoots 1 hour ago
0
\$\begingroup\$

Expand a road network


You've been employed as a city planner (obligatory seinfeld clip) and you have been tasked with expanding the road system of Codegolfville. Here's a diagram of what Codegolfville could look like:

        | |
        | |
--------+ +-------
--------+ +-------
        | |
        | +-------
        | +-------
        | |
        | |

Your job is to expand the existing infrastructure \$n\$ blocks in a specific direction.

The Challenge

  1. Take two inputs - a direction to expand in, and the number of blocks to expand - through any reasonable input format.

  2. Expand the existing roadways in the ASCII map, in the direction specified.

    a. You must take into account the existing roadways - you can only expand on roads that are already there, and if there are no roads to expand, you won't expand anything.

    b. Your program must work for any example map, not just the one provided above.

  3. Show the output on STDOUT, if your language supports it.

Test Cases

        will be done soon

Other Rules

This is , so lowest score in bytes wins. Standard loopholes are forbidden. Have fun!

\$\endgroup\$
  • 1
    \$\begingroup\$ Are blocks a fixed dimension or is it based on the size of the input? Does it expand in only one direction or can it be multiple? Finally, what does expansion mean? Are we replicating the block n times? Merely extending the roads on the expanding edge (i.e. appending n*width - or |s)? \$\endgroup\$ – Veskah 2 days ago
0
\$\begingroup\$

Union of Two Polygons

Given two intersecting polygons as input, output a third polygon that is the union of the two input polygons, that is to say, the perimeter that encloses all points present in at least one of the two input polygons.

Example polygon unions

Notes and Rules

  • Input will be two lists of at least 3 2d points each, taken in any convenient format.
  • Output should be a list of 2d points, in any convenient format.
  • It does not matter which point you list first.
  • It does not matter whether you output in clockwise or counterclockwise order.
  • Polygons may be concave
  • You may assume that both polygons are not self-intersecting
  • You may assume that the polygons overlap in at least two places exclusively via edge-edge crossings rather than vertex-edge intersections, vertex-vertex intersections, or flush edge-edge overlaps.
  • You may assume that the polygons do not overlap in such a way that the union would have at least one hole in it.
  • You must be accurate to at least 0.01 for all polygons between -100 and 100 units along each axis.
  • Standard rules apply. Shortest code wins.

\$\endgroup\$
  • \$\begingroup\$ Can you add some examples? \$\endgroup\$ – Carson Graham 1 hour ago
-1
\$\begingroup\$

Play snake on a 50*50 grid. The snake will start at length 3, heading (2,0) with body (1,0) and (0,0). It shouldn't bump into wall or itself. There is always one food, which increases the length of snake by 1 when eaten.

Smallest amount of steps till there's no space to place food win. Flexible I/O, anyway it doesn't matter.

Vote on whether the food placer is transparent and allow food manipulation(Up for yes, down for no)

\$\endgroup\$
  • \$\begingroup\$ I think there are already quite a few snake challenges. You need to flesh out some more details here. How do you determine where the food will spawn? Will you be given some sampling of the game state (vision?) on each step? \$\endgroup\$ – Beefster Dec 28 '18 at 19:22
  • \$\begingroup\$ @Beefster If "food placer is transparent and allow food manipulation", you just know how it spawns; If not, you get access to the location of current food \$\endgroup\$ – l4m2 Dec 29 '18 at 3:44
  • \$\begingroup\$ If food manip. is allowed, is the optimal score achievable by finding an Hamiltonian path starts with the snake? \$\endgroup\$ – user202729 Dec 29 '18 at 8:55
  • \$\begingroup\$ @user202729 It depends on how strong the manipulation is \$\endgroup\$ – l4m2 Dec 29 '18 at 10:54
-1
\$\begingroup\$

No-alphanumeric code exec

\$\endgroup\$
  • 4
    \$\begingroup\$ -1 for winning entries must be written in one of the 25 top languages. \$\endgroup\$ – Jo King Jan 19 at 9:28
  • \$\begingroup\$ I'm trying to exclude golfing languages with that - this only seems like an interesting challenge to me if you don't allow languages where it's excessively trivial. Any suggestions for how to do that in a more permissive way or other thoughts about that goal? \$\endgroup\$ – lahwran Jan 19 at 22:13
  • \$\begingroup\$ actually, I think this will be quite difficult in many code golf languages as well, as they usually try to get brevity by cramming things into single letters and numbers. there are of course languages where it'll be excessively trivial, but that's fine, those solutions most likely just won't be upvoted. \$\endgroup\$ – lahwran Jan 19 at 22:21
  • \$\begingroup\$ Most golfing languages won't be able to pull sth. from the interconnected-webs afaik, so there's no real need to invent arbitrary restrictions to ban them. \$\endgroup\$ – ბიმო Jan 21 at 16:25
  • 1
    \$\begingroup\$ Also "but that's fine, those solutions most likely just won't be upvoted" is too optimistic, usually it's the other way around :( \$\endgroup\$ – ბიმო Jan 21 at 16:26
  • \$\begingroup\$ dang, good to know. \$\endgroup\$ – lahwran Jan 21 at 22:55
-1
\$\begingroup\$

A Quine that Grows!

Challenge

Create a quine that, when run, outputs itself but copied larger in the next one. The output should be able to be run, and get larger each time the output is run. The output must consist only of characters from the original quine!

EX:

abc //original
abcabc //output

or

abc //original
aabcc //output

What not to do

abc //original
abcgef //output

abc //original
abcoooooooooooo //output

An example I created

Try it Online! It replicates pretty fast if I do say so myself!

Points

This challenge is meant to be a codegolf, but also emphasize on how fast it replicates. So perhaps something like the speed at which it gets bigger divided by the number of bytes.

I really don't want loopholes like just repetitively adding characters to a section of the code, making infinite loops, and things of the like.

Any input on how to make this a good challenge? I'm open to suggestions!!!

\$\endgroup\$
  • 1
    \$\begingroup\$ Related, related (probably a dupe) \$\endgroup\$ – Jo King Feb 10 at 10:25
  • \$\begingroup\$ @JoKing What about a polyglot that gets bigger? It runs, making another program that runs and outputs a bigger version of the original, and vice versa. \$\endgroup\$ – KrystosTheOverlord Feb 10 at 16:02
  • \$\begingroup\$ where's the polyglot part come from? otherwise that sounds like the second one \$\endgroup\$ – Jo King Feb 10 at 22:04
  • \$\begingroup\$ @JoKing The output has to be in a different programming language, and then create a larger version of the original, then this larger original makes a larger of second program etc... Also to prevent easy loopholes, no using program languages that are derivatives of eachother \$\endgroup\$ – KrystosTheOverlord Feb 10 at 22:32
-1
\$\begingroup\$

Just idea. Not sure what to do exactly.

Evolutionary Golf

Make simple (not golfed at all at first) code for (some program) with language (something).

Now, change a little bit (maximum 3 byte) of code to make it shorter.

Altered code must work properly (this is how evolution work).

(Maybe here will be starting code).

Sandbox

First. What program would be best? For example, 'Hello World' program is not proper, because it is too short, and can't golf that much.

Second. What language would be best? Esolang like BF? Or something like C?

\$\endgroup\$
  • \$\begingroup\$ If I understand the challenge idea correctly you will post an ungolfed answer that does something in some (probably verbose) language (i.e. FizzBuzz in C#). And then answers after that should have a Levensteihn distance change \$c\$ where \$1\leq c\leq3\$ (at least 1 delete) that does the same thing (in any language). And the shortest answer that's at the end of the answer chain wins if no other answers are posted within 2-3 weeks (which is usually the case with answer-chaining challenges)? Or do you mean that anyone can post an ungolfed program, and others using the same language chain it? \$\endgroup\$ – Kevin Cruijssen Jun 26 at 9:04
  • \$\begingroup\$ @KevinCruijssen I'm thinking of both. This is just brief outline, so everything can be changed. \$\endgroup\$ – LegenDUST Jun 26 at 12:10
  • \$\begingroup\$ this is just game of nim with extra steps \$\endgroup\$ – Kenneth Taylor Aug 2 at 17:51
-1
\$\begingroup\$

Print all the commands

META Just a rought idea, needs to be worked out.

Write a program that prints all the keywords and commands that are available in your langauge when you do not import/add anything

Details

  • require full program or standard code-golf?
\$\endgroup\$
  • 2
    \$\begingroup\$ Understanding that this is a rough idea, what happens in languages without commands corresponding to single tokens e.g. ///? \$\endgroup\$ – lirtosiast Jul 18 at 15:49
  • 7
    \$\begingroup\$ It is my opinion that this sort of challenge will likely never be clear. \$\endgroup\$ – Wheat Wizard Jul 18 at 16:08
  • \$\begingroup\$ I'd imagine for /// you'd output all valid non-text characters, so \ /. \$\endgroup\$ – bigyihsuan Jul 18 at 17:08
  • 1
    \$\begingroup\$ Another thing is that language version would be specified. For example, Python 2 has print as a keyword, while Python 3 has print() instead. \$\endgroup\$ – bigyihsuan Jul 18 at 17:10
  • \$\begingroup\$ Pretty sure this (or something similar enough to be a dupe) has been done before. Lemme see if I can find it .... \$\endgroup\$ – Shaggy Jul 21 at 21:11
  • \$\begingroup\$ Found it! codegolf.stackexchange.com/q/162384/58974 \$\endgroup\$ – Shaggy Jul 21 at 21:13
  • \$\begingroup\$ One way to do this might be to make it language specific? While that isn't usually popular, outputting all of, say, Python's commands in most languages besides python is a dupe of the Rickroll challenge. However, in python itself that isn't the best approach. I can't say how well reveived it'd be, but you could try "output these MATLAB commands in MATLAB" and see what people think. \$\endgroup\$ – FryAmTheEggman Jul 23 at 19:45
-1
\$\begingroup\$

Here's a challenge I'd like post because I'm curious to see what people will come up with. It's a bit of an anti-code-golf question because the code should look normal.

Is it clear what the constraints? Did I miss anything?


Introduction

Write a piece of unsuspicious code that does the following:

Let's say you've written a parser that parses it's input line by line and somewhere in your code is

find_string(line, "[start]", "[end]") // returns string between [start] and [end]

This program, when given it's own source code plain text as input, will match that line (twice actually); but we don't want that. It should still parse what it was designed for but not match any line of it's own source code.

Rules

  • It's preferred that your code makes it obvious that one of it's intended uses is to parse (and not match) itself. This is so anyone 'refactoring' the code will not accidentally undo the trick that made it work.
  • Your source code as input will be reduced to a single line.
  • Your program should be able to handle large input (~10mb) and perform reasonably (for your chosen language).
  • Your program does not need to parse the input line by line but that just seems like something reasonable code would do.
  • Points are awarded for code that looks like a normal parser and contains as little assumptions about the input as possible. Bonus points for solutions that contain the start and end delimiters in that order.

Easy solutions are to swap the start and end token arguments or to pre-treat the tokens in some way but that would look suspicious. Someone will come along and refactor your code and break the 'trick'.

I'm interested in reasonable solutions because this is a reduction of a real life problem.

Example Input and Output

  • Input lines may or may not contain [start] or [end], only return it in the output when it occurs in a pair.
  • Input lines will never contain more than one pair of [start] and [end] tokens.
  • Input lines may contain additional content before [start] or after [end]
  • Your source code plain text will be inserted at a random line in the input.

Input #1:

[start]hello[end]
<<your source code plain text>>
dont output this[start]world[end]

Output #1:

hello world

Input #2:

lorem[start]i solemnly[end]
[start]false start
[start]swear[end]
ope, sorry just passing through
this is not the[end]
[start]that i'm up to[end]ipsum
[start]no[end]dolor
<<your source code plain text>>
[start]good[end]

Output #2:

i solemnly swear that i'm up to no good
\$\endgroup\$
  • \$\begingroup\$ What is the objective winning criterion? \$\endgroup\$ – Unrelated String Aug 9 at 5:16
  • 1
    \$\begingroup\$ This could be a good challenge if it was just 'Write a program that takes a line of input and returns the concatenation of anything between [start] and [end] on each line, otherwise an empty string', with the restriction that if it was fed itself, it wouldn't return anything \$\endgroup\$ – Jo King Aug 9 at 6:05
  • \$\begingroup\$ I'm a little confused about what Bonus points for solutions that contain the start and end delimiters in that order. means, since I thought the point was that we're not allowed to have that? \$\endgroup\$ – Jo King Aug 9 at 6:07
  • 2
    \$\begingroup\$ "unsuspicious code" will raise red flags in the minds of a number of old-timers, for historical reasons which I won't explain in detail. What I will say is that unsuspicious is subjective, and we insist on objective criteria. In terms of actual reasonable solutions to the real world problem: don't use magic strings. If "[start]" and "[end]" are both constants and defined on separate lines, the problem is averted, and anyone who refactors to inline them deserves all the bugs that causes. \$\endgroup\$ – Peter Taylor Aug 9 at 10:45
-1
\$\begingroup\$

Make it improbable... BUT NOT IMPOSSIBLE

You must make a program that outputs truly once in a while. However, making it have output falsy all the time is not acceptable.

Rules

  • Standard loopholes are forbidden.
  • You may use any of accepted I/O formats.
  • Your program must be possible to output a truly value.
  • When not outputting a truly value, you may either output a falsy value or not output anything at all.
  • You may output two or more values, however if it contains a truly value, then the output is considered truly.
  • The probability of outputting a truly value must be at most 1/2.
  • Your program must not take/use an input.
  • Using non-deterministic but non-random(Such as getting the time) is prohibited. However, if date etc. is used in the builtin random function, it is allowed.
  • The program must theoretically always terminate or stop outputting anything.
  • You may assume that you have a fast enough computer and large enough memory.
  • Your program should not be affected by raising the maximum value of a data type. You may still use unaffected constants.
  • Data types must be following its spec: ie. for an unbounded arbituary precision integer type, you may assume that it can go as high as you want(but you are not allowed to increment until an error as in the rule above), but a double-precision floating-point format still has 22-bit fraction and 8-bit exponent.
  • Score is calculated as: Pl-1.5l, where P is the probability and l is the byte length.

Example(s)

JavaScript
alert(Math.random()<0.1)
P=0.1, l=24 => Score=23.534

The lowest score wins!

\$\endgroup\$
  • \$\begingroup\$ So is it acceptable for just a program that always outputs truly? You need to define improbable. (I assume this probability must be at least lest than 1/2.) Providing a few examples will be helpful. So is there only output and no input? In addition, you need an objective winning criterion, which is a criterion that posts for this challenge will need to comply in order for it to be a valid answer. (Usually this criterion is making the source code shortest.) \$\endgroup\$ – A̲̲ Sep 24 at 13:37
  • \$\begingroup\$ Sorry, I posted this incomplete. \$\endgroup\$ – Naruyoko Sep 24 at 16:14
  • \$\begingroup\$ I don't think your scoring method works particularly well, unless I'm making an error. For any \$ l > 1 \$ your score cannot be less than 1. Achieving a score arbitrarily close to 1 is relatively easy. So the only way to beat that is to have a one or zero byte solution. It is easy to make the probability increase exponentially with linear code additions. It might be necessary to penalise length massively, like \$ P \times e^{l!} \$, to avoid similar problems. \$\endgroup\$ – FryAmTheEggman Sep 24 at 18:39
  • \$\begingroup\$ I see. I guess P^l^k is too penalizing but Pk or Pe^k is too forgiving. Pe^l! looks simple enough but is is the middle so it may work. \$\endgroup\$ – Naruyoko Sep 24 at 20:11
  • 1
    \$\begingroup\$ The problem with any of scoring methods for this challenge is that it is possible for any increasing computable function f, a program with length l can have P around 1/f(l). The only non-broken formula could be uncomputable, i.e. P/BB(l), where BB is the busy beaver function. \$\endgroup\$ – Naruyoko Sep 24 at 20:15
-1
\$\begingroup\$

Title: Transposition

** The challenge **

Given a set of notes (as a string, or a list, or any other reasonable input - but as letters and accidentals, not a numerical equivalent), the key those notes are in, and a target key; output the notes transposed into the new key. Some of the notes may not exist in the scale for the given key (e.g Eb in the key of C).

** Inputs **

The complete set of input notes for this challenge will use the English naming convention, and so are as follows:

Ab,G##,A,A#,Bb,B,C,C#,Db,C##,D,D#,Eb,E,F,F#,Gb,F##,G,G#

where "b" represents a flattened note (down one semitone per b), and # represents a sharpened note (up one semitone per #). Theoretically all notes can be extended further with more #s and bs; but for the purposes of this program that won't happen beyond what is already given.

** What is transposing? **

Transposing a song involves "moving" the song into a different key, by finding the equivalent note of the scale in that key.

We will assume Major scales for the purposes of this challenge.

** Scales **

The scales for this challenge are officially as follows:

  • C: C, D, E, F, G, A, B, C
  • C#: C#, D#, E#, F#, G#, A#, B#, C#
  • Db: Db, Eb, F, Gb, Ab, Bb, C, Db
  • D: D, E, F#, G, A, B, C#, D
  • D#: D#, E#, F##, G#, A#, B#, C##, D#
  • Eb:Eb, F, G, Ab, Bb, C, D, Eb
  • E: E, F#, G#, A, B, C#, D#, E
  • F: F, G, A, Bb, C, D, E, F
  • F#: F#, G#, A#, B, C#, D#, E#, F#
  • Gb: Gb, Ab, Bb, Cb, Db, Eb, F, Gb
  • G: G, A, B, C, D, E, F#, G
  • G#: G#, A#, B#, C#, D#, E#, F##, G#
  • Ab: Ab, Bb, C, Db, Eb, F, G, Ab
  • A: A, B, C#, D, E, F#, G#, A
  • A#: A#, B#, C##, D#, E#, F##, G##, A#
  • Bb: Bb, C, D, Eb, F, G, A, Bb
  • B: B, C#, D#, E, F#, G#, A#, B

For simplicity, we can assume that both notes in the pairs A#/Bb, C#/Db, D#/Eb, F#/Gb, G#/Ab, C##/D, F##/G, G##/A are enharmonically equivalent (i.e. interchangeable - although they're not, always).

For scales with double-sharps, I will accept the enharmonic equivalents as an alternative implementation:

  • D#: D#, E#, G, G#, A#, B#, D, D#
  • G#: G#, A#, B#, C#, D#, E#, G, G#
  • A#: A#, B#, D, D#, E#, G, A, A#

but for all other notes in the scale, they must match. If the note isn't in the scale, either can be used.

e.g.

  • F in the key of C should transpose to F# in the key of C#, and not to Gb, because that option in the pair is explicitly in the scale
  • but D in the key of C# could transpose to either C# or Db in the key of C, because it's an incidental anyway and so there's no easy rule to determine which it should be.

BONUS feel-good points *: normally it's # if you're going up, and a b if you're going down - feel free to implement this if you want!

For double-sharps (e.g F##) in all cases, It's OK if the program "resolves" these (e.g.to G in that case) even if they are in the scale; but again, some BONUS feel-good points * if you keep the double-sharps in.

Examples

  • CDEFGABC in C to A -> ABC#DEF#G#A
  • C# in C to A -> A# OR Bb
  • ABCDEFGBAF#Bb in Bb to Gb -> FGAbBbCDbEbGFDGb
  • CCGGAAAAGFFEEDDCGGGFFEEEDCGGGFFFFEEED in C to G# -> G#G#D#D#E#E#E#E#D#C#C#B#B#A#A#G#D#D#D#C#C#B#B#B#A#G#D#D#D#C#C#C#C#B#B#B#A#

Websites like http://www.logue.net/xp/ can be used to test your answers to other inputs

* Bonus feel-good points don't get you anything extra, unless someone can come up with a quantifiable difference that it should make to the score?

\$\endgroup\$
  • \$\begingroup\$ This is kind of similar but doesn't use scales and has a different set of chords, so I think this is effectively different? \$\endgroup\$ – FryAmTheEggman Sep 24 at 18:47
  • \$\begingroup\$ Yes, I agree it's similar but doing a different thing to me (they're using chords, and so have the extra text to worry about; but I'm doing notes, like sheet music; and so you have accidentals to worry about) \$\endgroup\$ – simonalexander2005 Sep 25 at 8:48
-1
\$\begingroup\$

Interpret Unneccesary (Not quite)

Unneccesary is a joke language created by Keymaker. The source is unneccesary, and if given, it will error out.

Your task here is similar. If there is input, your program should error out. If the input is empty, your program should do nothing and terminate.

\$\endgroup\$
  • 1
    \$\begingroup\$ What does it mean to error out? \$\endgroup\$ – Beefster Oct 24 at 19:14
  • \$\begingroup\$ @Beefster throw a runtime error... Or? \$\endgroup\$ – HighlyRadioactive Dec 1 at 10:15
  • \$\begingroup\$ What if I'm using a language that does not have terminal errors such as Bash? \$\endgroup\$ – Beefster Dec 2 at 19:34
-1
\$\begingroup\$

Mirror, Mirror, on the wall. Who's the fairest of them all?

Well, you know it's Snow White, and the evil Queen is at it again. Will Snow White be saved? Will she fall asleep once again? Will the Prince find her?

Challenge:

Given an arbitrary number (>= 2) of possibly duplicated hexadecimal color values (ranging from #000000 to #FFFFFF) and paired strings, calculate the following:

  • If #FF0800 (Candy apple red) appears in the input, return "Return to Sleeping Death"
  • If #000000 appears in the input, return "Saved by Grumpy"
  • If #A98AC7 or #111111 appears in the input, return "Saved by Happy"
  • If #21E88E or #222222 appears in the input, return "Saved by Sleepy"
  • If #32DCD5 or #333333 appears in the input, return "Saved by Bashful"
  • If #43D11C or #444444 appears in the input, return "Saved by Sneezy"
  • If #54C563 or #555555 appears in the input, return "Saved by Dopey"
  • If #65B9AA or #666666 appears in the input, return "Saved by Doc"
  • If #76ADF1 or #777777 appears in the input, return "Saved by the Seven Dwarfs"
  • If #FFFAFA (Snow) appears in the input, return "Saved by Love's first kiss"
  • If an F variant appears in the input, return "Press F to pay respects to Snow White"
    • An F variant is any number that contains at least one F in its hexadecimal form, and is otherwise all 0s (e.g. #0FF0F0, #FFFFFF, #00000F, #F00F00)
  • If multiple of the preceding occur, return the "fairest" answer. The "fairest" answer is calculated as follows:
    • For all N occurrences of special color values, choose the (N-1)/2-th (truncating division) occurrence. The associated special output is the "fairest" answer.

"Appears in the input" here refers to only the hexadecimal color values, and not to the paired strings.

  • If none of the preceding occur, return the "fairest" answer. The "fairest" answer is calculated as follows:
    • Take the hexadecimal color value at the end of input values, write it down, and exclude that single color-string pair from consideration as the "fairest" answer
    • Show its binary form to the mirror, computing a reflection of only the last 24 (#FFFFFF is the mask) bits.
    • Choose the hexadecimal color with least Hamming distance from the reflection. If there are multiple (N) such colors, choose the middle ((N-1)/2-th, truncating division) instance of the color. The "fairest" answer is the associated string for the color.

Inputs:

A sequence of hexadecimal color values and String values separated by a space. The input may also be read as two separate sequences of hexadecimal color values and String values, or a single sequence of 2-tuples (either (hexValue, stringValue) or (stringValue, hexValue) is permissible, as long as the ordering is consistent across all 2-tuples). Input order matters - for each index, the corresponding element in the supply of color values is "associated" with the corresponding element in the supply of String values, and duplicates can affect the "fairest" answer. The effect is something like Function(List(HexColorValue),List(AssociatedStrings)) -> "fairest" answer. Hexadecimal color values may be represented as either (your choice of) a String "#"+6 digits, or 6 digits alone, as long as the representation is consistent across all color values.

Here's an example input:

76ADF1 Return to Sleeping Death
2FE84E Return whence ye came!

Here's another example input:

2FE84E Return to Sender
4FFAFC Return of the Obra Dinn
2FE84E Return to the house immediately, young lady!
2FE84E Return to Sleeping Death
2FE84E Return of the Jedi

Here's the third example input:

2FE84E Return to Sender
4FFAFC Return of the Obra Dinn
2FE84E Return to the house immediately, young lady!
2FE84E Return to Sleeping Death
7217F8 Return of the King

Here's the final sample input:

F4A52F Eating hearts and livers
F4A52F Eating apples
F4A52F Eating porridge
F4A52F Eating candy houses
F4A52F A Modest Proposal

Outputs:

The "fairest" answer as computed by the specified logic. For example, on the first sample input, the "fairest" answer would be Saved by the Seven Dwarfs, due to the special hex color 76ADF1 appearing within the input.

In the second sample, there are no special inputs. First, we take "2FE84E Return of the Jedi", which has value #2FE84E. In binary, this is:

001011111110100001001110

We take the reflection from the mirror, getting:

011100100001011111110100

We compare it against 2FE84E (001011111110100001001110) and 4FFAFC (010011111111101011111100), which have Hamming distances of 18 and 12 from the reflection, respectively. Since #4FFAFC has the uniquely lowest Hamming distance from the reflection, the "fairest" answer is Return of the Obra Dinn.

In the third sample input, there are no special inputs. First, we take "7217F8 Return of the King", which has value #7217F8. In binary, this is:

011100100001011111111000

We take the reflection from the mirror, getting:

000111111110100001001110

We compare it against 2FE84E (001011111110100001001110) and 4FFAFC (010011111111101011111100), which have Hamming distances of 2 and 8 from the reflection, respectively. All 3 instances of hexadecimal color value #2FE84E have minimum Hamming distance from the reflection, so we take the (3-1)/2=1th instance (0-indexed) of #2FE84E. Therefore, the "fairest" answer is Return to the house immediately, young lady!.

In the last sample input, there are no special inputs. First, we take "F4A52F A Modest Proposal", which has value #F4A52F. In binary, this is:

1111010011001100101111

We take the reflection from the mirror, getting:

1111010011001100101111

We compare it against F4A52F (1111010011001100101111), which has Hamming distance 0 from the reflection. All instances of hexadecimal color value #F4A52F have minimum Hamming distance from the reflection. There are FOUR instances of #F4A52F, because we always exclude the last hexadecimal color instance from evaluation. Therefore, we take the (4-1)/2=1th instance (0-indexed) of #F4A52F, and the "fairest" answer is Eating apples. If you don't exclude the last value from consideration, you actually get the (5-1)/2=2th instance of #F4A52F (Eating porridge), which is wrong.

Rules:

  • No standard loopholes
  • Input/output taken via standard input/output methods.
  • The output must be exactly equal to the "fairest" answer

Scoring:

This is code golf, so shortest program wins.

Posted~ you can see it here

\$\endgroup\$
  • \$\begingroup\$ Going to need tag suggestions :) \$\endgroup\$ – Avi Sep 30 at 20:57
  • \$\begingroup\$ Can each entry be taken as a tuple, i.e. ("#FFFFFF","Return the Slab")? Can the label part also have a hex number in it or are we guaranteed it wont? Rules has the # but the examples do not, is either form fine? Can we get a worked example of a list containing multiple matching entries? \$\endgroup\$ – Veskah Oct 1 at 12:33
  • \$\begingroup\$ @Veskah You can take tuples as input. You can choose whether to keep # in your input hex colors or not, as long as you keep it the same for every single input (no sneaky stuff like putting a # before the correct answer every time). I've added more sample inputs/outputs with explanation. \$\endgroup\$ – Avi Oct 1 at 14:28
  • \$\begingroup\$ -1: This has way too many hardcoded input/output mappings. This challenge is more about encoding those than solving a problem. \$\endgroup\$ – Beefster Oct 24 at 19:10
-1
\$\begingroup\$

CMC: Cross-Multiplication Calculator

In this task you should create a Cross-Multiplication Calculator.


Cross-multiplication is a way of factoring an algebraic expression. This is the expression form that this way can solve:

$$x^2 + ax + b$$

\$a\$ and \$b\$ are constants here, and \$x\$ is a variable.

Anyway, as far as I can tell, this expression form is only solvable in this method.

Anyway, how do I do Cross-Multiplication? (TODO)

You first take the number \$b\$ and factor this number into integral factors.

Okay. We are using the expression \$x^2 + 8x + 16\$ as an example.

(Although 16 is not a prime) let us assume that 16 only has 2 possible factors:

  • \$-1 \times -16\$ (because \$-x \times -x = x^2\$)
  • \$1 \times 16\$ (Obviously this is 16)
  • And the above 2 with the factors reversed.

Now you sum these possible two factors and check this against the number \$a\$.

  • Check 1. So \$-1 + (-16) = -17\$. And unfortunately -17 is not 8, we proceed to the next check.
  • Check 2. So \$1 + 16 = 17\$. And unfortunately 17 is not 8, we proceed to the next check. There are no checks left.

Did I make a mistake? Of course, I need to change the factors.

  • \$-2 \times -8\$ (because \$-x \times -x = x^2\$)
  • \$2 \times 8\$ (Obviously this is 16)
  • And the above 2 with the factors reversed.

We sum those values, and they are -10 and 10 respectively. So I should change the factors to another value:

  • \$-4 \times -4\$ (because \$-x \times -x = x\$)
  • \$4 \times 4\$ (Obviously this is 16)
  • And the above 2 with the factors reversed.

Finally! \$4+4 = 8\$, and here is the factorization:

$$(x+4)(x+4)$$

Now you will probably realize why I desperately need a program to automate this.

Test cases

You can assume that the input is always valid. You do not have to specify the variables, only the numbers. Therefore the expression

$$x^2 + ax + b$$

is converted into:

$$+a \, +b$$

The expected output is not:

$$(x+\alpha)(x+\beta)$$

but:

$$+\alpha \, +\beta$$

a, b => α, β
8, 16 => 4, 4
-5, -24 => 3, -8

Scoring

This is , so shortest answer in bytes wins.

Meta

  • Is this clear enough?
  • I haven't found a duplicate, but anything? (Although unlikely, I found nothing by searching "Cross Multiplication".)
  • Tags are code-golf, string and interpreter. Anything else?
  • Any further feedback?
\$\endgroup\$
  • 1
    \$\begingroup\$ I've edited your post to use MathJax for the mathematical formula/workings. In addition, I've edited out the rather strict input/output format (leading + etc.) as it's generally recommended to allow the most natural output format. Feel free to revert these changes if you dislike them. Also, your tags bullet point in the Meta section appears to be different to the tags in the title? \$\endgroup\$ – caird coinheringaahing Oct 21 at 17:48
  • \$\begingroup\$ Finally, I'd vote to close this as a duplicate of this or this challenge (as it is a subset of both) \$\endgroup\$ – caird coinheringaahing Oct 21 at 17:51
-1
\$\begingroup\$

Parse a regex

Grep is a wonderful tool. It can find stuff in files, it can help you spell stuff correctly (grep 'whatever' /usr/share/dict/words or wherever that file is), and it can even test if something is a prime number!

However, the first version was implemented back in the golden age, when FORTRAN was respected, Pascal was the language for beginners, and object orientation was just starting out in on its great adventure.

One could argue that modern developers have nowhere near that much talent or skill, what with their flashy "IDEs" and "frameworks". If they would be asked to implement something similar, they would just jump at the nearest library or cloud thingimabob and say "Done!".

At least, that is what some would say.

Prove them wrong! Golf grep!

Parse a regular expression without calling any built-in functions or operators explicitly meant for this.

input:

Basically the same as a simple grep: a regular expression as a command line parameter, followed by an optional filename or a dash. If the filename is not present, or it is a dash, read for stdin.

This is the recommended way to do it, but if you can write an adapter (eg: post stuff to a php form for your program via a shell script), then that is OK as well. The adapter does not contribute to your score.

output

Lines that match the regular expression.

Notes:

The regex dialect is PCRE (perl compatible). Files use unix line terminators if it is relevant.

\$\endgroup\$
  • \$\begingroup\$ Closely related, but not quite a duplicate. \$\endgroup\$ – AdmBorkBork Nov 18 at 20:42
  • \$\begingroup\$ Why the downvote? \$\endgroup\$ – Mark Gardner Nov 20 at 8:16
  • \$\begingroup\$ You've likely been downvoted because you "ban built-in functions or operations explicitly meant for this." Consider this post for a lengthy discussion of why this has fallen out of favour. Beyond this being trivial besides parsing regular expressions, it also doesn't actually describe what a regex is or what it means to be PCRE. Challenges need to be self contained! I think your bet is to make a different matching language yourself and ask us to implement grep but with that language instead of regex. \$\endgroup\$ – FryAmTheEggman Nov 20 at 19:09
-1
\$\begingroup\$

Predict the state of a Minecraft inventory after click events

Minecraft does inventory management over the network by sending packets describing the clicks that a player does. If you're caching these events, it can be non-trivial to predict what state the inventory is in after the clicks

Challenge

Take an inventory of 9 slots, each with an item and a type. Assume all items can stack up to 64 and that if a slot would be "overfilled" that the cursor will continue holding onto the items. Then, take a list of the slot index, button, and mode variables for the clicks to be done (mode and button are defined at https://wiki.vg/Protocol#Click_Window). Output the inventory afterwards.

Restrictions/Rules

You may input and output the inventory in any reasonable format. You may take click input in any reasonable format. You may ignore Mode==2, as the player inventory is not implemented correctly enough for this. You may ignore Mode==3 because this is a survival player You may ignore Mode==5 where Button==8, 9, or 10 for the same reason as Mode 3. Dropping the item is a delete. Your player won't pick it back up or anything silly like that. You may assume that input will have valid counts Don't use standard loopholes

Examples

Input:

[["diamond",64],[],[],[],[],[],[],[],[]]

[
 [0, 0, 0]
 [0, 0, 1]
]

Output

[[],["diamond",64],[],[],[],[],[],[],[]]

Input:

[["diamond",64],["dirt", 64],[],[],[],[],[],[],[]]

[
 [0, 0, 0]
 [0, 0, 1]
 [0, 0, 2]
]

Output

[[],["diamond",64],["dirt",64],[],[],[],[],[],[]]

Input:

[["diamond",64],[],[],[],[],[],[],[],[]]

[
 [0, 0, 0],
 [-999, 4, 4],
 [0, 4, 5],
 [1, 4, 5],
 [2, 4, 5],
 [3, 4, 5],
 [4, 4, 5],
 [5, 4, 5],
 [6, 4, 5],
 [7, 4, 5],
 [8, 4, 5],
 [-999, 4, 6],
 [8, 0, 0]
]

Output

[["diamond",56],["diamond",1],["diamond",1],["diamond",1],["diamond",1],["diamond",1],["diamond",1],["diamond",1],["diamond",1]]

Meta

I have no clue what I'm doing writing a question.

Tagged code golf

Critique goals:

  • Improve testcases
  • Improve description of problem
  • Determine if the problem is too complex
\$\endgroup\$
  • 1
    \$\begingroup\$ Challenges are meant to be self-contained. While information where the idea/process comes from can be nice, everything needed to solve the challenge should be in the description. This means you should write down what click does what, for all the people who don't remember what Minecraft clicks do by heart. \$\endgroup\$ – AlienAtSystem Nov 22 at 6:43
-1
\$\begingroup\$

A very-very old (maybe early 2000s) problem:

Print out a decimal number \$n\$ such as \$n^2\$ ends with \$n\$ with maximal length your program can compute in 60 seconds

In other words it's needed to find some long enough \$n\$ such as \$10^{\lfloor\log_{10}n\rfloor+1}|(n^2-n)\$.
A hint may be that an \$n\$ ending with \$5\$ is more easy to compute than an \$n\$ ending with \$6\$.

code-challenge

\$\endgroup\$
  • \$\begingroup\$ How can this be king-of-the-hill? Do you mean code-challenge? And what stops us from hardcoding some extremely large number? \$\endgroup\$ – Jo King Nov 21 at 23:36
  • \$\begingroup\$ king-of-the-hill needs interaction between submissions. I don't see any here \$\endgroup\$ – Jo King Nov 22 at 1:43
  • \$\begingroup\$ @JoKing the problem becomes very simple with modular arithmetic: got 205k digits for free with ~len(n) time for each step imgur.com/ExPdwMb , so there's no need for hardcoding and it's not much interesting. ) \$\endgroup\$ – Alexey Burdin Nov 22 at 14:11
-1
\$\begingroup\$

JavaScript: Free for All

This is a very experimental idea of mine: given a function which is provided a single function as an argument, try to run that function the most times possible in a browser environment while competing against other bots.

Bot submissions

Each bot consists of a function. This function takes a scoring function as input. Each bot has a state consisting of three values:

  • score: Number indicating score, winning criterion
  • locked: Boolean which, when true, prevents further score increases
  • calls: Number of times scoring function called in last 100ms (?), will set locked to true for the remainder of the round if it exceeds a certain value

The scoring function increments score and calls, as long as locked is not true.

Restrictions

If any of these restrictions are violated, a bot will have locked set to true.

No bot or bot-defined function may:

  • Run longer than 5ms
  • Attempt to modify the window location (location.href, location.assign, etc.)
  • Attempt to connect to the internet (AJAX, WebSockets, etc.)
  • Create web workers
  • Affect hardware (sound, microphone, camera, USB, gamepads, etc.)
  • Download files
  • Leave an impact which cannot be fixed by reloading the page

Notes

This is almost certainly a very bad idea on an assortment of levels. If you have any suggestions of restrictions or ways to make the challenge more interesting, be sure to comment.

I'm considering some sort of system to determine which bot runs first that adds to the strategy, and interesting attack angles for other bots.

To prevent this from becoming a "read the last answer and exactly cancel out its strategy" type thing, I'm open to any suggestions.

\$\endgroup\$
-1
\$\begingroup\$

Digits of the sum of the reciprocal exponential factorials

The exponential factorial, \$n^!\$, is the extension of the factorial using exponentiation instead multiplication:

$$n^! = \begin{cases} 1, & \text{if }n = 0 \\ n^{(n-1)^!}, & \text{if }n \ge 1 \end{cases}$$

The first few exponential factorials are \$1, 1, 2, 9, 262144, \dots\$

The infinite sum of the reciprocals of the exponential factorials tends towards a constant:

$$\begin{align} \sum_{n=1}^\infty\frac{1}{n^!} & = 1+\frac{1}{2^!}+\frac{1}{3^!}+\frac{1}{4^!} + \cdots \\ & = 1+\frac{1}{2}+\frac{1}{9}+\frac{1}{262144} + \cdots \\ & = 1.611114925808376736\underbrace{111\dots111}_{183213\text{ times}}27224\dots \end{align}$$

The digits after the decimal point are OEIS A080219

You are to take a positive integer \$n\$ as input and output the \$n\$th digit after the decimal point of the above constant. Your program must work for an arbitrarily large \$n\$, but can fail due to language constraints for reasonably large \$n\$. You may choose 0 or 1 indexing. This is so the shortest code in bytes wins


Meta

  • Is this clear?
  • Is this a duplicate?
  • Tags are , and . Any suggestions?
  • Any further feedback?
\$\endgroup\$
  • 3
    \$\begingroup\$ The $ symbol makes it look like you made a latex-typo :P Maybe you can mention that this is oeis.org/A080219 \$\endgroup\$ – flawr Dec 5 at 20:10
  • \$\begingroup\$ @flawr Given that it's the symbol used in the Wikipedia article, I think it's best to keep using it. And yes, I will include that OEIS sequence, thanks! \$\endgroup\$ – caird coinheringaahing Dec 5 at 20:11
-2
\$\begingroup\$

Every number is interesting

We know that every number is interesting but how?

You should write a program or function which:

  • takes a list of N positive integers (>0 and <2^31)
  • outputs N lines each of them showing how the corresponding input number is interesting
  • is not longer than 1024 bytes
  • uses no more than 1 second per number
  • doesn't use external sources

Examples

172: 444 in base6
5776: 76*76
9801: 9 * 1089 (reverse)
68101: no 11 in base2 (10000101000000101)
491033: 317 * 1549 (product of 2 big primes)
467808816: no digit 5 from base6 to base10

Inputs

You should include the output for the following input in your post:

58 92 120 224 358 490 912 1578 7812 222008 1645060 19796411 550453633 

If you care to run your program on a bigger sample and share the result with us use this input data (2500 numbers). (You can upload your output to e.g. pastebin.)

This is a popularity-contest so highest voted answer wins.

Tags: popularity-contest, number

\$\endgroup\$
  • 1
    \$\begingroup\$ What sort of criteria are necessary for defining a number as 'interesting'? I see things like square numbers, other bases, etc. But are there any specifics? I'm interested in this challenge (but worried it might be closed as too broad). \$\endgroup\$ – ASCIIThenANSI Apr 7 '15 at 13:18
  • \$\begingroup\$ @ASCIIThenANSI There wasn't a clear definition. That's part of the reason why I abandoned the challenge. \$\endgroup\$ – randomra Apr 8 '15 at 1:55
  • 1
    \$\begingroup\$ Would you mind if I tried taking it up? I would have to post as a new answer, because I can't directly edit. \$\endgroup\$ – ASCIIThenANSI Apr 8 '15 at 2:00
  • \$\begingroup\$ @ASCIIThenANSI Not at all. \$\endgroup\$ – randomra Apr 8 '15 at 2:01
  • \$\begingroup\$ @ASCIIThenANSI Where did you post it? \$\endgroup\$ – wizzwizz4 Jul 24 at 13:33
  • \$\begingroup\$ @ASCIIThenANSI I am also curious \$\endgroup\$ – MilkyWay90 Aug 27 at 23:41
-2
\$\begingroup\$

Something Else - ASCII Art maker:

A text to ASCII art generator maker, the program must input a string and return ASCII art from it. Something like patorjk.com/software/taag/. It has to use the Graffiti font. The winning criteria is the whoever gets the most likes.

\$\endgroup\$
  • \$\begingroup\$ Hello! Just a few things to point out: 1) The current spec is very broad. For example, what fonts, how does spacing look, what characters need to be supported... there's a lot more details that need to be included than just "return ASCII art of this text" \$\endgroup\$ – Sp3000 Feb 24 '15 at 4:07
  • 1
    \$\begingroup\$ 2) What's the winning criterion? Popularity contest? Code golf? \$\endgroup\$ – Sp3000 Feb 24 '15 at 4:08
-2
\$\begingroup\$

Identifying a Sonnet

This challenge is about determining if a given file (read-in from stdin) meets the criteria to be a sonnet. You may use any language for this challenge. If your language supports an API to use an online dictionary you may use that API, if your language doesn't then too bad.

Additionally, it is preferred if your language is one that can be ran directly from the command line and is a language that has a compiler or interpreter available directly from my distro's repos(Fedora), as I would rather just use a bash script to test the various programs, then test each program manually.

Definition of a Sonnet

  • Has 14 Lines (lines are denoted as the standard newline on your operating system).
  • Has a definite rhyme scheme, it will have one of the following rhyme schemes
    • ABBA ABBA CD CD CD
    • ABBA ABBA CDE CDE
    • ABAB ABBA EFEF GG
  • Iambic Pentameter - consists of alternating stressed, unstressed syllables. This doesn't have to be perfect 100% of the time, just at least 50% of the time.

In order for your program to declare a given string a sonnet, it must meet all of the above criteria.

Additional Notes

You do not have to identify the following:

  • Thought Structure - too intense for a code golf challenge, and too subjective.
  • Topic - computer lacks context to determine this

Input

Input will be read from stdin. This is the string that you will be declaring to be or not to be a sonnet.

Output

Your program will output either yes or no for the question:

Does this string meet the given requirements to be a sonnet?

As this is code golf yes or no can be abbreviated to Y/N.

Winner

The solution with fewest number of bytes win that has the highest accuracy ratio for the correct identification of a sonnet. The preference is for higher accuracy rather than brevity of the program.

Test Data and Resources

What is not a sonnet

The following are examples that you program should return false on:

  • Beowulf
  • Haiku
  • Input that doesn't have exactly 14 Lines in it
  • The text of this question.
  • The text of just about any other question on StackExchange.
  • Things that don't have a rhyme scheme. See Below

Not A Sonnet

A man got on a boat
The boat was leaky
and had poor construction
For it was made by a one-eyed blind man
and his dumb intern
As soon as he got out of port
at the fort
it started to sink
eventually, it tanked.
And it capsized
If only that shipwright
wasn't so blind deaf and dumb
as microsoft tech support
That's not much support at all.
\$\endgroup\$
  • 2
    \$\begingroup\$ I think without dictionaries for rhymes and stresses this is probably not a good idea. Of course you can use some sort of accuracy ratio, but then you also need false positives, and you need a lot more examples than the few on the pages you've linked. But if you do this there's no requirement to actually recognise the sonnets by their rhymes and stresses - instead, I'm pretty sure, people will just regex golf the test sets. \$\endgroup\$ – Martin Ender Mar 24 '15 at 19:36
  • \$\begingroup\$ @MartinBüttner I updated the requirements with an accuracy percentage, and added the option to use an API to look up terms from a dictionary. \$\endgroup\$ – HSchmale Mar 24 '15 at 19:57
  • 1
    \$\begingroup\$ 1. Test data which only covers one possible output isn't test data. I can write a program which always outputs Y in as little as one byte and it will pass all of the linked "test data", but it comes nowhere near to meeting spec. 2. Unless you specify which rhyme/stress dictionary to use, you can't guarantee that the test data is "correct". \$\endgroup\$ – Peter Taylor Mar 24 '15 at 20:20
  • \$\begingroup\$ @PeterTaylor I added examples of what is not a Sonnet. \$\endgroup\$ – HSchmale Mar 24 '15 at 20:32
  • 1
    \$\begingroup\$ I'm not sure how to say this, but it feels as though this task has a lot of individual parts, each of which could be quite tricky. Especiallly detecting rhymes/syllables/stresses, since words can be pronounced/stressed differently based on context. Also if you're using Shakespeare's sonnets I have no idea where to get rhyming and stress dictionaries for Elizabethan English... \$\endgroup\$ – Sp3000 Mar 25 '15 at 14:18
  • \$\begingroup\$ To make this interesting, you'll need some interesting near-misses: non-sonnets that can't be detected by something simple like counting lines or words per line. \$\endgroup\$ – xnor Mar 25 '15 at 20:59
  • \$\begingroup\$ @xnor You mean a file with a that looks like a sonnet but has no rhyme. \$\endgroup\$ – HSchmale Mar 25 '15 at 21:04
  • \$\begingroup\$ Yes, for example. Or, one with rhyme by wrong rhythm. Or, one with nonsense characters that seem to "rhyme". \$\endgroup\$ – xnor Mar 25 '15 at 21:06
  • \$\begingroup\$ @Sp3000 You can just use modern english, or just base it on words that have similar endings. \$\endgroup\$ – HSchmale Mar 25 '15 at 21:11
-2
\$\begingroup\$

Create a Drawing Guide for a Polygram

Poor old Jim, he's just terrible at drawing polygrams, and he's asked you to create a "drawing guide" for him - an ascii polygram with numbered edges, so he can follow the instructions.

Challenge

Write a program to produce an ascii polygram with P <= 10; each edge of the polygram should be made of a single digit 0-9, showing the order in which the edges should be drawn.

Input

Your program should receive (via STDIN, as function arguments, or some other language-appropriate method): P, the number of edges/vertices of the polygram, and Q, the spacing. In the notation as per the Wikipedia link, you'll be drawing a {p/q} polygram.

Output

Either print to STDOUT or return (or something else language-appropriate) a multiline string showing the drawing guide for the given polygram. The string can be any size you like, as long as it's large enough to display a clear polygram.

Notes

Your code should be able to handle compound regular polygons as well as regular regular polygons, and also inputs of q > p/2 (poor old Jim doesn't realize that the polygram for {p/q} is the same as for {p/p-q}).

Example Output for {10,3}

              5              
             5 4             
                4            
     21     5        888     
     2 11115     8888  7     
     2    5111888 4    7     
     2     888111  4   7     
     2  888      111   7     
     8885           4117     
  8882               4 711   
 8   2 5               7  111
     25               47     
 9   5                 7    0
  9  2                 74  0 
    52                 7  0  
   9 2                 7 4   
  5 92                 7 04  
     9                 70  4 
 5   2                 7     
5    29                7    4
6666 2 9              07   33
    666              0 7333  
     2 696           337     
     2   9666     333  7     
     2    9  66633 0   7     
     2      333 666    7     
     2   339       666 7     
     2333   9    0    67     
             9  0            
               0 

Scoring

This is code-golf, so shortest in bytes wins. Tiebreaker goes to the most votes.

\$\endgroup\$
  • \$\begingroup\$ I have a python solution to this which is ~600 bytes, so it's definitely doable, and it's not easy... \$\endgroup\$ – sirpercival Apr 27 '15 at 4:31
  • 5
    \$\begingroup\$ I think the spec needs to be more prescriptive for this to make a good question, especially since the example seems to indicate that you're not currently even prohibiting the lines from having gaps. At a minimum I would say that you should require the lines to be equivalent to those produced by Bresenham's algorithm, and specify how overlaps should be handled; at the extreme, you could tie it down so tightly that it becomes a parameterised kolmogorov-complexity. \$\endgroup\$ – Peter Taylor Apr 27 '15 at 9:34
-2
\$\begingroup\$

Pointer to pointers to pointers to pointers

You should choose a language supporting pointers like C. And your task is simple: demonstrate a legitimate use of the most level of pointers.

You should justify your code by describing an algorithm that:

  • Has only plain text, number or an array of those as input and output.
  • You think it will make things easier to write those code as a part of the implementation of this algorithm.
  • This implementation would have optimum memory usage (only declared variables and parameters, explicitly allocated space, and the return addresses for recursive functions count).

Other rules:

  • They must be pointers to pointers directly, i.e. a pointer to an object containing a pointer doesn't count. It's better if nobody using this code will want to extend some pointer to an object later.
  • Each pointer must have a different type (if your language can somehow make them the same type).
  • You should create at least one pointer, and either dereference or compare two non-null pointers once in each level.
  • Using pointers as arrays is only half as interesting.
  • Iterators, etc, are considered in essence pointers and allowed in this challenge. But you can't define new types implementing iterators for this purpose.

\$\endgroup\$
  • 3
    \$\begingroup\$ Could you specify "legitimate"? This sounds a bit like code bowling (and seems to have the same issues). With enough imagination I'm sure I can justify any depth of pointers. \$\endgroup\$ – Martin Ender Apr 30 '15 at 17:43
  • \$\begingroup\$ @MartinBüttner Edited but, basically, it is subjective. \$\endgroup\$ – jimmy23013 Apr 30 '15 at 17:57
  • \$\begingroup\$ @MartinBüttner Added a restriction to have optimum memory usage. I'm not sure whether it works. \$\endgroup\$ – jimmy23013 Apr 30 '15 at 18:19

You must log in to answer this question.

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