# What is the Sandbox?

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

See the Sandbox FAQ for more information on how to use the Sandbox.

## Get the Sandbox Viewer to view the sandbox more easily

To add an inline tag to a proposal use shortcut link syntax with a prefix: [tag:king-of-the-hill]

# Create a safe crossing.

Given a string/number/array of any two distinct characters make the "squarest" 2D array that allows "someone" to cross from left to right or top to bottom "stepping" only on whichever character you have chosen as your stepping stone

### or

Make the "squarest" array possible that contains a complete row or column of stepping stone characters. (clearer but takes away the fun story-ness)

"squarest" meaning smallest difference between the dimensions of the 2D array.

## Input

• A string/number/array of your choosing consisting only of your two chosen distinct characters. So no error checking needed. Allow true/false values if input is array?
• input will have at least 1 stepping stone character so that a valid solution is always possible 1 by x or x by 1
• a minimum length of x? needed? might make it easier if there's some weirdness with very short arrays in the algorithms people come up with
• the last row can be incomplete to allow for prime number length inputs and to more easily allow non trivial 1xX/Xx1 answers

## Output

The output should be the dimensions of the array

• and specify the row or column to use?
• print your 2D array so that the path can be seen graphically?

## Test Cases

100100100 -> 3x3 array

100
100
100


11111000 -> 4x2 or 3x3 - 3x3 is squarer so is correct

1111    111
1000    110
00


11000011000101001001 -> 5x4

11000
01100
01010
01001


1000000000000 -> 12x1 - trivial as only 1 stepping stone

100000000000


010111 -> 3x2 or 2x3 - either acceptable as both are only "1" away from square

010    01
111    01
11


## Issues

• allow diagonal crossings? does that make it a lot harder?
• need a lot more test cases I think?
• input spec
• output spec
• better/more tags?

# ASCII Sum of your code

Encoding is nice, adding things is also nice. Let's do both !

Your task will be to create a program that read itself, convert every of its character into ASCII values and return the sum of those numbers.

## Example

Let's say your program is Hello, world !. Convert every character into ascii values

H  e   l   l   o   ,  (space) w   o   r   l   d   (space) !
72 101 108 108 111 44 32      119 111 114 108 100 32      33


Now, sum everything into a meaningless very useful value

72 + 101 + 108 + 108 + 111 + 44 + 32 + 119 + 111 + 114 + 108 + 100 + 32 + 33
= 1193


Here it is, Hello, world! returns 1193 !

## Rules

• The code have to read itself and calculate the result
• Standard loopholes are not allowed
• This is codegolf, so the fewer bytes wins.
• Non-standard languages with non-ASCII characters should use their own codepage's encodings (Thanks for @Veskah for this rule)

# Feedback

• Is the challenge clear enouth ?
• Is there an already existing challenge like this one ?
• is this considered as a duplicate of this challenge ?
• I would probably have non-standard languages use their codepage's encodings (pretty much all of them should be 8 bytes) to crunch their output. The big hammer approach would be to ban non-ASCII languages but I would not recommend that. – Veskah Oct 23 '19 at 14:06
• Requiting the code to read itself and do the calculation is a non-observable requirement. Since it seems you don't want programs that just hardcode the value, I think the best way to be just to require the program take in an input string to use. Regardless, I don't really see room for interesting golfing in the challenge, since pretty much any normal-ish language has built-ins to take ASCII values and compute sums, and weird languages that don't have already done these as subtasks for many many challenges. – xnor Oct 25 '19 at 0:52
• @xnor Does this challenge with string input already exist ? – The random guy Oct 25 '19 at 7:06
• I don't remember an exact one, but I'm finding very close ones: averaging ASCII values and summing then counting binary 1's, which was closed as a duplicate of one without the character adding. I also found an unrestricted quine challenge with the same task as yours. So I think there's a good chance this would be closed as a duplicate either way. – xnor Oct 25 '19 at 7:11
• Yup, the last one is quite the same as mine. Duplicate it is then. – The random guy Oct 25 '19 at 7:13

# It's slashing time

(Inspired by Seven Slash Display)

You're lying in bed, awake. Sleepily, you turn your head to the alarm clock and read what time it is. Since you're lying down, the clock is facing diagonally, making it difficult to read. You decide to write a program to help you out (hey, you're awake anyway).

Given a "slashed" seven-segment display, output what time it is in 24-hour format.

      /\
/\
/\  /
\ \
. \/
/\ .
/
\/

2:03


You can choose where to place the : between the numbers (for example, evenly spaced as above or left-aligned as below, etc.), but the : must be present.

Some further examples:

       \
\
/\
/\
/ . /
\/\.
\  /
\

15:31

\
\/\
\
\
\.
\.

1:14


Here are the precise digit shapes:

/\
\ \
\/

\
\

/\
/
\/

/\
/\
/

\
\/\

/
\/\
/

/
\/\
\/

/\
\

/\
\/\
\/

/\
\/\
/


## Rules & Standard I/O boilerplate

• The time will always be valid. For example, you'll never receive something like 30:25 or 7:99 or the like.
• You're allowed to pad the input with whitespace however necessary (e.g., padding it to always be a rectangle with trailing spaces).
• Input always a valid time? Can we shift the dots? – Veskah Oct 29 '19 at 19:01
• 2 in 2:03 is not aligned with other digits :( – tsh Oct 31 '19 at 8:53
• @tsh Indeed it wasn't. Thanks for the correction! – AdmBorkBork Oct 31 '19 at 15:11

# Room volume as a function of paint on the walls/ceiling

Task: Write a function that will take in the size of a room (height, width, and length) and a number of paint layers (given that the layers are of a consistent thickness) and return the area of free space in the room after that many layers of paint are applied.

Requirements:

• Return the final area left in the room after the paint layers are added
• should be able to run on a room of any size
• The answer must account for the decreasing area in the room as each layer is applied.
• number of layers and paint layer thickness should both be inputs
• must account for walls and ceiling
• standard loopholes are disallowed

The winner is determined via byte count

• How thick is each coat of paint? Also, do you mean return the volume of free space in the room? – girobuz Nov 14 '19 at 4:30

# Substitute Unprintable ASCII Characters

Have y'all ever written an answer with unprintable ASCII characters in it and wished that there was an easy way to represent those characters in a printable way? Well, that's why the Control Pictures Unicode block was invented.

However, manually substituting these characters into one's answer is time-consuming, so that's what today's challenge is about: swapping out the nasty invisible characters for nice, readable characters.

## Input

You will be given strings that contain a mix of ASCII-only characters (i.e. the UTF-8 code point of each character will be in the range: $$\0 \lt char \le 127\$$).

## Output

For all unprintable characters, replace it with its corresponding character in the Control Pictures Unicode range.

In other words:

• Characters in the range $$\0 \lt char \lt 9\$$ are replaced with their corresponding character
• Vertical tabs and newlines (9 and 10) aren't replaced
• Characters in the range $$\11 \le char \lt 32\$$ are replaced with their corresponding character
• Spaces (32) aren't replaced
• The delete character (127) is replaced with its corresponding character: ␡

## Tests

Characters are given as escapes for nice formatting here, but each character will be replaced with the unprintable character

In -> Out
\x1f\x1c\x1f\x1e\x1f\x1e\x1f\x1f\x1e\x1f\x1e\x1f -> ␟␜␟␞␟␞␟␟␞␟␞␟
Hello\x07World! -> Hello,␇World!
\x01\x02\x03\x04\x05\x06\x07\x08\x0c\x0b\x0e\x0f\x10\x11\x12\x13\x14\x15\x16\x17\x18\x19\x1a\x1b\x1c\x1d\x1e\x1f\x7f -> ␁␂␃␄␅␆␇␈␌␋␎␏␐␑␒␓␔␕␖␗␘␙␚␛␜␝␞␟␡


## Rules

• All standard loopholes are forbidden
• Character substitutions must be made according to the Control Pictures Unicode block

## Scoring

This is code-golf so the answer with the fewest amount of bytes wins.

## Test-Case Generator

I have provided a test case generator for y'all. It prints inputs in the way they will be passed to your program and outputs the expected result.

Try it online!

• "DEL" (ASCII 127) is also unprintable. Also, did you mean 0≤char≤127? – Bubbler Nov 15 '19 at 8:00
• Updated! (I forgot DEL wasn't printable) – Lyxal Nov 15 '19 at 8:04
• I think you need to give test input as JSON (i.e. with escapes) – Adám Nov 15 '19 at 8:46
• Space has a substitution character (␠). Should it be replaced? I think you should clearly state that ≤ (or < 32) and 127 should be replaced. – Adám Nov 15 '19 at 8:48
• Updated accordingly. – Lyxal Nov 16 '19 at 1:33

List of integers to pairs ?? Any suggestions for the title ??

Write a function or a full program taking a list of non negative integers numbers L that outputs a pair of numbers [X , Y] such that X %( Y + i ) == L [ i ] .

Output specifications

• You can output X Y in any order, just indicate it and be consistent.
• X Y are also unsigned integers, obviously Y must be greater than 0 to avoid modulo 0 errors.
• If your language doesn't support 0 indexed list you can consider X %( Y + i ) == L [ i + 1 ] ?? Any suggestions how to handle this ??

Example

[ 1, 2, 3 ] => [ 11, 2 ]

 11 %( 2 + 0 ) = 1
11 %( 2 + 1 ) = 2
11 %( 2 + 2 ) = 3


[ 10, 2 ] => [ 98, 11 ]

 98 %( 11 + 0 ) = 10
98 %( 11 + 1 ) = 2


# Test cases

[ input ] , [ output ] pairs

[ 0, 1, 2 ] ,  [ 5, 1 ]
[ 1, 2 ] ,  [ 5, 2 ]
[ 1, 2, 3 ] ,  [ 11, 2 ]
[ 1, 2, 3, 4, 5 ] ,  [ 59, 2 ]
[ 4, 3, 2, 1, 0 ] ,  [ 9, 5 ]
[ 6, 12, 18 ] ,  [ 3318, 18 ]
[ 27, 18, 9 ] ,  [ 279, 28 ]
[ 3, 9, 27 ] ,  [ 4059, 26 ]
[ 2, 4, 8, 16 ] ,  [ 8584, 14 ]
[ 0, 0, 0, 0, 0, 0 ] ,  [ 60, 1 ]
[ 1, 1, 1, 1 ] ,  [ 61, 2 ]
[ 120, 20 ] ,  [ 12220, 121 ]
[ 10, 2 ] ,  [ 98, 11 ]
[ 9, 8, 7, 0 ] ,  [ 1339, 10 ]
[ 0, 1, 4, 9, 2, 10, 4, 15, 10, 5, 0, 16, 12, 8, 4, 0, 22, 19, 16, 13 ] ,  [ 100, 10 ]
[ 9, 99, 90, 81, 72, 63, 54, 45, 36, 27 ] ,  [ 999, 99 ]


# Rules

• Input/output can be given by any convenient method.
• You can print it to STDOUT or return it as a function result.
• Either a full program or a function are acceptable.
• Standard loopholes are forbidden.
• This is so all usual golfing rules apply, and the shortest code (in bytes) wins.

• For the testcases I think you can omit the outer parenthesis and the trailing comma. Furthermore I'd talk about nonnegative integers instead of unsigned integers. – flawr Nov 17 '19 at 16:44
• But I have another question: Is this problem always solvable? – flawr Nov 17 '19 at 16:44
• @flawr thanks I'll fix then. For the second question Idk.. Numbers increase extremely, I made a program for solving the problem and also a program to do the reverse(X,Y to list) I may do some test for each X,Y to a certain number.. – AZTECCO Nov 17 '19 at 17:48
• I don't think [0,0,1,1] has a solution (consider the parity of X) cc @flawr – H.PWiz Nov 17 '19 at 17:53
• @H.PWiz sadly yes – AZTECCO Nov 17 '19 at 18:45
• @flawr and H.PWiz so if it's not always solvable do I have to delete this challenge? – AZTECCO Nov 17 '19 at 18:47
• I dunno, you could guarantee that the input is solvable. Or you could ask a different (harder) question instead: "Is there a solution?" – H.PWiz Nov 17 '19 at 19:06

# Create a block maze solver AI

A block maze is a maze in which goal is to complete a pathway by adding blocks.

It starts like this :

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


# is a block (which can be crossed). . is empty space (which cannot be crossed).

The goal is to connect top-left corner S to the bottom-right corner E. Diagonals are not allowed.

S....
.....
.....
.....
....E


One possible solution for the example above is to add three blocks like this :

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


Think about a man who want to cross a river with crocodiles . using huge stone blocks #.

The task is to create a program that take a grid as input and return a solution as output.

## Scoring

The sum of all blocks required to solve all solutions in a 1.000 test case file I will provide.

The winning program is the one that use the fewest blocks to solve all mazes.

## Rules

• All grids are 25 x 25.
• Start / end points are always top-left / bottom-right corners. There is always a block on those points.
• There is always one guaranteed solution (which can be found by filling all empty spaces)
• Program must be entirely deterministic; pseudorandom solutions are allowed, but the program must generate the same output for the same test case every time. If two programs take the same number of steps (e.g. they both found the optimal solutions), the shorter program will win.

The program should return the solution as a sequence of blocks x-y coordinates (the coordinates of blocks to add to solve maze) in the format of your choosing :

11-3;15-6;19-12


## Meta

• I cannot think of a simple algorithm that returns an optimal (best possible) solution in a reasonable time. I expect programs to use some heuristics to get non-optimal/near-optimal solutions. I made the grids 25 x 25 to make it challenging enough and prevent simple solutions like brute force.
• Is this a duplicate? There is lot of related questions but I couldn't find anything related to block maze.
• The tags are . Anything else?

EDIT : as AlienAtSystem pointed out in comments, there is an optimal algorithm for all cases. I made some tests: even a slightly modified Dijkstra's algorithm will work (it will find shortest path in a short time). I will not post this challenge as it is trivial. I leave it here in case someone else would have same idea.

• By fewest total steps, do you mean cumulatively? – Corsaka Nov 20 '19 at 10:07
• I mean the sum of all blocks. If solution for maze01 use 4 blocks and solution for maze02 use 5 blocks, it is 4+5 = 9 blocks in total. The lowest is the best. Someone who has 7+1=8 blocks will win. I have edited answer. – tigrou Nov 20 '19 at 10:37
• You should allow people to have any output format as long as it has x first, y second. None of the mazes are duplicate. I can't think of any other tags. This should be good to post. – Corsaka Nov 20 '19 at 10:49
• Should we add a test suite of some sort? Or how are you going to verify the score of a submission? But in general the challenge looks clear. A few questions: I assume there are some test cases among the 1000 requiring us to go right/up for the optimal solution, instead of only going left/down? Are the input-characters strict, or could we also use for example 012 for @.x respectively as integer-matrix? One other relevant tag: [path-finding] – Kevin Cruijssen Nov 20 '19 at 13:25
• @KevinCruijssen I am planning to provide a program to validate solutions. right/up : some mazes might be shorter to solve that way but it is not allowed. The goal is go from top-left to bottom-right (not to cross from left to right). character set : programs should use the same characters as the test file. Anyway, using 012 might be a good idea (I might update the test file with such chars). There is no @ character in the test file since the start / end position are always the same. – tigrou Nov 20 '19 at 14:31
• @tigrou Ah ok, so @ is not part of the input. In that case a binary-matrix with just 0s and 1s would be a suitable input format I guess. As for the right/up: I meant it for an input like this pastebin. With this maze you could walk from the top-left to bottom-right with just 2 x insertions (at the _ positions), but you'd have to travel up and left in the path from the top-left to bottom-right. But if I understand correctly we only travel right and down, so this would be the solution (with 4 insertions at _) instead? – Kevin Cruijssen Nov 20 '19 at 18:38
• @KevinCruijssen : both solutions you posted are valid. You can go up / down / left right at any moment. – tigrou Nov 20 '19 at 18:42
• I can think of an algorithm that should be optimal for all test cases. This could result in the tie-breaker problem if other people realize it, too. – AlienAtSystem Nov 22 '19 at 6:32
• @AlienAtSystem : optimal algo : is it because of my test cases (which have some flaws) or the maze challenge in general ? – tigrou Nov 22 '19 at 8:20
• @tigrou In general. It can be translated into a shortest path challenge over a considerably smaller graph. While A* wouldn't work on that one, other algorithms will. This wouldn't be short in terms of bytes, although I suspect not that much compared to other approaches, given that some part tasks need to be done by everyone. – AlienAtSystem Nov 22 '19 at 9:35
• I think you don't need to give up entirely right away. While this doesn't work as test-battery challenge because it's too easy to get everything right, it should be good for posting as generic code golf. – AlienAtSystem Nov 22 '19 at 13:36

## OEIS A125959

https://oeis.org/A125959 is a sequence I submitted. It is the following array, which then repeats:

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


This is a rather useful array for quickly calculating the digital root of the product of any two numbers (i.e the iterative sum of the digits of the product). See the OEIS link if you're interested in the details.

The challenge is to print the array in the shortest number of bytes.

None

# Output

The above array. It can be output as strings with new lines, or as a nested array, or an array of strings; but not as a single-line sequence (i.e. the 2d-nature of the array must be reflected in your output).

• So it's the multiplication table mod 9, except 0s are 9's? – xnor Nov 25 '19 at 12:58
• @xnor is it? I hadn't spotted that before. Does that stop it being an interesting challenge? – simonalexander2005 Nov 25 '19 at 13:49
• I believe it does (because it is "create a 10x10 table of the function (-~a*-~b-1)%9+1" now). – the default. Nov 25 '19 at 14:05
• I think it makes it too similar to generic print-a-multiplication table challenges, but others might disagree. – xnor Nov 26 '19 at 2:10

# Times have changed!

(pun intended)

## Preface

As mathematics progressed, mathematicians agreed upon the 'order of operations', to prevent mathematical expressions from becoming ambiguous.

Given the expression $$\7 \times 6 + 5 \times 3\$$ we know to first evalulate multiplication, giving $$\ 42 + 15\$$, which is equal to $$\57\$$.

But what if another group of mathematicians had agreed to evaluate addition before multiplication? This expression would become $$\ 7 \times 11 \times 3\ = 231\$$: which is different from our answer by an error of $$\305\%\$$!

## The Challenge

Given a mathematical expression containing + (addition), * (multiplication), and the digits 0123456789, we can find:

• $$\E_1\$$ - the 'real' value of the expression, when multiplication takes precendence.
• $$\E_2\$$ - the 'alternate' value of the expression, when addition takes precedence.

Your task is to write a program or function which, given a string representing an expression, calculates and outputs the percentage error, $$\\frac{|E_1 - E_2|}{E_1} \times 100\$$.

## Rules

• WIP.
• Related – Chas Brown Dec 1 '19 at 22:33
• @ChasBrown do you think it's similar enough to call this challenge a dupe? – FlipTack Dec 27 '19 at 14:14

## Quick intro

So i was playing cookie clicker yesterday, and I thought about something. We keep producing cookies, without any loss. What if your cookies failed? This is where I thought about a clicker that would cook a cookie. Don't click too much, or the cookie will be overcooked!

• Your function will have to randomly select a number between 5 and 10 : it will establish the cooking duration of your cookie (and so, the number of time you'll have to call the function to cook your delicious cookie).
• Each time you call that function, it will iterate the baking process of your cookie.
• Your function should return "Undercooked" if your cookie is not fully cooked, "Overcooked" if you ... overcooked it, and "Cooked" when the cookie is baked just right.

## Example

Since I'm bad at explaining things, an example will show you more clearly what needs to be done. Let's call my function bake() :

bake()    // The random number generated is 6, so i need to call my function 6 times
Undercooked

bake()
Undercooked

bake()
Undercooked

bake()
Undercooked

bake()
Undercooked

bake()    // We hit the 6th function call, the cookie is baked.
Cooked

bake()    // The 7th call overcooked the cookie. Congratulation, you ruined it.
Overcooked


## Rules

• The random number of iterations has to be set the first time you call the function. It has to be between 5 and 10 (inclusive).
• A cookie has to be undercooked before being cooked, and has to be cooked before being overcooked. The 3 steps have to be reachable. A cookie can't uncook itself, therefore you can't go from cooked to undercooked, or from overcooked to cooked (it's too late, you ruined the cookie anyway).
• The function can have as many parameters as you please.
• Classic rules apply, no standard loopholes
• This is codegolf, so the shortest code wins.

## Meta

• Is the challenge clear enough ?
• Should I go with this method to iterate the "baking" process ?
• Are there some rules I could add to make it more exciting ?
• Does this challenge exist already ?
• Should we bake pies instead ?
• I'm assuming bake() will take no parameters and will have to store the count somehow, which means you might want to include some rules about file and global variable I/O. I also did a small editing pass. – Veskah Dec 2 '19 at 16:14
• @Veskah I never thout about restricting bake()'s parameters, gonna edit the rules to include this particulatiry. Also, thanks for the edits. – The random guy Dec 3 '19 at 8:12
• I don't think I understand what you are trying to accomplish. Why do you refer to the submission always as a function? Could it not be a program? Similarly, your edit to allow arbitrarily many parameters conflicts with the general tone that seems to imply that we should be storing state between calls. I think you will want to try explaining the task simply, perhaps even to the level of a non-programmer. – FryAmTheEggman Dec 8 '19 at 19:47
• I don't think this is possible? Surely you can't tell what direction is involved with the mirrors, e.g. /1, can you tell if the pointer started on 1 going east vs / going north? – Jo King Dec 18 '19 at 9:10
• @JoKing Hm yeah I think your right. I will try a little more but you are right that mirrors can't be used. – Wheat Wizard Dec 18 '19 at 15:06
• @JoKing I actually do think this is possible. – Wheat Wizard Dec 18 '19 at 15:15

## Traverse the Bridges of Köningsberg

The Seven Bridges of Köningsberg is a logical problem that singlehandedly kicked off both the fields of topology and graph theory. The city of Köningsberg was bisected by a river, with two islands in it. Thus the city spanned four landmasses. Connecting those were seven bridges. Leonhard Euler proved that it was impossible for a person to walk through Köningsberg and cross every bridge exactly once.

This is an increasingly abstract representation of the problem. The bridges can be represented as edges of a graph, and the landmasses as nodes. Try to start from one node, and "walk" to the other nodes, crossing every edge exactly once (crossing nodes multiple times is okay). Euler proved that it was impossible for Köningsberg. Info on how to solve this problem for any set of islands and bridges can be found on the Wiki page.

## The problem

As input, your program/function should take an adjacency matrix, in any form that you wish (e.g. concatenating every number to a single string is fine, as is making a string list, or even a built-in matrix data structure if your language has one). The examples here are provided using a csv format.

The adjacency matrix for Köningsberg looks like this:

0;2;1;2
2;0;1;0
1;1;0;1
2;0;1;0


Each row and column represents the bridges from and to specific nodes. Node 1 (first row) has 2 bridges to node 2 (second column), and vice versa. Every bridge is bi-directional, so the matrix will always be symmetrical. Bridges from a node to itself are allowed (that does not make much sense architecturally, but topology nerds recently hacked several city planning agencies to make this challenge more interesting, so do not disappoint them) - but by convention such connections are counted double in the adjacency matrix.

Output, for any given adjacency matrix, a truthey/falsey value for whether it is possible to walk so that you traverse every edge exactly once. You don't need to end up back at your starting position - that's a different problem. The maximum amount of nodes/landmasses is 9, and the maximum amount of bridges between two landmasses is also 9. The maximum amount of bridges from one landmass to itself is 4 (notated as 8 in the matrix). There is no guarantee that all the landmasses are connected - if there's islands that you cannot reach, but you can reach all the bridges, then the answer is still truthey!

This is a challenge, so the shortest challenge in bytes wins!

## Test cases

2


TRUE

2;8
8;2


TRUE

6;4;9
4;0;1
9;1;0


TRUE

6;2;4;0
2;4;3;9
4;3;2;3
0;9;3;4


TRUE

6;2;4;2;5
2;8;1;1;9
4;1;6;4;8
2;1;4;8;7
5;9;8;7;8


FALSE

0;0;0;0;0;0
0;0;0;0;0;0
0;0;0;0;0;0
0;0;0;0;0;0
0;0;0;0;0;0
0;0;0;0;0;0


TRUE (there's no bridges, so they can all be reached)

2;0;0;0;0;0;0
0;2;0;0;0;0;0
0;0;2;0;0;0;0
0;0;0;2;0;0;0
0;0;0;0;2;0;0
0;0;0;0;0;2;0
0;0;0;0;0;0;2


FALSE (every landmass only connects to itself)

0;0;0;0;0;0;0;0
0;0;0;0;0;0;0;0
0;0;0;0;0;0;0;0
0;0;0;0;0;0;0;0
0;0;0;0;0;1;0;0
0;0;0;0;1;0;1;0
0;0;0;0;0;1;0;1
0;0;0;0;0;0;1;0


TRUE (starting at a landmass with a bridge, you can reach all of them)

4;0;1;6;3;6;9;7;4
0;6;1;7;2;8;5;6;1
1;1;2;6;1;4;4;3;4
6;7;6;8;9;7;0;3;4
3;2;1;9;4;8;1;0;0
6;8;4;7;8;0;6;6;8
9;5;4;0;1;6;2;3;6
7;6;3;3;0;6;3;6;6
4;1;4;4;0;8;6;6;4


TRUE

## Sandbox

Do I need to include the logical solution to the problem? It's pretty simple, but I might want to make figuring that out part of the challenge.

Any other feedback welcome, of course.

• Why are the outputs to 5th and 6th examples False? Looks like 5th is invalid (because it's not symmetric) and 6th should be True (because there are no bridges to start with, so we already walked over all bridges). – Bubbler Dec 17 '19 at 4:30
• @Bubbler right on both counts (I was adjusting some of the squares but forgot the symmetry). Will update when I have time! – KeizerHarm Dec 17 '19 at 6:54
• @Bubbler fixed! Thank you! – KeizerHarm Dec 17 '19 at 8:24
• Pretty sure this is a duplicate – FlipTack Dec 20 '19 at 16:53
• @FlipTack Oh, bugger. Is this one different enough because the input is an adjacency matrix rather than a list of bridges? – KeizerHarm Dec 20 '19 at 19:11
• I wouldn't say so. Especially since the challenge isn't that interesting, just checking it's connected and there's 0-2 odd vertices. – FlipTack Dec 21 '19 at 6:55
• Especially because the degree of a node is simply the sum over its line in the adjacency matrix. – AlienAtSystem Dec 22 '19 at 16:52

# Input

The input will be a year between 1583 and 2250.

# Output

The Gregorian date of the first evening of Hannukah that year. That is the day before the first full day of Hannukah. Your code should output the month and day of the month in any easy to understand human readable form of your choice.

# Examples

2013    November 27
2014    December 16
2015    December 6
2016    December 24
2017    December 12
2018    December 2
2019    December 22
2020    December 10
2021    November 28
2022    December 18
2023    December 7
2024    December 25
2025    December 14
2026    December 4
2027    December 24
2028    December 12
2029    December 1
2030    December 20
2031    December 9
2032    November 27
2033    December 16


# How do you do this?

It could hardly be simpler. We start with a couple of definitions:

We define a new inline notation for the division remainder of $$\x\$$ when divided by $$\y\$$: $$(x|y)=x \bmod y$$

For any year Gregorian year $$\y\$$, the Golden Number, $$G(y) = (y|19) + 1$$ For example, $$\G(1996)=2\$$ because $$\(1996|19)=1\$$.

To find $$\H(y)\$$, the first evening of Hannukah in the year $$\y\$$, we need to find $$\R(y)\$$ and $$\R(y+1)\$$, the day of September where Rosh Hashanah falls in $$\y\$$ and in $$\y+1\$$. Note that September $$\n\$$ where $$\n≥31\$$ is actually October $$\n-30\$$.

$$R(y)=⌊N(y)⌋ + P(y)$$ where $$\⌊x⌋\$$ denotes $$\x-(x|1)\$$, the integer part of $$\x\$$, and

$$N(y)= \Bigl \lfloor \frac{y}{100} \Bigr \rfloor - \Bigl \lfloor \frac{y}{400} \Bigr \rfloor - 2 + \frac{765433}{492480}\big(12G(y)|19\big) + \frac{(y|4)}4 - \frac{313y+89081}{98496}$$

We define $$\D_y(n)\$$ as the day of the week (with Sunday being $$\0\$$) that September $$\n\$$ falls on in the year $$\y\$$. Further, Rosh Hashanah has to be postponed by a number of days which is

$$P(y)=\begin{cases} 1, & \text{if } D_y\big(\lfloor N(y)\rfloor \big)\in\{0,3,5\} & (1)\\ 1, & \text{if } D_y\big(\lfloor N(y)\rfloor\big)=1 \text{ and } (N(y)|1)≥\frac{23269}{25920} \text{ and } \big(12G(y)|19\big)>11 & (2)\\ 2, & \text{if } D_y\big(\lfloor N(y)\rfloor \big)=2 \text{ and } (N(y)|1)≥\frac{1367}{2160} \text{ and } (12G(y)|19)>6 & (3)\\ 0, & \text{otherwise} & (4) \end{cases}$$

For example, in $$\y=1996\$$, $$\G(y)=2\$$, so the $$\N(y)\approx13.5239\$$. However, since September 13 in 1996 was a Friday, by Rule $$\(1)\$$, we must postpone by $$\P(y)=1\$$ day, so Rosh Hashanah falls on Saturday, September 14.

Let $$\L(y)\$$ be the number of days between September $$\R(y)\$$ in the year $$\y\$$ and September $$\R(y+1)\$$ in year $$\y+1\$$.

The first evening of Hannukah is:

$$H(y)=\begin{cases} 83\text{ days after }R(y) & \text{if } L(y)\in\{355,385\}\\ 82\text{ days after }R(y) & \text{otherwise} \end{cases}$$

# Notes and thanks

Thank you to @Adám for pointing me to the rules. To keep things simple, this challenge assumes the location to be Jerusalem.

• Please type out the rules on that image into actual text. Challenges are supposed to be self-contained, while that image will be subject to link rot. Also, it's lacking an explanation how the Golden Number G is calculated. – AlienAtSystem Dec 29 '19 at 20:26
• What if the given year has no Hannukah? Or there are two "first day of Hannukah"s in the given year? – Adám Dec 30 '19 at 10:56
• @Adam. Now you have confused me! For which years between 1900 and 2100 were there 0 or 2 Hannukahs? – user9207 Dec 30 '19 at 11:01
• @Anush Ah, I didn't notice the range. 3031 will have 0 and 3032 will have 2. – Adám Dec 30 '19 at 11:17
• Hold on, the first evening? That'd be the day before before the "first day of Hannukah". You should be very clear about this. – Adám Dec 30 '19 at 11:26
• Hm, I just noticed that there's a risk of people actually not implementing the algorithms, but instead relying on a built-in calendar conversion. Though you don't state it, the answer is always the 24th day of the month Kislev in the Hebrew year CivilYear+3761. – Adám Dec 30 '19 at 11:47
• Also, you may want to extend the valid input range. Otherwise it will often be shortest to hard-code the dates, e.g. in base 30. – Adám Dec 31 '19 at 14:31
• @Adam Could you please double check the formula in the question actually matches the example dates I have given. If so, I will post the question. – user9207 Dec 31 '19 at 14:43
• Working on it... – Adám Dec 31 '19 at 15:00
• OK, I've tried it now and it works. It actually works. However, don't go ahead and post yet; There are a few issues to address. – Adám Dec 31 '19 at 15:39
• The first day of Hannukah day 84 if Rosh Hashanah is day 1, so you need to add 83 to get the first day of Hannukah, but 82 to get the evening before. – Adám Dec 31 '19 at 15:40
• The last three paragraphs are superfluous as your range is bigger. However, I also suggest adjusting the range somewhat. If you go above 2239 then .NET won't help (which may be good or bad depending on whether you want to push people to implement the actual algorithm instead of just converting the Hebrew date using the built-in. In any case, the Hebrew calendar isn't really defined beyond 2250. – Adám Dec 31 '19 at 15:47
• You can however pull back the earliest year to 1583, but not earlier, as that's the first year of the civil calendar. – Adám Dec 31 '19 at 15:49
• The mathematical formulas are really awkwardly written. Maybe MathJax those? I can do it if you want. – Adám Dec 31 '19 at 15:50
• I would adjust the output requirements to read "The Gregorian date of the first evening of Hannukah." to pre-empt people just submitting print("24 Kislev"). – AlienAtSystem Jan 1 at 8:24

Given a printable ASCII string separated with spaces, output the specified index of every word. E.g.

"are turbas unsafe ?!", 1


will yield run!

• When the index is out of bounds, this index should yield the null string (which can be joined with other strings).

## More test cases

"Is Pascal truly unloyal to users?",3 -> "sure"
"I'd pass kittens to anyone stopping by!!",4 -> "stop!"

• The definitive answer here is yes. – Lyxal Feb 3 at 6:58
• I assume this was just meant to be laying out the idea not to forget about it. But just in case I figured I should say that you definitely need to specify what happens when the index is too large for one of the substrings, and that the rest of the string will be printable ascii / whatever you choose. – FryAmTheEggman Feb 5 at 17:19
• The first test case in the more test cases section seem wrong should it not yield "sule" and not "sure"? – Mukundan314 Feb 11 at 15:56
• And the last test case only works for 1-indexing, while all others are 0-indexed. – AlienAtSystem Feb 11 at 16:10
• What happened to this user? – S.S. Anne Feb 11 at 23:58

# Is this entire list likewise-modulus-aligned?

A pair of numbers are aligned in a modulus when they all share the same remainder when they can be put under the modulus function against an integer greater than or equal to 2 and less than or equal to the absolute value of both.

For example,

13 and 22 are aligned numbers under 3 because
13%3 = 1
22%3 = 1

3<=13, 3<=22, and 3>=2

All our requirements are met.


A list is likewise-modulus-aligned when all the elements are aligned under the same modulus base.

## Challenge

Take in a list (not necessarily non-empty) of non-zero integers (not necessarily positive nor unique), and check if all the elements are likewise-modulus-aligned. Output is a truthy or falsy value.

Note; This is a "true-until-proven-otherwise" problem, meaning a single value in the list or an empty list will return TRUE.

## Example I/O

      In      | Out | Why
--------------|-----|---------
[5 7]|TRUE |1 mod 2
[7 12 18]|FALSE|(7,18) are not mod-aligned
[7 11 19]|TRUE |1 mod 2
[5 13 28 44]|FALSE|(5,28) are not mod-aligned
[10 13 37 108]|FALSE|(37,108) aren't aligned in any base below 10
[]|TRUE |No disproven pairs
[42]|TRUE |No disproven pairs
[-5 13 16]|TRUE |1 mod 3
[1 9 18]|FALSE|Arrays of size 2 or greater with 1 or -1 will always be false
[14 17 19]|FALSE|Every pair is modulus-aligned, but not under the same base
[17,22,32,107]|TRUE |2 mod 5
[4,8,12]|TRUE |0 mod 2
[-1,1]|FALSE|No mod 1 allowed
[1]|TRUE |No disproven pairs
[7,7,7]|TRUE |Numbers >=2 are always mod-aligned with themselves
[2,2,8,8]|TRUE |0 mod 2
[3 9 22 22]|FALSE|Pairs don't suddenly make (9,22) mod-aligned.


## Sandbox Questions

I'm gauging the interest to this question and seeing if this is an acceptable and unique challenge, just want to make sure I haven't missed another post doing a similar thing.

I changed the rules to be a lot more lenient on the comparisons, might do the pairwise comparison as a bonus or follow-up challenge later. But this is a compromise I can live with.

## Extra Hints/Tips

For all non-1 derivations, a number will be aligned with its negative self.
1 is never aligned with any other number, nor will -1.
A number that is a multiple of another will be aligned with that number in all its factors.
Numbers that share factors will always align, but numbers that don't share factors also may.
All odd numbers are aligned with each other, as are all even numbers.

• I'm not clear on why this challenge asks to compare all pairs of a list, rather than just a single pair. The condition covers pairs of numbers, so it would be more natural to just receive a pair of numbers as input. – isaacg Feb 19 at 18:21
• Because it's a combination of that function and a list-pair function with interesting shortcuts that can overlap. Asking for a pair could take X bits, and pushing all pairs to a function could take Y, but the combination of the two isn't necessarily X+Y. In my going at it, I saved like 8 bytes in the mix by being clever. This way, there are several ways to solve while still being a challenge. – Mathgeek Feb 19 at 18:24
• Some test cases that are not 1 mod x would be good – Jo King Feb 20 at 5:21
• Good suggestion, Jo. I just added one, and I'll add a few more in a bit - I hadn't even caught that! – Mathgeek Feb 20 at 13:32
• While what you observed can be true, in my experience it is not usually a source of interest in golfing to combine tasks unnecessarily. Similarly, does including negative numbers make this task more interesting? In most languages this will not make a difference, but it will make answering in some languages (consider Retina) substantially more difficult - to the point where people probably won't answer. I always try to recommend making a challenge as simple as possible - just like writing a proof. – FryAmTheEggman Feb 20 at 18:59
• I made negative numbers allowed because negative modulus is still a valid application of modulus - but that argument of "combining two things" is applicable to like literally every other code golf question. The string-wise calculus question could have just been "print out which of two characters is the largest", but then there was added difficulty to comparing pairs and assigning those values to distinct characters. This isn't just an arbitrary expansion, it's a setwise comparison of several elements applied over a function; You see these "expansions" all the time, so why is this one an issue? – Mathgeek Feb 20 at 19:24
• I agree that the part of the challenge where you check every pair seems unnecessary, and was going to comment on this independently. I think just having two numbers as inputs would make a better challenge overall. Or, have all numbers in the list need to be aligned by the same modulus, which seems like a more natural extension. – xnor Feb 20 at 19:33
• Okay, what about a fairer follow-up instead - instead of checking if all pairs are modulus-aligned, a list is modulus-aligned if all the entries share an identical mod-point. ie: They all have to be n mod m together for the list to be valid. Think that's still a more fair question? I think submitting pairs only is a very low-level simple problem that doesn't have any real puzzle or golfing elements to it, so I'd like it to be slightly more complex somehow. – Mathgeek Feb 20 at 19:37
• What you and xnor propose sounds good to me. I tried to phrase what I said as suggestions and opinions, because that is all they are. There isn't anything wrong with what you have, but I know I'd be more likely to answer if you changed some things about it. The same is true for many challenges on this site (including my own). Over time, I've come to see that including requirements that are technically valid but aren't necessary rarely adds interest to a challenge. – FryAmTheEggman Feb 20 at 20:29
• Doesn't [10 13 37 109] satisfy 1 mod 3 (and therefore it is modulus-aligned)? – Bubbler Feb 20 at 23:45
• You're correct fixed! – Mathgeek Feb 21 at 13:14
• @KevinCruijssen But that's fine. If I have a list [7, 14], they are aligned under Base 7. – Mathgeek Feb 21 at 14:40
• I also just read the "(not necessarily positive nor unique)" part of your challenge, so you might want to add a few test cases containing multiple of the same number in that case. – Kevin Cruijssen Feb 21 at 14:46
• Nice challenge btw. And good choice on explicitly mentioning "Note; This is a "true-until-proven-otherwise" problem, meaning a single value in the list or an empty list will return TRUE.", since those [1]/[-1] test cases are really annoying in my approach. ;) I had a prepared solution which worked for all initial test cases in 10 bytes, but now it's 50% larger to 15 bytes just to fix those two test cases, haha. Looking forward to when it goes live. I would leave it in the sandbox for a little while longer for others to give feedback though, just in case. Oh, and welcome to CGCC! – Kevin Cruijssen Feb 21 at 15:05
• @xnor yes, the question then dissolves to finding whether the gcd of the differences of consecutive elements is >1. – Don Thousand Feb 21 at 16:09

## Square-Cube Digit Usage

• In response to the first sentence: nice. – Lyxal Feb 20 at 0:43
• I'm not exactly sure how your title relates to the challenge. Obviously "Square-Cube Digit Usage" won't exactly roll off the tongue, but what you have now seems misleading. – FryAmTheEggman Feb 20 at 20:22
• Nice challenge. I prepared a solution for when it goes live. I would add a few more test cases first, though. One suggestion: 1333 (or 3133/3313/3331) -> 111 (first positive integer as input that has a 3-digit number as output). Here the results for the first 10,000 inputs. – Kevin Cruijssen Feb 21 at 10:53

# Draw an American flag for any amount of states

The flag of the United States of America goes by many names. The Stars and Stripes. Old Glory. The Last Known Non-Erotic Usage Of The Verb 'To Spangle'.

It is also one of the few flags semi-regularly updated. The red and white stripes represent the 13 original states, but one more star has been added to the blue canton for every state that joined the union later. This last happened in 1960, when Hawaii got in. Flag designs with 51 stars are already waiting for when Puerto Rico or Washington D.C. are made states, but this vexillologist is lazy. You are to make a program that can draw the flag with any number of stars desired!

### Specification

Here's a neat image of the official, government-standardised design for the current U.S. flag:

Disregard the contents of the canton for now. Your program must draw a flag that adheres to only the ratios I give here:

• A (the height of the flag) = 1
• B (the width of the flag) = 19/10
• C (the height of the canton) = 7/13
• D (the width of the canton) = 19/25
• L (the height of any stripe) = 1/13

Because raster solutions are not exact and this flag is commonly misdrawn anyway, there's tolerance of 2% for every ratio, taking the flag height as the base.

Furthermore, the correct colours must be used.

• Every odd-numbered stripe must be this shade (hex): #B22234
• The blue canton must be in this shade: #3C3B6E
• Every even-numbered stripe, and every star, must be in this shade: #FFFFFF

Conversions to other colour coordinate systems can be found on the wiki page as well.

### Stars

Your program must takes as input any integer between 0 and 200, and draw that number of stars within the canton. The following rules apply.

• Each star must have five outer points and be five-fold rotationally symmetrical.
• Each star must be the same size.
• The bounding circles of stars may overlap, but the surface of the stars itself may not overlap.
• The bounding circles of the stars may go outside the canton, but the surface of the stars itself may not go outside the canton.
• I don't want solutions that just place every star on the same line; that would leave a lot of blue canton untouched, which would be a waste. So, as a rule, the combined surface area of the bounding circles of every star in the canton must be at least 20% of the surface area of the canton.

Since overlapping bounding circles still count, you get a formula for the minimum width w of the star, where a is the area of the canton and n the number of stars: . See here for how it's derived.

### Other specifications

There's no minimum or maximum size for your output image, though I recommend something that will allow 200 stars to fit but still be demonstrably star-shaped. When they are only a few pixels high, it becomes hard to argue that they have the required amount of points. Obviously, for vector solutions any size is permissible.

This is , so the smallest program wins!

### Test cases

Because I gave no specific arrangement of the stars (you may arrange them however you want), there is an infinite number of correct and incorrect solutions for each number of stars. These are just examples of valid and invalid solutions:

Valid:

Invalid (stars too small):

Valid:

Invalid (stars of unequal size, going out of the canton):

Invalid (stars have too many points, stripes have wrong colours, colours are the wrong hue, proportions are wrong):

## Sandbox

Do I need more test cases? Any other feedback?

• If you really want to allow 0 as an input, you'll need an exception to the rule that the combined areas of the bounding circle must be at least 20% of the area of the canton. (If there aren't any stars, there aren't any bounding circles, so the combined areas would be 0.) – Mitchell Spector Mar 7 at 2:19
• I know it's less thematic, but maybe the task could be just to draw the canton? Arranging and drawing the stars is the interesting part, whereas the stripes aren't changing, so in terms of golfing the stripes seem somewhat extraneous. I guess you could also have the number of stripes be variable. – xnor Mar 7 at 17:40

## Symmetrical difference code-golf

Post'd.

• If a language supports it, can we take output and input as sets instead of a lists? – Chas Brown Apr 9 at 8:08
• I don't think it's a dupe. Post it. – null Apr 27 at 0:02

# Help, I've mixed my week up!

My dog ate my calendar, and now my days are all mixed up. I tried putting it back together, but I keep mixing up the days of the week! I need some help putting my calendar back together, with the days in the correct order.

And since I need my calendar put together as fast as possible, don't waste my time by sending me superfluous bytes. The fewer bytes I have to read, the better!

## Input

The days of the week, in any order. Input can be taken as a list of strings, or a space separated string, or any reasonable way of representing 7 strings (one for each day of the week).

The strings themselves are all capitalized, as weekdays should be, so the exact strings are:

Monday
Tuesday
Wednesday
Thursday
Friday
Saturday
Sunday


## Output

The days of the week, in sorted order (Monday - Sunday). Output can be as a list of strings, or printed with some delimiter.

## Disclaimer

Note that this is a challenge, with the added benefit of being able to use the input to shorten your code. You are not required to use the input if you don't want to.

## Examples

To see example input and output, you can consult this python script.

## For the sandbox

• You cannot use 6 tags, and this still needs [code-golf]. Otherwise this seems to be a nice challenge. (I can see a 4-6 Jelly solution by sort-nth permutation though) – the default. Apr 28 at 1:03
• @mypronounismonicareinstate I forgot about the code-golf tag, but of course it should be there. I have my own solution in MathGolf (not quite 4 bytes), but I'm interested in different approaches. – maxb Apr 28 at 6:19

# Fold my ACGT proteins code-golfstringbiologychemistry

Quoting Wikipedia, "Protein folding is the physical process by which a protein chain acquires its native 3-dimensional structure, a conformation that is usually biologically functional, in an expeditious and reproducible manner.". I don't know what that means but by means of a game called Foldit it seems we can use protein folding in some way to help and fight diseases.

Please bear in mind that the task described was inspired by the isolated meaning of the words in "protein folding" and doesn't necessarily translate into how protein folding really works! i.e. the title is just a pun.