578
\$\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\$
3
  • 1
    \$\begingroup\$ What if I posted on the sandbox a long time ago and get no response? \$\endgroup\$ Commented May 15, 2024 at 14:05
  • 2
    \$\begingroup\$ @None1 If you don't get feedback for a while you can ask in the nineteenth byte \$\endgroup\$ Commented May 29, 2024 at 13:27
  • \$\begingroup\$ I have been once submitted a question to sandbox and downvoted to -1, but after submitting it anyway it has 8-9 score right now. \$\endgroup\$ Commented Dec 5, 2025 at 18:13

5006 Answers 5006

1
150 151
152
153 154
167
0
\$\begingroup\$

Pick and Flip

Challenge

Given an array of integers, perform the Pick and Flip algorithm, which is defined like this:

  1. Set n to 1 (if 1-indexed) or 0 (if 0-indexed).
  2. Set i to the n-th element of the array. If it doesn't exist, stop and return the array.
  3. Reverse the i-th element of the array, if it exists. For example, 15 reverses to 51, and 20 reverses to 2.
  4. Increase n by 1 and return to step 2.

Test Cases

1-indexed:

  3   5  19   6 720  50    Input
 [3]  5  19   6 720  50    Pick
  3   5 (91)  6 720  50    Flip
  3  [5] 91   6 720  50    Pick
  3   5  91   6 (27) 50    Flip
  3   5 [91]  6  27  50    Pick
  3   5  91   6  27  50    Flip
  3   5  91  [6] 27  50    Pick
  3   5  91   6  27  (5)   Flip
  3   5  91   6 [27]  5    Pick
  3   5  91   6  27   5    Flip
  3   5  91   6  27  [5]   Pick
  3   5  91   6 (72)  5    Flip
  3   5  91   6  72   5    Output

0-indexed:

  2   4  19   5 720  40    Input
 [2]  4  19   5 720  40    Pick
  2   4 (91)  5 720  40    Flip
  2  [4] 91   5 720  40    Pick
  2   4  91   5 (27) 40    Flip
  2   4 [91]  5  27  40    Pick
  2   4  91   5  27  40    Flip
  2   4  91  [5] 27  40    Pick
  2   4  91   5  27  (4)   Flip
  2   4  91   5 [27]  4    Pick
  2   4  91   5  27   4    Flip
  2   4  91   5  27  [4]   Pick
  2   4  91   5 (72)  4    Flip
  2   4  91   5  72   4    Output

Restrictions

  • Every integer in the array will be at least 1 (if 1-indexed) or 0 (if 0-indexed).
  • The array will not be empty.

Scoring

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

Get BB(k-1) from BB(k)

Here BB(k) is the longest running step of k-state, 2-symbol deterministic Turing machine. A movement of tape head is required per step, as data source does.

Test cases:

47176870 => 107 # BB(5)=>BB(4)
107 => 21 # BB(4)=>BB(3)

Explain your code as there's technical difficulty to test answers.

\$\endgroup\$
4
  • 1
    \$\begingroup\$ You need to explain your definition of Turing machine a little more. For one I assume you probably mean deterministic Turing machine, but this is worth specifying. Some definitions require that a Turning machine move the tape head on every transition, some definitions allow the tape head to remain fixed. Some definitions require a specific halt state, some halt when there is no transition available. etc. These differences are usually trivial but BB(k) is highly sensitive to them. \$\endgroup\$ Commented Jan 9 at 13:38
  • \$\begingroup\$ Isn't this impossible? The BB(n) sequence is not computable. But if there was a program that solved your problem then wouldn't there be a simple modification of it that computed BB(n)? \$\endgroup\$ Commented Feb 3 at 12:04
  • \$\begingroup\$ @aeh5040 BB(n-1) is uncomputable because we don't have a value promised large enough, but here BB(n) is provided \$\endgroup\$ Commented Feb 4 at 15:16
  • \$\begingroup\$ @l4m2 I am not convinced. I don't know what you mean by "a value promised large enough". Every individual integer is trivially computable. It is sequences that may not be. The sequence mapping n to BB(n) is not because it would require determining which of the n-state TMs halt for each n, which requires solving the halting problem. The (n-1)-state machines are in effect a subset of the n-state ones, but just knowing the max 1s produced by a halting n-state does not help knowing which n-1 state ones halt. \$\endgroup\$ Commented Feb 5 at 15:06
0
\$\begingroup\$

List directories needed to exist to reach a path ("mkdir -p --dry-run")

(The challenge has been posted.)

\$\endgroup\$
7
  • \$\begingroup\$ Hmm. A similar challenge exists but it was closed... \$\endgroup\$ Commented Jan 28 at 5:06
  • 1
    \$\begingroup\$ you can safely ignore the old challenge, it needed a winning criterion which you have with code-golf. this seems relatively trivial, but maybe there's some odd cases in which it's not? \$\endgroup\$ Commented Jan 28 at 11:09
  • 1
    \$\begingroup\$ @Themoonisacheese The main catch of this proposed challenge is how to handle . and .. in paths. And I want to make it usable in the real world, as if one day someone implements the actual --dry-run in mkdir(1). \$\endgroup\$ Commented Jan 28 at 11:27
  • \$\begingroup\$ i see. nothing wrong with easy real-world use cases (As in, i'm not gonna tell you not to post it) but some people do downvote challenges that they find too easy, FYI. \$\endgroup\$ Commented Jan 28 at 11:29
  • \$\begingroup\$ Given that .. should never appear in the output, is it guaranteed that no input would perform a directory traversal attack as specified in the previous challenge? \$\endgroup\$ Commented Jan 28 at 16:35
  • \$\begingroup\$ @UnrelatedString If you do mkdir -p a/../b, you would see mkdir creates two directories. So you are to resolve .. to match the behavior. In other words, this challenge allows directory traversal. \$\endgroup\$ Commented Jan 28 at 20:58
  • \$\begingroup\$ It would be helpful to spell out the significance of . and .. for this challenge. I know what they mean, but it still took me a second to realize why a/d was in the output. \$\endgroup\$ Commented Jan 28 at 22:20
0
\$\begingroup\$

The first occurrence of k zeros in \$^\infty 3\$

Given k, find the first(lowest) occurrence of k continuous zeros in \$^\infty 3\$ in 10-adic.

Here, 10-adic mean base-10 but extend infinitely to left, and \$^\infty 3\$ is defined as limit of sequence \$a_1=3, a_{i+1}=3^{a_i}\$. It can be proven that every digits eventually get stable.

Your program should run in reasonable time and space for k=3.

The value ends with 05496638003222348723967018485186439059104575627262464195387, so you should return 19(0-index) for k=1.

Test cases

  • 1 => 19
  • 2 => 49
  • 3 => 356
  • 4 => 3448

Notes

Inspired by Are there G(63) continuous zeros in G(64)?, which I'd say G(64) is much larger than G(63) for this purpose and can be treated \$^\infty 3\$.

This may be not fun as due to likely unique and well-explored path

Maybe this is better posted as "Output 3^^inf" don't count zeros

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

Rational quadratics sequences

Let's define a rational quadratics sequence \$a_1, a_2, \cdots, a_n\$ of length \$n\$ one that satisfies all of the following:

  • The integers from 1 to \$n\$ appear exactly once each.
  • For \$1 \le i \le n - 2\$, at least one of the equations of the form \$a_{i} x^2 \pm a_{i+1} x \pm a_{i+2} = 0\$ has rational roots. In more direct terms, at least one of \$a_{i+1}^2 \pm 4 a_i a_{i+2}\$ is a square number.

Given a positive integer \$n\$, find the number of rational quadratics sequences of length \$n\$.

I/O rules apply. This means you can choose to implement one of the following:

  • Take \$n\$ and give the answer for \$n\$.
  • Take \$n\$ and give the answers for \$1, \cdots, n\$.
  • Without input, give all answers for \$1, 2, 3, \cdots\$.

Test cases

1 => 1
2 => 2
3 => 6
4 => 4
5 => 4
6 => 4
7 => 4
8 => 10
9 => 4
10 => 32
11 => 10
12 => 26
13 => 32
14 => 68
15 => 136
\$\endgroup\$
0
\$\begingroup\$

Find the paths and cycles

Given a finite digraph with all in-degrees and out-degrees at most 1, find its partition into directed paths and cycles.

The problem is potentially interesting because paths and cycles are slightly different - combining the two may inspire some ingenious approaches.

Input

A sequence of pairs of vertices representing the directed edges of the graph, which might appear in any order. You can assume:

  • The vertices are precisely the integers 0,...,n for some n>0.

  • Every such integer appears in some pair (so there are no isolated vertices).

  • Every such integer appears at most once on the left of a pair and at most once on the right of the pair (so in-degrees and out-degrees are at most 1).

Output

A sequence of lists of vertices representing the directed cycles and maximal directed paths of the graph.

  • A path must be represented by its vertices in order.

  • A cycle must be represented by its vertices in order starting from an arbitrary vertex with the initial vertex repeated once at the end.

  • The paths and cycles must include all vertices between them, with no repeats except for the repeat of the beginning and end of each cycle.

  • Thus, the edges of the input should be precisely the ordered consecutive pairs within each list of the output (in some order).

  • The paths and cycles can be output in any order. Each cycle can be started from any of its vertices.

Any reasonable representation of "list of lists of integers" is acceptable for input and output.

Examples

Input Output
[[0,1],[1,2],[2,3]] [[0,1,2,3]]
[[0,1],[1,2],[2,0]] [[0,1,2,0]]
[[1,0]] [[1,0]]
[[5,3],[1,2],[0,4],[3,1],[4,0]] [[5,3,1,2],[0,4,0]]

This is , so shortest program in each language wins!

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

Return the minimum Conjunctive Normal Formula equivalent to the one given in input.

Translated by Google + some my changes

A conjunctive normal formula (abbreviated here CNF) is a conjunction of clauses, which are disjunctions of variables. It is represented by writings such as

(A∨B∨∼C∨∼D)∧(Q∨R∨∼P∨∼K)∧...∧(∼M)

where (A∨B∨∼C∨∼D), (Q∨R∨∼P∨∼K), ..., (∼M) are each the clauses of the CNF above, where A B C D ... M are "variables" of the respective clauses. Each of these variables can take on any value in the set TF={1,0}. Once a value in the set TF has been assigned to each variable, the value of the CNF can be calculated by performing the functions ∨ ∧ ∼ with the binary values ​​0 1 of each variable.

The operation ∨ is defined by

1∨0=1; 0∨1=1; 1∨1=1; 0∨0=0

The operation ∧ is defined by

1∧0=0; 0∧1=0; 1∧1=1; 0∧0=0

The function ∼ is defined by

∼1=0; ∼0=1

Two CNFs A(x1,x2,...xn) and B(y1,y2,...yn), with variables {x1,x2,...xn} and {y1,y2,...yn}, are said to be equivalent if any assignment {x1,x2,...xn} ∪ {y1,y2,...yn} with values ​​in the set TF={1,0} yields the same final Boolean value (performing all calculations with the functions ∨ ∧ ∼) in CNF A and CNF B.

If A and B are two conjunctive normal formulas, we say that A is less than B if the sum of all occurence of ∧ and or ∨ of A is less than the sum of all occurence of the and ∧ and or ∨ of B

Examples: Let's say two CNFs A and B with

A=(a1∨a2)∧(a3∨a4) and B=(a1∨a2)∧a3

then B<A because numbers of ∧ and ∨ of B is 2 that is less than the number of ∧ and ∨ of A that is 3.

Here we require a program that, given a CNF A, returns a CNF B that is as small as possible and equivalent to A. The winner is the one who finds the minimum number of the sum of all the or[∨] and and[∧] that appear in all the CNF results of below exercises.

If two answers are tied, then the winner is the one with the smallest program in terms of number of bytes in the source code.

Exercises (the formulas are the same as those in Prove me wrong!)

(P∨∼Q∨∼R)∧(Q∨R∨∼P)∧(Q∨∼P∨-R)
(∼P)∧(S)∧(R∨∼P)∧(U∨∼Q)∧(X∨∼R)∧(Q∨∼S)∧(∼P∨∼U)∧(W∨∼Q∨∼U)
(∼P∨∼Q)∧(Q∨P)∧(P∨∼Q)∧(Q∨∼P)
(P)∧(∼P∨∼S)∧(P∨T)∧(Q∨∼R)∧(∼R∨∼S)∧(∼P∨∼Q∨��R)∧(∼P)
(T∨∼S)∧(∼S)∧(Q∨∼R)∧(∼R∨∼S)∧(∼P∨∼Q∨∼R)∧(∼P)

These formulas can be represented in the code with maximum freedom, for example,

(P∨∼Q∨∼R)∧(Q∨R∨∼P)∧(Q∨∼P∨-R)

could be represented as an array of 3 strings:

('P-Q-R')('QR-P')('Q-P-R')

Examples:

In finding a smaller equivalent CNF for (P∨∼Q∨∼R)∧(Q∨∼R∨∼P)∧(Q∨∼P∨-R) I would have found (Q∨∼P)∧(P∨∼Q∨∼R). It has 1 and ∧, and 3 or ∨ in total so 4 is the length of this result formula that is more little of the one of input that has length 6 or and 2 and that would be 8.

Could be useful these equivalences

A∨B∨..∨D is equivalent to each permutations of variables A B..D 
A∧B∧..∧D is equivalent to each permutations of variables A B..D 
A∨B∨..∨∼A∨..∨D is equivalent to 1 or always true, 1 is the name of that proposition 
A∧B∧..∧∼A∧..∧D is equivalent to ∼1 or always false or 0 zero
A∨∼1 is equivalent to  A
A∨ 1 is equivalent to  1
A∧∼1 is equivalent to ∼1 (that is 0 too)
A∧ 1 is equivalent to  A
A∧(A∨∼A) is equivalent to A
A∧(B∨∼A) is equivalent to A∧B
(P∨Q)∧(P∨R) is equivalent to P∨(Q∧R) useful when R is ∼Q
(A∨B∨C∨D)∧(Q∨R∨P∨K)∧(A∨B) is equivalent to (Q∨R∨P∨K)∧(A∨B)

tag logic codegolf

\$\endgroup\$
3
  • \$\begingroup\$ I thought this problem is NP-complete, is it not? \$\endgroup\$ Commented Feb 9 at 12:49
  • \$\begingroup\$ @Explorer09 I don't know, I didn't see in books the definition of equivalent cnf, and minimal equivalent cnf... one would ask that to one expert academic... I search 'minimal cnf' and this problem exist and Google says it is np-hard I don't know the meaning \$\endgroup\$ Commented Feb 9 at 13:30
  • \$\begingroup\$ It means there is unlikely a solution that can solve the problem in polynomial time (N² or N³). The time complexity would be (2^n) or more. It's a difficult computer science problem. \$\endgroup\$ Commented Feb 9 at 15:13
0
\$\begingroup\$

SCR max speed calculator

SCR is a train driving game on Roblox. Distances are measured in miles, and speeds in miles per hour. The driving guide dictates specific speeds for specific scenarios:

  • The speed should never be higher than either the maximum speed of the train or the imposed speed limit.
  • If the train is less than or equal to 0.35 miles from the station, the train should go no more than 35mph.
  • If it is a terminating station, it should be no more than 15mph.
  • If the signal is a single yellow aspect, it should be no more than 45mph.
  • If the signal is a red aspect and the distance to the signal is less than the distance to the station, the train should be at a complete stop (0mph). If the station is closer, normal station approach rules apply.
  • Double yellow and green aspects do not carry speed restrictions by themselves.

Given the train’s maximum speed, the current speed limit, the distance to the next station, the distance to the next signal, and the current signal aspect, output the maximum speed the train is allowed to move at in mph. If the next signal aspect is red and the station is closer than the next signal, you may assume that the train is at most 0.35mi away from the next station. Shortest code wins, standard loopholes apply.


Too complex?

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

Inference a transformer

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

Can you Shut The Box?

Shut The Box is a simple dice game, where a player attempts to "shut" all of the numbered tiles (traditionally, 1 through 9) by rolling dice. The way the game works:

  • The box has 9 numbered and hinged tiles, numbered 1, 2, 3, etc. up to 9. Initially, all 9 begin "open".
  • A player rolls two 6-sided dice and total the two dice.
  • They then "shut" any combination of tiles that sum to the dice total.
  • Repeat until all tiles are shut, or no more open tiles can sum to the dice total.
  • The player's final score is the total of all remaining open tiles, with a lower score being better.

Note that there are multiple ways that one dice roll can shut different tiles. For example, rolling a total of 5 can close either the 5 tile, the 4 and 1 tiles, or the 3 and 2 tiles. Importantly, there is only one of each numbered tile, so once a tile has been used, it cannot be used again. Thus, for a roll of 6, the combination of 3 and 3 isn't valid, but the 3, 2 and 1 tiles are.


Given a non-empty list of positive integers ranging from 2 to 12 inclusive, output the lowest possible score for that series of dice rolls, in that order. You may take input in any acceptable and reasonable format and method, but please note that, as order matters, the manner in which you take input must distinguish different orders of the same integers.

This is a challenge, so the shortest code in bytes in each language wins.

Test cases

Input -> Output
[10, 10, 10, 10, 5] -> 0
\$\endgroup\$
0
\$\begingroup\$

Simulate gravity

Given how simple this is, I'm pretty surprised there wasn't a question on here for this already. The task for this question is to simulate n-body gravity!

Simple? I thought the n-body problem was famously unsolved!

Yeah, yeah; whatever. There's (provably) no analytic equation, but gravity really just follows one simple rule:

$$F = G \frac{m_1m_2}{r^2}$$

That's it. There's no big gatchas until you start dealing with relativity, and relativity puts gatchas on everything. We're actually going to simplify our simulation even more, and say all our masses are one kg, and exist in a magical world where the gravitational constant G is 1\$ \text m^3 \over \text{kg} \cdot \text{s}^2 \$, so the equation you're going to simulate is

$$\ddot r_i = \sum_{j\ne i} \frac{\hat r_{ij}}{|r_{ij}|^2} \quad \forall i$$

"Gah," I hear you cry. "You tricked me, what are all these extra symbols you've added! There's dots and sums and hats and bars! And your A's upside down, the pointy bit goes up!"

Don't Panic!
Mathematicians love code golf too, most of these symbols are just fancy loops. We'll go one step at a time, from the outside in.
The upside down A is the closest you get to an actual for loop in math, and it means that this whole equation individually applies to each of our bodies, represented by a variable \$i\$. It's basically equivalent to for i in bodies
The double dot is a little more tricky. In math terms, it's the second derivative with respect to time, but we can keep it simpler than that. A derivative (in time) is a fancy way to say "the amount something changes (per second)," so this double dot equation is defining the change of the change of each radius. Our pseudocode now looks like this:

for i in bodies {
    v[i] += equation
    r[i] += v[i]
}

(for the math buffs that just started complaining, see this video for why we update velocity first)

The next piece is the summation. This is also a for loop, except you just sum all the terms and return the result. The thing on the bottom is the values we're looping over. This means equation now looks like equation = sum(fraction(i,j) for j in bodies if j != i)

Almost there! The ij subscript means the vector from \$r_i\$ to \$r_j\$, which you calculate by taking the vector difference: rij = r[j] - r[i].
The bars mean finding the magnitude, which you do by taking the square root of the sum of the squares of the components. In code that's rij_mag = sqrt(rij[1]^2 + rij[2]^2 + rij[3]^2)
The hat means normalizing a vector, which you do by dividing the magnitude; but if you look closely at our fraction we're already doing that! Dividing one more time just means incrementing the exponent.

Putting that all together, our pseudocode is:

for i in range(num_bodies) {
    v[i] += sum(
        (r[j]-r[i]) / sqrt(
            ( r[j][1]-r[i][1] )^2 + ( r[j][2]-r[i][2] )^2 + ( r[j][3]-r[i][3] )^2
        )^3
        for j in range(num_bodies)
        if j != i
    )
    r[i] += v[i]
}

Requirements

Your task for this challenge is to simulate one second of gravity. That is, your code should do the equivalent of running the above for loop once. You will be given \$n\$ bodies, where each body has a velocity and position. You may take these \$6n\$ numbers however you like, but you should return the updated \$6n\$ numbers in the same way. (ie, your code should accept its own output as a new input)

You can assume that two bodies will never perfectly overlap (so there's no division by zero), and you don't need to worry about precision (so just use the default floaty numeric type)

Test cases

{velocities}, {positions} -> {v}, {r}

{}, {} -> {}, {}
{[10, 5, 1]}, {[1, 2, 3]} -> {[10, 5, 1]}, {[11, 7, 4]}
{[0,0,0], [0,0,0], [0,0,0]}, {[1,0,0], [0,1,0], [0,0,1]} -> {[-.7071, .3535, .3535], [.3535, -.7071, .3535], [.3535, .3535, -.7071]}, {[.2928, .3535, .3535], [.3535, .2928, .3535], [.3535, .3535, .2928]}

Brownie Points

We simplified some stuff here, but we've done the hardest part of a fully fledged n-body gravity simulation. If you want extra brownie points, you can add those complications back in.
First, we want the gravitational constant G.
Then, we allow for masses on each bodies with a mass[] array
Finally, we'll take t and dt for total time and step time

Our updated pseudocode is:

T=0
while T < t {
    for i in range(num_bodies) {
        v[i] += G * sum(
            mass[j] * (r[j]-r[i]) / norm(r[j] - r[i])^3
            for j in range(num_bodies)
            if j != i
        ) * dt
        r[i] += v[i] * dt
    }
    T += dt
}
\$\endgroup\$
-1
\$\begingroup\$

Match the BF output

Your task is, when given a BF program as input and 256 1's on the line after the BF program, match the amount of 1's equal to the value of the pointer when the program halts.

For a BF tutorial, see here.

Example programs:

+++
(255 1's)

(The above program should match 3 1's.)

++[>+++>+++<<-]>
(255 1's)

(The above program should match 6 1's.)

Specs:

  • The tape in question is 10 long, with wrapping.
  • There is wrapping for the individual values: if it goes over 256, it goes back to 0.
  • There is no , or . in the BF code.
  • You are guaranteed that the code will terminate.
  • You may use any flavour you want.
  • You may match 1's in any position, as long as you match the correct amount of 1's.

This is , so shortest code in bytes wins!

Meta stuff:

  • How hard would this be to pull off? Is it even possible?
  • Anything I could improve with explanations?
\$\endgroup\$
9
  • 1
    \$\begingroup\$ 1. I think it should be "the value of the memory cell under the pointer" rather than "the value of the pointer". 2. This is clearly impossible using regular expressions, but it is possible using Perl 5's regexes, which are Turing-complete. However, at that point you're really just using Perl wrapped in regex notation, so it's arguably a dupe of codegolf.stackexchange.com/q/84/194 \$\endgroup\$ Commented Nov 8, 2016 at 7:30
  • \$\begingroup\$ @PeterTaylor Your second claim is false. With a wrap around BF becomes a finite state machine. Thus even it's halting problem is solvable by a push down automaton (regex). It may be extremely hard but this problem is most certainly solvable. \$\endgroup\$ Commented Nov 8, 2016 at 17:04
  • 1
    \$\begingroup\$ @WheatWizard, although my initial reaction was to agree with you, on further reflection I'm not entirely convinced. The halting problem for a finite state machine is trivial: they always halt. Since a BF program can enter an infinite loop, it's therefore not an FSM. It's true that any given program has a finite number of states, but the state includes the program counter and so the ecosystem as a whole can have an unbounded number of states. Consider that in execution we can jump back along the program string an arbitrary distance: how can a pushdown automaton remember the contents of a loop? \$\endgroup\$ Commented Nov 8, 2016 at 20:48
  • \$\begingroup\$ @PeterTaylor iirc finite state machines can loop infinitely however any loop must be periodic. I don't know why you claim finite state machines cannot loop. Toroidal Brainfuck fits every definition of a FSM I can find at the moment. It has a finite number of states and a well defined mapping of each state to another. I also don't understand what you mean when you say "Program counter" if you are referring to the instruction pointer it is certainly finite. Could you clarify this? I don't mean to be argumentative, but I do disagree with you. If I am incorrect I am sorry for wasting your time. \$\endgroup\$ Commented Nov 8, 2016 at 23:36
  • \$\begingroup\$ @PeterTaylor If it helps, the input program is guaranteed to halt. Would it be easier to decide if there are a limited number of "moves" (i.e. 30,000 moves, 1 move = any +-><)? \$\endgroup\$ Commented Nov 9, 2016 at 5:03
  • \$\begingroup\$ @WheatWizard, the point with FSMs and the halting problem is that each state transition occurs with one character of the input, each character of the input is processed only once, so therefore the execution time is bounded by the length of the input. On the main point, I'm not saying that you're wrong: just that I'm not convinced. Perhaps the thing to do is to edit the question to rule out "cheating" by calling out to a general-purpose programming language and then see whether anyone finds a solution. \$\endgroup\$ Commented Nov 9, 2016 at 7:36
  • \$\begingroup\$ Limiting the runtime would certainly make it doable, because then the values which the program counter (or instruction pointer, they're synonymous) can reach are bounded, and so the total number of states is bounded by the number of memory states times the number of moves. It's not a practical bound, but in theoretical terms it's certainly good enough. \$\endgroup\$ Commented Nov 9, 2016 at 7:37
  • \$\begingroup\$ @PeterTaylor So I'm getting the "this is impossibly hard" gist - but is it on the same level as "Tetris in GoL"? I want to make a challenge that's difficult, but not THAT difficult. \$\endgroup\$ Commented Nov 9, 2016 at 9:59
  • \$\begingroup\$ I just realized that vanilla regex (without lookarounds) is a finite state machine and not a push down automaton. I think PeterTaylor is correct in assessing this as impossible. \$\endgroup\$ Commented Nov 9, 2016 at 14:15
-1
\$\begingroup\$

Consecutive Composites

Your task is to write a program or function which, given a positive integer N, finds the first block of N consecutive composite numbers.

This should be the first block of integers which fit the requirements, larger than 0. For example, with an input of 2, the output must be [8, 9], and not [14, 15].

Rules:

  • The numbers in the block should be printed or returned as a list, in any reasonable format.
  • Submissions may be either full programs which perform I/O, or functions - no snippets.
  • You can assume that the block of numbers your program has been request to find is within your language's standard integer range.
  • This is , so the shortest program (in bytes) wins! Standard golfing loopholes apply.

Test Cases

1 -> [1]
2 -> [8, 9]
5 -> [24, 25, 26, 27, 28]
6 -> [90, 91, 92, 93, 94, 95]
10 -> [114, 115, 116, 117, 118, 119, 120, 121, 122, 123]

\$\endgroup\$
3
  • 1
    \$\begingroup\$ This is essentially codegolf.stackexchange.com/q/23844/194 with a tweaked output format. \$\endgroup\$ Commented Feb 6, 2017 at 9:34
  • \$\begingroup\$ One is not a composite number, the smallest is four, so the test case for 1 should be [4]. \$\endgroup\$ Commented Feb 6, 2017 at 20:39
  • \$\begingroup\$ @JonathanAllan i've misused the term composite there, I meant 'non-prime' - regardless, I probably won't post this anyway and Peter pointed out it's basically a dupe. \$\endgroup\$ Commented Feb 6, 2017 at 22:02
-1
\$\begingroup\$

Portable bitmap checkerboard pattern

Your task is to create a checkerboard pattern and store it in a PBM.

Size of the checkerboard is passed in STDIN as two numbers. Output is written to STDOUT.

Test case:

Input:
5
5

Output:
P1
5 5
0 1 0 1 0
1 0 1 0 1
0 1 0 1 0
1 0 1 0 1
0 1 0 1 0

This is so the shortest code wins

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

Bike saddle drawn through a fractal

Based on the Mandelbrot image in every language, and on the observation the 3rd layer (0 indexed) always looks like a bike saddle, I had a little bit different challenge:

  • Language must be capable of graphical output or drawing charts (saving files disallowed)
  • Render a window or control that is resizable by mouse action. As example, it can be a typical GUI Window with the typical frame that allows resizing
  • After resizing the GUI element, the fractal should be updated according to the new pixel space
  • The fractal coordinates range from approximately -2-2i to 2+2i
  • The pixels outside of the 3rd layer (0 indexed) of Mandelbrot set should have one color; the ones inside 3rd and inner layers should have another. The only two colors used should be clearly distinguishable
  • At least 99 iterations
  • ASCII art not allowed

Winning conditions:
Shortest version (size in bytes) for each language will get a mention in this post, ordered by size.
No answer will ever be 'accepted' with the button.

\$\endgroup\$
2
  • \$\begingroup\$ @Mark Jeronimus: credits to you. \$\endgroup\$ Commented May 27, 2017 at 8:48
  • \$\begingroup\$ "The only two colors used should be clearly distinguishable" Clarification? \$\endgroup\$ Commented Aug 15, 2023 at 14:30
-1
\$\begingroup\$

Do nothing

Write a program which terminates normally (not in an error), producing no output on the standard output stream (or the language's closest equivalent), nor on the standard error stream, regardless of what content is present on the standard input stream. (Note that this is intentionally overriding the normal I/O defaults; this is a challenge entirely about input/output handling.)

Additionally, your program may not have any other side effects (e.g. writing files, changing persistent state), unless they're an unavoidable consequence of running a program on the operating system you're using (e.g. on Linux, it's OK to change the "next process ID number to be assigned" value inside the kernel, because that happens whenever you run a program).

Finally, to avoid numerous uninteresting 0-byte (or boilerplate-plus-0-byte) solutions, you may not use a language in which the shortest program that does nothing (i.e. complies with the above specification) is also the shortest (or tied for the shortest) program which runs without error (but possibly reacts to input or produces output). In other words, you can't use a language unless doing nothing is more verbose than doing something.

Clarifications

  • Intentionally exiting the program early is permitted. If you do exit the program manually, on a system that uses exit codes, you may do so with any exit code.
  • Crashing the program is not permitted, even if it (for some reason) exits with a "success" code after the crash.
  • "No output" means 0 bytes of output, not even a trailing newline.
  • Likewise, your program must be able to handle any finite sequence of bytes on the standard input stream, even if it isn't, say, made of characters in the current encoding (but rather of arbitrary octets). You do not need to handle infinite input, though (e.g. your program won't be connected to /dev/zero or the like).
  • You don't have to actually read input; it's your choice as to whether you want to read and discard it, or not read it at all.

Victory condition

As a challenge, shorter is better, measured in bytes. (Remember that if you need to run the program in an unusual way, that incurs a byte penalty, under standard PPCG rules.)

Because languages which are particularly suited for this task (such as Perl and Python) are excluded by the rules, there's not much point in talking about the best answer cross-language; rather, the aim is to find the best answer you can in the language which you submit in. (Historically, on this sort of challenge, answers that are more unusual, interesting, or better-explained have tended to get more votes.)

Sandbox questions

Is this too trivial? We were discussing it in chat as a joke, and realised that it's actually possibly more interesting than it sounds. I'm fairly sure the spec's correct (although would definitely appreciate knowing if something's wrong here!), but would appreciate feedback on how much people would hate me if I posted it to main.

\$\endgroup\$
3
  • \$\begingroup\$ you can't use a language unless doing nothing is more verbose than doing something.you can't use a program unless your program is more verbose than any other program which does something. You must provide a shorter program which does something to prove your solutions validity. \$\endgroup\$ Commented Jun 8, 2017 at 1:03
  • \$\begingroup\$ @Adám: If you did that, people would just add a comment byte or two to create a program of the shortest possible length that was longer than a program that did something. That isn't particularly interesting. \$\endgroup\$ Commented Jun 8, 2017 at 1:21
  • \$\begingroup\$ So I write a buffer null that accepts input stdin > /dev/null I think it should do nothing. If it produces Moby Dick I will be surprised. \$\endgroup\$ Commented Dec 28, 2023 at 8:23
-1
\$\begingroup\$

Plan and Chain a route through OEIS

Your Task is to reach so many OEIS sequences you could make with chaining your last sequence with a operation to a new sequence.

You must avoid last sequence minus last sequence plus first sequence or something similar that your new sequence is based on the first sequence except to make the second sequence.

Your starting OEIS sequence is in every case https://oeis.org/A001477

Given as Input an positive Integer and a Letter that matches [A-Z] or [a-Z]

Example

PHP, 171 bytes

for($a=0;$a<=$argv[1];$a++)$r[]=[$a,$b=$a&1,$c=$a+!$b,$d=(($c-!$b)/2^0)+$b,$A[$b]=$e=$d*$c,$f=$e+$A[!$b],$g=$a?$g*sqrt($f):1,$h=$g%2];echo$r[$argv[1]][ord($argv[2])%32-1];

Try it online!

The example gives back the n value of a OEIS sequence for the following letters. A letter greater h is for this example a invalid input

  • a https://oeis.org/A001477 numbers
    $a Valid first sequence

  • b https://oeis.org/A000035 mod 2
    $b=$a&1 Valid use the variable in the sequence before

  • c https://oeis.org/A109613 odd numbers
    $c=$a+!$b Valid Can use sequences before

  • d https://oeis.org/A110654 a(n) = floor(n/2) + n mod 2
    $d=(($c-!$b)/2^0)+$b Valid an invalid example is $d=(($a/2)^0)+$b cause it not use the sequence before

  • e https://oeis.org/A000217 triangular
    $A[$b]=$e=$d*$c Valid you can create help variables

  • f https://oeis.org/A000290 square
    $f=$e+$A[!$b] Valid use a help variabale and the variable of the sequence before. $f=$A[!$b]+$A[!$b] Invalid causes it makes the same value but use indirectly the variable of the sequence before

  • g https://oeis.org/A000142 factorial $g=$a?$g*sqrt($f):1 Valid cause your condition is not always the case that it have no relationship to the sequence before.

  • h https://oeis.org/A019590 Fermat's Last Theorem $h=$g%2 Valid but now we have the problem to find the next sequence

Could You make a full alphabet? My alphabet ends with the letter h

\$\endgroup\$
9
  • \$\begingroup\$ I'm rather confused as to what is being asked here. It might be helpful to state how one can get from one sequence to another. \$\endgroup\$ Commented Jun 10, 2017 at 20:47
  • \$\begingroup\$ @WheatWizard I could understand you. The problem is at the moment to make rules that avoid that a trivial solution exits. There are too many sequences in OEIS. The way from every sequence to the next should not end in a simple addition or multiplication. But evrything else should be allowed to get more creative solutions \$\endgroup\$ Commented Jun 10, 2017 at 20:56
  • \$\begingroup\$ (1) The first sentence says that the aim is to build the longest chain possible, but the scoring mechanism rewards average code length per element in the chain rather than number of chains. I would think it most likely as it stands that the winner would be a chain of length 1 or at most 2. (2) If you delete everything from the header Example to the end, do you think that the question still makes sense? If not (and I don't think it does), it needs a lot of work. (3) What do the two values in the input mean? Why is the second one a letter rather than a number? \$\endgroup\$ Commented Jun 10, 2017 at 21:10
  • \$\begingroup\$ (4) I'm not sure how feasible it is to write objective rules which forbid "trivial" expressions. (5) It is not clear how to interpret the rule about the 32nd term where either it is not known or the sequence is finite and shorter than 32 terms. \$\endgroup\$ Commented Jun 10, 2017 at 21:12
  • \$\begingroup\$ @PeterTaylor (1) Think you that popularity Contest is a better winning criteria? (2+3) to limit the chaining length to 26. The goal is to show relationsships between two or more sequences. (4+5) Yes it is not easy and I can drop it if I switch to popularity Contest \$\endgroup\$ Commented Jun 10, 2017 at 21:26
  • \$\begingroup\$ @WheatWizard I allow now trivial solutions \$\endgroup\$ Commented Jun 10, 2017 at 21:53
  • \$\begingroup\$ I'm not clear on the purpose of the inputs if we're just supposed to hard code our way from one sequence to the next​. Replacing your PHP example with more generic, more verbose pseudo-code might help. \$\endgroup\$ Commented Jun 11, 2017 at 0:16
  • \$\begingroup\$ @programmer5000 exists a limit of correct tags? \$\endgroup\$ Commented Jun 11, 2017 at 11:39
  • \$\begingroup\$ @Shaggy See it as restriction for ways to code. You must have a chaining to the sequence before. So far I know any working code is a pseudocode \$\endgroup\$ Commented Jun 11, 2017 at 11:48
-1
\$\begingroup\$

Braid Badly Boundlessly


Your program or function must, given a string in any standard input format, output an infinite stream of delimiter-separated strings where each string is determined from the previous by a braiding algorithm. The program starts with printing the input string.

The algorithm is described as follows: Infinitely alternate between

(1) splitting the string into three substrings then swapping the first two substrings and flattening.

and

(2) splitting the string into three substrings then swapping the last two substrings and flattening.

starting with (1).

The three substrings should be of non-increasing length with the maximum length no more than 1 greater than the minimum length of the three substrings. (This means that when the length of the given string is a multiple of three, the three substrings should be the same length. When the length of the given string is one more than a multiple of three, the first substring should be one character longer than each of the last two substrings. When the length of the given string is two more than a multiple of three, the first and second substrings should each be one character longer than the last substring.)

Example

Let the input be "abcdefg". Let the delimiter be a newline.

Then the program would first print "abcdefg".

It applies (1) which splits the string into ["abc","de","fg"] and swaps the first two elements, reaching ["de","abc","fg"]. It flattens to get "deabcfg" which it prints and uses for the next step.

The program applies (2) to "deabcfg" to split into ["dea","bc","fg"] and swaps into ["dea","fg","bc"], flattening to reach "deafgbc".

The program applies (1) to "deafgbc" and the process repeats ad infinitum.

Then the output would be the newline-separated

abcdefg
deabcfg
deafgbc
fgdeabc
fgdbcea
bcfgdea
bcfeagd
eabcfgd
eabgdcf
gdeabcf
gdecfab
cfgdeab
cfgabde
abcfgde
abcdefg
deabcfg
deafgbc
fgdeabc
fgdbcea
bcfgdea
bcfeagd
eabcfgd
eabgdcf
gdeabcf
gdecfab
cfgdeab
cfgabde
abcfgde
abcdefg
[...]

Specifications

  • Note that the string should not be split at the beginning and then only swapped later. The string should be split on each and every iteration
  • The delimiter between lines could be whichever character is convenient. You may assume it does not appear in the input string.
  • The string input shall be at least three characters
  • The input consists solely of printable characters (0x20-0x7F)
  • Of course, standard loopholes are forbidden.

I/O

  • The input and output should be taken in standard I/O methods.
  • The input and output should be taken as string, list of characters, or equivalent.
  • The output should be output continuously, which means you may assume infinite memory.

Test cases

For the test cases, we will assume that the delimiter is a newline. Just the portion before the endless stream is repeats is shown.

input
--
output
-----
abcdefg
--
abcdefg
deabcfg
deafgbc
fgdeabc
fgdbcea
bcfgdea
bcfeagd
eabcfgd
eabgdcf
gdeabcf
gdecfab
cfgdeab
cfgabde
abcfgde
-----
abc
--
abc
bac
bca
cba
cab
acb
-----
abcdefgh
--
abcdefgh
defabcgh
defghabc
ghadefbc
ghabcdef
bcdghaef
bcdefgha
efgbcdha
efghabcd
habefgcd
habcdefg
cdehabfg
cdefghab
fghcdeab
fghabcde
abcfghde
abcdefgh
-----
Braid
--
Braid
aiBrd
aidBr
dBair
dBrai
radBi
raidB
idraB
idBra
Brida
-----
Cycle
--
Cycle
clCye
cleCy
eCcly
eCycl
yceCl
ycleC
leycC
leCyc
Cylec
-----
O Canada!
--
O Canada!
anaO Cda!
anada!O C
da!anaO C
da!O Cana
O Cda!ana
-----
A man, a plan, a canal - panama!
--
A man, a plan, a canal - panama!
an, a canalA man, a pl - panama!
an, a canal - panama!A man, a pl
 - panama!Aan, a canal man, a pl
 - panama!A man, a plan, a canal
 man, a pla - panama!An, a canal
 man, a plan, a canal - panama!A
n, a canal  man, a pla- panama!A
n, a canal - panama!A man, a pla
- panama!A n, a canal man, a pla
- panama!A man, a plan, a canal 
man, a plan- panama!A , a canal 
man, a plan, a canal - panama!A 
, a canal -man, a plan panama!A 
, a canal - panama!A man, a plan
 panama!A m, a canal -an, a plan
 panama!A man, a plan, a canal -
an, a plan, panama!A m a canal -
an, a plan, a canal - panama!A m
 a canal - an, a plan,panama!A m
 a canal - panama!A man, a plan,
panama!A ma a canal - n, a plan,
panama!A man, a plan, a canal - 
n, a plan, panama!A maa canal - 
n, a plan, a canal - panama!A ma
a canal - pn, a plan, anama!A ma
a canal - panama!A man, a plan, 
anama!A mana canal - p, a plan, 
anama!A man, a plan, a canal - p
, a plan, aanama!A man canal - p
, a plan, a canal - panama!A man
 canal - pa, a plan, anama!A man
 canal - panama!A man, a plan, a
nama!A man, canal - pa a plan, a
nama!A man, a plan, a canal - pa
 a plan, a nama!A man,canal - pa
 a plan, a canal - panama!A man,
canal - pan a plan, a ama!A man,
canal - panama!A man, a plan, a 
ama!A man, canal - pana plan, a 
ama!A man, a plan, a canal - pan
a plan, a cama!A man, anal - pan
a plan, a canal - panama!A man, 
anal - panaa plan, a cma!A man, 
anal - panama!A man, a plan, a c
ma!A man, aanal - pana plan, a c
ma!A man, a plan, a canal - pana
 plan, a cama!A man, anal - pana
 plan, a canal - panama!A man, a
nal - panam plan, a caa!A man, a
nal - panama!A man, a plan, a ca
a!A man, a nal - panamplan, a ca
a!A man, a plan, a canal - panam
plan, a cana!A man, a al - panam
plan, a canal - panama!A man, a 
al - panamaplan, a can!A man, a 
al - panama!A man, a plan, a can
!A man, a pal - panamalan, a can
!A man, a plan, a canal - panama
lan, a cana!A man, a pl - panama
lan, a canal - panama!A man, a p
l - panama!lan, a canaA man, a p
l - panama!A man, a plan, a cana
A man, a pll - panama!an, a cana
\$\endgroup\$
-1
\$\begingroup\$

Quick! Tell me all the numbers from 1 to 100,000!

Your task is to write a program or function that, when run, output all the numbers from 1 to 100 thousand as quickly as possible to STDOUT. It's that simple. All answers are tested on an HP Compaq nx9420 with an Intel Core Duo @ 1.83 GHz and 3 gigs of RAM using the time command.


Of course, standard loopholes are strictly forbidden.
This is , so may the fastest code win and the best programmer prosper...

\$\endgroup\$
9
  • 3
    \$\begingroup\$ Have you tried running an example to see if the times are variable enough to be meaningful? As-is, this is going to be strongly dependent upon how fast the code can do I/O, which makes the challenge pretty uninteresting, IMO. \$\endgroup\$ Commented Jul 19, 2017 at 18:16
  • \$\begingroup\$ @AdmBorkBork Might be interesting \$\endgroup\$ Commented Jul 19, 2017 at 21:12
  • 1
    \$\begingroup\$ As far as I can tell, this takes less than a tenth of a second, which means submissions will probably be differentiated solely by noise on your computer. \$\endgroup\$ Commented Jul 20, 2017 at 2:37
  • \$\begingroup\$ upvoted, though I think the differenciation is really difficult, unless you test it on a raspberry PI (for example) having ONLY the program and its compiler installed. \$\endgroup\$ Commented Jul 20, 2017 at 13:36
  • \$\begingroup\$ @FryAmTheEggman How could I improve on that? \$\endgroup\$ Commented Jul 20, 2017 at 23:38
  • 1
    \$\begingroup\$ @V.Courtois I do have a Pi, and I think I will use that (it has Raspbian installed). \$\endgroup\$ Commented Jul 20, 2017 at 23:39
  • \$\begingroup\$ The time is still so small even a basic operating system will have to much noise in process creation, etc, for this to work out. You need to make what we are computing substantially more complicated for this to be reasonable. \$\endgroup\$ Commented Jul 21, 2017 at 0:10
  • \$\begingroup\$ @FryAmTheEggman K \$\endgroup\$ Commented Jul 21, 2017 at 1:20
  • \$\begingroup\$ @ckjbgames good then :) \$\endgroup\$ Commented Jul 21, 2017 at 5:26
-1
\$\begingroup\$

What's that character? (Part 1)

Recently I ran a command on my laptop that returned a bunch of characters - some printable, some non-printable. I'm having trouble figuring out what those characters are, so I could use some help. Unfortunately, I'm running low on disk space, so you'll have to write me the shortest program you can that I can run.

Challenge

Given a list of ASCII characters, return their names as written on www.asciitable.com, my go-to site for looking up character points.

Input

You may take a string, a list of characters, or a list of ASCII code points (e.g. 'a' -> 97).

You may optionally take the length of the string/list as well. Note that for C, you must take this parameter, since the string could contain NUL bytes, so strlen won't work here.

Output

Output is flexible as usual; you may print or return from a function as you see fit. You should output a list of strings.

The Table

0 NUL
1 SOH
2 STX
3 ETX
4 EOT
5 ENQ
6 ACK
7 BEL
8 BS
9 TAB
10 LF
11 VT
12 FF
13 CR
14 SO
15 SI
16 DLE
17 DC1
18 DC2
19 DC3
20 DC4
21 NAK
22 SYN
23 ETB
24 CAN
25 EM
26 SUB
27 ESC
28 FS
29 GS
30 RS
31 US
32 Space
33 !
34 "
35 #
36 $
37 %
38 &
39 '
40 (
41 )
42 *
43 +
44 ,
45 -
46 .
47 /
48 0
49 1
50 2
51 3
52 4
53 5
54 6
55 7
56 8
57 9
58 :
59 ;
60 
63 ?
64 @
65 A
66 B
67 C
68 D
69 E
70 F
71 G
72 H
73 I
74 J
75 K
76 L
77 M
78 N
79 O
80 P
81 Q
82 R
83 S
84 T
85 U
86 V
87 W
88 X
89 Y
90 Z
91 [
92 \
93 ]
94 ^
95 _
96 `
97 a
98 b
99 c
100 d
101 e
102 f
103 g
104 h
105 i
106 j
107 k
108 l
109 m
110 n
111 o
112 p
113 q
114 r
115 s
116 t
117 u
118 v
119 w
120 x
121 y
122 z
123 {
124 |
125 }
126 ~
127 DEL

Test Cases

[0, 97, 7, 22] -> [NUL, a, BEL, SYN]

More to come...

Meta

  • Would it be more interesting to use the UTF-8 names for the printable characters (0x20 - 0x7E), and the ASCII names for the control characters?
\$\endgroup\$
3
  • \$\begingroup\$ hand copy the table from the website please dont. Try a Google search: theasciicode.com.ar/ascii-codes.txt \$\endgroup\$ Commented Jul 23, 2017 at 22:39
  • \$\begingroup\$ Downvoter: I would much like your feedback rather than just your vote \$\endgroup\$ Commented Jul 24, 2017 at 1:39
  • 1
    \$\begingroup\$ IMO just have take a letter and output the code. Since that part is boilerplate str.chars.map( real program ). Also for ASCII char names NUL is it ok is we output them in lower case? e.g. nul (obviously ascii letters would have fixed case) \$\endgroup\$ Commented Jul 24, 2017 at 1:42
-1
\$\begingroup\$

Lennyface parser and selector

Your mission

Create, in the language of your choice, a program that outputs a randomly selected lennyface (artistic minifigures, see this) from an input - a string composed of numbers and lennyfaces. You will have to : first, parse this input; second, extract a probability mass function f from the parsed input; third, select and output a lennyface respecting f. Read the rules for more details.

Rules

  • Input : A string with lennyfaces and numbers (positive AND negative integers), separated by newlines. You may take input by STDIN or function parameter for example.
  • Output (STDOUT for example) : the randomly-selected lennyface, as a string.
  • The input creates a probability mass function f. If l is a lennyface, then f(l)=(sum of all numbers since the previous lennyface)/x where x is obtained afterwards by summing each of those numerators. @Sandbox : is it clear enough?
  • If (sum of all numbers since the previous lennyface) is equal to zero or negative, you must do as if the numerator is equal to 1 in f's definition.
  • A line with a number contains only this number ; same for a line with a lennyface. So you can assume there will never be a number in a lennyface.
  • If there is nothing on a line (two newlines in a row), you must consider it as a lennyface.
  • You must consider that the last line of the string is directly before its first line. See Test 1 for an example.
  • You can assume there will be at least 1 lennyface in the list; it cannot be composed just by numbers (don't forget that an empty line is a lennyface too).

Example

Given this input list :

( ͡° ͜ʖ ͡°)
2
¯\_ツ_/¯
34
-4
8
└[⸟‿⸟]┘

1

You must have 1/42 chances of outputting ( ͡° ͜ʖ ͡°), 2/42 chances of outputting ¯\_ツ_/¯, 38/42 chances of outputting └[⸟‿⸟]┘ and 1/42 chances of outputting nothing (line 7).

Test cases

Test 1

(⌐■_■)
3

Must output (⌐■_■) with 3/3 chances.

Test 2

ʢ◉ᴥ◉ʡ

Must output ʢ◉ᴥ◉ʡ with 1/1 chance.

Test 3

0
\(ᗝ)/

Must output \(ᗝ)/ with 1/1 chance.

Test 4

( ͡° ͜ʖ ͡°)
2
¯\_ツ_/¯
34
4
☞   ͜ʖ  ☞

0

Must output ( ͡° ͜ʖ ͡°) with 1/42 chance, ¯\_ツ_/¯ with 1/21 chance, ☞  ͜ʖ  ☞ with 19/21 chances and nothing with 1/42 chance.

Test 5

1



( ͡° ͜ʖ ͡°)

Must output ( ͡° ͜ʖ ͡°) with 1/4 chance and nothing with 3/4 chance, since there are 3 empty lines.

Test 6

42

-1
( ͡° ͜ʖ ͡°)

Must output nothing with 43/44 chance and ( ͡° ͜ʖ ͡°) with 1/44 chance.

@Sandbox : should I add test cases?

This is , so shortest code in bytes wins. Standard loopholes apply.

Note : Please do not be discouraged if the parsing is difficult to handle in your language, or if testing is hard because of randomness. Your solution might be very interesting algorithmically, not obviously in terms of golfing. Just please explain in your answer why it works.

Moreover, this is the first code-golf I create, so please let me know if something is not appropriate or if I should give more details on a point. And overall, if you downvote, explain me why so I can improve it.

\$\endgroup\$
14
  • \$\begingroup\$ Yours tests seems a bit contraditory. The number is the chance of the next face (line), so what's the point of the empty line in the example / test 4? By the same logic, the test1 should have a 3/4 of outputting nothing? What is the point of the 0 in the test 4? \$\endgroup\$ Commented Jul 3, 2017 at 14:03
  • \$\begingroup\$ Why is the chance of outputting ( ͡° ͜ʖ ͡°) 1/42 and not 0 ? (since there are no numbers above it) \$\endgroup\$ Commented Jul 3, 2017 at 14:04
  • \$\begingroup\$ Sorry ! I forgot to copy paste the fact that the minimal chance is 1! \$\endgroup\$ Commented Jul 3, 2017 at 14:05
  • \$\begingroup\$ Also, a common thing to do on challenges involving randomness, and therefore, hard to test, is to ask people to provide a mandatory explanation, or at least ask them to show why it works. \$\endgroup\$ Commented Jul 3, 2017 at 14:05
  • \$\begingroup\$ @Rod the empty line is a lennyface, as said here : If there is nothing on a line, you must consider it as a lennyface. \$\endgroup\$ Commented Jul 3, 2017 at 14:08
  • \$\begingroup\$ @V.Courtois I meant and empty line without a preceding number \$\endgroup\$ Commented Jul 3, 2017 at 14:09
  • \$\begingroup\$ As I said, the minimum is one (sorry again for forgetting it). \$\endgroup\$ Commented Jul 3, 2017 at 14:10
  • 1
    \$\begingroup\$ If only positive integers are to be expected, you should write it. Otherwise, give some details and examples about what you consider "numbers". \$\endgroup\$ Commented Jul 3, 2017 at 14:12
  • \$\begingroup\$ @Dada editing. In fact I said the minimum is 1, but you can have things like 2,-1,-3,17 and then your lennyface ; that means the probability is 15/ total. \$\endgroup\$ Commented Jul 3, 2017 at 14:14
  • \$\begingroup\$ @V.Courtois just a small suggestion, to make the "list as circle" more explicit you could change the value to something else than 0 or 1, this way it would not overlap the "missing number" rule \$\endgroup\$ Commented Jul 3, 2017 at 14:15
  • \$\begingroup\$ @Rod does it? Sorry if I'm not getting what you are saying, but the list is always a circle, meaning if your list is 2,3,( ͡° ͜ʖ ͡°),4,5,☞  ͜ʖ  ☞,6, you have 6+2+3 chance of getting ( ͡° ͜ʖ ͡°) and 4+5 chance of getting ☞  ͜ʖ  ☞. \$\endgroup\$ Commented Jul 3, 2017 at 14:18
  • 5
    \$\begingroup\$ KISS. This is far more complicated than common sense would require. Deliberately overcomplicating things to make it "more difficult" is a guaranteed method to make a bad question. \$\endgroup\$ Commented Jul 4, 2017 at 7:32
  • \$\begingroup\$ For real?! I thought it was some purpose of PPCG to make difficult things :l @PeterTaylor \$\endgroup\$ Commented Jul 4, 2017 at 8:13
  • 1
    \$\begingroup\$ The challenge has two parts as far as I can tell. a) Create a probability mass function from an input by parsing b) sample from the probability mass function. Part a) needs to be rewritten as it is at best ambiguous and at worst just incorrect. \$\endgroup\$ Commented Jul 5, 2017 at 7:50
-1
\$\begingroup\$

Golf Cubically code

Your task is to optimize Cubically source code using one or more optimizations in this post.

How this challenge works:

  • You will choose one or more optimizations below and write a program (in the language of your choice) that performs those optimizations on a Cubically program.
  • Your program will take a Cubically program as input using any allowed input methods, and output a Cubically program using any allowed output methods.
  • The first answer to successfully perform all optimizations wins!

Optimizations

1. Face turn arguments

Before a face turn is performed, the interpreter calculates turns = turns mod 4. So R5 would be equivalent to R1 which is equivalent to R, R7 is equivalent to R3 which is equivalent to R', etc. Also note that R11111 is equivalent to R5, and R22 is equivalent to nothing at all.

Performing this optimization will mean evaluating all arguments to an R, L, U, D, M, E, or S command and shortening them as much as possible.

Test cases:

Relevant code -> Optimization
R11           -> R2
R1            -> R
L33           -> L2
U22           ->
D222          -> D2
M11111        -> M
E00001        -> E
S9            -> S

2. Repeated face turn

When multiple calls to the same face turn command are present right next to each other, they can clearly be golfed. For example, R2R1 is equivalent to R3. UUU is equivalent to U3. F2F2F2F2 is equivalent F8.

Test cases:

Relevant code -> optimization
R2R2R2        -> R6            (R2 if you also choose optimization 1)
LLL           -> L3
UU            -> UU or U2
D3D2D1        -> D6            (D2 if you also choose optimization 1)

3. "Set notepad to" commands

There are some commands that, instead of adding to/subtracting from/multiplying by/dividing by the notepad, just assign to it. Here are all such commands:

_^=<>⊕«»·|:

When called with multiple arguments, since each argument calls the command separately, only the final argument is relevant. So =123 is equivalent to =3, _00000 is equivalent to _0, and :12345678987654321 is equivalent to 1.

Test cases:

Relevant code -> Optimization
_333          -> _3
=12321        -> =1
+54321        -> +54321
:55           -> :5
/55           -> /55

4. Repeated non-face-turn commands

When multiple face turn commands are present right by each other, their arguments can simply be added together. Commands do not act this way. While R2 calls R with 2, =2 calls = with the face sum of the front face (face index 2).

To perform this optimization, when multiple commands outside of RLUDFBMES appear next to each other, simply remove the duplicated commands without removing the arguments.

Relevant code -> Optimization
_1_1_1_1      -> _1111         (_1 if you also choose optimization 3)
%11%22%33     -> %112233       (%3 if you also choose optimization 3)
+12345+67+8   -> +12345678

5. Nonexistent commands

Go check out the Cubically commands page and you'll see that there are plenty of characters that are not commands. For example, there are no commands that are lowercase letters.

To perform this optimization, remove all nonexistent commands and their arguments from the Cubically source. If the commands also have arguments, you must remove the arguments so that they are not passed to the previous command.

Test cases:

Relevant code -> Optimization
moo cow moo   -> 
moo2cow2moo   -> 
misteR2 FOO   -> R2F
FEAR ME.      -> ERME
u1U2u3U4u5U6  -> U2U4U6   (nothing if you also choose optimization 1, U12 if you also choose optimization 2)

6. Non-implicit commands

There are lots of implicit commands in Cubically (RLUDFBMES()$~&E!), but there are plenty that need to be called with arguments. So %%%% is equivalent to nothing at all while %%2%% is equivalent to %2.

Test cases:

Relevant code -> Optimization
%%%%          -> 
$$$$          -> $$$$
++2++2++2     -> +2+2+2                 (+222 if you also choose optimization 4)
+++>--<-      -> Not Brainf**k, sorry!  (:P)

Sandbox

I'll add more optimizations later.

\$\endgroup\$
2
  • \$\begingroup\$ Clarification on R123: That's the same as R6 and R2, not R3, right? Digits are summed, there are multidigit numbers? That would be better to specify \$\endgroup\$ Commented Aug 17, 2017 at 20:13
  • \$\begingroup\$ A few things: first, I can't find the tag "fgitw", is there a typo? Second, does optimization 1 require handling F and B as well, or just the currently listed ones? Third, in optimization 3 most of the listed commands seem invalid because the notepad is used in calculation and then overwritten with the output; for example =11 is not the same as =1 in most circumstances. In fact, I think only _: are valid. Fourth, is the winning answer one which performs all optimizations in a single program, or one which contains a separate program for each optimization? \$\endgroup\$ Commented Aug 18, 2017 at 18:03
-1
\$\begingroup\$

Hungry for Apples?

enter image description here

This challenge is simple, given an integer 0 <= n or 0 < n, output an ASCII-apple with that many bites taken out of it.


No bites (0):

         //
     .-.:|.-.
   .'   ''   '.
   ;          ;
  :            :
  :            :
  :            :
   :          ;
   '.        :
     '-_.._-'

Bite 1:

         //
     .-.:|.-.
   .'   ''   '.
   ;          ;
   '-.         :
     }         :
   .-'         :
   :          ;
   '.        :
     '-_.._-'

Bite 2:

         //
     .-.:|.-.
   .'   ''   '.
   '-.        ;
     }         :
     }         :
     }         :
   .-'        ;
   '.        :
     '-_.._-'

Bite 3:

         //
     .-.:|.-.
   .'   ''   '.
   '-.        ;
     }      .-'
     }      {
     }      '-.
   .-'        ;
   '.        :
     '-_.._-'

Bite 4:

         //
     .-.:|.-.
   .'   ''   '.
   '-.      .-'
     }      {
     }      {
     }      {
   .-'      '.
   '.        :
     '-_.._-'

Bite 5:

         //
     .-.:|.-.
   .'   ''   '.
   '-.      .-'
     }".    {
     } }    {
     } }    {
   .-'"     '.
   '.        :
     '-_.._-'

Bite 6:

         //
     .-.:|.-.
   .'   ''   '.
   '-.      .-'
     }"~".  {
     } } }  {
     } } }  {
   .-'"~"   '.
   '.        :
     '-_.._-'

Bite 7:

         //
     .-.:|.-.
   .'   ''   '.
   '-.      .-'
     }"~"~".{
     } } } }{
     } } } }{
   .-'"~"~" '.
   '.        :
     '-_.._-'

Bite >7:

[empty output]

Rules

  • You may have trailing spaces, make it consistent though.
  • You may have exactly 1 trailing newline.
  • You are NOT doing an animation here, you are taking in n and outputting an apple.
  • You may error on integers less than 0, as the spec provides n > 0.
  • You must have empty output (no error) on n > 7/8.
    • You threw out the core; you didn't error the core into non-existence.

This is

\$\endgroup\$
3
  • 3
    \$\begingroup\$ I feel this would be better if there was some more symmetry in the 5, 6, and 7 bytes so that people could possibly make better compression. \$\endgroup\$ Commented Aug 4, 2017 at 18:26
  • \$\begingroup\$ @AdmBorkBork better? \$\endgroup\$ Commented Aug 22, 2017 at 21:26
  • 1
    \$\begingroup\$ Yes, much better. \$\endgroup\$ Commented Aug 23, 2017 at 12:33
-1
\$\begingroup\$

Proper Kerning

Kerning is the adjustment of spacing between pairs of letters in order to obtain an aesthetic result. When kerning is applied automatically by a program (typically whatever editor you're using), it is said to be automatic. There are two types of automatic kerning. The one used in this challenge is metric kerning. With metric kerning, the amount of space between pairs of letters is dictated by the kerning tables found in the font file.

Given a TrueType font file, output the kerning values for each mapping in the kerning table for ASCII characters 48 - 122 inclusive.

Example

calibri.ttf

l="A" r="C" v="-15"
l="A" r="G" v="-15"
l="A" r="J" v="23"
l="A" r="O" v="-23"
l="A" r="Q" v="-23"
l="A" r="T" v="-160"
l="A" r="U" v="-32"
l="A" r="V" v="-89"
l="A" r="W" v="-80"
l="A" r="Y" v="-150"
l="A" r="t" v="-52"
l="A" r="v" v="-38"
l="A" r="y" v="-41"
l="A" r="?" v="-68"
l="B" r="A" v="-20"
l="B" r="T" v="-48"
l="B" r="V" v="-25"
l="B" r="W" v="-24"
l="B" r="X" v="-44"
l="B" r="Y" v="-57"
l="B" r="Z" v="-20"
l="B" r="f" v="-20"
l="B" r="t" v="-20"
l="B" r="v" v="-20"
l="B" r="x" v="-15"
l="B" r="y" v="-20"
l="C" r="G" v="-18"
l="C" r="J" v="12"
l="C" r="O" v="-18"
l="C" r="Q" v="-18"
l="C" r="T" v="10"
l="D" r="A" v="-30"
l="D" r="J" v="-22"
l="D" r="T" v="-23"
l="D" r="V" v="-24"
l="D" r="W" v="-14"
l="D" r="X" v="-31"
l="D" r="Y" v="-39"
l="D" r="Z" v="-22"
l="E" r="A" v="-22"
l="E" r="C" v="-24"
l="E" r="G" v="-24"
l="E" r="O" v="-32"
l="E" r="Q" v="-32"
l="E" r="S" v="-20"
l="E" r="Z" v="-10"
l="E" r="a" v="-34"
l="E" r="c" v="-28"
l="E" r="d" v="-30"
l="E" r="e" v="-37"
l="E" r="f" v="-64"
l="E" r="o" v="-37"
l="E" r="q" v="-30"
l="E" r="t" v="-24"
l="E" r="v" v="-48"
l="E" r="w" v="-34"
l="E" r="y" v="-48"
l="F" r="A" v="-115"
l="F" r="C" v="-18"
l="F" r="G" v="-18"
l="F" r="J" v="-109"
l="F" r="O" v="-18"
l="F" r="Q" v="-18"
l="F" r="S" v="-29"
l="F" r="X" v="-22"
l="F" r="Z" v="-11"
l="F" r="a" v="-55"
l="F" r="c" v="-28"
l="F" r="d" v="-20"
l="F" r="e" v="-30"
l="F" r="o" v="-28"
l="F" r="q" v="-20"
l="F" r="s" v="-35"
l="G" r="T" v="-10"
l="G" r="V" v="-10"
l="G" r="W" v="-9"
l="G" r="Y" v="-30"
l="G" r="v" v="-29"
l="G" r="w" v="-22"
l="G" r="x" v="-14"
l="G" r="y" v="-30"
l="J" r="A" v="-35"
l="J" r="X" v="-20"
l="K" r="C" v="-78"
l="K" r="G" v="-80"
l="K" r="O" v="-97"
l="K" r="Q" v="-97"
l="K" r="S" v="-18"
l="K" r="U" v="-29"
l="K" r="W" v="-34"
l="K" r="a" v="-34"
l="K" r="c" v="-40"
l="K" r="d" v="-33"
l="K" r="e" v="-37"
l="K" r="f" v="-25"
l="K" r="m" v="-32"
l="K" r="n" v="-32"
l="K" r="o" v="-37"
l="K" r="p" v="-32"
l="K" r="q" v="-33"
l="K" r="r" v="-32"
l="K" r="s" v="-18"
l="K" r="t" v="-38"
l="K" r="u" v="-32"
l="K" r="v" v="-101"
l="K" r="w" v="-95"
l="K" r="y" v="-85"
l="L" r="C" v="-22"
l="L" r="G" v="-47"
l="L" r="J" v="25"
l="L" r="O" v="-45"
l="L" r="Q" v="-45"
l="L" r="T" v="-150"
l="L" r="U" v="-44"
l="L" r="V" v="-147"
l="L" r="W" v="-118"
l="L" r="Y" v="-167"
l="L" r="f" v="-23"
l="L" r="t" v="-38"
l="L" r="v" v="-78"
l="L" r="w" v="-72"
l="L" r="y" v="-79"
l="O" r="A" v="-23"
l="O" r="J" v="-27"
l="O" r="T" v="-55"
l="O" r="V" v="-25"
l="O" r="W" v="-22"
l="O" r="X" v="-64"
l="O" r="Y" v="-55"
l="O" r="Z" v="-38"
l="O" r="x" v="-12"
l="O" r="z" v="-10"
l="P" r="A" v="-151"
l="P" r="J" v="-140"
l="P" r="T" v="-9"
l="P" r="V" v="-10"
l="P" r="X" v="-35"
l="P" r="Y" v="-11"
l="P" r="Z" v="-29"
l="P" r="a" v="-44"
l="P" r="c" v="-43"
l="P" r="d" v="-34"
l="P" r="e" v="-41"
l="P" r="f" v="12"
l="P" r="o" v="-41"
l="P" r="q" v="-34"
l="P" r="s" v="-32"
l="P" r="t" v="12"
l="P" r="y" v="12"
l="Q" r="J" v="41"
l="Q" r="T" v="-47"
l="Q" r="V" v="-25"
l="Q" r="W" v="-12"
l="Q" r="X" v="12"
l="Q" r="Y" v="-46"
l="Q" r="g" v="59"
l="Q" r="j" v="79"
l="Q" r="x" v="31"
l="Q" r=";" v="60"
l="Q" r="]" v="32"
l="R" r="C" v="-18"
l="R" r="G" v="-19"
l="R" r="O" v="-20"
l="R" r="Q" v="-20"
l="R" r="S" v="-27"
l="R" r="T" v="-20"
l="R" r="V" v="-28"
l="R" r="W" v="-18"
l="R" r="Y" v="-30"
l="R" r="e" v="-36"
l="R" r="o" v="-42"
l="R" r="v" v="-26"
l="R" r="w" v="-33"
l="R" r="y" v="-33"
l="S" r="A" v="-15"
l="S" r="J" v="-9"
l="S" r="T" v="-14"
l="S" r="V" v="-14"
l="S" r="W" v="-15"
l="S" r="X" v="-13"
l="S" r="Y" v="-20"
l="S" r="v" v="-23"
l="S" r="w" v="-17"
l="S" r="y" v="-25"
l="T" r="A" v="-160"
l="T" r="C" v="-42"
l="T" r="G" v="-59"
l="T" r="J" v="-65"
l="T" r="O" v="-58"
l="T" r="Q" v="-58"
l="T" r="S" v="-10"
l="T" r="T" v="28"
l="T" r="a" v="-160"
l="T" r="c" v="-177"
l="T" r="d" v="-147"
l="T" r="e" v="-182"
l="T" r="g" v="-151"
l="T" r="m" v="-127"
l="T" r="n" v="-127"
l="T" r="o" v="-182"
l="T" r="p" v="-127"
l="T" r="q" v="-147"
l="T" r="r" v="-127"
l="T" r="s" v="-153"
l="T" r="u" v="-127"
l="T" r="v" v="-92"
l="T" r="w" v="-86"
l="T" r="x" v="-90"
l="T" r="y" v="-93"
l="T" r="z" v="-142"
l="T" r=";" v="-114"
l="T" r=":" v="-134"
l="U" r="A" v="-45"
l="U" r="J" v="-40"
l="V" r="A" v="-96"
l="V" r="C" v="-18"
l="V" r="G" v="-25"
l="V" r="J" v="-80"
l="V" r="O" v="-27"
l="V" r="Q" v="-27"
l="V" r="S" v="-12"
l="V" r="V" v="9"
l="V" r="a" v="-114"
l="V" r="c" v="-103"
l="V" r="d" v="-87"
l="V" r="e" v="-102"
l="V" r="g" v="-100"
l="V" r="m" v="-50"
l="V" r="n" v="-50"
l="V" r="o" v="-86"
l="V" r="p" v="-50"
l="V" r="q" v="-87"
l="V" r="r" v="-50"
l="V" r="s" v="-90"
l="V" r="u" v="-50"
l="V" r="y" v="-35"
l="V" r="z" v="-82"
l="V" r=";" v="-108"
l="V" r=":" v="-73"
l="W" r="A" v="-93"
l="W" r="C" v="-22"
l="W" r="G" v="-22"
l="W" r="J" v="-88"
l="W" r="O" v="-22"
l="W" r="Q" v="-22"
l="W" r="S" v="-10"
l="W" r="X" v="-13"
l="W" r="a" v="-71"
l="W" r="c" v="-78"
l="W" r="d" v="-72"
l="W" r="e" v="-75"
l="W" r="g" v="-54"
l="W" r="m" v="-60"
l="W" r="n" v="-60"
l="W" r="o" v="-86"
l="W" r="p" v="-60"
l="W" r="q" v="-72"
l="W" r="r" v="-60"
l="W" r="s" v="-73"
l="W" r="u" v="-60"
l="W" r="v" v="-34"
l="W" r="y" v="-53"
l="W" r=";" v="-156"
l="X" r="C" v="-57"
l="X" r="G" v="-65"
l="X" r="O" v="-57"
l="X" r="Q" v="-57"
l="X" r="S" v="-20"
l="X" r="d" v="-44"
l="X" r="e" v="-39"
l="X" r="g" v="-9"
l="X" r="o" v="-38"
l="X" r="q" v="-44"
l="X" r="t" v="-31"
l="X" r="u" v="-38"
l="X" r="v" v="-55"
l="X" r="w" v="-49"
l="X" r="y" v="-43"
l="Y" r="A" v="-152"
l="Y" r="C" v="-67"
l="Y" r="G" v="-67"
l="Y" r="J" v="-112"
l="Y" r="O" v="-66"
l="Y" r="Q" v="-66"
l="Y" r="S" v="-17"
l="Y" r="Z" v="-10"
l="Y" r="a" v="-134"
l="Y" r="c" v="-159"
l="Y" r="d" v="-131"
l="Y" r="e" v="-147"
l="Y" r="f" v="-62"
l="Y" r="g" v="-142"
l="Y" r="i" v="-32"
l="Y" r="j" v="-49"
l="Y" r="m" v="-94"
l="Y" r="n" v="-94"
l="Y" r="o" v="-153"
l="Y" r="p" v="-94"
l="Y" r="q" v="-131"
l="Y" r="r" v="-94"
l="Y" r="s" v="-115"
l="Y" r="t" v="-44"
l="Y" r="u" v="-94"
l="Y" r="v" v="-69"
l="Y" r="w" v="-62"
l="Y" r="x" v="-70"
l="Y" r="y" v="-65"
l="Y" r="z" v="-100"
l="Y" r=";" v="-138"
l="Y" r=":" v="-154"
l="Z" r="A" v="-11"
l="Z" r="C" v="-25"
l="Z" r="G" v="-24"
l="Z" r="O" v="-24"
l="Z" r="Q" v="-24"
l="Z" r="W" v="-7"
l="Z" r="Y" v="-7"
l="Z" r="a" v="-10"
l="Z" r="c" v="-12"
l="Z" r="d" v="-18"
l="Z" r="e" v="-31"
l="Z" r="o" v="-29"
l="Z" r="q" v="-18"
l="Z" r="v" v="-45"
l="Z" r="w" v="-38"
l="Z" r="y" v="-37"
l="a" r="f" v="-12"
l="a" r="t" v="-19"
l="a" r="v" v="-34"
l="a" r="w" v="-14"
l="a" r="x" v="-19"
l="a" r="y" v="-38"
l="b" r="f" v="-17"
l="b" r="s" v="-10"
l="b" r="t" v="-9"
l="b" r="v" v="-10"
l="b" r="w" v="-10"
l="b" r="x" v="-41"
l="b" r="y" v="-10"
l="b" r="z" v="-28"
l="c" r="a" v="-17"
l="c" r="o" v="-17"
l="e" r="f" v="-18"
l="e" r="t" v="-11"
l="e" r="v" v="-10"
l="e" r="w" v="-10"
l="e" r="x" v="-31"
l="e" r="y" v="-13"
l="e" r="z" v="-20"
l="f" r="a" v="-40"
l="f" r="c" v="-45"
l="f" r="d" v="-53"
l="f" r="e" v="-51"
l="f" r="f" v="-20"
l="f" r="g" v="-60"
l="f" r="o" v="-43"
l="f" r="q" v="-53"
l="f" r="s" v="-27"
l="f" r="v" v="13"
l="f" r="w" v="6"
l="f" r="y" v="10"
l="f" r="z" v="-20"
l="g" r="a" v="-38"
l="g" r="c" v="-12"
l="g" r="d" v="-19"
l="g" r="e" v="-17"
l="g" r="g" v="19"
l="g" r="o" v="-14"
l="g" r="q" v="-19"
l="g" r="t" v="-31"
l="h" r="f" v="-12"
l="h" r="t" v="-19"
l="h" r="v" v="-34"
l="h" r="w" v="-14"
l="h" r="x" v="-19"
l="h" r="y" v="-38"
l="k" r="a" v="-35"
l="k" r="c" v="-48"
l="k" r="d" v="-56"
l="k" r="e" v="-66"
l="k" r="o" v="-69"
l="k" r="q" v="-56"
l="k" r="s" v="-19"
l="k" r="t" v="-10"
l="k" r="u" v="-26"
l="m" r="f" v="-12"
l="m" r="t" v="-19"
l="m" r="v" v="-34"
l="m" r="w" v="-14"
l="m" r="x" v="-19"
l="m" r="y" v="-38"
l="n" r="f" v="-12"
l="n" r="t" v="-19"
l="n" r="v" v="-34"
l="n" r="w" v="-14"
l="n" r="x" v="-19"
l="n" r="y" v="-38"
l="o" r="v" v="-9"
l="o" r="w" v="-8"
l="o" r="x" v="-40"
l="o" r="y" v="-11"
l="o" r="z" v="-27"
l="p" r="f" v="-17"
l="p" r="s" v="-10"
l="p" r="t" v="-9"
l="p" r="v" v="-10"
l="p" r="w" v="-10"
l="p" r="x" v="-41"
l="p" r="y" v="-10"
l="p" r="z" v="-28"
l="q" r="g" v="10"
l="r" r="a" v="-42"
l="r" r="c" v="-30"
l="r" r="d" v="-28"
l="r" r="e" v="-27"
l="r" r="g" v="-28"
l="r" r="o" v="-33"
l="r" r="q" v="-28"
l="r" r="s" v="-35"
l="r" r="v" v="19"
l="r" r="w" v="11"
l="r" r="y" v="10"
l="s" r="f" v="-19"
l="s" r="t" v="-23"
l="s" r="v" v="-31"
l="s" r="w" v="-10"
l="s" r="x" v="-22"
l="s" r="y" v="-37"
l="s" r="z" v="-18"
l="t" r="a" v="-25"
l="t" r="c" v="-25"
l="t" r="d" v="-23"
l="t" r="e" v="-22"
l="t" r="o" v="-20"
l="t" r="q" v="-23"
l="t" r="t" v="-29"
l="v" r="a" v="-30"
l="v" r="c" v="-25"
l="v" r="d" v="-20"
l="v" r="e" v="-20"
l="v" r="f" v="11"
l="v" r="g" v="-28"
l="v" r="o" v="-19"
l="v" r="q" v="-20"
l="v" r="s" v="-9"
l="v" r="t" v="10"
l="v" r="v" v="12"
l="v" r="w" v="12"
l="v" r="y" v="12"
l="v" r="z" v="-26"
l="w" r="a" v="-23"
l="w" r="c" v="-20"
l="w" r="d" v="-18"
l="w" r="e" v="-18"
l="w" r="f" v="6"
l="w" r="g" v="-18"
l="w" r="o" v="-19"
l="w" r="q" v="-18"
l="w" r="s" v="-18"
l="w" r="t" v="4"
l="w" r="v" v="12"
l="w" r="w" v="8"
l="w" r="y" v="12"
l="w" r="z" v="-17"
l="x" r="a" v="-37"
l="x" r="c" v="-46"
l="x" r="d" v="-44"
l="x" r="e" v="-54"
l="x" r="o" v="-55"
l="x" r="q" v="-44"
l="x" r="s" v="-12"
l="x" r="t" v="6"
l="x" r="u" v="-20"
l="y" r="a" v="-31"
l="y" r="c" v="-26"
l="y" r="d" v="-24"
l="y" r="e" v="-25"
l="y" r="f" v="10"
l="y" r="g" v="-26"
l="y" r="o" v="-24"
l="y" r="q" v="-24"
l="y" r="s" v="-19"
l="y" r="t" v="10"
l="y" r="v" v="12"
l="y" r="w" v="8"
l="y" r="y" v="10"
l="y" r="z" v="-17"
l="z" r="a" v="-34"
l="z" r="c" v="-45"
l="z" r="d" v="-46"
l="z" r="e" v="-46"
l="z" r="f" v="-10"
l="z" r="g" v="-17"
l="z" r="o" v="-45"
l="z" r="q" v="-46"
l="z" r="s" v="-22"
l="z" r="u" v="-10"
l="z" r="v" v="-18"
l="z" r="w" v="-22"
l="z" r="y" v="-18"

Scoring

This is , so the shortest answer (in bytes) wins.

Meta

I know this challenge is going to need a lot of work before it's ready for main. Please hold criticisms for now. Helpful ideas and thoughts are welcome.

\$\endgroup\$
7
  • \$\begingroup\$ I'm not sure that the problem is well defined. There's a reason it's called font hinting: the rendering application is free to take it into account or not, or even to apply more complex logic. E.g. some fonts have multiple sets of font hints for different contexts. There are other complex issues. A font can have Latin and Cyrillic letters and define hints for kerning between pairs of Latin and pairs of Cyrillic but not between Latin and Cyrillic; however, some letters may have identical glyphs, so a judgement on whether the kerning is "correct" might be ambiguous. Then there's antialiasing. \$\endgroup\$ Commented May 24, 2017 at 6:15
  • \$\begingroup\$ @PeterTaylor Good notes. I will likely restrict the character set. I just wanted to start getting ideas down in the sandbox. \$\endgroup\$ Commented May 24, 2017 at 6:51
  • \$\begingroup\$ Very ambiguous. \$\endgroup\$ Commented May 25, 2017 at 17:48
  • \$\begingroup\$ @Mendeleev It's not done yet. I'm aware it's ambiguous. \$\endgroup\$ Commented May 26, 2017 at 16:10
  • \$\begingroup\$ Looking at developer.apple.com/fonts/TrueType-Reference-Manual/RM06/… I can see a number of issues to address. 16- vs 32-bit entries? Should multiple tables be combined or printed separately? All tables or only tables with certain coverage values? Which of the four defined formats need to be supported? Do you have a test case which covers glyph index differing from codepoint? \$\endgroup\$ Commented Sep 16, 2017 at 17:28
  • \$\begingroup\$ @PeterTaylor I have a proof of concept that I wrote (it's the reason I have taken so long to update this) and I'm planning to address all of your questions. Thanks for doing a bit of research to help me out, though :] \$\endgroup\$ Commented Sep 16, 2017 at 18:57
  • \$\begingroup\$ Downvoter, why? \$\endgroup\$ Commented Oct 4, 2017 at 21:03
-1
\$\begingroup\$

Six Flags over HTTP

Let's say you need to transmit six boolean flags in a URL string. Obviously you could do it with six ones or zeroes, but you want better compression. With a little math you can pack them into two characters using 0-7 octal.

How about mapping all six to a single ASCII character? Here we have a problem: you are not allowed to use , / ? : @ & = + $ # or space. Now the range of printable ASCII no longer has 64 valid characters in a row.

In Javascript (or another language that can run from a web page, if any), what is the shortest code for a pair of functions to encode and decode this data, between an array of six booleans and a single character?

\$\endgroup\$
2
  • \$\begingroup\$ -1 language restriction, most languages have HTTP libraries so I think any language should be allowed \$\endgroup\$ Commented Sep 24, 2017 at 13:11
  • \$\begingroup\$ This challenge could be improved by rephrasing it to: "Write a bijective function between an array of six booleans and a single printable character excluding the characters ,/?:@&=+$# ". Mentioning that the encoder and decoder should be separate programs/functions would be helpful. Also, may the encoder and decoder share code? \$\endgroup\$ Commented Sep 24, 2017 at 22:08
-1
\$\begingroup\$

Is it a perfect loop?

Your task is to take a GIF or an animated image in any reasonable format as input (including taking the file name of a GIF in the current directory), and output whether it is a "perfect loop" - that is, the frames transition seamlessly from the end to the start, and a human cannot notice where it starts and ends at first glance. Return or print a truthy value if it is a perfect loop, otherwise print or return a falsy value.

Scoring

Winners will be determined from the percentage of test cases they get correct. In the event of a tie, highest votes wins. You can view test cases at https://ghostbin.com/paste/m3yaw. Show your score against the test cases when you post.

Input

If you are not taking input in a GIF, please provide a program that will convert a GIF to your desired format.

Images corresponding to a truthy value have been taken from /r/perfectloops and for falsy test cases, /r/almostperfectloops and /r/gifs.

Restrictions

  • Hard coding is not allowed (violates standard loophole 1 and 2).
  • You must provide consistent results for the same GIF (no randomness)
  • Remember, this is not , so byte count is not needed in your solution. Just post the language name and add the percentage correct when I comment.
\$\endgroup\$
2
  • \$\begingroup\$ I'm not sure it's as simple as comparing the first to the last frame, if it is we'd have duplicate frames. is this challenge allowing HTTP requests? \$\endgroup\$ Commented Oct 17, 2017 at 21:15
  • \$\begingroup\$ If hashing the inputs is not allowed, then you should clearly define what constitutes a “perfect loop”. It's not good to extrapolate from a handful of test cases where the pass/fail cases are very similar. \$\endgroup\$ Commented Oct 18, 2017 at 14:31
-1
\$\begingroup\$

Highest code size∕output ratio to generate a large executable section inside an elf file.

Your challenge is to create the shortest code in your language of choice or the tools of your choice (like objcopy) that will create an elf file with a the executable section as large as possible.
I mean that if I extract the.text section of the elf binary, the resulting extracted file should be at least 90% of the elf binary.

Requirements

  • The program should takes the desired section size as input.
  • The .text section name needs to corresponds to the executable section.
  • The type of the .text section should bePROGBITSand it should contains instructions.
  • The elf file should have a .shstrtab section.
  • The .text section should be readable and writable.
  • The target architecture should be Pnacl or armelv7 or x86_64.
  • The elf file should be valid and pass Google nacl’s validation whitelist in order to be loaded (but I don´t care if the sandbox segfault).
    If you have no idea about what Google native client is, just create a script that call the patched version of binutils from the nacl_sdk, or make sure the elf file is valid and can be executed on Linux.

Of course, you normally can’t use a compiler because it would takes too much computational years in order to finish.

Winner

The answer with the highest code size∕program output ratio.

\$\endgroup\$
9
  • 1
    \$\begingroup\$ Why not make scoring output size / code size? \$\endgroup\$ Commented Apr 4, 2017 at 3:49
  • \$\begingroup\$ Make it a code-challenge \$\endgroup\$ Commented Apr 4, 2017 at 3:49
  • \$\begingroup\$ This is essentially the same challenge as this one, and would be closed as a duplicate. Although it's not exactly the same, some answers to the previous question would require very little modification and answers to this question would also require very little modification to be answers to the other one. \$\endgroup\$ Commented Apr 4, 2017 at 8:37
  • \$\begingroup\$ @Alt-F4 : it was a code challenge. \$\endgroup\$ Commented Apr 4, 2017 at 21:52
  • \$\begingroup\$ @PeterTaylor : they were no answer to the previous question. In order to be closed as a duplicate the target needs to be already answered. You known it was closed an unclear, so please suggest change to make this answer clearer. \$\endgroup\$ Commented Apr 4, 2017 at 21:54
  • \$\begingroup\$ Huh? It's open and has 15 answers. \$\endgroup\$ Commented Apr 4, 2017 at 22:09
  • \$\begingroup\$ @PeterTaylor sorry, I thought to an another question that was closed as unclear and didn’t take time to read your link. In that case NO, the aim is to not use the compiler in order to actually build the file. This normally can’t be done with a compiler or an assembler. \$\endgroup\$ Commented Apr 4, 2017 at 22:16
  • \$\begingroup\$ Can't it? Why not? \$\endgroup\$ Commented Dec 16, 2017 at 19:55
  • \$\begingroup\$ Wait... shortest code that generate any program? Or what? Don't think this is a good idea... \$\endgroup\$ Commented Jan 6, 2018 at 12:10
-1
\$\begingroup\$

Removing a Letter adds a Letter

Your program should output nothing when unaltered, however, when any single character is removed it should have an output length of 1. This extends to any number of characters being removed from the program, as long as there is, at minimum, a single character remaining.


For example, if my program were abcdefg, it should output nothing if unaltered.

However, if I were to remove a and d from this program to get bcefg, it should output any two printable characters that represent 16 bytes of information (2 characters for 2 characters removed).

  • So if bcefg outputs (00,AA,etc...) this is valid.

Taking this further, if we were to remove all but the letter g we'd need an output of 6 characters.

  • So if g outputs ('000000','@$^%@(',etc...) this is valid.

Your program must function for all possible combinations of removals that are possible, that is to say each single letter in your program should be a valid program.


Rules

  • You may "lock" pieces of the code, each locked byte counts for 2-bytes instead of 1-byte.
    • Locked bytes will never be removed.
    • For instance, if my program was abcdefg and bcd is locked, the shortest program we'll get is abcd,bcde,bcdf and bcdg.
    • If bcd was locked in abcdefg it'd be 10 bytes, not 7.
  • The program may output any byte to represent 1 removed character, N-bytes for N removed chars in the code itself.
\$\endgroup\$
4
  • \$\begingroup\$ The rule only leads to totally locked code \$\endgroup\$ Commented Mar 13, 2018 at 0:13
  • \$\begingroup\$ @l4m2 hah. I disagree. \$\endgroup\$ Commented Mar 13, 2018 at 0:58
  • \$\begingroup\$ But more constructively, increase the penalty? Limit locked chars? \$\endgroup\$ Commented Mar 13, 2018 at 1:04
  • \$\begingroup\$ Maybe require an unlocked percent? \$\endgroup\$ Commented Apr 6, 2018 at 10:52
-1
\$\begingroup\$

Non-true, non-false JS boolean

Array prototype isn't redefined, input hasn't getters

function magic(input){
  let result = [];
  if(input.boolean != true){result.push("non-true");}
  if(input.boolean != false){result.push("non-false");}
  result.push(input);
  return result.join("\n");
}

returns

non-true
non-false
{"boolean": true}

What is passed to magic function?

Based on real problem :) I spent 30 minutes on this puzzle

\$\endgroup\$
19
  • 5
    \$\begingroup\$ This site is for programming contests, not pure programming puzzles. Thanks for using the sandbox, anyway. \$\endgroup\$ Commented Feb 1, 2018 at 12:11
  • 7
    \$\begingroup\$ Contrary to what user202729 states, Programming Puzzles are on-topic on this site. This challenge could use a little cleanup to make it a better fit here (for example, what language is this?), but this challenge is indeed allowed here. \$\endgroup\$ Commented Feb 1, 2018 at 14:02
  • \$\begingroup\$ ... someone said that I'm wrong. Anyway people definitely doesn't like this. \$\endgroup\$ Commented Feb 1, 2018 at 14:02
  • \$\begingroup\$ @AdmBorkBork this is JS \$\endgroup\$ Commented Feb 1, 2018 at 14:41
  • 3
    \$\begingroup\$ @ЕвгенийНовиков what JS version is this? in is a keyword, and can't be a variable name. \$\endgroup\$ Commented Feb 1, 2018 at 14:47
  • \$\begingroup\$ @dzaima Good point. Last time I check on TIO the object {boolean: true} doesn't have " around and it caused a syntax error. I forgot about in so just try to rename it and it worked... \$\endgroup\$ Commented Feb 1, 2018 at 14:51
  • \$\begingroup\$ "Programming Puzzle" is in the name of the site @user202729 \$\endgroup\$ Commented Feb 1, 2018 at 15:46
  • \$\begingroup\$ @dylnan But... \$\endgroup\$ Commented Feb 1, 2018 at 15:55
  • \$\begingroup\$ @AdmBorkBork is correct. We do allow programming puzzles. \$\endgroup\$ Commented Feb 1, 2018 at 16:25
  • \$\begingroup\$ @NathanMerrill Then just upvote the comment. \$\endgroup\$ Commented Feb 2, 2018 at 5:34
  • \$\begingroup\$ Many many things in the past, including but not limited to, code-trolling, underhanded, non-observable behavior, etc. are off-topic or heavily-discouraged nowadays. Be careful. \$\endgroup\$ Commented Feb 2, 2018 at 5:34
  • \$\begingroup\$ @user202729 I did upvote. I just wanted to make sure it was extra clear to the OP. Furthermore, this challenge doesn't fit any of those tags, because its not asking for trolling/underhanded/non-observable code. You could argue that the code in the challenge fits those tags, but that's not what we care about. \$\endgroup\$ Commented Feb 2, 2018 at 5:51
  • 2
    \$\begingroup\$ I don't believe that console is part of any JS spec. This presumably only works in certain contexts, and the question should specify what they are. Otherwise the task devolves into code-trolling by defining a suitable console. It's already borderline IMO. \$\endgroup\$ Commented Feb 2, 2018 at 12:04
  • \$\begingroup\$ @dzaima sorry, fixed this. Now input variable is input \$\endgroup\$ Commented Feb 3, 2018 at 7:40
  • 1
    \$\begingroup\$ OK, so, in that case you may want to work on the wording of the challenge before posting it to Main because, right now, it reads as though you've come across this challenge elsewhere, spent half an hour trying to solve and are now looking for help doing so. Also, just so you know, restricted language challenges rarely go down well here. \$\endgroup\$ Commented Feb 3, 2018 at 19:20
-1
\$\begingroup\$

Sandbox:

Is this question already available (duplicate)?

Are things too vague?

Does providing the example help or hinder?

Tidy the Pantry (easy)

I hate grocery shopping, particularly the part where I put groceries away--so I'm calling upon the collective hive-mind to handle that.

Challenge

Your challenge is to take a 1D-list of groceries and a 2D pantry as input; and output an newly assorted pantry. The two variables can be of your type choice, and in any order, but please specify what item types your program requires (e.g. string, array, etc.).

Rules & Additional info.

Scoring

  • This is code golf, so the shortest answer in bytes wins

Rules

  • The pantry should be ordered alphabetically (A - Z, left to right, top to bottom)
    • For simplicity, the pantry is case-insensitive
  • The pantry must retain its horizontal size (but trailing newlines are optional)
  • "Pockets" (empty spaces) should be filled between items (i.e. only the last item is allowed to have a trailing pocket)
  • If the pantry is too small for the incoming groceries, then the pantry must replace older items (Z being the oldest, A the youngest)
    • Z from groceries is younger than A in pantry
  • Standard loopholes are forbidden

Examples ([ and ] are used for readability)

Input (4x4 pantry):

[A][A][ ][ ]
[ ][ ][B][ ]
[C][ ][ ][ ]
[ ][ ][ ][D]

AAD

Output:

[A][A][A][A]
[B][C][D][D]
[ ][ ][ ][ ]
[ ][ ][ ][ ]

Input (2x2 pantry):

[A][B]
[C][D]

XYZ

Output:

[A][X]
[Y][Z]

Example solution

JavaScript ES6 (989 bytes)

// (String, String) -> String
let organise = (pantry, groceries) => {
  let n = pantry.split("\n").sort((a, b) => b.length - a.length); // used at the end of the function for horizontal sizing
  n = n[0].length;

  pantry = pantry
    .replace(/\W/g, "") // get rid of all non-alphanumeric characters
    .split("");         // turn the string into an array

  // we need the properties of the new array
  // so the extra `pantry = pantry` is needed
  pantry = pantry
    .slice(0, pantry.length - groceries.length) // go ahead and remove the last overlapping elements
    .concat(groceries)                          // add the groceries to the pantry
    .join("")                                   // turn into a string
    .split("")                                  // turn into an array
    .sort()                                     // sort the array
    .join("");                                  // turn into a string

    return pantry.replace(RegExp(`(.{${n}})`, 'g'), "$1\n");
};

/** Testing below **/

console.log("Test #2:\n" + organise(
`AJCHDJE
JJ   JA
    ASD
OOQ I U
Q     W
      R`,

'AHJBCJHDHHATTGEH'
))


Test Cases:

Test #1, 4x4 pantry

TVCX <- pantry
ABCD
ATDJ
UAIK

XYXY <- groceries
----
AAAB <- expected output
CCDD
IJKT
XYXY

Test #2, 7x6 pantry

AJCHDJE
JJ   JA
    ASD
OOQ I U
Q     W
      R

AHJBCJHDHHATTGEH
-------
AAAAABC
CDDDEGH
HHHHJJT
T

Test #3, 10x10 pantry

AAAAAAAAAA
AAAAAAAAAA
AAAAAAAAAA
AAAAAAAAAA
AAAAAAAAAA
AAAAAAAAAA
AAAAAAAAAA
AAAAAAAAAA
AAAAAAAAAA
AAAAAAAAAA

ZZZZZZZZZZZZZZZZZZZZ
----------
AAAAAAAAAA
AAAAAAAAAA
AAAAAAAAAA
AAAAAAAAAA
AAAAAAAAAA
AAAAAAAAAA
AAAAAAAAAA
AAAAAAAAAA
ZZZZZZZZZZ
ZZZZZZZZZZ

Test #4, 16x16 pantry pantry

ASDFGHJKLZXCVBNM
QJKAJ  KAKSJD  J
KJASDKFHI YOIER
W   OSDOFJ    DK
E PPPASP     AS
R
TASD 
YAAAAAAAAAAAA
U          JHOLK
IIAUSHODUYOAISUO
OASD  AUSODI 
PIASND JUASJNOIJ
A ASJDH PPOIO 
QHIAIUSOIUOOO
WYYAIUSNNAJSDASD
EAISDUUIOPJPIJPJ
ROQPEWIHRNXCAISD

QWERTYUIOP
----------------
AAAAAAAAAAAAAAAA
AAAAAAAAAAAAAAAA
ABCCDDDDDDDDDDDD
DDDEEEEEFFFGHHHH
HHHIIIIIIIIIIIII
IIIIIIJJJJJJJJJJ
JJJJJJKKKKKKKKLL
MNNNNNNOOOOOOOOO
OOOOOOOOOOPPPPPP
PPPPPPQQQQRRRRRS
SSSSSSSSSSSSSSSS
SSSTTUUUUUUUUUUU
UVWWY

Test #5, 2x2 pantry

HE
LO

[no groceries]
--
HE
LO
\$\endgroup\$
6
  • 1
    \$\begingroup\$ why divide the program score? \$\endgroup\$ Commented Feb 26, 2018 at 19:03
  • 1
    \$\begingroup\$ I recommend you do count by bytes otherwise someone is just going to encode their entire program in Chinese characters and win. \$\endgroup\$ Commented Feb 26, 2018 at 19:09
  • \$\begingroup\$ @labela--gotoa To get a golfed score (smaller programs get a smaller score), should I change it? \$\endgroup\$ Commented Feb 26, 2018 at 19:13
  • \$\begingroup\$ @EphellonDantzler I don't understand why not just normal scoring...? \$\endgroup\$ Commented Feb 26, 2018 at 19:14
  • \$\begingroup\$ LOL, that's why I set in in Sandbox first @labela--gotoa \$\endgroup\$ Commented Feb 26, 2018 at 19:16
  • 1
    \$\begingroup\$ Some notes on your reference implementation: 1 It appears far too soon in the challenge. 2 It's not 1768 bytes. 3 You need to ungolf it and make it readable or it's not much use. 4 As it's JS, create a Snippet for it. 5 Is it necessary? It seems to be thrown in there to try to patch over any holes in the challenge spec. \$\endgroup\$ Commented Feb 26, 2018 at 23:17
1
150 151
152
153 154
167

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.