538
\$\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 needs more feedback, but it's been ignored, you can ask for feedback in The Nineteenth Byte. It's not only allowed, but highly recommended!

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".

Get the Sandbox Viewer to view the sandbox more easily!

\$\endgroup\$
0

3549 Answers 3549

1
104 105
106
107 108
119
0
\$\begingroup\$

Transdeletion

Transdeletion is the process of removing a letter from a word and forming another word by creating an anagram from the remaining letters.

If you can do this repeatedly, all the way down to a single letter ("A" or "I", usually, in English), you have formed a "Transdeletion Pyramid".

The Challenge

Given a word list (containing any number of words, up to the max your language can handle) and a starting word, find and output the Transdeletion pyramid.

The word list will include the starting word, and is guaranteed to contain all of the words required to make the pyramid (Sandbox: should it? Or is it a better challenge if it won't always be possible to succeed?). A change of case for any letters of the word is allowed at any time - i.e. dealing with casing isn't part of the challenge. So you can assume all inputs are in lowercase, or uppercase, or whatever suits.

This is , so shortest answer in bytes wins, usual rules apply.

Examples

In the form [[wordList],"startWord"] -> [ordered output list]

[["a", "an", "ant"], "ant"] -> ["ant","an","a"]
[["I", "in", "tin", "sink", "ink"], "sink"] -> ["sink","ink","in", "I"]
[["I", "in", "tin", "sink", "ink"], "in"] -> ["in", "I"]
[["a", "I", "tin", "ant", "sink", "an" "ink"], "ant"] -> ["ant","an","a"]
[["FAT", "TALIERA", "INTERLAMINATES", "ULCER", "ALTER", "TALE", "A", "RATE", "I", "ANTICEREMONIALIST", "MATERIAL", "INCOMPETENT", "TRILAMINATE", "TEA", "TEA", "TRIFLE", "NONMATERIALITIES", "FRATERNISATION", "AT", "AT", "ORNAMENTALITIES", "RETAIL", "TAIL", "MATERNALITIES", "TERMINALIA", "LATIMERIA", "FATIMA", "OBSCURE", "LENS", "MATRILINEATE"],"ANTICEREMONIALIST"] -> ["ANTICEREMONIALIST", "NONMATERIALITIES", "ORNAMENTALITIES", "INTERLAMINATES", "MATERNALITIES", "MATRILINEATE", "TRILAMINATE", "TERMINALIA", "LATIMERIA", "MATERIAL", "TALIERA", "RETAIL", "ALTER", "RATE", "TEA", "AT", "A"]

Sandbox Questions

  1. Should it be possible that the input contains no valid chains?
  2. Should the challenge instead be to find the longest chain, even if it doesn't go down to 1 letter?
  3. Should the starting word be provided or would it be a better challenge without it?
\$\endgroup\$
0
\$\begingroup\$

Decide Magma's Identity

Objective

Given a magma with 256 elements, decide whether it has the identity element.

Definition

A magma is a set endowed with a binary operation. Let's denote the set by \$S\$ and the binary operation by \$\circ\$.

An element \$e \in S\$ is the identity element if for every \$a \in S\$, \$e \circ a = a \circ e = a\$ holds.

If \$e\$ exists, its existence is unique, for if \$f \in S\$ also is an identity element, \$e = e \circ f = f\$.

Input Format

The binary operation \$\circ\$ itself, as a black-box function, will be inputted.

The type of \$\circ\$ doesn't matter. Possible choices include (type names in C):

  • Accepting two chars, returning one char

  • Accepting two int8_ts, returning one int8_t

  • Accepting two uint8_ts, returning one uint8_t

  • Accepting one int16_t (to break bytewise), returning one unsigned char

Ungolfed Solution

Haskell

This implementation is much generalized version of the challenge. It can test an arbitrary finite magma, and will explicitly find the identity element if it exists.

It might seem to have time complexity of \$O(n^2)\$, but it's actually \$O(n)\$.

import Control.Monad
import Data.Maybe

findIdentity :: (Eq a, Enum a, Bounded a) => (a -> a -> a) -> Maybe a
findIdentity op = listToMaybe $ do
    let elements = [minBound .. maxBound]
    e <- elements
    guard (all (\f -> op e f == f) elements)
    guard (all (\f -> op f e == f) elements)
    pure e
\$\endgroup\$
0
\$\begingroup\$

Packing Boxes into a Truck

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

Compile Esolang to Esolang

Based on Convert FRACTRAN to Brainfuck.

  • Compile Brainfuck to FRACTRAN
  • Compile /// to Brainfuck
  • Compile Brainfuck to ///

If you have other ideas, please add them. Be sure it's reasonably doable with simple tarpits, eg Jelly to Vyxal to APL isn't all that fun. If you can make a variation of that fun, that should be posted separately.

If you'd like me to make this into a CW to make it easier to contribute, please comment and let me know!

\$\endgroup\$
4
  • \$\begingroup\$ FRACTRAN to Retina 0.8.2 would prove that the latter is Turing-complete (Regex on its own isn't, but Retina has loops. On the other hand, Retina 1 has eval, so you can probably do some nasty things like a payload-capable quine attempting to evaluate itself, thus implementing Fibonacci recursively.) \$\endgroup\$
    – Neil
    Jul 11 at 11:07
  • \$\begingroup\$ @Neil I'm thinking that one of them should be a simple, well-known and pretty vanilla lang. Eg Brainfuck <-> Retina, or, since it's based on string subs, /// <-> Retina might be fun. How do those sound? Or would you prefer from FRACTRAN/another Minsky machine? I also am slightly worried about Retina's complexity, but maybe just a subset of Retina would be required? \$\endgroup\$
    – AviFS
    Jul 11 at 19:45
  • \$\begingroup\$ I can't comment on the other languages because I don't know them, but Retina 0.8.2 isn't that complex; its only loop is the convergence loop and the only conditional code is basically whether a regex matches or not. \$\endgroup\$
    – Neil
    Jul 11 at 22:42
  • \$\begingroup\$ is this structured as an answer chaining problem? \$\endgroup\$
    – Razetime
    Jul 14 at 7:35
0
\$\begingroup\$

Make me some puzzles

So, a while ago on Puzzling, I posted this. It basically had a whole bunch of equations that were wrong, and when you figured out how much they were wrong by, and transformed 1-26 into A-z, it yielded the phrase ALLWRONG.

Your challenge is to take a string of letters as input, and output a series of wrong, randomly generated equations that are wrong by the correct amount to yield said string.

Equations must be of the form number operation number = number, where each number is a positive integer less than 100, and the operators are +-*/, although × and ÷ are acceptable instead of */.

I'm going to be quite lenient on the definition of 'random' in this one - all possible equations must have a nonzero chance of appearing for any given letter.

Valid equations should have the result of the left hand side's difference from the right hand side being the correct number to, when 1-26 is transformed into A-Z, yield the corresponding character.

Output can be as an array, newline separated, whatever. Equations don't need to be spaced, that's just for readability. You can even output as a list of [1,+,1,=,3] or something.

Testcases

These are possible outputs, not proper testcases.

A => 1 + 1 = 3
HI => 3 * 4 = 4, 9 * 2 = 9
LOL => 20 / 5 = 16, 7 * 5 = 20, 50 - 23 = 15
\$\endgroup\$
0
\$\begingroup\$

Avoid traps, run to an exit!

Code layout

Your code shall have:

  • One kind of characters as the protagonist. The protagonist must appear exactly once in the source.

  • One other kind as the trap. Traps must appear once or more.

  • One other kind as the exit. Exits must appear once or more.

No other restrictions.

Objective

The protagonist can move by replacing another character by the protagonist and removing the original protagonist.

Write a program/function that:

  • Outputs zero when executed/invoked on its own.

  • Outputs a negative number if the protagonist moved into a trap. The output need not be consistent.

  • Outputs a positive number if the protagonist moved into an exit. The output need not be consistent.

  • All other modifications fall in don't care situation.

Example

Given the following source:

Hello, world!

where H is the protagonist, ls are traps, and os are exits, the source shall output zero.

Then the following sources shall output a negative number:

eHlo, world!

elHo, world!

ello, worHd!

And the following sources shall output a positive number:

ellH, world!

ello, wHrld!

Scoring

The source with the least number of characters (not bytes) shall win.

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

Find out what type of adjective it is

There are 3 types of adjectives: absolute, comparative, and superlative adjectives. Your program should print what type of adjective it is.

Notes

  • Input will be a string, (not always 1 word), it'll be an adjective (the number of words will be finite)
  • Output must be either of these (the form of the adjective):
    • absolute, comparative, and superlative
    • a, c, s
    • 1, 2, 3 respectively
    • 0, 1, 2 respectively
  • The 15 adjectives below should be use as test-cases and you're program should be at least 90% accurate.

This is , so the shortest code wins!

Test cases:

pushiest => superlative
homeliest => superlative
most miserly => superlative
outgoing => absolute
most feline => superlative
roasted => absolute
frightening => absolute
fairer => comparative
more uncomfortable => comparative
more classic => comparative
smarter => comparative
muffled => absolute
scratchier => comparative
meager => absolute
tartest => superlative
\$\endgroup\$
6
  • \$\begingroup\$ So it only needs to correctly identify 14 of the below 15? \$\endgroup\$
    – rak1507
    Jun 30 at 14:00
  • \$\begingroup\$ @rak1507 at least. I'll add more test cases if necessary \$\endgroup\$
    – math
    Jun 30 at 14:02
  • \$\begingroup\$ @rak1507 but checking everyone of these won't work, as it's code golf \$\endgroup\$
    – math
    Jun 30 at 14:04
  • 3
    \$\begingroup\$ It should be made very clear whether the program is supposed to work on a finite list of words (as currently suggested) or on any input in theory. The approaches are going to be very different. \$\endgroup\$
    – Arnauld
    Jun 30 at 22:34
  • \$\begingroup\$ "tartest" is a superlative. \$\endgroup\$
    – DjinTonic
    Jul 17 at 2:04
  • \$\begingroup\$ @DjinTonic okay done \$\endgroup\$
    – math
    Jul 25 at 7:58
0
\$\begingroup\$

Is it a mathy-county-number

So I recently reinvented some boring type of number. Reinvented because I'm sure somebody else invented it before, but 'till figure out who actually invented it, let's call these numbers mathy-county-numbers.

So what is a mathy-county-number?

It's a number like 332222410.
The number 3 occurs 2 times, so there must be a 2. The number 2 occurs 4 times, so there must be a 4. 4 occurs once, and some other numbers occur 0 times.

The task is simple: Write a program to check if a number (received by the input) is a mathy-county-number.

Rules

  • Default loopholes apply
  • Default I/O rules apply
  • Output must be a boolean (1/0, True/False, anything/nothing)
  • If any digit occurs more than 9 times, count it as a 9.

Examples

332222410
> 1

33222241
> 0

1
> False

33222
> True

0112223333444445555556666666777777778888888889
> sdcvbhnjmk

1122233334444455555566666667777777788888888
> 
```
\$\endgroup\$
5
  • \$\begingroup\$ "The number 3 occurs 2 times, so there must be a 2." Does this means "3312" is valid as there is a 2 (although not followed by 3). \$\endgroup\$
    – tsh
    Jul 26 at 9:48
  • \$\begingroup\$ Why "1" is falsy? \$\endgroup\$
    – tsh
    Jul 26 at 9:49
  • \$\begingroup\$ @tsh 1: no, because in 3312 there's no 0. but eg. 03312 would be valid \$\endgroup\$
    – math
    Jul 26 at 10:44
  • \$\begingroup\$ @tsh 2: 0 is not there, 9, 8, 7, ... occur 0 times \$\endgroup\$
    – math
    Jul 26 at 10:54
  • \$\begingroup\$ "If any digit occurs more than 9 times, count it as a 9." is needlessly complicated, I'd suggest just saying that no digit will appear more than 9 times. The output for the last 2 test cases in unclear - what is sdcvbhnjmk supposed to represent? Just use something like true/false. Additionally, why is 33222 true? By the same logic as the example, it contains "some other numbers zero times", so should include a 0 to be true, right? \$\endgroup\$ Aug 6 at 14:02
0
\$\begingroup\$

Do you come here often?

Imagine a scenario where users are loging in to a website with an email address and a phone number. Sometimes when a user returns, they identify themselves differently; changing either their email or their number.

How do we find the unique users behind the log ins?

Illustration: Here Anna has changed her email between the first and second log in, and changed her phone number from the second to the third. Paul has logged in once, while Anna three times.

enter image description here

Challenge

Given two ordered list of identifiers (ID1 and ID2), return an ordered list showing the owners of the different IDs (named 0, 1, 2, etc.).

Input: List_ID1, List_ID2

Output: List_ID3

Connection:

A user logs on and identify with two IDs, e.g. List_ID1[0] and List_ID2[0]. 
The first unique user is called "0" making List_ID3[0] = 0
- If List_ID1[1] or List_ID2[1] can be traced to user 1: List_ID3[1] = 0
- If List_ID1[1] or List_ID2[1] cannot be traced to user 1: List_ID3[1] = 1

Example Input and Output

Input:

[7, 7, 8, 9, 10, 11, 11, 10, 12, 12, 15, 16, 15, 16, 15, 16]
[1, 2, 2, 3, 3, 3, 4, 4, 5, 6, 2, 1, 2, 1, 2, 1]

Output:

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

Meta

This is an idea I have had for some time, and though I have some code which can do this, I wonder what is the fastest algorithm for this problem. Today I discovered the Code Golf Meta, and I hope you can guide me through my first interaction with this community. I'm happy to be here!

Answer the following questions for your readers: (From template)

  1. Are there any corner cases? Is it clear how they should be handled?
    • I'm not sure.
  2. How will the winner of the challenge will be determined?
    • This is my first challenge. What I would want to ask that the fastest code wins, but I see that the convention is otherwise here. Or do you also do speed as a winning criteria?
  3. Is it clear how all submissions will be scored?
    • I was thinking to make some test cases to run. Does that work?
\$\endgroup\$
3
  • \$\begingroup\$ Welcome to Code Golf, and thank you for using the Sandbox! I think I understand the task, but I think it could benefit from a detailed explanation/walkthrough of the example I/O. For [fastest-code] challenges, the author typically times each submission on their own machine (and you publish some basic specs of your computer) with a set of test cases. You could also consider [fastest-algorithm] as a scoring criteria if you don't want to do this. \$\endgroup\$ Jul 26 at 23:17
  • \$\begingroup\$ Thank you for the warm welcome @cairdcoinheringaahing! I highly appreciate your feedback and I am positively surprised that [fastest-code] can be done in these two ways (I'm excited!). I will work on the explanation/walkthrough and improve the structure of the problem description. Let me know if you have some more feedback, and thanks again! \$\endgroup\$
    – thenarfer
    Jul 26 at 23:22
  • \$\begingroup\$ I'd also suggest that you find a challenge on main to answer so that you can get 20 rep. Once you do that, you can chat, including asking for feedback. Reputation earned anywhere on the network except for SO and Meta.SE will count towards that :) \$\endgroup\$ Jul 26 at 23:24
0
\$\begingroup\$

Group binary shapes together

\$\endgroup\$
7
  • \$\begingroup\$ I only asked about input, though you could allow it for output too, by allowing each group's 1s to be replaced with consecutive numbers (1-indexed, of course). \$\endgroup\$
    – Adám
    Jul 26 at 22:17
  • \$\begingroup\$ @Adám I don't think I'll allow it for output, that seems like too significant a deviation from the original challenge \$\endgroup\$ Jul 26 at 22:18
  • \$\begingroup\$ Sure, makes sense, and I didn't think of it before you mentioned it :-) \$\endgroup\$
    – Adám
    Jul 26 at 22:19
  • \$\begingroup\$ Can we answer with a list of lists of indices into the input? E.g. [[1,3],[2],[4,5]]? \$\endgroup\$
    – Adám
    Jul 26 at 22:23
  • \$\begingroup\$ @Adám Yes, added \$\endgroup\$ Jul 26 at 22:28
  • \$\begingroup\$ Suggested test cases: [[1,1,1],[1,0,1],[1,1,1]] and [[1,0,1],[1,0,1],[1,1,1]] \$\endgroup\$
    – Adám
    Jul 26 at 22:37
  • \$\begingroup\$ Please supply test cases as JSON. \$\endgroup\$
    – Adám
    Jul 26 at 22:37
0
\$\begingroup\$

King of the Hill: Nose Poker - An ogre game for ogres

\$\endgroup\$
2
  • \$\begingroup\$ I've edited this down to a stub now that it's been posted to save space \$\endgroup\$ Jul 27 at 1:01
  • \$\begingroup\$ @cairdcoinheringaahing Thanks! I'd meant to do that already. \$\endgroup\$
    – AJFaraday
    Jul 27 at 7:48
0
\$\begingroup\$

Two inverse quines

Your challenge is to write two programs A and B such that:

  • A outputs B
  • B outputs A
  • Wherever there is a space character in A, there is a non-whitespace character in B, and vice versa (newlines must be consistent through both)
  • This means A and B are the same length in characters.

For example A and B are valid, but A and B are not.

Newlines must be consistent through both, so A \nB and C\n D are valid, but A C and B\nD are not.

Scoring

Your score is the length in bytes of either of your programs. If they're different lengths in bytes, take the average.

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

Knapsack Paragraph, Format For A Phone

There are several paragraph formatting questions already on the site, where a string of text is split on space or other boundaries in order to fit into a rectangle; but they usually involve specifying a particular width for the formatted paragraph in addition to the supplied text.

For this problem, instead of a fixed width, we want to minimize the perimeter of the bounding box of the formatted text. Because we are developers for a phone app and we have to pay for the border by the inch. Or some other such tom-foolery; actually I noticed that this is a bit of a knapsack problem, and I just like the resemblance to that old folk song "knick-knack paddywack, give a dog a bone".

Challenge

Define a layout of a string T of text as a list of n strings s[i] such that the joined string using spaces as delimiter, i.e. s[0]+' '+s[1]+' '+...+' '+s[n-1] is equal to T.

The semiperimeter of a layout s is n plus the maximum length of any s[i] in s.

Given as input a string T, your submission must output the minimum semiperimeter across all valid layouts of T. Alternatively, you may output a layout which has a semiperimeter which is minimal.

The restrictions on input are forgiving; in particular, you may take T as a list of words (strings without spaces) instead of a single string; so long as the result includes the count of spaces that would be present in the layout when calculating the semiperimeter.

This is code-golf; so the shortest submission in each language is the winner, and will be honored with a parade at some vague time in the near future.

Notes:

Just wanted to get this down; will edit later. Mulling whether to have output be the integer, or an example layout having the minimal perimeter. The former is simpler to construct; but the latter just seems more satisfying as an output.

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

The Roly-Poly, Square-Wheeled Quine

Moved here. Thank you for the comments.

\$\endgroup\$
7
  • \$\begingroup\$ I feel like the whitespace rule is not really necessary, except for maybe just newlines? If my code is just whitespace does that mean I just have to output 6 newlines? \$\endgroup\$
    – Jo King Mod
    Jul 29 at 2:45
  • \$\begingroup\$ I'm not following how you are using "is". Do you mean if your code contains whitespace? Or do I need to specify some minimum n? Thanks. \$\endgroup\$
    – DjinTonic
    Jul 29 at 2:52
  • \$\begingroup\$ For example, the language Whitespace is composed of only three whitespace characters. What should that be outputting? \$\endgroup\$
    – Jo King Mod
    Jul 29 at 3:17
  • \$\begingroup\$ Wouldn't a minimum n x n square of non-blank characters take care of that? Non-whitespace characters that generate whitespace are fine. \$\endgroup\$
    – DjinTonic
    Jul 29 at 3:24
  • \$\begingroup\$ I looked Whitespace up. I don't think it can play if its output is encoded as whitespace between characters. Goodness, is it that popular? \$\endgroup\$
    – DjinTonic
    Jul 29 at 3:35
  • \$\begingroup\$ The output for Whitespace isn't encoded in any special way. A minimum of n being 1 would solve some problems sure, but my initial complaint is that I don't see why spaces should be treated any different from any other character. Newlines make sense sure, but not spaces or tabs (though this still leads to an issue with Unary). On the other hand, the scoring mechanism is still bytes, so I guess it isn't really abusable \$\endgroup\$
    – Jo King Mod
    Jul 29 at 3:46
  • \$\begingroup\$ Esthetically I like the idea of code output resembling a car leaving a car compactor. I see the code being on any number of lines desired as long as output is squares. \$\endgroup\$
    – DjinTonic
    Jul 29 at 3:52
0
\$\begingroup\$

Your challenge is to write a method that compresses/decompresses strings. It will get two arguments: any string (with any ASCII characters) to compress/decompress, and a boolean. If the boolean is true, compress, else decompress.

It can either print the output to stdout or return the data.

The twist is that your score is equal to the byte count of your source code + the byte count of your source code compressed by the compressor. So if your code was c=>c (which is invalid btw), your score would be 4 + 4 = 8.

Rules

  • Standard loopholes not allowed

  • The decompression and compression should work.

  • Your code should not just return the same data. So this

    c=>c
    

    is invalid

Test function to check the score

If you like, here's a function which checks your (javascript) answer.

function checkCompressor(compressor) {
    const source = compressor.toString();
    const compressed = compressor(source, true);
    const decompressed = compressor(compressed, false);
    if (source !== decompressed) return false;
    return compressed; // Have to get byte count manually
}
\$\endgroup\$
4
  • \$\begingroup\$ What are the possible input ranges for the compressor and the decompressor? Is it allowed for a compressor to output something longer than the input for some inputs? Under the current rules, it looks like I can get a score of 0 by doing if input == itself, return empty string; otherwise do something else. \$\endgroup\$
    – Bubbler
    Jul 30 at 4:20
  • \$\begingroup\$ @Bubbler nice catch! I've updated the question a bit, to account for these cases \$\endgroup\$ Jul 30 at 4:32
  • \$\begingroup\$ "any characters" doesn't look objective to me. Does it include full Unicode range, or just ASCII or Latin-1, for example? Is the length of the compression measured in characters or bytes? \$\endgroup\$
    – Bubbler
    Jul 30 at 4:36
  • \$\begingroup\$ @Bubbler Any characters were supposed to mean any and all characters, but I think that's a bit too much, so i'm changing it to ascii for now. The length of compression is measured in bytes \$\endgroup\$ Jul 30 at 6:44
0
\$\begingroup\$

Convince me that this vector theorem is true

Background Information

From Wikipedia:

A sequence of vectors \$\mathbf v_1,\mathbf v_2,\mathbf v_3,\dots,\mathbf v_k\$ from a vector space \$V\$ is said to be linearly dependent, if there exists scalars \$a_1,a_2,\dots,a_k\$ such that: $$a_1\mathbf v_1+a_2\mathbf v_2+\cdots+a_k\mathbf v_k=\mathbf 0$$ where \$\mathbf 0\$ denotes the zero vector.

Based on many sources1 around the internet, it is true that

If there are more vectors than dimensions, the vectors are linearly dependent.

In other words, if the vector space is \$\mathbb R^n\$(the number of entries in each vector is \$n\$), then the sequence of vectors \$\mathbf v_1,\mathbf v_2,\dots,\mathbf v_p\$ is always linearly dependent if \$p>n\ge2\$.

Task

After looking around, I'm still not entirely convinced that the above statement is true. Please convince me with a program that takes in: the dimension \$n\$(you don't have to take this in if you don't need to), and \$p\$ \$n\$-dimensional vectors \$\mathbf v_1,\mathbf v_2,\dots,\mathbf v_p\$, where \$p>n\ge2\$. You can take in \$p\$ in your program if you want to. You can assume that all vector entries in each vector are integer values. The input format can be whatever you choose, as long as there is a clear distinction between each vector. The program should return a list of scalars \$a_1,a_2,\dots,a_p\$, with at least one of them non-zero, such that $$a_1\mathbf v_1+a_2\mathbf v_2+\cdots+a_p\mathbf v_p=\mathbf 0$$ to show linear dependency. If there are multiple outputs that work, you can output any one of them. The output format is also flexible, as long as it is clear what the values of each scalar are.

This is , so the shortest code in bytes wins!

Example I/O

Input:
\$n=2\$
\$p=3\$
\$\mathbf v_1,\mathbf v_2,\dots,\mathbf v_p=\pmatrix{4\\5},\pmatrix{8\\10},\pmatrix{6\\7}\$

Output:
One possible solution is \$a_1,a_2,\dots,a_p=2,-1,0\$. We can quickly test that this does work: $$2\pmatrix{4\\5}+(-1)\pmatrix{8\\10}+0\pmatrix{6\\7}=\pmatrix{8\\10}-\pmatrix{8\\10}+\pmatrix{0\\0}=\pmatrix{0\\0}=\mathbf 0$$

Test Cases:

Work in progress

n, vectors -> scalars
2, [(4,5),(8,10),(6,7)] -> [2,-1,0]
2, [(3,6),(6,7),(3,9),(2,4),(5,5)] -> [2,0,0,-3,0]
3, [(1,2,3),(2,3,4),(3,4,5),(4,5,6),(5,6,7),(6,7,8),(7,8,9),(8,9,10)] -> [1,-1,-1,1,1,-1,-1,1]

1: Some sources: this, this, this, this


Concerns

  • Has a similar challenge been done before?
  • Is it clear what the challenge is specifying?
  • I want to change the title to be more specific, but I'm not sure what to change it to.
  • I need some test cases, but I'm not sure what test cases would be good for this.
\$\endgroup\$
3
  • \$\begingroup\$ A possible title would be "Solve a linear equation system" or "Find a kernel vector" \$\endgroup\$
    – NieDzejkob
    Aug 15 at 22:13
  • \$\begingroup\$ "\$n\geq 2\$" is superfluous. \$\endgroup\$ Sep 5 at 22:30
  • \$\begingroup\$ I do not quite understand the premise, since a vector space's dimension is defined to be its basis' length. Thus if you are not convinced your statement is true you should not accept \$K^n\$ to have dimension \$n\$. \$\endgroup\$ Sep 5 at 22:33
0
\$\begingroup\$

All valid N * N Flow Free Boards.

Since there are several other Flow Free question, either here or on main, but none, as far as I can tell, that do this, I will ask the question some of us have pondered at night: How many valid Flow Free Boards are there?

What is a valid board?

From what I can tell from my attempts at time trial, a valid board has all of these:

  1. Has between floor(2N/3) and ceil(3N/2) flows (where a flow is two distinct points, defined as it's ends, between which a line can be drawn connecting them).

  2. No two endpoints of a flow can be adjacent.

  3. The board must be solvable - that is, there must be a way that all endpoints of the flows can be connected together such that every square of the board is filled once and only once, and no two paths intersect at all.

Input/Output

Your program will receive N, the side length of the board. The board will always be square (as that is the case in most boards), and it must return all valid boards, and the number of such boards.

As always, you can take input and output in any reasonable format, and shortest byte count wins!

Meta

Has this been done before?

Anything that needs specifying?

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

Who Won Tic-Tac-Toe?

Your job is to be the judge of a game of Tic-Tac-Toe.

Given an input consisting of three lines (9 characters not including newlines), determine the winner of the game of Tic-Tac-Toe.

For example, for the input

XOO
-XO
O-X

your program should either return or print X.

For tie games or games where no one has won, do not print or return anything.

The only input characters will be 'X', 'O', and '-' (along with two newlines), and the only outputs your program should give are 'X' and 'O' (or nothing).

Also note that the given board will be a valid game of Tic-Tac-Toe, so there will be no situations where both players have winning positions.

More examples:

OOO
---
---

=> O

OXO
--X
---

=> (nothing)

OXO
X-O
X-O

=> O

OXO
XOX
XOX

=> (nothing)

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

Tic-Tac Clock

given a time of the day (0-12 inclusive) output the closest fitting clock. This means 0/12, 3, 6 and 9 should be straight up/to the side. The one's in between go in the corners!

The clock should look as follows:

      #|#
0  -> #+#
      ###

      ##/
1  -> #+#
      ###

      ##/
2  -> #+#
      ###

      ###
3  -> #+-
      ###

      ###
4  -> #+#
      ##\

      ###
5  -> #+#
      ##\

      ###
6  -> #+#
      #|#

      ###
7  -> #+#
      /##

      ###
8  -> #+#
      /##

      ###
9  -> -+#
      ###

      \##
10 -> #+#
      ###

      \##
11 -> #+#
      ###

      #|#
12 -> #+#
      ###

This is code-golf so the shortest answer (per language) in bytes wins.

questions

This is my first question so I'd appreciate some feedback, mainly if this challenge would be too tedious to do.

\$\endgroup\$
3
  • 1
    \$\begingroup\$ Given that the input is limited to 1 through 12, I'd suggest just showing what each output should be for all the possible inputs, just to avoid any confusion \$\endgroup\$ Aug 22 at 1:29
  • \$\begingroup\$ That sounds reasonable. Will edit it. Do you think this would be good to post on the main site otherwise? \$\endgroup\$
    – Jadefalke
    Aug 22 at 7:57
  • 1
    \$\begingroup\$ Overall, looks good (though I haven't done any dupe searching). One thing I'd clarify a bit would be the output format - can it be any characters, or does it have to match as shown? Can the output be a list of lines, or does it have to be a multi line string? Etc. \$\endgroup\$ Aug 22 at 8:28
0
\$\begingroup\$

Add 2 numbers using a graphics card

Introduction

Graphics cards have great performance when doing big calculations. So lets make a small calculation

Challenge

  • Inputs: 2 floats of choice

  • output: the addition of the two floats.

  • The addition should be calculated on the graphics card, but it doesn't matter if it doesn't work on all gpu's

  • Lowest score in bytes wins

Example Input and Output

2.5 and 3.2 -> 5.7

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

Implement the LC-3 VM [1] using 16-bit subneg4 [2] only & test it

\$\endgroup\$
2
  • \$\begingroup\$ Welcome to Code Golf, and thank you for using the Sandbox! We require challenges to be self-contained; you should fully explain the terms/acronyms used, as well as anything else relevant to the challenge - in short, imagine you're explaining this to someone who knows nothing about it. I'd also suggest removing the time limit, and explain the winning criteria better \$\endgroup\$ Aug 18 at 0:36
  • \$\begingroup\$ Welcome to Code Golf! The scoring criteria are kinda confusing for people who are new to such system, you may want to add some scoring examples because it's very unique compare to ordinary code-golf. \$\endgroup\$
    – okie
    Aug 18 at 2:36
0
\$\begingroup\$

What will the radio play next week?

Each week, Billboard publishes the US music industry standard ranking of the 100 most popular songs based on sales, radio play, and online streaming. The current chart can be found here.

For each song on the chart, Billboard reports the song's current ranking (from 1 to 100, with 1 being the best), the previous week's ranking of that song (labeled "last week"), the best ranking that the song has ever received by Billboard (labeled "peak"), and the number of weeks that the song has appeared on Billboard charts to date (labeled "wks on chart").

Pop stations in the US generally play the top 40 most popular songs on a given week. In this challenge, we will predict what the radio will play next week given previous Billboard charts.

The Data

This text file provides the "last week" data for every chart from July 25, 2015 though July 17, 2021 (based on data provided here). There are 313 lines (one for each week) with 100 comma-separated numbers in each line. The first line corresponds to July 25, 2015, and on that week's chart, "Cheerleader" by OMI was ranked #1 (up from #2 the previous week), while Chris Young's "I'm Comin' Over" made its debut on the chart at #100. In the first line of the data provided, this is reflected with the first entry being 2 and the last entry being 101 (throughout, 101 indicates that the song did not chart on the previous week). The next line of the data starts with a 1, indicating that OMI's "Cheerleader" was still ranked #1 on the August 1, 2015 chart. In this way, the data captures how songs move up and down the chart from week to week.

The Challenge

Write a program or function that, for each n from 0 to 312, receives the first n lines of the data as input and outputs the first 40 numbers from line n+1.

Standard rules apply. The shortest code in bytes wins.

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

Binary integer subtraction a - b with 0 < b < a using string processing logic

My Work

I noticed that for this subtraction problem it is not necessary to use twos-complement and that the result can be stored in the same memory required to store a; all that is required is to employ symbolic/logic processing on bit/char-strings.

I wrote a Python program that uses divmod, but that was just a way of 'shifting-off' the right most bit from the bitstring, so the code-golf answers should not use any arithmetical operations.

Here is my program, which can be taken to solve an implicit string processing specification:

minuend =    int(10**1111)
subtrahend = int(10**1110)

if True: #debugging
    minuend =    0b110101
    subtrahend = 0b000111
    M = minuend
    S = subtrahend

difference = ''
while 1: #State 0
    if minuend == 0:
        break
    minuend, m_right_bit = divmod(minuend, 2)
    subtrahend, s_right_bit = divmod(subtrahend, 2)        
    if     m_right_bit == 0 and s_right_bit == 0:
        difference = '0' + difference
    elif   m_right_bit == 1 and s_right_bit == 0:
        difference = '1' + difference
    elif   m_right_bit == 1 and s_right_bit == 1:
        difference = '0' + difference
    else:# m_right_bit == 0 and s_right_bit == 1:
        #State 1
        difference = '1' + difference
        while 1: #State 1
            if minuend == 0:
                break
            minuend, m_right_bit = divmod(minuend, 2)
            subtrahend, s_right_bit = divmod(subtrahend, 2)        
            if     m_right_bit == 0 and s_right_bit == 0:
                difference = '1' + difference
            elif   m_right_bit == 0 and s_right_bit == 1:
                difference = '0' + difference
            elif   m_right_bit == 1 and s_right_bit == 1:
                difference = '1' + difference
            else:# m_right_bit == 1 and s_right_bit == 0:
                difference = '0' + difference
                break # back to State 0     
            continue
    continue

if True: #debugging
    print('Answer (subtraction):', difference)    
    if int(difference, 2) != M -S:
        print('Program failed...')

raise SystemExit

Challenge

Code to perform the same subtraction as my Python program; no output should be produced.

Standard rules apply. The shortest code in bytes wins.

\$\endgroup\$
1
  • \$\begingroup\$ Unfortunately, this is not how challenges work on our site. A code-golf challenge should be defined in terms of input and output, not by some internal behavior. Behavior (or algorithm) requirements are non-observable. \$\endgroup\$
    – Bubbler
    Sep 14 at 1:12
0
\$\begingroup\$

Multiple Averages

In math, the average or mean of a range of numbers is in the middle of all of the numbers. The farthest number in the range from the average is as close as possible to it. So, to find multiple averages of a range of numbers, one would have to find numbers that best represent the numbers in the collection that are closest to them.

For example, the two averages of the range from 1 to 5 are 2 and 4. 2 represents the numbers 1-3, while 4 represents the numbers 3-5. Below is a diagram to help understand why these numbers best represent the range.

enter image description here

A simple way to calculate the averages is to divide the range into equal parts and calculate the average of each part. For the previous example, the average of 1-3 is 2 and the average of 3-5 is 4.

Challenge

Create a program that takes three inputs: a number f, another number l and a positive integer n, and outputs the n averages of the range of integers from f to l, inclusive. Assume that there are n or more numbers within this range.

Rules

  • Output can be a list/array or a string of numbers separated by spaces.
  • The order of the output does not matter.
  • Standard loopholes are not allowed.
  • This is code-golf, so the shortest code wins.

Test Cases

f l n Output
1 3 2 1.5, 2.5
5 5 1 5
4 25 2 9.25, 19.75
42 -4 3 3.666..., 19, 34.333...
0 27 4 3.375, 10.125, 16.875, 23.625
7 2.5 3 3.25, 4.75, 6.25

Sandbox Questions

  • Is the explanation clear enough?
  • Is this challenge fit for ?
  • Is this challenge too hard or easy?
  • What should be changed?
\$\endgroup\$
3
  • 3
    \$\begingroup\$ I don't understand the explanation at all (I know this isn't helpful feedback). Perhaps a test case, ideally with a step-by-step on how to get from the input to the output, will help us improve the explanation. Primarily, I don't understand how exactly you get multiple averages out of a list; isn't there just the one average being the sum divided by the count? \$\endgroup\$
    – hyper-neutrino Mod
    Sep 7 at 3:05
  • \$\begingroup\$ Answer to questions: 1. No, I can't understand what's gonna happen. 2. Yes, it is since it's most likely to be tasked with the shortest code possible. 3. It sounds easy, but no worries, challenges are not weighed by the difficulty, but it's fun. 4. Explanation, and you may want to add rule and winning criteria. \$\endgroup\$
    – okie
    Sep 7 at 3:11
  • \$\begingroup\$ I'll try to fix the explanation and make it clearer. Thanks for the suggestions. \$\endgroup\$
    – Yousername
    Sep 7 at 14:39
0
\$\begingroup\$

Most Contrasting Background Color

When putting colored text on a background, the text can sometimes be hard to read because the text color does not contrast with the background color well. Thus, this challenge will be to create a function or program that can find the most contrasting background color for a given text color.

Challenge

Create a function or program that takes a text color (in RGB format) and outputs the farthest color from the text color, which would be either "black" or "white" as a string. This will be based on the relative luminance of the text color, which is an approximation of how light or dark a color is based on human perception. The relative luminance can be calculated with this formula:

\$Y=0.2126R+0.7152G+0.0722B\$

If the relative luminance is closer to 255 (white), then the program should output "black" and vice versa.

Rules

  • Output should be a string: "black" or "white".
  • Standard loopholes are not allowed.
  • This is code-golf, so the shortest code wins.

Test Cases

Input Output
255, 0, 0 "white"
0, 0, 0 "white"
255, 255, 255 "black"
0, 255, 255 "black"
133, 193, 230 "black"
100, 62, 139 "white"
128, 128, 128 "black"

Sandbox Questions

  • Is this a dupe?
  • Is the challenge clear enough?
  • What should be changed?
\$\endgroup\$
1
  • \$\begingroup\$ You should probably add an explanation for what relative luminance actually is. \$\endgroup\$
    – Aiden4
    Sep 9 at 16:25
0
\$\begingroup\$

Unlolify a lolified message!

\$\endgroup\$
4
  • 1
    \$\begingroup\$ Welcome to the site! And thank you for using the sandbox. I'm not sure what is meant by rule #2 could you clarify it further? \$\endgroup\$
    – Grain Ghost Mod
    Sep 7 at 12:30
  • \$\begingroup\$ @WheatWizard Updated 1 and 2, trying to clarify it. Let me know if it's better :) \$\endgroup\$ Sep 7 at 13:42
  • \$\begingroup\$ Ok, this is clearer. Unicode however is not an encoding. UTF-8 and UTF-16 are encodings both of which are ASCII compliant. Do you mean to say that the decoded string will only ever contain bytes less than 256? \$\endgroup\$
    – Grain Ghost Mod
    Sep 7 at 14:08
  • \$\begingroup\$ Yes, I mean to say the decoded string will only have bytes less than 256! I meant to say that the whole Unicode isn't supported, but you are right -- ASCII is contained within it anyway. Edited trying to make that more clear, please let me know if you think if it's clear or what could improve! \$\endgroup\$ Sep 8 at 11:48
0
\$\begingroup\$

Implement a tag system simulator

\$\endgroup\$
2
  • \$\begingroup\$ I've edited this down to a stub now that it's been posted to save space \$\endgroup\$ Sep 12 at 16:26
  • \$\begingroup\$ Thanks, I forgot to do that. \$\endgroup\$
    – Pyautogui
    Sep 12 at 16:44
0
\$\begingroup\$

Convert chessboards to algebraic notation


Note: this is "simple" algebraic notation. It is only based off of my very limited knowledge. En passant, draw offers, disambiguation etc are not included and no bonuses will be given for handling those cases.

Algebraic notation is a compact, universal chess notation which provides an easy method of communication between two chess players. There are many apps that can convert a game of chess into algebraic notation given a list of boards; in this challenge you will write one as well.

Before I go over the challenge details, here's a quick crash course of algebraic notation.

Castling: there are two types of castling: kingside castling, the "short" way, and queenside castling, the "long" way. The short way is denoted as O-O (or 0-0) and the long way is O-O-O (or 0-0-0). When castling is performed, the king and rook both move at the same time, making castling the only occasion when two pieces can move at the same time.

K..R -> .RK. (kingside)
R...K -> ..KR. (queenside)

Other moves: the rest of the time, only a single piece moves. The move's anatomy in algebraic notation looks like this:

  • the first character is the piece type, except when a pawn is moving. In the case of the pawn the piece type is not included. Otherwise, a knight is N, king is K, rook is R, queen is Q and bishop is B.
  • next, we add x if the move is a capture. If not add nothing.
  • Then, as a chessboard "coordinate", the position that piece is moving to. For example a4, b5 etc:
a8 b8 c8 d8 e8 f8 g8 h8
a7 b7 c7 d7 e7 f7 g7 h7
a6 b6 c6 d6 e6 f6 g6 h6
a5 b5 c5 d5 e5 f5 g5 h5
a4 b4 c4 d4 e4 f4 g4 h4
a3 b3 c3 d3 e3 f3 g3 h3
a2 b2 c2 d2 e2 f2 g2 h2
a1 b1 c1 d1 e1 f1 g1 h1

So a pawn moving to e4 would be e4, a bishop moving to h5 capturing a piece there would be Bxh5, a rook moving to g6 would be Rg6, etc. Note that pawn capturing at e4 would be xe4.

An additional character is placed at the end in certain circumstances: if the move makes the moving side "check" the opposing side then a + is added. For checkmates we add # instead. Note that this applies to castling as well (O-O+).

I will ignore en passant for this challenge.

Now, for the challenge itself...

You will take in a sequence of boards representing an entire game, and output its corresponding algebraic notation.

I don't really care how you take the boards. You could take in a FEN string:

rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR

or a 8-line, 8-column board:

rnbqkbnr
pppppppp
........
........
........
........
PPPPPPPP
RNBQKBNR

or a list of pieces:

['W', 'R', 'a8'], ...

or whatever else is reasonable. I will not accept taking in algebraic notation-like strings like Ra8 Kb7, for instance. You can take in a list of boards, double-newline separated, etc.

For each board you must output the algebraic notation of the move from the previous board to the current board by inferring the move from the difference between the boards, along with any necessary pluses and hashes in case the move is a check or checkmate. You must output the correct algebraic notation, but the end "list" can be of any format: a list, space-separated, newline-separated, etc. I don't really care as long as it is reasonable.

Example

Two boards have been given.

rnbqkbnr
pppppppp
........
........
........
........
PPPPPPPP
RNBQKBNR

rnbqkbnr
pppppppp
........
........
........
.......N
PPPPPPPP
RNBQKB.R

Output:

Nh3

Another example:

....k...
........
........
K.......
....b...
....R...
........
.q......

....k...
........
........
K.......
....R...
........
........
.q......

Output:

Rxe4+

And finally, the Fool's mate with black castling once:

rnbqkbnr
pppppppp
........
........
........
........
PPPPPPPP
RNBQKBNR

rnbqkbnr
pppppppp
........
........
........
.....P..
PPPPP.PP
RNBQKBNR

rnbqkbnr
pppp.ppp
....p...
........
........
.....P..
PPPPP.PP
RNBQKBNR

rnbqkbnr
pppp.ppp
....p...
........
......P.
.....P..
PPPPP..P
RNBQKBNR

rnbqkb.r
pppp.ppp
....p..n
........
......P.
.....P..
PPPPP..P
RNBQKBNR

rnbqkb.r
pppp.ppp
....p..n
........
......P.
P....P..
.PPPP..P
RNBQKBNR

rnbqk..r
pppp.ppp
...bp..n
........
......P.
P....P..
.PPPP..P
RNBQKBNR

rnbqk..r
pppp.ppp
...bp..n
........
......P.
PP...P..
..PPP..P
RNBQKBNR

rnbq.rk.
pppp.ppp
...bp..n
........
......P.
PP...P..
..PPP..P
RNBQKBNR

rnbq.rk.
pppp.ppp
...bp..n
........
......P.
PP...P..
R.PPP..P
.NBQKBNR

rnb..rk.
pppp.ppp
...bp..n
........
......Pq
PP...P..
R.PPP..P
.NBQKBNR

Output:

f3 e6 g4 Nh6 a3 Bd6 b3 O-O Ra2 Qh4#

This is , so the winner is the answer with the least bytes.


Meta: is this a duplicate? How could I improve the challenge further?

\$\endgroup\$
5
  • \$\begingroup\$ Not a dupe, but a lot more complex than it seems. Also, there are several ways to get to one position, and some involve backtracking - for example, how would an algorithm know how to get to a position with one black pawn advanced two squares? \$\endgroup\$
    – emanresu A
    Sep 13 at 10:24
  • \$\begingroup\$ @emanresuA This is "simple" algebraic notation, in the sense that any more complex types of moves are not considered. I'm not much of a chess expert myself. \$\endgroup\$
    – ykcul
    Sep 13 at 10:26
  • \$\begingroup\$ What about, say, Nf4 d5 Ng1, with backtracking, and that's the only way to make it valid? \$\endgroup\$
    – emanresu A
    Sep 13 at 10:50
  • \$\begingroup\$ I know a little about chess, and no nothing about algebraic notation before. I'm confused that won't this cause ambiguous? Also, "check" and "checkmate" makes this challenge too complex, imo. \$\endgroup\$
    – tsh
    Sep 17 at 3:24
  • \$\begingroup\$ @tsh: I think it makes it more interesting, and more accurate as well as we are producing "more real" algebraic notation. I agree about ambiguities, but in the opening I decided that there would be no "disambiguation", partly because I'm not very familiar with the topic myself. \$\endgroup\$
    – ykcul
    Sep 17 at 15:11
0
\$\begingroup\$

Make a number serious

I'm a big fan of silly challenges, but I'm afraid we're going to have to get serious. It's time to get rid of the lols.

Or rather, the 101s, which look quite a bit like lols.

Task:

Take an integer as input. You'll make this number serious by removing the 101s from the number's binary representation. Now, particularly good jokes sometimes elicit lolols or even l(ol)+s from numbers, so we must get rid of these too.

\$\endgroup\$
4
  • 1
    \$\begingroup\$ I suspect everything will be along the lines of x.toString(2).replace(/(10)+1/g,'') \$\endgroup\$
    – emanresu A
    Sep 14 at 7:39
  • \$\begingroup\$ Clarification: do we output the binary or the base10? Or whatever base we want? \$\endgroup\$
    – ykcul
    Sep 14 at 11:13
  • \$\begingroup\$ @ykcul Must be number/decimal input and output, not a binary string \$\endgroup\$ Sep 14 at 13:26
  • 1
    \$\begingroup\$ @emanresuA Well, parseInt(x.toString(2).replace(/(10)+1/g,''),2) :p \$\endgroup\$ Sep 14 at 13:27
1
104 105
106
107 108
119

You must log in to answer this question.

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