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]

Call a library function

Given a single int32, a path to a Dynamic Link Library (.dll) or Shared Library (.so), and the name of a function, return the single int32 result of calling the function on the single int32.

Examples

On 64 bit Linux: 0 /usr/lib64/libm-2.24.so fesetround0

On 64 bit Linux: 1 /usr/lib64/libm-2.24.so fesetround1

On 32 bit Linux: 1023 /usr/lib/libm-2.24.so fesetround1

On 32 bit Linux: 1024 /usr/lib/libm-2.24.so fesetround0

On 64 bit Windows: inp please\edit\filename.dll fnameout

On 64 bit Windows: inp please\edit\filename.dll fnameout

• This needs to specify that the function takes a single int32 as argument and returns a single int32. – user62131 Jun 19 '17 at 19:58
• @ais523 Thanks, done. – Adám Jun 19 '17 at 20:03
• Where's the int32 in the Windows examples? – Peter Taylor Jun 19 '17 at 20:36
• @PeterTaylor I need help with a dll that's commonly found on Windows. – Adám Jun 19 '17 at 20:38
• It's worth noting in the testcases that although libm is very commonly seen on Linux, the exact file path tends to vary from distribution to distribution. (For example, it's different on Fedora and Ubuntu.) – user62131 Jun 19 '17 at 21:59
• @ais523 Can you edit the Linux samples to replace "Linux" with "Fedora" and "Ubuntu" and give the correct paths? – Adám Jun 19 '17 at 22:00
• @Adám: Not easily, they frequently change as a result of the system being updated, and it depends on processor architecture (not just bit depth) and sometimes even configuration. Just tell people to find the path to their own libm library for the appropriate architecture. (Note that the situation on Windows is much worse, because it doesn't ship even standard DLLs like libm by default.) – user62131 Jun 19 '17 at 22:02
• @ais523 Just as plausible example, I mean. – Adám Jun 19 '17 at 22:03

What is the maximum number of backslashes (escape characters) required to mean one backslash?

If you want to use a regex to look for a backslash, you have to escape that backslash, so that the character after it isn't escaped instead. But if you then have to store this regex in a string (in a c-style language, for instance), you need to double the number of backslashes, so that a regex string to match \stuff\ would need to be "\\\\stu(f+)\\\\" (and I had to further double the backslashes to post it in StackOverflow, but that isn't executable so doesn't count).

In your answer, explain the language and the (reasonable) situation, from either real or made-up business needs, and the answer with the most backslashes (per final, output backslash) will get upvoted (permanently) and accepted (until a better one comes along). If using AutoHotKey or another language that has a different escape character (for instance, ), then instances of that character will count instead of backslashes.

This question is not how many backslashes could you use in some esoteric code-golfing language to eventually calculate to a backslash, otherwise I don't think there would be an upper limit. This instead is about feasible scenarios that force you to use a lot of backslashes.

• I feel as though this simply devolves into finding as many languages as possible that have something like eval. You can't enforce "reasonableness" as it isn't objective. Sorry, but I don't think this kind of challenge is a good fit for our site. But thank you for using the sandbox! – FryAmTheEggman Jun 19 '17 at 20:35

Meta

• Is this a good idea?
• Is the point system good?
• If so, are the point values good? I based them off of how difficult I imaged each part to be.

Overview

Randall Munroe, author of the webcomic XKCD, posted a comic a while back about a joke programming language and how it gets types confused.

Here's the comic in question

Your job is to write an interpreter for a slightly modified version of this language.

Rules

• If your language supports it, it must be a live interpreter where all input lines start with [#]> (where # is the line number) and all outputs must start with =>.
• If your language does not support it, you may substitute this with reading all the lines on the input and printing out each output on its own line, still starting with =>. Remember to keep track of line numbers.
• All commands must be usable in any order and with any parameters (within reason)
• Each command you implement correctly is worth the listed point value. See scoring to find your final score.

Integers plus numeric strings (1 point)

Given an int and a string containing a number (in that order) calculate the numeric sum of them, then return the result as a string with quotes surrounding it.

[1]> 2 + "2"
=> "4"
[2]> 6 + "13"
=> "19"


Numeric strings plus lists (1 point)

Given a numeric string and a list, append the numeric value to the list and return the list as a string.

[1]> "3" + []
=> "[3]"
[2]> "7" + [1,4]
=> "[1,4,7]"


Dividing by zero (1 point)

Any number divided by zero returns a NaN object. This does not have quotes around it.

[1]> 1/0
=> NaN


NaN plus integer (2 points)

Given a NaN object and an integer, pretend it's a string and increment the leading character, carrying over if needed. The result does not have quotes.

[1]> (5/0)+2
=> NaP
[2]> NaN+256
=> NbN


You do not need to use ASCII for this, any character set works, as long as it includes at minimum the 52 uppercase and lowercase letters.

You will never have to add a result from this to another integer. (For example, NaP+4 is invalid)

String plus string (1 point)

Given two strings, remove swap the first and last quotes with single quotes and return the result.

[1]> ""+""
=> '"+"'
[2]> "Hello"+"world"
=> 'Hello"+"world'


List of integers plus integer (3 points)

Given a list of integers (or an empty list) and another integer, return True or False based on whether the new integer matches the linear pattern.

If the list has 0 or 1 items, return True regardless (everything matches).
Determine the pattern of the list by subtracting every item by the item right before it. If the pattern is inconsistent, return False regardless (nothing matches).
Otherwise, check if the new integer matches the pattern. If it does, return True. If it doesn't, return False.

[1]> [1, 2, 3, 4] + 5
=> True
[2]> [5, 7, 9, 11] + 13
=> True
[3]> [6, 5, 4, 3] + 2
=> True
[4]> [2, 4, 6, 8] + 9
=> False
[5]> [1, 2, 1, 4] + 5
=> False


Range(a, b) (1 point)

With the Range function given two numbers, return a list of numbers from a to b.

[1]> Range(1, 5)
=> [1, 2, 3, 4, 5]
[2]> Range(3, 6)
=> [3, 4, 5, 6]
[3]> Range(6, 4)
=> [6, 5, 4]


Plus integer (1 point)

Given simply "+" and an integer, return the line number plus the integer.

[1]> +2
=> 3
[2]> +2
=> 4
[3]> +1
=> 4


Single digit plus single digit (2 points)

Given two single digit integers a and b, replace all future instances of a in the output with (a+b)%10 (where % means modulo, essentially wrap around if the result is more than 1 digit). Return Done. This effect is superficial and has no effect on math. This only affects output, not input.

[1]> 3+2
=> Done
[2]> Range(1, 6)
=> [1, 2, 5, 4, 5, 6]
[5]> 1+2
=> Done
[4]> Range(1, 6)
=> [3, 2, 5, 4, 5, 6]


Floor (1 point)

Draw an ascii art floor with the number at the bottom. The specifications are 3 lines of only pipes, then a line with a pipe, 3 underscores, the number, and 3 underscores.

[1]> Floor(4.7)
=> |
=> |
=> |
=> |___4.7___
[2]> Floor(105.3)
=> |
=> |
=> |
=> |___105.3___


Scoring

Add up the points you've earned. Your score is now calculated as (15-points) * bytecount. Lower is better.

Notes

• You do not have to account for mixing functions. For example, Range(Floor(2.3)) is invalid.
• Whitespace may be added or removed as is convenient.
• Double quotes or single quotes may be used as convenient (as long as you use the opposite for "String plus string")
• Any brackets may be used for lists, as long as it's consistent.
• A few commands were omitted from the original comic because I couldn't figure out a way to make it well specified.
• Scoring is broken: it goes up when you implement more features, but down when you golf bytes off the program. Those should probably both aim in the same direction. Also, even if you change "multiply" to "divide", you're still only scoring on the average number of bytes per feature (which incentivizes only implementing one feature, the shortest). The normal fix is to divide the byte count by the square of the points from features, lower is better. – user62131 Jun 19 '17 at 7:52
• If your language supports this, do that. If not, do this is not a very good idea. Also, reading multiple lines and the => prefix seems like it's just extra code for no good reason. – Okx Jun 19 '17 at 7:56
• @ais523 Ah thanks for catching that. What I meant was, you take your point score and calculate (15-points)*bytes. If you get all of them, your score is simply your byte count. If you get a few of them, your score is larger accordingly. Lower is better. – Daffy Jun 19 '17 at 18:29
• @Okx The => prefix is to keep with the style of the comic. And reading multiple lines is important because some of the commands affect things in the future, which you wouldn't see if you can't input multiple lines. I see what you mean though about if this, that, if not, this. Do you think the interactive approach is better or the non-interactive one? – Daffy Jun 19 '17 at 18:31
• – Martin Ender Jun 20 '17 at 9:15
• @MartinEnder I would argue that is not a dupe. That question hopes to simulate the comic's output, without making it general. Return values to functions can be hardcoded. Mine has stricter specifications. – Daffy Jun 21 '17 at 6:10

Counting from 0 - 100

I posted this question, but it was not taken very well, so I wanted to put it through the sandbox and get some feedback/help before re-posting.

Challenge

Output all numbers from 0-100. Without using any of your languages built in loops.

Loops that are not allowed

This list contains, but is not limited to

• For loops
• While loops
• Do While loops
• Goto Statment
• In Range

Rules

• I really don't think this is a good idea for a challenge. It would either be builtins, like this in Jelly, or printing literal strings, with maybe some clever compression. – scatter Jun 20 '17 at 14:37
• Ok, I will leave it here in the sandbox incase anyone else thinks that they have a way to make it better. But I will not post it. – zoecarver Jun 20 '17 at 14:38
• @Christian Definitely golfable too. – Erik the Outgolfer Jun 20 '17 at 14:49
• – musicman523 Jun 20 '17 at 15:04
• "but is not limited to" - I think you're going to need to be more explicit than that. Does array mapping count as a loop, for example? – Shaggy Jun 20 '17 at 15:42
• @EriktheOutgolfer I actually had that ready to post when this challenge was posted in PPCG, but it was deleted before I had the chance to. I was just too lazy to look up the atom list when commenting on this post :P – scatter Jun 20 '17 at 16:33
• "Without loops in your code" is a non-observable requirement. I don't think there is a good way to do what you want at all, since there are so many ways to "loop" that you can't possibly define them all. Take this for example. – FryAmTheEggman Jun 21 '17 at 1:20
• This is what Fry is referring to with "non-observable requirement". In general imposing restrictions on which features answers can use is highly problematic. a) There are many many languages that don't have to constructs you explicitly disallow, but which may have similar constructs which aren't in the spirit of the restriction either. But b) "not limited to" doesn't fly because who is to decide whether any given construct is a loop or not? There are even languages where you can write loops without any specific syntax element for them. – Martin Ender Jun 21 '17 at 8:58
• In general, if you find yourself having to impose explicit restrictions on the allowed approaches to a challenge, it's often a sign that it's not a great idea in the first place. I assume this is why the challenge wasn't received well in the first place. – Martin Ender Jun 21 '17 at 8:59

OCR

In this challenge you will attempt to write a program to perform OCR in the fewest bytes possible. The tests are linked below, the only data that your program receives is the contents of the image, you may not rely on file name, timestamp, or other metadata, additionally you may not query any external source such as the internet or dispatch an independent program to outsource the task of OCR.

Spec

Given a hand written word in in image of 80px in height. Output the word. words will consist of lowercase latin letters:

abcdefghijklmnopqrstuvwxyz


Scoring

Given the test cases, your score is a percent of the words you have gotten correct. No partial credit.

Tests cases:

TODO

• The scoring doesn't seem to be affected by the length of the code. Should the specification in the fewest bytes possible be there? – musicman523 Jun 21 '17 at 3:16
• Closely related. I think this gives a good example of how to do an OCR question well, but it also demonstrates that they're not a good fit for the site. It uses a standard database rather than home-made test cases, and tries to model the standard approach of training set and test set to prevent overfitting, but that standard approach isn't really compatible with our definition of objective scoring, because only the OP knows what the test set is. – Peter Taylor Jun 21 '17 at 8:35

Data exfiltration

Frenzy in the frequency domain.

Summary of the challenge

You must find a way to broadcast a ten-character password through a lossy communication channel and recover the password on the other side. To achieve this you must write two programs. The first program will receive the password as input and encode it as output data for the channel, the second program has to decode the output of the channel back to the password.

Some background

In signal processing theory, many problems are usually dealt with by converting a signal from the time domain to the so-called frequency domain, a trick that relies on the fact that any function can be written as an infinite series of sine waves. Signals can be converted into this domain using a Fourier transform. This transform is lossless, and the resulting signal can be converted back into the time domain using the inverse Fourier transform. The frequency domain has some interesting properties, as the actual values of the signal in it represent the amplitude and phase of different frequencies in the original signal.

A special case exists for when the signal exists out of equally spaced sampled points, called the discrete-time Fourier transform. To perform this transform the fast fourier transform algorithm is commonly used. Given a signal of N samples spaced with dt spacing, it will convert it into a signal containing N frequency bins which are each 1/(N*dt) apart.

Channel definition

The communication channel requires 256 unsigned bytes data as input, and returns 256 unsigned bytes data as output. If the input values are centered around zero and interpreted as data samples on regular intervals, then the output values represent the amplitude of the signal in the frequency domain scaled to use the range 0 to 255, calculated using a discrete fourier transform. The channel is lossy as it only transfers the amplitude of each frequency, not the phase.

It can be simulated using the following python 3 script:

import cmath
def channel():
# amount of input and output values
l=256
# read the input values from standard input as newline separated integers and center them around zero
n=list(map(lambda: min(255, max(0, int(raw_input())))-127.5, range(l)))
# perform a discrete fourier transform
v=[sum(v*cmath.exp(-2.0j*cmath.pi*t*k/l)for t,v in enumerate(n))/l for k in range(l)]
# remove artifacts due to the Nyquist limit
v[1:128]=map(lambda n:n*2,v[1:128])
v[129:]=[.0]*127
# return the scaled magnitude of each frequency bin
for i in v:print(int(round(abs(i)*cmath.pi/2)))


Input/Output

The password is randomly generated using only using visible ASCII characters (0x20 up to and including 0x7E) and is 10 characters long.

Inputting the password to the encoder, communicating it to the channel, receiving data from the channel and communicating the decoded password should all follow the default input/output rules. The password must be decoded only from data received from the channel, no side-channels are allowed.

Scoring

This is , where the score is calculated by adding the length of both the encoder and decoder program. For each language, the shortest entry in bytes wins.

Meta

• Is the challenge clear
• Is the difficulty okay
• Anything else?

Tags:

• I feel like the background could use some work. I don't think someone unfamiliar with the FFT would know things like how it is periodic in time and in frequency, or that you could use and inverse DFT formula, barring calculation inaccuracies. Your description of the channel largely requires that people are already familiar with this, or that they understand python well. The penalties are largely pointless, it only really serves to make people not want to answer your question. The question is not too hard, but I think as it is it isn't accessible to people who haven't learned this already. – FryAmTheEggman Jun 21 '17 at 1:09
• "Must output to standard output" is the sort of restriction which 90% of languages don't care about and the other 10% will require crazy amounts of boilerplate to accomplish, rather detracting from the rest of the challenge. I recommend that you link to this post to define legal forms of input and output, unless you have a good reason not to. Additionally, penalising builtins with character penalties doesn't really work because the size of the penalty differs from language to language (and those penalties are prohibitively large in most). – user62131 Jun 21 '17 at 1:35
• I've changed the input/output rules and removed the penalties in accordance with your comments. However I'm not sure how to improve the background, as explaining all the interesting tricks you can do with frequency domain manipulation would require significantly more explanation than possible (or interesting for most people) in a challenge. If people really want to learn about the details of it, the background section offers a few links that explain it much better than I could myself. – CensoredUsername Jun 21 '17 at 12:37

List My Factors!

Introduction

Given an algebraic expression as input, list all the factors of it. A factor of an algebraic expression is any algebraic expression (or simply a numerical expression, sometimes) that evenly divides it. A factor can only be an integer or an algebraic expression consisting of integers and variables.

Rules

• The algebraic expression will contain * to denote multiplication.

• The algebraic expression will only contain integer constants and coefficients.

• The algebraic expression will contain ^ to denote exponentiation.

• The algebraic expression will only contain positive constants, coefficients and variables.

• Your program should output only the positive factors.

• The algebraic expression will not contain negative exponents.

• You must not use any built-in to accomplish this.

• Standard Loopholes apply.

Examples

The algebraic expression 5*x^2 has the following factors:

1. 5
2. x
3. x^2
4. 5*x^2
5. 5*x
6. 1

The algebraic expression 10*(x-y)^2 has the following factors:

1. 10
2. 5
3. 2
4. 1
5. (x-y)
6. (x-y)^2 or x^2 + y^2 - 2*x*y
7. 2*(x-y)^2 or 2*(x^2 + y^2 - 2*x*y) or 2*x^2 + 2*y^2 - 4*x*y
8. 5*(x-y)^2 or 5*(x^2 + y^2 - 2*x*y) or 5*x^2 + 5*y^2 - 10*x*y
9. 10*(x-y)^2 or 10*(x^2 + y^2 - 2*x*y) or 10*x^2 + 10*y^2 - 20*x*y.
10. 10*(x-y) or 10*x - 10*y
11. 2*(x-y) or 2*x - 2*y
12. 5*(x-y) or 5*x - 5*y

The algebraic expression x^2 - y^2 has the following factors:

1. 1
2. x-y
3. x+y
4. x^2 - y^2

Input

Your program may take the input in any way except assuming it to be present in a predefined variable. Reading from file, input box, modal window, command line etc. is allowed. Taking input as function argument is allowed as well.

Output

Your program should output a list of factors of the given input as a collection data type (such as array) or as a separator-separated String.

Your program may output in any way except writing the output to a variable. Writing to file, screen, modal window, command line etc. is allowed. Outputting using function return is allowed as well.

Test Cases

Input               Output

5*x^2               [5*x^2, 5, 1, 5*x, x, x^2]
10*x^2              [10*x^2, 10, 5, 2, 1, 10*x, 5*x, 2*x, x, 5*x^2, 2*x^2, x^2]
10*(x-y)^2          [10*(x-y)^2, 10, 2, 5, 1, 10*(x-y), 5*(x-y), 2*(x-y), (x-y), (x-y)^2, 2*(x-y)^2, 5*(x-y)^2]
x^2 - y^2           [x^2 - y^2, x+y, x-y, 1]


Winning Criterion

This is , so the shortest code in bytes wins!

Sandbox

1. Should I allow negative constants and coefficients? Answer : No
2. Should I allow variable exponents?
3. Is there any mistake in Examples and Test Cases?
4. How long should I let this challenge be here?
5. Any problem with the Input/Output Rules?
6. Should I allow built-in to accomplish the task?
7. Any other suggestion?
• Would x^2-y^2 be a valid input? – Leaky Nun Jun 22 '17 at 9:56
• @LeakyNun Yes . – Arjun Jun 22 '17 at 9:57
• What would the expected output be? – Leaky Nun Jun 22 '17 at 9:57
• The rules should mention that addition and subtraction are allowed; they currently don't. I'm wondering whether this challenge would be more interesting if you had to find the decomposition into "prime" (i.e. irreducible) factors, rather than just all factors, though; the two are similar tasks but the latter is more interesting and easier to read the results of. As for question 4, just leave the challenge up indefinitely; time limits on challenges are a bad idea if they're at all avoidable, as many people enjoy solving older challenges. – user62131 Jun 22 '17 at 10:01
• @LeakyNun 1, x-y, x+y, x^2-y^2 – Arjun Jun 22 '17 at 10:07
• It seems this challenge is more about parsing/pretty printing than about factoring. (The integers allow for brute forcing.) I'd recommend allowing for more flexible input and output, otherwise this is going to be trivial to write a competitive submission for some languanges with CAS but almost impossible for other languages. – flawr Jun 22 '17 at 10:09
• @ais523 I've added what LeakyNun asked to the challenge. Better? – Arjun Jun 22 '17 at 10:13
• @flawr I don't understand what you mean with your first comment. To your second point : Good point, I'll edit – Arjun Jun 22 '17 at 10:14
• @flawr Edited . – Arjun Jun 22 '17 at 10:22
• 1. The examples now contradict the spec's limitations on input. 2. What is a positive factor? Is it a factor with only positive coefficients? 3. What are the factors of x^x? 4. If this is fundamentally "factor a multivariate polynomial", I think there may be one or two questions along those lines already in the sandbox. The univariate case has been done on main. – Peter Taylor Jun 22 '17 at 11:52
• Before I forget, a nice (or nasty) illustration of the relevance of my question 2: x^3 + x^2 + 2x + 8 = (x + 2)(x^2 - x + 4). – Peter Taylor Jun 22 '17 at 16:19

Rotational Anagrams

Given, for lack of a better word, an anagram cube c with n rings and a word w, output whether or not you can rotate the individual sections to make w appear across the middle.

Constraints

• The letters that can appear are all printable ASCII characters EXCEPT for newlines.
• All three characters that make up the rings can appear (|-+).
• Your program should work for cubes of any size, though the maximum I expect you to test is my biggest case (this means that if your code won't finish for n=22 on TIO, I don't care).
• Your only input should be the ASCII-art c and the word w.
• Your only output is one of two distinct values for true/false, which are arbitrary.
• You can assume the input is well-formed, and output anything for bad input.

Examples

Example cube with n=3 and w='AXMOZC':

+----A----+
| +--Y--+ |
| | +N+ | |
B X M O Z D
| | +P+ | |
| +--W--+ |
+----C----+


Rotate the outer wheel once coutner clockwise:

+----D----+
| +--Y--+ |
| | +N+ | |
A X M O Z C
| | +P+ | |
| +--W--+ |
+----B----+


Ding-ding! A match, so we can output truthy for this, but for AXMOYC there is no rotation that allows that combination, so it would return falsy. (X and Y are not adjacent on the ring, which means they can't appear at the same time.

Here's a small cube of n=2:

+--G--+
| +P+ |
P C P G
| +C+ |
+--P--+


For an input w=PPCG|GPCP|PCPG|GCPP this returns true, everything else is false. So you can start to see that the possible keyspace of answers is always n**2, so... hint hint.

Here's the big honkin' example that took me a minute to piece up.

+----------1----------+
| +--------O--------+ |
| | +------5------+ | |
| | | +----E----+ | | |
| | | | +-----+ | | | |
| | | | | +G+ | | | | |
C 3 D E - B O L L I 4 G
| | | | | +O+ | | | | |
| | | | +--W--+ | | | |
| | | +----F----+ | | |
| | +------6------+ | |
| +--------N--------+ |
+----------2----------+


And, amongst many other strings, for w=CODE-GOLFING|CODE-BOWLING you should return true.

This is , if you're on my front lawn the third Tuesday of next month in a batman costume doing unspeakable things to my sprinkler system, you've won.

• Is this meant to be a challenge about parsing the input format? If so (and it seems to be), you probably want parsing. Also, is there a need to verify the format, or can programs assume it's correct? – user62131 Jun 22 '17 at 10:52
• @ais523 I feel like there's enoguh challenge in the parsing, and that will allow some unique interesting choices to extrapolate out the wanted symbols. You don't have to handle invalid input. – Magic Octopus Urn Jun 22 '17 at 13:39

Challenge

Given a range [0,n) that has been shuffled, return the index of each element of the range.

Examples

[1, 2, 0] -> [2, 0, 1]


This is the range [0, 3) after being shuffled. The element at index 0 in the result is 2 because, in the input, 0 is at index 2. Likewise, the 0 in the output is the index of the 1 in the input, and the 1 is the index of 2.

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


Bonus

I will award a +100 bounty to the first person to design and explain an algorithm that solves this problem using O(n) time and O(1) space.

Sandbox

• I think my explanation was rather poor. How can I make this more clear?
• Is this a dupe?
• Is the bonus a good idea? (I really want to hear the answer because I don't know if this is even possible!)
• Why [4, 3, 2, 0, 1] -> [3, 4, 1, 2, 0] not -> [3, 4, 2, 1, 0]? – Leaky Nun Jun 22 '17 at 14:25
• Oh, and do realize that this is what /: in J does, which makes this a 2-byte solution. – Leaky Nun Jun 22 '17 at 14:25
• @LeakyNun Oh, well that sucks /: – HyperNeutrino Jun 22 '17 at 14:27
• @LeakyNun Typo. Thanks! I've never used J so I didn't realize there would be a builtin for it /: maybe I could convert this into a "best-algorithm" question? – musicman523 Jun 22 '17 at 14:30
• Essentially codegolf.stackexchange.com/q/95838/194 ? – Peter Taylor Jun 22 '17 at 14:48
• @PeterTaylor Yes, essentially. And I think it's a one-byte solution in Jelly: Ụ. – musicman523 Jun 22 '17 at 15:09
• @musicman523 And it is a one-byter in Dyalog APL as well – user41805 Jun 22 '17 at 15:38
• I could do one of three things: post it anyway to allow non-golfing languages to compete, make it a best-algorithm question instead, or delete it entirely. What do you all think? – musicman523 Jun 22 '17 at 16:10
• I think that a) there's very little point in posting something which will be closed as a dupe; b) best-algorithm is hard to judge when built-ins do the job for you but their implementation might be closed or vary between versions; c) the bonus is pretty trivial provided that you specify that the code should modify the supplied array, and impossible otherwise. – Peter Taylor Jun 22 '17 at 16:17
• @PeterTaylor how can you do it, modifying the original array? – musicman523 Jun 22 '17 at 17:35
• Cycle by cycle, using ~ (bitwise not) as a flag to indicate which cycles have already been visited. – Peter Taylor Jun 22 '17 at 17:55
• What happens if the entire array is a cycle? How do you process it with O(1) memory? – musicman523 Jun 22 '17 at 18:09
• Bounty for O(n) time and O(1) space? But... but it's code golf. – Neil A. Jun 22 '17 at 21:54
• @NeilA. don't worry this isn't going to be posted, at least not as-is – musicman523 Jun 22 '17 at 22:37

Find the maximum number of coprimes in a set

Inspired by a recent question on Math.stackexchange.com, which I can't find anymore.

The challenge

Exactly what it says on the tin. You are given a set of integers and you have to create a program (according to the default definitions on meta) that outputs the size of the biggest subset that shares no divisors except for 1.

Input

A set of nonzero positive integers of length >= 2. You can take this input as per the defaults in meta.

Output

Output, print or return the size of the subset of the input that does not share any divisors except for one.

Testcases

1 2 3 4 5 6 7 8 9 10 11 12 13 14
7

1 3
1

2 3 5 7 9
4

2 3 5 7 11 13
6

• 1. The second test case is wrong: it should give 2. 2. What does it mean for a subset to share a divisor? Perhaps "the biggest subset such that no two of its elements share a divisor greater than 1". 3. In all of the test cases, it suffices to count the elements which are either 1 or prime. The question needs test cases for which that isn't sufficient. It might be nice to encode some classic graphs like Petersen's. – Peter Taylor Jun 22 '17 at 22:08

Golf a program whose behavior is independent from Peano arithmetic

Your task is to write a program that doesn't take any input, and whose termination cannot be proved or disproved inside Peano arithmetic. This is , so the shortest byte count wins!

Rules

• Standard loopholes apply
• Shortest by count wins
• You can assume that your program runs in a machine with an unlimited amount of memory.

Questions for meta

• Is this a good challenge?
• Is it a duplicate?
• I think the same question with a behavior independent of ZF set theory might be interesting as well (see this link for instance), but will attract very different answers; should I post it as a separate challenge?
• What can be improved? Are the tags ok?
• Current sandbox post that's fairly close to this one. There might be two challenges in this space, but maybe just one; perhaps you could give feedback on the other post? – user62131 Jun 23 '17 at 2:45
• It seems like the other sandbox post is pretty limited to Turing machines only, whereas this one allows any programming language, so I think the two will attract quite different answers. Secondly, I believe restricting to Peano arithmetic instead of ZF will make solutions that are simpler, so I believe the two challenges are still quite different (but I'd like input from others on this as well). – nore Jun 23 '17 at 3:06
• Is this the same as this challenge? – xnor Jun 23 '17 at 7:10
• @xnor it is the same indeed, so I guess I should instead go for independent of ZF. This makes it closer to the other sandbox proposal, but I still think allowing any programming language makes the challenge quite different from a Turing machine-only one. – nore Jun 23 '17 at 13:25
• – Peter Taylor Jun 23 '17 at 21:33
• If a program’s behavior is independent of ZF or ZFC, it’s also independent of PA, so I’d be happy to see such programs posted on the existing challenge, unless it starts getting so many answers that they get drowned out (current trends suggest that’s unlikely ☹). – Anders Kaseorg Jun 24 '17 at 6:49
• @AndersKaseorg true, it looks like people are not that interested in this kind of challenges :( The point for having two separate challenges was because ZF/ZFC-independent answers might be a lot more complicated than PA ones. – nore Jun 24 '17 at 14:28
• @nore Do you know of any simple answers to the PA challenge? I don’t think my PA answer is notably simpler than a ZFC version would be. – Anders Kaseorg Jun 24 '17 at 20:52
• @AndersKaseorg I tried to find statements that are easy to check and that are independent of PA, but the simplest I have been able to find is still the ZF-independent one used in the busy beaver paper. – nore Jun 25 '17 at 2:18

Iterate over all sets

(This question needs fixing so that the output size is not too large)

Consider all possible pairs of sets of integers (can have positive, negative and zero values) A and B such that |A| = |B| = 7. Define the set T_{A,B} = {a * b | a in A, B in B}.

The challenge is to iterate over all pairs of sets A and B so that |T_{A,B}| < 19 and the largest absolute value of an integer in A or B is at most 128. As an example of one such pair of sets, A = B = {2^i | for i in {1,...,7}}.

What should my code output?

Your code should output the pairs of sets A, B along with |T_{A,B}|.

For example:

A = {2,4,8,16,32,64,128}, B = {2,4,8,16,32,64,128}, |T_{A,B}| = 13.


Running time

Code golf the Fast growing hierarchy (fgh)

if your not familiar with the fgh you migth want to check out this explantion: Large Numbers, Part 3: Functions and Ordinals

and these value aproximations: Fast growing hierarchy Approximations

the goal this code golf is to golf the following functions:

• the exact value of fω(x) this means you can't golf the ackermann function

• the growth rate of fω2(x)

• the growth rate of fω2(x)

In any language of your chose.

This is a code golf so the smallest program that defines each of these functions wins (Note:the functions are allowed to call each other).

It is also allowed to ask for an input x and output the 3 function values in any order.

Sandbox notes

I'm not sure on which functions should be the target but these functions seem challenging yet golf-able in less than 150 bytes.

Upon closer inspection I realized that fω2(x) is probably to easy since it can be golfed with something like:

f(x,a...) {
for i in range(a.length) {
if(a[i] != 0) { //first non zero
Arrays.fill(a, 0, i, x); //replace 0's with x
a[i]--; //decrement a[i]
return f^x(x,a);
}
}
//all zeros
return x+1;
}


f(x,n) > fn(x)

f(x,0,n) > fωn(x)

f(x,0,0,n) > fω^n(x)

so f(x,0,...,0,x) (x zeros) ~= fε0(x)

Any other tags? Suggestions? Does this interest you?

• Having three winners doesn't really work. But having three separate questions is probably not the right solution either: they're close enough to be borderline dupes of each other. Perhaps the best way would be to score for the total length of the three functions, allowing the faster ones to call the slower ones but at the cost of having to name them. That might make for some interesting tradeoffs between using the functions directly vs having one function for f_{w^2 a + wb} which the others call with different values of a and b. – Peter Taylor Jun 23 '17 at 21:23
• @PeterTaylor good suggestion, I changed the win condition. But I realized those a probably not the right functions since w² can be golfed really easily. – fejfo Jun 24 '17 at 7:47
• Why not do exact values? – Simply Beautiful Art Nov 24 '17 at 20:51
• Your solution for f_{ω^2} is very sub-optimal. See my answer. – Simply Beautiful Art Nov 24 '17 at 20:53

Challenge

Write a program or function that will run without error once, but will crash when run for the second time.

If you are writing a function, you may assume the function will be run twice within the same interpreter session or program.

If you are writing a program, you may assume the machine will not be rebooted between runs.

Scoring

This is , so the shortest answer in each language wins.

• I feel like the function version is much easier than the program version so I don't think you will see many programs in languages that could do both. Take C: i=1;f(){return 1/i--;}. I don't think you could reasonably ban "global" values to prevent this, but it's up to you if you even think this is a bad thing. – FryAmTheEggman Jun 27 '17 at 1:10
• Will it run a third time? – Okx Jun 27 '17 at 10:16
• @FryAmTheEggman The answer you gave is exactly the type I would be looking for – musicman523 Jun 27 '17 at 15:01
• @Okx It would not be run a third time. For functions, the assumption is that the crash would kill the interpreter session/program. For programs, I just won't run it a third time. – musicman523 Jun 27 '17 at 15:02

What Tiles did I have?

Everyone should be aware of the scoring system in a classic board game: Scrabble. I remember going back into my old scrabble box and finding some old post-it notes containing old scores. I always wonder what the heck was played for some of the more insane point scores. That gave me the idea for this challenge...

English-language editions of Scrabble contain 100 letter tiles, in the following distribution:

• 0 points: * x 2 (These are the blank tiles)
• 1 point: E ×12, A ×9, I ×9, O ×8, N ×6, R ×6, T ×6, L ×4, S ×4, U ×4
• 2 points: D ×4, G ×3
• 3 points: B ×2, C ×2, M ×2, P ×2
• 4 points: F ×2, H ×2, V ×2, W ×2, Y ×2
• 5 points: K ×1
• 8 points: J ×1, X ×1
• 10 points: Q ×1, Z ×1

Your challenge is, given a single integer input between 0 and 185, output a corresponding sequence of scrabble tiles that sum to that score with a length between 2 and 100 characters in length.

The Specifics

• The letters don't have to spell anything, they just have to sum to that score.
• You can only use a tile the number of times it exists (E.G. E can be used 12 times).
• The shortest word is 2 characters long, for an input of 0 you get **.
• Outputs will not match between answers, as there are many solutions.

Inputs and Outputs

• Input should be a single integer, anything else is wrong.
• Output should be a single string, with no spaces, order of letters is arbitrary.

Example (Potential Solution)

0   | **
1   | *E
2   | EE
[... Pattern Omitted ...]
12  | EEEEEEEEEEE
13  | EEEEEEEEEEEA
[... Pattern Omitted ...]
68  | EEEEEEEEEEEEAAAAAAAAAIIIIIIIIIOOOOOOOONNNNNNRRRRRRRTTTTTTLLLLSSSSUUUU
[... Arbitrary Ordering Omitted ...]
185 | EEEEEEEEEEEEAAAAAAAAAIIIIIIIIIOOOOOOOONNNNNNRRRRRRRTTTTTTLLLLSSSSUUUUDDDDGGGBBCCMMPPFFHHVVWWYYKJXZQ


This is ,: Whomever contacts Cthulhu using the dark arts first wins.

• Whomever contacts Cthulhu using the dark arts first wins. that's bait – Stephen Jun 27 '17 at 20:25
• @StephenS wellp, if you want more bait check out 20 of my other random ass winning criterion for my sandboxies. – Magic Octopus Urn Jun 27 '17 at 20:27
• Sorry Sandbox sucks :/ can output be a list of one-char strings? and integer includes negatives, dunno if that's on purpose or not – Stephen Jun 27 '17 at 20:29
• @StephenS nono! That wasn't a diss on you or sandbox! That was just me stating that last 20 submission I've made to the sandbox I've put random winning criterion like "Winner buys dennis a subway footlong, or his countries' equivalent". – Magic Octopus Urn Jun 27 '17 at 20:35
• Also, it says an integer between 0 and 185. Also I mentioned words must be at least 2-chars. I feel like either my challenge's wording blows or you misread it a little. Probably more likely the challenge is worded poorly, I've had 2 already. – Magic Octopus Urn Jun 27 '17 at 20:35
• I made it a diss on Sandbox, that no one noticed them xD and I was looking in the #Input section for all the input specifics - I should have looked at the whole challenge, my bad. I just read Input should be a single integer, anything else is wrong. so that's what I assumed the whole rule for Input was (reading is hard) – Stephen Jun 27 '17 at 20:37
• @StephenS to be honest, reading isn't hard, it's contextual. I always have noticed in my career that I 100% understand anything that I create. Then, when explaining it to others, it may make literally 0 sense but be 100% viable in my head. Then like 10/12 people come forth saying "What the heck did you even try to write man?" And I realize, "what the hell did I even try to write?" Hahaha. The way I explain things to others can be horrifically inadequate by my own experience. – Magic Octopus Urn Jun 27 '17 at 20:48
• Related. It's a borderline dupe, in that the only real difference is a suitable wrapping loop. – Peter Taylor Jun 27 '17 at 21:42
• A standard Scrabble board is 15 x 15, and even a "Super Scrabble" board is only 21 x 21. Should the maximum word length be limited to 15 (instead of 100)? – Jasper Jun 29 '17 at 5:50

Display the Undisplayable

I have sometimes seen answers to challenges, written in binary machine code. The users who post them usually display them in hexadecimal representation. This representation makes the code extremely long, and does not do them justice!

Thus, we should give them help, and I don't care if they don't need it. Your task will to write a program/function/eldritch incantation to turn their beautifully golfed binary code into the shortest possible string of printable characters.

Input

A sequence of random binary data of random length. Use any of the standard IO methods (note to self: find the link to the Meta post).

Output

A sequence of printable characters. Use any of the standard IO methods.

• If encoding is relevant, you are free to choose any encoding, provided you clearly indicate which one you used in your answer. What is relevant is the number of characters anyway.

• Whitespaces (regular space, new line, non-breaking space, form feed, etc.) are considered not printable. They can be added if you wish, but their presence or absence must not impact the decoding of the output.

Conditions

• There must exist a program, that can take any possible output of your program, and turn it back into the input (providing it is not needed, but will be smiley'd at).

• If your program is run twice, with 2 inputs of same size, the 2 resulting outputs must have the same size.

• Standard loopholes apply.

Score

The score is calcaulated as the number of bytes in the input, divided by the number of characters in the output. The higher the better.

If the score varies depending on the length of the input, take its average over input sizes from 1 to 1024 bytes included (I don't think we'll have answer 1 kb long here).

Giving an answer in a binary language (machine code, LLVM bitcode, etc.) and adding the output when run with its own binary source will be smiley'd at (but no bonus, unless it can also summon Cthulhu).

Don't forget to explain how your code works!

Meta

• Do you think it's a good idea? Is there already a challenge like this one?
• Is there any blatant loophole/possible imporvements?
• What tag(s) do you recommend for this challenge? (please edit the answer)
• @Mr.Xcoder Sorry ^^ – Nathan.Eilisha Shiraini Jun 28 '17 at 12:43
• it's spelled Cthulhu – Skidsdev Jun 28 '17 at 13:10
• @Mayube That was what Mr.Xcoder's deleted comment was about... At first I didn't want to make a trivial edit, but since spelling of culture reference is such an important matter... Fixed! Now maybe I'll get more reactions about the challenge itself ^^ – Nathan.Eilisha Shiraini Jun 28 '17 at 13:14
• I think this needs a precise definition of printable character. Unicode doesn't define the term. But once that's provided this is just a base conversion with an awkward base and every answer should get the optimum score, so the scoring system doesn't work. – Peter Taylor Jun 28 '17 at 13:51
• I just wanted to say thank you for using the sandbox! I hope things go well with your challenges :) That said, I have to agree with Peter Taylor, it seems like every answer will get the optimal score. I think requiring the optimal score and changing to code-golf will work better, but there are many other ways you could fix it. Good luck! – FryAmTheEggman Jun 28 '17 at 14:03
• Worth noting that encoding is always gunna be relevant given non-printables don't count, as bytes 0x00-0x20 are non-printables by your definition, meaning if the given binary contains any of those bytes, ASCII can't be used. – Skidsdev Jun 28 '17 at 14:06
• @FryAmTheEggman I thought about something like that - maybe not the optimal score, but greater than a given value. And it seems I was right to use the sandbox, since there are already 2 potential loopholes detected! – Nathan.Eilisha Shiraini Jun 28 '17 at 14:08

Every Nth Line in Source Outputs N

Heavily inspired by Hello, World! (Every other character)

Related to my other Sandbox post Every Nth Char in Source Outputs N; is it a dupe?

Write a program that outputs 1. When the first, third, fifth, etc. lines are removed, it outputs 2. When all lines where their (1-based) index in the source, mod N, are not 0, are removed, it should output N.

This is . The winner is the program that works with the largest N, while working for all n < N (obviously, to run up to N, it has to be at least N lines long). If there is a tie, the winner is the shortest answer that reaches the largest N. Your program must at least work up to N=2, since I don't think any languages will struggle with simply printing 1.

Example

Examples are based off of this sample program:

test
hi
world
hello
12345
System.out.println(test);
timeout
let's dance


For the program to work for N=1, the original program should output 1.

For the program to work for N=2, the following should output 2:

hi
hello
System.out.println(test);
let's dance


For the program to work for N=3, the following should output 3:

world
System.out.println(test);


For the program to work for N=4, the following should output 4:

hello
let's dance


For the program to work for N=5, the following should output 5:

12345


etc.

The highest N this program could work for is its line length, 8.

Sandboxing this mostly so I don't forget about it (as I don't want to initiate this so soon after v3). Unlikely to need any serious revision, but comments are appreciated none the less.

Prisoner's Dilemma v4: The Amnesiac Gentlemen.

This is similar to v3 Petri Dilemma, except with one significant change: no one knows what round it is. The same setup, submission format, and scoring will be used. For sandbox brevity, I'm only noting the differences from v3.

Bots will receive input at the beginning of its turn in the format:

current points, enemies points, your previous moves, enemy's previous moves

The format of the move list (both yours and the enemy's) will be a string of characters, "c" for cooperation "d" for defection, in order from first round to last. However this list will contain only the first seven moves of the game as well as the most recent 7 moves (as everyone knows, you can only hold seven items in working memory). A String 14 characters or fewer would indicate a round at the beginning of the game where 14 total moves haven't yet been performed. Later rounds would be indeterminate.

Additionally, as the current round number is not being passed in, bots will be unaware of when the end of the game comes (games will still be 200 rounds). This should prevent "Ah ha, last round, I backstab!" "Ah ha, but I backstab you first, one round earlier!" strategies, which is what dominated a large swath of the v3 strategic playspace (I did tests where all backstab-early bots were coded to all backstab on the same round and there were only two that performed sub-optimally as a result, both of which were set to backstab "before all n-Tit-for-Tat strategies", moving them back 1 rounds re-elevated them above n-Tit-for-Tat again, as well as which one backstabbed the other first determining the winner between them). While several bots from v3 would be valid submissions in v4, all of the winning bots utilize more data than v4 will let them have, opening up the playing field for new techniques.

Here are four sample strategies that will be entered to start with:

Tit for Tat

def titfortatfunc(mypoints, enpoints, mylist, enlist):
if not enlist or enlist[counter-1] == "c":
return "c"
else:
return "d"


RandomPick

from random import choice
def randompickfunc(mypoints, enpoints, mylist, enlist):
return choice(["d", "c"])


Cooperator

def cooperatorfunc(mypoints, enpoints, mylist, enlist):
return "c"


Defector

def defectorfunc(mypoints, enpoints, mylist, enlist):
return "d"


(Code Golf) How Many Notes Are There?

Background

Most music games (MUG) describes the "instructions" that the player must follow as "notes". When the charts (set of notes) are first available, MUG players usually record the chart as a video and upload them to video sites. However, unless playing a full combo (able to pick up all notes) that the combo count directly shows the number of notes, it is usually not practical to count the number of notes one by one directly (since there are usually hundreds of notes), so they calculate that from the scores that may show on those videos if the score formula is known.

One of those examples is jubeat, which is somehow like a MUG version of "Whack-a-Mole". Although officially "instructions" are called "chips", players have the consensus to call them "notes". (For those who don't know what jubeat is please check it out here: jubeat - RemyWiki)

Objective

What you have to do, is to:

• Write a program or function,
• Which accepts a list of integers as the only input,
• That calculates the numbers of notes which is possible for all the given "basic scores".

Requirements

• The input can be an array of integers or a string containing those integers (Please indicate the input format).
• The integers in the input are guaranteed to be in the range of [0, 900000] inclusive.
• A case (NOTES in the formula) is possible means that, for each integer in the input, there exists a variable ACH, when substituted into the formula below, the formula evaluates to that integer. (See The Formula and Test Cases for details)
• All possible cases within the range [1, 1100] inclusive must be included in the output.
• The output can be an array of integers or a string containing the results (Please indicate the output format).
• If there is no case fulfilling the requirements, the program or function should either return an empty array, an empty string, null, or any objects indicating absence of results.
• NO RUNTIME EXCEPTIONS shall be thrown in any circumstances.

The Formula

The max score is 1000000, but here we only consider BASIC_SCORE, whose maximum is 900000.

The BASIC_SCORE is calculated by BASIC_SCORE = floor(floor(ACH * 100000 / NOTES) * 0.9), where ACH is an integer in the range [0, NOTES*10] inclusive except NOTES*10-1 and NOTES*10-2.

As a concrete example, take ACH=6850, NOTES=900, we have BASIC_SCORE = floor(floor(6850 * 100000 / 900) * 0.9) = 684999.

As a result, NOTES=900 is a possible case for the basic score 684999.

Test cases

 Input                                    | Output
-----------------------------------------------------------------------------------------
896757, 846353, 844486                   | 916
891000, 893999                           | (all multiples of 30 within [1, 1100])
899736                                   | 1024, 1025, 1026, 1027
| (342, 683, 684 are false positives because
|  in these cases ACH = NOTES*10-1 or
|  ACH = NOTES*10-2)
873540, 802468                           | (none: no case fits all inputs.
|  some cases do fit some inputs but not all)
0, 900000                                | (all values within [1..1100])
800000                                   | (none)


Rules and Winning Criteria

This is a , so the source code with the shortest length (in terms of bytes) wins. Standard loopholes apply.

Poor Man's Ransomware

This challenge is loosely inspired by the cheapo-enigma machine question. However, I beleive that the differences are substantial enough that this would not be a dupe. Feedback welcome.

You have been captured by a morally questionable "employer" and forced to write a piece of "ransomware". All it has to do is take in a string "in whatever format" and output another string (which can be used to recover the files) Essentially, across the set of all possible inputs (infinite) you will define a one to one function.

Participants will then publish their code to stack-exchange, where other aspiring "hackers" will try to break your code. A "cop" submission will consist of a byte count a sample plaintext and a sample "encrypted" file as well as an encrypted copy of your code.

Robbers will work tirelessly in another thread to reproduce your code. Any submission which correctly produces the corresponding "encrypted" files when fed the sample plaintext and itself will be considered to be cracked.

If your code lasts 7 days or longer you may mark your submission as "safe" by publishing the source code for the encryptor and a decryptor. Until this time robbers may still work to break your code. If anyone finds that a specific decryptor fails on a certain plaintext it is invalid.

The winning cop has the shortest safe submission and the winning robber has the largest sum of the bytes of his cracked cops. Ties go to the earlier poster. Good Luck!

• I'm not sure how much of the history of cops-and-robbers you are aware of. In the early days it was almost killed off as an interesting challenge type precisely by crypto, because it's so easy to make a problem which depends on e.g. factoring a large prime. In some senses this would be a duplicate of the very first cops-and-robbers. – Peter Taylor Jun 30 '17 at 20:07
• Almost every cnr problem can be solved using cryptography. Would you then say that almost every cops and robbers problem is dupe of the other ones? – Rohan Jhunjhunwala Jun 30 '17 at 20:41
• Many cnr's now try to ban the use of cryptography precisely to avoid this problem. – Peter Taylor Jun 30 '17 at 20:55
• @PeterTaylor could I ban Crypto built ins? – Rohan Jhunjhunwala Jun 30 '17 at 21:32
• What would be the point? It's crypto that's the problem, not crypto built-ins. – Peter Taylor Jun 30 '17 at 21:45
• Maybe it might not be that bad of a thing? – Rohan Jhunjhunwala Jun 30 '17 at 21:57
• It would be easy to implement some simple crypto and hardcode a key, making it impossible for robbers. – Shelvacu Jul 1 '17 at 23:39
• Isn't that what most cnr challenges center on? – Rohan Jhunjhunwala Jul 2 '17 at 0:30

Count bytes like a Java golfer

Java is verbose, everybody knows that. Sometimes, here on PPCG, it happens that a Java answer is shorter than 60 characters, but most of the time it's longer, way longer! And the Java golfers here often post improvement suggestions in comments.

Alas, the PPCG website is based on the stack software, which invisibly cuts <code> comments according to an obscure rule, which I shall name the "Java golfer's bane", making it impossible to get an accurate byte-count by copy-pasting.

The rule in question is the following:

• in a <code> tag, insert two invisible characters
• the first time after 60 non-whitespace consecutive characters
• then subsequently ever 20 non-whitespace consecutive characters

Challenge

Your goal is to help us, poor Java golfers, to get the byte-count straight from when we copy/paste code from comments.

SE software rules are, I'm sure, complex, so we will simplify a bit, but not that much.

• is mappable to UTF-8;
• must support codepoints until at least U+FFFF;
• will contain only characters with codepoints greater than or equal to U+0020;
• must be a string or a characters array/list if those accept unicode characters, or else must be an integer (16 bits minimum) array/list. Unless I forgot anything obvious, no other input format is allowed.
• If a sequence of non-whitespace characters in the input contains more than 60 characters:
• keep the 60 first characters, then skip the next 2 characters;
• then until you meet a whitespace, keep the next 20 characters and skip the next 2.
• We don't care which are the two stripped characters.
• Your output is the size of the string after being sanitized, in bytes as encoded in UTF-8! You must support very long Java answers, up to 500 characters (not bytes).
• You don't need to map to UTF-8 since I give the rule on how to count without mapping, but in some languages it might be easier to actually map!
• The standard loopholes are naturally forbidden.
• This is codegolf, so the shortest answer in bytes wins!

You may assume the following:

• the only whitespace character you will ever get is the space (U+0020). I abuse the term whitespace by including the start of the string as well in its meaning.
• no whitespace will be at positions 62, 94, 116, (+22) ... after the previous whitespace

You may not assume the following:

• The skippable characters will exclusively be the ones SE actually uses (U+200C U+200B);
• you will get only ASCII characters;
• you will not get any diacritics.

Bonus

• if your code supports Unicode code points up to U+1FFFFF, you can remove 10% off your byte count, do not round the resut.

How to count the number of UTF-8 bytes?

If you haven't a builtin for that, Wikipedia gives us the rule, based on code points:

first code point  |  last code point  |  # bytes
U+0000            |  U+007F           |  1
U+0080            |  U+07FF           |  2
U+0800            |  U+FFFF           |  3
U+10000           |  U+1FFFFF         |  4


Wikipedia goes beyond those number, but the RFC 3629 capped this mapping to 4 bytes, so we thank it!

Test cases

Work in progress!

Notes for review:

What feedback do you have for me?

Challenge

Convert and print out a time in a 12-hour format. HH:MM AM/PM

Examples

Input:

• 'Fri Jun 30 2017 21:14:20 GMT-0700 (PDT)'
• 'Sat Jun 31 2018 08:06:20 GMT-0700 (PDT)'
• 'Fri Jul 01 2017 01:14:20 GMT-0700 (PDT)'
• 'Sat Apr 10 2020 09:06:20 GMT-0700 (PDT)'

Ouput:

• 09:14 PM
• 08:06 AM
• 01:14 AM
• 09:06 AM

Rules

• I think this question has been covered pretty thoroughly by this challenge and this one, and would probably be closed as a dupe. – musicman523 Jul 1 '17 at 1:20
• did not realize it had already been done :( – zoecarver Jul 1 '17 at 1:22
• It's not exactly the same question, but I think that area has been pretty much covered. Now, what you could do is use this question as a model, but go from 24-hour time to 12-hour time :) – musicman523 Jul 1 '17 at 1:28
• I like that Idea! in fact I could take it a step further and convert a string in the following format: 2017-07-01T02:58:38.799Z to 12 hour time – zoecarver Jul 1 '17 at 2:58
• @musicman523 I made an edit to the question, what do you think? – zoecarver Jul 1 '17 at 4:16
• I definitely like this better. You should add more test cases with different days (for example, does 1 come out as 1 or 01?), months, days of the week, etc. so there is no confusion about the input format – musicman523 Jul 1 '17 at 4:27
• ok, sounds good. Is that enough test cases? feel free to edit and add more details. – zoecarver Jul 1 '17 at 4:28
• I feel like the testcases should be formatted like input -> output\ninput -> output. What about the midday and midnight? – NieDzejkob Jul 2 '17 at 17:53
• Ok, Sounds good. I am posting it. – zoecarver Jul 2 '17 at 23:12

Help! My code has exploded! code-challenge

Insert backstory here

• It must be able to be split exactly into pieces of the same length in bytes.
• Once you have separated your program into pieces, your program must print 1 if the first "piece" is removed from your code, 2 if the second "piece" is removed, etc., until the program prints n if the nth piece is removed.

For example, if your program was the following:

aabbccdd


And it could be split into 4 equal parts of length 2, then these programs must result in the following outputs:

bbccdd -> 1 (aa is removed)
aaccdd -> 2 (bb is removed)
aabbdd -> 3 (cc is removed)
aabbcc -> 4 (dd is removed)


Scoring requirements:

Your program is scored based on the number of parts that it can be split into, with each part following the rules defined above. The more parts, the higher the score.

In the event of a tie, there is a "hierarchy" of scoring methods (with the next method in the list being used when there is a tie):

• Number of parts the program can be split equally into
• Size of the full program, in bytes (shortest byte-count wins)
• Time posted (first poster wins)

Rules:

• Each byte in the program must belong to one part.
• Each part in the program must be of equal length.
• You can make arbitrarily long programs that do this. I suggest instead that each answer should describe a pattern that can go to infinity (with possibly a starting piece). However scoring is difficult, since I forsee that some answers will have the segment number within each segment, meaning that going from 99 segments to 100 segments may require more characters per segment. – Shelvacu Jul 1 '17 at 20:02
• Proof of concept for arbitrary number of segments: gist.github.com/shelvacu/e04c237ad8d1c066a7fd8b5170261e25 However, that was still fun to make so I definitely think there's potential here. – Shelvacu Jul 1 '17 at 20:13
• @Shelvacu That seems like a really cool idea, yeah. Will change my question. – clismique Jul 1 '17 at 23:12
• @Shelvacu Hmmm, I'm not sure how to properly make this into a challenge, TBH. I might scrap it. EDIT: I might have an idea, but I need to completely rewrite it. I might just delete this whole thing. – clismique Jul 3 '17 at 8:26
• If you don't want to post it I will. Keep me posted. – Shelvacu Jul 3 '17 at 22:14

Introduction

Ten years ago, a secret encryption key used by DVD players was published online. When the industry tried to censor it, the internet reacted by republishing it widely—creatively incorporating the key onto shirts, a flag and even in song.

If this code golf community had existed, I'm sure we would have joined in.

Challenge

Output the number 13256278887989457651018865901401704640.

Example input and output

Input:

Not applicable.

Output:

13256278887989457651018865901401704640

• This is code-golf I suppose, you should mention the winning condition. – officialaimm Jul 3 '17 at 17:42
• Is there any reason to believe that there's any way to compress this other than base conversion? – Peter Taylor Jul 4 '17 at 7:40

Background

Users with a high enough reputation on Stack Exchange can see the number of upvotes and downvotes on each question and answer. On Reddit, however, the net vote count and percentage of upvotes are displayed. Unfortunately due to rounding errors, it is impossible to determine exactly how many upvotes and downvotes occurred.

Challenge

Given a nonzero net vote count and a percentage of upvotes, return all possible pairs of the numbers of upvotes and downvotes.

Constraints

The net vote count can be any integer in the range [-2^31, 2^31).

The percentage can be a whole number in the range [0, 100], or a floating point number in the range [0, 1] with no more than two digits; you may decide which format to accept.

The percentage represents the percentage of votes which are upvotes, rounded to the nearest integer. So a value of 93% could be anywhere in the range [92.5%, 93.5%) that would result

The maximum numbers of upvotes and downvotes will not fall outside the range [-2^31, 2^31); that is, you should be safe using 32-bit signed integers.

You may not return two ranges representing all possible amounts of downvotes and upvotes; you must specify which numbers of upvotes correspond to which numbers of downvotes; hence you must return all possible pairs.

Test Cases

1, 67%  -> [(2, 1)]
1, 100% -> [(1, 0)]
1, 60%  -> [(3, 2)]
0, 50%  -> [(0, 0), (1, 1), (2, 2), ...]; cases like this will not be valid input
More involved ones to come...


Meta

Anything I can do to make this more clear or more fun?

• 1. Does "net vote count" mean upvotes minus downvotes? 2. The listed input 0, 100% is a special case ((0-0)/(0+0) = NaN% or a division by zero exception) so it should be mentioned explicitly in the spec, not just added as a test case. 3. Input 0, 50% would have 2^31 valid outputs, so that should also get an explicit mention because of the potential for answers to fail due to array size limits etc. Combined with point 2, I would suggest editing the question to guarantee that the net vote count will never be 0. – Peter Taylor Jul 4 '17 at 7:38
• "Unfortunately due to rounding errors, it is impossible to determine exactly how many upvotes and downvotes occurred." I was under the impression that reddit adds some random noise to the net votes (not sure about the percentage) to throw off bots or something. – Martin Ender Jul 4 '17 at 9:52
• @PeterTaylor Thank you, updated – musicman523 Jul 4 '17 at 19:33
• @MartinEnder I believe they simply stop reporting exact values after it reaches a certain threshold, but I'm not sure. For this challenge we'll assume they don't add any noise – musicman523 Jul 4 '17 at 19:34

Create The Correct Path

Which would be better code golf with shortest code and being able to run on at least two operating systems or code challenge and scoring by how many operating systems it can run on?

Given an input create a program that when ran on different operating systems creates a path for each one. For example, when ran on Windows:

[ "folder1", "folder2" ] -> folder1\folder2


Input

An array of strings or any suitable alternative. The input can be empty, in which case you would just return an empty string.

Output

The correct path for the operating system the program has been ran on.

• I'm mainly looking at feedback for what people think of this challenge before developing it further. – TheLethalCoder Jul 5 '17 at 10:16
• I think you should include other operating systems with different paths separators in the challenge itself. – user41805 Jul 6 '17 at 8:45
• @KritixiLithos I was going to, was waiting to see if I should go with code-golf or code-challenge before writing up the formatting for all the examples. – TheLethalCoder Jul 6 '17 at 9:02

Background

I'm conducting a probability experiment. I have a collection of live rats, and I'm going to assign each rat a probability as a percentage integer from 1 to 99 (inclusive). The experiment will last 10 weeks, and at the end of each week, I'll roll a 100-sided die. Any rats who have a higher or equal probability than the number I roll, I kill.

Now of course I'd rather not go actually killing rats, so I want to write a program to create a probability road to show the probability of a rat surviving, when given that rat's probability number.

Unfortunately my lab is full of rats, so I don't have much room to write this program. As a result it needs to be as short as possible in order to fit in my cramped room.

The Challenge

Given an integer 0 < x < 100, output an ASCII Art probability road that shows the rat's chances of surviving.

Input can be taken as an integer, a string, an array of digits or an array of characters.

Output (detailed below) should be either printed/outputted, or returned as a single string (not an array of strings)

But what is a probability road?

A probability road is a type of probability chart used for displaying all possible outcomes of a given event. It consists of a series of lanes, each lane being one possible outcome, and the vertical axis representing time.

For our ASCII art challenge, we want each lane to be a space with a pipe on either side, like so:

| |
| |
| |


However 2 neighbouring lanes should share a pipe, like so:

| | | |
| | | |
| | | |


Every 2 lines of ASCII art represents one week of the experiment, and at each week, a number of lanes corresponding to the probability given should be terminated. A terminated lane ends in an X like so:

| | |
| | |X
| | | |


The lanes should be ordered with the longest lanes on the left, in descending order to the right, and the number of lanes in your probability road should be the fewest possible to accurately represent the given probability, for example given a probability of 50 (50%), the road would look like this:

| | | | | | | | | | |X - Week 10
| | | | | | | | | | | |
| | | | | | | | | | | |X - Week 9
| | | | | | | | | | | | |
| | | | | | | | | | | | |X - Week 8
| | | | | | | | | | | | | |
| | | | | | | | | | | | | |X - Week 7
| | | | | | | | | | | | | | |
| | | | | | | | | | | | | | |X - Week 6
| | | | | | | | | | | | | | | |
| | | | | | | | | | | | | | | |X - Week 5
| | | | | | | | | | | | | | | | |
| | | | | | | | | | | | | | | | |X - Week 4
| | | | | | | | | | | | | | | | | |
| | | | | | | | | | | | | | | | | |X - Week 3
| | | | | | | | | | | | | | | | | | |
| | | | | | | | | | | | | | | | | | |X - Week 2
| | | | | | | | | | | | | | | | | | | |
| | | | | | | | | | | | | | | | | | | |X - Week 1
| | | | | | | | | | | | | | | | | | | | |


Given the probability of 50%, half of the lanes should succeed past week 10, while each week, 5% of the total lanes should be eliminated. This could be displayed using 1000 lanes (as could every probability from 1-99), by terminating 50 each week and having 500 reach the end, however this is not the most simplified form of the chart, so doing so would not be valid for this challenge.

Note that the Week X labels are not necessary

Another example, this time for the input 80:

| | | | | |X X
| | | | | | | |
| | | | | | | |X X
| | | | | | | | | |
| | | | | | | | | |X X
| | | | | | | | | | | |
| | | | | | | | | | | |X X
| | | | | | | | | | | | | |
| | | | | | | | | | | | | |X X
| | | | | | | | | | | | | | | |
| | | | | | | | | | | | | | | |X X
| | | | | | | | | | | | | | | | | |
| | | | | | | | | | | | | | | | | |X X
| | | | | | | | | | | | | | | | | | | |
| | | | | | | | | | | | | | | | | | | |X X
| | | | | | | | | | | | | | | | | | | | | |
| | | | | | | | | | | | | | | | | | | | | |X X
| | | | | | | | | | | | | | | | | | | | | | | |
| | | | | | | | | | | | | | | | | | | | | | | |X X
| | | | | | | | | | | | | | | | | | | | | | | | | |


This time, there are 25 lanes. Each week, 2 (8%) are terminated, and 5 (20%) make it to the end.

Rules

Standard loopholes apply, shortest code (in bytes, per language) wins.

As per usual, trailing whitespace is allowed. You may have trailing spaces at the end of lines, and one or more trailing newlines at the end of the output.

Meta

How can I make the explanation clearer? It seems difficult to understand currently.

Also is there anything else that needs specifying or clarifying?

If you've come here, you probably know what is, and that's what I'm going to assume.

Story

(I guess)

Keyboards are input devices we use all the time. They existed before mice and touch screen, etc.

Their fundamentals have not changed: when you press a key down, a signal is sent to the computer. When you release it, another signal is sent.

So here's the challenge: calculate the minimum number of signals(length of a signal does not matter) depending on the input string.

Example:

Input:

test


Output:

8


Explanation: All keys have to be pressed down and released

Input2:

TEst


Output2:

10


Explanation: Shift has to be pressed, then T, down, up, E, down, up, then release shift, then s down, up, then t down, up, totalling up to 10.

Rules

Any language is accepted.
This is , so shortest code in bytes wins.
Programs with incorrect outputs will be disqualified.

Edit:

The keyboard layout used should be this: http://dry.sailingissues.com/keyboard-US-International.png

Only characters in this keyboard layout will be used (+lowercase letters).

Using Caps-Lock is ok, since it DOES have an advantage: numbers remain numbers while letters become uppercase.

Thanks for the feedback so far.

• I think this might be a dupe, lemme see if I can find the original. EDIT: Ah, it's your challenege. I suggest deleting it from main while you work on it here; you can edit and then undelete it when it's ready. – Shaggy Jul 6 '17 at 9:10
• Test cases? Your comment about caps lock is a good example of an edge case which should be explicitly covered by the test cases, and implies another where a shift covers a substring which mixes upper-case letters and symbols. – Peter Taylor Jul 6 '17 at 10:24

Abbreviate a rename

After you commit a rename, git reminds you but tries to avoid showing the full source and target path. It does this by splitting the path into components, extracting identical leading and trailing components, then using them to abbreviate the rename. (Other output that git produces is not relevant here.) Here is an example:

foo/bar/baz/quux.c => foo/baz/bar/quux.c


The leading component foo and trailing component quux.c is the same, so this becomes

foo/{bar/baz => baz/bar}/quux.c


This also works when one of the components is empty, e.g.:

foo/{bar/baz => }/quux.c
foo/{ => baz/bar}/quux.c


Please write a program or function that abbreviates a rename. The input can be a pair of strings or a single string with a delimiter which can be => or newline or something else not typically found in a file name. The output should be a single string containing a => as shown. You can assume that neither string is a prefix of the other (git doesn't abbreviate the rename in that case for some reason.)

This is , so the shortest program wins!

Lazy programmers need help versioning!

So here's a question, which is related to a recent problem I had while doing some data processing. I think it is good practice to include version numbers in file names to prevent data being overwritten and so you can see how things have changed with each version but I'm lazy so want it automating!

Take a full Windows file path and either increment the file version, or if there is no version, make it version 1.

Input

A full Windows file path, that includes the file extension.

Output

The original file path with the file version, incremented appropriately.

Rules

• The version is determined by an underscore followed by a single digit, i.e _1 for version 1.
• For a file that already have a version, it will only be in the range 1-8, so you only ever have to deal with single digit file versions.
• Standard rules apply
• Default Loopholes are forbidden.
• Please provide explanations of your code so others can learn form it and if possible, links to an online interpreter such as TIO
• This is so shortest code in bytes wins!

Test cases

Case 1
Input:  C:\Foo\Bar.txt
Output: C:\Foo\Bar_1.txt

Case 2
Input:  C:\notsortedfile_version_1_new_5.docx
Output: C:\notsortedfile_version_1_new_6.docx

Case 3
Input:  D:\a\very\deep\file\567234.pdf
Output: D:\a\very\deep\file\567234_1.pdf

Case 4
Input:  Z:\Storage\Somefile_2017-04-11.txt
Output: Z:\Storage\Somefile_2017-04-11_1.txt

Case 5
Input:  Z:\Storage\I.Like.Dots.txt
Output: Z:\Storage\I.Like.Dots_1.txt


Sandbox Questions

Not sure if this is dupe of Please release me!

Any feedback welcome.

• I don't think it's a dupe. My opinions: You shouldn't let the test cases be dependent on OS. Just stick with one, the challenge is to modify a string, it doesn't really depend on which OS you're on. Personlly, I'd skip the 1-8 limitation. I think it would be more fun to go from file_9 to file_10. People (including you) might disagree with me though. – Stewie Griffin Apr 11 '17 at 8:51
• Also, I though version control was handled this way: filename.xyz -> filename_new.xyz -> filename_new_1.xyz (remember to rename the previous to: filename_new_OLD.xyz). And of course versions such as filename_new_2_backup.xyz, filename_final_version.xyz -> filename_final_version_2.xyz. – Stewie Griffin Apr 11 '17 at 8:56
• Which is why need to get some code to do it for us :) – Notts90 supports Monica Apr 11 '17 at 8:58
• Will file names only ever contain a .? – Shaggy Jul 6 '17 at 11:19
• @Shaggy It could be any valid windows file path so yes, I've added a test case to cover it. – Notts90 supports Monica Jul 6 '17 at 11:26
• Test case: c:\foo`? – Peter Taylor Jul 6 '17 at 13:32