# Sandbox for Proposed Challenges

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

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
• 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!

# Arbitrary base conversion

Given an integer n of any sign, output a list of digits of its representation in a given base b not in -1, 0, 1. If b is positive, n will be non-negative.

Rules:

• You may not use arbitrary base conversion built-ins like Jelly's b or 05AB1E's в.
• You may assume the input is valid, as above.
• All digits must be greater than or equal to 0 and strictly less than b.
• For zero you must return [].

# Test cases

256, 10 -> [2, 5, 6]
256, -10 -> [3, 5, 6]
1000, 25 -> [1, 15, 0]
1000, -30 -> [2, 27, 10]
0, 300 -> [0]
1000, 1000 -> [1, 0]
18446744073709551615, 4 -> [3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3]
18446744073709551615, -5 -> [3, 3, 2, 1, 3, 3, 1, 2, 1, 2, 2, 3, 0, 1, 1, 4, 0, 2, 0, 4, 3, 4, 2, 3, 3, 1, 4, 4]


# Sandbox

Is this a dupe?

• I'd suggest 0 in any base be the empty array, so it doesn't need special handling from recursive solutions and the like. – ETHproductions Aug 6 '17 at 21:57
• @ETHproductions Let's see...well, [0] shouldn't actually need special-case handling if you put the sum check before the special cases...but otherwise I did consider []. – Erik the Outgolfer Aug 7 '17 at 8:47
• We had this challenge which was closed as dupe of that challange. – nimi Aug 20 '17 at 18:10
• @nimi Hmm...from the title you would guess that it's about converting to bases 2..36 although that doesn't seem to be the case so not sure if this is a dupe or something. – Erik the Outgolfer Aug 20 '17 at 18:29

# Bomberman

Given an input Bomberman board b, use the following characters to define the different bomberman tiles:

• X denotes the outer boundary of the board.
• X is always in each of the four corners of the board.
• X may only be on the boundaries of the board.
• - denotes an empty space.
• When a bomb blows up over an empty space, it replaces it with *; and may continue.
• o denotes a blocker that is breakable.
• When a bomb blows up over a breakable blocker, it replaces it with *; and stops.
• O denotes an impenetrable blocker.
• When a bomb reaches an impenetrable blocker, it stops prior to it.
• 0-9 describes a bomb of n power.
• When a bomb explodes it explodes in a plus pattern.
• A bomb of 0 strength would be: *.
• A bomb of 1 strength would be: * \n***\n *
• And so on... 1-indexing is not okay because that would make the 9 bomb a 10 bomb.

# Worked Example

An example board would be (without bombs):

XXXXXXXXXXXX
X----------X
X-oo---O---X
X--------O-X
X--OoO-----X
X----------X
X--O-------X
X-------O--X
-----o------
X---------OX
X--O---o---X
XXXXXXXXXXXX


If we were to add some randomized bombs to this board we would see:

XXXXXXXXXXXX
X----------X
X-oo-1-O---X
X--------O-X
X--OoO--0--X
X---1------X
X--O-3-----X
X-------O--X
--4--o------
X---------OX
X--O-2-o---X
XXXXXXXXXXXX


This should, when input to your program, output the following explosion pattern:

XXXXXXXXXXXX
X----*-----X
X-oo***O---X # This didn't get blocked, it's just a small explosion.
X----*---O-X
X-*O*O--*--X # This destroyed a brittle block.
X-****-----X
X-*O*****--X # This got hard blocked.
X-*--*--O--X
*******---** # Notice how it wraps, because there's no boundary.
X-*--*----OX
X-*O****---X # This got hard-blocked.
XXXXXXXXXXXX


# Example 1:

Input:

XX
XX


Output:

XX
XX


# Example 2:

Input:

X-O--X
-o2-o-
-1--1-
-o-2o-
X--O-X


Output:

X-O--X
-****-
******
-****-
X--O-X


# Example 3:

Input:

X     X
OOOO
1114

X     X


Output:

X    *X
OOOO*
*******
****
*
X    *X


# Rules

More examples, soon. Is this good? Sandbox? What should I change?

# Is Effort Inversely Correlated with Upvotes?

Inspired by this chat message and the subsequent conversation

## Introduction

PPCG is infamous (famous?) for it's short golfing language answers that are showered with upvotes. But, are these short answers full of hard-core golfing, or are they just a few builtins that work? Do these answers take effort, and deserve upvotes, or are upvotes and effort inversely correlated?

## The Challenge

To get some variables out of the way, x=effort, and y=votes

Your challenge is, given a question ID, output A if the question has a strong positive correlation between effort and votes, B if it has a weak correlation between efforts and votes, or C if it has a strong negative correlation between effort and votes. A may be any value never given as B or C, B may be any value never given as A or C, and C may be any value never given as A or B (You doubt have to have consistent values across runs, but the set of values for A must not intersect with B or C, etc.).

### Defining Effort

Effort is an awfully complex concept, but for this challenge we will grossly simplify it to the number of significant edits. significant edits, in this context, will be the number of edits, by the question author, that occurred more than 1 minute after the previous edit (initial posting, in this case, counts as an edit).

Votes is upVotes - downVotes.

### Defining Correlation

For the sake of simplicity, will we use the least-squares regression line as our correlation model. If R^2 (the determination coefficient) is less than .3 (e.g. < 30% of the variation is explained by the model), we will say that there is weak correlation. If R^2 is greater than or equal to .3, we will say that the correlation is strong. Negative vs. positive correlation must be determined from the sign of R (the correlation coefficient).

### What Points?

The data points that should be included in your regression are points of the form (votes, effort) for each answer in the given question.

//TODO

### Specifics

• For the purposes of this challenge, you may access the api.stackexchange.com website. You may not shorten the URL with any out-of-language utilities (e.g. tinyurl, but you can still compress it if your language supports compression)
• You may not violate any standard loopholes
• You may take input and give output in any reasonable format
• You should exclude community wikis from your calculations

# Meta

• @programmer5000 okay – Socratic Phoenix Aug 22 '17 at 20:32
• "number of edits greater than 5 characters" counted how? Levenshtein distance with substitution counted as 1? (This is a terrible proxy for effort: apart from anything else, adding strikeout to record a one-byte improvement would take you past the threshold, even if the improvement was suggested in comments and required no effort on the OP's part). – Peter Taylor Aug 23 '17 at 21:23
• @PeterTaylor that's intentional (the strikeout), but I agree that's it's a bad proxy for effort.. I'll try and create a better one... – Socratic Phoenix Aug 23 '17 at 21:39
• @PeterTaylor updated definition of effort, is it better or worse? – Socratic Phoenix Aug 24 '17 at 18:03

# Word Problem Generator popularity-contest

Word problems can be a great way to test comprehension of concepts, but they are pain to write. That's why you need to make a program that takes an equation (or set of equations), and makes a word problem out of them. For example, if the input is x+3=8, you can output, Mary has 3 more apples than Johnny. If Mary has 8 apples, how many does Johnny have?

The best answers for this challenge will be able to handle many different types of equations and randomly generate a variety of unique word problems. It might be o.k. if your program creates non-sensical word problems, as long as they describe the input equation/equation set and people like them.

# Rules

• Submission must be no longer than 2000 bytes
• External files and URL's may be used to access word lists not specifically made for this challenge. You can also use libraries for parsing mathematical equations and sentence generation that were not specifically made for this challenge (WolframAlpha is acceptable). Inquire about other acceptable usage of external sources.
• Golfing is encouraged. Most popularity contests ask for readable code, but with a tight 2000 byte limit, I encourage golfing as much as possible (even using a golfing language), so that you'll have enough bytes remaining to create interesting word problems.

# Examples

• atan(x) = 5/4 => "At what angle should Jan hit the soccer ball to hit a target 5 feet high and 4 feet away?"
• x+5 = y, 2(x-1) = y-1 => "Paul is 5 years older than Sally. Last year Paul was twice Sally's age. How old are Paul and Sally?"
• x = 6^2/4^2  => "How much more pizza is there in a 12 inch pizza than an 8 inch pizza?"

# Submission

With your submission, you include the types of equations/equation sets it can handle (we'll assume that a,b,c,d,e,f,g refer to constants and t,u,v,w,x,y,z refer to variables).

As an example, let's say your program can only make 1 type of word problem: "How long will it take for a boat with speed a to catch up to a boat with speed b that is distance c ahead of the first boat?" In that case, you write that your program only handles equations of the form at = bt + c, so people will know to only test it with things like 5t = 3t + 2 or 4t = 2t + 1.

Furthermore, you should mention if your program can make multiple types of word problems for one type of equation/equation set. For example, an equation of the form a + bx = c could lead to word problems about the time it takes to get from one point to another, or the amount of a particular coin you need to reach a certain amount of money.

Likewise, mention other ways your program creates variety in generating word problems.

Finally, you can include some sample word problems your program has generated, and the equations they were for.

# Minimum Requirements

The most basic acceptable solution should handle at least 1 equation/equation set with at least 1 variable, 1 constant, and 1 mathematical operation. Such a minimal program might only handle equations of the form x = a + 1. It might output word problems like, "If Jerry has a apples, and he picks 1 more, how many does he have now?" Obviously, you should not strive for the bare minimum.

All suggestions welcome!

• In case you haven't seen it yet: Tag Wiki for popularity contest. As noted there, you should include an objective validity criterion. You already have some useful rules, but it's still not clear me what the minimum requirement for an answer is. E.g. would handling only equations x=1+2 suffice? What about only x=3. – Laikoni Jul 21 '17 at 8:51
• @Laikoni ty, updated. – geokavel Jul 21 '17 at 15:35
• Personally, I dislike the scoring. Having a hard byte count limit discourages more verbose languages, but at the same time, byte count is not a factor in scoring. Also, I'm not sure popularity-contest is the right choice here. I would either 1) Make it a code-golf and impose strict requirements on what the program should be able to do, or 2) Make it a test-battery, where the score is the percentage of inputs that result in coherent output – musicman523 Jul 21 '17 at 20:59
• @musicman523 I've thought about other formats than pop-con, but I think they all significantly reduce creativity. I don't have a perfect answer for byte count limit, but I think it is needed, otherwise people can spend forever hardcoding all sorts of words problems, which is not really what I'm looking for. Also, one tradeoff is the languages that are usually more verbose are the more established ones that also have more library access. – geokavel Jul 21 '17 at 21:55

# Help Me Catch Up With xkcd! code-golfinternet

I definitely enjoy xkcd, and you, as a code golfer, most likely enjoy it as well. However, I often find that I won't check the website for a while and there will be a lot to read! So, I want to make a solution for that. In proper code golf fashion.

## The Challenge

Your task is to write a program which, when run, will check for a new xkcd and, if there is a new comic (in other words, it is different from the one when the program last ran), output the text "There's a new xkcd out!". Use this method to check:

1. When the program is run, check if there is a file named .xkcd in the user's home directory. If not, create the file, which will contain the title of the current xkcd comic, then exit.
2. If the file .xkcd does exist in the user's home directory, the program will check if the title of the xkcd comic on the front page of xkcd.com is the same as the one in .xkcd. If it is, the program will exit and do nothing else. However, if the titles aren't the same, the program will output the specified text, change the contents of .xkcd to the new title, then exit.

If you have any other methods, tell me about them.

This is , so may the shortest code win and the best programmer prosper...

• This seems rather close to codegolf.stackexchange.com/q/91847/194 – Peter Taylor Aug 27 '17 at 15:51
• @PeterTaylor Dupe? – ckjbgames Aug 27 '17 at 22:06
• @PeterTaylor Also, how could I distinguish it and add something unique so that it isn't marked as a dupe? – ckjbgames Aug 27 '17 at 22:10
• My opinion in general is that when a question is a borderline dupe it's more productive to ditch it and try to think of a radically different question than to try to bisect to find the minimal sufficient difference. I don't see anything about this particular topic which would make it an exception to that general rule. – Peter Taylor Aug 28 '17 at 14:09

# Here's a list of languages & byte counts from PPCG:

Jelly, 27 bytes
Mathematica, 174 bytes
Scala, 91 bytes
05AB1E, 12 bytes
dc, 13 bytes
Python 2, 115 bytes
V, 25 bytes
Charcoal, 48 bytes
Jelly, 10 bytes
MATL, 14 bytes
x86-16, 43 bytes
Emoji, 50 bytes
Pyth, 9 bytes
C, 38 bytes
JavaScript, 69 bytes
R, 73 bytes
Node.js, 70 bytes
Ly, 7 bytes
Japt, 7 bytes
Java, 2777 bytes
Husk, 18 bytes
Beatnik, 148 bytes
APL, 10 bytes
Powershell, 127 bytes
Python 3, 111 bytes
Ruby, 38 bytes
Cubically, 1231 bytes
C++, 292 bytes
Common, 98 bytes
Swift 4, 63 bytes
Axiom, 91 bytes
Groovy, 7 bytes
Bitmap, 160 bytes
Batch, 86 bytes
Perl 5, 34 bytes
Pyke, 7 bytes
Java, 182 bytes
PHP, 1 bytes
C#, 163 bytes
Processing, 85 bytes
Tcl, 66 bytes
PowerShell, 11 bytes
LOGO, 33 bytes
axo, 22 bytes
Excel, 37 bytes
TXR Lisp, 76 bytes
Alice, 17 bytes
Moorhens, 716 bytes
PHP, 2943 bytes
Python, 79 bytes
QBIC, 25 bytes
D, 65 bytes
Emojicode, 50 bytes
REXX, 46 bytes
BBC, 70 bytes
Retina, 24 bytes
Bash, 74 bytes
Cubix, 28 bytes
cQuents, 7 bytes
J, 90 bytes
AHK, 110 bytes
Mathics, 46 bytes
RProgN 2, 8 bytes
SOGL, 36 bytes
Röda, 36 bytes
><>, 238 bytes
C#, 289 bytes
Bash, 385 bytes
JS, 2823 bytes
C, 14 bytes
HTML, 132 bytes
Ruby, 40 bytes
JS, 130 bytes
Gaia, 17 bytes
TI-BASIC, 17 bytes
Befunge, 10 bytes
Ruby 2.4, 53 bytes
Pari/GP, 21 bytes
Actually, 10 bytes
APL, 4 bytes
TXR, 74 bytes
Sage, 102 bytes
Grime, 28 bytes
Ruby, 101 bytes
C++17, 71 bytes
Perl, 41 bytes
CPython, 25984 bytes
SmileBASIC, 43 bytes
WendyScript, 50 bytes
Python, 2969 bytes
Clojure, 156 bytes
Lost, 57 bytes
C++, 19 bytes
Brachylog, 4 bytes
Octave, 25 bytes
C#, 123 bytes
Magneson, 102 bytes
Brain-Flak, 36 bytes


This list will change before this challenge is posted.

Look at the program before you. It will print something like JS, 23 bytes. That means that you must use JS as your language.

Then pick a line from the list. Let's say you pick LOGO, 33 bytes. That means that you must print LOGO, 33 bytes in JS.

Because LOGO, 33 bytes is the 44th line, your byte count modulo the number of languages in the list (there are 100) must equal 44.

The three restrictions:

• You must use JS
• You must print LOGO, 33 bytes
• Your byte count modulo 100 must be 44

So a valid submission might be:

x=>"LOGO, 33 bytes"//just wasting some bytes


Then, after your submission, you add the list from the last answer to your answer. Then, you remove Logo, 33 bytes from the list: (in your answer, not the question)

That's the language you used, and the byte count you used. Add it to the bottom. Dupes are OK.

# JS, 44 bytes

x=>"LOGO, 33 bytes"//just wasting some bytes


### Here's the new list:

(Insert the list here, and remove Logo, 33 bytes)


The next submission must use Logo.

Note that the list will continually get smaller, making the challenge harder.

# Meta

• Winning criterion? Last answer? Second-to-last?
• Unclear?
• Dupe?
• @BusinessCat Ok, I think I'll restrict to TIO-only langs when I update the list. Thanks for the feedback! – user58826 Aug 23 '17 at 14:00
• 1. In the interests of clarity, when picking arbitrary numbers make them different. 44 seems to occur in two different contexts in the example. 2. The bit about adding to the list is unclear. Are you saying that after submitting an answer, you must edit the question? That will (a) cause conflicts; (b) (I think) cause the question to become community wiki quite quickly; (c) break the example. And to accomplish what? 3. Expanding on that previous question: what is the motivation? Even answer-chaining questions benefit from a clear motivation for the core task. – Peter Taylor Aug 23 '17 at 21:29
• @PeterTaylor I hope the recent edit clarified 2., and I will use a different list when I post this (1.) – user58826 Aug 24 '17 at 11:38
• @programmer5000 Röda – Erik the Outgolfer Aug 25 '17 at 14:15
• @programmer5000 Thanks, that clears up adding to the list. – AdmBorkBork Aug 25 '17 at 14:25
• You probably want to remove from the list either what language was previously printed or what language you're currently printing, that way the list remains modulo 100. – AdmBorkBork Aug 25 '17 at 14:28
• I think that every answer-chaining question so far has some mechanism to make it increasingly harder to extend the chain. With this one it seems to get easier to extend the chain rather than harder. Is this not a fundamental flaw? – Peter Taylor Aug 27 '17 at 17:34
• The way I read it, every answerer removes one item from the list and adds one item to the list, so it doesn't get shorter. – Peter Taylor Aug 28 '17 at 13:56

# Where in the world am I?

## Original Challenge

This challenge has a single aim, given no input, print out the user's current location, with a minimum of the following info:

• City
• Country

So any of the following are allowed:

• "London, England"
• "Eifel Tower, Paris, France"
• ["London", "England"]
• {"country": "Scotland", "city": "Edinburgh"}

The following are not allowed:

• [51.5074, 0.1278]
• {"country": "Scotland", "city": "Edinburgh", ISP: "EE"}

Do not show the user's IP or ISP name, or any extra output.

Standard code golf rules apply

Good luck, and have fun!

## Reason for limits

• No ISP or IP
• Stops just using ipinfo.io
• No long and lat

## Thanks

programmer5000 - Suggesting to post here after original was deleted

caird coinheringaahing - Lon and Lat rules

• Is returning a list of geo-cordinates allowed? You might want to clarify that in the question – caird coinheringaahing Aug 28 '17 at 14:12
• This has a number of issues with ill-defined cases. In particular, the following are not addressed: (A) my location is unambiguously in a given country, but there's no city within several hours' drive; (B) my location is unambiguously not inside any country; (C) the territorial ownership of my location is disputed; (D) it's not clear what the name of the country is (where your example of Edinburgh is a good one: if Scotland is correct, is UK incorrect? How about dependencies, colonies, etc?) – Peter Taylor Aug 28 '17 at 21:26
• In addition, it contradicts itself over whether {"country": "Scotland", "city": "Edinburgh"} is allowed or not; and it is not very testable. To make this a good challenge I would recommend taking latitude and longitude as inputs and providing a complete and unambiguous specification of exactly what the output string should be such that any incorrect answer can be shown to be incorrect with a test case which it fails. – Peter Taylor Aug 28 '17 at 21:28
• TBH, if someone was onboard the International Space Station and decided to take time out to complete my code golf challenge I would take it as a compliment. For international waters I would be OK with an answer that pointed towards that. For ones with multiple answers / disputed it would probably be reasonable to accept multiple answers, but there may be issues with this I have not foreseen. – jrtapsell Aug 28 '17 at 21:35
• RE: The contradiction, this was an omission I hope I have fixed now – jrtapsell Aug 28 '17 at 21:37
• Is there a way to fix this issue more generally? I know my answer is a bit vague and not built into the question – jrtapsell Sep 1 '17 at 10:31
• Is this challenge good to go, needs changes, or not of use? – jrtapsell Sep 2 '17 at 23:20

# Paint with Pride!

Task: Output a 6 banded version of the pride flag

Details:

The flag consists of 6 bands of colour, each band is rectangular, and all are the same size which is 9x1 units (WxH) . These bands are stacked one on top of each other in the order shown to form a flag that is 9x6 units in size.

The output scale can be chosen by the participant, but all components must be in those ratios, that is, an output must have an aspect ratio which is a multiple of 3:2.

The hexadecimal values and relative positions of the colours are as below:

Or from top to bottom RGB (255,0,0), (255,153,0), (255,255,0), (0,153,0), (0,0,255), (204,0,153)

A minimal version would look like this:

Acceptable output:

Output to screen or as a file in a commonly accepted image format is allowed, ascii art is however not.

Sandbox notes:

related, related

I chose this flag because I think the rainbow provides potential for an additional mathematical element

I'm not sure whether to include a minimum size limit, such as the one for drawing the french flag, as perhaps the small output size allows hardcoded answers to succeed (which I don't really want) - any advice?

• This is a duplicate of this unfortunately – caird coinheringaahing Aug 29 '17 at 19:05
• @cairdcoinheringaahing Shoot, all that time searching for "Pride" and "Flags", forgot to search for rainbow! Perhaps this is significant-enough a variant (rectangle vs bow) that it will allow for different approaches though. I'm not sure what the etiquette is, but I guess I'll leave this up for a while longer and let votes tell me whether it is too much of a duplicate to post. – Greedo Aug 29 '17 at 19:25
• personally, I would close as a duplicate, but if you want to keep it here and see otherwise, go ahead. – caird coinheringaahing Aug 29 '17 at 19:26

# The source of pi

Inspired by an International Obfuscated C Code Contest entry.

As you all know, pi is a constant that represents the ratio of a circle's circumference to its diameter.

Using the dimensions of your own source code, approximate pi to at least two decimal places.

That is, your source code should read itself to obtain both circumference and diameter, then output the ratio.

For example, if your code is:

 AB
CDEF
GH


Your circumference is 14 and your diameter is 4.

For the purposes of this challenge, let diameter equal the larger of the height or width of your code.

## Rules

• Take no input
• Hardcoded values for pi are not allowed
• Output pi to at least two decimal places (e.g., 3.14 and 3.1415 are both acceptable outputs)
• Answers can be either whole programs or functions

## Notes

Answers with higher precision values are acceptable.

Standard rules apply.

## Meta

Looking for suggestions of a better title.

• Well, I'm not sure what "Using the area of your own source code" means. I could do some pretty "standard" approximation algorithm to fullfill your rules. – Felix Palmen Aug 29 '17 at 16:58
• Wouldn't print(3.14) work? It isn't hardcoding pi, as pi isn't 3.14. – caird coinheringaahing Aug 29 '17 at 19:22
• @FelixPalmen - I've updated the specification. Hopefully it is more clear. – CzarMatt Aug 29 '17 at 20:14
• @cairdcoinheringaahing - I've updated the specification. Hopefully it is more clear. – CzarMatt Aug 29 '17 at 20:16

# "Square Root of Pi(e)"

A pie (r=3) is drawn as such:

  @@
@@@@
@@@@@@
@@@@
@@


Pretending that it's a perfect circle, the square root of such a pie would be sqrt(PI*32) = 3sqrt(PI) ~ 5.317. Now take a square out of the pie, whose area is closest to the square root of the pie. In this case it would be a square of area 4. Therefore, you can output:

  @@
@@@@
@@  @@
@  @
@@


Yep, I took a square out of the pie, how do you like that?

r=7

      @@
@@@@
@@@@@@
@@@@@@@@
@@@@@@@@@@
@@@@@@@@@@@@
@@@@@@@@@@@@@@
@@@@@@@@@@@@
@@@@@@@@@@
@@@@@@@@
@@@@@@
@@@@
@@ 

7*sqrt(PI) ~ 12.407. Closer to 3x3 than 4x4 square.

      @@
@@@@
@@@@@@
@@@@@@@@
@@@@@@@@@@
@@@@@@@@@@@@
@@@@@@@@@@@@@@
@@@@@@   @@@
@@@@@   @@
@@@@   @
@@@@@@
@@@@
@@ 

### Specifications:

1. Input will be only a "pie" with integer radius of at least two. As you can see, the longest row has 2r @s, and the smallest rows have 2 @s.
2. You can use a symbol other than "@".
3. You can take a square out of the inside or the edge.
4. Approximate PI to at least 3.14.

Bonus: Valid answers that are in a language with food-related name get a free upvote!

• You don't ever define How one forms the pie shape, and in general you seem to be lacking specification. – Wheat Wizard Sep 3 '17 at 3:37

# The Best Question

This site gets a variety of questions: the good, the bad, the ugly. However, I've noticed some patterns that I think will help us find The Best Question (of a given week).

## Procedure

You are given a date in a human-readable format of your choice as input. You need to find the best question from that week. The week starts on Sunday and ends on Saturday. Click on the link for a valid query to use if the input is Aug 31, 2017. Note that when using the API without a key you can use UNIX epoch time or YYYY-MM-DD to specify the dates (info here). Since this site gets only about 45 questions a week, you can assume that no more than 100 questions will be asked in a given week in order to avoid pagination.

## Scoring

First of all, closed questions are disqualified. Next, here is the formula for Question Rating (QR)1, given Question Score (S) and Number of Answers (A):

The thinking is that there are two kinds of questions that undeservedly get a very high question score: 1) the ones that are easy and get a lot of answers, and 2) the ones that are so difficult that they get few or no answers. I've determined that the best questions have a QuestionScore:Answer ratio of about 3:2.

## Output

All you have to do is output the full URL of the question that got the best question score. If multiple tie, you can output them all or just one.

## Example

Here's a list of 8 imaginary questions, with their question score followed by the number of answers they received, and their resulting QR:

1. +6, 23A -> -0.333
2. +10, 0A -> 7.78
3. +8, 4A -> 7.56
4. -2, 6A -> -4.44
5. +5, 3A [closed] -> DQ
6. +20 2A -> 16.22
7. +24, 40A -> 16
8. +15, 14A -> 13.67


So the winner is question 6. Output its URL.

## Note

You don't need to handle the rare edge case when there are no valid questions in a given week.

1Disclaimer: This scoring system is just a joke.

Suggestions on formula and other stuff welcome.

• Is that abs((QuestionScore/2)-Answers)/2 or abs(QuestionScore/(2-Answers))/2? – Shaggy Sep 1 '17 at 12:05
• Hopefully this looks a bit better. – geokavel Sep 1 '17 at 15:29

# Extend the Pattern

Given a raster image with a lattice pattern, extend it to twice the size of the input image in both directions.

### Details

The input image is a section of an infinite repeating pattern defined by two vectors u=(ux,uy),v=(vx,vy) with integer entries, that are linearly independent. This means that both vectors are nonzero and do not point in the same direction. The pattern is defined such that the pixel at a point p = (x,y) has the exact same colour as the pixel at

q := p + s*u + t*v


for every integer s,t. This means if you know the colours of the pixels within the fundamental parallelogram Z = { s*u + t*v | s in [0,1),t in [0,1)} and corresponding vectors u,v you can extend the pattern to an arbitrary size. The goal of this challenge is finding the pattern and extend the image.

### Specs

• You can take the input image in any non-compressed image format that allows for at least 3 colours, this includes e.g. matrices, 2d arrays or strings.
• The input method must match the output method. That means if you read a .png file as input, you must also write a .png file as output, or if you take the input via console, you must also print the output via console e.t.c.

### Examples

• Is there freedom to choose which quadrant of the output image corresponds to the input image? – Peter Taylor Sep 3 '17 at 18:05
• You need to add some harder test-cases - at present you can just check for overlaps, tile "infinitely" then crop. – wizzwizz4 Sep 4 '17 at 16:25
• @PeterTaylor Good question, I think I will leave the direction arbitrary. – flawr Sep 4 '17 at 19:53
• @wizzwizz4 I think this method works in any case, or do you have an example in mind where this does not work? – flawr Sep 4 '17 at 19:54
• @flawr One where there's less than one copy of the parallelogram... wait, that wouldn't prevent the overlap technique from working. – wizzwizz4 Sep 4 '17 at 19:58

# Golf a Brainfuck compresser.

The eso-lang Brainfuck only has 8 instructions that do something: +-><[],. so in theory you could represent them in 3 bits. You could store 8 instructions in 24 bits or 3 bytes.

## BrnFck

This is compressed brainfuck an instruction will be represented by its bits.

1. + : 000
2. - : 001
3. > : 010
4. < : 011
5. [ : 100
6. ] : 101
7. , : 110
8. . : 111

This is a language counted in bits, 8 bits is 1 byte depending on the challenge you may round up or keep a decimal.

## The goal

Write the shortest program that can compile any inputted brainfuck code to BrnFck code:

• You can choose how you output it, byte,bit/boolean arrays and output streams are all acceptable. Just printing ASCII-letters is too.
• You can do anything (including crash) if the input isn't valid code or contains a non-bf character.

And can compile the BrnFck code back to Brainfuck (or any other language (except BrnFck)). You may ask which way you want to compile or write 2 separate programs/functions and sum their scores.

If you post the code online (for example as an answer) this should automatically allow BrnFck as a language in all future challenges!

## Scoring

If you use brainfuck you can divide your bytes by 2.

If you use BrnFck you can divide your bytes by 4 (let's get some recursion going here).

1 bit will be counted as 0.125 bytes (please put both in the title) so decimal byte scores are allowed.

## Tags

brainfuck,code-golf,...

• This encoding doesn't really work since no sensible architecture allows partial bits. Since each 3 bit word is already used, there is no way to distinguish say ,+. from ,+.. if you happen to fill the remaining bits in that way. That said, it isn't totally required for the question for this to work. Otherwise, the bonuses and scoring are needless and confusing, so I'd recommend removing them. – FryAmTheEggman Sep 3 '17 at 16:57
• Nearly every byte score on PPCG is decimal (base 10): I think you mean that fractional byte scores are possible. To deal with the padding problem, I suggest that you specify that where one or two padding bits are required, 0 should be used; and where three to seven are required, the padding should be 101 followed by as many 0s as necessary. Since [] must be balanced, this allows unambiguous detection of the padding on decompression. Then make sure to include a test case which ends in ] and requires no padding... – Peter Taylor Sep 4 '17 at 8:02

# Program that allows the user to edit it's own source code

Write a program that displays and allows the user to view, edit and save it's own source code.

• If no edits are made, the output file should be the same as the program, and hence executing it should allow the user to edit the program's code again. (ie a quine)
• If the code has been edited in a sensible way, running the program again should display the edited code. The definition of 'sensible' is left flexible to prevent this being impossible - as the source code can be edited, a user can obviously edit the program in such a way that it no longer displays it's source code.

The standard quine rule applies: no reading the source file directly.

Additional Notes and things to consider:

• How robust is your program? What percentage of your program can be edited (sensibly) before it stops displaying it's own source or saving the edits you made.
• Both overwriting and saving with a different filename are valid ways for the program to save it's new code
• If it is a compiled language, the program does not have to invoke the compiler or do the compiling itself after saving.
• This is a code challenge not code golf. Robustness, interface and 'coolness' of the solution are favoured over brevity.

• Extra, uh, points(?!) if your program can identify errors in the quine before saving.

Is this a feasible challenge? Does it need clarification?

• If the only winning-criteria is "Percentage of the characters which can be changed without breaking it" then the answerer can arbitrarily pad their score with an irrelevant string if their language has very versatile quining capabilities. The other things "favored" only really count if it's a popularity-contest and challenges with that tag are discouraged. – Kamil Drakari Sep 7 '17 at 21:07
• Do you have any suggestions on how to score it? I can't think of any cross-language methods. – sdfgeoff Sep 7 '17 at 21:21
• Currently you are scoring it as (characters that can change / total), You could square or cube the total to incentivise golfing, that way padding can only hurt you. However you want to watch out for very short programs that make little effort to complete the task but by virtue of their shortness are highly scoring. – Wheat Wizard Sep 17 '17 at 0:35

# Prime Number Locator

Given a prime number p > 1, determine at what index p appears in A000040.

• You may 0 or 1 index, meaning 2 can return 0 or 1.
• If you are given a non-prime number you must return -1.
• If you are 1-indexing you may return 0 instead, or still return -1.
• Your time complexity must be less than O(n): Please explain your calculations in the answer.

First 10 return values (0-indexed):

[2, 3, 5, 7, 11, 13, 17, 19, 23, 29]
[0, 1, 2, 3,  4,  5,  6,  7,  8,  9]


This is : Reduce your byte-count to win.

• Related – H.PWiz Sep 8 '17 at 17:41
• @H.PWiz, I'd call that a dupe; the count is the index. – Shaggy Sep 9 '17 at 11:48
• @Shaggy This one is restricted-complexity though – H.PWiz Sep 9 '17 at 12:00
• o(n) is impossible: this isn't a problem which can be solved without reading all of the input. If that were relaxed to O(n) I think this would fit the "Too broad" close criterion because a properly explained answer would be a (very good) doctoral thesis. The current state-of-the-art algorithms are O(2^(2n/3) + epsilon), so a polynomial algorithm would already be impressive, and a linear one would be astounding. – Peter Taylor Sep 11 '17 at 8:59

# Do the line segments cross?

Description: Today, we're going to do some geometry: We have two line segments and want to find out where they cross! A point is a pair of two integers being the x and y coordiantes of said point. If your calculations result in non-integers, you continue with the integer closest to your result.

I/O: You are given the two segments in form of 8 integers representing the 4 end points. You may take them in the order that fits you best, but you have to state the ordering. The output consisting of the point where the lines intersect, or null, an empty string or something similar, but no undefined behavior. You may use STDOUT, a file etc. to write your output.

This is - the shortest answer in bytes wins!

• Can I take 4 tuples (x,y) instead? – H.PWiz Sep 8 '17 at 17:46
• Of course. Are you golfing in Haskell? – racer290 Sep 8 '17 at 18:03
• I'm not golfing now. Many languages have tuples. – H.PWiz Sep 8 '17 at 18:05
• This is just a subset of this challenge. – AdmBorkBork Sep 8 '17 at 19:48
• Only up to a certain degree. The challenge you mentioned is ok with a truthy/falsey value. That makes a difference in chosing your "algorithm". – racer290 Sep 9 '17 at 5:17

...?

# Fork for n times

TL;DR: fork up to n times, than hang forever

Relevant chat discussion

Your challenge is to make a program / function that calls itself twice or uses some other method of creating copies of itself that create copies of itself, etc.

However, to avoid crashing the system, your program limits itself before it forks to death. Given an input n, your program should stop forking when it has n total copies of itself (including itself), and keep running forever with n total copies of itself.

# Meta

• Under-specified?
• Is the min of 500 good?
• Tags?
• Better title?
• It's not exactly a dupe of this one, but that one is the same spirit, and it's closed and locked, so I wouldn't expect this to be well received. Also see this and this – DJMcMayhem Aug 22 '17 at 21:41
• @DJMcMayhem see edits – user58826 Aug 22 '17 at 22:05

[tag:H̸̡̪̯ͨ͊̽̅̾̎Ȩ̬̩̾͛ͪ̈́̀́͘ ̶̧̨̱̹̭̯ͧ̾ͬC̷̙̲̝͖ͭ̏ͥͮ͟Oͮ͏̮̪̝͍M̲̖͊̒ͪͩͬ̚̚͜Ȇ̴̟̟͙̞ͩ͌͝S̨̥̫͎̭ͯ̿̔̀ͅ]

# Parse HTML with regex!

Alternate titles:

# Background

Don't parse HTML with regex. It always fails and sometimes summons Cthulhu.

But, because PPCG is different, we will parse HTML with regex.

And not easy, beginner HTML. HTML with comments, attributes with no quotes, HTML in script tags not commented out and much more. Can you write a regex to parse that?

# The challenge

Your challenge is to make a regex that matches valid HTML tags. Don't match comments, don't match invalid HTML, don't match HTML in comments, just match valid HTML tags. Each full regex match is one HTML tag.

Your input HTML will never contain commas. You will try to get the most points possible by successfully matching the HTML tags and not the text in as many inputs as possible. Whoever gets the most points wins. Please say at least 1 regex flavor that your regex works with.

You are not allowed to use regex features to execute language code. (Sorry, Perl)

The length of your regex is irrelevant, this is not code golf.

# Test cases

Here are the test cases. You can also find them at https://hastebin.com/raw/mikaxakipe.txt.

1,1,<b>HTML!</b>,<b>,</b>
2,1,<i><b>HTML</b></i>,<i>,<b>,</b>,</i>
3,1,a < b implies b > a,
4,2,<img alt=text>Img,<img alt=text>
5,2,<a href = "http://example.com">Example Domain</a>,<a href = "http://example.com">,</a>
6,2,<hr><br/>,<hr>,<br/>
7,2,<div id ="hi" class="what">What</div>,<div id ="hi" class="what">,</div>
8,3,<a>fake</>,<a>
9,3,Self-closing <img src = "self-closing.jpeg" />?,<img src = "self-closing.jpeg" />
10,3,<self-closed/>O_O<unclosed>,<self-closed/>,<unclosed>
11,3,Do<yOU>like<LoTs>of<mIXeD><cAsE>?,<yOU>,<LoTs>,<mIXeD>,<cAsE>
12,3,Wh<a b='c'd="e">at?,<a b='c'd="e">
13,3,Hi<p data-hi=3>hihihi</p>,<p data-hi=3>,</p>
14,4,<a"oops">Oops,
15,5,<!-- <b><!--hi--><i>,<i>
16,5,<0>NOT VALID</0><h0>fine</h0>,<h0>,<h0>
17,5,<a a=b<>what</a>,<a a=b<>,</a>
18,6,<!-- <b><!--hi--><i>-->,<i>
19,7,<how><deep can><your nesting nesting><level></level></go>?<how>Deep</how><can><your>nesting <go x=? j><how><deep can><your nesting nesting><level></level></go>?<how>Deep</how><can><your>nesting <go x=? j><how><deep can><your nesting nesting><level></level></go>?<how>Deep</how><can><your>nesting <go x=? j></your></can></your></deep></how></your></can></your></deep></how></your></can></your></deep></how>,<how>,<deep can>,<your nesting nesting>,<level>,</level>,</go>,<how>,</how>,<can>,<your>,<go x=? j>,<how>,<deep can>,<your nesting nesting>,<level>,</level>,</go>,<how>,</how>,<can>,<your>,<go x=? j>,<how>,<deep can>,<your nesting nesting>,<level>,</level>,</go>,<how>,</how>,<can>,<your>,<go x=? j>,</your>,</can>,</your>,</deep>,</how>,</your>,</can>,</your>,</deep>,</how>,</your>,</can>,</your>,</deep>,</how>
20,7,<plaintext><b></plaintext>,<plaintext>,</plaintext>
21,7,What<img src="imgs/>lolz.png" alt = "<heh"/>,<img src="imgs/>lolz.png" alt = "<heh"/>
22,7,<b><a href = "#" title = "4 > 3">hi</a></b>,<b>,<a href = "#" title = "4 > 3">,</a>,</b>
23,10,<StYle><b title = "not in html"></style><B>HTML!</b><style></style>,<StYle>,</style>,<B>,</b>,<style></style>
24,10,<script>//<script>< /script></script><script></script><p>,<script>,</script>,<script>,</script>,<p>
25,10,<i></i this="will be removed by a browser">,<i>,</i this="will be removed by a browser">
26,10,<div id="hi" class=class="what" data-the="heck='is'this" get-good>Attributes are weird<div>,<div id="hi" class=class="what" data-the="heck='is'this">,<div>
28,13,<textarea><script>/* *////*///*<!--</script><b>WHAT</b></textarea><i>Hi-->,<textarea>,</textarea>,<i>
29,15,<!--<b>Do you like comments??</b><script>--><script>//<!--hello</script><b>hi</b><!--What--><script>//<!-- <script> <!-- <script> --> </script><i>hello--><script></script>,<b>,</b>,<script>,</script>,<i>,<script>,</script>
30,15,<hi>hi</hi><0>hi</0><h0>hi</h0><h&>hi</h&><&>hi</&><??>hi</??><?php>hi</?php><php?>hi</php?><->hi</-><_-_>hi</_-_><h->hi</h-><_>hi</_><h-_>hi</h-_><?>hi</?><{>hi</{><h{>hi</h{></>hi<//><h~!@#$%^&*()>hi</h~!@#$%^&*()><h>hi</h><h~>hi</h~><h!>hi</h!><@>hi</@><h@>hi</h@><h!@#$%^&*()>hi</h!@#$%^&*()><@f>hi</@f><%>hi</%><;>hi</;><h>>hi</h>><h&>hi</h&><h~>hi</h~>,<hi>,</hi>,<h0>,</h0>,<H&>,</H&>,<PHP?>,</PHP?>,<h->,</h->,<H-_>,</H-_>,<H{>,</H{>,<H~!@#$%^&*()>,</H~!@#$%^&*()>,<H>,</H>,<H~>,</H~>,<H!>,</H!>,<h@>,</h@>,<h!@#$%^&*()>,</h!@#$%^&*()>,<H>,</H>,<H&>,</H&>,<h~>,</h~>
31,30,<hi>hi</hi><0 WHAT_is=HtMl>hi&<i attrubute="oops'></0><h0 attRiBu350Te="<b>oops</b><style>/*">hi</h0>*/<h&>hi</h&><&>hi</&><??>hi</??><?php>hi</?php><php?>hi</php?><->hi</-><_-_>hi</_-_><h->hi</h-><_>hi</_><h-_>hi</h-_><?>hi</?><{>hi</{><h{>hi</h{></>hi&<//><script>     &/*<h~!@#$%^&*()>*/</ script></StyLe>/*</ScrIPT>/*<b>oops</b>hi</h~!@#$%^&*()><h>hi</h><h~>hi</h~><h!>hi</h!><@>hi</@><h@>hi</h@><h!@#$%^&*()>hi</h!@#$%^&*()><@f>hi</@f><%>hi</%><;>hi</;><h>>hi</h>><h&>hi&</h&><h~>hi/*/</h~><b>oops</b>hi</h~!@#$%^&*()><h>hi</h><h~>hi</h~><h!>hi</h!><@>hi</@><h@>hi</h@><h!@#$%^&*()>hi</h!@#$%^&*()><@f>hi</@f><%>hi</%><;>hi</;><h>>hi</h>><h&>hi&</h&><h~>hi/<script></StyLe></ScrIPT><textarea><b>HE COMES</b></textarea><h!>hi</h!><@>hi</@><h@>hi</h@><h!@#$%^&*()>hi</h!@#$%^&*()><@f>hi</@f><%>hi</%><;>hi</;><h>>hi</h>><h&>hi&</h&><h~>hi</h~>,<hi>,</hi>,<i attrubute="oops'></0><h0 attRiBu350Te="<b>,<style>,</style>,<textarea>,</textarea>,<h!>,</h!>,<h@>,</h@>,<h!@#$%^&*()>,</h!@#\$%^&*()>,<h&>,</h&>,<h~></h~>


Each line is a separate test case. They are in this format:

1,1,<b>HTML!</b>,<b>,</b>
| | |            |   |
| | |            +---+- The correct output: all HTML tags in the string separated by commas
| | +- The HTML for you to parse
| +- The number of points you get if you parse this HTML correctly
+- The test case number


# Example

Let's say we have the regex /<.*?>/g (all flavors). For test case #1, it matches 2 times: <b>, and </b>. The correct output in the test case says that it should match <b> and </b>, so it is correct. Our regex gets 1 point.

Then for test case #2. Our regex matches <i>, <b>, </b>, and </i>, which is consistent with the test case so we get 1 point.

Now for test case #3. Our regex matches < b implies b >, when it should have not matched anything. We get 0 points for that.

Continuing for each test case gets us a score of 50 (out of 207, or 24.15%). Not great. Can you do better?

# Try It Online

If your regex will work with the ECMAScipt / JS flavor than you can try it here and get automatic scoring!

# Tie breaker

Here are the scoring systems. Whoever has the best score on the first wins. In the event of a tie, whoever out of the ties scores the best wins, etc.

1. Most points
2. Shortest length
3. First posted

# [insert score here] / 207 points

[insert regex here]


Explanation (optional but encouraged)

Proof of score (matched output vs. test cases, link to TIO to try it, etc.)

# Meta

• Any tie breaking for regexes with the same score, e.g. length? – Laikoni Sep 11 '17 at 5:28
• 1. This is a meta-regex question, and scoring it just on test cases means that there are already programs out there which will generate a regex that gets a perfect score. As it stands it's a pretty pointless contest. 2. I don't see a specification for an HTML tag, or even a link to one. Why, for example, is < b implies b > invalid? Without a spec it's even more a meta-regex question rather than an HTML question. 3. This isn't parsing HTML with regex. It's closer to lexing HTML with regex, and no-one said that that was impossible or would summon the Elder Ones. – Peter Taylor Sep 11 '17 at 7:50

# Matrix Decomposition

## Meta

• Duplicate?
• What rules should I add?
• Are my explanations sufficient?
• Any room for improvement?

It's possible to "factor" any invertible (a.k.a. non-singular) square matrix A into a combination of a permutation matrix1 (P), a unit3 lower triangular matrix2 (L), a diagonal matrix4 (D), and a unit upper triangular matrix2 (U).

That is, A = PLDU

For instance, the matrix [[4, 5], [2, 3]] can be expressed as the multiplication of the following matrices:

P = [[0, 1],
[1, 0]]
L = [[1, 0],
[2, 1]]
D = [[2, 0 ],
[0, -1]]
U = [[1, 3/2],
[0, 1  ]]


Given an invertible square matrix A, output P, L, D, and U.

# Test Cases

TBD


# Rules

• Any reasonable output format is acceptable, but P, L, D, and U must be separate outputs.

1. A permutation matrix is a permutation of the identity matrix.

2. An upper triangular matrix is a square matrix whose nonzero values occur only on or above the main diagonal, and a lower triangular matrix is a matrix whose nonzero values occur only on or below the main diagonal.

3. A unit triangular matrix is a triangular matrix whose main diagonal is all 1s.

4. A diagonal matrix is a matrix whose nonzero values occur only on the main diagonal.

# Become a Word-Pontif

The french used to define the word pontif as one who builds bridges stemming from the conjunction of pons, facere which literally translates to a bridge, to create one. Your task will be, given a list of 1 or more lower-case words l (String Array), output the MAXIMUM length of a bridge that can be built from these words.

# Bridge Rules

• Bridges can be made by connecting two or more words together:
• Words must be connected prefix-to-suffix or suffix-to-prefix.
• To join two words into one:
• The suffix of the first must match the prefix of the second (abc+cba=abcba).
• The prefix of the first must match the suffix of the second (earl+toe=toearl).
• If a word's prefix/suffix contains more than one common character:
• You can only connect them with the maximal common substring.
• In other words,abc and bcdefg can be connected using a[bc]defg.
• The length of a bridge is simply the length of the conjoined words in characters.

# Building Material Rules

• The list will contain at fewest 1 word.
• The list may hold 0 links between words, in this case the maximal size is the longest word in the list.
• The list will not contain the empty string and will only use the lowercase alphabet (a-z).
• The list MAY NOT contain duplicates.

# Examples

Example 1:

[abcdefgh,holographic,graphical,quine,loitering]

abcdefholo[graphic]al = 19

19


Example 2:

[noon,moon,loon,noon,groom]

groo[m]oon

8


Example 3:

[spoon,whatifgodwereoneofus,oneofusisatraitor,aaaaaaaaaaaaaa,aaaaaaaaaa]

whatifgodwere[oneofus]isatraitor (because the two aaaaa's overlap too much).

30


Example 4:

[abc,def,ghi,jkl,mnop,qrst,uvwxyz]

uvwxyz (No matches)

6


Example 5:

[xox,xxox,lol,lolol,lololol,xoxx]

xo[xx]o[x]ox    < 8  (Maximal of the xox path)
[lol]o[l]ololol < 10 (Maximal of the lol path)

10


Example 6 (Base):

[hi]

hi

2


Example 7:

# Note, when a link has been used it cannot be used twice.
# In other words, the brackets used cannot overlap in these examples.
[aa,aaa,aaaa]

aa[aa][a]a (Chose to use aaaa,aaa,aa)

7


# General Rules

• 1. This is extremely close to codegolf.stackexchange.com/q/132561/194 . 2. Examples 5 and 7 look wrong. – Peter Taylor Sep 12 '17 at 8:52
• In example 1, isn't it abcdefgholographicaloitering = 28? – KSmarts Sep 18 '17 at 14:22

# Word Grid Pathfinding

A follow up to Generating Word Grids and Validating Words in Word Grids.

## Meta

My original idea for this was to have entries compete, but I'd like to have different winning conditions. Given grid x, pit all scripts against each other for the following win criteria:

• Highest Score
• Shortest Path
• Fewest remaining tiles
• Longest Words

but I think perhaps just making it code golf and offering a bounty to each of the criteria above after some time. I'd like some feedback on this. I like @LegionMammal978's idea, but feel like perhaps that could be a separate challenge (again, only if these are interesting to anyone!)

Given a grid of letters, complete a path of words that reaches from the centre of the board, to the edges. You must return lists of your moves as co-ordinates and your score will be tallied. As soon as there is a clear path from the centre to the edge, the game is over, and no further words will be scored.

## Details

Grids will always have an equal, odd, number of rows and columns, such that no direction contains fewer tiles.

## Restrictions

In the event that the grid is unsolvable (or becomes unasolvable because of your chosen path, you may return something falsy instead of a list of co-ordinates.

Your script must be able to handle grids of varying sizes and solve them in a reasonable time, such that a service like TIO can be used, without causing problems in most cases, for extremely large inputs (> 500). You are free to take input in any reasonable format, but please include a link to your script with a wrapper such that it can take input in via STDIN/script arguments via an online service.

#TODO: copy details of the adjacency rules from above.

For example, in the grid provided below, the J, I, P or O letters (north, east, south and west of the blank square) must be included, once this word has been removed, you have more available words.

There are bonus letters that provide a double point score, denoted by a lowercase letter or ! (instead of ? for a blank tile). Blank tiles are used exactly as they are in Scrabble and can count as any letter, the validating program will search for words replacing the ? (or !) with a wildcard. Letters are scored as per Scrabble:

0 points: blank tiles
1 point: E, A, I, O, N, R, T, L, S, U
2 points: D, G
3 points: B, C, M, P
4 points: F, H, V, W, Y
5 points: K
8 points: J, X
10 points: Q, Z


Your score will be calculated by the validator.

## Examples

Input:

UWDESTKP?
TERMDYTSR
ROANJLEFT
EkCI OOsT
IPAJPGMNY
MZLORITVI
GwEGgPUeI
MNROYOEER


Output:

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


Total moves: 2
Points: 21

#TODO: more examples.

# Shift-left golfer

Sometimes when doing code-golf, a person needs to understand which format is shorter:

• 2147483648
• 0x80000000
• 1<<31

You will receive a number in one of the three formats above: decimal, hexadecimal, or shift-left operation. If there is no advantage in converting it to another format, just leave the number the way it is; otherwise I want the shortest format. Of course there are numbers you can't convert to shift-left format!

# Notation:

• Hexadecimal0x#######.... where there are no leading zeros after the x. When accounting for evaluating the golfiness, the 0x part is also taken into consideration. For example 0x80000000 has a length of 10.

• Decimal#######.... where there are no leading zeros.

• Shift-left#...<<#.... no leading zeros both sides of <<. The << operator is also considered for length, e.g 1<<31 has a length of 5. You must also handle multiple digits before the << signal.

# represents a digit and ... represent possible repetition of digits

I don't care if you handle leading zeros at the input or not; but if you handle them, you must do the comparison operations without them and output also without them — You're a golfer, come on! You will understand!

There will be no accepted answer.

, so I want to know shortest answer by language.

# UPDATE 1:

In spite of @dzaima 's comment, now it also needs to handle multiple digits before << signal.

• How about just take an integer as input and return the shortest form as output? – hyper-neutrino Sep 15 '17 at 19:20
• 1<<31 has a length of 4 not 5? – Rɪᴋᴇʀ Sep 15 '17 at 22:38
• @Riker: Sorry, my mistake. Now fixed. – sergiol Sep 15 '17 at 22:59
• @dzaima: Updated. Yes, it will need to handle multiple digits before << – sergiol Sep 16 '17 at 11:07
• If you allow non-ones in front of the byte shift as input, but not as output, an input like 99<<99 would result in the output having more bytes than the input. – Jonathan Frech Sep 18 '17 at 5:23
• What about something like 0x45<<0x378? i.e., why not hex numbers in left-shifts? – wastl Jul 7 '18 at 20:38

# Translate Tetris moves to GoL!

Unless you've been living under a rock, you're probably aware of the fact that the highest voted unanswered, incredibly hard challenge to build a working game of Tetris in Conway's Game of Life just recently got answered. (Go check it out if you haven't already.)

Unfortunately, since this game is written in Conway's Game of Life, giving input to the code is a bit tricky. (Of course, if they can simulate Tetris in GoL, you can play it with tricky moves. :P) To quote the main answer:

Each move only requires editing a single bit of RAM, and this input register is automatically cleared after the input event has been read.

Each Tetris move corresponds to a single number by the following table:

value     motion

1         counterclockwise rotation
2         left
4         down (soft drop)
8         right
16        clockwise rotation


Now, of course, if there was only a way to automate this...

## Challenge

Write a program/function that takes a series of keypresses as input and outputs each keypress' respective number according to the table above.

The keypresses should map as the following:

value            motion

<                counterclockwise rotation
<left arrow>     left
<down arrow>     down (soft drop)
<right arrow>    right
>                clockwise rotation


### Specifications

• Standard I/O rules apply.
• Standard loopholes are forbidden.
• This challenge is not about finding the shortest approach in all languages, rather, it is about finding the shortest approach in each language.
• Your code will be scored in bytes, usually in the encoding UTF-8, unless specified otherwise.
• Built-in functions that perform this task are allowed but including a solution that doesn't rely on a built-in is encouraged. (Pshh, how likely is that?)
• Explanations, even for "practical" languages, are encouraged.

### Test cases

// incoming


# Sandbox

• Should I switch from keypresses to strings of ( < v > )?
• I'm really lacking on tags...
• Bump!
• Not all languages can support keypresses, so using a string would be better. – fireflame241 Sep 23 '17 at 18:20
• Also, if you go for keypresses: What happens if I hold a key for 10s? What happens if I hold a key and simultaneously press another one? – ბიმო Sep 25 '17 at 11:04

# Two-Symbol n-state Universal Turing Machine

A program is defined as a set of transition rules from one state to another based on the current state and symbol, optionally moving the tape head left or right.

The goal is to produce a program that satisfies all of the following criteria:

• It is a two-symbol Turing Machine program.
• It emulates a two-symbol Turing Machine program that is represented on the tape.
• where all tape that is not data is initialised to one symbol (designated 0 - the other is 1).

There are two scoring criteria:

1. The number of states. Smaller is better.
2. The compressibility of the program format (see below).

There is an individual scoring for each criterion and a combined position. The combined position is the sum of the ordinal positions in the leaderboard for each criterion (e.g. if your solution is 1st for number of states but 4th for compressibility it has a combined position of 5th). In the likely event of a tie, the compressibility of the program format is the tie-breaker.

## Compressibility of the Program Format

The compressibility of the program format is defined as the number of (additional) states required to write the program onto a blank (0) tape, move the head to the start position of the program and start running the emulator on the program (change state to a correct emulator state). Sandbox note: Hand-compressed test-cases? Average-case Big O?

• Todo: Work in a reference to this article and how a good solution to this challenge will reduce the upper bound for the maximum computable value of the Busy Beaver function. – wizzwizz4 Sep 22 '17 at 20:49
• Is there a way to tell the Kolmogorov complexity when compressed through a certain method? It seems like the compressibility of the input format is poorly defined and will vary between inputs. – wizzwizz4 Sep 22 '17 at 20:54
• I'm not quite seeing the busy beaver connection. Clearly it's not about emulating a single program, because in general the program itself would have fewer states than the program which puts it onto the tape and then runs the emulator; so it must be about some kind of loop over all programs, but then you run into undecidability of the termination of the emulator programs, meaning that the emulator certainly doesn't terminate. – Peter Taylor Sep 23 '17 at 20:25

# It’s raining numbers! Better to get a good umbrella!

Your task is to take in one integer input and print a “raining” alternating pattern with that number, and an umbrella of appropriate size to protect yourself from such a rain!

# Examples

1 =>

1
_|_
/   \
-----
|
C

2 =>

2
2
___|___
/       \
---------
|
|
C

3 =>

3       3
3
3       3
_____|_____
/           \
-------------
|
|
|
C

4 =>

4       4
4       4
4       4
4       4
_______|_______
/               \
-----------------
|
|
|
|
C

10 =>

1       1       1       1       1
0       0       0       0       0
1       1       1       1       1
0       0       0       0       0
1       1       1       1       1
0       0       0       0       0
1       1       1       1       1
0       0       0       0       0
1       1       1       1       1
0       0       0       0       0
1       1       1       1       1
0       0       0       0       0
1       1       1       1       1
0       0       0       0       0
1       1       1       1       1
0       0       0       0       0
1       1       1       1       1
0       0       0       0       0
1       1       1       1       1
0       0       0       0       0
___________________|___________________
/                                       \
-----------------------------------------
|
|
|
|
|
|
|
|
|
|
C


# Rules

• The output should use only the ascii characters _ | - / \ C, space, and the digits (no tabs are allowed).
• Numbers should have an alternating pattern, two digits on the same line are separated by 7 spaces.
• Number with more than one digit must be written vertically.
• The size of the first line of the top of the umbrella should be equal to 4n-1, for input n, centered below the “rain”; the size of the second line should be equal to 4n+1.
• The shank of the umbrella under the top is centered and should be of height n (the | characters), and terminated by a C handle.
• Lines can have trailing spaces.

This is a task, so the shortest solution is any language wins.

• shortest solution in any – Adám Sep 27 '17 at 7:36
• I think that you should explicitly state the input for each example output. – H.PWiz Sep 27 '17 at 9:21
• Allowed whitespace should be mentioned in the first rule. Regular spaces seem obvious, but using tab characters in place of 4 spaces could be used and it's a good idea to explicitly allow or forbid it. Also, that rule should start with "The output should..." to clarify that this is not restricted-source – Kamil Drakari Sep 27 '17 at 14:46

# Sort a nested object by nested value

Your goal is to sort a nested object by a nested value. What does that mean? For example:

#1: Input

{
foo: {
category: "A",
hello: "world",
color: "blue"
},
bar: {
category: "B",
cu: "cumber",
color: "blue"
},
baz: {
category: "A",
let: "tuce",
color: "green",
}
}


#1a: Output sorted by category

{
A: {
foo: {
hello: "world",
color: "blue",
},
baz: {
let: "tuce",
color: "green"
}
},
B: {
bar: {
cu: "cumber",
color: "blue"
}
}
}


#1b: Output sorted by color

{
blue: {
foo: {
hello: "world",
category: "A"
},
bar: {
cu: "cumber",
category: "B"
}
},
green: {
baz: {
let: "tuce",
category: "A"
}
}
}


Note that the sorting key is always deleted from the objects (when sorting by color none of the items contain color).

Given an object, and a sorting key (a string), output the sorted object as shown.

## Rules

• You can always assume that the value of the sorting key is a string (as it also needs to be a key in the output)
• You can always assume that the given sorting key exists in all values
• Sorting will only occur on the first-level objects, but the sorting key can be nested (see test case #2)
• The object may be a JSON object, a python dict, a JS object, etc. but must always have string only keys.
• You may accept the object as a JSON string and/or return a JSON string.

## Test Cases

#2: Input

Sort by: rating.healthiness

{
icecream: {
sweet: true,
rating: {
tastiness: "8",
healthiness: "4"
}
},
pizza: {
sweet: false,
rating: {
tastiness: "9",
healthiness: "3"
}
},
chocolatecake: {
sweet: true,
rating: {
tastiness: "8",
healthiness: "3"
}
}
}


#2: Output (sorted by rating.healthiness)

{
"3": {
pizza: {
sweet: false,
rating: {
tastiness: "9"
}
},
chocolatecake: {
sweet: true,
rating: {
tastiness: "8"
}
}

},
"4": {
icecream: {
sweet: true,
rating: {
tastiness: "8"
}
}
},
}


## Sandbox Questions

1. I really need to make the question clearer. Any thoughts? How can I better describe the task?
2. Is this a duplicate?
3. I'm guessing I need a better title. Any ideas?
4. Should I make the input a JSON object or just a general object?
5. Are multi-level nested objects even possible? Would it be too easy without them?
6. Should I also allow booleans & numbers as the value for the sorting key (and then in a key form it would be stringified)?

# Output the Yggdrasil graph

In Norse mythology, Yggdrasil, or the world tree, is a giant tree that spans the entire universe and connects all nine worlds of the Norse mythology together. Here, we shall take a rather liberal reinterpretation of the term "world tree" - it's the tree that contains all other trees as subgraphs. Not only that, but each graph is present everywhere in Yggdrasil. Clearly, the only way to achieve that is if every node in the graph has infinitely many neighbors.

Yggdrasil is the unique (up to isomorphism) non-empty graph with the two properties that each vertex has ℵ₀ neighbors and that there is a unique simple path between any two vertices. In other words, Yggdrasil is the Cayley graph of the free group with countably infinitely many generators. Your goal is to output this graph.

Nodes can be given any printable label of your choice, as long as they are non-empty and unique within the graph. Edges shall be denoted as pairs of vertices in either order. It must be clear from the output which are the two nodes in a graph (a-b-c is not an acceptable representation of an edge from a-b to c, but ["a-b", "c"] is fine). In the output, each edge shall be output on a single line, and different edges shall go on different lines.

The output should be just the list of edges in the graph, one edge per line. Each edge in the graph must be output exactly once, and in a finite amount of time (barring memory limitations). Edges not in the graph must not be output. For example:

• Listing the edges in breath-first order is not sufficient, as any edge disjoint from the root would not get output.
• Listing the edges in depth-first order is not sufficient, as no more than two edges of any node would ever get output.
• It is sufficient (but not necessarily optimal) to generate the output by repeating (for each node in a copy of the list of known nodes, take the first unknown child, output the edge to it and add it to the list of known nodes).

The sufficient example above will output, if nodes are labeled 0, 0 1, 0 2, 0 1 1, ... :

0 => 0 1
0 => 0 2
0 1 => 0 1 1
0 => 0 3
0 1 => 0 1 2
0 2 => 0 2 1
0 1 1 => 0 1 1 1
...

• So basically we have a countably infinite set of vertices V, a countably infinite index set I, and an injection (V x I) -> V. Since any bijection is an injection, we can use minor variants of e.g. codegolf.stackexchange.com/q/8892/194 , codegolf.stackexchange.com/q/78606/194 , codegolf.stackexchange.com/q/48705/194 with a loop for(n=0;;n++) wrapped round to create a valid answer. So although quite well disguised this is actually a dupe. – Peter Taylor Oct 3 '17 at 8:34
• @PeterTaylor not sure how that would work. Are you trying to output the complete infinite graph rather than the infinite order regular tree? – John Dvorak Oct 3 '17 at 9:00
• Use the reverse direction of the bijection: N -> (N x N). Then for(n=0;;n++)print(unpair(n)[0],"=>",n). Every node has an infinite number of successors, but each node has only one predecessor, so it's a tree. For the previous questions which use a bijection N -> (Z x Z) it's ever so slightly more subtle: to enumerate the entire tree we need to add in a bijection N -> Z and write for(n=0;;n++)print(unpair(n)[0],"=>",z(n)), but there are some very simple bijections N -> Z. – Peter Taylor Oct 3 '17 at 9:28

# Is my Sukkah Kosher?

Do not rely on this text for questions of Jewish law!

You will be given a floor plan of a sukkah as follows:

• A rectangular 2D text (in any reasonable format).
• The first and last rows and columns will consist of printable ASCII (32-126).
• All interior characters will be spaces.

Determine if the sukkah is acceptible according to these simplified rules, using the scale of one character width/height representing the tefach unit.

• The inner area, as encompassed by the completion of the two longest solid walls into a square, must be at least 6 units by 6 units.

• If the two longest solid walls are across from each other, then the shorter one must be at least 6 units long, and the length with with they are diametrically across from each other must also be 6 units long.

• There must be an additional wall which is at least one unit long.

• The walls may be made of any material, i.e. any character except space.

• Walls with single unit gaps are still considered solid.

You may answer with any two distinct values, but please specify if different from true/1 and false/0. Explanations are appreciated.

### Acceptable

oOOOo.ooo...o--o
#              @
#              )
#              (
#
|
#
+++++++*******


oOOOo.ooo...o--o

@
@
@

+++++****



o O o o o . o

@

@
@

+++++****


### Not acceptable

oOOOo.ooo...o--o
#              @
#              )
(

|
#
++++      ****


       oOOOo.ooo..

@
@
@

+++++****



o O o o o . o

@

@
@
8
8


## A Conc-urn-ing Problem

You have a mysterious urn, which contains 0 <= n <= 10 sets of k balls. Each set of balls shares a numeric label, from zero to n-1. You perform a repeated experiment, wherein you remove a ball from the urn, and note its number. If the number of balls in the urn with the same label as the ball you removed has the highest or tied for highest frequency still in the urn, you put the ball back in.

Taking the recorded results of each of the trials yields an infinite sequence. For example, you might have for n=2, k=2 pulled: 1001000000...

Given n and k write a program or function that returns a regular expression which will match any valid real number generated by this process, and which fails to match any other real number.

### Sandbox

This is missing quite a bit (haven't written a program yet), but I'm not sure if it is too tedious the way that it currently is. It's somewhat boring if restricted to n=2 but rather quickly becomes tedious after that. Since most of the result would be symmetric, would it make sense to only require the "first" result? This also seems like it removes too much of the interest in the problem.

# Search Stack Overflow for Duplicates

The Stack Overflow search algorithm has been under fire recently. Several problems with the search algorithm being flawed exist, but one of the most important issues raised is with duplicates:

[...] The search engine is used while authoring a question to find potential duplicates. At that point there is no way for you to take advantage of its features through custom search operators, and it absolutely, positively must be as good as an external search engine in this scenario. Unfortunately, it isn't. – IInspectable (source)

A flawed duplicate search algorithm causes a lot more work for the comparatively few reviewers and duplicate closers than there should be, by not informing the question askers that the question that they are attempting to post is a duplicate. It is also bad for the question askers, preventing them from finding the answer to their question until somebody reviews the question.

This is where you come in. Given the title, body and tags of a question, output a list of 25 relevant questions in a reasonable format (e.g. question ids). Your program should run within 500ms on the Stack Exchange servers for each question. (Sandbox note: How fast are the Stack Exchange servers? What conversion factor should I use to test on my hardware?) You have access to all T-SQL database tables available from the Stack Exchange Data Explorer, but the current question that needs to be checked for duplicates will be absent from all tables (so it isn't found as a duplicate of itself). To test the algorithm, it would be tested on a random selection of or all of the existing duplicates on Stack Overflow - the algorithm with the lowest average position of the duplicate master(s) in the list would win, where "not in the list" is counted as 50. The set of existing duplicates tested would be the same for all algorithms to test - rationale includes scoring of questions with multiple duplicate masters. The search algorithm should be deterministic. It is allowed to prepare a cache table beforehand - none of the duplicates to test will be passed to this part of the algorithm. This cache table should be able to be updated with new questions without being completely rebuilt. (Sandbox note: How to score this?)

(Sandbox note: The final paragraph should be spread out and better laid out and reworded, but I think the wall of text contains enough information.)