567
\$\begingroup\$

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

Sandbox FAQ

Posting

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

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

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

Discussion

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

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

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

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

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

Other

Search the sandbox / Browse your pending proposals

The sandbox works best if you sort posts by active.

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

\$\endgroup\$
0

4472 Answers 4472

1
81 82
83
84 85
150
1
\$\begingroup\$

Knook to Mate... With Portals!

\$\endgroup\$
3
  • \$\begingroup\$ In this image you may want to mark someway that B3 can't be reached, right now you use the arrow both to mean inclusive range and just the endpoint \$\endgroup\$
    – mousetail
    Jan 20 at 6:42
  • \$\begingroup\$ cdn.discordapp.com/attachments/968416999808057344/… is d6 also valid? \$\endgroup\$
    – l4m2
    Jan 20 at 7:14
  • \$\begingroup\$ @l4m2 d6 is indeed also valid. Positions may have multiple solutions \$\endgroup\$
    – lyxal
    Jan 20 at 8:03
1
\$\begingroup\$

Longest N-Sum Sub-Array

Write a program or function which when given an array of non-negative integers and a number \$N\$, output the longest contiguous sub-array whose sum of elements adds up to \$N\$:

$$S = \{ (x, y) : \sum_{n=x}^{y} a_n = N \}$$

$$\text{Output: } argmax_S (y - x)$$

Constraints

  • If there are multiple solutions, output any of them or all of them (choose one).
  • You may output the solution in any reasonable format, which must allow for the following point.
  • There will always be a solution, but it can be the empty list.
  • \$N \ge 0\$.

Test cases

[input array], N -> [output array]

[1, 0, 0, 1, 0], 1 -> [0, 0, 1, 0]
[1, 0, 0, 1, 0], 0 -> [0, 0]
[1, 2, 3, 4, 5], 0 -> []
[1, 2, 3, 4, 5], 5 -> [2, 3]
[4, 3, 1, 1, 0, 5, 2], 8 -> [1, 0, 5, 2]
[0], 0 -> [0]
[], 0 -> []

This is , so shortest code in bytes wins.

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

Toggle my Comments

Write a program which takes a string as input. If the string is a syntactically valid comment in the program's language, the program must output an uncommented version of the string. Otherwise, it must output a syntactically valid commented version. Programs may use either multiline or single-line comments. Languages that do not support comments may not compete.

Python example

Input: spaghetti
Possible output: #spaghetti
Possible output: # spaghetti

Input: # spaghetti
Output: spaghetti

Input: #spaghetti
Output: spaghetti
```
\$\endgroup\$
1
\$\begingroup\$

Toggle Hangul Vowel Harmony

(This post is partly self-plagiarized.)

Objective

Given a Hangul syllable, toggle its vowel harmony.

Introduction to Hangul syllables

Hangul(한글) is the Korean writing system invented by Sejong the Great. Hangul syllables are allocated in Unicode point U+AC00 – U+D7A3. A Hangul syllable consists of an initial consonant, a vowel, and an optional final consonant.

The initial consonants are:

ㄱ ㄲ ㄴ ㄷ ㄸ ㄹ ㅁ ㅂ ㅃ ㅅ ㅆ ㅇ ㅈ ㅉ ㅊ ㅋ ㅌ ㅍ ㅎ

The vowels are:

ㅏ ㅐ ㅑ ㅒ ㅓ ㅔ ㅕ ㅖ ㅗ ㅘ ㅙ ㅚ ㅛ ㅜ ㅝ ㅞ ㅟ ㅠ ㅡ ㅢ ㅣ

The final consonants are:

(none) ㄱ ㄲ ㄳ ㄴ ㄵ ㄶ ㄷ ㄹ ㄺ ㄻ ㄼ ㄽ ㄾ ㄿ ㅀ ㅁ ㅂ ㅄ ㅅ ㅆ ㅇ ㅈ ㅊ ㅋ ㅌ ㅍ ㅎ

For example, has initial consonant , vowel , and final consonant .

South Korean dictionary order

The consonants and vowels above are sorted in South Korean dictionary order. The syllables are firstly sorted by initial consonants, secondly by vowels, and finally by (optional) final consonants.

The Unicode block for Hangul syllables contains every consonant/vowel combinations, and is entirely sorted in South Korean dictionary order.

The Unicode block can be seen here, and the first 256 characters are shown for illustrative purpose:

가각갂갃간갅갆갇갈갉갊갋갌갍갎갏감갑값갓갔강갖갗갘같갚갛개객갞갟갠갡갢갣갤갥갦갧갨갩갪갫갬갭갮갯갰갱갲갳갴갵갶갷갸갹갺갻갼갽갾갿걀걁걂걃걄걅걆걇걈걉걊걋걌걍걎걏걐걑걒걓걔걕걖걗걘걙걚걛걜걝걞걟걠걡걢걣걤걥걦걧걨걩걪걫걬걭걮걯거걱걲걳건걵걶걷걸걹걺걻걼걽걾걿검겁겂것겄겅겆겇겈겉겊겋게겍겎겏겐겑겒겓겔겕겖겗겘겙겚겛겜겝겞겟겠겡겢겣겤겥겦겧겨격겪겫견겭겮겯결겱겲겳겴겵겶겷겸겹겺겻겼경겾겿곀곁곂곃계곅곆곇곈곉곊곋곌곍곎곏곐곑곒곓곔곕곖곗곘곙곚곛곜곝곞곟고곡곢곣곤곥곦곧골곩곪곫곬곭곮곯곰곱곲곳곴공곶곷곸곹곺곻과곽곾곿

Vowel Harmony

Korean vowels express vowel harmony as positive-negative pairs. They're paired like the followings:

(Positive) - (Negative)
ㅏ - ㅓ
ㅐ - ㅔ
ㅑ - ㅕ
ㅒ - ㅖ
ㅗ - ㅜ
ㅘ - ㅝ
ㅙ - ㅞ
ㅚ - ㅟ
ㅛ - ㅠ
(ㅡ, ㅢ, and ㅣ lack counterparts)

Examples

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

It's a dog!

\$\endgroup\$
2
  • \$\begingroup\$ Picture show tail something like leg but don't touch floor; I usually see tail in real life touch floor with lot laid, though \$\endgroup\$
    – l4m2
    Jan 22 at 5:37
  • 1
    \$\begingroup\$ You may want to specify that the legs need to be separate (i.e. cannot share a common "border"). As per the tail one option is to simplify the task only to check a simple tail (or a "tail ending"), e.g. (space)_ \\ [_ and the leftmost bracket touches the left border (and perhaps is the only non-space character there). \$\endgroup\$
    – pajonk
    Jan 24 at 13:53
1
\$\begingroup\$

Determine the Octet(/Duplet/18-electron) Rule

Tags:

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

An address is decoded as follow:

   reg eax ecx edx ebx esp ebp esi edi  0  sib
    id  0   1   2   3   4   5   6   7   -   -
+0      00  01  02  03  /   /   06  07  /   04
+imm8   40  41  42  43  /   45  46  47  /   44
+imm32  80  81  82  83  /   85  86  87  05  84

where sib means the following byte parsed as follow:

    +  eax ecx edx ebx esp ebp/imm32*esi edi
   eax  00  01  02  03  04     05     06  07
   ecx  08  09  0a  0b  0c     0d     0e  0f
   edx  10  11  12  13  14     15     16  17
   ebx  18  19  1a  1b  1c     1d     1e  1f
     0  20  21  22  23  24     25     26  27
   ebp  28  29  2a  2b  2c     2d     2e  2f
   esi  30  31  32  33  34     35     36  37
   edi  38  39  3a  3b  3c     3d     3e  3f
 2*eax  40  41  42  43  44     45     46  47
 2*ecx  48  49  4a  4b  4c     4d     4e  4f
 2*edx  50  51  52  53  54     55     56  57
 2*ebx  58  59  5a  5b  5c     5d     5e  5f
 2*esp  60  61  62  63  64     65     66  67
 2*ebp  68  69  6a  6b  6c     6d     6e  6f
 2*esi  70  71  72  73  74     75     76  77
 2*edi  78  79  7a  7b  7c     7d     7e  7f
 4*eax  80  81  82  83  84     85     86  87
 4*ecx  88  89  8a  8b  8c     8d     8e  8f
 4*edx  90  91  92  93  94     95     96  97
 4*ebx  98  99  9a  9b  9c     9d     9e  9f
 4*esp  a0  a1  a2  a3  a4     a5     a6  a7
 4*ebp  a8  a9  aa  ab  ac     ad     ae  af
 4*esi  b0  b1  b2  b3  b4     b5     b6  b7
 4*edi  b8  b9  ba  bb  bc     bd     be  bf
 8*eax  c0  c1  c2  c3  c4     c5     c6  c7
 8*ecx  c8  c9  ca  cb  cc     cd     ce  cf
 8*edx  d0  d1  d2  d3  d4     d5     d6  d7
 8*ebx  d8  d9  da  db  dc     dd     de  df
 8*esp  e0  e1  e2  e3  e4     e5     e6  e7
 8*ebp  e8  e9  ea  eb  ec     ed     ee  ef
 8*esi  f0  f1  f2  f3  f4     f5     f6  f7
 8*edi  f8  f9  fa  fb  fc     fd     fe  ff
* imm32 if no another imm

If an imm8 or imm32 is used, the value is followed after, little-endian.

Given a value of {0,1,2,4,8}*reg+{reg,0}+imm32, output a shortest expression of the address.

Test cases

eax => 00
eax+8 => 40 08
eax+128 => 80 80 00 00 00
esp => 04 24
ebp => 45 00
4*eax => 04 85 00 00 00 00
2*eax => 04 00
2*esp => 04 60 00 00 00 00 

Sandbox Notes

  • Since it's modified(enabled to allow esp*4), and I'd allow use of id, should I remove the eax expression?
\$\endgroup\$
1
\$\begingroup\$

Translate to plorcly borglar

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

How to find the counterfeit coin?

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

How spherical is my ellipsoid?

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

Find opposite string

\$\endgroup\$
2
  • \$\begingroup\$ What do you mean by “opposite mirror letter” \$\endgroup\$
    – noodle man
    Feb 15 at 20:43
  • \$\begingroup\$ @Jacob "opposite mirror letter from the English alphabet" - it means that a must be replaced with z, b must be replaced with y and so on. In general let's we have some letter which index in alphabet is Index then it must be replaced with letter which index is 25 - Index (25 if zero based and 26 if 1 based) \$\endgroup\$
    – EzioMercer
    Feb 15 at 21:22
1
\$\begingroup\$

Random point inside boundary

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

Given a signed int64, convert into base -2 integer. + - & | ^ ~ cost 1. =, variable name, constant are free. Other operations disallowed. Lowest cost win.

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

3D rotation matrix to quaternion

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

Number Clusters

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

Injectively saturate bit strings

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

Elevator movement order

\$\endgroup\$
6
  • \$\begingroup\$ Is it possible to have the first input also in the array? If so, how to handle that case? \$\endgroup\$
    – pajonk
    Feb 22 at 5:25
  • \$\begingroup\$ @pajonk Can you please explain why do you need only first input in array and why not all inputs in one array? I don't like to mix the inputs because they separated by meaning \$\endgroup\$
    – EzioMercer
    Feb 22 at 8:47
  • \$\begingroup\$ I meant a test case like 0, 3, [0,4,-2,-5,2,-4,1,5] --> ? - where to sort the 0 from the array? Or such input combination will never appear? Also, will the array never contain duplicates? \$\endgroup\$
    – pajonk
    Feb 22 at 10:33
  • \$\begingroup\$ @pajonk 1. The zero is the floor where elevator already stopped it can not be in the order of future destinations. 2. There can not be a duplicates, also in the input array can not be the same number as in second input because this floor already exist in the order. Please inform me if this information MUST BE in challenge, I will add it :) \$\endgroup\$
    – EzioMercer
    Feb 22 at 11:31
  • 1
    \$\begingroup\$ I think not specifying those conditions in the challenge body may prompt similar questions on main, so yes, please add it :) \$\endgroup\$
    – pajonk
    Feb 22 at 11:36
  • \$\begingroup\$ @pajonk Done. Thank you! \$\endgroup\$
    – EzioMercer
    Feb 22 at 13:12
1
\$\begingroup\$

Simultaneously solve N-queens and no-3-in-line

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

Consolidate a 6-axis Vector

\$\endgroup\$
2
  • \$\begingroup\$ I suggest specifying that the input will contain only integers. Also, as I read it, there is always one Consolidated Vector for any given input - is it the case? \$\endgroup\$
    – pajonk
    Feb 23 at 12:53
  • \$\begingroup\$ @pajonk good points, I've added that information. Yes, there is only valid valid solution per input. \$\endgroup\$
    – Pavel
    Feb 23 at 20:50
1
\$\begingroup\$

Decoding a non injective bit matrix encoding

\$\endgroup\$
2
  • \$\begingroup\$ Is the size always even? If not, how do you define quadrants? \$\endgroup\$ Feb 27 at 3:43
  • \$\begingroup\$ The side can be odd, in which case the boundaries are obtained by dividing the side length and flooring it. I've edited the statement to clarify this, thank you for pointing it out! \$\endgroup\$ Feb 27 at 13:21
1
\$\begingroup\$

Sum of strings (UTF-16 codepoints)

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

Animate the shape!

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

Simulate Just Friends

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

Triangularly embed a graph on a surface

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

Arbitrary numeric base as string

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

For a given base b, the following should hold:

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

Examples:

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

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

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

Find the linear transformation

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

Vertically Aligned JSON formatting

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

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

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

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

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

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

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

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

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

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

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

Hyperjumps Challenge

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

Is it a hyperjump?

Easy-mode of this challenge

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

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

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

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


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

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

Determine NBA conference seedings

\$\endgroup\$
1
81 82
83
84 85
150

You must log in to answer this question.

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