571
\$\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\$
1
  • \$\begingroup\$ What if I posted on the sandbox a long time ago and get no response? \$\endgroup\$
    – None1
    May 15 at 14:05

4686 Answers 4686

1
140 141
142
143 144
157
0
\$\begingroup\$

Contract a tensor

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

Find the odd one out

\$\endgroup\$
3
  • \$\begingroup\$ I don't think this is a duplicate, but I hope you realize this is extremely easy, Vyxal and a few other golfing languages have 1-byte solutions for this \$\endgroup\$
    – noodle man
    Feb 27 at 3:02
  • \$\begingroup\$ I don’t think that’s a good reason to add arbitrary tasks to your still simple challenge \$\endgroup\$
    – noodle man
    Feb 27 at 16:59
  • \$\begingroup\$ If you create a new challenge you should create a new sandbox post, not edit an old one \$\endgroup\$ Feb 28 at 8:04
0
\$\begingroup\$

Define a set containing N elements

Consider a simple language that allows making basic statements about sets. It is defines as follows:

  • = 0 1 Sets 0 and 1 are equal. Variables are referenced using De Bruijn Indexes
  • < 0 1 Set 0 is an element of set 1
  • & a b Expression A and expression B
  • ! a Not A
  • A a b B holds for all elements of A. Defines a new variable

We use polish notation here, a simpler format that avoids much parsing.

Challenge

Given a number N. give an expression in this language that will return true if the first variable is a set that contains exactly N elements. The formula does not need to be optimal.

Examples

  • 0: A 0 ! = 0 0 (All elements must not be equal to themselves)
  • 1: & ! A ! = 0 0 A 0 A 1 = 0 1 (Not all elements are not equal to themselves, and all elements must equal all other elements)
  • 2 & ! A ! = 0 0 & ! A 0 A 1 = 0 1 & A 0 A 1 A 2 ! & ! & ! = 0 1 ! = 1 2 ! = 0 2 (For each set of 3 elements, at least 2 must be equal)

There are many different ways to encode a given number, you may pick any of them arbitrarily.

Goal is to make the generating code as short as possible.

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

Soundex

Note: This question was asked previously but it was not very well specified. I'd like to ask it again with a proper spec

Given a string containing only ASCII lowercase letters, output its Soundex code. Soundex is an algorithm originally described by Donald Knuth to give words that sound similar the same index, as a form of fuzzy searching.

We'll use a slightly modified version that removes the padding step. It works as follows:

  • Remove all instances of h, w, or y except the first letter
  • Replace all remaining consonants, except the first letter, based on the following table:
Consonant Code
b, f, p, v 1
c, g, j, k, q, s, x, z 2
d, t 3
l 4
m, n 5
r 6
  • Remove any successive instances of the same number. Also remove any numbers after the first that would have the same number as the first letter
  • Finally, remove all the vowels, except the first letter

Worked out example

  • Lets take the string "squeezers"
  • First, we remove all h, w, or ys. There aren't any.
  • Then, we replace all consonants except the first with numbers. This creates s2uee2e62
  • Now we remove all successive duplicates. We remove the first 2 since s would map to 2. This creates suee2e62
  • Finally, we remove vowels to create s262

Test Cases

Word Soundex
squeezers s262
batman b355
robert r163
roberto r163
clarinet c4653
amazing a5252
whole w4
hole h4
asbestos a21232
yankee y52
\$\endgroup\$
0
\$\begingroup\$
\$\endgroup\$
1
  • \$\begingroup\$ Cyclic maximal words are also known as Lyndon words (the usual definition is for minimal words, but that doesn't really matter) \$\endgroup\$ Mar 19 at 18:45
0
\$\begingroup\$

Find the missing side in a right triangle

You've solved for the legs when you have the hypotenuse. You've solved for the hypotenuse when you have the legs. But can you code golf a program to do both?

Input: three lines from stdin, for leg a, leg b, and hypotenuse. One line will be blank, which is the variable your program must solve for. All input will be integers.

Output: The missing side, as a float with at least 3 digits after the decimal. Leading and trailing whitespace is OK.

Scoring: Least bytes wins!

\$\endgroup\$
1
  • 2
    \$\begingroup\$ I suggest not being so strict with input and output. We typically allow function input in addition to stdin, as well as fractions in addition to floats. \$\endgroup\$
    – chunes
    Mar 20 at 22:57
0
\$\begingroup\$

Given a non-negative integer,

  1. Write the integer into base64, and store into bytes
  2. Set each bit 7 to 1 but the last byte.
  3. Set each bit 6 to 1 but the first byte.

In this way an integer has clear edges. Notice that 0x80 is unused.

Questions:

  1. Given an input, encode it.
  2. Given some bytes, decide whether it's complete, incomplete or invalid.
  3. Given some bytes, assuming not invalid, decode all numbers inside.

Test cases

         0 => 00
        63 => 3F
        64 => 81 40
       132 => 82 44
      4096 => 81 C0 40

Sandbox Notes

  • Is such encoding named?
\$\endgroup\$
0
\$\begingroup\$

Choose a language or its subset, write a program in it that, compute some function bool f(Program P, Int T) such that:

  • If f(P,T), then f(P, T+1)
  • lim[T->∞] f(P,T)=true iff P halts

Notes:

  • This is a component for a bounded busy beaver solver, by storing the program with largest running time. This task actually asks for a definition of running time.
\$\endgroup\$
1
  • \$\begingroup\$ This is fairly similar to Compute the Uncomputable. Also, does the program have to be in the same language or just in any turing complete language? \$\endgroup\$ Mar 23 at 13:06
0
\$\begingroup\$

Input part of staff, output its midi.

Symbols:

  • 0-9: octave symbol. Set O = the value.
  • CDEFGAB: a note.
    • If octave is just set, then use the octave.
    • Otherwise, if the distance to last note is larger than 5 (C-A, D-B or C-B),
      • Increase O by 1 if the new note is C or D; decrease if A or B.
    • Output O*12+{C:0, D:2, E:4, F:5, G:7, A:9, B:11}+K[O,c]
  • #, b, ##, bb, %: accidentals. Set K[next note] to 1, -1, 2, -2, 0, respectively.
  • |: bar line. Reset accidentals. (Since beats are not given, bar line doesn't have other meaning.)
  • You can assume all outputs are in [0,127], accidentals appear before octave if both exist, no double octave, octave or accidental to bar line, first note has octave provided

Test cases:

4CCGG|AAG => 48,48,53,53,55,55,53
4CDEFGAB|C4G5C => 48,50,52,53,55,57,59,60,55,60
5E#DEDE4B%DCA => 64,63,64,63,64,59,62,60,57
4C#CFAC => 48,49,53,57,60
#0D#E||##F#G#A#B||##C#D => 3,5,7,8,10,12,14,15
0EDCB => (invalid)
A#|B => (invalid)
10C => (invalid)
#9B => 120
9BCDEFG => 119,120,122,124,125,127
9BCDEFGA => (invalid)

  • Should I have key signatures?
  • Should I shift octave by 1?
  • s and f or # and b?
  • are triple accidentals allowed?
\$\endgroup\$
3
  • \$\begingroup\$ I would keep it simple: note to midi rather than staff to midi to avoid confusing nonmusicians, so no key signatures and no multiple flats/sharps. #`` and b` are used almost universally. That leaves the choice of natural symbol, I would probably go for something nonalphanumeric like ~ or & . I suppose you could keep the bar to reset accidentals to avoid making it too simple. \$\endgroup\$ Mar 24 at 15:09
  • \$\begingroup\$ The octave change needs some thinking about. I would suggest sticking with the standard octave CDEFGAB, although this means octave change when you move between nearby B and C. I appreciate what you're trying to do with your "larger than 5" system but the interval (at least if expressed in letters) needs to be smaller. C to F could be a default up change, and C to G a default down change. C to G is known as a fifth in 1-indexed musical notation, though it's actually only a change of 4 letters in 0- indexed. \$\endgroup\$ Mar 24 at 15:13
  • \$\begingroup\$ @LevelRiverSt I'm recently on Braille Music, where 4th and 5th by default remain in same octave. Lilypond just use the nearest one, though \$\endgroup\$
    – l4m2
    Mar 25 at 2:54
0
\$\begingroup\$

Is the triangle decided?

Given some angles and edges of a triangle, decide if it's decided, impossible or multi possibility.

Input:

3 angles and 3 edges. Choose a non-positive value, maybe 0 or non-number, as input to mean not provided. Order is flexible, like [a,b,c,A,B,C], [A,b,C,a,B,c], etc.

Output:

3 values, representing decided, impossible or multi possibility.


  • Allow different placeholder for angle and edge?
  • Due to imperfect float, extra condition(AAAS) would likely make it wrongly claim impossible. Suggestion?
\$\endgroup\$
2
  • \$\begingroup\$ I assume that decided means that all the angles and sides are consistent with another, and actually form a Euclidean triangle. Impossible would be the opposite of this. Multi possibility only makes sense if the input is incomplete, i.e. not enough information (angles and edges) to finalise an entire triangle with all sides and angles known. Is that correct? Could you please elaborate what your definition of those three categories are? Also, you have stated that the input is 3 angles and 3 edges. Can it actually be 0-3 angles and 0-3 edges? \$\endgroup\$ Apr 1 at 7:39
  • 1
    \$\begingroup\$ @DanielOnMSE Angles and edges may be missing, which I said maybe (take) 0 or non-number \$\endgroup\$
    – l4m2
    Apr 1 at 8:11
0
\$\begingroup\$

Number houses in a street

House numbering varies across the world, and sometimes within a country, but the traditional numbering system in my country is to have the odd numbers ascending on one side of the street and the even numbers ascending in the same direction on the other side of the street. Here is an example:

9 |
  | 10
  | 8
7 |
5 |
  | 6
  | 4
3 |
1 |
  | 2

Here there are two detached houses, one at each end of the street, and four pairs of semi-detached houses. The empty spaces are probably where the garages and driveways are, but they are not relevant here, so I have left them out.

Your challenge is to write a program or function that will take an unnumbered street and number it.

You can input the houses in any convenient way, so you could take input as a diagram but with the houses marked by a fixed placeholder (e.g. ?), or you could take a pair of lists of distances of each house from the start of the street (so for the above example the input could be [[1, 2, 5, 6, 9], [0, 3, 4, 7, 8]].) Note that there may be two houses directly opposite each other, and there may also be different number of houses on each side of the street.

As well as numbering from the bottom left up, you may also number from the top right down, like this:

 2 |
   | 1
   | 3
 4 |
 6 |
   | 5
   | 7
 8 |
10 |
   | 9

The house numbers on the left of the street must be right-justified and those on the right of the string must be left-justified. The street can be marked with any fixed non-empty non-numeric string of your choice; it doesn't have to be | .

In addition to the above two output formats, I will also allow any rotations (but not transpositions) of the above output formats, in case that is helpful for you, e.g.

 0
 18  64  2
==========
9  75  31
\$\endgroup\$
0
\$\begingroup\$

Input:

a byte array of length 1 to 31, inclusive.

Take an example, oxDE, 0xAD

Objective:

Write each byte into 8-bit binary, big-endian 1101111010101101

Average split into 8 parts 11 01 11 10 10 10 11 01

Convert each part from binary to number [3,1,3,2,2,2,3,1]


  • Which endian, or allow both?
\$\endgroup\$
5
  • \$\begingroup\$ @greybeard Title not decided. Average mean with total=m, each given m/8. I say number cuz lots of language at the moment is just number, you need to printf %d to convert it to decimal, or %x hex \$\endgroup\$
    – l4m2
    Apr 1 at 0:31
  • 1
    \$\begingroup\$ Average split -> Evenly split \$\endgroup\$
    – Bubbler
    Apr 1 at 4:33
  • \$\begingroup\$ I don’t understand the question Which endian […]? Endianness is only relevant if multiple bytes together represent one number. In this challenge we have up 31 independent bytes/numbers so endianness is not an issue. \$\endgroup\$ Apr 2 at 10:12
  • \$\begingroup\$ @KaiBurghardt That reverse the array, it seems reasonable to allow both \$\endgroup\$
    – l4m2
    Apr 2 at 10:16
  • \$\begingroup\$ I see. Well, it does not seem “reasonable” to me. Could you explain? I say, KISS – keep it simple. An array element with a lower index comes first, there is no ambiguity in that. \$\endgroup\$ Apr 2 at 10:50
0
\$\begingroup\$

Vending Machine Simulator

Alternate title: Linear Logic Simulator

Objective

Write an interactive program that asks you to design a vending machine, and then simulate the vending machine.

The fuss is, the vending machine is designed for simulation of linear logic.

Design

The vending machine has some items available for purchasing, identified by words consisting of ASCII capital Latin letters.

Upon accepting a penny, the vending machine will or will not output an item, owing to its design.

The vending machine's design is defined as a logical expression consisting of the items and the binary operators. The binary operators and their semantics are:

  • P times Q: This vending machine has one slot. Upon accepting a penny, the vending machine will output the items P and Q together.

  • P with Q: This vending machine has two slots. The left slot, upon accepting a penny, will let the machine output P. The right slot, upon accepting a penny, will let the machine output Q.

  • P plus Q: This vending machine has one slot. Upon accepting a penny, the machine has fifty-fifty chance to output P or output Q.

  • P par Q: This vending machine has two slots, and one of them, chosen with fifty-fifty chance, has a pre-installed coin.

    • If you insert a penny in the other slot, the vending machine will consume one of the two pennies with fifty-fifty chance, and will output the item that corresponds to the consumed penny.

    • However, if you insert a penny in the slot that already had a penny pre-installed, the machine will reject the inserted coin, giving it back to you. You will try again with the rejected penny.

I/O format

(WIP)

Worked Examples

Example #1

Design your vending machine: (CANDY with CHIPS) times CHOCOLATE
Simulating (CANDY with CHIPS) times CHOCOLATE...
    Simulating (CANDY with CHIPS)...
        Which slot will you insert a penny? (Left|Right): Left
        Simulating CANDY...
            You get the CANDY.
    Simulating CHOCOLATE...
        You get the CHOCOLATE.

Example #2

Design your vending machine: CANDY par (CHIPS plus CHOCOLATE)
Simulating CANDY par (CHIPS plus CHOCOLATE)...
    Which slot will you insert a penny? (Left|Right): Left
    Wrong guess! The machine rejects the penny.
    Which slot will you insert a penny? (Left|Right): Right
    Correct guess!
    The machine decides to simulate CANDY.
    Simulating CANDY...
        You get the CANDY.

Example #3

Design your vending machine: CANDY par (CHIPS plus CHOCOLATE)
Simulating CANDY par (CHIPS plus CHOCOLATE)...
    Which slot will you insert a penny? (Left|Right): Right
    Correct guess!
    The machine decides to simulate (CHIPS plus CHOCOLATE).
    Simulating (CHIPS plus CHOCOLATE)...
        The machine decides to simulate CHOCOLATE.
        Simulating CHOCOLATE...
            You get the CHOCOLATE.

Meta Question

Any misunderstanding I have? Especially for par?

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

Construct the largest number by combining

Given an array, each time you can remove two values \$a\leq b\$, and add value \$\min\left(2a\color{red}{+1},a+b\right)\$.

Return the largest value you can get.

Duplicate Checker

  • The red part is +0 or +1
  • Is it fine to leave some values?
\$\endgroup\$
2
  • \$\begingroup\$ By "Largest value you can get", do you mean: Repeat the function until only 1 value remains, or Return the highest value obtained by a pair in the original list? \$\endgroup\$
    – ATaco
    Apr 4 at 20:52
  • \$\begingroup\$ @ATaco Not decided, ref "Is it fine to leave some values?" \$\endgroup\$
    – l4m2
    Apr 5 at 4:09
0
\$\begingroup\$

Is this function communative?

Given a function of the form of a valid mathematical expression with at least two variables named a through z, determine if it is impossible to rearrange the values of the variables so that the result is different. For example:

$$ x + y - 3 $$

would be commutative, because let's \$x = 2\$ and \$y = 6\$. Then the result would be 33, but even if you made \$x = 6\$ and \$y = 2\$, the result would be the same.

Clarifications

  • The expression consists of digits (0-9), addition (+), subtraction (-), multiplication (*), and division (/). No ab, it will always be written as a * b.
  • You may evaluate the expression left-to-right or adhere to the order of operations, but it must be consistent.
  • Variables can be any positive integer including zero unless that might result in division by zero.

Test cases

x + y - 3 => True
x * 3 / y => False
3 * x + y / x * 0 => True
\$\endgroup\$
6
  • 1
    \$\begingroup\$ Case x/x, x-y+0/0 ? \$\endgroup\$
    – l4m2
    Apr 10 at 1:00
  • \$\begingroup\$ What about x+2 + (y*y - 4) / (y - 2)? \$\endgroup\$ Apr 11 at 8:35
  • 1
    \$\begingroup\$ Do you have a solution? Is this problem always solvable? \$\endgroup\$
    – Tbw
    Apr 12 at 20:54
  • 1
    \$\begingroup\$ Typo in the title. And if the input can't contain parentheses, aren't left to right and order of operations solutions on totally different playing fields? (Maybe allow/encourage looser I/O, like prefix notation or even a pre-parsed tree structure.) \$\endgroup\$ Apr 17 at 2:01
  • 2
    \$\begingroup\$ Test cases with more than two variables would be good. \$\endgroup\$
    – pxeger
    Apr 17 at 10:12
  • \$\begingroup\$ Things to avoid: parsing expressions \$\endgroup\$
    – xnor
    Apr 19 at 22:33
0
\$\begingroup\$

Given a piece of notes, make accidentals clear.

Accidentals include b, % and #. Pitch names include uppercase A to G1. In input, every note is an accidental and a pitch name. Besides, bar lines exist to split bars.

For each note in output,

  • Default1 claims that a note share the recent accidental with same pitch name in this bar, or % if same pitch name never appeared in this bar. If this is false, preserve accidental as-is. Otherwise,
  • Default2 claims that a note share the recent accidental with same pitch name if there are less than 8 notes between it and current note, % otherwise. If this is false, surround the accidental with (). Otherwise, remove the accidental in output.

Test cases:

%C%C%C%C|#C#C#C#C|#C#C#C#C|%C%C%C%C| =>
CCCC|#CCCC|#CCCC|(%)CCCC|

enter image description here

1 Whether CDEFGAB or ABCDEFG doesn't matter here

Sandbox Notes

  • Any nouns incorrect
  • Name of Default1 and Default2
  • How does this work in real?
\$\endgroup\$
3
  • \$\begingroup\$ I'm pretty sure for default 2 that a note shares the accidental if there is a same note in the same measure, might be wrong. \$\endgroup\$ Apr 11 at 13:41
  • \$\begingroup\$ @LarryBagel Don't quite understand. Example? \$\endgroup\$
    – l4m2
    Apr 11 at 21:30
  • \$\begingroup\$ I mean that if there is a c-sharp in a measure and a normal c after that c-sharp in the same measure, that c will also be sharp. But if that c is in any other measure (without a c accidental preceding it), it's natural. \$\endgroup\$ Apr 12 at 12:34
0
\$\begingroup\$

Decode Caesar cipher based on a given text

I can't think of a better name. This is similar to this challenge, but a lot easier.

Read three strings which contain only uppercase letters. The length of the first and second strings are the same. The second string and the third string are encrypted using Caesar cipher using the same key. The original string of the second string is the first string. You have to decrypt the third string. Obviously, there is exactly one possible original string of the third string.

Examples

AAA BBB CCC -> BBB
I U TQXXAIADXP -> HELLOWORLD
HELLO FCJJM QRPGLM -> STRING

Rule

This is , so code in the fewest bytes.

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

Divisibility patterns

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

Convert CSV tables to Wikitext

Input a CSV table, like this:

data00,data01,data02,...,data0m
data10,data11,data12,...,data1m
...
datan0,datan1,datan2,...,datanm

The cells in the CSV table is guaranteed to contain only letters or numbers, and there's no extra whitespace.

Your task is to convert it to a Wikitext table, and output it, like this:

{| class="wikitable"
| data00 || data01 || data02 || ... || data0m
|-
| data10 || data11 || data12 || ... || data1m
|-
...
|-
| datan0 || datan1 || datan2 || ... || datanm
|}

Your output must strictly follow this format, except for the whitespaces before or after each cell.

For example, input:

a,b,c
1,2,3

Will output:

{|
| a || b || c
|-
| 1 || 2 || 3
|}

but

{|
| a || b || c
|-
|1||2||3
|}

is also a valid output. This is code golf, so use the fewest bytes.

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

Given a function f: N->N and non-negative integer n, output integer k s.t. f(f(...f(n)..)) (repeat k times) = 0, or some non-natural number if no k exist.

You can assume f is bounded, i.e. there's some number M s.t. for each n, f(n)<M.

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

*Trivial* near-repdigit perfect powers

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

Create a random Triling

Over in the Puzzling SE, user23087 came up with an interesting new puzzle type. (https://puzzling.stackexchange.com/questions/126659/try-triling-triangular-tiling).

Given two positive integers N and M, display a randomized "Triling" gameboard layout of N x M tiles, made of (N+1) x (M+1) dots placed at the corners of each tile, marking out a board, with some of the tiles containing numbers.

The board layout can be validly "Triled" if a player can join dots on the board to create triangles, with the tile of each number wholly contained by a non-overlapping triangle with an area equal to the number, and with the whole board covered in such triangles with no gaps.

I don't think it's possible to Trile a board with odd values of both N and M. It's also impossible to Trile one with an N or M less than 2. You can assume you'll only be given Trilable values of N and M.

How exactly the dots and letters are spaced doesn't matter, so long as it looks reasonable and you can tell which tiles are meant to be number-tiles, and the value they're meant to handle. Single-digit numbers may may be zero-padded or space-padded.

N = 2, M = 2 - Output must randomly be a board like either:

.  .  .
 2
.  .  . 
     2
.  .  . 

or:

.  .  .
     2
.  .  . 
 2
.  .  . 

Those are the only two legal layouts for a 2 x 2 board.

The former would be solvable by drawing just one line like so, placing both "2" tiles entirely within non-overlapping triangles of area 2:

.  .  /
 2  ,`
.  /  . 
 ,`  2
/  .  . 

N = 4, M = 4 - Layouts such as:

. . . . .
.2. . .2.
. . .4. .
. .4. . .
.2. . .2.

Or:

. . . . . 
.2. . .4. 
. .4. . . 
. . .4. . 
.2. . . . 

Or:

. . . . . 
. .4. . . 
.2. . . . 
.2. .8. . 
. . . . . 

...Or many others, though I think this size only allows tile values of 2, 4, and 8.

Scoring: It's trivial to generate boards that use only the values "2" and "3". To encourage more novel algorithms, this is code golf with handicapping, and lowest score wins. Shortest code will have a good head start, but then:

  • Double the score if your solution is only trivially-random (eg produces the same board just with alternative rotations, even for larger boards with many alternative solutions). I don't think it's possible to prove that an answer can generate all possible valid solutions, and that's OK.
  • Double your score if your answer can only generate layouts solvable entirely with right-angle triangles.
  • Double your score if your answer cannot generate layouts containing obtuse triangles.
  • Multiply your score by the count of the numbers in the list [1, 2, 3, 4, 5, 6, 7, 8, 9, and 10] that your answer can't/won't place in its generated boards. (As "1" is impossible to legally place, even an ideal solution will still multiply by 1, rather than 0.)

These handicapping penalties stack. Mention in your answer which ones you applied.

To further encourage novel algorithms rather than mere re-golfing of the first efficient one people come up with, each person posting an answer that uses a new layout-generation algorithm can use an exclamation-mark in the title of their answer. Nobody else gets to use exclamation marks in their answer title! So, just a completely cosmetic and self-policed reward, as opposed to the scores, which are made of authentic, bona fide Internet Points, probably tradable for food in some countries.

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

Win in a ball removing game

This challenge is interactive. You need to win in a ball removing game.

Rule

The rule of the game is like this. You have N balls in a row, numbered 1 to N, your program and the user will take turns to remove one ball or two consecutive balls, if a player can't remove, then he/it loses. Your program goes first. The user is guarranteed to follow the rules. Obviously, your program can always win using a strategy.

Format

First, you need to read N from standard input. Then, if your program removes a ball, print 1 and then the number of the ball to remove, separated by spaces, otherwise, print 2 and then the minimum number of the ball to remove, separated by spaces. The user will then follow the same format to input.

Example

User: 5
Program: 1 3
User: 2 1
Program: 2 4

This is an example of an interaction. There are 5 balls, the program first removes the third ball, then the user removes the first and the second ball, then the program removes the fourth and fifth ball. The user has no balls to remove now, so the program wins.

Goal

This is , so code in the fewest bytes.

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

Is this a slovable Numberlink?

Challenge

Per Wikipedia:

Numberlink is a type of logic puzzle involving finding paths to connect numbers in a grid.

The player has to pair up all the matching numbers on the grid with single continuous lines (or paths). The lines cannot branch off or cross over each other, and the numbers have to fall at the end of each line (i.e., not in the middle).

For example, consider this numberlink puzzle:

numberlink puzzle 1

This puzzle is slovable, see the solution below:

numberlink puzzle 1 solution

But some numberlink puzzle is unsolvable, like for this one when it's obvious

numberlink puzzle 2

Your challenge is, given a numberlink puzzle, decide whether it is slovable or not.

Input / Output

Input / Output can be taken in any reasonable format for taking in a rectangle numberlink puzzle, and deciding whether it is slovable or not. A dot . is used for blank space.

Example testcase:

Input -> Output
[[1, 3, ., ., ., ., .], 
 [., 2, ., 4, 6, ., .], 
 [., ., ., ., 5, ., .],
 [., ., 1, ., ., ., .], -> True
 [., ., ., ., ., ., .],
 [., 2, ., ., 5, 6, .],
 [., ., ., 3, 4, ., .]

[[., 2, 3, 4, .], 
 [1, ., ., ., 1],       -> False
 [., 2, 3, 4, .],

This is , so shortest answer (in bytes) wins!


Meta

The challenge itself.

  • Is this a duplicate?
  • I really don't know what can be harder testcases, so can anyone suggest me some ideas? It would be greatlyappreciated.
  • Is the input requiments fine? Should I use another character to denote the blank space? I also thought of another input requiments that is coordinate -based, so the second example would look something like this:
[3, 5]         // denote the size of the puzzle
[2, 1], [2, 5] // starting and ending coordinates 
[1, 2], [3, 2]
[1, 3], [3, 3]
[1, 4], [3, 4]

Is that better? Or should I allow both?

Editing

  • Do someone knows to shrink the image? It looks horrendous.
\$\endgroup\$
3
  • \$\begingroup\$ Your solution example looks like it's required to fill each empty cell with a number s.t. every number connected, which seems not intended \$\endgroup\$
    – l4m2
    May 14 at 22:20
  • \$\begingroup\$ or if allowing to leave some empty cell, then both are equivalent \$\endgroup\$
    – l4m2
    May 14 at 22:22
  • \$\begingroup\$ @l4m2 well you can leave some blank space, just that it has a path \$\endgroup\$
    – badatgolf
    May 15 at 1:37
0
\$\begingroup\$

Ultra-modular representative of rational numbers

Objective

Given a rational number, output the representative in the corresponding coset in the additive (abelian) quotient group \$\mathbb{Q} / \mathbb{Z}[1/2]\$. \$\mathbb{Q}\$ is the additive group of rational numbers, and \$\mathbb{Z}[1/2]\$ is the additive group of rational numbers whose denominator is power of 2, identified as an adjoint ring with multiplicative structure forgotten.

Representative

Being a quotient group, \$\mathbb{Q} / \mathbb{Z}[1/2]\$ consists of cosets. Each coset has exactly one rational number such that:

  • is \$0\$, or
  • is a positive proper fraction with positive odd denominator.

And this number is the representative of the said coset.

I/O format

The I/Oed rational numbers shall be a reduced fraction. That is, the numerator and the denominator shall be coprime, and the denominator shall be positive.

Example

Input -> Output

0/1 -> 0/1
1/1 -> 0/1
2/1 -> 0/1
1/2 -> 0/1
3/2 -> 0/1
1/3 -> 1/3
2/3 -> 2/3
1/6 -> 2/3
5/6 -> 1/3
1/8 -> 0/1
1/10 -> 3/5
3/10 -> 4/5
7/10 -> 1/5
-1/1 -> 0/1
-1/6 -> 1/3
-1/12 -> 2/3

Meta Question

How would this challenge be presented in laymen's terms?

\$\endgroup\$
-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\$ 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\$ 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\$
    – FlipTack
    Feb 6, 2017 at 22:02
-1
\$\begingroup\$

Wifi Puzzle! Crack the router [code-golf] [networking]

SITUATION

Consider that you have three wifi routers in your home , all with different SSIDs and none of them are dualband. You have invited a mischievous friend to your home who had changed the password of each router, without letting you know about it. Now to annoy you more he has set up a programming challenge.

THE CHALLENGE

Your friend has created three .txt files containing a set of passwords with only one correct among them. (i.e. each .txt file contains a correct password while all other are wrong ones. Also one .txt file contains only one correct password) and the .txt files do not specify which one may contain the correct password for a certain router (i.e. you cannot be sure that file1.txt(let us assume it is one of those .txt files) contains the password for router1( say any one of those routers). Now your friend has kept them in a certain directory( say E:\Wifi) and asked you to create a programme or function that would pick up a file and take input from it, try to connect to a random Access point ( out of the three routers) and find which password fits to which router.

Sample Input

Let us consider a file, file1.txt( or any other name you like) be like this

A12e77799U5
Pdc555089rtf
Ds442Y779#1
1&2*fe$996Yt
Uty66%92Gu4

Note that each password contains a capital letter, numbers, special characters, (of a standard keyboard) and each file contains only five unique passwords. Also all the .txt files are in the same directory and there are no subdirectories in the directory concerned. Also each .txt file contains at least one correct password.

Sample Output

Your programme or function must keep a log of its activity in a separate file log.txt which you may put in the same directory concerned or in a different directory. The log file must show which router has been cracked with which password and also the file containing it.

Example: Say that router1 ( SSID of a router) has been cracked by the password A12e77799U5 from file1.txt so the output of the log.txt must be

router1 password A12e77799U5
File: file1.txt

Also you must be sure that all the output goes into the log.txt not seperate files each time a router is cracked. You can create a programme or a function in any programming language.

Keep In Mind

  1. This is code-golf so the shortest answer wins.

  2. Standard loopholes apply as usual.

Discussion I feel to ask this question but the foremost problem I face is how can others test their code. Also strict I/o rules (like the log.txt I mentioned ) are not appreciated here. So please help me out!

\$\endgroup\$
2
  • 1
    \$\begingroup\$ So, you want us to access the network settings programmatically? Even if we disregard the difficulties in testing it, this is not a golfing challenge, but rather a challenge in convincing our OSes to let us fiddle with the settings, and then figuring out how. \$\endgroup\$ Feb 12, 2017 at 19:25
  • \$\begingroup\$ So is there any category I can put it in, I mean any tags. \$\endgroup\$
    – jyoti proy
    Feb 12, 2017 at 20:04
-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\$
    – sergiol
    May 27, 2017 at 8:48
  • \$\begingroup\$ "The only two colors used should be clearly distinguishable" Clarification? \$\endgroup\$
    – Joao-3
    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\$
    – Adám
    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\$
    – user62131
    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\$
    – Willtech
    Dec 28, 2023 at 8:23
1
140 141
142
143 144
157

You must log in to answer this question.

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