# 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]

• How are tags added to questions? – guest271314 Jan 9 '19 at 7:51
• @guest271314 You can use this markup to create a tag in a draft: [tag:code-golf] – James Aug 29 '19 at 15:19
• Why no featured anymore? Can't we have it auto-added or something? – S.S. Anne Sep 26 '19 at 15:57
• @JL2210 We now have a permanent info box that links to the Sandbox, so the featured tag isn't necessary – caird coinheringaahing Sep 29 '19 at 13:43

## Lucky Numbers in a Matrix

Given a m * n matrix of distinct numbers, return all lucky numbers in the matrix in any order.

A lucky number is an element of the matrix such that it is the minimum element in its row and maximum in its column.

### Test cases

Case 1:

Input: matrix = [[3,7,8],[9,11,13],[15,16,17]]
Output: [15]
Explanation: 15 is the only lucky number since it is the minimum in its row
and the maximum in its column


Case 2:

Input: matrix = [[1,10,4,2],[9,3,8,7],[15,16,17,12]]
Output: [12]
Explanation: 12 is the only lucky number since it is the minimum in its row
and the maximum in its column.

• What will be the smallest size of the matrix? Also, I suggest formatting the matrices 2-dimensionally in the test cases so that it is easier to see the corresponding output tio.run/##SyzI0U2pTMzJT/8PBI/… – user41805 Mar 15 at 8:11

## Balance a Binary Search Tree

Given a binary search tree, return a balanced binary search tree with the same node values.

A binary search tree is balanced if and only if the depth of the two subtrees of every node never differ by more than 1.

If there is more than one answer, return any of them.

Test Case:

Input: root = [1,null,2,null,3,null,4,null,null]
Output: [2,1,3,null,null,null,4]
Explanation: This is not the only correct answer, [3,1,4,null,2,null,null] is also correct.

• Perhaps, you can include an explanation of this input format in the challenge body. What counts as valid input formats for the binary tree? – user41805 Mar 15 at 8:18

### Description

Start with an array initialized to zeros with indices starting at 1 and a series of operations to perform on segments of the list. Each operation will consist of a starting and ending index within the array, and a number to add to each element within that range.

Determine the maximum value in the final array.

For example, start with an array of 5 elements: list = [0, 0, 0, 0, 0]. The variables a and b represent the starting and ending indices, inclusive. Another variable, k, is the addend. The first element is at index 1.


a    b    k             list

[  0,  0,  0,  0,  0]

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

2    4    5    [ 10, 15,  5,  5,  0]

3    5   12    [ 10, 15, 17, 17, 12]


The maximum value in the resultant array is 17. That is the value to be determined.

Function description

The function must return a long integer that denotes the largest value in the array after all operations have been performed.

listMax has the following parameters:

n: an integer, the size of the initial array.
operations: a 2D integer array where each element contains an operation.


Test Cases

Sample Input

5

3

3

1 2 100

2 5 100

3 4 100


Sample Output

200

Return the maximum value in the final list, 200, as the answer.


Explanation

Perform the following sequence of o = 3 operations on list = [0, 0, 0, 0, 0]:

1. Add k = 100 to every element in the inclusive range [1, 2], resulting in list = [100, 100, 0, 0, 0].

2. Add k = 100 to every element in the inclusive range [2, 5], resulting in list = [100, 200, 100, 100, 100].

3. Add k = 100 to every element in the inclusive range [3, 4], resulting in list = [100, 200, 200, 200, 100].

This is code-golf so shortest submission in bytes wins! If you liked this challenge, consider upvoting it... And happy golfing!

## Golf yourself a real calculator [draft] code-golfarithmetic

We will only cover the characters(0123456789+-*/=%√±) in our tutorial.

### The = operations

Unlike most desktop calculators, our household calculator is a tacit language. Therefore it is able to do a lot more than other infix calculators.

Take a simple calculation as an example. The non-scientific calculator does not have the exponentiation operator. What do you do to calculate 2^5?

2*2====


However, there's a shortcut for doing that. Since 2 is already in the expression buffer, you can simply do

2*====


The calculator automatically fills in the current expression during the inputting.

Here is a demonstration of how this works:

(A template for easy copy&paste.

Pressed Key      :
Expression buffer:
Output buffer    :
)

Pressed Key      : 2
Expression buffer: 2
Output buffer    : 2

Pressed Key      : *
Expression buffer: 2 *
Output buffer    : 2

Pressed Key      : =
Expression buffer: * 2
Output buffer    : 4

Pressed Key      : =
Expression buffer: * 2
Output buffer    : 8

Pressed Key      : =
Expression buffer: * 2
Output buffer    : 16

Pressed Key      : =
Expression buffer: * 2
Output buffer    : 32


## Implicit 0 before calculation

Suppose you enterede the following expression:

*1


Now, don't get me wrong, the household calculator of course doesn't have pointers. So, why doesn't it raise a syntax error though? (The output is 0 by the way.) Here's why.

The calculator initially has the expression starting at 0, therefore it prepends a 0 to the expression. Therefore the full form of our expression is:

0*1


## What we've learned so far

• The output buffer is a part of the calculator storing the latest-evaluated integer. All entered numbers get appended to the output buffer as well as the expression buffer.
• The expression buffer is a part of the calculator storing the latest instruction. After a = operator, it stores the latest applied expression for later application.
• The = operator tries to evaluate the instruction buffer. If that's a syntax error, it tries to evaluate that concatenated the output buffer. If that still fails, it tries to evaluate the output buffer concatenated with the instruction buffer. After that operation, the expression starting from the newest-entered dyadic operator is saved in the expression buffer.

# Represent n as a expression containing all the digits

Related Challenge: Single Digit Representations of Natural Numbers

Write a program/function that when given a non-negative integer $$\n\$$ that is less than or equal to $$\1000\$$ outputs a expression which uses all the digits from $$\0\$$ to $$\9\$$ exactly once and evaluates to $$\n\$$

The expression outputted by your program may only use the operations listed below:

• subtraction and unary minus (both must have the same symbol)
• multiplication
• division
• exponentiation
• concatenation (must be explicit)
• parentheses

The precedence of the operators is up to you but must be consistent for all outputs produced by you program. You may also use custom symbols for representing the digits and operators but the symbols must be distinct and must be consistent for all outputs produced by you program

## Scoring

This is so shortest bytes wins

## Testcases

0 -> 0 * (1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9)
42 -> 4 || (2 + 0 * (1 + 3 + 5 + 6 + 7 + 8 + 9))
100 -> 123 + 4 − 5 + 6 || 7 − 8 || 9 + 0
100 -> 9 || 8 − 7 || 6 + 5 || 4 + 3 + 2 || 1 + 0
100 -> 1 || 0 || ((9 - 7 - 2) * (3 + 4 + 5 + 6 + 8))
1000 -> 1 || (9 - 7 - 2) || ((8 - 5 - 3) * (4 + 6)) || 0


Note: In the testcases || represents concatenation

A proof by exhaustion that shows that all number less than a $$\1000\$$ have a expression that uses all the digits.

# For Sandbox

• Any tags I should add
• I really don't want concatenation as an operation so if someone could find a proof or show by exhaustion that all numbers below $$\1000\$$ have expression that uses all the digits and doesn't use concatenation I would be grateful

# Dilapidated art gallery problem

In a typical art gallery problem, the objective is to place as few guards as necessary inside an arbitrary polygon so that all of it is visible by some guard. This time, we'll make some changes to simplify the task:

• The gallery can only afford to pay one guard. No more. This means that it won't be possible to keep everything in sight, so the objective becomes to maximize the amount of art visible.
• Not even a dilapidated art gallery is barbaric enough to put art on the floor, and they don't have enough money to afford pedestals, so we only care about how much wall area is visible.
• Since the art gallery doesn't even have a roof, the whole floor is visible anyways. If you are wondering how the guard manages to hover high above the gallery - he doesn't. He has a telescopic camera tied to a weather balloon. There. Problem solved. Therefore, what counts for visibility isn't occlusion. The only thing that matters is that the walls are facing the right way.
• You can assume the floor plan is a (not necessarily connected) union of rectangles. I was thinking about including diagonal walls, but this version fits better with the theme. Any internal walls have a definite thickness. If they didn't, you could just ignore them, and that's no good.
• The guard doesn't have to be inside the gallery. They can sit outside, or even lean against the walls. You, however, cannot place the guard with infinite precision. If you try to align the guard with one of the walls, they will be displaced infinitesimally in one direction chosen with uniform probability. But yes, you can try.

The input will consists of the following characters:

• The space character represents 1m x 1m of empty space. It's up to you to decide if it's inside the gallery, or outside. You may assume that the input encodes a rectangular area that includes all of the gallery floor and that all of the walls are depicted.
• - and | represent 1m x 1m squares with walls (east-west and north-south respectively) passing through their centers. Each wall will be adjoined by either the same type of wall or a corner in its lengthwise direction, and empty space in its transverse direction.
• + Represents a corner. Each corner will be adjoined by an east-west wall either on its east side or on its west side, but not both, and by a north-south wall either on its north side or its south side, but not both, and by empty space on the remaining two sides, and in all four diagonally neighboring tiles.

Your objective is to determine and mark all guard locations - tile centers - that maximize the number of wall segments viewed from the correct side - empty space should be marked with . and wall tiles should be marked with #.
In the event that none of the optimal spots align with tile centers, do not mark any tile as optimal. It is the user's responsibility to provide a more detailed floor plan. You may optionally display an error message in that case. If you choose so, the error message must be: displayed in every situation in which no optimal tile would have been marked; same for every input that causes it to be shown; includes at one character not allowed in any valid output.

Example cases:

+----+    +----+
|    |    |....|
|    | => |....|
|    |    |....|
+----+    +----+


The guard can be anywhere inside the gallery, but they can't lean against the wall because they might suddenly find themself on the other side of that wall unexpectedly.

+---+        +---+
|   |        |   |  .
+---+ +-+    +---+ +-+
| | =>       | |
| |          | |
| |          | |
+-+          +-+


In this case, the gallery consists of two separate buildings, and the guard's best spot lies outside either of them.

+---+
|   |
|   +-+ => error
+-+   |
|   |
+---+


In this case, there is a 1m x 2m area in which the guard can see all of the walls, but there's no way to depict that in the output. You may pass the input unmodified, or you may output an error message.

+-----+    +-----+
|     |    |.   .|
| +-+ |    | +-+ |
| | | | => | | | |
| +-+ |    | +-+ |
|     |    |.   .|
+-----+    +-----+


This art gallery has a courtyard. Two inner walls must be left unprotected, but it doesn't matter which ones.

  +-+          +-+
| |         .#.#...
+-+ +-+     .###.##+
| |     .....#.|
+-+   +-+ => +##...##+
| |          |.#.....
+-+ +-+      +##.###.
| |       ...#.#.
+-+          +-+


For every wall but four, there is another wall such that exactly one of the two can be seen at any given time. As long as the other four walls are guarded, the number of walls guarded is maximized. This is also one of the rare cases where the guard can lean against a wall - if they fall through, they'll wind up guarding another wall instead.

+-------------+


This is not an art gallery. It's a fence with no inside or outside. Invalid input.

+---+-+---+   +
|   | |   |   |
|   | |   |   +
+---+-+---+


You might think this depicts two rooms with an internal wall, or three rooms with two internal walls - either way, internal walls are banned. Also, fences are banned. Invalid input.

+---+ +--+ +-+
|   | |  ++| |
|   +-+   |+-+
+---------+


This building has a clear interior and exterior, but the southern corridor is too narrow, the dent in the north-east corner is too jagged to leave enough room for art, and the nearby closet is too close to the main building. Each of these reasons suffices to make this an invalid input.

|---------+
| +-+     |
|    *a k |
| ei 32A  |
+-+++-+--++


There's a gap in the northwest corner, debris all over the floor, and the southern wall has exposed scaffolding. All wrong.

• I'm not sure if I'm misreading, but I feel as though there is a lot of excess information provided, while certain more basic concepts are left unexplained. For example, the rule about guard displacement being uniformly random and the size of the tiles being 1m2 seem unnecessary for computing the output, whereas the rule for what the guard sees was difficult for me to interpret. My understanding is that the guard sees infinitely far in every direction, but not through walls? – FryAmTheEggman Mar 20 at 16:00
• @FryAmTheEggman from the third point: "Therefore, what counts for visibility isn't occlusion. The only thing that matters is that the walls are facing the right way". Are you suggesting I should reformulate that? – John Dvorak Mar 20 at 16:09
• Yes, that part wasn't totally clear to me, and it feels like a very important detail that is somewhat buried amongst much less relevant information. – FryAmTheEggman Mar 20 at 16:24

# For How Long am I Alone? code-golf

You are a factory worker, whose shift is from time X to time Y. It's a very boring job, and you want to know if any other workers are working during your shift. Given a list of start and end times for the other workers and your own shift time, output the longest amount of time that you are the only one working in the factory.

# Input

List of start and end times. Any reasonable format is allowed, such as a list of tuples representing (startHour, startMinutes, endHour, endMinutes) or a list of date objects.

A pair of times, which represent your own start and end times. These may be received as a tuple/list or as separate arguments. Again, the times can be passed as a tuple, date objects, or two object array representing (hour, minutes), or you can pass the hours and minutes as separate arguments.

Each person starts working precisely at their start time and gets off work right when the end time starts. For example, if someone is working from 8:00 to 17:00, at 17:00 they are not considered to be at work anymore.

Each person does his shift 7 days a week.

If you choose to use date objects, the "Year" field of the date objects must always be the same across all inputs.

Note that the end time of your shift can look like it's earlier than your start time, e.g. 21:30 - 5:30. This means that your shift starts at 21:30 at the first day and ends at 5:30 on the next day.

# Output

The longest interval in minutes in which you are the only one working in the factory.

# Test Cases

In the form of [(hh:mm,hh:mm)...], hh:mm, hh:mm

[(3:30, 12:00), (13:00, 21:40)], (8:30), (16:30) -> 60
[(1:01, 1:03), (1:04, 1:06), (1:07, 1:10)], (1:00), (1:10) -> 1
[(21:00, 5:00), (22:30, 7:00)], (0:00), (4:00) -> 0


# Questions

Should I keep the part about the shift being able to stretch across midnight?

Is the input specification clear enough?

Any suggestions welcome.

• Say my shift is overnight and someone has a shift that isn't overnight. How do I know what day said shift belongs to? e.g. if I'm working from 21:30 to 5:30 and I get another input as 1:00 to 4:00 how do I know if I haven't even started? – RGS Mar 20 at 13:26
• @RGS Good question. Added a part about the shifts being 7 days a week, so there is no confusion. I feel like the part about having a overnight shift might make this challenge unnecessarily complicated; What do you think? – Embodiment of Ignorance Mar 20 at 18:13
• I am not a sandbox veteran, but from my POV this challenge will have us handling intervals and do arithmetics with the interval endpoints and that is probably the main core of the challenge. But adding the overnight shifts means we are trying to intersect segments of a circumference, instead of regular intervals, which is also interesting, I think! (do you understand what I mean with this?) So maybe either remove overnight shifts or rephrase the challenge as intersecting segments of a circumference? So that it becomes more clear that it isn't just an edge case, but the core challenge itself – RGS Mar 20 at 19:00
• As for the title, I would have "For how long am I alone" because "How long am I alone" looks like you are asking for your length when you are alone, instead of the amount of time during which you will be alone. – RGS Mar 20 at 19:01
• Instead of "must always be the same across all inputs", I suggest "will always be the same across all inputs". This makes it more clear that you don't have to deal with the year. – S.S. Anne Mar 20 at 23:56

## Numbers by index

Challenge

Print the numbers:

0
1
22
333
4444
55555
666666
7777777
88888888
999999999


In that order.

I/O

Takes no input. The numbers can have any delimiters desired (or none). Example outputs:

0122333444455555666666777777788888888999999999

[0,1,22,333,4444,55555,666666,7777777,88888888,999999999]

etc....


Code Example

This is an un-golfed example that may perhaps act as algorithm guide (or maybe not):

# Turing Machine Code, 553 bytes

0 * 0 r K
K * _ r 1
1 * 1 r L
L * _ r 2
2 * 2 r a
a * 2 r M
M * _ r 3
3 * 3 r b
b * 3 r c
c * 3 r N
N * _ r 4
4 * 4 r d
d * 4 r e
e * 4 r f
f * 4 r O
O * _ r 5
5 * 5 r g
g * 5 r h
h * 5 r i
i * 5 r j
j * 5 r P
P * _ r 6
6 * 6 r k
k * 6 r l
l * 6 r m
m * 6 r n
n * 6 r o
o * 6 r Q
Q * _ r 7
7 * 7 r p
p * 7 r q
q * 7 r r
r * 7 r s
s * 7 r t
t * 7 r u
u * 7 r R
R * _ r 8
8 * 8 r v
v * 8 r w
w * 8 r x
x * 8 r y
y * 8 r z
z * 8 r A
A * 8 r B
B * 8 r S
S * _ r 9
9 * 9 r C
C * 9 r D
D * 9 r E
E * 9 r F
F * 9 r G
G * 9 r H
H * 9 r I
I * 9 r J
J * 9 r halt


Try it online!

This prints out the numbers with a space delimiter:

0 1 22 333 4444 55555 666666 7777777 88888888 999999999


Challenge Type

, so shortest answer in bytes (by language) wins.

Edit: Link to the related challenge. Curiously, there is one answer on there where if it was by index, and the zero was included, it would be shorter.

• Nice challenge! Are preceding & trailing whitespace (during string output) permitted? – petStorm Mar 11 at 3:22
• I think it should also be kolgomorov-complexity. – PkmnQ Mar 11 at 5:19
• I don't like how the zero breaks the pattern of having the digit N appear N times -- it seems like an exceptional edge case. I think it would be better for 0 not to appear, so the numbers would just start from 1. – xnor Mar 11 at 7:06
• @xnor, I knew you wouldn't like it (and probably a few other won't as well) That's on purpose. It just seems a little too easy otherwise. – ouflak Mar 11 at 7:28
• @a'_', Yes. @ PkmnQ, Noted. – ouflak Mar 11 at 7:29
• I don't really see how adding a fixed zero to the beginning makes the challenge harder in almost any language. In some, the empty string will actually convert to zero, which makes it more natural but still fairly trivial. I feel like you probably either want to go with omitting the zero, or finding a different way to make the challenge more complicated. – FryAmTheEggman Mar 11 at 14:53
• @FryAmTheEggman, How can you have a challenge about indexes and not have zero? That just seems wrong. – ouflak Mar 11 at 15:31
• Most people start counting from one - only people who use computers a lot default to starting at zero. And separately, I think finding another way to incorporate it is better than leaving it out (I just also think both are better than having an unexplained outlier). – FryAmTheEggman Mar 11 at 15:40
• @FryAmTheEggman, But it's not really unexplained is it? It's the index of the first number. – ouflak Mar 11 at 15:46
• As per what xnor said, it doesn't match the pattern of the others. That behaviour is not explained. Comments aren't really for a discussion like this; if you disagree that is fine. I've just given feedback on how I think you could improve the challenge. – FryAmTheEggman Mar 11 at 16:15
• I do want to make sure that everyone knows that I am VERY grateful for the feedback! I also appreciate having a Sandbox where we can have this discussion here instead of on the main site. – ouflak Mar 11 at 16:18
• @FryAmTheEggman, It's not that I disagree. I kind of agree. I like that leading zero in there to represent the index location of the initial value. I considered this when I thought of the question, before posting it here. It breaks up a trivial loop sequence answer a bit, or maybe even inspires a clever solution that nobody considered. I'd like to keep it because it stands out like that, not despite that. – ouflak Mar 11 at 16:21
• I posted an example implementation above. The zero wasn't a big deal. – ouflak Mar 11 at 16:31
• My guess is that you're excited about the arithmetic expression 10**n/9*n or similar. But I don't think that's much more interesting than the obvious loops that removing the zero would allow unmodified. – xnor Mar 11 at 21:59
• @ouflak I contrast, I am very excited about arithmetic expressions :) – xnor Mar 12 at 21:16

# Is this a Freeman Dyson Number?

Background

From this Popular Mechanic article

One day, in a gathering of top scientists, one of them wondered out loud whether there exists an integer that you could exactly double by moving its last digit to its front. For instance, 265 would satisfy this if 526 were its exact double – which it isn’t. After apparently just five seconds, Dyson responded, “Of course there is, but the smallest such number has 18 digits.”

Challenge Write a program that, when given a number that is at least 18 digits long, moves the last digit to the front and checks if it is doubled as a result.

I/O
Input can be any 18 (or longer) digit integer. Any leading digit must be larger than zero.
Output can be any truthy/falsey value.

Test Cases

111111111111111111 -> false
100000000000000002 -> false
123456789123456789 -> false
42105263157894736842 -> false
808080808080808080808080808016 - false
246802468024680246802468024680246802 -> false
105263157894736842 -> true
315789473684210526 -> true
263157894736842105263157894736842105 -> true

etc...


, so shortest answer in bytes (by language) wins.

• I would specify that you are talking about decimal digits. – Jonathan Frech Mar 22 at 17:46
• @JonathanFrech, Do you mean base 10? – ouflak Mar 22 at 19:32
• I think one issue here is how to verify that the specific action of moving the digit from back-to-front, and then subsequently checking for doubling, actually happened. Not sure how to get around that. – ouflak Mar 22 at 20:10
• Yes, you should specify that this is in base 10. – S.S. Anne Mar 22 at 20:46
• @ouflak Yes, I mean base ten. One often hears for example "binary digits", so the term "digits" is in my opinion not clearly defined to mean base ten. – Jonathan Frech Mar 22 at 21:55
• @JonathanFrech, @ S.S. Anne, The reason why I haven't immediately made the change is because I hadn't considered the idea of different number bases, and I'm really liking the idea of a challenge that in fact does include either various number bases, or a specific challenge for binary and this separate challenge for base ten. Mulling it over now. This would mean I'd have to figure out some binary test cases.... – ouflak Mar 23 at 6:44
• In binary doubling a number is adding 0 to the end of it, so unless you allow leading 0s it's not possible, otherwise it's correct iff the number starts with a 0 – Command Master Mar 24 at 19:43
• @CommandMaster, Yes! For binary, you would have to allow, even implicitly, a leading zero. The most obvious example is '1', which is really '01', which when the '1' is moved to the front becomes '10'. Don't see how you can get around that. It would be a different challenge. The number base thing has got me thinking. – ouflak Mar 25 at 8:35

## In need of title.

Note: In the final challenge $$\N\$$ will be a concrete number (I am thinking about 100), but while this is in the sandbox it is subject to change so I have left it as $$\N\$$.

This challenge is based off of a list of $$\N\$$ Castilian (also called Spanish) words and the words they originate from.

You are to write a program or function which takes the origin word as input and outputs as close as possible the Castilian derivative. Your program should be no longer than $$\N\$$ bytes.

## Scoring

To calculate your score run your program on every origin word and calculate the distance between your output and the correct answer. Your score is the sum of all these distances.

The distance here is a modified version of Levenshtein distance. It is the same as Levenshtein distance except replacement steps that add or remove a diacritic cost only 1/2 of a step as opposed to their normal 1.

You can use this code to calculate the distance between two strings.

The goal is to have as low a score as possible.

All of the origin words spare 1 are Latin words (Late or Classical depending on the word). The one exception is ezkerra (the origin for izquierda) which is of Basque origin. It has been added as an extra curve-ball in case you can get all the others with a little space to spare.

Verbs are always in the infinitive form and nouns in the nominative singular.

The words are not chosen randomly but rather I have focused on choosing words that follow a number of simple rules. The list is also organized so that words that undergo similar transformations are grouped together. This is for your ease of use, nothing more.

# The list

profundus, profundo
fundus, hondo
fabulare, hablar
furnus, horno
ferrum, hierro
filus, hijo
folia, hoja
fovea, hoyo
factum, hecho
octo, ocho
noctu, noche
lacte, leche
capere, caber
sapere, saber
lupus, lobo
liber, libro
thema, tema
theatrum, teatro
thesaurus, tesoro
thorax, tórax
aether, éter
anthropologia, antropología
orthographia, ortografía
philosophia, filosofía
materia, materia
resistentia, resistencia
aurum, oro
taurus, toro
autumnus, otoño
annus, año
scribere, escribir
scutum, escudo
scutella, escudilla
scriptor, escritor
ezkerra, izquierda

• I think it's interesting in that it should be near impossible to get a perfect score without built-ins. As a suggestion I'd remove the non-ASCII words, or at least normalise them, and perhaps not let $N$ be too high. Also, I wonder what the default cat program would be. – Jo King Mar 3 at 12:31
• @JoKing I am looking to somewhat twart perfect scores, I feel there should always be some room for improvement, It just is a little hard to balance this with golfing-languages ability for expressiveness. I am interested to hear what ranges for $N$ you think are too high. I started out by avoiding any non-ASCII characters, but it was really hard to build up a representative corpus of words. Plus the accents and eñe really are a feature of the language. I may adjust the scoring so that i and í for example are only half away from each other so that the penalty is small. – Ad Hoc Garf Hunter Mar 3 at 13:05

# Pseudo-deterministic number generator code-golfsequencemath

Write a function/full program that, given an integer seed, always outputs the same infinite sequence in [0, ..., 9] (let me call it c), except when its input is a specific integer n specified by you in your answer. In that case, your code should produce a pseudo-random sequence s with terms in [0, ..., 9] that is different from c.

Both sequences should be s.t. the relative frequencies with which each digit appears tend to $$\10\%\$$. Be prepared to prove this if needed.

There should be one extra restriction your sequences should satisfy: when zipped together to form a sequence a of numbers in [0, ..., 99], the relative frequency of each number should converge to 0.01. That is, the $$\n\$$th term of the sequence a is the two-digit number built this way: the digit in the tens place is the $$\n\$$th term of the sequence c and the digit in the units place is the $$\n\$$th term of the sequence s.

# Input

A non-negative integer representing the seed, which you use to decide whether to output the general sequence of the specific one.

# Output

A sequence of integers in [0, ..., 9]. Your code may do any of the following:

• take no additional input and output an infinite stream with the sequence
• take an additional integer n and output the nth term of the sequence (0- or 1-indexed)
• take an additional positive integer n and output the first n terms of the sequence
• Is this allowed: If the seed is 0, give a single 0 then cycle through 0...9; otherwise, give a single 1 then cycle through 0...9? – Bubbler Mar 24 at 8:06
• @Bubbler as per the current spec, yes, which wouldn't be very interesting. I wanted to find a second reasonable restriction on the "seed" sequence... Maybe require that as n grows, the fraction of terms in which these two sequences coincide converge to 0.1? – RGS Mar 24 at 8:25
• Then how about this? "When the two sequences are zipped together, the probability of every combination 00, 01, ..., 99 converges to 0.01." – Bubbler Mar 24 at 8:31
• @Bubbler that seems like a reasonable suggestion, thanks! – RGS Mar 24 at 18:53

# Ordinal to Cardinal

Given a positive integer represented as the English spelling of an ordinal number, return the equivalent cardinal number.

## Rules

• Where an integer requires multiple words to spell, only the last word changes.

• The following integers are strongly irregular:

• "one" becomes "first"
• "two" becomes "second"
• "three" becomes "third"
• Other integers take a suffix of "th", however there are a few integers that are weakly irregular:

• "five" becomes "fif(th)"
• "eight" becomes "eigh(th)"
• "nine" becomes "nin(th)"
• "twelve" becomes "twelf(th)"
• "twenty" to "ninety" become "twentie(th)" to "ninetie(th)".
• The input can be assumed to be the English spelling of an ordinal number that follows the above rules to transform it into the equivalent cardinal number.

## Examples

• "one hundred and nineteen" becomes "one hundred and nineteenth"
• "one hundred and twenty" becomes "one hundred and twentieth"
• "one hundred and twenty one" becomes "one hundred and twenty first"

This is , so the shortest program or function that breaks no standard loopholes wins!

• There are a lot of loosely related challenges, with this one being the closest. I don't think this is a dupe at all, though, since the amount to change is much more significant. Is there an upper limit on the input? If not, you definitely need to specify how the larger numbers might appear i.e. do we need to handle "milliard" as well as "million"? – FryAmTheEggman 2 days ago
• @FryAmTheEggman That and the other challenge takes the numbers as digits rather than words, which IMHO is a significant difference already. As for large numbers, you can assume for the purposes of the question that any number I forgot about takes a "th" suffix. – Neil 2 days ago
• Which integers do we need to handle? I'd suggest limiting it to, say, numbers from 1 to 99. Or if you do want all positive integers, could you please clarify how these are written out? – xnor yesterday
• @xnor a) this challenge is about words, not numbers b) the rules are there, I don't understand what you're missing – Neil yesterday
• @Neil Like, is "one billion, two hundred and thirty four million, five hundred and sixty seven thousand, eight hundred and ninety" a possible input, for which the output would be "one billion, two hundred and thirty four million, five hundred and sixty seven thousand, eight hundred and ninetieth"? If so, what is the exact format for such numbers? I understand that really only the last word matters for the conversion in the challenge, but it might make a difference for, say, a regex that does a replacement that might falsely trigger on something like "Duotrigintillion". – xnor yesterday
• @xnor Why would it falsely trigger on duotrigintillion? Is there no duotrigintillionth? – Neil yesterday
• @Neil I mean if it's part of a longer number and the regex does a replacement that doesn't check for the end of the string, but simply replaces certain sequences of characters. Duotrigintillion is an arbitrary example; I don't expect it specifically to actually "collide" with anything useful. – xnor yesterday
• @xnor Well, surely if it collides as the last word, then it will collide as an earlier word, which would be an error, according to the first rule? – Neil yesterday
• @Neil Oh, you're right, that would catch it. Maybe a more useful example is "one hundred and one" wrongly being made into 'first hundred and first". In any case, I think it would be useful to either add large-valued test cases or put an upper bound. – xnor yesterday
• @xnor I still don't see that it needs an upper bound. You can just assume that the rules I've given apply, even if they don't in real life for some reason. – Neil yesterday

# Program calculating its own length code-golf

Your task is simple: write a program that produces its own length, without using any literals or built-in constants other than 0 (or its equivalents in your language).

## Rules

1. Your code must print its own length in bytes when run, followed by a single newline.
2. Your code cannot use any literals other than 0 (or whatever equivalents your language might have). This includes string and character literals.
3. Your code cannot use any built-in constants of your language, unless these are guaranteed to always have the value 0.
4. Any functions and operators provided by your language can be used.
5. You're not allowed to use any external libraries or external resources in your program.

## Scoring

The score of a valid program is its length in bytes. The score of an invalid program is ∞.
As this is code golf, lowest score wins.

• Does "any literals" include the more involved ones like function, array and object literals? Apart from this restriction, I'm pretty sure this has been asked before. – Martin Ender Aug 3 '14 at 17:54
• @MartinBüttner Probably a dupe: codegolf.stackexchange.com/q/27079/16402 – user16402 Aug 3 '14 at 17:58
• Would this Python entry be valid (not golfed)? It uses only globals. text = open(__file__, 'rb').read(); length = len(text); print(length) – Isiah Meadows Aug 12 '14 at 5:41
• May we use built-in lists that are guaranteed to be []? – Adám Feb 8 '19 at 8:28
• In Jelly (and likely much more esolangs), a empty program outputs 0, producing an answer that is very hard to beat; Try it online! – my pronoun is monicareinstate May 24 '19 at 8:44

# Complicating Simple Maths code-golf

We do know what 1 + 1 is, or 2 - 1. How about we turn those and other really simple operations into complex numbers?

## Goal:

As stated in the intro, taking an operation that can be done within the range of the following operators ( +, -, /, *, ^ and () ), print out a complex number operation that is pretty much a transformed version, and when done using the order of operations, results in the same answer as the inputted operation.

## Examples:

Input: 5 - 1
Output: 5 + 2i

Input: 4 * (7 ^ 2)
Output: (4 * 4i) * (7 ^ 2)


## Rules:

• It is recommended you print out the sector(s) that holds your complex number(s) as a + bi, e.g. (a + bi) - (ci * (di ^ f)). (NOTE: If you are doing non-communicative operations, such as ^, /, or -, the recommendation doesn't apply to the sub-operation).

• If you want to, feel free to use operations/functions other than the set mentioned in the Goal, but your input operation must have at least one of them.

• You can format your operators in any way, e.g. x or • instead of *, ÷ instead of /, etc.

• Input and output is allowed in any format as long as it fits within the standard I/O rules.

• Input must also be flexible (as in to return any input from a simple operation to a complex number operation.

• This is , so shortest answer wins.

## Sandbox use only:

Is there any way I can improve this challenge? Are there any other loopholes to be covered in the rules?

• Can you relax output to standard IO too? At the moment it seems you can only print the result. Also isn't this essentially calculate the result of the inputted expression then work out a complex expression that gives the same answer seeing as you don't need to keep anything in the input the same. – TheLethalCoder Aug 7 '17 at 10:32
• And if that is the case isn't this challenge just return input + (1 + i^2)? – TheLethalCoder Aug 7 '17 at 10:33
• No, the challenge is to transform parts of the input into complex numbers and output that. – S.G. Harmonia Aug 7 '17 at 13:13
• But 5 - 1 becomes 5 + 2i You are removing two stages - and 1 and adding 2 + and 2i. It's not entirely clear how much you can remove and how much you can add. – TheLethalCoder Aug 7 '17 at 13:15
• At least one sub-operation should be transformed from simple to complex (which could take two steps). – S.G. Harmonia Aug 7 '17 at 13:16

# Golf Cubically code code-challengefgitw

Your task is to optimize Cubically source code using one or more optimizations in this post.

How this challenge works:

• You will choose one or more optimizations below and write a program (in the language of your choice) that performs those optimizations on a Cubically program.
• Your program will take a Cubically program as input using any allowed input methods, and output a Cubically program using any allowed output methods.
• The first answer to successfully perform all optimizations wins!

# Optimizations

### 1. Face turn arguments

Before a face turn is performed, the interpreter calculates turns = turns mod 4. So R5 would be equivalent to R1 which is equivalent to R, R7 is equivalent to R3 which is equivalent to R', etc. Also note that R11111 is equivalent to R5, and R22 is equivalent to nothing at all.

Performing this optimization will mean evaluating all arguments to an R, L, U, D, M, E, or S command and shortening them as much as possible.

Test cases:

Relevant code -> Optimization
R11           -> R2
R1            -> R
L33           -> L2
U22           ->
D222          -> D2
M11111        -> M
E00001        -> E
S9            -> S


### 2. Repeated face turn

When multiple calls to the same face turn command are present right next to each other, they can clearly be golfed. For example, R2R1 is equivalent to R3. UUU is equivalent to U3. F2F2F2F2 is equivalent F8.

Test cases:

Relevant code -> optimization
R2R2R2        -> R6            (R2 if you also choose optimization 1)
LLL           -> L3
UU            -> UU or U2
D3D2D1        -> D6            (D2 if you also choose optimization 1)


### 3. "Set notepad to" commands

There are some commands that, instead of adding to/subtracting from/multiplying by/dividing by the notepad, just assign to it. Here are all such commands:

_^=<>⊕«»·|:


When called with multiple arguments, since each argument calls the command separately, only the final argument is relevant. So =123 is equivalent to =3, _00000 is equivalent to _0, and :12345678987654321 is equivalent to 1.

Test cases:

Relevant code -> Optimization
_333          -> _3
=12321        -> =1
+54321        -> +54321
:55           -> :5
/55           -> /55


### 4. Repeated non-face-turn commands

When multiple face turn commands are present right by each other, their arguments can simply be added together. Commands do not act this way. While R2 calls R with 2, =2 calls = with the face sum of the front face (face index 2).

To perform this optimization, when multiple commands outside of RLUDFBMES appear next to each other, simply remove the duplicated commands without removing the arguments.

Relevant code -> Optimization
_1_1_1_1      -> _1111         (_1 if you also choose optimization 3)
%11%22%33     -> %112233       (%3 if you also choose optimization 3)
+12345+67+8   -> +12345678


### 5. Nonexistent commands

Go check out the Cubically commands page and you'll see that there are plenty of characters that are not commands. For example, there are no commands that are lowercase letters.

To perform this optimization, remove all nonexistent commands and their arguments from the Cubically source. If the commands also have arguments, you must remove the arguments so that they are not passed to the previous command.

Test cases:

Relevant code -> Optimization
moo cow moo   ->
moo2cow2moo   ->
misteR2 FOO   -> R2F
FEAR ME.      -> ERME
u1U2u3U4u5U6  -> U2U4U6   (nothing if you also choose optimization 1, U12 if you also choose optimization 2)


There are lots of implicit commands in Cubically (RLUDFBMES()$~&E!), but there are plenty that need to be called with arguments. So %%%% is equivalent to nothing at all while %%2%% is equivalent to %2. Test cases: Relevant code -> Optimization %%%% ->  ->  ++2++2++2 -> +2+2+2 (+222 if you also choose optimization 4) +++>--<- -> Not Brainf**k, sorry! (:P)  # Sandbox I'll add more optimizations later. • Clarification on R123: That's the same as R6 and R2, not R3, right? Digits are summed, there are multidigit numbers? That would be better to specify – isaacg Aug 17 '17 at 20:13 • A few things: first, I can't find the tag "fgitw", is there a typo? Second, does optimization 1 require handling F and B as well, or just the currently listed ones? Third, in optimization 3 most of the listed commands seem invalid because the notepad is used in calculation and then overwritten with the output; for example =11 is not the same as =1 in most circumstances. In fact, I think only _: are valid. Fourth, is the winning answer one which performs all optimizations in a single program, or one which contains a separate program for each optimization? – Kamil Drakari Aug 18 '17 at 18:03 # Proper Kerning Kerning is the adjustment of spacing between pairs of letters in order to obtain an aesthetic result. When kerning is applied automatically by a program (typically whatever editor you're using), it is said to be automatic. There are two types of automatic kerning. The one used in this challenge is metric kerning. With metric kerning, the amount of space between pairs of letters is dictated by the kerning tables found in the font file. Given a TrueType font file, output the kerning values for each mapping in the kerning table for ASCII characters 48 - 122 inclusive. ## Example calibri.ttf l="A" r="C" v="-15" l="A" r="G" v="-15" l="A" r="J" v="23" l="A" r="O" v="-23" l="A" r="Q" v="-23" l="A" r="T" v="-160" l="A" r="U" v="-32" l="A" r="V" v="-89" l="A" r="W" v="-80" l="A" r="Y" v="-150" l="A" r="t" v="-52" l="A" r="v" v="-38" l="A" r="y" v="-41" l="A" r="?" v="-68" l="B" r="A" v="-20" l="B" r="T" v="-48" l="B" r="V" v="-25" l="B" r="W" v="-24" l="B" r="X" v="-44" l="B" r="Y" v="-57" l="B" r="Z" v="-20" l="B" r="f" v="-20" l="B" r="t" v="-20" l="B" r="v" v="-20" l="B" r="x" v="-15" l="B" r="y" v="-20" l="C" r="G" v="-18" l="C" r="J" v="12" l="C" r="O" v="-18" l="C" r="Q" v="-18" l="C" r="T" v="10" l="D" r="A" v="-30" l="D" r="J" v="-22" l="D" r="T" v="-23" l="D" r="V" v="-24" l="D" r="W" v="-14" l="D" r="X" v="-31" l="D" r="Y" v="-39" l="D" r="Z" v="-22" l="E" r="A" v="-22" l="E" r="C" v="-24" l="E" r="G" v="-24" l="E" r="O" v="-32" l="E" r="Q" v="-32" l="E" r="S" v="-20" l="E" r="Z" v="-10" l="E" r="a" v="-34" l="E" r="c" v="-28" l="E" r="d" v="-30" l="E" r="e" v="-37" l="E" r="f" v="-64" l="E" r="o" v="-37" l="E" r="q" v="-30" l="E" r="t" v="-24" l="E" r="v" v="-48" l="E" r="w" v="-34" l="E" r="y" v="-48" l="F" r="A" v="-115" l="F" r="C" v="-18" l="F" r="G" v="-18" l="F" r="J" v="-109" l="F" r="O" v="-18" l="F" r="Q" v="-18" l="F" r="S" v="-29" l="F" r="X" v="-22" l="F" r="Z" v="-11" l="F" r="a" v="-55" l="F" r="c" v="-28" l="F" r="d" v="-20" l="F" r="e" v="-30" l="F" r="o" v="-28" l="F" r="q" v="-20" l="F" r="s" v="-35" l="G" r="T" v="-10" l="G" r="V" v="-10" l="G" r="W" v="-9" l="G" r="Y" v="-30" l="G" r="v" v="-29" l="G" r="w" v="-22" l="G" r="x" v="-14" l="G" r="y" v="-30" l="J" r="A" v="-35" l="J" r="X" v="-20" l="K" r="C" v="-78" l="K" r="G" v="-80" l="K" r="O" v="-97" l="K" r="Q" v="-97" l="K" r="S" v="-18" l="K" r="U" v="-29" l="K" r="W" v="-34" l="K" r="a" v="-34" l="K" r="c" v="-40" l="K" r="d" v="-33" l="K" r="e" v="-37" l="K" r="f" v="-25" l="K" r="m" v="-32" l="K" r="n" v="-32" l="K" r="o" v="-37" l="K" r="p" v="-32" l="K" r="q" v="-33" l="K" r="r" v="-32" l="K" r="s" v="-18" l="K" r="t" v="-38" l="K" r="u" v="-32" l="K" r="v" v="-101" l="K" r="w" v="-95" l="K" r="y" v="-85" l="L" r="C" v="-22" l="L" r="G" v="-47" l="L" r="J" v="25" l="L" r="O" v="-45" l="L" r="Q" v="-45" l="L" r="T" v="-150" l="L" r="U" v="-44" l="L" r="V" v="-147" l="L" r="W" v="-118" l="L" r="Y" v="-167" l="L" r="f" v="-23" l="L" r="t" v="-38" l="L" r="v" v="-78" l="L" r="w" v="-72" l="L" r="y" v="-79" l="O" r="A" v="-23" l="O" r="J" v="-27" l="O" r="T" v="-55" l="O" r="V" v="-25" l="O" r="W" v="-22" l="O" r="X" v="-64" l="O" r="Y" v="-55" l="O" r="Z" v="-38" l="O" r="x" v="-12" l="O" r="z" v="-10" l="P" r="A" v="-151" l="P" r="J" v="-140" l="P" r="T" v="-9" l="P" r="V" v="-10" l="P" r="X" v="-35" l="P" r="Y" v="-11" l="P" r="Z" v="-29" l="P" r="a" v="-44" l="P" r="c" v="-43" l="P" r="d" v="-34" l="P" r="e" v="-41" l="P" r="f" v="12" l="P" r="o" v="-41" l="P" r="q" v="-34" l="P" r="s" v="-32" l="P" r="t" v="12" l="P" r="y" v="12" l="Q" r="J" v="41" l="Q" r="T" v="-47" l="Q" r="V" v="-25" l="Q" r="W" v="-12" l="Q" r="X" v="12" l="Q" r="Y" v="-46" l="Q" r="g" v="59" l="Q" r="j" v="79" l="Q" r="x" v="31" l="Q" r=";" v="60" l="Q" r="]" v="32" l="R" r="C" v="-18" l="R" r="G" v="-19" l="R" r="O" v="-20" l="R" r="Q" v="-20" l="R" r="S" v="-27" l="R" r="T" v="-20" l="R" r="V" v="-28" l="R" r="W" v="-18" l="R" r="Y" v="-30" l="R" r="e" v="-36" l="R" r="o" v="-42" l="R" r="v" v="-26" l="R" r="w" v="-33" l="R" r="y" v="-33" l="S" r="A" v="-15" l="S" r="J" v="-9" l="S" r="T" v="-14" l="S" r="V" v="-14" l="S" r="W" v="-15" l="S" r="X" v="-13" l="S" r="Y" v="-20" l="S" r="v" v="-23" l="S" r="w" v="-17" l="S" r="y" v="-25" l="T" r="A" v="-160" l="T" r="C" v="-42" l="T" r="G" v="-59" l="T" r="J" v="-65" l="T" r="O" v="-58" l="T" r="Q" v="-58" l="T" r="S" v="-10" l="T" r="T" v="28" l="T" r="a" v="-160" l="T" r="c" v="-177" l="T" r="d" v="-147" l="T" r="e" v="-182" l="T" r="g" v="-151" l="T" r="m" v="-127" l="T" r="n" v="-127" l="T" r="o" v="-182" l="T" r="p" v="-127" l="T" r="q" v="-147" l="T" r="r" v="-127" l="T" r="s" v="-153" l="T" r="u" v="-127" l="T" r="v" v="-92" l="T" r="w" v="-86" l="T" r="x" v="-90" l="T" r="y" v="-93" l="T" r="z" v="-142" l="T" r=";" v="-114" l="T" r=":" v="-134" l="U" r="A" v="-45" l="U" r="J" v="-40" l="V" r="A" v="-96" l="V" r="C" v="-18" l="V" r="G" v="-25" l="V" r="J" v="-80" l="V" r="O" v="-27" l="V" r="Q" v="-27" l="V" r="S" v="-12" l="V" r="V" v="9" l="V" r="a" v="-114" l="V" r="c" v="-103" l="V" r="d" v="-87" l="V" r="e" v="-102" l="V" r="g" v="-100" l="V" r="m" v="-50" l="V" r="n" v="-50" l="V" r="o" v="-86" l="V" r="p" v="-50" l="V" r="q" v="-87" l="V" r="r" v="-50" l="V" r="s" v="-90" l="V" r="u" v="-50" l="V" r="y" v="-35" l="V" r="z" v="-82" l="V" r=";" v="-108" l="V" r=":" v="-73" l="W" r="A" v="-93" l="W" r="C" v="-22" l="W" r="G" v="-22" l="W" r="J" v="-88" l="W" r="O" v="-22" l="W" r="Q" v="-22" l="W" r="S" v="-10" l="W" r="X" v="-13" l="W" r="a" v="-71" l="W" r="c" v="-78" l="W" r="d" v="-72" l="W" r="e" v="-75" l="W" r="g" v="-54" l="W" r="m" v="-60" l="W" r="n" v="-60" l="W" r="o" v="-86" l="W" r="p" v="-60" l="W" r="q" v="-72" l="W" r="r" v="-60" l="W" r="s" v="-73" l="W" r="u" v="-60" l="W" r="v" v="-34" l="W" r="y" v="-53" l="W" r=";" v="-156" l="X" r="C" v="-57" l="X" r="G" v="-65" l="X" r="O" v="-57" l="X" r="Q" v="-57" l="X" r="S" v="-20" l="X" r="d" v="-44" l="X" r="e" v="-39" l="X" r="g" v="-9" l="X" r="o" v="-38" l="X" r="q" v="-44" l="X" r="t" v="-31" l="X" r="u" v="-38" l="X" r="v" v="-55" l="X" r="w" v="-49" l="X" r="y" v="-43" l="Y" r="A" v="-152" l="Y" r="C" v="-67" l="Y" r="G" v="-67" l="Y" r="J" v="-112" l="Y" r="O" v="-66" l="Y" r="Q" v="-66" l="Y" r="S" v="-17" l="Y" r="Z" v="-10" l="Y" r="a" v="-134" l="Y" r="c" v="-159" l="Y" r="d" v="-131" l="Y" r="e" v="-147" l="Y" r="f" v="-62" l="Y" r="g" v="-142" l="Y" r="i" v="-32" l="Y" r="j" v="-49" l="Y" r="m" v="-94" l="Y" r="n" v="-94" l="Y" r="o" v="-153" l="Y" r="p" v="-94" l="Y" r="q" v="-131" l="Y" r="r" v="-94" l="Y" r="s" v="-115" l="Y" r="t" v="-44" l="Y" r="u" v="-94" l="Y" r="v" v="-69" l="Y" r="w" v="-62" l="Y" r="x" v="-70" l="Y" r="y" v="-65" l="Y" r="z" v="-100" l="Y" r=";" v="-138" l="Y" r=":" v="-154" l="Z" r="A" v="-11" l="Z" r="C" v="-25" l="Z" r="G" v="-24" l="Z" r="O" v="-24" l="Z" r="Q" v="-24" l="Z" r="W" v="-7" l="Z" r="Y" v="-7" l="Z" r="a" v="-10" l="Z" r="c" v="-12" l="Z" r="d" v="-18" l="Z" r="e" v="-31" l="Z" r="o" v="-29" l="Z" r="q" v="-18" l="Z" r="v" v="-45" l="Z" r="w" v="-38" l="Z" r="y" v="-37" l="a" r="f" v="-12" l="a" r="t" v="-19" l="a" r="v" v="-34" l="a" r="w" v="-14" l="a" r="x" v="-19" l="a" r="y" v="-38" l="b" r="f" v="-17" l="b" r="s" v="-10" l="b" r="t" v="-9" l="b" r="v" v="-10" l="b" r="w" v="-10" l="b" r="x" v="-41" l="b" r="y" v="-10" l="b" r="z" v="-28" l="c" r="a" v="-17" l="c" r="o" v="-17" l="e" r="f" v="-18" l="e" r="t" v="-11" l="e" r="v" v="-10" l="e" r="w" v="-10" l="e" r="x" v="-31" l="e" r="y" v="-13" l="e" r="z" v="-20" l="f" r="a" v="-40" l="f" r="c" v="-45" l="f" r="d" v="-53" l="f" r="e" v="-51" l="f" r="f" v="-20" l="f" r="g" v="-60" l="f" r="o" v="-43" l="f" r="q" v="-53" l="f" r="s" v="-27" l="f" r="v" v="13" l="f" r="w" v="6" l="f" r="y" v="10" l="f" r="z" v="-20" l="g" r="a" v="-38" l="g" r="c" v="-12" l="g" r="d" v="-19" l="g" r="e" v="-17" l="g" r="g" v="19" l="g" r="o" v="-14" l="g" r="q" v="-19" l="g" r="t" v="-31" l="h" r="f" v="-12" l="h" r="t" v="-19" l="h" r="v" v="-34" l="h" r="w" v="-14" l="h" r="x" v="-19" l="h" r="y" v="-38" l="k" r="a" v="-35" l="k" r="c" v="-48" l="k" r="d" v="-56" l="k" r="e" v="-66" l="k" r="o" v="-69" l="k" r="q" v="-56" l="k" r="s" v="-19" l="k" r="t" v="-10" l="k" r="u" v="-26" l="m" r="f" v="-12" l="m" r="t" v="-19" l="m" r="v" v="-34" l="m" r="w" v="-14" l="m" r="x" v="-19" l="m" r="y" v="-38" l="n" r="f" v="-12" l="n" r="t" v="-19" l="n" r="v" v="-34" l="n" r="w" v="-14" l="n" r="x" v="-19" l="n" r="y" v="-38" l="o" r="v" v="-9" l="o" r="w" v="-8" l="o" r="x" v="-40" l="o" r="y" v="-11" l="o" r="z" v="-27" l="p" r="f" v="-17" l="p" r="s" v="-10" l="p" r="t" v="-9" l="p" r="v" v="-10" l="p" r="w" v="-10" l="p" r="x" v="-41" l="p" r="y" v="-10" l="p" r="z" v="-28" l="q" r="g" v="10" l="r" r="a" v="-42" l="r" r="c" v="-30" l="r" r="d" v="-28" l="r" r="e" v="-27" l="r" r="g" v="-28" l="r" r="o" v="-33" l="r" r="q" v="-28" l="r" r="s" v="-35" l="r" r="v" v="19" l="r" r="w" v="11" l="r" r="y" v="10" l="s" r="f" v="-19" l="s" r="t" v="-23" l="s" r="v" v="-31" l="s" r="w" v="-10" l="s" r="x" v="-22" l="s" r="y" v="-37" l="s" r="z" v="-18" l="t" r="a" v="-25" l="t" r="c" v="-25" l="t" r="d" v="-23" l="t" r="e" v="-22" l="t" r="o" v="-20" l="t" r="q" v="-23" l="t" r="t" v="-29" l="v" r="a" v="-30" l="v" r="c" v="-25" l="v" r="d" v="-20" l="v" r="e" v="-20" l="v" r="f" v="11" l="v" r="g" v="-28" l="v" r="o" v="-19" l="v" r="q" v="-20" l="v" r="s" v="-9" l="v" r="t" v="10" l="v" r="v" v="12" l="v" r="w" v="12" l="v" r="y" v="12" l="v" r="z" v="-26" l="w" r="a" v="-23" l="w" r="c" v="-20" l="w" r="d" v="-18" l="w" r="e" v="-18" l="w" r="f" v="6" l="w" r="g" v="-18" l="w" r="o" v="-19" l="w" r="q" v="-18" l="w" r="s" v="-18" l="w" r="t" v="4" l="w" r="v" v="12" l="w" r="w" v="8" l="w" r="y" v="12" l="w" r="z" v="-17" l="x" r="a" v="-37" l="x" r="c" v="-46" l="x" r="d" v="-44" l="x" r="e" v="-54" l="x" r="o" v="-55" l="x" r="q" v="-44" l="x" r="s" v="-12" l="x" r="t" v="6" l="x" r="u" v="-20" l="y" r="a" v="-31" l="y" r="c" v="-26" l="y" r="d" v="-24" l="y" r="e" v="-25" l="y" r="f" v="10" l="y" r="g" v="-26" l="y" r="o" v="-24" l="y" r="q" v="-24" l="y" r="s" v="-19" l="y" r="t" v="10" l="y" r="v" v="12" l="y" r="w" v="8" l="y" r="y" v="10" l="y" r="z" v="-17" l="z" r="a" v="-34" l="z" r="c" v="-45" l="z" r="d" v="-46" l="z" r="e" v="-46" l="z" r="f" v="-10" l="z" r="g" v="-17" l="z" r="o" v="-45" l="z" r="q" v="-46" l="z" r="s" v="-22" l="z" r="u" v="-10" l="z" r="v" v="-18" l="z" r="w" v="-22" l="z" r="y" v="-18"  ## Scoring This is , so the shortest answer (in bytes) wins. ### Meta I know this challenge is going to need a lot of work before it's ready for main. Please hold criticisms for now. Helpful ideas and thoughts are welcome. • I'm not sure that the problem is well defined. There's a reason it's called font hinting: the rendering application is free to take it into account or not, or even to apply more complex logic. E.g. some fonts have multiple sets of font hints for different contexts. There are other complex issues. A font can have Latin and Cyrillic letters and define hints for kerning between pairs of Latin and pairs of Cyrillic but not between Latin and Cyrillic; however, some letters may have identical glyphs, so a judgement on whether the kerning is "correct" might be ambiguous. Then there's antialiasing. – Peter Taylor May 24 '17 at 6:15 • @PeterTaylor Good notes. I will likely restrict the character set. I just wanted to start getting ideas down in the sandbox. – Poke May 24 '17 at 6:51 • Very ambiguous. – dkudriavtsev May 25 '17 at 17:48 • @Mendeleev It's not done yet. I'm aware it's ambiguous. – Poke May 26 '17 at 16:10 • Looking at developer.apple.com/fonts/TrueType-Reference-Manual/RM06/… I can see a number of issues to address. 16- vs 32-bit entries? Should multiple tables be combined or printed separately? All tables or only tables with certain coverage values? Which of the four defined formats need to be supported? Do you have a test case which covers glyph index differing from codepoint? – Peter Taylor Sep 16 '17 at 17:28 • @PeterTaylor I have a proof of concept that I wrote (it's the reason I have taken so long to update this) and I'm planning to address all of your questions. Thanks for doing a bit of research to help me out, though :] – Poke Sep 16 '17 at 18:57 • Downvoter, why? – Poke Oct 4 '17 at 21:03 # Shift-left golfer Sometimes when doing code-golf, a person needs to understand which format is shorter: • 2147483648 • 0x80000000 • 1<<31 The task: 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? – HyperNeutrino 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 Six Flags over HTTP Let's say you need to transmit six boolean flags in a URL string. Obviously you could do it with six ones or zeroes, but you want better compression. With a little math you can pack them into two characters using 0-7 octal. How about mapping all six to a single ASCII character? Here we have a problem: you are not allowed to use , / ? : @ & = +$ # or space. Now the range of printable ASCII no longer has 64 valid characters in a row.

In Javascript (or another language that can run from a web page, if any), what is the shortest code for a pair of functions to encode and decode this data, between an array of six booleans and a single character?

• -1 language restriction, most languages have HTTP libraries so I think any language should be allowed – ASCII-only Sep 24 '17 at 13:11
• This challenge could be improved by rephrasing it to: "Write a bijective function between an array of six booleans and a single printable character excluding the characters ,/?:@&=+$# ". Mentioning that the encoder and decoder should be separate programs/functions would be helpful. Also, may the encoder and decoder share code? – fireflame241 Sep 24 '17 at 22:08 # Count letter frequency Inspired by question Tweetable hash function challenge, you should take the English dictionary used there and produce a program or function that outputs the the absolute and relative frequency of each character. It is CASE SENSITIVE and the APOSTROPHE is also accountable as a real letter. Example of a valid output format (but with stupid guessing values): A 5566 20% ... Z 60 0.2% a 27000 30% ... z 120 0.01% ' 450 3.5%  It is , but no answer will be accepted. Wanna know shortest script for each language. • -1 (01) Don't rely on another challenge to define yours; include all the information we need in your write-up. (02) Make an effort to come up with some actual test cases - do you honestly expect us to verify our solutions against "stupid guessing values"? – Shaggy Sep 30 '17 at 0:55 # Is it a perfect loop? test-batterydecision-problem Your task is to take a GIF or an animated image in any reasonable format as input (including taking the file name of a GIF in the current directory), and output whether it is a "perfect loop" - that is, the frames transition seamlessly from the end to the start, and a human cannot notice where it starts and ends at first glance. Return or print a truthy value if it is a perfect loop, otherwise print or return a falsy value. ## Scoring Winners will be determined from the percentage of test cases they get correct. In the event of a tie, highest votes wins. You can view test cases at https://ghostbin.com/paste/m3yaw. Show your score against the test cases when you post. ## Input If you are not taking input in a GIF, please provide a program that will convert a GIF to your desired format. Images corresponding to a truthy value have been taken from /r/perfectloops and for falsy test cases, /r/almostperfectloops and /r/gifs. ## Restrictions • Hard coding is not allowed (violates standard loophole 1 and 2). • You must provide consistent results for the same GIF (no randomness) • Remember, this is not , so byte count is not needed in your solution. Just post the language name and add the percentage correct when I comment. • I'm not sure it's as simple as comparing the first to the last frame, if it is we'd have duplicate frames. is this challenge allowing HTTP requests? – tuskiomi Oct 17 '17 at 21:15 • If hashing the inputs is not allowed, then you should clearly define what constitutes a “perfect loop”. It's not good to extrapolate from a handful of test cases where the pass/fail cases are very similar. – japh Oct 18 '17 at 14:31 # Removing a Letter adds a Letter Your program should output nothing when unaltered, however, when any single character is removed it should have an output length of 1. This extends to any number of characters being removed from the program, as long as there is, at minimum, a single character remaining. For example, if my program were abcdefg, it should output nothing if unaltered. However, if I were to remove a and d from this program to get bcefg, it should output any two printable characters that represent 16 bytes of information (2 characters for 2 characters removed). • So if bcefg outputs (00,AA,etc...) this is valid. Taking this further, if we were to remove all but the letter g we'd need an output of 6 characters. • So if g outputs ('000000','@$^%@(',etc...) this is valid.

Your program must function for all possible combinations of removals that are possible, that is to say each single letter in your program should be a valid program.

# Rules

• You may "lock" pieces of the code, each locked byte counts for 2-bytes instead of 1-byte.
• Locked bytes will never be removed.
• For instance, if my program was abcdefg and bcd is locked, the shortest program we'll get is abcd,bcde,bcdf and bcdg.
• If bcd was locked in abcdefg it'd be 10 bytes, not 7.
• The program may output any byte to represent 1 removed character, N-bytes for N removed chars in the code itself.
• The rule only leads to totally locked code – l4m2 Mar 13 '18 at 0:13
• @l4m2 hah. I disagree. – Magic Octopus Urn Mar 13 '18 at 0:58
• But more constructively, increase the penalty? Limit locked chars? – Magic Octopus Urn Mar 13 '18 at 1:04
• Maybe require an unlocked percent? – l4m2 Apr 6 '18 at 10:52

# Non-true, non-false JS boolean

Array prototype isn't redefined, input hasn't getters

function magic(input){
let result = [];
if(input.boolean != true){result.push("non-true");}
if(input.boolean != false){result.push("non-false");}
result.push(input);
return result.join("\n");
}


returns

non-true
non-false
{"boolean": true}


What is passed to magic function?

Based on real problem :) I spent 30 minutes on this puzzle

• This site is for programming contests, not pure programming puzzles. Thanks for using the sandbox, anyway. – user202729 Feb 1 '18 at 12:11
• Contrary to what user202729 states, Programming Puzzles are on-topic on this site. This challenge could use a little cleanup to make it a better fit here (for example, what language is this?), but this challenge is indeed allowed here. – AdmBorkBork Feb 1 '18 at 14:02
• ... someone said that I'm wrong. Anyway people definitely doesn't like this. – user202729 Feb 1 '18 at 14:02
• @AdmBorkBork this is JS – Евгений Новиков Feb 1 '18 at 14:41
• @ЕвгенийНовиков what JS version is this? in is a keyword, and can't be a variable name. – dzaima Feb 1 '18 at 14:47
• @dzaima Good point. Last time I check on TIO the object {boolean: true} doesn't have " around and it caused a syntax error. I forgot about in so just try to rename it and it worked... – user202729 Feb 1 '18 at 14:51
• "Programming Puzzle" is in the name of the site @user202729 – dylnan Feb 1 '18 at 15:46
• @dylnan But... – user202729 Feb 1 '18 at 15:55
• @AdmBorkBork is correct. We do allow programming puzzles. – Nathan Merrill Feb 1 '18 at 16:25
• @NathanMerrill Then just upvote the comment. – user202729 Feb 2 '18 at 5:34
• Many many things in the past, including but not limited to, code-trolling, underhanded, non-observable behavior, etc. are off-topic or heavily-discouraged nowadays. Be careful. – user202729 Feb 2 '18 at 5:34
• @user202729 I did upvote. I just wanted to make sure it was extra clear to the OP. Furthermore, this challenge doesn't fit any of those tags, because its not asking for trolling/underhanded/non-observable code. You could argue that the code in the challenge fits those tags, but that's not what we care about. – Nathan Merrill Feb 2 '18 at 5:51
• I don't believe that console is part of any JS spec. This presumably only works in certain contexts, and the question should specify what they are. Otherwise the task devolves into code-trolling by defining a suitable console. It's already borderline IMO. – Peter Taylor Feb 2 '18 at 12:04
• @dzaima sorry, fixed this. Now input variable is input – Евгений Новиков Feb 3 '18 at 7:40
• OK, so, in that case you may want to work on the wording of the challenge before posting it to Main because, right now, it reads as though you've come across this challenge elsewhere, spent half an hour trying to solve and are now looking for help doing so. Also, just so you know, restricted language challenges rarely go down well here. – Shaggy Feb 3 '18 at 19:20

Sandbox:

Is this question already available (duplicate)?

Are things too vague?

Does providing the example help or hinder?

# Tidy the Pantry (easy)

I hate grocery shopping, particularly the part where I put groceries away--so I'm calling upon the collective hive-mind to handle that.

## Challenge

Your challenge is to take a 1D-list of groceries and a 2D pantry as input; and output an newly assorted pantry. The two variables can be of your type choice, and in any order, but please specify what item types your program requires (e.g. string, array, etc.).

### Scoring

• This is code golf, so the shortest answer in bytes wins

### Rules

• The pantry should be ordered alphabetically (A - Z, left to right, top to bottom)
• For simplicity, the pantry is case-insensitive
• The pantry must retain its horizontal size (but trailing newlines are optional)
• "Pockets" (empty spaces) should be filled between items (i.e. only the last item is allowed to have a trailing pocket)
• If the pantry is too small for the incoming groceries, then the pantry must replace older items (Z being the oldest, A the youngest)
• Z from groceries is younger than A in pantry
• Standard loopholes are forbidden

## Examples ([ and ] are used for readability)

Input (4x4 pantry):

[A][A][ ][ ]
[ ][ ][B][ ]
[C][ ][ ][ ]
[ ][ ][ ][D]



Output:

[A][A][A][A]
[B][C][D][D]
[ ][ ][ ][ ]
[ ][ ][ ][ ]


Input (2x2 pantry):

[A][B]
[C][D]

XYZ


Output:

[A][X]
[Y][Z]


# JavaScript ES6 (989 bytes)

// (String, String) -> String
let organise = (pantry, groceries) => {
let n = pantry.split("\n").sort((a, b) => b.length - a.length); // used at the end of the function for horizontal sizing
n = n[0].length;

pantry = pantry
.replace(/\W/g, "") // get rid of all non-alphanumeric characters
.split("");         // turn the string into an array

// we need the properties of the new array
// so the extra pantry = pantry is needed
pantry = pantry
.slice(0, pantry.length - groceries.length) // go ahead and remove the last overlapping elements
.concat(groceries)                          // add the groceries to the pantry
.join("")                                   // turn into a string
.split("")                                  // turn into an array
.sort()                                     // sort the array
.join("");                                  // turn into a string

return pantry.replace(RegExp((.{${n}}), 'g'), "$1\n");
};

/** Testing below **/

console.log("Test #2:\n" + organise(
AJCHDJE
JJ   JA
ASD
OOQ I U
Q     W
R,

'AHJBCJHDHHATTGEH'
))

## Test Cases:

### Test #1, 4x4 pantry

TVCX <- pantry
ABCD
ATDJ
UAIK

XYXY <- groceries
----
AAAB <- expected output
CCDD
IJKT
XYXY


### Test #2, 7x6 pantry

AJCHDJE
JJ   JA
ASD
OOQ I U
Q     W
R

AHJBCJHDHHATTGEH
-------
AAAAABC
CDDDEGH
HHHHJJT
T


### Test #3, 10x10 pantry

AAAAAAAAAA
AAAAAAAAAA
AAAAAAAAAA
AAAAAAAAAA
AAAAAAAAAA
AAAAAAAAAA
AAAAAAAAAA
AAAAAAAAAA
AAAAAAAAAA
AAAAAAAAAA

ZZZZZZZZZZZZZZZZZZZZ
----------
AAAAAAAAAA
AAAAAAAAAA
AAAAAAAAAA
AAAAAAAAAA
AAAAAAAAAA
AAAAAAAAAA
AAAAAAAAAA
AAAAAAAAAA
ZZZZZZZZZZ
ZZZZZZZZZZ


# Test #4, 16x16 pantry pantry

ASDFGHJKLZXCVBNM
QJKAJ  KAKSJD  J
KJASDKFHI YOIER
W   OSDOFJ    DK
E PPPASP     AS
R
TASD
YAAAAAAAAAAAA
U          JHOLK
IIAUSHODUYOAISUO
OASD  AUSODI
PIASND JUASJNOIJ
A ASJDH PPOIO
QHIAIUSOIUOOO
WYYAIUSNNAJSDASD
EAISDUUIOPJPIJPJ
ROQPEWIHRNXCAISD

QWERTYUIOP
----------------
AAAAAAAAAAAAAAAA
AAAAAAAAAAAAAAAA
ABCCDDDDDDDDDDDD
DDDEEEEEFFFGHHHH
HHHIIIIIIIIIIIII
IIIIIIJJJJJJJJJJ
JJJJJJKKKKKKKKLL
MNNNNNNOOOOOOOOO
OOOOOOOOOOPPPPPP
PPPPPPQQQQRRRRRS
SSSSSSSSSSSSSSSS
SSSTTUUUUUUUUUUU
UVWWY


# Test #5, 2x2 pantry

HE
LO

[no groceries]
--
HE
LO

• why divide the program score? – RedClover Feb 26 '18 at 19:03
• I recommend you do count by bytes otherwise someone is just going to encode their entire program in Chinese characters and win. – HyperNeutrino Feb 26 '18 at 19:09
• @labela--gotoa To get a golfed score (smaller programs get a smaller score), should I change it? – Ephellon Dantzler Feb 26 '18 at 19:13
• @EphellonDantzler I don't understand why not just normal scoring...? – RedClover Feb 26 '18 at 19:14
• LOL, that's why I set in in Sandbox first @labela--gotoa – Ephellon Dantzler Feb 26 '18 at 19:16
• Some notes on your reference implementation: 1 It appears far too soon in the challenge. 2 It's not 1768 bytes. 3 You need to ungolf it and make it readable or it's not much use. 4 As it's JS, create a Snippet for it. 5 Is it necessary? It seems to be thrown in there to try to patch over any holes in the challenge spec. – Shaggy Feb 26 '18 at 23:17

# Interpret pseudocode

Wikipedia says pseudocode

and

A program in pseudocode is not an executable program.

I don't care.

Make a pseudocode interpreter that can run pseudocode that fits the rules described below*. This is based on the IB pseudocode guide, but it is simplified quite a bit to make it fit for the challenge.

# Pseudocode specifications

This is a simplified pseudocode to make the challenge less tedious. The pseudocode language has no strings, no arrays, no classes, no methods, and no variables other than integers.

## Basic syntax

Comments that start at // and end at a newline (like java one-line comments). // is not necessarily followed by a space, and the comment may be empty. Example:

A = 2 + 3 // I can't write five because my keyboard is broken


Statements are separated by newlines. Lines may be empty (without statements). The exact number of spaces doesn't matter, and spaces are not required. The language is case sensitive.

## Variables

All variables are global, and can be accessed anywhere. They do not need to be declared. To keep things simple, all variables can be assumed to be integers. All variable names are UPPERCASE, and consist only of letters. Your program should at least handle integers from -256 to 256. A wider range is not a requirement.

Variables are assigned values using this syntax:

VARIABLE = Expression


Where VARIABLE can be any uppercase name and expression can be any integer expression, as discussed below.

Examples:

A = 5
B = A + 3
NUMBER = A * B


## Expressions

An expression can be:

• An integer, like 42
• A variable, like NUMBER
• A binary operation on two other expressions, like NUMBER + 5. There are only four operations: +, -, *, /. Division rounds integers down.

Expressions can be surrounded by parentheses to indicate that they need to be evaluated first. To keep things simple, all expressions are evaluated from left to right no matter what the operations are (unless there are parentheses that specify otherwise), so

A = 2 - RM * 9 + 3 / NUMBER
B = 1 + 2 * (3 - 4) / 6


is equivalent to

A = (((2 - RM) * 9) + 3) / NUMBER
B = ((1 + 2) * (3 - 4)) / 6


## Boolean expressions

Boolean expressions can compare two expressions using == (equality), != (not equal to), < (less than), and > (greater than). They are only used for control flow, as discussed below (there are no boolean variables).

## Control flow

There are four types of control flow. They can be infinitely nested in all combinations.

### If

if (booleanExpression) then
// statements (discussed below)
endif


### If-else

if (booleanExpression) then
// statements (discussed below)
else
// other statements
endif


### Loop while

loop while (booleanExpression)
// do stuff
endloop


Where booleanExpressions are boolean expressions. The ifs work the same as in normal programming languages. The while loop is a simple while loop.

The booleanExpressions will always be surrounded by (). The pseudocode is very flexible with spaces, and any number of spaces is valid.

### Loop for

loop VARIABLE from Expression1 to Expression2
// things to do over and over again
end loop


Where Expression1 and Expression2 are expressions that are evaluated before the loop begins and their values are stored until the loop finishes. The content of the loop is executed for every integer from the result of Expression1 to that of Expression1, inclusive. At every iteration, the index variable (VARIABLE in this case) is updated.

Example:

loop I from 3 to 5
output(I)
endloop


Outputs:

3
4
5


## Statements

### Output

output(Expression) outputs the evaluated expression. It's like println in programming languages. So:

output(1+1)


prints 2, followed by a newline.

output() with no arguments should print a newline.

### Other statements

If the interpreter encounters any other statement that looks like a method call with no arguments, it should pretend it's executing it. For example,

lightsoff()
gohome()


should print (together with a newline):

executing lightsoff
executing gohome


In other words, executing [Method name] should be printed. All statements will be lowercase and will consist entirely of letters.

Keywords cannot be statements. You do not have to deal with the following (it will not appear in the pseudocode): - if() - endif() - loop() - while() - etc.

However, statements that start with keywords are valid. For example, loophole() should print executing loophole, even though loop() itself is not valid.

# Challenge rules

• Your program should take a string as input. It can also take something equivalent, like an array of characters. But you can't take an array of strings; your program must itself separate the lines and tokens. You can also take a file as input.
• Your program should print the output of the pseudocode in any reasonable form.
• No standard loopholes.
• There are no restrictions on what your program should do when given invalid pseudocode.
• This is code golf. The shortest code in bytes wins.

# 1

A = 3
output(A) // prints 3
B = 4 + A * 2
output(B)
helloworld()
output(A + B + 1 * 3)


Should give:

3
14
executing helloworld
54


# 2

loop NUM from 2 to 20 // cycle through possible prime numbers
COUNT = 0
loop DIV from 2 to NUM // cycle through possible divisors
if(NUM/DIV*DIV == NUM) then // if the number is exactly divisible
COUNT = COUNT + 1
endif
endloop
if (COUNT == 2) then // if number is prime
output(NUM)
endif
endloop


Should give:

2
3
5
7
11
13
17
19


# 3

Tricky cases that your interpreter should handle:

// empty comment:
//
// empty line:

// more comment testing // ///
////

if     (3<4) then
endoftheworld() // a statement
ifff()
endifnot()
// endif in a comment doesn't count
endif
// loops can be empty:
loop I from 0 to 10
endloop
output(I) // variables are global
if(1<2)
if(3<4) // nesting is ok
ok()
endif
endif
// spacing doesn't matter:
output   (2+   8   - 1   )
loop             while(2<1)
neverhappened()
endloop


Should output:

executing endoftheworld
executing ifff
executing endifnot
10
excecuting ok
9


*Technically, once pseudocode follows rules as strict as those described here, it is arguably not pseudocode anymore. Wikipedia says it's called skeleton code.

Any suggestions?

I double-checked all the specifications, but if anything seems reasonably unclear, please let me know.

• Actually that's because the challenge is uninteresting. – Akangka May 3 '18 at 2:11
• @Akangka thanks for the feedback. How do you think it could be made more interesting? – Reinis Mazeiks May 3 '18 at 16:47
• Unfortunately, there is nothing to improve. You have to find other challenge. Also, it is not pseudo-code. – Akangka May 4 '18 at 3:03
• @Ok, thanks. I'll try to think of something. Also, read the *note. :) – Reinis Mazeiks May 5 '18 at 19:39

# Common Logic Gates

Given positive integer n, make a common n-to-1 gate with fewest input, i.e. make a function f: {0,1}k ↦ {0,1} with smallest k that, for each function g: {0,1}n ↦ {0,1}, there exists {ak}, such that each element ai in the sequence map to one of 0, 1, x1, x2, x3, ..., xn, satisfying that, for each {xn}, g(x1, x2, x3, ..., xn) = f(a1, a2, a3, ..., an).

Samples:

To make a common 1-to-1 gate, your circuit must take at least 2 input:

f(A,B) = A XOR B


For a buffer gate (g = x1 ↦ x1), let A=0 and B=Input (a1 = 0, a2 = x1); for a not gate (g = x1 ↦ ¬x1) , let A=1 and B=Input (a1 = 1, a2 = x1).

Alternatively, you can use f(A,B) = A AND NOT B. For a buffer gate, let B=0 and A=Input; for a not gate, let A=1 and B=Input.

To make a common 2-to-1 gate, the circuit must take at least 4 input bits: (The two inputs are represented as a and b)

f(A,B,C,D) = ((A AND B) OR (C AND NOT B)) XOR D

(ab)
00 01 10 11 A B C D
0  0  0  1  a b 0 0
0  0  1  0  0 b a 0
0  1  1  0  a a a b
0  1  1  1  1 b a 0
1  0  0  0  1 b a 1
1  0  0  1  0 a 1 b
1  1  0  1  0 b a 1
1  1  1  0  a b 0 1


Output can be an boolean expression with reasonable logic gates, or just the output corresponding to all possible input of the n-to-1 function f (the truth table of f). If there are more than one possible functions, you can output any of them.

Shortest code in bytes win.

Code that matches the requirement:

function solve(n) { // n positive int
var res = [], tmp=[], inmap=[], need=[];
for (var i=1; ; i++) {
for (var _res=0; _res<2**(2**i); _res++) {
var valid = 1;
for (var j=0; j<2**i; j++)
tmp[j] = Math.floor(_res/2**j)%2;
for (var _need=0; _need<2**(2**n); _need++) {
for (var j=0; j<2**n; j++)
need[j] = Math.floor(_need/2**j)%2;
var valid2 = 0;
for (var _inmap=0; _inmap<(n+2)**i; _inmap++) {
var valid3 = 1;
for (var j=0; j<i; j++)
inmap[j] = Math.floor(_inmap/(n+2)**j)%(n+2) - 1;
for (var j=0; j<2**n; j++) {
var bits = 0;
for (var k=0; k<i; k++) {
if (inmap[k]==-1 || (inmap[k] && (j>>(inmap[k]-1))%2))
bits |= 1 << k;
}
if (tmp[bits] != need[j])
valid3 = 0;
}
valid2 |= valid3;
}
if (!valid2) valid = 0;
}
if (valid)
res.push (tmp.slice());
}
if (res.length)
return res[AnyNonNegativeIntegerLessThan(res.length)];
// binary index input
}
}

function AnyNonNegativeIntegerLessThan(x) { if(R>=x) throw ("end"); return R;}
for (R=0; ; R++) { console.log (solve(1)); }

• You don't define what an n-to-1 gate is anywhere in your question. – Ad Hoc Garf Hunter Mar 27 '18 at 1:00
• @user202729 @user56656 n-to-1 gate means a gate with n input and 1 output. common n-to-1 logic gate mean a logic gate that can be used to replace any n-to-1 gate with some proper wiring. You can treat a logic gate as a ROM(so you can decide for each input what the output is) – l4m2 Mar 27 '18 at 1:15
• Output gates or ROM – l4m2 Mar 27 '18 at 1:25
• You should put the definitions in the challenge. "that can be used to replace any n-to-1 gate with some proper wiring" is still not very clear, you should define more carefully what you mean by proper wiring. – Ad Hoc Garf Hunter Mar 27 '18 at 3:22
• I assume you mean functions g: {0,1}^n -> {0,1}, right? Why do you specify x_0 and x_-1? Shouldn't x just be a vector with indices 1,2,3,...,n? – flawr Mar 27 '18 at 14:07
• Is {a_k} just a subset of {1,2,3,...,n}? Or can we have a_1=a_2=a_3=1 for example? – flawr Mar 27 '18 at 14:09
• {a_k} seems not a multiset. It should be an array or say a sequence of numbers – l4m2 Mar 27 '18 at 14:43
• So you're asking for something which outputs answers to codegolf.stackexchange.com/q/24983/194 ? – Peter Taylor Mar 28 '18 at 11:33
• @PeterTaylor No. it requires to use NAND gate to make up one circult that do the thing. Also 24983 is a 1-of-4 (74LS153), not a 4-to-1 gate common 2-to-1 – l4m2 Mar 28 '18 at 12:41
• (+) Any reason for downvoting? Downvoting in the sandbox indicates that the challenge is incomplete, if you don't leave a comment the OP can't know what is wrong. – user202729 Mar 29 '18 at 4:48
• @user202729, there are already comments indicating that this question is going to attract close votes as unclear if it's posted to main in the current state. – Peter Taylor Mar 29 '18 at 10:59
• @user56656 Are the issues fixed now? – user202729 Mar 31 '18 at 15:16
• @flawr Are the issues fixed now? – user202729 Mar 31 '18 at 15:16
• No I still think the explanation is quite bad and the notation is not very clear – flawr Mar 31 '18 at 16:15
• A reference implementation is no substitute for a clear specification. The first paragraph is where you need to focus your efforts. – Peter Taylor Mar 31 '18 at 19:32

# Is the program 32 or 64 bits?

Assignment is simple to explain: write the shortest code you need to determine whether an executable binary program supplied as parameter is 32 or 64 bits.

If there is a different kind of bitness, you can also do for it, but is not mandatory.

What I really don't want is telling me you support other bitnesses and after I get 32 or 64 as a result.

Valid outputs for 32:

32
32bit
32bits
32 bit
32 bits


The same pattern for 64.

• I think you're missing a word somewhere in the region of "determine supplied" – Kamil Drakari Apr 4 '18 at 19:43
• @KamilDrakari thanks. – sergiol Apr 4 '18 at 19:53
• Executable on Windows or Linux machine? What if (... maybe ...) the program is a valid executable for both "bitness" but do different things? – user202729 Apr 5 '18 at 1:30
• Of the output formats you allow, I think the first one will result in the shortest code in every single language. Because of this, you might as well just specify that the output should be the number 32 or the number 64. – Nathaniel Apr 5 '18 at 8:03
• This made me wonder what to do about shell scripts, which are executable programs, but require another file to interpret them and as such aren't 32-bit or 64-bit per se. Maybe it would be best to specify "executable binary file" to not have to deal with that mess. – Angs Apr 5 '18 at 11:22
• @Angs: Thanks. Changed. – sergiol Apr 5 '18 at 11:27
• @user202729: I don't care. Windows, Linux, Mac, whatever, ... – sergiol Apr 5 '18 at 11:28
• @Nathaniel: It is intentional. If you have a language feature called bitness(program) returning 32bits you do not need to waste more bytes removing the bits part! – sergiol Apr 5 '18 at 11:30
• The word "challenge" is not really true, at least for ELF. It's absolutely trivial. – Peter Taylor Apr 6 '18 at 20:20
• @PeterTaylor : Changed, thanks. – sergiol Apr 6 '18 at 21:20
• The real "challenge" is to know the executable file format, so this becomes more of a puzzle than a challenge. And for puzzles, people can just copy others' solution and port to other languages. // Consider having some popular file format in the challenge itself so people don't have to look up them? – user202729 Apr 7 '18 at 11:19
• @user202729: My initial idea was to ask only for Windows .exe files but I changed my mind because it was too limiting. Without such restrictions the question becomes multi-platform. – sergiol Apr 7 '18 at 11:38

## The challenge

• Write a Discord bot with a single command, !oldest, that gives the oldest user in the server that the command that was run in.

• Gracefully failing in DM channels is not required.

• Assume the bot's token is this invalid token: MjM4NDk0NzU2NTIxMzc3Nzky.CunGFQ.wUILz7z6HoJzVeq6pyHPmVgQgV4.
If the token is compressed in the program, provide instructions on how to change it so I can test it.

## Sample discord.py implementation

import discord
client = discord.Client()
@client.event
async def on_message(M):
if(M.content=="!oldest"):
N=sorted([x.id for x in M.server.members])[1]
await client.send_message(M.channel, str(M.server.get_member(N)))
client.run("MjM4NDk0NzU2NTIxMzc3Nzky.CunGFQ.wUILz7z6HoJzVeq6pyHPmVgQgV4")

1. Get a list of every user in the server
2. Sort their snowflake IDs
3. Print the username and discriminator of the member with the smallest ID.

No API for your language? Have fun.

Standard loopholes forbidden, etc, etc.

Shortest code in bytes wins.

# Sandbox

I originally posted this question on the main site, but I deleted it, as it turns out I'm bad at writing these. Please forgive me.

• I'm sure I've seen this already, but with comments saying that it needed a lot more information to be self-contained. It still needs a lot more information to be self-contained. – Peter Taylor May 5 '18 at 11:11
• Yep. I've edited the question to clarify. – SIGSTACKFAULT May 5 '18 at 12:35
• Are you talking about discord servers? Other than form the example this is not clear at all. What is a DM channel? What is a token in this context? – flawr May 5 '18 at 13:02
• A: Clarify that you're talking about Discord B: When you make a challenge that requires a library does that mean I can use a library that conveniently has the command you're asking of? – IQuick 143 May 6 '18 at 2:12

# Divide two strings

One day, I saw the challenge to multiply two strings and I thought I might be able to do one better.

That challenge was fake. It was elementwise maximum. It was not real multiplication. So I set out to make something real. Real division between two strings.

I quickly realized that this would make an amazing challenge, as the algorithm was surprisingly complex and interesting to implement.

I then realized that it was actually easily reduced into a mere few operations. I'm still doing the challenge, though.

Enough with the backstory. Let's go.

## Method

To divide two strings, do the following, where x is the first string and y the second:

• If x does not contain y, return a space and a period concatenated to x.
• For example, testx and blah would become .textx, with a space at the beginning.
• Otherwise, return every occurrence of y in x, a period, then y divided by x with every occurrence of y removed, with all the periods removed.
• For example, eestestst and est would become estest.est.

## Challenge

Write a program or function that, given two strings via standard input, returns the first string divided by the second.

You may assume that neither input string contains a space, newline or period, and that the operation does not require more than 10 layers of recursion.

## Test cases

test, es => es. es
test, blah =>  .test
okayye, y => yy. y
testes, es => eses. es
battat, at => atat. at
see, es =>  .see
see, e => ee. e
same, same => same.
aabb, ab => ab.ab
eestestst, est => estest.est
aheahahe, aheah => aheah.aheah ah


## Scoring

As this is , the submission with the least amount of bytes wins.

# Sandbox questions

• Is this a duplicate?
• Have I missed anything?
• Does anything need further explaining?
• Is there an issue with the concept of the challenge?
• What for aabb / ab? – l4m2 Jun 1 '18 at 12:42
• okayye, y => yy. okay typo? – l4m2 Jun 1 '18 at 12:42
• The test case battat, at => atat. by seems like it should be battat, at => atat. bt instead. – Kamil Drakari Jun 1 '18 at 13:47
• It seems odd to me that when no characters are matched the output format is {matched characters (empty)}<space>.{unmatched characters} while the format when there are matches becomes {matched characters}.<space>{unmatched characters}. I would much rather see consistent ordering of the . and <space> – Kamil Drakari Jun 1 '18 at 13:50
• @KamilDrakari 2 / 4 is 0.5, not .05, when 4 is not contained within 2 at all. Thus it makes no sense for test / blah to be . test when blah is not contained within test. We treat a space essentially like a zero would be with normal numbers. – LyricLy Jun 1 '18 at 22:15
• @LyricLy 6/4 is 1.5 not 1.05. If you're treating space as 0 then there shouldn't be any space after the dot in any of the test cases. – Kamil Drakari Jun 1 '18 at 22:58
• @KamilDrakari Actually, you're right. I was entirely mistaken because you get a fraction from 1 / remainder, not original number / remainder. Meaning this entire thing is wrong and I need to figure out a good replacement for 1 in string form. – LyricLy Jun 2 '18 at 3:32
• Fixed the issues. – LyricLy Jun 2 '18 at 3:50
• I accept downvotes, but I'd appreciate suggestions on how to improve the idea, or at least an explanation of what's wrong with it, so I know why I shouldn't post it. – LyricLy Jun 2 '18 at 8:18

# Introduction

I recently came across an oral exam where the candidates were asked to find a logical circuit than can negate 3 inputs A,B,C using only two NOT gates.

The question also specified that such a circuit is unique up to removal of useless gates and reordering inputs/outputs. The candidates were asked to prove this assertion by writing a piece of code that generates all such circuits.

# Challenge

No inputs whatsoever are given.

The program must output all logical circuits using unlimited AND and OR gates but only two NOT gates which take in three inputs which map to three outputs. The outputs should be the negation of each input.

The outputted circuits should not have any redundant/trivial gates (gates that always output the same thing) or unused gates (whose output doesn't influence the outcome).

The program should use as little precalculated data as possible.

Output format is left up to the coders.

The winner will be determined by overall simplicity -- low run time and code elegance. It is not an objective criterion.

# Example Input and Output

Input:

N/A

Output:

R    = (A & B) | (A & C) | (B & C)
notR = !R
S    = (notR & (A | B | C)) | (A & B & C)
notS = !S

notA = (notR & notS) | (notR & S & (B | C)) | (R & notS & (B & C))
notB = (notR & notS) | (notR & S & (A | C)) | (R & notS & (A & C))
notC = (notR & notS) | (notR & S & (A | B)) | (R & notS & (A & B))

• Example output and proof of existence are provided here – John Do Jun 17 '18 at 9:22
• "It is not an objective criterion." Then it is not an on-topic question. – Peter Taylor Jun 19 '18 at 8:49

# Two functions with same input/output, with largest difference in bytes.

This challenge is a terrible idea. Don't try submitting it or anything similar!

Provide two functions with the largest difference in bytes. (These two functions will be referred to in bold italics to distinguish them from built-in functions available in your language in the rules below.)

Rules:

1. Both functions must take an input and must produce an output. The input to and output from both functions must be identical.

2. Both functions must be explicitly named. The function names must have the same byte count.

3. You may not define any other functions.

4. If you use a built-in function your language provides, it must be used with the same number of parameters in each of the functions.

5. You may use string/numeric literals or any built-in constants, but you must use exactly the same ones in both functions.

6. You can define variables, must you must use the same variable names in both functions.

7. You can use comments, no-ops, and the equivalent, but they must be the same in both functions.

8. Both functions must contain the same amount of whitespace (or equivalently, don't count whitespace at all.)

9. You can import libraries/packages and the equivalent, as long as you import the same ones for both functions.

10. You can use pre-processor directives as long as they are the same for both functions.

If any of these rules mean your language cannot compete, so be it.

Not really sure how to tag this. A little bit of and .

• I don't think this is a good idea. {Main downvote} – user202729 Jul 12 '18 at 16:26
• Give up. E.g. in APL, ⊢ and ⊢⊢⊢⊢⊢⊢⊢⊢⊢ do the same. – Adám Jul 12 '18 at 16:26
• @Adám, with those rules, it'd be something like f←⊢ and g←⊢(⊢(⊢(⊢(...)))) due to rules #2 and #3. The same thing still applies to OP: give up! – Zacharý Jul 12 '18 at 16:36
• Thank you. I am happy to give up! – ngm Jul 12 '18 at 16:56
• @Zacharý I intended them to be dyadic, but whatever… – Adám Jul 12 '18 at 17:18
• "Both functions must take an input", which I assume would restrict the functions to monadic. – Zacharý Jul 12 '18 at 17:39