568
\$\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\$
0

4563 Answers 4563

1
83 84
85
86 87
153
1
\$\begingroup\$

Sum of strings (UTF-16 codepoints)

\$\endgroup\$
3
  • \$\begingroup\$ I thought this was a dupe but can't find anything that really matches this. By "the module of sum by the 65536" do you mean "the sum, modulo 65536"? \$\endgroup\$
    – noodle man
    Feb 26 at 22:37
  • \$\begingroup\$ @Jacob Yes, exactly. If you can rephrase this sentence correctly, I will be grateful to you! \$\endgroup\$
    – EzioMercer
    Feb 26 at 22:40
  • 1
    \$\begingroup\$ If the resulting sum is greater than 65535 (maximum UTF-16 codepoint), take the sum \$\mod{65535}\$ \$\endgroup\$
    – noodle man
    Feb 26 at 23:13
1
\$\begingroup\$

Animate the shape!

\$\endgroup\$
1
  • \$\begingroup\$ Nice challenge idea! You might want to add some examples.' \$\endgroup\$
    – emanresu A
    Feb 26 at 0:19
1
\$\begingroup\$

Simulate Just Friends

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

Triangularly embed a graph on a surface

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

Arbitrary numeric base as string

Given a positive integer n and an integer base b where 1<b<96, please convert n into a string that represents its value in base b.

For a given base b, the following should hold:

  • Digits should only have place value between 0 and b.
  • Digits should be output in order from most significant to least significant.
  • Digits with place value 0 to 9 should be represented with the ASCII characters "0" to "9".
  • Digits with place value 10 to 15 can be represented with your choice of ASCII characters "a" to "f" or "A" to "F" (but not a mix).
  • Digits with place value 16 to 94 can be represented with your choice of the remaining ASCII characters, but they must be deterministic for a given base b.

Examples:

250, 5 -> "2000"
250, 16 -> "fa" or "FA"
250, 80 -> "3a" or "3A"

This is , so the shortest program or function that breaks no standard loopholes wins!

\$\endgroup\$
1
  • 1
    \$\begingroup\$ You should clarify in "Digits should only have place value between 0 and b." that 0 is inclusive and b exclusive \$\endgroup\$ Mar 13 at 11:57
1
\$\begingroup\$

Find the linear transformation

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

Vertically Aligned JSON formatting

We have a question on JSON formatting on this site before, however, this one requires a different formatting convention.

Arrays should be formatted with the first element on the same line as the opening [, and the final ] should be on the same line as the ]. All other elements should be on separate lines, aligned with the first. Commas go on the end of each line except the last. like this:

["alpha",
 "beta",
 "gamma",
 "delta"]

Objects are mapped the same, but the values must also be aligned. There must always be at least one space between the : and the value, like this:

{"alpha":   "beta",
 "gamma":   "delta",
 "upsalon": "sigma",
 "iota":    "zeta"}

When structures are nested, they are aligned with their first element, like this:

[{"iota":  "beta",
  "gamma": "sigma"},
 {"zeta": {"meena": "kim",
           "vot":   "dilinia"}}]

Note how separate objects do not need to align with each other, only keys in the same object align.

We will consider only 3 types: arrays, objects, and strings. Handing of numbers and null is optional.

Input is a mimified JSON string, you should output a vertically aligned JSON string with the same data. You do not need to preserve key order. This is . Shortest answer in each language wins.

\$\endgroup\$
3
  • \$\begingroup\$ Related \$\endgroup\$
    – emanresu A
    Mar 28 at 20:01
  • \$\begingroup\$ It's vaguely similar for array formatting but completely different for object formatting \$\endgroup\$
    – mousetail
    Mar 28 at 20:06
  • \$\begingroup\$ That's why I said related. \$\endgroup\$
    – emanresu A
    Mar 28 at 21:31
1
\$\begingroup\$

Hyperjumps Challenge

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

Is it a hyperjump?

Easy-mode of this challenge

A hyperjump is a sequence of numbers 0-9 (exclusive), where:

  • The first two digits can be any two
  • Each number after is the result of a simple math operation (*, /, +, -) on the previous two.
    • E.g. [3, 2] → 3+2=5, 3-2=1, 3*2=6, 3/2=not an integer
    • If the result is multiple digits, take the last one. E.g. [7, 5] → 7+5=1 2, 7*5=3 5
    • The third- and second-most-recent digits may combine to one number and be used. E.g. [4, 1, 3] → 41-3=3 8, …
  • The sequence should end with 9. There is no 9 in the list, but it should be able to be there by the rules outlined above.

For example, the sequence 7, 4, 3, 1, 2 is a hyperjump because 7-4=3, 4-3=1, 3-1=2, 31-2=9.

Your task is: Given a sequence of digits 1 through 8 inclusive, determine whether it is a valid hyperjump. You may output a truthy/falsy value, or choose two distinct values. This is , so the shortest submission in bytes per language wins.


Meta: I don’t have time to add test cases right now, I want to make sure this isn’t too similar to the other challenge before working on it more.

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

Determine NBA conference seedings

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

Draw a Regular Reuleaux Polygon

Related

A Reuleaux polygon is a curve of constant width made up of circular arcs of constant radius. The most well-known Reuleaux polygon is the Reuleaux triangle, which has three sides. In this challenge, you will be tasked to draw a regular Reuleaux polygon of a given number of sides.

A Reuleaux polygon is constructed by taking a polygon and replacing each of its sides with an arc centered at the opposite vertex.

This sort of shape can only be constructed from a polygon with an odd number of sides, so your input will be an odd number greater than or equal to three.

Reuleaux pentagon (5 sides) Reuleaux heptagon (7 sides)
constructed pentagon constructed heptagon
pentagon heptagon

The circles in the first row are shown to demonstrate the construction; Your program's output should be closer to that of the second row (though the border and center mark are optional.)

Given a odd number ≥ 3, draw a regular Reuleaux polygon with that many sides.

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

Single Transferable Vote (Ranked Choice Vote)

Single transferable vote is a algorithm for selecting the best N candidates from a set of ranked choice votes. It works like this:

  • Every voter must rank every candidate, first to last
  • Let the voting threshold be the number of voters divided by the number of available positions
  • While less than N candidates have been elected:
    • If the candidate with the most #1 votes has more votes than the threshold, elect them. Then remove that candidate from every voters ballot.
    • If no candidate has enough votes to be elected, eliminate the candidate with the lowest number of votes choosing them as #1. Remove this candidate from every ballot. In case of a tie tiebreaker is how often they are ranked #2, then #3 etc.

Given a list of votes, the number of open positions, and optionally a list of candidates, output which candidates get elected. Order doesn't matter.

You do not need to implement the algorithm above exactly as long as the result is the same.

Test Cases

Positions: 2
Votes: [1,2,3]
       [2,3,1]
       [3,2,1]
Outcome: 2, 1

More test cases TBD

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

Countdown solver

Input

An array of up to 6 integers, value 1..100, and a target integer 1..999

Output

A series of mathematical operations (in any sensible format), using each of the integers in the input array 0..1 times, and the mathematical operators +-*/ any number of times, to reach the target integer.

Intermediate operations may result in floats (e.g. (3/2) * 4 = 6), and there is no guarantee that the target is reachable at all (in which case the output is undefined). The input integers may not be concatenated (e.g. 1, 2 can't be used as 12)

Win criteria

Code golf, usual exclusions apply.

\$\endgroup\$
3
  • \$\begingroup\$ Is this a dupe of this challenge? \$\endgroup\$
    – Arnauld
    Apr 25 at 23:57
  • \$\begingroup\$ @Arnauld yes, looks like it might be. Oh well. Unless anyone thinks it's suitably different with a variable length input? \$\endgroup\$ Apr 27 at 14:41
  • \$\begingroup\$ It would be great if you can somehow make this one different enough, as the other challenge is quite old and didn't receive much attention. \$\endgroup\$
    – Arnauld
    Apr 27 at 16:48
1
\$\begingroup\$

Find Index of Rational Number in Calkin-Wilf Sequence

\$\endgroup\$
1
  • \$\begingroup\$ I think this is definitely different enough from the Stern-Brocot Tree \$\endgroup\$ Jan 24 at 21:21
1
\$\begingroup\$

Get all URLs on an HTML webpage

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

Langton's Ant

Langton's ant is a simple two-dimensional universal Turing machine. From Wikipedia:

Squares on a plane are colored variously either black or white. We arbitrarily identify one square as the "ant". The ant can travel in any of the four cardinal directions at each step it takes. The "ant" moves according to the rules below:

At a white square, turn 90° clockwise, flip the color of the square, move forward one unit

At a black square, turn 90° counter-clockwise, flip the color of the square, move forward one unit

In this challenge, you will be given three inputs:

  • A 2D square grid \$G\$ of two distinct symbols, where one represents a black cell and the other represents a white cell
  • A coordinate \$(x,y)\$ representing the location on the grid where the ant starts
  • A number of steps \$n\$

Your code should then return the grid after the ant starting at \$(x,y)\$ and facing upwards, completes \$n\$ steps.

You can use any reasonable form of indexing to describe the intial location of the ant on the grid (e.g. 0-based or 1-based).

You can assume that the ant will not attempt to go off the side of the grid at any point during the given steps.

Test cases

For these tests, I will assume that \$(0,0)\$ is the top-left corner of the board. I will also use 0 to represent a white cell and 1 to represent a black cell.

\$G\$ \$x\$ \$y\$ \$n\$ Result
[[0]] 0 0 0 [[0]]
[[1]] 0 0 0 [[1]]
[[0,0],[0,0]] 0 1 1 [[0,0],[1,0]]
[[0,0],[0,0]] 0 1 2 [[1,0],[1,0]]
[[0,0],[0,0]] 0 1 3 [[1,1],[1,0]]
[[0,0,0],[0,0,0],[0,0,0]] 1 1 7 [[0,1,1],[0,0,1],[1,1,0]]

Standard loopholes are forbidden. Since this is , shortest code wins.

\$\endgroup\$
3
  • \$\begingroup\$ Related \$\endgroup\$
    – mousetail
    Apr 24 at 15:48
  • \$\begingroup\$ Title appears to be a typo, should be Langton's ant, rather than Langston's ant? \$\endgroup\$
    – ATaco
    May 1 at 5:30
  • \$\begingroup\$ @ATaco Fixed it. \$\endgroup\$ May 1 at 14:11
1
\$\begingroup\$

Sanitize the Spaces

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

A Graphical Degree Sequence?

Write the shortest program to determine if a degree sequence is graphical.

Given a sequence of numbers S, output a Boolean value representing whether or not a graph with S as its degree sequence exists.

The degree sequence of a graph is a sequence representing the degrees of each of its vertices. The degree of a vertex is the number of edges connected to it. Generally the degree sequence is given in non-increasing order, but for this challenge, it may be specified in any order. This means that graphs may have multiple degree sequences.

Example

The following graph has a degree sequence of [4, 3, 2, 1, 1, 1] or any of its reorderings.

A Graph

Some degree sequences like [3, 3, 3, 2] are impossible. If you try to draw such a graph, it becomes clear why.

Test cases

[4, 3, 2, 1, 1, 1] -> True
[3, 3, 3, 2] -> False
[] -> True
[5, 5, 5, 5, 5, 5] -> True
[4, 4, 2, 4] -> False
[1, 2, 3, 2, 1, 4, 2] -> False
[3, 4, 4, 3, 3, 3, 4] -> True
[3, 0, 2, 1, 4, 2] -> True
[0, 0, 0] -> True
[2, 1, 2, 2, 2, 0, 2, 6] -> False
[2, 4, 2, 2, 2] -> True
[4, 4, 3, 2, 4] -> False
\$\endgroup\$
1
  • \$\begingroup\$ Related, but not quite the same. \$\endgroup\$
    – Bbrk24
    May 7 at 21:46
1
\$\begingroup\$

Evaluate Minkowski's question mark function at rational numbers

\$\endgroup\$
2
  • \$\begingroup\$ Could you please add some worked-out examples? \$\endgroup\$
    – pajonk
    May 9 at 8:21
  • 1
    \$\begingroup\$ @pajonk One example is there now. \$\endgroup\$ May 9 at 9:56
1
\$\begingroup\$

Draw any infinite fractal

Write a function that, given as input 2 positive integers for X and Y, outputs one of two distinct values, representing white and black. Your function should have the following properties:

  • No horizontal or vertical ray should infinitely repeat itself. A ray is a straight line that starts at one point then continues upto infinity. Mathematically \$ \not \exists x, y, \delta : \forall e \geq y+\delta: f(x,e)=f(x,e-\delta)\$ and the same with \$x\$ and \$y\$ reversed.
  • Large scale structure: For every positive integer Z there exists a ZxZ square that is entirely white and also a ZxZ square that is entirely black. This rule ensures no matter how much you zoom out you should still be able to see some shapes and not just grey.

For the purpose of this challenge you may ignore the numerical limits of your language. When proving that your function meets the requirements, assume they don't exist.

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

Cube calendar numbers

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

Generate a naïve isEven()

We've all seen the memes of a beginner programmer writing an isEven() function that looks something like this:

def isEven(num):
    if (num == 0):
        return True
    elif (num == 1):
        return False
    # and so on

You and I know this is tedious to do by hand, so let's write a program to make this function for us.

Task

Write a program that accepts a positive integer n and outputs a valid naïve isEven() function that can check all integers from 0 up to and including n. The resulting function can be in any language, so long as it:

  1. Is named isEven, and
  2. Accepts a single parameter, num (integer), and
  3. Explicitly checks whether num is equal to each integer from 0 to n, inclusive (i.e. no else for the last case), and
  4. Uses 1 if statement and n - 1 else if statements (or the equivalent for your resulting language, but not ternary operators) across n lines, and
  5. Returns a truthy or falsey value for the language of the resulting function on a new line after each check. This must be an explicit value, not a calculation (e.g. True not num%2).

You can assume n and num are both valid positive integers (i.e. no error checking necessary).

Your resulting function will be at least 2(n+1) + 1 lines, since each value up to n requires 2 lines; one for the check, and one for the return. The +1 in parenthesis comes from the need to check 0, and the + 1 outside the parenthesis comes from the function declaration.

Scoring

This is , so fewest bytes win. Also, standard rules apply, and standard exclusions are forbidden.

Please put the resulting language in your title (e.g. Jelly --> C++, n bytes).

Test cases

Resulting language: Python

# n = 1
def isEven(num):
    if num == 0:
        return True
    elif num == 1:
        return False
# n = 10
def isEven(num):
    if num == 0:
        return True
    elif num == 1:
        return False
    elif num == 2:
        return True
    elif num == 3:
        return False
    elif num == 4:
        return True
    elif num == 5:
        return False
    elif num == 6:
        return True
    elif num == 7:
        return False
    elif num == 8:
        return True
    elif num == 9:
        return False
    elif num == 10:
        return True

Edit: remove parenthesis from test case

Edit: remove parenthesis from function name

Edit: add condition about explicit true/false return

Edit: fix typo in second condition

\$\endgroup\$
8
  • \$\begingroup\$ What if the target language doesn't use trailing () in functions? \$\endgroup\$
    – Adám
    May 24 at 6:17
  • \$\begingroup\$ Instead of return True and return True would it be permitted to write return num%2? \$\endgroup\$
    – Adám
    May 24 at 6:21
  • \$\begingroup\$ The trailing () don't really matter since the byte count of the resulting function doesn't count toward the score. Python technically doesn't require parenthesis around the conditional. Edit: I think you meant around the function declaration? So long as the function symbol is isEven, it doesn't matter. \$\endgroup\$
    – QueueBot
    May 24 at 6:37
  • \$\begingroup\$ No, it must be a truthy or falsey value, not a truthy or falsey calculation. \$\endgroup\$
    – QueueBot
    May 24 at 6:37
  • \$\begingroup\$ It's not hard to learn the x%2<1 trick... \$\endgroup\$ May 24 at 13:28
  • \$\begingroup\$ So, the output is in our choice of language, and not necessarily the language our solution is in? \$\endgroup\$
    – Shaggy
    May 31 at 11:56
  • 1
    \$\begingroup\$ @Shaggy that's correct \$\endgroup\$
    – QueueBot
    Jun 3 at 5:05
  • \$\begingroup\$ Would it be allowed to use a certain programming language as the output language, if that language's closest equivalent to an if/else statement is a ternary operator? (For example, many functional programming languages - for example in Scheme, (if (= n 0) #t (if (= n 1) #f ...)) ) \$\endgroup\$ Jun 9 at 21:59
1
\$\begingroup\$

Output subsequent powers of two

Output endless powers of 2

\$\endgroup\$
12
  • \$\begingroup\$ You should clarify if the program must circumvent floating-point data type limitations. Those limitations prevent large powers of 2 to be output accurately. That is, must the program handle arbitrarily large powers exactly? From our default rules (see here and here) it could be interpreted that that's not necesssary. In any case, for this challenge I think it's better to be explicit about that \$\endgroup\$
    – Luis Mendo
    May 25 at 23:25
  • \$\begingroup\$ Perhaps another goal would be better, EG. A decision problem per this discussion. \$\endgroup\$
    – ATaco
    May 25 at 23:28
  • \$\begingroup\$ @ATaco It isn't a decision problem, as it is asking for subsequent powers of two, rather than testing if it is a power of two. (If I'm understanding your question correctly) \$\endgroup\$
    – Dadsdy
    May 26 at 0:32
  • \$\begingroup\$ I was suggesting this should be a decision problem challenge instead of an infinite sequence, as it better handles what I perceive to be the bulk of the challenge. \$\endgroup\$
    – ATaco
    May 26 at 0:47
  • \$\begingroup\$ @ATaco It intentionally is open either to doing it by incrementing numbers and outputting if it's a power of two (your way, it seems), or doubling (as in my example). Doubling wouldn't work if it were a decision problem. \$\endgroup\$
    – Dadsdy
    May 26 at 1:01
  • \$\begingroup\$ I could just start at 0, which is 2 to the minus infinity, and always print 0. \$\endgroup\$ May 26 at 9:23
  • \$\begingroup\$ @Hippopotomonstrosesquipedalian 0 doesn't count as a power of 2. \$\endgroup\$
    – Dadsdy
    May 26 at 17:25
  • \$\begingroup\$ @Dadsdy enter print(2**float('-inf')) into Python IDLE \$\endgroup\$ May 26 at 17:29
  • \$\begingroup\$ infinity is also a power of 2. It is 2 to the power of infinity. \$\endgroup\$ May 26 at 17:32
  • \$\begingroup\$ @Hippopotomonstrosesquipedalian Fair points. Now zero and infinity as starting points are no longer valid. Also removed ability to multiply by 4 each time. \$\endgroup\$
    – Dadsdy
    May 26 at 17:36
  • \$\begingroup\$ zero is finite. i would change the wording to "any finite non-zero power of 2". \$\endgroup\$ May 26 at 17:38
  • \$\begingroup\$ @Hippopotomonstrosesquipedalian It couldn't be zero, as it has to output subsequent powers of two, (which would be always 0), and it has to output each sufficently large power of two after finite time. \$\endgroup\$
    – Dadsdy
    May 26 at 17:44
1
\$\begingroup\$

Generate the SMKG aperiodic tiling

Task

Smith, Myers, Kaplan and Goodman-Strauss discovered the first "einstein" - a single connected tile that can tile the plane only aperiodically. They call their tile the "hat". Write a program to generate a finite patch of a tiling of the plane by hats. enter image description here

Details

The program must output a sequence of tiles that make up the patch. Each tile must be given in the form of its 13 (or 14 - see below) vertices, listed in order around the tile either clockwise or anticlockwise. Each vertex must be given in the form of its triangular coordinates, as explained below, and these coordinates must be integers.

Triangular coordinates are with respect to a pair of axes at 60 degrees to each other. A point with triangular coordinates (u,v) corresponds to a point with ordinary cartesian coordinates (u+v/2, v*sqrt(3)/2). An example of a single hat tile has vertices with triangular coordinates

[(4,2),(2,1),(2,2),(1,2),(2,4),(4,5),(4,6),(5,7),(6,6),(5,4),(6,4),(6,2),(5,1)]

Note that it is possible and allowed for the hat to have a different size and still have integer coordinates, although it must not be a different shape. The hat has a unique longest side (of length 2 at this scale), which may optionally be bisected by an additional vertex to give 14 vertices.

All output tiles must belong to a valid tiling of the full plane by hats (all related to each other by congruences or reflections). The output must include every tile that intersects a certain square, where this square is large enough that there are at least 1000 such tiles. (At the above scale, a square of side 120 is sufficient). The program may optionally output further tiles of the tiling that lie outside the square. The same tile should not appear more than once in the output.

The algorithm should theoretically be capable of generating arbitrarily large patches (given the ability to work with arbitrary precision integers). In particular this means that algorithms that calculate floating point coordinates and then round them to integers are typically NOT acceptable.

Examples

The beginning of the output (corresponding to the first 5 hats) might be:

[(12,0),(10,-1),(10,0),(9,0),(10,2),(12,3),(12,4),(13,5),(14,4),(13,2),(14,2),(14,0),(13,-1)]
[(10,2),(9,0),(8,0),(7,-1),(6,0),(7,2),(6,2),(6,3),(8,4),(9,3),(10,4),(12,4),(12,3)]
[(2,-2),(4,-1),(4,0),(5,1),(4,2),(2,1),(2,2),(1,2),(0,0),(1,-1),(0,-2),(0,-4),(1,-4)]
[(6,0),(7,-1),(6,-2),(6,-3),(4,-4),(3,-3),(2,-4),(1,-4),(2,-2),(4,-1),(4,0),(6,2),(7,2)]
[(4,2),(2,1),(2,2),(1,2),(2,4),(4,5),(4,6),(5,7),(6,6),(5,4),(6,4),(6,2),(5,1)]
...

The output can be in any reasonable form, such as a linefeed-delimited sequence of lists of pairs as above.

The picture below shows a possible output converted to graphical form. Note that the program itself does not need to produce any graphical output (although obviously it is useful for testing). enter image description here

This is code golf, so the shortest program in each language wins.

Related: Draw the GKMS aperiodic tile

\$\endgroup\$
3
  • \$\begingroup\$ 1. There is no input. The program should simply output the coordinates of tiles as described. 2. There are no partial tiles. The output should be exactly as described. It should include every tile that intersects the square, and is allowed to include others, but all tiles output must belong to a tiling of the plane by hats. \$\endgroup\$
    – aeh5040
    May 31 at 16:40
  • \$\begingroup\$ The specifications reads: "All output tiles must belong to a valid tiling of the full plane by hats (all related to each other by congruences or reflections). The output must include every tile that intersects a certain square, where this square is large enough that there are at least 1000 such tiles. (At the above scale, a square of side 120 is sufficient). The program may optionally output further tiles of the tiling that lie outside the square. The same tile should not appear more than once in the output." \$\endgroup\$
    – aeh5040
    May 31 at 23:31
  • \$\begingroup\$ Outputting 5 tiles would not qualify, because 5<1000. Terminating with a memory overflow would be acceptable (although somewhat perverse) provided the task is completed as described first. Not sure what the issue is here...? \$\endgroup\$
    – aeh5040
    May 31 at 23:33
1
\$\begingroup\$

Split a string on unnested commas

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

Print every finite string

In this challenge, you're given the task to create a full program that generates and prints strings indefinitely. The strings must be printed on separate lines, and every finite string must (theoretically) be printed in finite time.

Rules

  • Your submission must be a full program, not a function.
  • You must output the strings to STDOUT.
  • There should be a single line feed between each string.
  • A string is a sequence of printable ASCII characters (0x20-0x7e, inclusive). You may also include any number of null-terminators (0x0), EOFs (0xff) or other zero-space characters.
  • The algorithm used must theoretically print any finite string in finite time. In practice, however, your program may fail after having printed at least 65535 strings.
  • No string can be printed twice. Zero-space characters don't count as part of the string, so the program cannot output both Hello and Hello(EOF).
  • The empty string may or may not be generated.

Valid strings:

Hello
AAAA
(space)
Hello(EOF)
Hello, World!
"#(){ :|~A

Invalid strings:

(tab)
(newline)
ë
ñ
ø
π

This is a , so the shortest answer in each language wins!

\$\endgroup\$
4
  • \$\begingroup\$ I've posted a similar challenge Output all strings though it takes the character set as an input \$\endgroup\$
    – xnor
    Jun 8 at 19:51
  • \$\begingroup\$ Does the program have to be deterministic? Or, Is it valid that for any string my program will output it with a probability of 1? The second one is simply repeat forever { s=generate random string; if (s not yet printed) { print(s) } }. \$\endgroup\$
    – tsh
    Jun 9 at 6:36
  • \$\begingroup\$ @xnor I didn't know of that challenge, thanks for notifying me :) I don't think I'll post this one, considering how similar it is to yours. \$\endgroup\$
    – Peter
    Jun 9 at 7:55
  • \$\begingroup\$ @tsh If all submissions had to be deterministic, they could just set the seed for functions generating random things, so I don't think I'll impose such restriction. \$\endgroup\$
    – Peter
    Jun 9 at 7:57
1
\$\begingroup\$

Output every second

\$\endgroup\$
2
  • \$\begingroup\$ time is a synonym for date, so maybe not what you want here. I'd also be unsurprised if this is a duplicate, though I'm not certain off the top of my head. \$\endgroup\$
    – Bbrk24
    Jun 21 at 20:04
  • \$\begingroup\$ @Bbrk24 The tag says "This challenge is intended to be solved using [...] clock times", so it should still be fine (maybe). If there are any other tags you think belong on this len be know. I searched, and didn't find any others that are the same. \$\endgroup\$
    – Dadsdy
    Jun 21 at 20:54
1
\$\begingroup\$

Counting black and white piano keys

Given a major or minor triad (3 note chord) name, return the amount of black and white piano keys needed to play it. (I will add more explanation later)


Little bit of music theory

A piano contains 88 keys: 52 whites and 36 blacks. The keys are divided into octaves which have 7 white keys and 5 black. The notes represented by the white keys go from A to G (although the starting note in an octave is C; notes from left to right are as following: C, D, E, F, G, A, B). The notes represented by the black keys are accidentals of the white keys. An accidental is either a sharp note (#) or a flat note (b). (There is an exception since there is only 5 black keys and 7 white keys, Should I expand on this?) . A sharp note is one semitone higher than the same note (C# is one semitone higher than C). A flat note is one semitone lower (Db is one semitone lower than D). There is one full tone in between notes except for E-F and B-C where there is a semitone instead and one semitone between keys.

I'll keep adding more details if needed

Note: For this challenge, we don't care which octave the triad is played on since it will be the same answer for any octave.

Example

Cmaj  = 3 white, 0 black 
Fmin  = 2 white, 1 black
G#maj = 1 white, 2 black
Gbmaj = 0 white, 3 black

Input can be the chord name or can be divided into 2 variables: Root (C, F, G#, Gb) and quality (maj, min). I will extend on music theory if this is accepted as a good challenge

Output must be an array of 2 position where the first one is the number of white keys and the second one the number of black keys


Has this been asked before?

\$\endgroup\$
3
  • 1
    \$\begingroup\$ Looks like a nice challenge idea. But, as you say in your post, this definitely needs more music theory to explain what the major/minor triad names really mean. PS: Welcome back! \$\endgroup\$
    – Arnauld
    Jun 29 at 13:21
  • \$\begingroup\$ @Arnauld An usual explaination is just [0,3,7] and [0,4,7], which is enough here \$\endgroup\$
    – l4m2
    Jul 3 at 11:46
  • \$\begingroup\$ @Arnauld thanks mate! Good to be back. I have to research more into this challenge (I know music theory but I dont know how to explain it very well) therefore I'll leave here until my inspiration comes back. I have another idea tho I'll be posting soon! \$\endgroup\$ Jul 12 at 19:15
1
\$\begingroup\$

Draw the initial positions of Mölkky pins in ASCII Art

\$\endgroup\$
5
  • 1
    \$\begingroup\$ I'm afraid this won't lead to many creative answers. Even with a short clever formula generating the pin numbers in the correct order, the cost of applying the correct formatting is very likely to give something longer than just hardcoding the output (for standard languages) or using a built-in string compression (for esolangs). \$\endgroup\$
    – Arnauld
    Jun 29 at 14:08
  • \$\begingroup\$ @Arnauld Sadly i found the same conclusion while trying to code it. For standard languages, would it be more interesting if i discouraged hardcoding by discouraging using too many digits, for example with a scoring system? (for esolangs, i think it's part of the game that anything goes and i shouldn't try to oppose it) \$\endgroup\$
    – Fhuvi
    Jun 29 at 15:00
  • 1
    \$\begingroup\$ This is usually a bad idea. Maybe it would be better to turn this into a slightly more complex ASCII art, giving more compression opportunities. Here is a quick attempt. \$\endgroup\$
    – Arnauld
    Jun 29 at 15:25
  • 1
    \$\begingroup\$ Alternate version \$\endgroup\$
    – Arnauld
    Jun 29 at 15:28
  • 1
    \$\begingroup\$ @Arnauld Thank you for your input. I've changed the challenge with your alternate version. I still hope that this would allow some clever and competitive formulas for the pins numbers! \$\endgroup\$
    – Fhuvi
    Jun 29 at 16:01
1
\$\begingroup\$

Critical Calculations

\$\endgroup\$
2
  • \$\begingroup\$ Computing the damage per ring instead of just the total damage seems like an unnecessary transformation, perhaps allow both? \$\endgroup\$ Jul 7 at 6:24
  • \$\begingroup\$ @CommandMaster Fair point, I think I will allow both \$\endgroup\$ Jul 7 at 14:23
1
83 84
85
86 87
153

You must log in to answer this question.

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