569
\$\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

4562 Answers 4562

1
134 135
136
137 138
153
0
\$\begingroup\$

Four Candles

There is a tradition in Germany to have an Adventskranz in the run up to Christmas. This is basically four candles. One is lit each Sunday during advent (including the ones from the last Sundays) up until Christmas. This gave me an idea for an ASCII art challenge (we haven't had many of those recently).

The challenge: Reproduce the burning of the candles exactly as shown below.

  ||     ||     ||     ||   
 ____   ____   ____   ____
|    | |    | |    | |    |
|    | |    | |    | |    |
|    | |    | |    | |    |
|____| |___ | |____| |____|

         ||     ||     ||   
  ()    ____   ____   ____
 ____  |    | |    | |    |
|    | |    | |    | |    |
|    | |    | |    | |    |
|____| |___ | |____| |____|

                ||     ||   
         ()    ____   ____
  ()    ____  |    | |    |
 ____  |    | |    | |    |
|    | |    | |    | |    |
|____| |___ | |____| |____|

                       ||   
                ()    ____
         ()    ____  |    |
  ()    ____  |    | |    |
 ____  |    | |    | |    |
|____| |___ | |____| |____|

                       ()
                ()    ____
         ()    ____  |    |
  ()    ____  |    | |    |
______ |___ | |____| |____|

The rules: Very simple really...no input required, any amout of trailing newlines or spaces alowed as long as the output looks exactly as above. Please feel free to show each stage as a different frame and clear the screen between each but this is not a requirement. Simply printing (or retuning from a function) what is shown above is fine. Oh and also, this is ASCII art...printing or returning a list of lines is not good enough.

This is code golf. The shortest answer in any language will earn respect and I'm sure some upvotes. There will be no accepted answer so feel free to join in. The more languages the better no matter how long the answer is, as long as it is a best effort to make it as short as possible (golfed).

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

Make the cheapest cut

\$\endgroup\$
2
  • 1
    \$\begingroup\$ I suggest allowing also outputting all cuts if there are ties, not just any; or guaranteeing unique solution (this is my personal preference, but I understand other views on that matter). Re 2.: Yes, some test-cases would be nice. \$\endgroup\$
    – pajonk
    Dec 1, 2022 at 13:45
  • \$\begingroup\$ @pajonk Good feedback, thanks. \$\endgroup\$
    – Jordan
    Dec 1, 2022 at 15:31
0
\$\begingroup\$

Find the box by its corners

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

Denoise a image

There are various de-noising algorithms available. This question focuses on a specific one that preserves sharp edges but is also very simple to implement.

Take 2 parameters, r and k, and a grayscale image.

For every pixel, draw a r by r square around it and select all pixels inside.

 r=1   r=3     r=5
              #####
       ###    #####
  p    #p#    ##p##
       ###    #####
              #####

Find the k pixels in this area that are closest to the source pixel in terms of absolute color difference.

Replace each pixel with the median of the k closest pixels in it's area. Include the pixel itself in it's area. If there are less than k closest pixels take all of them. This can happen for pixels near the edge.

Note: If r==0 or k==1 this will return the image unchanged

r is always odd.

Test Cases

In    K    R    Out
-------------------
000             000
010   1    1    010
000             000
-------------------
000             000
010    3    3   000
000             000
-------------------
000             000
010    3    3   010
100             100
-------------------
000             000    000
010    5    3   010 OR 010 since the median is tied
101             000    101
-------------------
12345           
23451
34512  5    5
45123
51234
-------------------

IO

Take input as either a image file or as a 2 dimensional array of integers between 0 and 255. Output in the same format.

\$\endgroup\$
1
  • \$\begingroup\$ The input requirements are not clear to me - what do you mean by a "greyscale image"? An image file? A matrix of floats from [0-1]? An integer matrix (as suggested by test-cases)? \$\endgroup\$
    – pajonk
    Dec 5, 2022 at 12:50
0
\$\begingroup\$

Is It a Flat 3D Quadrilateral?

Your task is to write a program or function that, given a collection of four 3D points with Cartesian coordinates, outputs whether the shape formed by connecting those points is a flat 3D quadrilateral (i.e. all the points are coplanar).

Rules

  • The input will always have 4 points.
  • Each shape will be formed by connecting the points with lines in the order they were given and then back to the first point. You may assume that no two of these lines will intersect each other and that no three consecutive points will be collinear.
  • For each point \$(x, y, z)\$, \$x\$, \$y\$, and \$z\$ will all be integers within the range \$[0,8]\$.
  • You may choose any two distinct values to represent a truthy and falsy output, as long as it is consistent. Input can be in any convenient format.
  • This is , so the shortest code in bytes wins.

Test Cases

Input Output
(0, 0, 0) (0, 1, 0) (1, 2, 0) (1, 0, 0) true
(0, 0, 0) (0, 1, 0) (0, 0, 1) (1, 0, 0) false
(0, 0, 0) (1, 0, 0) (1, 1, 1) (0, 1, 1) true
(0, 1, 2) (3, 4, 6) (7, 8, 5) (4, 3, 2) false
(1, 1, 1) (2, 2, 2) (1, 3, 2) (2, 4, 5) false
(0, 4, 8) (4, 8, 4) (8, 4, 0) (4, 0, 4) true

Meta

  • Any additional test case suggestions?
\$\endgroup\$
2
  • \$\begingroup\$ I suggest that the input has exactly 4 points. The main approach will be anyway to check if the fourth point is coplanar with other 3, and then the fifth and so on, so maybe stick to the first task not to lose the main focus of the challenge? \$\endgroup\$
    – pajonk
    Dec 6, 2022 at 9:16
  • \$\begingroup\$ @pajonk That makes sense; I will change that. \$\endgroup\$
    – Yousername
    Dec 6, 2022 at 14:31
0
\$\begingroup\$

Find the representative submatrix

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

Rolling a 1x1x2 block

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

Write a program that prints a program that's almost quine.

\$\endgroup\$
5
  • \$\begingroup\$ So basically, we write a program, which given n, prints a program which prints its own first n characters, which are also the first n characters of all other programs that can be outputted? And the program has to be irreducible? \$\endgroup\$ Dec 4, 2022 at 2:58
  • \$\begingroup\$ @RadvylfPrograms Correct. \$\endgroup\$
    – Fmbalbuena
    Dec 4, 2022 at 15:58
  • \$\begingroup\$ What should the program do if input number is greater than its length? For example, my program has only 10 bytes, and i got an input 100. \$\endgroup\$
    – tsh
    Dec 15, 2022 at 7:14
  • \$\begingroup\$ Maybe you should define what irreducible is in your question. \$\endgroup\$
    – tsh
    Dec 15, 2022 at 7:18
  • \$\begingroup\$ @tsh The challenge is already uploaded. \$\endgroup\$
    – Fmbalbuena
    Dec 15, 2022 at 15:29
0
\$\begingroup\$

Balanced Candy Distribution

There are 4 piles with 12 pieces of candy each, for a total of 48 pieces, and there are 12 kids to split that candy with, each kid will receive exactly 1 piece of candy from each pile, each piece of candy has a unique number on it, from 0 to 47, the candies with numbers 0 through 11 are on one pile, candies number 12 through 23 are on another, candies 24 through 35 are on a pile, and the last pile is candies 36 to 47. Candy #0 tastes amazing, and candy #47 tastes not so great, so to make it fair, each kid’s 4 candies should add up to the same number (which should be 94), there is an issue though, there are an unknown number of different flavors of candy, completely independent of their tastiness, and it would be unfair if Timmy was to, by bad luck, have all his 4 pieces of candy end up being cinnamon flavored, so, we introduce the idea of “Unfairness points”. For each kid, if we match each of their four candy pieces to their other three candies, for each pairing if both candies are the same flavor, we add one unfairness point, to illustrate this, let’s imagine a smaller example, with only four kids and 16 candies, if Timmy got 4 cinnamon candies, Laura got 1 cinnamon candy, 1 vanilla candy, and 2 chocolate candy, Johnny got 2 vanilla candies and 2 caramel candies, and Sam got 3 cinnamon candy and 1 strawberry candy, this arrangement would receive 12 unfairness points: 6 from Timmy, 1 from Laura, 2 from Johnny, and 3 from Sam.

Your code must output the arrangement that satisfies the two restrictions set forth in the beginning (each kid receives a single candy from each pile, and that for each kid all of their four candies add up to 94) that has the fewest unfairness points, if there is more than one arrangement that is tied for least number of unfairness points, you must output the list of all of those arrangements given a list of all the candies. This input could be formatted in any way that is convenient, but preferably something resembling a list of strings, where the index is the number of the candy and the string is the flavor, for example, in python, a valid input format would be

[“Chocolate”,“Chocolate”,“Chocolate”,“Vanilla”,“Chocolate”,“Apple”,“Chocolate”,“Vanilla”,“Caramel”,“Chocolate”,“Vanilla”,“Chocolate”,“Apple”,“Apple”,“Caramel”,“Chocolate”,“Vanilla”,“Chocolate”,“Apple”,“Sour”,“Chocolate”,“Chocolate”,“Vanilla”,“Chocolate”,“Apple”,“Sour”,“Pear”,“Pear”,“Caramel”,“Vanilla”,“Vanilla”,“Vanilla”,“Apple”,“Sour”,“Chocolate”,“Chocolate”,“Avocado”,“Apple”,“Sour”,“Pear”,“Pear”,“Chocolate”,“Chocolate”,“Chocolate”,“Vanilla”,“Chocolate”,“Vanilla”,“Caramel”]

Or it could also be already separated into the piles

[[“Chocolate”,“Chocolate”,“Chocolate”,“Vanilla”,“Chocolate”,“Apple”,“Chocolate”,“Vanilla”,“Caramel”,“Chocolate”,“Vanilla”,“Chocolate”],[“Apple”,“Ap...

Or it could include the number itself, if you wanted

[[0,“Chocolate”],[1,“Chocolate”],[2,“Chocolate”],[3,“Vanilla”],[4,“Chocolate”],[5,“Apple”],[6,“Chocola...

The output can be given in any way that makes it easy to interpret what the numbers of the candies each kid should get, for example, in python, an output like

[[0,19,30,45],[9,14,28,43],[5...

Is totally fine, and anything that is easy or understandable like that is fine.

This is code-golf and so lowest bytes wins


Sandbox questions:

  • English is my second language, is this written clearly enough?
  • Would it be better if it was generalized? As in "There are N piles with C pieces of candy each, for a total of N*C pieces, and there are C kids to split that candy with, each kid will receive exactly 1 piece of candy from each pile..."
  • Any other thoughts?
\$\endgroup\$
0
\$\begingroup\$

Wordle games without repeating letters

Given a word list, find all sets of five words of five letters each, such that the words of each set have 25 distinct letters in total.

This challenge was inspired by this video by Matt Parker.

Example

TODO

Rules

  • Standard I/O rules apply.
  • Words contain only lowercase (or alternatively, uppercase) alphabetic characters.
  • You can assume there are no empty words (i.e. words of length zero).
  • The input can contain words that cannot belong to any set that satisfies the property, such as words with less then five letters, words with more than five letters, and words with repeated letters.
### Scoring

This challenge wants to be an experimental mix of and .

If your solution has:

  • a time complexity of \$\Omega(f(n))\$ (see Big Omega notation) where \$f: \mathbb N \to \mathbb N\$ is a function of the form $$f(n) = (\log_2 \log_2 n)^{k_{-2}} \cdot (\log_2 n)^{k_{-1}} \cdot n^{k_0} \cdot 2^{k_1} \cdot 2^{(2^{k_2})} \cdot \ldots $$ where \$n\$ the the total number of the letters of the words in the input;
  • a length of \$x\$ bytes (or whatever unit of measurement is commonly used in the language of your choice);

then the score is \$f(x + 4)\$. Lowest score wins!

Notes
  • obviously, infinitely many terms \$k_i\$ can be \$0\$;
  • terms with three or more \$\log\$ (e.g. \$\log_2 \log_2 \log_2 n\$) cannot be used in function \$f\$ because they could be used to arbitrarily lower the score, unless we introduce further complex scoring rules (and most probably they won't be used as a real lower bound).
Scoring example

If your solution has a length of \$37\$ bytes, and it has a time complexity of \$\Omega(n^5)\$, then it has a score of \$(37+4)^5\$.

Edit: scoring rules postponed for a future challenge

\$\endgroup\$
4
  • \$\begingroup\$ can we assume that there will be at least one solution in the input? \$\endgroup\$ Oct 17, 2022 at 15:47
  • \$\begingroup\$ I didn't think about it. In which case this assumption can be useful? \$\endgroup\$
    – matteo_c
    Oct 17, 2022 at 22:01
  • 2
    \$\begingroup\$ I think that since the number of distinct five-letter words is constant, any algorithm taking a subset of them would be constant time. So, once you filter out words that not five letters long and de-duplicate, the complexity of the rest of the algorithm doesn't matter. Having the length "5" instead be a parameter could address this. \$\endgroup\$
    – xnor
    Oct 18, 2022 at 2:22
  • 1
    \$\begingroup\$ assuming at least one solution avoids the "no solutions" edge case, which (depending on algorithm) may require extra code to handle logic that the bulk of the code doesn't handle. Example: if i have a loop which doesn't stop until i've seen some N>0 eligible words, it would run into an infinite loop in the "no solutions" scenario. Considering you have to output all solutions, however, I can see how it might not make a huuge difference. It's up to you tbh :-) \$\endgroup\$ Oct 18, 2022 at 13:15
0
\$\begingroup\$

Tell 32-bit from 64-bit with most disallowed bytes

Decide an integer N. Take an array of length N, and output a x86 opcode, which when running, reach different position after leaving the opcode you provided.

  • No bytes given in input is allowed in your output.
  • You'll be in Ring 3, so some x86 features can't be used.
  • You can destroy all available registers, including XMM, x87, etc.
  • You can assume 4096 bytes of available stack under stack pointer.
  • It's not necessary a jmp. Other ways to reach different position are fine.
  • The destination should be in 256 bytes before your code or in 256 bytes after your code. jmp .+0xEBEBEBEB is not allowed unless your output is at least ~336859924 bytes.
  • Each destination should have at least 2 bytes of space to fit a jmp short instruction.

Here is a possible program with N=0:

([])=>[0x66, 0x40, 0x3D]

Assuming this program is loaded into 0, then in 32-bit mode, it goes to 7; in 64-bit mode, it goes to 5, both of which have enough space.

This is an example with N=1:

([x])=>x==0x66||x==0x41||x==0x3D?[0x24,0x00,0x40,0x74,0x74]:[0x66,0x41,0x3D]

Largest N wins.

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

Title Case (WIP)

Input a string with letters and spaces, input a set of mirror words. Output a string which is title case of the input string that follow the following rules:

  1. Cases is unchanged for any words already contains uppercase letters;
  2. Cases is unchanged for any words in the set mirror words AND is not the first word;
  3. For all other words, the first letter is changed into uppercase

The set mirror words is an input to your program / function. Here are mirror words used in testcases:

["a", "an", "and", "as", "as", "at", "but", "by", "for", "if", "in", "nor", "of", "off", "on", "or", "per", "so", "the", "to", "up", "via", "yet"]

Testcases

Input -> Output
the sun and the moon -> The Sun and the Moon
jQuery tutorial using jQuery plugins -> jQuery Tutorial Using jQuery Plugins
\$\endgroup\$
0
\$\begingroup\$

A map maps keys(string) to values(string). Basic operations includes:

  • Set. Given a key and a value, store it.
  • Get. Given a key, get the last value stored into this key, or ""(empty string) if nothing ever stored into.

For some reason, sometimes keys looks same but need to refer to different object. Therefore, color is introduced. Provided keys is therefore splitted, and to get colored key, color each part of keys, and concat them.

For example, say a is colored red, then

  • a is \$\color{red}a\$
  • aa is \$aa\$
  • a a is \$\color{red}{aa}\$
  • ab is \$ab\$
  • a b is \$\color{red}{a}b\$

Therefore, another operation is

  • Color. Given a keypart, resign its color. Color is a non-negative integer and default to 0.

Shortest code in each languages wins.

Test cases

[[GET, "a"],         // ""
 [SET, "a", "1"],
 [GET, "a"],         // "1"
 [COL, "a", 1],
 [GET, "a"],         // ""
 [SET, "a bb", "2"],
 [GET, "a b b"],     // "2"
 [COL, "a", 0],
 [GET, "a"]]         // "1"
\$\endgroup\$
0
\$\begingroup\$

Solve the "/" puzzles from Taiji

Spoilers for the game Taiji, it's really good you should play it

Taiji puzzles consist of a rectangular grid, a solution consists of setting each square to either on or off:

####
#...
##..

However, not every solution is correct, a puzzle can contain any number of colored slashes, here represented by numbers:

....
1...
..1.
....

A shape is defined as a contiguous area that all has the same state. (either on or off). Areas with the same color slash must have the same shape, but it may be rotated (but not mirrored). For example, if you have this:

1..1.
.22.1
1..1.

A solution would be:

.#.#.
##..#
.#.#.

Note that all 1s are a single square while both 2s are a T shape, in this case in opposite colors.

Note that the number must be in the same place in every shape, so if you have this puzzle:

.....
1..1.
.....

This would Not be valid:

#..##
..##.
#..##

Because one 1 is in the tip and the other is in the tail.

If the numbers are different the shapes must be different. However, they count as different if the number is in a different part of the shape.

A shape can contain multiple numbers. If it contains the same number twice that means the shape must be irrationally symmetric.

Your challenge is: Given a number, output a possible solution. Note: There will always be at least 2 possible solutions, since the inverse of any valid solution is also valid.

Test Cases

Note many of these have many valid solutions.

1..1.            #..#.
.22.1        --> ....#
1..1.            #..#.

....              ##..
123.          --> #.##
....              #.##


...               #.#
111           --> #.#
...               #.#

1.22.1            ##..##
......            ######
2....2        --> .####.
2....2            .####.
......            ######
1.22..            ##..##

3....             #####
11211         --> ..#..
3....             #####

....              #.#.
111.          --> #.#.
....              #.#.

You may take input as a 2d list of numbers, and use any constant value to represent a cell that does not create a hint (eg. 0). For output you may also use any 2 constant values to represent on and off.

\$\endgroup\$
1
  • \$\begingroup\$ Is mirrored same? \$\endgroup\$
    – l4m2
    Jan 25 at 13:27
0
\$\begingroup\$

Best Iterated Prisoner's Dilemma

\$\endgroup\$
1
  • \$\begingroup\$ this is a great idea. an example would be nice :-) \$\endgroup\$ Oct 8, 2022 at 20:30
0
\$\begingroup\$

Optimize your score on a biased multiple choice test

In a multiple choice test, sometimes, by chance, multiple questions in a row will have the same answer. Some of my teachers dislike this, and will change questions to ensure there are never more than \$n\$ of the same answer in a row.

In this challenge, for each question in a test, you'll be given a set of four confidence values from 0 to 1, which sum to 1. These represent the odds of each choice being correct (for example, [0.1, 0.6, 0.2, 0.1] if you're 60% sure that B is correct, 20% sure C is correct, and 10% sure either of the others could be right). You'll also be given a positive integer n, the maximum number of same-answer questions in a row.

Given this information, you must output the set of answers that would give you the highest estimated score.

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

Pushing boxes away but

I'll accept first fastest algorithm and then this challenge turns into .

Sandbox Notes

  • Some options are listed in comment
\$\endgroup\$
4
  • \$\begingroup\$ Upvote this comment if this idea of question is good \$\endgroup\$
    – l4m2
    Jan 27 at 2:24
  • \$\begingroup\$ Upvote this comment if this idea of question is bad \$\endgroup\$
    – l4m2
    Jan 27 at 2:24
  • 1
    \$\begingroup\$ Upvote this comment if this way of handling fastest-algorithm is good \$\endgroup\$
    – l4m2
    Jan 27 at 2:24
  • 1
    \$\begingroup\$ Upvote this comment if this way of handling fastest-algorithm is bad \$\endgroup\$
    – l4m2
    Jan 27 at 2:24
0
\$\begingroup\$

A randomly colored walk

Given two inputs, a distance \$d\$ and a number \$n\$ output \$n\$ random colors which each have distance \$d\$ from the previous.

Background

A random walk is a path which is defined by choosing a random direction and (usually) fixed distance to go at each step. We will be taking a random walk through the RGB color space using Euclidean distance as our metric.

The challenge

For this challenge you will take two inputs, \$n\$ and \$d\$. Let \$n\$ be the number of colors to output, this will always be an integer \$1 \leq n\$, and \$d\$ be the distance between consecutive elements, which will always be \$0 \leq d \leq 128\$. You may additionally assume that \$d\$ is an integer.

For each consecutive pair of elements \$(r_1, g_1, b_1), (r_2, g_2, b_2)\$ of the \$n\$ element sequence output, it must be the case that all values are between 0 and 255 inclusive (or \$[0,256)\$ for floats), and the distance between elements must be within 1 of d, that is \$|\sqrt{(r_1-r_2)^2+(g_1-g_2)^2+(b_1-b_2)^2} - d| < 1\$. This should allow one to restrict their output to integers if they so choose. The walk need not be uniform, but it does need to be random. The starting point of the walk should be random as well.

Standard i/o rules apply, input and output can be in any reasonable format. Graphical output is allowed (and encouraged, though I doubt it will be golfy to do so) so long as the order of the sequence is clear.

This is , so the shortest answer in bytes wins.

Test cases

For these test cases input is in the order \$n,d\$ and output is \$(r, g, b)\$ as integers. These are some possible results.

5, 5 -> (81, 60, 243), (81, 57, 239), (76, 60, 240), (80, 62, 241), (84, 60, 243)
4, 10 -> (163, 89, 77), (162, 83, 85), (166, 75, 79), (166, 82, 87)
4, 50 -> (212, 36, 232), (247, 1, 239), (220, 44, 243), (217, 81, 209)
\$\endgroup\$
0
\$\begingroup\$

Related

Play chess. You can't see the current board, and can only memory two bytes.

Each turn, you're given your current state(initially 0) and opponent's move(a special value if first move in the game). You then output a list of [moves,state] pair, and the first valid one will get used. If no valid move, then you automatically resign.

Aim is obviously win as many games and lose as less as possible.

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

4D rotation matrix to quaternions

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

Ternary 2-input logic gate

Objective

Given an expression of a ternary 2-input logic gate, pretty-print its truth table.

Ternary logic and ternary operators

L, E, and G are the truth values of the ternary logic dealt here. They correspond to Haskell's LT, EQ, and GT.

The expression can have two free variables, hence "2-input".

There are four operators that the expression can have: min, max, compare, and mappend. (Again, from Haskell.) Their truth tables are:

min|L E G
---+-----
L  |L L L
E  |L E E
G  |L E G

max|L E G
---+-----
L  |L E G
E  |E E G
G  |G G G

compare|L E G
-------+-----
L      |E L L
E      |G E L
G      |G G E

mappend|L E G
-------+-----
L      |L L L
E      |L E G
G      |G G G

where the first column is for the first argument and the first row is for the second argument.

I/O format

The input format shall be a nonempty binary tree whose branches are the operator and whose leaves are the free variables and the truth values.

The output format shall be like this:

 |L E G
-+-----
L|? ? ?
E|? ? ?
G|? ? ?

where ? is filled with appropriate truth values represented by L, E, or G. Again, the first column is for the first argument and the first row is for the second argument.

Examples

Let the free variables be P and Q in sake of demonstration.

Given P compare (E compare Q), the truth table is:

 |L E G
-+-----
L|L L E
E|L E G
G|E G G

Given (P min Q) compare (E compare (P max Q)), the truth table is:

 |L E G
-+-----
L|L E E
E|E E E
G|E E G

Given ((E compare (P max Q)) compare (P min Q)) mappend (P compare (E compare Q)), the truth table is:

 |L E G
-+-----
L|G L E
E|L E G
G|E G L

Given Q mappend P, the truth table is:

 |L E G
-+-----
L|L L G
E|L E G
G|L G G
\$\endgroup\$
0
\$\begingroup\$

Floating-point numbers have errors in addition, oh my!

Given two IEEE double-precision floating-point numbers \$x\$ and \$y\$, output the most accurate IEEE double-precision floating-point approximation of the error that would be caused by performing the floating-point addition \$x + y\$.

As a reminder, an error is defined as the approximation subtracted by the exact value.

The inputs must deal with denormal numbers and the negative zero as well. However, infinities and NaNs fall into don't care situation.

If the output is zero, its sign doesn't matter.

\$\endgroup\$
2
  • \$\begingroup\$ "If either of the operands is an infinity or a NaN, the output shall be NaN" - what about languages that don't support infinity/NaN. \$\endgroup\$
    – The Thonnu
    Feb 22 at 16:53
  • \$\begingroup\$ I'm thinking their equivalent of 1/0... or maybe just the strings "NaN" and "Infinity" \$\endgroup\$ Feb 24 at 12:10
0
\$\begingroup\$

A Fine sequence with fine interpretations

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

Making one shape out of dissections of another

\$\endgroup\$
7
  • \$\begingroup\$ Can the pieces be rotated and/or flipped? \$\endgroup\$
    – Bubbler
    Feb 22 at 7:29
  • \$\begingroup\$ @Bubbler Yes, they can be moved, rotated, and flipped, but nothing else. I will clarify in the post. \$\endgroup\$
    – Aiden Chow
    Feb 22 at 7:30
  • \$\begingroup\$ Two falsy test cases are actually truthy: tio.run/##S07MK0ss/v8/… \$\endgroup\$
    – Bubbler
    Feb 22 at 7:31
  • \$\begingroup\$ @Bubbler Lol f*** i am bad at puzzles \$\endgroup\$
    – Aiden Chow
    Feb 22 at 7:32
  • \$\begingroup\$ How am i gonna make the falsey test cases if i can't even make these simple ones lol \$\endgroup\$
    – Aiden Chow
    Feb 22 at 7:33
  • 1
    \$\begingroup\$ Well, the correct answer here is to write a working code yourself and generate test cases based on it :) \$\endgroup\$
    – Bubbler
    Feb 22 at 7:38
  • 1
    \$\begingroup\$ @Bubbler You overestimate my coding capabilities :( \$\endgroup\$
    – Aiden Chow
    Feb 22 at 7:39
0
\$\begingroup\$

Find the sum of the sub-list with the largest sum

Challenge

Given a list that contains an integer, a sub-list is a contiguous non-empty sequence of elements within that list.

For example, the list \$[1, 3, -2, 5, -6]\$, has some sub-lists \$[1]\$, \$[3, -2]\$, \$[3, -2, 5, -6]\$, etc.

Your job today is to find the sum of the sub-list with the largest sum.

For example \$[1, 3, -2, 5, -6]\$, the sum of the sub-list with the largest sum is \$7\$, the sub-list with the largest sum is \$[1, 3, -2, 5]\$.

Specification

  • Input / Output can be taken in any reasonable format, taking a list of numbers and returning a number, which is the sum of the sub-list with the largest sum
  • The input array is guaranteed to have at least one element.

Testcases:

[1, 3, -2, 5, -6] -> 7
[-2, 1, -3, 4, -1, 2, 1, -5, 4] -> 6
[-3, -6, -8, -1] -> -1
[5, 4, -1, 7, 8] -> 23

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

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

Canonical form of a cubic Bézier curve

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

Draw Parcly Taxel's cutie mark

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

Generating all possible equations with 10 characters

\$\endgroup\$
6
  • 1
    \$\begingroup\$ Welcome to CGCC, and thanks for using the Sandbox! This looks like an interesting challenge. You'll need to specify a winning criterion; it looks like you're interested in fastest-code (code should run as fast as possible), but we normally don't combine that with restricted-time (code must take less than an hour to run). fastest-code without the 1-hour restriction is one option; code-golf + restricted-time is another. If you're not sure which to choose, I recommend code-golf, since it's easier to calculate the score for submissions. \$\endgroup\$
    – DLosc
    Mar 1 at 23:21
  • \$\begingroup\$ @DLosc I wanted this "1 hour" part to be just a kind of side note for people to know what to expect regarding the performance. I changed my question to make it seem less like a winning requirement \$\endgroup\$
    – ordptt
    Mar 1 at 23:32
  • \$\begingroup\$ You need to objectively specify what does "as fast as possible" mean. See codegolf.stackexchange.com/tags/fastest-code/info and refer to other fastest-code challenges for inspirations: codegolf.stackexchange.com/questions/tagged/… \$\endgroup\$
    – pajonk
    Mar 2 at 7:51
  • \$\begingroup\$ @pajonk is it better? I edited it \$\endgroup\$
    – ordptt
    Mar 2 at 14:31
  • \$\begingroup\$ @ordptt for me it would be enough. Also, do I understand "There are no operators in sequence" correctly that this applies only to successive operators like 1*-1, but -1+2=1 is ok? What about 1-2=-1 - is this valid? Or 1*(-1)? \$\endgroup\$
    – pajonk
    Mar 2 at 19:07
  • \$\begingroup\$ @pajonk it means that there cannot be any *,+,-,/ adjacent to each other, so I believe you got it right. So 1*-1 is not valid but -1+2=1, 1*(-1) are. 1-2=-1 is not valid because the RHS is negative. \$\endgroup\$
    – ordptt
    Mar 2 at 20:30
0
\$\begingroup\$

Generate number from given range

\$\endgroup\$
10
  • 1
    \$\begingroup\$ This downvote was too fast :) \$\endgroup\$
    – EzioMercer
    Mar 3 at 21:32
  • \$\begingroup\$ Is the output a floating point number? \$\endgroup\$
    – noodle man
    Mar 5 at 14:29
  • \$\begingroup\$ @Jacob It is doesn't matter. For example if your function for inputs 10.55, -1, 1 will output 0 it is fine but if the output will be 0.55 it is also fine. In general the output can not be only integers because at least for range [0, 1] you can output integers 0 and 1 only for two different speed of wind, another wind speed must give some number from range (0, 1) \$\endgroup\$
    – EzioMercer
    Mar 5 at 14:41
  • \$\begingroup\$ Could you clarify the sentence "and multiply this value to -1 pseudo randomly"? \$\endgroup\$ Mar 5 at 18:59
  • \$\begingroup\$ @CommandMaster It is just part of story :) He do it to get the negative numbers too, because of speed of wind can not be negative number \$\endgroup\$
    – EzioMercer
    Mar 5 at 19:11
  • \$\begingroup\$ What's the range of the speed of wind? Can it be any real number? \$\endgroup\$ Mar 5 at 19:12
  • 2
    \$\begingroup\$ "Your function must output different result each time for different wind speed" - I think it may be impossible for some inputs because of floating point inaccuracies (there is in practice only a finite amount of floating point numbers between two integers) - or are we to ignore floating point errors? \$\endgroup\$
    – pajonk
    Mar 5 at 19:33
  • \$\begingroup\$ @CommandMaster It can be any float or double (it is up to you) number which provide your chosen language \$\endgroup\$
    – EzioMercer
    Mar 5 at 21:03
  • \$\begingroup\$ @pajonk Good point. Yes, of course you can ignore floating point errors. I will add it to challenge \$\endgroup\$
    – EzioMercer
    Mar 5 at 21:05
  • 1
    \$\begingroup\$ This is a pretty easy challenge but still fairly interesting \$\endgroup\$
    – noodle man
    Mar 5 at 22:41
0
\$\begingroup\$

The topology of origami

\$\endgroup\$
1
134 135
136
137 138
153

You must log in to answer this question.

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