text
stringlengths 180
608k
|
---|
[Question]
[
Consider these 15 ASCII [playing card](http://en.wikipedia.org/wiki/Standard_52-card_deck) patterns (ace through Joker, and the back side), where `X` is a placeholder for the [suit](http://en.wikipedia.org/wiki/Suit_(cards)) symbol: (they look better with less line spacing)
```
------------- ------------- ------------- ------------- ------------- ------------- ------------- ------------- ------------- ------------- ------------- ------------- ------------- ------------- -------------
|AX | |2X | |3X | |4X | |5X | |6X | |7X | |8X | |9X | |10X | |JX | |QX | |KX | |J | |* * * * * * *|
| ------- | | ------- | | ------- | | ------- | | ------- | | ------- | | ------- | | ------- | | ------- | | ------- | | ------- | | ------- | | ------- | |O ------- | | * * * * * * |
| | | | | | | | | | | | | |X X| | | |X X| | | |X X| | | |X X| | | |X X| | | |X X| | | |X X| | | |X | | | |X | | | |X | | |K | | | |* * * * * * *|
| | | | | | X | | | | X | | | | | | | | | | | | | | | | X | | | | X | | | | | | | | X | | | | | | | | | | | | | | |E | J | | | * * * * * * |
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | |X X| | | |X X| | | | | | | | | | | | | | |R | O | | |* * * * * * *|
| | X | | | | | | | | X | | | | | | | | X | | | |X X| | | |X X| | | |X X| | | | X | | | | | | | | J | | | | Q | | | | K | | | | K | | | * * * * * * |
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | |X X| | | |X X| | | | | | | | | | | | | | | | E | J| |* * * * * * *|
| | | | | | X | | | | X | | | | | | | | | | | | | | | | | | | | X | | | | | | | | X | | | | | | | | | | | | | | | | R | O| | * * * * * * |
| | | | | | | | | | | | | |X X| | | |X X| | | |X X| | | |X X| | | |X X| | | |X X| | | |X X| | | | X| | | | X| | | | X| | | | | K| |* * * * * * *|
| ------- | | ------- | | ------- | | ------- | | ------- | | ------- | | ------- | | ------- | | ------- | | ------- | | ------- | | ------- | | ------- | | ------- E| | * * * * * * |
| XA| | X2| | X3| | X4| | X5| | X6| | X7| | X8| | X9| | X10| | XJ| | XQ| | XK| | R| |* * * * * * *|
------------- ------------- ------------- ------------- ------------- ------------- ------------- ------------- ------------- ------------- ------------- ------------- ------------- ------------- -------------
```
Write a program that takes in a string denoting a space separated sequence of cards using...
* `A 2 3 4 5 6 7 8 9 10 J Q K` followed by one of `C D H S` (for clubs, diamonds, hearts, and spades) for the 52 standard cards.
* A single `R` for a Joker.
* A single `B` for the back side (a face down card).
So the string `B AS KH 10C R JD` denotes a face down card, followed by an ace of spades, followed by a king of hearts, followed by a ten of clubs, followed by a Joker, followed by a jack of diamonds.
Your program needs to print the corresponding ASCII playing cards to stdout, replacing`X` with the appropriate suit symbol.
For example, the output for `B AS KH 10C R JD` would be
```
------------- ------------- ------------- ------------- ------------- -------------
|* * * * * * *| |AS | |KH | |10C | |J | |JD |
| * * * * * * | | ------- | | ------- | | ------- | |O ------- | | ------- |
|* * * * * * *| | | | | | |H | | | |C C| | |K | | | | |D | |
| * * * * * * | | | | | | | | | | | C | | |E | J | | | | | |
|* * * * * * *| | | | | | | | | | |C C| | |R | O | | | | | |
| * * * * * * | | | S | | | | K | | | | | | | | K | | | | J | |
|* * * * * * *| | | | | | | | | | |C C| | | | E | J| | | | |
| * * * * * * | | | | | | | | | | | C | | | | R | O| | | | |
|* * * * * * *| | | | | | | H| | | |C C| | | | | K| | | D| |
| * * * * * * | | ------- | | ------- | | ------- | | ------- E| | ------- |
|* * * * * * *| | SA| | HK| | C10| | R| | DJ|
------------- ------------- ------------- ------------- ------------- -------------
```
You can take the input from stdin or write a function that takes a string.
The submission with the shortest number of characters wins.
**Bonus:** Subtract **30** from your character count if you use the black [Unicode suit symbols](http://en.wikipedia.org/wiki/Playing_cards_in_Unicode#Card_suits) `♣ ♦ ♥ ♠` instead of `C D H S` in your output. (The input always uses `C D H S`.)
# Notes
* There may be more than 54 cards in the input string and there may be duplicates of any card.
* There should be no output if the input is the empty string.
* There should be no trailing spaces besides (optionally) the two that make up the right corners of the last card.
* You may assume the input is valid.
* **Update:** The lower right label on standard cards has been reversed so the value is in the corner. The lower right Joker label hasn't changed.
[Answer]
# JavaScript (E6) 542 (572 - bonus 30) ~~553 564 576~~
3 kinds of shapes:
1. Back and Joker: more or less literal
2. JQK: mark at topleft and rightbottom, inner frame and 3 kind of rows inside, always the same structure
3. A...10: mark at topleft and rightbottom, inner frame with 3 kind of rows inside, variable with the numeric value. Taken care of with lookup using array and q variable
The `z` string (compressed) contains the basic building blocks for
* numeric cards - 3 blocks, 7 chars each
* joker - 11 blocks, 13 char each, used simply in sequence
*Bonus note* The code for winning the 30 points bonus is 29 chars.
```
F=c=>(
p='|',b=' ',d=b+b,t=d+b,
S='substr',
z="9J2J4J55O102K |6|1E | J4|1R |1O3|3|2K2|3|3E1| J1|4R | O1|6| K201E55R".replace(/\d/g,n=>n++?b.repeat(n):l='-------'),
i=7,
console.log([c.split(b).map(c=>
m<d
?b+l+l[S](1)+b
:p+(c=='B'
?'* '.repeat(i)[S](i,13)
:c=='R'
?z[S](i,13)
:(
[,h,k]=c.match(/(.+)(.)/),
k='♣♦♥♠'['CDHS'.search(k)], //comment to avoid the unicode symbols
n=h-1|0,
s=t+t+t+(n>8?b:d),
m-7
?m-8
?m-9
?d+p+(h>'A'
?-m?m-6?m-3?t+b+t:t+h+t:t+t+k:k+t+t
:z[S](([64,1028,1092,8194,8258,8322,8326,9350,8802,9766][n]>>m*2&3)*7,7).replace(/J/g,k)
)+p+d
:t+l+t
:s+k+h
:h+k+s
)
)+p
).join(b,i+=13)
for(m of ' 79012345698 ')].join('\n'))
)
```
**Test** In FireFox/FireBug console
```
F('10C JD QH KS AC B R')
F('2C 3D 4H 5S 6C 7D 8H 9S')
```
*Output*
```
------------- ------------- ------------- ------------- ------------- ------------- -------------
|10♣ | |J♦ | |Q♥ | |K♠ | |A♣ | |* * * * * * *| |J |
| ------- | | ------- | | ------- | | ------- | | ------- | | * * * * * * | |O ------- |
| |♣ ♣| | | |♦ | | | |♥ | | | |♠ | | | | | | |* * * * * * *| |K | | |
| | ♣ | | | | | | | | | | | | | | | | | | | * * * * * * | |E | J | |
| |♣ ♣| | | | | | | | | | | | | | | | | | |* * * * * * *| |R | O | |
| | | | | | J | | | | Q | | | | K | | | | ♣ | | | * * * * * * | | | K | |
| |♣ ♣| | | | | | | | | | | | | | | | | | |* * * * * * *| | | E | J|
| | ♣ | | | | | | | | | | | | | | | | | | | * * * * * * | | | R | O|
| |♣ ♣| | | | ♦| | | | ♥| | | | ♠| | | | | | |* * * * * * *| | | | K|
| ------- | | ------- | | ------- | | ------- | | ------- | | * * * * * * | | ------- E|
| ♣10| | ♦J| | ♥Q| | ♠K| | ♣A| |* * * * * * *| | R|
------------- ------------- ------------- ------------- ------------- ------------- -------------
------------- ------------- ------------- ------------- ------------- ------------- ------------- -------------
|2♣ | |3♦ | |4♥ | |5♠ | |6♣ | |7♦ | |8♥ | |9♠ |
| ------- | | ------- | | ------- | | ------- | | ------- | | ------- | | ------- | | ------- |
| | | | | | | | | |♥ ♥| | | |♠ ♠| | | |♣ ♣| | | |♦ ♦| | | |♥ ♥| | | |♠ ♠| |
| | ♣ | | | | ♦ | | | | | | | | | | | | | | | | ♦ | | | | ♥ | | | | | |
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | |♠ ♠| |
| | | | | | ♦ | | | | | | | | ♠ | | | |♣ ♣| | | |♦ ♦| | | |♥ ♥| | | | ♠ | |
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | |♠ ♠| |
| | ♣ | | | | ♦ | | | | | | | | | | | | | | | | | | | | ♥ | | | | | |
| | | | | | | | | |♥ ♥| | | |♠ ♠| | | |♣ ♣| | | |♦ ♦| | | |♥ ♥| | | |♠ ♠| |
| ------- | | ------- | | ------- | | ------- | | ------- | | ------- | | ------- | | ------- |
| ♣2| | ♦3| | ♥4| | ♠5| | ♣6| | ♦7| | ♥8| | ♠9|
------------- ------------- ------------- ------------- ------------- ------------- ------------- -------------
```
**Not golfed code**
```
F=c=>
{
p='|',b=' ',d=b+b,t=d+b;
l='------';
z="9X2X4XJ55O10-2K |6|1E | J4|1R |1O3|3|2K2|3|3E1| J1|4R | O1|6| K20-1E55R".replace(/\d/g,n=>-n?b.repeat(-~n):l);
c=c.split(b);
for(o=i=''; c[0]&&i<13; i++)
{
o+=c.map(c => {
if (i==0 || i==12) r=' -'+l+l+b;
else
{
if (c=='B') r=' *'.repeat(7).substr(i&1,13);
else if (c=='R') r=z.substr(i*13+8,13);
else {
[,h,k]=c.match(/(.+)(.)/),n=h-1|0,
k='♣♦♥♠'[{C:0,D:1,H:2,S:3}[k]],
r=t+t+t+(n>8?b:d);
if(i==1)r=h+k+r;
else if(i==11)r+=k+h;
else if(i==2||i==10)r=t+'-'+l+t;
else {
if (h>'A')
{
if(i==3)r=k+t+t;
else if(i==9)r=t+t+k;
else if(i==6)r=t+h+t;
else r=t+b+t
}
else
{
q=[64,1028,1092,8194,8258,8322,8326,9350,8802,9766][n]>>(i+i-6)&3,
r=z.substr(q*7,7).replace(/X/g,k)
}
r=d+p+r+p+d
}
}
r=p+r+p
}
return r
}).join(' ')+'\n'
}
console.log(o);
}
```
[Answer]
# C# - 906
Rather large and simple C# program that takes command-line input and outputs to standard output. There is probably a lot that can still be golfed, I've spotted a few boring bytes while writing this, but that will have to wait. I don't think I will be going for the Unicode suit character bonus.
Golfed code:
```
class P{static void Main(string[]A){int O,i=0,L,n;for(;i<13;i++){var k="";foreach(var a in A){var R=new char[208];System.Action<int,int,string,int>P=(s,l,g,w)=>{for(O=0;O<l;s+=O%w<1?17-w:1)R[s]=g[O++%g.Length];};P(0,208," ",16);P(1,13,"-",13);P(193,13,"-",13);P(16,11,"|",1);P(30,11,"|",1);if(a=="B")P(17,143,"* ",13);else{P(36,7,"-",7);P(164,7,"-",7);P(51,7,"|",1);P(59,7,"|",1);if(a=="R"){P(17,5,"JOKER",1);P(125,5,"JOKER",1);P(69,25,"J O K E R",5);}else{L=a.Length;var S=a.Substring(L-1);var v=a.Substring(0,L-1);P(17,L,a,L);P(190-L,L,S+v,L);if(int.TryParse(v,out n)){var f=new string[]{S="HEHI",S+"HG",S="EDKDEJKJ",S+"HG",v=S+"EGKG",v+="HE",v+"HI",(S+="EFEHKFKH")+"HG",S+"HEHI",}[n-2];for(O=0;O<f.Length;)R[f[O++]+f[O++]*16-1105]=a[L-1];}else{if(v=="A"){P(103,1,S,1);}else{P(52,1,S,1);P(154,1,S,1);P(103,1,v,1);}}}}for(O=0;O<16;)k+=R[i*16+O++];}System.Console.WriteLine(k.TrimEnd());}}}
```
Example output for `cardGolf.exe 7H QH 3S B R`
```
------------- ------------- ------------- ------------- -------------
|7H | |QH | |3S | |* * * * * * *| |J |
| ------- | | ------- | | ------- | | * * * * * * | |O ------- |
| |H H| | | |H | | | | | | |* * * * * * *| |K | | |
| | H | | | | | | | | S | | | * * * * * * | |E | J | |
| | | | | | | | | | | | |* * * * * * *| |R | O | |
| |H H| | | | Q | | | | S | | | * * * * * * | | | K | |
| | | | | | | | | | | | |* * * * * * *| | | E | J|
| | | | | | | | | | S | | | * * * * * * | | | R | O|
| |H H| | | | H| | | | | | |* * * * * * *| | | | K|
| ------- | | ------- | | ------- | | * * * * * * | | ------- E|
| H7| | HQ| | S3| |* * * * * * *| | R|
------------- ------------- ------------- ------------- -------------
```
Most of the rendering is done by the `P` anonymous method, which takes a position, length, string, and width, and renders a rectangle of the string end on end. For example, the back of the card is just `"* "` repeated. The `T` anonymous method is a modified version of one I used for a previous task, which renders lots of rectangles. It is, however, rather bulky, and would only allow me to render the borders and background in fewer bytes, which probably isn't worth it. A striped down version of `T` is `W` which renders cells rather than rectangles, and also isn't used, but an inlined version of it is used to render cards of value 2 through 10. Note that unused code *was* removed for the byte count, I'm leaving it in because I may end up using it, and I do use them for testing.
The program simply loops through each line of output (13 of them) and then renders each card in turn, and then extracts 1 slice from it, so each card is rendered in it's entirety 13 times. For the purpose of spacing them, each card is treated as a 16 by 13 block, and I trim each line of output to remove trailing spaces (the corner spaces are removed).
Formatted code, with comments and concept/testing code:
```
class P
{
static void Main(string[]A)
{
int O,J,i=0,L,n,r,z;
for(;i<13;i++)
{
var k="";
foreach(var a in A)
{
// got card a and line i
var R=new char[208];
System.Action<int,int,string,int>P=(s,l,g,w)=>
{
for(O=0;O<l;s+=O%w<1?17-w:1)
R[s]=g[O++%g.Length];
};
// not used
System.Action<string>T=f=>
{
f+="AAPM!";
for(J=64;J++<77;)
for(O=64;O++<80;R[z=O+J*16-1105]=f[r]=='!'?R[z]:f[r])
for(r=0;f[r++]>O|f[r++]>J|O>f[r++]|J>f[r++];r++);
};
// not used (derivative below)
System.Action<string>W=f=>
{
for(O=0;O<f.Length;)
R[f[O++]+f[O++]*16-1105]=f[O++];
};
// render
// outer
P(0,208," ",16); // fill
P(1,13,"-",13); // top
P(193,13,"-",13); // bottom
P(16,11,"|",1); // left
P(30,11,"|",1); // left
//T("BBNL BANM-ABOL|AAPM ");
if(a=="B") // back
P(17,143,"* ",13);
else
{
// inner
P(36,7,"-",7); // top
P(164,7,"-",7); // bottom
P(51,7,"|",1); // left
P(59,7,"|",1); // left
//T("EDKJ ECKK-DDLJ|");
// joker
if(a=="R")
{
P(17,5,"JOKER",1);
P(125,5,"JOKER",1);
P(69,25,"J O K E R",5);
//T("FEFEJGFGFOHGHGKIHIHEJIJIR");
}
else
{
L=a.Length;
// card
var S=a.Substring(L-1);
var v=a.Substring(0,L-1);
P(17,L,a,L);
P(190-L,L,S+v,L);
if(int.TryParse(v,out n))
{
// number card
var f=new string[]
{
S="HEHI",
S+"HG",
S="EDKDEJKJ",
S+"HG",
v=S+"EGKG",
v+="HE",
v+"HI",
(S+="EFEHKFKH")+"HG",
S+"HEHI",
}[n-2];
for(O=0;O<f.Length;)
R[f[O++]+f[O++]*16-1105]=a[L-1];
}
else
{
if(v=="A")
{
// ace
P(103,1,S,1);
}
else
{
// face card
P(52,1,S,1);
P(154,1,S,1);
P(103,1,v,1);
}
}
}
}
// write
for(O=0;O<16;)
k+=R[i*16+O++];
}
System.Console.WriteLine(k.TrimEnd());
}
}
}
```
[Answer]
# [PowerShell](https://github.com/TryItOnline/TioSetup/wiki/Powershell), score 442 = (~~509~~ ~~495~~ 472 bytes = (156 script + 316 archive) - 30 bonus)
```
param($s)tar xOf t|%{$l=$_
($s-split'1| '-ne''|%{($l|% s*g(14*('A234567890JQKRB'|% i*f $_[0]))15)-replace'X','♣♦♥♠'[('CDHS'|% i*f $_[1])]})-join' '}
```
[Try it online!](https://tio.run/##3VjdTttKEL73U4zAHCcoafP/c4FUE@jJsS@ikJtIFUJuWBNXxs6xN20PmAfhDqkqD8aLcNZxEjy7zh8JgWKQo2/WO/Z4dr5v1gP3B/H8PrHtR9mEA7h@HBiecZmS/TQ1PPjZMoEGe9eyfSCfScya9Qe2RZV8AErWIYrCxlKyHeyBv3@Rypf2U4paKJbKlWqtntPa@skhuwKsfRPksy@503Q6X05nPTKwjR5RukpGebj99XB7/3D7@@H2TvmSUhpHzU5sSv40fXqTzn5zLUcB5ebxRpJ2oWN8J9AzvHPwhxb1gbpgWjaBDx9NMJxzCB/covDDon24uLIG4QUfPlIpJSmQjR/vAikZSQnULjwdQQGhIkIlhMoIVRCqIlRDqI5QPheDgYbG2gjpCGkQR/sQ@wtGYTHzJEx2wZ@CWngsHtckrGAS9OR/NoreWPfFESxCOnqyxGyJgXTnIFgaLe9l9Tscs7P2NLZmtjaD5mVrSS8n4bm1MFvPfZfd5yzQBT41hNoI6cnovWRrjI7DX227tQUvWFsTFC7G1h/AhLAiYr/6@9GtODpOztb06KoIFRAqIlRCqIxQBaEqQjWE6jHUzefQmIZQGyE9juAkIVvvsSeU0iydHUKzDdehxKFgQvaz6/WIFDbHVz3W1YcmV/o7vKZv2ef/UHLJjLvgDulgSMFyTBeMrwyB4fX6Fmu5feuKhP03JT4bp9KnlCRlUsohqB3Qm5DPNViha0cJ7xQ2jEerEWcSApVtIeL9JOtY2L4CW/I5tuFAFtyDMsy2I3FLtPBRLQh1sxC35o4nRsOxX3iaRhOzRMGw38imJ826f7LMiEaYlICje0UWrmfiZiwbDyyKBvcwibdJjiVaCfFJ@oLo@HFt07FghV8hllXywuntWnlhq21hNGMFRLPug01VDadHy1XN9GBrQOUtv3VkYeGESsIpBDfnXgu2wWjpEZeGHKodQbsJegfUBhzCyRZunkivCVTJUSPb3AsEqwskrCI3oYVPGqbgpAZqfcwtxZa4lGYsc0SfM2n4bl6d8vHqCaU/s5SfjbmIMWXPi3it2/KxYgpP6vn5zR@//ZtB0OhdJRKnvu1YMcVvKa@Y8hfHOiboGUQ/pc6VIh7LwFYqF4sCty1JIPQRgfMy0BakQuctv9TEeONC8RrMHMlEoQHFIyg1odyBSgOqR1BrQr3zCg@UKB0FgfKLgnSUBOkoC9JREfxUBT81wU@d8/Myy3IlPIf3EqUF9153QlHOE6p4gS/hby5NRT7XIS7RQ/RMsxv6dflxdTz7jcDK74PbeayTKOTt7b2bl1gtsPG18noV9Qb4Ji5nBUEWi4IslgRZLAuyWBH8VAU/NcFPPXgL2sTEM/wutgfX0kjByaX7nWRHX75MyB57nuupPWq5DnQsmzjU/i/8fGY5QwK70LOJ4QwH8JWYrkeA9i1/9CVMGvmSfepZzkUGZPJzQHqUnMMByGfRmEf8oU2Z4S/ZnFw5GtkZD@1kyb8705k78VnSjSShB80Anf@sj/8D "PowerShell – Try It Online")
Unrolled:
```
# # the tar archive t should be in default folder
param($s)
tar xOf t|%{ $line=$_
($s-split'1| '-ne''|%{
$pos = 14*('A234567890JQKRB'|% indexOf $_[0])
$x=$line|% SubString $pos 15
$suit = 'CDHS'|% indexOf $_[1]
$x-replace'X','♣♦♥♠'[$suit]
})-join' ' # implicit output
}
```
Powershell script to create the tar archive `t` (see TIO):
```
(
' ------------- ------------- ------------- ------------- ------------- ------------- ------------- ------------- ------------- ------------- ------------- ------------- ------------- ------------- ------------- ',
'|AX |2X |3X |4X |5X |6X |7X |8X |9X |10X |JX |QX |KX |J |* * * * * * *|',
'| ------- | ------- | ------- | ------- | ------- | ------- | ------- | ------- | ------- | ------- | ------- | ------- | ------- |O ------- | * * * * * * |',
'| | | | | | | | | | |X X| | |X X| | |X X| | |X X| | |X X| | |X X| | |X X| | |X | | |X | | |X | |K | | |* * * * * * *|',
'| | | | | X | | | X | | | | | | | | | | | | X | | | X | | | | | | X | | | | | | | | | | |E | J | | * * * * * * |',
'| | | | | | | | | | | | | | | | | | | | | | | | | |X X| | |X X| | | | | | | | | | |R | O | |* * * * * * *|',
'| | X | | | | | | X | | | | | | X | | |X X| | |X X| | |X X| | | X | | | | | | J | | | Q | | | K | | | K | | * * * * * * |',
'| | | | | | | | | | | | | | | | | | | | | | | | | |X X| | |X X| | | | | | | | | | | | E | J|* * * * * * *|',
'| | | | | X | | | X | | | | | | | | | | | | | | | X | | | | | | X | | | | | | | | | | | | R | O| * * * * * * |',
'| | | | | | | | | | |X X| | |X X| | |X X| | |X X| | |X X| | |X X| | |X X| | | X| | | X| | | X| | | | K|* * * * * * *|',
'| ------- | ------- | ------- | ------- | ------- | ------- | ------- | ------- | ------- | ------- | ------- | ------- | ------- | ------- E| * * * * * * |',
'| XA| X2| X3| X4| X5| X6| X7| X8| X9| X10| XJ| XQ| XK| R|* * * * * * *|',
' ------------- ------------- ------------- ------------- ------------- ------------- ------------- ------------- ------------- ------------- ------------- ------------- ------------- ------------- ------------- '
) | Set-Content f -Force
tar zcf t f -o
Get-ChildItem t # output info about archive size
```
]
|
[Question]
[
[Befunge](https://en.wikipedia.org/wiki/Befunge) is a 2-dimensional esoteric programming language. The basic idea is that (one-character) commands are placed on a 2-dimensional grid. Control flow walks across the grid, executing commands it passes over, and changing direction when it hits an arrow (`>^<v`). Commands are stack-based; see [this list](https://en.wikipedia.org/w/index.php?title=Befunge&oldid=510575082#Befunge-93_instruction_list). See also <http://esolangs.org/wiki/Befunge>.
[The specification for Befunge-98](http://catseye.tc/projects/funge98/doc/funge98.html) is available.
# Problem
Write a program that transforms a Befunge program into a more compact representation. For example, the following program prints `0`:
```
> 0 v
> @ .
^ <
```
In this case, it could be compacted without changing the program's behavior by removing rows of spaces, to give
```
>0v
>@.
^ <
```
More sophisticated transformations could rotate or mirror sequences of commands and eliminate unnecessary control-flow commands in order to compact the program. For example, with this program:
```
>12345v
6
v....7<
.
.
.
@
```
you might tuck the end of the program into the hole:
```
>12345v
>...@ 6
^....7<
```
For the first example, the most compact program possible is
```
>0.@
```
You may use any transformations as long as the output program gives the same result.
# Input programs
Input programs are valid Befunge-98 programs.
You may assume that the input program is deterministic. That is, it does not use commands that read external state: the user input commands `&` and `~`, the randomizer `?`, and the self-modifying code commands `p` and `g`.
You may assume the input program terminates.
# Scoring
This is not a code golf, but a problem to write a program that performs code golfing.
The input is a set of test cases (Befunge programs that satisfy the input restrictions above). The total score is the sum of the scores for the test cases.
## Score for each test case
The score is the area of the convex hull of the non-empty cells in the output program, where each cell is treated as a square whose four corners are lattice points in the Cartesian plane. For example, a program of
```
> v
@ <
```
gets a score of 9.5.
If your program does not terminate in a reasonable amount of time and memory on a particular input, the score is that of the input program. (This is because you could trivially add a time-limiting wrapper that outputs the input program unchanged if your program doesn't terminate in time.)
If the test-case program has a different result (or fails to terminate) after processing with your program, the score is the score of the input program plus a penalty of 100 points.
[Answer]
I spent a long plane ride coding this one up. I've written a pseudo befunge compiler which runs the befunge program, extracts basic blocks, and lays them out in a compact representation.
[Link to the program](http://keithandkatie.com/downloads/befunge_py).
When run on this 99 bottles program:
```
92+9* :. v <
>v"bottles of beer on the wall"+910<
,:
^_ $ :.v
>v"bottles of beer"+910<
,:
^_ $ v
>v"Take one down, pass it around"+910<
,:
^_ $ 1-v
:
>v"bottles of beer"+910.:_ v
,:
^_ $ ^
>v" no more beer..."+910<
,:
^_ $$ @
```
It generates the following output:
```
92+9*:.019+"llaw eht no "v
v _v# :"bottles of beer"<
> ,: v
^ _v# <
>$:.019+"reeb f"v
v _ v#:"bottles o"<
> ,: v
^ _ v# <
>$019+"dnuo"v
v"pass it ar"<
>" ,nwod eno"v
v _ v#:"Take "<
> ,:v
^ _ v# <
>$1-:v
v _ v# <
> :.019+"reeb "v
v_ v# :"bottles of"<
> ,v
^_ v# :<
> $019+"llaw"v
v" on the "<
>"reeb fo "v
^ _^# :"bottles"<
>019+"...r"v
v _v#:" no more bee"<
> ,: v
^ _v# <
>$$@
```
It actually isn't much more compact than the source, but it will probably do better on larger/sparser programs.
The program is laid out with a routing area on the left and basic block contents on the right. A basic block is usually laid out in an even number of rows so the entrance and exit adjoin the routing area. At the end of each basic block, the gadget `#^_v` and variants, laid out right-to-left, do the conditional branch and route flow into columns. At the start of each basic block, these columns are routed into the rows for the destination basic block.
In addition, if the output is short it just generates the output explicitly, like this:
```
"output">:#,_@
```
I haven't done anything to optimize the basic blocks themselves, just the layout. Todo.
So where are the tests?
[Answer]
# Sed, 5 chars
So, even if this is not codegolf, here's a solution that will have a rather good codelength to score ratio, but not necessarily a good score.
```
/^$/d
```
It simply removes blank lines.
]
|
[Question]
[
## Background
I was inspired by [3Blue1Brown](https://www.youtube.com/channel/UCYO_jab_esuFRV4b17AJtAw)'s recent [video](https://www.youtube.com/watch?v=FhSFkLhDANA) about the [necklace splitting problem](https://en.wikipedia.org/wiki/Necklace_splitting_problem) (or as he calls it, the stolen necklace problem) and its relationship to the [Borsuk-Ulam theorem](https://en.wikipedia.org/wiki/Borsuk%E2%80%93Ulam_theorem).
In this problem, two thieves have stolen a valuable necklace consisting of several different types of jewels. There are an even number of each type of jewel and the thieves wish to split each jewel type evenly amongst the two of them. The catch is that they must do so by splitting the necklace into some number of contiguous segments and distribute the segments between the two of them.
Here is an example with four jewel types denoted `S`, `E`, `D`, and `R` (for sapphire, emerald, diamond, and ruby, respectively). Let's say the necklace is as follows:
```
[S,S,S,E,S,D,E,R,S,R,E,S,S,S,D,R,E,E,R,E,D,E,R,R,D,E,E,E]
```
There are `8` sapphires, `10` emeralds, `4` diamonds, and `6` rubies. We can split the necklace as follows:
```
[[S],[S],[S,E,S,D,E,R,S],[R,E,S,S,S,D,R,E,E,R,E,D,E],[R,R,D,E,E,E]]
```
Then if we give the first, third, and fifth segments to one thief and the second and fourth segments to the other thief, each will end up with `4` sapphires, `5` emeralds, `2` diamonds, and `3` rubies:
```
[S], [S,E,S,D,E,R,S], [R,R,D,E,E,E]
[S], [R,E,S,S,S,D,R,E,E,R,E,D,E],
```
Using `0`-indexing, these cuts occur at the indices `[1,2,9,22]`.
## Goal
It turns out that such a fair division can always be done using at most `n` cuts, where `n` is the number of jewel types. Your task is to write a complete program or function which takes a necklace as input and outputs a minimal such division (fewest number of cuts).
## Input
Input may be in any convenient format. The necklace should be a sequence of jewels and nothing more; e.g. a list of integers, dictionary with keys representing the jewel types and values being lists of indices. You may optionally include the length of the necklace or the number of distinct jewel types, but you should not take any other input.
You may assume that the input necklace is valid. You do not need to handle the case where there is an odd number of jewels of a given type or the necklace is empty.
## Output
Again, output may be in any convenient format; e.g. a list of segments, a list of cut positions, a dictionary with keys representing the two thieves and values being lists of segments, etc. Segments may be represented by their starting index, ending index, list of consecutive indices, list of jewels, their lengths, etc. You may use `0`- or `1`- indexing. If the ordering is not significant to your format, then your output may be in any order. Here is the above output in several different formats:
```
list of segments: [[S],[S],[S,E,S,D,E,R,S],[R,E,S,S,S,D,R,E,E,R,E,D,E],[R,R,D,E,E,E]]
list of cuts: [1,2,9,22]
list of lengths: [1,1,7,13,6]
dictionary: {'thief1' : [(R,R,D,E,E,E),(S),(S,E,S,D,E,R,S)], 'thief2' : [(S),(R,E,S,S,S,D,R,E,E,R,E,D,E)]}
```
Note that order is important in the list of segments (segments alternate between the thieves) and the list of lengths (in order to identify the segments), but not in the list of cuts or the dictionary. *Edit: Greg Martin pointed out that these wouldn't be valid outputs since a fair division can be obtained in two cuts*
## Test cases
```
[1,2,1,2,1,3,1,3,3,2,2,3] -> [[1,2,1],[2,1,3,1],[3,3,2],[2,3]]
[1,1,1,1,2,2,3,3,3,3,3,3] -> [[1,1],[1,1,2],[2,3,3,3],[3,3,3]]
[1,1,1,1,1,1,1,1,1,1,1,1] -> [[1,1,1,1,1,1],[1,1,1,1,1,1]]
[1,1,1,1,2,3,4,2,3,4,2,2] -> [[1,1],[1,1,2,3,4,2],[3,4,2,2]]
```
## Notes
1. [Standard loopholes](http://meta.codegolf.stackexchange.com/questions/1061/loopholes-that-are-forbidden-by-default) are forbidden.
2. This is [code-golf](/questions/tagged/code-golf "show questions tagged 'code-golf'"); shortest answer (in bytes) wins.
[Answer]
# [Brachylog](https://github.com/JCumin/Brachylog), 13 bytes
```
~c.ġ₂z₁Ċcᵐoᵛ∧
```
[Try it online!](https://tio.run/##SypKTM6ozMlPN/r/vy5Z78jCR01NVY@aGo90JT/cOiH/4dbZjzqW//8fbagDgUY6xjomcNIoFgA "Brachylog – Try It Online")
Note: the metapredicate `ᵛ` is newer than this challenge.
## Explanation
```
~c.ġ₂z₁Ċcᵐoᵛ∧ Input is a list, say L = [1,2,2,2,1,2,3,3]
~c. Output is a partition of the input: [[1,2,2],[2,1,2],[3],[3]]
.ġ₂ Split the output into chunks of length 2: [[[1,2,2],[2,1,2]],[[3],[3]]]
z₁ Zip (transpose) the chunks: [[[1,2,2],[3]],[[2,1,2],[3]]]
Ċ This is a 2-element list (forbid the trivial partition).
cᵐ Concatenate both: [[1,2,2,3],[2,1,2,3]]
oᵛ If you sort both lists, they are equal.
∧ Don't unify with the output.
```
The partitions are enumerated in increasing order of the number of blocks, so the result will have as few blocks as possible.
[Answer]
# [Jelly](https://github.com/DennisMitchell/jelly), 18 [bytes](https://github.com/DennisMitchell/jelly/wiki/Code-page)
```
s2ZFṢ$€E¬,L
ŒṖṖÇÞḢ
```
**[Try it online!](https://tio.run/nexus/jelly#@19sFOX2cOcilUdNa1wPrdHx4To66eHOaUB0uP3wvIc7Fv3//z/aUMdIB4KNwdgYyDbSMY4FAA)**
Not efficient - the example has **28** jewels which wont work without huge resources since this implementation's first step would be to build a list of the **227** possible partitions.
Returns a list of lists - the segments in the order to dish them out between alternate thieves. (Re the TIO output: when a list only has a single item the implicit print does not bother with the brackets, `[]`)
### How?
```
s2ZFṢ$€E¬,L - Link 1, get (isUnfair, Slices): A possible partition
s2 - split into slices of length 2 (any odd one on it's own at the end)
Z - transpose (first item is one thief's slices, second is the others)
$€ - last two links as a monad for €ach
F - flatten
Ṣ - sort
E - equal? (theif1's jewels == theif2's jewels)
¬ - not
L - length (number of slices in the partition)
, - pair
ŒṖṖÇÞḢ - Main link: necklace
ŒṖ - all partitions
Ṗ - pop, we must remove the rightmost one...
because Link 1 will say it is fair, and it will have length 1!
(a list of one thing has all entries equal)
Þ - sort by
Ç - last link (1) as a monad
Ḣ - head (get the first one, i.e. minimal isUnfair, then minimal length)
```
[Answer]
# Mathematica, 118 bytes
Almost beat Jelly ... just 1 off ;)
```
SelectFirst[l_±c_:=Append[-#±Most@c,#2]&@@l~TakeDrop~Last@c;l_±{}:={l};i=#;(i±#)&/@Range@#2~Subsets~#3,Tr[Tr/@#]==0&]&
```
Pure function taking three arguments: the necklace, as a list of tokens such as `{A, A, A, A, B, C, D, B, C, D, B, B}`; the length of the necklace; and the number of distinct jewel times. It returns a list of sublists in the form `{{A, A}, {-A, -A, -B, -C, -D, -B}, {C, D, B, B}}`, where the tokens without negative signs go to one thief and the tokens with negative signs go to the other thief. (While this is redundant information, the algorithm leads to this representation, and removing the negative signs would cost several bytes.)
First we have to implement a function that takes a list and a set of `n` cut-places and returns the list of `n+1` sublists obtained by cutting the input list at those `n` cut-places; the binary infix operator `±` is used for this purpose, and defined recursively through `l_±c_:=Append[-#±Most@c,#2]&@@l~TakeDrop~Last@c;l_±{}:={l};`. Because of the negative sign right after `Append`, the result is that the sublists alternately do and do not have negative signs attached to each token.
Then we generate all possible cut-place sets whose length is at most the number of jewel types, using `Range@#2~Subsets~#3`, and use `i=#;(i±#)&/@` to apply the `±` operator (with the input list of jewels) to each of these cut-place sets in turn.
Finally, `SelectFirst[...,Tr[Tr/@#]==0&]&` picks out the first of the resulting necklace divisions that is fair. It does so by literally adding up all of the elements in all of the sublists; Mathematica is wise enough to cancel the positive and negative copies of each token in the obvious way.
[Answer]
# Pyth, 16 bytes
```
hfqFSMsM.TcT2t./
```
Try it online: [Demonstration](http://pyth.herokuapp.com/?code=hfqFSMsM.TcT2t.%2F&input=%5B1%2C2%2C1%2C2%2C1%2C3%2C1%2C3%2C3%2C2%2C2%2C3%5D&test_suite_input=%5B1%2C2%2C1%2C2%2C1%2C3%2C1%2C3%2C3%2C2%2C2%2C3%5D%0A%5B1%2C1%2C1%2C1%2C2%2C2%2C3%2C3%2C3%2C3%2C3%2C3%5D%0A%5B1%2C1%2C1%2C1%2C1%2C1%2C1%2C1%2C1%2C1%2C1%2C1%5D%0A%5B1%2C1%2C1%2C1%2C2%2C3%2C4%2C2%2C3%2C4%2C2%2C2%5D&debug=0) or [Test Suite](http://pyth.herokuapp.com/?code=hfqFSMsM.TcT2t.%2F&input=%5B1%2C2%2C1%2C2%2C1%2C3%2C1%2C3%2C3%2C2%2C2%2C3%5D&test_suite=1&test_suite_input=%5B1%2C2%2C1%2C2%2C1%2C3%2C1%2C3%2C3%2C2%2C2%2C3%5D%0A%5B1%2C1%2C1%2C1%2C2%2C2%2C3%2C3%2C3%2C3%2C3%2C3%5D%0A%5B1%2C1%2C1%2C1%2C1%2C1%2C1%2C1%2C1%2C1%2C1%2C1%5D%0A%5B1%2C1%2C1%2C1%2C2%2C3%2C4%2C2%2C3%2C4%2C2%2C2%5D&debug=0)
### Explanation:
```
hfqFSMsM.TcT2t./Q implicit Q (=input) at the end
./Q create all partitions of the input list
(they are already sorted by number of cuts)
t remove the partition with zero splits
f filter for partitions T, which satisfy:
cT2 chop into pieces of length 2
.T transpose to get the pieces of each thieve
SMsM combine all pieces for each thieve and sort the results
qF check if they got the same jewels
h print the first such partition
```
[Answer]
# [05AB1E](https://github.com/Adriandmen/05AB1E/wiki/Commands), 14 [bytes](https://github.com/Adriandmen/05AB1E/wiki/Codepage)
```
.œ¨ʒ2ôζε˜{}Ë}¤
```
[Try it online](https://tio.run/##yy9OTMpM/f9f7@jkQytOTTI6vOXctnNbT8@prj3cXXtoyf//0UY6hjrGQAiiLS2BKBYA) or [verify all test cases](https://tio.run/##yy9OTMpM/W/h5ulir6TwqG2SgpL9f72jkw@tODXJ6PCWc9vObT09p7r2cHftoSX/df5HKwUr6cCxKxC7QNkgOggqFqQUyxVtqGOkA8HGYGwMZBvpGINlIBDMR0AkGTSIosdYxwROGkHtMYLaBTHFCG4fSKc5UKUZWIUZEJromOuYxQIA).
**Explanation:**
```
.œ # All partitions of the (implicit) input
# i.e. [2,3,2,1,3,1]
# → [[[2],[3],[2],[1],[3],[1]],[[2],[3],[2],[1],[3,1]],
# ...,[[2,3,2,1,3,1]]]
¨ # Remove the last one
ʒ } # Filter this list by:
2ô # Split it into parts of 2
# i.e. [[2,3],[2],[1],[3,1]] → [[[2,3],[2]],[[1],[3,1]]]
# i.e. [[2,3,2],[1,3],[1]] → [[[2,3,2],[1,3]],[[1]]]
ζ # Swap rows and columns (using space as filler if necessary)
# i.e. [[[2,3],[2]],[[1],[3,1]]] → [[[2,3],[1]],[[2],[3,1]]]
# i.e. [[[2,3,2],[1,3]],[[1]]] → [[[2,3,2],[1]],[[1,3]," "]]
ε } # Map each inner list to:
˜ # Flatten the list
# i.e. [[2,3],[1]] → [2,3,1]
# i.e. [[1,3]," "] → [1,3," "]
{ # Sort the list
# i.e. [2,3,1] → [1,2,3]
# i.e. [1,3," "] → [1,3," "]
Ë # Check if both sorted lists are equal
# (if not, remove them from the partitions)
¤ # After filtering, take the last one as result (and output implicitly)
# i.e. [[[2],[3,2],[1,3],[1]],[[2,3],[2],[1],[3,1]]]
# → [[2,3],[2],[1],[3,1]]
```
]
|
[Question]
[
This question is about [abelian sandpiles](https://en.wikipedia.org/wiki/Abelian_sandpile_model). Read [this previous challenge](https://codegolf.stackexchange.com/questions/92251/build-a-sandpile) and [watch this numberphile video](https://www.youtube.com/watch?v=1MtEUErz7Gg) to learn more.
---
An abelian sandpile of size *n* by *n* is a grid containing the number 0, 1, 2 and 3 (representing the number of grains of sand). Adding two sandpiles works by first adding element by element, and then *toppling* any element that goes above 3. The order in which you topple doesn't matter, the end result is the same. When a cell topples its number decreases by 4, and each of its direct neighbors increases by 1. This can cause a chain reaction. If a cell is on the edge of the grid, any grains that fall off the grid while toppling disappear.
For example, I'm adding two 3 by 3 sandpiles (giving a rather extreme chain reaction):
```
3 3 3 1 2 1 4 5 4 4 6 4 6 2 6 6 3 6 2 5 2 4 1 4 4 2 4 0 4 0 2 0 2 2 1 2
3 3 3 + 2 1 2 = 5 4 5 -> 6 0 6 -> 2 4 2 -> 3 0 3 -> 5 0 5 -> 1 4 1 -> 2 0 2 -> 4 0 4 -> 0 4 0 -> 1 0 1
3 3 3 1 2 1 4 5 4 4 6 4 6 2 6 6 3 6 2 5 2 4 1 4 4 2 4 0 4 0 2 0 2 2 1 2
```
**In this challenge we're interested in a subset of all possible *n* by *n* sandpiles.** This subset contains any sandpile that you can get by adding an arbitrary sandpile to the all-3s *n* by *n* sandpile. For example, just above we saw that `212 | 101 | 212` is in the subset, because we got it by adding something to the all-3 sandpile.
Now this subset has an interesting element: the *identity* element. If you take this element and add it to *any other element in the **subset***, the sum is unchanged. In other words, this sandpile acts like a *zero* of this subset. It just so happens that `212 | 101 | 212` is the zero element for the subset of 3 by 3. For example:
```
2 2 2 2 1 2 4 3 4 0 5 0 2 1 2 2 2 2
2 2 2 + 1 0 1 = 3 2 3 -> 5 2 5 -> 1 6 1 -> 2 2 2
2 2 2 2 1 2 4 3 4 0 5 0 2 1 2 2 2 2
```
Now this is your challenge: **given *n*, find the identity element of the subset of the *n* by *n* grid**. Output it by assigning a unique color with sufficient contrast of your choice to each of `0, 1, 2, 3` and outputting an n by n image. **Your code must be able to produce the 50 by 50 case in under a minute on a reasonable modern PC.**
---
For example, the 500 by 500 identity element:
[](https://i.stack.imgur.com/q8Sqm.png)
Here is blue = 3, green = 2, red = 1, white = 0. But you don't have to use this color scheme in your answer.
[Answer]
# Mathematica, ~~177~~ ~~157~~ ~~135~~ 133 bytes
```
Colorize[f=BlockMap[⌊{l={0,1,0},1-l,l}#/4⌋~Total~2+#[[2,2]]~Mod~4&,#~ArrayPad~1,{3,3},1]&~FixedPoint~#&;k=Table[6,#,#];f[k-f@k]]&
```
Takes a number `n`. The output is the identity sandpile. 0 is black, 1 is light gray, 2 is magenta, and 3 is blue-gray.
Sadly, Mathematica does not have a builtin for this...
Uses the algorithm stated in [Scott Corry and David Perkinson's paper](http://people.reed.edu/%7Edavidp/divisors_and_sandpiles/draft-11.20.2016.pdf).
Takes 91.7 seconds on my 5-year-old laptop to calculate the 50x50 identity sandpile. I am confident that a reasonable modern desktop computer is more than 50% faster. (I also have a way faster code at the end).
**Explanation**
```
f= ...
```
Define function `f` (the input is a sandpile matrix): a function that ...
```
BlockMap[ ... ]~FixedPoint~#&
```
... repeats the `BlockMap` operation until the output does not change. `BlockMap` operation: ...
---
```
#~ArrayPad~1
```
... pad the input array with one layer of 0 ...
```
{3,3},1
```
... partition it into 3x3 matrices, with offset 1 ...
```
⌊{l={0,1,0},1-l,l}#/4⌋~Total~2+#[[2,2]]~Mod~4&
```
... and for each partition, add the number of sand grains toppled onto the center cell and the center cell value mod 4.
i.e. the output of `f` is the stabilized version of the input.
---
```
k=Table[6,#,#]
```
Define `k` as an *n* by *n* array of 6s.
```
f[k-f@k]]
```
Compute f(k - f(k)).
```
Colorize[ ... ]
```
Apply colors to the result.
**Faster version (142 bytes)**
```
Colorize[r=RotateLeft;a=ArrayPad;f=a[b=#~a~1;b+r[g=⌊b/4⌋,s={0,1}]+g~r~-s+r[g,1-s]+r[g,s-1]-4g,-1]&~FixedPoint~#&;k=Table[6,#,#];f[k-f@k]]&
```
Same code, but uses built-in list rotation instead of `BlockMap`. Computes n=50 in 4.0 seconds on my laptop.
[Answer]
# Octave, ~~120~~ 113 bytes
```
function a=W(a);while nnz(b=a>3);a+=conv2(b,[t=[0 1 0];!t;t],'same')-b*4;end;end;@(n)imagesc(W((x=ones(n)*6)-W(x)))
```
Thanks to [JungHwan Min](https://codegolf.stackexchange.com/users/60043/junghwan-min) for providing a link to the reference paper in his Mathematica answer.
Thanks to [Stewie Griffin](https://codegolf.stackexchange.com/users/31516/stewie-griffin) saved me 7 bytes `[any(any(x)) -> nnz(x)]`
Here two function is used:
1.`f`: for stabilization of a matrix
2. An anonymous function that takes `n` as input and shows the identity matrix.
[Try It On rextester!](http://rextester.com/JVF23775) for generation of a 50 \* 50 matrix
Elapsed time for computation of the matrix: `0.0844409 seconds`.
**Explanation:**
Consider a function `f` that stabilizes a matrix the task of finding the identity is simply
`f(ones(n)*6 - f(ones(n)*6)`.
that `ones(n)*6` means a n\*n matrix of 6.
so for `n=3`:
```
M = [6 6 6
6 6 6
6 6 6];
```
The result will be `f(M-f(M))`
For stabilization function 2D convolution used to speed the task;
In each iteration we make a binary matrix `b` with the same size of the input matrix and set it to 1 if corresponding element of the input matrix is >3.
Then we apply a 2D convolution of the binary matrix with the following mask
```
0 1 0
1 0 1
0 1 0
```
representing four direct neighbors .
Result of convolution is added to the matrix and 4 times the binary matrix subtracted from it.
The loop continued until all element of the matrix are <= 3
**Ungolfed version**:
```
function a=stabilize(a)
mask = [t=[0 1 0];!t;t];
while any(any(b=a>3))
a+=conv2(b,mask,'same')-b*4;
end
end
n= 50;
M = ones(n)*6;
result = stabilize(M-stabilize(M));
imagesc(result);
```
[Answer]
# Python 3 + Numpy + PIL, ~~385~~ ~~370~~ 364 bytes
```
import numpy as q,PIL.Image as w
n=int(input())
z=n,n
def r(p):
while len(p[p>3]):
for x,y in q.ndindex(z):
if p[x,y]>3:
p[x,y]-=4;p[x-1,y]+=x>0;p[x,y-1]+=y>0
if~-n>x:p[x+1,y]+=1
if~-n>y:p[x,y+1]+=1
s=q.full(z,6)
t=s.copy()
r(t)
i=s-t
r(i)
w.fromarray(q.uint8(q.array(q.vectorize(lambda x:[x//1*65]*3,otypes=[object])(i).tolist()))).save('i.png')
```
Takes input on STDIN. Outputs the image as greyscale to `i.png`. Black corresponds to 0, dark grey to 1, light grey to 2, and white to 0.
Uses the formula `I = R(S - R(S))`, where `I` is the identity element, `S` is the matrix filled with sixes, and `R` is the reduction function.
I could probably save some bytes by switching to Python 2 and doing `from numpy import*`, but (1) I don't have Numpy installed on Python 2 and (2) the program wasn't terminating with `from numpy import*`.
Ungolfed:
```
import numpy as np
from PIL import Image
# Compute the identity element
n = int(input('Size of the sandpile: '))
def reduce_pile(sandpile):
while any(element >= 4 for element in np.nditer(sandpile)):
for x, y in np.ndindex((n, n)):
if sandpile[x, y] >= 4:
sandpile[x, y] -= 4
if x > 0: sandpile[x - 1, y] += 1
if y > 0: sandpile[x, y - 1] += 1
if x < n - 1: sandpile[x + 1, y] += 1
if y < n - 1: sandpile[x, y + 1] += 1
s = np.full((n, n), 6, dtype=np.int32)
s_prime = np.copy(s)
reduce_pile(s_prime)
identity = s - s_prime
reduce_pile(identity)
# Output it to identity.png as an image
colours = [[255, 255, 255], [255, 0, 0], [0, 255, 0], [0, 0, 255]]
img_array = np.vectorize(lambda x: colours[x], otypes=[object])(identity)
img_array = np.array(img_array.tolist(), dtype=np.uint8)
img = Image.fromarray(img_array)
img.save('identity.png')
```
]
|
[Question]
[
The order of operations, PEMDAS, is a basic rule in mathematics telling us which order operations should be performed:
"Parentheses, Exponents, Multiplication and Division, and Addition and Subtraction"
The problem is, PEMDAS is not very versatile! What if you wanted to do it in another order? We won't mess with the parentheses, so we keep them where they are (first).
Create a program that takes two arguments:
* A string, telling which order the operations should follow. Some examples are `"DAMES"`, `"SAD, ME"`, `"ME SAD"`, `"MEADS"`. Yes, spaces and commas are OK, as it makes the order easier to remember.
+ *Following suggestions in chat: Supporting spaces and commas is now optional.*
+ If one of the letters is missing, or if there are additional letters that shouldn't be there, you can consider the input invalid and treat it however you like.
* A string, or an expression containing the expression that should be evaluated.
Return the result of the expression as either a decimal number, or an integer. If the answer is not an integer, it has to be returned as a decimal number.
Rules:
* It's OK to combine the two input arguments into one, if that's easier in your language.
* It doesn't have to be a string, but it has to have letters. You can't substitute Addition with 1, Division with 2, etc.
* You can choose which input is first.
* The expression is evaluated ~~right to left~~ left to right. (Change of rule. Any submissions poster the first 12 hours that have this the other way around are accepted).
* The operations use the symbols: `( ) ^ * / + -`. For instance, you can't use `¤` instead of `+` for addition.
* **Spaces in the input expression is not valid as input**
* Unary +/- is not valid as input if it directly follows + or -. Consider `3+-2` as invalid input. It can be treated however you like (doesn't have to produce an error). If `+` or `-` follows any other operator than plus or minus, it's treated the usual way: `3*-3 = -9`, `sin(-2)=-0.909`
* The program must strictly follow the letters, so `"EMDAS", 1-3+4 => -6`, and `"EMDSA", 1-3+4 => 2`.
Examples:
```
Input: "EMDAS", "3+6*2/4-1" // -> 3+12/4-1 -> 3+3-1 -> 6-1 -> 5
Output: 5
Input: "DAMES", "3+6*2/4-1" // -> 3+6*0.5-1 -> 9*0.5-1 -> 4.5-1 -> 3.5
Output: 3.5
Input: "SAD, ME", "3+6*2/4-1" // -> 3+6*2/3 -> 9*2/3 -> 9*0.66667 -> 6
Output: 6
Input: "ME ADS", "3+5^4/2-3*2 // -> 3+5^4/2-6 -> 3+625/2-6 -> 628/2-6 -> 314-6 -> 308
Output: 308
Input: "AM EDS", "4*3-sin(0.5^2)*3+1" // -> 4*3-sin(0.5^2)*4 -> 12-sin(0.5^2)*4 -> 4*3-(4*sin(0.5^2)) -> 12-(4*sin(0.5^2)) -> 12-(4*sin(0.25)) -> 12-(4*0.24740) -> 12-0.98961 -> 11.01038
Output: 11.01038
Input: "DAMES", "4-5-6" // -> (4-5)-6 -> = -7
Output: -7 // NOT: -> 4-(5-6) -> 4-(-1) -> 5
```
Note, the parentheses where added to show that the multiplication `4*sin(0.5^2)` is evaluated before the exponentiation.
This is code golf, so the shortest code in bytes win.
[Answer]
# JavaScript (ES6) 349 ~~353 387 400~~
... maybe still golfable
This old parser of mine sometimes comes in handy - (already used in other 2 challenges)
```
E=
(d,x,W=[],Q=['_'],h={'(':1,_:8,')':7},z=1,C=n=>{for(;h[q=Q.pop()]<=h[n];W.push(q=='^'?Math.pow(a,b):eval(`a${q}b`)))a=W.pop(b=W.pop());Q.push(q,n)})=>([...d].map(l=>h[l='+-/*^'['ASDME'.search(l)]]=(d+=!!l),d=1),(x+')').replace(/\D|\d+/g,t=>(u=~~h[t])-1?u-7?u?z&&t=='-'?z=-z:C(t,z=1):(W.push(z*t),z=0):Q.pop(Q.pop(C(t),z=0)):z=!!Q.push('_')),W.pop())
// TEST
console.log=(...x)=>O.innerHTML+=x.join` `+'\n'
console.log(E('MDASE','3+4*5^2'))
console.log(E("EMDAS", "3+6*2/4-1")) // 5
console.log(E("DAMES", "3+6*2/4-1")) //3.5
console.log(E("SAD, ME", "3+6*2/4-1")) // 6
console.log(E("ME ADS", "3+5^4/2-3*2")) // 308
console.log(E("AM EDS", "4*3-sin(0.5^2)*3+1")) // 11.01038 sin not supported
console.log(E("DAMES", "4-5-6")) // -7
// MORE READABLE
U=(d,x,W=[],Q=['_'],h={'(':1,_:8,')':7},z=1,
C=n=>{
for(;h[q=Q.pop()]<=h[n];
W.push(q=='^'?Math.pow(a,b):eval(`a${q}b`)))
a=W.pop(b=W.pop());
Q.push(q,n)
}
)=>(
[...d].map(l=>h[l='+-/*^'['ASDME'.search(l)]]=(d+=!!l),d=1),
(x+')').replace(/\D|\d+/g,t=>
(u=~~h[t])-1
?u-7
?u
?z&&t=='-'?z=-z:C(t,z=1)
:(W.push(z*t),z=0)
:Q.pop(Q.pop(C(t),z=0))
:(Q.push('_'),z=1)
),
W.pop()
)
```
```
<pre id=O></pre>
```
**Ungolfed**
```
Evaluate=(oprec,expr)=>
{
var tokens = expr.match(/\D|\d+/g).concat(')')
var t,a,b,v, SignV
var vstack=[]
var ostack=['_']
var op={ '(':8, _: 1, ')':2}
oprec.match(/\w/g).map((l,p)=>op['+-/*^'['ASDME'.search(l)]]=7-p)
var OPush=o=>ostack.push(o)
var OPop=_=>ostack.pop()
var VPush=v=>vstack.push(v)
var VPop=v=>vstack.pop()
var Scan=i=>
{
SignV = 1
for (; t=tokens[i++]; )
{
if (t == '(')
{
OPush('_')
SignV = 1
}
else if (t == ')')
{
CalcOp(t);
OPop();
OPop();
SignV = 0
}
else if (op[t])
{
if (SignV && t=='-')
SignV = -SignV
else
CalcOp(t), SignV = 1
}
else
{
VPush(SignV*t)
SignV=0
}
}
}
var CalcOp=nop=>
{
for (; op[po = OPop()] >= op[nop];)
b=VPop(), a=VPop(), CalcV(a,b,po);
OPush(po), OPush(nop);
}
var CalcV=(a,b,o)=>
{
// console.log('CV',a,b,o)
if (o=='+')
a+=b
if (o=='-')
a-=b
if (o=='*')
a*=b
if (o=='/')
a/=b
if (o=='^')
a=Math.pow(a,b)
VPush(a)
}
Scan(0)
return VPop()
}
console.log=(...x)=>O.innerHTML+=x.join` `+'\n'
console.log(Evaluate('MDASE','3+4*5^2'))
console.log(Evaluate('EMDAS','3+6*2/4-1')) // 5
console.log(Evaluate("DAMES", "3+6*2/4-1")) //3.5
console.log(Evaluate("SAD, ME", "3+6*2/4-1")) // 6
console.log(Evaluate("ME ADS", "3+5^4/2-3*2")) // 308
console.log(Evaluate("AM EDS", "4*3-sin(0.5^2)*3+1")) // 11.01038 sin not supported
console.log(Evaluate("DAMES", "4-5-6")) // -7
```
```
<pre id=O></pre>
```
[Answer]
# R 3.3.2: 209 196 187 177 bytes
The idea is to "misuse" the non-arithmetic operators <, &, |, ~, ? where we know the precedence (see `?Syntax` in R - but before the override ;)) and overriding them with the given arithmetic operators. The mapping is according to the desired order of operations.
Spaces and commas in the input are **not** supported.
Golfed version
```
f=function(a,b){s=substr;l=list(E='^',M='*',D='/',A='+',S='-');q="<&|~?";for(i in 1:5){x=s(q,i,i);y=l[[s(a,i,i)]];assign(x,.Primitive(y));b=gsub(y,x,b,,,T)};eval(parse(text=b))}
```
Ungolfed and commented:
```
f = function(a,b) {
s = substr
# All arithmetic operators
l = list(E = '^', M = '*', D = '/', A = '+', S = '-')
# Some non-arithmetic R operators in descending precedence
q = "<&|~?"
for (i in 1:5) {
# The substituted symbol
x = s(q, i, i)
# The original operator which has to be substituted
y = l[[s(a, i, i)]]
# Substitute the operator for the R interpreter
assign(x, .Primitive(y))
# Substitute the operator in the input string
b = gsub(y, x, b, , , T)
}
# Parse and evaluate
eval(parse(text = b))
}
```
Examples:
```
> f("EMDAS", "3+6*2/4-1")
[1] 5
> f("DAMES", "3+6*2/4-1")
[1] 3.5
> f("SADME", "3+6*2/4-1")
[1] 6
> f("MEADS", "3+5^4/2-3*2")
[1] 308
> f("AMEDS", "4*3-sin(0.5^2)*3+1")
[1] 11.01038
> f("DAMES", "4-5-6")
[1] -7
```
]
|
[Question]
[
You're given a tree, which in computer science tradition, has the *root* at the top and *leaves* at the bottom. The leaf nodes are labelled with numbers. Your goal is to take the special leaf marked `-1` and move it up to be the new root.
`[3, [[16], -1], [4]] --> [[[[4], 3], [16]]]`

You can imagine rotating the special leaf to the top and letting the rest of tree hang off of it. Keeping the tree in the plane while rotating it to get the correct left-to-right order of all the branches.
The new tree has all the leaves of the original tree except for `-1`.
**Input:**
A tree whose leaves are distinct positive integers, except for one leaf of `-1`. The root of the tree will have at least two branches coming off.
The input is given as a nested list like `[3, [[16], -1], [[4]]]` or its string representation. Delimiters are optional and up to you, but adjacent numbers need to be separated.
**Output:**
Output or print the flipped tree in the same format as your input. The order of the list entries must be correct. In-place modification is fine.
If your input/output is a data type, it must be one that prints in the required format by default. Built-ins that basically do the task for you are not allowed.
**Test cases:**
```
>> [3, [[16], -1], [4]]
[[[[4], 3], [16]]]
>> [2, -1]
[[2]]
>> [44, -1, 12]
[[12, 44]]
>> [[[[-1]]], [[[[4]]]]]
[[[[[[[[[4]]]]]]]]]
>> [[1, 2, 3], [4, -1, 6], [7, 8, 9]]
[[6, [[7, 8, 9], [1, 2, 3]], 4]]
>> [9, [8, [7, [6, -1, 4], 3], 2], 1]
[[4, [3, [2, [1, 9], 8], 7], 6]]
```
[Answer]
# CJam, 24 24 22 bytes
```
l~{):T]{s$}$(+T1+}gW<p
```
[Try it online](http://cjam.aditsu.net/#code=l%7E%7B%29%3AT%5D%7Bs%24%7D%24%28%2BT1%2B%7DgW%3Cp&input=%5B3%20%5B%5B16%5D%20-1%5D%20%5B4%5D%5D).
Thanks Dennis for removing 2 bytes.
### Explanation
```
l~ e# Read the input.
{ e# Do:
):T e# Save the last item to T.
] e# Wrap everything else (as an array) and the last item into an array,
{s$}$ e# where the one with -1 (having "-" if stringified) is the first item.
(+ e# Insert the second array into the first array as the first item,
e# or just move the -1 to the end if the first item is already -1.
T1+ e# Check if the array before this iteration ended with -1.
}g e# Continue the loop if it did't.
W<p e# Remove the -1 and print.
```
[Answer]
# Pyth, ~~26~~ ~~25~~ ~~24~~ 23 bytes
```
L?y.>b1}\-`Jtb.xyahbJ]J
```
[Demonstration.](https://pyth.herokuapp.com/?code=L%3Fy.%3Eb1%7D%5C-%60Jtb.xyahbJ%5DJyQ&input=%5B3%2C+%5B%5B16%5D%2C+-1%5D%2C+%5B%5B4%5D%5D%5D&debug=0) [Test Harness.](https://pyth.herokuapp.com/?code=L%3Fy.%3Eb1%7D%5C-%60Jtb.xyahbJ%5DJFN.zI%26NqhN%5C%3Eyv%3EN3&input=%3E%3E+%5B3%2C+%5B%5B16%5D%2C+-1%5D%2C+%5B%5B4%5D%5D%5D%0A%5B%5B%5B%5B%5B4%5D%5D%2C+3%5D%2C+%5B16%5D%5D%5D%0A%0A%3E%3E+%5B2%2C+-1%5D%0A%5B%5B2%5D%5D%0A%0A%3E%3E+%5B44%2C+-1%2C+12%5D%0A%5B%5B12%2C+44%5D%5D%0A%0A%3E%3E+%5B%5B%5B%5B-1%5D%5D%5D%2C+%5B%5B%5B%5B4%5D%5D%5D%5D%5D%0A%5B%5B%5B%5B%5B%5B%5B%5B%5B4%5D%5D%5D%5D%5D%5D%5D%5D%5D%0A%0A%3E%3E+%5B%5B1%2C+2%2C+3%5D%2C+%5B4%2C+-1%2C+6%5D%2C+%5B7%2C+8%2C+9%5D%5D%0A%5B%5B6%2C+%5B%5B7%2C+8%2C+9%5D%2C+%5B1%2C+2%2C+3%5D%5D%2C+4%5D%5D%0A%0A%3E%3E+%5B9%2C+%5B8%2C+%5B7%2C+%5B6%2C+-1%2C+4%5D%2C+3%5D%2C+2%5D%2C+1%5D%0A%5B%5B4%2C+%5B3%2C+%5B2%2C+%5B1%2C+9%5D%2C+8%5D%2C+7%5D%2C+6%5D%5D&debug=0)
This defines a function, `y`, which takes a nested Pyth list as input.
There are three cases to explore in this recursive function, due to the ternary, `?`, and the try - except function, `.x`. In the function, the input is `b`.
The first case occurs when `}\-`Jtb` is truthy. This tests whether there is a `-` in the string representation of `tb`, the "tail" of `b`, which is all of `b` except its first element. `tb` is also stored in `J`. Since all labels are positive except for `-1`, this will be true if and only if the `-1` is not in the first element of the list.
In this case, we cyclically right shift `b` by 1 with `.>b1`, and then call the function recursively. This ensures that we will progress to the next step with the element containing `-1` as the head (first element) of the list.
In the next two cases, the above is falsy, so `-1` is in the head of the list.
In the second case, `ahbJ` does not throw an error. An error will be thrown if and only if `hb` is an integer. If this is not the case, then `hb` is a list, and we need to rotate the tree so that the `-1` leaf is nearer the root. `ahbJ` accomplishes this by appending `J` as a single element at the end of `hb`, which effectively moves the root of the tree from `b` to `hb`.
In the third and final case, an error is thrown. Thus, `hb` is a single element. Because of the test in the first case, `hb` must be `-1`. Thus, we can return the rest of `b`, namely `J`, wrapped in a list, namely `]J`.
]
|
[Question]
[
Dark black ink has splattered all over your white sheet of printer paper! The obvious solution is to fold the paper so black and white parts meet and both become grey as the ink diffuses. Then unfold and refold until your paper is all equally grey.
Finding the best way to make these folds is your task in this coding challenge. [This Pastebin](http://pastebin.com/uXKseDir) contains four different sized grids of ones and zeros. Each grid represents a piece of ink splattered paper that you must turn grey. Zeros are paper and ones are ink.
In these grids, only horizontal and vertical folds along the spaces between lines and columns are valid. When a fold is made the pairs of overlapping values are averaged. Folds are done one at a time and always unfolded. Folds only change the ink distribution, not the size of the paper.
Rn denotes folding the left edge of the grid to the right, starting after the nth column. Dn denotes folding the top edge of the grid downward fold, starting after the nth row. (n is 1-indexed)
## Example
Given this grid
```
0 1 1 1
0 0 0 0
0 0 0 0
```
a D1 fold means "fold the entire top row down then unfold".
```
0 0.5 0.5 0.5
0 0.5 0.5 0.5
0 0 0 0
```
Then an R2 will produce
```
0.25 0.5 0.5 0.25
0.25 0.5 0.5 0.25
0 0 0 0
```
and another R2 will not change anything.
## Goal
Your goal is to write an algorithm that finds the best ink-spreading folding sequence for each of the four grids using **exactly 8 folds** each time. The folds may be any combination of Rs or Ds.
**Scoring**
The score of your submission is the sum of your scores for each grid. A grid's score is the sum of the absolute differences between each of its values and its average (its sum divided by its area). Lower scores are better. A score of 0 is perfect, but is probably impossible in only 8 folds.
You must report your four 8-step folding sequences with your code in your answer. This is so we can verify your algorithm really works.
Please put them in this form:
```
20*20R1D2R3D4R5D6R7D8
40*20R1D2R3D4R5D6R7D8
40*40R1D2R3D4R5D6R7D8
20*80R1D2R3D4R5D6R7D8
```
[Here](http://ideone.com/5wbrOQ) is a Python script that will calculate your scores given your folding sequences.
Naturally you should not copy someone else's sequence submission. Sequences for each grid only belong to the person who first created them.
# Clarifications
* Ideally your algorithm will work well on any grid, though you can tailor it to these specific ones.
* You must submit your code with your sequence. To win you need the smallest-scoring set of 8-step folding sequences that has not already been posted, and also an algorithm that stands up to public scrutiny. Explain your code, don't obfuscate it.
* The grid should never contain negative numbers.
* Standard loopholes apply.
[Answer]
# Python
Exhaustively tries different combinations of folds for the first few folds, then does the rest of the folds using a greedy approach.
The exhaustive approach is bounded within a reasonable range of folds in the center, such that it won't take forever, while not ignoring too many possible folds to yield a good minimum.
Ran using [pypy](http://pypy.org/) on my macbook air.
Answers:
```
20*20D9R15R6D11R10R9D10R11
40*20D6D13D9R19R21R20D11D10
40*40D21R21R11D19R23R20D23D15
20*80D33D47D40R10D39D41R9R11
```
Outputs:
```
Exhaustive folds levels: 3
Percentage pruned from sides from exhaustive folds: 0.2
Time taken: 4.016076s
Score: 7.91125
20*20D9R15R6D11R10R9D10R11
Exhaustive folds levels: 3
Percentage pruned from sides from exhaustive folds: 0.2
Time taken: 28.529278s
Score: 16.34375
40*20D6D13D9R19R21R20D11D10
Exhaustive folds levels: 3
Percentage pruned from sides from exhaustive folds: 0.25
Time taken: 98.430465s
Score: 42.13
40*40D21R21R11D19R23R20D23D15
Exhaustive folds levels: 3
Percentage pruned from sides from exhaustive folds: 0.25
Time taken: 234.873787s
Score: 32.30875
20*80D33D47D40R10D39D41R9R11
```
Total Score: 7.91125 + 16.34375 + 42.13 + 32.30875 = 98.69375
Code:
```
import time, math
from collections import deque
numberOfFolds = 8 # Total number of folds
startTime = time.clock()
exec "grid = ("+"""
1 1 1 0 1 1 0 0 1 0 0 1 0 1 1 0 1 0 1 1
1 1 0 0 0 1 0 1 1 0 0 0 1 0 1 1 1 0 1 1
0 1 0 0 0 1 0 1 0 1 1 1 1 0 1 0 1 0 1 0
0 0 0 1 0 1 0 0 0 0 1 1 1 0 1 1 0 0 0 1
0 1 0 1 1 0 0 0 0 0 1 0 1 1 1 0 1 0 1 0
1 0 1 1 0 1 1 1 1 1 1 0 0 1 0 1 0 1 0 1
0 1 1 1 0 0 0 1 1 0 1 0 1 1 0 0 0 0 0 0
0 0 0 0 0 0 1 1 1 1 1 0 0 0 1 1 0 0 0 0
1 1 1 0 1 0 0 1 0 1 1 1 1 1 1 0 0 0 0 1
1 1 0 0 0 1 1 1 0 1 0 1 0 0 1 1 0 0 1 0
0 1 1 0 0 0 1 1 0 1 1 1 0 1 1 1 0 1 0 1
0 1 1 1 1 0 0 1 1 0 1 0 1 1 1 1 0 1 1 0
0 0 0 1 0 0 0 1 0 1 0 0 1 0 0 0 1 0 0 1
0 0 1 1 1 1 1 1 0 0 1 1 0 0 1 1 0 0 1 1
1 1 1 1 0 1 1 0 0 0 0 1 1 1 0 0 0 0 0 1
1 0 0 1 0 0 0 0 1 0 0 1 1 0 0 0 0 0 0 0
0 1 1 1 0 0 1 1 0 0 1 1 1 1 0 1 1 0 0 1
0 0 1 0 1 1 1 1 0 1 1 0 1 0 1 0 0 1 1 0
0 1 1 0 1 0 0 1 0 0 1 1 1 1 1 0 1 1 0 0
0 0 1 0 1 1 1 0 0 1 0 0 0 1 0 1 1 1 1 1
""".replace(" ",",").replace("\n","],[")[2:-2]+")"
def getAverage(grid):
count = total = 0
for j in grid:
for i in j:
count += 1
total += i
return total/float(count)
def getScore(grid, average):
score = 0
for j in grid:
for i in j:
score += abs(average-i)
return score
def downFoldedGrid(grid, row, width, height, copy=True):
if copy: grid = [r[:] for r in grid]
foldRange = min(row, height-row)
for j in xrange(foldRange):
rowRef1 = grid[row+j]
rowRef2 = grid[row-1-j]
for i in xrange(width):
rowRef1[i] = rowRef2[i] = (rowRef1[i] + rowRef2[i]) * .5
return grid
def downFoldedScore(grid, score, average, row, width, height):
foldRange = min(row, height-row)
average2 = 2*average
for j in xrange(foldRange):
rowRef1 = grid[row+j]
rowRef2 = grid[row-1-j]
a = b = c = 0
for i in xrange(width):
a = rowRef1[i]
b = rowRef2[i]
c = a+b
score += abs(average2-c) - abs(average-a) - abs(average-b)
return score
def rightFoldedGrid(grid, column, width, height, copy=True):
if copy: grid = [r[:] for r in grid]
foldRange = min(column, width-column)
for j in xrange(height):
rowRef = grid[j]
for i in xrange(foldRange):
a = column+i
b = column-1-i
rowRef[a] = rowRef[b] = (rowRef[a] + rowRef[b]) * .5
return grid
def rightFoldedScore(grid, score, average, column, width, height):
foldRange = min(column, width-column)
average2 = 2*average
for j in xrange(height):
rowRef = grid[j]
a = b = c = 0
for i in xrange(foldRange):
a = rowRef[column+i]
b = rowRef[column-1-i]
c = a+b
score += abs(average2-c) - abs(average-a) - abs(average-b)
return score
def bestFoldsGreedy(grid, average, maxFolds, width, height):
score = getScore(grid, average)
folds = []
append = folds.append
for z in xrange(maxFolds):
bestFold = 0
bestFoldScore = score
bestFoldGrid = grid
for i in xrange(1, width): #Try all right folds
foldScore = rightFoldedScore(grid, score, average, i, width, height)
if foldScore < bestFoldScore:
bestFold = i
bestFoldScore = foldScore
for i in xrange(1, height): #Try all down folds
foldScore = downFoldedScore(grid, score, average, i, width, height)
if foldScore < bestFoldScore:
bestFold = -i
bestFoldScore = foldScore
if bestFold:
append(bestFold)
score = bestFoldScore
if bestFold > 0: rightFoldedGrid(grid, bestFold, width, height, False)
else: downFoldedGrid(grid, -bestFold, width, height, False)
return score, folds
# Get the height and width
height = len(grid)
width = len(grid[0])
# Transpose the grid if height > width for better locality of reference
transposed = False
if height > width:
grid = [[grid[i][j] for i in range(height)] for j in range(width)]
transposed = True
height, width = width, height
# The exhaustive grids and folds attempted
exhaustiveGridsAndFolds = deque([(grid,[])])
popleft = exhaustiveGridsAndFolds.popleft
append = exhaustiveGridsAndFolds.append
# Set the bounds to exhaustively test for
exhaustiveLevels = 3
prunePadding = [0.2, 0.25][width*height > 1000]
leftBound = int(max(width*prunePadding, 1))
rightBound = int(width*(1.0-prunePadding))
topBound = int(max(height*prunePadding, 1))
bottomBound = int(height*(1.0-prunePadding))
# Populate the exhaustive grids and folds
while 1:
grid, folds = popleft()
if len(folds) == exhaustiveLevels:
append((grid, folds))
break
for i in xrange(leftBound, rightBound):
if i not in folds:
append((rightFoldedGrid(grid, i, width, height), folds+[i]))
for i in xrange(topBound, bottomBound):
if -i not in folds:
append((downFoldedGrid(grid, i, width, height), folds+[-i]))
# Test all the exhaustive grids and folds greedily
average = getAverage(grid)
bestFinalScore = getScore(grid, average)
bestFinalFolds = []
numberOfGreedyFolds = numberOfFolds-exhaustiveLevels
while exhaustiveGridsAndFolds:
grid, exhaustiveFolds = popleft()
finalScore, greedyFolds = bestFoldsGreedy(grid, average, numberOfGreedyFolds, width, height)
if finalScore <= bestFinalScore:
bestFinalScore = finalScore
bestFinalFolds = exhaustiveFolds + greedyFolds
# Repeat the last fold till the total number of folds if needed
if len(bestFinalFolds) < numberOfFolds:
bestFinalFolds += [bestFinalFolds[-1]]*(numberOfFolds-len(bestFinalFolds))
# Print the best result
foldsString = ""
down = "D"
right = "R"
if transposed:
down, right = right, down
width, height = height, width
for fold in bestFinalFolds:
if fold > 0: foldsString += right+str(fold)
elif fold < 0: foldsString += down+str(-fold)
print "Exhaustive folds levels: " + str(exhaustiveLevels)
print "Percentage pruned from sides from exhaustive folds: " + str(prunePadding)
print "Time taken: " + str(time.clock()-startTime) + "s"
print "Score: " + str(bestFinalScore)
print str(width) + "*" + str(height) + foldsString
```
[Answer]
# C, 16.344 (4 minutes 33 seconds)
### Best moves found so far: D6,D13,R19,D9,D11,R21,D10,R20
Uses a mixture of Monte Carlo and hill climbing. Could be made to run much faster, I'm sure.
```
#include <stdio.h>
#include <stdlib.h>
/*
Best result so far: 16.344
D6,D13,R19,D9,D11,R21,D10,R20
real 4m33.027s
user 4m12.787s
sys 0m1.334s
*/
#define GRID_WIDTH 40
#define GRID_HEIGHT 20
#define GRID_SIZE (GRID_WIDTH * GRID_HEIGHT)
#define NUM_FOLDS 8
#define MAX_VALUE (1 << NUM_FOLDS)
#define TARGET_VALUE (MAX_VALUE / 2)
double score_grid(short *g) {
int i, sum;
for (i=sum=0; i<GRID_SIZE; i++) sum += abs(*g++ - TARGET_VALUE);
return sum * 1.0 / MAX_VALUE;
}
void h_fold(short *g, int fold_row) {
int x, y0, y1;
if (fold_row<1 || fold_row>=GRID_HEIGHT) return;
y1 = fold_row * GRID_WIDTH;
y0 = y1 - GRID_WIDTH;
while (y0>=0 && y1<GRID_SIZE) {
for (x=0; x<GRID_WIDTH; x++) {
g[y0+x] = g[y1+x] = (g[y0+x] + g[y1+x]) >> 1;
}
y0 -= GRID_WIDTH;
y1 += GRID_WIDTH;
}
}
void v_fold(short *g, int fold_col) {
int y, x0, x1;
if (fold_col<1 || fold_col>=GRID_WIDTH) return;
x1 = fold_col;
x0 = x1 - 1;
while (x0>=0 && x1<GRID_WIDTH) {
for (y=0; y<GRID_SIZE; y+=GRID_WIDTH) {
g[y+x0] = g[y+x1] = (g[y+x0] + g[y+x1]) >> 1;
}
x0--;
x1++;
}
}
void print_grid(short *g) {
int i=0, checksum=0;
while (i<GRID_SIZE) {
checksum += *g;
printf("%3X",*g++);
if ((++i) % GRID_WIDTH == 0) putchar('\n');
}
if (checksum != GRID_SIZE * TARGET_VALUE) printf("Bad total: %d\n",checksum);
}
void init_grid(short *g) {
int i;
static short *start_grid=0, *sg;
if (!start_grid) {
char *src = "11010110100011100000001000110001001101010111000100100100000101100000101111000010"
"10110011111011111101101011111001000010101010110111000101000001011111101000011001"
"10000111111001111011100101101001101100001110001101001011010011011110101000011100"
"00110010100010100010110101001100110001100100111010000110100110001000110000111101"
"01000001110000101000110101011011101010111110101010110000001011010010000011101000"
"11111011111100100100100010111010111111000101011110000100111111111000110101101101"
"00110100010111101111000011011010000110001001101010010101110010110111101001011111"
"10110001101100001110010100110100010011011110100110000100100111101101000010011001"
"00011100110100111101000000001000010100001101001011000101101001000100111100011010"
"00010110001110011111100011101111011100111001110011111011010010000100101111101001";
start_grid = malloc(GRID_SIZE * sizeof(short));
for (i=0; i<GRID_SIZE; i++) start_grid[i] = (src[i]&1)<<NUM_FOLDS;
}
sg = start_grid;
for (i=0; i<GRID_SIZE; i++) *g++ = *sg++;
}
double evaluate(int *moves) {
short *grid;
double score;
int i, f;
grid = malloc(GRID_SIZE * sizeof(short));
init_grid(grid);
for (i=0; i<NUM_FOLDS; i++) {
f = moves[i];
if (f>0) v_fold(grid,f);
else h_fold(grid,-f);
}
score = score_grid(grid);
free(grid);
return score;
}
double optimize_folding(int *moves, double score) {
int opt_cycle, i, which_fold, new_move, f1, f2, t;
double s;
for (opt_cycle=0; opt_cycle<1000; opt_cycle++) {
for (i=0; i<NUM_FOLDS; i++) {
which_fold = random() % NUM_FOLDS;
do {
if (random()&1) new_move = random() % (GRID_WIDTH-1) + 1;
else new_move = -(random() % (GRID_HEIGHT-1) + 1);
} while (moves[which_fold]==new_move);
t = moves[which_fold];
moves[which_fold] = new_move;
s = evaluate(moves);
if (s>score) moves[which_fold] = t;
else score = s;
}
for (i=0; i<NUM_FOLDS; i++) {
f1 = random() % NUM_FOLDS;
do {
f2 = random() % NUM_FOLDS;
} while (f2==f1);
t = moves[f1];
moves[f1] = moves[f2];
moves[f2] = t;
s = evaluate(moves);
if (s>score) {
t = moves[f1];
moves[f1] = moves[f2];
moves[f2] = t;
}
else score = s;
}
}
return score;
}
void show_moves(int *moves) {
int i, m;
for (i=0; i<NUM_FOLDS; i++) {
m = moves[i];
printf("%c%d%c",(m>0)?'R':'D',abs(m),((i+1)%NUM_FOLDS)?',':'\n');
}
}
int main() {
int i, j, moves[NUM_FOLDS], save_moves[NUM_FOLDS];
double score, best_score = 1.0E+99;
srandomdev();
for (i=0; i<400; i++) {
for (j=0; j<NUM_FOLDS; j++) {
if (random()&1) moves[j] = random() % (GRID_WIDTH-1) + 1;
else moves[j] = -(random() % (GRID_HEIGHT-1) + 1);
}
score = optimize_folding(moves, 1.0E+99);
if (score<best_score) {
best_score = score;
for (j=0; j<NUM_FOLDS; j++) save_moves[j]=moves[j];
}
}
printf("%.3lf\n",best_score);
show_moves(save_moves);
return 0;
}
```
]
|
[Question]
[
Write a program in your chosen language which plays a perfect game of tic-tac-toe on a 3 \* 3 board against a human player. However, **every move has to be a different program**, generated from the previous iteration.
How and in what form you evaluate human input, is up to you, but it has to be read from the standard input. Similarly, you are free to choose a method how you will determine which player starts (for example, you ask first, or you allow the human to enter an invalid move to signal that the computer starts, or other ideas).
Validating moves is not necessary, you can assume a fairly playing human opponent.
Basically, you have program which corresponds to a state of the board. The state is printed in any recognizable way, but at least the following level of detail is expected:
```
X..
00X
x..
```
After the human player entered his moves, your program has to generate the next iteration of itself as a source file in the same language (either to standard output or to a file) and terminate. You are not allowed to store information anywhere else outside of that source file. (it is not necessary for your program to build and run the generated program, it can be done by the user - however, it's not forbidden). When the generated program is built and run, it will behave similarly, display the state, wait for user input, etc.
At the end of the game, you have to print the result (whether you won or it's a tie) in any unambiguously identifiable way.
**By perfect play I mean the program must not lose, and if there is a possibility to force a win, it should win.**
**Shortest code wins**, winner is selected at least 10 days after the first valid entry.
You get a 10% reduction in the score if your program can handle the building and launching of its next iteration. (I know, it's most probably not worth it) Of course, the program itself must be terminated by the time the next iteration accepts the moves from the user.
If you use some strange uncommon tricks, please post a short explanation with your code.
[Answer]
## Perl, 933 characters
```
$m=<<'';$_=' ';
sub h{/^(?:...)*(\d)\1\1/|/^.?.?(\d)..\1..\1/|/(\d)...\1...\1/|/^..(\d).\1.\1/&&$1}
sub r{substr($_,$p-1,1)=pop}sub p{my$w=pop;my@b=(0,h==$w||h&&-1);if(!$b[1]&&/ /){$b[1]=-9;
while(/ /g){local($_,$p)=($_,pos);r$w;$r=-(p($w^1))[1];@b=($p,$r)if$r>$b[1]}}@b}
if(($w=h||!/ /)||!@ARGV){$w--&&print+(nobody,X,O)[$w]," wins\n";s/(...)/$1\n/g;
tr/ 23/.XO/;print}else{$w=3;$w^=1for/\d/g;($p=pop)?r($w^1)&&!h&&(($p)=p$w)&&r$w:s/ /2/;
print"\$m=<<'';\$_='$_';\n$m\n$m"}
sub h{/^(?:...)*(\d)\1\1/|/^.?.?(\d)..\1..\1/|/(\d)...\1...\1/|/^..(\d).\1.\1/&&$1}
sub r{substr($_,$p-1,1)=pop}sub p{my$w=pop;my@b=(0,h==$w||h&&-1);if(!$b[1]&&/ /){$b[1]=-9;
while(/ /g){local($_,$p)=($_,pos);r$w;$r=-(p($w^1))[1];@b=($p,$r)if$r>$b[1]}}@b}
if(($w=h||!/ /)||!@ARGV){$w--&&print+(nobody,X,O)[$w]," wins\n";s/(...)/$1\n/g;
tr/ 23/.XO/;print}else{$w=3;$w^=1for/\d/g;($p=pop)?r($w^1)&&!h&&(($p)=p$w)&&r$w:s/ /2/;
print"\$m=<<'';\$_='$_';\n$m\n$m"}
```
Please note that the blank line in the middle of the script is actually required to be there. (The line breaks at the end of the long lines are not required, other than for legibility, and are not included in the character count.)
Usage: When the program is run without arguments, it displays the current game state. Since at the start the board is empty, the output will be:
```
...
...
...
```
Run the program with an argument between 1 and 9 to claim that square as your move. The program will make its own move and then output a replacement script with the new state. Thus, for example:
```
$ perl ./qttt 5 > ./qttt-2
$ perl ./qttt-2
O..
.X.
...
```
On the very first turn only, you may give a move of `0` to indicate that the computer should take the first move. Note that the first player will always be `X`.
When the game is over, the display output will include a note to that effect:
```
$ perl ./qttt-4 6 > ./qttt-5
$ perl ./qttt-5
O wins
OXX
OOX
X.O
```
The program works by doing a standard minimax search of the game tree. (Tic-tac-toe is a small enough game that a full game tree can be generated on every run.) The exception to this is when the computer moves first -- in this case the initial move to the upper left corner is hard-coded.
Note that this program works in the fashion of a proper quine -- at no point does the script access its own source file in order to produce its output.
]
|
[Question]
[
## Background
One kind of river-crossing problems involves two kinds of animals. One such problem reads like this: (all wordings, including animal species, are arbitrary)
>
> A farmer has to cross a river with three chickens and three dogs. There's a boat which can only fit the farmer and at most two animals. On either side of the river, if both kinds of animals are present and the dogs outnumber the chickens at any moment, the dogs will kill the chickens. Also, for some reason, the farmer can't cross the river alone. Can the farmer safely cross the river with all his animals? (For the sake of the puzzle, assume that all animals land on the destination side before the next turn.)
>
>
> Bonus: What if the farmer had four of each kind of animals?
>
>
>
whose answer is
>
> Yes:
>
>
> ```
> üêîüêîüêîüêïüêïüêï | |
> üêïüêï->
> üêîüêîüêîüêï | | üêïüêï
> <-üêï
> üêîüêîüêîüêïüêï | | üêï
> üêïüêï->
> üêîüêîüêî | | üêïüêïüêï
> <-üêï
> üêîüêîüêîüêï | | üêïüêï
> üêîüêî->
> üêîüêï | | üêîüêîüêïüêï
> <-üêîüêï
> üêîüêîüêïüêï | | üêîüêï
> üêîüêî->
> üêïüêï | | üêîüêîüêîüêï
> <-üêï
> üêïüêïüêï | | üêîüêîüêî
> üêïüêï->
> üêï | | üêîüêîüêî üêïüêï
> <-üêï
> üêïüêï | | üêîüêîüêî üêï
> üêïüêï->
> | | üêîüêîüêî üêïüêïüêï
> ```
> Bonus: No.
>
>
>
>
>
One way to solve this puzzle is to construct a grid like this: `O` indicates that the dog-chicken combination is allowed on the initial side (and the rest on the opposite side); `X` means not allowed.
```
üêï\üêî| 0 1 2 3
-----+---------
0 | O X X O
1 | O O X O
2 | O X O O
3 | O X X O
```
Then the problem is about going from (3,3) to (0,0) with alternating forward-backward moves (using NSEW for one step in each cardinal direction):
* Forward: one of N, W, NN, WW, or NW
* Backward: one of S, E, SS, EE, or SE
The solution in the spoiler box follows the path below:
```
(3,3) NN -> (1,3)
S -> (2,3)
NN -> (0,3)
S -> (1,3)
WW -> (1,1)
SE -> (2,2)
WW -> (2,0)
S -> (3,0)
NN -> (1,0)
S -> (2,0)
NN -> (0,0)
```
## Challenge
Given a rectangular grid of valid states as shown above, determine whether the river-crossing puzzle has a solution or not, i.e. a forward-backward alternating path exists between the top left corner and the bottom right corner.
The input has at least two rows and columns, but it may or may not be a square. The O's and X's in the input may be represented using any two distinct constant values (e.g. booleans, numbers, strings). You may assume the start and end corners are both O's.
For output, you can choose to
* output truthy/falsy using your language's convention (swapping is allowed), or
* use two distinct, fixed values to represent true (affirmative) or false (negative) respectively.
Standard [code-golf](/questions/tagged/code-golf "show questions tagged 'code-golf'") rules apply. The shortest code in bytes wins.
## Test cases
The test cases use 1 and 0 for O and X respectively.
### Truthy
```
[[1, 0],
[0, 1]]
[[1, 1, 1],
[1, 1, 1],
[1, 1, 1]]
[[1, 1, 0],
[0, 1, 1]]
[[1, 0, 1, 1, 1, 0, 1],
[1, 1, 1, 0, 1, 1, 1]]
[[1, 1, 1],
[0, 0, 1],
[0, 0, 1]]
[[1, 0, 1, 1, 1],
[1, 0, 0, 0, 1],
[1, 1, 1, 0, 1]]
[[1, 0, 0, 1],
[1, 1, 0, 1],
[1, 0, 1, 1],
[1, 0, 0, 1]]
```
### Falsy
```
[[1, 0, 0],
[0, 0, 1]]
[[1, 0, 1],
[1, 0, 1]]
[[1, 1, 0],
[1, 0, 1]]
[[1, 0, 0, 0, 1],
[1, 1, 0, 0, 1],
[1, 0, 1, 0, 1],
[1, 0, 0, 1, 1],
[1, 0, 0, 0, 1]]
```
Related: [Wolves and Chickens](https://codegolf.stackexchange.com/q/96861/78410) (bonus: can you exploit the strategy to golf the linked challenge further?)
[Answer]
# [Wolfram Language (Mathematica)](https://www.wolfram.com/wolframscript/), 97 bytes
Saved 6 bytes thanks to [@att](https://codegolf.stackexchange.com/users/81203/att).
```
FindPath[Pick[e@@#<->#2,0<=Min[d=#2-#]<Tr@d<3]&@@@#~Tuples~2,1~e~1,Last@#]~FreeQ~{}&@*Position[1]
```
[Try it online!](https://tio.run/##dVCxCsIwFPyVB4EOkmJS17ZkclKo4BYylDbFoFZp4xSSX68Wraakwhsul7t7l1xLfZLXUquqHBrIhq1q6@LF8UJVZy4ZQ2mcowSTNNurltcZSmIk0mPH6nQjIvYSuOPjfpG9SzB10lG8K3vNkHDbTsqDMzZiq@LWK61uLadiKDrVao4gzqHhSAiIYM3AGEMxEIvBEAzUjmBkxhnxAvQkX5/Pf85vwdzrXwaryE8@wTDyE0amCdN901xAZv4gbe78V8MLCH5iuUFQIuhBgiqLL7V2eAI "Wolfram Language (Mathematica) – Try It Online")
[Answer]
# [Charcoal](https://github.com/somebody1234/Charcoal), 88 bytes
```
⊞υ⊖⟦⁰LθL§θ⁰⟧FθF²⊞ι⁰F²⊞θE§θ⁰¦⁰FυF³F³«≔Eι⎇ν⁺μ×§ι⁰⎇⊖νλκ±μη¿∧∨κλ∧›³⁺κλ›§§θ§η¹§η²№υη«⊞υη¬⌈Φην
```
[Try it online!](https://tio.run/##VVFNb4MwDD3Dr/DRkTKpH8ed0KZOk7aOw26IA6IpiUrCGsjUaepvZ04gLUOWYj8/P@eFWla27qp2HHPXS3QcnkVthRZmEAcsVhzehGkGiWd2S7Ph1RzEBc8cVoyVjD2mx84CUSCcGwZBTPn@3IsYzbxXX/8lgszMc7PG9n7@pknW96ox6CdJ9FNYU9kfNBzy1vWoCVJa9DdVNalG3tKRIbzlcGKMkr1oqkGgDoWkKyTqCJiZA35YPBGRYF@9WEE8i9t5YWhRL@Jx78JVTCWHtacu6o2vnzpnBv/ckvnPm0ziHwg3SXKriLHvBrJ9Udpp3KnWbyMJ42eIdE2v41gUxZoM06IpSp4CzNAUd2iKAJXl@PDd/gE "Charcoal – Try It Online") Link is to verbose version of code. Outputs `-` if a solution exists, nothing if not. Explanation:
```
⊞υ⊖⟦⁰LθL§θ⁰⟧
```
Start a breadth-first search with the initial position of the next move from the bottom right corner being a "forward" move.
```
FθF²⊞ι⁰F²⊞θE§θ⁰¦⁰
```
Pad the input with two rows and columns of zeros.
```
FυF³F³«
```
Consider all moves from all positions plus some illegal moves at this point.
```
≔Eι⎇ν⁺μ×§ι⁰⎇⊖νλκ±μη
```
Calculate the resulting position from this move, adjusted for "forward" and "reverse".
```
¿∧∨κλ∧›³⁺κλ›§§θ§η¹§η²№υη«
```
If the move is legal (i.e. one of NN, NW, N, WW or W for "forward" and equivalently for "reverse"), and the resulting position is legal and as yet unknown, then:
```
⊞υη
```
Add the position to the list of known positions.
```
¬⌈Φην
```
Output a `-` if this position is in fact the top left.
[Answer]
# JavaScript (ES6), 112 bytes
Expects a matrix of 0's and 2's, for `'X'` and `'O'` respectively. Returns 0 or 2.
```
f=(m,x=0,y=0,i=1,r=m[y]||0)=>(r[x]--&&[1,2,4,5,8].some(d=>r[x+1]+1||m[y+1]?f(m,x+i*d%4,y+i*(d>>2),-i):1))*++r[x]
```
[Try it online!](https://tio.run/##dVDLboMwELzzFdtIBTsYZFCqVqlMTs0PpDfHBwQmccUjNSQKKv12Cm2jkkCltbze2Zmd9Vt4CstIq0Pl5EUs2zZhKCNnRkndHcU8olnGa9E0FLMAaX4WjmOa3CM@WZAH8iTcssgkilnQYbYnbK9pOkKXrZJeyVbz@H5B6u5GcRD4mDgKLz2M57bdq7Vavh@VlshKSgu7WobxWqVyU@cRotitik2lVb5D2C0PqarQbJtv8xl2k0K/hNEeoZKAwsAC@DAAUllBBgzkKUxRiZ@7kgLG4BFWEBV5WaTSTYsdsrY5X4dpWQsLwxLuFJjmdQN/1cdq3@O9yBDq1sJd8RO3nPsEqCAGcErAF8Iwvkt9fFen8kHTH3UI/L5/Om7YQ3Q8jg4Il3ysetGjl5iYMKTddNBribHiNflfM0ON8adM@xhbGbuhY0PTS4sv "JavaScript (Node.js) – Try It Online")
### Commented
```
f = ( // f is a recursive function taking:
m, // m[] = input matrix
x = 0, y = 0, // (x, y) = current position
i = 1, // i = direction (1 for S/E, -1 for N/W)
r = m[y] || 0 // r[] = current row
) => ( //
r[x]-- // decrement r[x]
&& // abort if it was 0 or undefined
[1, 2, 4, 5, 8] // otherwise, for each value d
.some(d => // in [1, 2, 4, 5, 8]:
r[x + 1] + 1 || // if there's either a cell on our right
m[y + 1] ? // or below us:
f( // do a recursive call:
m, // pass m[]
x + i * d % 4, // update x to x + i * (d mod 4)
y + i * (d >> 2), // update y to y + i * (d >> 2)
-i // invert the direction
) // end of recursive call
: // else (we've reached the bottom-right corner):
1 // success
) // end of some()
) * ++r[x] // restore r[x]
```
]
|
[Question]
[
[OG post](https://codegolf.stackexchange.com/questions/202894/how-happy-is-this-emoticon)
# Task
In this challenge, you will be given an string emoticon, and your task will be to output its happiness.
## How?
An emoticon will always have eyes and mouth. It can also include eyebrows and nose. Each part will influence the overall happiness rating, which is the sum of happiness ratings of all parts. Emoticons may be flipped, reversing the order of parts. Here is the different possible parts and their happiness rating:
```
Symbol Flipped symbol Happiness rating
Eyebrows:
<None> <None> 0
< > -2
[ ] -1
| | 0
] [ 1
> < 2
Eyes:
: : 0
; ; 1
Noses:
^ ^ 0
- - 0
Mouth
< > -3
( ) -2
[ ] -1
| | 0
] [ 1
) ( 2
> < 3
```
## Test cases:
```
In Out
:) 2
<:( -4
|:-| 0
>;^) 5
(; 3
>-:< -1
(:| 2
```
## Rules
1. You must be able to handle flipped emoticons. If the input can be interpreted both ways (for example <:<) you can output either of the possible results
2. Standard loopholes and I/O rules apply.
3. This is code-golf, so shortest code wins.
[Answer]
# [05AB1E](https://github.com/Adriandmen/05AB1E/wiki/Commands), ~~60~~ 59 [bytes](https://github.com/Adriandmen/05AB1E/wiki/Codepage)
```
„:;S¡D€gÆI„()SkàĀ-dUv">)]|"')NXQ×K©.ºDysÃk®g<-X·<*yĀ*}I';åO
```
[Try it online](https://tio.run/##AVsApP9vc2FiaWX//@KAnjo7U8KhROKCrGfDhknigJ4oKVNrw6DEgC1kVXYiPildfCInKU5YUcOXS8KpLsK6RHlzw4Nrwq5nPC1Ywrc8KnnEgCp9SSc7w6VP//8@LTo8) or [verify all test cases](https://tio.run/##yy9OTMpM/V9TVmmvpPCobZKCkn3l/0cN86ysgw8tdHnUtCb9cFslkK@hGZx9eMGRBt2U0DIlO83YGiV1Tb@IwMPTvQ@t1Du0y6Wy@HBz9qF16Ta6EYe222hVHmnQqq1Utz681P@/zn8rTS4bKw2uGivdGi476zhNLg1rLjtdKxsuDasaoAyXlR1Q2I7LxtoGAA).
**Explanation:**
```
„:;S # Push string ":;", and convert it to a list of characters: [":",";"]
¡ # Split the (implicit) input-string on these characters
D # Duplicate the pair
€g # Get the length of each part
Æ # Reduce by subtracting
I # Push the input again
„()S # Push string "()", and convert it to a list of characters: ["(",")"]
k # Get the 0-based index of these characters in the string
# (or -1 if it isn't present)
à # Pop and push the maximum
Ā # Check that this is NOT 0 (0 if 0; 1 if -1, 1, 2, or 3)
- # Subtract the two from one another
d # Check that this is non-negative (>=0)
U # And pop and store this result in variable `X`
# (X=1 for faces where the mouth is left; X=0 for faces where the
# mouth is right or where we couldn't determine mouth/eyebrows)
v # Loop over the parts `y` in the pair we duplicated after the split:
">)]|" # Push string ">)]|"
N # Push the 0-based loop-index
XQ # Check if it's equal to variable `X` (1 if N==X, 0 if N!=X)
') × '# Repeat ")" that many times (")" if N==X, "" if N!=X)
K # Remove that from string ">)]|"
© # Store this string in variable `®` (without popping)
.º # Mirror it with overlap: ">)]|"→">)]|[(<" or ">]|"→">]|[<"
D # Duplicate this mirrored string
y # Push the current part
s # Swap so the copy of the mirrored string is at the top
à # Keep only those characters in the part (removes noses "^"/"-")
k # Get the 0-based index of the character in the mirrored string
®g # Push string `®`, and pop and push its length
< # Decrease it by 1
- # And subtract this from the index
X # Push variable `X`
· # Double it
< # Decrease it by 1
* # And multiply the top two values
# (negates the current value if X==0, or leaves it as is if X==1)
y # Push the current part again
Ā # Check that it's NOT empty (0 if empty; 1 otherwise)
* # And multiply that as well, so empty parts become 0
}I # After the loop, push the input again
';å '# Check if it contains a ";" (1 if truthy; 0 if falsey)
O # And sum all values on the stack
# (after which the result is output implicitly)
```
[Answer]
# JavaScript (ES6), ~~181~~ 176 bytes
```
s=>((/^[()]|[-^][:;]|[:;]$/.test(s)?s=[...s].reverse(q=-1):q=1,[b,e,n,m]=s,n?m?0:e<':'|e>';'?[e,b,m]=s:m=n:[e,m,b]=s,"<[|]>".indexOf(b)-2)%3+q*(e>':')+"<([|])>".indexOf(m)-3)*q
```
[Try it online!](https://tio.run/##ZY5NboMwEEb3PQWyWjGT2CaEdjNgOEIPYIEUEhOlCqZgFHXhu1Na0R@RzWhG73ua7@1wO7jjcHkfhe1OZmrU5FQOEFUasPRaVKWmdF7m8RjJ0bgRHBZOaSmlK@VgbmZwBnolYqRexVzX3HDL21I5bou22JHJQgq9ycM0LLTh9TejVlmar5bXX0mWaV/mTF7syXy8NlCj2ONTsu03MIsU4pZlMEfwX6ZFkeCmn46ddd3VyGt3hgYYIQsCxCCKgmD/sIIZAVugeF5DT8KzxdytYZ5W@ANf1hDSv5/JnSkoW0wR35nk2W/b6RM "JavaScript (Node.js) – Try It Online")
### Commented
```
s => ( // s = smiley string
( //
/^[()]|[-^][:;]|[:;]$/ // the smiley is unambiguously flipped if:
// - it starts with a parenthesis
// - or there's a nose before the eyes
// - or it ends with the eyes
.test(s) ? // if the smiley is flipped:
s = [...s] // reverse s
.reverse(q = -1) // and set q to -1
: // else:
q = 1, // set q to 1
[b, e, n, m] = s, // default order: eyebrows, eyes, nose, mouth
n ? // if s is at least 3 character long:
m ? // if s is 4 character long:
0 // we got it right, so do nothing
: // else (3 characters):
e < ':' | e > ';' ? // if there's a nose:
[e, b, m] = s // new order: eyes, nose, mouth
// but we actually load the nose into the
// eyebrows to invalidate them
: // else:
m = n // the nose is actually the mouth
: // else (2 characters):
[e, m, b] = s, // new order: eyes, mouth
// (and set eyebrows to undefined)
"<[|]>".indexOf(b) - 2 // compute the score for the eyebrows
) % 3 + // turn -3 into 0
q * (e > ':') + // add the score for the eyes
"<([|])>".indexOf(m) - 3 // add the score for the mouth
) * q // multiply the final result by q
```
[Answer]
# [Retina 0.8.2](https://github.com/m-ender/retina/wiki/The-Language/a950ad7d925ec9316e3e2fb2cf5d49fd15d23e3d), 165 bytes
```
$
@
([()].+|..[:;].|.+[:;])@
@$1
T`()><`Ro`@.|.@
T`(<[]>)`Ro`@.+
[[<(]
#$&
T`()<>[];`33221
\d
$*1@
1
@1
+`#@1
#1#
+`#1[^1]*@1|@1[^1]*#1
[^#1]
^(#)?(1#*)*
$#1$*-$#2
```
[Try it online!](https://tio.run/##JYq9CsIwFIX38xo3yk1KA7fd0hDv5i5uMSWCDi4K4ph3r60u5@877/vn8bwuOz7WxUDBmW3xXfM@h6n45rvNrUKN4FzZplhPr6or0a3HXJL9Lx1yjlxAZv97xpTLVMdxGASXG4wThUAFXaVVSWhLkmcpTqXpP5EAeSYpwMxkDyzkrIMhMa43NCxLsIiB0ULfkKbZgiekPkRwaCv5Ag "Retina 0.8.2 – Try It Online") Link includes test cases. Explanation:
```
$
@
```
Append a chin to the face.
```
([()].+|..[:;].|.+[:;])@
@$1
```
If the face seems flipped then prepend the chin instead.
```
T`()><`Ro`@.|.@
```
Switch `()`s and `><`s in the mouth, so that `><`s are scored consistently.
```
T`(<[]>)`Ro`@.+
```
Flip the characters in a flipped face.
```
[[<(]
#$&
```
Mark the unhappy characters.
```
T`()<>[];`33221
```
Get the happiness of each character.
```
\d
$*1@
```
Convert the happiness to unary.
```
1
@1
```
Initially mark the happiness as positive.
```
+`#@1
#1#
```
Propagate negative happiness.
```
+`#1[^1]*@1|@1[^1]*#1
```
Pair happiness and unhappiness and delete both.
```
[^#1]
```
Delete all other characters.
```
^(#)?(1#*)*
$#1$*-$#2
```
Calculate the total happiness.
[Answer]
# [Wolfram Language (Mathematica)](https://www.wolfram.com/wolframscript/), 213 bytes
```
Association[Thread[{""<>#,""<>(Reverse@#/.(Rule@@@Characters@"<>><())([]]["~Partition~2))}&[StringTake[" <[|]>:; ^-<([|])>",List/@{##}+{0,6,8,11}]~StringDelete~" "]->If[#<2,4,#]+#2+#4-9]&@@@Tuples@Range@{6,2,3,7}]
```
[Try it online!](https://tio.run/##JY5fT4MwFMW/CmmTpR3FOVymltrUqA9LfFgYb02XNFgGkYGBzhf@fHUs@HLP/Z3ce3Ku2ubmqm2R6inzXqbXtq3TwnFdySRvjP6SHQCMQzJPFJtf07RGwM0dim@lEUK85brRqXW2cBecIYyRVEqC8agbW8xJY4jxsJIn2xTVJdHfRgKPyV5xGnnngCG3Yg7IZ9HajeggHPzunuzJE9luBzX@v72b0lgzAg@ogB8yCVlIdgQqH4Y@3AXPauW6JLef0rQi1tXFiG5PQvJAHgc1nVJdyaOLsWKdifVHmtdKdIBiQDzAKJqlp0E/K4/Oi42ihQLKFqI9GKLpDw "Wolfram Language (Mathematica) – Try It Online") This is an expression which evaluates to an `Association` object. It takes a string as input and returns an integer as output. The logic is very simple: it generates and rates all possible emoticons, and then it returns the rating for the given emoticon.
[Answer]
# [Jelly](https://github.com/DennisMitchell/jelly), 56 [bytes](https://github.com/DennisMitchell/jelly/wiki/Code-page)
```
O:6ṣ9Ẉ>/ȯḢƲ%5Ḣ
ṚÇ©¡“<[|]>“<([|])>”iⱮ€U2¦o3SḢḟ0_7N®¡+”;e$
```
**[Try it online!](https://tio.run/##y0rNyan8///hjsVGjxrmKGho6sY9apib@Wjjuoc7WuyMuR7unHW4/dDKQwuBsjbRNbF2IFoDyNC0g6p71LQm1OjQsnzj4Ic7Fj3cMd8g3tzv0LpDC7WB8tapKv///7fRtbYBAA "Jelly – Try It Online")** Or see the [test-suite](https://tio.run/##y0rNyan8///hjsVGjxrmKGho6sY9apib@Wjjuoc7WuyMuR7unHW4/dDKQwuBsjbRNbF2IFoDyNC0g6p71LQm1OjQsnzj4Ic7Fj3cMd8g3tzv0LpDC7WB8tapKv8f7t5yuB2oKPL/fytNLhsrDa4aK90aLjvrOE0uDWsuO10rGy4NqxoA "Jelly – Try It Online"). Or see [all the emoticons](https://tio.run/##y0rNyan8/9/fyuzhzsWWD3d12OmfWP9wx6Jjm1RNgRTXw52zDrcfWnlo4aOGOTbRNbF2IFoDyNAEsuZmPtq47lHTmlCjQ8vyjYOB6h/umG8Qb@53aN2hhdpAeetUlf/Wjxr3KSg83NloonO43ZsLqF8BZpCVNYinG4di5tFJBUBTgKY@atxmHapyuB3IjPz/HwA "Jelly – Try It Online").
### How?
This decides whether to reverse the string using the helper link (if the left of the eyes is longer than the right or if the string starts with a `(` or `)`, all using ordinals div six). Then finds the unflipped values of the eyebrows and mouth by indexing into two lists of characters while special-casing a lack of eyebrows and then offsetting the sum. Negates this result if we reversed the string (effectively the same as flipping the characters). Finally adds one to the result if the eyes are winking.
```
ṚÇ©¡“<[|]>“<([|])>”iⱮ€U2¦o3SḢḟ0_7N®¡+”;e$ - Main Link: list of characters, E
¡ - repeat...
Ç - ...number of times: call helper link as f(E)
© - (and copy the result to the register)
Ṛ - ...action: reverse
“<[|]>“<([|])>” - list of lists of characters = ["<[|]>","<([|])>"]
€ - for each (list, p, in that list):
Ɱ - map (across c in E) with:
i - first index (of c) in (p)
U2¦ - reverse the second of the resulting list
o3 - replace 0s (not found) with 3s
(offsetting a lack of eyebrows)
S - sum (e.g. [[2,4],[5,1]] -> [7,5])
Ḣ - head -> the sum of the relevant indices
zero if empty
ḟ0 - filter discard zeros
_7 - subtract 7
¡ - repeat...
® - ...number of times: recall from register
N - ...action: negate
$ - last two links as a monad:
”; - ';' character
e - exists in (E)?
+ - add
- implicit print (the result is a list containing a single integer, which is printed as that integer)
O:6ṣ9Ẉ>/ȯḢƲ%5Ḣ - Link 1, should_reverse?: list of characters, E
O - ordinals
:6 - integer divide by six
ṣ9 - split at nines (':' or ';')
Ʋ - last four links as a monad - f(x):
Ẉ - length of each
/ - reduce by:
> - greater than?
Ḣ - head (x)
ȯ - logical OR (replace a 0 with the list of ordinals of the left part)
%5 - modulo by five - '(' and ')' give 1, others give 0
Ḣ - head
```
]
|
[Question]
[
# Introduction
The [Boids Algorithm](https://en.wikipedia.org/wiki/Boids) is a relatively simple demonstration of emergent behavior in a group. It has three main rules, as described by its creator, Craig Reynolds:
>
> The basic flocking model consists of three simple steering behaviors which describe how an individual boid maneuvers based on the positions and velocities its nearby flockmates:
>
>
> * **Separation**: steer to avoid crowding local flockmates.
> * **Alignment**: steer towards the average heading of local flockmates.
> * **Cohesion**: steer to move toward the average position of local flockmates.
>
>
> Each boid has direct access to the whole scene's geometric description, but flocking requires that it reacts only to flockmates within a certain small neighborhood around itself. The neighborhood is characterized by a distance (measured from the center of the boid) and an *angle*, measured from the boid's direction of flight. Flockmates outside this local neighborhood are ignored. The neighborhood could be considered a model of limited perception (as by fish in murky water) but it is probably more correct to think of it as defining the region in which flockmates influence a boids steering.
>
>
>
I am not perfect when explaining things, so I highly recommend checking out the [source](http://www.red3d.com/cwr/boids/). He also has some super informative pictures on his site.
# Challenge
Given the number of boids (simulated entities) and the number of frames, output an animation of the simulation.
* The boids should be rendered as a red circle, with a line inside of the circle showing its heading, which is the direction the boid is pointing in:
[](https://i.stack.imgur.com/ZLL1Q.png)
* The angle of each boid (as described by Reynolds) should be a full 300 degrees. (not 360)
* The starting heading and position of each boid should be uniformly random (but seeded, so that the output is still determinate), as well as the position.
* If the radius of the boid is 1, than the radius of the neighborhood should be 3.
* The number of boids will be anywhere from 2-20.
* The number of frames will be anywhere from 1-5000
* The animation should be played with a minimum of 10 milliseconds per frame and a maximum of 1 second times the number of boids. (2 boids = 2 seconds per frame max, 3 boids = 3 seconds per frame max, et cetera)
* The output animation should be at least 5 boid-radii by 5 boid-radii, times half the number of boids. So, the minimum size for 2 boids would be 10 boid-radii by 10 boid-radii, the minimum for 3 boids would be 15 boid-radii by 15 boid-radii, et cetera.
* The radius of each boid must be a minimum of 5 pixels and a maximum of 50 pixels.
* The speed of each boid needs to be limited so that it doesn't move more than 1/5th of its radius in one frame.
* The output needs to be determinate, so that the same input will produce the same output if run multiple times.
* If a boid reaches a border, it should wrap back to the other side. Likewise, the neighborhood around each boid should also wrap around the borders.
## Rules for the algorithm
In this case, each boid has a sector around it spanning 300 degrees, centered on the boid's heading. Any other boids in this "neighborhood" are considered "neighbors", or (to use Reynolds' term) "flockmates".
1. Each boid should adjust its heading to avoid collisions and maintain a comfortable distance of one boid-radius with its neighbors. (This is the "Separation" aspect of the algorithm. The one boid-radius may be bypassed, but it should be like a rubber band, snapping back into place.)
2. Each boid should additionally adjust its heading to be closer to the average heading of the other boids in its neighborhood, as long as it doesn't interfere with the first rule. (This is the "Alignment" aspect of the algorithm)
3. Each boid should turn itself towards the average position of its flockmates, as long as this doesn't cause collision or significantly interfere with the second rule.
In [his paper on the subject](http://www.macs.hw.ac.uk/%7Edwcorne/Teaching/Craig%20Reynolds%20Flocks,%20Herds,%20and%20Schools%20A%20Distributed%20Behavioral%20Model.htm), he explains this as follows:
>
> To build a simulated flock, we start with a boid model that supports geometric flight. We add behaviors that correspond to the opposing forces of collision avoidance and the urge to join the flock. Stated briefly as rules, and in order of decreasing precedence, the behaviors that lead to simulated flocking are:
>
>
> * Collision Avoidance: avoid collisions with nearby flockmates
> * Velocity Matching: attempt to match velocity with nearby flockmates
> * Flock Centering: attempt to stay close to nearby flockmates
>
>
>
## More detailed description of movement:
* The standard implementation of the Boids Algorithm usually does a calculation for each of the rules, and merges it together.
* For the first rule, the boid goes through the list of neighboring boids within its neighborhood, and if the distance between itself and the neighbor is less than a certain value, a vector pushing the boid away from is neighbor is applied to the boid's heading.
* For the second rule, the boid calculates the average heading of its neighbors, and adds a small portion (we'll use 1/10 in this challenge) of the difference between its current heading and the average heading to its current heading.
* For the third and final rule, the boid averages the positions of its neighbors, calculates a vector that points towards this location. This vector is multiplied by an even smaller number than what was used for rule 2 (for this challenge, 1/50 will be used) and applied to the heading.
* The boid is then moved in the direction of its heading
[Here](http://www.kfish.org/boids/pseudocode.html) is a helpful pseudocode implementation of the Boids Algorithm.
# Example Input and Output
Input:
>
> 5, 190 (5 boids, 190 frames)
>
>
>
Output:
>
> [](https://i.stack.imgur.com/SmBP2.gif)
>
>
>
# Winning criterion
This is [code-golf](/questions/tagged/code-golf "show questions tagged 'code-golf'"), so the smallest solution in bytes wins.
[Answer]
# [Processing 3.3.6 (Java)](https://processing.org/), ~~932~~ ~~931~~ ~~940~~ ~~928~~ ~~957~~ ~~917~~ 904 bytes
-1 byte from [Jonathan Frech](https://codegolf.stackexchange.com/questions/154277/implement-the-boids-algorithm/154679#comment377504_154679)
+11 bytes to better match the [spec](https://codegolf.stackexchange.com/questions/154277/implement-the-boids-algorithm/154679#comment377565_154679)
-2 bytes from [Kevin Cruijssen](https://codegolf.stackexchange.com/questions/154277/implement-the-boids-algorithm/154679#comment377937_154679)
-12 bytes for changing args to t()
+29 bytes because I was doing ghosting wrong, see commented version below
-40 bytes for using for loops instead of separate calls for each ghost
-13 bytes for using default frameRate, 30
Well, it's a start, for someone who doesn't Java-golf. :)
```
int n=15,f=400,i,j,z=255,w=500;float d=200./n;PVector m;B[]a=new B[n];void setup(){size(500,500);fill(z,0,0);randomSeed(n);for(i=0;i<n;a[i++]=new B(new PVector(random(w),random(w)),m.fromAngle(random(TAU))));}void draw(){background(z);for(B b:a)b.u();if(frameCount%f<1)setup();}class B{PVector p,v,e,q,r;ArrayList<B>n;B(PVector m,PVector o){p=m;v=o;}void u(){e=v.copy();n=new ArrayList();for(B b:a){if(b!=this)for(i=-w;i<=w;i+=w)for(j=-w;j<=w;j+=w)t(i,j,b);}if(n.size()>0){q=new PVector();r=q.copy();for(B b:n){q.add(b.v);r.add(b.p);if(p.dist(b.p)<=d)e.add(p).sub(b.p);}e.add(q.div(n.size()).sub(v).div(10));e.add(r.div(n.size()).sub(p).div(50));}p.add(e.limit(d/10));v=e.mult(10);p.set((p.x+w)%w,(p.y+w)%w);noStroke();ellipse(p.x,p.y,d,d);stroke(0,0,z);line(p.x,p.y,p.x+v.x,p.y+v.y);}void t(int x,int y,B o){m=o.p.copy().add(x,y);if(2*d>=p.dist(m)&q.angleBetween(v,q.sub(m,p))<=5*PI/6)n.add(new B(m,o.v));}}
```
I don't know any reasonable way to do input in Processing, so the first two variables are the inputs (and I didn't count their values (5 bytes) toward the byte count). If this is a problem, I can try other things.
I also don't know of a good way to allow trying it online (the Processing.js project can't deal with this code style) without hosting things myself; and that is something I'm not eager to attempt. Let me know if there is anything clever I can do.
# Formatted code, with comments
```
int n=15, // Number of boids
f=400, // Number of frames
i,j,z=255,w=500; // temp*2, and two constants
float d=200./n; // Boid diameter
PVector m; // temp
B[]a=new B[n];
void setup(){ // This is automatically called at startup
size(500,500); // Can't use variables for this without extra bytes for settings()
fill(z,0,0);
randomSeed(n); // seeded from number of Boids, so that n=19 is very different from n=20
for(i=0;i<n;a[i++]=new B(new PVector(random(w),random(w)),m.fromAngle(random(TAU))));
}
void draw(){ // This is automatically called each frame
background(z);
for(B b:a)
b.u();
if(frameCount%f<1) // When desired frames length is hit, reset everything.
setup(); // Could also use noLoop() instead of setup() to just stop instead.
// Or, remove this if statement altogether to go on to infinity.
}
class B{ // Boid
PVector p,v,e,q,r; // Position, Velocity, Next velocity, and two temp vectors
ArrayList<B>n; // List of neighbors
B(PVector m,PVector o){
p=m;
v=o;
}
void u(){ // Update function, does rules and redraw for this Boid
e=v.copy();
n=new ArrayList();
for(B b:a){ // Test a Boid and its eight ghosts for neighborship
if(b!=this) // Note: Assumes neighborhood diameter < min(width,height)
// The ghosts are to check if it'd be closer to measure by wrapping
// We need eight for wrapping north, east, south, west, northeast,
// northwest, southeast, and southwest. And also the non-wrapped one.
// The above assumption ensures that each ghost is further apart than
// the neighborhood diameter, meaning that only one neighbor might be
// found for each boid. To test this, place a boid in each corner, right
// to the edge, facing away from center. Each boid should find three
// neighbors, that are the three other boids.
for(i=-w;i<=w;i+=w)for(j=-w;j<=w;j+=w)t(i,j,b);
}
if(n.size()>0){
q=new PVector();
r=q.copy();
for(B b:n){
q.add(b.v); // Velocity matching, pt 1
r.add(b.p); // Flock centering, pt 1
if(p.dist(b.p)<=d)
e.add(p).sub(b.p); // Collision avoidance
}
e.add(q.div(n.size()).sub(v).div(10)); // Velocity matching, pt 2
e.add(r.div(n.size()).sub(p).div(50)); // Flock centering, pt 2
}
p.add(e.limit(d/10)); // Update vectors
v=e.mult(10);
p.set((p.x+w)%w,(p.y+w)%w); // Wrapping
noStroke();
ellipse(p.x,p.y,d,d); // Draw Boid, finally
stroke(0,0,z);
line(p.x,p.y,p.x+v.x,p.y+v.y);
}
void t(int x,int y,B o){ // Test if a Boid (or a ghost) is a neighbor
m=o.p.copy().add(x,y);
if(2*d>=p.dist(m)&q.angleBetween(v,q.sub(m,p))<=5*PI/6)
n.add(new B(m,o.v));
}
}
```
## Sample output
n = 15, frames = 400:
[](https://i.stack.imgur.com/maM0U.gif)
[Or, the same animation, but showing the neighborhood of each boid.](https://i.stack.imgur.com/WaEzL.gif)
[Answer]
# JavaScript (ES6) + HTML5, 1200 bytes
Here's my current solution using the Canvas API. The `eval()` returns a curried function whose first input is the `Boid` population, and second is the number of animation frames. You can use `Infinity` for continuous animation.
The `eval(...)` is 1187 bytes and `<canvas id=c>` is 13 bytes, making a total of 1200. The CSS is unnecessary, but for convenience, it allows you to see the edges of the canvas.
```
eval("L7F7{function B8{t=this,t.a=o8*T,t.x=o8*S,t.y=o8*S}C=this.c,D=C.getContext`2d`,({abs:z,random:o,atan2:k,cos:u,sin:g,PI:P,T=2*P,G={c:_7A[r='filter'](b7b!=t)[i](9)79)),n:_7A[r](b7b!=t)[i](9)7({a,x,y:y-S})),s:_7A[r](b7b!=t)[i](9)7({a,x,y:y+S})),e:_7A[r](b7b!=t)[i](9)7({a,x:x-S,y})),w:_7A[r](b7b!=t)[i](9)7({a,x:x+S,y}))},M=I7[I,I+T,I-T][p]((a,x)7z(x)<z(a)?x:a)}=Math),B.prototype={d8{with(D)save8,translate(x,y),rotate(a),beginPath8,arc(0,0,5,0,T),fillStyle='red',fill8,beginPath8,moveTo(0,0),lineTo(10,0),strokeStyle='blue',stroke8,restore8},n:_7(({c,n,s,e,w}=G),c8.concat(n8,s8,e8,w8)[r](b7(d=b.x-x,f=b.y-y,400>d*d+f*f&&z(z(k(f,d)-a)/P-1)>1/6))),s8{q=(j=t.n8).length,v=t.v8||0,l=t.l8||0,f=t.f8||0,a=t.a=(t.a+v+l/10+f/50)%T,t.x=(x+u(a)+S)%S,t.y=(y+g(a)+S)%S},v:_7([d,f]=j[r](b7225>(b.x-x)**2+(b.y-y)**2)[p='reduce'](([d,f],b)7[x+d-b.x,y+f-b.y],[0,0]),d||f?M(k(f,d)-a):0),l:_7j[i](b7M(b.a-a))[p]((a,x)7a+x,0)/q,f:_7([d,f]=j[p](([d,f],b)7[d+b.x,f+b.y],[-x*q,-y*q]),d||f?M(k(f,d)-a):0)},S=C.width=C.height=50*L,A=Array(L).fill().map(_7new B),R=_7{D.clearRect(0,0,S,S),A[i='map'](b79=b).d8),A[i](b79=t=b).s8),F--&&setTimeout(R,10)},R8}".replace(/[789]/g,m=>['=>','()','({a,x,y}'][m-7]))
(10)(Infinity)
```
```
canvas{border:1px solid}
```
```
<canvas id=c>
```
### Edit
As requested, another snippet with an input for Boid population:
```
b.onchange=()=>{eval("L7F7{function B8{t=this,t.a=o8*T,t.x=o8*S,t.y=o8*S}C=this.c,D=C.getContext`2d`,({abs:z,random:o,atan2:k,cos:u,sin:g,PI:P,T=2*P,G={c:_7A[r='filter'](b7b!=t)[i](9)79)),n:_7A[r](b7b!=t)[i](9)7({a,x,y:y-S})),s:_7A[r](b7b!=t)[i](9)7({a,x,y:y+S})),e:_7A[r](b7b!=t)[i](9)7({a,x:x-S,y})),w:_7A[r](b7b!=t)[i](9)7({a,x:x+S,y}))},M=I7[I,I+T,I-T][p]((a,x)7z(x)<z(a)?x:a)}=Math),B.prototype={d8{with(D)save8,translate(x,y),rotate(a),beginPath8,arc(0,0,5,0,T),fillStyle='red',fill8,beginPath8,moveTo(0,0),lineTo(10,0),strokeStyle='blue',stroke8,restore8},n:_7(({c,n,s,e,w}=G),c8.concat(n8,s8,e8,w8)[r](b7(d=b.x-x,f=b.y-y,400>d*d+f*f&&z(z(k(f,d)-a)/P-1)>1/6))),s8{q=(j=t.n8).length,v=t.v8||0,l=t.l8||0,f=t.f8||0,a=t.a=(t.a+v/3+l/10+f/50)%T,t.x=(x+u(a)+S)%S,t.y=(y+g(a)+S)%S},v:_7([d,f]=j[r](b7225>(b.x-x)**2+(b.y-y)**2)[p='reduce'](([d,f],b)7[x+d-b.x,y+f-b.y],[0,0]),d||f?M(k(f,d)-a):0),l:_7j[i](b7M(b.a-a))[p]((a,x)7a+x,0)/q,f:_7([d,f]=j[p](([d,f],b)7[d+b.x,f+b.y],[-x*q,-y*q]),d||f?M(k(f,d)-a):0)},S=C.width=C.height=50*L,A=Array(L).fill().map(_7new B),R=_7{D.clearRect(0,0,S,S),A[i='map'](b79=b).d8),A[i](b79=t=b).s8),F--&&setTimeout(R,10)},R8}".replace(/[789]/g,m=>['=>','()','({a,x,y}'][m-7]))(+b.value)(Infinity);b.remove()}
```
```
input{display:block}canvas{border:1px solid}
```
```
<input id=b><canvas id=c>
```
]
|
[Question]
[
Many people know what a [truth machine](https://esolangs.org/wiki/Truth-machine) in programming is. But is time we kick things up a notch. Introducing, the extended truth machine! An extended truth machine takes two things as input, a integer `n` and a nonempty string `s`. It outputs `s` `n` times with optional trailing whitespace. However, if `n` is equal to `0`, you must output `s` until the program is manually stopped i.e. it should never terminate.
Also, if `n` is a negative number, then the string needs to be reversed. For example with `s=hello` and `n=-1`, output would be `olleh`.
Standard methods of input, any kind of output as long as it can handle infinite. If you have an answer that does not handle infinite, feel free to post it if it is interesting or in a language that cannot handle infinite output.
# Test Cases
```
n, s, output
5, "hello world", "hello worldhello worldhello worldhello worldhello world"
0, "PPCG", "PPCGPPCGPPCGPPCG..."
-2, "truThY", "YhTurtYhTurt"
2000, "o", "oooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo"
```
This is [code-golf](/questions/tagged/code-golf "show questions tagged 'code-golf'"), so shortest code wins!
[Here](https://codegolf.meta.stackexchange.com/a/12065/66833) is the original Sandbox post. Edits have been made to it. Thanks go to @ComradeSparklePony for creating the idea of this challenge
[Answer]
## Haskell, ~~57~~ 54 bytes
```
f 0=cycle
f n|n<0=f(-n).reverse|n>0=concat.replicate n
```
Explanation:
```
f 0 -- If n=0 ..
=cycle -- infinitely repeat the input
f n|n<0 -- Otherwise, if n<0 ..
=f(-n) -- call f with the negative of n ..
.reverse -- and the reverse of the input
|n>0 -- Finally, if n>0 ..
concat -- concatenate the result of ..
.replicate n -- repeating the input n times
```
-3 bytes thanks to @nimi
[Answer]
# PHP>=7.1, 67 Bytes
```
for([,$x,$y]=$argv,$z=$x<=>0;!$z||$x;$x-=$z)echo$x<0?strrev($y):$y;
```
Version with `list(,$x,$y)` instead of `[,$x,$y]`
[Try it online!](https://tio.run/##HYuxCoAgGAb33iL5BgMD5@yvoaG1PRoiKoMgsQiT3t2k4aa7M9qEsjbaJBjtelPPciaYjHRd07JBheWwfN/Oiws4gSejPxTwBFdSJVUK/75wCi4n@Gye9BGNrM/L2vnmcSnwqBA@ "PHP – Try It Online")
[Answer]
# [05AB1E](https://github.com/Adriandmen/05AB1E), ~~17~~ ~~16~~ 14 bytes
```
0‹iR}¹Ä×¹_i[²?
```
[Try it online!](https://tio.run/##ASwA0/8wNWFiMWX//zDigLlpUn3CucOEw5fCuV9pW8KyP///NQpoZWxsbyB3b3JsZA "05AB1E – Try It Online")
**Explanation:**
```
0‹iR}¹Ä×¹_i[²?
0‹ Is the input negative?
iR} If so, reverse the second input.
¹Ä Get the absolute value of the first input.
× Repeat the string that many times.
¹_ Boolean NOT the first input. (Is the first input 0?)
i If so...
[ Do forever...
²? Print the second input without a newline.
```
Saved 2 bytes thanks to @EriktheOutgolfer
[Answer]
# [MATL](https://github.com/lmendo/MATL), 37 bytes
```
jXJiXI0=?`1wtwDw]}I0>?I:"t]x}PI|:"t]x
```
[Try it online!](https://tio.run/##y00syfn/PyvCKzPC08DWPsGwvKTcpTy21tPAzt7TSqkktqI2wLMGzPj/P043jssQAA "MATL – Try It Online")
Explanation:
```
j % input string
XJ % copy to clipboard J
i % input
XI % copy to clipboard I
0 % number literal
= % is equal? (element-wise, singleton expansion)
? % if
` % do...while
1 % number literal
w % swap elements in stack
t % duplicate elements
w % swap elements in stack
D % convert to string and display / string representation
w % swap elements in stack
] % end
} % else
I % paste from clipboard I
0 % number literal
> % is greater than? (element-wise, singleton expansion)
? % if
I % paste from clipboard I
: % range; vector of equally spaced values
" % for
t % duplicate elements
] % end
x % delete
} % else
P % flip the order of elements
I % paste from clipboard I
| % absolute value / norm / determinant
: % range; vector of equally spaced values
" % for
t % duplicate elements
] % end
x % delete
% (implicit) end
% (implicit) end
% (implicit) convert to string and display
```
[Answer]
## Python 3, 71 bytes
```
def f(n,s,k=1):
if n<0:s=s[::-1];n=-n
while n|k:print(end=s);n-=1;k=0
```
[Try it online!](https://tio.run/##BcGxCsMgFAXQPV/xyKSgoGR79k0durqXblEihttQhVDIv5tzjn/fvljGWFOmrGCaqeI1T1Qy4eG4SXszW/8JEIuJzq3siXBVPn4FXSWs0nSAFR@quJGV9c7MMT5fsx43 "Python 3 – Try It Online")
The variable `k` guarantees the loop is always run at least once. This means that if `n=0`, then `n` will be negative on the next iteration of the loop, so the loop will continue to be run forever.
[Answer]
# Matlab, 87 bytes
```
n=input('')
s=input('','s')
a=repmat(s,1,abs(n))
while~n s=[s s]
end
if n<0,flip(a)
end
```
My first attempt at code-golf! Any suggestions for golfing are welcome.
[Answer]
# [Cubix](https://github.com/ETHproductions/cubix), 41 ~~Forty four~~ ~~45~~ bytes
Takes input as *`<N> <String>`*
```
.uq.sB.p$IA;p?;ouu(..!q/o()uq?..@<w?q<<_)
```
[Try it online!](https://tio.run/##Sy5Nyqz4/1@vtFCv2EmvQMXT0brA3jq/tFRDT0@xUD9fQ7O00F5Pz8Gm3L7QxiZe8/9/XSOFkKLSkoxKAA "Cubix – Try It Online")
Cubified:
```
. u q
. s B
. p $
I A ; p ? ; o u u ( . .
! q / o ( ) u q ? . . @
< w ? q < < _ ) . . . .
. . .
. . .
. . .
```
[Watch it running](https://ethproductions.github.io/cubix/?code=ICAgICAgLiB1IHEKICAgICAgLiBzIEIKICAgICAgLiBwICQKSSBBIDsgcCA/IDsgbyB1IHUgKCAuIC4KISBxIC8gbyAoICkgdSBxID8gLiAuIEAKPCB3ID8gcSA8IDwgXyApIC4gLiAuIC4KICAgICAgLiAuIC4KICAgICAgLiAuIC4KICAgICAgLiAuIC4K&input=MiBIZWxsbyBXb3JsZA==&speed=20)
There is still an amount of no-ops in the code which I might be able to get a few more bytes out of, but wanted to get this up before I break it.
Basic procedure is
* `I` get counter from input
* `A` take the rest of input in as characters
* `;p?` remove the space, bring the number up and test it
+ `psuqB$)` if the counter is negative, reverse the stack. This involves handling the input number and EOI marker(-1). Increment the counter.
+ `;p;ouqu` if the counter is zero, remove the counter and EOI marker and start perpetual output loop.
+ `(` if positive decrement the counter
* `<<q?/o()u` the output loop. This will output each character of the stack until the EOI marker (-1) is reached.
* `... _ ... ?wq!` on end EOI marker, go around the cube and reflect back to the `?`, change lane, drop the EOI marker to the bottom and test the counter.
* `@` if zero, halt
* `?u(` if positive u-turn and decrement, thie ends up hitting the beginning of the loop
* `? ... <)` if negative, go around the cube to the otherside, redirect to the beginning of the loop while passing over a increment.
* `/)<` if negative increment and carry on to output loop
[Answer]
# JavaScript (ES6), 79 bytes
```
f=(n,s)=>n<0?f(-n,[...s].reverse().join``):(alert(!n?s:s.repeat(n)),!n&&f(n,s))
```
**Snippet:**
```
f=(n,s)=>n<0?f(-n,[...s].reverse().join``):(alert(!n?s:s.repeat(n)),!n&&f(n,s))
f(5, "hello world")
//f(0, "PPCG") //uncomment this at your peril!!!
f(-2, "truThY")
f(2000, "o")
```
[Answer]
# JavaScript (ES6), ~~98~~ ~~94~~ ~~91~~ 83 bytes
```
n=>s=>{s=n<0?[...s].reverse().join``:s;while(!n)l(s);l(s.repeat(n<0?-n:n))}
```
-4, -5 bytes thanks to Arjun
-3 bytes thanks to Rick Hitchcock
Started out different than the [Java answer](https://codegolf.stackexchange.com/a/124381/65836), but quickly became very similar after golfing. Alert is infinite, but if you want it to look nice, switch to `console.log`. `l=alert;` and writing out `alert` are the same length, but if you switch to `console.log` it's shorter to redefine it.
[Answer]
## [QBIC](https://drive.google.com/drive/folders/0B0R1Jgqp8Gg4cVJCZkRkdEthZDQ), 36 bytes
Lot ging on here, and QBIC/QBasic just doesn't have the syntax to deal with such conditions elegantly.
```
~:<0|;=_fA}[abs(a)|Z=Z+A]~a|_X}{?A';
```
Explanation:
```
~:<0| IF cmd line arg 'a' is negative
;=_fA Make cmd line arg A$ into its reverse
} Close the IF (this eliminates the need for a | fuction terminator on _f)
[abs(a)| FOR b = 1 to (abs(a) (hammering out negatives)
Z=Z+A Add A$ to Z$ (on exit, Z$ is printed explicitly)
] NEXT
~a|_X IF a is non-zero, terminate the program
} END IF
{?A'; If we're here, just start a DO-loop and keep on printing the input.
```
[Answer]
# [Java (OpenJDK 8)](http://openjdk.java.net/), 137 bytes
```
void f(String[] a){for(long n=Long.valueOf(a[0]),i=0;n==0|i++<Math.abs(n);)System.out.print(n<0?new StringBuilder(a[1]).reverse():a[1]);}
```
[Try it online!](https://tio.run/##TY8xb8IwEIV3fsWNtmitMHQhREidQQyMKMNBLsGpOUe2E4TS/HZjUoa@5en0pE/ftTjgp@2I2@ondv3Z6AtcDHoPe9QMYxysrqAWx@A0N6cSUI61dcJYboCLXSo1oOnpUAs8ZaX80EWWc1Fkv3q53OwxXBWevWCZy@PDB7op2wfVJVoQvMm2THf4g3/32lTkEmZVSuVoIOdJyPV851OElLehDxhSzW635PlfD8YFvPNiv94QUiU713iZz9u0mGL8ilcyxsLdOlM9AQ "Java (OpenJDK 8) – Try It Online")
[Answer]
# [str](https://github.com/ConorOBrien-Foxx/str), 30 bytes
```
I#Lbd0<[_u_][d0='e'u#?]#?xo;db
```
[Try it online!](https://tio.run/##Ky4p@v/fU9knKcXAJjq@ND42OsXAVj1VvVTZPlbZviLfOiXp/39dIwWP1JycfB2u8PyinBRFAA "str – Try It Online")
## Explanation
```
I#Lbd0<[_u_][d0='e'u#?]#?xo;db
...........................; preamble
I read number
#L read rest of STDIN
b buffer the STDIN
d duplicate number
0<[ ] #? if the number is less than zero
_ negate that number
u_ and reverse STDIN from buffer
[ ] otherwise
d0='e #? if its 0, push the empty string
'u otherwise, push the unbuffered STDIN untouched
x repeat STDIN by the TOS
o and output
;.. main program (only activates when input = 0)
d duplicate the implicitly unbuffered STDIN
b and rebuffer it
implicitly displayed
```
[Answer]
# [C (gcc)](https://gcc.gnu.org/), ~~115~~ ~~112~~ ~~109~~ ~~107~~ 104 bytes
```
f(n,s,l,p,d)char*s;{d=n<0?-1:1;do for(l=1,p=0;p>=0;p+=l)s[p]?d==l&&putchar(s[p]):l--;while(!n||(n-=d));}
```
[Try it online!](https://tio.run/##VY6xbsIwEIb3PMWVSmAXW3KidolrMiDBytClKgwoThpLV9tKQhlCnj21UVvBDTd8n/7/ruSfZTlNNbGsY8g807Rsju1TJwet7KsoeJqnUjuoXUtQpcwrIf0qrqVC2n34Q6GVwvncn/qYJBHRHDmX58ZgRR7s5UIsV5pSOU6PuqqNrWATD1IIxQPsE/id8EZh8@csKHmD/6oXe7u4ihGu3UAETRJje/g6Gku@ndEUhv/YhrwwmDUVooOza1HPqLyRIsjdbr29pzwLuG9Pb837vciEiAkX6Tj9AA "C (gcc) – Try It Online")
>
> Who said, we need `strlen`?
>
>
>
## [C (gcc)](https://gcc.gnu.org/), 115 bytes (134 with `#include<string.h>` in front)
```
#include<string.h>
f(n,s)char*s;{int l=strlen(s),d=n<0?0:2,m=d--,p;do for(p=m?0:l-1;p!=(m?l:-1);p+=d)putchar(s[p]);while(!n||(n-=d));}
```
[Try it online!](https://tio.run/##VY49b8IwFEX3/IoHDNhtXJmoXWLcDJXoytClKgwodogl59nKRxlCfnvqRG0FbzxH976bs3Oej@PKYG47pbdNWxs8P5WvUUEwbmhenuqHRvQGW7AyWKuRNDRWErc842kSV1IxFnuhHBSuJl5WAVu2EX4hSZXZlG2o8I9SUd@1Ux1pvvyRiktprCYLvF4JsmCpGMaV0oVBDbv5N4TKHg4R/F5YlGH6nAQlbvBf7fqA61kMMHcD4TSKpuHVySD5dkZR6P9jO/ISw7LU1jq4uNqqJRU3kge537@931OWBNzW3Uf5eS8SzqeEm@gw/gA "C (gcc) – Try It Online")
>
> Without `#include<string.h>` we get an implicit prototype for `strlen` that returns `int`, but `strlen` is `size_t` (at least nowadays, not perfectly sure about k&r or c89, but I believe, it returned `int` in the old days).
>
>
> The missing `#include <stdio.h>` isn't a problem, because due to integer promotion, the default prototype will be `int putchar(int)` which is exactly what we want.
>
>
>
[Answer]
# [Retina](https://github.com/m-ender/retina/wiki/The-Language), 49 bytes
```
/¶-/&V`^.+
/¶0/&//+>G0`
~`(.+)¶-*(\d+)
.-$2+>K`$1
```
Input format: takes in the string, followed by a newline, followed by the number.
[Try it online!](https://tio.run/##K0otycxLNPz/X//QNl19tbCEOD1tLiDbQF9NX1/bzt0ggasuQUNPWxMoraURk6KtyaWnq2KkbeedoALUlc9lZGBgAAA "Retina – Try It Online")
**Explanation:**
```
/¶-/&V`^.+
```
The `/¶-/&` runs this line only if the number is negative. `V` is the reverse stage, and it reverses `^.+`, which matches the string (`.` matches every character apart from newlines).
```
/¶0/&//+>G0`
```
The `/¶0/&` runs this line only if the number is 0. `//+>` starts an infinite loop, which prints the working string after each iteration. `G0` takes the string and discards the number; it does this infinitely, printing every time.
```
~`...
```
This marks code that will generate a string; the program evaluates the string as Retina code after.
```
(.+)¶-*(\d+)
.-$2+>K`$1
```
`(.+)¶-*(\d+)` matches the whole string and puts the string in capturing group 1 and the number in capturing group 2. `.-$2+>K`` `$1` generates the Retina code to be run: `.` turns implicit output off (otherwise the string would be printed n+1 times), `-$2+` sets a repeat loop that repeats for {capturing group 2} times. The minus at the beginning turns the number into a negative number, as this disables the convergence functionality in the loop, which would stop it after the 1st iteration. `>` sets this loop to print after each iteration. The rest of the code is just to print the string.
[Answer]
# [Perl 6](https://github.com/nxadm/rakudo-pkg), 44 bytes
```
{[$^s.flip,$s,$s Zxx-$^n,Inf,$n][$n.sign+1]}
```
[Try it online!](https://tio.run/##K0gtyjH7n1upoJamYPu/OlolrlgvLSezQEelGIgUoioqdFXi8nQ889J0VPJio1Xy9Ioz0/O0DWNr/xcnViqkaZjqKGWk5uTkK5TnF@WkKGlac0HEDXSUAgKc3RECukY6SiVFpSEZlQgxIwMDoLp8oMB/AA "Perl 6 – Try It Online")
Anonymous code block that takes a number and a string and returns a (possibly infinite) list
[Answer]
# [Pip](https://github.com/dloscutoff/pip), 16 bytes
```
TaOba<0?RbbX:ABa
```
[Replit!](https://replit.com/@dloscutoff/pip) Or, here's a 17-byte equivalent in Pip Classic: [Try it online!](https://tio.run/##K8gs@P8/JNE/KdHGwD4oLCkpwsrRKfH///@m/z1Sc3LyFQE "Pip – Try It Online")
### Explanation
```
TaOba<0?RbbX:ABa
a and b are the two command-line arguments
Ta Loop until a is truthy:
Ob Output b without a newline
If a=0, this loops infinitely; otherwise, it doesn't loop at all
a<0? If a is negative:
Rb b reversed
Else (if a is positive):
b b
X: Repeat that string this many times:
ABa Absolute value of a
```
]
|
[Question]
[
I recently got a really weird irregular chess board. It's squares are all over the place and not even all connected. At least they're still laid out on a regular grid. I want to adapt the chess rules to be able to play on the board, but to start with, I need a piece that can actually go anywhere on the board, and it seems a leaper is my best bet for that.
[Leapers](https://en.wikipedia.org/wiki/Fairy_chess_piece#Leapers) are the fairy chess generalisation of knights. Leapers are parameterised by two integers **m** and **n** and can move **m** squares in one direction and then another **n** squares in either perpendicular direction. For the standard knight, we have **(m, n) = (2, 1)**. The entire move is considered a single jump such that none of the squares on the way to the target need to be empty or even exist.
## The Challenge
You're given a "chess board" in the form of a list of positive 2D integer coordinates which represent the squares that are part of the board. Your task is to find a leaper which, given enough moves, can reach any square on the board.
Let's look at some examples. The standard chessboard uses a regular grid of 8x8 squares (note that we don't distinguish between white and black squares for this challenge):
```
########
########
########
########
########
########
########
########
```
The standard knight can reach all of those, so `(2, 1)` would be a valid output. However, `(1, 1)` for example wouldn't be valid, since such a piece can only reach half of the squares no matter where it starts. `(1, 0)` on the other hand would also be a valid output, since all the squares are orthogonally connected.
Now if we have an irregular board like:
```
# #
# # #
# # #
# #
#
```
Then possible solutions are `(1, 1)` and `(3, 1)`. We can also have a board with completely disconnected regions like:
```
#### ####
#### ####
#### ####
#### ####
```
The standard knight `(2, 1)` can still reach all of the squares here, which is in fact the only solution.
And finally, the following simple board cannot be completely reached by any leaper at all:
```
#
##
```
Note that the input format will not be as an ASCII representation but a list of coordinates instead. E.g. the second example above could be given as:
```
[[1, 1], [5, 1], [2, 2], [4, 2], [6, 2], [3, 3], [5, 3], [7, 3], [2, 4], [4, 4], [5, 5]]
```
## Rules
You may write a program or function, taking input via STDIN (or closest alternative), command-line argument or function argument and outputting the result via STDOUT (or closest alternative), function return value or function (out) parameter.
The input coordinates can be taken in any convenient list format (flat list, list of pairs, list of complex integers, string with consistent separators, etc.).
The output should be the two integers **m** and **n** that identify the leaper if a solution exists (as two separate integers, a list, a string with non-numeric delimiter, etc.). If no solution exists, you may output any consistent value which cannot possibly be a valid leaper. This includes the pair of integers `(0, 0)` in your normal format, as well as anything that isn't a pair of non-negative integers.
Your program needs to handle any of the test cases **within a minute**. This is a somewhat fuzzy restriction, but use common sense: if it takes 2 minutes on your machine, I think we can assume that it might run within 1 on someone else's, but if it takes 20 that's less likely. It shouldn't be hard to solve each test case in a matter of seconds, so this rule only acts to rule out naive brute force.
Standard [code-golf](/questions/tagged/code-golf "show questions tagged 'code-golf'") rules apply.
## Test Cases
Each test case is of the form `board => all valid leapers`. Remember that you only need to output one of those. If the list of leapers is empty, make sure to return something that *isn't* a valid leaper.
```
Examples above:
[[1, 1], [1, 2], [1, 3], [1, 4], [1, 5], [1, 6], [1, 7], [1, 8], [2, 1], [2, 2], [2, 3], [2, 4], [2, 5], [2, 6], [2, 7], [2, 8], [3, 1], [3, 2], [3, 3], [3, 4], [3, 5], [3, 6], [3, 7], [3, 8], [4, 1], [4, 2], [4, 3], [4, 4], [4, 5], [4, 6], [4, 7], [4, 8], [5, 1], [5, 2], [5, 3], [5, 4], [5, 5], [5, 6], [5, 7], [5, 8], [6, 1], [6, 2], [6, 3], [6, 4], [6, 5], [6, 6], [6, 7], [6, 8], [7, 1], [7, 2], [7, 3], [7, 4], [7, 5], [7, 6], [7, 7], [7, 8], [8, 1], [8, 2], [8, 3], [8, 4], [8, 5], [8, 6], [8, 7], [8, 8]] => [[0, 1], [1, 2], [1, 4], [2, 3], [3, 4]]
[[1, 1], [5, 1], [2, 2], [4, 2], [6, 2], [3, 3], [5, 3], [7, 3], [2, 4], [4, 4], [5, 5]] => [[1, 1], [1, 3]]
[[1, 1], [2, 2], [3, 2]] => []
[[1, 1], [1, 2], [1, 3], [1, 4], [2, 1], [2, 2], [2, 3], [2, 4], [3, 1], [3, 2], [3, 3], [3, 4], [4, 1], [4, 2], [4, 3], [4, 4], [6, 1], [6, 2], [6, 3], [6, 4], [7, 1], [7, 2], [7, 3], [7, 4], [8, 1], [8, 2], [8, 3], [8, 4], [9, 1], [9, 2], [9, 3], [9, 4]] => [[1, 2]]
Square boards:
[[1, 1], [1, 2], [2, 1], [2, 2]] => [[0, 1]]
[[1, 1], [1, 2], [1, 3], [2, 1], [2, 2], [2, 3], [3, 1], [3, 2], [3, 3]] => [[0, 1]]
[[1, 1], [1, 2], [1, 3], [1, 4], [2, 1], [2, 2], [2, 3], [2, 4], [3, 1], [3, 2], [3, 3], [3, 4], [4, 1], [4, 2], [4, 3], [4, 4]] => [[0, 1], [1, 2]]
[[1, 1], [1, 2], [1, 3], [1, 4], [1, 5], [2, 1], [2, 2], [2, 3], [2, 4], [2, 5], [3, 1], [3, 2], [3, 3], [3, 4], [3, 5], [4, 1], [4, 2], [4, 3], [4, 4], [4, 5], [5, 1], [5, 2], [5, 3], [5, 4], [5, 5]] => [[0, 1], [1, 2]]
[[1, 1], [1, 2], [1, 3], [1, 4], [1, 5], [1, 6], [2, 1], [2, 2], [2, 3], [2, 4], [2, 5], [2, 6], [3, 1], [3, 2], [3, 3], [3, 4], [3, 5], [3, 6], [4, 1], [4, 2], [4, 3], [4, 4], [4, 5], [4, 6], [5, 1], [5, 2], [5, 3], [5, 4], [5, 5], [5, 6], [6, 1], [6, 2], [6, 3], [6, 4], [6, 5], [6, 6]] => [[0, 1], [1, 2], [2, 3]]
[[1, 1], [1, 2], [1, 3], [1, 4], [1, 5], [1, 6], [1, 7], [2, 1], [2, 2], [2, 3], [2, 4], [2, 5], [2, 6], [2, 7], [3, 1], [3, 2], [3, 3], [3, 4], [3, 5], [3, 6], [3, 7], [4, 1], [4, 2], [4, 3], [4, 4], [4, 5], [4, 6], [4, 7], [5, 1], [5, 2], [5, 3], [5, 4], [5, 5], [5, 6], [5, 7], [6, 1], [6, 2], [6, 3], [6, 4], [6, 5], [6, 6], [6, 7], [7, 1], [7, 2], [7, 3], [7, 4], [7, 5], [7, 6], [7, 7]] => [[0, 1], [1, 2], [2, 3]]
Miscellaneous:
[[1, 1], [2, 1]] => [[0, 1]]
[[1, 1], [1, 2]] => [[0, 1]]
[[1, 1], [12, 35]] => [[11, 34]]
[[1, 1], [1, 2], [2, 1], [2, 2], [6, 1], [6, 2], [6, 3], [6, 4], [7, 1], [7, 2], [7, 3], [7, 4], [8, 1], [8, 2], [8, 3], [8, 4], [9, 1], [9, 2], [9, 3], [9, 4]] => []
[[1, 1], [1, 2], [1, 3], [1, 4], [1, 5], [1, 6], [2, 1], [2, 2], [2, 3], [2, 4], [2, 5], [2, 6], [3, 1], [3, 2], [3, 5], [3, 6], [4, 1], [4, 2], [4, 5], [4, 6], [5, 1], [5, 2], [5, 3], [5, 4], [5, 5], [5, 6], [6, 1], [6, 2], [6, 3], [6, 4], [6, 5], [6, 6]] => [[0, 1], [1, 2], [1, 4]]
[[2, 2], [2, 4], [2, 6], [2, 8], [4, 2], [4, 4], [4, 6], [4, 8], [6, 2], [6, 4], [6, 6], [6, 8], [8, 2], [8, 4], [8, 6], [8, 8]] => [[0, 2], [2, 4]]
Random boards:
[[1, 5], [1, 9], [2, 6], [2, 8], [2, 10], [2, 12], [3, 5], [3, 7], [3, 9], [3, 11], [3, 13], [4, 2], [4, 4], [4, 6], [4, 8], [4, 14], [5, 1], [5, 3], [5, 5], [5, 7], [6, 2], [6, 4], [7, 1], [8, 2]] => [[1, 1], [1, 3]]
[[1, 3], [1, 4], [1, 5], [1, 6], [1, 7], [2, 1], [2, 2], [2, 3], [2, 4], [2, 7], [3, 1], [3, 2], [3, 3], [3, 4], [3, 6], [3, 7], [4, 2], [4, 3], [4, 4], [4, 5], [4, 6], [5, 3], [5, 4], [5, 6]] => [[0, 1], [1, 2]]
[[1, 8], [2, 6], [2, 10], [3, 3], [3, 4], [3, 8], [4, 1], [4, 11], [5, 3], [5, 9], [6, 12], [8, 11], [10, 10], [11, 12], [12, 6], [12, 8], [13, 6], [13, 8], [13, 10], [13, 11], [14, 5], [14, 7], [14, 8], [14, 13], [14, 14], [15, 7], [15, 9], [15, 11], [15, 12], [16, 6], [16, 7], [16, 9], [16, 13], [16, 14], [17, 10], [17, 12], [18, 8], [18, 12], [20, 9], [21, 11], [22, 13], [23, 10], [23, 11], [23, 15], [24, 12]] => [[1, 2]]
[[1, 17], [1, 21], [3, 11], [3, 15], [3, 19], [3, 23], [5, 13], [5, 21], [7, 11], [7, 15], [7, 19], [9, 1], [9, 13], [9, 17], [11, 3], [11, 7], [11, 15], [11, 19], [13, 5], [13, 9], [13, 13], [13, 17], [13, 21], [15, 11], [15, 15], [15, 19], [17, 13], [17, 17]] => [[2, 2], [2, 6], [2, 10]]
[[1, 3], [2, 4], [2, 5], [3, 6], [4, 1], [5, 3], [5, 6], [5, 7], [6, 12], [6, 14], [6, 21], [7, 9], [7, 19], [8, 9], [8, 15], [8, 17], [8, 18], [8, 24], [9, 12], [9, 19], [10, 12], [10, 14], [10, 17], [10, 21], [11, 22], [12, 15], [12, 17], [12, 24], [13, 16], [14, 20], [14, 21], [14, 26], [15, 13], [15, 19], [16, 18], [16, 23], [17, 16], [17, 24]] => [[2, 3]]
[[1, 11], [3, 13], [4, 10], [6, 14], [8, 12], [9, 9], [9, 15], [12, 8], [13, 5], [13, 19], [13, 21], [14, 8], [15, 1], [15, 17], [16, 4], [16, 14], [16, 18], [16, 20], [17, 21], [18, 2], [18, 16], [18, 18], [19, 9], [19, 13], [19, 15], [20, 12], [21, 1], [21, 17], [22, 4], [22, 10], [23, 7]] => [[1, 3]]
[[1, 39], [6, 37], [8, 32], [10, 27], [11, 31], [11, 35], [12, 22], [16, 21], [16, 29], [16, 33], [18, 34], [21, 3], [21, 9], [21, 19], [23, 8], [23, 14], [23, 22], [23, 24], [23, 36], [24, 6], [25, 13], [25, 17], [26, 1], [26, 11], [28, 6], [28, 20], [28, 26], [28, 30], [28, 34], [30, 11], [30, 15], [30, 21], [32, 6], [33, 28], [33, 32], [35, 13], [35, 23]] => [[2, 5]]
```
As a special case, note that for a board consisting of only one cell, any leaper works, but your output must correspond to an actual leaper, so `[0, 0]` is not valid output.
[Answer]
# Pyth, ~~41~~ 35
```
hfqQu@+G+VM*s_BM*F_BMTGQ]hQ)maVhQdt
```
Exits on error if there are no valid leapers, giving the empty string if STDERR is ignored.
[Try it here](http://pyth.herokuapp.com/?code=hfqQu%40%2BG%2BVM%2as_BM%2aF_BMTGQ%5DhQ%29maVhQdt&input=%5B%5B1%2C+1%5D%2C+%5B1%2C+2%5D%2C+%5B1%2C+3%5D%2C+%5B1%2C+4%5D%2C+%5B1%2C+5%5D%2C+%5B1%2C+6%5D%2C+%5B1%2C+7%5D%2C+%5B1%2C+8%5D%2C+%5B2%2C+1%5D%2C+%5B2%2C+2%5D%2C+%5B2%2C+3%5D%2C+%5B2%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D%2C+%5B6%2C+6%5D%2C+%5B6%2C+8%5D%2C+%5B8%2C+2%5D%2C+%5B8%2C+4%5D%2C+%5B8%2C+6%5D%2C+%5B8%2C+8%5D%5D%0A%5B%5B1%2C+1%5D%2C+%5B1%2C+2%5D%2C+%5B1%2C+3%5D%2C+%5B1%2C+4%5D%2C+%5B2%2C+1%5D%2C+%5B2%2C+2%5D%2C+%5B2%2C+3%5D%2C+%5B2%2C+4%5D%2C+%5B3%2C+1%5D%2C+%5B3%2C+2%5D%2C+%5B3%2C+3%5D%2C+%5B3%2C+4%5D%2C+%5B4%2C+1%5D%2C+%5B4%2C+2%5D%2C+%5B4%2C+3%5D%2C+%5B4%2C+4%5D%2C+%5B6%2C+1%5D%2C+%5B6%2C+2%5D%2C+%5B6%2C+3%5D%2C+%5B6%2C+4%5D%2C+%5B7%2C+1%5D%2C+%5B7%2C+2%5D%2C+%5B7%2C+3%5D%2C+%5B7%2C+4%5D%2C+%5B8%2C+1%5D%2C+%5B8%2C+2%5D%2C+%5B8%2C+3%5D%2C+%5B8%2C+4%5D%2C+%5B9%2C+1%5D%2C+%5B9%2C+2%5D%2C+%5B9%2C+3%5D%2C+%5B9%2C+4%5D%5D&debug=0)
Saved 6 bytes thanks to [isaacg](https://codegolf.stackexchange.com/users/20080/isaacg)! Basically just finds all leaper candidates by selecting each valid leaper from the first tile to each other tile. Then for each of these, it makes all eight configurations of `[x, y]` offsets that the leaper could take. It then finds all moves starting from the first tile that follow after the move, and discards those that are not in the input. It keeps doing this until the result doesn't change. If this final list is the same as the input then the leaper was valid.
The standard chess board took the longest when I was testing, it took about 3 seconds on my not very impressive computer.
]
|
[Question]
[
Your code is going to generate a very simple ASCII-art representation of DNA, forever. It will take two numbers as input in any format you want: as a list, as arguments to a function, on stdin, etc.
* A floating-point interval `I` in seconds between 0.0 and 1.0 (inclusive)
* A zoom level `Z` as an integer from 1 to 64 (inclusive)
Your code will print one line to stdout or its equivalent every `I` seconds, producing an infinite output that looks something like this (for zoom level 4):
```
A
T-----a
G-------c
G-----c
g
t-----A
a-------T
c-----G
T
A-----t
C-------g
...
```
Specifically, our representation of DNA is a pair of sine waves connected by hyphens, one consisting of the characters `a`, `c`, `g`, and `t`, the other of the characters `A`, `C`, `G`, and `T`. If `x` is the 0-indexed number of the line we're currently printing, the 0-based position of the character in the lowercase wave is given by `(sin(πx / Z) + 1) * Z`, and in the uppercase wave is given by `(-sin(πx / Z) + 1) * Z`, both **rounded** (not floored) to the nearest integer. Further details:
* In cases where the two waves overlap, you need to alternate which wave is in the front, starting with the uppercase wave. (Starting with the lowercase wave would give us a double helix that [does not exist](http://www.theguardian.com/science/blog/2013/apr/30/dna-twist-to-right)!)
* Ignoring case, A always pairs with T and C always pairs with G, as in real DNA. The pairs themselves should be randomly chosen with a uniform distribution over the four possibilities. It does not matter if the choice of pairs is the same or different on successive runs of your code. The statistical quality of your random choices is not an issue as long as the output has no obvious pattern and a period at least in the billions (flawed PRNGs like [RANDU](https://en.wikipedia.org/wiki/RANDU) are fine.)
* You must either have no trailing spaces or pad every line to the maximum position of the waves at that zoom level (in the example above, nine characters.) Zoom level 1 may have one optional additional trailing space for mathematical reasons.
Because DNA is small, your code will need to be as short as possible.
**More examples:**
Zoom level 8:
```
T
C-----g
A-----------t
C-------------g
G---------------c
T-------------a
T-----------a
T-----a
c
g-----C
t-----------A
g-------------C
a---------------T
...
```
Zoom level 2:
```
A
T---a
c
g---C
G
A---t
c
a---T
...
```
Zoom level 1 (note the leading space):
```
G
a
C
t
...
```
[Answer]
# Ruby, Rev B ~~171~~ 161 bytes
~~Fixing the output for z=1 cost 10 bytes. It's a special case: the helix is really 3 characters wide if you looked at it at 90 degrees, but as we look at it at 0 degrees it looks only 1 character wide.~~ **zero leading spaces on z=1 no longer required**
Some savings by eliminating brackets and by multiplying y.abs by 2 before truncation when calculating the number of - characters needed.
Finally, I avoided the `include Math` (required for `sin` and `PI`) by using complex number arithmetic with powers of the number `i`. The imaginary part of the complex number is equivalent to sin x, except that it repeats with period 4 instead of period 2\*PI. Saving for this change was either 1 or 0 bytes.
```
->z,i{x=0
loop{y=z*("i".to_c**x).imag
s=(?-*(y.abs*2)).center z*2+1
s[z-y+0.5]='TGAC'[r=rand(4)]
x!=0&&s[z+y+0.5]='actg'[r]
puts s
sleep i
x+=2.0/z
x>3.99&&x=0}}
```
# Ruby, Rev A 165 bytes
This is way longer than expected. There are a few potential golfing opportunities to be explored.
```
include Math
->z,i{x=0
loop{y=z*sin(x)
s=('--'*(y.abs+h=0.5)).center(z*2+1)
s[z+h-y]='TGAC'[r=rand(4)]
x!=0&&s[z+h+y]='actg'[r]
puts s
sleep(i)
x+=PI/z
x>6.28&&x=0}}
```
Commented in test program
```
include Math
f=->z,i{x=0
loop{y=z*sin(x)
s=('--'*(y.abs+h=0.5)).center(z*2+1) #make a space-padded string of z*2+1 characters, containing enough - signs
s[z+h-y]='TGAC'[r=rand(4)] #insert random capital letter, saving index in r
x!=0&&s[z+h+y]='actg'[r] #insert small letter. This will normally go on top of the capital as it is done second, but supress for x=0 to make helix
puts s
sleep(i)
x+=PI/z #increment x
x>6.28&&x=0 #reset x if equal to 2*PI (this proofs against loss of floating point precision, making correct output truly infinite.)
}
}
Z=gets.to_i
I=gets.to_f
f[Z,I]
```
[Answer]
# C, ~~294~~ ~~289~~ ~~285~~ ~~283~~ ~~281~~ ~~270~~ ~~265~~ ~~237~~ 218 bytes
```
#include<math.h>
o,i,p,r;char*c="acgtTGCA",d[256]={[0 ...254]='-'};P(w,z)float w;{for(;;poll(0,0,r=w*1e3))p=fabs(sinf(M_PI*i++/z))*z+.5,r=rand()&3,o^=4*!p,printf(p?"%*c%s%c\n":"%*c\n",z-p+1,c[r+o],d+256-p*2,c[r+4-o]);}
```
Or the longer version which parses input from main:
```
#include<stdlib.h>
#include<math.h>
o,i,p,r;char*c="acgtTGCA",d[256]={[0 ...254]='-'};main(n,v)char**v;{for(;n=strtod(v[2],0);poll(0,0,n=atof(v[1])*1e3))p=fabs(sinf(M_PI*i++/n))*n+.5,r=rand()&3,o^=4*!p,printf(p?"%*c%s%c\n":"%*c\n",n-p+1,c[r+o],d+256-p*2,c[r+4-o]);}
```
It's a pretty dumb overall implementation, with some printf tricks thrown in. It has some missing includes, uses K&R syntax for the function, and relies on GCC's range initialisers, so this isn't very standard. Also the function version still uses globals, so it can only be called once!
The function version takes 2 parameters; wait (in seconds) and zoom. Here's a caller for it:
```
#include <stdlib.h>
int main( int argc, const char *const *argv ) {
if( argc != 3 ) {
printf( "Usage: %s <delay> <zoom>\n", argv[0] );
return EXIT_FAILURE;
}
const float delay = atof( argv[1] );
const int zoom = strtod( argv[2], 0 );
if( delay < 0 || zoom <= 0 ) {
printf( "Invalid input.\nUsage: %s <delay> <zoom>\n", argv[0] );
return EXIT_FAILURE;
}
P( delay, zoom );
return EXIT_SUCCESS;
}
```
Run as:
```
./dna <delay> <zoom>
./dna 0.5 8
```
Breakdown:
```
// Globals initialise to 0
o, // Ordering (upper/lower first)
i, // Current iteration
p, // Current indent
r; // Current random value
char*c="acgtTGCA", // The valid letters
d[256]={[0 ...254]='-'}; // Line of dashes (for printing)
main(n,v)char**v;{ // K&R-style main definition (saves 2 bytes)
// n will be used for Zoom, random number & casting delay
for(
;n=strtod(v[2],0); // Store zoom
poll(0,0,n=atof(v[1])*1e3) // After each loop, use poll to delay
// (Use variable to cast delay to int)
)
p=fabs(sinf(M_PI*i++/n))*n+.5, // Calculate separation / 2
r=rand()&3, // Pick random number [0-4)
o^=4*!p, // Reverse order if crossing
printf(p // Print... if not crossing:
?"%*c%s%c\n" // indent+character+dashes+character
:"%*c\n", // Else indent+character
n-p+1, // Width of indent + 1 for char
c[r+o], // First character
d+256-p*2, // Dashes
c[r+4-o] // Second character
);
}
```
[Answer]
## C, ~~569~~ ~~402~~ 361 bytes
```
#include<stdlib.h>
u,l,r,m,n,Z,I,y=0,x=0;main(c,char**v){Z = atoi(v[1]);I=atof(v[2])*1000000;srand(time(0));char *a="ACGTtgca";while(1){r=rand()%4;usleep(I);double s=sin(3.14*x++/Z);u=floor(((-1*s+1)*Z)+0.5);l=floor(((s+1)*Z)+0.5);m=(u<l)?u:l;n=u<l?l:u;char z[n+1];memset(z,' ',n);z[l]=a[r+4];z[u]=a[r];for(y=m+1;y<n;y++)z[y]='-';z[n+1]='\0';printf("%s\n",z);}}
```
Whipped this up pretty quick so I am sure there are some other things I could do to decrease my score but I am just happy I got this program to compile and run properly on the first attempt.
De-golf version:
```
#include<stdio.h>
#include<math.h>
#include<unistd.h>
#include<time.h>
#include<stdlib.h>
u,l,r,m,n,Z,I,y=0,x=0;
main(c,char**v){
Z = atoi(v[1]);
I=atof(v[2])*1000000;
srand(time(0));
char *a="ACGTtgca";
while(1){
r=rand()%4;
usleep(I);
double s=sin(3.14*x++/Z);
u=floor(((-1*s+1)*Z)+0.5);
l=floor(((s+1)*Z)+0.5);
m=(u<l)?u:l;
n=u<l?l:u;
char z[n+1];
memset(z,' ',n);
z[l]=a[r+4];
z[u]=a[r];
for(y=m+1;y<n;y++)z[y]='-';
z[n+1]='\0';
printf("%s\n",z);
}
}
```
UPDATE: I adjusted the loop to print everything in one print statement and used the fact that variables are defined as int by default to shave some bytes.
UPDATE2: Some var renaming and some logic shortening to shave a few more bytes.
[Answer]
# JavaScript (ES6) ~~241~~ ~~244~~ ~~227~~ ~~222~~ 231 bytes
This looked interesting - I love ASCII art!
Just started, still in the process of golfing it...
```
(I,Z)=>{c=i=0,setInterval(_=>{with(Math)m=sin(PI*i++/Z),a=round(++m*Z),b=round((2-m)*Z),r=random()*4|0,D="TGAC"[r],d="actg"[r],e=a-b,c^=!e,p=" ".repeat(a>b?b:a)+(c?D:d)+"-".repeat(e?abs(e)-1:0)+(e?a>b?d:D:""),console.log(p)},I*1e3)
```
**--- EDIT: turns out I can't actually put it in eval() - otherwise it can't access vars I and Z (so adds 9 bytes)**
*- saved 6 bytes thanks to user81655*
*- saved 5 bytes thanks to Dave*
## Explanation
```
(I,Z)=>{
c=i=0, // clear vars
setInterval(_=>{ // repeat
with(Math)
m=sin(PI*i++ / Z), // calculate waves
a=round(++m * Z),
b=round((2-m) * Z),
r=random()*4|0, // get random amino-acids
D="TGAC"[r],
d="actg"[r],
e=a-b,
c^=!e, // alternate upper/lowercase
p= // prepare output
" ".repeat(
a>b ? b : a
)+(
c ? D : d
)+
"-".repeat(
e ? abs(e)-1 : 0
)+(
e ? a>b ? d : D : ""
),
console.log(p) // return output
},I*1e3) // repeat for every 'I' seconds
}
```
]
|
[Question]
[
The challenge is to follow (draw) the path:
* `^n` - up by n lines
* `vn` - down by n lines
* `>n` - right by n character positions
* `<n` - left by n characters positions
---
* `n` is an integer, greater than zero (i.e. you can't receive a command like `>-2`).
* There're no separators between the commands, the well-formed input looks like this: `>5v8<10^3`, no other form of input allowed.
* The number of commands is unlimited.
* No more characters are supposed to creep into the input.
Examples.
1. Input is an empty string, output:
```
*
```
2. Input is either `>3` or `<3`: note that this doesn't make any difference to the output:
```
****
```
3. Similar for `^3` and `v3`:
```
*
*
*
*
```
4. Input: `>1v2`, output:
```
**
*
*
```
5. Input: `^4>3v2<1`, output:
```
****
* *
* **
*
*
```
6. If you go back and use the same path, don't draw anything new. E.g. `>5<5`
```
******
```
7. ...though you don't draw anything new, you obviously change the position. Hence, if your input looks like this: `>4<2v3`, the output is:
```
*****
*
*
*
```
8. This is a more complex example: 1) the path can cross itself 2) note that the last three steps of the last command shift the whole path to the right. Input: `v6>4^3<7`, output:
```
*
*
*
********
* *
* *
*****
```
9. [Input](https://codegolf.stackexchange.com/posts/comments/165676):
```
^2v2>3<3v3>4^5v5>3^5>4v2<4v3>4^3v3>3^5>4v2<4v3>7^5>4v2<4v3>9^3<2^2v2>4^2v2<2v3>8^5>2v4>2^4v5<3>6^5>5<5v2>5<5v2>5<4v1>8^3<1^2v2>1v2>2^3v3>2^2>1^2v2<1v3<3>11^3<2^2v2>4^2v2<2v3>5^5>5<5v2>5<5v2>5<4v1>7^5>4v2<4v3>4^3v3>3^5>4v2<3v1<1v2>3^1>1v1
```
Output:
```
* * ***** ***** ***** * * *** * ****** * * * * ****** ***** *****
* * * * * * * * * * * * * * * * * * * * * * * *
***** ***** ***** ***** ***** * * * ****** ** * ** ***** ****** ***** *****
* * * * * * * * * * * * * * * * * * **
* * * * * * * * *** ****** ***** * ****** * * * **
*******************************************************************************************
```
[Answer]
# JavaScript (ES6), 204 ~~211 210~~
**Edit 1** Bug fix - output '\*' for void input
**Edit 2** Simpler decoding of direction to x and y diff
Here is my answer to [The treasure map](https://codegolf.stackexchange.com/a/54361/21348), revised to fulfill the specs.
```
F=m=>(m.replace(/\D(\d+)/g,(d,z)=>{for(;z--;r=[...r],r[x]=m,p[y]=r.join``)for(d<'>'?--x:d<'^'?++x:d<'v'?--y:++y,p=~x?~y?p:[y=0,...p]:p.map(r=>' '+r,x=0),r=p[y]||'';!r[x];)r+=' '},x=y=0,p=[m='*']),p.join`
`)
```
**Less golfed** and explained more or less
```
f=m=>(
x=y=0, // starting position
p=['*'], // output string array (initialized with minimum output)
m.replace( /\D(\d+)/g,
(d,z) => // execute the following for each group direction/length. Length in z, direction in d[0]
{
while( z--) // repeat for the len
{
// check d to change values of x and y
// all the comparison are with > and <, not equal
// so that they work with the whole d, not just d[0]
d<'>'?--x:d<'^'?++x:d<'v'?--y:++y,
// now if x or y are < 0 then p must be adjusted
p = ~x
? ~y
? p // both x and y are >= 0, p is not changed
: [y = 0, ...p] // y < 0, shift p by on adding a 0 element and set y to 0
: p.map(r=> ' ' + r, x = 0); // x < 0, add a space to the left for each row in p and set x to 0
r = p[y] || ''; // get current row in r
for( ; !r[x]; ) // if the current row is empty or too short
r += ' '; // ... add spaces up to position x
// set character in x position
r = [...r], // the shorter way is converting to array ...
r[x] = '*', // setting the element
p[y] = r.join`` // and the back to string using join
}
}),
p.join`\n` // return output array as a newline separated string
}
```
**Test**
```
F=m=>(m.replace(/\D(\d+)/g,(d,z)=>{for(;z--;r=[...r],r[x]='*',p[y]=r.join``)for(d<'>'?--x:d<'^'?++x:d<'v'?--y:++y,p=~x?~y?p:[y=0,...p]:p.map(r=>' '+r,x=0),r=p[y]||'';!r[x];)r+=' '},x=y=0,p=['*']),p.join`
`)
// TEST
console.log = x => O.textContent += x + '\n';
console.log(F('')+'\n')
console.log(F('v6>4^3<7')+'\n')
console.log(F('^2v2>3<3v3>4^5v5>3^5>4v2<4v3>4^3v3>3^5>4v2<4v3>7^5>4v2<4v3>9^3<2^2v2>4^2v2<2v3>8^5>2v4>2^4v5<3>6^5>5<5v2>5<5v2>5<4v1>8^3<1^2v2>1v2>2^3v3>2^2>1^2v2<1v3<3>11^3<2^2v2>4^2v2<2v3>5^5>5<5v2>5<5v2>5<4v1>7^5>4v2<4v3>4^3v3>3^5>4v2<3v1<1v2>3^1>1v1'))
```
```
<pre id=O></pre>
```
[Answer]
# [MATL](https://esolangs.org/wiki/MATL), 71 bytes
```
1thj'.\d+'XX"@Z)XK6L)U:"K1)XK118=K94=-K62=K60=-hv]]YstY)X<1--lqg10*32+c
```
Uses [current release (6.0.0)](https://github.com/lmendo/MATL/releases/tag/6.0.0) of the language/compiler. Works in Matlab and in Octave.
*EDIT (June 21, 2016): due to changes in the language, the code requires a few modifications to run in current release (16.0.0). You can [try it online](http://matl.tryitonline.net/#code=MXRoaicuXGQrJ1hYIkBZOlhLNEwpVToiSzEpWEsxMTg9Szk0PS1LNjI9SzYwPS1oMiR2XV1Zc3RYOlg8MS0tbGxYUWcxMCozMitj&input=XjJ2Mj4zPDN2Mz40XjV2NT4zXjU-NHYyPDR2Mz40XjN2Mz4zXjU-NHYyPDR2Mz43XjU-NHYyPDR2Mz45XjM8Ml4ydjI-NF4ydjI8MnYzPjheNT4ydjQ-Ml40djU8Mz42XjU-NTw1djI-NTw1djI-NTw0djE-OF4zPDFeMnYyPjF2Mj4yXjN2Mz4yXjI-MV4ydjI8MXYzPDM-MTFeMzwyXjJ2Mj40XjJ2MjwydjM-NV41PjU8NXYyPjU8NXYyPjU8NHYxPjdeNT40djI8NHYzPjReM3YzPjNeNT40djI8M3YxPDF2Mj4zXjE-MXYx) including the needed modifications.*
### Examples
```
>> matl
> 1thj'.\d+'XX"@Z)XK6L)U:"K1)XK118=K94=-K62=K60=-hv]]YstY)X<1--lqg10*32+c
>
> ^4>3v2<1
****
* *
* **
*
*
>> matl
> 1thj'.\d+'XX"@Z)XK6L)U:"K1)XK118=K94=-K62=K60=-hv]]YstY)X<1--lqg10*32+c
>
> ^2v2>3<3v3>4^5v5>3^5>4v2<4v3>4^3v3>3^5>4v2<4v3>7^5>4v2<4v3>9^3<2^2v2>4^2v2<2v3>8^5>2v4>2^4v5<3>6^5>5<5v2>5<5v2>5<4v1>8^3<1^2v2>1v2>2^3v3>2^2>1^2v2<1v3<3>11^3<2^2v2>4^2v2<2v3>5^5>5<5v2>5<5v2>5<4v1>7^5>4v2<4v3>4^3v3>3^5>4v2<3v1<1v2>3^1>1v1
* * ***** ***** ***** * * *** * ****** * * * * ****** ***** *****
* * * * * * * * * * * * * * * * * * * * * * * *
***** ***** ***** ***** ***** * * * ****** ** * ** ***** ****** ***** *****
* * * * * * * * * * * * * * * * * * **
* * * * * * * * *** ****** ***** * ****** * * * **
*******************************************************************************************
```
### Explanation
The program has four main steps:
1. Read input string and split into its components.
2. Build a 2-column matrix where each row describes a unit displacement in the appropriate direction. For example, `[0 -1]` indicates one step to the left. The first row is the origin of the path, `[1 1]`
3. Compute the cumulative sum of that matrix along the first dimension . Now each row describes the coordinates of a `*`. Normalize to minumum value `1`
4. Create a new matrix that contains `1` at the coordinates indicated by the matrix from step 3, and `0` otherwise. This is then transformed into a char matrix.
Code:
```
1th % row vector [1 1]. Initiallize matrix of step 2
j % (step 1) read input string
'.\d+'XX % split into components. Creates cell array of substrings
" % (step 2) for each component
@Z)XK % unbox to obtain substring and copy
6L)U: % obtain number and build vector of that size
" % repeat as many times as that number
K1) % paste substring. Get first character: '^', 'v', '>', '<'
XK118=K94=- % vertical component of unit displacement: -1, 0 or 1
K62=K60=- % horizontal component of unit displacement: -1, 0 or 1
h % concatenate horizontally
v % append vertically to existing matrix
] % end
] % end
Ys % (step 3) cumulative sum along first dimension
tY)X<1-- % normalize to minimum value 1
lqg % (step 4) build matrix with 0/1
10*32+c % replace 0 by space and 1 by asterisk
```
[Answer]
# Perl, 174 bytes
```
@M=(['*']);pop=~s/(.)(\d+)/($z=ord$1)&64?($y+=$z&8?-1:1)<0&&unshift@M,[$y++]:($x+=($z&2)-1)<0?@M=map{[$x=0,@$_]}@M:0,$M[$y][$x]='*'for1..$2/gre;print map{map{$_||$"}@$_,$/}@M
```
Expects input as commandline argument. *Be sure to quote the argument!*
Example: `perl 177.pl "<1^2>3v4<5^6>7v8<9^10>11"`
**Somewhat readable:**
```
@M=(['*']); # output origin/starting position
pop=~ # apply regex to cmdline arg
s!(.)(\d+)! # match $1=direction, $2=count
($z=ord$1) # get ASCII code for char
&64 # 'v^' have this bit set, '<>' don't
? # adjust y:
($y += $z&8 ? -1 : 1) # '^' has bit set, 'v' doesn't
< 0 && # negative y?
unshift @M, [$y++] # prepend row; abuse [] for $y++ saving 3 bytes
: # adjust x:
($x+= ($z&2) -1 ) # '>' has bit set: 2-1=1, '<' hasn't: 0-1=-1
< 0 ? # negative x?
@M = map{ [$x=0,@$_] } @M # prepend column, reset x
:0 # '?:0' shorter than '&&()'
, # oh, and also:
$M[$y][$x]='*' # output current position.
for 1..$2 # iterate count
!grex;
print map{ map{$_||$"} @$_, $/ } @M # iterate rows/cols, print '*' or space
```
[Answer]
# [Vyxal](https://github.com/Vyxal/Vyxal/tree/version-2) `?`, 197 [bitsv2](https://github.com/Vyxal/Vyncode/blob/main/README.md), 24.625 bytes
```
kdFf`^>v<`kd√Ŀ?f⌊0€Ḣṅ⌊›×?[ø^
```
[Try it Online!](https://vyxal.pythonanywhere.com/?v=2&c=1#WyI9PyIsIiIsImtkRmZgXj52PGBrZOKImsS/P2bijIow4oKs4bii4bmF4oyK4oC6w5c/W8O4XiIsIiIsIl4ydjI+MzwzdjM+NF41djU+M141PjR2Mjw0djM+NF4zdjM+M141PjR2Mjw0djM+N141PjR2Mjw0djM+OV4zPDJeMnYyPjReMnYyPDJ2Mz44XjU+MnY0PjJeNHY1PDM+Nl41PjU8NXYyPjU8NXYyPjU8NHYxPjheMzwxXjJ2Mj4xdjI+Ml4zdjM+Ml4yPjFeMnYyPDF2MzwzPjExXjM8Ml4ydjI+NF4ydjI8MnYzPjVeNT41PDV2Mj41PDV2Mj41PDR2MT43XjU+NHYyPDR2Mz40XjN2Mz4zXjU+NHYyPDN2MTwxdjI+M14xPjF2MSJd)
Bitstring:
```
10000000000001110010111101000000110111011010110000000000100001111110101111001000101011110011001101001000011000101100010101000011110111000110001011100110000011001111111111010010100100111110001000000
```
```
kdFf`^>v<`kd√Ŀ?f⌊0€Ḣṅ⌊›×?[ø^­⁡​‎‎⁡⁠⁡‏⁠‎⁡⁠⁢‏⁠‎⁡⁠⁣‏⁠‎⁡⁠⁤‏‏​⁡⁠⁡‌⁢​‎‎⁡⁠⁢⁡‏⁠‎⁡⁠⁢⁢‏⁠‎⁡⁠⁢⁣‏⁠‎⁡⁠⁢⁤‏⁠‎⁡⁠⁣⁡‏⁠‎⁡⁠⁣⁢‏‏​⁡⁠⁡‌⁣​‎‎⁡⁠⁣⁣‏⁠‎⁡⁠⁣⁤‏⁠‎⁡⁠⁤⁡‏⁠‏​⁡⁠⁡‌⁤​‎‎⁡⁠⁤⁢‏⁠⁠‏​⁡⁠⁡‌⁢⁡​‎‎⁡⁠⁤⁣‏⁠‎⁡⁠⁤⁤‏⁠‎⁡⁠⁢⁡⁡‏‏​⁡⁠⁡‌⁢⁢​‎‎⁡⁠⁢⁡⁢‏⁠‎⁡⁠⁢⁡⁣‏⁠‎⁡⁠⁢⁡⁤‏‏​⁡⁠⁡‌⁢⁣​‎‎⁡⁠⁢⁢⁡‏⁠‎⁡⁠⁢⁢⁢‏‏​⁡⁠⁡‌⁢⁤​‎‎⁡⁠⁢⁢⁣‏‏​⁡⁠⁡‌⁣⁡​‎‎⁡⁠⁢⁢⁤‏‏​⁡⁠⁡‌⁣⁢​‎‎⁡⁠⁢⁣⁡‏⁠‎⁡⁠⁢⁣⁢‏‏​⁡⁠⁡‌⁣⁣​‎‎⁡⁠⁢⁣⁣‏⁠‎⁡⁠⁢⁣⁤‏‏​⁡⁠⁡‌⁣⁤​‎‏​⁢⁠⁡‌­
kdFf # ‎⁡remove all digits from input and flatten
# ‎⁡to give list of directions
`^>v<` # ‎⁢arrows in canvas directions
kd√ # ‎⁣even digits (02468)
Ŀ # ‎⁤transliterate directions to corresponding canvas directional number (ignores the 8) [1]
?f⌊ # ‎⁢⁡flatten the input and get the numbers
0€Ḣ # ‎⁢⁢split on 0 and remove the first element (always an empty list due to input format)
ṅ⌊ # ‎⁢⁣join sublists by nothing and convert to number(deals with multi digit numbers)
› # ‎⁢⁤increment (no idea why i need this but the entire program breaks without it) [2]
× # ‎⁣⁡literal "*"
?[ # ‎⁣⁢if the input is true
ø^ # ‎⁣⁣draw on the canvas using directions defined in [1] lengths defined in [2] and printing the text as "*"
# ‎⁣⁤otherwise, implicitly print "*"
üíé
```
Created with the help of [Luminespire](https://vyxal.github.io/Luminespire).
[Answer]
# [05AB1E](https://github.com/Adriandmen/05AB1E), 27 bytes
```
">^v<"žCÍS1ú‡#¦εć)>}ø`'*s<Λ
```
[Try it online!](https://tio.run/##dY4xCgJBDEXvooVol2TGVQhpPIJ9UMHCymIhnWBn5QmsbLyBIBYWrrZ7CC8yZgeELdYiIXlJ/s@2XK4265R6osa992NWHedQ3T/7c/95qa@vw1B21W0xGJVcn1JSNBRiMpKg0aKQRgmGHDJpeJsUrXqqxJjvQ5MZnU18jhYENVhkkrH3kaPv/HIw8C1iyJfggdnFlSQzBvN/BKBDPnbKFX9fJgNuLEjBreAL "05AB1E – Try It Online") (2020 is close enough so why not)
]
|
[Question]
[
Write a program or function that takes in an integer greater than 1 or less than -1. That is, the input won't be 0, 1, or -1.
If the input is `2`, the output should be:
```
|\_/|
|___|
```
If the input is `3`, the output should be:
```
|\_/\_/|
|______|
```
If the input is `4`, the output should be:
```
|\_/\_/\_/|
|_________|
```
The pattern continues in the same exact manner for larger inputs. For example, if the input is `10`, the output should be:
```
|\_/\_/\_/\_/\_/\_/\_/\_/\_/|
|___________________________|
```
If the input is `-2`, the output should be:
```
____
| |
|_/\_|
```
If the input is `-3`, the output should be:
```
_______
| |
|_/\_/\_|
```
If the input is `-4`, the output should be:
```
__________
| |
|_/\_/\_/\_|
```
The pattern continues in the same exact manner for smaller inputs. For example, if the input is `-10`, the output should be:
```
____________________________
| |
|_/\_/\_/\_/\_/\_/\_/\_/\_/\_|
```
The output can be printed or returned as a string with an optional trailing newline. The top right "empty" corner of the output for negative inputs may be a space or it may remain empty.
**The shortest code in bytes wins.**
[Answer]
# CJam, ~~56~~ ~~50~~ 49 bytes
```
ri_(z"\_/"*'_@0>{\4>W<_,@*SooNoS}|1$,*]${'|\'|N}/
```
Try it online in the [CJam interpreter.](http://cjam.aditsu.net/#code=ri_(z%22%5C_%2F%22*'_%400%3E%7B%5C4%3EW%3C_%2C%40*SooNoS%7D%7C1%24%2C*%5D%24%7B'%7C%5C'%7CN%7D%2F&input=23)
### How it works
```
ri e# Read an integer from STDIN and push it on the stack.
_(z e# Push a copy, decrement it and apply absolute value.
e# For positive n, (n -> n-1) and (-n -> n+1).
"\_/"* e# Repeat the string that many times.
'_ e# Push an underscore.
@0> e# Check if the original integer is positive.
{ e# If it isn't:
\ e# Swap the generated string with the underscore.
4>W< e# Discard the string's first 4 and last character.
e# This makes the pattern of the bottom row start and end with an
e# underscore, truncating it to the correct length in the process.
_, e# Push the length of a copy.
@* e# Repeat the underscore that many times.
So e# Print a space.
oNo e# Print the underscores, then a linefeed.
S e# Push a space.
}| e#
1$, e# Retrieve the strings length.
* e# Repeat the underscore or space that many times.
]$ e# Wrap the two generated strings in an array and sort it.
{ e# For each string:
'|\ e# Push a vertical bar and swap the string on top of it.
'|N e# Push a vertical bar and a linefeed.
}/ e#
```
[Answer]
# Pyth, ~~56~~ 54 bytes
I'm golfing Pyth on a phone with the online interpreter. That's a totally great idea.
**Update 2015-10-15:** I rewrote the thing (still on my phone, lol) and saved 2 bytes, of which one could've been done with the original too.
```
J<Q0Ljb"||"jPW!J_WJ[y<>*K+J*3t.aQ"\_/"JKy*K?Jd\_+d*K\_
```
[Try it online.](http://pyth.herokuapp.com/?code=J%3CQ0Ljb%22%7C%7C%22jPW!J_WJ%5By%3C%3E*K%2BJ*3t.aQ%22%5C_%2F%22JKy*K%3FJd%5C_%2Bd*K%5C_&input=4&debug=0)
[Answer]
## [Minkolang 0.8](http://esolangs.org/wiki/Minkolang), 100 bytes
```
"|"nd0`u!vbd3*["_"]"|"25*"|"1g["\_/"]"|"(O).
"[d~g1"_"<.)O(" "D*3R~1"_"*52"|"D*3R1dg2"| "*52"|"]"\/_
```
Just builds up the stack and then prints it all out at once. I'm sure this could be golfed but I've already spent a lot of time on this...
[Answer]
# Pyth, 45 bytes
```
jtW!J<Q0.b+.[YN+h*3t.aQJY.>[d.<"\_/"J\_)J" ||
```
Try it online: [Demonstration](http://pyth.herokuapp.com/?code=jtW!J%3CQ0.b%2B.%5BYN%2Bh*3t.aQJY.%3E%5Bd.%3C%22%5C_%2F%22J%5C_%29J%22%20%7C%7C&input=-4&test_suite_input=2%0A-2%0A3%0A-3&debug=0) or [Test Suite](http://pyth.herokuapp.com/?code=jtW!J%3CQ0.b%2B.%5BYN%2Bh*3t.aQJY.%3E%5Bd.%3C%22%5C_%2F%22J%5C_%29J%22%20%7C%7C&input=-4&test_suite=1&test_suite_input=2%0A-2%0A3%0A-3&debug=0)
### Explanation:
```
jtW!J<Q0.b+.[YN+h*3t.aQJY.>[d.<"\_/"J\_)J" || implicit: Q = input number
J<Q0 assign Q < 0 to J
[ ) create a list with
d * the string " "
.<"\_/"J * the string "\_/" rotated to
the left by J
\_ * the string "_"
.> J rotate to the right by J
" || the string " ||"
.b binary mapping, N iterates
over list, Y over string:
.[YN+h*3t.aQJ pad Y with N to reach a string
of length 3*(abs(Q)-1)+1-J
+ Y and append Y
tW!J remove the first line if Q > 0
j print each on separate line
```
[Answer]
# JavaScript (ES6), ~~111~~ 98 bytes
Optimal technique discovered! Turns out removing all those interpolators from the template strings saves a *lot* of bytes. Perhaps it could still be made shorter, perhaps not. In any case, ES6 template strings (and arrow functions) are awesome. :)
```
x=>(x>0?`|\\_/A|
|___A|`:` ___A_
| A |
|_/\\A_|`).replace(/(...)A/g,(_,y)=>y.repeat(x>0?x-1:~x))
```
[Answer]
# [Vyxal](https://github.com/Lyxal/Vyxal), 67 bytes
```
ȧ=[‹`\_/`*\|:„+p,‹3*\_*\|:„+p,|N3*⇩:\_*ðp,ð*\|:„+p,ȧ`\_/`*ḢṪ\|:„+p,
```
[Try it Online!](http://lyxal.pythonanywhere.com?flags=&code=%C8%A7%3D%5B%E2%80%B9%60%5C_%2F%60*%5C%7C%3A%E2%80%9E%2Bp%2C%E2%80%B93*%5C_*%5C%7C%3A%E2%80%9E%2Bp%2C%7CN3*%E2%87%A9%3A%5C_*%C3%B0p%2C%C3%B0*%5C%7C%3A%E2%80%9E%2Bp%2C%C8%A7%60%5C_%2F%60*%E1%B8%A2%E1%B9%AA%5C%7C%3A%E2%80%9E%2Bp%2C&inputs=-4&header=&footer=)
Oof.
[Answer]
## Python 2.7, 144 bytes
This took more bytes than expected. Here's the code.
```
c=int(input())
p,w,n,u=list('| \n_')
a=abs(c)-1
d=3*a
if c>0:
s=p+"\\_/"*a+p+n+p+u*d+p
else:
d=d+1
s=w+u*d+n+p+w*d+p+n+p+"_/\\"*a+u+p
print s
```
[Answer]
**Java, 272 Bytes**
```
String f(int i) {
String p = i>0?"\\_/":"_/\\_",x = "|"+new String(new char[(i<0?-i:i)-1]).replace("\0",p)+"|",
l=new String(new char[x.length()-2]).replace("\0","_");
return i>0?x+"\n|"+l+"|":" "+l+" \n|"+new String(new char[x.length()-2]).replace("\0"," ")+"|\n"+x;
}
```
[Answer]
# SpecBAS - 167 bytes
```
1 INPUT n: DIM s$="\_/","_/\": LET t$=s$(2-(n>0))*(ABS n-1)+("_"*(n<0)),u$="_"*LEN t$
2 TEXT IIF$(n>0,"|"+t$+"|"#13"|"+u$+"|"," "+u$+#13"|"+" "*LEN t$+"|"#13"|"+t$+"|")
```
`IIF$` is an inline `IF` statement, `#13` is a way of embedding newlines into a string (and doesn't always need a "+" if it's between hardcoded strings).
Since a few releases ago, SpecBAS lets you have multiple assignments to one `LET` statement, which helps save some characters.
[Answer]
# Python 2.7, 118 bytes
```
n=input()*3-3
a=-n-6
s=' %s_\n| %s|\n|%s_|'%(a*'_',a*' ',a/3*'_/\\')
if n>0:s='|%s|\n|%s|'%(n/3*'\\_/',n*'_')
print s
```
Getting down from 120 to 118 was fun!
[Answer]
# Ruby - 113 bytes
Seems too long. I'll try to golf this down a bit more.
```
n=gets.to_i;p,h=n.abs-1,?|;n>0 ? (puts h+'\\_/'*p+h,h+'___'*p+h):(k=p*3+1;puts' '+?_*k,h+' '*k+h,'|_'+'/\\_'*p+h)
```
[Answer]
# C#, 185 bytes
C# struggles with golfing repeating strings.
Completely golfed:
```
string S(int n){int m=n>0?n:-n;return string.Format(n>0?"|{0}\n|{1}|":" {1}\n|{2}|\n|_{0}","|".PadLeft(m).Replace(" ",n>0?@"\_/":@"/\_"),"".PadLeft(m=m*3-(n>0?3:2),'_'),"".PadLeft(m));}
```
Indentation and new lines added for clarity:
```
string S(int n){
int m=n>0?n:-n;
return string.Format(n>0?"|{0}\n|{1}|":" {1}\n|{2}|\n|_{0}",
"|".PadLeft(m).Replace(" ",n>0?@"\_/":@"/\_"),
"".PadLeft(m=m*3-(n>0?3:2),'_'),
"".PadLeft(m)
);
}
```
[Answer]
# Powershell - 200 190 186 168 154
Golfed out the equation (4-(($n-2)*3)) to (3*$n-6) along with some extraneous parens and semicolons.
Found that `n is the equivalent of `[Environment]::NewLine` and that `$s -f [args]` is the equivalent of `[String]::Format`:
```
$n=$args;if($n-gt0){$s="|{1}|{0}|{2}|";$a=$n;$b=$n*3}else{$n*=-1;$s=" {2}{0}|{3}|{0}|_/{1}\_|";$a=$n-2;$b=$c=3*$n-2};$s-f"`n",("\_/"*$a),("_"*$b),(" "*$c)
```
Explanation retains clarifying parentheses:
```
$n=$args;
// Basically a way of coming up with a string to format and the
// necessary counts of repeated characters
if($n-gt0){
// Placeholder format
$s="|{1}|{0}|{2}|{3}";
// Number of repeated "\_/" instances
$a=$n;
// Number of repeated "_" instances
$b=$n*3
} else {
$n*=-1;
$s=" {2}{0}|{3}|{0}|_/{1}\_|";
$a=($n-2);
$b=(4+(($n-2)*3));
// Number of repeated " " instances .. not needed for "positive" saw
$c=$b;
};
[String]::Format($s,[Environment]::NewLine,"\_/"*$a,"_"*$b," "*$c)
```
]
|
[Question]
[
**Objective:**
A guru once said a perfect code selfie is best shot diagonally from upper left corner. A code selfie is almost like a Quine - but rotated 45 degree clockwise.
Your mission is to code a program that outputs a code selfie.
**Rules:**
1. You can use any programming language.
2. Your programs should not take any input from file, filename, network or anything else.
**Mandatory criterias:**
Selfies is about the motive and background, so blankspaces (and other not visible content like linefeeds and such)
does not count as being part of the character count. All visible characters is restricted to be outputted on the correct 45 degree rotated position while all non-visible characters is not restricted to the correct 45 degree rotated position.
Just like a color palette on a normal selfie, mandatory to a code selfie is that it contains atleast 16 of these characters: {a-zA-Z0-9}
**Example:**
If this example is valid sourcecode:
```
Output abcd
Output efgh
Output ijkl
Output mnop
```
The example code should output this:
```
O
O u
O u t
O u t p
u t p u
t p u t
p u t
u t a
t e b
i f c
m j g d
n k h
o l
p
```
This is code-golf, shortest sourcecode in bytes wins!
[Answer]
# Javascript (*ES6*), 72 bytes
16 unique alphanumeric character pallete: `fjalert0plcgmixn`
```
(f=j=>alert(`(f=${f})(0)`.replace(/./gmi,x=>' '.repeat(j++)+x+'\n')))(0)
```
`m` and `i` flags are added to the regexp to meet minimum palette requirements.
[Answer]
# CJam, ~~30 28~~ 25 bytes
```
{95c103ic]seeSf.*N*Xmr}_g
```
This is kind of long due to the 16 character from `A-Za-z0-9` limit.
This is a bit non-trivial variant of a standard quine in CJam. Will add explanations soon.
*UPDATE - 2 bytes saved thanks to Martin, 3 bytes saved thanks to Dennis*
[Try it online here](http://cjam.aditsu.net/#code=%7B95c103ic%5DseeSf.*N*Xmr%7D_g)
[Answer]
# Java, 312
```
class Z{public static void main(String[]a){String s="class Z{public static void main(String[]a){String s=%c%s%1$c,t;for(int i=0,j;i<326;System.out.println(t+s.format(s,34,s).charAt(i++)))for(j=i,t=%1$c%1$c;j-->0;)t+=' ';}}",t;for(int i=0,j;i<326;System.out.println(t+s.format(s,34,s).charAt(i++)))for(j=i,t="";j-->0;)t+=' ';}}
```
There are actually 326 bytes, but if I understand the rules correctly, I don't have to count the 14 spaces.
The program is basically a standard Java quine, plus a lot of whitespace.
[Answer]
# Python 3, 139 characters - 10 spaces = 129 characters
```
sjxd='sjxd=%r;[print(" "*i+(sjxd%%sjxd)[i]) for i in range(len(sjxd%%sjxd))]';[print(" "*i+(sjxd%sjxd)[i]) for i in range(len(sjxd%sjxd))]
```
Since my code was one line, all I had to do was print the program diagonally. My string has the weird name 'sjxd' so that my code could have the 16 unique alphanumeric characters.
[Answer]
# CSS, 69 bytes
```
<style>:before,*{transform:rotate(45deg;display:block;content:'<style>
```
Put in a blank html page to avoid conflict with other tags.
Palette: `stylebfortanm45dgiplck` (22 chars)
[Answer]
# MATLAB, 40 bytes
Bit difficult with the whole recursion thing - how do you print your own source code when adding the code to a string to be printed increases the size of the source code itself. But, never the less, the following will do it:
```
123456;disp(diag('123456;disp(diag())'))
```
The `123456;` bit is there to meet the required 16 unique characters. The following are used:
```
'()123456;adgips
```
The above code doesn't work on Octave for some reason, but does work in MATLAB. Below is the output:
```
1
2
3
4
5
6
;
d
i
s
p
(
d
i
a
g
(
)
)
```
---
Now if you don't mind the `ans=` bit that MATLAB enjoys putting, the following would work for **32 bytes**:
```
12345678;diag('12345678;diag()')
```
]
|
[Question]
[
In this challenge, you will be given a list of points. **These points lie on the perimeter of an imaginary square**. Your goal is to:
1. If possible, print out the rotation of the square, which will be a value from [0, 90) where 0 represents a square with lines vertical and horizontal. The rotation is to be given in degrees counted counter-clockwise.
2. If the rotation of the square is ambiguous (such as only being given 2 points), print out "Unknown"
3. If creating a square given the points is impossible, print out "Impossible"
The points you are given are guaranteed to be unique, and are in no particular order. You can use any format you wish to input the list, but for my examples, my points will be in the format `x,y`, and space separated. The numbers are floating-point numbers, and you can assume they are within a range that your language can handle. Your output should be accurate to at least 3 decimal places, and assume your language handles floating point numbers with perfect accuracy.
Here are some test cases (I have made most of these using whole numbers for easy visualizing, but your program should handle floating points):
Unknown:
```
0,0
0,0 1,0
0,0 1,0 0,1
0,0 1,0 0,1 1,1
0,1 0,2 1,0 1,3 2,0 2,3 3,1 3,2
```
Impossible:
```
0,0 1,0 2,0 3,1 4,2
0,0 1,0 2,0 1,1
0,1 0,2 1,0 1,3 2,0 2,3 3,1 3,2 2,2
2,0 0,1 2,2 0,3
0,0 2,1 0,2 2,2 -1,1
```
Possible (if not designated, should return 0):
```
0,0 1,0 2,0
0,0 0.3,0.3 0.6,0.6 (should return 45)
0,0 0.1,0.2 0.2,0.4 (should return appx 63.435 (the real value is arctan(2)))
0,0 0,1 2,1 2,2
0,1 0,2 1,0 1,4 2,0 2,4 4,1 4,3
```
I may have missed some interesting test cases. If so, please comment to add them.
This is code-golf, so the shortest-code wins!
[Answer]
# Rev 1: Ruby, 354 bytes
**further golfing thanks to blutorange.**
```
->a{t=s=Math::PI/18E4
d=r=c=0
a=a.map{|e|e-a[0]}
0.upto(36E4){|i|b=a.map{|e|(e/Complex.polar(1,i*s)).rect}.transpose
m,n=b
if n.min>=f=0
l=[m.max-x=m.min,n.max].max
a.each_index{|j|f+=((l-w=n[j])*(x+l-v=m[j])*(x-v)*w)**2}
(1E-9>q=f/l**8)&&(c>0&&(i-d)%9E4%89E3>1E3?c=9E9:0;c+=1;d=i)
q<t&&(r=i)&&t=q;end}
c<101&&a[1]?c<1?'impossible':r%9E4/1.0E3:'unknown'}
```
# Ruby, 392 bytes
```
->(a){
s=Math::PI/18E4
t=1
d=r=c=0
a=a.map{|e|e-a[0]}
(0..36E4).each{|i|
b=a.map{|e|(e/Complex.polar(1,i*s)).rect}.transpose
m=b[0]
n=b[1]
x=m.min
if n.min>=0
l=[m.max-x,n.max].max
f=0
a.each_index{|j|f+=((l-n[j])*(x+l-m[j])*(x-m[j])*n[j])**2}
q=f/l**8
if q<1E-9
c>0&&(i-d)%9E4%89E3>1E3?(c=9E9):0
c+=1
d=i
end
if q<t
r=i
t=q
end
end
}
c>100||a.size<2?'unknown':c<1? 'impossible':r%9E4/1.0E3
}
```
The algorithm is as follows:
-Pick an arbitrary point (the first one) and move that to the origin (subtract the coordinates of this point from all points in the list.)
-Try all rotations of the square about the origin in 0.001 degree increments, through 360 degrees.
-For a given rotation, if all points are above the y axis, draw the smallest possible square around all the points, incorporating the lowest and leftmost point.
-Check if all points are on the edge. This is done with a soft calculation that takes each point, finds the squared distances from all edges, and multiplies them together. This gives a good fit rather than a yes/no answer. It is interpreted that a solution is found if this product divided by sidelength^8 is less than 1E-9. In practice this is less than a degree of tolerance.
-The best fit is taken mod 90 degrees and reported as the correct angle.
Currently the code returns a value of ambiguous if over 100 solutions are found (at 0.001 degree resolution. That's 0.1 degrees of tolerance.)
**first fully working function, in test program**
I left the resolution at 1/10th of the required resolution to make the speed reasonable. There is an error of 0.01 degress on the very last test case.
```
g=->(a){
s=Math::PI/18000
t=1
d=r=-1
c=0
a=a.map{|e| e-a[0]}
(0..36000).each{|i|
b=a.map{|e|(e/Complex.polar(1,i*s)).rect}.transpose
m=b[0]
n=b[1]
x=m.min
if n.min>=0
l=[m.max-x,n.max].max
f=0
a.each_index{|j|f+=((l-n[j])*(x+l-m[j])*(x-m[j])*n[j])**2}
q=f/l**8
if q<1E-9
j=(i-d)%9000
c>0&&j>100&&j<8900?(c=9E9):0
c+=1
d=i
end
if q<t
r=i
t=q
end
end
}
print "t=",t," r=",r," c=",c," d=",d,"\n"
p c>100||a.size<2?'unknown':c<1? 'impossible':r%9000/100.0
}
#ambiguous
#g.call([Complex(0,0)])
#g.call([Complex(0,0),Complex(1,0)])
#g.call([Complex(0,0),Complex(1,0),Complex(0,1)])
#g.call([Complex(0,0),Complex(1,0),Complex(0,1),Complex(1,1)])
#g.call([Complex(0,1),Complex(0,2),Complex(1,0),Complex(1,3),Complex(2,0),Complex(2,3),Complex(3,1),Complex(3,2)])
#impossible
#g.call([Complex(0,0),Complex(1,0),Complex(2,0),Complex(3,1),Complex(4,2)])
#g.call([Complex(0,0),Complex(1,0),Complex(2,0),Complex(1,1)])
#g.call([Complex(0,1),Complex(0,2),Complex(1,0),Complex(1,3),Complex(2,0),Complex(2,3),Complex(3,1),Complex(3,2),Complex(2,2)])
#g.call([Complex(2,0),Complex(0,1),Complex(2,2),Complex(0,3)])
#g.call([Complex(0,0),Complex(2,1),Complex(0,2),Complex(2,2),Complex(-1,1)])
#possible
g.call([Complex(0,0),Complex(1,0),Complex(2,0)])
g.call([Complex(0,0),Complex(0.3,0.3),Complex(0.6,0.6)]) #(should return 45)
g.call([Complex(0,0),Complex(0.1,0.2),Complex(0.2,0.4)]) #(should return appx 63.435 (the real value is arctan(2)))
g.call([Complex(0,0),Complex(0,1),Complex(2,1),Complex(2,2)])
g.call([Complex(0,1),Complex(0,2),Complex(1,0),Complex(1,4),Complex(2,0),Complex(2,4),Complex(4,1),Complex(4,3)])
```
**golfed version, resolution compliant with spec, takes about a minute per call, in test program.**
There's still a pesky error of 0.001 degrees on the last test case. Increasing resolution further would probably eliminate it.
```
g=->(a){ #take an array of complex numbers as input
s=Math::PI/18E4 #step size PI/180000
t=1 #best fit found so far
d=r=c=0 #angles of (d) last valid result, (r) best fit; c= hit counter
a=a.map{|e|e-a[0]} #move shape so that first point coincides with origin
(0..36E4).each{|i| #0..360000
b=a.map{|e|(e/Complex.polar(1,i*s)).rect}.transpose #rotate each element by dividing by unit vector of angle i*s, convert to array...
m=b[0] #...transpose array [[x1,y1]..[xn,yn]] to [[x1..xn],[y1..yn]]...
n=b[1] #...and assign to variables m and n
x=m.min #find leftmost point
if n.min>=0 #if all points are above x axis
l=[m.max-x,n.max].max #find the sidelength of smallest square in which they will fit
f=0 #f= accumulator for errors. For each point
a.each_index{|j|f+=((l-n[j])*(x+l-m[j])*(x-m[j])*n[j])**2} #...add to f the product of the squared distances from each side of the smallest square containing all points
q=f/l**8 #q= f normalized with respect to the sidelength.
if q<1E-9 #consider a hit if <1E-9
c>0&&(i-d)%9E4%89E3>1E3?(c=9E9):0 #if at least one point is already found, and the difference between this hit and the last exceeds+/-1 deg (mod 90), set c to a high value
c+=1 #increment hit count by 1 (this catches infinitely varible cases)
d=i #store the current hit in d
end
if q<t #if current fit is better than previous one
r=i #store the new angle
t=q #and revise t to the new best fit.
end
end
}
c>100||a.size<2?'unknown':c<1? 'impossible':r%9E4/1.0E3 #calculate and return value, taking special care of case where single point given.
}
#ambiguous
puts g.call([Complex(0,0)])
puts g.call([Complex(0,0),Complex(1,0)])
puts g.call([Complex(0,0),Complex(1,0),Complex(0,1)])
puts g.call([Complex(0,0),Complex(1,0),Complex(0,1),Complex(1,1)])
puts g.call([Complex(0,1),Complex(0,2),Complex(1,0),Complex(1,3),Complex(2,0),Complex(2,3),Complex(3,1),Complex(3,2)])
#impossible
puts g.call([Complex(0,0),Complex(1,0),Complex(2,0),Complex(3,1),Complex(4,2)])
puts g.call([Complex(0,0),Complex(1,0),Complex(2,0),Complex(1,1)])
puts g.call([Complex(0,1),Complex(0,2),Complex(1,0),Complex(1,3),Complex(2,0),Complex(2,3),Complex(3,1),Complex(3,2),Complex(2,2)])
puts g.call([Complex(2,0),Complex(0,1),Complex(2,2),Complex(0,3)])
puts g.call([Complex(0,0),Complex(2,1),Complex(0,2),Complex(2,2),Complex(-1,1)])
#possible
puts g.call([Complex(0,0),Complex(1,0),Complex(2,0)])
puts g.call([Complex(0,0),Complex(0.3,0.3),Complex(0.6,0.6)]) #(should return 45)
puts g.call([Complex(0,0),Complex(0.1,0.2),Complex(0.2,0.4)]) #(should return appx 63.435 (the real value is arctan(2)))
puts g.call([Complex(0,0),Complex(0,1),Complex(2,1),Complex(2,2)])
puts g.call([Complex(0,1),Complex(0,2),Complex(1,0),Complex(1,4),Complex(2,0),Complex(2,4),Complex(4,1),Complex(4,3)])
```
Note that for about 30% more code this algorithm could be adapted to work fast: it is obvious that in cases with a finite number of solutions, one of the edges lies flat along a a cube, so all we really have to try is those angles that correspond to each pair of vertices. It would also be necessary to do a bit of wiggling to check there aren't there aren't infinitely many solutions.
[Answer]
# Perl
Hello, here is my humble soution.
Test cases are put in **DATA** stream at the bottom of the file.
The algorithm has grown by a try-error approach.
I admit that it is a broadly heuristic approach, but it is really fast: it resolves all the cases *instantly*.
I am aware there will be some bugs, but up to now it gives correct replies to all the test cases.
I am also aware that the *shortest* code wins, but I am sure this is among the shortest in the *fastest* meaning of the term.
Here is the algorithm
1. examine dots and for each segment between two dots record slope, length, x-intercept, y-intercept
2. find straight lines (i.e. three dots or two adjacent segments) and distinct possible slopes (say them rotations). Keep track of the longest segment available in each line.
3. find all the distances between a segment and a third point (this should be used to point 4). Keep track of minimum non-zero distance.
4. for any four dots (rougly a rectangle) find inner dots
Show solutions:
A. Say "Impossible" if there are one or more inner dots.
B. One Line:
* In case of most of dots in a single line without inner dots, say "Possible"
* In case of dots too close to line, say "Impossible"
C. Two lines:
* Say "Possible" when there is only one possible rotation
* Say "Impossible" when there are more than one rotation
D. No lines: find rotation that fits its 90° rotate segment
* Say "Possible" if only one fits or as many as dots fit.
* Say "Impossible" if more than one fits and not as many as dots
* Say "Unknown" if as many as rotation fit.
Here is the code (all known bugs are resolved)
```
#!/usr/bin/perl
use strict ;
use warnings ;
my $PI = 4*atan2( 1, 1 ) ;
my $EPS = 0.000001 ;
while ( <DATA> ) {
if ( /^\s*#/ ) { print ; next } # print comments
chomp ;
my @dot = split /\s+/ ;
my $n = scalar @dot || next ; # skip empty lines
# too few dots
if ( $n < 3 ) {
print "@dot : Unknown.\n" ;
next
}
my %slop = () ; # segment --> its slope
my %leng = () ; # segment --> its length
my %x0 = () ; # segment --> its line's x-intercept
my %y0 = () ; # segment --> its line's y-intercept
my %side = () ; # slope --> list of segments (with duplicates)
# 1. examine dots
for my $p (@dot) {
my ($px,$py) = split /,/, $p ;
for my $q (@dot) {
next if $p eq $q ;
next if defined ( $slop{ "$q $p" } ) ;
my $segment_name = "$p $q" ;
my ($qx,$qy) = split /,/, $q ;
my $dx = $px - $qx ;
my $dy = $py - $qy ;
my $slope = "inf" ; $slope = $dy / $dx if abs($dx) > 0 ;
my $sd = $dx*$dx+$dy*$dy ;
my $x0 = ( $slope eq 'inf' ? $px : "nan" ) ;
my $y0 = ( abs($slope) > 0 ? $px : "nan" ) ;
$x0 = $qx - $qy / $slope if abs($slope) > 0 ;
$y0 = $qy - $qx * $slope if $slope ne "inf" ;
push @{ $side{ $slope } }, $segment_name ;
$slop{ $segment_name } = $slope ;
$leng{ $segment_name } = sqrt( $sd ) ;
$x0{ $segment_name } = $x0 ;
$y0{ $segment_name } = $y0 ;
}
}
# 2. find straight lines and distinct possible slopes (rotation)
my %line = () ; # slope --> segment name
my %rotation = () ; # slope --> slope itself
my $a_rotation ;
for my $slope ( keys %side ) {
my %distinct = () ;
for my $segment_name ( @{ $side{ $slope } } ) {
$distinct{ $segment_name } = $slope ;
my $rot = $slope eq 'inf' ? '0' : abs( $slope < 0 ? 1/$slope : $slope ) ;
$rotation{ $rot } = $rot ;
$a_rotation = $rot ;
}
for my $a_segm ( keys %distinct ) {
for my $b_segm ( keys %distinct ) {
next if $a_segm eq $b_segm ;
# the two segment has to be adjacent
my ($a1,$a2) = split / /, $a_segm;
my ($b1,$b2) = split / /, $b_segm;
next unless $a1 eq $b1 || $a1 eq $b2 || $a2 eq $b1 || $a2 eq $b2 ;
# the two segment has to have same intercepts
my $x0a = $x0{ $a_segm } ;
my $x0b = $x0{ $b_segm } ;
my $y0a = $y0{ $a_segm } ;
my $y0b = $y0{ $b_segm } ;
next unless $x0a eq $x0b && $y0a eq $y0b ;
# keep the longest segment
my $a_len = 0 ;
$a_len = $leng{ $line{ $slope } } if defined( $line{ $slope } ) && defined( $leng{ $line{ $slope } } ) ;
for my $segm ("$a1 $b1", "$a1 $b2", "$a2 $b1", "$a2 $b2",
"$b1 $a1", "$b2 $a1", "$b1 $a2", "$b2 $a2" ) {
next unless defined ( $leng{ $segm } ) ;
if ( $a_len < $leng{ $segm } ) {
$a_len = $leng{ $segm } ;
$line{ $slope } = $segm ;
}
}
}
}
}
# 3. find distance between a segment and a third point
my %distance = () ; # segment-point --> distance
my %distance_mani = () ; # distance --> array of segment-point
my %min_distance = () ; # segment --> min distance to other dots
for my $segment_name ( keys %slop ) {
my $a = $slop{ $segment_name } ;
my $b = -1 ;
my $c = $y0{ $segment_name } ;
my $z = $x0{ $segment_name } ;
for my $p (@dot) {
next if $segment_name =~ /$p/ ; # skip dots that are in the segment
my ($px,$py) = split /,/, $p ;
my $d = 0 ;
if ( $a ne 'inf' ) {
my $num = ($b * $py) + ($a * $px) + $c ;
my $den = sqrt( $a*$a + $b*$b ) ;
$d = abs( $num ) / $den ;
}
else {
$d = abs( $px - $z );
}
$distance{ "$segment_name $p" } = $d ;
push @{ $distance_mani{ $d } }, "$segment_name $p" ;
if ( $d > 0 ) {
$min_distance{ $segment_name } = $d if !defined ( $min_distance{ $segment_name } ) or $d < $min_distance{ $segment_name }
}
}
}
# 4. find inner dots: pick 4 dots to form a well shaped pseudo-rectangle
# and check for any other dot that is too close to all the 4 sides.
my $fail = 0 ;
RECTANGLE:
for my $a ( @dot ) {
for my $b ( @dot ) {
next if $a eq $b ;
my ($ax,$ay) = split /,/, $a ;
my ($bx,$by) = split /,/, $b ;
next if $ax > $bx || $ay > $by ;
for my $c ( @dot ) {
next if $c eq $a or $c eq $b ;
my ($cx,$cy) = split /,/, $c ;
next if $bx < $cx || $by > $cy ;
for my $d ( @dot ) {
next if $d eq $a or $d eq $b or $d eq $c ;
my ($dx,$dy) = split /,/, $d ;
next if $cx < $dx || $cy < $dy ;
next if $dx > $ax || $dy < $ay ;
for my $e ( @dot ) {
next if $e eq $a or $e eq $b or $e eq $c or $e eq $d ;
my $abe = $distance{ "$a $b $e" } || $distance{ "$b $a $e" } || next ;
my $bce = $distance{ "$b $c $e" } || $distance{ "$c $b $e" } || next ;
my $cde = $distance{ "$c $d $e" } || $distance{ "$d $c $e" } || next ;
my $dae = $distance{ "$d $a $e" } || $distance{ "$a $d $e" } || next ;
my $abd = $distance{ "$a $b $d" } || $distance{ "$b $a $d" } || next ;
my $abc = $distance{ "$a $b $c" } || $distance{ "$b $a $c" } || next ;
my $bca = $distance{ "$b $c $a" } || $distance{ "$c $b $a" } || next ;
my $bcd = $distance{ "$b $c $d" } || $distance{ "$c $b $d" } || next ;
my $cdb = $distance{ "$c $d $b" } || $distance{ "$d $c $b" } || next ;
my $cda = $distance{ "$c $d $a" } || $distance{ "$d $c $a" } || next ;
my $dac = $distance{ "$d $a $c" } || $distance{ "$a $d $c" } || next ;
my $dab = $distance{ "$d $a $b" } || $distance{ "$a $d $b" } || next ;
if ( $abd > $abe && $abc > $abe &&
$bca > $bce && $bcd > $bce &&
$cdb > $cde && $cda > $cde &&
$dac > $dae && $dab > $dae) {
## print " $a $b $c $d --> $e\n";
$fail ++ ;
last RECTANGLE ;
}
}
}
}
}
}
if ( $fail ) {
print "@dot : Impossible.\n" ;
next # DATA
}
my $m = scalar keys %rotation ; # how many distinct slopes
my $r = scalar keys %line ; # how many lines i.e. >3 dots in a straight line
print "@dot : " ;
# most of dots lie in single line without inner dots
if ( $r == 1 ) {
$a_rotation = (keys %line)[0] ;
my $a_segment = $line{ $a_rotation } ;
my $a_dist = $min_distance{ $a_segment } || 0 ;
if ( $a_dist && $a_dist < $leng{ $a_segment } ) {
print "Impossible.\n" ;
}
else {
print "Possible. --> " . sprintf("%.3f deg", 180 / $PI * atan2( $a_rotation, 1 ) ) . "\n" ;
}
next # DATA
}
# two lines
if ( $r == 2 ) {
print "Impossible.\n" if $m > 1 ;
print "Possible. --> " .
sprintf("%.3f deg", 180 / $PI * atan2( $a_rotation, 1 ) ) . "\n" if $m == 1 ; # never?
next ; # DATA
}
# no lines
if ( $r == 0 ) {
# match between segment rotation and other side
my $count = 0 ;
my $numeros = 0 ;
for my $slope ( keys %rotation ) {
my $rot = $slope eq '0' ? 'inf' : -1/$slope ;
if ( exists $side{ $rot } ) {
$count++ ;
my $u = scalar @{ $side{ $rot } } ;
if ( $numeros < $u ) {
$numeros = $u ;
$a_rotation = $slope ;
}
}
}
print "Possible. --> " .
sprintf("%.3f deg", 180 / $PI * atan2( $a_rotation, 1 ) ) . "\n" if $count < 2 or $count == $n ;
print "Unknown.\n" if $count == $m ;
print "Impossible.\n" if $count > 2 && $count != $n && $count != $m;
next # DATA
}
# there are lines
print "lines $r " ;
my $shorter = 0 ;
my $longer = 0 ;
for my $slope ( keys %line ) {
for my $dis ( keys %distance_mani ) {
$shorter++ ;
$longer++ ;
}
}
print "ACK! WHAT IS THIS CASE! n=$n, m=$m, r=$r\n" ;
1 ;
}
1;
__DATA__
# Unknown:
0,0
0,0 1,0
0,0 1,0 0,1
0,0 1,0 0,1 1,1
0,1 0,2 1,0 1,3 2,0 2,3 3,1 3,2
# Impossible:
0,0 1,0 2,0 3,1 4,2
0,0 1,0 2,0 1,1
0,1 0,2 1,0 1,3 2,0 2,3 3,1 3,2 2,2
2,0 0,1 2,2 0,3
0,0 2,1 0,2 2,2 -1,1
# Possible (if not designated, should return 0):
0,0 1,0 2,0 1,2
0,0 1,0 2,0 0.5,2.1
0,0 1,0 2,0
0,0 1,0 2,0 1,2
0,0 0.3,0.3 0.6,0.6
0,0 0.1,0.2 0.2,0.4
0,0 0,1 2,1 2,2
0,1 0,2 1,0 1,4 2,0 2,4 4,1 4,3
```
And here is its ouptut
```
# Unknown:
0,0 : Unknown.
0,0 1,0 : Unknown.
0,0 1,0 0,1 : Unknown.
0,0 1,0 0,1 1,1 : Unknown.
0,1 0,2 1,0 1,3 2,0 2,3 3,1 3,2 : Unknown.
# Impossible:
0,0 1,0 2,0 3,1 4,2 : Impossible.
0,0 1,0 2,0 1,1 : Impossible.
0,1 0,2 1,0 1,3 2,0 2,3 3,1 3,2 2,2 : Impossible.
2,0 0,1 2,2 0,3 : Impossible.
0,0 2,1 0,2 2,2 -1,1 : Impossible.
# Possible (if not designated, should return 0):
0,0 1,0 2,0 1,2 : Possible. --> 0.000 deg
0,0 1,0 2,0 0.5,2.1 : Possible. --> 0.000 deg
0,0 1,0 2,0 : Possible. --> 0.000 deg
0,0 1,0 2,0 1,2 : Possible. --> 0.000 deg
0,0 0.3,0.3 0.6,0.6 : Possible. --> 45.000 deg
0,0 0.1,0.2 0.2,0.4 : Possible. --> 63.435 deg
0,0 0,1 2,1 2,2 : Possible. --> 0.000 deg
0,1 0,2 1,0 1,4 2,0 2,4 4,1 4,3 : Possible. --> 0.000 deg
```
Regards.
Matteo.
]
|
[Question]
[
This is my head:
```
\ /-- -|
/ -\ | | |
\ \ \ \ |
--\ | \ | |
/ |--| / / |
/|- //--| / |
| | || //\ |
| \ /| // \ |
```
It consists of exactly eight hairs. My hair is too long. Please cut each individual strand to a length I specify.
## Input
The main attraction in this section is the actual head of hair. Here's a **graphical, color-coded representation, along with an animation**, for the lazy:
 
And here is a **full specification** for what a set of hairs is:
* The individual hairs, which we will call **strands**, will be made out of the `/`, `\`, `|`, and `-` ASCII characters, henceforth known as **atoms**.
* The entire **head** of hear (all of the strands combined) will be `c` columns by `r` rows, where `c` ≥ 1 and `r` ≥ 2.
* Each strand will...
+ start at the last row of the head (row `r` - 1).
+ have a length `l` where `l` ≥ 2.
* Strands may be parsed with the following method:
1. Start at the bottom of the strand. This will be a `/`, `|`, or `\` atom, which we will call the **root**. (Strands are parsed from left to right, ordered by the root.)
2. Find the atom that points towards the root.
+ A `|` atom points up and down. A `-` atom points left and right (but can never point to the root since only roots can be in the bottom row). A `/` atom points left-down and up-right, and a `\` atom does the opposite.
+ There will always be exactly one atom that points towards the root atom.
3. Find an *unused* atom (one that is not yet part of any strand) that points towards this atom and is also not below this atom (hair can't grow downwards, but sideways is okay).
+ If there are zero, you have reached the end of the strand!
+ If there is one, this is the next atom of the strand. Repeat step 3 with this atom. (This atom is now marked as "used" for the purposes of step 3, since it's part of a strand.)
+ There will never be multiple *unused* atoms here at any point in the head.
The **input format** will be:
* A head of hair. Can be input as-is (multiline input with literal newlines), or with a delimiter of your choice in place of newlines. Note that the head will always be a rectangle; i.e. trailing whitespace will be added as necessary (the weird straight line hair at the right is just to eliminate extra trailing whitespace to avoid confusion).
* A number ≥ 1 specifying how much hair to cut. This will be described in detail in the next section.
You may accept input to a function, use STDIN/STDOUT, etc. (anything [reasonable](http://meta.codegolf.stackexchange.com/a/1326/3808)).
## Output
Your output will be the head of hair with the haircut applied. To give a haircut, simply reduce the length of each strand of hair by the amount specified (which will always be 1 or greater), starting from the endpoint of the hair moving towards the root. However, *always* leave the root intact!
Here's a simple example. Say the input for the head is
```
\
/
|
|
```
With a second input of `2`, you would cut two atoms from the strand and get a result of
```
|
|
```
And with an input of `42`, the output would just be
```
|
```
Note that whitespace before and after the head is completely irrelevant; you can trim extra newlines or you could add more padding. It doesn't matter, as long as the head remains intact. (You may do whatever you want with trailing whitespace as well.)
## Test Cases
For all test cases, the example presented at the very beginning of this post will be used.
Haircut length = 1:
```
/- |
/ \ | |
\ \ \ \ |
--\ | \ | |
/ |-- / / |
|- //--| / |
| | || // |
| \ /| // \ |
```
Length of 3:
```
|
\ |
--\ | \ |
/ |-- / / |
|- // | / |
| || // |
| \ /| // \ |
```
Length of 7:
```
|- / |
| | / |
| \ /| // \ |
```
Length of 1337:
```
| \ /| // \ |
```
## Scoring
This is [code-golf](/questions/tagged/code-golf "show questions tagged 'code-golf'"), so the shortest code in bytes will win!
[Answer]
# JavaScript (E6) 195 ~~212 222 232~~
Using a recursive function R to find the path of each strand and marking the positions starting from 1 for the farest from the root. Then it's easy, in a second pass, to substitute the lower marked position with blanks.
```
F=(h,t,
n=[...h],c=h.search('\n'),
R=p=>[1,-1,c+2,c+1,c].some((d,i)=>n[p-d]=='--\\|/'[i]?n[p-=d]=1:0)&&R(p)+(R[p]=l++)
)=>
n.map((v,p)=>R[p]<t?' ':h[p],n.map((a,p)=>!h[p+c]&a>' '&&R(p,l=0))).join('')
```
**Test** in FireFox/FireBug console
```
head = "\\ /-- -|\n / -\\ | | |\n\\ \\ \\ \\ |\n --\\ | \\ | |\n / |--| / / |\n /|- //--| / |\n| | || //\\ |\n| \\ /| // \\ |";
console.log(F(head,0))
console.log(F(head,1))
console.log(F(head,3))
console.log(F(head,7))
console.log(F(head, 1337))
```
*Output*
```
\ /-- -|
/ -\ | | |
\ \ \ \ |
--\ | \ | |
/ |--| / / |
/|- //--| / |
| | || //\ |
| \ /| // \ |
/- |
/ \ | |
\ \ \ \ |
--\ | \ | |
/ |-- / / |
|- //--| / |
| | || // |
| \ /| // \ |
|
\ |
--\ | \ |
/ |-- / / |
|- // | / |
| || // |
| \ /| // \ |
|- / |
| | / |
| \ /| // \ |
| \ /| // \ |
```
]
|
[Question]
[
# Find X
I was inspired by math questions in which one is asked to "Find X" for a given shape. Originally, I was just going to have the challenge be to print the x and y location of the character 'x' in a String. But I supposed that would be too simple. So I considered the context they were normally in, and decided finding the length of a Line next to the x just seemed appropriate.
Given a string input containing a Diagram of ascii 'lines' as well as a single 'x' and potentially junk characters, print the length of the only line that has an 'x' directly adjecent to it.
## Examples
Input:
```
|
|
|x
|
|
```
Ouput:
```
5
```
Input:
```
|\
| \x
| \
|___\
```
Output:
```
4
```
Input:
```
Diagram of a Wobbly Line:
IRRELEVANTTEXT____
____ ____/
\___/ X ;)
x
```
Output:
```
3
```
Input:
```
______________
/ ____________ \
|/ __________ \|
||/ ________ \||
|||/ ______ \|||
||||/ \||||
|||||/ x |||||
|||||\_____/||||
||||\_______/|||
|||\_________/||
||\___________/|
\_____________/
```
Output:
```
5
```
## Notes
* The Valid line characters are `\/_|`
* `\` connects the top left and bottom right of itself.
* `/` connects the top right and bottom left of itself.
* `_` connects the left and right of itself
* `|` connects the top and bottom of itself
* A line will always be straight, and only consist of one of the line characters repeated n times.
* The x will always be lowercase, and it will always be the only one in the diagram.
* Adjecent refers to the x being exactly one character above, below, or besides.
* The x will always be next to exactly one Line.
* Tabs will never appear in the input.
* Input and Output may be any acceptable format.
* This is Code Golf, so Shortest Code Wins!
* HAVE FUN. DO IT. ENJOY YOURSELF.
[Reference Implementation](https://repl.it/EQ0Z/2)
[Answer]
# Python 3, ~~428~~ ~~408~~ ~~385~~ 378 bytes
Working, but has a ton of potential to be golfed. I'm a bit rusty.
Assumes input is padded with spaces to make a rectangle.
EDIT: Thanks to @Artyer for 23 byte savings!
EDIT2: Wow I completely missed a 6 byte savings. Saved 1 more by swapping sides of an equals check.
```
*i,=map(list,input().split('\n'))
r=c=s=q=e=w=0
o=lambda y,x:len(i[0])>x>=0<=y<len(i)
d='\/_|'
for l in i:
if'x'in l:r=i.index(l);c=l.index('x')
for a,b in(1,0),(0,1),(-1,0),(0,-1):
y,x=r+a,c+b;f=o(y,x)and i[y][x]
if f in d:s=f;w=d.index(f);q,e=y,x
k=lambda y,x,g=[1,1,0,1][w],v=[1,-1,1,0][w]:o(y,x)and s==i[y][x]and(exec('i[y][x]=0')or 1+k(y+g,x+v)+k(y-g,x-v))
print(k(q,e))
```
Expanded version with explanation:
```
inputtt=''' ______________.
/ ____________ \
|/ __________ \|
||/ ________ \||
|||/ ______ \|||
||||/ \||||
|||||/ x |||||
|||||\_____/||||
||||\_______/|||
|||\_________/||
||\___________/|
\_____________/'''
# First, we get the input from STDIN and make it
# into a doubly-nested array
*input_text,=map(list,inputtt.split('\n'))
# A pretty cool Python trick to assign 0 to
# mulitple variables at once.
row=col=line_letter=line_row=line_col=line_char_index=0
# A function to check if a certian row and col is
# in bounds or not. Uses python's comparator chaining
in_bounds=lambda y,x:len(input_text[0])>x>=0<=y<len(input_text)
# A string to store all the line characters.
chars='\/_|'
# Search for the x
for line in input_text:
# If this line contains the x...
if'x'in line:
# Mark the row and column
row=input_text.index(line);col=line.index('x')
# For each direction...
for down,right in(1,0),(0,1),(-1,0),(0,-1):
# Move in that direction
y,x=row+down,col+right
# If the position is in bounds, mark the char at that position
line_found=in_bounds(y,x)and input_text[y][x]
# If the char is a line char, set all the variables saying we found it
if line_found in chars:
line_letter=line_found
line_char_index=chars.index(line_found)
line_row,line_col=y,x
recur=lambda y,x,\
# Find which directions we are supposed to recur in based on the line char
g=[1,1,0,1][line_char_index],v=[1,-1,1,0][line_char_index]:\
# If the char is in bounds and we are still on the line...
in_bounds(y,x)and input_text[y][x]==line_letter and\
# Set the spot to a 0, so we won't go back, increment,
# and recur in both directions
(exec('i[y][x]=0')or 1+recur(y+g,x+v)+recur(y-g,x-v))
# Finally, print the answer
print(recur(line_row,line_col))
```
[Answer]
# JavaScript (ES6), ~~165~~, 155 bytes
EDIT: Inlined *x* and *w*, to save some more bytes.
**Golfed**
(assumes input is padded with spaces to make a rectangle)
```
t=>([k=e=o=1,v=t.search`\n`+2,-1,-v].some(h=>i=({"|":v-1,"_":1,"/":v,"\\":v})[d=t[r=l=t.search`x`+h]]),[...t].map(_=>o+=(k&=t[l-=i]==d)+(e&=t[r+=i]==d)),o)
```
**Expanded**
```
/*
G(<input string,space padded>) => line length
*/
G=t=> {
/*
! Note that these two are inlined, in the "golfed" version !
"w" - line "width"
"x" - index of "x"
*/
x=t.search`x`;
w=t.search`\n`+1;
/*
Locate the "line"
l,r - left cursor, right cursor (for navigating along the line)
k - left stop flag, e - right stop flag
i - increment
d - direction (char)
*/
[k=e=o=1,v=w+1,-1,-w-1].some(h=>i=({"|":w,"_":1,"/":v,"\\":v})[d=t[r=l=x+h]]);
/*
Travel along the line axis in both directions
Note, the stop condition should rather be: while(k|e),
but we iterate over all the chars with map instead (as o is guaranteed to be < # chars),
to save some space
*/
[...t].map(_=>o+=(k&=t[l-=i]==d)+(e&=t[r+=i]==d));
/*
Resulting line length
*/
return o;
};
```
**Test**
```
G=
t=>([k=e=o=1,v=t.search`\n`+2,-1,-v].some(h=>i=({"|":v-1,"_":1,"/":v,"\\":v})[d=t[r=l=t.search`x`+h]]),[...t].map(_=>o+=(k&=t[l-=i]==d)+(e&=t[r+=i]==d)),o);
[
G(
"| \n" +
"| \n" +
"|x\n" +
"| \n" +
"| \n"
),
G(
"|\\ \n" +
"| \\x \n" +
"| \\ \n" +
"|___\\\n"
),
G(
"Diagram of a Wobbly Line:\n" +
"IRRELEVANTTEXT____ \n" +
"____ ____\/ \n" +
" \___\/ X ;) \n" +
" x \n"
),
G(
" ______________ \n" +
"/ ____________ \\\n" +
"|/ __________ \\|\n" +
"||/ ________ \\||\n" +
"|||/ ______ \\|||\n" +
"||||/ \\||||\n" +
"|||||/ x |||||\n" +
"|||||\_____\/||||\n" +
"||||\_______\/|||\n" +
"|||\_________\/||\n" +
"||\___________\/|\n" +
" \_____________\/\n"
)
]
```
Sample output (if you run this in Google Chrome Developer Tools console)
>
> [5, 4, 3, 5]
>
>
>
[Answer]
# Lua, 480 Bytes
Lua, Being the Verbose Language it is, doesn't beat the Python Answer. But it doesn't need to.
```
a=...s={}for _ in a:gmatch"[^\n]*"do s[#s+1]={}for S in _:gmatch"."do if S=="x"then x=#s[#s]+1y=#s end s[#s][#s[#s]+1]=S end end c="\\/_|"X={-1,1,1,0}Y={-1,-1,0,-1}for _,d in pairs({{x-1,y},{x,y-1},{x+1,y},{x,y+1}})do K=d[2]k=d[1]h=s[K]w=h and h[k]C=w and c:find(w)if C then n=1 j=k J=K while true do j=j+X[C]J=J+Y[C]if s[J]and s[J][j]==w then n=n+1 else break end end j=k J=K while true do j=j-X[C]J=J-Y[C]if s[J]and s[J][j]==w then n=n+1 else break end end print(n)break end end
```
Similar to my reference implementation, but takes an actual shot at golfing, and does some things a bit more smartly than before. Still could probably be golfed a bit better though.
## With comments.
```
a=... -- Take the input from the command line.
s={} -- Store the string as a 2D Table, instead of a multiline string.
for _ in a:gmatch"[^\n]*"do -- For each new row.
s[#s+1] = {} -- Make a new sub-table. This is our line.
for S in _:gmatch"."do -- For every character.
if S=="x"then x=#s[#s]+1y=#s end -- If it's an x, mark down the X and Y position of it.
s[#s][#s[#s]+1]=S -- Push the character. This could probably be better golfed.
end
end
c="\\/_|" -- The ascii line characters.
X={-1,1,1,0} -- Their X Directionals.
Y={-1,-1,0,-1} -- Their Y Directionals.
-- These are inversed to get their opposite direction.
for _,d in pairs({{x-1,y},{x,y-1},{x+1,y},{x,y+1}}) do -- For each up down left and right.
K=d[2] -- K = y
k=d[1] -- k = x
h=s[K] -- h = the yth row
w=h and h[k] -- w = the xth character of the yth row, if the yth row exists.
C=w and c:find(w) -- C = the id of the ascii line character, if w existed.
if C then
n=1 -- n = the length of the line.
j=k -- Temp x
J=K -- Temp y
while true do
j=j+X[C] -- Increment j by the directional of the ascii.
J=J+Y[C] -- Ditto. for J
if s[J]and s[J][j]==w then -- if it's still the same.
n=n+1 -- Add 1 to the length.
else
break -- Or stop.
end
end
j=k -- Re-assign the temps as their original.
J=K
while true do
j=j-X[C] -- Search in the other direction.
J=J-Y[C]
if s[J]and s[J][j]==w then
n=n+1
else
break
end
end
print(n) -- Print the length.
break
end
end
```
[Answer]
# JavaScript (ES6), 175
Assuming input is padded with spaces to make a rectangle.
```
s=>(o=>{s.replace(/[_|\\/]/g,(c,p)=>[o,-o,1,-1].map(d=>s[p+d]=='x'?[q,k]=[p,c]:c));for(n=z=k>'_'?o:k>'\\'?-1:k>'/'?o-1:o+1;s[q+=z]==k||z<0&&(n=-1,z=-z);)n++})(~s.search`
`)||n
```
*Less golfed*
```
s=>{
o = ~s.search`\n`; // offset between rows (negated)
// look for a line character near an 'x'
s.replace(/[_|\\/]/g,
(c,p)=> // for each line char 'c' in position 'p'
[o,-o,1,-1].map(d=>s[p+d]=='x' // found a near 'x' ?
?[q,k]=[p,c] // remember char and position
:c)
);
n=0;
z=k>'_'?o:k>'\\'?-1:k>'/'?o-1:o+1; // offset to prev char of line
while (s[q+=z]==k // move to left/top first
|| z<0 && (n=0,z=-z) // at left/top, go back and start counting
)
n++;
return n-1;
}
```
**Test** Dots instead of spaces for clarity
```
f=
s=>(o=>{s.replace(/[_|\\/]/g,(c,p)=>[o,-o,1,-1].map(d=>s[p+d]=='x'?[q,k]=[p,c]:c));for(n=z=k>'_'?o:k>'\\'?-1:k>'/'?o-1:o+1;s[q+=z]==k||z<0&&(n=-1,z=-z);)n++})(~s.search`
`)||n
out=x=>O.textContent+=x
;["|.\n|.\n|x\n|.\n|.\n", "|\\...\n|.\\x.\n|..\\.\n|___\\\n"
,"Diagram of a Wobbly Line:\nIRRELEVANTTEXT...........\n____.....____/...........\n....\\___/.X.;)...........\n......x..................\n"
,"./ ____________ \\\n.|/ __________ \|\n.||/ ________ \\||\n.|||/ ______ \\|||\n.||||/ \\||||\n.|||||/ x |||||\n.|||||\\_____/||||\n.||||\\_______/|||\n.|||\\_________/||\n.||\\___________/|\n. \\_____________/\n"].forEach(s=>out(s+f(s)+'\n\n'))
```
```
<pre id=O></pre>
```
]
|
[Question]
[
## Challenge
Given a number `x` and a number `n`, round number `x` to `n` significant figures and output the result.
## Significant figures
The significant figures of a number are digits that carry meaning contributing to its measurement resolution. This includes all numbers *except* leading zeroes.
Bear in mind that leading zeroes after a decimal point are still *insignificant* figures.
When rounding a digit, you must round away from zero if the following digit is greater or equal than five.
All trailing zeroes after a decimal point are counted as significant.
## Input
The first number will be `x`, the number to be rounded. The second number will be `n`, the number of significant figures you should round `x` to.
`x` will be a number (your code should handle both integers and floating points) between -1,000,000,000 and 1,000, 000,000 inclusive. `n` will be a positive integer between 1 and 50 inclusive. `n` will never be greater than the nunber of digits in `x`.
The input will never be `0` or any form of `0`, e.g. `0.000` or `000`.
## Examples
```
Inputs: 2.6754, 2
Output: 2.7
```
An output of `2.7000` would be invalid because the trailing zeroes after the decimal point are counted as significant figures.
---
```
Inputs: 0.00034551, 4
Output: 0.0003455
```
---
```
Inputs: 50237.1238, 3
Output: 50200
```
Note that this must not have a decimal point.
---
```
Inputs: 2374905, 1
Output: 2000000
```
---
```
Inputs: 543.0489, 4
Output: 543.0
```
---
```
Inputs: 15, 1
Output: 20
```
---
```
Inputs: 520.3, 3
Output: 520
```
If you wish, you can output `520.` instead but not `520.0`.
---
```
Inputs: -53.87, 2
Output: -54
```
---
```
Inputs: 0.0999, 2
Output: 0.10
```
## Rules
Built-in functions and libraries which allow you to round a number to `n` significant figures are disallowed.
## Winning
The shortest code in bytes wins.
[Answer]
# PHP, 130 Bytes
```
<?=number_format($r=round($i=$argv[1],($n=$argv[2])-ceil(log(abs($i),10))),($d=(1+floor(log(abs($r),10))-$n))<0?abs($d):0,".","");
```
PHP, 133 Bytes works with values <1 for the significant figures
```
<?=number_format($r=round($i=$argv[1],($n=$argv[2])-floor(log(abs($i),10))-1),($d=(1+floor(log(abs($r),10))-$n))<0?abs($d):0,".","");
```
PHP, 56 Bytes works but skip unneccessary Zeros
```
<?=round($i=$argv[1],$argv[2]-floor(log(abs($i),10))-1);
```
Someone has stolen or deleted the round function in PHP! To make the challenge more interesting. 127 Bytes
```
<?=ceil($x=($i=$argv[1])*10**(($r=$argv[2])-($l=floor(log(abs($i),10))+1)))-$x<=0.5?ceil($x)*10**($l-$r):floor($x)*10**($l-$r);
```
[Answer]
## Python 3, 83 bytes
(similar to the PHP answer)
```
from math import *
def s(x,n):
y=10**(ceil(log10(abs(x)))-n)
return y*round(x/y)
```
Test cases:
```
tests = [(2.6754,2), (0.00034551, 4), (50237.1238, 3),
(2374905, 1), (543.0489, 4), (15, 1), (520.3, 3), (-53.87, 2)]
print ([s(x,n) for x,n in tests])
```
Output:
```
[2.7, 0.0003455, 50200, 2000000, 543.0, 20, 520, -54]
```
Apart from being slightly longer, another approach that I considered:
```
from math import *
def s(x,n):
z=ceil(log10(abs(x)))
return "%.*f"%(n-z,10**z*round(x/10**z,n))
```
... produces an incorrect output for the input of (15, 1):
```
['2.7', '0.0003455', '50200', '2000000', '543.0', '10', '520', '-54']
```
... due to floating point imprecision in the `round()` function. It seems likely to me that I could find test cases that would break the "round to zero decimal places" method also if I looked hard enough.
Thus, it seems to me that my solution probably isn't 100% correct for all cases and wouldn't be unless it was computed in decimal. This issue may therefore affect solutions in any language that use FP arithmetic.
[Answer]
## Batch, ~~660~~ 652 bytes
```
@echo off
set m=%1.
set s=
if %m:~,1%==- set s=-&set m=%m:~1%
:m
if %m:~,1%==0 set m=%m:~1%&goto m
set d=%m:.=%
:d
if %d:~,1%==0 set d=%d:~1%&goto d
for /l %%i in (1,1,%2) do call set d=%%d%%0
call set r=%%d:~%2,1%%
call set d=%%d:~,%2%%
if %r% leq 4 goto r
set r=
:i
set/ai=1+%d:~-1%
set r=%i:~-1%%r%
set d=%d:~,-1%
if %i% leq 9 set d=%d%%r%&goto r
if not "%d%"=="" goto i
set d=1%r:~1%
set m=1%m%
set m=%m:1.0=.%
:r
if %m:~,2%==.0 set m=%m:.0=.%&set d=0%d%&goto r
set i=0
set p=.
:l
if %m:~,1%==. echo %s%%i%%p%%d%&exit/b
if %i%==0 set i=
if "%d%"=="" set d=0&set p=
set i=%i%%d:~,1%
set d=%d:~1%
set m=%m:~1%
goto l
```
Explanation: Starts by suffixing a `.` to the parameter in case it doesn't have one already, then trims off the sign (which is saved) and any leading zeros. The resulting variable `m` is saved for later because it will tell us the desired magnitude of the result. Any `.`s are then removed, which could result in further leading zeros, so they are removed too. `n` zeros are suffixed to ensure that there are enough digits to round, then the `n`th and first `n` digits are extracted. If the `n`th digit is not 4 or less then we tediously add `1` to the string. If the string overflows then we increase the magnitude by prefixing a `1`, but if it was originally less than `0.1` we do that by removing the `1` we just added and also a `0` after the decimal point. If the magnitude is still less than `1` then we copy the zeros after the decimal point to the result, however if it is `1` or more then we extract the integer portion of the answer, adding extra zeros if necessary to reach the decimal point (which is then deleted as it would show incorrect precision). Finally the sign, integer portion, decimal point and decimal portion are concatenated.
]
|
[Question]
[
Inspired by [this](https://codegolf.stackexchange.com/q/63056/43319) wonderful (based on the number of views and votes) challenge, which, in my humble opinion, has way too few answers.
Given (by any means) a list of strings, return (by any means) a set of letters that, when removed from the given strings, leaves the total length of (what remains of) the strings as small as possible, while keeping each string unique and at least one character long.
**Examples:**
Given "Day" and "day"; return "ay", because the given strings will be "D" and "d" when the characters "ay" are removed.
Given "Hello World!", "Hello world.", and "Hello world"; return "Helo Wrd" gives because the strings will be "!", "w.", and "w" when the characters "Helo Wrd" (with a space) are removed.
Given "century", "decade", "year", "month", "week", "day", "hour", "minute", and "second"; return "centurdowi" because the given words will be "y", "a", "ya", "mh", "k", "ay", "h", "m", "s" when the characters "centurdowi" are removed.
The order and format of the returned set is not important.
[Answer]
## Haskell, ~~138~~ 130 bytes
```
import Data.List
c=concat
f i=snd$minimum[(length$c q,s)|s<-subsequences$nub$c i,q<-[map(filter(`notElem`s))i],nub q==q,all(>"")q]
```
Usage example: `f ["century", "decade", "year", "month", "week", "day", "hour", "minute", "second"]` -> `"centurdoki"`.
This is a brute force approach.
```
s<-subsequences$nub$c i -- concatenate input i to a single string, remove
-- duplicates and make a list of all subsequences
q<-[map(filter(...))i] -- remove chars appearing in subsequence s from all
-- input words, call result q
nub q==q -- keep those s where q has no duplicates (i.e. each
-- resulting string is unique) and
all(>"")q -- contains no empty strings
(length$c q,s) -- make pairs from all kept s, where the first element
-- is the combines length of all strings in q,
-- second element is s itself
snd$minimum -- find minimum of those pairs and discard length
```
Edit: @Seeq helped me saving 8 bytes. Thanks!
[Answer]
# [JavaScript (V8)](https://v8.dev/), 288 bytes
```
s=>(l=[...new Set(s.join``)],g=[],[...Array(2**l[L="length"])].map((x,i)=>l.filter((c,j)=>(i&2**j))).filter(x=>new Set(h=s.map(m=>[...m].filter(n=>!x.includes(n)).join``)).size==s[L]&&h.every(n=>n[L])&&g.push(h.reduce((a,b)=>a+b[L],0))).map(x=>[x,g.shift()]).sort((a,b)=>a[1]-b[1])[0][0])
```
[Try it online!](https://tio.run/##XVA9b8MgEN37KxIPFqQEpZ26YKlShw7ZOnRASCH22cbF2AKc2P3zLsR1K0VC3B3v455o5EW63Kre7y8vc8lmxzKkGaeUGrhuPsAjR5tOmdMJC1IxLkjEXq2VE3re7TQ/skSDqXydCCxoK3uERqIwyzQtlfZgEcpJE2ak0iBoMMYrMLJsXVIzd9O2LIv@rVg5hmXbkSqT66EAh0xQ/8bB1KlvYMzxo0jTmsIF7BT5JjzgNK1oP7ga1dRCMeSAkCTnEEM@ngNODjFH3BhC8JFU1NWq9AiLYNtZ/8fmT2J/DhfmBxEOnnurjEcl4smbnBKySYpQBMYP/8A7aN1tPjuri21kLPM1zvRuvlPmYPxgF1vIZQGxm0DaWNvOhF8OzRXga90cSt0NC67M4G8KB3lnbt7zDw "JavaScript (V8) – Try It Online")
Explanation:
```
s=> // Arrow function with argument s
(l=[...new Set(s.join``)], // Create a set l containing every character in s
// Sets automatically remove duplicates
// This converts the set back to an array, since arrays are easier to work with
g=[], // Create an empty array g
[...Array(2**l[L="length"])] // Create an array with length 2 ** number_of_inputs
.map((x,i)=>l.filter((c,j)=>(i&2**j))) // Populate the array with each combination of characters in l
.filter(x=>new Set(h=s.map(m=> // Filter the array (with each combination being x)
[...m].filter(n=>!x.includes(n)) // For each inputted string, after removing the characters in x
.join``)).size==s[L]&& // Check if the number of unique strings is equal to the number of inputs
h.every(n=>n[L])&& // Ensure every string is at least one character
g.push(h.reduce((a,b)=>a+b[L],0))) // Push the total length to g
.map(x=>[x,g.shift()]) // For each item x in the array, put it in an array with its corresponding item in g
.sort((a,b)=>a[1]-b[1])[0][0]) // Sort the array to find the shortest valid result, and output it
```
[Answer]
# Pyth, 34
Takes input in the format `["century", "decade", "year", "month", "week", "day", "hour", "minute", "second"]`. Golfing tips are appreciated, as always.
```
hh.mlsebfqlQl{eTf!}keTm,dm-kdQy{sQ
```
[Answer]
# Pyth, 24 bytes
```
hols-RNQf<}kJ-RTQ{IJy{sQ
```
[Try it online.](http://pyth.herokuapp.com/?code=hols-RNQf%3C%7DkJ-RTQ%7BIJy%7BsQ&input=%5B%22Hello+World!%22%2C+%22Hello+world.%22%2C+%22Hello+world%22%5D&debug=0) [Test suite.](http://pyth.herokuapp.com/?code=hols-RNQf%3C%7DkJ-RTQ%7BIJy%7BsQ&input=%5B%22Hello+World!%22%2C+%22Hello+world.%22%2C+%22Hello+world%22%5D&test_suite=1&test_suite_input=%5B%22Day%22%2C+%22day%22%5D%0A%5B%22Hello+World!%22%2C+%22Hello+world.%22%2C+%22Hello+world%22%5D%0A%5B%22century%22%2C+%22decade%22%2C+%22year%22%2C+%22month%22%2C+%22week%22%2C+%22day%22%2C+%22hour%22%2C+%22minute%22%2C+%22second%22%5D&debug=0)
Note that the last test case will take a little while to run.
Takes input in array form, like `["Day", "day"]`.
Another interesting one I found and [isaacg](https://codegolf.stackexchange.com/users/20080/isaacg) [improved](https://codegolf.stackexchange.com/questions/67261/remove-letters-while-keeping-strings-unique/67360?noredirect=1#comment163248_67360) (also 24 bytes):
```
-J{sQhlDsM.A#f{ITm-RdQyJ
```
]
|
[Question]
[
In various [Super Mario](https://en.wikipedia.org/wiki/Super_Mario) games [green](http://www.mariowiki.com/Green_Shell) and [red](http://www.mariowiki.com/Red_Shell) [Koopa Troopa](http://www.mariowiki.com/Koopa_Troopa) shells can slide frictionlessly on flat surfaces and destroy [brick blocks](http://www.mariowiki.com/Brick_Block) that are in their way. When a shell hits a brick block the block breaks, turning it into empty space, and the Koopa shell reverses direction. As an example, watch the red shell [here](https://youtu.be/EkPllTegEXc?t=37s).
Suppose a Super Mario level is just one block high and every grid cell is either a brick or empty space, except for the leftmost cell which contains a rightward moving shell. The level is also [periodic](https://en.wikipedia.org/wiki/Periodic_boundary_conditions), so if the shell exits the right or left edge of the level it will reenter on the opposite side. In this situation the shell will continue to bounce off of and break all the brick blocks in the level until there are no more. **How far will the shell have traveled just after the last brick block is broken?**
# Challenge
Write a program or function that takes in a non-negative decimal integer. This number, expressed in binary with no leading zeros (the only exception is 0 itself), encodes the one-block-high level layout. A `1` is a brick block and a `0` is empty space.
The Koopa Shell is inserted at the very left edge of the level and is initially moving right. For example, the level associated with input `39` is
```
>100111
```
because `100111` is 39 in binary, and `>` and `<` represent right and left moving shells respectively.
You need to print or return the total distance traveled by the shell once the very last brick block (a.k.a. `1`) has been broken.
The output for `39` is `7` and the changes in the level look like this:
```
Level Cumulative Distance
>100111 0
<000111 0
>000110 0
0>00110 1
00>0110 2
000>110 3
000<010 3
00<0010 4
0<00010 5
<000010 6
000001< 7
000000> 7 <-- output
```
Similarly, the output for `6` is `1`:
```
Level Cumulative Distance
>110 0
<010 0
001< 1
000> 1 <-- output
```
**The shortest code in bytes wins.**
For reference, here are the outputs for inputs `0` to `20`:
```
0 0
1 0
2 0
3 0
4 0
5 0
6 1
7 1
8 0
9 0
10 1
11 2
12 2
13 1
14 3
15 3
16 0
17 0
18 1
19 3
20 2
```
[And here are the outputs up to input `1000`.](http://pastebin.com/raw.php?i=spTQdNC2)
[Answer]
# CJam, ~~29~~ ~~26~~ 24 bytes
*Thanks to Sp3000 for saving 3 bytes.*
```
q~2b{_1&}{W\({%}*0+}w],(
```
[Test suite.](http://cjam.aditsu.net/#code=q~)%7Bs%3AQ%3B%0A%0AQ~2b%7B_1%26%7D%7B(%7BW%250%2B%7D%7B0%2B_%7D%3F%7Dw%5D%2C(%0A%0A%5DoNo%7D%2F&input=20) (This prints all results from 0 to the integer given on STDIN.)
## Explanation
This turns the spec on its head a bit: instead of moving the shell through the binary string, we shift and reverse the binary string such that the shell is always at the front, pointing to the right:
```
q~ e# Read and evaluate the input.
2b e# Convert to base-2 to get the "level".
{_1&}{ e# While there is a 1 in the level...
W\ e# Put a -1 below the level.
( e# Pull off the first digit, i.e. the cell the shell is pointing at.
{ e# If it's a 1 (i.e. a brick)...
% e# Reverse the level, consuming the -1. This isequivalent to reversing the
e# shell in place.
}*
0+ e# Append a zero. If the cell was a brick, this just replaces it with an empty
e# cell. Otherwise, this rotates the level by one cell. This is equivalent
e# to moving the shell one cell through the periodic level.
e# Note that if the leading cell was 0, the -1 remains on the stack.
}w
],( e# Wrap the stack in an array, get its length and decrement.
```
[Answer]
# Pyth, 24 bytes
```
&.WsH_XZeaYxZ1 0jQ2ssPBY
```
Try it online: [Demonstration](http://pyth.herokuapp.com/?input=39&code=%26.WsH_XZeaYxZ1%200jQ2ssPBY&test_suite_input=0%0A1%0A2%0A3%0A4%0A5%0A6%0A7%0A8%0A9%0A10%0A11%0A12%0A13%0A14%0A15%0A16%0A17%0A18%0A19%0A20&test_suite=0) or [Test Suite](http://pyth.herokuapp.com/?input=39&code=%26.WsH_XZeaYxZ1%200jQ2ssPBY&test_suite_input=0%0A1%0A2%0A3%0A4%0A5%0A6%0A7%0A8%0A9%0A10%0A11%0A12%0A13%0A14%0A15%0A16%0A17%0A18%0A19%0A20&test_suite=1)
The following 22 bytes code should also do the trick. It doesn't work currently, due to a bug in the Pyth compiler.
```
&u_XGeaYxG1ZjQ2)ssPBPY
```
edit: Bug fixed, but of course the solution doesn't count.
Try it online: [Demonstration](http://pyth.herokuapp.com/?code=%26u_XGeaYxG1ZjQ2%29ssPBPY&input=39&test_suite_input=0%0A1%0A2%0A3%0A4%0A5%0A6%0A7%0A8%0A9%0A10%0A11%0A12%0A13%0A14%0A15%0A16%0A17%0A18%0A19%0A20&debug=0) or [Test Suite](http://pyth.herokuapp.com/?code=%26u_XGeaYxG1ZjQ2%29ssPBPY&input=39&test_suite=1&test_suite_input=0%0A1%0A2%0A3%0A4%0A5%0A6%0A7%0A8%0A9%0A10%0A11%0A12%0A13%0A14%0A15%0A16%0A17%0A18%0A19%0A20&debug=0)
### Explanation:
Alternating from the front and the back I do the following:
* I search for a 1
* Remember this index by putting it in a list
* Update this 1 to a 0
When there are no 1s left, I calculate the distance. Important is: The shell moves each distance in the list twice (forward and backward), except the last distance.
```
&.WsH_XZeaYxZ1 0jQ2ssPBY implicit: Y = empty list
jQ2 convert input number to binary
.WsH start with Z=^;
while the sum(Z) > 0, apply the the following to Z:
xZ1 index of 1 in Z
aY append this to Y
e take the last element of Y (=this index)
XZ 0 set this 1 (at index ^) in Z to 0
_ and revert the order of Z
this returns a list of zeros
& don't print ^, print the next thing
PBY creates the list [Y, Y[:-1]]
s combine these lists
s sum up the distances
```
]
|
[Question]
[
We have been [cloning](https://codegolf.stackexchange.com/questions/24134/create-a-simple-2048-game-clone) 2048, [analyzing](https://codegolf.stackexchange.com/questions/24589/would-this-number-make-a-good-2048-combo) 2048, but why haven't we played it yet? Write a 555 byte javascript snippet to play 2048 automatically, the best score after an hour will count (see scoring below).
# Setup:
Goto [2048](http://gabrielecirulli.github.io/2048/) and run:
```
a = new GameManager(4, KeyboardInputManager, HTMLActuator, LocalStorageManager);
```
`a` is the object to control the game.
# Rules:
After setup you may run 555 bytes of javascript from the console to control the game. The source code of the game can be [found here](http://gabrielecirulli.github.io/2048/js/game_manager.js) (including comments).
* It may only do things which are possible for the user:
+ `a.move(n)`
to trigger a key action in any of the 4 directions.
- 0: up, 1: right, 2: down, 3: left
+ `a.restart()`
to restart the game. Restarting is allowed in the middle of the game.
* Information about the state of the game can be found in `a.grid.cells`. This information is read-only
* Hooking into any of the functions is allowed, altering their behaviour in any way is not (or changing any other data)
* Moving is allowed only once every 250ms
# Example
Just a very simple example to start from. Without comments and enters **181 bytes**.
```
//bind into new tile function and change m(ove) variable when a tile was moved
b = a.addRandomTile.bind(a);
m = !1;
a.addRandomTile = function() { m = !0; b(); };
//number of move fails
mfs = 0;
setInterval(function() {
//set global moved tracking variable to false
m = !1;
a.move(Math.floor(4 * Math.random()));
m || mfs++;
//restart after 10 moves failed
10 < mfs && (mfs = 0, a.restart());
}, 250);
```
# Scoring and results
I will be running the snippets for one hour straight and the best score will count. Indeed there is a chance that `randombot` above will win that way, but 1 hour should be enough to beat it:
* **King** `Bottomstacker VII`: **9912**
* *Queen* `Bottomstacker V`: **9216**
* *Prince* `Bottomstacker II`: **7520**
* *Lord* `Bottom and Right`: **6308**
* *Peasant* `Randombot`: **1413**
* ~~`Bottomstacker IV`: **12320**~~ *Disqualified for making two moves in one interval (within 250ms)*
# FAQ
* Why is this challenge not language agnostic through the terminal?
+ For the simple reason that it is more fun like this. Watching a game play itself graphically is simply a lot more mesmerizing than seeing a console spit out numbers. Even knowing no javascript you should be able to join into this challenge as it isn't about language features primarily (just use [this tool](http://closure-compiler.appspot.com/home) to minimize the code)
[Answer]
I can't code javascript, so I stole your answer.
```
//bind into new tile function and change m(ove) variable when a tile was moved
b = a.addRandomTile.bind(a);
m = !1;
a.addRandomTile = function() { m = !0; b(); };
//number of move fails
mfs = 0;
c=1;
setInterval(function() {
//set global moved tracking variable to false
m = !1;
a.move(c)
c++
if (c>3) {c=1}
m || mfs++;
//restart after 10 moves failed
10 < mfs && (mfs = 0, a.restart());
}, 250);
```
It uses the strategy I also use.
EDIT: Nice, it just beat your score after about 5 minutes on my machine :D
EDIT:
Forgot to move down twice instead of just once, this is the code you should use:
```
a = new GameManager(4, KeyboardInputManager, HTMLActuator, LocalStorageManager);
//bind into new tile function and change m(ove) variable when a tile was moved
b = a.addRandomTile.bind(a);
m = !1;
a.addRandomTile = function() { m = !0; b(); };
//number of move fails
mfs = 0;
c=1;
setInterval(function() {
//set global moved tracking variable to false
m = !1;
if (c<=3) {n=c}
else {n=2}
a.move(n)
c++
if (c>4) {c=1}
m || mfs++;
//restart after 10 moves failed
10 < mfs && (mfs = 0, a.restart());
}, 250);
```
Also, there's a bug in it that it restarts when it's not needed, but I'm not sure how to fix this.
EDIT: It currently has a highscore of 3116 (after 3 minutes). I think it's safe to say this algoritm is better than just doing random moves.
EDIT Newer version:
```
a = new GameManager(4, KeyboardInputManager, HTMLActuator, LocalStorageManager);
//bind into new tile function and change m(ove) variable when a tile was moved
b = a.addRandomTile.bind(a);
m = !1;
a.addRandomTile = function() { m = !0; mfs=0; b(); };
//number of move fails
mfs = 0;
c=1;
setInterval(function() {
//set global moved tracking variable to false
m = !1;
if (c<=3) {n=c}
else {n=2}
a.move(n)
c++
if (c>4) {c=1}
m || mfs++;
//up after 5 moves
5 < mfs && (a.move(0));
//restart after 10 moves failed
10 < mfs && (mfs = 0, a.restart());
}, 250);
```
EDIT: Another new version, this one moves down directly after moving up.
```
a = new GameManager(4, KeyboardInputManager, HTMLActuator, LocalStorageManager);
//bind into new tile function and change m(ove) variable when a tile was moved
b = a.addRandomTile.bind(a);
m = !1;
a.addRandomTile = function() { m = !0; mfs=0; b(); };
//number of move fails
mfs = 0;
c=1;
setInterval(function() {
//set global moved tracking variable to false
m = !1;
if (c<=3) {n=c}
else {n=2}
a.move(n)
c++
if (c>4) {c=1}
m || mfs++;
//up after 5 moves
5 < mfs && (a.move(0), c=4);
//restart after 10 moves failed
10 < mfs && (mfs = 0, a.restart());
}, 250);
```
EDIT: Update: it just broke my personal record with a pretty crazy score of 12596.
EDIT: Hey, I'm bottomstacker :D
Also:
```
b=a.addRandomTile.bind(a);m=!1;a.addRandomTile=function(){m=!0;mfs=0;b()};mfs=0;c=1;setInterval(function(){m=!1;n=3>=c?c:2;a.move(n);c++;4<c&&(c=1);m||mfs++;5<mfs&&(a.move(0),c=4);10<mfs&&(mfs=0,a.restart())},250);
```
(Not actually a change, just compressed.)
5th time's a charm? Not sure. Anyways:
```
//bind into new tile function and change m(ove) variable when a tile was moved
b = a.addRandomTile.bind(a);
m = !1;
a.addRandomTile = function() { m = !0; mfs=0; b(); };
//number of move fails
mfs = 0;
c=1;
setInterval(function() {
//set global moved tracking variable to false
m = !1;
if (c<=3) {n=c}
else {n=2}
a.move(n)
c++
if (c>4) {c=1}
if (c==0) {c=4}
m || mfs++;
//up after 5 moves
5 < mfs && (c=0);
//restart after 10 moves failed
10 < mfs && (mfs = 0, a.restart());
}, 250);
```
and:
```
b=a.addRandomTile.bind(a);m=!1;a.addRandomTile=function(){m=!0;mfs=0;b()};mfs=0;c=1;setInterval(function(){m=!1;n=3>=c?c:2;a.move(n);c++;4<c&&(c=1);0==c&&(c=4);m||mfs++;5<mfs&&(c=0);10<mfs&&(mfs=0,a.restart())},250);
```
Another new version:
```
a = new GameManager(4, KeyboardInputManager, HTMLActuator, LocalStorageManager);
//bind into new tile function and change m(ove) variable when a tile was moved
b = a.addRandomTile.bind(a);
m = !1;
a.addRandomTile = function() { m = !0; mfs=0; b(); };
//number of move fails
mfs = 0;
c=1;
setInterval(function() {
//set global moved tracking variable to false
m = !1;
if (c<=3) {n=c}
else {n=2}
a.move(n)
c++
if (c>4) {c=1}
if (c==0) {c=4}
m || mfs++;
//up after 5 moves
5 < mfs && (c=0);
//Found this in the source, as the criteria for a gameover. Might as well reset then ;)
if (!a.movesAvailable()) {
a.restart()
}
}, 250);
```
and:
```
a=new GameManager(4,KeyboardInputManager,HTMLActuator,LocalStorageManager);b=a.addRandomTile.bind(a);m=!1;a.addRandomTile=function(){m=!0;mfs=0;b()};mfs=0;c=1;setInterval(function(){m=!1;n=3>=c?c:2;a.move(n);c++;4<c&&(c=1);0==c&&(c=4);m||mfs++;5<mfs&&(c=0);a.movesAvailable()||a.restart()},250);
```
(I hope it's not too much of a problem that this continues behind the gameover screen? I think you could add an `a.over=0` somewhere that gets executed often. I'll figure it out someday.)
EDIT (again):
I dropped the standard gameover way and reverted to the old way of doing things. I'm now testing out an addition that'll always merge if there are 2 tiles of 16 or more together:
```
a = new GameManager(4, KeyboardInputManager, HTMLActuator, LocalStorageManager);
b = a.addRandomTile.bind(a);
m = !1;
a.addRandomTile = function() {
m = !0;
mfs = 0;
b();
};
mfs = 0;
c = 1;
setInterval(function() {
m = !1;
l = 8;
for (x = 0;x < 4;x++) {
for (y = 0;y < 4;y++) {
t1 = a.grid.cellContent({x:x, y:y});
t2 = a.grid.cellContent({x:x, y:y + 1});
t3 = a.grid.cellContent({x:x + 1, y:y + 1});
if (t1 & t2) {
if (t1.value == t2.value) {
if (t1.value > l) {
l = t1.value;
c = 2;
}
}
if (t1 & t3) {
if (t1.value == t2.value) {
if (t1.value > l) {
l = t1.value;
}
}
}
}
}
}
if (c <= 3) {
n = c;
} else {
n = 2;
}
a.move(n);
c++;
if (c > 4) {
c = 1;
}
if (c == 0) {
c = 4;
}
m || mfs++;
5 < mfs && (c = 0);
10 < mfs && (mfs = 0, a.restart());
}, 250);
```
[Answer]
# Right and Down bot: 345 bytes
Short version
```
b=a.addRandomTile.bind(a);m=!1;t=250;d=!0;a.addRandomTile=function(){m=!0;b();d&&setTimeout(c,t)};c=function(){d=!1;a.move(2);setTimeout(function(){m=!1;d=!0;a.move(1);m||setTimeout(function(){a.move(0);m?a.grid.cells[3][0]&&a.grid.cells[3][3]&&setTimeout(function(){a.move(1)},t):setTimeout(function(){a.move(3);m||a.restart()},t)},t)},t)};c();
```
Long version
```
a = new GameManager(4, KeyboardInputManager, HTMLActuator, LocalStorageManager);
b = a.addRandomTile.bind(a);
m = !1;
t = 250;
d = !0;
a.addRandomTile = function() {
m = !0;
b();
d && setTimeout(c, t);
};
c = function() {
d = !1;
a.move(2);
setTimeout(function() {
m = !1;
d = !0;
a.move(1);
m || setTimeout(function() {
a.move(0);
m ? a.grid.cells[3][0] && a.grid.cells[3][3] && setTimeout(function() {
a.move(1);
}, t) : setTimeout(function() {
a.move(3);
m || a.restart();
}, t);
}, t);
}, t);
};
c();
```
# In words
Move down, then right, if you can't move, move up (or if you can't, move left), if both the top right and bottom right corner is filled, move right otherwise start over.
# Current highscore
My own best score was 7668, but that was run at far greater speed than `t=250` (and thus indirectly longer than an hour).
[Answer]
Somehow I ran across this older contest this morning, and since I love 2048, I love AI, and JS is one of the few languages I currently know well, I figured I'd give it a shot.
# GreedyBot (~~607~~ 536 bytes)
Short version:
```
C=function(x,y){return a.grid.cellContent({x:x,y:y})},h=[[1,3,2,0],[2,1,3,0]],V='value',A='addRandomTile';a=new GameManager(4,KeyboardInputManager,HTMLActuator,LocalStorageManager);b=a[A].bind(a);m=!1;f=d=X=Y=0;a[A]=function(){m=!0;f=0;b()};setInterval(function(){m=!1;for(var c=X=Y=0;4>c;c++)for(var e=0;4>e;e++)if(u=C(c,e),!!u){for(q=e+1;4>q;){v=C(c,q);if(!!v){u[V]==v[V]&&(Y+=u[V]);break}q++}for(q=c+1;4>q;){v=C(q,e);if(!!v){u[V]==v[V]&&(X+=u[V]);break}q++}}f<4&&a.move(h[X>Y+4?0:1][f]);m&&(f=0);m||f++;15<f&&(f=0,a.restart())},250);
```
Long version (outdated):
```
a = new GameManager(4, KeyboardInputManager, HTMLActuator, LocalStorageManager);
b = a.addRandomTile.bind(a);
m = !1;
f = d = X = Y = 0;
a.addRandomTile = function() { m = !0; f = 0; b(); };
setInterval(function() {
m = !1;
X = Y = 0;
for(var x=0;x<4;x++) {
for(var y=0;y<4;y++) {
u = a.grid.cellContent({x:x, y:y});
if(u==null){continue;}
q = y+1;
while(q < 4) {
v = a.grid.cellContent({x:x,y:q});
if(v!=null){
if(u.value==v.value){
Y+=u.value;
}
break;
}
q++;
}
q = x+1;
while(q < 4) {
v = a.grid.cellContent({x:q,y:y});
if(v!=null){
if(u.value==v.value){
X+=u.value;
}
break;
}
q++;
}
}
}
if(X>=Y){
if(f==0)
a.move(1);
else if(f==1)
a.move(3);
else if(f==2)
a.move(2);
else if(f==3)
a.move(0);
} else {
if(f==0)
a.move(2);
else if(f==1)
a.move(0);
else if(f==2)
a.move(1);
else if(f==3)
a.move(3);
}
if(m)f=0;
m || f++;
if(15 < f) f=0,a.restart();
}, 250);
```
The longer version was not golfed at all (other than shrinking variable names), so it could be shortened quite a bit while still being readable. The shorter version was created using Closure Compiler (thanks for the link!), which ended up at 650. With some custom modifications on my part, I was able to shave off another ~~43~~ 114 bits.
Basically, it searches for through the grid for possible moves, and whenever it finds one, adds its value to either the horizontal or vertical total. After searching through every possible move, it determines which direction it should move, based on if the H or V total is higher, and the directions it has already tried. Right and Down are the first choices.
Looking back at this, I realize now that if either total is non-zero, the first attempt at sliding the tiles in that direction is guaranteed to succeed. Perhaps I could simplify the move-deciding section towards the end based on this.
I left this program running for an hour and ended up with a high score of `6080`. However, in one of the trial runs (pre-minification), it managed a high score of `6492`, only 128 behind my personal best of `6620`. Its logic could be greatly improved by having it move left-down occasionally, as the numbers tend to pile up like this:
```
2 4 8 16
4 8 16 32
8 16 32 64
16 32 64 128
```
(**EDIT:** I left it running a while longer, and it managed some `7532` points. Darn, my program is smarter than me....)
One more interesting tidbit: in one of my glitched attempts at creating something useable, somehow it ended up so that anytime *any* two tiles were in the same row or column, they were combined. This led to interesting developments as the random 2s or 4s would repeatedly combine with the highest tile, doubling it every time. One time, it somehow managed to score over 11,000 in 15 seconds before I shut it off.... XD
Any suggestions for improvement are very welcome!
[Answer]
# Windshield Wipers: 454 bytes
Simply goes Right, Up, Left, Up... repeating (just like the wipers on a car) unless it gets jammed. If it gets jammed, it will attempt to turn off the wipers and turn them back on. Highest score I got in an hour was 12,156 -- However, most of the scores are somewhere between 3k - 7k.
It will output the score into the console after every attempt.
```
var move = !1;
var bad = 0;
var c = 0;
var b = a.addRandomTile.bind(a);
a.addRandomTile = function() {
b();
move=!0;
bad=0;
}
setInterval(function() {
if (!move) bad++;
if (c>3) c=0;
move = !1;
if (c==3) {a.move(0);c++;}
if (c==2) {a.move(3);c++;}
if (c==1) {a.move(0);c++;}
if (c==0) {a.move(1);c++;}
if (bad>10) {a.move(2);}
if (!a.movesAvailable()) {console.log("Score: "+a.score);a.restart();}
}, 250);
```
[Answer]
# UpAndLeftBot
As title suggests, moves up & left by stealing [David Mulder's work](https://codegolf.stackexchange.com/a/25229/11376) & swapping some numbers (I don't know jack about Javascript, so best I can do is this).
```
a = new GameManager(4, KeyboardInputManager, HTMLActuator, LocalStorageManager);
b = a.addRandomTile.bind(a);
m = !1;
t = 250;
d = !0;
a.addRandomTile = function() {
m = !0;
b();
d && setTimeout(c, t);
};
c = function() {
d = !1;
a.move(0); // a.move(2)
setTimeout(function() {
m = !1;
d = !0;
a.move(3); // a.move(1)
m || setTimeout(function() {
a.move(2); //a.move(0)
m ? a.grid.cells[3][0] && a.grid.cells[3][3] && setTimeout(function() {
a.move(3); // a.move(1)
}, t) : setTimeout(function() {
a.move(1); // a.move(3)
m || a.restart();
}, t);
}, t);
}, t);
};
c();
```
]
|
[Question]
[
Giving **`n`**(any amount) of points `(x,y)`. What's the minimum amount of circles required to cross every point given?
## Task
Your program will get `n` (you can have `n` as part of input or use EOF instead) points `(x,y)`.
The points might at same place => `(x1,y1) = (x2,y2)` **can happen**
`x` and `y` will be *integer* of range `-10000~10000`, while `n`, if you need it, will be *integer* too.
You should output an integer `A` which represent the minimum amount of circle needed to intersect all of the points. Those circle are not required to intersect each other.
## Explanation
For example:
1, 2 points will need 1 circle only to be sure that the points touch the circles boundary
but 3, 4 points may need 2 circles, or 1 (Determined by where the points are)
```
Basic test cases:
(10,10), (0,5), (0,0), (5,10) => 1 circle
(10,10), (5,5), (0,0), (5,10) => 2 circles
(1,1), (2,2), (5,3), (-1,5), (0,0) => 2
(0,0), (1,1), (2,2), (3,3), (4,4), (5,5) => 3
```
**Line are NOT considered as a circle**
If there are 3 points `(0,0)` `(5,5)` `(10,10)`. Then the answer would be `2` since those 3 points forms a line if you try to force a circle out of it.
## Rules
* Input can be taken in any convenient format.
* Output can be in any convenient format as well. As long as it follow the input-reversed input order.
* Standard Loopholes are forbidden.
## Scoring
Golf your way to the shortest code!
[Answer]
# [Haskell](https://www.haskell.org/), ~~252~~… 203 bytes
```
minimum.map g.permutations.nub
g[]=0
g(p:q:r)=1+g(snd$span(p#q$r!!0)r)
g _=1
(a#b)c d|t<-c!a?j(b!a)=t!!1/=0&&b!d?t?j(c!d)!!1==0
j[x,y]=[x,-y]
[x,y]?[z,t]=[x*z-y*t,x*t+y*z]
(!)=zipWith(-)
import Data.List
```
[Try it online!](https://tio.run/##bZDLbsIwEEX3/gobomITGxIeG4Rh0yX7LtKoch4EU@KYxEgk4tubOoG2QupmRnPnzJ2xD6L6TE@nVua6KA18FUZMdrIyYM/f21wqmV/ySS40zCY6LfOLEUYWqpqoSwSyIOQeyLBenVcl4b6b4UolTqWFwnp4dkqEPFISkMEP7gMshhGJYXIzaxYjsT3iCAnCDUL@lHsvLxFKtsaqMUqI1bi1PgZXWofcRlaHoC@2QUNNJ40bVo8NvY6NW4@bEGBEeCP1mzQHzAhg7Pk9bS6k4kkBIMSSFmTN@jOnfMRHZO1sstTspEpt@5QaqAupTMWDfuUN22gHylQkziAYuK503UE4CC3MWIcLVUEO@35SFhrOYLdHl9bE2T/MrNCd0GLfo75HKMQeXd5TXy07FfINtD/1iyz/R2YWoX4nzejs3pl3ifl//IN7jD7j8zu@oIufJR09h1/x/iSyqmWx1t8 "Haskell – Try It Online")
The relevant function is `minimum.map g.permutations.nub`, which takes a list of points as input (each point as a list `[x,y]`) and returns an integer as output.
This solution uses only integer arithmetic, and therefore does not suffer from accuracy problems stemming from floating point errors.
## How?
Coming soon, after I finish golfing this and convincing myself that the formulas are right.
[Answer]
# [Wolfram Language (Mathematica)](https://www.wolfram.com/wolframscript/), 86 bytes
-5 bytes thanks to @att.
```
CircleThrough@#/.{_@{_.,_.}|_Circle:>1,_:>Min[#+Reverse@#&[#0/@Subsets[#][[2;;-2]]]]}&
```
[Try it online!](https://tio.run/##fY1JC8IwEIXv/oqBQC@mS7pcKpaAZ8HtFkqoJbUBF2hTLzG/vcbainhwLjNv3vdmLoWqxaVQsiz6Cpb9SjblWRzq5tadaop8T3OquYe5Zx78baYZwTzN1vLK0Hwn7qJpBUUOQ4FP992xFaplKGcsXCzcMLdlnH7bSaHYppFXxRC4GVQWyXNwwKczAK01CTCQwGDQdkjGPuhkMAy2HHxzyX/Oqtc2xBCObvTqLvmOTfR04zcVjakYQ/z5aUz/BA "Wolfram Language (Mathematica) – Try It Online")
]
|
[Question]
[
It's the end of the year, you and your friends have just received your grades and ranks for the GOLF101 class. On a chat group, everyone sends their grade and rank to see who's got the best one.
**Problem:** someone is lying.
Here is an excerpt from the chat:
```
<A> I'm ranked 1 with a grade of 85.
<B> Ranked 3, got 50.
<C> Ranked 1st, prof. gave me 65/100.
<D> Got ranked second with 70/100
```
Obviously here, student C is lying (at least) on their rank; they can't be 1st with a grade of 65 since both A and D got a better grade.
There can also be cases where someone is lying but we can't know who, specifically.
```
Rank | Grade
-------------
2 71
1 80
3 60
2 70
```
Here, one of the two rank-2 students is lying (since two students can't have the same rank while having different grades) but we can't know which one.
# Challenge
Create a function or program that, when given a sequence of (rank, grade) tuples which contains exactly one *lie*, returns the index of the *lie* in the list or a sentinel value if is impossible to know.
A *lie* is a tuple that, when removed from the list, makes the list valid (i.e. without any conflicting ranks/grades).
A valid list contains **all the possible ranks starting from 1** (or 0 if you use 0-indexing), so the rank sequence `1 2 3` is valid while `2 3 4` is not. The only way to not have every possible rank is when there are equal grades, in which case you can get sequences like `1 2 2` or `1 2 3 3 3`.
Multiple tuples may have the same grade, in which case they will have the same rank, and other tuples' ranks will not be affected. Two tuples having the second-best grade will lead to the sequence `1 2 2 4 ...`.
The input format is not fixed, you may use whatever is easier to parse for your language (a 2D int array, a list of tuples, a list of strings containing space-separated ints). The logic is more important than the parser's implementation details.
The output format is not fixed either. The "index" returned may be 0-based or 1-based, and the sentinel value can be anything that is clearly distinguishable from an index (if you're using 1-based indexing, 0 is a valid sentinel value).
# Test Cases
```
Rank | Grade
-------------
2 71
1 80
3 60
2 70
```
**Output**: impossible to know
```
Rank | Grade
-------------
1 85
3 50
1 65
2 70
```
**Output**: third student
```
Rank | Grade
-------------
1 85
3 50
1 65
2 70
```
**Output**: third student
Additional cases, thanks to @tsh:
* `[(1, 100), (2, 60), (3, 90), (3, 90)]` -> invalid input because we can't remove a single item to get a valid list
* `[(1, 100), (1, 100), (2, 90), (3, 90)]` -> fourth (if we remove the third we get an invalid list with ranks [1, 1, 3])
This is [code-golf](/questions/tagged/code-golf "show questions tagged 'code-golf'"), so the lowest byte count for each language wins!
**EDIT:** printing multiple values is a valid sentinel as long as you specify it. 0-indexing for ranks is fine too.
[Answer]
# [J](http://jsoftware.com/), 49 47 22 bytes
```
[:I.1(-:\:~i.])/@|:\.]
```
[Try it online!](https://tio.run/##VY5RS4RAFIXf51ccFFaNHGcWtLogLAVBED30qhLizqohDjEjFIV/3Ua3fejhXi7nHr5z3hePByfkhADXECA3McfD6/PjUtATl2FMJc09r6Lk8EMlr5aIvdxz6OEIo4fJ9nrchNV9CP1Z5tJ3bhmGMt/54nvmCY/mq4RiKkoqLhjW5rwgnPC2R1WiYkw1ncYeOVrX4TZ1ZyrclaWQuBFsC7HK2H5sYbvawhvU2NoOvcGoLdRn3djhC@pjqgdYDenRGSox0853XAeSK1w4eCbO3P8OJ4r1ka2Wu7@1JZsuMDBT27oK6rg1QVMbxZZf "J – Try It Online")
-14 bytes after reading [xigoi's idea](https://codegolf.stackexchange.com/a/219540/15469) of comparing the first index matches to the ranks.
Thanks to tsh for a test case showing that we needed "length not equal to 1" rather than "length greater than 1" as the failure criterion.
Returns 0-based index if exactly one liar is found, and 0 or multiple values otherwise. Takes "length" by 2 matrix with 0-indexed rank list as left column, score list as right column.
* `1...\.]` For each 1-item outfix (list with item removed), apply the verb...
* `(...)/@|:` Transpose and put the verb in parens between the two rows, so that the rank list is its left arg, and the score list is its right arg.
* `-:\:~i.]` Does the rank list match `-:` the first index of the score list `i.]` within the score list sorted descending `\:~`? We now have a 0-1 list, where 1 indicates a liar.
* `[:I.` Return the indexes of all ones.
[Answer]
# [Jelly](https://github.com/DennisMitchell/jelly), 15 bytes
```
ṙJṖZNÞiⱮḷ⁼ʋ/Ɗ€T
```
[Try it online!](https://tio.run/##y0rNyan8///hzpleD3dOi/I7PC/z0cZ1D3dsf9S451S3/rGuR01rQv4fbgdS//9Hc0VHW5jqGMbqRJsa6BgDKTMIz9xAxyg2VgcobW4IZOlEWxiAxc0gqmDSsQA "Jelly – Try It Online")
I'm pretty sure it works correctly with the multiple equal grades rule, but I'd appreciate a testcase for that.
Takes a list of [grade, rank]. Returns a 1-indexed list of all possible liars.
## Explanation
```
ṙJṖZNÞiⱮḷ⁼ʋ/Ɗ€T Main monadic link
ṙ Rotate left by
J all of [1..length]
€ For each rotation
Ɗ (
Ṗ Pop (remove the last pair)
Z Zip, change to a pair of [grades, ranks]
/ Reduce by
ʋ (
Þ Sort the grades by
N their negation
iⱮḷ Find the first index of each grade in the reverse-sorted grades
⁼ Is this equal to the list of ranks?
ʋ )
Ɗ )
T Find the indices where this is true
```
]
|
[Question]
[
# The challenge
How well can you gerrymander North Carolina into 13 voting districts?
In this challenge, you use the following files to draw different maps for Republicans and Democrats.
**File 1:** [NC\_2016\_presidential\_election.csv](https://www.dropbox.com/s/rlwlcgz7ppd6vag/NC_2016_presidential_election.csv?dl=0)
**File 2:** [NC\_county\_adjacency.csv](https://www.dropbox.com/s/q4e8kaoujw5k373/NC_county_adjacency.csv?dl=0)
File 1 gives county-level voting data from the 2016 presidential election (based on [this](https://en.wikipedia.org/wiki/2016_United_States_presidential_election_in_North_Carolina#By_county) and [that](https://er.ncsbe.gov/contest_details.html?election_dt=11/08/2016&county_id=0&contest_id=1001)), while File 2 gives adjacency information between counties (based on [this](https://www2.census.gov/geo/docs/reference/county_adjacency.txt)). For File 2, the first entry of each row is adjacent to the other entries in that row. For example, Alexander is adjacent to Alexander, Caldwell, Catawba, Iredell and Wilkes. (Note that every county is adjacent to itself.)
# Admissibility
Your code should be written in a way that can gerrymander arbitrary maps. In particular, your code must take each of the following as inputs:
* A set \$C\$ of counties and a set \$P\$ of parties.
* Weights \$(v\_{cp})\$ that count voters in county \$c\in C\$ who vote for party \$p\in P\$. (E.g., File 1.)
* A connected graph \$G\$ with vertex set \$C\$. (E.g., File 2.)
* A number of districts \$k\$.
* A party \$p^\star\in P\$ to gerrymander in favor of.
The output must be an assignment of counties to districts such that the counties in each district induce a connected subgraph of \$G\$. For example, for the counties in Files 1 and 2 (listed in alphabetical order), the following is one of 13! sequences that specify the partition of counties into districts pictured below:
```
3,5,5,10,5,5,13,11,10,8,9,12,1,12,13,13,3,9,3,12,13,12,9,8,13,10,13,13,4,4,8,11,11,5,7,9,11,12,11,13,4,11,7,12,12,11,1,13,4,12,7,13,3,13,9,12,12,11,12,2,12,1,1,7,8,11,13,3,13,13,8,13,3,11,9,3,10,10,3,1,9,8,10,1,5,5,12,12,13,10,11,6,11,11,5,8,5,7,5,12
```
[](https://i.stack.imgur.com/iycX6.png)
(This map is loosely based on [the current map of U.S. congressional districts in North Carolina](https://en.wikipedia.org/wiki/North_Carolina%27s_congressional_districts).)
# Scoring
Your score is determined by how your code performs for various problem instances.
Given a district assignment, let \$d\$ denote the number of districts for which party \$p^\star\$ receives the plurality of votes cast, and let \$a\$ and \$b\$ denote the minimum and maximum number of voters in a district, respectively. Then the score for the district assignment is given by
$$ \text{assignment score} = d - \frac{b}{a}. $$
For example, if \$p^\star\$ is the Republican party, then the district assignment described above has \$d=10\$, \$a=247739\$, and \$b=527337\$, leading to a score of about \$7.87\$.
To compute your score, gerrymander North Carolina (as specified in Files 1 and 2) into \$k=13\$ districts in favor of the Republican party, and then in favor of the Democratic party. Let \$S\_1\$ denote the sum of these two assignment scores. Next, gerrymander 10 different modifications of North Carolina, each obtained by removing one of the following counties from Files 1 and 2:
```
Cleveland,Davidson,Hyde,Johnston,Madison,Montgomery,Pender,Scotland,Warren,Wilkes
```
(Since North Carolina is [biconnected](https://en.wikipedia.org/wiki/Biconnected_graph), each of these are acceptable problem instances.) For each modification, gerrymander into \$k=13\$ districts in favor of the Republican party, and then in favor of the Democratic party. Let \$S\_2\$ denote the sum of these 20 assignment scores. Then the score of your submission is given by
$$ \text{submission score} = S\_1+\frac{S\_2}{10}. $$
In addition to your code, you are encouraged to provide an illustration of your two maps that gerrymander all of North Carolina for Republicans and for Democrats. ([DRA2020](http://gardow.com/davebradlee/redistricting/help/createmap.html) might be a helpful resource.)
[Answer]
# C++, score = 33.526203, all test cases in 2min34s
(of course, the score can be improved by running the program for more time; please do not do that to claim a victory or something)
That score is usually 11 won districts for the Republicans and from 9 to 11 for the Democrats.
In this revision, the score decreased significantly, because I found some *really* large bugs in the input parsing. My program also verifies its solution now.
```
//#define _GLIBCXX_DEBUG
#include <iostream>
#include <streambuf>
#include <iomanip>
#include <fstream>
#include <cstring>
#include <bitset>
#include <cassert>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <cmath>
#include <climits>
#include <random>
#include <set>
#include <map>
#include <deque>
#include <string>
constexpr uint64_t rotl(uint64_t x, char k)
{
return (x<<k) | (x>>(64-k)); //typo of the day: replace the >> with <<
}
uint64_t xs128()
{
static uint64_t s_0 = 0, s_1 = 1;
const uint64_t s0 = s_0;
uint64_t s1 = s_1;
uint64_t res = s0 + s1;
s1 ^= s0;
s_0 = rotl(s0, 24) ^ s1 ^ (s1 << 16);
s_1 = rotl(s1, 37);
return res >> 4;
}
std::vector<std::string> getCsvLine(std::istream& str)
{
https://stackoverflow.com/a/1120224 - saved some time writing a parser...
std::vector<std::string> result;
std::string line; std::getline(str,line);
std::stringstream lineStream(line);
std::string cell;
while(std::getline(lineStream,cell, ','))
result.push_back(cell);
return result;
}
struct county
{
int good = 0;
int sum = 0;
std::vector<int> others;
std::string name;
};
struct district
{
int good = 0;
int sum = 0;
std::vector<int> others;
void operator += (county& rhs)
{
good += rhs.good; sum += rhs.sum;
for(int i = 0; i < others.size(); i++)
others[i] += rhs.others[i];
}
void operator -= (county& rhs)
{
good -= rhs.good; sum -= rhs.sum;
for(int i = 0; i < others.size(); i++)
others[i] -= rhs.others[i];
}
};
//seems like exactly 100 districts exist, below CHAR_MAX
std::vector<std::vector<char>> graph;
std::vector<char> curdistrict;
std::vector<county> counties;
std::vector<district> districts;
std::vector<char> marks;
bool pluralityCheck(const district& d)
{
return d.good > *std::max_element(d.others.begin(), d.others.end());
}
int n, k, excluded;
double getFitness(std::vector<char>& dmap)
{
std::vector<district> districts(k);
for(district& d : districts)
d.others.resize(counties[excluded==0?1:0].others.size());
for(int i = 0; i < n; i++)
if(i != excluded) districts[dmap[i]] += counties[i];
double score = 0;
int min = INT_MAX, max = INT_MIN;
for(int i = 0; i < k; i++)
score += pluralityCheck(districts[i]),
min = std::min(min, districts[i].sum), max = std::max(max, districts[i].sum);
score -= double(max) / min;
return score;
}
void dfs(char v, char color)
{
marks[v] = color;
for(int to : graph[v])
if(marks[to] != color && curdistrict[to] == curdistrict[v])
dfs(to, color);
}
bool dfsFor(char at, char target, char color)
{
marks[at] = color;
if(at == target) return true;
if(at == excluded) return false;
bool ans = false;
for(int to : graph[at])
if(marks[to] != color && curdistrict[to] == curdistrict[at])
ans |= dfsFor(to, target, color);
return ans;
}
bool isCutpoint(int v)
{
static int call = 0;
char color = call + 1;
call = (call + 1) % 255;
if(color == 1) for(char& el : marks) el = 0; //reset every 256 calls
marks[v] = color;
int calls = 0;
for(char to : graph[v])
{
if(curdistrict[to] != curdistrict[v]) continue;
if(marks[to] == color) continue;
calls++;
if(calls == 2) break;
dfs(to, color);
}
return calls != 1; //0 -> kills a district, >=2 -> a cutpoint -> splits a district
}
std::map<std::string, int> dnamemap;
double solve(int n, int k, int target, int excluded)
{
::n = n; ::k = k; ::excluded = excluded;
marks = std::vector<char>(n);
curdistrict = std::vector<char>(n, -1); graph = std::vector<std::vector<char>>(n);
districts = std::vector<district>(k); counties = std::vector<county>(n);
dnamemap = std::map<std::string, int>();
std::ifstream data("NC_2016_presidential_election.csv");
getCsvLine(data); //skip header
for(int i = 0; i < n; i++)
{
std::vector<std::string> row = getCsvLine(data);
dnamemap[row[0]] = i;
counties[i].name = row[0];
if(i == excluded) continue;
for(int j = 1; j < row.size(); j++)
{
int v = std::stoi(row[j]);
if(j - 1 == target)
counties[i].good = v;
else counties[i].others.push_back(v);
counties[i].sum += v;
}
}
data = std::ifstream("NC_county2.csv"); //no header
//NC_county2.csv is obtained by cat NC_county_adjacency.csv | sort | tr -d '\r'
//the default counties file caused not one but TWO horrible parsing bugs
//they silently increased the score.
//There were \r\n line endings instead of \n, and my program mishandled them.
//and *the worst*. It seems to be in alphabetic order, but it actually simply isn't.
for(int i = 0; i < n; i++)
{
std::vector<std::string> row = getCsvLine(data);
if(i == excluded) continue;
for(int j = 1; j < row.size(); j++)
{
if(row[j] == row[0]) continue;
int to = dnamemap[row[j]];
if(to == excluded) continue;
graph[i].push_back(to);
}
}
for(district& d : districts)
d.others.resize(counties[excluded==0?1:0].others.size());
int di = 0;
for(int i = 0; di < k; i++) if(i != excluded) curdistrict[i] = di++;
for(int it = n; it --> 0;)
for(int i = 0; i < n; i++)
{
if(i == excluded || curdistrict[i] != -1) continue;
for(int to : graph[i])
{
if(to == excluded || curdistrict[to] == -1) continue;
curdistrict[i] = curdistrict[to];
break;
}
}
if(excluded >= 0) curdistrict[excluded] = -1;
for(int i = 0; i < n; i++) printf("%d ", curdistrict[i]);
printf("%d\n", excluded);
for(int i = 0; i < n; i++) if(excluded != i) districts[curdistrict[i]] += counties[i];
double temp = 3;
int its = 2e7;
std::vector<char> bestplacement = curdistrict;
std::vector<district> bestdistricts = districts;
int lastimprovement = 0;
double bestscore = getFitness(curdistrict);
int perblock = 2e4; //max number of iterations without improvement
double delta = 1.01 * temp / its;
double curscore = bestscore;
double withoutimprovement = 0;
for(int it = 0; it < its; it++)
{
temp -= delta;
if(it % 1048576 == 0)
printf("it=%d, cs=%lf \r", it, curscore);
int i = xs128() % n;
while(i == excluded) i = xs128() % n;
if(isCutpoint(i)) continue; //<- around 50% of program time
std::vector<int> nearby;
bool ok = false;
for(int to : graph[i])
if(curdistrict[to] != curdistrict[i] && curdistrict[to] != -1) ok = true;
if(!ok) continue;
int nd = -1;
while(nd == curdistrict[i] || nd == -1)
nd = curdistrict[graph[i][xs128() % graph[i].size()]];
//calculate new min size, new max size etc.
//can be done via std::set and other tree-based stuff, but it's much simpler to use a normal arrays (for k=13)
//*might* use a segment tree to optimize later, but it's not spending a lot of time here
char oldmaj1 = pluralityCheck(districts[curdistrict[i]]);
char newmaj1 = pluralityCheck(districts[nd]);
int maxs = INT_MIN, mins = INT_MAX;
for(int i = 0; i < k; i++)
maxs = std::max(maxs, districts[i].sum), mins = std::min(mins, districts[i].sum);
double pen1 = double(maxs) / mins;
districts[curdistrict[i]] -= counties[i];
districts[nd] += counties[i];
char oldmaj2 = pluralityCheck(districts[curdistrict[i]]);
char newmaj2 = pluralityCheck(districts[nd]);
maxs = INT_MIN, mins = INT_MAX;
for(int i = 0; i < k; i++)
maxs = std::max(maxs, districts[i].sum), mins = std::min(mins, districts[i].sum);
double pen2 = double(maxs) / mins;
double delta = pen1 - pen2 + (oldmaj2 + newmaj2 - oldmaj1 - newmaj1);
if(delta <= 0 && (temp <= 0 || ldexpf(std::exp(delta / temp), 60) < xs128()))
{
districts[nd] -= counties[i], districts[curdistrict[i]] += counties[i];
}
else
{
curdistrict[i] = nd;
curscore += delta;
if(curscore > bestscore)
{
bestscore = curscore; lastimprovement = it;
bestplacement = curdistrict; withoutimprovement = 0;
bestdistricts = districts;
}
}
if(curscore < bestscore) withoutimprovement += bestscore - curscore;
if(it - lastimprovement > perblock || withoutimprovement > 3e4)
{
//restart at best score so far
withoutimprovement = 0;
lastimprovement = it;
curdistrict = bestplacement;
districts = bestdistricts;
curscore = bestscore;
}
}
for(int i = 0; i < n; i++)
printf("%d ", curdistrict[i]);
printf("\n");
for(district& d : districts)
{
printf("%d total, maj=%d, %d good; rest:", d.sum, (int)pluralityCheck(d), d.good);
for(int el : d.others) printf(" %d", el);
printf("\n");
}
for(int i = 0; i < n; i++) //verify validness
for(int j = i+1; j < n; j++)
{
if(i == excluded || j == excluded) continue;
if(curdistrict[i] != curdistrict[j]) continue;
for(char& el : marks) el = 0;
bool good = dfsFor(i, j, 1);
if(!good) printf("invalid: i=%d, j=%d, d=%d!\n", i, j, curdistrict[i]);
}
double score = getFitness(curdistrict);
printf("%lf\n", score);
return score;
}
int main()//int64_t argc, char*argv[])
{
//randomly choose and recolor vertices
//do not recolor a vertex if it is a cutpoint (more known as an articulation point or cut vertex) or alone
//to check, DFS over same-colored vertices from it. If != 1 calls were done, it's alone or a cutpoint
//initial state: all counties belong to district 0, but first 13 belong to district i (dumb but why bother)
//for each district maintain the voters for both parties and total number
//oh, and don't merely randomly recolor: use Simulated Annealing (TM) (it actually improves a lot!)
setbuf(stdout, 0);
int k = 13, n = 100;
std::vector<int> toExclude { -1, 22, 28, 47, 50, 57, 61, 70, 82, 92, 97 }; //the final score computing
//std::vector<int> toExclude { -1 };
double score = 0;
for(int el : toExclude)
{
double s = 0;
s += solve(n, k, 0, el);
s += solve(n, k, 1, el);
if(el == -1) score += s;
else score += s / 10;
}
printf("%lf\n", score);
}
```
Uses (attempts to use) simulated annealing to improve from a dumb assignment by making random changes if they do not ruin things (that is, destroy or split districts). Restarts from the best known assignment when either 20000 iterations passed without an improvement or the accumulated difference between the best score and the current score since the last improvement exceeds 30000.
Can be compiled with `clang++ hax.cpp -Ofast -march=native -flto -no-pie -o a.out`. Assumes files `NC_2016_presidential_election.csv` and `NC_county2.csv` are in the current directory, where `NC_county2.csv` is the `NC_county_adjacency.csv`, but with its lines *actually* sorted in alphabetical order, and with Unix (`\n`) line endings.
Quoting from the question, "you are encouraged to provide an illustration". I am definitely encouraged (I would really like to know whether or not the code has no bugs), but I have no idea how to create an illustration. I also have no idea how to export the output into a format readable by the linked website.
Assignment information on the normal map for the Democrats, then for the Republicans:
```
begin assignment for target=0, excluded=-1
Alamance,4
Alexander,8
Alleghany,8
Anson,12
Ashe,8
Avery,5
Beaufort,6
Bertie,6
Bladen,9
Brunswick,9
Buncombe,5
Burke,10
Cabarrus,8
Caldwell,8
Camden,7
Carteret,9
Caswell,0
Catawba,10
Chatham,12
Cherokee,10
Chowan,7
Clay,10
Cleveland,10
Columbus,2
Craven,9
Cumberland,2
Currituck,7
Dare,7
Davidson,12
Davie,8
Duplin,6
Durham,12
Edgecombe,6
Forsyth,3
Franklin,7
Gaston,10
Gates,7
Graham,10
Granville,0
Greene,6
Guilford,4
Halifax,7
Harnett,12
Haywood,10
Henderson,10
Hertford,7
Hoke,2
Hyde,7
Iredell,8
Jackson,10
Johnston,12
Jones,6
Lee,12
Lenoir,6
Lincoln,11
Macon,10
Madison,10
Martin,6
McDowell,5
Mecklenburg,11
Mitchell,5
Montgomery,12
Moore,12
Nash,7
New Hanover,9
Northampton,7
Onslow,9
Orange,0
Pamlico,9
Pasquotank,7
Pender,9
Perquimans,7
Person,0
Pitt,6
Polk,10
Randolph,4
Richmond,12
Robeson,2
Rockingham,0
Rowan,8
Rutherford,10
Sampson,9
Scotland,2
Stanly,8
Stokes,0
Surry,3
Swain,10
Transylvania,10
Tyrrell,7
Union,8
Vance,7
Wake,1
Warren,7
Washington,6
Watauga,5
Wayne,9
Wilkes,8
Wilson,6
Yadkin,8
Yancey,10
end assignment for target=0, excluded=-1
begin assignment for target=1, excluded=-1
Alamance,0
Alexander,1
Alleghany,11
Anson,7
Ashe,11
Avery,10
Beaufort,6
Bertie,6
Bladen,8
Brunswick,12
Buncombe,10
Burke,10
Cabarrus,7
Caldwell,11
Camden,9
Carteret,6
Caswell,0
Catawba,1
Chatham,2
Cherokee,4
Chowan,9
Clay,4
Cleveland,4
Columbus,12
Craven,9
Cumberland,8
Currituck,6
Dare,6
Davidson,0
Davie,7
Duplin,9
Durham,0
Edgecombe,9
Forsyth,1
Franklin,6
Gaston,4
Gates,9
Graham,10
Granville,6
Greene,6
Guilford,11
Halifax,6
Harnett,8
Haywood,10
Henderson,4
Hertford,9
Hoke,2
Hyde,6
Iredell,7
Jackson,4
Johnston,8
Jones,9
Lee,2
Lenoir,9
Lincoln,10
Macon,4
Madison,10
Martin,9
McDowell,10
Mecklenburg,5
Mitchell,10
Montgomery,2
Moore,2
Nash,9
New Hanover,12
Northampton,9
Onslow,12
Orange,2
Pamlico,9
Pasquotank,6
Pender,12
Perquimans,6
Person,0
Pitt,6
Polk,4
Randolph,0
Richmond,7
Robeson,8
Rockingham,0
Rowan,2
Rutherford,4
Sampson,12
Scotland,2
Stanly,2
Stokes,11
Surry,11
Swain,10
Transylvania,4
Tyrrell,6
Union,7
Vance,6
Wake,3
Warren,9
Washington,6
Watauga,11
Wayne,9
Wilkes,1
Wilson,9
Yadkin,1
Yancey,10
end assignment for target=1, excluded=-1
```
]
|
[Question]
[
This is a sequence question of the usual type, as applied to [OEIS sequence A038666](https://oeis.org/A038666). That is, do either of the following:
* Accept no or any input, and output A038666 until the heat death of the universe.
* Accept a positive integer as input, and output the \$n\$th term of A038666 or its first \$n\$ terms. (If using \$0\$- instead of \$1\$-indexing, then of course you also have to output `1` on `0` input.)
The \$n\$th term of A038666 is the least area among rectangles that contain non-overlapping squares of sizes \$1\times1,2\times2,\dots n\times n\$ if you're using \$1\$-indexing.
### Example:
The smallest-area rectangle which can contain non-overlapping squares of sizes \$1\times1\$ through \$4\times4\$ has dimensions \$7\times5\$:
```
4 4 4 4 3 3 3
4 4 4 4 3 3 3
4 4 4 4 3 3 3
4 4 4 4 2 2 1
x x x x 2 2 x
```
Therefore, \$a(4)=7\times5=35\$ (\$1\$-indexed).
Similarly, the least-area rectangle containing non-overlapping squares of sizes \$1\times1\$ through \$17\times17\$ [has dimensions \$39\times46\$](http://web.archive.org/web/20190218045512/http://www.mathpuzzle.com/17sqrsrect.gif), so \$a(17)=39\times46=1794\$ (\$1\$-indexed).
[Answer]
# JavaScript (ES6), 172 bytes
*Slower but shorter version suggestion suggested by @JonathanAllan (also saving 4 bytes in the original answer):*
```
f=(n,A,S=(n,c)=>n>=0?c(n)||S(n-1,c):0)=>S(A,w=>(F=(l,n)=>n?S(w-n,x=>S(A/w-n,y=>l.some(([X,Y,W])=>X<x+n&X+W>x&Y<y+n&Y+W>y)?0:F([...l,[x,y,n]],n-1))):A%w<1)([],n))?A:f(n,-~A)
```
[Try it online!](https://tio.run/##HY5BboNADEX3OcUs0sgWZgrLUgY0m1yARUAIKYhA1Yp6qlAVEKFXp6ar//X8LPuj/qmH5v7@9e2zu7Xb1hlgspTt0aBJODFB2gDj45EB@6HAKBCegaXRJHA20BPvYprB6DNN/7Pnvc4m6fXgPluAMqeCLpV4eTx5fMq9SzKdiniWXkifMQ2iM5Ra657KiWbiqiK5h4iRfRrjEKEUgJjaqJPf/F@LW@fuwMqo8FWxitWLhOehWg5KNY4H17e6d29wreG48IpiHhdZxvWKh3X7Aw "JavaScript (Node.js) – Try It Online")
---
# Original answer, ~~209 183 178~~ 174 bytes
Returns the \$N\$th term of the sequence, 1-indexed.
```
f=(n,A,S=(n,c)=>n>=0?c(n)||S(n-1,c):0)=>S(A,w=>A%w?0:(F=(l,n)=>n?S(w-n,x=>S(A/w-n,y=>l.some(([X,Y,W])=>X<x+n&X+W>x&Y<y+n&Y+W>y)?0:F([...l,[x,y,n]],n-1))):1)([],n))?A:f(n,-~A)
```
[Try it online!](https://tio.run/##HY7BboNADETv@Yo9pJEtzBaulAVxyQ9wCAghBVGoGm28VagKiNBfp6anGY@ePb41P83QPj6/vn1279229QaYMsp3adEknJggbYHx@cyB/VDCKJA8h4xGk2QvYxpEcDZgiXc8zWH0maZ/4nW3s0msHty9A6gKKulSC1fEk8enwrsk06mMZ/Gl@Bnl2BkqrbWlaqKZuK5JWhExChEqGRDTLOrlO/83w613D2BlVPimWMUqDEQ9D9VyUKp1PDjbaes@4NrAceEVBT0uso3rFQ/r9gc "JavaScript (Node.js) – Try It Online")
## Commented
### Helper function
We first define a helper function \$S\$ which invokes a callback function \$c\$ for \$n\$ to \$0\$ (both included) and stops as soon as a call returns a truthy value.
```
S = (n, c) => // n = integer, c = callback function
n >= 0 ? // if n is greater than or equal to 0:
c(n) || // invoke c with n; stop if it's truthy
S(n - 1, c) // or go on with n - 1 if it's falsy
: // else:
0 // stop recursion and return 0
```
### Main function
We start with \$A=1\$.
For each pair \$(w,h)\$ such that \$w\times h = A\$, we try to insert all squares of size \$1\times1\$ to \$n\times n\$ (actually starting with the largest one) in the corresponding area, in such a way that they don't overlap with each other.
We keep track of the list of squares with their position \$(X,Y)\$ and their width \$W\$ in \$l[\text{ }]\$.
We either return \$A\$ if a valid arrangement was found, or try again with \$A+1\$.
```
f = ( n, // n = input
A ) => // A = candidate area (initially undefined)
S(A, w => // for w = A to w = 0:
A % w ? // if w is not a divisor of A:
0 // do nothing
: ( // else:
F = (l, n) => // F = recursive function taking a list l[] and a size n
n ? // if n is not equal to 0:
S(w - n, x => // for x = w - n to x = 0
S(A / w - n, y => // for y = A / w - n to y = 0:
l.some( // for each square in l[]
([X, Y, W]) => // located at (X, Y) and of width W:
X < x + n & // test whether this square is overlapping
X + W > x & // with the new square of width n that we're
Y < y + n & // trying to insert at (x, y)
Y + W > y //
) ? // if some existing square does overlap:
0 // abort
: // else:
F([ ...l, // recursive call to F:
[x, y, n] // append the new square to l[]
], //
n - 1 // and decrement n
) // end of recursive call
) // end of iteration over y
) // end of iteration over x
: // else (n = 0):
1 // success: stop recursion and return 1
)([], n) // initial call to F with an empty list of squares
) ? // end of iteration over w; if it was successful:
A // return A
: // else:
f(n, -~A) // try again with A + 1
```
[Answer]
# [Python 2 (PyPy)](http://pypy.org/), ~~250~~ 236 bytes
-14 bytes thanks to [msh210](https://codegolf.stackexchange.com/users/1976/msh210)'s suggestions.
Outputs the 1-indexed nth term of the sequence.
```
n=input()
r=range
k=n*-~n*(n-~n)/6
m=k*k
for Q in r(m):
P={0}
for X in r(n,0,-1):P|=([x for x in[{(x+a,y+b)for a in r(X)for b in r(X)}for x in r(Q%k-X+1)for y in r(Q/k-X+1)]if not x&P]+[{0}])[0]
if len(P)>k:m=min(Q%k*(Q/k),m)
print m
```
[Try it online!](https://tio.run/##NY7LCoMwEEX3@YrZtGR8oJbShZB@g@4EcWGhj5BmDMGCwdpft1HbzcA998wwxvWPjg6xccbNMwlJ5tVzZFbYlu5XpgQF8YcCTn5icmJaqECxW2ehBElgucacQSHGdGKw4GrDFKVRnGFevAWvh7UZfFOPfAjbyIUXXFC7ydUaLv8w/W2fyp2KqzBbBfdDyYYaeQPqehj2RRPW/oEG67Rh4PHzSrzAs8q10JKWI8GyhpFGZqykHvQ8H78 "Python 2 (PyPy) – Try It Online") For n>4, this takes lot of time. I have verified the result up to n=7 locally.
]
|
[Question]
[
In this challenge, we render Ascii user interfaces.
```
+----------------------+
|+-----------++-------+|
||<- Previous||Next ->||
|+-----------++-------+|
|== The title == |
| |
|Lorem ipsum dolor |
|sit amet... |
|+--------------+ |
||Post a comment| |
|+--------------+ |
|+-----------------+ |
||User X commented:| |
|| | |
||This is amazing! | |
|+-----------------+ |
|+-----------------+ |
||User Y commented:| |
|| | |
||lol | |
|+-----------------+ |
+----------------------+
```
Each drawing like this is made of one *element*, which can contain subelements. The possible elements are listed below:
1. Text element. Contains one or more lines of text.
2. Box element. Contains one subelement that is surrounded with borders. The borders have `+`s at the corners and `-`s and `|` at the edges.
3. Horizontal list. Contains one or more elements that are aligned horizontally.
4. Vertical list. Contains one or more elements that are aligned over each other vertically and to left horizontally.
Every element is a rectangle.
Each element, in addition to its content, has a property called *baseline*. The baseline is used to align the elements vertically: every element of a horizontal list is aligned such that their baselines are on the same line. In the example below, the baseline contain characters `aeg`. The baselines of the three box elements are (0-indexed) `1`, `3` and `2`.
```
+-+
|c|+-+
+-+|d||f|
|a||e||g|
|b|+-+|h|
+-+ +-+
```
The baselines are determined with the following rules:
1. For text elements, the first line of text is the baseline, ie. `0`.
2. For box elements, the baseline is 1 + the baseline of the subelement.
3. For horizontal lists, the baseline is the maximum baseline in the list (`3` in the example above).
4. For vertical lists, the baseline is the baseline of an element, which must be specified in the input.
## Input
The input is a specification of an interface in some format (eg. lists, json). The example inputs have the following format:
1. A string element is a string: `"..."`
2. A box element is a list thats first element is `"b"`: `["b", subelement]`
3. A horizontal list is a list thats first element is `"h"`: `["h", items...]`
4. A vertical list is a list thats first element is `"v"` and the second element is the (0-indexed) number of the element thats baseline is used: `["v", n, items...]`
## Output
The output must contain the elements aligned using the rules I specified above. The output can be stdout, a list of strings or anything else meaningful.
## Scoring
This is [code-golf](/questions/tagged/code-golf "show questions tagged 'code-golf'"), the usual rules apply.
## Test cases
1
```
["b", ["v", 0, ["h", ["b", "<- Previous"], ["b", "Next ->"]], "== The title ==\n\nLorem ipsum dolor\nsit amet...", ["b", "Post a comment"], ["b", "User X commented:\n\nThis is amazing!"], ["b", "User Y commented:\n\nlol"]]]
+----------------------+
|+-----------++-------+|
||<- Previous||Next ->||
|+-----------++-------+|
|== The title == |
| |
|Lorem ipsum dolor |
|sit amet... |
|+--------------+ |
||Post a comment| |
|+--------------+ |
|+-----------------+ |
||User X commented:| |
|| | |
||This is amazing! | |
|+-----------------+ |
|+-----------------+ |
||User Y commented:| |
|| | |
||lol | |
|+-----------------+ |
+----------------------+
```
2
```
["h", ["b", ["v", 0, "a", "b"]], ["b", ["v", 2, "c", "d", "e"]], ["b", ["v", 1, "f", "g", "h"]]]
+-+
|c|+-+
+-+|d||f|
|a||e||g|
|b|+-+|h|
+-+ +-+
```
3
```
["h", ["b", ["v", 0, ["b", ["h", "a\nb", "c"]], "d", "e", ["h", ["h", "f"], ["b", ["h", "g"]], "h"]]], ["b", "ijk\nl\nmn\no"], ["v", 2, ["b", "pqrst"], ["b", "uv\nw"], ["b", "x"]], ["b", ["b", ["b", "yz"]]]]
+-----+
|pqrst|
+-----+
+--+
|uv|
|w | +------+
+-----+ +--+ |+----+|
|+--+ |+---++-+ ||+--+||
||ac| ||ijk||x| |||yz|||
||b | ||l |+-+ ||+--+||
|+--+ ||mn | |+----+|
|d ||o | +------+
|e |+---+
| +-+ |
|f|g|h|
| +-+ |
+-----+
```
4
```
["h", "a * b = ", ["v", 0, "a + a + ... + a", "\\_____________/", " b times"]]
a * b = a + a + ... + a
\_____________/
b times
```
[Answer]
# [Python 3](https://docs.python.org/3/index.html), 721 694 693 671 661 bytes
**Edit:** Saved 27 bytes due to [@Arnold Palmer](https://codegolf.stackexchange.com/users/72137/arnold-palmer) and [@Step Hen](https://codegolf.stackexchange.com/users/65836/step-hen)
**Edit:** Saved 1 byte
**Edit:** Saved 22 bytes thanks to [@Arnold Palmer](https://codegolf.stackexchange.com/users/72137/arnold-palmer)
**Edit:** Saved 10 bytes
This could probably be golfed quite a bit
```
L,M,R,e=len,max,range,lambda t:([list(r)+[" "]*(M(map(L,t.split("\n")))-L(r))for r in t.split("\n")],0)if str==type(t)else b(t)if"h">t[0]else h(t)if"v">t[0]else v(t);F=lambda t:"\n".join(map("".join,e(t)[0]))
def h(t):
t=[e(r)for r in t[1:]];Z=M(s[1]for s in t);X=M(L(s[0])-s[1]for s in t)+Z;u=[[]for i in R(X)]
for a,b in t:u=[u[j]+[Z-b<=j<L(a)+Z-b and a[j-Z+b][i]or" "for i in R(L(a[0]))]for j in R(X)]
return u,Z
def b(t):t,b=e(t[1]);u=[["+",*"-"*L(t[0]),"+"]];return u+[["|"]+r+["|"]for r in t]+u,1+b
def v(t):w=[e(r)for r in t[2:]];return[a[i]+[" "]*(M(L(a[0])for a,d in w)-L(a[i]))for a,c in w for i in R(L(a))],sum(L(x[0])for x in w[:t[1]])+w[t[1]][1]
```
[Try it online](https://tio.run/##dVTRbtowFH0uX@H5KSYOg@4tNNWe@kSnquqkDseaHDBgljhZ7ACt@u/s2gQIVIuUxD733ON7bq5SvdlVqb/t9xP6SJ@pTHKpaSF2tBZ6KWkuimwukI0Dlitjg5qEDCPM@8FjUIgqmFA7MFWubIBTjQkh0QQ4ZFHWqEZKo4sop0OiFsjYOknsWyUDS2RuJMpgoRZ4he8tG3IPrQ7QpgNtABo/JKeKnORgXSrtC8GHNXWikEFIby4XXibu3diESSjrXBUbxZyPp8ljYNiIO9x4nIxfAZsAChLRVSycjpuEMQ8pBz0Hr4T3btxe0MyTYmA0bM1DNo2yu2R9NwkEJEYZEnqOBFtH0zDjTPGyhjZ2lIDny/bq6456LW1Ta9TQqXfkehVbmiVgFMojviQcYtrHEe5PAtcuQgEAf8fUEBgfmId16N/nNvCwoaMw88KuvfH2U6Nu45MQE1D3@fO3FR/czx17676@I5EWnXkUXdoEj9Q0BSx3x/yd57HYOeIk3DK/gHsvd6KocmlQgsBEhiliMBQUDd1i5bcOxHcReqrlRpWNwfyE/pA7i6J76AVskgS9rCSyyuYSJUmqUz0pa1kgVUE5aF7mZZ1qoywShbSDweCs/lQaQNGsLAqpbeeAn0bW6PUYkPPYqb6sFEyMARnxrvTyyzX/1xU/L3OokNOuoZNLLFxe5i10Q7eAzlxo7h7yU3wE6MKFlu6x@v8Bx60LYZFqX@fs0LJW@9xrT1pgfpW2PNAPpxy9qvUf8JbqAiyWh5S28JZQ/a1Nt5nNJtXbzn53Yer8xG/v7qCjHyxQH2UwIJdtQyFyN3xHt3K8NP3dvb46DMGVwUwU0jjNXs@NYzt0biiP8wc/kapW2gYPQQvBH6aF8HfcHw2HpLf/Bw)
]
|
[Question]
[
This is [**Weekly Challenge #2.**](http://meta.codegolf.stackexchange.com/q/3578/8478) Theme: **Translation**
Write a program or function that takes in source code for a program in [Prelude](http://esolangs.org/wiki/Prelude) and outputs code for an equivalent program in [Befunge-93](http://esolangs.org/wiki/Befunge). For the program to be equivalent, it should, for any given input, produce the same output as the Prelude program, and halt if and only if the Prelude program halts.
## Input language: Prelude
Python interpreter:
```
#!/usr/bin/python
import sys
NUMERIC_OUTPUT = True
NUMERIC_INPUT = True
try:
filename = sys.argv[1]
except:
print "Usage:", sys.argv[0], "<filename>"
raise SystemExit
try:
inFile = file(filename)
except:
print "Error when opening", filename
raise SystemExit
# code is kept as a list of voices, each voice a string
code = []
firstLine = True
eof = False
while not eof:
# read batch of lines
batch = []
while 1:
line = inFile.readline()
if line == '': eof = True
if line == '' or line.rstrip() == '*':
break
batch.append(line.rstrip())
maxLen = max([len(b) for b in batch])
batch = [b + ' '*(maxLen - len(b)) for b in batch]
if firstLine:
code = batch
firstLine = False
else:
if len(batch) != len(code):
print "Error in the program: number of voices changes"
raise SystemExit
for i in range(len(batch)):
code[i] += batch[i]
class Stack:
def __init__(self):
self.data = []
def push(self, value):
if self.data or value != 0: self.data.append(value)
def drop(self):
if self.data: self.data.pop()
def top(self):
if self.data: return self.data[-1]
return 0
def pop(self):
value = self.top()
self.drop()
return value
numVoices = len(code)
numInstructions = len(code[0])
stacks = [Stack() for x in range(numVoices)]
topValues = [0 for x in range(numVoices)]
# establish loop couplings
loopStack = []
loops = {}
for cp in range(numInstructions):
curr = [voice[cp] for voice in code]
if curr.count('(') + curr.count(')') > 1:
print "Error in the program: More than one bracket; position", cp
raise SystemExit
if '(' in curr:
loopStack.append((cp, curr.index('(')))
if ')' in curr:
if not loopStack:
print "Error in the program: extraneous closing bracket; position", cp
raise SystemExit
openingPosition, openingVoice = loopStack.pop()
loops[openingPosition] = cp
loops[cp] = openingPosition, openingVoice
if loopStack:
print "Error in the program: not enough closing brackets"
raise SystemExit
# now, actually execute the program
cp = 0 # code pointer
while cp < numInstructions:
# technically we're supposed to shuffle our voices to make sure to perform IO
# in random order, but screw that for now
next_cp = cp+1 # can be modified by ( )
for voice in range(numVoices):
i = code[voice][cp] # current instruction
if i == '^':
stacks[voice].push(topValues[(voice-1) % numVoices])
elif i == 'v' or i == 'V':
stacks[voice].push(topValues[(voice+1) % numVoices])
elif i == '+':
stacks[voice].push(stacks[voice].pop() + stacks[voice].pop())
elif i == '-':
b = stacks[voice].pop()
a = stacks[voice].pop()
stacks[voice].push(a-b)
elif i == '#':
stacks[voice].drop()
elif i == '?':
if NUMERIC_INPUT:
try: num = int(raw_input())
except ValueError: num = 0
stacks[voice].push(num)
else:
char = sys.stdin.read(1)
if not char: char = '\0'
stacks[voice].push(ord(char))
elif i == '!':
if NUMERIC_OUTPUT:
print stacks[voice].pop()
else:
sys.stdout.write(chr(stacks[voice].pop()))
elif i == '(':
if stacks[voice].top() == 0:
next_cp = loops[cp] + 1
elif i == ')':
openingPosition, openingVoice = loops[cp]
if topValues[openingVoice] != 0:
next_cp = openingPosition + 1
elif i in '0123456789':
stacks[voice].push(int(i))
topValues = [stacks[i].top() for i in range(numVoices)]
cp = next_cp
```
A Prelude program consists of a number of "voices" which execute instructions simultaneously. The instructions for each voice are on a separate line. Each voice has a separate stack, which is initialized with an infinite amount of zeroes. Execution begins at the leftmost column, and advances one column to the right each tick, except when influenced by `)` or `(` instructions. The program terminates when the last column is reached.
Prelude spec for this challenge:
```
Digits 0-9 Push onto the stack a number from 0 to 9. Only single-digit
numeric literals can be used.
^ Push onto the stack the top value of the stack of the above
voice.
v Push onto the stack the top value of the stack of the below
voice.
# Remove the top value from the stack.
+ Pop the top two integers from the stack and push their sum.
- Pop the top two integers from the stack, subtract the topmost
from the second, and push the result.
( If the top of the stack is 0, jump to the column after the
matching `)` after the current column executes.
) If the top of the stack is not 0, jump to the column after
the matching `(` after the current column executes.
? Read an integer from STDIN.
! Pop one value from the stack and print it to STDOUT as an
integer.
<space> No-op
```
Notes
* `v` and `^` act cyclically, so the `v` on the bottom voice will copy the stack element of the top voice, and `^` on the top voice will copy from the bottom voice. *Corollary:* Both `v` and `^` duplicate the top of the stack in a single-voice program.
* A `(` and its matching `)` may be located on different lines. *However*, a `)` will always look at the stack of the voice where the corresponding `(` was placed, not the stack where the `)` itself is placed.
* The values produced by the `^` and `v` instructions operate on the values present prior to the completion of any other operations in the same column.
* `?` and `!` operate differently from the specification found on esolangs.org, so be be sure to test with the slightly modified interpreter provided in this post.
Input is guaranteed to have:
* Matching parentheses
* No more than one parenthesis in a column
* Same number of characters on each line
* At least one line
* No column with more than one I/O (`!` or `?`) instruction
* One linefeed character after the instructions for each voice
* No characters other than the ones mentioned above
## Output language: Befunge-93
Befunge is a stack-based language whose program counter (PC; a pointer to the current instruction) moves freely on a two-dimensional grid. It start in the top left corner, moving to the right. The playfield is toroidal, i.e. PC movement wraps around both edges. Befunge also has a stack which is initialised to an infinite number of zeroes. Befunge has the following operations:
```
Digits 0-9 Push onto the stack a number from 0 to 9. Only single-digit
numeric literals can be used.
+ Pop the top two integers from the stack and push their sum.
- Pop the top two integers from the stack, subtract the topmost
from the second, and push the result.
* Pop the top two integers from the stack and push their product.
/ Pop the top two integers from the stack, divide the second by
the topmost, and push the result. Rounds down.
% Pop the top two integers from the stack, divide the second by
the topmost, and push the remainder.
! Pop a value, push 1 if it's zero, push 0 otherwise.
` Pop the top two integers from the stack, push 1 if the second
is greater than the topmost, push 0 otherwise.
> Set PC direction to right.
< Set PC direction to left.
^ Set PC direction to up.
v Set PC direction to down.
? Set PC direction randomly.
_ Pop a value, if it's 0 set PC direction to right, left otherwise.
| Pop a value, if it's 0 set PC direction to down, up otherwise.
" Toggle string mode. While in string mode, push each character's
ASCII value instead of executing it.
: Duplicate top stack element.
\ Swap top two stack elements.
$ Pop and discard top stack element.
. Pop a value and output it as an integer. Whitespace not included.
, Pop a value and output the corresponding ASCII character.
# Jump over the next instruction.
g Pop y, pop x, push the character at coordinate (x,y).
p Pop y, pop x, pop v, set character at coordinate (x,y) to v.
& Read an integer from STDIN and push it.
~ Read a character from STDIN and push it ASCII value.
@ End program.
```
You may assume the following characteristics of the Befunge-93 compiler/interpreter:
* Integers are unlimited-precision.
* It allows grids of any size.
* Grid coordinates (for `g` and `p`) are 0-based.
## Scoring
In order to prevent submissions which simply produce a Prelude interpreter in Befunge and hardcode the Prelude source into it, the goal will be to minimise the size of the resulting Befunge source code.
Below are provided a number of Prelude programs. Your translator will be run on all of these. Your score is the sum of the sizes of the Befunge programs, provided all of them are valid.
Your translator should not be optimised specifically towards these test cases (e.g. by hardcoding handwritten Befunge programs for them). If I suspect any answer of doing so, I reserve the right to change inputs or create additional ones.
## Sample Inputs
Print `n-1` down to `0`:
```
?(1-^!)
```
Logical AND:
```
? (0)
?(0 )
1 !
```
Logical OR:
```
? (0)
? (0)
1 1 !
```
Check parity of input (i.e. modulo 2) of nonnegative number:
```
?(1-)
^ v
v1-^^-!
```
Square the input:
```
^
^+ !
?(1-)
```
Print the *n*th Fibonacci number, where `n = 0` corresponds to 0 and `n = 1` corresponds to 1:
```
0 v+v!
1 ^
?(1-)
```
Signum:
```
1) v # - !
vv (##^v^+)
?(# ^ ##
```
Division for non-negative inputs:
```
1 (# 1) v # - 1+)
vv (##^v^+)
? v-(0 # ^ #
?
1+ 1-!
```
Of course, your program must exhibit the same behavior for all cases, even if the sample program's behavior for negative numbers is not specified.
Finally, your translator should not be unreasonably long:
* It must be contained inside a Stack Exchange post
* It should process the sample inputs in under 10 minutes on a typical desktop computer.
Note that a numeric input for Prelude or Befunge is given as an optional minus sign followed by one or more decimal digits, followed by a newline. Other input is undefined behavior.
You may write your translator in any language. Shortest translated Befunge code wins.
## Leaderboard
* **Sp3000**: 16430 bytes
[Answer]
# Python 3, will score later
```
from collections import defaultdict
from functools import lru_cache
import sys
NUMERIC_OUTPUT = True
@lru_cache(maxsize=1024)
def to_befunge_num(n):
# Convert number to Befunge number, using base 9 encoding (non-optimal,
# but something simple is good for now)
assert isinstance(n, int) and n >= 0
if n == 0:
return "0"
digits = []
while n:
digits.append(n%9)
n //= 9
output = [str(digits.pop())]
while digits:
output.append("9*")
d = digits.pop()
if d:
output.append(str(d))
output.append("+")
output = "".join(output)
if output.startswith("19*"):
return "9" + output[3:]
return output
def translate(program_str):
if program_str.count("(") != program_str.count(")"):
exit("Error: number of opening and closing parentheses do not match")
program = program_str.splitlines()
row_len = max(len(row) for row in program)
program = [row.ljust(row_len) for row in program]
num_stacks = len(program)
loop_offset = 3
stack_len_offset = program_str.count("(")*2 + loop_offset
stack_offset = stack_len_offset + 1
output = [[1, ["v"]], [1, [">"]]] # (len, [strings]) for each row
max_len = 1 # Maximum row length so far
HEADER_ROW = 0
MAIN_ROW = 1
FOOTER_ROW = 2
# Then stack lengths, then loop rows, then stacks
# Match closing parens with opening parens
loop_map = {} # {column: (loop num, stack number to check, is_start)}
loop_stack = []
loop_num = 0
for col in range(row_len):
col_str = "".join(program[stack][col] for stack in range(num_stacks))
if col_str.count("(") + col_str.count(")") >= 2:
exit("Error: more than one parenthesis in a column")
if "(" in col_str:
stack_num = col_str.index("(")
loop_map[col] = (loop_num, stack_num, True)
loop_stack.append((loop_num, stack_num, False))
loop_num += 1
elif ")" in col_str:
if loop_stack:
loop_map[col] = loop_stack.pop()
else:
exit("Error: mismatched parentheses")
def pad_max(row):
nonlocal max_len, output
while len(output) - 1 < row:
output.append([0, []])
if output[row][0] < max_len:
output[row][1].append(" "*(max_len - output[row][0]))
output[row][0] = max_len
def write(string, row):
nonlocal max_len, output
output[row][1].append(string)
output[row][0] += len(string)
max_len = max(output[row][0], max_len)
def stack_len(stack, put=False):
return (to_befunge_num(stack) + # x
str(stack_len_offset) + # y
"gp"[put])
def get(stack, offset=0):
assert offset in [0, 1] # 1 needed for 2-arity ops
# Check stack length
write(stack_len(stack) + "1-"*(offset == 1) + ":0`", MAIN_ROW)
pad_max(HEADER_ROW)
pad_max(MAIN_ROW)
pad_max(FOOTER_ROW)
write(">" + to_befunge_num(stack + stack_offset) + "g", HEADER_ROW)
write("|", MAIN_ROW)
write(">$0", FOOTER_ROW)
pad_max(HEADER_ROW)
pad_max(MAIN_ROW)
pad_max(FOOTER_ROW)
write("v", HEADER_ROW)
write(">", MAIN_ROW)
write("^", FOOTER_ROW)
def put(stack, value=""):
put_inst = (value +
stack_len(stack) +
to_befunge_num(stack + stack_offset) +
"p")
post_insts.append(put_inst)
def pop(stack):
put(stack, "0")
def inc_stack_len(stack):
post_insts.append(stack_len(stack) + "1+")
post_insts.append(stack_len(stack, put=True))
def dec_stack_len(stack):
post_insts.append(stack_len(stack) + ":0`-") # Ensure nonnegativity
post_insts.append(stack_len(stack, put=True))
# Technically not necessary to initialise stack lengths per spec, but it makes it
# more portable and easier to test against other Befunge interpreters
for stack in range(num_stacks):
write("0" + stack_len(stack, put=True), MAIN_ROW)
for col in range(row_len):
post_insts_all = []
loop_start = False
loop_end = False
if col in loop_map:
if loop_map[col][2]:
loop_start = True
else:
loop_end = True
if loop_start:
loop_row = loop_offset + 2*loop_map[col][0]
get(loop_map[col][1])
elif loop_end:
get(loop_map[col][1])
write("!", MAIN_ROW)
for stack in range(num_stacks-1, -1, -1):
char = program[stack][col]
post_insts = [] # Executed after the gets in reverse order, i.e. last added first
if char in " ()":
continue
# Pre-inc, post-dec
elif char.isdigit():
inc_stack_len(stack)
put(stack, char)
elif char == "?":
inc_stack_len(stack)
put(stack, "&")
elif char == "!":
get(stack)
post_insts.append(".91+," if NUMERIC_OUTPUT else ",")
pop(stack)
dec_stack_len(stack)
elif char == "#":
pop(stack)
dec_stack_len(stack)
elif char in "+-":
get(stack, 1)
get(stack)
post_insts.append(char)
pop(stack) # This one first in case of ! or 1!
post_insts.append(stack_len(stack) + ":1`-:1\\`+") # Ensure >= 1
post_insts.append(stack_len(stack, put=True))
put(stack)
elif char in "^v":
offset = -1 if char == "^" else 1
get((stack + offset) % num_stacks)
inc_stack_len(stack)
put(stack)
else:
exit("Error: invalid character " + char)
post_insts_all.append(post_insts)
while post_insts_all:
write("".join(post_insts_all.pop()), MAIN_ROW)
if loop_start or loop_end:
loop_row = loop_offset + 2*loop_map[col][0]
pad_max(HEADER_ROW)
pad_max(MAIN_ROW)
pad_max(loop_row)
pad_max(loop_row + 1)
write(">v", HEADER_ROW)
write("|>", MAIN_ROW)
if loop_start:
write(" ^", loop_row)
write(">", loop_row + 1)
else:
write("<", loop_row)
write(" ^", loop_row + 1)
write("@", MAIN_ROW)
return "\n".join("".join(row) for row_len, row in output)
if __name__ == '__main__':
if len(sys.argv) < 3:
exit("Usage: py -3 prefunge.py <input filename> <output filename>")
with open(sys.argv[1]) as infile:
with open(sys.argv[2], "w") as outfile:
outfile.write(translate(infile.read()))
```
Run like `py -3 prefunge.py <input filename> <output filename>`.
It's been a slow week for me, so I was finally bored enough to tackle this six-month old question. I'd ask why nobody else tried, but I'm still feeling the pain from debugging (and there's probably still bugs remaining for all I know).
The question doesn't provide a Befunge-93 interpreter, so I used [this one](http://www.quirkster.com/iano/js/befunge.html), which is slightly different from the spec. The two key differences are:
* If a char doesn't exist in a given row of the program, then you can't write to that row. This means **you'll need to hit Enter several times to introduce enough newlines at the end**. If you see `NaN`s in the output, this is the most likely cause.
* Grid cells aren't preinitialised to zero - for convenience I've included some preinitialisation in the Befunge outputs, but since it's not necessary I might take it away when I start scoring.
The core layout of the output programs is this:
```
v [header row]
> [main row]
[footer row]
---
|
| rows for loops (2 per loop)
|
---
[stack length row]
---
|
| rows for stack space (1 per voice)
|
---
```
The stack space is outside the program, hence the newline Enter-spamming comment from earlier.
The core idea is to assign each voice a row which serves as its stack. To maintain these stacks, we also have a special stack length row where the length of each stack is recorded in a cell along the row. The program is then a lot of `g`ets and `p`uts, e.g. for printing the process is:
* Get the cell at `y = stack_row[stack], x = stack_length[stack]`
* Perform `.91+,`, i.e. print as integer then print a newline
* Replace the cell at the above coords with 0 (to simulate popping)
* Decrement `stack_length[stack]`
To perform the simultaneous evaluation of a column, all necessary cells are read and their values are kept on the stack before any cells are written to (e.g. for the printing example, there may be more instructions in between the first and second steps).
```, which is greater than, is employed to make sure the stack lengths never go negative, and for pushing 0s when the stack is empty. This is where the clearly visible branching comes from, but I've got an idea that'll remove the branching, which should remove a great deal of whitespace from the first and third rows.
For the loops, because Prelude loops can jump both ways, we use two rows per loop in a configuration like this:
```
>v >v
(cond) |> (program) (cond) !|>
^ <
> ^
```
These loops currently make up the majority of the bytes, but can easily be golfed down by placing them into the codebox with `p`, which I plan to do after I'm happy that the translator is working correctly.
Here's some example output for `?(1-^!)`, i.e. print `n-1` down to `0`:
```
v >6gv>v >6gv >6gv >6gv >6gv >6gv >v
>005p05g1+05p&05g6p05g:0`| >|>05g1+05p105g6p05g1-:0`| >05g:0`| >-005g6p05g:1`-:1\`+05p05g6p05g:0`| >05g1+05p05g6p05g:0`| >.91+,005g6p05g:0`-05p05g:0`| >!|>@
>$0^ >$0^ >$0^ >$0^ >$0^ >$0^
^ <
> ^
```
Square-the-input:
```
v >8gv >8gv >v >6gv >8gv >8gv >7gv >7gv >8gv >v >7gv
>005p015p025p25g1+25p&25g8p25g:0`| >25g:0`| >05g1+05p05g6p|>05g:0`| >15g1+15p15g7p25g1+25p125g8p25g1-:0`| >25g:0`| >15g1-:0`| >15g:0`| >+015g7p15g:1`-:1\`+15p15g7p-025g8p25g:1`-:1\`+25p25g8p25g:0`| >!|>15g:0`| >.91+,015g7p15g:0`-15p@
>$0^ >$0^ >$0^ >$0^ >$0^ >$0^ >$0^ >$0^ >$0^
^ <
> ^
```
Division (small inputs are recommended):
```
v >91+gv>v >94+gv >95+gv >95+gv >93+gv >93+gv >93+gv >93+gv >v >93+gv >93+gv >v >92+gv >v >92+gv >92+gv >91+gv >93+gv >91+gv >92+gv >92+gv >91+gv >91+gv >92+gv >v >91+gv >91+gv >91+gv >v >95+gv >95+gv >95+gv
>009p019p029p039p049p09g1+09p109g91+p29g1+29p&29g93+p39g1+39p&39g94+p09g:0`| >|>39g:0`| >009g91+p09g:0`-09p29g1+29p29g93+p49g1+49p149g95+p49g1-:0`| >49g:0`| >29g1-:0`| >29g:0`| >-029g93+p29g:1`-:1\`+29p29g93+p+049g95+p49g:1`-:1\`+49p49g95+p29g:0`| >29g:0`| >19g1+19p19g92+p|>29g:0`| >09g1+09p109g91+p19g1+19p19g92+p29g1+29p029g93+p29g:0`| >!|>19g:0`| >029g93+p29g:0`-29p|>19g:0`| >09g1+09p09g91+p019g92+p19g:0`-19p19g:0`| >019g92+p19g:0`-19p29g1+29p29g93+p09g:0`| >009g91+p09g:0`-09p19g1+19p19g92+p29g:0`| >19g1+19p19g92+p09g:0`| >19g1+19p19g92+p19g1-:0`| >19g:0`| >09g1-:0`| >09g:0`| >-009g91+p09g:1`-:1\`+09p09g91+p+019g92+p19g:1`-:1\`+19p19g92+p029g93+p29g:0`-29p19g:0`| >!|>09g1+09p109g91+p09g1-:0`| >09g:0`| >+009g91+p09g:1`-:1\`+09p09g91+p09g:0`| >!|>49g1+49p149g95+p49g1-:0`| >49g:0`| >-049g95+p49g:1`-:1\`+49p49g95+p49g:0`| >.91+,049g95+p49g:0`-49p@
>$0 ^ >$0 ^ >$0 ^ >$0 ^ >$0 ^ >$0 ^ >$0 ^ >$0 ^ >$0 ^ >$0 ^ >$0 ^ >$0 ^ >$0 ^ >$0 ^ >$0 ^ >$0 ^ >$0 ^ >$0 ^ >$0 ^ >$0 ^ >$0 ^ >$0 ^ >$0 ^ >$0 ^ >$0 ^ >$0 ^ >$0 ^
^ <
> ^
^ <
> ^
^ <
> ^
```
There's also a bunch of other minor optimisations that come to mind, like replacing `07p07g` with `:07p`, but I'm taking this one step at a time :)
]
|
[Question]
[
# Challenge:
Given a Sudoku board on standard input, find the minimum number of numbers added to make the board unique.
## Specifics/Rules:
* The input is formatted as follows (all whitespace is significant)
```
516|827|943
278|394|615
349|615|872
---+---+---
98 |4 2|156
465|189|237
12 |5 6|489
---+---+---
892|743|561
634|951|728
751|268|394
```
* The output is formatted with one number per line, formatted like `(x,y):z` - x and y start from one at the top left and increase down and right; z is the number to be added.
+ In this case these would all be valid outputs: `(3,4):3`, `(3,4):7`, `(5,4):3`, `(5,4):7`, `(3,6):3`, `(3,6):7`, `(5,6):3`, and `(5,6):7`, as any one of these would allow the board to be solved.
* If a unique/solved Sudoku board is entered, the program should not print anything, even a newline.
* The program should run in less than an hour for any board (I suggest testing using a fully blank board, or a board with one random number on it...).
## Scoring:
* Take your total (golfed) code size in characters, *including all whitespace*...
## Bonuses:
**1/2 code size**: If the program prints a single exclamation point and stops upon having a board with no solutions entered.
**1/2 code size**: If the program prints two exclamation points and stops upon having a board with an internal contradiction entered (two numbers the same on the same row/column/square).
[Answer]
# [Brachylog](https://github.com/JCumin/Brachylog), 245 bytes /2 = 122.5
```
@n:1a:"-"x:7fF:3a$\:3a@3:4a,Fc~bCh[0:0:0]gO,Co~c[V:O:T]h:F:6f:10ao:ba(h:11a;!);"!!"w!
h"-".|:"|"x:2f.
e(~m["0123456789":.]`;0<.<=9)
:ha#d.
:@3az:ca:5a.
:3a.
hs.:=a,?t:9ac:=fl1
:Im:8f:[[I]]z:ca.
:Jm:J.
:ha.
lg:?c.
b:+a[X:Y],?h:Y:Xr:"(~d,~d):~d
"w
```
**(Note that you have to use [the version of the language as of this commit](https://github.com/JCumin/Brachylog/tree/8184dab5a2e041ffbe44ae2e886ad3cc53749c1d). This code would need some slight changes for it to work properly in the following versions of Brachylog)**
This prints `"!!"` if the given board has internal contradictions (This takes a few seconds in that case however on TIO, so be patient).
I'm not sure I understand the first bonus correctly so I'm not addressing it.
This is obviously non-competing since the language is much more recent than the challenge, however since there are no other answers I'm not sure this matters a whole lot…
### Explanation
* Main predicate:
```
@n Split the input on line breaks
:1a:"-"x Transform into a list of lists, each sublist contains a line's values
:7fF Transform so that cells are [Value:X:Y]
:3a All values on lines must be different
$\:3a All values on columns must be different (by transposition)
@3:4a, All 3*3 block values must be different
Fc~bCh[0:0:0]gO, Append a fake cell [0:0:0]
Co~c[V:O:T] Sort the board, the blank cells V will be those before O ([0:0:0])
h:F:6f Find all subsets of blank cells with specific values for which
the board has only one solution
:10ao Sort the subsets by lengths
:ba Discard the lengths
(
h:11a Print the first subset = an answer
; Or (board is already fully determined)
! Terminate
)
; Or (Some values don't respect the constraints)
"!!"w! Print "!!" and terminate
```
* Predicate 1: Remove all "`|`" on lines, transform the `---+---+---` into `-` to remove them after
```
h"-". If the first char is "-", then Output is "-"
| Or
:"|"x Remove all occurences of "|" from the input
:2f. Output is the result of all outputs of predicate 2 on the filtered string
```
* Predicate 2: Convert one char to an integer, or if blank to a variable between 1 and 9.
```
e Take a char of the input string
(
~m["0123456789":.] Output is the index of the char in "0123456789"
` Discard the choice point caused by the ;
; Or
0<.<=9 Output is an integer between 1 and 9
)
```
* Predicate 3: Impose that all values of the input list of cells must be distinct
```
:ha Retrieve the head of each cell (i.e. the value) in the input
#d. Apply a constraint of distinctness to those values
```
* Predicate 4: Apply the distinctness constraint to values in 3\*3 blocks
```
:@3a Split 3 lines of the board in 3 parts
z Zip them together
:ca:5a. Concatenate each element of the zip, apply predicate 5 to that
```
* Predicate 5:
```
:3a. Apply predicate 3 to each element of the input
```
* Predicate 6: Assign values satisfying the constraints to a subset of the blank cells, then with those values there is only one solution to the board.
```
hs. Output is a subset of the blank cells
:=a, Assign values to those cells
?t:9ac Concatenate the values of all cells of the board
:=f Find all solved boards
l1 There is only 1 such solved board
```
* Predicate 7: Transforms the board such that each cell is now `[V:X:Y]` instead of only `V` (the value).
```
:Im Take the Ith line of the board
:8f Transform all elements of the line using predicate 8
:[[I]]z Zip the result with [I]
:ca. Concatenate each element of the zip
```
* Predicate 8: Transforms a line such that each cell is now `[V:X]`.
```
:Jm Take the Jth element of the line
:J. Output is [That element:J]
```
* Predicate 9: Retrieve the values of cells
```
:ha. Take the head of each element of the input
```
* Predicate 10: Append the length of a subset at the beginning of it
```
lg Put the length of the input in a list
:?c. Concatenate it with the input
```
* Predicate 11: Print one cell
```
b:+a[X:Y], Increment coordinates by 1 to get X and Y
?h:Y:Xr: Build the list [X:Y:Value]
"(~d,~d):~d\n"w Format that list as "('X','Y'):'Value'\n" to STDOUT
```
]
|
[Question]
[
*"All roads lead to Rome"* is a saying that essentially means there are plenty of different ways of achieving an objective.
# Task
Your task is to write a program that finds a set of link connections from one Wikipedia page to the [Wikipedia page about Rome](https://en.wikipedia.org/wiki/Rome).
Notice that it is not enough to find the word `Rome` with a hyperlink, `Rome` has to be linked to [this specific page](https://en.wikipedia.org/wiki/Rome): `"https://en.wikipedia.org/wiki/Rome"`
## Link connections
The Wikipedia pages are written in HTML, a markup language. With the appropriate syntax, a word or phrase can be annotated and turned into a hyperlink, which allows people to click the word/phrase and open a new Wiki page. You can see a couple of such link in the screenshot below:
[](https://i.stack.imgur.com/zJXE4.png)
Those annotated hyperlinks are what your program should locate and follow. To try and avoid some loopholes, we are going to restrict the links you are allowed to follow to the links within the `div` named `content`, which is roughly this part of the wiki page:
[](https://i.stack.imgur.com/RXRg2.png)
## Loopholes
* You are only allowed to query Wikipedia wiki pages on the internet. Your answer may not communicate with anything else. E.g., you are not allowed to download someone else's answer and run it.
* You may not communicate with any wiki APIs or Wiki "meta" pages, such as the "Category" page.
This community is very clever and imaginative. As more loopholes arise, those may be explicitly disallowed in the challenge. The *spirit* of the challenge is to find a series of links a user could click in the content of wiki pages.
# Input
Your code should take one of the two as input:
* a string that, when appended to `https://en.wikipedia.org/wiki/`, gives a valid link to a valid Wikipedia page;
* a string with the link already built for you.
You may assume there is a valid path between the input page and Rome's page.
# Output
Your program should output the path taken so that the lengths you claim are actually verifiable. It is up to you to output the path in any way that is human readable and understandable. Some suggestions include:
* the successive path links
* the successive page names
# Scoring
This is code-golf, so we care about byte count. You are allowed to define a string literal containing exactly these characters in this order: `"https://en.wikipedia.org/wiki/"` and not count it for the byte count of your program.
# Test cases
At the time of writing, these pages had a 1-link path to Rome:
```
"https://en.wikipedia.org/wiki/Italy"
"https://en.wikipedia.org/wiki/A.S._Roma"
"https://en.wikipedia.org/wiki/Vatican_Hill"
"https://en.wikipedia.org/wiki/Europe"
"https://en.wikipedia.org/wiki/European_Union"
```
And these pages had a path of length at most 2 to Rome:
```
"https://en.wikipedia.org/wiki/Continent"
"https://en.wikipedia.org/wiki/France"
```
(feel free to suggest more!)
Please submit your code with a screenshot or a TIO link showing a path from a Wikipedia page of your choosing to Rome.
[Answer]
# [JavaScript (Node.js)](https://nodejs.org), 335 - 30 = 305 bytes
I'm not very happy with it, but let's get the ball rolling.
Takes input as a page name. Prints a list of page names, separated with linefeeds.
```
u=>(i=0,g=a=>(m=a.find(u=>u=='Rome'))?console.log((h=v=>g[v]==u?u:h(g[v])+`
`+g[v])(m)+`
`+m):require('https').get('https://en.wikipedia.org/wiki/'+(U=a[i++]),r=>r.on('data',s=>h+=s,h="").on("end",_=>g([...new Set([...a,...((h.match(/mw-b.*mw-d/s)||[''])[0].match(/(?<=href=".wiki.).*?(?=")/g)||[]).map(v=>(g[v]=g[v]||U,v))])]))))([u])
```
[(Don't) try it online!](https://tio.run/##NU/LboMwELz3Kyou3g2OnTPqwj@0yglZjQsOdhtsah658O/UpO2uNJrZHWlnP/Wixya6YTr60JrtSttMJTg68Y50Yj1pcXW@hTSeidhr6A1DrJrgx3Az4hY6AEsLlV29KKK5mgsLO8f88nTJHwz6X9FjEc337KIBZqdpGBmKzkx/opDSeHF3X24wrdMixE7uSrIczqRrl@cKeaQyiuCBtXrSjI9U2pxGbinLcJ9nxrcZf095oBZCeHN/fksndq55gpRW9HpqLMj@fvwQh4StHHFda8YU1if1v4bqhWw0V8oeoQSKQwUVZSi73a0wGQdInz/epR3W9cwXRJU6FdSzwm37AQ)
### Example I/O
```
f("Commodore_64")
```
Results in:
```
Commodore_64
Christmas
Rome
```
[Answer]
# Python 3 + BeautifulSoup 4, 269 - 30 = 239 bytes
```
import bs4,requests as r
k=l=[(input(),)]
while'Rome'!=k[-1]:k=l.pop(0);l+=[k+(h[6:],)for h in[l.get('href')for l in bs4.BeautifulSoup(r.get('https://en.wikipedia.org/wiki/'+k[-1]).content).find(id='content').find_all('a')]if None!=h>h[:6]=='/wiki/'[':'in h:]]
print(k)
```
Input and output are page titles.
**Example outputs**
`OVS_(company)` => `('OVS_(company)', 'Albania', 'Rome')`
`Code_golf` => `('Code_golf', 'Source_code', 'Free_speech', 'Rome')`
[Answer]
# Java 10, ~~451~~ 418 - 30 = 388 bytes
```
p->{for(;;)for(var t:p){if(t.endsWith(" Rome"))return t;String w="https://en.wikipedia.org/wiki/",c=t;try{try(var b=new java.io.BufferedReader(new java.io.InputStreamReader(new java.net.URL(w+t.replaceAll(".*?(\\S+)$","$1")).openStream()))){for(;(i=b.readLine())!=null;)c+=i;}for(var h:c.replaceAll(".*ole=.mai(.*)id=.catl.*","$1").split("href=./wiki/"))p.add(t+" "+h.substring(0,h.indexOf('"')));}finally{continue;}}}
```
Extremely slow would be an understatement, but it works..
Takes just the page (wrapped into a `CopyOnWriteArraySet<String>`) as input. Outputs the pages space-delimited as String.
Example run locally:
```
Input: "Java_(programming_language)"
Output: "Java_(programming_language) Rust_(programming_language) Rome"
```
**Explanation:**
```
p->{ // Method with Set<String> parameter and String return-type
for(;;) // Loop indefinitely:
for(var t:p){ // Loop over each String `t` in the input-CopyOnWriteArraySet:
// (it's a CopyOnWriteArraySet, since we otherwise wouldn't
// be able to add while iterating)
if(t.endsWith(" Rome")) // If the current String `t` ends with " Rome"
return t; // Return it as result
String w="https://en.wikipedia.org/wiki/",
// String with the base url of Wikipedia
c=t; // Content-String (starts at `t` instead of "" to save a byte)
try{try(var b=new java.io.BufferedReader(new java.io.InputStreamReader(new java.net.URL(w
// Go to the Wikipedia website
+t.replaceAll(".*?(\\S+)$","$1")
// with everything after the last space in `t` as page
).openStream()))){ // And open this website as a try-with-resources BufferedReader
for(;(i=b.readLine())!=null;)
// Read all lines of the page:
c+=i;} // And append each line to the content-String
for(var h:c.replaceAll(".*ole=.mai(.*)id=.catl.*","$1")
// Take the content between 'ole="mai' and 'id="catl':
// ('role="main"' and 'id="catlinks"')
.split("href=./wiki/"))
// Split it on 'href="/wiki/', and loop over each part:
p.add( // Add to the input-Set:
t+" " // The current String with an appended space
+h.substring(0,h.indexOf('"')));
// Appended with the leading part up until the first '"'
}finally{ // If any error occurs accessing the page (i.e. going to "wiki/.")
continue;}}} // Skip it, and go to the next iteration
```
]
|
[Question]
[
*This is the second in a series of Island Golf challenges. [Previous challenge](https://codegolf.stackexchange.com/q/113628/16766)*
Two hermits have arrived on a desert island. Since they came seeking solitude, they wish to live as far away from each other as possible. Where should they build their huts to maximize the walking distance between them?
[Related reading](https://en.wikipedia.org/wiki/Distance_(graph_theory)#Related_concepts)
## Input
Your input will be a rectangular grid consisting of two characters, representing land and water. In the examples below, land is `#` and water is `.`, but you may substitute any two distinct characters you wish.
```
...........
...##......
..#####....
..#######..
.#########.
...#######.
...#####.#.
....####...
...........
```
There will always be at least two land tiles. The land tiles will all be contiguous (i.e. there's only one island). The water tiles will also be contiguous (i.e. there are no lakes). The outer border of the grid will all be water tiles. Land tiles will **not** be connected diagonally: i.e., you will never see something like
```
....
.#..
..#.
....
```
## Output
Your code must output the same grid, with two *hut locations* marked on it. In the examples below, the hut locations are marked with X, but you may substitute any character as long as it is distinct from your land and water characters.
The hut locations must be two land tiles, chosen so as to maximize the *walking distance* between them. We define walking distance as the length of the shortest path, entirely on land, between the two points. Land tiles are considered adjacent horizontally or vertically, but **not** diagonally.
A possible solution for the above island:
```
...........
...X#......
..#####....
..#######..
.#########.
...#######.
...#####.X.
....####...
...........
```
The walking distance between these two points is 11, which is the greatest distance between any two points on this island. There is another distance-11 solution:
```
...........
...##......
..X####....
..#######..
.#########.
...#######.
...#####.X.
....####...
...........
```
## Details
Your solution may be a [full program or a function](https://codegolf.meta.stackexchange.com/a/2422/16766). Any of the [default input and output methods](https://codegolf.meta.stackexchange.com/q/2447/16766) are acceptable.
Your input and output may be a multiline string, a list of strings, or a 2D array/nested list of characters/single-character strings. Your output may (optionally) have a single trailing newline. As mentioned above, you may use any three distinct characters in place of `#.X` (please specify in your submission which characters you're using).
## Test cases
**A.** Islands with unique hut placements:
```
....
.##.
....
....
.XX.
....
......
......
..##..
...#..
......
......
......
......
..X#..
...X..
......
......
........
.#####..
.##..##.
.#..###.
.##..##.
........
........
.#####..
.##..##.
.#..###.
.#X..#X.
........
.........
.#####.#.
.#...#.#.
.#.###.#.
.#.....#.
.#######.
.........
.........
.#####.X.
.#...#.#.
.#.X##.#.
.#.....#.
.#######.
.........
```
**B.** Example of an island with multiple possible solutions:
```
........
....##..
...####.
..###...
.#####..
.#####..
..##....
........
```
Possible outputs:
```
........
....#X..
...####.
..###...
.#####..
.X####..
..##....
........
........
....#X..
...####.
..###...
.#####..
.#####..
..X#....
........
........
....##..
...###X.
..###...
.#####..
.X####..
..##....
........
........
....##..
...###X.
..###...
.#####..
.#####..
..X#....
........
```
**C.** [Large test case as a Gist](https://gist.github.com/dloscutoff/6bc4a16c1ee9b7932aef9c00ea99cd3e)
---
This is [code-golf](/questions/tagged/code-golf "show questions tagged 'code-golf'"): the shortest code in each language wins.
[Answer]
# Python 3, ~~249~~ 246 bytes
Shaved off 3 bytes, thanks DLosc.
Input and output are single strings, with '.', '@', and 'X' representing water, huts, and land, respectively.
```
A='@'
def f(s):
w=s.find('\n')+1;d=u={(k,k):0for k,c in enumerate(s)if A<c}
while u:d.update(u);u={(k,j):d[(k,i)]+1for k,i in d for j in{i+1,i+w,i-1,i-w}if A<s[j]and(k,j)not in d}
k,j=sorted(max(d,key=d.get))
return s[:k]+A+s[k+1:j]+A+s[j+1:]
```
Prior version:
Input is a single string, with '.' and '#' representing water and land, respectively. 'X' represents the huts in the output.
```
def f(s):
w=s.find('\n')+1;d=u={(k,k):0for k,c in enumerate(s)if'#'==c}
while u:d.update(u);u={(k,j):d[(k,i)]+1 for k,i in d for j in{i+1,i+w,i-1,i-w}if'#'==s[j]and(k,j)not in d}
k,j=sorted(max(d,key=d.get))
return s[:k]+'X'+s[k+1:j]+'X'+s[j+1:]
```
Explanation:
It's basically doing a breadth first search from every possible starting point at the same time. Keep a dictionary, d, of path lengths keyed by the start and end of the path, e.g., d[(k,i)] is the distance from k to i. Then iterate over the keys in the dictionary, d, and create a new dictionary, u, with paths that are 1 unit longer by moving the end point 1 unit to the N,S,E,W, e.g., u[(k, i+1)] = d[(k,i)] + 1. Don't include paths that are already in d. If u is not empty, then add the new longer paths to d and repeat. When u is empty, that means no more paths could be made. Now d contains all the possible paths and their lengths. So its just a matter of getting the key with the longest path.
Less golfed, commented version:
```
def f(s):
w=s.find('\n')+1 # width of a row, or a move N or S
d = {} # dictionary of all the paths.
# The key is a tuple (k,j) and the
# value is the distance from k to j.
for k,c in enumerate(s): # Initialize. Distance from k to k is 0
if'#'==c: # Only do land.
d[(k,k)] = 0
u = d # dictionary of new paths. initialize it to d
# so loop is entered. first d.update is
# basically a NOP
while u: # while there are new paths
d.update(u) # add the new paths to the dict of old paths
u={} #
for k,i in d: # iterate over the known paths. k is the start, i is the end
for j in{i+1,i+w,i-1,i-w}: # iterate over squares 1 move to the E,S,W,N from i
if'#'==s[j]and(k,j)not in d: # if it's still land, and the path (k,j) isn't already in d,
u[(k,j)] = d[(k,i)]+1 # then add the new path to u
k,j=sorted(max(d,key=d.get)) # find the longest path
return s[:k]+'X'+s[k+1:j]+'X'+s[j+1:] # X marks the endpoints.
```
[Answer]
# C#, 387 bytes
Let's get the ball rolling...
```
using C=System.Console;class P{static void Main(){string D="",L;int W=0,H=0,z,n,q,h,b=0,c,a,i=0,j=0;for(;(L=C.ReadLine())!=null;H+=W=L.Length)D+=L+="\n";for(z=H;z-->0;){int[]S=new int[H],Q=new int[H*8];for(Q[h=q=0]=z;q<=h;)if((c=S[n=Q[q++]]-1)<0&D[S[n]=n]==35)for(a=4;a-->0;b=c<b?c+(i=z)*(j=n)*0:b)S[Q[++h]=new[]{1,-1,W,-W}[a]+n]=S[Q[h]]<1?c:1;}for(;++z<H;)C.Write(z==i|z==j?'X':D[z]);}}
```
[Try it Online](https://tio.run/nexus/cs-mono#lZJfb4IwFMXf/RRMko3aQiDbksVy54M@8MCSOR9Y0vUBEaXG1Si4ZTg/uyuocypmW/nXnh/nnlzKepEKOdLa0PtIs/jVak9lOp3ENJqEaao9LtMszESkvU3FQHsIhTSQkuaFpQP1OvGpkJkWgE08deVEkhlJSF/NIxISoZ5jsOlwOjeo4UPbeorDgS9kbCB0AXIxmVAPQwC@5cdylCWog8HHUH@R9dKUg0dz07y3KVqqIMZ7ION3rZh6nHT3i8YdLw1dlsAMbA45nbmQUCSGhhFBj0noshnGnJsOcu3LDlMSB3XC9S0qnCHc0LCM6kPk9lsRNgTkqGGMQaKG3eyjHusyjBNepDK@dIjpkICYwYqFHKtKBU84d51W1HToqmwa49z1KGpbwVxkseoHxKe6jVtXz1fNDss5oqtVbb22zoza34BeDfTi0Lf8FGzhD6Bvx1lQwi3Qq8Gu8gGpFW8eiXtQoW9KVejVju/Oq4F@zqGfDf@PYwNO0q2d45jswO7THm5h7XRTf/kZvgA)
Complete program, reads from STDIN, writes to STDOUT. It simply goes over each cell, and runs a BFS to compute the farthest cell, recording both if it is the farthest on record. Nothing to it really, and frustratingly little I can find to golf.
Formatted and commented code:
```
using C=System.Console;
class P
{
// \n 10
// \r 13
// . 46
// # 35
// x 88
static void Main()
{
string D="", // map
L; // line of input
int W=0, // width
H=0, // length
z, // outer position
n, // next position to expand
q, // queue position pointer
h, // queue head pointer
b=0, // best
c, // distance to this cell (negative)
a, // counter
i=0, // hermit 1 pos
j=0; // hermit 2 pos
for(;(L=C.ReadLine())!=null; // read a line, while we can
H+=W=L.Length) // record the width, and add to length
D+=L+="\n"; // add a newline, and add the line to the map
for(z=H;z-->0;) // for each cell
{
int[]S=new int[H], // 'seen' >0 -> seen, else it is the distance we have found to it
Q=new int[H*8]; // due queue (fewer than H*4 expantions, two ints each)
// standard BFS
for(Q[h=q=0] // reset currect
=z; // expand z first
q<=h;)
if((c=S[n=Q[q++]]-1)<0& // record 'seen', and check we havn't been seen
D[S[n]=n]==35) // mark as seen, and check we are a hash #
// 'move'
for(a=4;a-->0; // for each of the 4 neighbours
b=c<b? // if we have beaten the best
c+(i=z)*(j=n)*0: // set new best, record hermit positions
b)
S[Q[++h]=new[]{1,-1,W,-W}[a]+n]= // queue it for expantion
S[Q[h]]<1? // not seen? (this is BFS, don't need to check c is less thatn S[l+n]
c: // distance
1; // mark as seen (means it won't actually be expanded)
}
// z = -1
for(;++z<H;) // for each cell
C.Write(z==i|z==j?'X':D[z]); // print either the original char, or X if it is a hermit's home
}
}
```
]
|
[Question]
[
Consider the following string:
```
Tin Snips
```
This string contains several atomic symbols on the [periodic table](https://en.wikipedia.org/wiki/Periodic_table). We could rewrite this string to identify several of them:
```
[Ti][N] [Sn][I][P][S]
```
Of course, we could also write it this way:
```
T[In] [S][Ni][P][S]
```
The rules for rewriting the input are as follows:
1. The case of the input does not matter in terms of matching atomic symbols.
2. If an element is used in an atomic symbol, its case must change so the symbol is correct. Ex: `h` would become `[H]`.
3. All element symbols are encased in ASCII square brackets, `[` and `]`.
4. Whitespace is preserved: `Big ego` cannot combine the "g" and "e" into `[Ge]`.
5. Not all input characters need be combined into an atomic symbol: if an input character is not put into a symbol, it is passed through as-is (case does not matter).
6. If a symbol can be made, it *must* be made. In other words, it is not allowed to output `Tin` in the above example because it is possible to create at least one symbol in that word. The only time a character may be passed through unused is when it cannot be used to construct an atomic symbol.
7. For the purposes of this challenge, all elements from Hydrogen (1) to Oganesson (118) are valid. No higher elements are valid.
8. Some of the higher elements have ambiguous names and symbols: for the purposes of this challenge, the [version at Wikipedia](https://en.wikipedia.org/wiki/Periodic_table) shall be used. For convenience, the allowable atomic symbols are here: H, He, Li, Be, B, C, N, O, F, Ne, Na, Mg, Al, Si, P, S, Cl, Ar, K, Ca, Sc, Ti, V, Cr, Mn, Fe, Co, Ni, Cu, Zn, Ga, Ge, As, Se, Br, Kr, Rb, Sr, Y, Zr, Nb, Mo, Tc, Ru, Rh, Pd, Ag, Cd, In, Sn, Sb, Te, I, Xe, Cs, Ba, La, Ce, Pr, Nd, Pm, Sm, Eu, Gd, Tb, Dy, Ho, Er, Tm, Yb, Lu, Hf, Ta, W, Re, Os, Ir, Pt, Au, Hg, Tl, Pb, Bi, Po, At, Rn, Fr, Ra, Ac, Th, Pa, U, Np, Pu, Am, Cm, Bk, Cf, Es, Fm, Md, No, Lr, Rf, Db, Sg, Bh, Hs, Mt, Ds, Rg, Cn, Nh, Fl, Mc, Lv, Ts, Og.
Write a program or function that generates all possible outputs from a single provided input. Both input and output may be in any form of your choosing. This could be a string, array of characters, or some other data structure: whatever is both convenient and clearly represents the input and output. Both input and output may be passed in/out of your code however you choose: standard in/out, function argument/return, or something else.
* Input shall be a string (see previous paragraph) of positive length containing only ASCII characters of arbitrary case and the space (`0x20`) character.
* Your code must generate all output strings that can be created using the input rules above.
* The order of the output is implementation-defined. The only requirement is that *all* output strings are present.
* If presented with a valid input string that does not contain any atomic symbols, simply output the input string.
* If presented with an input string that is not valid per the rules above (null, zero characters, contains illegal characters, etc.) your program may do anything (crash, blank output, etc.)
* Output is case-insensitive other than atomic symbols needing to match the periodic table.
* Standard loopholes not allowed.
Test cases:
```
Tin Snips
[Ti][N] [Sn][I][P][S]
[Ti][N] [S][Ni][P][S]
[Ti][N] [S][N][I][P][S]
T[In] [Sn][I][P][S]
T[In] [S][Ni][P][S]
T[In] [S][N][I][P][S]
T[I][N] ...
Quack
Q[U][Ac][K]
Q[U]a[C][K]
hehe
[H]e[H]e
[H]e[He]
[He][H]e
[He][He]
Stack Exchange
[S][Ta][C][K] Ex[C][H]a[N][Ge]
[S]t[Ac][K] Ex[C][H]a[N][Ge]
```
This is code golf, so let me see your shortest code!
[Answer]
# Python 3, ~~289~~ 263 bytes
Found a more complete library on Pypi: `mendeleev`
```
from mendeleev import*
Z={element(i).symbol for i in range(1,119)}
L,R='[]'
def f(h,r=''):t=h.title();return((Z&{t[0]}and f(h[1:],r+L+t[0]+R)or[])+(Z>{(t+L)[:2]}and f(h[2:],r+L+t[:2]+R)or[])+(not{(r[-1:]+t[0]).title(),t[0]}&Z and f(h[1:],r+h[0])or[]))if h else[r]
```
Old answer:
```
from elements import*
Z={e.symbol for e in ELEMENTS}|{*'Cn Ds Fl Lv Mc Nh Og Rg Ts'.split()}
L,R='[]'
def f(h,r=''):t=h.title();return((Z&{t[0]}and f(h[1:],r+L+t[0]+R)or[])+(Z>{(t+L)[:2]}and f(h[2:],r+L+t[:2]+R)or[])+(not{(r[-1:]+t[0]).title(),t[0]}&Z and f(h[1:],r+h[0])or[]))if h else[r]
```
Uses a library `elements.py` from <http://www.lfd.uci.edu/~gohlke/code/elements.py.html>. It is missing elements 110 to 118, but it was the most up to date library I could find. Cost 40 bytes to add the missing elements.
The trickiest part was the logic for when a character can be passed through without being part of an element symbol.
[Answer]
# [Jelly](https://github.com/DennisMitchell/jelly), ~~192~~ 191 bytes
-1 by use of `Ɗ` (a since-developed quick)
```
“¦UV2ḤF2ı½ṅḶḊ⁼5JI5MẇvẋẊẊ¬Ḥḳ'ƈ<ḷėƤ7*⁾ṾxMæS⁺`?^Ƭb¦ɗDß⁼pþɲOṃ⁽2Ė>,Ḣ(ḞŒƊOGƤ×⁺ṇṂ®ȤT0y°^Ẇ⁺:Þ]ṢṬ¶ịṪḂƇ ñAƬCṫ$wÆĿĖỴỴƇẓƊqḌ@;ẏ`ṃFƥḣ⁽²»ḟ⁶s2;“¤²R.ȯ7ŒL£ɦ»Œt
Œte¢
ŒṖµL€=1oÇ€ṂµÐfµṡ2;€ÇÐfÇ€€S€¬SµÐḟ⁾[]jŒtƊ¹Ç?€€
```
**[Try it online!](https://tio.run/##JU9dSwJREH3vV/QQFBFRCyH0ZVEYhSKkBRGKBAVGlGFUvqWRG2tQGOhLGOm2D7X0YWn3rmkwd73kz5j9I9tocIZhZs6cM7O7vbeXcl3n7A6MtXUFme5T7HdoIr9AVkemOenviZXliQBa6jFaObQ0AphERPYxKC@nkX3ZRal7hp10C3nrNCCMkJO2Yt6oNLfA6BQXxT2JJESrUw0iP3fSTcUuzI4gKw8hK7XzUgsuSV0UaQm5ijwDL796eCwFb1G0stSdFKUI8jJyE@rYyCF/QpaRar94n5fmAvLngRORtX/sAjY@CVJF61Zqh8iu5qbQuo6RqU8@IquQNVShgYwOqieVqe7XOlRXR39fPe28HyodAxrt/FEfxTaUKSEvQM3vZMyZ8QOhUu6eVxM3O1BD/kAKGVOoVPZmhBAFmKEupefS2ozskpjUgAvV@89xhbrhuuH4fn9oP55I/gE "Jelly - Try It Online")** - Too inefficient for the "Stack Exchange" test case to complete within the 60s limit (running it offline gives the correct result within 2 minutes).
### How?
The first line of code is a niladic link to create a list containing all 118 element symbols. To do so it concatenates two lists, the first containing all length 2 lists of characters (i.e. strings) the second a list of characters and title cases the resulting list. The two lists themselves are created mostly by looking up words in Jelly's dictionary to make single strings.
The first of these compressions is:
```
“¦UV2ḤF2ı½ṅḶḊ⁼5JI5MẇvẋẊẊ¬Ḥḳ'ƈ<ḷėƤ7*⁾ṾxMæS⁺`?^Ƭb¦ɗDß⁼pþɲOṃ⁽2Ė>,Ḣ(ḞŒƊOGƤ×⁺ṇṂ®ȤT0y°^Ẇ⁺:Þ]ṢṬ¶ịṪḂƇ ñAƬCṫ$wÆĿĖỴỴƇẓƊqḌ@;ẏ`ṃFƥḣ⁽²»
```
which yields
```
" biznagas sepmag ratbag catchflies paracmes mdse bharal ramcat monopteros irrepressibilities lunarnauts geniculate hopbinds rutabaga potlache broghs bergamas crossbirth purblind xebecs nonhardy classism fleurets moneybag scarce corf Mg Sr Zr CD HG CF FM Lr SG TM Gd Bk Fr Rh Fe Sn lv cndbmnnbkrmtpdnp"
```
Where all but the final entry (split by spaces) are entries in Jelly's dictionary. The spaces are filtered out with `ḟ⁶`, and then the result is split into twos:
```
["bi","zn","ag","as","se","pm","ag","ra","tb","ag","ca","tc","hf","li","es","pa","ra","cm","es","md","se","bh","ar","al","ra","mc","at","mo","no","pt","er","os","ir","re","pr","es","si","bi","li","ti","es","lu","na","rn","au","ts","ge","ni","cu","la","te","ho","pb","in","ds","ru","ta","ba","ga","po","tl","ac","he","br","og","hs","be","rg","am","as","cr","os","sb","ir","th","pu","rb","li","nd","xe","be","cs","no","nh","ar","dy","cl","as","si","sm","fl","eu","re","ts","mo","ne","yb","ag","sc","ar","ce","co","rf","Mg","Sr","Zr","CD","HG","CF","FM","Lr","SG","TM","Gd","Bk","Fr","Rh","Fe","Sn","lv","cn","db","mn","nb","kr","mt","pd","np"]
```
The second,
```
“¤²R.ȯ7ŒL£ɦ»
```
is formed from the concatenation of the words "finch", "pub", "sky", and "vow" (without spaces), and as such is a list of characters:
```
['f','i','n','c','h','p','u','b','s','k','y','v','o','w']
```
The two lists are concatenated with `;` and every entry is title-cased using `Œt`, yielding:
```
["Bi","Zn","Ag","As","Se","Pm","Ag","Ra","Tb","Ag","Ca","Tc","Hf","Li","Es","Pa","Ra","Cm","Es","Md","Se","Bh","Ar","Al","Ra","Mc","At","Mo","No","Pt","Er","Os","Ir","Re","Pr","Es","Si","Bi","Li","Ti","Es","Lu","Na","Rn","Au","Ts","Ge","Ni","Cu","La","Te","Ho","Pb","In","Ds","Ru","Ta","Ba","Ga","Po","Tl","Ac","He","Br","Og","Hs","Be","Rg","Am","As","Cr","Os","Sb","Ir","Th","Pu","Rb","Li","Nd","Xe","Be","Cs","No","Nh","Ar","Dy","Cl","As","Si","Sm","Fl","Eu","Re","Ts","Mo","Ne","Yb","Ag","Sc","Ar","Ce","Co","Rf","Mg","Sr","Zr","Cd","Hg","Cf","Fm","Lr","Sg","Tm","Gd","Bk","Fr","Rh","Fe","Sn","Lv","Cn","Db","Mn","Nb","Kr","Mt","Pd","Np","F","I","N","C","H","P","U","B","S","K","Y","V","O","W"]
```
A list containing all 118 element symbols as required (there are duplicates, but that's fine).
The second line of code is a monadic link (a helper function designed to take one input) that returns a 1 if the input, titled-cased exists in the list created above and a 0 otherwise.
The third line of code is the main link, a monadic function that takes a string and returns a list of lists of characters (i.e. strings) as required:
```
ŒṖµL€=1oÇ€ṂµÐfµṡ2;€ÇÐfÇ€€S€¬SµÐḟ⁾[]jŒtƊ¹Ç?€€ - Main link: s
ŒṖ - all partitions of s
µ µÐf - filter keep:
L€=1 - length €ach equals (vectorises) 1
o - or
Ç€ - last link as a monad (is an element when title-cased)
Ṃ - minimum
- (i.e. all partitions that are all single characters OR are strings that when title-cased are elements)
µ µÐḟ - filter discard:
ṡ2 - slices of length 2
;€ - concatenate €ach
Ðf - filter keep:
Ç - last link as a monad (is an element when title-cased)
Ç€€ - last link as a monad for €ach for €ach
S€ - sum €ach
¬ - logical not
S - sum
- (i.e. discard any partitions that contain a run of two that joined together and title-cased ARE an element but separately NEITHER are)
?€€ - if then else for €ach (partition) for €ach (part):
Ç - IF: last link as a monad (is an element when title-cased)
- THEN:
Ɗ - last three links as a monad:
⁾[] "[]"
j - joined by:
Œt - title case the part
- ELSE:
¹ - the part itsef (¹ is the identity atom)
```
[Answer]
# C++11, ~~944~~ 928 bytes
Here's a piece of truly terrible code, but it should work. Could still be made a lot shorter probably.
```
#import<iostream>
#import<set>
using namespace std;int r,i;set<string>O;S(string&s){s[0]-=s[0]>90?32:0;if(s[1])s[1]+=s[1]<91?32:0;char*l="HHeLiBeBCNOFNeNaMgAlSiPSClArKCaScTiVCrMnFeCoNiCuZnGaGeAsSeBrKrRbSrYZrNbMoTcRuRhPdAgCdInSnSbTeIXeCsBaLaCePrNdPmSmEuGdTbDyHoErTmYbLuHfTaWReOsIrPtAuHgTlPbBiPoAtRnFrRaAcThPaUNpPuAmCmBkCfEsFmMdNoLrRfDbSgBhHsMtDsRgCnNhFlMcLvTsOg";for(r=0;*l++;)if(*l>90){if(*(l++-1)==s[0]&&*(l-1)==s[1])r=1;}else if(*(l-1)==s[0]&&!s[1])r=1;}P(set<string>*V,string s,string o,int b,int l=0,int m=0){if(!s[b])O.insert(o);else if(l)P(V,s,o,b+1);else if(V[b].size()==0)P(V,s,o+s[b],b+1);else for(auto t:V[b]){P(V,s,o+"["+t+"]",b+1,t.length()-1);if(t.length()>1&&V[b].size()==1&&V[b+1].size()>0&&!m)P(V,s,o+s[b],b+1,0,1);}}F(string s){set<string>V[s.length()];for(i=0;s[i++];){string t="";t+=s[i-1];S(t);if(r)V[i-1].insert(t);t+=s[i];S(t);if(r&&s[i])V[i-1].insert(t);}P(V,s,"",0);for(auto o:O)cout<<o<<"\n";O.clear();}
```
Call with:
```
int main()
{
F("Tin Snips");cout << "\n";
F("Quack");cout << "\n";
F("hehe");cout << "\n";
F("Stack Exchange");
}
```
]
|
[Question]
[
I was browsing esolangs, and chanced upon this language: <https://github.com/catseye/Quylthulg>.
One interesting thing about this language, is that it doesn't use prefix, postfix, or infix, it uses *all three of them*, calling it "panfix" notation.
Here is an example. To represent normal infix `1+2` in panfix, it becomes: `+1+2+`. Notice how the operator is both before, in between, and after the operands. Another example is `(1+2)*3`. This becomes `*+1+2+*3*`. Notice again how `*` is in all three places with respect to the operands `+1+2+` and `3`.
# The Challenge
As you may have guessed, your task in this challenge is to convert an expression from infix to panfix.
A few clarifications:
* You only have to deal with the four basic operations: `+-*/`
* You won't have to deal with the unary versions of those, only binary
* You have to deal with parenthesis
* Assume the normal precedence rules of `*/` then `+-` and left associativity for all of them.
* The numbers will be nonnegative integers
* You can optionally have a spaces in both the input and output
# Test Cases
```
1+2 -> +1+2+
1+2+3 -> ++1+2++3+
(1+2)*3 -> *+1+2+*3*
10/2*5 -> */10/2/*5*
(5+3)*((9+18)/4-1) -> *+5+3+*-/+9+18+/4/-1-*
```
This is [code-golf](/questions/tagged/code-golf "show questions tagged 'code-golf'"), so shortest code in **bytes** wins!
[Answer]
## JavaScript (ES6), 160 bytes
```
f=(s,t=s.replace(/[*-/]/g,"'$&'"),u=t.replace(/^(.*?)([*-9]+)'([*/])'([*-9]+)|([*-9]+)'([+-])'([*-9]+)|\(([*-9]+)\)/,"$1$3$2$3$4$3$6$5$6$7$6$8"))=>t==u?t:f(s,u)
```
Works by quoting all the operators (which gives them character codes before `*`), then looking for available `'*'` or `'/'` operations, `'+'` or `'-'` operations or `()`s, and replacing the first with its panfix notation. Example:
```
(5+3)*((9+18)/4-1)
(5'+'3)'*'((9'+'18)'/'4'-'1)
(+5+3+)'*'((9'+'18)'/'4'-'1)
+5+3+'*'((9'+'18)'/'4'-'1)
+5+3+'*'((+9+18+)'/'4'-'1)
+5+3+'*'(+9+18+'/'4'-'1)
+5+3+'*'(/+9+18+/4/'-'1)
+5+3+'*'(-/+9+18+/4/-1-)
+5+3+'*'-/+9+18+/4/-1-
*+5+3+*-/+9+18+/4/-1-*
```
[Answer]
# JavaScript (ES6), ~~285~~ ~~282~~ ~~281~~ ~~267~~ ~~251~~ ~~243~~ ~~241~~ ~~238~~ ~~234~~ ~~232~~ 231 bytes
*~15 bytes thanks to [Neil](https://codegolf.stackexchange.com/users/17602/neil).*
```
f=(I,E=I.match(/\d+|./g),i=0)=>(J=T=>T.map?T.map(J).join``:T)((R=(H,l=(P=_=>(t=E[i++])<")"?R(0):t)(),C,F)=>{for(;(C=P())>")"&&(q=C>"*"&&C<"/")*H-1;)F=q+H?l=[C,l,C,P(),C]:F?l[3]=[C,l[3],C,R(1),C]:l=R(1,l,i--)
i-=C>")"
return l})(0))
```
In JavaScript this is a bit harder than in Mathematica. This is basically an over-specialized and golfed [operator-precedence parser](https://en.wikipedia.org/wiki/Operator-precedence_parser).
Causes stack overflows on invalid inputs.
### Demo
```
f=(I,E=I.match(/\d+|./g),i=0)=>(J=T=>T.map?T.map(J).join``:T)((R=(H,l=(P=_=>(t=E[i++])<")"?R(0):t)(),C,F)=>{for(;(C=P())>")"&&(q=C>"*"&&C<"/")*H-1;)F=q+H?l=[C,l,C,P(),C]:F?l[3]=[C,l[3],C,R(1),C]:l=R(1,l,i--)
i-=C>")"
return l})(0))
```
```
<input id="input" value="(5+3)*((9+18)/4-1)"/><button onclick="console.log(f(document.querySelector('#input').value))">Convert</button>
```
### Ungolfed
```
convert = input => {
tokens = input.match(/\d+|./g);
i = 0;
parse_token = () => (token = tokens[i++]) == "(" ? parse_tree(false) : token;
parse_tree = (mul_div_mode, left = parse_token()) => {
while ((oper = parse_token()) != ")" && !((is_plus_minus = oper == "+" || oper == "-") && mul_div_mode)) {
if (is_plus_minus || mul_div_mode)
left = [oper, left, oper, parse_token(), oper];
else if (non_first)
left[3] = [oper, left[3], oper, parse_tree(true), oper];
else
left = parse_tree(true, left, i--);
non_first = true;
}
if (oper != ")")
i--;
return left;
};
format_tree = tree => tree.map ? tree.map(format_tree).join("") : tree;
return format_tree(parse_tree(false));
}
```
[Answer]
## Mathematica, ~~203~~ 195 bytes
This is likely less than efficient, but seems to do the job.
```
Function[f,ReleaseHold[(Inactivate@f/._[Plus][a_,b_/;b<0]:>a~"-"~-b//Activate@*Hold)//.a_/b_:>a~"/"~b/.{a_Integer:>ToString@a,Plus:>"+",Times:>"*"}]//.a_String~b_~c_String:>b<>a<>b<>c<>b,HoldAll]
```
This is an anonymous function that takes an actual expression and returns a string with panfix notation. Mathematica sorts out the precedence of operators at parsing time, rather than evaluation time, so the nesting should be automagically correct. At least the test cases work as expected.
Explanation: It's easy enough to interpret the entire expression as a tree, like so:
[](https://i.stack.imgur.com/ngmA7.png)
At this stage the operators (every node that isn't a leaf) aren't operators any more, they've actually been converted to strings such as `"+"`. The integers are also cast to strings. Then a repeated replacement rule converts every node that has exactly two leafs to the panfix `parent-leaf1-parent-leaf2-parent`. After some iterations the tree reduces to a single string.
The main loss in the byte count is that Mathematica interprets
```
5 - 4 -> 5 + (-4)
9 / 3 -> 9 * (3^(-1))
```
And this happens also at parsing time.
Golfed down a bit, since the pattern `a_/b_` is also interpreted as `a_ * (b_)^(-1)`. Also some minor optimizations elsewhere.
[Answer]
# Prolog, 87 bytes
```
x(T)-->{T=..[O,A,B]}->[O],x(A),[O],x(B),[O];[T].
p:-read(T),x(T,L,[]),maplist(write,L).
```
This is a function (mostly because writing a full program has nightmarish levels of boilerplate in Prolog; normally, even if you *compile* a program, it produces a REPL when run), called `p`. It takes input from stdin and outputs on stdout. Note that you need to append a period to the input, which is an unfortunate consequence of the way that Prolog's input routines work (they use periods in the input in much the same way that other languages use newlines); that might or might not disqualify the answer.
## Explanation
Arithmetic operators, in Prolog, are normally interpreted [as tuple constructors](https://codegolf.stackexchange.com/a/108132/62131). However, they obey the same precedence rules as the actual arithmetic operators they're based on; you can form tuples with infix notation, and `+` and `-` bind less tightly than `*` and `/`, with precedence taken left to right within a group. This is exactly what the question asks for; thus, we can read an entire nested tuple from the input, and it already has the right structure. That's what `p` does.
Next, we need to convert it to panfix notation. `x` converts the input into a panfixed list of constructors and integers, and can be read as an English sentence almost directly: "`x` of `T` is: if `T` is a tuple with constructor `O` and arguments `A`,`B`, then `O`, `x` of `A`, `O`, `x` of `B`, `O`, else `T`". Finally, we just have to print the list without any separators (i.e. using `maplist` to call `write` on each element of the list).
I used SWI-Prolog for testing this, because my version of GNU Prolog doesn't have `maplist` yet (apparently it's been added to a newer version), but it should generally be fairly portable between Prolog implementations.
]
|
[Question]
[
For every given degree \$n\$ it is possible to construct (at least one) an integral polynomial \$p \in \mathbb Z[X]\$ such that \$p(k)\$ (\$p\$ evaluated in \$k\$) is the coefficient of the term \$x^k\$ in the polynomial for all \$0 \leqslant k \leqslant n\$. To make them unique, we require the leading coefficient (the coefficient of \$x^n\$) to be positive and minimal.
These polynomials have some interesting properties, you can find some references in the [thread that inspired me to do this challenge](https://www.reddit.com/r/math/comments/4lnlfy/selfreferential_polynomials/). You can also find those polynomials in <https://oeis.org/A103423>
One of the a priori unexpected properties is how the roots behave depending on \$n\$:
[](https://i.stack.imgur.com/FDX1z.gif)
[source (by /u/zorngov and /u/EpicSauceSc2)](https://www.reddit.com/r/math/comments/4lnlfy/selfreferential_polynomials/d3ozkom)
### Task
Given a nonnegative integer \$n\$ output the self referential integral polynomial of degree \$n\$ with minimal positive leading coefficient.
### Details
The output can be in any human readable form, as string `x^2-x-1`, or also as a list of coefficients `[1,-1,-1]`. (The order of the coefficients can also be the other way around, it just needs to be consistent.)
### First few outputs
```
n=0: 1
n=1: x
n=2: x^2-x-1
n=3: 10*x^3-29*x^2-6*x+19
n=4: 57*x^4-325*x^3+287*x^2+423*x-19
n=5: 12813*x^5-120862*x^4+291323*x^3+44088*x^2-355855*x-227362
```
[Answer]
# Mathematica, 55 bytes
```
NullSpace@Table[x^c-Boole[r==c]/.x->r,{r,0,#},{c,0,#}]&
```
Output is the list coefficients, beginning from the constant term. Example:
```
In[1084] := Do[Print[%1077[n] // StandardForm], {n, 0, 7}]
{{1}}
{{0,1}}
{{-1,-1,1}}
{{19,-6,-29,10}}
{{-19,423,287,-325,57}}
{{-227362,-355855,44088,291323,-120862,12813}}
{{145991969,64989065,-123338281,-85635661,79841909,-18146731,1286795}}
{{-5958511844199,3384370785404,8437850634901,489428412300,-4499161007143,1776194531596,-258931801371,13131073916}}
```
---
This simply finds the vector such that `(A - I)v = 0`, similar to the MAPLE code in OEIS. The `NullSpace` method seems to always pick the minimal positive number for the last element, which matches the task description.
The `x^c-…/.x->r` indirection is to prevent having `0^0 == Indeterminate`.
[Answer]
# [Sage](http://www.sagemath.org/), 74 bytes
```
lambda n:kernel(matrix(n+1,[j^-i-(-i==j)for i in[-n..0]for j in[0..n]])).0
```
The `-i` and `[-n..0]` could be `i` and `[0..n]`, if not for the positive leading coefficient requirement.
[Try it on Sage Cell](http://sagecell.sagemath.org/?z=eJxLs81JzE1KSVTIs8pOLcpLzdHITSwpyqzQyNM21InOitPN1NXQzbS1zdJMyy9SyFTIzIvWzdPTM4gFcbNAXAM9vbzYWE1NPQNeLrgaoKBprFVBUWZeiUKaRqYmAMYlIAU=&lang=sage)
[Answer]
# [Pari/GP](http://pari.math.u-bordeaux.fr/), 57 bytes
```
n->(a=matkerint(matrix(n++,,i,j,i--^j--)-1))*sign(a[n,1])
```
[Try it online!](https://tio.run/##HYsxCoAwDAC/EpwSTcA@oH5EFDrYEsVYqoO/r8Xhjlsuh6KSco3gq8mEwZ/hObai9mCroi/aMDAr76wi6y5C4oj6W5NhmI3dQjVeBQ08jAyukf/doAOZmiIaEdUP "Pari/GP – Try It Online")
Returns the coefficients as a column vector.
[Answer]
# [Julia](http://julialang.org/), 172 bytes
Similar to the Mathematica code in OEIS.
---
[Try it online!](https://tio.run/##LU5BCsIwELznFUtPCbbYXKM5eBQ851IrxJqUrekqqYH@vibisLCzO8MwUwpo5bptaUEa4YLkbDyF0d2jZT7R8MEXgeckGGnaSWY0pRCWtx0c79C7sDj@BK1B1mX4BA1Iccu/sgX4V4QJkEAqquH5Z31Wz6JTtewZem46R4/@2AowujGHfDBu9rNdcU4zN0IUXTVSZXtmWwmlEtUq2TLIeEekDy89a6iuVImf7ws)
```
using LinearAlgebra
function f(n)
n=n+1
V=nullspace([ifelse(k == 1, 1, (j - 1)^(k - 1)) for j in 1:n, k in 1:n] - I)[:,1]
if(V[end]<0) V=-V;end
(V/maximum(V))[end:-1:1]
end
```
---
]
|
[Question]
[
Being short of cash, you have signed up to build donuts for The Doughnut Shop™, the biggest digital doughnut company in the world, mostly because they sell every size of doughnut imaginable.
Now, given that trading standards nowadays is very tough, you need to write a piece of code as short as possible to create these doughnuts so that the source code that created them can be put on the outside of the packet.
# Challenge
Given 4 inputs, radius of the outer ring, radius of the inner ring, the possible sprinkles and the chance of a cell having a sprinkle, output a doughnut covered in those sprinkles which has the correct inner and outer radii.
* The input may be taken how you wish (arguments to a function, stdin, program arguments) and in any order.
+ The sprinkles will be given in the form of 1 character per sprinkle type
+ `^+*-` as sprinkle input would be a list of 4 sprinkles, `^`, `+`, `*`, `-`
+ The chance of a sprinkle will be entered as a floating point value between 0 and 1. eg: `0.1`, `0.23`
* You must print out the output to stdout or equivalent.
* Sprinkles can't be on the edges of the doughnut.
* Each type of sprinkle must have an equally likely chance of being on each cell.
* The radii are given in 1-cell units.
* If the inner radius equals either 0 OR the outer radius, the doughnut is said to have no ring.
* Both radii will be non-negative integers.
* The inner and outer edges of the doughnut must be represented using hashes (`#`)
* A test to see if a point is in a circle, given a radius and the center of the circle is:
`(x-center)**2+(y-center)**2 < radius**2`
### Example input with output
(outer radius, inner radius, sprinkles, chance of sprinkle)
* 10, 4, "^+\*-", 0.1
```
#########
# #
## ++ * *##
# #
# ^^ - * #
# ##### ^ #
#+ # # #
# # #- #
# # # * #
# # #+ #
# # # #
#^ +# # #
# # # #
# * ##### #
# + - #
# ^ #
## ^ + ##
# ^ #
#########
```
* 5, 2, ":^+\*", 0.9
```
#####
#^^+ ^#
#**### #
#:# #^#
#^# #*#
#:# #*#
#:+###* #
# *:^:#
#####
```
**This is code golf, the shortest answer in bytes wins**
[Answer]
# Python, 263 bytes
So I saw a challenge with no answers that looked relatively easy but also interesting and thought to myself:
*Hmm... If I'm the only one with an answer, I'll be winning until a better answer inevitably shows up.*
So I sat down with Python for a few minutes and came up with a rough draft which, with the help of the community's suggestions, I have been tweaking to reduce its size.
```
from random import*
def D(O,I,S,P):
a=range(-O,O+1);C=lambda x,y,z,n:(n-.5)**2<x*x+y*y<(z+.5)**2
if I>=O:I=0
for y in a:
R=''
for x in a:
if C(x,y,O,O)+(C(x,y,I,I)&(I!=0)):R+='#'
elif C(x,y,O,I)&(uniform(0,1)<P):R+=choice(s)
else:R+=' '
print(R)
```
For the examples above, this creates
```
>>> D(10, 4, "^+*-", 0.1)
#######
## ##
# * #
# #
# + ^ #
# + #
# + +##### - #
# ## ## ^ #
# ## ## * #
#- # # #
# # # + #
# + # # #
# ## ## #
# ## ## * #
#+- ##### #
# - - #
# - - +#
# ^ #
# - + #
## * ##
#######
>>>
```
and
```
>>> D(5, 2, ":^+*", 0.9)
#####
#*^:* #
#^::*:^*#
#* :###+*:#
#:*# #+:#
#::# #+ #
#+:# #*:#
#^^:###::^#
# + :*^ #
# *:+*#
#####
>>>
```
I highly doubt that this is the shortest possible solution, but I think it worked out pretty well for a self-taught teenager's attempt to kill time. Since this was designed to be as small as possible, I have not included comments and have taken shortcuts on every variable name and as such, this program is more for usability than readability.
Should you want to use this code for some reason unbeknownst to me, just run it in IDLE and type the command
```
D(Outer Radius, Inner Radius, Sprinkles, Chance of Sprinkle)
```
in the format described above.
[Answer]
## MATLAB, 231 bytes
Here a matlab solution:
```
function g=z(r,q,s,p);[x,y]=meshgrid(1:2*r,1:2*r);d=(x-r).^2+(y-r).^2;h=size(d);e=zeros(h);e(d<r^2 & d>=q^2)=1;f=bwperim(e,4);k=rand(h);j=numel(s);l=changem(randi(j,h),s,1:j);g=char(e);g(:,:)=' ';g(k<=p)=l(k<=p);g(f)='#';g(~e)=' ';
```
Some examples:
```
>> z(10, 4, '^+*-', 0.1)
ans =
#########
# #
## ##
# - -#
# #
# - ##### ^ #
# # # #
# -# # #
# * # #+ #
#** # # #
# * # # - #
#+ *# # #
# # # #
# ##### #
# ^ #
# * #
##+ ##
# #
#########
>> z(5, 2, ':^+*', 0.9)
ans =
#####
#++::*#
#^^###++#
# # #+#
#^# #^#
#*# #*#
#+:###^*#
#*:^+^#
#####
>> z(20,6, 'erthhjjjjkjkk', 0.4)
ans =
#############
##jh k k k ##
## jjj j khh ##
#r kj h k tjhj j #
##jk t k jh j h##
#k rre k j #
# j j j j khtkt jr kj #
# k rk je j h j #
# j k k jth e k j j j #
#h h h e t e ej j r k r e #
# j r jh jk j kk j #
# k k h k jk k j #
# jjk hh k hj r j je rjj k j #
# ek j j jj h####### hke #
#hj k j j # #ke jhkt jee #
# jk k# # k j t #
#k j # #khk r j#
# tj j te # # j r j j #
#e je jhk# # t j #
#jj j h # # k jj e #
# j j hj j # # jkt kjjjr e#
#j k e # # r k#
#jj k ek # # hj j rtj #
# k j hk h# # j h j #
# h trt jrht# # et k#
#j ehjj j #######ett kh kjj k #
# r jj ekk jk th k kkk h #
#hj khe kj hr jj kk r j #
#r t k j k r j jk k hh jj#
# kjj h k j j rrr j r j #
#j kej jj t h j hh #
# he e tje j tjhkjk kj #
#j kt rjk j j ee rkj #
# jjr e j jkt j e j j#
##k thhjj je kj kh ##
# hje j jj kk t j#
## k h e ##
## e jje kkhj##
#############
```
]
|
[Question]
[
I heard somewhere that one thing that technology cannot do yet is fold towels1. So it is now your job to prove that statement false!
Given a string as input, made up of rectangles (towels), like the following, fold each towel in half twice. For example:
```
+------+ +------+ +--+
| | | | | |
| | | | | |
| | -> +------+ -> +--+
| |
| |
| |
+------+
```
Notice that when a towel is folded, it is first folded up, then from left to right. You program must mimic this behavior as well. Also notice that in the test cases, the towels stays in the same place, but folded.
**Rules:**
* Standard methods of input/output.
* Standard loopholes apply.
* Input and output should be as a string.
* Trailing whatevers are okay in output, as long as the towels are in the right place relative to each other.
* You may assume that the length of each side of the towel will always be divisible by 2.
* The towels passed as input will always be rectangular.
* The towels will always be separated-- however, they may be separated by variable amounts.
* [code-golf](/questions/tagged/code-golf "show questions tagged 'code-golf'"), so shortest code wins!
**Test cases:**
```
Input:
+------+
| |
| |
| |
| |
| |
| |
+------+
Output:
+--+
| |
| |
+--+
Input:
+--+ +--+ +--+
| | | | | |
| | | | | |
+--+ +--+ +--+
Output:
++ ++ ++
++ ++ ++
Input:
+----+
| |
| |
| |
| | ++
+----+ ++
Output:
+-+
| |
+-+
+
Input:
+--+
+--+ ++
||
||
++
Output:
++
+
+
```
1: This has been disproved by Geobits and Laikoni. However, I did hear it somewhere.
[Answer]
# [Retina](https://github.com/m-ender/retina), 245 bytes
```
m1+`^((.)*(?!\+ )[+|]([- ])*[+|].*¶(?<-2>.)*)([+|][- ]*[+|])
$1$.4$*
m+`^((.)*) ( *) (.*¶(?<-2>.)*)(?(2)(?!))\|\3\|
$1|$3|$4 $3
m+`^((.)*)\|( *)\|(?=.*¶(?<-2>.)*(?(2)(?!)) )
$1+$.3$*-+
([+|])\1
$1
(?!\+ )([+|])([- ])\2(\2*)\3\1
$.3$* $1$3$1
```
[Try it online!](https://tio.run/nexus/retina#lU/LDYMwDL1nCiP5YMcCKYRjWwYhVF2ADTxXB@hiNA6ftohLfXh5sd97iecpyONO1LCnvkoCPIiONNQwsjfa@NeT@kvd3rKEyVo2LDN2GLDp0IObthQGAoODr6c2Q8WcNMWk2agYFTvA@G1Oau6M/fUn4OMHe1SwiehrceU/nIIDDG5dYOktK6SWUpsDY5YUD0BWYsQwz1KXEqdQSv8ju92YwA6mUNjheD2Il5j1D3p6gMiqMlYClhSr3IGtVM@5yBs "Retina – TIO Nexus")
Note: some lines end in spaces. Explanation:
```
m1+` Repeatedly search from the beginning of input
^((.)* Optional indentation
(?!\+ ) Towel does not start with a plus and a space
[+|]([- ])*[+|] A row of towel
.*¶ Rest of the line
(?<-2>.)* Some indentation on the next line
)
([+|][- ]*[+|]) Another row of towel
$1$.4$* Replace the second row with blanks
```
Delete every other line of every towel (this works because all towels have even height),
```
m+` Repeatedly search
^((.)*) Optional indentation
( *) Find some space
(.*¶ Rest of the line
(?<-2>.)*) Matching indentation on the next line
(?(2)(?!)) Ensure that the indentation exactly matches
\|\3\| Piece of towel
$1|$3|$4 $3 Swap the piece into the space above
```
shift all the detached towel pieces up,
```
m+` Repeatedly search
^((.)*) Optional indentation
\|( *)\| Piece of towel
(?= Followed by
.*¶ Rest of the line
(?<-2>.)* Matching indentation on the next line
(?(2)(?!)) Ensure that the indentation exactly matches
) Nothing on the next line
$1+$.3$*-+ Change the piece into a towel bottom
```
and fix the bottom of the towels, effectively folding them up.
```
([+|])\1 Match a row of towel of width 2, which is just ++ or ||
$1 Change the first column to a space, which folds it
```
Fold the towels of width 2 to the right.
```
(?!\+ ) Towel does not start with a plus and a space
([+|]) Start with a + or a |
([- ])\2 Then at least two -s or spaces
(\2*)\3 Then an even number of -s or spaces
\1 Then another + or |
$.3$* Replace the left half with spaces
$1$3$1 Replace the first character of the right half
```
Fold the remaining towels to the right.
[Answer]
# [Octave](https://www.gnu.org/software/octave/) with [Image Package](https://octave.sourceforge.io/image/overview.html), ~~277~~ 272 bytes
```
function x=f(x)
[i,j,v]=find(bwlabel(x-32));a=@(w)accumarray(v,w,[],@max);r=-a(-i);R=a(i);s=-a(-j);S=a(j);x(:)=32;for k =1:nnz(r)
u=(r(k)+R(k)-1)/2;v=(s(k)+S(k)+1)/2;p=v:S(k);x(r(k),p)=45;x(u,p)=45;q=r(k):u;x(q,v)=124;x(q,S(k))=124;x(u,[v S(k)])=43;x(r(k),[v S(k)])=43;end
```
Input and output are 2D char arrays.
[Try it online!](https://tio.run/nexus/octave#nVHLbsIwELz7K3ypsiscVQn0EmslvgGOUVQZSCTzcIITBxfx79QORVUPXLrSPmY0O4fde@PMdtCt4Z4a8MhKLfZirKjRZgeby1Ft6iP4dJ4jSkVLuKDabt1JWau@YBQXUVZieVIepaVUQapRrkhBaP2E9yjXAYfmoUCa57JpLT9wygpjrmCROQILB5ytQkkzfM/lSNBHZh3LxHQ0FhEFk6gVHdLiIwD3M50p0oUL1FmMSFm@mMa480ROlCOPRBVW5k@nP1xtdveQz5sw5jnxkiWzdIpZwpIbn@L2//HXrJJsp/sunJ2/jDeuTeeGh9DW3UkNkHwmIhO9vtbgRXgMPoR93SmrhtY@xPGd@NK1dUOwvX8D) Or verify all test cases: [1](https://tio.run/nexus/octave#nVHLbsIwELz7K3ypsiscVQn0EmslvgGOUVQZSCTzcIITBxfx79QORVUPXLrSPmY0O4fde@PMdtCt4Z4a8MhKLfZirKjRZgeby1Ft6iP4dJ4jSkVLuKDabt1JWau@YBQXUVZieVIepaVUQapRrkhBaP2E9yjXAYfmoUCa57JpLT9wygpjrmCROQILB5ytQkkzfM/lSNBHZh3LxHQ0FhEFk6gVHdLiIwD3M50p0oUL1FmMSFm@mMa480ROlCOPRBVW5k@nP1xtdveQz5sw5jnxkiWzdIpZwpIbn@L2//HXrJJsp/sunJ2/jDeuTeeGh9DW3UkNkHwmIhO9vtbgRXgMPoR93SmrhtY@xPGd@NK1dUOwvX8D), [2](https://tio.run/nexus/octave#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3YFPEfShJPbI7H4z0FZyWig@o7v2T2Nj6Y0p0dJqOpu4scIP6KecZ7da/BcX8GnIx93Ukjh9ZM5nA8fDu1tYMf@/wB). (Note that `endfunction` in the test cases is only needed to separate the function from the subsequent code. It is not necessary if the function is saved in its own file.)
### Readable version and explanation
```
function x = f(x)
[i,j,v] = find(bwlabel(x-32)); % make background equal to 0 by subtracting 32.
% Then label each connected component (i.e. towel) with a unique integer
% Then get row indices (i) and column indices (j) of nonzero values (v)
a = @(w)accumarray(v,w,[],@max); % helper function. Gives the maximum of w for
% each group given by an integer label in v
r = -a(-i); % upper coordinate of each towel (minimum row index)
R = a(i); % lower coordinate of each towel (maximum row index)
s = -a(-j); % left coordinate of each towel (minimum column index)
S = a(j); % right coordinate of each towel (maximum column index)
x(:) = 32; % remove all towels: fill x with spaces
for k = 1:nnz(r) % for each original towel: create the new, folded towel
u = (r(k)+R(k)-1)/2; % new lower coordinate
v = s(k)+S(k)+1)/2; % new left coordinate
p = v:S(k); % column indices of horizontal edges
x(r(k),p) = 45; % fill upper horizontal edge with '-'
x(u,p) = 45; % fill lower horizontal edge with '-'
q = r(k):u; % row indices of vertical edges
x(q,v) = 124; % fill left vertical edge with '|'
x(q,S(k)) = 124; % fill right vertical edge with '|'
x(u,[v S(k)]) = 43; % fill lower corners with '+'
x(r(k),[v S(k)]) = 43; % fill upper corners with '+'
end
```
]
|
[Question]
[
# Intro
Consider a grid of the characters `f A\/` such as
```
f f f
A
A / \
\ / A
A \/
/
\/
```
where:
* `f` represents a faucet that pours a stream of water downward
* `A` bifurcates the stream of water above so exactly half goes left and exactly half goes right
* `\` shifts the stream of water above to the right by one unit
* `/` shifts the stream of water above to the left by one unit
* the combinations `\/` creates a trough with infinite capacity that collects the water streams above it
* `[space]` is empty space than the water can move through
From this we can imagine the path the water (`*`) would take as it comes out of the faucets and falls either into the troughs or out of the grid area:
```
f f f <-- first second and third faucets
* * *A*
* *A*/ \*
\*/ * *A <-- a '*' is not drawn to the right of this A because it would be out of the 9×7 bounds
* *A*\/ <-- upper trough
**/ *
\/ * <-- lower trough
```
Assuming the 3 faucets output the same amount of water one at a time we can see that
* All of the first faucet's water goes to the lower trough.
* One half of the second faucet's water goes to the lower trough and the other half is split between the lower trough and falling off the grid.
* One quarter of the third faucet's water goes to the lower trough, one quarter falls off the bottom of the grid, one quarter goes into the upper trough, and one quarter falls off the grid to the right.
From this we can tell that `(1 + 3/4 + 1/4 + 1/4) / 3 = 75%` of the water is caught by the troughs and `(1/4 + 1/4 + 1/4) / 3 = 25%` falls off the grid.
# Challenges
You may complete any or all of these challenges relating to this ASCII water flow setup. They are all code-golf, the shortest answer for each challenge is the winner. The accepted answer will be the person who completes the most challenges, with total code length as tie-breaker.
**Challenge 1**
Write a program that outputs the fraction of water that flows into troughs for a given grid. The output of the example above would simply be `0.75`.
**Challenge 2**
Write a program that, given a grid, draws the `*`'s in the places water flows as I've done above. You should not overwrite anything besides space characters and the grid should not change size. So for something like
```
f
/A
```
nothing needs to be done since, although water does flow on either side of the A, it can't be drawn to the left without removing the `/` and it can't be drawn to the right without making the 2×2 grid bigger.
**Challenge 3 (Updated)**
Write a program that takes in two non-negative integers, the total T and the amount to keep K (T >= K). Generate and draw a grid with exactly one `f` such that when that faucet pours out T units of water, exactly K will flow into troughs. If it is impossible to do this in a finite grid for a particular (T, K) pair then output 'Impossible'.
# Clarifications (apply to all challenges)
* Input can be via stdin, or a file, or even a function call on the string representation of the grid. Just make it obvious how to run different inputs.
* Output must go to stdout.
* `\A` and `A/` and `AA` are also troughs as you'd expect.
* A w by h grid will always be a well formatted rectangle of w\*h characters not counting newlines. There will be no missing trailing spaces and no occurrences of `*`.
* The grid dimensions can be as small as 1×1 and arbitrarily large. (Arbitrarily large within reason, int.maxValue or the like is an acceptable limit. Same goes for T and K.)
* A stream above an `f` flows right through it.
* The faucets can be anywhere, not just on the top row.
* `A` always divides the amount of water poured on it exactly in half.
*Note:* Things like `/A` and `//` are perfectly valid. The water *does* freely flow between the characters (though for challenge 2 there's not enough room to draw it).
So, in the setup
```
ff
/A
```
The left `f` stream pours down, hits the `/` and shifts left. The right `f` stream pours down, hits the `A`, half goes right and half goes left between the `A` and the `/`.
e.g.
```
ff
**
*/A*
** *
** *
```
[Answer]
## All Challenges C# 690bytes (416bytes + 274bytes)
### Challenges 1&2 C# ~~579~~ ~~446~~ 416bytes
This is a complete program which should do Challenges 1 & 2, just about. It reads lines of input from stdin until it receives an empty line. It prints out the result for Challenge 2, and then the result for Challenge 1. Uses the .NET decimal class to hopefully avoid any rounding errors.
```
using C=System.Console;class P{static void Main(){decimal u,t=0,f=0;string c,z="";for(decimal[]n=null,o;(c=C.ReadLine())!="";z+='\n'){int s=c.Length,i=s,e;o=n;n=new decimal[s];for(o=o??n;i-->0;n[i]+=(e&2)*u/2){e=c[i]%13;u=o[i]/(e<1?2:1);if(e%8<1)if(i>0)if(c[i-1]%7<3)t+=u;else n[i-1]+=u;if(e<2)if(i<s-1)if(c[i+1]%2>0)t+=u;else n[i+1]+=u;if(e>9){u++;f++;}}for(;++i<s;)z+=c[i]<33&n[i]>0?'*':c[i];}C.WriteLine(z+t/f);}}
```
Less golfed:
```
using C=System.Console;
class P
{
static void Main()
{
decimal u,t=0,f=0;
string c,z="";
for(decimal[]n=null,o;(c=C.ReadLine())!="";z+='\n')
{
int s=c.Length,i=s,e;
o=n;
n=new decimal[s];
for(o=o??n;i-->0;n[i]+=(e&2)*u/2)
{
e=c[i]%13;
u=o[i]/(e<1?2:1);
if(e%8<1)
if(i>0)
if(c[i-1]%7<3)t+=u;
else n[i-1]+=u;
if(e<2)
if(i<s-1)
if(c[i+1]%2>0)t+=u;
else n[i+1]+=u;
if(e>9)
{
u++;
f++;
}
}
for(;++i<s;)
z+=c[i]<33&n[i]>0?'*':c[i];
}
C.WriteLine(z+t/f);
}
}
```
Test run (with a lack of trailing spaces which I promise are there):
```
f f f
A
A / \
\ / A
A \/
/
\/
f f f
* * *A*
* *A*/ \*
\*/ * *A
* *A*\/
**/ *
\/ *
0.75
```
### Challenge 3 C# 274bytes
This is a complete program which should complete Challenge 3. I a managed to save 6bytes by writing my own integer parser to read the input rather than `Split`ing a `ReadLine` and using `long.Parse`;
```
using C=System.Console;class P{static void Main(){long t=-1,f=t,k;for(;f<0;)for(f=t,t=0;(k=C.Read())>47;)t=t*10+k-48;var r="Impossible\n";for(k=t;k<t*f;)k*=2;if(f<1||(k/f)*f==k)for(r=" f \n";t>0&t<f;t-=(t/f)*f)r+=((t*=2)<f?" ":"A")+"A \n/ /\n";C.Write(r+(t<f?"":"AAA\n"));}}
```
Less golfed:
```
using C=System.Console;
class P
{
static void Main()
{
long t=-1,f=t,k;
for(;f<0;)
for(f=t,t=0;(k=C.Read())>47;)
t=t*10+k-48;
var r="Impossible\n";
for(k=t;k<t*f;)
k*=2;
if(f<1||(k/f)*f==k)
for(r=" f \n";t>0&t<f;t-=(t/f)*f)
r+=((t*=2)<f?" ":"A")+"A \n/ /\n";
C.Write(r+(t<f?"":"AAA\n"));
}
}
```
Test run (again with a lack of trailing spaces which I promise are there):
```
32 17
f
AA
/ /
A
/ /
A
/ /
A
/ /
AA
/ /
```
[Answer]
First of all, I have a question regarding the challenge. Since I do not have enough reputation to comment on the question, I'm writing it here:
* What is the behavior of `/A` (water flowing on A), `//` (water flowing on the right side) and variations of this principle? Does the water flow to the first "free spot" on the side or does is flow "below" its neighbour?
---
Just a simple try, it can be waaaaay simplified (which I will do later by editing this post).
**Edit:** Second version, a little bit smaller. I went for a different approach: instead of looking for each cell to check what's comming from the top and sides, I start from the faucets and "flow" downwards with recursion.
## Javascript, 226 bytes (Challenge 1)
```
function f(c){function h(b,a,d,e){b<c.length&&0<=a&&a<c[0].length&&("\\"==c[b][a]?"/"==e||"A"==e?g+=d:h(b,a+1,d,"\\"):"/"==c[b][a]?"\\"==e||"A"==e?g+=d:h(b,a-1,d,"/"):"A"==c[b][a]?"A"==e||"\\"==e||"/"==e?g+=d:(h(b,a-1,d/2,"A"),h(b,a+1,d/2,"A")):h(b+1,a,d,c[b][a]))}for(var g=0,m=0,k=0;k<c.length;k++)for(var l=0;l<c[k].length;l++)"f"==c[k][l]&&(h(k+1,l,1),m++);alert(g/m)};
```
## Javascript, 204 bytes (Challenge 2)
```
function f(c){function e(b,a,d){b<c.length&&0<=a&&a<c[0].length&&("\\"==c[b][a]?"/"!=d&&"A"!=d&&e(b,a+1,"\\"):"/"==c[b][a]?"\\"!=d&&"A"!=d&&e(b,a-1,"/"):"A"==c[b][a]?"A"!=d&&"\\"!=d&&"/"!=d&&(e(b,a-1,"A"),e(b,a+1,"A")):(" "==c[b][a]&&(c[b][a]="*"),e(b+1,a,c[b][a])))}for(var g=0;g<c.length;g++)for(var h=0;h<c[g].length;h++)"f"==c[g][h]&&e(g+1,h)};
```
## Javascript, 238 bytes (Challenge 1 + 2)
```
function f(c){function h(b,a,d,e){b<c.length&&0<=a&&a<c[0].length&&("\\"==c[b][a]?"/"==e||"A"==e?g+=d:h(b,a+1,d,"\\"):"/"==c[b][a]?"\\"==e||"A"==e?g+=d:h(b,a-1,d,"/"):"A"==c[b][a]?"A"==e||"\\"==e||"/"==e?g+=d:(h(b,a-1,d/2,"A"),h(b,a+1,d/2,"A")):(" "==c[b][a]&&(c[b][a]="*"),h(b+1,a,d,c[b][a])))}for(var g=0,m=0,k=0;k<c.length;k++)for(var l=0;l<c[k].length;l++)"f"==c[k][l]&&(h(k+1,l,1),m++);alert(g/m)};
```
---
**How to use**
Provide a two dimensionnal representation ofthe map. Here is the example provided in the question:
```
var input = [["f"," "," ","f"," "," ","f"," "," "],[" "," "," "," "," "," ","A"," "," "],[" "," "," ","A"," ","/"," ","\\"," "],["\\"," ","/"," "," "," "," "," ","A"],[" "," "," "," ","A"," ","\\","/"," "],[" "," "," ","/"," "," "," "," "," "],[" ","\\","/"," "," "," "," "," "," "]];
f(input);
```
**Output**
Challenge 1: It will simply create a dialog box (alert) with the result (0.75 for the example above).
Challenge 2: It will directly modify the map. *Should I print it? If so, is console.log is accepted? as a valid output?*
Challenge 1+2: Both of above combined, *obviously*...
[Answer]
# Python 3, 186 bytes (Challenge 3)
I took the idea for the grid from [VisualMelon's answer](https://codegolf.stackexchange.com/a/34870/29688). The function should print a valid grid to stdout for arbitrarily large T and K, provided it is possible (finite size grid) of course.
```
from fractions import*
def c(T,K):
p=print;g=gcd(T,K);K//=g;T//=g
if T&(T-1):p('Impossible')
else:
p(' f ')
while T-1:
T//=2;p('A/'[K<T]+'A \n///')
if K>=T:K-=T
p('AAA'*K)
```
---
## How to use
Call the `c` function with the total amount and amount to keep as arguments.
```
>>> c(24, 9)
f
/A
///
AA
///
AA
///
>>> c(6, 2)
Impossible
```
]
|
[Question]
[
I could only find code-golf challenges for Mastermind, so here's a code-challenge version that I would have liked to take on myself.
An optimal strategy for the normal Mastermind game, MM(4,6), was found by Koyama and Lai in 1993, having an average # of guesses = 5625/1296 ~ 4.34. MM(5,8) is still unsolved, but is estimated to have an average # of guesses ~ 5.5.
Your task is to create an MM(5,8) strategy, that is for 5 holes and 8 colors, covering all `pow(8,5) = 32768` possible distinct solutions. Obviously, it doesn't have to be an optimal one. You have two choices:
1. Post a deterministic program that generates the strategy. The program must be compileable/runnable on Windows 7, Mac OS X or Linux without any extra non-free software.
2. Publish your strategy (along with your StackExchange name) somewhere on the Internet and post the URL here.
In both cases, state the score (see below) in the answer's header.
The strategy must be encoded according to the following grammar:
```
strategy : guessing-strategy | known-solution-strategy
guessing-strategy : '{' guess ':' branches '}'
known-solution-strategy : guess
guess : color color color color color
color : 'A'..'H'
branches : '{' branch (',' branch)* '}'
branch : reply ':' strategy
reply : number-of-blacks number-of-whites
number-of-blacks : number-of-key-pegs
number-of-whites : number-of-key-pegs
number-of-key-pegs : '0'..'5'
```
The algorithm used to decide the number of black/white key pegs is described in [http://en.wikipedia.org/wiki/Mastermind\_(board\_game)](http://en.wikipedia.org/wiki/Mastermind_%28board_game%29)
Note that the reply "50" (i.e. correct guess) is implied and not part of the grammar.
Scoring: N = the sum of the number of guesses for each of the 32768 paths/solutions. The strategy with the lowest N wins. First tie-break: The lowest maximum number of guesses. Second tie-break: The first posted answer. The competition ends **August 1, 2014 0:00 GMT**.
---
An example of a strategy for MM(2,3) with score = 21:
```
{AB:{10:{AC:{10:AA,01:CB,00:BB}},02:BA,01:{BC:{01:CA}},00:CC}}
```
Using this strategy, the 9 possible games will go like this:
* AB 20
* AB 10, AC 20
* AB 10, AC 10, AA 20
* AB 10, AC 01, CB 20
* AB 10, AC 00, BB 20
* AB 02, BA 20
* AB 01, BC 20
* AB 01, BC 01, CA 20
* AB 00, CC 20
I will soon post a Java-based MM(5,8) strategy verifier for your convenience.
[Answer]
## Java
My algorithm for MM(5,8) scores with ~~177902~~ ~~178006~~ ~~182798~~ **182697** with a maximum depth of ~~8~~ **9** and needs only a few seconds (on my slow computer).
An example output of a strategy for MM(2,3) with score = 21 found by this algorithm looks like this:
```
{BC:{00:AA,01:AB:{01:CA},02:CB,10:AC:{00:BB,01:BA,10:CC}}}
```
---
There is nothing exciting with my algorithm. No invention. I just followed recipes found in the net and compressed them into this Java code.
The only optimization I did is trying to optimize the lines of code (in a way). It goes like this:
1. Create the initial set S0 of all possible codes to be the current set S.
2. Codebreaker finds a (greedy) good guess for S. Each guess leads to a partition P of S, where each subset S' collects all codes (from S) having the same reply on the guess. A good guess has a good partition, as the one giving most information for the guess.
3. Take the good guess and its P. For each nonempty S' in P apply codebreaker recursive (step 2).
@MrBackend: Writing a verifier is hard, I guess. ;-)
```
import java.util.TreeMap;
import java.util.Vector;
public class MM {
Vector<String> codeset = new Vector<String>();
String guess;
TreeMap<Integer, MM> strategy = new TreeMap<Integer, MM>();
public String toString() {
String list="";
for (Integer reply: strategy.keySet()) {
if (strategy.get(reply)!=null) list+=(list.length()>0?",":"")+(reply<10?"0":"")+reply+":"+strategy.get(reply);
}
if (list.length()>0) return guess+":{"+list+"}"; else return guess;
}
MM() { }
MM(int h, int c) {
for (int i = 0; i < Math.pow(c, h); i++) {
String code = "";
for (int j = 0, p=i; j < h; j++) {
code+="ABCDEFGH".charAt(p%c);
p/=c;
}
codeset.add(code);
}
}
int replyAccordingToDonaldKnuth(String secret, String guess) {
int black=0;
int totalHitsBlackAndWhite=0;
for (char n = 'A'; n <= 'H'; n++) {
int a=0, b=0;
for (int i = 0; i < secret.length(); i++) {
if (secret.charAt(i)==n) a++;
if ( guess.charAt(i)==n) b++;
}
totalHitsBlackAndWhite+=Math.min(a, b);
}
for (int i = 0; i < secret.length(); i++) {
if (secret.charAt(i) == guess.charAt(i)) black++;
}
return 10 * black + (totalHitsBlackAndWhite-black);
}
int reply(String secret, String guess) {
return replyAccordingToDonaldKnuth(secret, guess);
}
MM codebreaker(Vector<String> permuts) {
int fitness=0;
MM protostrategy=null;
for (int greedy = 0; greedy < Math.min(permuts.size(), 200); greedy++) {
MM tmp=partition(permuts, permuts.get(greedy));
int value=tmp.strategy.size();
if (fitness<=value) {
fitness=value;
protostrategy=tmp;
protostrategy.guess=permuts.get(greedy);
}
}
if (protostrategy!=null) {
for (Integer reply: protostrategy.strategy.keySet()) {
protostrategy.strategy.put(reply, codebreaker(protostrategy.strategy.get(reply).codeset));
}
}
return protostrategy;
}
MM partition(Vector<String> permuts, String code) {
MM protostrategy=new MM();
for (int c = 0; c < permuts.size(); c++) {
int reply=reply(permuts.get(c), code);
if (!protostrategy.strategy.containsKey(reply)) protostrategy.strategy.put(reply, new MM());
if (permuts.get(c)!=code) protostrategy.strategy.get(reply).codeset.add(permuts.get(c));
}
return protostrategy;
}
public static void main(String[] args) {
MM mm = new MM(5,8);
System.out.println("{"+mm.codebreaker(mm.codeset)+"}");
}
}
```
**Some remarks:**
1. No consistency check is needed because sets S and their partitions are build in a (auto-)consistent way.
2. Picking a good guess out of S0 (instead of S) makes sense. But I don't follow this approach in the current code.
3. My greedy search is artificially pruned to 200 tries.
4. I know, "giving most information for the guess" is not very precise. The simple idea is to pick the partition with the most number of subsets.
5. The result heavily depends on how you calculate the reply(..). Finally I adapted Donald Knuth's expression.
The strategy for `MM(5,8)` [can be found here](https://gist.github.com/BobGenom/7cef941fa64f977f2aa2). GitHub has some issues displaying lines that long, so click on the **Raw** button.
[Answer]
## Ruby
**EDIT:** Added some logic to exclude impossible guesses. Hence, the strategies now comply with the given format and are much more manageable.
So here is one attempt to get this going. It's pretty naive (and not very legible - it helps to read the if/elsif/else branch from bottom to top).
```
Holes, Colors = ARGV.map &:to_i
ColorChars = ('A'..'H').to_a
def is_possible(guess, blacks, result)
blacks == guess.chars.zip(result.chars).count {|chars| chars[0] == chars[1]}
end
def print_strategy(known_colors, remaining_permutations, next_color)
char = ColorChars[next_color]
if remaining_permutations
guess = remaining_permutations[0]
print guess
if remaining_permutations.length > 1
print ':{'
(Holes-1).times do |i|
new_permutations = (remaining_permutations - [guess]).select { |perm| is_possible(guess, i, perm) }
next if new_permutations.empty?
print "#{i}#{Holes-i}:"
print '{' if new_permutations.length > 1
print_strategy(known_colors, new_permutations, next_color)
print '}' if new_permutations.length > 1
print ',' if i < Holes-2
end
print '}'
end
elsif known_colors.length == Holes
print_strategy(known_colors, known_colors.chars.permutation.map(&:join).uniq, next_color)
elsif next_color == Colors-1
print_strategy(known_colors+char*(Holes - known_colors.length), remaining_permutations, next_color+1)
else
print char*Holes, ':{'
(Holes - known_colors.length + 1).times do |i|
break if i == Holes
print "#{i}0:"
print '{' if next_color < Colors-2 || i > 0 || known_colors.length > 0
print_strategy(
known_colors+char*i,
remaining_permutations,
next_color+1
)
print '}' if next_color < Colors-2 || i > 0 || known_colors.length > 0
print ',' if i < (Holes - known_colors.length) && i < Holes-1
end
print '}'
end
end
print '{'
print_strategy('', nil, 0)
puts '}'
```
First, I try 5 of each colour: `AAAAA`, `BBBBB`, etc. From that I figure out which colours are actually used in the pattern. And then I simply try all permutations of the given colours, omitting those which have been ruled out by the black pegs already.
Here is the `MM(2,3)` strategy:
```
{AA:{00:{BB:{00:CC,10:{BC:{02:CB}}}},10:{BB:{00:{AC:{02:CA}},10:{AB:{02:BA}}}}}}
```
The strategy for `MM(5,8)` takes 376KB and [can be found here](https://gist.github.com/mbuettner/fa20b54ecc3e654e7d8c). GitHub has some issues displaying lines that long, so click on the **Raw** button.
Now if I get a verifier, I can also tell you what my actual score is. :)
]
|
[Question]
[
The goal is to create a preprocessor for the C language, as small as possible in terms of source code size *in bytes*, in your preferred language.
Its input will be a C source file, and its output will be the pre-processed source code.
The items that it will need to be able to process shall be:
Comment removal (line/block), #include directives (by opening files *at relative paths* and replacing text at the point needed), #define, #undef, #if, #elif, #else, #endif, #ifdef, #ifndef, and defined(). Other C preprocessor directives like #pragmas or #errors may be ignored.
There is no need to calculate arithmetic expressions or comparison operators in #if directives, we assume the expression will evaluate to true as long as it contains an integer other than zero (its main use will be for the defined() directive). Examples of possible input and output follow (possible extra whitespaces in output files were trimmed for better appearance, there is no need for your code to do so). A program able to process the following examples properly will be considered sufficient.
```
----Input file: foo.c (main file being preprocessed)
#include "bar.h" // Line may or may not exist
#ifdef NEEDS_BAZZER
#include "baz.h"
#endif // NEEDS_BAZZER
#ifdef _BAZ_H_
int main(int argc, char ** argv)
{
/* Main function.
In case that bar.h defined NEEDS_BAZ as true,
we call baz.h's macro BAZZER with the length of the
program's argument list. */
return BAZZER(argc);
}
#elif defined(_BAR_H_)
// In case that bar.h was included but didn't define NEEDS_BAZ.
#undef _BAR_H_
#define NEEDS_BARRER
#include "bar.h"
int main(int argc, char ** argv)
{
return BARRER(argc);
}
#else
// In case that bar.h wasn't included at all.
int main()
{return 0;}
#endif // _BAZ_H_
----Input file bar.h (Included header)
#ifndef _BAR_H_
#define _BAR_H_
#ifdef NEEDS_BARRER
int bar(int * i)
{
*i += 4 + *i;
return *i;
}
#define BARRER(i) (bar(&i), i*=2, bar(&i))
#else
#define NEEDS_BAZZER // Line may or may not exist
#endif // NEEDS_BARRER
#endif // _BAR_H_
----Input file baz.h (Included header)
#ifndef _BAZ_H_
#define _BAZ_H_
int baz(int * i)
{
*i = 4 * (*i + 2);
return *i;
}
#define BAZZER(i) (baz(&i), i+=2, baz(&i))
#endif // _BAZ_H_
----Output file foopp.c (no edits)
int baz(int * i)
{
*i = 4 * (*i + 2);
return *i;
}
int main(int argc, char ** argv)
{
return (baz(&argc), argc+=2, baz(&argc));
}
----Output file foopp2.c (with foo.c's first line removed)
int main()
{return 0;}
----Output file foopp3.c (with bar.h's line "#define NEEDS_BAZZER" removed)
int bar(int * i)
{
*i += 4 + *i;
return *i;
}
int main(int argc, char ** argv)
{
return (bar(&argc), argc*=2, bar(&argc));
}
```
[Answer]
## Flex, 1170+4=1174
1170 characters in the flex code + 4 characters for a compilation flag. To produce an executable, run `flex pre.l ; gcc lex.yy.c -lfl`. The entry leaks memory like a sieve and doesn't close included files. But otherwise, it should be completely functional as per the spec.
```
%{
#define M malloc
#define X yytext
#define A a=X
#define B(x) BEGIN x;
#define Y YY_CURRENT_BUFFER
*a,*b,**v,**V,**t,**T,i,s=1,o;
g(){t=M(++s);T=M(s);for(i=1;i<s-1;i++)t[i]=v[i],T[i]=V[i];free(v);free(V);v=t;V=T;}
f(){for(i=1;i<s;i++)if(!strcmp(v[i],a))return i;return 0;}
d(y){X[yyleng-y]=0;}
%}
%x D F I
N .*\n
%%
"//".*
"/*"([^\*]|\*[^\/])*"*/"
\"(\\.|[^\\"])*\" ECHO;
^"#include "\"[^\"]*\" d(1),yypush_buffer_state(yy_create_buffer(fopen(X+10,"r"),YY_BUF_SIZE));
^"#define "[^ ]* {B(D)strcpy(a=M(yyleng),X+8);}
<D>" "?{N} {b=M(yyleng);d(1);f(strcpy(b,X+(X[0]==32)))?free(V[i]),V[i]=b:g(),v[s-1]=a,V[s-1]=b;B(0)}
^"#undef "{N} d(1),v[f(A+7)][0]=0;
^"#if defined(".*")\n" h(2,12);
^"#ifdef "{N} h(1,7);
^"#if "{N} {d(1);if(!atoi(X+4))B(F)}
^"#ifndef "{N} {d(1);if(f(A+8))B(F)}
<F>^"#if"{N} o++;
<F>^"#endif"{N} if(!o--)B(++o)
<F>^"#else"{N} if(!o)B(0)
<F>^"#elif defined(".*")\n" if(!o){d(2);if(f(A+14))B(0)}
<F>^"#elif "{N} if(!o){d(1);if(atoi(X+6))B(0)}
<F>{N}
^"#endif"{N}
^"#el"("se"|"if"){N} B(I)
<I>^"#endif"{N} B(0)
<I>{N}
[a-zA-Z_][a-zA-Z_0-9]* printf(f(A)?V[i]:a);
<<EOF>> {a=Y;yypop_buffer_state();if(!Y)exit(0);fclose(a);}
%%
h(x,y){d(x);if(!f(A+y))B(F)}
```
Some explanation:
* `a` and `b` are temps to hold strings from the input. `a` is also used as the parameter to function `f`.
* `v` holds the names of macros and `V` holds the 'V'alues of macros
* `t` and `T` are 't'emporary holders for when we grow `v` and `V`
* `i` is an 'i'ncrementer for loops
* `s` is the 's'ize of the macro array
* `o` is the count of the 'o'pen `if`s inside a false conditional
* `g()` 'g'rows the macro arrays
* `f()` 'f'inds a macro with the same value in `v` as `a`
* `d(y)` 'd'rops the last `y` characters from the current input
* state `D` is for inside a 'D'efine
* state `F` is for ignoring a 'F'alse conditional
* state `I` is for 'I'gnoring `else`/`elif` after a true conditional was found.
EDIT1: cleaned up many of the memory leaks and implemented file closing
EDIT2: modified code to handle nested macros more correctly
EDIT3: crazy amount of golfing
EDIT4: more golfing
EDIT5: more golfing; I've also noticed that my call to fclose() causes issues on some computers...looking into this.
]
|
[Question]
[
For mostly historical reasons, bash is quite a hodge-podge of syntax and programming paradigms - this can make it awkward and sometimes frustrating to golf in. However it does have a few tricks up its sleeve that can often make it competitive with other mainstream script languages. One of these is [brace expansion](https://www.gnu.org/software/bash/manual/html_node/Brace-Expansion.html).
There are two basic types of brace expansion:
* List braces may contain comma-separated lists of arbitrary strings (including duplicates and the empty string). For example `{a,b,c,,pp,cg,pp,}` will expand to `a b c pp cg pp` (note the spaces around the empty strings).
* Sequence braces may contain sequence endpoints separated by `..`. Optionally another `..` may follow, followed by a step size. Sequence endpoints may be either integers or characters. The sequence will automatically ascend or descend according to which endpoint is greater. For example:
+ `{0..15}` will expand to `0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15`
+ `{-10..-5}` will expand to `-10 -9 -8 -7 -6 -5`
+ `{3..-6..2}` will expand to `3 1 -1 -3 -5`
+ `{a..f}` will expand to `a b c d e f`
+ `{Z..P..3}` will expand to `Z W T Q`
Beyond this, sequence and list braces may exist with list braces:
* `{a,b,{f..k},p}` will expand to `a b f g h i j k p`
* `{a,{b,c}}` will expand to `a b c`
Braces expand with non-whitespace strings either side of them. For example:
* `c{a,o,ha,}t` will expand to `cat cot chat ct`
This also works for multiple braces concatenated together:
* `{ab,fg}{1..3}` will expand to `ab1 ab2 ab3 fg1 fg2 fg3`
This can get quite complex. For example:
* `{A..C}{x,{ab,fg}{1..3},y,}` will expand to `Ax Aab1 Aab2 Aab3 Afg1 Afg2 Afg3 Ay A Bx Bab1 Bab2 Bab3 Bfg1 Bfg2 Bfg3 By B Cx Cab1 Cab2 Cab3 Cfg1 Cfg2 Cfg3 Cy C`
However, if there is whitespace between expansions, then they simply expand as separate expansions. For example:
* `{a..c} {1..5}` will expand to `a b c 1 2 3 4 5`
Note how order is always preserved.
---
Entries for this challenge will expand bash brace expansions as described above. In particular:
* eval by `bash` (or other shells that perform similar expansion) is not allowed
* sequence braces will always be number-to-number, lowercase-to-lowercase or uppercase-to-uppercase with no mixing. Numbers will be integers in the 32-bit signed range. If given, the optional step size will always be a positive integer. *(Note that bash will also expand `{A..z}` as well, but this may be ignored for this challenge)*
* individual items in list braces will always be composed only of upper- and lower-case alphanumeric characters (empty string included)
* list braces may contain arbitrary nestings of other brace expansions
* braces may be concatenated arbitrary numbers of times. This will be limited by your language's memory, so the expectation is that you can theoretically do arbitrary numbers of concatenations but if/when you run out of memory that won't count against you.
The examples in the text above serve as testcases. Summarised, with each line of input corresponding to the same line of output, they are:
### Input
```
{0..15}
{-10..-5}
{3..-6..2}
{a..f}
{Z..P..3}
{a,b,{f..k},p}
{a,{b,c}}
c{a,o,ha,}t
{ab,fg}{1..3}
{A..C}{x,{ab,fg}{1..3},y,}
{a..c} {1..5}
{a{0..100..10},200}r
```
### Output
```
0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
-10 -9 -8 -7 -6 -5
3 1 -1 -3 -5
a b c d e f
Z W T Q
a b f g h i j k p
a b c
cat cot chat ct
ab1 ab2 ab3 fg1 fg2 fg3
Ax Aab1 Aab2 Aab3 Afg1 Afg2 Afg3 Ay A Bx Bab1 Bab2 Bab3 Bfg1 Bfg2 Bfg3 By B Cx Cab1 Cab2 Cab3 Cfg1 Cfg2 Cfg3 Cy C
a b c 1 2 3 4 5
a0r a10r a20r a30r a40r a50r a60r a70r a80r a90r a100r 200r
```
[Answer]
# Ruby, ~~405~~ ~~403~~ ~~401~~ 400 bytes
A wise man (Jamie Zawinski) once said, "Some people, when confronted with a problem, think 'I know, I'll use regular expressions.' Now they have two problems."
I don't think I fully appreciated that quote until I tried to solve this problem with recursive regex. Initially, the regex cases seemed simple, until I had to deal with the edge cases involving letters adjacent to brackets, and then I knew that I was in hell.
[Anyways, run it online here with test cases](https://repl.it/C9sG/4)
```
->s{s.gsub!(/{(-?\w+)..(-?\w+)(..(\d+))?}/){x,y=$1,$2;a,b,c=[x,y,$4].map &:to_i
$1[/\d/]?0:(a,b=x,y)
k=a<b ?[*a..b]:[*b..a].reverse
?{+0.step(k.size-1,$4?c:1).map{|i|k[i]}*?,+?}}
r=1
t=->x{x[0].gsub(/^{(.*)}$/){$1}.scan(/(({(\g<1>|,)*}|[^,{}]|(?<=,|^)(?=,|$))+)/).map{|i|i=i[0];i[?{]?r[i]:i}.flatten}
r=->x{i=x.scan(/({(\g<1>)*}|[^{} ]+)/).map(&t)
i.shift.product(*i).map &:join}
s.split.map(&r)*' '}
```
Ungolfed:
```
->s{
s.gsub!(/{(-?\w+)..(-?\w+)(..(\d+))?}/){ # Replace all range-type brackets {a..b..c}
x,y=$1,$2;a,b,c=[x,y,$4].map &:to_i # Set up int variables
$1[/\d/]?0:(a,b=x,y) # Use int variables for a,b if they're numbers
k=a<b ?[*a..b]:[*b..a].reverse # Create an array for the range in the correct direction
'{'+ # Return the next bit surrounded by brackets
0.step(k.size-1,$4?c:1).map{|i|k[i] # If c exists, use it as the step size for the array
}*',' # Join with commas
+'}'
}
r=1 # Dummy value to forward-declare the parse function `r`
t=->x{ # Function to parse a bracket block
x=x[0].gsub(/^{(.*)}$/){$1} # Remove outer brackets if both are present
# x[0] is required because of quirks in the `scan` function
x=x.scan(/(({(\g<1>|,)*}|[^,{}]|(?<=,|^)(?=,|$))+)/)
# Regex black magic: collect elements of outer bracket
x.map{|i|i=i[0];i[?{]?r[i]:i}.flatten # For each element with brackets, run parse function
}
r=->x{ # Function to parse bracket expansions a{b,c}{d,e}
i=x.scan(/({(\g<1>)*}|[^{} ]+)/) # Regex black magic: scan for adjacent sets of brackets
i=i.map(&t) # Map all elements against the bracket parser function `t`
i.shift.product(*i).map &:join # Combine the adjacent sets with cartesian product and join them together
}
s.split.map(&r)*' ' # Split on whitespace, parse each bracket collection
# and re-join with spaces
}
```
[Answer]
# Python 2.7, ~~752~~ 728 bytes
Wow, this is like a bunch of code golfs in one challenge!
Thanks to @Neil for shortening a lambda
```
def b(s,o,p):
t,f=s>':'and(ord,chr)or(int,str);s,o=t(s),t(o);d=cmp(o,s)
return list(map(f,range(s,o+d,int(p)*d)))
def e(s):
c=1;i=d=0
while c:d+=-~'{}}'.count(s[i])%3-1;i+=1;c=i<len(s)and 0<d
return i
def m(s):
if len(s)<1:return[]
if','==s[-1]:return m(s[:-1])+['']
i=0
while i<len(s)and','!=s[i]:i+=e(s[i:])
return[s[:i]]+m(s[i+1:])
n=lambda a,b:[c+d for c in a for d in b]or a or b
def p(s):
h=s.count
if h('{')<1:return[s]
f,l=s.index('{'),e(s)
if h('{')<2and h('..')>0and f<1:s=s[1:-1].split('..');return b(s[0],s[1],s[2])if len(s)>2 else b(s[0],s[1],1)
if f>0 or l<len(s):return n(p(s[:f]),n(p(s[f:l]),p(s[l:])))
return sum(map(list,map(p,m(s[1:-1]))),[])
o=lambda s:' '.join(p('{'+s.replace(' ',',')+'}'))
```
### Explanation
* `b`: calculates range according to specs.
* `e`: returns position of first outermost close brace. Iterative.
* `m`: splits outermost elements on commas. Recursive.
* `n`: combines arrays while checking for empties. ~~I couldn't get `and/or` to work.~~
* `p`: Where most of the work is done. Checks all the cases (Range, just list, needs to combine). Recursive.
* `o`: What should take input. Formats input/output to `p`.
---
I feel I can improve in some places, so I will try to golf more. Also I should put in more detail in the explanation.
[Answer]
## JavaScript (Firefox 30-57), ~~465~~ ~~427~~ 425 bytes
```
f=s=>/\{/.test(s)?f(s.replace(/([^,{}]*\{[^{}]*\})+[^,{}]*/,t=>t.split(/[{}]+/).map(u=>u.split`,`).reduce((a,b)=>[for(c of a)for(d of b)c+d]))):s.split`,`.join` `
s=>f(`{${s.split` `}}`.replace(/\{(-?\w+)\.\.(-?\w+)(\.\.(\d+))?\}/g,(m,a,o,_,e)=>{m=(a>'@')+(a>'_');a=parseInt(a,m?36:10);o=parseInt(o,m?36:10);e=+e||1;if(o<a)e=-e;for(r=[];e<0?o<=a:a<=o;a+=e)r.push(m?a.toString(36):a);r=`{${r}}`;return m-1?r:r.toUpperCase()}))
```
ES6 version of `f` weighs in at an extra 10 bytes:
```
f=s=>/\{/.test(s)?f(s.replace(/([^,{}]*\{[^{}]*\})+[^,{}]*/,t=>t.split(/[{}]+/).map(u=>u.split`,`).reduce((a,b)=>[].concat(...a.map(c=>b.map(d=>c+d)))))):s.split`,`.join` `
g=s=>f(`{${s.split` `}}`.replace(/\{(-?\w+)\.\.(-?\w+)(\.\.(\d+))?\}/g,(m,a,o,_,e)=>{m=(a>'@')+(a>'_');a=parseInt(a,m?36:10);o=parseInt(o,m?36:10);e=+e||1;if(o<a)e=-e;for(r=[];e<0?o<=a:a<=o;a+=e)r.push(m?a.toString(36):a);r=`{${r}}`;return m-1?r:r.toUpperCase()}))
h=(s,t=s.replace(/\{[^{}]*\}/,""))=>s!=t?h(t):!/[{}]/.test(s)
```
```
<input oninput="o.textContent=h(this.value)?g(this.value):'{Invalid}'"><div id=o>
```
Explanation: Starts by changing spaces into commas and wrapping the entire string in `{}` for consistency (thanks to @Blue for the idea). Then searches for all the `{..}` constructs and expands them into `{,}` constructs. Next uses recursion to repeatedly expands all `{,}` constructs from the inside out. Finally replaces all commas with spaces.
```
f=s=>/\{/.test(s)? while there are still {}s
f(s.replace( recursive replacement
/([^,{}]*\{[^{}]*\})+[^,{}]*/, match the deepest group of {}s
t=>t.match(/[^{}]+/g split into {} terms and/or barewords
).map(u=>u.split`,` turn each term into an array
).reduce((a,b)=> loop over all the arrays
[for(c of a)for(d of b)c+d])) cartesian product
):s.split`,`.join` ` finally replace commas with spaces
s=>f( change spaces into commas and wrap
`{${s.split` `}}`.replace( match all {..} seqences
/\{([-\w]+)\.\.([-\w]+)(\.\.(\d+))?\}/g,(m,a,o,_,e)=>{
m=(a>'@')+(a>'_'); sequence type 0=int 1=A-Z 2=a-z
a=parseInt(a,m?36:10); convert start to number
o=parseInt(o,m?36:10); convert stop to number
e=+e||1; convert step to number (default 1)
if(o<a)e=-e; check if stepping back
for(r=[];e<0?o<=a:a<=o;a+=e) loop over each value
r.push(m?a.toString(36):a); convert back to string
r=`{${r}}`; join together and wrap in {}
return m-1?r:r.toUpperCase()})) convert type 1 back to upper case
```
]
|
[Question]
[
# Introduction
In this challenge, your task is to decide whether a given sequence of numbers can be separated into two subsequences, one of which is increasing, and the other decreasing.
As an example, consider the sequence `8 3 5 5 4 12 3`.
It can be broken into two subsequences as follows:
```
3 5 5 12
8 4 3
```
The subsequence on the first row is increasing, and the one on the second row is decreasing.
Furthermore, you should perform this task efficiently.
# Input
Your input is a non-empty list `L` of integers in the range 0 – 99999 inclusive.
It is given in the native format of your language, or simply delimited by spaces.
# Output
Your output is a truthy value if `L` can be broken into an increasing and a decreasing subsequence, and a falsy value otherwise.
The subsequences need not be strictly increasing or decreasing, and either of them may be empty.
# Rules and bonuses
You can write a full program or a function.
The lowest byte count wins, and standard loopholes are disallowed.
Furthermore, brute forcing is forbidden in this challenge: **your program must run in polynomial time in the length of the input**.
You are not required to actually return the two subsequences, but there is a **bonus of -20%** for doing so.
To make the bonus easier to claim in statically typed languages, it is acceptable to return a pair of empty lists for the falsy instances.
# Test cases
Given in the format `input -> None` for falsy inputs and `input -> inc dec` for truthy inputs.
Only one possible pair of subsequences is given here; there may be more.
```
[4,9,2,8,3,7,4,6,5] -> None
[0,99999,23423,5252,27658,8671,43245,53900,22339] -> None
[10,20,30,20,32,40,31,40,50] -> None
[49,844,177,974,654,203,65,493,844,767,304,353,415,425,857,207,871,823,768,110,400,710,35,37,88,587,254,680,454,240,316,47,964,953,345,644,582,704,373,36,114,224,45,354,172,671,977,85,127,341,268,506,455,6,677,438,690,309,270,567,11,16,725,38,700,611,194,246,34,677,50,660,135,233,462,777,48,709,799,929,600,297,98,39,750,606,859,46,839,51,601,499,176,610,388,358,790,948,583,39] -> None
[0,1,2,3,4] -> [0,1,2,3,4] []
[4,3,2,1,0] -> [] [4,3,2,1,0]
[1,9,2,8,3,7,4,6,5] -> [1,2,3,4,6] [9,8,7,5]
[71414,19876,23423,54252,27658,48671,43245,53900,22339] -> [19876,23423,27658,48671,53900] [71414,54252,43245,22339]
[10,20,30,20,30,40,30,40,50] -> [10,20,20,30,40,40,50] [30,30]
[0,3,7,13,65,87,112,43,22,1] -> [0,3,7,13,65,87,112] [43,22,1]
[7,4,4,7,4,7,7,4,7,4,4,4,7,7] -> [7,7,7,7,7,7,7] [4,4,4,4,4,4,4]
[7,997,991,957,956,952,7,8,21,924,21,923,22,38,42,44,920,49,58,67,71,83,84,85,917,89,907,896,878,878,90,861,115,860,125,128,140,148,858,155,160,836,164,182,826,191,824,805,195,792,205,782,206,210,769,213,756,748,214,745,724,701,234,241,693,268,685,293,679,297,334,671,336,669,341,652,356,648,362,364,370,375,386,630,622,388,389,618,398,408,468,615,470,533,611,539,544,609,586,582,572,565,547,602,536,619,624,528,512,631,640,649,669,671,677,505,678,723,743,489,489,473,454,757,446,445,758,759,764,445,431,770,429,426,418,409,790,383,379,366,363,791,358,795,809,827,835,356,353,841,844,333,867,323,317,879,311,881,309,896,282,281,897,263,904,237,236,226,202,195,914,186,177,917,920,157,926,936,154,138,943,131,945,100,98,947,957,964,95,973,989,57,43,32,21,16,13,11,8,0] -> [7,7,8,21,21,22,38,42,44,49,58,67,71,83,84,85,89,90,115,125,128,140,148,155,160,164,182,191,195,205,206,210,213,214,234,241,268,293,297,334,336,341,356,362,364,370,375,386,388,389,398,408,468,470,533,539,544,586,602,619,624,631,640,649,669,671,677,678,723,743,757,758,759,764,770,790,791,795,809,827,835,841,844,867,879,881,896,897,904,914,917,920,926,936,943,945,947,957,964,973,989] [997,991,957,956,952,924,923,920,917,907,896,878,878,861,860,858,836,826,824,805,792,782,769,756,748,745,724,701,693,685,679,671,669,652,648,630,622,618,615,611,609,582,572,565,547,536,528,512,505,489,489,473,454,446,445,445,431,429,426,418,409,383,379,366,363,358,356,353,333,323,317,311,309,282,281,263,237,236,226,202,195,186,177,157,154,138,131,100,98,95,57,43,32,21,16,13,11,8,0]
```
[Answer]
# Pyth, 34 bytes
```
.N|!N|&ghNT:tNhNY&gYhN:tNThN:QZ^T5
```
[Test Suite](https://pyth.herokuapp.com/?code=.N%7C%21N%7C%26ghNT%3AtNhNY%26gYhN%3AtNThN%3AQZ%5ET5&test_suite=1&test_suite_input=%5B4%2C9%2C2%2C8%2C3%2C7%2C4%2C6%2C5%5D%0A%5B0%2C99999%2C23423%2C5252%2C27658%2C8671%2C43245%2C53900%2C22339%5D%0A%5B10%2C20%2C30%2C20%2C32%2C40%2C31%2C40%2C50%5D%0A%5B49%2C844%2C177%2C974%2C654%2C203%2C65%2C493%2C844%2C767%2C304%2C353%2C415%2C425%2C857%2C207%2C871%2C823%2C768%2C110%2C400%2C710%2C35%2C37%2C88%2C587%2C254%2C680%2C454%2C240%2C316%2C47%2C964%2C953%2C345%2C644%2C582%2C704%2C373%2C36%2C114%2C224%2C45%2C354%2C172%2C671%2C977%2C85%2C127%2C341%2C268%2C506%2C455%2C6%2C677%2C438%2C690%2C309%2C270%2C567%2C11%2C16%2C725%2C38%2C700%2C611%2C194%2C246%2C34%2C677%2C50%2C660%2C135%2C233%2C462%2C777%2C48%2C709%2C799%2C929%2C600%2C297%2C98%2C39%2C750%2C606%2C859%2C46%2C839%2C51%2C601%2C499%2C176%2C610%2C388%2C358%2C790%2C948%2C583%2C39%5D%0A%5B0%2C1%2C2%2C3%2C4%5D%0A%5B4%2C3%2C2%2C1%2C0%5D%0A%5B1%2C9%2C2%2C8%2C3%2C7%2C4%2C6%2C5%5D%0A%5B71414%2C19876%2C23423%2C54252%2C27658%2C48671%2C43245%2C53900%2C22339%5D%0A%5B10%2C20%2C30%2C20%2C30%2C40%2C30%2C40%2C50%5D%0A%5B0%2C3%2C7%2C13%2C65%2C87%2C112%2C43%2C22%2C1%5D%0A%5B7%2C4%2C4%2C7%2C4%2C7%2C7%2C4%2C7%2C4%2C4%2C4%2C7%2C7%5D%0A%5B7%2C997%2C991%2C957%2C956%2C952%2C7%2C8%2C21%2C924%2C21%2C923%2C22%2C38%2C42%2C44%2C920%2C49%2C58%2C67%2C71%2C83%2C84%2C85%2C917%2C89%2C907%2C896%2C878%2C878%2C90%2C861%2C115%2C860%2C125%2C128%2C140%2C148%2C858%2C155%2C160%2C836%2C164%2C182%2C826%2C191%2C824%2C805%2C195%2C792%2C205%2C782%2C206%2C210%2C769%2C213%2C756%2C748%2C214%2C745%2C724%2C701%2C234%2C241%2C693%2C268%2C685%2C293%2C679%2C297%2C334%2C671%2C336%2C669%2C341%2C652%2C356%2C648%2C362%2C364%2C370%2C375%2C386%2C630%2C622%2C388%2C389%2C618%2C398%2C408%2C468%2C615%2C470%2C533%2C611%2C539%2C544%2C609%2C586%2C582%2C572%2C565%2C547%2C602%2C536%2C619%2C624%2C528%2C512%2C631%2C640%2C649%2C669%2C671%2C677%2C505%2C678%2C723%2C743%2C489%2C489%2C473%2C454%2C757%2C446%2C445%2C758%2C759%2C764%2C445%2C431%2C770%2C429%2C426%2C418%2C409%2C790%2C383%2C379%2C366%2C363%2C791%2C358%2C795%2C809%2C827%2C835%2C356%2C353%2C841%2C844%2C333%2C867%2C323%2C317%2C879%2C311%2C881%2C309%2C896%2C282%2C281%2C897%2C263%2C904%2C237%2C236%2C226%2C202%2C195%2C914%2C186%2C177%2C917%2C920%2C157%2C926%2C936%2C154%2C138%2C943%2C131%2C945%2C100%2C98%2C947%2C957%2C964%2C95%2C973%2C989%2C57%2C43%2C32%2C21%2C16%2C13%2C11%2C8%2C0%5D&debug=0)
Uses memoized recursion to keep the runtime down. Defines a 3 input function `:`, which takes inputs `list suffix, end of increasing sequence, end of decreasing sequence.
[Answer]
# [Brachylog](https://github.com/JCumin/Brachylog), 16 bytes - 20% = 12.8 (but it's almost certainly not polynomial)
```
⊇≥₁X&⊇≤₁Y;X.cp?∧
```
[Try it online!](https://tio.run/##jY47TgMxFEW3Ek2R6oL8Ph7bQoIdUAeNpoAoggIRRBOhkIIgAaFiESBaGhp2E29k8jwEQUGBi@vrJ9vnnFwdj8@uz6en3M1n1WBnf1DNhvN8/56Xdzf58a06nF5MqsX6c7VYfzx3@ekhr17z8nY07OuL1aO90e748sAud13TKBIYEYIARQ3fonFIZYFFWeDZMzjUPiLWgaDC6uElOQdmkWQvyKqDfCVDLamkd/13ZAiBWlfb2c5lTn@gAykpKMVQf@P1h6//E3C9gPslUBAkqD2iFTJD0zCPQjS29gZhm7qdhLbdAA "Brachylog – Try It Online")
Fails if there's no pair of compliant subsequences and outputs them through its output variable if there is one (but will just print `true.` if it's run as a program). I say it's *almost* certainly not polynomial because the beauty of Brachylog is that since it's a declarative language, you don't do so much in the way of implementing an algorithm as you do just describing relationships between variables and asking the computer to crank out results. So chances are this is hardcore brute force, but I spent long enough copy pasting the test cases (two of which it just times out on) that I feel like I should submit this anyhow, if for no other reason than to drag this challenge up from the back of the [decision-problem](/questions/tagged/decision-problem "show questions tagged 'decision-problem'") "Newest" list.
```
X X is a
≥₁ non-increasing
⊇ sublist of the input
& and
Y Y is a
≤₁ non-decreasing
⊇ sublist of the input
;X which paired with X
. is the output variable
c which when its elements are concatenated
p is a permutation of
? the input
∧ which is not unified with the output.
```
[Answer]
# [Haskell](https://www.haskell.org/), 65 bytes
```
(>[]).foldl(%)[(0,9^6)]
p%x=do(u,d)<-p;[(x,d)|x>=u]++[(u,x)|x<=d]
```
[Try it online!](https://tio.run/##jVLLTtxAELznK3wIklcUaB7d0zMK5kccR1qx2QTFgBVA2gPfjlPtrJJLDvFhxu5HVXWXv@@ff3yd5/U4fF7723HaXR@f5sPcX@zGPqB9Kbvpw3JxGg5P/SsOu5ur5dPYn/j2drodXqfLy5HxE79uhsO0PuzvH7uhW37eP750H7uH/dIdeY@joCGhIsMgKNAJI@H9QcqSMjRpQrKiFbVYhOQkCs0tBKSUc2NH5GtA/n0mCM/opwYmpaGKIJqhGTlUWJZ5Q1reUlaMzYKsGRIZT4qqxjJDJWWlDCsVkTxCWuOdFZnZCq0sJGapTDr2xl4gpCscj5iZggt5tCaY8xhjhXCsTsIuornABB@wUWhVxERREpFIrIF4ShAWcE@5ojSflzsyTkn5MYKcRuFMGjUWjzSXUwiz9SmjJSBSOvcGKVTjcN7QYNx4Sw3F99oonqYw6k1kr9rYgMqQRka4XtZHoyJfBveQaZBRVRPfCQdsm5UcgOaK@8A78ds9if@w3aJwIbFVgp6tl7/ey/@ZHzbzwx/zw0YRN7urr4l/B2VQhzOSWzYFdj7lHLFpWt/vjvP@2/N6dbcsvwA "Haskell – Try It Online")
Iterates through the list, tracking the possible pairs `(u,d)` of the max of the increasing sequence and the min of the decreasing one. Each new element `x` replaces either `u` or `d`, which corresponds to it being append to that subsequence. It could be that both or neither options are valid. In the end, we check that the list of possibilities is nonempty.
The initial bounds `(0,9^6)` use that the problem specifies the numbers to be in the range 0 – 99999. A more general solution could do `(1/0,-1/0)` to makes `(-inf,inf)`.
]
|
[Question]
[
Python's [pickle module](https://docs.python.org/2/library/pickle.html) is used for serialisation, allowing one to dump an object in a way such that it can be later reconstructed. For this, pickle uses a simple stack-based language.
To keep things simple, we will be dealing with a small subset of this language:
```
( Push a mark to the stack
S'abc'\n Push a string to the stack (here with contents 'abc')
l Pop everything up to the last mark, wrapping all but the mark in a list
t Pop everything up to the last mark, wrapping all but the mark in a tuple
. Terminate the virtual machine
```
Your task is to implement this subset of the language. Note that `\n` is a literal newline here, and newlines are actually important to the language.
For those familiar with GolfScript or CJam-like languages, `(` and `l/t` operate similarly to `[` and `]` respectively.
# Input
To keep things simple, the input will always be valid. In particular, you may assume the following about the input:
* Strings will only consist of lowercase letters and spaces `[a-z ]`, and will always use single quotes.
* There will be no extraneous characters, with all instructions being as specified above. For example, this means that newlines will only ever occur after strings.
* Every `l/t` has a matching `(` before it and every `(` has a matching `l/t` after it. There will also be at least one `(`.
* There will be exactly one `.`, and it will always be the final character.
You may take input via command line, STDIN or function argument. You may use a single newline-escaped string instead of a multiline string if you wish, but please specify this in your answer.
# Output
Output should be a representation of the final object, printed to STDOUT or returned **as a string**. Specifically:
* Strings are represented by opening and closing single quotes with content in between, e.g. `S'abc' -> 'abc'`. You may not use double quotes for this challenge, even though they are allowed in Python.
* Lists are represented by comma-separated elements surrounded by `[]` (e.g. `['a','b','c']`), while tuples are repsented by comma-separated elements surrounded by `()` (e.g. `('a','b','c')`).
* Spaces don't matter, e.g. `('a', 'b', 'c' )` is okay.
* **You cannot have a comma before the closing bracket.** Note that this is intentionally different from Python syntax rules to make things easier for most languages, and also to make it harder to simply build the list/tuple in Python then output it, due to how the single-element tuple is represented (for this challenge, we need `('a')` as opposed to `('a',)`).
## Examples
The above text might seem daunting, but the following examples should make things a bit clearer.
```
(l.
```
**Possible output:** `[]`
```
(t.
```
**Possible output:** `()`
```
(S'hello world'
l.
```
**Possible output:** `['hello world']`
```
(S'string one'
S'string two'
S'string three'
t.
```
**Possible output:** `('string one', 'string two', 'string three')`
```
(S'a'
(S'b'
S'c'
lt.
```
**Possible output:** `('a',['b','c'])`
```
((S'a'
S'b'
(lS'c'
t(S'd'
tl.
```
**Possible output:** `[('a', 'b', [], 'c'), ('d')]`
```
((S'a'
((S'b'
t(S'c'
lS'd'
(((ltlS'e'
S'f'
lS'g'
tl.
```
**Possible output:** `[('a',[('b'),['c'],'d',[([])],'e','f'],'g')]`
# Rules
* This is [code-golf](/questions/tagged/code-golf "show questions tagged 'code-golf'"), so the code in the fewest bytes wins.
* Any functionality that is designed to work with Python pickles is not allowed.
---
Security note: In real code, only unpickle from sources you trust, or else you might get a nasty `cos\nsystem\n(S'rm -rf'\ntR.` surprise
[Answer]
# CJam, 63
```
q{"Slt 1:T;L ]',*'[\+']+ ]',*'(\+')+ [
0:T; C+"35/T=S/(C#=~}fC
```
[Try it online](http://cjam.aditsu.net/#code=q%7B%22Slt%201%3AT%3BL%20%5D'%2C*'%5B%5C%2B'%5D%2B%20%5D'%2C*'(%5C%2B')%2B%20%5B%0A%200%3AT%3B%20C%2B%2235%2FT%3DS%2F(C%23%3D~%7DfC&input=((S'a'%0A((S'b'%0At(S'c'%0AlS'd'%0A(((ltlS'e'%0AS'f'%0AlS'g'%0Atl.)
**Explanation:**
```
q read the input
{…}fC for each character C in the input
"…" push that long string, containing code to handle various cases
35/ split it into (two) parts of length 35
T= get the T'th part; T is 1 when parsing a string and 0 otherwise
(T is initially 0 by default)
S/ split by space into an array of strings
( take out the first item (containing special characters to check)
C# find the index of C in that string
= get the corresponding string from the array
(when C is not found, # returns -1 which gets the last array item)
~ execute that string
```
Now the long string with various pieces of code. Each part has a few characters to check and then a block for handling each one, and the default case.
First part: `Slt 1:T;L ]',*'[\+']+ ]',*'(\+')+ [`
```
Slt special characters to check
######## first block, corresponding to character 'S'
1:T; set T=1, causing the next characters to be processed with the 2nd part
L push an empty string/array, which will be used to collect the string
######## second block, corresponding to character 'l'
] end array
',* join with commas
'[\+ prepend a '['
']+ append a ']'
######## third block, corresponding to character 't'
] end array
',* join with commas
'(\+ prepend a '('
')+ append a ')'
######## last block, corresponding to other characters (practically, '(' and '.')
[ start array
```
Second part: `(newline) 0:T; C+`
```
newline special characters to check (only one)
######## first block, corresponding to newline
0:T; set T=0, switching back to the first part
######## last block, corresponding to any other character (including apostrophe)
C+ append the character to the collecting string
```
[Answer]
# Perl, 149 bytes
I have a bad feeling that this is a poor attempt, but here goes:
```
$/=$,;$"=",";@s=[];/^\(/?$s[@s]=[]:{$p=/S(.*')/?$1:/l|t/?($l="@{pop@s}")|/l/?"[$l]":"($l)":0,push@{$s[-1]},$p}for<>=~/([(lt]|S.*?\n)/g;print$s[0][0];
```
The script has to be saved in a file and it takes input from STDIN.
Explanation:
```
# Set the input record separator to undef so that <> reads all lines at
# once
$/=$,;
# Ensure that elements of lists printed in quotes are separated by commas
$"=",";
# The stack. Initialise the bottom element with an empty array
@s=[];
# Tokens are extracted in the for loop a few lines below. Copied here for
# clarity: Read the entire input and iterate over all valid tokens of the
# pickle language
# for <>=~/([(lt]|S.*?\n)/g;
# the token is a mark - push an empty array to the stack
/^\(/ ? $s[@s]=[]
# token is a string, push it inside the stack top
: {$p=/S(.*')/ ? $1
# otherwise, remove the top and create list or tuple
# from it and push it inside the top element
: /l|t/ ? ($l="@{pop@s}") | /l/ ? "[$l]"
: "($l)"
: 0 # dummy value
# pushing of the string/list/tuple actually
# happens here
, push@{$s[-1]},$p}
# read the entire input at once and iterate over all valid tokens
for <>=~/([(lt]|S.*?\n)/g;
# in the end, the bottom element of the stack will be an array with just one
# element which is the string representation of the object
print$s[0][0];
```
[Answer]
# ><>, 88 bytes
```
^"][">}r]
~rl?!;o11.
^0\!\
&</\?[1&~?=1l","
1/\ii:"'"=?v44.
>i9%0$. >r]i~
")("\
```
Fun with jumps! Uses the fact that the ASCII codes for the 5 main commands involved, mod 9, are:
```
S -> 2
l -> 0
t -> 8
( -> 4
. -> 1
```
This allows each operation to be handled on its own line, which will be jumped to directly. Also uses the stack of stacks to construct each string and nested list/tuple separately before wrapping them in the required characters.
[Answer]
# JavaScript (ES6), 199 bytes
```
s=>(q=x=>(o=[],x.slice(0,-1).map(v=>o=[...o,v.map?q(v):`'${v}'`]),x.pop()<"m"?`[${o}]`:`(${o})`),q(eval(s[r="replace"](/\(/g,"[")[r](/[tl](?![\w ]+'\n)/g,"'$&'],")[r](/S('.+')/g,"$1,").slice(0,-2))))
```
Runs several regex replaces on the input to turn it into valid JS code, then parses that.
## Test Snippet
```
f=
s=>(q=x=>(o=[],x.slice(0,-1).map(v=>o=[...o,v.map?q(v):`'${v}'`]),x.pop()<"m"?`[${o}]`:`(${o})`),q(eval(s[r="replace"](/\(/g,"[")[r](/[tl](?![\w ]*'\n)/g,"'$&'],")[r](/S('.+')/g,"$1,").slice(0,-2))))
```
```
<select oninput="I.value=this.selectedIndex?this.value.replace(/\\n/g,'\n'):'';O.innerHTML=this.selectedIndex?f(I.value):''"><option>---Tests---<option>(l.<option>(t.</option><option>(S'hello world'\nl.<option>(S'string one'\nS'string two'\nS'string three'\nt.<option>(S'a'\n(S'b'\nS'c'\nlt.<option>((S'a'\nS'b'\n(lS'c'\nt(S'd'\ntl.<option>((S'a'\n((S'b'\nt(S'c'\nlS'd'\n(((ltlS'e'\nS'f'\nlS'g'\ntl.</select><br>
<textarea rows=10 cols=20 id=I></textarea><br><button onclick="O.innerHTML=f(I.value)">Run</button><br><pre id=O></pre>
```
[Answer]
# Julia + [ParserCombinator.jl](https://github.com/andrewcooke/ParserCombinator.jl) ~~306~~ 240
With my latest set of revisions I no longer think a pure julia solution would be shorter.
```
using ParserCombinator
v=join
j(t)=v(t,",")
a=Delayed()
s=E"S'"+Star(p".")+Drop(Equal("'\n"))|>x->"'$(v(x))'"
i=Star(a)|E""
l=E"("+i+E"l"|>x->"[$(j(x))]"
t=E"("+i+E"t"|>x->"($(j(x)))"
a.matcher=s|l|t
f(x)=parse_one(x,a+E".")|>first
```
That was interesting.
I think the coded is fairly eloquent.
* Output formatting is done at generation
* `a` `l`, `i`, `t`, and `s` are basically CFG rules
* `f` is the function that is called it brings it all together.
* the `Drop(Equal("'\n"))` is annoying -- that would ideally be written as `E"\n"` but the `E` string macro does not handle escape sequences.
* Interestingly this can trivially be converted to returning julia data-structures, it is basically removing the transforms on the RHS of `|>`s and adding `tuple` for the `t` rule
]
|
[Question]
[
The famous C64 basic one liner
```
10 PRINT CHR$(205.5+RND(1)); : GOTO 10
```
prints a maze of slashes and backslashes.
```
\\/\\\//\/\////\\/\/
\/\///\\///////\//\/
/\\\//\//\////\\//\\
\////\//\//\/\\\\\\/
/\/\\///\\\\/\\\\/\\
\/\//\\\\\\//\/\////
/\//\\///\/\///\////
\/\\\//\\/\\\//\\/\/
//////\\/\\/\/\/\///
\\/\/\\////\/\/\\/\/
```
Read in such maze made of diagonal walls from stdin and print out the same maze with *horizontal* and *vertical* walls consisting of the wall character "#"
For example the small maze
```
/\\
\\/
///
```
translates to
```
#####
# #
# # # #
# # # #
##### # # #
# #
#########
#####
```
To be precise, each isolated wall segment has the length of five characters, adjacent wall segments share a corner. Moving a character to the right/left/top/down in the matrix of slashes and backslashes corresponds to a diagonal translation by 2 characters in vertical and 2 characters in horizontal direction in the #-matrix.
More context can be found in the book [10 print](https://10print.org/10_PRINT_121114.pdf).
[Answer]
# Python 3, ~~226~~ 224 bytes
My first Python golf, so probably very sub-optimal.
It produces a whole lot of trailing whitespace, but there are no preceding newlines, and at most two preceding spaces.
The input needs to be given by hand from command line (maybe someone knows a shorter way to get multiline input in Python...).
```
e,z,s=enumerate,'0',list(iter(input,""))
p=''.join(s)*5
r=[len(p)*[' ']for _ in p]
for y,l in e(s):
for x,c in e(l):
for i in range(-2,3):r[2*(x+y+(s>[z]))+i*(c>z)][2*(x+len(s)-y)+i*(c<z)]='#'
for l in r:print(''.join(l))
```
The idea is to initialize a huge array of spaces `r`, then iterate through the input and replace the spaces with `#` as needed, and finally print the whole array.
A trick I used is to compare characters to `z = '0'` instead of testing equality to `'/'` or `'\'`, which saves a bunch of bytes.
[Answer]
# Julia, 258 bytes
A functional solution...
```
A=split(readall(STDIN))
q(i,j)=fld(i-1,j)
n,^ =A[].(3),q
f(i,j)=try A[1+i^5][1+j^5]<'0'?(i+j)%5==1:(i-j)%5==0catch 0end
h(i,j)=f(i+i^4,j)|f(i+(i-1)^4,j)
g(i,j)=h(i,j+j^4)|h(i,j+(j-1)^4)
for i=1:6length(A),j=-n-5:2n;print(" #"[1+g(i-j,i+j)],j==2n?"\n":"")end
```
In order of appearance:
`f` covers '/' and '\' by their 5\*5 bit patters,
`h` folds every fifth and following line into a single line (recall "adjacent wall segments share a corner") and `g` does the same for the columns. Finally, `i-j,i+j` rotates the picture.
[Answer]
# JavaScript (ES6), 258
A function with the maze as a parameter, returning the output.
Unsure if it's valid, due to the input/output rules (it was fun anyway)
```
f=m=>([...m].map(c=>{if(c<' ')x=sx-=2,y=sy+=2;else for(x+=2,y+=2,d=c>'0',i=y-3*d,j=x-3*!d,c=5;c--;)o[i+=d][j+=!d]='#';},w=m.search`
`,h=m.match(/\n/g).length,sy=y=0,sx=x=h*2,o=Array(z=(w+h+1)*2).fill(' ').map(x=>Array(z).fill(x))),o.map(r=>r.join``).join`
`)
// LESS GOLFED
U=m=>(
w=m.search`\n`,
h=m.match(/\n/g).length,
o=Array(z=(w+h+1)*2).fill(' ').map(x=>Array(z).fill(x)),
sy=y=0,
sx=x=h*2,
[...m].forEach(c=>{
if(c<' ')x=sx-=2,y=sy+=2
else for(x+=2,y+=2,d=c>'0',i=y-3*d,j=x-3*!d,c=5;c--;)o[i+=d][j+=!d]='#';
}),
o.map(r=>r.join``).join`\n`
)
// TEST
out=x=>O.innerHTML+=x+'\n'
test=`\\\\/\\\\\\//\\/\\////\\\\/\\/
\\/\\///\\\\///////\\//\\/
/\\\\\\//\\//\\////\\\\//\\\\
\\////\\//\\//\\/\\\\\\\\\\\\/
/\\/\\\\///\\\\\\\\/\\\\\\\\/\\\\
\\/\\//\\\\\\\\\\\\//\\/\\////
/\\//\\\\///\\/\\///\\////
\\/\\\\\\//\\\\/\\\\\\//\\\\/\\/
//////\\\\/\\\\/\\/\\/\\///
\\\\/\\/\\\\////\\/\\/\\\\/\\/`
out(test),out(f(test))
```
```
<pre id=O></pre>
```
]
|
[Question]
[
You are the captain of a battleship. The engineering department's been cutting corners with designs this year, so the ship you're on takes the shape of a simple triangle.
You walk out onto the deck and enjoy the sea breeze... though not for long. An enemy has fired at you! — but will the shot hit?
## Input
You may write either a function or a full program for this challenge.
Your program will take in 11 integers, ten of which are paired:
* The first three pairs of integers (x1, y1), (x2, y2), (x3, y3) will specify the vertices of your ship. The triangle formed will have nonzero area.
* The next pair of integers (ex, ey) specifies the location of the enemy's cannon. The enemy cannon will never lie on, or within the boundary of your ship.\*
* The pair (ax, ay) after that specifies where the enemy aimed at. This will be distinct from (ex, ey).
* The final positive integer R specifies the range of the enemy's shot
\*You'd be a terrible captain if you didn't even notice that happening!
## Output
You must print/return a [truthy](http://meta.codegolf.stackexchange.com/a/2194) value (e.g. true, 1) if the battleship will be hit, otherwise a falsy value (e.g. false, 0).
## What is a hit?
The enemy shot is a straight line segment of length R from (ex, ey) in the direction of (ax, ay). If this line segment overlaps any part of the *interior* of your triangular battleship, then this counts as a hit. Otherwise it is not a hit.
Shots which graze along or only reach up to the boundary of the triangle do not count as a hit.
## Examples
```
0 0 0 1 1 0
1 1
0 0
2
```

**Hit:** The enemy has shot right through the centre of your ship!
---
```
2 0 0 2 4 4
0 0
1 1
1
```

**No hit:** The enemy's range is too short, so you are safe.
---
```
0 0 1 2 3 0
-4 0
0 0
8
```

**No hit:** The enemy has grazed the side of your ship, so this does not count as a hit. Lucky!
---
```
0 0 -1 3 4 -1
-3 -4
3 4
5
```

**No hit:** The enemy shot just stops short of the ship, so you are safe. If the enemy's cannon had even slightly better range, then you would have been hit! Phew!
---
```
-2 -3 -3 6 7 -2
-6 2
1 -4
7
```

**Hit:** Even though the shot didn't penetrate to the other side, this is still a hit.
---
```
-3 2 2 -4 7 -3
-3 -4
-3 0
10
```

**No hit:** For the record, this is another close miss.
---
## Additional test cases
```
0 0 6 0 6 8
-6 -8
6 8
20
```

**No hit:** This is another graze, but at an angle.
---
```
0 0 -2 -5 5 3
-3 4
0 0
6
```

**Hit:** The shot entered via a vertex of the ship.
## Scoring
This is [code-golf](/questions/tagged/code-golf "show questions tagged 'code-golf'"), so the shortest code in bytes wins. [Standard loopholes](http://meta.codegolf.stackexchange.com/questions/1061/standard-loopholes-which-are-no-longer-funny) apply.
[Answer]
# Python 3, 252 bytes
This is certainly the most variables I've ever used in code golf. :^P
```
from math import*;A=atan2
def h(a,b,c,d,e,f,g,h,i,j,R):
r=R;_=0
while r>0:Q=A(j-h,i-g);k,l=g+r*cos(Q),h+r*sin(Q);D=A(d-b,c-a);E=A(f-b,e-a);F=A(l-b,k-a);G=A(b-d,a-c);H=A(f-d,e-c);I=A(l-d,k-c);_=_ or(D<F<E or E<F<D)and(G<I<H or H<I<G);r-=.001
return _
```
Slightly ungolfed, with comments:
```
from math import*
# Parameters:
# (a,b) (c,d) (e,f) - vertices of the triangle
# (g,h) - location of cannon
# (i,j) - aim of cannon
# R - range of cannon
# Variables within function:
# _ - was this shot a hit?
# r - distance 0 < r <= R that we're testing
# Q - angle between cannon source and destination
# (k,l) - point that we're testing
# D,E,F - angles between point 1 and 2,3,test
# G,H,I - angles between point 2 and 1,3,test
def h(a,b,c,d,e,f,g,h,i,j,R):
r=R;_=0
while r>0:
Q=atan2(j-h,i-g)
k,l=g+r*cos(Q),h+r*sin(Q)
D=atan2(d-b,c-a)
E=atan2(f-b,e-a)
F=atan2(l-b,k-a)
G=atan2(b-d,a-c)
H=atan2(f-d,e-c)
I=atan2(l-d,k-c)
_=_ or(D<F<E or E<F<D)and(G<I<H or H<I<G)
r-=.001
return _
```
**How it works:**
* Calculate the endpoint of the shot.
* Test lots of points along the line from the endpoint to the cannon's location:
+ Calculate angles from vertex 1 to other two vertices and to test point;
+ Calculate angles from vertex 2 to other two vertices and to test point;
+ If the test point angle is between the other two angles, in both cases, then the test point is within the triangle and the ship has been hit.
**Sample runs:**
```
>>> h(0,0,0,1,1,0,1,1,0,0,2)
True
>>> h(0,0,1,2,3,0,-4,0,0,0,8)
False
>>> h(0,0,-1,3,4,-1,-3,-4,3,4,5)
False
>>> h(-2,-3,-3,6,7,-2,-6,2,1,-4,7)
True
```
[Answer]
# Python 2.7, 235 bytes
```
from numpy import*
X=cross
h=lambda q,w,a,s,y,x,c,v,d,f,r:max([(X([a-q,s-w],[c+k*(d-c)-q,v+k*(f-v)-w])>0)==(X([y-a,x-s],[c+k*(d-c)-a,v+k*(f-v)-s])>0)==(X([q-y,w-x],[c+k*(d-c)-y,v+k*(f-v)-x])>0)for k in arange(0,r/hypot(d-c,f-v),1e-4)])
```
Computes the cross product `AB x AP` between the corners A,B and the point P. If all three have the same sign, then the point is inside the triangle.
Ungolfed:
```
from numpy import *
def i(q,w,a,s,y,x,e,r): # helper-function, checks whether ER is inside the triangle QW-AS-YX
t=cross([a-q,s-w],[e-q,r-w])>0
g=cross([y-a,x-s],[e-a,r-s])>0
b=cross([q-y,w-x],[e-y,r-x])>0
return t==g==b
def h(q,w,a,s,y,x,c,v,d,f,r):
R=arange(0,r/hypot(d-c,f-v),1e-3)
return max([i(q,w,a,s,y,x,c+k*(d-c),v+k*(f-v)) for k in R])
```
Tests:
```
In : h(0,0,0,1,1,0,1,1,0,0,2)
Out: True
In : h(-3,2,2,-4,7,-3,-3,-4,-3,0,10)
Out: False
In : h(0,0,1,2,3,0,-4,0,0,0,8)
Out: True
Grazes may count as hits...
In : h(1,2,0,0,3,0,-4,0,0,0,8)
Out: False
...or not, depending on the order of edges
```
[Answer]
# C, 247 bytes
Definitely not quite golfed yet.
```
#include<math.h>
int z(float*k){float s=1e-3,t=s,p=k[8]-k[6],q=k[9]-k[7],r=k[10]/hypot(p,q);int w=0;for(;t<1;t+=s){float x=k[6]-k[0]+p*r*t,y=k[7]-k[1]+q*r*t,b=k[2]*k[5]-k[3]*k[4],d=(x*k[5]-y*k[4])/b,e=(x*k[3]-y*k[2])/b;w|=d>0&e<0&d-e<1;}return w;}
```
Currently this uses an approach similar to DLosc's solution, i.e. iterates through all possible coordinates on the line segment to determine if it intersects with the triangle. (So it will fail if the range is over 1000) However, it uses the formula from <http://mathworld.wolfram.com/TriangleInterior.html> to determine if a point is inside the triangle. This avoids a bunch of trigonometric functions.
---
Example check, should print `1 0 0 0 1 0`.
```
#include <stdio.h>
int main() {
{
float arr[] = {0,0,0,1,1,0,1,1,0,0,2};
printf("%d\n", z(arr));
}
{
float arr[] = {2,0,0,2,4,4,0,0,1,1,1};
printf("%d\n", z(arr));
}
{
float arr[] = {0,0,1,2,3,0,-4,0,0,0,8};
printf("%d\n", z(arr));
}
{
float arr[] = {0,0,-1,3,4,-1,-3,-4,3,4,5};
printf("%d\n", z(arr));
}
{
float arr[] = {-2,-3,-3,6,7,-2,-6,2,1,-4,7};
printf("%d\n", z(arr));
}
{
float arr[] = {-3,2,2,-4,7,-3,-3,-4,-3,0,10};
printf("%d\n", z(arr));
}
}
```
[Answer]
# JavaScript (ES6) 320 ~~448 522 627~~
(Could still be golfed more?)
Steps:
1. Find the actual hit target (point at distance r on the line from enemy to aim)
2. Hit: if the segment from enemy to target intersect any of the sides of the ship, but not at the endpoints
3. Hit too: if the target is inside the ship - even if the shot entered at a vertex - test case 8
Ref:
[Segment intersection](https://stackoverflow.com/questions/563198/how-do-you-detect-where-two-line-segments-intersect)
[Point inside triangle](https://stackoverflow.com/questions/2049582/how-to-determine-a-point-in-a-triangle)
[Point in a segment given a distance](https://math.stackexchange.com/questions/134112/find-a-point-on-a-line-segment-located-at-a-distance-d-from-one-endpoint)
*Test in Firefox*
```
C=(i,j,k,l,m,n,g,h,a,b,r,
d=a-g,e=b-h,f=r/Math.sqrt(d*d+e*e),
p=g+f*d,q=h+f*e,
z=j*(m-k)+i*(l-n)+k*n-l*m,
s=(j*m-i*n+(n-j)*p+(i-m)*q)/z,
t=(i*l-j*k+(j-l)*p+(k-i)*q)/z,
S=(i,j,k,l,
a=k-i,b=l-j,c=p-g,d=q-h,e=i-g,f=j-h,
s=a*f-b*e,t=c*f-d*e,m=a*d-c*b)=>
m&&((s/=m)>0&s<1&(t/=m)>0&t<1)
)=>s>0&t>0&s+t<1|S(i,j,k,l)|S(i,j,m,n)|S(m,n,k,l)
// Test
MyOutput.innerHTML = ['Test1', C(0,0, 0,1, 1,0, 1,1, 0,0, 2),
'<br>Test2', C(2,0, 0,2, 4,4, 0,0, 1,1, 1),
'<br>Test3', C(0,0, 1,2, 3,0, -4,0, 0,0, 8),
'<br>Test4', C(0,0, -1,3, 4,-1, -3,-4, 3,4, 5),
'<br>Test5', C(-2,-3, -3,6, 7,-2, -6,2, 1,-4, 7),
'<br>Test6', C(-3,2, 2,-4, 7,-3, -3,-4, -3,0 ,10),
'<br>Test7', C(0,0, 6,0, 6,8, -6,-8, 6,8, 20),
'<br>Test8', C(0,0,-2,-5, 5,3, -3,4, 0,0, 6)];
```
```
<div id="MyOutput"></div>
```
**Ungolfed**
```
function check(p0x, p0y, p1x, p1y, p2x, p2y, ex, ey, ax, xy, r)
{
var sec = function(p0x, p0y, p1x, p1y, p2x, p2y, p3x, p3y)
{
var s10x = p1x - p0x, s10y = p1y - p0y,
s32x = p3x - p2x, s32y = p3y - p2y,
s02x = p0x - p2x, s02y = p0y - p2y,
s = s10x * s02y - s10y * s02x, t = s32x * s02y - s32y * s02x,
d = s10x * s32y - s32x * s10y;
return d && (s/=d) > 0 && s<1 && (t/=d) > 0 && t < 1 && [p0x + (t * s10x), p0y + (t * s10y)];
}
var pr = function(p0x, p0y, p1x, p1y, r)
{
var dx = (p1x-p0x), dy = (p1y-p0y), f = r/Math.sqrt(dx*dx+dy*dy);
return [p0x + f*dx, p0y+f*dy];
}
var inside = function(p0x, p0y, p1x, p1y, p2x, p2y, px, py)
{
var area2 = (-p1y*p2x + p0y*(-p1x + p2x) + p0x*(p1y - p2y) + p1x*p2y),
s = (p0y*p2x - p0x*p2y + (p2y - p0y)*px + (p0x - p2x)*py)/area2,
t = (p0x*p1y - p0y*p1x + (p0y - p1y)*px + (p1x - p0x)*py)/area2;
return s > 0 && t > 0 && s+t < 1;
}
var tx, xy;
[tx, ty] = pr(ex, ey, ax, ay, r);
return inside(p0x, p0y, p1x, p1y, p2x, p2y, tx,ty)
|| sec(p0x, p0y, p1x, p1y, ex, ey, tx, ty)
|| sec(p0x, p0y, p2x, p2y, ex, ey, tx, ty)
|| sec(p2x, p2y, p1x, p1y, ex, ey, tx, ty);
}
```
[Answer]
# [Scala](http://www.scala-lang.org/), ~~349~~ 328 bytes
Saved 21 bytes thanks to the comment of @ceilingcat
---
Golfed version. [Try it online!](https://tio.run/##hZDdasJAEIXvfYq5kqTNqlGrJXEFIf5dlBJLb1JK2SRrEhsT2awtEvPsdpIYaEEozGGGb/ccdifzWMwuqbvjnoQnFiWQX6L9IRUSsvKos2cy7ORMsqRPpzPtozDl6cDBplZ6dGNu@nwLocIMW3NRHspHcdQWFaBCVITaoTaGrdL8iwkQdGOW3aH6VDe/wyjmipj2VDyMMX2m7EioRSRQzRJ80uBe3Hlpptg1iGmIIIuSBlho8YmreYTVYI5gi4A3YIEgRvDZgCUCl/gaI14NVpXFR8sVrCuLjxYEDnXOZ2uyaC8m8/O86la7vZys2@vJ6ryq@tIUhOqcDArTKS4tgHI9e1yrwkSQGTATgp3eXqSIkuBdNeA1iSRQyPEmwAGpjBMlVHoa1KVX9XvA6qsqdLvwfJSHozRAiiO/6UdDX4NBNZNh48Z6/BuwZXF2O4HolX9YT2RQ59Tk4f8Q0r@aUCMNxjiVZFS9S6/Dxjc/U7SK1uUH)
```
import scala.math.{atan2=>A,_};type Q=Double;def h(a:Q,b:Q,c:Q,d:Q,e:Q,f:Q,g:Q,h:Q,i:Q,j:Q,R:Q)={var r=R;var Z=1>1;while(r>0){val Q=A(j-h,i-g);val k=g+r*cos(Q);val l=h+r*sin(Q);val D=A(d-b,c-a);val E=A(f-b,e-a);val F=A(l-b,k-a);val G=A(b-d,a-c);val H=A(f-d,e-c);val I=A(l-d,k-c);Z=Z||D<F&F<E|E<F&F<D&&G<I&I<H|H<I&I<G;r-=1e-3};Z}
```
Ungolfed version. [Try it online!](https://tio.run/##hVLBTuMwFLznK@aEHDYpaWEBVRSpUrttD2hVVlxAaOUkbpKSppXj7gpBv7378hxCWiGt5IznzfiNncRlJHO532erzVoblFXVWUmTdt6kkUUPg1sMPfzeOetwqSKDO5kVeHMA87pRmGOA0Xob5oqUWC2QCtnH3EPIGDHGjIpxwZgwpowZ45LxntClyCof@CM1NFX3TfVI1ULmpWLlb5rlCkLjFoFb91Trcj7WUCzhI6UNaErclvtCboJvlH2KaF2KedvMyUxrs8yKQ3PEuTEFhvRyNMm2O2Z3YV117P5gN7fuy7E7YTckOfYgaYra7rRJjm3ygTtrkmOb3Lj0vWpW8fd3CDHCDR3l5ITgBmOXxXFbG7luRYWYUDGr6IzI1K6ctrWJ@7GPhj9A0AmCLgs7xkenYvW9WNG1EVInZR9DreXr0y@jsyJ5dvt4KDLT/PMNqSYvRCoCD3Z0ebQJjR6d8uwMP7dmszV9GL1VX/ZTQ8/DOXP/4qObxvVhwOetOk7wu9x/YZl/bnOs8v3/IX6vbqLn0sMVsUq55HN1bdjVly@zc3bO3tn/Aw)
```
import scala.math.{atan2 => A, _}
object Main {
type Q = Double
def h(a: Q, b: Q, c: Q, d: Q, e: Q, f: Q, g: Q, h: Q, i: Q, j: Q, R: Q) = {
var r = R
var Z = false
while (r > 0) {
val Q = A(j - h, i - g)
val k = g + r * cos(Q)
val l = h + r * sin(Q)
val D = A(d - b, c - a)
val E = A(f - b, e - a)
val F = A(l - b, k - a)
val G = A(b - d, a - c)
val H = A(f - d, e - c)
val I = A(l - d, k - c)
Z =
Z || ((D < F && F < E) || (E < F && F < D)) && ((G < I && I < H) || (H < I && I < G))
r -= 0.001
}
Z
}
def main(args: Array[String]): Unit = {
println(h(0, 0, 0, 1, 1, 0, 1, 1, 0, 0, 2)) // Output: true
println(h(0, 0, 1, 2, 3, 0, -4, 0, 0, 0, 8)) // Output: false
println(h(0, 0, -1, 3, 4, -1, -3, -4, 3, 4, 5)) // Output: false
println(h(-2, -3, -3, 6, 7, -2, -6, 2, 1, -4, 7)) // Output: true
}
}
```
]
|
[Question]
[
You are given a bunch of weights, and your task is to build a small balanced mobile using those weights.
The input is a list of integer weights in the range 1 through 9, inclusive. There may be duplicates.
The output is an ascii picture of a mobile that, when hung, would balance. Perhaps best shown by example:
**input**
```
3 8 9 7 5
```
**possible output**
```
|
+-----+---------+
| |
+--+-+ +----+------+
| | | |
8 ++--+ 7 5
| |
9 3
```
You must use the ascii characters as shown. The horizontal and vertical segments may be of any length. No part of the mobile may touch (horizontally or vertically) another unconnected part of the mobile. All weights must be hung from a vertical segment of length at least 1, and there must be a vertical segment from which the whole mobile is hung.
The size of a mobile is the total number of `+`,`-`,and `|` characters required to build it. Lower sizes are better.
You may put as many connections on a segment as you would like. For example:
**input**
```
2 3 3 5 3 9
```
**possible output**
```
|
+---+---+-----------+
| | |
+--+-+ 5 9
| | |
2 | 3
|
+++
| |
3 3
```
The winning program is the one that can generate the lowest average of mobile sizes for a test set of inputs. The real test is super-secret to prevent hard-coding, but it will be something like this:
```
8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 7
1 2 3 4 5 6 7 8 9 1 2 3 4 5 6 7 8 9 7 7
3 4 4 4 4 5 5 5 5 6 6 6 6 7 7 7 7
```
[Answer]
Python 2.
I'm cheating a ~~little~~ bit:
* I only construct mobiles with one horizontal. ~~I have a feeling (but I haven't proven it) that the optimal mobile under the given conditions actually always *does* only have one horizontal.~~ **Edit:** Not always true; with `2 2 9 1` Nabb has found a counter-example in the comments below:
```
Size 18: Size 16:
| |
+-++--+-----+ +--++-+
| | | | | | |
2 9 2 1 -+- 9 1
| |
2 2
```
* I just do stupid brute-forcing:
1. The given weights are shuffled randomly.
2. Two weights at a time are placed on the mobile in the best positions such that it stays balanced.
3. If the resulting mobile is better than any that we had before, remember it.
4. Rinse and repeat, until a pre-defined number of seconds is up.
My results for your sample inputs; each was run for 5 seconds (I'm aware that this is ridiculous for the small ones – just going through all possible permutations would be faster). Note that since there's a random element, subsequent runs may find better or worse results.
```
3 8 9 7 5
Tested 107887 mobiles, smallest size 20:
|
+-+-----+-+--+
| | | | |
5 3 7 9 8
2 3 3 5 3 9
Tested 57915 mobiles, smallest size 23:
|
+--+-++--+-+---+
| | | | | |
3 5 9 3 3 2
8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 7
Tested 11992 mobiles, smallest size 50:
|
+-+-+-+--+-+-+-+++-+-+--+-+-+-+-+
| | | | | | | | | | | | | | | |
8 8 8 8 8 8 8 8 8 8 8 7 8 8 8 8
1 2 3 4 5 6 7 8 9 1 2 3 4 5 6 7 8 9 7 7
Tested 11119 mobiles, smallest size 62:
|
+-+-+-+-+-+--+-+-+-+++-+-+-+--+-+-+-+-+-+
| | | | | | | | | | | | | | | | | | | |
2 7 5 6 6 8 3 2 3 7 9 7 8 1 1 7 9 5 4 4
3 4 4 4 4 5 5 5 5 6 6 6 6 7 7 7 7
Tested 16301 mobiles, smallest size 51:
|
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| | | | | | | | | | | | | | | | |
4 6 5 7 7 4 6 5 3 5 6 4 7 6 7 5 4
```
The code (verbose, as this isn't code golf):
```
import time, random
def gcd(a, b):
while b > 0:
a, b = b, a % b
return a
class Mobile(object):
def __init__(self):
self.contents = [None];
self.pivot = 0;
def addWeights(self, w1, w2):
g = gcd(w1, w2)
m1 = w2 / g
m2 = w1 / g
mul = 0
p1 = -1
while True:
if p1 < 0:
mul += 1
p1 = mul * m1
p2 = -mul * m2
else:
p1 *= -1
p2 *= -1
if self.free(p1) and self.free(p2):
self.add(w1, p1)
self.add(w2, p2)
return
def add(self, w, pos):
listindex = self.pivot - pos
if listindex < 0:
self.contents = [w] + (abs(listindex) - 1) * [None] + self.contents
self.pivot += abs(listindex)
elif listindex >= len(self.contents):
self.contents += (listindex - len(self.contents)) * [None] + [w]
else:
self.contents[listindex] = w
def at(self, pos):
listindex = self.pivot - pos
if 0 <= listindex < len(self.contents):
return self.contents[listindex]
return None
def free(self, pos):
return all(self.at(pos + d) is None for d in (-1, 0, 1))
def score(self):
return 1 + 2 * len(self.contents) - self.contents.count(None)
def draw(self):
print self.pivot * " " + "|"
print "".join("+" if c is not None or i == self.pivot else "-" for i, c in enumerate(self.contents))
print "".join("|" if c is not None else " " for c in self.contents)
print "".join(str(c) if c is not None else " " for c in self.contents)
def assertBalance(self):
assert sum((i - self.pivot) * (c or 0) for i, c in enumerate(self.contents)) == 0
weights = map(int, raw_input().split())
best = None
count = 0
# change the 5 to the number of seconds that are acceptable
until = time.time() + 5
while time.time() < until:
count += 1
m = Mobile()
# create a random permutation of the weights
perm = list(weights)
random.shuffle(perm)
if len(perm) % 2:
# uneven number of weights -- place one in the middle
m.add(perm.pop(), 0)
while perm:
m.addWeights(perm.pop(), perm.pop())
m.assertBalance() # just to prove the algorithm is correct :)
s = m.score()
if best is None or s < bestScore:
best = m
bestScore = s
print "Tested %d mobiles, smallest size %d:" % (count, best.score())
best.draw()
```
[Answer]
Well this is an old question, but I just saw it appear in the top questions tab so here's my (optimal) solution:
```
#include <stdio.h>
#include <limits.h>
#include <math.h>
#include <stdlib.h>
int main(int argc, const char *const *argv) {
if(argc < 2) {
fprintf(stderr,
"Balances weights on a hanging mobile\n\n"
"Usage: %s <weight1> [<weight2> [...]]\n",
argv[0]
);
return 1;
}
int total = argc - 1;
int values[total];
int maxval = 0;
for(int n = 0; n < total; ++ n) {
char *check = NULL;
long v = strtol(argv[n+1], &check, 10);
if(v <= 0 || v > INT_MAX || *check != '\0') {
fprintf(stderr,
"Weight #%d (%s) is not an integer within (0 %d]\n",
n + 1, argv[n+1], INT_MAX
);
return 1;
}
values[n] = (int) v;
if(values[n] > maxval) {
maxval = values[n];
}
}
int maxwidth = (int) log10(maxval) + 1;
for(int n = 0; n < total; ++ n) {
int width = (int) log10(values[n]) + 1;
fprintf(stdout,
"%*s\n%*d\n",
(maxwidth + 1) / 2, "|",
(maxwidth + width) / 2, values[n]
);
}
return 0;
}
```
From looking at the rules I'm pretty sure it isn't cheating, although it feels like it is. This will just output all the given numbers in a vertical chain, for a total cost of 2\*number\_of\_inputs (which is the minimum possible because each number must have a bar above it no matter what the layout). Here's an example:
```
./mobile 3 8 9 7 5
```
Produces:
```
|
3
|
8
|
9
|
7
|
5
```
Which is of course in perfect balance.
---
I was originally going to try something more in the spirit of this challenge, but it quickly turned out that it just optimised away to this structure anyway
[Answer]
Here is a solution that brute forces the smallest single row solution.
The code iterates over all permutations and compute the center of mass for each. If the center of mass has integer coordinates, we've found a solution.
After all permutations have been tried, we add a segment to the mix (equivalent to a weight of mass 0) in our current set of weights and retry.
To run the program, do `python balance.py 1 2 2 4`.
```
#!/usr/bin/env python3
import itertools, sys
# taken from http://stackoverflow.com/a/30558049/436792
def unique_permutations(elements):
if len(elements) == 1:
yield (elements[0],)
else:
unique_elements = set(elements)
for first_element in unique_elements:
remaining_elements = list(elements)
remaining_elements.remove(first_element)
for sub_permutation in unique_permutations(remaining_elements):
yield (first_element,) + sub_permutation
def print_solution(cm, values):
print((' ' * cm) + '|')
print('-'.join(['-' if v == 0 else '+' for v in values]))
print(' '.join([' ' if v == 0 else '|' for v in values]))
print(' '.join([' ' if v == 0 else str(v) for v in values]))
input = list(map(int, sys.argv[1:]))
mass = sum(input)
while True:
n = len(input)
permutations = filter(lambda p: p[0] != 0 and p[n-1] != 0, unique_permutations(input))
for p in permutations:
cm = 0
for i in range(n):
cm += p[i] * i;
if (cm % mass == 0):
print_solution(cm//mass, p)
sys.exit(0)
input.append(0)
```
which produces these best solutions :
```
|
+-+-+-+-+
| | | | |
8 3 9 5 7
|
+-+-+-+-+-+
| | | | | |
9 2 3 5 3 3
|
+-+-+-+-+-+-+---+-+-+-+-+-+-+-+-+
| | | | | | | | | | | | | | | |
8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 7
|
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| | | | | | | | | | | | | | | | | | | |
1 1 2 2 3 3 4 4 8 8 5 5 6 6 7 7 7 7 9 9
|
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| | | | | | | | | | | | | | | | |
3 4 4 4 4 5 5 5 5 6 7 6 7 7 7 6 6
```
[Answer]
# Python 3
This does no worse than 1 more than optimal on any of the test cases, I believe, and does so in 5 seconds.
Basically, I use a single bar approach. I randomly order the input, then insert the weights onto the bar one at a time. Each element is either put in the position that minimizes the excess weight on either side, or the second best position from that perspective, using the former 75% of the time and the latter 25% of the time. Then, I check whether the mobile is balanced at the end, and is better than the best mobile found so far. I store the best one, then halt and print it out after 5 seconds of searching.
Results, in 5 second runs:
```
py mobile.py <<< '3 8 7 5 9'
Best mobile found, score 15:
|
+-+-+-+-+
| | | | |
8 7 3 5 9
py mobile.py <<< '2 2 1 9'
Best mobile found, score 13:
|
+-++-+-+
| | | |
1 9 2 2
py mobile.py <<< '2 3 3 5 3 9'
Best mobile found, score 18:
|
+-+-+-+-+-+
| | | | | |
2 3 3 5 9 3
py mobile.py <<< '8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 7'
Best mobile found, score 49:
|
+-+--+-+-+-+-+-+++-+-+-+-+-+-+-+
| | | | | | | | | | | | | | | |
7 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8
\py mobile.py <<< '1 2 3 4 5 6 7 8 9 1 2 3 4 5 6 7 8 9 7 7'
Best mobile found, score 61:
|
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+--+
| | | | | | | | | | | | | | | | | | | |
1 7 7 5 4 3 1 9 6 7 8 2 2 9 3 7 6 5 8 4
py mobile.py <<< '3 4 4 4 4 5 5 5 5 6 6 6 6 7 7 7 7'
Best mobile found, score 51:
|
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| | | | | | | | | | | | | | | | |
4 4 6 7 7 4 5 7 6 6 5 4 6 3 5 5 7
```
Code:
```
import random
import time
class Mobile:
def __init__(self):
self.contents = {}
self.lean = 0
def usable(self, loc):
return not any(loc + k in self.contents for k in (-1,0,1))
def choose_point(self, w):
def goodness(loc):
return abs(self.lean + w * loc)
gl = sorted(list(filter(self.usable,range(min(self.contents.keys() or [0]) - 5,max(self.contents.keys() or [0]) + 6))), key=goodness)
return random.choice((gl[0], gl[0], gl[0], gl[1]))
def add(self, w, loc):
self.contents[loc] = w
self.lean += w*loc
def __repr__(self):
width = range(min(self.contents.keys()), max(self.contents.keys()) + 1)
return '\n'.join((''.join(' ' if loc else '|' for loc in width),
''.join('+' if loc in self.contents or loc == 0 else '-' for loc in width),
''.join('|' if loc in self.contents else ' ' for loc in width),
''.join(str(self.contents.get(loc, ' ')) for loc in width)))
def score(self):
return max(self.contents.keys()) - min(self.contents.keys()) + len(self.contents) + 2
def my_score(self):
return max(self.contents.keys()) - min(self.contents.keys()) + 1
best = 1000000
best_mob = None
in_weights = list(map(int,input().split()))
time.clock()
while time.clock() < 5:
mob = Mobile()
for insert in random.sample(in_weights, len(in_weights)):
mob.add(insert, mob.choose_point(insert))
if not mob.lean:
if mob.score() < best:
best = mob.score()
best_mob = mob
print("Best mobile found, score %d:" % best_mob.score())
print(best_mob)
```
The only one of these solutions which I believe is suboptimal is the longest one, which has this solution, which I found after a 10 minute run:
```
Best mobile found, score 60:
|
+-+-+-+-+-+-+-+-+-+++-+-+-+-+-+-+-+-+-+
| | | | | | | | | | | | | | | | | | | |
3 2 9 4 7 8 1 6 9 8 7 1 6 2 4 5 7 3 5 7
```
]
|
[Question]
[
# The challenge
Given a list of words `["Programming", "Puzzles", "Code", "Golf"]` output the words crossword-style:
```
P r o g r a m m i n g
u
z
z
G l
C o d e
l s
f
```
# The Algorithm
* You have to process the list in the given order.
* The words are printed in alternating orientations, starting **horizontally**.
* The two words intersect at the first letter in the first word which is also present in the second word. If this letter occurs multiple times in the seond word, take the first one.
**Example**:
`["no", "on"]` becomes:
```
o
n o
```
and **not**
```
n o
n
```
# Additional notes
* Adjacent words in the list will have at least one common letter. `["Hi", "there"]` is not a valid input.
* Words will never collide. There will always be enough space to print the a word at the first possible intersection. `["Hello", "there", "end", "hello"]` is not a valid input
* The matching is case-sensitive.
* Words can expand to the left and to the top.
* The letters of the horizontal words have to be separated by one space.
* The input list will contain at least two words.
* All words will match the regex: `[A-Za-z]+`
* You may print as many trailing whitespaces or newlines as you want, as long as the words are correctly chained.
* On the other hand you may not add additional leading whitespaces. The word which floats to the left the most has zero leading spaces, the other lines have so many leading spaces that it all lines up correctly.
* You program has to be able to deal with an arbitrary amount of words
# Rules
* Function or full program allowed.
* [Default rules](https://codegolf.meta.stackexchange.com/questions/2447/default-for-code-golf-input-output-methods) for input/output.
* [Standard loopholes](https://codegolf.meta.stackexchange.com/questions/1061/loopholes-that-are-forbidden-by-default) apply.
* This is [code-golf](/questions/tagged/code-golf "show questions tagged 'code-golf'"), so lowest byte-count wins. Tiebreaker is earlier submission.
# Test cases
Input list on the first line, output starts on the second line.
```
["Stack", "Exchange"]
E
x
c
h
S t a c k
n
g
e
```
```
["This", "site", "graduated", "finally"]
f
i s
n T h i s
g r a d u a t e d
l e
l
y
```
**Happy Coding!**
[Answer]
# JavaScript (ES6) 253
As an anonymous function with an array parameter
```
z=>(z.map((w,i)=>(i&&[...p].some((c,j)=>~(k=w.search(c))?i&1?[y-=k,x+=j]:[y+=j,x-=k]:0),[p=w,x<t?t=x:x,y<u?u=y:y]),t=u=x=y=0).map(([w,x,y],i)=>{x-=t,y-=u;for(c of w)(o[y]=o[y]||[])[x]=c,i&1?y++:x++},o=[]),o.map(r=>[...r].map(x=>x||' ').join` `).join`
`)
```
```
F=z=>(z.map((w,i)=>(i&&[...p].some((c,j)=>~(k=w.search(c))?i&1?[y-=k,x+=j]:[y+=j,x-=k]:0),[p=w,x<t?t=x:x,y<u?u=y:y]),t=u=x=y=0).map(([w,x,y],i)=>{x-=t,y-=u;for(c of w)(o[y]=o[y]||[])[x]=c,i&1?y++:x++},o=[]),o.map(r=>[...r].map(x=>x||' ').join` `).join`
`)
// Less golfed
F=z=>(
z.map( // Step 1, find intersection points and relative position
(w,i)=>(
i && // for each word after thw first, find position respect the previous word
[...p].some((c,j)=> // scan prec word using .some to exit at the first intersection found
~(k=w.search(c)) // search current char of p inside w
?i&1 // calc position, odd is vertical, even is horizontal
?[y-=k, x+=j] // returning an array so to have a truthy value
:[y+=j, x-=k] // returning an array so to have a truthy value
:0 // false = not found, continue the scan
),
[p=w, // set preceding word
x<t?t=x:x, // keep trace of min x
y<u?u=y:y // keep trace of min y
] // meanwhile, return word, x and y to be used in next step
), t=u=x=y=0 // initializations
)
.map(([w,x,y],i)=>{ // Step 2, put char into the output array
x-=t,y-=u; // normalize position respect to min values
for(c of w) // for each char in word, set in the output array at the right place
(o[y]=o[y]||[])[x]=c,
i&1?y++:x++ // increment x or y, again odd is vertical, even is horizontal
}, o=[] // initialization of output array
),
// Step 3, add the missing spaces and newlines
o.map(r=>[...r].map(x=>x||' ').join` `).join`\n`
)
O.textContent=F(["This", "site", "graduated", "finally"])
```
```
<pre id=O></pre>
```
[Answer]
# ANSI C, 385 ~~390~~ Characters
```
int N,a=1,x,y,d=1,u,k,l;int main(int c,char**v){for(;a<c;)N+=strlen(v[a++]);int H=N*2,W=N*4,m=H,n=N,q=m,w=n;char*p,F[W][H],*o;memset(F,32,W*H);for(a=1;a<c;a++){q=(x=m)<q?m:q;w=(y=n)<w?n:w;m=-1;for(p=v[a];*p;p++){F[x][y]=*p;if(m<0&&a<c-1&&(o=strchr(v[a+1],*p))){u=o-v[a+1];m=d?x:x-u*2;n=d?y-u:y;}if(d)x+=2;else y++;}d=!d;}for(l=w;l<H;l++){for(k=q;k<W;)putchar(F[k++][l]);putchar(10);}}
```
Call it like this: `./crossword This site graduated finally`
Ungolfed version:
```
int N,a=1,x,y,d=1,u,k,l;
int main(int c, char **v) {
for(;a<c;)
N+=strlen(v[a++]);
int H = N*2, W = N*4, m = H, n = N, q=m, w=n;
char *p,F[W][H], *o;
memset(F, 32, W*H);
for (a=1; a < c; a++) {
q=(x=m)<q?m:q;
w=(y=n)<w?n:w;
m=-1;
for (p=v[a]; *p; p++) {
F[x][y] = *p;
if (m<0&&a<c-1&&(o = strchr(v[a+1], *p))) {
u = o-v[a+1];
m = d ? x : x-u*2;
n = d ? y-u : y;
}
if (d) x+=2; else y++;
}
d=!d;
}
for (l = w; l < H; l++) {
for (k = q; k < W;)
putchar(F[k++][l]);
putchar(10);
}
}
```
Thank you tucuxi for the tips!
]
|
[Question]
[
In my Economics class, my friends and I like to come up with ways to rearrange the digits in the date (in MM/DD/YY) format to create a valid mathematical equation. For the most part, we are allowed to use addition, subtraction, multiplication, division, parentheses, and exponentiation in addition to concatenation.
Your program should do something similar. The program should import the current date and insert operators to print an expression according to the following rules.
* The digits MUST be used in order. Rearrangement of digits is not allowed.
* The resulting expression must be mathematically accurate.
* Addition, subtraction, multiplication, division, exponentiation, and use of parentheses is allowed. So is concatenation of digits. However, not all operations are necessary. You cannot use a subtraction sign to make a digit negative (like `-1+1+11=10` on November 11, 2010).
* The program must run in 60 seconds on a standard machine.
For example, this challenge was written on November 10, 2015. The program would interpret this as 11/10/15. A sample output would be `(1+1)/10=1/5`.
---
**Bonuses**
You may multiply the number of bytes in your code by 0.9 for each one of the following your program supports.
* The program prints *all* possible expressions that can be formed, separated by newlines. Multiply by an additional 0.95 if the expressions are listed in increasing order of additional symbols.
* The program also works for MM/DD/YYYY dates, printing a possibility with the first two digits of the year in addition to the possibility without. If this bonus is combined with the first bonus, all possibilities with the first two digits of the year must be printed.
* The program also prints an equation for when there are multiple equalities (for example, on November 11, 2011, `1=1=1=1=1=1` would be printed, in addition to possibilities such as `1*1=1=1=1=1`, `1*1*1=1=1=1`, and `1*1*1*1=1=1`. All such cases must be printed for the first bonus to be achieved.
* The program supports conversion to bases between 2 and 16. Note that if the base is not 10, all numbers in the expression must be written in the same base, and `(Base b)` must be written after the expression (with `b` replaced accordingly).
---
This is code golf, so standard rules apply. Shortest code in bytes wins.
[Answer]
# Python 3, ~~424~~ ~~420~~ ~~369~~ 363 bytes
```
import time as t
r=range
x=len
d=list(t.strftime('%m%d%y'))
o=([[x,x+'(',x+')']for x in ['']+"+ - == * / **".split()])
n=[]
for l in o:
n=l+n
o=n
for p in r(x(o)**(x(d)-1)):
e=''
for i in r(x(d)-1):
e+=str(d[i])+o[(p//(x(o)**i))%x(o)]
e+=str(d[-1])
try:
if eval(e)and e.find('=')!=-1:
print(e.replace('==','=').replace('**','^'))
break
except:pass
```
Brute-forces all possible combinations of operations in the numbers and stops when it finds one.
EDIT: Saved 4 bytes thanks to @NoOneIsHere
EDIT 2: Saved 51(!) bytes thanks to @ValueInk
]
|
[Question]
[
# The scene is:
Peter is at the gym with his buddy Brian when Brian suddenly is in dire need of his inhaler. Brian manages to tell Peter the code to his combination lock before he collapses on the floor.
The moment Peter gets to Brian's locker and sees what the indicator is pointing at, Stewie ambushes him and sprays a full can of pepper spray in his face, thus blinding Peter.
Peter must now try to open the lock without looking at it. He starts turning the dial to the right, counting the numbers while he passes them. He then, at the correct number starts turning the dial to the left, still counting, and finally turns it to the right until the lock opens.
---
# The challenge:
Write a function/program that takes two inputs, the combination from Brian, and the indicator position. Output the numbers Peter has to count.
Rules:
* The combination and the indicator position must be separate arguments.
* The input can be either from command prompt or as function arguments.
* The output must be printed to the screen / otherwise displayed (not to file)
* Assume that the starting position is not the same as the first number, and that all three numbers in the combination are unique
* It's the lock shown in the picture below, with possible numbers: 0-39.
# Instructions:
To open the lock below, you need to follow a set of instructions:
1. You must know your code. Assume it's (38, 16, 22) for now.
2. Turn the dial 3 times to the right (passing the starting number three times), then stop when the first number (38) aligns with the indicator
3. Turn the dial 1 full turn to the left, passing
the first number, and stop when the second number (16) lines
up with the indicator.
4. Turn the dial to the right and stop when the
third number (22) lines up with the indicator
5. Pull the lock down
[](https://i.stack.imgur.com/fCGusm.jpg)
Example:
```
Input
38 16 22
33
Output
33 32 31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0 39 38 37 36 35 34 33 32 31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0 39 38 37 36 35 34 33 32 31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0 39 38 37 36 35 34 33 32 31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0 39 38 39 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0 39 38 37 36 35 34 33 32 31 30 29 28 27 26 25 24 23 22
```
Standard code golf rules apply.
Solutions that are posted later can still win if they're shorter than Dennis' answer.
[Answer]
# CJam, ~~52~~ 39 bytes
```
q~[3X0].{@40,m<1$({(+W%}&:T*T@#)T<)}e_p
```
Try it online in the [CJam interpreter](http://cjam.aditsu.net/#code=q~%5B3X0%5D.%7B%4040%2Cm%3C1%24(%7B(%2BW%25%7D%26%3AT*T%40%23)T%3C)%7De_p&input=33%20%5B38%2016%2022%5D).
### How it works
```
q~ e# Read and evaluate all input. This pushes the initial position
e# as an integer and the combination as an array.
[3X0] e# Push [3 1 0]. This encodes the respective numbers of full turns
.{ e# For each number in the combination (N) and the corresponding
e# number of full turns (F):
@ e# Rotate the initial position on top of the stack.
40,m< e# Push [0 ... 39] and rotate it that many units to the left.
e# For position P, this pushes [P P+1 ... 39 0 ... P-2 P-1].
1$( e# Copy F and subtract 1.
{ e# If the result is non-zero:
(+ e# Rotate the array of length 40 one unit to the left.
W% e# Reverse it.
}& e# For position P, this pushes [P P-1 ... 0 39 ... P+2 P+1].
:T* e# Save in T and repeat the array F.
T@ e# Push T. Rotate N on top of the stack.
#) e# Find the index of N in T and add 1 to it.
T< e# Keep that many elements from the beginning of T.
) e# Pop the last element of the result (N).
} e# N is the new initial position.
e_p e# Flatten the resulting array and print it.
```
[Answer]
# Groovy, ~~189~~ 175 bytes
Assumes the indicator is passed as arg0 and the combo is passed as arg1, arg2, and arg3 on the command line...
```
i=(args[0]as int)+1
r={i--;i=i<0?39:i;print"$i "}
l={i=++i%40;print"$i "}
M={j,c->while(i!=j as int){c()}}
120.times{r()}
M(args[1],r)
40.times{l()}
M(args[2],l)
M(args[3],r)
```
[Answer]
# [Perl 5](https://www.perl.org/), 129 + 1 (-a) = 130 bytes
```
sub c{$f=pop;do{say$f;$f+=$_[0];$f=$f==-1?39:$f==40?0:$f}while$f-$_[1]}$p=3;c(2*!$p-1,@F[$_,$p]),$p=$_ for 3,3,3,0,0,1,2;say$F[2]
```
[Try it online!](https://tio.run/##FY3LCsIwFER/JcJd@EgkDytqCHXVnV9QQtHaYKGYS6uIlP668ZYZhrMYZrDpuyyl4X1j9QjBYUR7j@Nw/UKwEDYOqlJ6Ikd2QuXmeJppJ3NJMH0ebddAEFRTfgJ0xtZLvV4ACsXPRQkVB/QrClpiIfbM8FmSpLi281FRap@SOTC1Z1ozY34RX218Dklcsq1UMonrHw "Perl 5 – Try It Online")
**How?**
```
sub c{ # Takes 3 parameters: increment, ending position, starting position
$f=pop; # first place to start counting
do{
say$f; # output current position
$f+=$_[0]; # move position
$f=$f==-1?39:$f==40?0:$f # roll over when passing zero
}while$f-$_[1] # stop when ending positition reached
}
# @F gets defined by the -a command line option
# @F holds the combination followed by the starting position
$p=3; # starting position is in array index 3, this variable will track the array index of
# the current position on the dial
c(2*!$p-1,@F[$_,$p]),$p=$_ # call the movement function (c), setting direction to the left (1) or right (-1) as needed
# based on the array index of the previous position (go left when moving from array index 0)
for 3,3,3,0,0,1,2; # list of the array index of the next position
say$F[2] # output final position
```
[Answer]
## Python 2, 262 bytes
It feels so long. But there is also a lot of turning going on.
```
def f(l,s):
r=lambda a,b,c=1:range(a,b,c)
a=r(39,l[0],-1);b=r(l[0],-1,-1)
c=r(l[1],l[2]-1,-1)if l[2]<l[1]else r(l[1],-1,-1);c.extend(r(39,l[2]-1,-1))
return' '.join(`x`for x in sum([r(s,-1,-1),a,b,a,b,a,b,r(39,l[0],-1),r(l[0],40),r(0,40),r(0,l[1]+1),c],[]))
```
[Try it online!](https://tio.run/##VZDdCoMwDIXvfYrc2bJM/Blj0/kkUrBq3RxapSq4p3et1sEuQvOdJIdDh8/06mW4rpWooSYtjjR2QKUt74qKA8cCyzSIFZdPQTaiDvBUkeiObeYzPAc0KTRbMOxAuQkB0ysh28WmBgMPI4t2FGA39mlSemKZhKyIdT7OtJkS06ykC@B6776RJF/yulewQCNhnDuSKTJaGzQJj/rLiDbhxTet/3tNhpMelwwzRuk6qEZO@iOy6IYQXBHCkCFEEV2/)
I think I can concatenate some parts better in my last line but I am still new to code golf and I don't know how to tackle that list combination in a short way.
Any Ideas on improving this?
[Answer]
# [Haskell](https://www.haskell.org/), ~~135~~ 112 bytes
```
s!t=[s..39]++[0..mod(t-1)40]
s#t=[s,s-1..0]++[39,38..mod(t+1)40]
(a%b)c s=[s#s,s#s,s#s,s#a,a!a,a!b,b#c,[c]]>>=id
```
[Try it online!](https://tio.run/##PcrRCsIgFIDh@57iDBsoOtGdiO3CvcjwQl2QtK1I398mRRf/1f/dXXrc1rWU1GQzJylxtJzPSsrtudDcaXZR9pRInSJ1WkpVP44Ch5/hX0Nd61mAdEBy0H9OuKbmhSdBzMHaaTJxKZuLOxh4veOe4QwUh1ZfGfQ9IJYP "Haskell – Try It Online")
*Saved 23 bytes thanks to Laikoni*
]
|
[Question]
[
### Historical Background
The shield wall is a tactical war formation that dates back to *at least* 2500 BC. It consisted of warriors overlapping their shields with those of their companions to form a 'wall'. The appeal of the tactic comes from the fact that even the most unskilled warrior could fight in a wall as long as they had a shield and a weapon. Because of the proximity of the walls, there was little space to move around, and the battle usually became a shoving match fought with sharp weapons.
## The Challenge
Your task is to create a program or function that, given two arrays/lists/vectors of warriors as input, decides the outcome of the battle. The lists will represent a single-line wall of shields, and they will follow a specific notation:
### Vikings:
The nordic warriors had a fierce drive for battle. During the late 8th through the mid 11th centuries, Danish vikings invaded the kingdoms of Britain looking for riches and farmable land.
For the purpose of this challenge, these are the vikings' warriors:
* The `J`arl: Usually found leading his men from the center of the wall, jarls were the leaders of the viking hordes. Takes 15 damage to die, and deals 2 damage per round.
* The `B`erserker: Although fantasy has greatly twisted the image of the berserkers, these warriors were known to fight in a trance-like fury without any kind of protection other than their shields. Takes 6 damage to die, and deals 3 damage per round.
* The `C`hieftain: Chieftains were rich men who had free men at their service. They'd usually have earned great glory and riches in battle. Takes 10 damage to die, and deals 2 damage per round.
* The Free `M`en: Warriors that served a chieftain. They were sworn to fight for their lords until death. Takes 8 damage to die, and deals 1 damage per round.
* The `S`kald: Skalds, usually translated as bards, were free men who were hired to write poems, stories or songs about the great deeds of the nordic warriors. Takes 8 damage to die, and gives each adjacent warrior 1 bonus damage. Skalds deal **no** damage. Warriors **cannot** gain more than 1 bonus damage this way.
### Saxons:
The Saxons came to settle in Britain from continental Europe following the demise of the Roman Empire in the 5th century. For the purposes of this challenge, there are the saxons' warriors:
* The `E`arl: *Ealdormen*, commonly called Earls, were members of the higher nobility. They usually held great streches of land and had hundreds or even thousands of sworn men. Takes 20 damage to die, and deals 1 damage per round.
* The `K`night: For lack of a better term, the *knights* were minor noblemen who owned some land. In most cases, knights were sworn servants to an Earl. Takes 10 damage to die, and deals 2 damage per round.
* The `W`arrior: Common men, usually minor noblemen without land or peasants who served a knight. When adjacent to a Knight or Earl, warriors have a +1 damage bonus. Takes 8 damage to die, and deals 2 damage per round.
* The `F`yrd: The Fyrd was a militia-like group of free men, usually poor farmers, who'd bring any weapon (or weapon-like farming implement) they had to fight in the wall. Takes 5 damage to die, and deals 1 damage per round.
* The `P`riest: Priests were highly valued in early Saxon culture, being heralds of the words of God. Priests take 15 damage to die, and prevent up to 1 damage each adjacent warrior would be dealt. Priests deal **no** damage. Priests **cannot** prevent more than 1 damage to a warrior.
### The Wall
Walls meet each other at their centers. Each round, each warrior assigns damage to the warrior directly in front of it or, if there's no living warrior in front of it, the diagonally adjacent living warrior with least health remaining. If there is a tie, choose the warrior closer to the edge of the wall.
Example:
```
Vikings
[M,M,M,B,B,C,J,C,B,B,M,M,M]
[F,F,F,W,W,K,E,K,W,W,F,F,F]
Saxons
To make matters easier, let's convert these walls into numbers:
Round 0:
M M M B B C J C B B M M M
[8,8,8,6,6,10,15,10,6,6,8,8,8]
[5,5,5,8,8,10,20,10,8,8,5,5,5]
F F F W W K E K W W F F F
Round 1: Notice that 2 of the Saxons' warriors are adjacent to Knights, so they have a +1 damage bonus.
M M M B B C J C B B M M M
[7,7,7,4,3,8,14,8,3,4,7,7,7]
| | | | | | || | | | | | |
[4,4,4,5,5,8,18,8,5,5,4,4,4]
F F F W W K E K W W F F F
Round 2:
M M M B B C J C B B M M M
[6,6,6,2,0,6,13,6,0,2,6,6,6]
| | | | | | || | | | | | |
[3,3,3,2,2,6,16,6,2,2,3,3,3]
F F F W W K E K W W F F F
Round 3: Remember to collapse the arrays to account for dead warriors. Also, notice that the 2 outermost Fyrd are now attacking the diagonally adjacent viking.
M M M B C J C B M M M
[4,5,4,0,4,12,4,0,4,5,4]
/| | | | | || | | | | |\
[2,2,2,1,0,4,14,4,0,1,2,2,2]
F F F W W K E K W W F F F
Round 4: Notice once again the saxon Warriors next to the Knights dealing 3 damage:
M M M C J C M M M
[2,4,1,2,11,2,1,4,2]
/| | | | || | | | |\
[2,1,1,0,2,12,2,0,1,1,2]
F F F W K E K W F F F
Round 5:
M M M C J C M M M
[1,3,0,0,10,0,0,3,1]
| | | | || | | | |
[1,0,0,0,10,0,0,0,1]
F F F K E K F F F
Round 6:
M M J M M
[1,2,9,2,1]
\| | |/
[0,8,0]
F E F
Rounds 7 and 8:
M M J M M M M J M M
[1,2,8,2,1] [1,2,8,2,1]
\|/ \|/
[4] [0]
E E
Output: Viking victory.
```
### Rules:
* [Default Loopholes](https://codegolf.meta.stackexchange.com/questions/1061/loopholes-that-are-forbidden-by-default) apply.
* You can use [any convenient IO method](https://codegolf.meta.stackexchange.com/questions/2447/default-for-code-golf-input-output-methods).
* This is [code-golf](/questions/tagged/code-golf "show questions tagged 'code-golf'"), so shortest code (in bytes, per language) wins.
* You **may not** assume the lists will have the same length, but they will **always** be alignable at their centers (there will always be an odd number of warriors in each list if the lists are of different sizes).
* You may output any truthy/falsey value. *Please specify in your answer* the equivalents of "Viking/Saxon victory".
* The loser is determined when all the warriors of a wall are dead.
* If you ever end up with walls that are not alignable during the code execution, align them as centrally as possible, leaving one extra warrior on the longer wall to the right side.
E.g.:
```
[M,M,M,J,M,M,M]
[K,E,K,W];
[B,B,B,J]
[K,K,W,W,K,E,K,W,W,K,K]
```
* Feel free to try and test your code with any setup of walls, not just the ones in the test cases.
### Test Cases:
```
V: [M,M,B,C,B,C,J,C,B,C,B,M,M]
S: [F,F,W,K,W,K,E,K,W,K,W,F,F]
O: Viking victory.
------------------------------
V: [M,M,M,M,M,M,M,M,M,M]
S: [W,W,W,W,W,W,W,W,W,W]
O: Saxon victory.
------------------------------
V: [B,C,M,B,C,M,M,C,B,M,C,B,M]
S: [W,F,W,F,E,E,E,F,W,F,W]
O: Viking victory.
------------------------------
V: [B,B,B,J,B,B,B]
S: [W,W,W,W,K,K,K,E,K,K,K,W,W,W,W]
O: Saxon victory.
------------------------------
V: [J]
S: [E]
O: Viking victory.
------------------------------
V: [C,C,C,C,B,B,M,M,M,M,J,J,J,M,M,M,M,B,B,C,C,C,C]
S: [K,K,K,K,K,K,K,K,K,K,W,E,W,K,K,K,K,K,K,K,K,K,K]
O: Saxon victory.
------------------------------
V: [M,M,S,C,B,J,B,C,S,M,M]
S: [F,K,P,W,K,E,K,W,P,K,F]
O: Saxon victory.
------------------------------
V: [S,S,S,...,S]
S: [P,P,P,...,P]
O: UNDEFINED (since both priests and skalds deal no damage, you can output anything here.)
------------------------------
```
There are some historical inaccuracies. Feel free to point them out and I'll do my best to fix them.
[Answer]
# [Python 2](https://docs.python.org/2/), ~~576~~ ~~573~~ ~~565~~ ~~554~~ ~~540~~ 549 bytes
```
O=[(0,0)]
g=lambda D,W,i:D[i-1]*(W[i-1]<1)+D[i]+D[i+1]*(W[i+1]<1)
h=lambda*V:[v for v in zip(*V)if v[1]>0]
def f(v,s):
l,L=len(v),len(s);m=max(l,L);a,b=(L-l)/2,(l-L)/2;V,U=zip(*O+O*a+v+O*a+O+O);S,T=zip(*O+O*b+s+O*b+O+O);z=[0]*(m+2);w=z[:];r=range(1,m+1);U=list(U);T=list(T)
for i in r:w[i]=[0,2,3,2,1,0][V[i]]+(5in V[i-1:i+2:2])*(V[i]<5);z[i]=[0,1,2,2+({1,2}&set(S[i-1:i+2:2])>set()),1,0][S[i]]
for i in r:U[i]-=g(z,V,i);d=g(w,S,i);T[i]-=d-(d>0)*(5in S[i-1:i+2:2])
V=h(V,U);S=h(S,T)
if([],[])<(V,S)!=(v,s):return(f(V,S)if S else'V')if V else'S'
```
[Try it online!](https://tio.run/##bVLfj5pAEH7nr9imSd2VMQU8mwZcHzz1QTSaoPBAeMCISoKcAautTf92Ozuop97lCzOz3/zamWX3Z795y63zeSJDboAhIm0ts3i7WMasBwGkdi9MG2ZU5wHptil0ZCIl9AutE61tLnl13w4PbPVWsANLc3ZKd7zui3TFDqEZdYxIWyYrtuIHKIWtsQxGMktyfhCgVCmcrdzGvznywolhIfmokYnvFvCsMULt@DCXVHOiT@qxfiCJtnA8mL17FnpJkjwnGRp4161uCecoT6EdOYUs4nydcBO2uimcuczScs/nwplV1kxoNEOqZijsI86MRcCCJn4mGFHoIxXpvIV@X@3GTnXLtiJR58rTbmHbS5KJKZbO/6L@961M9ty7j@8oRoiqqKeKPnSeI9OQa34CH1LhLNE8gqfMGXmWDb7sGNhVXeShsMZ8ueG4L1wNGrgepNIVDyMII9FGjye@yOohimT/q8j5ikh8K48lWZnU/Jo6@NXBq52H0IVXGIPHJMPVmS0B3IIfKJtgGqhe4CfKFkqtDy7@QAOYVrGWQbEU1aSoF2hRLFbRtF2R5nv8LcIxKHSp0RA/ZRGHtx6AQoBwoSofEDOIBPvqP9d4AGYH8AEqz3vPq4ar5Jh6XyRlD6hbn1DZwVPfLt12SLJ719El9C/6895DjO8/1XuFCrcdIIaE66naEwHzXfiIAPsGn/DuU39VzaNe1SN7t527ML3b@BTl4CnXgxswYwo3qLheER/vRrqO@UhfMq@O838 "Python 2 – Try It Online")
[Answer]
# [APL (Dyalog Classic)](https://www.dyalog.com/), 128 bytes
```
{t l d b p←(-⌊2÷⍨+/0=⊃⍵)∘⌽¨⍵⋄l+←e+3+/0,0,⍨(0=t)×e←(×≢¨p∩¨h)-⊖d+×≢¨b∩¨h←3,/0,t,0⋄⍵≡a←↑¨(⊂↓l>0)/¨¨↓¨t l d b p:0⋄0∊s←+/l>0:×-/s⋄∇a}
```
[Try it online!](https://tio.run/##jVPBbtNAEL3nK@bmWHGIk6gIVSqHde1DXEuRUskHxMFJnDTIxFFiVFWoF0AlTWsEQpBeOMDJSNyqiBMX50/2R8Ib24QU9cDYb9Y7@@bNrO31JkG1f@YF4bDaC7zZbNTbyHefRqG8eK@XBvAvS0THGCkzha8WIAADcIAOYAI24AIW0FZIxl/o1JtOR@GUorOJD6GjrRDpRPU9jA8x4pke5WjoO/O9nMNCwWjAAod3BKgBNIuxXsTqxXwnxgJ977k3ZAkBiWM5v5HxbZqkiZYmMv5B@S52QFl0xyumfTfKqt1w/GJGpyf@mLz@M6/njyOKQlRp31@F/tvzG/y32mQaRn4vGoXj@0oOy3LxKlI1@Cd1ajw9okMSaGR@8wArr2WcqOUoayu@lRcfZLxSS@ebIX/jiALqU5cmmJSr8nrRWP8Ev1LTD7LMlcpbuf7Fu1jJqzdBBUS/0gRB0zUwy/pBpK6XPuevl/LyW5pM5Px7mpyoVbn43K8UwW4eBK2pITfSdKix5uVXD0G0lSa8DXnxMXisqzV@d3hOk22H@5yhy/liBn6lBtb@elmtzVhn/tY732wGiuMIQxgtQDj8g1qWa7u2CbiWpZSY8Mf4l90aLwkDyY6DTNy8armWaZrw@bIQLaBIs22o2naRW9ZwNFR4U1FBNWBCcJFWq8WDEBzig7I113T/TvLOOgYqGJ28cbud9d22s7Y7MD5bMOU3 "APL (Dyalog Classic) – Try It Online")
There are two functions in the TIO link: `g` is the golfed function above and `f` is an ungolfed function that accepts a pair of strings, converts them to a suitable representation and calls the golfed function.
The input is five matrices: `t` warrior types as ints; `l` life; `d` damage; `b` what warrior types give bonus when adjacent; `p` same for protection. The matrices consist of two rows - Vikings and Saxons. If their warriors are not the same number, the matrices must be 0-padded, though not necessarily centred. The result is `1`/`¯1` for Viking/Saxon victory or `0` for a draw.
```
{
t l d b p←(-⌊2÷⍨+/0=⊃⍵)∘⌽¨⍵ ⍝ centre the matrices
⍝ (-⌊2÷⍨+/0=⊃⍵) is a pair of numbers - by how much we should rotate (⌽) the rows
⍝ +/0=⊃⍵ how many dead? (⊃⍵ is the types, dead warriors have type 0)
⍝ -⌊2÷⍨ negated floor of half
l+←e+3+/0,0,⍨(0=t)×e←(×≢¨p∩¨h)-⊖d+×≢¨b∩¨h←3,/0,t,0 ⍝ compute and apply effective damage
⍝ h←3,/0,t,0 are triples of types - self and the two neighbours
⍝ b∩¨h for each warrior intersect (∩) h with his bonus-giving set b
⍝ ×≢¨ non-empty? 0 or 1
⍝ d+ add to the damage normally inflicted
⍝ ⊖ reverse vertically (harm the enemy, not self)
⍝ (×≢¨p∩¨h) same technique for protections (neighbouring priests)
⍝ e← remember as "e" for "effective damage"; we still need to do the diagonal attacks
⍝ (0=t)× zero out the attacks on living warriors
⍝ 3+/0,0,⍨ sum triples - each warrior suffers the damage intended for his dead neigbours
⍝ e+ add that to the effective damage
⍝ l+← decrease life ("e" is actually negative)
⍵≡a←↑¨(⊂↓l>0)/¨¨↓¨t l d b p:0 ⍝ remove dead; if no data changed, it's a draw
⍝ ↓¨ split each matrix into two row-vectors
⍝ (⊂↓l>0) boolean mask of warrios with any life left, split in two and enclosed
⍝ /¨¨ keep only the survivors
⍝ ↑¨ mix the pairs of rows into matrices again, implicitly padding with 0-s
⍝ a← call that "a" - our new arguments
⍝ ⍵≡a ... :0 is "a" the same as our original arguments? - nothing's changed, it's a draw
0∊s←+/l>0:×-/s ⍝ if one team has no members left, they lost
⍝ l>0 bitmask of survivors
⍝ s←+/l>0 how many in each camp
⍝ 0∊ has any of the two armies been annihilated?
⍝ :×-/s if yes, which one? return sign of the difference: ¯1 or 1, or maybe 0
∇a ⍝ repeat
}
```
]
|
[Question]
[
In the game Yahtzee, players take turns rolling 5 6-sided dice up to three times per turn, possibly saving dice between rolls, and then selecting a category they wish to use for their roll. This continues until there are no more categories (which happens after 13 turns). Then, players' scores are tallied, and the player with the highest score wins.
The categories are as follows ("sum of dice" means adding up the number of pips on the specified dice):
* **Upper Section**
+ **Aces**: sum of the dice showing 1 pip
+ **Twos**: sum of the dice showing 2 pips
+ **Threes**: sum of the dice showing 3 pips
+ **Fours**: sum of the dice showing 4 pips
+ **Fives**: sum of the dice showing 5 pips
+ **Sixes**: sum of the dice showing 6 pips
* **Lower Section**
+ **Three of a Kind**: 3 dice with same value, score is sum of all dice
+ **Four of a Kind**: 4 dice with same value, score is sum of all dice
+ **Full House**: 3 dice with one value and 2 with another, score is 25
+ **Small Straight**: 4 sequential dice, score is 30
+ **Large Straight**: 5 sequential dice, score is 40
+ **Yahtzee**: all 5 dice with same value, score is 50
+ **Chance**: any combination of dice, score is sum of all dice
There are a few rules about the category choices:
* If a player chooses a category that does not match their roll, they receive a score of 0 for that category.
* If a player earns a score of at least 63 in the upper section, they receive 35 bonus points.
* If a player has rolled a Yahtzee but the Yahtzee category is already taken (by another Yahtzee - filling in 0 for a miss doesn't count), they receive a bonus of 100 points. This bonus is awarded for every Yahtzee after the first.
+ Additionally, the player must still choose to fill in a category. They must choose the upper section category corresponding to their roll (e.g. a roll of 5 6's must be placed in the Sixes category). If the corresponding upper section category has already been used, the Yahtzee may be used for a lower section category (in this case, choosing Full House, Small Straight, or Large Straight awards the normal amount of points rather than 0). If all of the lower section categories are taken, then the Yahtzee may be applied to an unused upper section category, with a score of 0.
## The Challenge
In this challenge, the competitors will play 1000 games of Yahtzee. At the end of each game, the submission(s) that scored the highest will receive 1 point. After all of the games are finished, the submission with the most points will win. If there is a tie, additional games will be played with only the tied submissions until the tie is broken.
## Controller
The complete controller code can be found on [this GitHub repository](https://github.com/Mego/Yahtzee). Here are the public interfaces with which players will be interacting:
```
public interface ScorecardInterface {
// returns an array of unused categories
Category[] getFreeCategories();
// returns the current total score
int getScore();
// returns the current Yahtzee bonus
int getYahtzeeBonus();
// returns the current Upper Section bonus
int getUpperBonus();
// returns the current Upper Section total
int getUpperScore();
}
```
```
public interface ControllerInterface {
// returns the player's scorecard (cloned copy, so don't try any funny business)
ScorecardInterface getScoreCard(Player p);
// returns the current scores for all players, in no particular order
// this allows players to compare themselves with the competition,
// without allowing them to know exactly who has what score (besides their own score),
// which (hopefully) eliminates any avenues for collusion or sabotage
int[] getScores();
}
```
```
public enum Category {
ACES,
TWOS,
THREES,
FOURS,
FIVES,
SIXES,
THREE_OF_A_KIND,
FOUR_OF_A_KIND,
FULL_HOUSE,
SMALL_STRAIGHT,
LARGE_STRAIGHT,
YAHTZEE,
CHANCE;
// determines if the category is part of the upper section
public boolean isUpper() {
// implementation
}
// determines if the category is part of the lower section
public boolean isLower() {
// implementation
}
// determines if a given set of dice fits for the category
public boolean matches(int[] dice) {
// implementation
}
// calculates the score of a set of dice for the category
public int getScore(int[] dice) {
// implementation
}
// returns all categories that fit the given dice
public static Category[] getMatchingCategories(int[] dice) {
// implementation
}
}
```
```
public class TurnChoice {
// save the dice with the specified indexes (0-4 inclusive)
public TurnChoice(int[] diceIndexes) {
// implementation
}
// use the current dice for specified category
public TurnChoice(Category categoryChosen) {
// implementation
}
}
public abstract class Player {
protected ControllerInterface game;
public Player(ControllerInterface game) {
this.game = game;
}
public String getName() {
return this.getClass().getSimpleName();
}
// to be implemented by players
// dice is the current roll (an array of 5 integers in 1-6 inclusive)
// stage is the current roll stage in the turn (0-2 inclusive)
public abstract TurnChoice turn(int[] dice, int stage);
}
```
Additionally, there are some utility methods in `Util.java`. They are mainly there to simplify the controller code, but they can be used by players if they desire.
## Rules
* Players are not allowed to interact in any way except using the `Scorecard.getScores` method to see the current scores of all players. This includes colluding with other players or sabotaging other players via manipulating parts of the system that are not part of the public interface.
* If a player makes an illegal move, they will not be allowed to compete in the tournament. Any issues that cause illegal moves must be resolved prior to the running of the tournament.
* If additional submissions are made after the tournament is run, a new tournament will be run with the new submission(s), and the winning submission will be updated accordingly. I make no guarantee of promptness in running the new tournament, however.
* Submissions may not exploit any bugs in the controller code that cause it to deviate from the actual game rules. Point out bugs to me (in a comment and/or in a GitHub issue), and I'll fix them.
* Use of Java's reflection tools is forbidden.
* Any language which runs on the JVM, or can be compiled to Java or JVM bytecode (such as Scala or Jython) can be used, so long as you supply any additional code needed to interface it with Java.
## Final Comments
If there is any utility method you would like me to add to the controller, simply ask in the comments and/or make an issue on GitHub, and I'll add it, assuming it doesn't allow for rule breaking or expose information to which players are not privy. If you want to write it yourself and create a pull request on GitHub, even better!
[Answer]
## DummyPlayer
```
package mego.yahtzee;
import java.util.Random;
import java.util.stream.IntStream;
import java.util.stream.Stream;
public class DummyPlayer extends Player {
public DummyPlayer(ControllerInterface game) {
super(game);
}
@Override
public TurnChoice turn(int[] dice, int stage) {
Category[] choices = game.getScoreCard(this).getFreeCategories();
Category choice = choices[new Random().nextInt(choices.length)];
if(IntStream.of(dice).allMatch(die -> die == dice[0])) {
if(Stream.of(choices).filter(c -> c == Category.YAHTZEE).count() > 0) {
choice = Category.YAHTZEE;
} else if(Stream.of(choices).filter(c -> c == Util.intToUpperCategory(dice[0])).count() > 0) {
choice = Util.intToUpperCategory(dice[0]);
} else {
choices = Stream.of(game.getScoreCard(this).getFreeCategories()).filter(c -> c.isLower()).toArray(Category[]::new);
if(choices.length > 0) {
choice = choices[new Random().nextInt(choices.length)];
} else {
choices = game.getScoreCard(this).getFreeCategories();
choice = choices[new Random().nextInt(choices.length)];
}
}
}
return new TurnChoice(choice);
}
}
```
This player is here to serve as a basic outline for how to use the tools present in the Yahtzee controller. It chooses Yahtzee whenever possible, and makes random choices otherwise, while complying with the strict joker rules.
[Answer]
# Aces and Eights
Well, this took a lot longer than I would have liked thanks to how busy I've been lately.
```
package mego.yahtzee;
import java.util.Arrays;
import java.util.Comparator;
import java.util.List;
import static mego.yahtzee.Category.*;
public class AcesAndEights extends Player {
private Category[] freeCategories, matchingCategories, usableCategories;
public AcesAndEights(ControllerInterface game) {
super(game);
}
@Override
public TurnChoice turn(int[] dice, int stage) {
List<Integer> holdIndices = new java.util.ArrayList<>();
freeCategories = game.getScoreCard(this).getFreeCategories();
matchingCategories = Category.getMatchingCategories(dice);
Arrays.sort(matchingCategories);
usableCategories = Arrays.stream(freeCategories)
.filter(this::isMatchingCategory)
.toArray(Category[]::new);
Arrays.sort(usableCategories);
if (isMatchingCategory(YAHTZEE))
return doYahtzeeProcess(dice);
if (isUsableCategory(FULL_HOUSE))
return new TurnChoice(FULL_HOUSE);
if (stage == 0 || stage == 1) {
if (isMatchingCategory(THREE_OF_A_KIND)) {
int num = 0;
for (int i : dice) {
if (Util.count(Util.boxIntArray(dice), i) >= 3) {
num = i;
break;
}
}
for (int k = 0; k < 5; k++) {
if (dice[k] == num)
holdIndices.add(k);
}
return new TurnChoice(toIntArray(holdIndices.toArray(new Integer[0])));
}
if (isFreeCategory(LARGE_STRAIGHT) || isFreeCategory(SMALL_STRAIGHT)) {
if (isUsableCategory(LARGE_STRAIGHT))
return new TurnChoice(LARGE_STRAIGHT);
if (isMatchingCategory(SMALL_STRAIGHT)) {
if (!isFreeCategory(LARGE_STRAIGHT))
return new TurnChoice(SMALL_STRAIGHT);
int[] arr = Arrays.stream(Arrays.copyOf(dice, 5))
.distinct()
.sorted()
.toArray();
List<Integer> l = Arrays.asList(Util.boxIntArray(dice));
if (Arrays.binarySearch(arr, 1) >= 0 && Arrays.binarySearch(arr, 2) >= 0) {
holdIndices.add(l.indexOf(1));
holdIndices.add(l.indexOf(2));
holdIndices.add(l.indexOf(3));
holdIndices.add(l.indexOf(4));
}
else if (Arrays.binarySearch(arr, 2) >= 0 && Arrays.binarySearch(arr, 3) >= 0) {
holdIndices.add(l.indexOf(2));
holdIndices.add(l.indexOf(3));
holdIndices.add(l.indexOf(4));
holdIndices.add(l.indexOf(5));
}
else {
holdIndices.add(l.indexOf(3));
holdIndices.add(l.indexOf(4));
holdIndices.add(l.indexOf(5));
holdIndices.add(l.indexOf(6));
}
return new TurnChoice(toIntArray(holdIndices.toArray(new Integer[0])));
}
}
if (isFreeCategory(FULL_HOUSE)) {
int o = 0, t = o;
for (int k = 1; k <= 6; k++) {
if (Util.count(Util.boxIntArray(dice), k) == 2) {
if (o < 1)
o = k;
else
t = k;
}
}
if (o > 0 && t > 0) {
for (int k = 0; k < 5; k++) {
if (dice[k] == o || dice[k] == t)
holdIndices.add(k);
}
return new TurnChoice(toIntArray(holdIndices.toArray(new Integer[0])));
}
}
}
else {
Arrays.sort(freeCategories, Comparator.comparingInt((Category c) -> c.getScore(dice))
.thenComparingInt(this::getPriority)
.reversed());
return new TurnChoice(freeCategories[0]);
}
return new TurnChoice(new int[0]);
}
private TurnChoice doYahtzeeProcess(int[] dice) {
if (isUsableCategory(YAHTZEE))
return new TurnChoice(YAHTZEE);
Category c = Util.intToUpperCategory(dice[0]);
if (isUsableCategory(c))
return new TurnChoice(c);
Category[] arr = Arrays.stream(freeCategories)
.filter(x -> x.isLower())
.sorted(Comparator.comparing(this::getPriority)
.reversed())
.toArray(Category[]::new);
if (arr.length > 0)
return new TurnChoice(arr[0]);
Arrays.sort(freeCategories, Comparator.comparingInt(this::getPriority));
return new TurnChoice(freeCategories[0]);
}
private boolean isFreeCategory(Category c) {
return Arrays.binarySearch(freeCategories, c) >= 0;
}
private boolean isMatchingCategory(Category c) {
return Arrays.binarySearch(matchingCategories, c) >= 0;
}
private boolean isUsableCategory(Category c) {
return Arrays.binarySearch(usableCategories, c) >= 0;
}
private int getPriority(Category c) {
switch (c) {
case YAHTZEE: return -3; // 50 points
case LARGE_STRAIGHT: return -1; // 40 points
case SMALL_STRAIGHT: return -2; // 30 points
case FULL_HOUSE: return 10; // 25 points
case FOUR_OF_A_KIND: return 9; // sum
case THREE_OF_A_KIND: return 8; // sum
case SIXES: return 7;
case FIVES: return 6;
case FOURS: return 5;
case THREES: return 4;
case TWOS: return 3;
case ACES: return 2;
case CHANCE: return 1; // sum
}
throw new RuntimeException();
}
private int[] toIntArray(Integer[] arr) {
int[] a = new int[arr.length];
for (int k = 0; k < a.length; k++)
a[k] = arr[k];
return a;
}
}
```
The bot looks for patterns in the dice that could match certain categories and holds the necessary ones. It immediately chooses a high-priority matching category if one's found; otherwise it chooses a category that yields the highest score. Scores nearly 200 points per game on average.
]
|
[Question]
[
**Introduction**
My niece wants to make a race car track. She has wooden parts that fit together to form the track. Each part is square shaped and contains a different shape. I'll use the pipe drawing characters to illustrate:
* `│`: the road that goes vertically
* `─`: the road that goes horizontally
* `┌` `┐` `└` `┘`: the roads that turn in a direction
* `┼`: A bridge with an underpass
Curiously, there are no t-junction pieces.
Here's an example of a possible race car track:
```
┌─┐
│ │┌─┐
│ └┼─┘
└──┘
```
The rules for a valid race car track are as follows:
* There can't be any roads that go to nowhere.
* It must form a loop (and all the pieces must be part of the same loop).
* At the bridges / underpasses, you can't turn (so you have to go straight through them).
Unfortunately, the race car track pieces my niece and I have are limited. But we definitely want to use all of them in the track. Write a **program** that, given a list of what pieces are in our inventory, outputs a race car track that uses all of those pieces.
**Input Description**
We'd like the input to come in via STDIN, command line arguments, file reading, or a user input function (such as `raw_input` or `prompt`). The input is comma separated positive integers in the form
```
│,─,┌,┐,└,┘,┼
```
where each of those represent the amount of that particular piece we have. So for instance the input:
```
1,1,1,1,1,1,1
```
would mean that we had one of each piece.
**Output Description**
Output a race car track using the pipe drawing characters listed above. The race car track should use exactly the number of each piece specified in the input -- no more, and no less. There will be at least one valid race car track for every input.
**Example Inputs and Outputs**
Input: `3,5,2,2,2,2,1`
A possible output:
```
┌─┐
│ │┌─┐
│ └┼─┘
└──┘
```
Input: `0,0,1,4,4,1,3`
A possible output:
```
┌┐
└┼┐
└┼┐
└┼┐
└┘
```
[Answer]
# Ruby 664 ~~671 677 687 701~~ (678 bytes)
```
_={│:[1,4],─:[2,8],┌:[4,8],┐:[4,2],└:[1,8],┘:[1,2],┼:[1,4,2,8]}
s=->a,l,b{l==[]&&a==[]?b:(l.product(l).any?{|q,r|q,r=q[0],r[0];(q[0]-r[0])**2+(q[1]-r[1])**2>a.size**2}?!0:(w,f=l.pop
w&&v=!a.size.times{|i|y=_[x=a[i]]
f&&y&[f]==[]||(k=l.select{|p,d|w!=p||y&[d]==[]}
(y-[f]).map{|d|z=[w[0]+(d<2?-1:(d&4)/4),w[1]+(d==2?-1:d>7?1:0)]
g=d<3?d*4:d/4
b[z]?_[b[z]]&[g]!=[]||v=0:k<<[z,g]}
v||r=s[a[0...i]+a[i+1..-1],k,b.merge({w=>x})]
return r if r)}))}
c=eval"[#{gets}]"
r=s[6.downto(0).map{|i|[_.keys[i]]*c[i]}.flatten,[[[0,0],nil]],{}]
h=j=k=l=0
r.map{|w,_|y,x=w
h>x&&h=x
j>y&&j=y
k<x&&k=x
l<y&&l=y}
s=(j..l).map{|_|' '*(k-h+1)}
r.map{|w,p|y,x=w
s[y-j][x-h]=p.to_s}
puts s
```
This is not the shortest program I could come up with, but I sacrificed some brevity for execution speed.
You can experiment with the program [here](http://ideone.com/L4TSYm). Note that ideone has an execution time limit, so for inputs consisting of more than about 12 pieces, the program will probably time out.
There's also a [test suite](http://ideone.com/6hCfFF) for the program. Note that the last two tests are disabled on ideone, due to the time limit mentioned above. To enable these tests, delete the `x_` prefix from their names.
The program finds a solution using Depth-first search; it places pieces one at a time and keeps tracks of loose ends. The search stops when there are no more loose (unconnected) ends and all pieces have been placed.
This is the ungolfed program:
```
N, W, S, E = 1, 2, 4, 8
# given a direction, find the opposite
def opposite (dir)
dir < 3 ? dir * 4 : dir / 4
end
# given a set of coordinates and a direction,
# find the neighbor cell in that direction
def goto(from, dir)
y, x = from
dx = case dir
when W then -1
when E then 1
else 0
end
dy = case dir
when N then -1
when S then 1
else 0
end
[y+dy, x+dx]
end
CONNECTIONS = {
?│ => [N, S],
?─ => [W, E],
?┌ => [S, E],
?┐ => [S, W],
?└ => [N, E],
?┘ => [N, W],
?┼ => [N, S, W, E],
}
BuildTrack =-> {
piece_types = CONNECTIONS.keys
piece_counts = gets.split(?,).map &:to_i
pieces = 6.downto(0).map{|i|piece_types[i]*piece_counts[i]}.join.chars
def solve (available_pieces, loose_ends=[[[0,0],nil]], board={})
return board if loose_ends==[] and available_pieces==[]
# optimization to avoid pursuing expensive paths
# which cannot yield a result.
# This prunes about 90% of the search space
c = loose_ends.map{ |c, _| c }
not_enough_pieces = c.product(c).any? { |q, r|
((q[0]-r[0])**2+(q[1]-r[1])**2) > available_pieces.size**2
}
return if not_enough_pieces
position, connect_from = loose_ends.pop
return unless position
available_pieces.size.times do |i|
piece = available_pieces[i]
remaining_pieces = available_pieces[0...i] + available_pieces[i+1..-1]
piece_not_connected_ok = connect_from && CONNECTIONS[piece] & [connect_from] == []
next if piece_not_connected_ok
new_loose_ends = loose_ends.select { |pos, dir|
# remove loose ends that may have been
# fixed, now that we placed this piece
position != pos || CONNECTIONS[piece] & [dir] == []
}
invalid_placement = false
(CONNECTIONS[piece]-[connect_from]).map do |dir|
new_pos = goto(position, dir)
new_dir = opposite(dir)
if board[new_pos]
if CONNECTIONS[board[new_pos]] & [new_dir] != []
# do nothing; already connected
else
# going towards an existing piece
# which has no suitable connection
invalid_placement = true
end
else
new_loose_ends << [new_pos, new_dir]
end
end
next if invalid_placement
new_board = board.merge({position => piece})
result = solve(remaining_pieces, new_loose_ends, new_board)
return result if result
end
nil
end
def print_board board
min_x = min_y = max_x = max_y = 0
board.each do |position, _|
y, x = position
min_x = [min_x, x].min
min_y = [min_y, y].min
max_x = [max_x, x].max
max_y = [max_y, y].max
end
str = (min_y..max_y).map{|_|
' ' * (max_x - min_x + 1)
}
board.each do |position, piece|
y, x = position
str[y-min_y][x-min_x] = piece
end
puts str
end
print_board(solve(pieces))
}
```
]
|
[Question]
[
In this challenge, you will calculate what your reputation would be, if the reputation cap didn't exist on PPCG.
Everyone can access the rawdata for reputation changes on the adress: [codegolf.stackexchange.com/reputation](https://codegolf.stackexchange.com/reputation).
The raw data follows a setup like this (these are the first few lines of my version of the page.
```
total votes: 2955
-- bonuses (100)
2 37663 (10)
-- 2014-09-11 rep +110 = 111
2 41751 (10)
-- 2014-11-23 rep +10 = 121
2 41751 (10)
2 41751 (10)
-- 2014-11-24 rep +20 = 141
```
The first line is irrelevant for this challenge (it shows the total number of votes you have received on all your answers and questions).
The second line shows the "Association bonus". If you don't have the bonus then that line will not be there at all.
After these two (or one, if no bonus) lines, you'll have a list of reputation changes per question, along with a summary of all the rep gained/lost on each day. You'll also get a list of the total reputation you have at the end of that day. Only days where your reputation changed are shown in this list.
There are identifiers in the beginning of each line (except the daily summary lines). These represent the following potential reputation change reasons:
```
1 : Accept (+2 if you accept, +15 if your answer is accepted)
2 : Upvote (+5 for question, +10 for answer)
3 : Downvote (-1 if you downvote answer, -2 if you get downvoted)
4 : Offensive (-100)
8 : Give bounty
9 : Receive bounty
12: Spam (-100)
16: Approved edit (+2)
```
The missing numbers (`5,6,7,10,11,13,14,15` don't affect reputation).
---
## Your challenge is to calculate the reputation you would have, if it weren't for the reputation cap.
---
**How you'll do this:**
Save the content of `codegolf.stackexchange.com/reputation` as plain text locally, or some other place of your choosing (this is because you need to be logged in to access the information).
You may retrieve the data from the website directly if you prefer, although I assume that will be a lot longer.
Sum up all the positive and negative reputation changes. Votes that doesn't result in a reputation change (due to the rep cap) are shown like this
(notice the square brackets, instead of regular parentheses):
```
2 106125 [0]
2 106125 [0]
3 106125 [-2]
2 106088 [2]
2 106125 [0]
2 106088 [0]
```
*You must include the rep you would have received if it wasn't for the cap.*
Post number `106125` is a [question](https://codegolf.stackexchange.com/q/106125/31516), while `106088` is [an answer](https://codegolf.stackexchange.com/a/106088/31516).
As you can see, there's no way to tell the difference between the two using only the data given in the table. You must therefore access the website (`codegolf.stackexchange.com`) to check whether a post is a question or answer. You may also use the API for this.
---
**Rules:**
* Everyone must be able to run your script so:
+ You must include all the different reputation change types, even if you haven't encountered it yourself.
+ The code must work even if you haven't received the Association bonus (the line won't be there if you haven't)
+ You may use non-free languages (Mathematica, MATLAB etc.), as long as others with a license can run the code.
+ You do not have to provide the raw-data, since everyone can test your code on their own version of the page (it will be interesting if you share the results though, but that's optional).
* You may use the API or access the website directly. url-shorteners are not allowed.
* If there are other ways to find the rep you would have without the rep cap then you can't use it. You have to use the data from the mentioned page.
Note that posts that are answers get a different extension to the url:
```
https://codegolf.stackexchange.com/questions/106088 // Answer: Notice the end of the url
https://codegolf.stackexchange.com/questions/106079/detect-ms-windows/106088#106088
https://codegolf.stackexchange.com/questions/106079/ // Question: Notice the end of the url
https://codegolf.stackexchange.com/questions/106079/detect-ms-windows
```
**Output:**
The output should be:
```
Rep w cap: 15440
Rep w/o cap: 16202
```
The format is optional, `[15440,16202]` is accepted. `Rep w cap` can be taken directly from the line: `** total rep 15440 :)` near the bottom of the page.
---
This is [code-golf](/questions/tagged/code-golf "show questions tagged 'code-golf'") so the shortest code in byte wins.
[Answer]
# Perl 5 (+ `curl`), 209 +1 (`-n` flag) = 210 bytes
```
if(/([0-9]+)\s*([0-9]+) \[([0-9]*)/){$_=`curl https://codegolf.stackexchange.com/a/$2`;@p=(2,5,-1);$p[15]=2;@s=(13,5,-1);$x=$1;$r+=($p[--$x]//-100)-$3;$r+=$s[$x]if/#/;};$t=$1 if/([0-9]+) :/;END{say$t,$",$r+$t}
```
Abuses the fact that the url for an answer has a `#` in it. Can add a `-s` flag after `curl` if you don't like stderr being flooded with progress bars. I would appreciate someone with a more varied reputation page testing it- I can't be sure I didn't miss anything.
Mine is 421 and would be 451, by the way.
]
|
[Question]
[
# Background
A few months ago, the adventure of your life was just about to start. Now, in this precise moment (yeah, now), after months of suffering and hard work, you and a group of friends are standing on the top of the world. Yes, you are right, you are on the summit of [Sagarmāthā](https://en.wikipedia.org/wiki/Mount_Everest).
However, things aren't going as well as you would like to. A dense fog has surrounded you and an incredibly bad-looking storm is coming as fast as it can. You didn't fix any rope on the way up, and your footprints have been covered in snow. If you want to survive (at least for today), you need to get out of there as fast as you can, but you MUST first find a way to know which face of the mountain is the one you should descend.
Luckily, you brought with you your [sat phone](https://en.wikipedia.org/wiki/Satellite_phone) which you modified before the trip so you are able to program and execute programs in it.
# Challenge
You have been able to download to your phone the map of the mountain in an ASCII-old-fashioned-unreadable-on-the-top-of-the-world way. Your task is to decide which face of the mountain presents the easiest descent so you can increase your chances of surviving. In order to do so, you have the brilliant idea to code a program on your phone that will tell which is the easiest way down. (Disclaimer: These activities have been done by professionals. No programmer was hurt during this narration. Please, do not try this at home.)
Maps are only made of the characters `/` and `\` (plus spaces and newlines).
In any map, the summit of the mountain is always represented by
```
/\
\/
```
and from each of the sides (`1,2,3` or `4`) of the summit you will always find a "possible" way down the mountain.
```
1 /\ 2
3 \/ 4
```
The routes are always presented in the next way:
```
\
Steep-> / /
/ / <-Flat
/ \
Flat-> \ \
/ \ <-Steep
/\
\/
```
where each new character is either one place to the left/right of its predecessor. The meaning of each character is:
* If the slash/backlash is parallel to its summit side -> counts as a 'steep' part.
* If the slash/backslash is perpendicular to its summit side -> counts as a 'flat' part.
\*For further reference see graphic above.
**Note**: The sides can have different lengths and the characters which constitute the summit also count as part of their side. In case of a draw, you can choose any of them.
[Standard loopholes](https://codegolf.meta.stackexchange.com/questions/1061/loopholes-that-are-forbidden-by-default) are disallowed.
# Input
A string representing the map of the mountain or a plain text file containing the same info.
Either
```
C:\....\file.txt
```
or
```
\
/ /
/ /
/ \
\ \
/ \
/\
\/
\ /
\ \
\ \
\ \
/ /
```
as a string are valid inputs.
# Output
As output, you should produce either a file in plain text or by stdout an **ASCII profile representation of the side with the smallest average steepness** using `_` for flat parts and `/` for steep parts **along with the average steepness** of the side `(number of "/")/(total chars)`.
Output example for map above:
```
/
___/
/
AS:0.5
```
The format is not important as long as you have the profile and average steepness.
# Scoring
What? Do you want a better reward than saving your and your friend's lives and being the first programmer who has ever programmed on the top of the world? Okay... this is code golf, so shortest program in bytes wins.
# Test cases
Input:
```
\
/ /
/ /
/ \
\ \
/ \
/\
\/
\ /
\ \
\ \
\ \
/ /
```
Output:
```
/
___/
/
AS=0.5
```
Input:
```
/
\ /
/ /
\ /
\ /
/ /
/\
\/
\ /
\ \
\ \
\ \
/ /
/
/
```
Output:
```
______/
AS=0.143 (1/7)
```
Input:
```
/ \
\ \
/ /
/ \
/\
\/
\ /
\ /
\ /
/ \
```
Output:
```
/
/
/
_/
AS=0.8
```
[Answer]
# JavaScript (ES6), 303
Test running the snippet blow in an EcmaScript compliant browser - surely Firefox, probably Chrome. Using template strings, arrow functions.
```
// Golfed, no indentenation, all newlines are significant
f=s=>(s=`
${s}
`.split`
`,s.map((r,i)=>~(q=r.search(/\/\\/))&&(y=i,x=q),x=y=0),z=[],[0,2,0,2].map((d,i)=>{t=x+i%2,u=y+i/2|0,b=s[u][t];for(p=[''],n=l=0;(c=s[u][t])>' ';++l,t+=d-1,u+=(i&2)-1)c==b?p.push(p[n++].replace(/./g,' ',w='/')):w='_',p=p.map((r,i)=>(i<n?' ':w)+r);z=z[0]<(p[0]=n/l)?z:p}),z.join`
`)
// Less golfed
U=s=>(
s=(`\n${s}\n`).split`\n`,
x = y = 0,
s.map((r,i)=>~(q=r.search(/\/\\/))&&(y=i,x=q)),
z=[],
[0,2,0,2].map((d,i) => {
t = x+i%2,
u = y+i/2|0,
b = s[u][t];
for(p=[''], n=l=0; (c=s[u][t])>' '; ++l, t += d-1, u +=(i&2)-1)
c == b
? p.push(p[n++].replace(/./g,' ',w='/'))
: w='_',
p = p.map((r,i) => (i<n?' ':w)+r);
z = z[0]<(p[0]=n/l)?z:p
}),
z.join`\n`
)
// TEST
// redirect console into the snippet body
console.log=x=>O.innerHTML+=x+'\n'
maps=[ // as javascript string literals, each baskslasch has to be repeated
` \\
/ /
/ /
/ \\
\\ \\
/ \\
/\\
\\/
\\ /
\\ \\
\\ \\
\\ \\
/ /`,
` /
\\ /
/ /
\\ /
\\ /
/ /
/\\
\\/
\\ /
\\ \\
\\ \\
\\ \\
/ /
/
/ `,
` / \\
\\ \\
/ /
/ \\
/\\
\\/
\\ /
\\ /
\\ /
/ \\`]
maps.forEach(m=>console.log(m + '\n'+ f(m) +'\n'))
```
```
<pre id=O></pre>
```
]
|
[Question]
[
Your job is to simulate a mathematically perfect game of 2048. The idea is to find the theoretical upper limit of how far a 2048 game can go, and find how to get there.
To get an idea of what this looks like, play with [this 2x2 clone](http://ehzhang.github.io/4/) and try to score 68 points. If you do, you will end up with a 2, 4, 8, and 16 tile. It's impossible to advance past that point.
Your task is made easier because you can choose where tiles spawn and what their values are, just like [this clone](http://akhilanb.github.io/Human2048/).
You must write a program or function that accepts a 2048 board as input, and outputs the board with the spawned tile and the board after collapsing tiles. For example:
```
Input:
-------
0 0 0 0
0 0 0 0
0 0 0 0
0 0 8 8
Output:
-------
0 0 0 0
0 0 0 0
0 0 0 0
0 4 8 8
0 0 0 0
0 0 0 0
0 0 0 0
0 0 4 16
```
Your program will be repeatedly fed its own output to simulate an entire game of 2048. The first input of the program will be an empty board. You must spawn one tile on it, unlike the original game's two tiles. At the last step of the game, you will be unable to move, so your two output boards can be identical.
You must of course only output legal moves. Only a 2 or 4 can be spawned, you must move or collapse at least one tile on a move, etc.
I've purposely made the input and output requirements vague. You are free to choose the format of the input and output. You can use matrices, arrays, strings, or whatever you want. As long as you can simulate a 2048 game with them, your inputs and outputs are fine.
The winner will be the one who ends the game with the highest sum of tiles on the board, then by the lowest number of bytes in the source code. The scoring from the original game will not be taken into account. (Hint: use 4's)
[Answer]
## Ruby, Into the Corner, Score: 3340
Here is a very simple strategy to kick this off. I do have an idea for a (near) perfect score, but I'm having trouble formalising it, so here is something simple to get things going.
```
def slide board, dir
case dir
when 'U'
i0 = 0
i_stride = 1
i_dist = 4
when 'D'
i0 = 15
i_stride = -1
i_dist = -4
when 'L'
i0 = 0
i_stride = 4
i_dist = 1
when 'R'
i0 = 15
i_stride = -4
i_dist = -1
end
4.times do |x|
column = []
top_merged = false
4.times do |y|
tile = board[i0 + x*i_stride + y*i_dist]
next if tile == 0
if top_merged || tile != column.last
column.push tile
top_merged = false
else
column[-1] *= 2
top_merged = true
end
end
4.times do |y|
board[i0 + x*i_stride + y*i_dist] = column[y] || 0
end
end
board
end
def advance board
if board.reduce(:*) > 0
return board, board
end
16.times do |i|
if board[15-i] == 0
board[15-i] = 4
break
end
end
spawned = board.clone
# Attention, dirty dirty hand-tweaked edge cases to avoid
# the inevitable for a bit longer. NSFS!
if board[11] == 8 && (board[12..15] == [32, 16, 4, 4] ||
board[12..15] == [16, 16, 4, 4] && board[8..10] == [256,64,32]) ||
board[11] == 16 && (board[12..15] == [32, 8, 4, 4] ||
board[12..15] == [4, 32, 8, 8] ||
board[12..15] == [4, 32, 0, 4])
dir = 'R'
elsif board[11] == 16 && board[12..15] == [4, 4, 32, 4] ||
board[11] == 8 && board[12..15] == [0, 4, 32, 8]
dir = 'U'
else
dir = (board.reduce(:+)/4).even? ? 'U' : 'L'
end
board = slide(board, dir)
if board == spawned
dir = dir == 'U' ? 'L' : 'U'
board = slide(board, dir)
end
return spawned, board
end
```
The `advance` function is the one your asking for. It takes a board as 1d array and returns the board after the tile has been spawned and after the move has been made.
You can test it with this snippet
```
board = [0]*16
loop do
spawned, board = advance(board)
board.each_slice(4) {|row| puts row*' '}
puts
break if board[15] > 0
end
puts "Score: #{board.reduce :+}"
```
The strategy is very simple, and is the one I actually used to skip to the 128 when I was playing 2048 myself: just alternate between **up** and **left**. To make this work for as long as possible, new `4`s are spawned in the bottom right corner.
**EDIT:** I've added a hard coded switch to go right a few times at specific steps just before the end, which actually lets me reach 1024. This is getting somewhat out of hand though, so I'll stop with this for now and think about a generally better approach tomorrow. (Honestly, the fact that I can increase my score by a factor of 4 by adding hand-tweaked hacks only tells me that my strategy is crap.)
This is the board you end up with
```
1024 512 256 128
512 256 128 16
256 128 64 8
8 32 8 4
```
]
|
[Question]
[
Doorknobs are great and all, but when you open a door, it always dents the walls around it. I need you to take input of ASCII art of a room, like this:
```
+---------+--X --X --+-----+
| \ \ |\ | \ |
| \ \ | \ | \|
| X | \ | X
| / | | \ X
| / | \ /
| / | \ / |
+---X --+-------X------+-----+
```
And output the room with doorstops, like this:
```
+---------+--X --X --+-----+
| \ . \ |\ | \.|
| \ \ | \ .| \|
| X | \ | X
| / | |. \ X
| / .| \ /
|. / | .\ / |
+---X --+-------X------+-----+
```
Specification:
* The ASCII room (input) will consist of `+`, `-`, and `|`. These characters are purely cosmetic; they could all be `+`s but that would look horrible. It will also contain hinges (`X`) and doors (`/` or `\`).
* Doors are made up of `/` or `\`. Starting from the "hinge" character, which is `X`, they will go directly diagonally (change of 1 in `x` and 1 in `y`) for 2 or more units (characters).
* To find where to put the doorstop for a door (there is always only one doorstop per door), find the doorway for the door. The doorway will always start at one hinge, and go the same amount of spaces as the door's length up, down, left, or right from there. The next space after that will always be a wall. For example, in this door, the doorway is marked by `D`s:
```
\
\
---DDX-----
```
One the doorway is found, find out whether you need to go clockwise or counterclockwise to reach the door. For example, in that example door above, you have to go clockwise, and in this one, you must go counterclockwise:
```
\ <-
\ )
-----X ---
```
Once you know which way to go, keep going that way (ignoring the door) until you reach a wall.
Here's a visualization of that for the example door above:

The blue is the doorway, the orange is finding that you must go clockwise, and the red is continuing to go clockwise until a wall is reached.
Once you reach a wall, go (the door's length) spaces from the hinge (`X`) on that wall, move one space away from the wall towards the door (so you don't place the doorstop right on the wall), and insert a `.` there. Here's the same example door showing how the doorstop is placed:
```
\
\ .
---DDX12---
```
Repeat for every door, and output the result! Use the example input at the top of this post as a test case to check if your program is valid.
Note that you do not have to handle doors that don't fit on their walls, such as:
```
| /
| /
| /
| /
+-X --
```
Or:
```
/
/
/
+-X --
|
|
```
* This is [code-golf](/questions/tagged/code-golf "show questions tagged 'code-golf'"), so the shortest code in bytes will win.
[Answer]
## Scala, 860 bytes
**Golfed**:
```
object D extends App{val s=args(0)split("\n")
val r=Seq(P(1,0),P(1,-1),P(0,-1),P(-1,-1),P(-1,0),P(-1,1),P(0,1),P(1,1))
var m=r(0)
val e=s.map(_.toCharArray)
case class P(x:Int,y:Int){def u=x==0||h
def h=y==0
def p(o:P)=P(x+o.x,y+o.y)
def o="\\/".contains(c)
def w="-|+".contains(c)
def c=try s(y)(x) catch {case _=>'E'}
def n=r.filter(!_.u).map(d => d.j(p(d))).sum
def j(t:P):Int=if(t.o)1+j(p(t))else 0
def q=if(c=='X'){m=this
r.filter(_.u).map{d=>if(p(d).c==' '&&p(P(d.x*(n+1),d.y*(n+1))).w)d.i}}
def i:Unit=Seq(r++r,(r++r).reverse).map(l=>l.drop(l.indexOf(this)+1)).map(_.take(4)).filter(_.exists(a=>a.p(m)o))(0).grouped(2).foreach{p=>if(p(1)p(m)w){p(0)add;return}}
def add=if(r.filter(_.h).map(p(_)p(m)).exists(_.w))e(y*m.n+m.y)(x+m.x)='.'else e(y+m.y)(x*m.n+m.x)='.'}
val f=args(0).size
Array.tabulate(f,f){(i,j)=>P(i,j)q}
e.map(_.mkString).map(println)}
```
**Un-golfed**:
```
object DoorknobCleanVersion extends App {
val s = args(0) split ("\n")
val r = Seq(P(1, 0), P(1, -1), P(0, -1), P(-1, -1), P(-1, 0), P(-1, 1), P(0, 1), P(1, 1))
val HorizontalDirections = r.filter(_.isHorizontal)
var hinge = r(0)
val result = s.map(_.toCharArray)
type I = Int
case class P(x: Int, y: Int) {
def isCardinal = x == 0 || isHorizontal
def isHorizontal = y == 0
override def toString = x + "," + y
def p(o: P) = P(x + o.x, y + o.y)
def isDoor = Seq('\\', '/').contains(charAt)
def isWall = Seq('-', '|', '+').contains(charAt)
def charAt = try s(y)(x) catch { case _ => 'E' }
def doorLength = r.filter(!_.isCardinal).map(d => d.recursion2(p(d))).sum
def recursion2(currentPosition: P): Int =
if (currentPosition.isDoor)
1 + recursion2(p(currentPosition))
else
0
def findDoorway =
if (charAt == 'X') {
hinge = this
r.filter(_.isCardinal).map { d =>
if (p(d).charAt == ' ' && p(P(d.x * (doorLength + 1), d.y * (doorLength + 1))).isWall)
d.getCorrectRotation2
}
}
def getCorrectRotation2: Unit = Seq(r ++ r, (r ++ r).reverse).map(l => l.drop(l.indexOf(this) + 1))
.map(_.take(4))
.filter(_.exists(a => a.p(hinge)isDoor))(0)
.grouped(2)
.foreach {
p =>
if (p(1) p (hinge)isWall) {
p(0)add;
return
}
}
def add =
if (HorizontalDirections.map(p(_) p (hinge)).exists(_.isWall))
result(y * hinge.doorLength + hinge.y)(x + hinge.x) = '.'
else
result(y + hinge.y)(x * hinge.doorLength + hinge.x) = '.'
}
val size = args(0).size
Array.tabulate(size, size) { (i, j) => P(i, j).findDoorway }
result.map(_.mkString).map(println)
}
```
Using OOP was definitely the wrong approach here, in hindsight. If I could do it again I would definitely go with a bunch of hardcoded truth tables.
]
|
[Question]
[
## Syntax
`~` not
`/\` and
`\/` or
`t` true
`f` false
`P`, `Q`, `FISH`, etc: variables
(Operators are given in order of precedence)
## Introduction
Some boolean formulae can be changed to different forms to make them shorter. For example, the formula
```
~(~P /\ ~Q)
```
can be changed to the shorter form
```
P\/Q
```
while the formula
```
P \/ ~P
```
can be changed to the shorter form
```
t
```
---
## Challenge
In this challenge, you are required to write a program that, given any boolean formula using only `/\`, `\/`, `~`, `t`, `f`, parentheses, boolean variables (in uppercase), and whitespace, outputs a shortest form (since there may be more than one shortest form) in characters of that expression which is equivalent for all assignments of the variables. Shortest code (in any language) wins. I/O can be done in any reasonable manner.
Also, since answers are difficult to verify, it would be helpful (but isn't required) to include a brief explanation of how the code works.
[Answer]
# Python 616
Not particularly efficient, but works in reasonable time for inputs whose results are around 5 or 6 characters. To check a string to see if it matches, it loops through every possible combination of truth/false values for all the variables and makes sure each one agrees. Using this it checks every possible string comprised of the relevant characters (not even necessarily a syntactically correct one).
It actually will print every equivalent expression (of every size) and does not actually ever terminate.
Code:
```
c=['t','f'];o=['1 ','0 ']
def e(s,v):
for k in v:s=s.replace(k,v[k])
return eval(s)
def z(t,p='~/\\() '):
w=[]
if p=='':return[t]*(t not in['']+c)
for s in t.split(p[0]):w.extend(z(s,p[1:]))
w.sort(key=lambda v:-len(v));return w
def m(v):
l=list('~\\/()')+v
for s in l:yield s
for r in m(v):
for s in l:yield s+r
def n(x):
if x<1:yield []
else:
for l in n(x-1):
for b in o:yield[b]+l
t=raw_input();v=z(t)+c;l=len(v)
for s in m(v):
g=1
for y in n(l):
y[-2:]=o;d=dict(zip(v+['/\\','\\/','~'],y+['and ','or ','not ']))
try:
if e(s,d)!=e(t,d):g=0
except:g=0
if g:print s
```
Input/Ouput:
```
> ~(~P /\ ~Q)
Q\/P
P\/Q
...
> P /\ ~P
f
~t
...
> (P \/ Q) /\ P
P
(P)
...
```
[Answer]
Oh right, I forgot to ever actually post my answer. It uses essentially the exact same approach which [KSab's answer](https://codegolf.stackexchange.com/questions/23606/compressing-boolean-formulae/25087#25087) uses, but prints only the shortest valid expression.
# Python3, ~~493~~ 484
```
e=lambda x:eval(x.replace('\\/','+').replace('/\\','%'),None,w)
class V(int):
def __add__(s,o):return V(s|o)
def __mod__(s,o):return V(s*o)
def __invert__(s):return V(1-s)
import re;from itertools import product as P;t=V(1);f=V(0);i=input();v=re.findall('[A-Z]+',i)
for k in range(1,len(i)):
for m in P(i+'~/\\tf()',repeat=k):
m=''.join(m)
try:
for d in P((V(0),V(1)),repeat=len(v)):
w=dict(zip(v,d))
if e(m)!=e(i):raise
except:continue
print(m);exit()
print(i)
```
Edit: fixed a bug where parentheses might not be generated, and golfed the computation of `m` a bit. Also replaced `-s+1` with `1-s`.
]
|
[Question]
[
[0h n0](http://0hn0.com/) is a very simple and enjoyable game, a bit like Sudoku or minesweeper.
## Game rules
(I recommend using the [tutorial](http://0hn0.com/) in the game if you can, it is very simple and useful)
The puzzle starts with an `n * n` board containing some fixed pieces and some empty cells, and the solver must find a way to fill the empty cells with pieces and satisfy all of the constraints imposed by the fixed pieces. Here are the piece types we will be using with the abbreviation:
* `#` Red piece (blocks view of a blue piece)
* `O` Blue piece
* `.` Empty location
* `number` Numbered blue piece (`number` is a one digit number >0)
All the numbered pieces must see exactly the same amount of blue pieces as the number. For example:
```
#1O#O
...O.
```
The `1` piece can see only one other blue piece.
### How pieces see each other
Two blue pieces can see each other if they are in the same row or column and no red piece is between them. Example:
(`S` is a location that the `O` piece can see, `X` can't be seen)
```
S
S
X#SOSS
#
X
```
Each blue piece must see at least one other blue piece:
```
#O#
```
Wont work, but:
```
#OO
```
Or:
```
###
```
Do work.
### Demo board solve
```
.1..
..1.
....
22#2
```
The right bottom 2 can only see above itself, so they must be blue, and the top right must be red.
```
.1.#
..1O
...O
22#2
```
Since the `1` is filled, we can surround it with red pieces.
```
.1##
.#1O
..#O
22#2
```
The top left `1` can only see in one direction now, so we can fill it in.
```
O1##
.#1O
..#O
22#2
```
Now about those last `2`s. We can put 2 blue pieces over them.
```
O1##
.#1O
OO#O
22#2
```
The last one will be filled with `#`
```
O1##
##1O
OO#O
22#2
```
## Input
Input is a multi-line string. The size will be `9x9` without trailing space. It has the following piece types:
* `.` Empty
* `#` Preset red, cannot be changed
* `number` Preset number, cannot be changed
(Note that blue will not ever be in the input)
## Output
Output is the same as input, with the change that empty (`.`) is replaced with either a red or a blue to solve the board, and numbers are replaced with blue pieces (`O`).
## Examples
(Note that multiple solutions may be possible for each puzzle, but you only need to show one of them)
```
Input:
........4
...3.1...
45...2.3.
..9......
1..6#44..
....4..5.
....4.36.
2.......6
1....4...
Output:
OOO###OOO
OOOO#O#OO
OOO#OO#OO
#OOOO#O##
O#OO#OOOO
O#OOOO#OO
#OOOO#OOO
OO#O#OOOO
O#OOOO#O#
Input:
..7..#...
#...8..11
2....5...
..5...48.
...#...4.
.5...6...
...1.2...
2.....6.8
.7..#....
Output:
OOOOO####
##OOOO#OO
O#OOOO###
OOO#OOOOO
OO##O##O#
#O##OOOOO
#O#O#O#OO
OO#OOOOOO
OOO###O#O
Input:
5.3..33..
...4...23
.6.6.34..
...3#....
....5..4.
.5....3..
7.98.6#.3
.5.6..2..
..6...2..
Output:
OOOOO####
##OOOO#OO
O#OOOO###
OOO#OOOOO
OO##O##O#
#O##OOOOO
#O#O#O#OO
OO#OOOOOO
OOO###O#O
```
Thanks to [@PeterTaylor](http://meta.codegolf.stackexchange.com/users/194/peter-taylor) and [@apsillers](http://meta.codegolf.stackexchange.com/users/7796/apsillers) for all their help in the sandbox!
[Answer]
# Haskell, 224 bytes
Not fully tested, because it's so slow (at least `O(n*2^n^2)`).
```
t=1<2
x!p|p<0=0|t=mod(div x$2^p)2
l#x=[[sum$map(p&)[-1,1,l+1,-l-1]|p<-[q..q+l]]|q<-[0,l..l*l],let i&v|x!i<1=0|t=x!(i+v)+(i+v)&v]
b%v|b<1=t|t=b==v
s b|l<-length b-1=[l#x|x<-[0..2^l^2],and.map and$zipWith(zipWith(%))b(l#x)]!!0
```
# Explanation:
Basic idea is to represent a board of `Red, Blue` pieces as a list of lists of `0, 1`, where the list of lists is packed into a single integer for easier enumeration. All such integers for the board size are generated and converted to a form with neighbor counts. The first such board that is a valid solution of the input is returned.
```
-- integer x at position p with out of bounds defined to be 0 (so no bounds checking)
(!) :: (Integral b, Integral r) => r -> b -> r
x ! p | p < 0 = 0
| otherwise = mod (div x (2^p)) 2
-- Sum of values from position p along vector v (x is implicit)
-- Note that a cartesian vector (x,y) in this representation is (l*x + y)
(&) :: (Integral a, Integral b) => b -> b -> a
p & v | x ! p == 0 = 0
| otherwise = x ! (p+v) + (p+v) & v
-- Value of board at position p (implicit x, l)
value :: Integral a => a -> a
value p = sum $ map (p&) [-1, 1, l+1, -l-1]
-- Integer to board, where l is length, x is input integer
(#) :: (Integral t, Integral a) => a -> t -> [[t]]
l # x = [[sum $ map (p&) [-1,1,l+1,-l-1] | p <- [q..q+l-1]] | q <- [0,l..l*l]]
-- Comparison operator, to see whether a solved board is a solution of the input
(%) :: (Num a, Ord a) => a -> a -> Bool
b % v | b == 0 = True
| otherwise = b == v
-- Check one possible solution
check :: Integral a => [[a]] -> Int -> [[a]] -> Bool
check b l x = (and . (map and)) zipWith(zipWith (%)) b (l # x)
-- Solver
solve :: Integral t => [[t]] -> [[t]]
solve b = [l # x | x <- [0..2^l^2], check b l x]
where
l = length b
```
The part that could probably be most golfed is: `and.map and$zipWith(zipWith(%))`. Otherwise, I caught a few off-by-one errors that added length and could probably be golfed more.
[Answer]
# Python3 1244 bytes
Very long, but optimized to crunch all the test cases (and some others) in ~0.5 seconds.
```
E=enumerate
from itertools import*
M=[(0,1),(0,-1),(-1,0),(1,0)]
def T(v,D,d):
s,c=[],0
for l,X,Y in D.pop(1):s+=[(l[0][1],X,Y)];c+=len(l[0][1]);D[0]+=[(l[1:],X,Y)]
if c>v:return
q=[(D[0],c,s)]
while q:
O,c,s=q.pop(0)
if c==v:yield s;continue
if[]==O:continue
q+=[(O[1:],c,s)]
L,X,Y=O[0]
for i,(_,U)in E(L):
if 0==i%2:
for I in range(1,len(U)+1):
if len(Q:=[j for k in L[:i]for j in k[1]]+U[:I]+(L[i+1][1]if I==len(U)and L[i+1:]else[]))+c<=v:q+=[(O[1:],c+len(Q),s+[(Q,X,Y)])]
def B(x,y,v,d):
q=[(x,y,X,Y,[])for X,Y in M]
while q:
x,y,X,Y,p=q.pop(0)
if not(V:=d.get(g:=(x+X,y+Y)))or'#'==V:yield([(a,[*b])for a,b in groupby(p,key=lambda x:d[x]!='.')],X,Y);continue
q+=[(*g,X,Y,p+[g])]
def f(b):
d={(x,y):v for x,r in E(b)for y,v in E(r)}
q=[([(i,d[i])for i in d if d[i].isdigit()],d)]
while q:
o,d=q.pop(0)
if[]==o:return d
W=[]
for(x,y),v in o:
D={0:[],1:[]}
for V,X,Y in B(x,y,v,d):
if V:D[V[0][0]]+=[(V,X,Y)]
W+=[((x,y),v,[*T(int(v),D,d)])]
if all(i[2]for i in W):
(x,y),v,L=W[0]
for w in L:
D={**d}
for l,X,Y in w:
for j,k in l:D[(j,k)]='O'
if(j+X,k+Y)in D:D[(j+X,k+Y)]='#'
for X,Y in M:
if'.'==D.get(H:=(x+X,y+Y)):D[H]='#'
q+=[(o[1:],D)]
```
[Try it online!](https://tio.run/##XVVtb9s2EP48/gouxiDSYghLst1UGfdhcIcGSJd1aJwWnFDIluwyUSRFUpwYRX57dkdKbhoDosh7e@6Oz8n1vvtWldFJ3Tw/v1N5eX@bN2mXk01T3VLT5U1XVUVLzW1dNd2YfFCaTUTABazH@DoOxAReuCYkyzf0E9uJhch4TGgr1konYkLopmpoIT6LL9SUdCHrqmYBj1sfohV6kuggQSVPTte@KvJyEPLTBWycVRD3NoSaDV3/sYubvLtvSkLvQI92Yi1aVD98M0VO7yABeoEydWcBJxwE6KrULt6bvMhoe7quys6U97lV6USpi/iF6A6hLyx0H5ueYxLqAuDggGUZwb6KSw51vWPnWLUFmShlfgvtyVqdYeFNWm5zaBVWeMn9wFlbexR9jJW@ttY3aH2uY5Pg6RpPN9COxL/U8Vnis3Nt/AAbBJ5nSrl4aZlRq4iTvGhznXDur3@HWl9W4VsgLlpfs4@un/29/ckexV7s3M1hS/EIBgICYRb95X34ucGDUf2qyWXVsWWsMrnNO7aNFXv0P4u9/4VzXjXeyFNq6e6AaZYKPV45kFSsEGTbVPf1as9qcZPvVZHerrKUPsaZfkx@VZ70uKPC6eurGm9dMr7eDmVt2AoLytR3LIjHO9vgR9FQe2MrCwt1u2PDn1zxmhmRaeOyMqjMsCwUSdNmZms6Bllkr/hWieznRiClqp6pNAPRFUyEY47NxwFXlggL9X0Sw7wEsDyRnjjLYWp@uh9HmmW80EuclElih2Q5DAjA4LlHgPZ@Yqbs2I7byUysCfinRcGMDpNDjVcu9uB3rq4cz20mD5aUDhxSHY@zpwO9D7P90FPa8lZYHheQJYM9T5R34Q2MZ9dAiBsgBH4QrEV/BquRdwg8sO4wKXD7Si0srd6/pBWEeP/D1bKhspRf8OS5DamiR0dHRIaSyAAe@eKBM@raYDAKrMaZSRKGo9AZRINB/5viLkJzSaYzWEM4geytUxNQzEfTqcOR8J4Nu2gOcfsoc7Sz6j6P6QHmjZQjFONyAhkFzmnmUsfX9MSGHNkAxIrmfWGBDG36DkSekCFcDzPrYWaQtIwi54RZhBEB@7mM@swj59QjDzDoRd7ItydQo4xQNscGoN1cuh1Gxxn851@2crxdqXyXFqztGpg8TvpZ3Nv5ilcw3npvL9GOmqUhzA9cOcUv2kFEaN0gn73/Sk9eV6Zkt2nNPLcXEJgTi9tVX1dV2mSsBexf@iHUemx@MH5jCviPY39XZS5oK9u6MC4uBxgb5C/rDZm/iEZcSRtXRJ/MsTcOYeoJOAQc19CukV2ndp3x5/8B)
]
|
[Question]
[
# Background
A [*matryoshka doll*](https://en.wikipedia.org/wiki/Matryoshka_doll) (or Russian nesting doll) is a set of dolls that fit inside of each other. I've accidentally mixed up my collection of matryoshka dolls and I don't remember which one goes inside which.
# Objective
Given a list of *unique* strings, sort them into nested matryoshka dolls. Each string is an individual doll, and a matryoshka doll is a list of strings.
# Rules
Let `min(a,b)` be the lexicographic min of strings `a` and `b`. Let `a ⊂ b` denote that `a` is a substring of `b`. Then,
1. The list of matryoshka dolls must be sorted lexicographically
2. String `a` can *fit* into string `b` if `a ⊂ b`
3. If `a ⊂ b` and `a ⊂ c`, then `a` will go inside `min(b,c)`
4. If both `a ⊂ c` and `b ⊂ c`, but `a ⊄ b` `b ⊄ a`, then only `min(a,b)` will go inside `c`
5. If both `a ⊂ c` and `b ⊂ c`, and also `a ⊂ b`, then only `b` will go inside `c`. I.e., superstrings go before substrings so that the matryoshka isn't prematurely terminated.
# Examples
```
In:
hahaha, hah, lol, lololol, bahaha, bah, haha, ah
Out:
bahaha, bah, ah
hahaha, haha, hah
lololol, lol
In:
aa, aaaa, a, aaaaaaaaaa
Out:
aaaaaaaaaa, aaaa, aa, a
```
[Answer]
# [Python 2](https://docs.python.org/2/), 298 bytes
```
def f(x,E=enumerate):
o=[]
while any(x):
for k,p in E(x):
e=0
if sum(i(p,j)for j in x)<1:
for d,r in E(o):
if i(p,r[-1])*((r[-1]<e)or e==0):m,e=d,r[-1]
if e:o[m]+=[p]
else:o+=[[p]]
x[k]=''
print sorted(o)
i=lambda p,b:(b!=p)*any([p==b[j:j+len(p)]for j in range(len(b)-len(p)+1)])
```
[Try it online!](https://tio.run/##PY/djoMgEIWv16eYzV4ILU3avTTlsk9BvIA6ViwCQZu1T@8O2jYkzDlnvuEnPqcu@N/lB3yYEMYpWX@D81vYERzO9hpuScfOXrVbGmyhZbO4SPSPAZOekFcFBKnqAv466xC0f7KZwq82JLiLCNbDZUsA5ZF228L4GJhlUfQ8U31mZn4@EbOONSJtYyGPrROZTupwqvmOsVWckROKUh55NQiUzdYnnnCsghrqvVQxB@hGCsiRzX5W91qWZQGRPjrBGNKEDV1WWOn0YBoNUZiKmW8Z@S5/SEUpjeqrfu/Qs8jrz7OT9jdkOTX8sDX3J17zpWWq7HRepYCscnHBvUp4SfNBzIa8LTk65R8 "Python 2 – Try It Online")
*-28 bytes with tips from @dylnan, bug find by @Dennis, and bug fix by @Mr.Xcoder*
]
|
[Question]
[
# Introduction
I have a lot of ASCII rocks. They are built with dashes, pipes, Vs, carets, angle brackets, slashes and spaces. Example:
```
/--\
| |
| |
\--/
```
I want to erode them, like this:
```
/\
/ \
\ /
\/
```
All of the corners have become rounder. A more complicated example:
```
/----\
| \------\
| |
| |
\------------/
/--\
/ \------\
| \
\ /
\----------/
```
After another erosion, it would become
```
/\
/ \------\
< \
\ /
\--------/
```
And another:
```
/\------\
< \
\ /
\------/
```
# Challenge
Your challenge is to write a program that can erode an input once. You can assume there is only one rock and you can assume it is one closed loop. The input will only contain the chars `/\ -| <> ^V \n` and will have trailing spaces to create a rectangle. The program can either get input from STDIN and output to STDOUT or can be a function. At the end of each row is a newline character. The erosion must follow the rules outlined below (Note: in the examples the rock isn't completed, this is for ease of explanation). The output must be in the same format as the input, with the same size as the input. However, trailing spaces may be omitted.
The slashes will spread to pipelines and dashes and move across.
```
/---
|
|
/--
/
|
/-
/
/
```
If two slashes merge together, the appropriate character out of `<>^V` is used.
```
/-----\
| |
| |
| |
\-----/
/---\
/ \
| |
\ /
\---/
/-\
/ \
< >
\ /
\-/
^
/ \
< >
\ /
V
```
If a part of the rock can merge, it will. Note: if one part can merge but the other can't (i.e, `/\` in the second line of the example), then the one that can merge will (see example).
```
/\
/\-^-/\-/ \--
|
<
|
/
\
|
/
/
\
\
|
|
/-------/\--
/
|
|
|
|
|
|
/
\
|
|
|
```
Eventually, all rocks will become nothing.
```
<> ^ /\
V \/
```
# Test cases
Test 1:
```
/----\
| \------\
| |
| |
\------------/
/--\
/ \------\
| \
\ /
\----------/
/\
/ \------\
< \
\ /
\--------/
/\------\
< \
\ /
\------/
/-----\
< \
\ /
\----/
/---\
< \
\ /
\--/
/-\
< \
\ /
\/
^
< \
\/
```
Test 2:
```
/----\
| |
| |
| |
| |
\----/
/--\
/ \
| |
| |
\ /
\--/
/\
/ \
/ \
\ /
\ /
\/
/\
/ \
\ /
\/
/\
\/
```
Test 3:
```
^ /\
/\--/\--/ \--/ \-\
\ |
| |
/ |
\ |
| |
| |
/ |
< |
\ |
| |
| |
/ |
/ |
\ |
\-----------------/
/-------^----/\-\
/ \
| |
| |
| |
| |
| |
| |
< |
| |
| |
| |
| |
/ |
\ /
\---------------/
/-------------\
/ \
/ \
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
\ /
\ /
\-------------/
/-----------\
/ \
/ \
/ \
| |
| |
| |
| |
| |
| |
| |
| |
\ /
\ /
\ /
\-----------/
/---------\
/ \
/ \
/ \
/ \
| |
| |
| |
| |
| |
| |
\ /
\ /
\ /
\ /
\---------/
/-------\
/ \
/ \
/ \
/ \
/ \
| |
| |
| |
| |
\ /
\ /
\ /
\ /
\ /
\-------/
/-----\
/ \
/ \
/ \
/ \
/ \
/ \
| |
| |
\ /
\ /
\ /
\ /
\ /
\ /
\-----/
/---\
/ \
/ \
/ \
/ \
/ \
/ \
/ \
\ /
\ /
\ /
\ /
\ /
\ /
\ /
\---/
/-\
/ \
/ \
/ \
/ \
/ \
/ \
/ \
\ /
\ /
\ /
\ /
\ /
\ /
\ /
\-/
^
/ \
/ \
/ \
/ \
/ \
/ \
/ \
\ /
\ /
\ /
\ /
\ /
\ /
\ /
V
^
/ \
/ \
/ \
/ \
/ \
/ \
\ /
\ /
\ /
\ /
\ /
\ /
V
^
/ \
/ \
/ \
/ \
/ \
\ /
\ /
\ /
\ /
\ /
V
^
/ \
/ \
/ \
/ \
\ /
\ /
\ /
\ /
V
^
/ \
/ \
/ \
\ /
\ /
\ /
V
^
/ \
/ \
\ /
\ /
V
^
/ \
\ /
V
^
V
```
# Scoring
This is [code-golf](/questions/tagged/code-golf "show questions tagged 'code-golf'"), so the program with the smallest number of bytes wins!
[Standard loopholes](https://codegolf.meta.stackexchange.com/questions/1061/loopholes-that-are-forbidden-by-default) are not allowed.
[Answer]
# Rust
I gave up on this after a while, the instructions kind of seem ambiguous. However i did get some shrinky-looking rocks (see output). I also am pretty sure this needs to be done in a 2 dimensional space rather than in a 1 dimensional string as i tried here. My main "issue" is that I transform the given input by marking space as 'inside' or 'outside' the rock, unfortunately at this point it cannot distinguish between inside and the top/bottom edges.
```
enum State {
OutsideLeft,CrossLI,Inside,CrossRI,OutsideRight,
}
const INPUT: &str = r#"
/----\
| \------\
| |
| |
\------------/
"#;
fn precycle( mut data:Vec<char> ) -> Vec<char> {
let mut state = State::OutsideLeft;
let mut curcol = 0;
let mut curline:Vec<char> = Vec::new();
let mut lastline:Vec<char> = Vec::new();
for mut i in 0..data.len() {
if data[i]=='\n' {
lastline = curline.to_vec();
lastline.push(' ');
curline.clear();
curline.push(' ');
curcol = 0;
} else {
curline.push(data[i]);
curcol += 1;
}
let n = curcol%lastline.len();
let n2 = lastline.len()-n;
//println!("[{}]",lastline.iter().collect::<String>());
//println!("[{}]",curline.iter().collect::<String>());
//println!("({}{})({}{})>",data[i],state,lastline[n],curline[n]);
//print!("{}{}>",data[i],state);
match state {
State::OutsideLeft => {
if data[i]=='/' { state = State::CrossLI; }
else if data[i]=='\\' { state = State::CrossLI; }
else if data[i]=='|' { state = State::CrossLI; }
else if data[i]=='<' { state = State::CrossLI; }
if data[i]==' ' { }
} State::CrossLI => {
if data[i]=='/' { state = State::CrossRI; }
else if data[i]=='\\' { state = State::CrossRI; }
else if data[i]=='|' { state = State::CrossRI; }
else if data[i]=='>' { state = State::CrossRI; }
if data[i]==' ' { data[i]='-'; }
if data[i]=='-' { state = State::Inside; }
} State::Inside => {
if data[i]=='/' { state = State::CrossRI; }
else if data[i]=='\\' { state = State::CrossRI; }
else if data[i]=='|' { state = State::CrossRI; }
else if data[i]=='>' { state = State::CrossRI; }
if data[i]==' ' { data[i] = '-'; }
} State::CrossRI => {
if data[i]==' ' { state = State::OutsideRight; }
if data[i]=='\n' { state = State::OutsideLeft; }
} State::OutsideRight => {
if data[i]==' ' { }
if data[i]=='\n' { state = State::OutsideLeft; }
} }
match state {
State::CrossLI => {
if curline[n]=='|' && lastline[n]=='.' { data[i]='9'; curline[n]='9'; }
}
State::CrossRI => {
if curline[n]=='|' && lastline[n]=='.' { data[i]='8'; curline[n]='8'; }
if curline[n]=='.' && lastline[n]=='8' { data[i-n-n2+1]='>'; }
if curline[n]=='.' && lastline[n]=='|' { data[i-n-n2+1]='6'; }
}
State::OutsideLeft => {
if curline[n]=='.' && lastline[n]=='|' { data[i-n-n2+1]='7'; curline[n] = '7'; }
if curline[n]=='.' && lastline[n]=='9' { data[i-n-n2+1]='<'; }
}
_ => { }
}
//print!("{} ",state);
}
for mut i in 0..data.len() {
if data[i]=='9' {data[i]='/'}
if data[i]=='8' {data[i]='\\'}
if data[i]=='7' {data[i]='\\'}
if data[i]=='6' {data[i]='/'}
}
data
}
fn cycle( data:String ) -> String {
data
.replace(r#"^"#,r#"."#)
.replace(r#"V"#,r#"."#)
.replace(r#"/-\"#,r#".^."#)
.replace(r#"\-/"#,r#".V."#)
.replace(r#"-/\-"#,r#"----"#)
.replace(r#"-\/-"#,r#"----"#)
.replace(r#"/\-"#,r#"/--"#)
.replace(r#"-/\"#,r#"--\"#)
.replace(r#"\/-"#,r#"\--"#)
.replace(r#"-\/"#,r#"--/"#)
.replace(r#"./\."#,r#"...."#)
.replace(r#".\/."#,r#"...."#)
.replace(r#"/\"#,r#".."#)
.replace(r#"\/"#,r#".."#)
.replace(r#"-\"#,r#"\."#)
.replace(r#"-/"#,r#"/."#)
.replace(r#"/-"#,r#"./"#)
.replace(r#"\-"#,r#".\"#)
.replace(r#"->"#,r#">."#)
.replace(r#"<-"#,r#".<"#)
.replace(r#".-"#,r#"--"#)
.replace(r#"-."#,r#"--"#)
}
fn main() {
let mut inputv: Vec<char> = INPUT.chars().collect();
let mut input0: Vec<char> = inputv;
for j in 1..18 {
let mut inputa = precycle( input0 );
let pdata = inputa.iter().collect::<String>().replace("."," ");
println!("{}",pdata);
let mut input2 = cycle( inputa.iter().collect::<String>() );
input0 = input2.chars().collect();
}
}
```
output
```
/----\
|-----\------\
|------------|
|------------|
\------------/
/--\
/----\------\
|------------\
\------------/
\----------/
/\
/--\------\
<-----------\
\----------/
\--------/
/\------\
<---------\
\--------/
\------/
/-----\
<-------\
\------/
\----/
/---\
<-----\
\----/
\--/
/-\
<---\
\--/
\/
^
<-\
\/
<\
<\
<\
<\
<\
<\
<\
<\
<\
```
]
|
[Question]
[
[Next >>](https://codegolf.stackexchange.com/questions/149746/advent-challenge-2-the-present-vault-raid)
Descriptive Keywords (for searching): Make Two Matrices Equivalent, Overlap, Array, Find
# Challenge
Santa has had a history of elves stealing presents from his vault in the past, so this year he designed a lock that is very hard to crack, and it seems to have kept the elves out this year. Unfortunately, he has lost the combination and he can't figure out how to open it either! Fortunately, he has hired you to write a program to find the combination. It doesn't need to be the shortest one, but he needs to find it as fast as possible!
He has a very strict schedule and he can't afford to wait for very long. Your score will be the total run-time of your program multiplied by the number of steps your program outputs for the scoring input. Lowest score wins.
# Specifications
The lock is a square matrix of 1s and 0s. It is set to a random arrangement of 1s and 0s and needs to be set to a specified code. Fortunately, Santa remembers the required code.
There are a few steps he can perform. Each step can be performed on any contiguous sub-matrix (that is, you must select a sub-matrix that is entirely bounded by a top-left and bottom-right corner) (it can be a non-square sub-matrix):
1. Rotate right 90 degrees\*
2. Rotate left 90 degrees\*
3. Rotate 180 degrees
4. Cycle each row `n` elements right or left (wraps)
5. Cycle each column `m` elements up or down (wraps)
6. Flip Horizontally
7. Flip Vertically
8. Flip on the Main Diagonal\*
9. Flip on the Main Anti-diagonal\*
\*only if the sub-matrix is square
Of course, he can also perform these steps on the entire matrix. Since 1s and 0s can only be swapped on the matrix but the value of a square cannot be directly changed, the number of 1s and 0s is the same for the start and end configuration.
# Formatting Specifications + Rules
You will be given the input as two square matrices (starting position and ending position) in any reasonable format you want. The output should be a sequence of these steps in any readable format. Since this isn't code-golf, please make it an easily verifiable format, but that's not a strict requirement. You can choose to take the side-length of the matrices in the input if you want.
Your program will be run on my computer (Linux Mint, exact version details available upon request if anyone cares :P) and I will time it based on the amount of time between the time I press "enter" on the command line and when the command exits.
# Test Cases
```
1 0 0 1 0 0 0 0
0 1 1 0 -> 0 0 0 0
0 1 1 0 -> 1 1 1 1
1 0 0 1 1 1 1 1
```
1. Take the entire matrix. Cycle each column up 1.
2. Take the middle two columns as a sub-matrix. Cycle each column down 2.
```
1 0 1 0 1 0 1 0 1 0
0 1 0 1 0 1 0 1 0 1
1 0 1 0 1 -> 0 1 1 1 0
0 1 0 1 0 1 0 1 0 1
1 0 1 0 1 0 1 0 1 0
```
1. Take the entire matrix. Cycle each column down 1.
2. Take the middle column. Cycle it down 2.
3. Take the top 2 rows. Flip it vertically.
4. Take the top row's rightmost 2 elements. Swap them (rotate right/left 1, flip horizontally).
5. Take the top row's leftmost 2 elements. Swap them.
There might be more efficient methods, but that doesn't matter. Feel free to point them out in the comments if you find one though :)
# Judging Test Case
This test case will be used to judge your submission. If I believe that an answer is specializing for the test case too much, I have the right to repick a random input and rejudge all answers with the new case. The test case can be found [here](https://hastebin.com/avayimodaw.txt) where the top is the start and the bottom is the desired configuration.
If I believe answers are specializing too much, the MD5 of the next test case is `3c1007ebd4ea7f0a2a1f0254af204eed`. (This is written here right now to liberate myself from accusations of cheating :P)
Standard Loopholes Apply. No answer will be accepted. Happy coding!
Note: I drew inspiration for this challenge series from [Advent Of Code](http://adventofcode.com/). I have no affiliation with this site
You can see a list of all challenges in the series by looking at the 'Linked' section of the first challenge [here](https://codegolf.stackexchange.com/questions/149660/advent-challenge-1-help-santa-unlock-his-present-vault).
[Answer]
# [Java](http://openjdk.java.net/projects/jdk9/)
```
import java.util.Arrays;
public class SantaMatrix4 {
public static void flipV(int[][] matrix, int row1, int col1, int row2, int col2) {
for (int row = row1; row <= (row2 - row1) / 2 + row1; row++) {
for (int col = col1; col <= col2; col++) {
int tmp = matrix[row][col];
matrix[row][col] = matrix[row2 - row + row1][col];
matrix[row2 - row + row1][col] = tmp;
}
}
}
public static void flipH(int[][] matrix, int row1, int col1, int row2, int col2) {
for (int row = row1; row <= row2; row++) {
for (int col = col1; col <= (col2 - col1) / 2 + col1; col++) {
int tmp = matrix[row][col];
matrix[row][col] = matrix[row][col2 - col + col1];
matrix[row][col2 - col + col1] = tmp;
}
}
}
public static void main(String[] args) {
int counter = 0;
int n = Integer.parseInt(args[counter++]);
int[][] matrix1 = new int[n][n];
for (int i = 0; i < n; i++) {
for (int j = 0; j < n; j++) {
matrix1[i][j] = Integer.parseInt(args[counter++]);
}
}
int[][] matrix2 = new int[n][n];
for (int i = 0; i < n; i++) {
for (int j = 0; j < n; j++) {
matrix2[i][j] = Integer.parseInt(args[counter++]);
}
}
int[] ops = new int[5 * matrix1.length * matrix1.length * 2];
int numOps = 0;
int opsI = 0;
for (int row = 0; row < n; row++) {
for (int col = 0; col < n; col++) {
int goal = matrix2[row][col];
boolean gotIt = false;
//Look for required number to the right
for (int i = row; i < n && !gotIt; i++) {
for (int j = col; j < n && !gotIt; j++) {
if (i == row && j == col) continue;
if (matrix1[i][j] == goal) {
flipH(matrix1, row, col, i, j);
flipV(matrix1, row, col, i, j);
ops[opsI++] = 1;
ops[opsI++] = row;
ops[opsI++] = col;
ops[opsI++] = i;
ops[opsI++] = j;
numOps++;
gotIt = true;
}
}
}
//Look for required number below and to the left
for (int i = row + 1; i < n && !gotIt; i++) {
for (int j = 0; j < col && !gotIt; j++) {
if (matrix1[i][j] == goal) {
flipH(matrix1, i, j, i, col);
ops[opsI++] = 2;
ops[opsI++] = i;
ops[opsI++] = j;
ops[opsI++] = i;
ops[opsI++] = col;
flipV(matrix1, row, col, i, col);
ops[opsI++] = 3;
ops[opsI++] = row;
ops[opsI++] = col;
ops[opsI++] = i;
ops[opsI++] = col;
numOps += 2;
gotIt = true;
}
}
}
}
}
System.out.println(Arrays.toString(ops));
System.out.println(numOps);
}
}
```
Slightly faster hard-coded version: [Try it online!](https://tio.run/##vVdRb5swEH6GX@G9VGSkKabaw0T7sLdV2rSHSn1BeSANSU0JZuC0qyp@e3a2wRBiA5m2SQmY8@e783d35kiil@iS5nGWrJ8/Hw5kl9OCoQSkiz0j6eJLUURvZWDb@X6Vkkf0mEZlib5HJEPvtmVbtbhkEYPbCyVrtElJ/uCQjIXLcIl2ESvIrzmCZ1TQVyxHjzTFSuYrmT/jWq0NLZBTT6JbsSwQ45tb5PAF6FIIZ@gK@chtAa4rFbQaQClo4OYCMb4RD754UGiLI9kuB6R0NwRdyxAgy0DM96VHwNqb2g/9Mh0GlIBNgaxs8a8GGP36zxjl@OnsOVwp7IYLG/4V4C8xKkS1kVq9flkPo2NUS@gO8te5B1XZFgiNim0p/T6mGIO@LH5FjVTs7B1Y9o5/uPmpx3a2motFPbgG2AW0i7DOknZRY0k7P2YJH2s32ujvSesPnuQeNizCRkvemG@4z97pCnxyNcQJT9iT2dJpOrTXoTh5pggYM8JEDR6K04DtwdybRvmpMb2HVRWclJw/seRM@8eaqIzu2VCn2sLD44UwUrMjXJ1f3Mbs6Rf3KCNm9kYKb@TA0qfD2e4NEoHHDyxsCMmEk3vYnrm4sflowEPviOGTa2xR78hpB7LkLNuq6w7RvOxU3Cf0sXn1LdI427InncCX72L@hs/2ux9Cg6dEoPFOCRROvd4bPcFRnyG7Eq9uSVA22I54dS/CYSc9x5ZGqTLm97uOFaVpHGWAYncMYJsoLWM5JS5XV98ofUbcYBH/3JMiXvM9ruICMYrYU4wKsn1iAqu8IrKhCmAAPqGLC/RB6AdB61sLT2RHFcCgB086cItsAI5uhWoOSvgY1s3gkjGS7Wu/JbImNyTLMFlyJOehVWbJDrJGzbnOOVcGbeIcJbOgC3sYh0GMQx5n1@UtFzbIOSf6Gb59/QwxyBMllynnukrQ3JuYsqKlprI7N94LDsd4FadAdpStm2in8UYfbOg48TkB92S4ed4OBfzMMPKoiCvPCwNz/h8zPQ3fjeWUNBpw9fo/JJLO3foUc7tkTcimRoX81IDL/VvJ4t2C7tkih08LlmaO/HxeMCo/NhxwZCa2r8FKN/hsZVeHw28 "Java (OpenJDK 9) – Try It Online")
Input is space separated integers via the command line. The first integer is the width of the two matrices. The remaining integers are their elements, row-by-row.
Every permutation of a matrix can be obtained with just the horizontal flip and vertical flip operators, so I ignored the rest except for replacing a consecutive vFlip and hFlip in the same region with a rotation by 180 degrees.
The program scans through each element. Whenever we encounter an element that has the wrong bit, it looks further ahead through the array to find a spot that has the correct bit. I've divided the search region in two: those with an equal or larger column coordinate, and those with a smaller column coordinate. Note that the latter must have a larger row coordinate based on the way we're traversing the array. If we find a correct bit in the first search region, we can just rotate by 180 degrees the sub-matrix spanning the two elements for a total of one operation. If it's in the second region, we can use a horizontal flip to move the correct bit to the same column as the wrong bit and then vertically flip the sub-matrix spanning the two for a total of two operations.
The output of the program is an array that should be mentally split into groups of five. Each group is (i, row1, col1, row2, col2) where i is 0 for a no-op, 1 for a rotation by 180 degrees, 2 for a horizontal flip, and 3 for a vertical flip. The remaining 4 components describe the region over which the operation runs. I am not sure if this is a readable format.
For the given test case, I get 258 operations and two to three milliseconds on my computer.
]
|
[Question]
[
# Introduction
[Skat](https://en.wikipedia.org/wiki/Skat_%28card_game%29) is a traditional German card game for 3 players. The deck consists of 32 cards: Ace, King, Queen, Jack, 10, 9, 8, 7 in all 4 suits (Clubs, Spades, Hearts, Diamonds).
In every round there one player plays solo while the other two play against him.
At the start of a round each player is dealt 10 cards, the remaining 2 card are called the *skat* and are put facedown in the middle. The solo player is determined by a bidding phase. This is the part of the game that you will have to deal with in this challenge, more details on this below.
The player who wins the bidding phase becomes the solo player. He picks up the skat and then drops two cards (which may be the same, the other team does not know), picks the trump suit, and the round starts.
One round consists of ten tricks. The player who wins a trick leads the next one until all cards are played. I won't explain the rules here, but you should know that having a lot of trump cards is good. If you want to learn about the rules check the Wikipedia article which I linked at the start of this post, but it is not needed for this challenge.
# The Challenge
You want to teach your two sons how to play skat. The rules are not that hard, so they quickly get into it. The only thing giving them a hard time is the bidding, specifically calculating the game value of their hand. So you decide to write a small program which outputs the maximum game value that they can bid given their current hand.
# Calculating the game value
Every hand has a certain game value. It is determined by the amount of sequential Jacks you have and the suit which you want to pick as trump. Let's start with the first factor, the jacks!
## The Jack Factor
Jacks are always trump cards, and they beat every other trump card. The order of strength between the four Jacks is:
1. Jack of Clubs (highest)
2. Jack of Spades
3. Jack of Hearts
4. Jack of Diamonds (lowest)
In the further explanation I will refer to them with the numbers I assigned to them here.
You remember that there is some kind of factor that you get from the Jacks in your hand which is parts of the game value? Great! Here is how you get it:
This Jack factor is the number of top Jacks (see order above) in sequence, plus 1. So if you have all 4 Jacks it is 4 + 1 = 5. If you have only the first 2 Jacks, it is 2 + 1 = 3.
Alternatively, to make things a bit more complicated, the Jack Factor can also be the number of top Jacks in sequence that you are **missing**, plus 1. So if you are missing the first one, it is 1 + 1 = 2. If you are missing he first 3, it is 3 + 1 = 4. Here some examples, using the numbering above:
```
[1, 4] -> 1 + 1 = 2
[1, 2, 4] -> 2 + 1 = 3
[2, 3, 4] -> 1 + 1 = 2
[1, 2, 3, 4] -> 4 + 1 = 5
[] -> 4 + 1 = 5
```
That was the first factor. Here is how you get the 2nd one:
## The Trump Suit Factor
This one is a lot simpler. The 2nd factor is determined by the trump suit that the solo player picks using the following mapping:
```
Clubs -> 12
Spades -> 11
Hearts -> 10
Diamonds -> 9
```
That was easy, wasn't it?
## The Game Value
The game value is the product of the two factors. Pretty easy you think? Wrong! While the Jack-Factor is fixed, the suit-factor is not. The suit you end up picking as trump depends on the amount of trumps and the value of your non-trump cards in your hand. It would be way too complicated to explain what a good hand looks like, so you will use the following algorithm:
# The Which-Trump-do-I-Pick Algorithm
You don't have to participate in the bidding. If you decide that your hand is too bad to play solo, you can just pass. Your hand must match the following criteria to be playable:
* Have at least 6 trump cards (cards of the trump suit you pick + the number of Jacks). If this is possible for more than one suit, pick the one which would result in more trump cards. If there is *still* a tie, pick the suit with the highest rating given above.
* Out of the non-trump cards, have at least 1 Ace.
If your hand does not match both of this criteria, you will pass. If it does, you will output the calculated game value and the chosen trump suit.
*Short note: Of course this is a very simplified algorithm. There goes way too much strategy and experience into judging a hand than we could ever cover in a challenge like this.*
# Input
Every card has an unique identifier. The first part is the suit (**C**lubs, **S**pades, **H**earts, **D**iamonds), the second part is the value which is given by this mapping:
```
Ace -> A
King -> K
Queen -> Q
Jack -> J
10 -> 0
9 -> 9
8 -> 8
7 -> 7
```
Both parts combined form one card. The value comes first, then comes the suit. You may take the cards in any format as you want.
# Output
If the hand is playable, output the game value and the picked trump suit (order doesn't matter). If it's not, output "pass".
# Rules
* As mentioned you can take the input in the most convenient format for you. Examples see below in the test cases.
* Input may be provided by command line arguments, user input, or function arguments.
* Output may be provided as return value or may just be printed on the screen.
* The cards in the input may not be ordered in any way. Your program has to be able to deal with any random card order.
* Lowest byte-count wins!
# Testcases
Input in the test cases will be a list of 2-char Strings.
```
1. ["JC", "JS", "JD", "AC", "KC", "9C", "AS", "7H", "QD", "8D"] -> 36 Clubs
2. ["JD", "AS", "0S", "KS", "QS", "9S", "8S", "AD", "8C", "9C"] -> 44 Spades
3. ["JH", "JD", "0S", "KS", "9C", "8C", "QH", "KH", "AD", "9D"] -> pass
4. ["JD", "AS", "KS", "QS", "0S", "9S", "8D", "7D", "0C", "QH"] -> pass
```
Explanation:
1. Two Jacks in a row with Clubs as trump. So the game value is 3 x 12 = 36
2. Three Jacks in a row missing with Spades as trump. So the game value is 4 x 11 = 44
3. Only a maximum 4 of trump cards is possible, so you will pass.
4. Six trump cards with Spades but no non-trump ace, so you will pass.
*If some rules are unclear, go ahead and comment. I have grown up with this game, so it hard for me to judge if I described everything in enough detail.*
And now... **Happy Coding!**
**edit:** As pointed out to me in the comments (thanks to isaacg), there is a rule which counts the following top trumps after the 4 Jacks into the "Jack-factor" so it could go up to 11. To keep this challenge simple and to not confuse people, the rules I proposed originally will stay as they are. So the maximum factor stays at 5.
[Answer]
# Python 2, example implementation
Since there are no submissions yet, I wrote down an example implementation in Python. The input format is the same as in the testcases in the challenge.
Maybe that motivates you guys to get going, it's not that hard :)
```
def gameValue(hand):
jacks = ""
suits = {"C" : 0, "S" : 0, "H" : 0, "D" : 0}
# Loop through the hand, find all jacks and count the cards of each suit
for card in hand:
jacks += card[1] if "J" in card else ""
suits[card[1]] += 1 if card[0] != "J" else 0
# Map the Jacks to numbers while 1 is the highest (Clubs) then sort them ascending
jacks = sorted(map(lambda j: {"C" : 1, "S" : 2, "H" : 3, "D" : 4}[j], list(jacks)))
# Sort the suits by amount. Highest amount and value is first after that
suits = sorted(suits.items(), key = lambda suit: suit[1], reverse = True)
trumpSuit = suits[0][0];
# Amount of trumps is jack-count plus trumpsuit-count
trumpCount = len(jacks) + suits[0][1];
# Check for at least one ace that is no trump
hasAce = len(filter(lambda c: c[0] == "A" and c[1] != trumpSuit, hand)) >= 1
# If the hand is playable, calculate jack-factor and output the result, otherwise pass
if trumpCount >= 6 and hasAce:
# If there no jacks the factor is 5. If there are, find the first gap
if len(jacks) > 0:
lastJack = 0
for jack in jacks:
if jack - lastJack >= 2:
break
lastJack = jack
jackFactor = jacks[0] if lastJack == 0 else lastJack + 1
else:
jackFactor = 5
trumpFactor = {"C" : 12, "S" : 11, "H" : 10, "D" : 9}[suits[0][0]]
print str(trumpFactor * jackFactor) + " " + {12 : "Clubs", 11 : "Spades", 10 : "Hearts", 9 : "Diamonds"}[trumpFactor]
else:
print "pass"
```
[Answer]
# Java, 256 bytes
```
h->{int i,j=1,m=0,t,n=0,a[]=new int[8];for(var c:h){t=c[1]-48;if(c[0]==74){j+=1<<t;n++;}else{m+=i=c[0]==65?1:0;a[--t+4]+=i;a[t]++;}}for(i=t=0;i<4;i++)t=a[i]<a[t]?t:i;return a[t]+n<6|m-a[t+4]<1?"p":(t+++9)*(5-(int)(Math.log(j>7?~j&7:j)/Math.log(2)))+" "+t;}
```
Takes input as an array of character arrays in the format `A4`, where `4` is *Clubs*, `3` is *Spades*, `2` is *Hearts* and `1` is *Diamonds*. Output is `36 4` for a bid of 36 with trump suit *Clubs*, `p` for passing.
Try it online [here](https://tio.run/##lVVNU6NAED2zv2LksAU7CUKM5oOgRW1tlbrrIeUROYxkDINkSMEkrpXN/nW3pwEl60Uvz3G6p7/o95KxLetni8eX9eY@FwlJclZV5IYJSXZfjHUptkxxUimmwPggJMtJBk@cjRK580tUanarSiGX52TBk0cSdKxhWbLnymGVdrPMcGj2iPkTcY54jegiThDHiCPE8AT9EeeI14gu4gRxjDhCDAfojzhHvEZ0ESeIY8QRYuihP@Ic8RrRRZwgjhFHnmn7XwwhFS8fWMLJ7SNTejxG3Tu5FwsrSVkZxVFMUiYX2n0P46tn2kxvW4gFWcFkrfoZ@LJyWdl1JB2y0hCQl7R/voNsRPSywOutArenehKQRXEg@RMBWzSO/YeitLasJMk0tXcqSCIv7g/HvniwksiNg2A0tHcZDbzZTPmSUn/P84rvVjQQQe1wdnrhTV2fRf2@osMYDHBWsXbd6@AiUIHri9nQF5TaKmCRiGfa40JNhV9ytSklwRdydvZn1YcjhJl5F@banFqKUjqxv1mnfQsKtq0bplInL5ZWdj66@Jt9HU0z@/j1cmDbNjWJSZW/fzEMX8/kuVJ85RQb5cAiSpVLS0/I0ePWU7aaDar3ov563S2bdPao/ubz9qtCMp8cH5OTM/I939xXH8vmvcVz321ndyPr3Rq3VbTZhkNyu2YL/sF0g85SdtJ1qTLvLH3YLm6bbg1U/nRj3ZYOqNZS4ZWykPvTmcIOJbtUnXSJ2ZGF12G3mU5dcslZqaqaYIf6dMDBhmWO45CElYuGZ5pWOZdLlQLR8N6p/9ULB8xpbEcB8VwbrgyVlsUT0ay7ynO@ZHlYLjcrLtWP3wlfK1FIy7yEdLC576RPFXUNVl0ArHfKKvJUFqAZTSKT1gcKfVZpsckX5J5DbgclxzjoCCrWdeBd/SqOBrF2Q7JqwQAX14c/syY@nIG52HkrVrqWtnfgs36uGz/S@u0khVSgUBVWbOMAPjSBK7llOcgbBr8zTaoP1LwzQavq2j8ynh55i1KBOHISmbT5jFkBwqmXoYe/NOAdNzMydHzoBCSt6cvRIwqV5R7avf/tHtphj4xGy7QnSvf@5R8).
Ungolfed version:
```
h -> { // lambda taking a char[][] as argument and returning a String
int i, // used as a loop variable and as a temporary variable
j = 1, // variable storing the jacks present in the hand in its four last-to-least significant bits
m = 0, // number of aces in the hand
t, // used as a temporary variable at first, later stores the trump suit
n = 0, // number of jacks in the hand
a[] = new int[8]; // in the lower 4 indices, stores the number of non-jack cards present in the hand for each suit; in the higher 4 indices, stores the number of aces present in the hand for each suit (0 or 1)
for(var c : h) { // loop over all the cards in the hand
t = c[1] - 48; // determine the suit of the current card; 48 is the ASCII code for '0'
if(c[0] == 74) { // if it's a jack; 74 is the ASCII code for 'J'
j += 1 << t; // set the corresponding bit
n++; // and increment the total number of jacks
} else { // if it's not a jack
m += (i = (c[0] == 65 ? 1 : 0)); // increment the total number of aces if it's an ace (65 is the ASCII code for 'A')
a[ --t + 4] += i; // increment the number of aces for this suit if it's an ace
a[t]++; // increment the number of non-jack cards for this suit
}
}
for(i = t = 0; i < 4; i++) // loop over the suits ...
t = (a[i] < a[t]) ? t : i; // ... and find the one with the most cards, giving priority to higher-valued suits in case of a tie
return (a[t] + n < 6) | // if there are less than 6 trump cards
(m - a[t + 4] < 1) ? // or less than 1 non-trump ace
"p" // return "p" to pass on the hand
: // else return
((t++ + 9) * // the value of the trump suit (and increment the trump suit for output later)
(5 - (int) (Math.log((j > 7) ? (~j & 7) : j) / Math.log(2))) // times the jack factor
+ " " + t); // followed by the trump suit
}
```
[Answer]
# C, 235 bytes
```
f(char*h){int i,j=1,m=0,t,n=0,a[8]={0};for(;*h;h+=2){t=h[1]-48;if(*h-74){m+=i=*h==65;a[--t+4]+=i;a[t]++;}else{j+=1<<t;n++;}}for(i=t=0;i<4;i++)t=a[i]<a[t]?t:i;printf(a[t]+n<6|m-a[t+4]<1?"p":"%d %d",(t+9)*(5-(int)log2(j>7?~j&7:j)),t+1);}
```
Port of my Java [answer](https://codegolf.stackexchange.com/a/164501/79343).
Try it online [here](https://tio.run/##fY5NT4NAGITP@isIiWaXhbhfLdBlbYgX054ajw2HlZayBJCU9YT408XFj4PReHnzZjLPzOTBKc@nqQB5qc5eCQfdGkf7lSR@I7Fv/NZetY8yOeBRFE9nILxSlEhSOBhZ7kkW8EjoAnhlEHI4NEhq6ZVSLhdC7YPAIJ5Zyf4mQ0iMx7o/DhWSJEmMaGdlnEO1NBILnXChEYJGqr3OkplZm5UW3dmuKsBHRpssX5rAvjY4IWu3c1fu1cG5Org@MCiGHlgEwNph/XSioLoN16/VdbiqIPQNIlCMU6N0C6AzXF4UwN3wDduQlG95zFMW0h2JiAuFc3PjsKVzVz8/9pcX3bPpgWvlT4SkDLMt27GYRSwlkUW/EM6dh04djr8ZuiEzE/OI7@iWpiT@rulU/2fFXIDnChISbKF/7CnFNnNHYxrSlGM@7/uyL7Bzf1Rn84MZp7e8qNWpn4K6eQc).
Takes input as an array of characters in the format `A4`, where `4` is *Clubs*, `3` is *Spades*, `2` is *Hearts* and `1` is *Diamonds*. Output is `36 4` for a bid of 36 with trump suit *Clubs*, `p` for passing.
Ungolfed version:
```
f(char* h) { // function taking an array of characters as argument (and implicitly returning an unused int)
int i, // used as a loop variable and as a temporary variable
j = 1, // variable storing the jacks present in the hand in its four last-to-least significant bits
m = 0, // number of aces in the hand
t, // used as a temporary variable at first, later stores the trump suit
n = 0, // number of jacks in the hand
a[8] = {0}; // in the lower 4 indices, stores the number of non-jack cards present in the hand for each suit; in the higher 4 indices, stores the number of aces present in the hand for each suit (0 or 1); partially initialized to zero, the compiler will do the rest
for(; *h; h += 2) { // loop over all the cards in the hand
t = h[1] - 48; // determine the suit of the current card; 48 is the ASCII code for '0'
if(*h - 74) { // if it's not a jack; 74 is the ASCII code for 'J'
m += (i = (*h == 65)); // increment the total number of aces if it's an ace (65 is the ASCII code for 'A')
a[ --t + 4] += i; // increment the number of aces for this suit if it's an ace
a[t]++; // increment the number of non-jack cards for this suit
} else { // if it's a jack
j += 1 << t; // set the corresponding bit
n++; // and increment the total number of jacks
}
}
for(i = t = 0; i < 4; i++) // loop over the suits ...
t = a[i] < a[t] ? t : i; // ... and find the one with the most cards, giving priority to higher-valued suits in case of a tie
printf( (a[t] + n) < 6 | // if there are less than 6 trump cards
(m - a[t + 4] < 1) ? // or less than 1 non-trump ace
"p" : "%d %d", // print "p" to pass on the hand, else print two numbers
(t + 9) * // first the value of the trump suit ...
(5 - (int) log2((j > 7) ? (~j & 7) : j)), // ... times the jack factor,
t + 1 ); // followed by the trump suit
}
```
]
|
[Question]
[
**Closed.** This question is [off-topic](/help/closed-questions). It is not currently accepting answers.
---
Questions without an **objective primary winning criterion** are off-topic, as they make it impossible to indisputably decide which entry should win.
Closed 2 years ago.
[Improve this question](/posts/230111/edit)
The task is to provide code that evaluates to 0.5 numerically, i.e. the output must be recognized by your chosen language as a numeric value (Number, float, double, etc), not as a string. The catch, the characters 0 through to 9 cannot be used.
PLEASE NOTE: This IS NOT a golfing challenge, this is a popularity contest, so creative answers are encouraged. The more obscure and convoluted answers are also encouraged.
One example that fits the brief would be the following:
`((++[[]][[~~""]]<<++[[]][[~~""]]))**((--[[]][[~~""]]))` which works out to 0.5 in JavaScript.
A bounty of 150 will be awarded as an added incentive for the most voted creative answer. Good luck!
Any questions, feel free to ask.
[Answer]
# [Jelly](https://github.com/DennisMitchell/jelly), 177 bytes
```
Never gonna give you up,
Never gonna let you down,
Never gonna run around and desert you.
Never gonna make you cry,
Never gonna say goodbye,
Never gonna tell a lie and hurt you.
```
[Try it online!](https://tio.run/##VY5BDsMwCATvfQUPqPqU/IHWqzSJCxEJqXi9Yzk91AckxKyGnZFzlDLggNGoIkzjdIBCnXy93/5Bxt7uSb/SE3MhNnVJxHUSNljLPrrYh5fL/LLoBRtH3TQ9Az3Yaz@qryc089t/3lJO "Jelly – Try It Online")
Explanation thanks to caird coinheringaahing.
```
Never gonna give you up, Helper Link; never called
Never gonna let you down, Helper Link; never called
Never gonna run around and desert you. Helper Link; never called
Never gonna make you cry, Helper Link; never called
Never gonna say goodbye, Helper Link; never called
Never gonna tell a lie and hurt you. Main Link
Never gonna tell a lie and hurt yo Random stuff that doesn't matter
u Undefined so everything before it gets trashed
. 0.5
```
... yeah. Not that exciting when you see how it works.
[Answer]
# [Perl 5](https://www.perl.org/)
```
Once upon a midnight dreary, while "I pondered", !weak and weary;
Over many a quaint and curious volume of for@gotten, @lore;
While I nodded, nearly napping, until /|there came a tapping|/;
As if someone ? ${!gently} = "rapping" ^ "rapOing at": my $chamber, $door;
"Tis some visitor", I-muttered, "tapping at my chamber door";
print unpack f, ${!this} and nothing x more
```
[Try it online!](https://tio.run/##LVA9T8MwEN3zK16tjkadWIgQZezUBYkNycSXxKp9Fxy7JaL97cFJuz3p3fu6gaJ/nucjN4Q8CMMgOMuu6xNsJBMnjUvvPEEdUHhLkazS2FzInGDY4rIc1dXxTBHB8FQcfrJxnFa2ydFJHnEWnwNBWrQS952kRKyx9xKprj7XgANYrCWrwcXST2AzDI47jczJeeyuqS/paEwxMkh39rqrq/cRrsUogYQJb9j@bTri5KcbXqHi/VDha8XHgmGSekGYsG16E74pamytSKwr9eHG1QlnN7oksWw9PIVc@salmnrEFodF/5BjEau6GuKyO/NgmhNavRRJvRtv6ytYCi7KX4Syep7/AQ "Perl 5 – Try It Online")
Ah, distinctly I remember it was in the bleak December;
And each separate dying ember wrought its ghost upon the floor.
### Explanation / Spoiler:
Perl has a feature called 'barewords', which allows alphanumeric sequences to automatically be parsed as strings. This means that something like
```
foo bar baz
```
Will parse as valid Perl, but give a runtime error. However, if we can avoid Perl evaluating it, we can avoid the runtime error. The following program will run without any error:
```
foo bar baz while 0
```
Now let's have a look line by line:
```
Once upon a midnight dreary, while "I pondered", !weak and weary;
```
`"I pondered", !weak and weary` evaluates essentially to `("I pondered", false)` which is falsy so the stuff on the left hand side of the while loop does not get evaluated.
```
Over many a quaint and curious volume of for@gotten, @lore;
```
This is a `for` loop over the lists `@gotten` and `@lore`, which are empty, so the left hand side doesn't get evaluated.
```
While I nodded, nearly napping, until /|there came a tapping|/;
```
This is an `until` loop, where `/|there came a tapping|/` is a regex matching against `$_`. Even though `$_` is empty, the leading `|` matches against the empty string so the match becomes truthy so we don't evaluate the left hand side.
```
As if someone ? ${!gently} = "rapping" ^ "rapOing at": my $chamber, $door;
```
`if` is a keyword here. `someone` is a bareword which is truthy, so we evaluate `${!gently} = "rapping" ^ "rapOing at"`, which sets `${''}` to the string `"\0\0\0?\0\0\0 at"`. `my $chamber, $door` parses as a function call which is never evaluated, so there's no error.
```
"Tis some visitor", I-muttered, "tapping at my chamber door";
```
`I` and `muttered` are both barewords.
```
print unpack f, ${!this} and nothing x more
```
This parses as `(print unpack f, ${!this}) and nothing x more`. `${!this}` is `${''}`, which is our string from earlier. `unpack f` is a function that unpacks a single 32 bit float from a packed 4 byte representation. The first 4 bytes of `${''}` are `"\0\0\0?"`, which happens to be a valid representation of `0.5`. The rest of the string is ignored.
Since `(print unpack f, ${!this})` is truthy, the right hand side of the `and` is evaluated. `x` is the string repeat operator, and `nothing` and `more` are both barewords, so there's no error generated.
[Answer]
# [Raku](https://github.com/nxadm/rakudo-pkg), 5 bytes
```
π/τ
```
[Try it online!](https://tio.run/##K0gtyjH7X5xYqfD/fIP@@Zb//wE "Perl 6 – Try It Online")
The constant Pi divided by Tau is, of course, `1/2`. An alternative without the pesky unicode is to spell it out like `pi/tau`.
[Answer]
# Python 3, 117 bytes
[Try it online!](https://tio.run/##ZcgxDsIwDAXQq2SzP4J2YGODi1hBaSESsSOTDl24ekBl7Pb06tqepufeq2dtzK9Y7ikGvbgtmvi9FBbJpZo3ESaPmqwQhj8Ys3mQkDX84jGxAqMezRPTjXDacCUAvPFDOOwA9P4F "Python 3 – Try It Online")
```
(lambda n:round(sum(__import__('random').random()for _ in range(n))/n,ord('B')-ord('A')))(ord('~')*ord('~')*ord('~'))
```
This takes the average of a bunch of random numbers in the range 0-1 then rounds it. There is a *very* small chance this does not evaluate to 0.5
[Answer]
# [Vyxal](https://github.com/Lyxal/Vyxal), 122 bytes
```
H H AAAAA L FFFFF
H H A A L F
HHHHH AAAAA L FFFFF
H H A A L F
H H A A LLLLL ¬Ω
```
[Try it Online!](http://lyxal.pythonanywhere.com?flags=&code=H%20%20%20H%20%20AAAAA%20%20L%20%20%20%20%20%20FFFFF%0AH%20%20%20H%20%20A%20%20%20A%20%20L%20%20%20%20%20%20F%0AHHHHH%20%20AAAAA%20%20L%20%20%20%20%20%20FFFFF%0AH%20%20%20H%20%20A%20%20%20A%20%20L%20%20%20%20%20%20F%0AH%20%20%20H%20%20A%20%20%20A%20%20LLLLL%20%20%C2%BD&inputs=&header=&footer=)
You asked for half, so I've given you half in more ways than 1 (/2).
This relies on the fact that most things here are NOPS and that getting the length of a number works.
The real work comes when we get to the `L`s in the bottom row: the first `L` is passed, 0, which has length 1. The next 4 `L`s all return 1 because the length of 1 is 1. The `¬Ω` then divides that 1 by 2.
[Answer]
# [Jelly](https://github.com/DennisMitchell/jelly), "HALF OF ONE"
Yes, Jelly can output half of one with just `.` but did you know there is a secret verbose mode with a certain lexicon of ***reversed English***?
```
ENO FO FLAH
```
**[Try it online!](https://tio.run/##y0rNyan8/9/Vz1/BDYh8HD3@/wcA "Jelly – Try It Online")**
### How?
OK, so I lied.
```
ENO FO FLAH - Link: no arguments (implicit 0)
E - (implicit [0]) all equal? -> 1
N - negate -> -1
O - ordinal (a no-op with numeric input) -> -1
F - flatten -> [-1]
O - ordinal (vectorises; again a no-op) -> [-1]
F - flatten -> [-1]
L - length -> 1
A - absoulte value -> 1
H - halve -> 0.5
```
[Answer]
# [Jelly](https://github.com/DennisMitchell/jelly), 1 byte
```
.
```
[Try it online!](https://tio.run/##y0rNyan8/1/v/38A "Jelly – Try It Online")
I know it isn't golf, but why be creative when the tools are provided for you?
`.` is a decimal literal in Jelly. When the values before the `.` is omitted, it defaults to `0` and after it defaults to `5`. Therefore `.` is just `0.5`
[Answer]
# [BQN](https://mlochbaum.github.io/BQN/)
A.k.a "the worm".
```
=⊸÷⟜≠⌾‿⌾
```
[Try it!](https://mlochbaum.github.io/BQN/try.html#code=PeKKuMO34p+c4omg4oy+4oC/4oy+)
Produces a 2-element list consisting of two built-ins (`‚åæ`), then divides the rank (1) by the length (2).
Various superfluous parentheses and no-ops can be added for style:
`(=÷≠)(⌾‿⌾)`
`=(⊸)(÷⟜≠)(⌾‿⌾)`
`⊣(=)(⊸)(÷⟜≠)(⌾‿⌾)`
`(=)(⊸)(÷)(⟜)(≠)(⌾‿⌾)`
Or how about the chicken and the owl:
`(≡÷≠)⊢⟨˙⋄˙⟩`
`(≡÷≠)⊢⟨⌾,⌾⟩`
[Answer]
# C (GCC, MIPS)
```
// A very mysterious function
float mystery()
{
// A very mysterious string
char whaaaaaa['?'] = "?";
// A very mysterious cast
return *(float *)whaaaaaa;
}
```
>
> If you want to test it on a non-based x86 or ARM CPU, try `htonl('?')`.
>
>
>
#### Explanation
>
> The reason I choose MIPS is because I wanted it to be big endian.
>
> The convenient thing about 0.5f is it is represented as `0x3f000000`. `0x3f` is `?` in ASCII.
>
> The string will be stored as `3f 00 00 00 ...` in memory, and dereferencing it on a big endian machine will conveniently result in `0x3f000000`.
>
>
>
[Answer]
# [Wolfram Language (Mathematica)](https://www.wolfram.com/mathematica/), 75 bytes
```
ElementData["Hydrogen","AtomicNumber"]/ElementData["Helium","AtomicNumber"]
```
The atomic numbers of hydrogen and helium are exactly 1 and 2, respectively. Atomic masses aren't exact (except for carbon-12's, by defintion, when expressed in daltons), but atomic numbers are, since they're simply the number of protons in the atoms of the element.
[Not sure how to get this working in TIO, or if solutions requring a server connection are allowed in popularity contests.]
[Answer]
# JavaScript, 67 bytes
Abuses the fact that `undefined` is a valid identifier in JS.
```
undefined=>(undefined=>undefined/(undefined+undefined))(!undefined)
```
[Try it online!](https://tio.run/##y0osSyxOLsosKNEts/ifnJ9XnJ@TqpeTn66h8b80LyU1LTMvNcXWTgOJDWfqI0S14SxNTQ1FBOe/poam5n8A)
[Answer]
# [Python 3](https://docs.python.org/3/), 420 bytes
```
from math import*
H=lambda n:int(n,int(sqrt(ord('Ā'))))
o=ord
print(round(sin(H('d')*pi/(H('d')-H('a')))*cos(H('d')*pi/(o('G')-ord('A')))-sin(H('b')*pi/(o('G')-ord('A')))*cos(-(H('f')-H('a'))*pi/(H('d')-H('a'))))/(round((sin(pi/(o('h')-o('a')))*(pi/(o('h')-o('a'))))+(sin((H('f')-H('a'))*pi/H('e'))*(H('f')-H('a'))*pi/H('e'))+(sin(sqrt(o('@'))*pi/((o('h')-ord('a'))))**(H('d')-H('a')))+(sin(sqrt(o('Q'))*pi/H('e'))))))#
```
[Try it online!](https://tio.run/##dVC7DsIgFN37FU0ceGjTwc2kiU529ROo2JREHlIc3Pw4/wu5lKo17R3gwnncA@bhOq223rdWy1wy1@VCGm0dzerqymTDWa52QjmsNrD2N@uwthyj1xORUJmuwjEzFlCr74rjXihcY8QRoUaUqS3CxkBBz7r/hTVGxwBHzwMQiqRvlgjRoQBK@/WdG0XKlChGSl4deI1Z5i7JOtJn/EN7gXYZGqTDJ2G0H3N9RsAbhiGU/qedak9TY6iV928 "Python 3 – Try It Online")
Directly from my math book. Solving it by bare hands was a big pain. But writing this answer from mobile was fun. oh plus got a nice byte count.
$$
\frac{\sin \frac{13\pi}{3}\cos
\frac{13\pi}{6}-\sin \frac{11\pi}{6}\cos \left(-\frac{5\pi}{3}\right)}{
\sin^2\frac{7\pi}{3}+\sin^2\frac{5\pi}{14}+\sin^2\frac{8\pi}{7}+\sin^2\frac{9\pi}{4}}=0.5
$$
[Answer]
# [Jelly](https://github.com/DennisMitchell/jelly), 10 bytes
```
Ænɓ,ÆṛUÆrḢ
```
[Try it online!](https://tio.run/##ARsA5P9qZWxsef//w4ZuyZMsw4bhuZtVw4Zy4bii//8 "Jelly – Try It Online")
I already made an answer that fits with Jelly's ability to be short. How about an answer about Jelly's ability to have stupidly convoluted builtins?
We construct the polynomial \$4x^2 - 4x + 1\$, then solve it as equal to \$0\$, giving \$x = \frac 1 2\$
## How it works
```
Ænɓ,ÆṛUÆrḢ - Main link. Takes no arguments
Æn - Next prime after zero; 2
…ì - New dyadic chain f(2,2):
, - Pair; [2,2]
Æṛ - Construct the polynomial with the roots 2, 2: [4,-4,1]
U - Reverse; [1,-4,4]
Ær - Get the roots of this polynomial; [0.5, 0.5]
·∏¢ - Get the first element
```
Why use 1 byte when lot byte do trick?
[Answer]
# [Ruby](https://www.ruby-lang.org/)
Line number trickery.
```
p __LINE__ -
__LINE__ **-
__LINE__ *
__LINE__ .
to_f
```
[Try it online!](https://tio.run/##KypNqvz/v0AhPt7H0881Pl5Bl0sBwdHSQuUic/SAnJL8@LT//wE "Ruby – Try It Online")
### Explanation
`__LINE__` is a global constant which stores the current line number. As such, the program can be rewritten into one line as: `p 1-2**-3*4.to_f`, which just so happens to evaluate to `0.5`. The `.to_f` is needed to cast the result to a float (otherwise `(1/2)` is printed).
[Answer]
# [Dyalog APL](https://dyalog.com)
```
÷∊⊆⊂∪⊃⊢⊣⊥⍨⍲⍀∨\⍱⌿∧/↑↓⍎⍕⍋⍒⍸⍴⍪,⍉⊖⌽⌹|⌈⌊*¨⍟⍤○⍥!×+~-≢⍬⍝
```
EDIT: I've updated the picture & text, but not the link nor the explanation.
[Try it online!](https://razetime.github.io/APLgolf/?h=AwA&c=DczPCgFhFIfha7H1JzfkUiRRX2eO81OIWUkN00yTDSkspMydvFdi9k9P@8QcT/gCa/AlXuBnvEQ1uqM5uhFfrJ5g1Zi0Ie3QGu3RCm3RCz1QM0QZfiA@xHtKGOH9X7ec0IW8s2WvzQezEVmBruj4Bw&f=AwA&i=AwA&r=tryAPL&l=apl-dyalog&m=dfn&n=%E2%8E%95)
Uses as many unique primitives as I had the patience to cram in. Andvmany thanks to Ad√°m for giving me a bunch more to cram in! It looks cooler with a proper APL font:
[](https://i.stack.imgur.com/4HcoG.png)
(That is, as many primitives as I could use in a linear chain of execution without parentheses. I'm sure you can use every single one if you allow parentheses, as that opens up the dyadic functions.)
### Explanation
```
√∑ Inverse -> 1/2
‚Üë Mix -> 2
‚Üì Split -> 2
⊃ First -> 2
‚à™ Unique -> 2
⊂ Enclose -> 2
⊣ Same (left) -> 2
⊢ Same (right) -> 2
‚à®\ Scan with GCD -> 2
‚àß/ Reduce with LCM -> 2
‚ç∏ Where -> [1,2]
⍴ Shape -> [1,1]
‚ç™ Table -> 3
, Ravel -> 3
‚çâ Transpose -> 3
‚äñ Horizontal flip -> 3
‚åΩ Vertical flip -> 3
| Absolute value -> 3
‚åà Ceiling -> 3
‚åä Floor -> 3
* Exponent -> 3.14159
¨ Map -> 1.14472
‚çü Natural logarithm -> 1.14472
‚ç§ Atop -> 3.14159
‚óã Pi times -> 3.14159
‚ç• Over -> 1
! Factorial -> 1
√ó Direction -> 1
+‚ç® Add to itself -> 2
~ NOT -> 1
- Negate -> 0
‚àä Enlist -> 0
≢ Length -> 0
⍬ Empty list -> []
```
[Answer]
# [Perl 6](https://github.com/nxadm/rakudo-pkg)
```
say ¬Ω
```
[Try it online!](https://tio.run/##K0gtyjH7/784sVLh0N7//wE "Perl 6 – Try It Online")
Doesn't need explanation, does it?
[Answer]
# [Pyth](https://github.com/isaacg1/pyth), 4 bytes
```
cTyT
```
[Try it here!](http://pythtemp.herokuapp.com/?code=cTyT&debug=0)
Divides ten by twice ten.
[Answer]
# [C (gcc)](https://gcc.gnu.org/), 30 bytes
```
float f(){float x=' ';x/='@';}
```
[Try it online!](https://tio.run/##S9ZNT07@/z8tJz@xRCFNQ7MawqqwVVdQt67Qt1V3ULeu/Z@ZV6KQm5iZp6HJVc2lAAQFRUChNA0l1bSYPCUdkEZNa67a//@S03IS04v/65YDAA "C (gcc) – Try It Online")
Because \$x\$ is a `float` the characters `' '` (\$32\$) and `'@'` (\$64\$) get converted to floating point numbers. Then the GCC trick of returning the last calculation is used to return \$\frac{1}{2}\$.
[Answer]
# [APL (Dyalog Extended)](https://github.com/abrudz/dyalog-apl-extended)
```
#÷⍥≢⍬⍬
```
[Try it online!](https://tio.run/##SyzI0U2pTMzJT9dNrShJzUtJTfn/qKO94L/y4e2Pepc@6lz0qHcNEIEE/yuAQQEA "APL (Dyalog Extended) – Try It Online")
Divides the length of a reference to the root namespace (1) by the length of `[[],[]]` (2).
[Answer]
# [APL (dzaima/APL)](https://github.com/dzaima/APL)
```
⎕←⌈∘○⍢÷*≢~≢⍬
```
[Try it online!](https://tio.run/##SyzI0U2pSszMTfz//1Hf1EdtEx71dDzqmPFoevej3kWHt2s96lxUB8SPetf8/w8A "APL (dzaima/APL) – Try It Online")
`⍬` the empty list; `[]`
`≢` its length; `0`
`~`‚ÄÉlogical NOT; `1`
`*` *e* to the power of that; `2.71828…`
…`⍢÷` while inverted; `0.36787…`
 `∘○` multiply by π; `1.15572…`
‚ÄÉ`‚åà`‚ÄÉround up; `2`
Then we "un-invert"; `0.5`
[Answer]
# Desmos, 686 bytes
```
f\left(x\right)=\frac{\frac{\left(\csc x\right)\left(\csc x\right)-\left(\cot x\right)\left(\cot x\right)}{\left(\sin x\right)\left(\sin x\right)}-\frac{\left(\sec x\right)\left(\sec x\right)-\left(\tan x\right)\left(\tan x\right)-\left(\sin x\right)\left(\sin x\right)}{\left(\sec x\right)\left(\sec x\right)-\left(\tan x\right)\left(\tan x\right)-\left(\cos x\right)\left(\cos x\right)}}{\sin\left(\arcsin\left(\left(\cos x\right)\left(\cos x\right)-\cos\left(x+x\right)+\left(\left(\left(\sec x\right)\left(\sec x\right)-\left(\tan x\right)\left(\tan x\right)\right)\left(\cos x\right)\right)\left(\left(\left(\sec x\right)\left(\sec x\right)-\left(\tan x\right)\left(\tan x\right)\right)\left(\cos x\right)\right)\right)\right)+\left(\csc x\right)\left(\csc x\right)-\left(\cot x\right)\left(\cot x\right)}
```
Or rendered properly:
\$f\left(x\right)=\frac{\frac{\left(\csc x\right)\left(\csc x\right)-\left(\cot x\right)\left(\cot x\right)}{\left(\sin x\right)\left(\sin x\right)}-\frac{\left(\sec x\right)\left(\sec x\right)-\left(\tan x\right)\left(\tan x\right)-\left(\sin x\right)\left(\sin x\right)}{\left(\sec x\right)\left(\sec x\right)-\left(\tan x\right)\left(\tan x\right)-\left(\cos x\right)\left(\cos x\right)}}{\sin\left(\arcsin\left(\left(\cos x\right)\left(\cos x\right)-\cos\left(x+x\right)+\left(\left(\left(\sec x\right)\left(\sec x\right)-\left(\tan x\right)\left(\tan x\right)\right)\left(\cos x\right)\right)\left(\left(\left(\sec x\right)\left(\sec x\right)-\left(\tan x\right)\left(\tan x\right)\right)\left(\cos x\right)\right)\right)\right)+\left(\csc x\right)\left(\csc x\right)-\left(\cot x\right)\left(\cot x\right)}\$
[Try it online!](https://www.desmos.com/calculator/5jlojbydjf) Defines a function f that will return 0.5 no matter what you put into it, pretty much. It will barf on multiples of π/2 though. Sorry if Desmos lags a bit.
[Answer]
# [Desmos](https://www.desmos.com/calculator), ~~14~~ 7 bytes
```
e/(e+e)
```
[Try it on Desmos!](https://www.desmos.com/calculator/jsi7cvuzau)
[Answer]
# [Python 3](https://python.org), 71 bytes
```
from http import HTTPStatus
print(HTTPStatus.OK/HTTPStatus.BAD_REQUEST) # 200/400
```
[Answer]
# [Wolfram Language (Mathematica)](https://www.wolfram.com/mathematica/), 35/12 bytes
```
Limit[(-I*I-Cos[x])/(x*x),x->I/‚àû]
```
The starting point for this is the following limit:
$$\lim\_{x\rightarrow 0}\frac{1-\cos(x)}{x^2} = \frac{1}{2}$$
To eliminate the numbers, I then replaced 0 with ⅈ/∞, 1 with –ⅈ^2, and x^2 with x\*x:
$$\lim\_{x\rightarrow i/\infty}\frac{-i^2-\cos(x)}{x\*x} = \frac{1}{2}$$
Or, less fancy:
```
-I*I/Floor@E
```
$$\frac{-i\*i}{\lfloor e \rfloor} = \frac{1}{\lfloor \approx 2.718 \rfloor} =\frac{1}{2}$$
[Wasn't sure if the etiquette is to combine this with my previous answer or post separately but, following Caird's example, I did the latter.]
[Answer]
# JSFuck, 2443 bytes
```
[][(![]+[])[+[]]+(![]+[])[!+[]+!+[]]+(![]+[])[+!+[]]+(!![]+[])[+[]]][([][(![]+[])[+[]]+(![]+[])[!+[]+!+[]]+(![]+[])[+!+[]]+(!![]+[])[+[]]]+[])[!+[]+!+[]+!+[]]+(!![]+[][(![]+[])[+[]]+(![]+[])[!+[]+!+[]]+(![]+[])[+!+[]]+(!![]+[])[+[]]])[+!+[]+[+[]]]+([][[]]+[])[+!+[]]+(![]+[])[!+[]+!+[]+!+[]]+(!![]+[])[+[]]+(!![]+[])[+!+[]]+([][[]]+[])[+[]]+([][(![]+[])[+[]]+(![]+[])[!+[]+!+[]]+(![]+[])[+!+[]]+(!![]+[])[+[]]]+[])[!+[]+!+[]+!+[]]+(!![]+[])[+[]]+(!![]+[][(![]+[])[+[]]+(![]+[])[!+[]+!+[]]+(![]+[])[+!+[]]+(!![]+[])[+[]]])[+!+[]+[+[]]]+(!![]+[])[+!+[]]]((!![]+[])[+!+[]]+(!![]+[])[!+[]+!+[]+!+[]]+(!![]+[])[+[]]+([][[]]+[])[+[]]+(!![]+[])[+!+[]]+([][[]]+[])[+!+[]]+(+[![]]+[][(![]+[])[+[]]+(![]+[])[!+[]+!+[]]+(![]+[])[+!+[]]+(!![]+[])[+[]]])[+!+[]+[+!+[]]]+(!![]+[])[!+[]+!+[]+!+[]]+(+(!+[]+!+[]+!+[]+[+!+[]]))[(!![]+[])[+[]]+(!![]+[][(![]+[])[+[]]+(![]+[])[!+[]+!+[]]+(![]+[])[+!+[]]+(!![]+[])[+[]]])[+!+[]+[+[]]]+([]+[])[([][(![]+[])[+[]]+(![]+[])[!+[]+!+[]]+(![]+[])[+!+[]]+(!![]+[])[+[]]]+[])[!+[]+!+[]+!+[]]+(!![]+[][(![]+[])[+[]]+(![]+[])[!+[]+!+[]]+(![]+[])[+!+[]]+(!![]+[])[+[]]])[+!+[]+[+[]]]+([][[]]+[])[+!+[]]+(![]+[])[!+[]+!+[]+!+[]]+(!![]+[])[+[]]+(!![]+[])[+!+[]]+([][[]]+[])[+[]]+([][(![]+[])[+[]]+(![]+[])[!+[]+!+[]]+(![]+[])[+!+[]]+(!![]+[])[+[]]]+[])[!+[]+!+[]+!+[]]+(!![]+[])[+[]]+(!![]+[][(![]+[])[+[]]+(![]+[])[!+[]+!+[]]+(![]+[])[+!+[]]+(!![]+[])[+[]]])[+!+[]+[+[]]]+(!![]+[])[+!+[]]][([][[]]+[])[+!+[]]+(![]+[])[+!+[]]+((+[])[([][(![]+[])[+[]]+(![]+[])[!+[]+!+[]]+(![]+[])[+!+[]]+(!![]+[])[+[]]]+[])[!+[]+!+[]+!+[]]+(!![]+[][(![]+[])[+[]]+(![]+[])[!+[]+!+[]]+(![]+[])[+!+[]]+(!![]+[])[+[]]])[+!+[]+[+[]]]+([][[]]+[])[+!+[]]+(![]+[])[!+[]+!+[]+!+[]]+(!![]+[])[+[]]+(!![]+[])[+!+[]]+([][[]]+[])[+[]]+([][(![]+[])[+[]]+(![]+[])[!+[]+!+[]]+(![]+[])[+!+[]]+(!![]+[])[+[]]]+[])[!+[]+!+[]+!+[]]+(!![]+[])[+[]]+(!![]+[][(![]+[])[+[]]+(![]+[])[!+[]+!+[]]+(![]+[])[+!+[]]+(!![]+[])[+[]]])[+!+[]+[+[]]]+(!![]+[])[+!+[]]]+[])[+!+[]+[+!+[]]]+(!![]+[])[!+[]+!+[]+!+[]]]](!+[]+!+[]+!+[]+[!+[]+!+[]])+(![]+[])[+!+[]]+(![]+[])[!+[]+!+[]])()((![]+[])[+!+[]]+(![]+[])[!+[]+!+[]]+(!![]+[])[!+[]+!+[]+!+[]]+(!![]+[])[+!+[]]+(!![]+[])[+[]]+([][(![]+[])[+[]]+(![]+[])[!+[]+!+[]]+(![]+[])[+!+[]]+(!![]+[])[+[]]]+[])[+!+[]+[!+[]+!+[]+!+[]]]+[+[]]+(+(+!+[]+[+!+[]]+(!![]+[])[!+[]+!+[]+!+[]]+[!+[]+!+[]]+[+[]])+[])[+!+[]]+[!+[]+!+[]+!+[]+!+[]+!+[]]+([+[]]+![]+[][(![]+[])[+[]]+(![]+[])[!+[]+!+[]]+(![]+[])[+!+[]]+(!![]+[])[+[]]])[!+[]+!+[]+[+[]]])
```
Quite big
[Answer]
# [Factor](https://factorcode.org/) + `math.unicode`
```
¬Ω .
```
[Try it online!](https://tio.run/##S0tMLskv@h8a7OnnbqWQm1iSoVeal5mcn5KqUFCUWlJSWVCUmVeiYP3/0F4Fvf//AQ "Factor – Try It Online")
---
Or, slightly more interesting: since Factor has a *ton* of constants and helper words named `a`, `b`, `c`, etc. in private vocabularies, I thought it would be fun to see how far down the alphabet I had to go before arriving at a solution. Turns out not very far. I struck gold with the word `a` from the `math.finance.private` vocabulary which is defined as `: a ( n -- a ) 1 + 2 swap / ; inline` Or, in math terms: \$a(n)=\frac{2}{n+1}\$. Then, I just had to find a value of \$3\$ which turns out to be defined in `checksums.md5.private` as `CONSTANT: d 3 inline`. So:
# [Factor](https://factorcode.org/) + `math.finance.private checksums.md5.private`
```
d a .
```
[Try it online!](https://tio.run/##S0tMLskv@h8a7GqlUFCUWlJSWVCUmVfC5Rbk72ulkJtYkqGXlpmXmJecqgeUKEssSVWwtVNIVLCGqkjOSE3OLi7NLdbLTTFFVpKiYP0/BahQ7/9/AA "Factor – Try It Online")
[Answer]
# [J](http://jsoftware.com/), 11 bytes
```
_"_-:@-:_"_
```
[Try it online!](https://tio.run/##y/qvpKeepmBrpaCuoKNgoGAFxLp6Cs5BPm7/45Xida0cdK2A9H9NrtTkjHyFNAV19f8A "J – Try It Online")
* In J, `-:`, as a dyadic verb, means "do the two things match?" and, as a monadic verb, means "half".
* `_` is the literal symbol for infinity. Adding `"_` turns it into a verb of infinite rank that always returns the value infinity. This is required syntactically for the right version of `_"_`, and we add it to the left one for symmetry.
* Now, for any argument, the verb checks if `_` is equal to `_`, and always returns 1. And half of 1 is 0.5.
[Answer]
# [APL (Dyalog Unicode)](https://www.dyalog.com/)
```
(+-÷)⍨⍣(×≡#⍬)≢⍬
```
[Try it online!](https://tio.run/##SyzI0U2pTMzJT///qKO94L@Gtu7h7ZqPelc86l2scXj6o86Fyo9612g@6lwEpEBK/iuAQQEA "APL (Dyalog Unicode) – Try It Online")
`⍬` the empty list; `[]`
`≢` its length; 0
`(`…`)` compute:
 `#⍬` a literal; `[reference-to-root-namespace,[]]`
 `≡` the depth (nestedness) of that; `-1` (maximum depth is 1, but negative value indicates raggedness)
…`⍣` apply the following tacit function that many times (i.e. find an argument to the following function such that the result is 0 (from the length of the empty list above)
 `(`…`)⍨` apply this function with its sole argument as both left and right argument:
  `+-÷` the sum minus the ratio
Effectively solves \$x+x-x√∑x=0\$ or \$2x-1=0\$ which gives \$x=1√∑2=0.5\$.
[Answer]
# [Ly](https://github.com/LyricLy/Ly), 23 bytes
```
<<'<::+/u':':'u/+::<'<<
```
[Try it online!](https://tio.run/##y6n8/9/GRt3Gykpbv1TdCghL9bWtrIAiNv//AwA "Ly – Try It Online")
A reversible one just for fun...
```
<< # Shift stack left twice
'< # Push "<" on the stack
:: # Duplicate top of stack twice
+/ # Add then divide to get 0.5
u # Print as a number
# The rest of the code winds up being ignored... The code just
# has to be valid and not generate output.
':':'u # Push "::u" onto the stack
/+:: # Divide, add, then duplicate top of stack twice
< # Shift stack left
'< # Push "<" on the stack
< # Shift stack left (to an empty stack)
```
And another one that's a mirror image around a central point.
# [Ly](https://github.com/LyricLy/Ly), 21 bytes
```
<<'<::+/'upu'\+::>'>>
```
[Try it online!](https://tio.run/##y6n8/9/GRt3GykpbX720oFQ9RtvKyk7dzu7/fwA "Ly – Try It Online")
[Answer]
# [QBasic (QB64)](http://www.qb64.net/)
```
X = Y = Z
PRINT ATN(X) / ATN(X / Y)
```
>
> All variables in QBasic are initialized to 0. The first line is `X = (Y = Z)`, where the first `=` is assignment but the second `=` is comparison. Truthy is -1 in QBasic, so now `X` is -1. QB64 allows division by 0, returning floating point infinity (or in this case, negative infinity); \$\arctan(-1) = -\frac \pi 4\$, and \$\arctan(-\infty) = -\frac \pi 2\$.
>
>
>
]
|
[Question]
[
**Locked**. This question and its answers are [locked](/help/locked-posts) because the question is off-topic but has historical significance. It is not currently accepting new answers or interactions.
The challenge:
>
> Write a program or a function that inputs a positive number and returns its [factorial](http://en.wikipedia.org/wiki/Factorial).
>
>
>
Note: This is a [code-trolling](/questions/tagged/code-trolling "show questions tagged 'code-trolling'") question. Please do not take the question and/or answers seriously. More information [here](https://codegolf.stackexchange.com/tags/code-trolling/info "Rules"). Every [code-trolling](/questions/tagged/code-trolling "show questions tagged 'code-trolling'") question is also a [popularity-contest](/questions/tagged/popularity-contest "show questions tagged 'popularity-contest'") question, so the highest voted answer wins.
[Answer]
This is a very simple numerical computing problem that we can solve with [Stirling's approximation](https://en.wikipedia.org/wiki/Stirling%27s_approximation):

As you can see, that formula features a square root, which we will also need a way to approximate. We will choose the so-called ["Babylonian method"](https://en.wikipedia.org/wiki/Babylonian_method#Babylonian_method) for that because it is arguably the simplest one:

Note that computing the square root this way is a good example of recursion.
Putting it all together in a Python program gives us the following solution to your problem:
```
def sqrt(x, n): # not the same n as below
return .5 * (sqrt(x, n - 1) + x / sqrt(x, n - 1)) if n > 0 else x
n = float(raw_input())
print (n / 2.718) ** n * sqrt(2 * 3.141 * n, 10)
```
With a simple modification the above program can output a neat table of factorials:
```
1! = 0.92215
2! = 1.91922
3! = 5.83747
4! = 23.51371
5! = 118.06923
6! = 710.45304
7! = 4983.54173
8! = 39931.74015
9! = 359838.58817
```
This method should be sufficiently accurate for most applications.
[Answer]
## C#
Sorry, but I hate recursive function.
```
public string Factorial(uint n) {
return n + "!";
}
```
[Answer]
Java
```
public int factorial ( int n ) {
switch(n){
case 0: return 1;
case 1: return 1;
case 2: return 2;
case 3: return 6;
case 4: return 24;
case 5: return 120;
case 6: return 720;
case 7: return 5040;
case 8: return 40320;
case 9: return 362880;
case 10: return 3628800;
case 11: return 39916800;
case 12: return 479001600;
default : throw new IllegalArgumentException();
}
}
```
[Answer]
# Python
Of course the best way how to solve any problem is to use regular expressions:
```
import re
# adapted from http://stackoverflow.com/q/15175142/1333025
def multiple_replace(dict, text):
# Create a regular expression from the dictionary keys
regex = re.compile("(%s)" % "|".join(map(re.escape, dict.keys())))
# Repeat while any replacements are made.
count = -1
while count != 0:
# For each match, look-up corresponding value in dictionary.
(text, count) = regex.subn(lambda mo: dict[mo.string[mo.start():mo.end()]], text)
return text
fdict = {
'A': '@',
'B': 'AA',
'C': 'BBB',
'D': 'CCCC',
'E': 'DDDDD',
'F': 'EEEEEE',
'G': 'FFFFFFF',
'H': 'GGGGGGGG',
'I': 'HHHHHHHHH',
'J': 'IIIIIIIIII',
'K': 'JJJJJJJJJJJ',
'L': 'KKKKKKKKKKKK',
'M': 'LLLLLLLLLLLLL',
'N': 'MMMMMMMMMMMMMM',
'O': 'NNNNNNNNNNNNNNN',
'P': 'OOOOOOOOOOOOOOOO',
'Q': 'PPPPPPPPPPPPPPPPP',
'R': 'QQQQQQQQQQQQQQQQQQ',
'S': 'RRRRRRRRRRRRRRRRRRR',
'T': 'SSSSSSSSSSSSSSSSSSSS',
'U': 'TTTTTTTTTTTTTTTTTTTTT',
'V': 'UUUUUUUUUUUUUUUUUUUUUU',
'W': 'VVVVVVVVVVVVVVVVVVVVVVV',
'X': 'WWWWWWWWWWWWWWWWWWWWWWWW',
'Y': 'XXXXXXXXXXXXXXXXXXXXXXXXX',
'Z': 'YYYYYYYYYYYYYYYYYYYYYYYYYY'}
def fact(n):
return len(multiple_replace(fdict, chr(64 + n)))
if __name__ == "__main__":
print fact(7)
```
[Answer]
Haskell
Short code is efficient code, so try this.
```
fac = length . permutations . flip take [1..]
```
Why it's trolling:
I'd laugh at any coder who wrote this... The inefficiency is beautiful. Also probably incomprehensible to any Haskell programmer who actually can't write a factorial function.
Edit: I posted this a while ago now, but I thought I'd clarify for future people and people who can't read Haskell.
The code here takes the list of the numbers 1 to n, creates the list of all permutations of that list, and returns the length of that list.
On my machine it takes about 20 minutes for 13!.
And then it ought to take four hours for 14! and then two and a half days for 15!.
Except that at some point in there you run out of memory.
Edit 2: Actually you probably won't run out of memory due to this being Haskell (see the comment below). You might be able to force it to evaluate the list and hold it in memory somehow, but I don't know enough about optimizing (and unoptimizing) Haskell to know exactly how to do that.
[Answer]
## C#
Since this is a math problem, it makes sense to use an application specifically designed to solve math problems to do this calculation...
### Step 1:
Install MATLAB. A trial will work, I think, but this super-complicated problem is likely important enough to merit purchasing the full version of the application.
### Step 2:
Include the MATLAB COM component in your application.
### Step 3:
```
public string Factorial(uint n) {
MLApp.MLApp matlab = new MLApp.MLApp();
return matlab.Execute(String.Format("factorial({0})", n);
}
```
[Answer]
## C#
Factorials are a higher level math operation that can be difficult to digest all in one go. The best solution in programming problems like this, is to break down one large task into smaller tasks.
Now, n! is defined as 1\*2\*...\*n, so, in essence repeated multiplication, and multiplication is nothing but repeated addition. So, with that in mind, the following solves this problem:
```
long Factorial(int n)
{
if(n==0)
{
return 1;
}
Stack<long> s = new Stack<long>();
for(var i=1;i<=n;i++)
{
s.Push(i);
}
var items = new List<long>();
var n2 = s.Pop();
while(s.Count >0)
{
var n3 = s.Pop();
items.AddRange(FactorialPart(n2,n3));
n2 = items.Sum();
}
return items.Sum()/(n-1);
}
IEnumerable<long> FactorialPart(long n1, long n2)
{
for(var i=0;i<n2;i++){
yield return n1;
}
}
```
[Answer]
```
#include <math.h>
int factorial(int n)
{
const double g = 7;
static const double p[] = { 0.99999999999980993, 676.5203681218851,
-1259.1392167224028, 771.32342877765313,
-176.61502916214059, 12.507343278686905,
-0.13857109526572012, 9.9843695780195716e-6,
1.5056327351493116e-7 };
double z = n - 1 + 1;
double x = p[0];
int i;
for ( i = 1; i < sizeof(p)/sizeof(p[0]); ++i )
x += p[i] / (z + i);
return sqrt(2 * M_PI) * pow(z + g + 0.5, z + 0.5) * exp(-z -g -0.5) * x + 0.5;
}
```
Trolls:
* A 100% correct way of computing factorial that completely misses the point of either doing it iteratively or recursively.
* You have no idea why it works and could not generalize it to do anything else.
* More costly than just computing it with integer math.
* The most obvious "suboptimal" code (`z = n - 1 + 1`) is actually self-documenting if you know what's going on.
* For extra trolling I should compute `p[]` using a recursive calculation of the series coefficients!
(It's the [Lanczos approximation of the gamma function](http://en.wikipedia.org/wiki/Lanczos_approximation))
[Answer]
We all know from college that the most efficient way to calculate a multiplication is through the use of logarithms. After all, why else would people use logarithm tables for hundreds of years?
So from the identity `a*b=e^(log(a)+log(b))` we form the following Python code:
```
from math import log,exp
def fac_you(x):
return round(exp(sum(map(log,range(1,x+1)))))
for i in range(1,99):
print i,":",fac_you(i)
```
It creates a list of numbers from `1` to `x`, (the `+1` is needed because Python sucks) calculates the logarithm of each, sums the numbers, raises the e to the power of the sum and finally rounds the value to the nearest integer (because Python sucks). Python has a built-in function for calculating factorials, but it only works for integers, so it can't produce big numbers (because Python sucks). This is why the function above is needed.
Btw, a general tip for students is that if something doesn't work as expected, it's probably because the language sucks.
[Answer]
Unfortunately, Javascript lacks a built-in way to compute the factorial. But, you can use its meaning in combinatorics to determine the value nevertheless:
The factorial of a number n is the number of permutations of an list of that size.
So, we can generate every list of n-digit number, check if it is a permutation, and if so, increment a counter:
```
window.factorial = function($nb_number) {
$nb_trials = 1
for($i = 0; $i < $nb_number; $i++) $nb_trials *= $nb_number
$nb_successes = 0
__trying__:
for($nb_trial = 0; $nb_trial < $nb_trials; $nb_trial++){
$a_trial_split = new Array
$nb_tmp = $nb_trial
for ($nb_digit = 0; $nb_digit < $nb_number; $nb_digit++){
$a_trial_split[$nb_digit] = $nb_tmp - $nb_number * Math.floor($nb_tmp / $nb_number)
$nb_tmp = Math.floor($nb_tmp / $nb_number)
}
for($i = 0; $i < $nb_number; $i++)
for($j = 0; $j < $nb_number; $j++)
if($i != $j)
if($a_trial_split[$i] == $a_trial_split[$j])
continue __trying__
$nb_successes += 1
}
return $nb_successes
}
alert("input a number")
document.open()
document.write("<input type = text onblur = alert(factorial(parseInt(this.value))))>")
document.close()
```
---
---
Trolls:
* Types hungarian notation, snake\_case *and* unneccessary sigils. How evil is that?
* Invented my own convention for jump labels, incompatible with the current use of this convention.
* Every possible variable is accidentally global.
* The solution is not `O(n)`, not `O(n!)`, but `O(n^n)`. This alone would have sufficed to qualify here.
* Incrementing a number and then converting as base-n is a bad way to generate a list of sequences. Even if we did want duplicates. Mysteriously breaking for n > 13 is not the only reason.
* Of course we could have used `number.toString(base)`, but that doesn't work for bases above 36. Yes, I know 36! is a *lot*, but still...
* Did I mention Javascript had the modulus operator? Or `Math.pow`? No? Oh well.
* Refusing to use `++` outside of for-loops makes it even more mysterious. Also, `==` is bad.
* Deeply nested braceless looping constructs. Also, nested conditionals instead of AND. Also, the outer condition could have been avoided by ending the inner loop at `$i`.
* The functions `new Array`, `document.write` (with friends) and `alert` (instead of a prompt or an input label) form a complete trifecta of function choice sins. Why is the input added dynamically after all?
* Inline event handlers. Oh, and deep piping is hell to debug.
* Unquoted attributes are fun, and the spaces around `=` make them even harder to read.
* Did I already mention I hate semicolons?
[Answer]
**Ruby and WolframAlpha**
This solution uses the WolframAlpha REST API to calculate the factorial, with RestClient to fetch the solution and Nokogiri to parse it. It doesn't reinvent any wheels and uses well tested and popular technologies to get the result in the most modern way possible.
```
require 'rest-client'
require 'nokogiri'
n = gets.chomp.to_i
response = Nokogiri::XML(RestClient.get("http://api.wolframalpha.com/v2/query?input=#{n}!&format=moutput&appid=YOUR_APP_KEY"))
puts response.xpath("//*/moutput/text()").text
```
[Answer]
# Javascript
Javascript is a functional programming language, this means you have to use functions for everything because its faster.
```
function fac(n){
var r = 1,
a = Array.apply(null, Array(n)).map(Number.call, Number).map(function(n){r = r * (n + 1);});
return r;
}
```
[Answer]
# Using Bogo-Sort in Java
```
public class Factorial {
public static void main(String[] args) {
//take the factorial of the integers from 0 to 7:
for(int i = 0; i < 8; i++) {
System.out.println(i + ": " + accurate_factorial(i));
}
}
//takes the average over many tries
public static long accurate_factorial(int n) {
double sum = 0;
for(int i = 0; i < 10000; i++) {
sum += factorial(n);
}
return Math.round(sum / 10000);
}
public static long factorial(int n) {
//n! = number of ways to sort n
//bogo-sort has O(n!) time, a good approximation for n!
//for best results, average over several passes
//create the list {1, 2, ..., n}
int[] list = new int[n];
for(int i = 0; i < n; i++)
list[i] = i;
//mess up list once before we begin
randomize(list);
long guesses = 1;
while(!isSorted(list)) {
randomize(list);
guesses++;
}
return guesses;
}
public static void randomize(int[] list) {
for(int i = 0; i < list.length; i++) {
int j = (int) (Math.random() * list.length);
//super-efficient way of swapping 2 elements without temp variables
if(i != j) {
list[i] ^= list[j];
list[j] ^= list[i];
list[i] ^= list[j];
}
}
}
public static boolean isSorted(int[] list) {
for(int i = 1; i < list.length; i++) {
if(list[i - 1] > list[i])
return false;
}
return true;
}
}
```
This actually works, just very slowly, and it isn't accurate for higher numbers.
[Answer]
**PERL**
Factorial can be a hard problem. A map/reduce like technique -- just like Google uses -- can split up the math by forking off a bunch of processes and collecting the results. This will make good use of all those cores or cpus in your system on a cold winter's night.
Save as f.perl and chmod 755 to make sure you can run it. You do have the Pathologically Eclectic Rubbish Lister installed, don't you?
```
#!/usr/bin/perl -w
use strict;
use bigint;
die "usage: f.perl N (outputs N!)" unless ($ARGV[0] > 1);
print STDOUT &main::rangeProduct(1,$ARGV[0])."\n";
sub main::rangeProduct {
my($l, $h) = @_;
return $l if ($l==$h);
return $l*$h if ($l==($h-1));
# arghhh - multiplying more than 2 numbers at a time is too much work
# find the midpoint and split the work up :-)
my $m = int(($h+$l)/2);
my $pid = open(my $KID, "-|");
if ($pid){ # parent
my $X = &main::rangeProduct($l,$m);
my $Y = <$KID>;
chomp($Y);
close($KID);
die "kid failed" unless defined $Y;
return $X*$Y;
} else {
# kid
print STDOUT &main::rangeProduct($m+1,$h)."\n";
exit(0);
}
}
```
Trolls:
* forks O(log2(N)) processes
* doesn't check how many CPUs or cores you have
* Hides lots of bigint/text conversions that occur in every process
* A for loop is often faster than this code
[Answer]
## Python
Just an O(n!\*n^2) algorithm to find the factorial. Base case handled. No overflows.
```
def divide(n,i):
res=0
while n>=i:
res+=1
n=n-i
return res
def isdivisible(n,numbers):
for i in numbers:
if n%i!=0:
return 0
n=divide(n,i)
return 1
def factorial(n):
res = 1
if n==0: return 1 #Handling the base case
while not isdivisible(res,range(1,n+1)):
res+=1
return res
```
[Answer]
Well, there is an easy solution in Golfscript. You could use a Golfscript interpreter and run this code:
```
.!+,1\{)}%{*}/
```
Easy huh :) Good luck!
[Answer]
### Mathematica
```
factorial[n_] := Length[Permutations[Table[k, {k, 1, n}]]]
```
It doesn't seem work for numbers larger than 11, and factorial[11] froze up my computer.
[Answer]
# Ruby
```
f=->(n) { return 1 if n.zero?; t=0; t+=1 until t/n == f[n-1]; t }
```
The slowest one-liner I can imagine. It takes 2 minutes on an i7 processor to calculate `6!`.
[Answer]
The correct approach for these difficult math problems is a DSL. So I'll model this in terms of a simple language
```
data DSL b a = Var x (b -> a)
| Mult DSL DSL (b -> a)
| Plus DSL DSL (b -> a)
| Const Integer (b -> a)
```
To write our DSL nicely, it's helpful to view it as a free monad generated by the algebraic functor
```
F X = X + F (DSL b (F X)) -- Informally define + to be the disjoint sum of two sets
```
We could write this in Haskell as
```
Free b a = Pure a
| Free (DSL b (Free b a))
```
I will leave it to the reader to derive the trivial implementation of
```
join :: Free b (Free b a) -> Free b a
return :: a -> Free b a
liftF :: DSL b a -> Free b a
```
Now we can descibe an operation to model a factorial in this DSL
```
factorial :: Integer -> Free Integer Integer
factorial 0 = liftF $ Const 1 id
factorial n = do
fact' <- factorial (n - 1)
liftF $ Mult fact' n id
```
Now that we've modeled this, we just need to provide an actual interpretation function for our free monad.
```
denote :: Free Integer Integer -> Integer
denote (Pure a) = a
denote (Free (Const 0 rest)) = denote $ rest 0
...
```
And I'll leave the rest of the denotation to the reader.
To improve readability, it's sometimes helpful to present a concrete AST of the form
```
data AST = ConstE Integer
| PlusE AST AST
| MultE AST AST
```
and then right a trivial reflection
```
reify :: Free b Integer -> AST
```
and then it's straightforward to recursively evaluate the AST.
[Answer]
# Python
Below is a Python version of the solution, which is not limited to the 32 bit (or 64 bit on a very recent system) limit for integer numbers in Python. To get around this limitation, we shall use a string as input and output for the `factorial` routine and internally split the string in it's digits to be able to perform the multiplication.
So here is the code: the `getDigits` function splits a string representing a number in to its digits, so "1234" becomes `[ 4, 3, 2, 1 ]` (the reverse order just makes the `increase` and `multiply` functions simpler). The `increase` function takes such a list and increases it by one. As the name suggests, the `multiply` function multiplies, e.g. `multiply([2, 1], [3])` returns `[ 6, 3 ]` because 12 times 3 is 36. This works in the same way as you would multiply something with pen and paper.
Then finally, the `factorial` function uses these helper functions to calculate the actual factorial, for example `factorial("9")` gives `"362880"` as its output.
```
import copy
def getDigits(n):
digits = []
for c in n:
digits.append(ord(c) - ord('0'))
digits.reverse()
return digits
def increase(d):
d[0] += 1
i = 0
while d[i] >= 10:
if i == len(d)-1:
d.append(0)
d[i] -= 10
d[i+1] += 1
i += 1
def multiply(a, b):
subs = [ ]
s0 = [ ]
for bi in b:
s = copy.copy(s0)
carry = 0
for ai in a:
m = ai * bi + carry
s.append(m%10)
carry = m//10
if carry != 0:
s.append(carry)
subs.append(s)
s0.append(0)
done = False
res = [ ]
termsum = 0
pos = 0
while not done:
found = False
for s in subs:
if pos < len(s):
found = True
termsum += s[pos]
if not found:
if termsum != 0:
res.append(termsum%10)
termsum = termsum//10
done = True
else:
res.append(termsum%10)
termsum = termsum//10
pos += 1
while termsum != 0:
res.append(termsum%10)
termsum = termsum//10
return res
def factorial(x):
if x.strip() == "0" or x.strip() == "1":
return "1"
factorial = [ 1 ]
done = False
number = [ 1 ]
stopNumber = getDigits(x)
while not done:
if number == stopNumber:
done = True
factorial = multiply(factorial, number)
increase(number)
factorial.reverse()
result = ""
for c in factorial:
result += chr(c + ord('0'))
return result
print factorial("9")
```
### Notes
In python an integer doesn't have a limit, so if you'd like to do this manually you can just do
```
fac = 1
for i in range(2,n+1):
fac *= i
```
There's also the very convenient `math.factorial(n)` function.
This solution is obviously far more complex than it needs to be, but it does work and in fact it illustrates how you can calculate the factorial in case you are limited by 32 or 64 bits. So while nobody will believe this is the solution you've come up with for this simple (at least in Python) problem, you can actually learn something.
[Answer]
## Python
The most reasonable solution is clearly to check through all numbers until you find the one which is the factorial of the given number.
```
print('Enter the number')
n=int(input())
x=1
while True:
x+=1
tempx=int(str(x))
d=True
for i in range(1, n+1):
if tempx/i!=round(tempx/i):
d=False
else:
tempx/=i
if d:
print(x)
break
```
[Answer]
# A most elegant recursive solution in C
Every one knows the most elegant solutions to factorials are recursive.
Factorial:
```
0! = 1
1! = 1
n! = n * (n - 1)!
```
But multiplication can also be defined recursively as successive additions.
Multiplication:
```
n * 0 = 0
n * 1 = n
n * m = n + n * (m - 1)
```
And so can addition as successive incrementations.
Addition:
```
n + 0 = n
n + 1 = (n + 1)
n + m = (n + 1) + (m - 1)
```
In `C`, we can use `++x` and `--x` to handle the primitives `(x + 1)` and `(x - 1)` respectively, so we have everything defined.
```
#include <stdlib.h>
#include <stdio.h>
// For more elegance, use T for the type
typedef unsigned long T;
// For even more elegance, functions are small enough to fit on one line
// Addition
T A(T n, T m) { return (m > 0)? A(++n, --m) : n; }
// Multiplication
T M(T n, T m) { return (m > 1)? A(n, M(n, --m)): (m? n: 0); }
// Factorial
T F(T n) { T m = n; return (m > 1)? M(n, F(--m)): 1; }
int main(int argc, char **argv)
{
if (argc != 2)
return 1;
printf("%lu\n", F(atol(argv[1])));
return 0;
}
```
Let's try it out:
```
$ ./factorial 0
1
$ ./factorial 1
1
$ ./factorial 2
2
$ ./factorial 3
6
$ ./factorial 4
24
$ ./factorial 5
120
$ ./factorial 6
720
$ ./factorial 7
5040
$ ./factorial 8
40320
```
Perfect, although 8! took a long time for some reason. Oh well, the most elegant solutions aren't always the fastest. Let's continue:
```
$ ./factorial 9
```
Hmm, I'll let you know when it gets back...
[Answer]
# Python
As @Matt\_Sieker's answer indicated, factorials can be broken up into addition- why, breaking up tasks is the essence of programming. But, we can break that down into addition by 1!
```
def complicatedfactorial(n):
def addby1(num):
return num + 1
def addnumbers(a,b):
copy = b
cp2 = a
while b != 0:
cp2 = addby1(cp2)
b -= 1
def multiply(a,b):
copy = b
cp2 = a
while b != 0:
cp2 = addnumbers(cp2,cp2)
if n == 0:
return 1
else:
return multiply(complicatedfactorial(n-1),n)
```
I think this code *guarantees* an SO Error, because
1. Recursion- warms it up
2. Each layer generates calls to multiply
3. which generates calls to addnumbers
4. which generates calls to addby1!
Too much functions,right?
[Answer]
Just go to Google and type in your factorial:
```
5!
```
<http://lmgtfy.com/?q=5!>
[Answer]
## TI-Basic 84
```
:yumtcInputdrtb@gmail And:cReturnbunchojunk@Yahoo A!op:sEnd:theemailaddressIS Crazy ANSWER LOL
```
It really works :)
[Answer]
# Javascript
Obviously the job of a programmer is to do as little work as possible, and to use as many libraries as possible. Therefore, we want to import [jQuery](http://jquery.com/) *and* [math.js](http://mathjs.org/). Now, the task is simple as this:
```
$.alert=function(message){
alert(message);
}$.factorial=function(number){
alert(math.eval(number+"!"));
return math.eval(number+"!");
}
$.factorial(10);
```
[Answer]
## Python
With just a slight modification of the standard recursive factorial implementation, it becomes intolerably slow for n > 10.
```
def factorial(n):
if n in (0, 1):
return 1
else:
result = 0
for i in range(n):
result += factorial(n - 1)
return result
```
[Answer]
# Bash
```
#! /bin/bash
function fact {
if [[ ${1} -le 1 ]]; then
return 1
fi;
fact $((${1} - 1))
START=$(date +%s)
for i in $(seq 1 $?); do sleep ${1}; done
END=$(date +%s)
RESULT=$(($END - $START))
return $RESULT
}
fact ${1}
echo $?
```
[Answer]
Let's try to do it by **the Monte Carlo Method**. We all know that the probability of two random ***n***-permutations being equal is exactly ***1/n!***. Therefore we can just check how many tests are needed (let's call this number ***b***) until we get ***c*** hits. Then, ***n! ~ b/c***.
## Sage, should work in Python, too
```
def RandomPermutation(n) :
t = range(0,n)
for i in xrange(n-1,0,-1):
x = t[i]
r = randint(0,i)
t[i] = t[r]
t[r] = x
return t
def MonteCarloFactorial(n,c) :
a = 0
b = 0
t = RandomPermutation(n)
while a < c :
t2 = list(t)
t = RandomPermutation(n)
if t == t2 :
a += 1
b += 1
return round(b/c)
MonteCarloFactorial(5,1000)
# returns an estimate of 5!
```
[Answer]
## bash
Factorials are easily determined with well known command line tools from bash.
```
read -p "Enter number: " $n
seq 1 $n | xargs echo | tr ' ' '*' | bc
```
As @Aaron Davies mentioned in the comments, this looks much tidier and we all want a nice and tidy program, don't we?
```
read -p "Enter number: " $n
seq 1 $n | paste -sd\* | bc
```
]
|
[Question]
[
Your task is to create a program or function which **randomly** errors. Specifically, there must be a nonzero probability of erroring, but also a nonzero probability of running without error.
An error is anything that causes a program to terminate abnormally, such as dividing by zero or using an uninitialized variable. This also includes runtime errors, syntax errors and errors while compiling. Statements which manually throw an error, such as JavaScript's `throw` are allowed.
This program doesn't need to do anything if it doesn't error, other than exiting gracefully.
This is [code-golf](/questions/tagged/code-golf "show questions tagged 'code-golf'"), so shortest answer per language wins.
**Note:** For this challenge, "randomly" follows [the current consensus](https://codegolf.meta.stackexchange.com/a/1325/79857) (so no using undefined behavior or uninitialized memory for randomness), and the program must be capable of producing both outputs if run or compiled multiple times (so a random number with the same seed is not valid)
[Answer]
# [Baby Language](https://esolangs.org/wiki/Baby_Language), 0 bytes
```
```
[Try it online!](https://tio.run/##tVQ9b7MwEN75FS5LgwgVTZUMVZyhnSq9Q3fEQOAgSGAjY9Tm1@f1ByTGkKRD6wXw3T3P3XN3NEd@oOTllDNaI5aQTDzKuqGMq6@ScIdAy3HopIeEtdjd7vxg@RS5TgY5KoB8MlqwpF54rw4Sp6joPqmQcjYvJIj6ph1vOo5dV319HcoKBqZFuNx4aIdCDSUPgW@eYtN@NmkgHyuqSDnGZ2OZ61CEMdpc4DRkK6KeR3fKveVoi1bh2NtkMqudQAYW5BDkxrpSBrxjpL9W4omKgDXifrHPe/V40oCQWr7WUFN2xFGoi2qocO9NWjTpu62AXKLlSfE@j6RppEWKRePcV7tmDYpnSr6w@/p15AFVC9MYhWbK0BPvLGLlN9OBPhtZkub0ruXln2UxaHyLRrtGCjWeoRvZMV6tN9foBp/QpgxuUQZ3KYPne4yr9drmfLLVZHIz0gNbjEK9JQKS4cdHzwZYWgAFcFwSMZTWUAt32Qph9m6MyFSb6wMyjqAsk@Cik5MUo@moWtLNbWkDBLJ32p33xDx6ZwyfHQ4RZWjYlge5qFPQYSnt@TEyGxBm8r6S3s/A4p@BmWMGVS9gfEfAhz8RMLohYPCbNf9qN8zMhlbnlI7/9pd/tTB5juO6LvooCGWA3pL9Ef1LSNElBaB3msHpJMyn/w)
I *knew* this could be fun with a non-deterministic tarpit! I looked through the [category](https://esolangs.org/wiki/Category:Nondeterministic) on the *Esolang* wiki and found this language...
From the [page](https://esolangs.org/wiki/Baby_Language):
>
> A Baby Language interpreter ignores the input program and does something random. (Likewise, a Baby Language compiler generates a random executable.) As such, whatever you wanted your program to do, there's an (admittedly small) chance that it will actually do it.
>
>
> The intended use case for the language is to run your program repeatedly until it does what you want. Just like trying to reason with a real baby, this may take quite a while.
>
>
>
So the blank program, and every program for that matter, executes a random program which will therefore randomly error!
### Details on TIO link
I used *Esolang* user Enoua5's source code which generates and executes a random brainfuck program. It's linked on the Esolang page:
>
> An interpreter created in Python 3 by [User:Enoua5](https://esolangs.org/wiki/User:Enoua5): [View Source](https://pastebin.com/c5ZsULwH)
>
>
>
So the *TIO* link above takes you to Python 3 interpreter is implemented in the header and the actual (blank) code is in the (blank) code slot, which is ignored anyway!
The above interpreter is simply copied and pasted into the header; a multiline comment starting/ending in the header/footer nullifies the actual code.
[Answer]
# [Charcoal](https://github.com/somebody1234/Charcoal), 2 bytes
```
‽‽
```
[Try it online!](https://tio.run/##S85ILErOT8z5/z@gKDOvRCMoMS8lPxdGaWpqWv///1@3LAcA "Charcoal – Try It Online") Link is to verbose version of code. Explanation:
```
‽ Random value (defaults to 0 or 1)
‽ Random element from implicit range
```
If the first random value is `1`, then the implicit range is simply `[0]`, so the random element is just `0`, which does nothing (it's implicitly printed, but printing `0` has no effect).
If the first random value is `0` however, then the implicit range is `[]`. This is an illegal input to `randrange` which therefore throws a ValueError.
[Answer]
# [Bash](https://www.gnu.org/software/bash/) + Unix utilities, ~~12~~ ~~11~~ 8 bytes
```
m$RANDOM
```
[Try it online!](https://tio.run/##S0oszvj/P1clyNHPxd/3/38A "Bash – Try It Online")
If `$RANDOM` happens to have the value `4`, this will run the macro processor `m4` (which exits right away on TIO because stdin is empty). If `$RANDOM` has any other value, you'll get an error because there's no program available via $PATH with the indicated name.
---
If you want pure bash, with no external utilities, then the shortest I’ve found is my first version (which is 12 bytes long):
```
((1/RANDOM))
```
[Answer]
# [Python 3](https://docs.python.org/3/), ~~15~~ ~~14~~ 11 bytes
*-3 bytes thanks to @newbie!*
```
1/(id(0)%3)
```
[Try it online!](https://tio.run/##K6gsycjPM/7/31BfIzNFw0BT1Vjz/38A "Python 3 – Try It Online")
**Also 11 bytes**:
```
id(0)%3or a
```
[Try it online!](https://tio.run/##K6gsycjPM/7/PzNFw0BT1Ti/SCHx/38A "Python 3 – Try It Online")
**How**: The `id` of an object varies across different runs. Thus `id(0)%3` can be `0`, which causes `ZeroDivisionError` and `NameError` in the programs above respectively.
[Answer]
includes 3 different answers, smallest first
# x86-64 machine code "function", 4 bytes
("works" in all 3 modes: 16-bit, 32-bit, and 64-bit. In other modes, FE 00 is a jmp to eax or ax.)
```
0000000000401000 <timejump>:
401000: 0f 31 rdtsc # EDX:EAX = timestamp counter
401002: ff e0 jmp rax # "return" with jmp to register
```
This function can be called with `jmp` instead of `call`; it doesn't need you to pass it a return address on the stack. **It uses the low 32 bits of the time counter as a jump target, which might or might not be the correct return address (or somewhere else useful).**
The crash possibility is code-fetch from an unmapped or non-executable page, or jumping to instructions that fault (e.g. `00 00 add [rax],al`), or to an illegal instruction, like a `1F` or other byte somewhere in 64-bit mode, or a multi-byte illegal sequence in 16 or 32-bit mode, that will raise #UD.
RDTSC sets EDX:EAX = the number of reference cycles since power-on (i.e. the TSC = TimeStamp Counter, SO [canonical Q&A about it](https://stackoverflow.com/questions/13772567/how-to-get-the-cpu-cycle-count-in-x86-64-from-c/51907627#51907627). Note that it doesn't count core clock cycles on modern x86). The reference frequency is normally close to the CPU's sticker frequency (e.g. 4008MHz on a nominally 4GHz i7-6700k) so **the low 32 bits wraps around in just over 1 second, which is close enough to random for interactive use.** Or every few seconds on chips with lower "base" frequencies.
Assuming a valid return address or other jump target exists in the low 32 bits of virtual address space, we have a `1` in `2^32-1` chance of reaching it. Or higher if there are multiple useful targets to dispatch to. (Assuming TSC is uniformly distributed, and fine-grained enough that every 32-bit low half is actually possible. I think this is the case.)
In 32 and 16-bit mode, every possible address (in the same code segment) is reachable, but 64-bit mode unfortunately still splits the TSC between EDX and EAX so most of the 64-bit (or 48-bit) address space is unreachable.
On systems like MacOS where 64-bit processes normally have all their code outside the low 4GiB of address space, use 32-bit mode. Linux non-PIE executables are mapped in the low 2GiB of virtual address space so any non-library code will be reachable.
---
# x86 32-bit machine code function, 5 bytes
```
0000000000401000 <inctime>:
8049000: 0f 31 rdtsc # EDX:EAX = timestamp counter
8049002: 40 inc eax # EAX++
8049003: ce into # trap if OF==1
8049004: c3 ret
```
On most x86 CPUs, the TSC is fine-grained and really can be any value in the low half, including 231-1. So incrementing it can produce signed integer overflow, setting OF.
Also works in 16-bit mode (incrementing only AX with this machine code), but not 64-bit mode where [`into`](https://www.felixcloutier.com/x86/intn:into:int3:int1) isn't a valid opcode.
# x86-64 machine code function, 6 bytes
(same machine code works in all 3 modes, using the default operand size for the mode; 16, 32, and 32.)
divides 64-bit user input by a random number: can overflow or divide by 0.
```
0000000000401000 <divrandom>: # input in EDX and EAX
401000: 0f c7 f1 rdrand ecx
401003: f7 f1 div ecx # return EDX:EAX / ECX
401005: c3 ret
```
Yup, x86 has a *true* RNG built in (Intel since IvyBridge, and AMD since at least Zen).
x86 division of 64-bit EDX:EAX / 32-bit ECX => 32-bit quotient and remainder faults (with a #DE exception -> SIGFPE or other OS signal) if the quotient doesn't fit in 32-bit EAX. With a small dividend, this can only happen on divisor = 0, 1 chance in 2^32.
With function input in EDX:EAX above 2^32-1, small divisors could leave a quotient larger than 2^32-1. So the chance of faulting depends on the input value. Specifically, division runs without faulting if ECX > EDX, where ECX is the random divisor and EDX is the high half of the 64-bit input.
---
[`rdrand`](https://www.felixcloutier.com/x86/rdrand) always sets OF to 0 so we can't use 1-byte [`into`](https://www.felixcloutier.com/x86/intn:into:int3:int1) conditionally trap on overflow. (It only sets CF = success, 0 means HW RNG temporarily exhausted).
---
I can't think of any "unpredictable / undefined behaviour" situation that could actually give different results on different runs, other than meltdown-style timing that depends on microarchitectural conditions.
Some old ARM and MIPS CPUs have unpredictable behaviour that depends on timing if you for example use a multiply where the destination is one of the inputs, or on MIPS I read the result of a load in the next instruction (in the load delay slot). So for example on MIPS `lw $ra, ($a0)` ; `jr $ra` (4 bytes each) might use the original return address in `$ra` (the link register) if the load hits in cache, otherwise it stalls and we'd return to wherever the load points.
[Answer]
# [JavaScript (V8)](https://v8.dev/), ~~15~~ 13 bytes
*idea and -2 bytes from @apsillers*
Uses `new Date` instead of `Math.random`, has a \$\frac{1}{9}\$ chance of not erroring:
```
new Date%9&&a
```
[Try it online!](https://tio.run/##y0osSyxOLsosKNEts/j/Py@1XMElsSRV1VJNLfH/fwA "JavaScript (V8) – Try It Online")
# [JavaScript (V8)](https://v8.dev/), ~~17~~ 16 bytes
*-1 thanks to @newbie*
```
Math.random()&&a
```
[Try it online!](https://tio.run/##y0osSyxOLsosKNEts/j/3zexJEOvKDEvJT9XQ1NNLfH/fwA "JavaScript (V8) – Try It Online")
This has a \$\frac{1}{2^{1074}}\$ chance of not erroring, as `Math.random()` can occasionally be 0.
[Answer]
# [><>](https://esolangs.org/wiki/Fish), 3 bytes
```
x,;
```
[Try it online!](https://tio.run/##S8sszvj/v0LH@v9/AA "><> – Try It Online")
My first submission in ><>, very simple
[Answer]
# [J](http://jsoftware.com/), 6 byte function
```
z^:?@2
```
[Try it online!](https://tio.run/##y/pvqWhlGGumaGWprs6lpKeepmBrpaCuoKNgoGAFxLp6Cs5BPm7/q@Ks7B2M/mtycRWlFpZmFqUqqOeV5qYWZSarcxUl5qXk52ZWpQJN4EpNzshXSFMAMklm/QcA "J – Try It Online")
If `y` is the argument, `z^:v` conditionally returns the result `z y` if `v y` returns `1`. Otherwise it returns `y` unchanged.
`? 2` will return 0 half the time and 1 half the time.
No matter what argument we pass to this function, it will be converted into the constant `2` and then passed to `z^:?`.
So half time the result will be `2`, and half the time it will error when trying to execute the non-existent verb `z`.
## alternative full programs
Though these may look like snippets they should count as full programs in the context of this challenge.
4 bytes thanks to Bubbler:
```
q:?2
```
5 bytes thanks to Adam:
```
0^.?2
```
[Answer]
# Python <= 3.7, ~~25~~ 24 bytes
`lambda x:id(x.__dir__)`
Included for its weirdness rather than its brevity. This will cause a [segmentation fault](https://bugs.python.org/issue33930) in obscure cases involving deep recursion. A fix is being applied, but only to python versions >=3.8.
The crash only occurs on cleanup when *exiting* the interpreter, but an example of how to call this function (and reproduce the segfault) can be found here: [Try it online!](https://tio.run/##K6gsycjPM/7/P802JzE3KSVRocIqM0WjQi8@PiWzKD5e83@Fgq1CflJWanKJhiZXWn6RQoVCZp5CUWJeeqqGYbyBgQEIa1pxKQABSC1cK1gkTaNC8z8A "Python 3 – Try It Online")
[Answer]
# [Lost](https://github.com/Wheatwizard/Lost) -A, 9 bytes (Probability 1/2)
```
\\\\
%1-@
```
[Try it online!](https://tio.run/##y8kvLvn/PwYIuFQNdR3@//@v6wgA "Lost – Try It Online") [Verification1](https://tio.run/##y8kvLvn/PwYIuFQNdR3@//@vGwYA "Lost – Try It Online")
As an introduction to Lost for anyone unfamiliar, Lost is a 2-D programming language in which the start location and direction are selected at random at the beginning of the program. This source of randomness is what we use in this challenge.
We want some start locations that will cause an error and some that will not.
The program will error if it starts on the character `%` going right (or down). In this case it will encounter the ops `%1-@` before termination. This pushes `-1` and exits. Since `-1` is not a valid character code this causes an error in character mode.
The program will terminate safely if it starts on the character `%` going left (or up). In this case it will encounter the ops `%@` before termination. This does nothing and exits.
Since we have a path that errors and one that does not, all that remains is to know that every path terminates, which is guarenteed by the `\\\\`. So this program is valid.
We could shorten this significantly if there was not a termination requirement. The program :
```
%1-@
```
[Try it online!](https://tio.run/##y8kvLvn/X9VQ1@H///@6jgA "Lost – Try It Online")
Either errors, terminates cleanly or loops forever, and it selects which at random with the following probabilities:
* **1/2** Non-terminating
* **1/4** Errors
* **1/4** Terminates cleanly
---
1: For verification we turn off character mode. All outputs containing negative numbers are the ones that will error in character mode.
[Answer]
# INTERCAL, 10 bytes
```
DO%9GIVEUP
```
The only way to terminate an INTERCAL program without an error is to execute a `GIVE UP` statement -- running off the end of the source code is a runtime error. This program uses INTERCAL's probabilistic execution feature to have a 9% chance of successfully exiting; the rest of the time, it errors out:
```
ICL129I PROGRAM HAS GOTTEN LOST
ON THE WAY TO WHO KNOWS WHERE
CORRECT SOURCE AND RESUBNIT
```
[Answer]
# [APL (Dyalog Unicode)](https://www.dyalog.com/), 3 bytes
```
÷?2
```
[Try it online!](https://tio.run/##SyzI0U2pTMzJT///qG@qp/@jtgkGXI862tP@H95ub/QfyOICigNF0/4DAA "APL (Dyalog Unicode) – Try It Online")
(Requires `IO←0`)
Inverse of random boolean (any range including 0 would work). I expect this'll be a common technique...
```
÷ ⍝ Inverse
?2 ⍝ Random number in [0,1]
```
[Answer]
# [PowerShell](https://github.com/TryItOnline/TioSetup/wiki/Powershell), 10 bytes
```
1/(random)
```
[Try it online!](https://tio.run/##K8gvTy0qzkjNyfn/31BfoygxLyU/V/P/fwA "PowerShell – Try It Online")
`get-random` returns an int between 0 and 0x7FFFFFFF so it'll eventually divide by 0. Maybe...
[Answer]
# [><>](https://esolangs.org/wiki/Fish), 5 bytes
```
v
x+;
```
[Try it online!](https://tio.run/##S8sszvj/v4yrQtv6/38A "><> – Try It Online")
## Explanation
The pointer will be represented by a hashtag symbol. It will replace in bewteen these spaces:
```
v
x + ;
```
Ok, explanation start.
The instruction pointer goes down.
```
v*
x + ;
```
The step is randomized.
```
v
x*+ ;
```
Case 1: Error
```
v
x +*;
```
It tries to pop two items, but there is nothing on the stack. Cue error.
Case 2: Exit gracefully
```
v
x + ;*
```
It loops to the right side, and ends on the semicolon.
[Answer]
# [C (gcc)](https://gcc.gnu.org/), ~~17~~ 16 bytes
Random across function calls.
Saved a byte thanks to [newbie](https://codegolf.stackexchange.com/users/89856/newbie)!!!
```
f(i){i/=rand();}
```
[Try it online!](https://tio.run/##S9ZNT07@/z9NI1OzOlPftigxL0VD07r2f25iZp6GZjVXGpDHVVCUmVeSpqGUnx2TpwTk1/4HAA "C (gcc) – Try It Online")
Has a \$\frac1{\text{RAND\_MAX} + 1}\$ chance of failing with `Floating point exception`.
**Random across runs.**
# [C (gcc)](https://gcc.gnu.org/), 19 bytes
```
f(i){i/=(int)&i%3;}
```
[Try it online!](https://tio.run/##S9ZNT07@/z9NI1OzOlPfViMzr0RTLVPV2Lr2f25iZp6GZjVXmoahpjVXQRFQKk1DKT87Jk8JyK/9DwA "C (gcc) – Try It Online")
[Answer]
# [Google Sheets](https://sheets.google.com), 8 bytes
```
=0/RAND(
```
Google will a closing parentheses automatically to give `=0/RAND()`.
Since `RAND()` produces a uniformly random between 0 inclusive and 1 exclusive and to 15 decimal points of accuracy, is has a 0.0000000000001% chance of returning exactly 0 and causing the `#DIV/0!` error.
[Answer]
# [Metatape](https://esolangs.org/wiki/Metatape), ~~4~~ 3 bytes
```
x?(
```
*-1 byte thanks to [Hactar](https://codegolf.stackexchange.com/users/59288/hactar), the language creator, on Discord*
Initially, the tape head is within a tape and pointing to a null cell. The command `x` exits the current cell, creating a new tape and putting the initial tape within it. Now the tape head is within a tape and pointing at a tape.
The `?` command then generates a random bit, setting the current cell of the tape to null if it is `0` and doing nothing if it is `1`. Then the `(` command jumps to the next `|` or `)` characters in the code if and only if the current cell is null, and does nothing otherwise. Thus, if the bit generated by `?` is `0`, the interpreter will throw an error, as there is no `|` or `)` to jump to. On the other hand, Metatape does not implicitly check for every `(` matching with a `)`, so if the bit generated by `?` is `1`, no error will be thrown.
EDIT: After further clarification with the language's creator, I found that the last sentence I wrote may not apply to all interpreters, and thus this answer might not work for all interpreters. Oops.
[Answer]
# Z80 machine code, 6 5 bytes
I finally managed to reduce it to 5 bytes and also make it more well-behaved at the same time:
```
ED 5F B7 C0 76
```
Explanation:
```
ED 5F LD A, R ; get non-deterministic value (00-7F) from memory refresh register
B7 OR A, A ; set Z flag if A is zero
C0 RET NZ ; return normally, unless we were unlucky and got zero
76 HALT ; halt the CPU
```
Alternatively to the `HALT` instruction `RST` could be used to call an error handler.
Other approaches that use 6 bytes and fail in a less well-behaved way:
---
```
ED 5F 17 32 06 00
```
Explanation:
```
ED 5F LD A, R ; get random value (00-7F) from refresh count register
17 RLA ; rotate left one
32 06 00 LD (0006), A ; write the byte immediately following this instruction.
```
There is a chance that this results in one of the conditional RET instructions to be written after the code, which returns normally if the condition happens to be met, which is the case for `RET NZ (C0)`, `RET NC (D0)`, `RET PE (E8)` and `RET M (F8)`. Otherwise, a random instruction is executed and the program counter runs into whatever is in RAM after that, failing horribly. If bit 8 of the R register was somehow set (which doesn't normally happen), or any instruction with an opcode up to 7F would somehow end the program normally, this could be reduced to 5 bytes. The address operand in the last instruction must be set relative to where the code is actually located.
---
```
ED 5F B7 28 FE C9
```
Explanation:
```
ED 5F LD A, R ; get non-deterministic value (00-7F) from memory refresh register
B7 OR A, A ; set Z flag if A is zero
28 FE JR Z, -2 ; infinite loop if Z-flag is set
C9 RET ; return
```
An infinite loop might not really count as an 'error' though. An alternative solution (same length), inspired by Peter Cordes' x86 solution, is to mess with the return address:
---
```
E5 ED 5F AC 67 E9
```
Explanation:
```
E5 POP HL ; get return address from stack
ED 5F LD A, R ; get non-deterministic value (00-7F) from memory refresh register
AC XOR A, H ; this will only leave H intact
67 LD H, A ; if R was zero by chance
E9 JP HL ; jump to (probably broken) return address
```
[Answer]
# [Zsh](https://www.zsh.org), ~~8~~ 7 bytes, \$ \approx \frac{1}{10}\$ chance of success
```
>$$
<*4
```
[Attempt This Online!](https://ato.pxeger.com/run?1=m724qjhjwYKlpSVpuhbL7VRUuGy0TCA8qCBMEgA)
Determines whether the process ID ends in `4`.
[Answer]
# [Jelly](https://github.com/DennisMitchell/jelly), 5 bytes
I haven't used Jelly for a long time, it's time for me to pick it up again.
```
2X’İX
```
[Try it online!](https://tio.run/##y0rNyan8/98o4lHDzCMbIv7/BwA "Jelly – Try It Online")
# Explanation
```
2X Pick random from [ 1, 2]
’ Decrement: [ 0, 1]
İ Reciprocal: [ inf, 1]
X randrange 1 [Error, 1]
```
[Answer]
# [Octave](https://www.gnu.org/software/octave/) / MATLAB, 13 bytes
```
det(0:rand*2)
```
[Try it online!](https://tio.run/##y08uSSxL/f8/JbVEw8CqKDEvRctI8/9/AA "Octave – Try It Online")
### How it works
`rand` produces a random number with uniform distribution between `0` and `1`. So the range `0:rand*2` may be `0` (1×1 matrix) or `[0 1]` (1×2 matrix). `det` tries to compute the determinant, which is only defined for square matrices.
[Answer]
# [05AB1E](https://github.com/Adriandmen/05AB1E), 4 bytes
```
Î)ΩE
```
[Try it online!](https://tio.run/##yy9OTMpM/f//cJ/muZWu//8DAA "05AB1E – Try It Online")
```
Î Push 0 and input, ie. [0, ""] b/c input blank
) Wrap total stack to an array
Ω Push random element of a, ie. [0, ""]
E For-loop in [1 .. a]
```
where `a` is the top of the stack
Errors when `""` is randomly selected & for loop is attempted on it.
Proceeds when `0` is randomly selected & for loop is attempted on it.
[Answer]
# SQL (Oracle), 3733 Bytes
```
SELECT 1/INSTR(UID,3) FROM DUAL;
```
Fails if the User Session doesn't have a 3 in it.
Edit: Was using SYSDATE, but UID is shorter. Although I'm kinda sad. I liked having a function that worked in March, but not February.
[Answer]
# [R](https://www.r-project.org/), ~~15~~ 14 bytes
```
if(rexp(1)>1)a
```
[Try it online!](https://tio.run/##K/r/PzNNoyi1okDDUNPOUDPx/38A "R – Try It Online")
R doesn't throw errors often. In particular, dividing by 0 doesn't lead to an error (`1/0=Inf`); nor does attempting to access an out-of-bounds entry in a vector (outputs `NA` with a warning). Two easy ways to get an error are: 1. an `if` statement gives an error if it is not fed a `TRUE`/`FALSE` value; 2. trying to access a non-existing object.
Here, if the random variate is >1, we try to access `a` which doesn't exist, so R throws `Error: object 'a' not found`. If the random variate is <1, nothing happens.
---
Previous version:
# [R](https://www.r-project.org/), 15 bytes
```
if(T[rexp(1)])1
```
[Try it online!](https://tio.run/##K/r/PzNNIyS6KLWiQMNQM1bT8P9/AA "R – Try It Online")
Here, `rexp(1)` generates a realization of the exponential distribution, i.e. a random value \$x\in\mathbb R\_+\$.
* if \$x<1\$ then `T[x]` is an empty logical vector and R throws an `Error: argument is of length zero`
* if \$1\leq x<2\$ then `T[x]` is `TRUE` and R outputs `1` without error
* if \$2\leq x\$ then `T[x]` is `NA` and R throws an `Error: missing value where TRUE/FALSE needed`
An error is thrown with probability \$1-e^{-1}+e^{-2}\approx 0.767\$.
[Answer]
## [Compiled Stax](https://raw.githubusercontent.com/joshudson/stax/master/staxc/staxc1.stax), 28 27 25 bytes
Requires 116 TB RAM, and ulimit -s set to 116TB.
```
8000000000000{1-cy{}?}Y!
```
At present time, obvious ways to golf this fail to compile due to the compiler not supporting the requisite language feature.
This program attempts a recursive block invocation with a depth of 8000000000000, which in turn tries to create 8000000000000 16 byte stack frames on the runtime stack. This either succeeds or fails with probability of about .5 depending on how far apart the program and the top of the stack are in address space are.
I am using the environment's RNG that is actually documented to be random to make this fault or not fault.
And recursive said there's no such thing as nondetermistic stax.
[Answer]
# [Taxi](https://bigzaphod.github.io/Taxi/), 209 bytes
```
Go to Heisenberg's:w 1 r 3 r 1 l.Pickup a passenger going to Magic Eight.Pickup a passenger going to Magic Eight.Go to Magic Eight:s 1 r 1 l 3 r.Pickup a passenger going to Cyclone.Go to Taxi Garage:e 2 l 2 r.
```
[Try it online!](https://tio.run/##K0msyPz/3z1foSRfwSM1szg1Lym1KF292KpcwVChSMEYiA0VcvQCMpOzSwsUEhUKEouBatJTixTS8zPz0kHafBPTM5MVXDPTM0qIVgexEEnEqhhsH9AukJ14zXGuTM7Jz0uFmhEC9ICCe2JRYnqqVaqCEVC/EVD///8A "Taxi – Try It Online")
Ungolfed and commented:
```
[ Heisenberg's produces random integers ]
Go to Heisenberg's:w 1 r 3 r 1 l.
[ Pickup two random integers ]
Pickup a passenger going to Magic Eight.
Pickup a passenger going to Magic Eight.
[ Magic Eight compares two numeric passengers ]
[ It returns the first passenger if it is less than the second and no one if it is not ]
Go to Magic Eight:s 1 r 1 l 3 r.
[ Try to pickup a passenger, which will error if there isn't anyone waiting ]
Pickup a passenger going to Cyclone.
[ Return to the garage to avoid getting the "you're fired" error ]
Go to Taxi Garage:e 2 l 2 r.
```
[Try the ungolfed and commented version online!](https://tio.run/##jVI9T8MwEN37K566dEGVWrauCBUGJIS6RQzGuTonEjs6O4T8@nC2SikCIQYP53t@X3Iy7zzPFe6II/kXEreK6CXUg6UIMb4OHdgnciQRz4t9QArf0LsRGwiu9WzQrhcVHtm@Dj3SGH4hOC0NehOVQ2/hAnuXaR@MY4tbdk1a/x9YXY6woeuNqPcs74eORFdniuygwn2CUBrEK6ohHFliupDhIziBI1qKGWF8gUWywdfQRPABwdMX0Id07ubCzC6WarSWXE92epApY/of2a4wNmwbjNy2IJFQbKisqEz0q6S6U9YcDafcwt9N3ky2VXSWfCpJ82UO4YwYR3kyb4FrOEqFLu@WUxhWUvqgenly8RnroB8F@/J6R9hqpK1GmucP "Taxi – Try It Online")
[Answer]
# [Knight](https://github.com/knight-lang/knight-lang), 3 bytes
```
/1R
```
[Try it online!](https://tio.run/##rVltV9vKEf5s/4rFOdhaWw6SoOfc2sgckgs5nBLIhaT3A7iJkNegU1l2JRlCCf3r6czsi1a2SZv28sGydp@ZnXl2dmbWxP3bOP7@KsnidDkR@0U5Seav70ZNeyRNbmpDcfm4ECugPMlua0NlMpOYiZgmmWBpytJ5dksfzebODltm8Xw2E1nJyrukYCmCpvOcRewmmrBCiAlMRCVCc1Eu86xgHptnLI@yicNxWKvGpZyvnAV7e3/2/WbTrPnx7NN75levlx8vWFC9/vXwgu1Vr8dnb9kv1evFJ@ZX4OPTSwt79unUgn46e394@Ren4MzBjzb7l/8nbmYPL2FZORnfRTnr8krARoGtRsVoxPaqubOj33Eyg0ny6BvD7/v7KxhchjDoJmDSlCOwhnlzfn5KIPw4ICcH6JtlyMU7CQB5y9b7KF0Kzq@yMW82yQ/Y86txeNE6Oj92vu/4F985fGsN5WQXZkU0YyHChs0m6FpEeSEczp6ajQQ2PRk2GzBKel3WnUI4wAgJx/BezhZusciugnH45LneM@hoJKCO8PD0cABiACNvwR7uklIUiygWzQZ8T4UD4yDuSDNc1rour7Pr6XXOnp6vxg4fvGpxMqWRTJljrA1Z51WHM6lCj27B6HUGw72eHAE7GyIthD3wLM2J70T8dwrjbDm7EXmh7GFOUkyS26TUWmF1dMd3jUfy2WW@x3qsqyzv9Tjrs47XgSXQ0oSrw8B0JEgxCobhqg33UZ5EN6nQVoAR6fxB5E4M62lD2LdvTBsX01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ditNbSXkugVpcPVkhdsKnm73PQBgZHeo8H/0BChYfjErYhN82/aIbs3CsBDXLXnY5NEDYKMfzlJD0L01EmA1SdiGkGSBM90h5lkMJlM6DekKC6hTHW24w72nDjC2QuXWFRmaiB0g@p3hFmUZNissii/jV1S2u3C93uOv1bR9ZL@S@ORNfVr3PP3fwM "C (gcc) – Try It Online")
Has a roughly \$\frac{1}{65536}\$ chance of dividing by zero.
The classic `1/rand()` trick. Assumes that dividing by zero throws an error, of course.
Uncommenting the line at the top of the header code will `srand` with a seed that will cause glibc's `rand()` to return `0xe7d0000`, which when masked by `0xFFFF`, results in `0`.
[Answer]
****><>, 4 bytes****
The **!** skips the next instruction, even if it would give an error.
The **x** set the pointer's direction to a random direction. It can make it go up or down but if the pointer reaches the edge then it wraps around.
The **;** ends the program.
The **{** can be replaced with any character as long as it's not a valid command in ><>.
```
!{x;
```
<https://tio.run/##S8sszvj/X7G6wvr/fwA>
Try it online!
[Answer]
# [C (clang)](http://clang.llvm.org/), 24 bytes
```
main(i){i/=(time(0)%3);}
```
[Try it online!](https://tio.run/##S9ZNzknMS///PzcxM08jU7M6U99WoyQzN1XDQFPVWNO69v9/AA "C (clang) – Try It Online")
# C, 20 bytes
```
main(i){i/=time(0);};
```
Will crash once every +/- 68 years.
<https://en.wikipedia.org/wiki/Year_2038_problem>
[Answer]
# [Aussie++](https://github.com/zackradisic/aussieplusplus/), 78 bytes
```
G'DAY MATE!
IMPOHT ME FUNC ChuckSomeDice;
ChuckSomeDice(0,ChuckSomeDice(0,2));
```
Tested in commit 9522366.
`ChuckSomeDice` is the only way to get a random number, but it behaves a bit interestingly:
* If either argument is a finite non-integer, it's truncated to an integer.
* Inputs are capped to be no greater than 9223372036854775296.
* NaN is treated as 0.
* If both arguments (let's call them `x` and `y`) are integers, and `y` is greater than `x`, it gets a random integer in `[x, y)`.
* If `x` is less than `y`, it prints `OI MATE, CAN YA FUCKIN' COUNT?? START MUST BE LESS THAN END!!` to STDERR, but continues execution.
* If `x` is equal to `y`, it panics. See [this Github issue](https://github.com/zackradisic/aussieplusplus/issues/41).
The result is stored as a double, so calling e.g. `ChuckSomeDice(9223372036854775295, 1/0)` only ever produces either 9223372036854775000 or 9223372036854776000.
**TL;DR:** The arguments can't be equal, and behind the scenes it's likely casting between `i64` and `f64`.
So, I get either 0 or 1 randomly, and then get a random number between 0 and the result. If that was also 0, it panics. If that was 1, it returns 0.
]
|
[Question]
[
This is an [answer-chaining](/questions/tagged/answer-chaining "show questions tagged 'answer-chaining'") question, which means that all answers are affected by those before them.
# The task
The *n*-th answer to this question must run in all languages that are present in answers before it. They need not run in order, but must print the name of the language currently running, *reversed*.
## Additional rules
* A language cannot be used twice.
* Your program must run without errors. Using errors to log the language name is not permitted, but you are allowed to use errors to determine language.
* Each answer must be no more than 30% or 40 bytes (whichever is larger) longer than the previous answer. If the percentage is not an integer, it is rounded **down**.
* Your added language must be a [free implementation](http://meta.codegolf.stackexchange.com/q/7822/62131) language.
* Any interpreter for a language is allowed.
* If you can link to reproducible results, please do so.
* The name of the language being reversed is Case-insensitive, so '3nohtyp' is valid for Python 3.0
* You may not put 2 answers in a row.
* If your language does not support strings, print the letters as numbers, following this pattern: "A" = 0, "B" = 1, "C" = 2...
* In the case of a language not supporting strings *and* having non-letter characters in its name, print -1 instead of the non-letter character. Please show verification that the language does not support strings.
# Victory condition
If this question goes for 20 days without an answer, the *second to last* answer wins.
# Answer format
>
> # 4. CoffeeScript, 20 bytes
>
>
>
> ```
> (program goes here)
>
> ```
>
> This program prints **nohtyp** in Python 3, and **tpircsavaj** in JavaScript.
>
>
> (If you wish to explain how you did it, do so here)
>
>
>
[Answer]
# 3. [><>](https://esolangs.org/wiki/Fish), 106 bytes
```
void main(){import std.stdio;"D".write;}
/* ;ooo"><>"
1j U8=XPC#18M<<}9F ,+;q,+;
*/
```
[Try it online!](https://tio.run/##S8sszvj/vyw/M0UhNzEzT0OzOjO3IL@oRKG4JEUPiDPzrZVclPTKizJLUq1rufS1FHAA6/z8fCU7GzslLsMshVAL24gAZ2VDC18bm1pLNwUdbetCIObS0v//HwA "><> – Try It Online")
This program prints **D** in D, **emmoS** in Somme, and **><>** in ><>.
Next answer cannot exceed **146 bytes** (106 + 40).
# Explanation
`;ooo"><>"` prints "><>" in ><> (which is a palindrome), then exits.
[Answer]
# 4. C, 125 bytes
```
void main(){//\
/*;ooo"><>"
printf("C")/*/import std.stdio;"D".write/**/;}/*
J'zvSfN0cb&)}kf ;K-+ ,+;q,+;60d}[}q(-6+:puupd"*/
```
[Try it online!](https://tio.run/##DcMxDsIgFADQnVOQPyhQ29@pg5guOmni4qhLhWKIttBKa6Lh7NiXPJWrV9M/Upqd1bRrbM/4D/FGUEjnHNS7GogfbR8Mgz1wFGg778ZA30EXS@skHKD4jDa0KATKiIIc19/5Ys6luq94fBoqT3lGN5kcllWp4zUOLK@yrZ8mr0FgSn8) (I picked clang, but works with gcc as well.)
This program prints **C** in C, **D** in D, **emmoS** in Somme, and **><>** in ><>.
Next answer cannot exceed 165 bytes (125 + 40).
## Explanation
This takes advantage of the fact that single-line comments in C can be extended to the next line by escaping the newline with a backslash, while in D that is (apparently) not possible. This means that the `/*` on line 2 starts a multi-line comment in D, while in C it does not. Also makes use of the fact that `/*/` can act as both start and end of a multi-line comment in both languages.
The ><> part works exactly the same as in previous answers, and the Somme part was generated anew with [this script](https://github.com/ConorOBrien-Foxx/Somme/blob/master/somme-help.rb).
[Answer]
# 1. D, 40 bytes
```
void main(){import std.stdio;"D".write;}
```
[Try it online](https://tio.run/##S/n/vyw/M0UhNzEzT0OzOjO3IL@oRKG4JEUPiDPzrZVclPTKizJLUq1r//8HAA)
One byte language names!
[Answer]
# 2. [Somme](https://github.com/ConorOBrien-Foxx/Somme), 73 bytes
```
void main(){import std.stdio;"D".write;}
/*
1j U8=XPC#18M<<}9F ,+;q,+;
*/
```
[Try it online!](https://tio.run/##K87PzU39/78sPzNFITcxM09DszoztyC/qEShuCRFD4gz862VXJT0yosyS1Kta7n0tbgMsxRCLWwjApyVDS18bWxqLd0UdLStC4GYS0v//38A "Somme – Try It Online")
This program prints **D** in D, and **emmoS** in Somme.
Next answer cannot exceed **113 bytes** (73 + 40).
## Explanation
Somme adds up each column and treats the result as commands. For example, the first column is `v/1*`, which sums to [this](https://tio.run/##KypNqvz/P78opVjBViE4xMXTT68oNTFFLzkjsahYLzexQKFaoSa1RiFVD6hGQVfB2Eihlqsotbg0pwSoAaRPr7g0V0FVwdJUQRsoy1WgAJUFGlH0/3@ZvqEWAA).
This translates (roughly) into:
```
Asi:8+::2+:47*-m,;
A push 10
[10]
s square it
[100]
i increment
[101]
: duplicate
[101, 101]
8+ add 8
[101, 109]
:: duplicate twice
[101, 109, 109, 109]
2+ add 2
[101, 109, 109, 111]
: duplicate
[101, 109, 109, 111, 111]
47*- subtract 28
[101, 109, 109, 111, 83]
m, output each as a character
emmoS
; terminate
```
You can plug in the other rows and the target column [with this script](https://github.com/ConorOBrien-Foxx/Somme/blob/master/somme-help.rb).
[Answer]
# 9. [Befunge-93](https://github.com/TryItOnline/befunge-97-mtfi), 221 bytes
```
void main(){//\
/*SmiVZZ;ooo"><>"
#define S""
#ifdef __OBJC__
#define S"-evitcejbO"
#endif
printf("C"S)/*/import std.stdio;"D".write/**/;}/*
>"Befunge-98";"Befunge-93",,,,,,,,,,@;9k,@
,wVkk_,xeWvl<h_VZUn*///⎚laocrahC
```
Thanks to @JoKing for pointing out that I forgot a `9`.
[Try it online!](https://tio.run/##TY7NasJAFIX38wpuhutGh8S7cFMZCWJcuXERmkIoDNHcqdeYGUmnsSC@Qh@gj9cXSbPpz4ED5@OcxdmTfXMvFC/mcRMs933nuZJNyW4yvSE@C1SjrOF8VBTaew/JMgExrsiyI5nBkNkOJI3ZrbepMf@6mDoOBzrtd8OKXMVWXFp2wU4ghWyKCrm5@DbI11DNBrPXsIHZteVAqBTqOyqRwPrn4QPoP5hD9KuVXtTRSsjomte1id7pqTsvjyYvHp1CxK@Pz3PpD215TPv@Gw "Befunge-93 (MTFI) – Try It Online")
[Try it online! (Vim)](https://tio.run/##TYxBasMwEEX3ukI2QoWQCNtD002DgwhxV91kYZqCKQjHkmvVtmRs2TGUXqEH6PF6EUfdxB34MO//mX9Ou2KastRihgdVB5kREo2juAFmyw1ygP1u9kxvm94GdnRvIOQAuq8qvGHLe/RXNcfTNBglcJ0qvVp/ArwhoIu4VqdFkoTGGMJ2jKA7IXOlJY6J21XuCHN@PDxHnP/LfDkom8mP89FdSS1UjppWaZuvSETiNVBQdWNaizsrAidlQvJEgkurrARKIfwCihg5yLzX79LfPpJwhgfi3WYfbktvj7B3OZUl90b5OlS7gp@SF00B4Pf7p0pN1qZFdAU)
Prints `39-egnufeB` in Befunge-93, along with maintaining the other outputs in the other languages.
Next answer cannot exceed **287** bytes.
Will work in MTFI, and input must be given for PyFunge.
# Hexdump
```
00000000: 766f 6964 206d 6169 6e28 297b 2f2f 5c0a void main(){//\.
00000010: 2f2a 1b53 6d69 561b 5a5a 3b6f 6f6f 223e /*.SmiV.ZZ;ooo">
00000020: 3c3e 220a 2364 6566 696e 6520 5322 220a <>".#define S"".
00000030: 2369 6664 6566 205f 5f4f 424a 435f 5f0a #ifdef __OBJC__.
00000040: 2364 6566 696e 6520 5322 2d65 7669 7463 #define S"-evitc
00000050: 656a 624f 220a 2365 6e64 6966 0a70 7269 ejbO".#endif.pri
00000060: 6e74 6628 2243 2253 292f 2a2f 696d 706f ntf("C"S)/*/impo
00000070: 7274 2073 7464 2e73 7464 696f 3b22 4422 rt std.stdio;"D"
00000080: 2e77 7269 7465 2f2a 2a2f 3b7d 2f2a 0a3e .write/**/;}/*.>
00000090: 2242 6566 756e 6765 2d39 3822 3b22 4265 "Befunge-98";"Be
000000a0: 6675 6e67 652d 3933 222c 2c2c 2c2c 2c2c funge-93",,,,,,,
000000b0: 2c2c 2c40 3b39 6b2c 400a 202c 7756 6b6b ,,,@;9k,@. ,wVkk
000000c0: 5f2c 7865 5776 6c3c 685f 565a 556e 2a2f _,xeWvl<h_VZUn*/
000000d0: 2f2f e28e 9a6c 616f 6372 6168 43 //...laocrahC
```
# How?
Befunge-93 does not know what `;` is (in Befunge-98, it skips commands until the next `;`), so it ignores it. Allowing us to distinguish the two versions of Befunge. Also, the Somme portion was modified to work using [this script](https://github.com/ConorOBrien-Foxx/Somme/blob/master/somme-help.rb)
[Answer]
# 10. FreeDOS COM file, 277 bytes
This should work in MS-DOS and DOSbox too, but I can't test that right now, so better safe than sorry.
```
void /*hL!X-@ P^h~~X@@0D 0D"hp!X-@ PZh )X5 M!M elif MOC SODeerF$*/main(){//\
/*SmiVZZ;ooo"><>"
#define S""
#ifdef __OBJC__
#define S"-evitcejbO"
#endif
printf("C"S)/*/import std.stdio;"D".write/**/;}/*
>"Befunge-98";"Befunge-93";,,,,,,,,,,@
,wVkJ7-;l(e[Kt!m[*///⎚laocrahC
```
Prints:
* `D` in D
* `emmoS` in Somme
* `><>` in ><>
* `C` in C
* `laocrahC` in Charcoal
* `miV` in Vim
* `C-evitcejbO` in Objective-C
* `89-egnufeB` in Befunge-98
* `39-egnufeB` in Befunge-93
* `elif MOC SODeerF` in FreeDOS COM file
[Try it online!](https://tio.run/##rRnZVttI9hn9wrzcGBpJYFs2JIQYzARs06GbBE5MMnSM45alkq2gxUcL2J1Of8J8wHze/Ejm3qqSLC9J95kZzsFU1d3XumWGZjz@@nUTTm0bTGAjMx0F5iUkIe4moTcbeWECCYsTGJtRwOIYhjN447L2b@zTfThUNqEVep45iRmUWqHNSmAGNpROo1HqsyCJSxAzK3HDIAYnjGDIkoRFwKYTFrkssJiiWGYCJ2AhrZKEqTWGSeQioYKsXQdmYQom6ZYxLINv3jOI04iRln5ou84MUEJ1MoM4hGSM/JIxmyEJAzewvNRmNi7oEDw3uFeYNQ6hEkBpq15C0YK2cLpHp3YY06lyefrmx3enP3YGF2/andtmXTn75abTbZa2tEcLKtYxKa6XFCcNuJngmcEoNUdM0z8rG5xnaRO2FrlUYatehi3OCf2J7i0pG1fvbq7f3RDjIcYEWXN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HRLLGkcaFEZHOEQW9eO6JQZGjIvctfJQM8Uq45wApFRERTifiRSuOs@8ui7e1vFTUd4Hr46hAX1fwf80ke3XI/4GCNwut@Z2iFjr6N4mlD5Eu3@TECg9cKv8DxR@F6Gi7AeKbsYa8lYSfR/macni5xMtEul9rFKpLHD37c24f13HbRJWf1lBSbfrsnP7JheYMmRc@EteDwzlXWXxrFTp40Vhpdxzw/GDOYLkVFxsOXv2FbiKYWnZjnvH05Mw2lngayq8VcdOAwgQ2H@uo6HRJZbO/TFWZU5HNq2RzT0iSHD2cfFeIbDC6Qi8zfFGxaTl7oLEg9VlkYvHSA4/Km/@jkj9qCtlDqL@5Ey0ygxHTKHJlDNwBfh7iI6lX9JCkk5ZnO2lRvuUa9/l4U0zSnnzRcCX512LiWzitgMR1x9a5UNEcvq4hJdGMhIzNwPb4y3hBHN/gREhf/GMV/cxmHSq0QsWV0uA@CB@DIl1DlBvu89lP8tf0/wA) (runs all languages and generates an answer template, except COM file, which uses a really minimal x86 emulator I wrote. If you change the code so much that you hit an unimplemented instruction or interrupt, either implement it or drop a comment on one of my answers here)
Next answer must not exceed 360 bytes.
## Hexdump
```
00000000: 766f 6964 202f 2a68 4c21 582d 4020 505e void /*hL!X-@ P^
00000010: 687e 7e58 4040 3044 2030 4422 6870 2158 h~~X@@0D 0D"hp!X
00000020: 2d40 2050 5a68 2029 5835 2020 4d21 4d20 -@ PZh )X5 M!M
00000030: 656c 6966 204d 4f43 2053 4f44 6565 7246 elif MOC SODeerF
00000040: 242a 2f6d 6169 6e28 297b 2f2f 5c0a 2f2a $*/main(){//\./*
00000050: 1b53 6d69 561b 5a5a 3b6f 6f6f 223e 3c3e .SmiV.ZZ;ooo"><>
00000060: 220a 2364 6566 696e 6520 5322 220a 2369 ".#define S"".#i
00000070: 6664 6566 205f 5f4f 424a 435f 5f0a 2364 fdef __OBJC__.#d
00000080: 6566 696e 6520 5322 2d65 7669 7463 656a efine S"-evitcej
00000090: 624f 220a 2365 6e64 6966 0a70 7269 6e74 bO".#endif.print
000000a0: 6628 2243 2253 292f 2a2f 696d 706f 7274 f("C"S)/*/import
000000b0: 2073 7464 2e73 7464 696f 3b22 4422 2e77 std.stdio;"D".w
000000c0: 7269 7465 2f2a 2a2f 3b7d 2f2a 0a3e 2242 rite/**/;}/*.>"B
000000d0: 6566 756e 6765 2d39 3822 3b22 4265 6675 efunge-98";"Befu
000000e0: 6e67 652d 3933 223b 2c2c 2c2c 2c2c 2c2c nge-93";,,,,,,,,
000000f0: 2c2c 400a 202c 7756 6b4a 372d 3b6c 2865 ,,@. ,wVkJ7-;l(e
00000100: 5b4b 7421 6d5b 2a2f 2f2f e28e 9a6c 616f [Kt!m[*///...lao
00000110: 6372 6168 43 crahC
```
## Explanation
`vo` is a `jbe`, but FreeDOS explicitly sets the flags on entry to guarantee that this jump is never taken. This should also be the case on MS-DOS and DOSbox, but I can't test it right now.
`id /*` clobbers the stack pointer with `imul sp, [si+0x20], 0x2a2f`, but the result is always the same, since SI always points at the beginning of the code. The result of this multiplication is high enough to not interfere with the code during execution.
The rest is just standard printable x86 assembly. Here's the `yasm` source code:
```
org 0x100
bits 16
start:
jbe short start+0x71
imul sp, [si+0x20], 0x2a2f
push patch+0x2020
pop ax
sub ax, 0x2040
push ax
pop si
push 0x7e7e
pop ax
inc ax
inc ax
xor [si+0x20], al
xor [si+0x22], al
push msg+0x2040
pop ax
sub ax, 0x2040
push ax
pop dx
push 0x2920
pop ax
xor ax, 0x2020
patch:
db 0x4d, 0x21, 0x4d, 0x20 ; int 0x21 / int 0x20
msg:
db "elif MOC SODeerF$"
```
[Answer]
# 17. brain-flak, 613 bytes
```
void /*hL!X-@ P^h~~X@@0D 0D"hp!X-@ PZh +X5 "M!M elif MOC SODeerF$+[*/main(){//\
/+\
1+///\
/*SmiVZZ;ooo"loG";?=0%S!11ooo<"><>"
#define S""
#ifdef __OBJC__
#define S"-evitcejbO"
#endif
printf("C"S)/*/import std.stdio;"D".write/**/;}/*<<
"rT";#z_"B",@>2+; > ][ v;#;8k,7y2-;@,, <<<
>"Befunge-96"#^Z00G#^_$4->1+>,,,,,,,,,,@
noj6ZR42[jeeOCy(dm*///)]]⎚¿⁵laocrahC¦++++[-<+++++>]<[-<++++++<+++++<+++++>>>]<<<+++++++.>-.>---.<<-----.++++++++.-----.>--.>---.<+.>>>((((((((((()()()){}){}){}){}()){})((()()()()){}){})[(([][]){}){}()])([]()){})[]())(([[][]()]([]()((((([][][])){}{})[]){})))[]())@,ka"89-egnufenU"
```
Prints:
* `D` in D
* `emmoS` in Somme
* `><>` in ><>
* `C` in C
* `laocrahC` in Charcoal
* `miV` in Vim
* `C-evitcejbO` in Objective-C
* `89-egnufeB` in Befunge-98
* `39-egnufeB` in Befunge-93
* `elif MOC SODeerF` in FreeDOS COM file
* `><>loG` in Gol><>
* `89-egnufenU` in Unefunge-98
* `79-egnufeB` in Befunge-97
* `69-egnufeB` in Befunge-96
* `kcufniarb` in brainfuck
* `89-egnuferT` in Trefunge-98
* `kalf-niarb` in brain-flak
[Try it online!](https://tio.run/##rRpZctvI9Vu4Qn7akGwAIkCQlC1LFMnRbiuRLZUlzzimaA4INEhYWFhYJNIeT1UukAPkALlBvlM1R5mLOO91N0BwkT2VhLao7n5rv7Ub0MBKRl@/rpMDxyEWoUMrG4bWOUkjmI0jfzr0o5SkNEnJyIpDmiRkMCWvPXr8iX68jQbSOjmKfN8aJ5TIR5FDZWKFDpEP4mEW0DBNZJJQO/WiMCFuFJMBTVMaEzoZ09ijoU0lybZS0iE20Ep@SIyEDdlXdeCSdXJI3SwcUmN3S0qjzB6RcewBYwlEey6ZRhmxUPdcoE4C65aSJIsp7iKIHM@dEtCgOp6SJCLpCOSlIzoFEkq80PYzhzowwEXie@GtRO1RRIyQyBt1GVTjtKXVBq46UTK/uoWrSRQE1HC9CcKk8TQdReHWwur5wesXbw9enPTPXh@fvGvXpcO/Xp9cteUN9d4mht3CrWuyBLtmhiO@FQ4za0hV7bO0xuTJ62RjnkuVbNR1ssE4g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fj@LNqiCU1ebz7rLLVyJ9o8xfqnJWsiz8B@A8)
Next answer must not exceed 796 bytes.
## Hexdump
```
00000000: 766f 6964 202f 2a68 4c21 582d 4020 505e void /*hL!X-@ P^
00000010: 687e 7e58 4040 3044 2030 4422 6870 2158 h~~X@@0D 0D"hp!X
00000020: 2d40 2050 5a68 202b 5835 2022 4d21 4d20 -@ PZh +X5 "M!M
00000030: 656c 6966 204d 4f43 2053 4f44 6565 7246 elif MOC SODeerF
00000040: 242b 5b2a 2f6d 6169 6e28 297b 2f2f 5c0a $+[*/main(){//\.
00000050: 202f 2b5c 0a31 2b2f 2f2f 5c0a 2f2a 1b53 /+\.1+///\./*.S
00000060: 6d69 561b 5a5a 3b6f 6f6f 226c 6f47 223b miV.ZZ;ooo"loG";
00000070: 3f3d 3025 5321 3131 6f6f 6f3c 223e 3c3e ?=0%S!11ooo<"><>
00000080: 220a 2364 6566 696e 6520 5322 220a 2369 ".#define S"".#i
00000090: 6664 6566 205f 5f4f 424a 435f 5f0a 2364 fdef __OBJC__.#d
000000a0: 6566 696e 6520 5322 2d65 7669 7463 656a efine S"-evitcej
000000b0: 624f 220a 2365 6e64 6966 0a70 7269 6e74 bO".#endif.print
000000c0: 6628 2243 2253 292f 2a2f 696d 706f 7274 f("C"S)/*/import
000000d0: 2073 7464 2e73 7464 696f 3b22 4422 2e77 std.stdio;"D".w
000000e0: 7269 7465 2f2a 2a2f 3b7d 2f2a 3c3c 0a20 rite/**/;}/*<<.
000000f0: 2272 5422 3b23 7a5f 2242 222c 403e 322b "rT";#z_"B",@>2+
00000100: 3b20 203e 2020 2020 5d5b 2076 3b23 3b38 ; > ][ v;#;8
00000110: 6b2c 3779 322d 3b40 2c2c 203c 3c3c 0a3e k,7y2-;@,, <<<.>
00000120: 2242 6566 756e 6765 2d39 3622 235e 5a30 "Befunge-96"#^Z0
00000130: 3047 235e 5f24 342d 3e31 2b3e 2c2c 2c2c 0G#^_$4->1+>,,,,
00000140: 2c2c 2c2c 2c2c 400a 6e6f 6a36 5a52 3432 ,,,,,,@.noj6ZR42
00000150: 5b6a 6565 4f43 7928 646d 2a2f 2f2f 295d [jeeOCy(dm*///)]
00000160: 5de2 8e9a c2bf e281 b56c 616f 6372 6168 ]........laocrah
00000170: 43c2 a62b 2b2b 2b5b 2d3c 2b2b 2b2b 2b3e C..++++[-<+++++>
00000180: 5d3c 5b2d 3c2b 2b2b 2b2b 2b3c 2b2b 2b2b ]<[-<++++++<++++
00000190: 2b3c 2b2b 2b2b 2b3e 3e3e 5d3c 3c3c 2b2b +<+++++>>>]<<<++
000001a0: 2b2b 2b2b 2b2e 3e2d 2e3e 2d2d 2d2e 3c3c +++++.>-.>---.<<
000001b0: 2d2d 2d2d 2d2e 2b2b 2b2b 2b2b 2b2b 2e2d -----.++++++++.-
000001c0: 2d2d 2d2d 2e3e 2d2d 2e3e 2d2d 2d2e 3c2b ----.>--.>---.<+
000001d0: 2e3e 3e3e 2828 2828 2828 2828 2828 2829 .>>>((((((((((()
000001e0: 2829 2829 297b 7d29 7b7d 297b 7d29 7b7d ()()){}){}){}){}
000001f0: 2829 297b 7d29 2828 2829 2829 2829 2829 ()){})((()()()()
00000200: 297b 7d29 7b7d 295b 2828 5b5d 5b5d 297b ){}){})[(([][]){
00000210: 7d29 7b7d 2829 5d29 285b 5d28 2929 7b7d }){}()])([]()){}
00000220: 295b 5d28 2929 2828 5b5b 5d5b 5d28 295d )[]())(([[][]()]
00000230: 285b 5d28 2928 2828 2828 5b5d 5b5d 5b5d ([]()((((([][][]
00000240: 2929 7b7d 7b7d 295b 5d29 7b7d 2929 295b )){}{})[]){})))[
00000250: 5d28 2929 402c 6b61 2238 392d 6567 6e75 ]())@,ka"89-egnu
00000260: 6665 6e55 22 fenU"
```
## How
I switched around some code to balance the brackets. I don't know how the brainflak works. Many thanks to @CatWizard (if that's still his username) ~~for the brainflak portion [in chat](https://chat.stackexchange.com/transcript/message/45447490#45447490)~~. Per @JoKing's comment, I changed it to outputting "brain-flak" reversed with [his script](https://codegolf.stackexchange.com/a/157666/55550).
[Answer]
# 46. Curry, 3755 bytes
I tested this with different implementations (Sloth, KiCS2 and PAKCS) but only PAKCS (tested with version 2.0.2-b7) allowed me to get the BangPatterns to work:
```
void /*-{-- #hR!X-@ P^h~~X@@0D 0D"hv!X-@ PZh +X5 "M!M eliF MOC SODeerF$}++++[*///opfzzfzzfzzfzzzfzzfzfzfffzffzzzzzffzfzzzffzfzzzfzfzfzzfzfzzzfzfzfzzfzfzfffzzfzfzzzfzffff⠆⡆⠆⡆⠆⡆⠆⡆⠆⡆⠆⡆⠆⡆\
/+ #\
basename "$(readlink /proc/$$/exe)"|rev;:<<'EOF' #>>\
1+/// O\
/* ggcGmiVZZ;ooo"loG";?=0%S!11ooo<"><>"
#define S"C" //A
#ifdef __cplusplus//l
f(); //i
#include<cstdio>//c
#define S"++C" //e
int/// "
#endif// \.
#ifdef __OBJC__
#define S"C-evitceJbO"
#endif
main(){printf(S)/*/main(){import std.stdio;"D".write/**/;}/*}<
> vwWWWWwWWWWWwvwWWwWWWwvwWWwWWWwvwWWwWWWwvwWWwWWWwvwWWwWWWwvwWWwWWWwvWwwwwwwwwwwwWWWwWWWWWWwWWWWWWWwWWWWWWWWWwWWWWWWWWWWWWwWWWWWWWWWWwWWWWWWWWWWWWWWWWWwWWWWWWWWWWWWWWWWWWwWWWWWWWWWWWWWWWWWWwWWWWWWWWWWWWWWWWWWWwwWWWWWWWWWWWWWWWWWWWWwwwwwwWWWWWWWWWWWWWWWWWWWWWwwwwwWWWWWWWWWWWWWWWWWWWWWWwwwwwwwwwww
999 999 99
999 999 9
999v<>0000110110
v <>"efunge-98",,,,,,,,,7y3-v< @
> #^Gv @,"B"_"Tr",,@
v<[_"]Befunge-93">,,,,,,,,,,0|@<
>#<"Befunge-96"> ^v$G001
v ,,,,,"79-egnufeB" _ v<
> ,,,,,@# ,"79-egnuferT"_v# $G0001<>
<>10000G$v
#@,,,,,,,,,,,,,,@#"79-egnuferdauQ"_100000G$v
,,"79-egnufetniuQ"_1000000G$!v@,,,,,,,,,,,,
"79-egnufetpeS"_"Sexefunge-97"#@,,,,,,,,,,,,@#,
<>"v"@
@,"F","u","n","c","t","o","i","d"<> red down two red left one yellow up green down yellow up green down red up three red right two yellow down yellow down blue left green down red down one yellow down blue left green down red down two red left one yellow up yellow down blue left green down red left one red down three yellow down yellow down blue left green down red up two green down yellow up yellow down blue left red up three red right two yellow down yellow down blue left 0001110000100000100010000010000010100000100000000010001000100000100010000010000010100000100000100010000010001000100000000010001000001000100011000010001000100000100011000010000010001000001000100000100000100000100010000010001000001000100000000010001000001000100010000000110000110000011000001001100000100010001000100010000001001101110000001100111100011001100000001001110011110000110111000001000000010000000100000001000000010000000100000001000000010001100011011110001000100010000010001010000100000001000100000001000000010000000100000001000000010000000100000000100110
01 & && &&& & {}]⎚F¹laocrahC«▲²²²²²⌂↨α↨ß↨²²⌂↨←ß≤▼→▼←≥→⌂↨σ→→→↨ß→→→↨π→→→→→↨¡ß¡→→↨δ→↨ß→→→→↨µ→→→↨¡φ↨επ⌂↨¡ß¡→→→↨¡πσ▲⌂↨¡σµ¡→↨¡α¡→↨¡π¡▲▲▲¡▲▲▲¡σ▲¡δ¡φ▲▲▲▲¡ε▼▼¡»+[-++++[-<+++++>]<[-<++++++<+++++<+++++>>>]<<<+++++++.>-.>---.<<-----.++++++++.-----.>--.>---.<+.>>>](()()()()())<>(()())<>{({}[()])<>({({})({}[()])}{})<>}<>((){[()](<{}((((((((((()()()){}){}){}){}()){})((()()()()){}){})[(([][]){}){}()])([]()){})[]())(([[][]()]([]()((((([][][])){}{})[]){})))[]())>)}{}){{}(<((((((((((((((()()()){}){}){}){}()){})((()()()()){}){})[(([][]){}){}()])([]()){})[]())[[]()()()])[])[[]()()()()])[][][][()])((((((()()()){}()){}){}){})[()()])>)}{}({ -}_=")";x--?y
=y;y="yrruC";(!)=seq;main=let b!_=""in putStr$(""!"snrettaPgnaB+")++y--?"lleksaH"
--N'Zi(Tji8=@/BmU2)[-]<>\[\<>\\/<>\/\[/\/\<><><>\[/\/\/<>\//\/<><><><><>\\]/\//\//\/\]/\/\\./]s*///∙SAVNACp💬ijome💬➡😭Emotinomicon😲⏪⏬⏩@,ka"89-egnufenUsssssaaaaaeeeeeeeeeepaeeeeeeeeeecisaeeeeeeejiiiiiiiijeeeeeeeeeeeeeeeeeejzaciiiiiiiiiiiiijeeeaceeacewuuuweejiiiijiiiiiiiiiiijeeeaaaakeeaaaawvw⠀⠖⠗⠎⢎⢦⢦⠮"
```
Prints:
* `D` in D
* `emmoS` in Somme
* `><>` in ><>
* `C` in C
* `laocrahC` in Charcoal
* `miV` in Vim
* `C-evitceJbO` in ObJective-C
* `89-egnufeB` in Befunge-98
* `39-egnufeB` in Befunge-93
* `eliF MOC SODeerF` in FreeDOS COM file
* `><>loG` in Gol><>
* `89-egnufenU` in Unefunge-98
* `79-egnufeB` in Befunge-97
* `69-egnufeB` in Befunge-96
* `kcufniarb` in brainfuck
* `89-egnuferT` in Trefunge-98
* `kalf-niarb` in brain-flak
* `hsab` in bash
* `lleksaH` in Haskell
* `hsz` in zsh
* `ijome` in emoji
* `snrettaPgnaB+lleksaH` in Haskell+BangPatterns
* `++C` in C++
* `nocimonitomE` in Emotinomicon
* `hsk` in ksh
* `hsad` in dash
* `79-egnuferT` in Trefunge-97
* `ecilA` in Alice
* `79-egnuferdauQ` in Quadrefunge-97
* `99` in 99
* `79-egnufetniuQ` in Quintefunge-97
* `kcufniarb cilobmys` in symbolic brainfuck
* `79-egnufexeS` in Sexefunge-97
* `senots` in stones
* `79-egnufetpeS` in Septefunge-97
* `diotcnuF` in Functoid
* `ssarG` in Grass
* `kcuhpla` in alphuck
* `SAVNAC` in CANVAS
* `egaugnal sseleman` in nameless language
* `LIve` in evil
* `V` in V
* `elliarb` in braille
* `68xalfniarb` in BrainFlaX86
* `NOOPS` in Spoon
* `yrruC` in Curry
[Try it online!](https://tio.run/##rTvbcttGls/CL8xLG1IMQCQIUbJliSIZ3WV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vjuCWNPGu@otSWS403K4IdmmMq0fuiMv8VFe97EZJhZK2VlnF7AmQojdFHIIYFmKK8Xl3Jr94yVleEcvI@DQQNZT9Fi0MApkT88ST0F2ZYkN4phL0waroZLrwMUlZJ94AG@DMq0p3E4kRlELc9AcdLuiYRtTpLYVeZQd5E4k6fyEbJVwRVVfF9qh9qfmooqVYrKK5AZJT3/w)
Next answer must not exceed 4881 bytes.
## Explanation
As with the Haskell one the code defines the `(/*-)` operator, then it goes on to define the operator `(--?)` which only Haskell recognizes, Curry treats everything after the `x` as comment:
```
void /*-{- ...
-}_=")";x--?y
```
So we define `x --? y = y` for Haskell and then the expression (needs to be at the end of a line) `"yrruC"--?"lleksaH"` will evaluate to the right string in each language:
```
=y;y="yrruC";(!)=seq;main=let b!_=""in putStr$(""!"snrettaPgnaB+")++y--?"lleksaH"
```
The above code makes sure that the `-XBangPatterns` flag is still recognized, I had to rewrite that a little to make sure Curry works well with it.
## Hexdump
```
00000000: 766f 6964 202f 2a2d 7b2d 2d20 2368 5221 void /*-{-- #hR!
00000010: 582d 4020 505e 687e 7e58 4040 3044 2030 X-@ P^h~~X@@0D 0
00000020: 4422 6876 2158 2d40 2050 5a68 202b 5835 D"hv!X-@ PZh +X5
00000030: 2022 4d21 4d20 656c 6946 204d 4f43 2053 "M!M eliF MOC S
00000040: 4f44 6565 7246 247d 2b2b 2b2b 5b2a 2f2f ODeerF$}++++[*//
00000050: 2f6f 7066 7a7a 667a 7a66 7a7a 667a 7a7a /opfzzfzzfzzfzzz
00000060: 667a 7a66 7a66 7a66 6666 7a66 667a 7a7a fzzfzfzfffzffzzz
00000070: 7a7a 6666 7a66 7a7a 7a66 667a 667a 7a7a zzffzfzzzffzfzzz
00000080: 667a 667a 667a 7a66 7a66 7a7a 7a66 7a66 fzfzfzzfzfzzzfzf
00000090: 7a66 7a7a 667a 667a 6666 667a 7a66 7a66 zfzzfzfzfffzzfzf
000000a0: 7a7a 7a66 7a66 6666 66e2 a086 e2a1 86e2 zzzfzffff.......
000000b0: a086 e2a1 86e2 a086 e2a1 86e2 a086 e2a1 ................
000000c0: 86e2 a086 e2a1 86e2 a086 e2a1 86e2 a086 ................
000000d0: e2a1 865c 0a20 2f2b 2023 5c0a 2062 6173 ...\. /+ #\. bas
000000e0: 656e 616d 6520 2224 2872 6561 646c 696e ename "$(readlin
000000f0: 6b20 2f70 726f 632f 2424 2f65 7865 2922 k /proc/$$/exe)"
00000100: 7c72 6576 3b3a 3c3c 2745 4f46 2720 233e |rev;:<<'EOF' #>
00000110: 3e5c 0a31 2b2f 2f2f 2020 2020 2020 2020 >\.1+///
00000120: 2020 2020 2020 2020 2020 4f5c 0a2f 2a20 O\./*
00000130: 1b67 6763 476d 6956 1b5a 5a3b 6f6f 6f22 .ggcGmiV.ZZ;ooo"
00000140: 6c6f 4722 3b3f 3d30 2553 2131 316f 6f6f loG";?=0%S!11ooo
00000150: 3c22 3e3c 3e22 0a23 6465 6669 6e65 2053 <"><>".#define S
00000160: 2243 2220 2020 2020 2020 2f2f 410a 2369 "C" //A.#i
00000170: 6664 6566 205f 5f63 706c 7573 706c 7573 fdef __cplusplus
00000180: 2f2f 6c0a 2066 2829 3b20 2020 2020 2020 //l. f();
00000190: 2020 2020 202f 2f69 0a23 696e 636c 7564 //i.#includ
000001a0: 653c 6373 7464 696f 3e2f 2f63 0a23 6465 e<cstdio>//c.#de
000001b0: 6669 6e65 2053 222b 2b43 2220 2f2f 650a fine S"++C" //e.
000001c0: 2069 6e74 2f2f 2f20 2020 2020 2020 2020 int///
000001d0: 220a 2365 6e64 6966 2f2f 2020 2020 2020 ".#endif//
000001e0: 205c 2e0a 2369 6664 6566 205f 5f4f 424a \..#ifdef __OBJ
000001f0: 435f 5f0a 2364 6566 696e 6520 5322 432d C__.#define S"C-
00000200: 6576 6974 6365 4a62 4f22 0a23 656e 6469 evitceJbO".#endi
00000210: 660a 206d 6169 6e28 297b 7072 696e 7466 f. main(){printf
00000220: 2853 292f 2a2f 6d61 696e 2829 7b69 6d70 (S)/*/main(){imp
00000230: 6f72 7420 7374 642e 7374 6469 6f3b 2244 ort std.stdio;"D
00000240: 222e 7772 6974 652f 2a2a 2f3b 7d2f 2a7d ".write/**/;}/*}
00000250: 3c0a 3e20 2076 7757 5757 5777 5757 5757 <.> vwWWWWwWWWW
00000260: 5777 7677 5757 7757 5757 7776 7757 5777 WwvwWWwWWWwvwWWw
00000270: 5757 5777 7677 5757 7757 5757 7776 7757 WWWwvwWWwWWWwvwW
00000280: 5777 5757 5777 7677 5757 7757 5757 7776 WwWWWwvwWWwWWWwv
00000290: 7757 5777 5757 5777 7657 7777 7777 7777 wWWwWWWwvWwwwwww
000002a0: 7777 7777 7757 5757 7757 5757 5757 5777 wwwwwWWWwWWWWWWw
000002b0: 5757 5757 5757 5777 5757 5757 5757 5757 WWWWWWWwWWWWWWWW
000002c0: 5777 5757 5757 5757 5757 5757 5757 7757 WwWWWWWWWWWWWWwW
000002d0: 5757 5757 5757 5757 5777 5757 5757 5757 WWWWWWWWWwWWWWWW
000002e0: 5757 5757 5757 5757 5757 5777 5757 5757 WWWWWWWWWWWwWWWW
000002f0: 5757 5757 5757 5757 5757 5757 5757 7757 WWWWWWWWWWWWWWwW
00000300: 5757 5757 5757 5757 5757 5757 5757 5757 WWWWWWWWWWWWWWWW
00000310: 5777 5757 5757 5757 5757 5757 5757 5757 WwWWWWWWWWWWWWWW
00000320: 5757 5757 5777 7757 5757 5757 5757 5757 WWWWWwwWWWWWWWWW
00000330: 5757 5757 5757 5757 5757 5777 7777 7777 WWWWWWWWWWWwwwww
00000340: 7757 5757 5757 5757 5757 5757 5757 5757 wWWWWWWWWWWWWWWW
00000350: 5757 5757 5757 7777 7777 7757 5757 5757 WWWWWWwwwwwWWWWW
00000360: 5757 5757 5757 5757 5757 5757 5757 5757 WWWWWWWWWWWWWWWW
00000370: 5777 7777 7777 7777 7777 7777 0a39 3939 Wwwwwwwwwwww.999
00000380: 2039 3939 2039 390a 3939 3920 3939 3920 999 99.999 999
00000390: 390a 3939 3976 3c3e 3030 3030 3131 3031 9.999v<>00001101
000003a0: 3130 0a76 2020 3c3e 2265 6675 6e67 652d 10.v <>"efunge-
000003b0: 3938 222c 2c2c 2c2c 2c2c 2c2c 3779 332d 98",,,,,,,,,7y3-
000003c0: 763c 2040 0a3e 2020 235e 4776 2020 2020 v< @.> #^Gv
000003d0: 2020 2020 2020 2020 2020 2020 2040 2c22 @,"
000003e0: 4222 5f22 5472 222c 2c40 0a20 2020 763c B"_"Tr",,@. v<
000003f0: 5b5f 225d 4265 6675 6e67 652d 3933 223e [_"]Befunge-93">
00000400: 2c2c 2c2c 2c2c 2c2c 2c2c 307c 403c 0a20 ,,,,,,,,,,0|@<.
00000410: 2020 3e23 3c22 4265 6675 6e67 652d 3936 >#<"Befunge-96
00000420: 223e 205e 7624 4730 3031 0a76 2020 2c2c "> ^v$G001.v ,,
00000430: 2c2c 2c22 3739 2d65 676e 7566 6542 2220 ,,,"79-egnufeB"
00000440: 5f20 2020 2020 2020 2020 2020 2020 2020 _
00000450: 2020 2076 3c0a 3e20 202c 2c2c 2c2c 4023 v<.> ,,,,,@#
00000460: 2020 2020 2020 2c22 3739 2d65 676e 7566 ,"79-egnuf
00000470: 6572 5422 5f76 2320 2447 3030 3031 3c3e erT"_v# $G0001<>
00000480: 0a20 2020 2020 2020 2020 2020 2020 2020 .
00000490: 2020 2020 2020 2020 2020 2020 2020 203c <
000004a0: 3e31 3030 3030 4724 760a 2020 2020 2023 >10000G$v. #
000004b0: 402c 2c2c 2c2c 2c2c 2c2c 2c2c 2c2c 2c40 @,,,,,,,,,,,,,,@
000004c0: 2322 3739 2d65 676e 7566 6572 6461 7551 #"79-egnuferdauQ
000004d0: 225f 3130 3030 3030 4724 760a 2020 2020 "_100000G$v.
000004e0: 2020 2020 2020 2020 2020 2020 2020 2020
000004f0: 2020 2020 2020 2020 2020 2c2c 2237 392d ,,"79-
00000500: 6567 6e75 6665 746e 6975 5122 5f31 3030 egnufetniuQ"_100
00000510: 3030 3030 4724 2176 402c 2c2c 2c2c 2c2c 0000G$!v@,,,,,,,
00000520: 2c2c 2c2c 2c0a 2020 2020 2020 2020 2020 ,,,,,.
00000530: 2020 2020 2020 2020 2020 2020 2020 2020
00000540: 2020 2020 2020 2020 2020 2020 2020 2020
00000550: 2020 2237 392d 6567 6e75 6665 7470 6553 "79-egnufetpeS
00000560: 225f 2253 6578 6566 756e 6765 2d39 3722 "_"Sexefunge-97"
00000570: 2340 2c2c 2c2c 2c2c 2c2c 2c2c 2c2c 4023 #@,,,,,,,,,,,,@#
00000580: 2c0a 2020 2020 2020 2020 2020 2020 2020 ,.
00000590: 2020 2020 2020 2020 2020 2020 2020 2020
000005a0: 203c 3e22 7622 400a 2040 2c22 4622 2c22 <>"v"@. @,"F","
000005b0: 7522 2c22 6e22 2c22 6322 2c22 7422 2c22 u","n","c","t","
000005c0: 6f22 2c22 6922 2c22 6422 3c3e 2072 6564 o","i","d"<> red
000005d0: 2064 6f77 6e20 7477 6f20 7265 6420 6c65 down two red le
000005e0: 6674 206f 6e65 2079 656c 6c6f 7720 7570 ft one yellow up
000005f0: 2067 7265 656e 2064 6f77 6e20 7965 6c6c green down yell
00000600: 6f77 2075 7020 6772 6565 6e20 646f 776e ow up green down
00000610: 2072 6564 2075 7020 7468 7265 6520 7265 red up three re
00000620: 6420 7269 6768 7420 7477 6f20 7965 6c6c d right two yell
00000630: 6f77 2064 6f77 6e20 7965 6c6c 6f77 2064 ow down yellow d
00000640: 6f77 6e20 626c 7565 206c 6566 7420 6772 own blue left gr
00000650: 6565 6e20 646f 776e 2072 6564 2064 6f77 een down red dow
00000660: 6e20 6f6e 6520 7965 6c6c 6f77 2064 6f77 n one yellow dow
00000670: 6e20 626c 7565 206c 6566 7420 6772 6565 n blue left gree
00000680: 6e20 646f 776e 2072 6564 2064 6f77 6e20 n down red down
00000690: 7477 6f20 7265 6420 6c65 6674 206f 6e65 two red left one
000006a0: 2079 656c 6c6f 7720 7570 2079 656c 6c6f yellow up yello
000006b0: 7720 646f 776e 2062 6c75 6520 6c65 6674 w down blue left
000006c0: 2067 7265 656e 2064 6f77 6e20 7265 6420 green down red
000006d0: 6c65 6674 206f 6e65 2072 6564 2064 6f77 left one red dow
000006e0: 6e20 7468 7265 6520 7965 6c6c 6f77 2064 n three yellow d
000006f0: 6f77 6e20 7965 6c6c 6f77 2064 6f77 6e20 own yellow down
00000700: 626c 7565 206c 6566 7420 6772 6565 6e20 blue left green
00000710: 646f 776e 2072 6564 2075 7020 7477 6f20 down red up two
00000720: 6772 6565 6e20 646f 776e 2079 656c 6c6f green down yello
00000730: 7720 7570 2079 656c 6c6f 7720 646f 776e w up yellow down
00000740: 2062 6c75 6520 6c65 6674 2072 6564 2075 blue left red u
00000750: 7020 7468 7265 6520 7265 6420 7269 6768 p three red righ
00000760: 7420 7477 6f20 7965 6c6c 6f77 2064 6f77 t two yellow dow
00000770: 6e20 7965 6c6c 6f77 2064 6f77 6e20 626c n yellow down bl
00000780: 7565 206c 6566 7420 3030 3031 3131 3030 ue left 00011100
00000790: 3030 3130 3030 3030 3130 3030 3130 3030 0010000010001000
000007a0: 3030 3130 3030 3030 3130 3130 3030 3030 0010000010100000
000007b0: 3130 3030 3030 3030 3030 3130 3030 3130 1000000000100010
000007c0: 3030 3130 3030 3030 3130 3030 3130 3030 0010000010001000
000007d0: 3030 3130 3030 3030 3130 3130 3030 3030 0010000010100000
000007e0: 3130 3030 3030 3130 3030 3130 3030 3030 1000001000100000
000007f0: 3130 3030 3130 3030 3130 3030 3030 3030 1000100010000000
00000800: 3030 3130 3030 3130 3030 3030 3130 3030 0010001000001000
00000810: 3130 3030 3131 3030 3030 3130 3030 3130 1000110000100010
00000820: 3030 3130 3030 3030 3130 3030 3131 3030 0010000010001100
00000830: 3030 3130 3030 3030 3130 3030 3130 3030 0010000010001000
00000840: 3030 3130 3030 3130 3030 3030 3130 3030 0010001000001000
00000850: 3030 3130 3030 3030 3130 3030 3130 3030 0010000010001000
00000860: 3030 3130 3030 3130 3030 3030 3130 3030 0010001000001000
00000870: 3130 3030 3030 3030 3030 3130 3030 3130 1000000000100010
00000880: 3030 3030 3130 3030 3130 3030 3130 3030 0000100010001000
00000890: 3030 3030 3131 3030 3030 3131 3030 3030 0000110000110000
000008a0: 3031 3130 3030 3030 3130 3031 3130 3030 0110000010011000
000008b0: 3030 3130 3030 3130 3030 3130 3030 3130 0010001000100010
000008c0: 3030 3130 3030 3030 3031 3030 3131 3031 0010000001001101
000008d0: 3131 3030 3030 3030 3131 3030 3131 3131 1100000011001111
000008e0: 3030 3031 3130 3031 3130 3030 3030 3030 0001100110000000
000008f0: 3130 3031 3131 3030 3131 3131 3030 3030 1001110011110000
00000900: 3131 3031 3131 3030 3030 3031 3030 3030 1101110000010000
00000910: 3030 3031 3030 3030 3030 3031 3030 3030 0001000000010000
00000920: 3030 3031 3030 3030 3030 3031 3030 3030 0001000000010000
00000930: 3030 3031 3030 3030 3030 3031 3030 3030 0001000000010000
00000940: 3030 3031 3030 3031 3130 3030 3131 3031 0001000110001101
00000950: 3131 3130 3030 3130 3030 3130 3030 3130 1110001000100010
00000960: 3030 3030 3130 3030 3130 3130 3030 3031 0000100010100001
00000970: 3030 3030 3030 3031 3030 3031 3030 3030 0000000100010000
00000980: 3030 3031 3030 3030 3030 3031 3030 3030 0001000000010000
00000990: 3030 3031 3030 3030 3030 3031 3030 3030 0001000000010000
000009a0: 3030 3031 3030 3030 3030 3031 3030 3030 0001000000010000
000009b0: 3030 3030 3130 3031 3130 0a30 3120 2620 0000100110.01 &
000009c0: 2626 2026 2626 2020 2020 2026 207b 7d5d && &&& & {}]
000009d0: e28e 9aef bca6 c2b9 6c61 6f63 7261 6843 ........laocrahC
000009e0: c2ab e296 b2c2 b2c2 b2c2 b2c2 b2c2 b2e2 ................
000009f0: 8c82 e286 a8ce b1e2 86a8 c39f e286 a8c2 ................
00000a00: b2c2 b2e2 8c82 e286 a8e2 8690 c39f e289 ................
00000a10: a4e2 96bc e286 92e2 96bc e286 90e2 89a5 ................
00000a20: e286 92e2 8c82 e286 a8cf 83e2 8692 e286 ................
00000a30: 92e2 8692 e286 a8c3 9fe2 8692 e286 92e2 ................
00000a40: 8692 e286 a8cf 80e2 8692 e286 92e2 8692 ................
00000a50: e286 92e2 8692 e286 a8c2 a1c3 9fc2 a1e2 ................
00000a60: 8692 e286 92e2 86a8 ceb4 e286 92e2 86a8 ................
00000a70: c39f e286 92e2 8692 e286 92e2 8692 e286 ................
00000a80: a8c2 b5e2 8692 e286 92e2 8692 e286 a8c2 ................
00000a90: a1cf 86e2 86a8 ceb5 cf80 e28c 82e2 86a8 ................
00000aa0: c2a1 c39f c2a1 e286 92e2 8692 e286 92e2 ................
00000ab0: 86a8 c2a1 cf80 cf83 e296 b2e2 8c82 e286 ................
00000ac0: a8c2 a1cf 83c2 b5c2 a1e2 8692 e286 a8c2 ................
00000ad0: a1ce b1c2 a1e2 8692 e286 a8c2 a1cf 80c2 ................
00000ae0: a1e2 96b2 e296 b2e2 96b2 c2a1 e296 b2e2 ................
00000af0: 96b2 e296 b2c2 a1cf 83e2 96b2 c2a1 ceb4 ................
00000b00: c2a1 cf86 e296 b2e2 96b2 e296 b2e2 96b2 ................
00000b10: c2a1 ceb5 e296 bce2 96bc c2a1 c2bb 2b5b ..............+[
00000b20: 2d2b 2b2b 2b5b 2d3c 2b2b 2b2b 2b3e 5d3c -++++[-<+++++>]<
00000b30: 5b2d 3c2b 2b2b 2b2b 2b3c 2b2b 2b2b 2b3c [-<++++++<+++++<
00000b40: 2b2b 2b2b 2b3e 3e3e 5d3c 3c3c 2b2b 2b2b +++++>>>]<<<++++
00000b50: 2b2b 2b2e 3e2d 2e3e 2d2d 2d2e 3c3c 2d2d +++.>-.>---.<<--
00000b60: 2d2d 2d2e 2b2b 2b2b 2b2b 2b2b 2e2d 2d2d ---.++++++++.---
00000b70: 2d2d 2e3e 2d2d 2e3e 2d2d 2d2e 3c2b 2e3e --.>--.>---.<+.>
00000b80: 3e3e 5d28 2829 2829 2829 2829 2829 293c >>](()()()()())<
00000b90: 3e28 2829 2829 293c 3e7b 287b 7d5b 2829 >(()())<>{({}[()
00000ba0: 5d29 3c3e 287b 287b 7d29 287b 7d5b 2829 ])<>({({})({}[()
00000bb0: 5d29 7d7b 7d29 3c3e 7d3c 3e28 2829 7b5b ])}{})<>}<>((){[
00000bc0: 2829 5d28 3c7b 7d28 2828 2828 2828 2828 ()](<{}(((((((((
00000bd0: 2828 2928 2928 2929 7b7d 297b 7d29 7b7d (()()()){}){}){}
00000be0: 297b 7d28 2929 7b7d 2928 2828 2928 2928 ){}()){})((()()(
00000bf0: 2928 2929 7b7d 297b 7d29 5b28 285b 5d5b )()){}){})[(([][
00000c00: 5d29 7b7d 297b 7d28 295d 2928 5b5d 2829 ]){}){}()])([]()
00000c10: 297b 7d29 5b5d 2829 2928 285b 5b5d 5b5d ){})[]())(([[][]
00000c20: 2829 5d28 5b5d 2829 2828 2828 285b 5d5b ()]([]()((((([][
00000c30: 5d5b 5d29 297b 7d7b 7d29 5b5d 297b 7d29 ][])){}{})[]){})
00000c40: 2929 5b5d 2829 293e 297d 7b7d 297b 7b7d ))[]())>)}{}){{}
00000c50: 283c 2828 2828 2828 2828 2828 2828 2828 (<((((((((((((((
00000c60: 2829 2829 2829 297b 7d29 7b7d 297b 7d29 ()()()){}){}){})
00000c70: 7b7d 2829 297b 7d29 2828 2829 2829 2829 {}()){})((()()()
00000c80: 2829 297b 7d29 7b7d 295b 2828 5b5d 5b5d ()){}){})[(([][]
00000c90: 297b 7d29 7b7d 2829 5d29 285b 5d28 2929 ){}){}()])([]())
00000ca0: 7b7d 295b 5d28 2929 5b5b 5d28 2928 2928 {})[]())[[]()()(
00000cb0: 295d 295b 5d29 5b5b 5d28 2928 2928 2928 )])[])[[]()()()(
00000cc0: 295d 295b 5d5b 5d5b 5d5b 2829 5d29 2828 )])[][][][()])((
00000cd0: 2828 2828 2829 2829 2829 297b 7d28 2929 ((((()()()){}())
00000ce0: 7b7d 297b 7d29 7b7d 295b 2829 2829 5d29 {}){}){})[()()])
00000cf0: 3e29 7d7b 7d28 7b20 2d7d 5f3d 2229 223b >)}{}({ -}_=")";
00000d00: 782d 2d3f 790a 203d 793b 793d 2279 7272 x--?y. =y;y="yrr
00000d10: 7543 223b 2821 293d 7365 713b 6d61 696e uC";(!)=seq;main
00000d20: 3d6c 6574 2062 215f 3d22 2269 6e20 7075 =let b!_=""in pu
00000d30: 7453 7472 2428 2222 2122 736e 7265 7474 tStr$(""!"snrett
00000d40: 6150 676e 6142 2b22 292b 2b79 2d2d 3f22 aPgnaB+")++y--?"
00000d50: 6c6c 656b 7361 4822 0a2d 2d4e 275a 6928 lleksaH".--N'Zi(
00000d60: 546a 6938 3d40 2f42 6d55 3229 5b2d 5d3c Tji8=@/BmU2)[-]<
00000d70: 3e5c 5b5c 3c3e 5c5c 2f3c 3e5c 2f5c 5b2f >\[\<>\\/<>\/\[/
00000d80: 5c2f 5c3c 3e3c 3e3c 3e5c 5b2f 5c2f 5c2f \/\<><><>\[/\/\/
00000d90: 3c3e 5c2f 2f5c 2f3c 3e3c 3e3c 3e3c 3e3c <>\//\/<><><><><
00000da0: 3e5c 5c5d 2f5c 2f2f 5c2f 2f5c 2f5c 5d2f >\\]/\//\//\/\]/
00000db0: 5c2f 5c5c 2e2f 5d73 2a2f 2f2f e288 9953 \/\\./]s*///...S
00000dc0: 4156 4e41 43ef bd90 f09f 92ac 696a 6f6d AVNAC.......ijom
00000dd0: 65f0 9f92 ace2 9ea1 f09f 98ad 456d 6f74 e...........Emot
00000de0: 696e 6f6d 6963 6f6e f09f 98b2 e28f aae2 inomicon........
00000df0: 8fac e28f a940 2c6b 6122 3839 2d65 676e .....@,ka"89-egn
00000e00: 7566 656e 5573 7373 7373 6161 6161 6165 ufenUsssssaaaaae
00000e10: 6565 6565 6565 6565 6570 6165 6565 6565 eeeeeeeeepaeeeee
00000e20: 6565 6565 6563 6973 6165 6565 6565 6565 eeeeecisaeeeeeee
00000e30: 6a69 6969 6969 6969 696a 6565 6565 6565 jiiiiiiiijeeeeee
00000e40: 6565 6565 6565 6565 6565 6565 6a7a 6163 eeeeeeeeeeeejzac
00000e50: 6969 6969 6969 6969 6969 6969 696a 6565 iiiiiiiiiiiiijee
00000e60: 6561 6365 6561 6365 7775 7575 7765 656a eaceeacewuuuweej
00000e70: 6969 6969 6a69 6969 6969 6969 6969 6969 iiiijiiiiiiiiiii
00000e80: 6a65 6565 6161 6161 6b65 6561 6161 6177 jeeeaaaakeeaaaaw
00000e90: 7677 e2a0 80e2 a096 e2a0 97e2 a08e e2a2 vw..............
00000ea0: 8ee2 a2a6 e2a2 a6e2 a0ae 22 .........."
```
[Answer]
# 49. boolfuck, 3989 bytes
```
void /*-{-- #hR!X-@ P^h~~X@@0D 0D"hv!X-@ PZh +X5 "M!M eliF MOC SODeerF$}++++-+[*///opfzzfzzfzzfzzzfzzfzfzfffzffzzzzzffzfzzzffzfzzzfzfzfzzfzfzzzfzfzfzzfzfzfffzzfzfzzzfzffff⠆⡆⠆⡆⠆⡆⠆⡆⠆⡆⠆⡆⠆⡆\
/+ #\
basename "$(readlink /proc/$$/exe)"|rev;:<<'EOF' #>>\
1+/// O\
/* ggcGmiVZZ;ooo"loG";?=0%S!11ooo<"><>"
#define S"C" //A
#ifdef __cplusplus//l
f(); //i
#include<cstdio>//c
#define S"++C" //e
int/// "
#endif// \.
#ifdef __OBJC__
#define S"C-evitceJbO"
#endif
main(){printf(S)/*/main(){import std.stdio;"D".write/**/;}/*}<
> vwWWWWwWWWWWwvwWWwWWWwvwWWwWWWwvwWWwWWWwvwWWwWWWwvwWWwWWWwvwWWwWWWwvWwwwwwwwwwwwWWWwWWWWWWwWWWWWWWwWWWWWWWWWwWWWWWWWWWWWWwWWWWWWWWWWwWWWWWWWWWWWWWWWWWwWWWWWWWWWWWWWWWWWWwWWWWWWWWWWWWWWWWWWwWWWWWWWWWWWWWWWWWWWwwWWWWWWWWWWWWWWWWWWWWwwwwwwWWWWWWWWWWWWWWWWWWWWWwwwwwWWWWWWWWWWWWWWWWWWWWWWwwwwwwwwwww
999 999 99
999 999 9
999v<>0000110110
v <>"efunge-98",,,,,,,,,7y3-v< @
> #^Gv @,"B"_"Tr",,@
v<[_"]Befunge-93">,,,,,,,,,,0|@<
>#<"Befunge-96"> ^v$G001
v ,,,,,"79-egnufeB" _ v<
> ,,,,,@# ,"79-egnuferT"_v# $G0001<>
<>10000G$v
#@,,,,,,,,,,,,,,@#"79-egnuferdauQ"_100000G$v
,,"79-egnufetniuQ"_1000000G$!v@,,,,,,,,,,,,
"79-egnufetpeS"_"Sexefunge-97"#@,,,,,,,,,,,,@#,
<>"v"@
& I8 H I d $$$
a&8g&3g4g6R9PPPPPP<
>"gnalokniM"OOOOOOOOO.
@,"F","u","n","c","t","o","i","d"<> red down two red left one yellow up green down yellow up green down red up three red right two yellow down yellow down blue left green down red down one yellow down blue left green down red down two red left one yellow up yellow down blue left green down red left one red down three yellow down yellow down blue left green down red up two green down yellow up yellow down blue left red up three red right two yellow down yellow down blue left 0001110000100000100010000010000010100000100000000010001000100000100010000010000010100000100000100010000010001000100000000010001000001000100011000010001000100000100011000010000010001000001000100000100000100000100010000010001000001000100000000010001000001000100010000000110000110000011000001001100000100010001000100010000001001101110000001100111100011001100000001001110011110000110111000001000000010000000100000001000000010000000100000001000000010001100011011110001000100010000010001010000100000001000100000001000000010000000100000001000000010000000100000000100110
01 & && &&& & {}]⎚F¹laocrahC«▲²²²²²⌂↨α↨ß↨²²⌂↨←ß≤▼→▼←≥→⌂↨σ→→→↨ß→→→↨π→→→→→↨¡ß¡→→↨δ→↨ß→→→→↨µ→→→↨¡φ↨επ⌂↨¡ß¡→→→↨¡πσ▲⌂↨¡σµ¡→↨¡α¡→↨¡π¡▲▲▲¡▲▲▲¡σ▲¡δ¡φ▲▲▲▲¡ε▼▼¡»😭Emotinomicon😲⏪⏬⏩+-+[-++++[-<+++++>]<[-<++++++<+++++<+++++>>>]>+{}[<<<<+++++++.>-.>---.<<-----.++++++++.-----.>--.>---.<+.>>->-]<+[<<+.<++++++++++++.>>+.<+++.<--.>+.--------.<++++.>+.>>{}]>](()()()()())<>(()())<>{({}[()])<>({({})({}[()])}{})<>}<>((){[()](<{}((((((((((()()()){}){}){}){}()){})((()()()()){}){})[(([][]){}){}()])([]()){})[]())(([[][]()]([]()((((([][][])){}{})[]){})))[]())>)}{}){{}(<((((((((((((((()()()){}){}){}){}()){})((()()()()){}){})[(([][]){}){}()])([]()){})[]())[[]()()()])[])[[]()()()()])[][][][()])((((((()()()){}()){}){}){})[()()])>)}{}({ -}_=")+;;+;+;+;+;;+;+;;+;;;+;;+;+;+;+;+;+;;;+;;+;;+;;+;;+;;;+;;+;+;;+;+";x--?y
=y;y="yrruC";(!)=seq;main=let b!_=""in putStr$(""!"snrettaPgnaB+")++y--?"lleksaH"
--N'Zi(Tji8=@/BmU2)[-]<>\[\<>\\/<>\/\[/\/\<><><>\[/\/\/<>\//\/<><><><><>\\]/\//\//\/\]/\/\\./]s*///∙SAVNACp💬ijome💬➡@,ka"89-egnufenUsssssaaaaaeeeeeeeeeepaeeeeeeeeeecisaeeeeeeejiiiiiiiijeeeeeeeeeeeeeeeeeejzaciiiiiiiiiiiiijeeeaceeacewuuuweejiiiijiiiiiiiiiiijeeeaaaakeeaaaawvw;+;;+;+;;;;+;+;;+;;+;+;;;+;;+;⠀⠖⠗⠎⢎⢦⢦⠮"
```
Prints:
* `D` in D
* `emmoS` in Somme
* `><>` in ><>
* `C` in C
* `laocrahC` in Charcoal
* `miV` in Vim
* `C-evitceJbO` in ObJective-C
* `89-egnufeB` in Befunge-98
* `39-egnufeB` in Befunge-93
* `eliF MOC SODeerF` in FreeDOS COM file
* `><>loG` in Gol><>
* `89-egnufenU` in Unefunge-98
* `79-egnufeB` in Befunge-97
* `69-egnufeB` in Befunge-96
* `kcufniarb` in brainfuck
* `89-egnuferT` in Trefunge-98
* `kalf-niarb` in brain-flak
* `hsab` in bash
* `lleksaH` in Haskell
* `hsz` in zsh
* `ijome` in emoji
* `snrettaPgnaB+lleksaH` in Haskell+BangPatterns
* `++C` in C++
* `nocimonitomE` in Emotinomicon
* `hsk` in ksh
* `hsad` in dash
* `79-egnuferT` in Trefunge-97
* `ecilA` in Alice
* `79-egnuferdauQ` in Quadrefunge-97
* `99` in 99
* `79-egnufetniuQ` in Quintefunge-97
* `kcufniarb cilobmys` in symbolic brainfuck
* `79-egnufexeS` in Sexefunge-97
* `senots` in stones
* `79-egnufetpeS` in Septefunge-97
* `diotcnuF` in Functoid
* `ssarG` in Grass
* `kcuhpla` in alphuck
* `SAVNAC` in CANVAS
* `egaugnal sseleman` in nameless language
* `LIve` in evil
* `V` in V
* `elliarb` in braille
* `68xalfniarb` in BrainFlaX86
* `NOOPS` in Spoon
* `yrruC` in Curry
* `gnalokniM` in Minkolang
* `epyhniarb` in Brainhype
* `kcufloob` in boolfuck
[Try it online!](https://tio.run/##rTvbchvHlc@cX8hLa0gTMwQGQ5ASRYIAwrskryQyoixpBUDIYNAAhhjMIHMBCNF0uTZVrk3VVuzKg/fysLa3dlN7SbYqrvhha7Mvynv8D/yB5A@053T3XHChJDsZEjPd596nT19OY9A0/O7r14tkt9UiBqEdI@w4xn0SuFAbuPa4Y7sBCagfkK7hOdT3SXNMHlr04CU967lNaZHsu7ZtDHxK5H23RWViOC0i73qdsE@dwJeJT83Ach2ftF2PNGkQUI/Q8wH1LOqYVJJMIyAVYgKvZDtE81mR3fLNNlkke7QdOh2qba3P4Ps9GwgeWE7PtQ2nIwVuaHbJwLNAsQSmWW0ydkNiYNsig3Kkb/Qo8UOPYiv7bstqjwlYmB@Mie@SoAv2BF06BhZKLMe0wxZtQQGBxAZdEjW7LtEcIi8VZDCd86agawhtuf4kdB2hvtvvU61tnU/ibiLuSX5gBGZXkgbjoOs66/OJ73iG7xelwCOa2SKjp0NSYr5DPLbZdPsDy6bQfaxpFtg@pJ4PPUDcNtnzDMu5a5g9orDikW0829wg9CehNTRs8I8qNZuIaNsG0KjkQiKk32tZ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twoWarmEQ8ppxRxeSpoTh0hEqRpHZgybYOB50quFr0nbm0hAvbPMuWeEKwxOTu4I1KxASjSpiZsdfuclGCRp2wTz0DBi8meDi82Y/zWFKTih4kfWkNFM9wOlTBnstBx23AfROSpGraQ4JPtDyqiRbFVWZxnW1v0kFaFRkNM5IdjPFzOCVFxGyHqXNiRDP8vAkp8MaopGs4LZtlxhPqWAV2hPhaGoyiv6LjQxxoqREnh07Pwa@YU3xFPtygHu/9hHwFj16PPatjOYZN4qFqMB82x2QnOXWFbaJ4Mw3txV935GEPaPbAlC56mb2@aeiFjdu3b97Sb24WtjbFetG2zhvs7FlBTsg82NvMOWI7ZZznwakSwSNV20k2tfi9JtRhFtO0DDhYwRNIzsiWLHUlQzLIhyKr2hrb7zkEpl3IP8M@P4Sl7HAWy@yVSYsdrfoU9yUQerC3wDcAUUg8I8syVlnY5czJeBPKuWl@mb@UqK2vsTpy2EiPiori3RBsElhtq7BFsoq@xnjsqlWP2ZI5GSd2/72tW9n1NRVNEGua@NHYzKludKDL2586zs37AxtWrUzNyTDv28JBsKpO@4Z1Sdoz7GeiiVsk3mL0yq5vFTezxeJatnjz9orWz23LUuiMDDapA361YJjUOnMHvqJeXFbrpUour2VlVAlCYYTgT7F8Pv23qUfJSCcuYDyuXoness6RXfHW9zL/8aJ2ZBs9VeraAwyFZehxZmD5mpiCJvvQt0nYZMQ3JH1joIjJxsSTOpLJgky1yvo4akk9x5qvqtW1Yv3NimCH5rRU8Waswn8Px/tehmQYWavFNdyeABlKY/QCxLAAU9XXG@u5jdvmxrpUit8bgqCh7EeFUQjAlIg/g4X@wgwL0juVsFdjW26KCy@TlDTSvUMD/EEc6U5jcaIyidueguOVuZEhWmWewq46h7yBxJ0BUcyir0qapuF7Y9/V/MRQUqmUUVyeKCjv/wE)
Next answer must not exceed 5185 bytes.
## Hexdump
```
00000000: 766f 6964 202f 2a2d 7b2d 2d20 2368 5221 void /*-{-- #hR!
00000010: 582d 4020 505e 687e 7e58 4040 3044 2030 X-@ P^h~~X@@0D 0
00000020: 4422 6876 2158 2d40 2050 5a68 202b 5835 D"hv!X-@ PZh +X5
00000030: 2022 4d21 4d20 656c 6946 204d 4f43 2053 "M!M eliF MOC S
00000040: 4f44 6565 7246 247d 2b2b 2b2b 2d2b 5b2a ODeerF$}++++-+[*
00000050: 2f2f 2f6f 7066 7a7a 667a 7a66 7a7a 667a ///opfzzfzzfzzfz
00000060: 7a7a 667a 7a66 7a66 7a66 6666 7a66 667a zzfzzfzfzfffzffz
00000070: 7a7a 7a7a 6666 7a66 7a7a 7a66 667a 667a zzzzffzfzzzffzfz
00000080: 7a7a 667a 667a 667a 7a66 7a66 7a7a 7a66 zzfzfzfzzfzfzzzf
00000090: 7a66 7a66 7a7a 667a 667a 6666 667a 7a66 zfzfzzfzfzfffzzf
000000a0: 7a66 7a7a 7a66 7a66 6666 66e2 a086 e2a1 zfzzzfzffff.....
000000b0: 86e2 a086 e2a1 86e2 a086 e2a1 86e2 a086 ................
000000c0: e2a1 86e2 a086 e2a1 86e2 a086 e2a1 86e2 ................
000000d0: a086 e2a1 865c 0a20 2f2b 2023 5c0a 2062 .....\. /+ #\. b
000000e0: 6173 656e 616d 6520 2224 2872 6561 646c asename "$(readl
000000f0: 696e 6b20 2f70 726f 632f 2424 2f65 7865 ink /proc/$$/exe
00000100: 2922 7c72 6576 3b3a 3c3c 2745 4f46 2720 )"|rev;:<<'EOF'
00000110: 233e 3e5c 0a31 2b2f 2f2f 2020 2020 2020 #>>\.1+///
00000120: 2020 2020 2020 2020 2020 2020 4f5c 0a2f O\./
00000130: 2a20 1b67 6763 476d 6956 1b5a 5a3b 6f6f * .ggcGmiV.ZZ;oo
00000140: 6f22 6c6f 4722 3b3f 3d30 2553 2131 316f o"loG";?=0%S!11o
00000150: 6f6f 3c22 3e3c 3e22 0a23 6465 6669 6e65 oo<"><>".#define
00000160: 2053 2243 2220 2020 2020 2020 2f2f 410a S"C" //A.
00000170: 2369 6664 6566 205f 5f63 706c 7573 706c #ifdef __cpluspl
00000180: 7573 2f2f 6c0a 2066 2829 3b20 2020 2020 us//l. f();
00000190: 2020 2020 2020 202f 2f69 0a23 696e 636c //i.#incl
000001a0: 7564 653c 6373 7464 696f 3e2f 2f63 0a23 ude<cstdio>//c.#
000001b0: 6465 6669 6e65 2053 222b 2b43 2220 2f2f define S"++C" //
000001c0: 650a 2069 6e74 2f2f 2f20 2020 2020 2020 e. int///
000001d0: 2020 220a 2365 6e64 6966 2f2f 2020 2020 ".#endif//
000001e0: 2020 205c 2e0a 2369 6664 6566 205f 5f4f \..#ifdef __O
000001f0: 424a 435f 5f0a 2364 6566 696e 6520 5322 BJC__.#define S"
00000200: 432d 6576 6974 6365 4a62 4f22 0a23 656e C-evitceJbO".#en
00000210: 6469 660a 206d 6169 6e28 297b 7072 696e dif. main(){prin
00000220: 7466 2853 292f 2a2f 6d61 696e 2829 7b69 tf(S)/*/main(){i
00000230: 6d70 6f72 7420 7374 642e 7374 6469 6f3b mport std.stdio;
00000240: 2244 222e 7772 6974 652f 2a2a 2f3b 7d2f "D".write/**/;}/
00000250: 2a7d 3c0a 3e20 2076 7757 5757 5777 5757 *}<.> vwWWWWwWW
00000260: 5757 5777 7677 5757 7757 5757 7776 7757 WWWwvwWWwWWWwvwW
00000270: 5777 5757 5777 7677 5757 7757 5757 7776 WwWWWwvwWWwWWWwv
00000280: 7757 5777 5757 5777 7677 5757 7757 5757 wWWwWWWwvwWWwWWW
00000290: 7776 7757 5777 5757 5777 7657 7777 7777 wvwWWwWWWwvWwwww
000002a0: 7777 7777 7777 7757 5757 7757 5757 5757 wwwwwwwWWWwWWWWW
000002b0: 5777 5757 5757 5757 5777 5757 5757 5757 WwWWWWWWWwWWWWWW
000002c0: 5757 5777 5757 5757 5757 5757 5757 5757 WWWwWWWWWWWWWWWW
000002d0: 7757 5757 5757 5757 5757 5777 5757 5757 wWWWWWWWWWWwWWWW
000002e0: 5757 5757 5757 5757 5757 5757 5777 5757 WWWWWWWWWWWWWwWW
000002f0: 5757 5757 5757 5757 5757 5757 5757 5757 WWWWWWWWWWWWWWWW
00000300: 7757 5757 5757 5757 5757 5757 5757 5757 wWWWWWWWWWWWWWWW
00000310: 5757 5777 5757 5757 5757 5757 5757 5757 WWWwWWWWWWWWWWWW
00000320: 5757 5757 5757 5777 7757 5757 5757 5757 WWWWWWWwwWWWWWWW
00000330: 5757 5757 5757 5757 5757 5757 5777 7777 WWWWWWWWWWWWWwww
00000340: 7777 7757 5757 5757 5757 5757 5757 5757 wwwWWWWWWWWWWWWW
00000350: 5757 5757 5757 5757 7777 7777 7757 5757 WWWWWWWWwwwwwWWW
00000360: 5757 5757 5757 5757 5757 5757 5757 5757 WWWWWWWWWWWWWWWW
00000370: 5757 5777 7777 7777 7777 7777 7777 0a39 WWWwwwwwwwwwww.9
00000380: 3939 2039 3939 2039 390a 3939 3920 3939 99 999 99.999 99
00000390: 3920 390a 3939 3976 3c3e 3030 3030 3131 9 9.999v<>000011
000003a0: 3031 3130 0a76 2020 3c3e 2265 6675 6e67 0110.v <>"efung
000003b0: 652d 3938 222c 2c2c 2c2c 2c2c 2c2c 3779 e-98",,,,,,,,,7y
000003c0: 332d 763c 2040 0a3e 2020 235e 4776 2020 3-v< @.> #^Gv
000003d0: 2020 2020 2020 2020 2020 2020 2020 2040 @
000003e0: 2c22 4222 5f22 5472 222c 2c40 0a20 2020 ,"B"_"Tr",,@.
000003f0: 763c 5b5f 225d 4265 6675 6e67 652d 3933 v<[_"]Befunge-93
00000400: 223e 2c2c 2c2c 2c2c 2c2c 2c2c 307c 403c ">,,,,,,,,,,0|@<
00000410: 0a20 2020 3e23 3c22 4265 6675 6e67 652d . >#<"Befunge-
00000420: 3936 223e 205e 7624 4730 3031 0a76 2020 96"> ^v$G001.v
00000430: 2c2c 2c2c 2c22 3739 2d65 676e 7566 6542 ,,,,,"79-egnufeB
00000440: 2220 5f20 2020 2020 2020 2020 2020 2020 " _
00000450: 2020 2020 2076 3c0a 3e20 202c 2c2c 2c2c v<.> ,,,,,
00000460: 4023 2020 2020 2020 2c22 3739 2d65 676e @# ,"79-egn
00000470: 7566 6572 5422 5f76 2320 2447 3030 3031 uferT"_v# $G0001
00000480: 3c3e 0a20 2020 2020 2020 2020 2020 2020 <>.
00000490: 2020 2020 2020 2020 2020 2020 2020 2020
000004a0: 203c 3e31 3030 3030 4724 760a 2020 2020 <>10000G$v.
000004b0: 2023 402c 2c2c 2c2c 2c2c 2c2c 2c2c 2c2c #@,,,,,,,,,,,,,
000004c0: 2c40 2322 3739 2d65 676e 7566 6572 6461 ,@#"79-egnuferda
000004d0: 7551 225f 3130 3030 3030 4724 760a 2020 uQ"_100000G$v.
000004e0: 2020 2020 2020 2020 2020 2020 2020 2020
000004f0: 2020 2020 2020 2020 2020 2020 2c2c 2237 ,,"7
00000500: 392d 6567 6e75 6665 746e 6975 5122 5f31 9-egnufetniuQ"_1
00000510: 3030 3030 3030 4724 2176 402c 2c2c 2c2c 000000G$!v@,,,,,
00000520: 2c2c 2c2c 2c2c 2c0a 2020 2020 2020 2020 ,,,,,,,.
00000530: 2020 2020 2020 2020 2020 2020 2020 2020
00000540: 2020 2020 2020 2020 2020 2020 2020 2020
00000550: 2020 2020 2237 392d 6567 6e75 6665 7470 "79-egnufetp
00000560: 6553 225f 2253 6578 6566 756e 6765 2d39 eS"_"Sexefunge-9
00000570: 3722 2340 2c2c 2c2c 2c2c 2c2c 2c2c 2c2c 7"#@,,,,,,,,,,,,
00000580: 4023 2c0a 2020 2020 2020 2020 2020 2020 @#,.
00000590: 2020 2020 2020 2020 2020 2020 2020 2020
000005a0: 2020 203c 3e22 7622 400a 2026 2049 3820 <>"v"@. & I8
000005b0: 4820 4920 2064 2020 2020 2020 2424 240a H I d $$$.
000005c0: 6126 3867 2633 6734 6736 5239 5050 5050 a&8g&3g4g6R9PPPP
000005d0: 5050 3c0a 3e22 676e 616c 6f6b 6e69 4d22 PP<.>"gnalokniM"
000005e0: 4f4f 4f4f 4f4f 4f4f 4f2e 0a20 402c 2246 OOOOOOOOO.. @,"F
000005f0: 222c 2275 222c 226e 222c 2263 222c 2274 ","u","n","c","t
00000600: 222c 226f 222c 2269 222c 2264 223c 3e20 ","o","i","d"<>
00000610: 7265 6420 646f 776e 2074 776f 2072 6564 red down two red
00000620: 206c 6566 7420 6f6e 6520 7965 6c6c 6f77 left one yellow
00000630: 2075 7020 6772 6565 6e20 646f 776e 2079 up green down y
00000640: 656c 6c6f 7720 7570 2067 7265 656e 2064 ellow up green d
00000650: 6f77 6e20 7265 6420 7570 2074 6872 6565 own red up three
00000660: 2072 6564 2072 6967 6874 2074 776f 2079 red right two y
00000670: 656c 6c6f 7720 646f 776e 2079 656c 6c6f ellow down yello
00000680: 7720 646f 776e 2062 6c75 6520 6c65 6674 w down blue left
00000690: 2067 7265 656e 2064 6f77 6e20 7265 6420 green down red
000006a0: 646f 776e 206f 6e65 2079 656c 6c6f 7720 down one yellow
000006b0: 646f 776e 2062 6c75 6520 6c65 6674 2067 down blue left g
000006c0: 7265 656e 2064 6f77 6e20 7265 6420 646f reen down red do
000006d0: 776e 2074 776f 2072 6564 206c 6566 7420 wn two red left
000006e0: 6f6e 6520 7965 6c6c 6f77 2075 7020 7965 one yellow up ye
000006f0: 6c6c 6f77 2064 6f77 6e20 626c 7565 206c llow down blue l
00000700: 6566 7420 6772 6565 6e20 646f 776e 2072 eft green down r
00000710: 6564 206c 6566 7420 6f6e 6520 7265 6420 ed left one red
00000720: 646f 776e 2074 6872 6565 2079 656c 6c6f down three yello
00000730: 7720 646f 776e 2079 656c 6c6f 7720 646f w down yellow do
00000740: 776e 2062 6c75 6520 6c65 6674 2067 7265 wn blue left gre
00000750: 656e 2064 6f77 6e20 7265 6420 7570 2074 en down red up t
00000760: 776f 2067 7265 656e 2064 6f77 6e20 7965 wo green down ye
00000770: 6c6c 6f77 2075 7020 7965 6c6c 6f77 2064 llow up yellow d
00000780: 6f77 6e20 626c 7565 206c 6566 7420 7265 own blue left re
00000790: 6420 7570 2074 6872 6565 2072 6564 2072 d up three red r
000007a0: 6967 6874 2074 776f 2079 656c 6c6f 7720 ight two yellow
000007b0: 646f 776e 2079 656c 6c6f 7720 646f 776e down yellow down
000007c0: 2062 6c75 6520 6c65 6674 2030 3030 3131 blue left 00011
000007d0: 3130 3030 3031 3030 3030 3031 3030 3031 1000010000010001
000007e0: 3030 3030 3031 3030 3030 3031 3031 3030 0000010000010100
000007f0: 3030 3031 3030 3030 3030 3030 3031 3030 0001000000000100
00000800: 3031 3030 3031 3030 3030 3031 3030 3031 0100010000010001
00000810: 3030 3030 3031 3030 3030 3031 3031 3030 0000010000010100
00000820: 3030 3031 3030 3030 3031 3030 3031 3030 0001000001000100
00000830: 3030 3031 3030 3031 3030 3031 3030 3030 0001000100010000
00000840: 3030 3030 3031 3030 3031 3030 3030 3031 0000010001000001
00000850: 3030 3031 3030 3031 3130 3030 3031 3030 0001000110000100
00000860: 3031 3030 3031 3030 3030 3031 3030 3031 0100010000010001
00000870: 3130 3030 3031 3030 3030 3031 3030 3031 1000010000010001
00000880: 3030 3030 3031 3030 3031 3030 3030 3031 0000010001000001
00000890: 3030 3030 3031 3030 3030 3031 3030 3031 0000010000010001
000008a0: 3030 3030 3031 3030 3031 3030 3030 3031 0000010001000001
000008b0: 3030 3031 3030 3030 3030 3030 3031 3030 0001000000000100
000008c0: 3031 3030 3030 3031 3030 3031 3030 3031 0100000100010001
000008d0: 3030 3030 3030 3031 3130 3030 3031 3130 0000000110000110
000008e0: 3030 3030 3131 3030 3030 3031 3030 3131 0000110000010011
000008f0: 3030 3030 3031 3030 3031 3030 3031 3030 0000010001000100
00000900: 3031 3030 3031 3030 3030 3030 3130 3031 0100010000001001
00000910: 3130 3131 3130 3030 3030 3031 3130 3031 1011100000011001
00000920: 3131 3130 3030 3131 3030 3131 3030 3030 1110001100110000
00000930: 3030 3031 3030 3131 3130 3031 3131 3130 0001001110011110
00000940: 3030 3031 3130 3131 3130 3030 3030 3130 0001101110000010
00000950: 3030 3030 3030 3130 3030 3030 3030 3130 0000001000000010
00000960: 3030 3030 3030 3130 3030 3030 3030 3130 0000001000000010
00000970: 3030 3030 3030 3130 3030 3030 3030 3130 0000001000000010
00000980: 3030 3030 3030 3130 3030 3131 3030 3031 0000001000110001
00000990: 3130 3131 3131 3030 3031 3030 3031 3030 1011110001000100
000009a0: 3031 3030 3030 3031 3030 3031 3031 3030 0100000100010100
000009b0: 3030 3130 3030 3030 3030 3130 3030 3130 0010000000100010
000009c0: 3030 3030 3030 3130 3030 3030 3030 3130 0000001000000010
000009d0: 3030 3030 3030 3130 3030 3030 3030 3130 0000001000000010
000009e0: 3030 3030 3030 3130 3030 3030 3030 3130 0000001000000010
000009f0: 3030 3030 3030 3031 3030 3131 300a 3031 0000000100110.01
00000a00: 2026 2026 2620 2626 2620 2020 2020 2620 & && &&& &
00000a10: 7b7d 5de2 8e9a efbc a6c2 b96c 616f 6372 {}]........laocr
00000a20: 6168 43c2 abe2 96b2 c2b2 c2b2 c2b2 c2b2 ahC.............
00000a30: c2b2 e28c 82e2 86a8 ceb1 e286 a8c3 9fe2 ................
00000a40: 86a8 c2b2 c2b2 e28c 82e2 86a8 e286 90c3 ................
00000a50: 9fe2 89a4 e296 bce2 8692 e296 bce2 8690 ................
00000a60: e289 a5e2 8692 e28c 82e2 86a8 cf83 e286 ................
00000a70: 92e2 8692 e286 92e2 86a8 c39f e286 92e2 ................
00000a80: 8692 e286 92e2 86a8 cf80 e286 92e2 8692 ................
00000a90: e286 92e2 8692 e286 92e2 86a8 c2a1 c39f ................
00000aa0: c2a1 e286 92e2 8692 e286 a8ce b4e2 8692 ................
00000ab0: e286 a8c3 9fe2 8692 e286 92e2 8692 e286 ................
00000ac0: 92e2 86a8 c2b5 e286 92e2 8692 e286 92e2 ................
00000ad0: 86a8 c2a1 cf86 e286 a8ce b5cf 80e2 8c82 ................
00000ae0: e286 a8c2 a1c3 9fc2 a1e2 8692 e286 92e2 ................
00000af0: 8692 e286 a8c2 a1cf 80cf 83e2 96b2 e28c ................
00000b00: 82e2 86a8 c2a1 cf83 c2b5 c2a1 e286 92e2 ................
00000b10: 86a8 c2a1 ceb1 c2a1 e286 92e2 86a8 c2a1 ................
00000b20: cf80 c2a1 e296 b2e2 96b2 e296 b2c2 a1e2 ................
00000b30: 96b2 e296 b2e2 96b2 c2a1 cf83 e296 b2c2 ................
00000b40: a1ce b4c2 a1cf 86e2 96b2 e296 b2e2 96b2 ................
00000b50: e296 b2c2 a1ce b5e2 96bc e296 bcc2 a1c2 ................
00000b60: bbf0 9f98 ad45 6d6f 7469 6e6f 6d69 636f .....Emotinomico
00000b70: 6ef0 9f98 b2e2 8faa e28f ace2 8fa9 2b2d n.............+-
00000b80: 2b5b 2d2b 2b2b 2b5b 2d3c 2b2b 2b2b 2b3e +[-++++[-<+++++>
00000b90: 5d3c 5b2d 3c2b 2b2b 2b2b 2b3c 2b2b 2b2b ]<[-<++++++<++++
00000ba0: 2b3c 2b2b 2b2b 2b3e 3e3e 5d3e 2b7b 7d5b +<+++++>>>]>+{}[
00000bb0: 3c3c 3c3c 2b2b 2b2b 2b2b 2b2e 3e2d 2e3e <<<<+++++++.>-.>
00000bc0: 2d2d 2d2e 3c3c 2d2d 2d2d 2d2e 2b2b 2b2b ---.<<-----.++++
00000bd0: 2b2b 2b2b 2e2d 2d2d 2d2d 2e3e 2d2d 2e3e ++++.-----.>--.>
00000be0: 2d2d 2d2e 3c2b 2e3e 3e2d 3e2d 5d3c 2b5b ---.<+.>>->-]<+[
00000bf0: 3c3c 2b2e 3c2b 2b2b 2b2b 2b2b 2b2b 2b2b <<+.<+++++++++++
00000c00: 2b2e 3e3e 2b2e 3c2b 2b2b 2e3c 2d2d 2e3e +.>>+.<+++.<--.>
00000c10: 2b2e 2d2d 2d2d 2d2d 2d2d 2e3c 2b2b 2b2b +.--------.<++++
00000c20: 2e3e 2b2e 3e3e 7b7d 5d3e 5d28 2829 2829 .>+.>>{}]>](()()
00000c30: 2829 2829 2829 293c 3e28 2829 2829 293c ()()())<>(()())<
00000c40: 3e7b 287b 7d5b 2829 5d29 3c3e 287b 287b >{({}[()])<>({({
00000c50: 7d29 287b 7d5b 2829 5d29 7d7b 7d29 3c3e })({}[()])}{})<>
00000c60: 7d3c 3e28 2829 7b5b 2829 5d28 3c7b 7d28 }<>((){[()](<{}(
00000c70: 2828 2828 2828 2828 2828 2928 2928 2929 (((((((((()()())
00000c80: 7b7d 297b 7d29 7b7d 297b 7d28 2929 7b7d {}){}){}){}()){}
00000c90: 2928 2828 2928 2928 2928 2929 7b7d 297b )((()()()()){}){
00000ca0: 7d29 5b28 285b 5d5b 5d29 7b7d 297b 7d28 })[(([][]){}){}(
00000cb0: 295d 2928 5b5d 2829 297b 7d29 5b5d 2829 )])([]()){})[]()
00000cc0: 2928 285b 5b5d 5b5d 2829 5d28 5b5d 2829 )(([[][]()]([]()
00000cd0: 2828 2828 285b 5d5b 5d5b 5d29 297b 7d7b ((((([][][])){}{
00000ce0: 7d29 5b5d 297b 7d29 2929 5b5d 2829 293e })[]){})))[]())>
00000cf0: 297d 7b7d 297b 7b7d 283c 2828 2828 2828 )}{}){{}(<((((((
00000d00: 2828 2828 2828 2828 2829 2829 2829 297b ((((((((()()()){
00000d10: 7d29 7b7d 297b 7d29 7b7d 2829 297b 7d29 }){}){}){}()){})
00000d20: 2828 2829 2829 2829 2829 297b 7d29 7b7d ((()()()()){}){}
00000d30: 295b 2828 5b5d 5b5d 297b 7d29 7b7d 2829 )[(([][]){}){}()
00000d40: 5d29 285b 5d28 2929 7b7d 295b 5d28 2929 ])([]()){})[]())
00000d50: 5b5b 5d28 2928 2928 295d 295b 5d29 5b5b [[]()()()])[])[[
00000d60: 5d28 2928 2928 2928 295d 295b 5d5b 5d5b ]()()()()])[][][
00000d70: 5d5b 2829 5d29 2828 2828 2828 2829 2829 ][()])((((((()()
00000d80: 2829 297b 7d28 2929 7b7d 297b 7d29 7b7d ()){}()){}){}){}
00000d90: 295b 2829 2829 5d29 3e29 7d7b 7d28 7b20 )[()()])>)}{}({
00000da0: 2d7d 5f3d 2229 2b3b 3b2b 3b2b 3b2b 3b2b -}_=")+;;+;+;+;+
00000db0: 3b3b 2b3b 2b3b 3b2b 3b3b 3b2b 3b3b 2b3b ;;+;+;;+;;;+;;+;
00000dc0: 2b3b 2b3b 2b3b 2b3b 2b3b 3b3b 2b3b 3b2b +;+;+;+;+;;;+;;+
00000dd0: 3b3b 2b3b 3b2b 3b3b 2b3b 3b3b 2b3b 3b2b ;;+;;+;;+;;;+;;+
00000de0: 3b2b 3b3b 2b3b 2b22 3b78 2d2d 3f79 0a20 ;+;;+;+";x--?y.
00000df0: 3d79 3b79 3d22 7972 7275 4322 3b28 2129 =y;y="yrruC";(!)
00000e00: 3d73 6571 3b6d 6169 6e3d 6c65 7420 6221 =seq;main=let b!
00000e10: 5f3d 2222 696e 2070 7574 5374 7224 2822 _=""in putStr$("
00000e20: 2221 2273 6e72 6574 7461 5067 6e61 422b "!"snrettaPgnaB+
00000e30: 2229 2b2b 792d 2d3f 226c 6c65 6b73 6148 ")++y--?"lleksaH
00000e40: 220a 2d2d 4e27 5a69 2854 6a69 383d 402f ".--N'Zi(Tji8=@/
00000e50: 426d 5532 295b 2d5d 3c3e 5c5b 5c3c 3e5c BmU2)[-]<>\[\<>\
00000e60: 5c2f 3c3e 5c2f 5c5b 2f5c 2f5c 3c3e 3c3e \/<>\/\[/\/\<><>
00000e70: 3c3e 5c5b 2f5c 2f5c 2f3c 3e5c 2f2f 5c2f <>\[/\/\/<>\//\/
00000e80: 3c3e 3c3e 3c3e 3c3e 3c3e 5c5c 5d2f 5c2f <><><><><>\\]/\/
00000e90: 2f5c 2f2f 5c2f 5c5d 2f5c 2f5c 5c2e 2f5d /\//\/\]/\/\\./]
00000ea0: 732a 2f2f 2fe2 8899 5341 564e 4143 efbd s*///...SAVNAC..
00000eb0: 90f0 9f92 ac69 6a6f 6d65 f09f 92ac e29e .....ijome......
00000ec0: a140 2c6b 6122 3839 2d65 676e 7566 656e .@,ka"89-egnufen
00000ed0: 5573 7373 7373 6161 6161 6165 6565 6565 Usssssaaaaaeeeee
00000ee0: 6565 6565 6570 6165 6565 6565 6565 6565 eeeeepaeeeeeeeee
00000ef0: 6563 6973 6165 6565 6565 6565 6a69 6969 ecisaeeeeeeejiii
00000f00: 6969 6969 696a 6565 6565 6565 6565 6565 iiiiijeeeeeeeeee
00000f10: 6565 6565 6565 6565 6a7a 6163 6969 6969 eeeeeeeejzaciiii
00000f20: 6969 6969 6969 6969 696a 6565 6561 6365 iiiiiiiiijeeeace
00000f30: 6561 6365 7775 7575 7765 656a 6969 6969 eacewuuuweejiiii
00000f40: 6a69 6969 6969 6969 6969 6969 6a65 6565 jiiiiiiiiiiijeee
00000f50: 6161 6161 6b65 6561 6161 6177 7677 3b2b aaaakeeaaaawvw;+
00000f60: 3b3b 2b3b 2b3b 3b3b 3b2b 3b2b 3b3b 2b3b ;;+;+;;;;+;+;;+;
00000f70: 3b2b 3b2b 3b3b 3b2b 3b3b 2b3b e2a0 80e2 ;+;+;;;+;;+;....
00000f80: a096 e2a0 97e2 a08e e2a2 8ee2 a2a6 e2a2 ................
00000f90: a6e2 a0ae 22 ...."
```
# Explanation:
Boolfuck uses bits instead of bytes/integers. `-` is now a noop, and `;` replaces `.`. Using `-+` to get boolfuck in the desired state works without affecting brainfuck. All that is needed is to make sure we don't go into an infinite loop or output a bit we shouldn't, and squeeze "+;;+;+;+;+;;+;+;;+;;;+;;+;+;+;+;+;+;;;+;;+;;+;;+;;+;;;+;;+;+;;+;+;;;;+;+;;+;+;;;;+;+;;+;;+;+;;;+;;+;" into the program. The reason it's split into two portions is because the four `;`s would interfere with the proper output, so it was split at a point where there were four `;`s.
[Answer]
# 12. Unefunge-98, 320 bytes
```
void /*hL!X-@ P^h~~X@@0D 0D"hp!X-@ PZh )X5 M!M elif MOC SODeerF$*/main(){//\
/+\
1+///\
/*SmiVZZ;ooo"loG";?=0%S!11ooo"><>"
#define S""
#ifdef __OBJC__
#define S"-evitcejbO"
#endif
printf("C"S)/*/import std.stdio;"D".write/**/;}/*
>"Befunge-98";5-;,,,,,,,,,,@
nq]j\m7-;l(e[Kagd-*///⎚¿⁵laocrahC¦@,ka"89-egnufenU"
```
Prints:
* `D` in D
* `emmoS` in Somme
* `><>` in ><>
* `C` in C
* `laocrahC` in Charcoal
* `miV` in Vim
* `C-evitcejbO` in Objective-C
* `89-egnufeB` in Befunge-98
* `39-egnufeB` in Befunge-93
* `elif MOC SODeerF` in FreeDOS COM file
* `><>loG` in Gol><>
* `89-egnufenU` in Unefunge-98
[Try it online!](https://tio.run/##rRnbUttI9hn9wryciEwkgW3ZEAgYzASMSdiBQMVkNhtwPLLUshV08eoC9mQyVfsD@wH7AfsH@7xV8ynzI9lzuluybJzM1O6mKqa7z/3ap@2BlYw@f16FQ8cBC9jQyoahdQZphLtx5E@HfpRCypIURlYcsiSBwRReeez4J/bhNhooq9COfN8aJwzUduQwFazQAfUwHmYBC9NEhYTZqReFCbhRDAOWpiwGNhmz2GOhzRTFtlI4ABtpFT@EasKX/KM2cGEVjpibhUNW3d1U0iizRzCOPWSsoGjPhWmUgUW65wIrEFi3DJIsZmRFEDmeOwXUoDaeQhJBOkJ56YhNkYSBF9p@5jAHF3QIvhfeKsweRVANQX3cUFE1QVs63aBTJ0roVDk7fPXizeGLTv/01XHnbauhHP3lqtNtqY/1exuq9j4ZYqgK2sDdAL4VDjNryHTjo7LCeaqr8HieSw0eNyrwmHNCf6P7VWXl4s3V5ZsrYjzAmCFrrgmyXum8vey0rzrHBBMcUfGfY3ZHQPTRNR4IahUetXCTE6jQ2yOzQ2VFqtLBwNgp@qPAqcAQMyCnJ8SJl0JDWXE9ZWXBeJSvL5iy3jBIC8G9Cjc/Sk43P5LLuYMP8oh@opiO0nScNE1z6KWjbFCzo8C8iqen6UWIsWFmGk@9NMrXjJmBlWBGmfexNcacSpBD7mFQKW9VULlwvlZmMDRedQIHqnEW8mwrA7tREGAqq3GG2W5G49RM6ER81uLBA4KD/QNEH0/TURRuCgrXS0b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SxXa3m0@aHcc8Gx7xmCxFZcbDl79pW4imNpOc5bx9OTMN7Z4GsqvFXHThNIENhvrqOgMSeWwP0xVnVGRzQ/JZp6QJAV6NP6qENlgDIVeZviiYpNK/kBjYRaw2MLipQcelTf/DZU/akrZQ6g/eWM9tsIh0ylyFQzcNn7u4CPpuuwhSSctz3fSomLLNe7x8aacpNfyRcOV5F@LiW/h9BIS1x1b51xFc/iyhpTGUxIyskLH5y/jOXF8gxMh/UaAVfQ9m3ao0EoVp2bhbRjdh2W6pig33Bezn@SvG/8B)
Next answer must not exceed 416 bytes.
## Hexdump
```
00000000: 766f 6964 202f 2a68 4c21 582d 4020 505e void /*hL!X-@ P^
00000010: 687e 7e58 4040 3044 2030 4422 6870 2158 h~~X@@0D 0D"hp!X
00000020: 2d40 2050 5a68 2029 5835 2020 4d21 4d20 -@ PZh )X5 M!M
00000030: 656c 6966 204d 4f43 2053 4f44 6565 7246 elif MOC SODeerF
00000040: 242a 2f6d 6169 6e28 297b 2f2f 5c0a 202f $*/main(){//\. /
00000050: 2b5c 0a31 2b2f 2f2f 5c0a 2f2a 1b53 6d69 +\.1+///\./*.Smi
00000060: 561b 5a5a 3b6f 6f6f 226c 6f47 223b 3f3d V.ZZ;ooo"loG";?=
00000070: 3025 5321 3131 6f6f 6f22 3e3c 3e22 0a23 0%S!11ooo"><>".#
00000080: 6465 6669 6e65 2053 2222 0a23 6966 6465 define S"".#ifde
00000090: 6620 5f5f 4f42 4a43 5f5f 0a23 6465 6669 f __OBJC__.#defi
000000a0: 6e65 2053 222d 6576 6974 6365 6a62 4f22 ne S"-evitcejbO"
000000b0: 0a23 656e 6469 660a 7072 696e 7466 2822 .#endif.printf("
000000c0: 4322 5329 2f2a 2f69 6d70 6f72 7420 7374 C"S)/*/import st
000000d0: 642e 7374 6469 6f3b 2244 222e 7772 6974 d.stdio;"D".writ
000000e0: 652f 2a2a 2f3b 7d2f 2a0a 3e22 4265 6675 e/**/;}/*.>"Befu
000000f0: 6e67 652d 3938 223b 352d 3b2c 2c2c 2c2c nge-98";5-;,,,,,
00000100: 2c2c 2c2c 2c40 0a6e 715d 6a5c 6d37 2d3b ,,,,,@.nq]j\m7-;
00000110: 6c28 655b 4b61 6764 2d2a 2f2f 2fe2 8e9a l(e[Kagd-*///...
00000120: c2bf e281 b56c 616f 6372 6168 43c2 a640 .....laocrahC..@
00000130: 2c6b 6122 3839 2d65 676e 7566 656e 5522 ,ka"89-egnufenU"
```
## Explanation
I compacted the Befunge code a bit, because why not. Then I had to fix Somme because of that. I need to add Somme-fixer to that TIO link...
Unefunge looks at the `v`, and reflects, since a `v` does not make sense in one dimension. You might think it will go to the end of the first line, but since the Fungespace has only one dimension, the entire code is treated as a single line. Therefore, `@,ka"89-egnufenU"` is executed.
Charcoal uses the `¿` conditional with an always true expression `⁵` to ignore the Unefunge code.
[Answer]
# 13. Befunge-97, 358 bytes
```
void /*hL!X-@ P^h~~X@@0D 0D"hp!X-@ PZh )X5 M!M elif MOC SODeerF$*/main(){//\
/+\
1+///\
/*SmiVZZ;ooo"loG";?=0%S!11ooo"><>"
#define S""
#ifdef __OBJC__
#define S"-evitcejbO"
#endif
printf("C"S)/*/import std.stdio;"D".write/**/;}/*
$$< >1-v
>"Befunge-98";5-;00#^G#^_$>,,,,,,,,,,@
nq]j\m7-;l(e[Kagd)*///⎚¿⁵laocrahC¦@,ka"89-egnufenU"
```
Prints:
* `D` in D
* `emmoS` in Somme
* `><>` in ><>
* `C` in C
* `laocrahC` in Charcoal
* `miV` in Vim
* `C-evitcejbO` in Objective-C
* `89-egnufeB` in Befunge-98
* `39-egnufeB` in Befunge-93
* `elif MOC SODeerF` in FreeDOS COM file
* `><>loG` in Gol><>
* `89-egnufenU` in Unefunge-98
* `79-egnufeB` in Befunge-97
[Try it online!](https://tio.run/##rRnbUttI9hn9wrycGCaSwLZsCAQM9gSMSdghgYrJbDbgeGSpZSvo4tUF7MlkqvYH9gP2A/YP9nmr5lPmR7LndLdk@ZLM1O5Shenuc793m4E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000000: 766f 6964 202f 2a68 4c21 582d 4020 505e void /*hL!X-@ P^
00000010: 687e 7e58 4040 3044 2030 4422 6870 2158 h~~X@@0D 0D"hp!X
00000020: 2d40 2050 5a68 2029 5835 2020 4d21 4d20 -@ PZh )X5 M!M
00000030: 656c 6966 204d 4f43 2053 4f44 6565 7246 elif MOC SODeerF
00000040: 242a 2f6d 6169 6e28 297b 2f2f 5c0a 202f $*/main(){//\. /
00000050: 2b5c 0a31 2b2f 2f2f 5c0a 2f2a 1b53 6d69 +\.1+///\./*.Smi
00000060: 561b 5a5a 3b6f 6f6f 226c 6f47 223b 3f3d V.ZZ;ooo"loG";?=
00000070: 3025 5321 3131 6f6f 6f22 3e3c 3e22 0a23 0%S!11ooo"><>".#
00000080: 6465 6669 6e65 2053 2222 0a23 6966 6465 define S"".#ifde
00000090: 6620 5f5f 4f42 4a43 5f5f 0a23 6465 6669 f __OBJC__.#defi
000000a0: 6e65 2053 222d 6576 6974 6365 6a62 4f22 ne S"-evitcejbO"
000000b0: 0a23 656e 6469 660a 7072 696e 7466 2822 .#endif.printf("
000000c0: 4322 5329 2f2a 2f69 6d70 6f72 7420 7374 C"S)/*/import st
000000d0: 642e 7374 6469 6f3b 2244 222e 7772 6974 d.stdio;"D".writ
000000e0: 652f 2a2a 2f3b 7d2f 2a0a 2020 2020 2020 e/**/;}/*.
000000f0: 2020 2020 2020 2020 2020 2020 2424 3c20 $$<
00000100: 203e 312d 760a 3e22 4265 6675 6e67 652d >1-v.>"Befunge-
00000110: 3938 223b 352d 3b30 3023 5e47 235e 5f24 98";5-;00#^G#^_$
00000120: 3e2c 2c2c 2c2c 2c2c 2c2c 2c40 0a6e 715d >,,,,,,,,,,@.nq]
00000130: 6a5c 6d37 2d3b 6c28 655b 4b61 6764 292a j\m7-;l(e[Kagd)*
00000140: 2f2f 2fe2 8e9a c2bf e281 b56c 616f 6372 ///........laocr
00000150: 6168 43c2 a640 2c6b 6122 3839 2d65 676e ahC..@,ka"89-egn
00000160: 7566 656e 5522 ufenU"
```
## Explanation:
Uses `G` as a distinguishing thing between Befunge-97 and Befunge-98: in 97, it is `g` but relative to the current position, but in the Befunge-98 interpreter, it just reflects. As always, the Somme portion at the bottom had to be modified, but only by one character this time
[Answer]
# 14. Befunge-96, 355 bytes
That's smaller than the previous answer!
```
void /*hL!X-@ P^h~~X@@0D 0D"hp!X-@ PZh )X5 M!M elif MOC SODeerF$*/main(){//\
/+\
1+///\
/*SmiVZZ;ooo"loG";?=0%S!11ooo"><>"
#define S""
#ifdef __OBJC__
#define S"-evitcejbO"
#endif
printf("C"S)/*/import std.stdio;"D".write/**/;}/*
>"8"; > ]#;v
>#^Z"6"00G#^_$4->1+>,"Befunge-9",,,,,,,,,@
np#s)KhdpR>!}bbg$%*///⎚¿⁵laocrahC¦@,ka"89-egnufenU"
```
Prints:
* `D` in D
* `emmoS` in Somme
* `><>` in ><>
* `C` in C
* `laocrahC` in Charcoal
* `miV` in Vim
* `C-evitcejbO` in Objective-C
* `89-egnufeB` in Befunge-98
* `39-egnufeB` in Befunge-93
* `elif MOC SODeerF` in FreeDOS COM file
* `><>loG` in Gol><>
* `89-egnufenU` in Unefunge-98
* `79-egnufeB` in Befunge-97
* `69-egnufeB` in Befunge-96
[Try it online!](https://tio.run/##rRlZctvI9Vu4Qn7aoCwAIkiQlE1TlMixVlsZ2VJZ8sSxRHNAoEHCwlZYJHI8nqpcIAfIAXKDfKdqjjIXcd7rboDgYs9UEleZ6u63793kyEwmX75UyIFtE5PQsZmNA/OcpCHsotCbjb0wJSlNUjIx44AmCRnNyGuXHv9EP96FI6lCjkLPM6OEEvkotKlMzMAm8kE8znwapIlMEmqlbhgkxAljMqJpSmNCpxGNXRpYVJIsMyV9YgGt5AWklrAl@6iPHFIhh9TJgjGt7e5IaZhZExLFLjCWQLTrkFmYERN1zwXqxDfvKEmymKIVfmi7zoyABvVoRpKQpBOQl07oDEgocQPLy2xqwwIPiecGdxK1JiGpBUTebMqgGqctnbbw1A6TxdMdPE1C36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Z7uBNG7GKSxFYTci5J19@QEAyQwkreBvBU49DWEnRh3qBFSeYhb8ZoG/@0yndoELyUsZwCSNkj4wZfGIOyjEVaDb8H5yQFxXtOUaIv2z8NY34zBHId9Vk2vMPsxj7PMMZipZEPfA0kmmiKEby38yrpLjwNri6ZDtxduNNIDUd0Ue5lRH254nL2YSSujwuztMQUNF193iBLFI5d62vwvDg5zqriq@gtaXUaioyC9xqrvQAI4ixKv5LDJThmb4tduIp3HB9La9DYfQlf4ZxtRy2/JjTxmkD@HAdpGrusW4dZGmWojaKwC5Ntx/OYwOuCXRYfJq5HGTN@fQvoAyBZk1hlwpBIY4icnj/3@EWRoQL3TXiUjGAk3DGAkAqIAMcT/qLlx/l3o@VpLYaK8jZwfbgq4NcV7JevtNUkxa9NMFlwzWaKUuroXyUWPgS6YlMQSyxwmfgBkD0KwdF2l/DvyrpiKnE/j4s15vByietIutPolqqLHz39fW4f1nGrgMpPGiCpMX16ir8hgjkj6oUPyLXdmXMVxbdWofZud6XdMcCz9pzBcisuNxwY/aVuwpladnee8fjkzDcWfxqKLxph0yWlG9j8WodFpwkqm/5hqtqcCm1eJZt7QpAU6GH0TSGiwWgSvszgRUWnev5Ao0Hm09iE4sUHHpY3@52YPWpK2YOoP7mRGpvBmKoYOR0C14bPDjySbsoeEnTC8nwnLCq2TOMBu96Uk/RGvGiYkuxrMf4tnFpCYrpD61yoaAZf15DSeIZCJmZge@xlvCCObeBGiD8sQBV9T2cnWGilipOz4C4IH4IyXZeXG@yLu5/gr2pflr8uLL4ptPjjO/@asJ5EHvRD5TaAUsVv/RB@U4N2XQGKJPP5156U/3zNfzNzxVeZFCINoxx/MpFSMwajgbF8kLjdTrXbbVW7T55t13x9T5aK3ijLPPq6tRh2Ts6uCD3@005tp8WzwENMlNsVV2awydPgfuJ2kxpD9m7cAcefd0Nsqcnj3afVnVb@jTb/nZazknWOqv0H) (added `somme-fix.py`: print what the first 18 characters of the bottom line should be changed to to make Somme work again)
Next answer must not exceed 461 bytes.
## Hexdump
```
00000000: 766f 6964 202f 2a68 4c21 582d 4020 505e void /*hL!X-@ P^
00000010: 687e 7e58 4040 3044 2030 4422 6870 2158 h~~X@@0D 0D"hp!X
00000020: 2d40 2050 5a68 2029 5835 2020 4d21 4d20 -@ PZh )X5 M!M
00000030: 656c 6966 204d 4f43 2053 4f44 6565 7246 elif MOC SODeerF
00000040: 242a 2f6d 6169 6e28 297b 2f2f 5c0a 202f $*/main(){//\. /
00000050: 2b5c 0a31 2b2f 2f2f 5c0a 2f2a 1b53 6d69 +\.1+///\./*.Smi
00000060: 561b 5a5a 3b6f 6f6f 226c 6f47 223b 3f3d V.ZZ;ooo"loG";?=
00000070: 3025 5321 3131 6f6f 6f22 3e3c 3e22 0a23 0%S!11ooo"><>".#
00000080: 6465 6669 6e65 2053 2222 0a23 6966 6465 define S"".#ifde
00000090: 6620 5f5f 4f42 4a43 5f5f 0a23 6465 6669 f __OBJC__.#defi
000000a0: 6e65 2053 222d 6576 6974 6365 6a62 4f22 ne S"-evitcejbO"
000000b0: 0a23 656e 6469 660a 7072 696e 7466 2822 .#endif.printf("
000000c0: 4322 5329 2f2a 2f69 6d70 6f72 7420 7374 C"S)/*/import st
000000d0: 642e 7374 6469 6f3b 2244 222e 7772 6974 d.stdio;"D".writ
000000e0: 652f 2a2a 2f3b 7d2f 2a0a 2020 3e22 3822 e/**/;}/*. >"8"
000000f0: 3b20 2020 203e 2020 2020 5d23 3b76 0a3e ; > ]#;v.>
00000100: 235e 5a22 3622 3030 4723 5e5f 2434 2d3e #^Z"6"00G#^_$4->
00000110: 312b 3e2c 2242 6566 756e 6765 2d39 222c 1+>,"Befunge-9",
00000120: 2c2c 2c2c 2c2c 2c2c 400a 6e70 2373 294b ,,,,,,,,@.np#s)K
00000130: 6864 7052 3e21 7d62 6267 2425 2a2f 2f2f hdpR>!}bbg$%*///
00000140: e28e 9ac2 bfe2 81b5 6c61 6f63 7261 6843 ........laocrahC
00000150: c2a6 402c 6b61 2238 392d 6567 6e75 6665 ..@,ka"89-egnufe
00000160: 6e55 22 nU"
```
## Explanation
I have redone the Befunge section because modifying someone else's Funge code is harder.
* `Z` is an undefined instruction in all versions. In -98, invalid instructions reflect, and all others ignore them.
* `G` (relative get) does not exist in -93.
* `]` (turn right) does not exist in -96.
[Answer]
# 15. brainfuck, 452 bytes
```
void /*hL!X-@ P^h~~X@@0D 0D"hp!X-@ PZh )X5 M!M elif MOC SODeerF$++[*/main(){//\
/+\
1+///\
/*SmiVZZ;ooo"loG";?=0%S!11ooo"><>"
#define S""
#ifdef __OBJC__
#define S"-evitcejbO"
#endif
printf("C"S)/*/import std.stdio;"D".write/**/;}/*
>"8"; > ]#;v[
>#^Z"6"00G#^_$4->1+>,"Befunge-9",,,,,,,,,@
np#s)KhdpR>!}bbg$%*///]⎚¿⁵laocrahC¦++++[->+++++<]>[->+++++>+++++>++++++<<<]>+++++++.>-.>---.<<-----.++++++++.-----.>--.>---.<+.@,ka"89-egnufenU"
```
Prints:
* `D` in D
* `emmoS` in Somme
* `><>` in ><>
* `C` in C
* `laocrahC` in Charcoal
* `miV` in Vim
* `C-evitcejbO` in Objective-C
* `89-egnufeB` in Befunge-98
* `39-egnufeB` in Befunge-93
* `elif MOC SODeerF` in FreeDOS COM file
* `><>loG` in Gol><>
* `89-egnufenU` in Unefunge-98
* `79-egnufeB` in Befunge-97
* `69-egnufeB` in Befunge-96
* `kcufniarb` in brainfuck
[Try it online!](https://tio.run/##rRlZctvI9Vu4Qn7aoGwAIkCQkk3TlMixVlsZ2VJZ8sQxRXNAoEHCwlZYJGo8nqpcIAfIAXKDfKdqjjIXcd7rboDgYs9UEpUNdvdb@63dwNhKp1@@1Mi@4xCL0ImVT0LrjGQRzOLIv5/4UUYymmZkaiUhTVMyvievPXr0E/14E42lGjmMfN@KU0rkw8ihMrFCh8j7ySQPaJilMkmpnXlRmBI3SsiYZhlNCJ3FNPFoaFNJsq2M9IkNtJIfEiNlQ/ZojF1SIwfUzcMJNZ7tSFmU21MSJ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LSPQd2WprI2yzL2v24tu5@TsiNDj346MnW0eBT5iotyuODLDnnwNzideNzUYsj/whhx/Xg2xpKYPnz2p72wXb7T512POStY5qvYf)
Next answer must not exceed 587 bytes.
## Hexdump
```
00000000: 766f 6964 202f 2a68 4c21 582d 4020 505e void /*hL!X-@ P^
00000010: 687e 7e58 4040 3044 2030 4422 6870 2158 h~~X@@0D 0D"hp!X
00000020: 2d40 2050 5a68 2029 5835 2020 4d21 4d20 -@ PZh )X5 M!M
00000030: 656c 6966 204d 4f43 2053 4f44 6565 7246 elif MOC SODeerF
00000040: 242b 2b5b 2a2f 6d61 696e 2829 7b2f 2f5c $++[*/main(){//\
00000050: 0a20 2f2b 5c0a 312b 2f2f 2f5c 0a2f 2a1b . /+\.1+///\./*.
00000060: 536d 6956 1b5a 5a3b 6f6f 6f22 6c6f 4722 SmiV.ZZ;ooo"loG"
00000070: 3b3f 3d30 2553 2131 316f 6f6f 223e 3c3e ;?=0%S!11ooo"><>
00000080: 220a 2364 6566 696e 6520 5322 220a 2369 ".#define S"".#i
00000090: 6664 6566 205f 5f4f 424a 435f 5f0a 2364 fdef __OBJC__.#d
000000a0: 6566 696e 6520 5322 2d65 7669 7463 656a efine S"-evitcej
000000b0: 624f 220a 2365 6e64 6966 0a70 7269 6e74 bO".#endif.print
000000c0: 6628 2243 2253 292f 2a2f 696d 706f 7274 f("C"S)/*/import
000000d0: 2073 7464 2e73 7464 696f 3b22 4422 2e77 std.stdio;"D".w
000000e0: 7269 7465 2f2a 2a2f 3b7d 2f2a 0a20 203e rite/**/;}/*. >
000000f0: 2238 223b 2020 2020 3e20 2020 205d 233b "8"; > ]#;
00000100: 765b 0a3e 235e 5a22 3622 3030 4723 5e5f v[.>#^Z"6"00G#^_
00000110: 2434 2d3e 312b 3e2c 2242 6566 756e 6765 $4->1+>,"Befunge
00000120: 2d39 222c 2c2c 2c2c 2c2c 2c2c 400a 6e70 -9",,,,,,,,,@.np
00000130: 2373 294b 6864 7052 3e21 7d62 6267 2425 #s)KhdpR>!}bbg$%
00000140: 2a2f 2f2f 5de2 8e9a c2bf e281 b56c 616f *///]........lao
00000150: 6372 6168 43c2 a62b 2b2b 2b5b 2d3e 2b2b crahC..++++[->++
00000160: 2b2b 2b3c 5d3e 5b2d 3e2b 2b2b 2b2b 3e2b +++<]>[->+++++>+
00000170: 2b2b 2b2b 3e2b 2b2b 2b2b 2b3c 3c3c 5d3e ++++>++++++<<<]>
00000180: 2b2b 2b2b 2b2b 2b2e 3e2d 2e3e 2d2d 2d2e +++++++.>-.>---.
00000190: 3c3c 2d2d 2d2d 2d2e 2b2b 2b2b 2b2b 2b2b <<-----.++++++++
000001a0: 2e2d 2d2d 2d2d 2e3e 2d2d 2e3e 2d2d 2d2e .-----.>--.>---.
000001b0: 3c2b 2e40 2c6b 6122 3839 2d65 676e 7566 <+.@,ka"89-egnuf
000001c0: 656e 5522 enU"
```
## Explanation
```
++++[->+++++<]> 20
[->
+++++>
+++++>
++++++
<<<]> 100 100 120
+++++++.> 107 100 120: k
-.> 107 99 120: c
---.<< 107 99 117: u
-----. 102 99 117: f
++++++++. 110 99 117: n
-----.> 105 99 117: i
--.> 105 97 117: a
---.< 105 97 114: r
+. 105 98 114: b
```
[Answer]
# 16. Trefunge-98, 472 bytes
```
void /*hL!X-@ P^h~~X@@0D 0D"hp!X-@ PZh +X5 "M!M elif MOC SODeerF$+[*/main(){//\
/+\
1+///\
/*SmiVZZ;ooo"loG";?=0%S!11ooo"><>"
#define S""
#ifdef __OBJC__
#define S"-evitcejbO"
#endif
printf("C"S)/*/import std.stdio;"D".write/**/;}/*
"rT";#z_"B",@>2+; > ][ v;#;8k,7y2-;@,,
>"Befunge-96"#^Z00G#^_$4->1+>,,,,,,,,,,@
noj6ZR42[jeeOCy(dm*///]]⎚¿⁵laocrahC¦++++[->+++++<]>[->+++++>+++++>++++++<<<]>+++++++.>-.>---.<<-----.++++++++.-----.>--.>---.<+.@,ka"89-egnufenU"
```
Prints:
* `D` in D
* `emmoS` in Somme
* `><>` in ><>
* `C` in C
* `laocrahC` in Charcoal
* `miV` in Vim
* `C-evitcejbO` in Objective-C
* `89-egnufeB` in Befunge-98
* `39-egnufeB` in Befunge-93
* `elif MOC SODeerF` in FreeDOS COM file
* `><>loG` in Gol><>
* `89-egnufenU` in Unefunge-98
* `79-egnufeB` in Befunge-97
* `69-egnufeB` in Befunge-96
* `kcufniarb` in brainfuck
* `89-egnuferT` in Trefunge-98
[Try it online!](https://tio.run/##rRlZctvI9Vu4Qn7akGwAIkCQlE3TlMjRbiuRLZUlzzimaA4INEhYWFhYJNIeT1UukAPkALlBvlM1R5mLOO91N0BwsT2VhCWR3f2Wfv32BoZWMv7yZZMcOA6xCB1Z2Si0zkkawWwS@bORH6UkpUlKxlYc0iQhwxl55dHjj/TDbTSUNslR5PvWJKFEPoocKhMrdIh8EI@ygIZpIpOE2qkXhQlxo5gMaZrSmNDphMYeDW0qSbaVki6xgVbyQ2IkbMi@qkOXbJJD6mbhiBrPdqQ0yuwxmcQeMJZga88lsygjFsqeb6iTwLqlJMliiqcIIsdzZwQkqE5mJIlIOob90jGdAQklXmj7mUMdGOAi8b3wVqL2OCJGSOStugyicdrSagNXnShZXN3B1SQKAmq43hRh0mSWjqNwZ2n1/ODV8zcHz08GZ6@OT9526tLhX69PrjrylnpvE8Pew6NrsgSnZoojvhWOMmtEVe2TtMH2kzfJ1iKXKtmq62SLcQILgcFkaWMItgWGTOJulKWTLBUMxOF@ieldF21hp9TJeS@vG6EvbYCmHxA7mBDOhuRA8ujRegBQ7aJGQ2mD8/0pjsKRwKqSF3TqZMGkDdDp1CG5cK4nbSypB9SiLh22UtdAP0Jcg9z8vKWiE3Em2s3PaExmum7uK5/RW8ZpOknapjny0nE2rNpRYF7Hs7P0IgSrUzONZ14a5WNKzcBKwFfN@9iagLcmwCG3BJExImQiMxHYWJrDjgHgBA4x4ixkflwGXqErAEKcQRyZ0SQ1mXPw72o8XCHo7nUBPfckRuF6yZh9oUsv4x8BNsOyjdS2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9i2k94Bkj2OVbYZEGkPk9Py6xxtFhgrct@BSMoSScMsAYldABDiu8BstX84fyJartSgqypvQC6BVwMcV7HVg2qiT4hUcVBYcs5qilDL6V4mFDoGumBTEEjNcJt6KskshKNppE/6srC2qEtfzqBijDy@HuI6kO7V2Kbr40pPvc3u/jtsmiPy4BjvVpk9O8cUqHGdI/egeuTZbc64i@NYK1HzWXkl3DPC0OWewnIrLCQdKfymbcKa20557PF4584nNr4biQSNM2qTUgc3bOgw6TVA59A9TGXMqPPMq2VwTgqRAjybf3EQkGE3CmxncqOhUzy9oNMwCGlsQvHjBw/BmL8/ZpabkPYj60ZuosRWOqIqW08FwTfhuwSWpV9aQoBMnz2fiRMWUSdxn7U3ZSXviRsOEZI/F@FM4tYTEZIfUuRDRDL4uIaXxDDcZW6Hjs5vxwnZsAh0hvs2AKPoLnZ1goJUiTs7C2zC6D8t0bR5uMC96P8Ff1b4sPy4snhTa/PKdPyasJhMf8qFyE0Ko4lM/hPcMSNebQJFkAX/sSfk7ff5e0BOPMilYGko5vqeRUiuGQwNj@SDx2q1Ku92otB8/3TYCfVeWitwoy9z6ur1odk7OWoQOf59k7DS4F/iIifu2RcsMZ/I16E@8dmIwZL/n9Tn@PBtiSk0ePntS2WnkT7T5u2jOStbF2/P/AA)
Next answer must not exceed 613 bytes.
## Hexdump
```
00000000: 766f 6964 202f 2a68 4c21 582d 4020 505e void /*hL!X-@ P^
00000010: 687e 7e58 4040 3044 2030 4422 6870 2158 h~~X@@0D 0D"hp!X
00000020: 2d40 2050 5a68 202b 5835 2022 4d21 4d20 -@ PZh +X5 "M!M
00000030: 656c 6966 204d 4f43 2053 4f44 6565 7246 elif MOC SODeerF
00000040: 242b 5b2a 2f6d 6169 6e28 297b 2f2f 5c0a $+[*/main(){//\.
00000050: 202f 2b5c 0a31 2b2f 2f2f 5c0a 2f2a 1b53 /+\.1+///\./*.S
00000060: 6d69 561b 5a5a 3b6f 6f6f 226c 6f47 223b miV.ZZ;ooo"loG";
00000070: 3f3d 3025 5321 3131 6f6f 6f22 3e3c 3e22 ?=0%S!11ooo"><>"
00000080: 0a23 6465 6669 6e65 2053 2222 0a23 6966 .#define S"".#if
00000090: 6465 6620 5f5f 4f42 4a43 5f5f 0a23 6465 def __OBJC__.#de
000000a0: 6669 6e65 2053 222d 6576 6974 6365 6a62 fine S"-evitcejb
000000b0: 4f22 0a23 656e 6469 660a 7072 696e 7466 O".#endif.printf
000000c0: 2822 4322 5329 2f2a 2f69 6d70 6f72 7420 ("C"S)/*/import
000000d0: 7374 642e 7374 6469 6f3b 2244 222e 7772 std.stdio;"D".wr
000000e0: 6974 652f 2a2a 2f3b 7d2f 2a0a 2022 7254 ite/**/;}/*. "rT
000000f0: 223b 237a 5f22 4222 2c40 3e32 2b3b 2020 ";#z_"B",@>2+;
00000100: 3e20 2020 205d 5b20 763b 233b 386b 2c37 > ][ v;#;8k,7
00000110: 7932 2d3b 402c 2c0a 3e22 4265 6675 6e67 y2-;@,,.>"Befung
00000120: 652d 3936 2223 5e5a 3030 4723 5e5f 2434 e-96"#^Z00G#^_$4
00000130: 2d3e 312b 3e2c 2c2c 2c2c 2c2c 2c2c 2c40 ->1+>,,,,,,,,,,@
00000140: 0a6e 6f6a 365a 5234 325b 6a65 654f 4379 .noj6ZR42[jeeOCy
00000150: 2864 6d2a 2f2f 2f5d 5de2 8e9a c2bf e281 (dm*///]].......
00000160: b56c 616f 6372 6168 43c2 a62b 2b2b 2b5b .laocrahC..++++[
00000170: 2d3e 2b2b 2b2b 2b3c 5d3e 5b2d 3e2b 2b2b ->+++++<]>[->+++
00000180: 2b2b 3e2b 2b2b 2b2b 3e2b 2b2b 2b2b 2b3c ++>+++++>++++++<
00000190: 3c3c 5d3e 2b2b 2b2b 2b2b 2b2e 3e2d 2e3e <<]>+++++++.>-.>
000001a0: 2d2d 2d2e 3c3c 2d2d 2d2d 2d2e 2b2b 2b2b ---.<<-----.++++
000001b0: 2b2b 2b2b 2e2d 2d2d 2d2d 2e3e 2d2d 2e3e ++++.-----.>--.>
000001c0: 2d2d 2d2e 3c2b 2e40 2c6b 6122 3839 2d65 ---.<+.@,ka"89-e
000001d0: 676e 7566 656e 5522 gnufenU"
```
## Explanation
If Funge-98 is detected, the number of dimensions is queried using `7y`. Additionally, I changed the DOS code a little to remove the `)`, making it possible to use Brain-Flak. The `)` has been changed into a `+`, so a different `+` was removed (after `$` from DOS). Also, Somme has a `[` in it now, so brainfuck code got another `]`.
[Answer]
# 19. Haskell, 690 bytes
```
void /*-{-- #hR!X-@ P^h~~X@@0D 0D"hv!X-@ PZh +X5 "M!M elif MOC SODeerF$}++++[*/main(){//\
/+ #\
echo hsab<<'EOF' #>>
1+///\
/*ggcGmiVZZ;ooo"loG";?=0%S!11ooo<"><>"
#define S""
#ifdef __OBJC__
#define S"-evitcejbO"
#endif
printf("C"S)/*/import std.stdio;"D".write/**/;}/*<<
"rT";#z_"B",@>2+; > ][ v;#;8k,7y2-;@,, <<<
>"Befunge-96"#^Z00G#^_$4->1+>,,,,,,,,,,@
n*'um{Z'; 5kziZ<m%*///><>}]⎚¿⁵laocrahC¦++++[-<+++++>]<[-<++++++<+++++<+++++>>>]<<<+++++++.>-.>---.<<-----.++++++++.-----.>--.>---.<+.>>>((((((((((()()()){}){}){}){}()){})((()()()()){}){})[(([][]){}){}()])([]()){})[]())(([[][]()]([]()((((([][][])){}{})[]){})))[]())({ -}_=")";main=putStr"lleksaH"-- *///@,ka"89-egnufenU"
```
Prints:
* `D` in D
* `emmoS` in Somme
* `><>` in ><>
* `C` in C
* `laocrahC` in Charcoal
* `miV` in Vim
* `C-evitcejbO` in Objective-C
* `89-egnufeB` in Befunge-98
* `39-egnufeB` in Befunge-93
* `elif MOC SODeerF` in FreeDOS COM file
* `><>loG` in Gol><>
* `89-egnufenU` in Unefunge-98
* `79-egnufeB` in Befunge-97
* `69-egnufeB` in Befunge-96
* `kcufniarb` in brainfuck
* `89-egnuferT` in Trefunge-98
* `kalf-niarb` in brain-flak
* `hsab` in bash
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E7Pr3v8oMhQgfs2XErG0BKuGUBIBUSA4wq/0fJl@bC52q1FU9F@ioMIjgr4wIK9ZM3bLVK@2ITOgmPWU7RKRf8hsbAh0JWTklhhjivEu2Z2KQRDex3Cn5Z1RFfidp6UY4zh1RQ3kXS32alkF1969tvcvmziVgOVnzZBUnP@7AxfV8N2xjRMbpHr3v6Cq0i@jQrtveislTsGeL63YLBaiqsFB1p/pZpwpq7XWUQ8XjnlxOVXQ/GoESYdUjmBLY51mHSGoPLo76ayFlS453WyhSUESYmezH5ViCgwhoI3M7hR0bkpL2g0LiKaOpC8eMHD9GZ/ksAuNZXoQdRvwUxPnXhCdfScCY7bg899uCQNqhYSdGLnciZ2VE6ZxkN2vKkG6UDcaJiS7MEYfw6nV5CY7lA6lzKawTcVpDy9QyFTJ/ZCdjNeEscmcCLENzWQRf9B704x0SoZpxbxdZzcxlW6Dk83mJdnP8FfN76vPjAsnxW6/PItHxQ2slkI9VC7iiFV8bkfwgcWlOsaUGRFxB98Uv6XEvyFXCAeZlLwNLRyfAel5E4KmwbG6mEWdPbrnU673nn6fMeKzANVKWujqnLvm@6y2zk5OyL0@Lsya7fNoyBETJTbEUdm2FNowPkk6GQWQw4HwZDjL6ohltTs8Ytn9d22fKbN3/BzVqop/ibh/wA)
Next answer must not exceed 897 bytes.
## Explanation
After working for a long time on how to integrate Haskell with the FreeDOS COM binary code and finding an ugly solution, it didn't work with the interpreter on TIO and thus I pinged @NieDzejkob which quickly found another way, thanks!
Instead of `/* multi-line comment */` Haskell uses `{- multi-line comment -}`, so `void /* ...` will get properly parsed. The way this polyglot handles it, is to use `void` as an identifier for defining the operator `(/*-)` after which follows a long comment, a new identifier `_` and a definition and finally the `main`-function.
Basically I only needed to take care of Unefunge-98 (just moving it to the end of the file, fixing Somme and rebalancing & no-opping the newly integrated parentheses for Brain-Flak. This worked nicely because I had a useless definition floating around, where I could just put the only tricky paren `)`.
## Hexdump
```
00000000: 766f 6964 202f 2a2d 7b2d 2d20 2368 5221 void /*-{-- #hR!
00000010: 582d 4020 505e 687e 7e58 4040 3044 2030 X-@ P^h~~X@@0D 0
00000020: 4422 6876 2158 2d40 2050 5a68 202b 5835 D"hv!X-@ PZh +X5
00000030: 2022 4d21 4d20 656c 6966 204d 4f43 2053 "M!M elif MOC S
00000040: 4f44 6565 7246 247d 2b2b 2b2b 5b2a 2f6d ODeerF$}++++[*/m
00000050: 6169 6e28 297b 2f2f 5c0a 202f 2b20 235c ain(){//\. /+ #\
00000060: 0a20 6563 686f 2068 7361 623c 3c27 454f . echo hsab<<'EO
00000070: 4627 2023 3e3e 0a31 2b2f 2f2f 5c0a 2f2a F' #>>.1+///\./*
00000080: 1b67 6763 476d 6956 1b5a 5a3b 6f6f 6f22 .ggcGmiV.ZZ;ooo"
00000090: 6c6f 4722 3b3f 3d30 2553 2131 316f 6f6f loG";?=0%S!11ooo
000000a0: 3c22 3e3c 3e22 0a23 6465 6669 6e65 2053 <"><>".#define S
000000b0: 2222 0a23 6966 6465 6620 5f5f 4f42 4a43 "".#ifdef __OBJC
000000c0: 5f5f 0a23 6465 6669 6e65 2053 222d 6576 __.#define S"-ev
000000d0: 6974 6365 6a62 4f22 0a23 656e 6469 660a itcejbO".#endif.
000000e0: 7072 696e 7466 2822 4322 5329 2f2a 2f69 printf("C"S)/*/i
000000f0: 6d70 6f72 7420 7374 642e 7374 6469 6f3b mport std.stdio;
00000100: 2244 222e 7772 6974 652f 2a2a 2f3b 7d2f "D".write/**/;}/
00000110: 2a3c 3c0a 2022 7254 223b 237a 5f22 4222 *<<. "rT";#z_"B"
00000120: 2c40 3e32 2b3b 2020 3e20 2020 205d 5b20 ,@>2+; > ][
00000130: 763b 233b 386b 2c37 7932 2d3b 402c 2c20 v;#;8k,7y2-;@,,
00000140: 3c3c 3c0a 3e22 4265 6675 6e67 652d 3936 <<<.>"Befunge-96
00000150: 2223 5e5a 3030 4723 5e5f 2434 2d3e 312b "#^Z00G#^_$4->1+
00000160: 3e2c 2c2c 2c2c 2c2c 2c2c 2c40 0a6e 2a27 >,,,,,,,,,,@.n*'
00000170: 756d 7b5a 273b 2035 6b7a 695a 3c6d 252a um{Z'; 5kziZ<m%*
00000180: 2f2f 2f3e 3c3e 7d5d e28e 9ac2 bfe2 81b5 ///><>}]........
00000190: 6c61 6f63 7261 6843 c2a6 2b2b 2b2b 5b2d laocrahC..++++[-
000001a0: 3c2b 2b2b 2b2b 3e5d 3c5b 2d3c 2b2b 2b2b <+++++>]<[-<++++
000001b0: 2b2b 3c2b 2b2b 2b2b 3c2b 2b2b 2b2b 3e3e ++<+++++<+++++>>
000001c0: 3e5d 3c3c 3c2b 2b2b 2b2b 2b2b 2e3e 2d2e >]<<<+++++++.>-.
000001d0: 3e2d 2d2d 2e3c 3c2d 2d2d 2d2d 2e2b 2b2b >---.<<-----.+++
000001e0: 2b2b 2b2b 2b2e 2d2d 2d2d 2d2e 3e2d 2d2e +++++.-----.>--.
000001f0: 3e2d 2d2d 2e3c 2b2e 3e3e 3e28 2828 2828 >---.<+.>>>(((((
00000200: 2828 2828 2828 2928 2928 2929 7b7d 297b (((((()()()){}){
00000210: 7d29 7b7d 297b 7d28 2929 7b7d 2928 2828 }){}){}()){})(((
00000220: 2928 2928 2928 2929 7b7d 297b 7d29 5b28 )()()()){}){})[(
00000230: 285b 5d5b 5d29 7b7d 297b 7d28 295d 2928 ([][]){}){}()])(
00000240: 5b5d 2829 297b 7d29 5b5d 2829 2928 285b []()){})[]())(([
00000250: 5b5d 5b5d 2829 5d28 5b5d 2829 2828 2828 [][]()]([]()((((
00000260: 285b 5d5b 5d5b 5d29 297b 7d7b 7d29 5b5d ([][][])){}{})[]
00000270: 297b 7d29 2929 5b5d 2829 2928 7b20 2d7d ){})))[]())({ -}
00000280: 5f3d 2229 223b 6d61 696e 3d70 7574 5374 _=")";main=putSt
00000290: 7222 6c6c 656b 7361 4822 2d2d 202a 2f2f r"lleksaH"-- *//
000002a0: 2f40 2c6b 6122 3839 2d65 676e 7566 656e /@,ka"89-egnufen
000002b0: 5522 U"
```
[Answer]
# 30. 99, 1187 bytes
```
void /*-{-- #hR!X-@ P^h~~X@@0D 0D"hv!X-@ PZh +X5 "M!M elif MOC SODeerF$}++++[*///\
/+ #\
basename "$(readlink /proc/$$/exe)"|rev;:<<'EOF' #>>\
1+/// O\
/* ggcGmiVZZ;ooo"loG";?=0%S!11ooo<"><>"
#define S"C" //A
#ifdef __cplusplus//l
f(); //i
#include<cstdio>//c
#define S"++C" //e
int/// "
#endif// \.
#ifdef __OBJC__
#define S"C-evitcejbO"
#endif
main(){printf(S)/*/main(){import std.stdio;"D".write/**/;}/*}<
> v
999 999 99
999 999 9
999v<>
v <>"efunge-98",,,,,,,,,7y3-v<
> #^Gv @,"B"_"Tr",,@
v<[_"]Befunge-93">,,,,,,,,,,@<
>#<"Befunge-96"> ^v$G001
v ,,,,,"79-egnufeB" _ v<
> ,,,,,@#,,,,"79-egnuferdauQ"_v#!$G0001<>
@,,,,,,,,,,,"79-egnuferT"<>
.l . .*///{}]⎚¿⁵laocrahC¦++++[-<+++++>]<[-<++++++<+++++<+++++>>>]<<<+++++++.>-.>---.<<-----.++++++++.-----.>--.>---.<+.>>>((((((((((()()()){}){}){}){}()){})((()()()()){}){})[(([][]){}){}()])([]()){})[]())(([[][]()]([]()((((([][][])){}{})[]){})))[]())({ -}_=")";(!)=seq;main|let b!_=""=putStr$(""!"snrettaPgnaB+")++init"lleksaH("{-
//TJri$8Al|?lz=a20-}--)*///💬ijome💬➡😭Emotinomicon😲⏪⏬⏩@,ka"89-egnufenU"
```
Prints:
* `D` in D
* `emmoS` in Somme
* `><>` in ><>
* `C` in C
* `laocrahC` in Charcoal
* `miV` in Vim
* `C-evitcejbO` in Objective-C
* `89-egnufeB` in Befunge-98
* `39-egnufeB` in Befunge-93
* `elif MOC SODeerF` in FreeDOS COM file
* `><>loG` in Gol><>
* `89-egnufenU` in Unefunge-98
* `79-egnufeB` in Befunge-97
* `69-egnufeB` in Befunge-96
* `kcufniarb` in brainfuck
* `89-egnuferT` in Trefunge-98
* `kalf-niarb` in brain-flak
* `hsab` in bash
* `lleksaH` in Haskell
* `hsz` in zsh
* `ijome` in emoji
* `snrettaPgnaB+lleksaH` in Haskell+BangPatterns
* `++C` in C++
* `nocimonitomE` in Emotinomicon
* `hsk` in ksh
* `hsad` in dash
* `79-egnuferT` in Trefunge-97
* `ecilA` in Alice
* `79-egnuferdauQ` in Quadrefunge-97
* `99` in 99
[Try it online!](https://tio.run/##rTrLcttIkmfhF@ZSAtUGIBIEKdmyRJFsi3rY7rEtjaXu8ZqiOSBQJGHhwcFDoiyrI@YHpiP2tLGHndjLRuzG7GUj9rwR8yn@gvkDb2Y9QPBhd8fM0BZZVfmszKzMLJADOxl//lwiB65LbEJHdjYK7RckjWA2ifzbkR@lJKVJSsZ2HNIkIYNb8sqjRx/o@6tooJTIYeT79iShRD2MXKoSO3SJehCPsoCGaaKShDqpF4UJGUYxGdA0pTGh0wmNPRo6VFEcOyVt4gCt4ofETNiQvVUHQ1IiHTrMwhE197aVNMqcMZnEHjBWQLQ3JLdRRmzUXQqskMC@oiTJYoq7CCLXG94S0KA6uSVJRNIxyEvH9BZIKPFCx89c6sIAF4nvhVcKdcYRMUOibtRVUI3TFla3cNWNkvnVbVxNoiCg5tCbIkyZ3KbjKNxeWH1x8Orp9wdPj/vPXx0dv2nVlc4/XRyft9QN/cYhptPErRuqArtmhiO@HY4ye0R1405ZY/LUEtmY51IlG/UK2WCcwEPgMFXivs7C0AtHhG3mwZayNgCXgxy2kXaUpZMsFbhizx9jet1GFzkpdSWbxXUz9JU1cMA6cYIJ4WyIBJIHD1YDgGofDR0qa5zvb@MIdONYVfKMTt0smDQAOp26RCo39JS1BauBtfQFG5TrhpHv2iSXv9vQMbY4E@Pyd@hjZoS2DKF7DKJxmk6ShmWNvHScDapOFFgX8e3z9DSEYKBWGt96aSTHlFqBnUAIWzexPYEgToCDdBBR8aCoRGUqsLEygx0BwA1cYsZZyMK7CDzHCAGEOIPjZUWT1GIxw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oHLpL6YyZ1S452WymSUESY4eTb4qRCQYQ8GbGdyo6LQiL2g0zAIa23B48YKHx5v9HIpdagrRg6gfvIke2@GI6ui5CjhuB9534ZLULVpI0Imdy5nYUT5lGvdYe1MM0q640TAl2YMx/hxOLyAx3SF1zp1oBl@VkNL4FoWM7dD12c14ThybQEeIX83BKfo1vT3Gg1Y4cWoWXoXRTVika/DjBvO89xP8dePz4gPD/Fmhwy/f8kFhNZn4kA@1yxCOKj73Q3jXhHRdAookC/iDT8p/pcW/AffEw0wKnoZSjl86Kqkdw6aBsXqQeI3dcqOxVW48fLxpBpV9Vclzo6py71ecebdzctYitPiXo@b2Fo8CHzFRbkO0zLAn34D@xGskJkP2u16P48@yIabU5Ju9R@XtLflMm/@MiLNSK@KHT/8P)
Next answer must not exceed 1543 bytes.
## Explanation
**Befunge-93** didn't like the `999` in it's path, so I changed its control-flow a little. The rest is very simple **99** code:
```
999 999 99 -- set 999 = 999 - 99 (900)
999 999 9 -- set 999 = 900 - 9 (891)
999 -- print 891/9 ( 99)
```
## Hexdump
```
00000000: 766f 6964 202f 2a2d 7b2d 2d20 2368 5221 void /*-{-- #hR!
00000010: 582d 4020 505e 687e 7e58 4040 3044 2030 X-@ P^h~~X@@0D 0
00000020: 4422 6876 2158 2d40 2050 5a68 202b 5835 D"hv!X-@ PZh +X5
00000030: 2022 4d21 4d20 656c 6966 204d 4f43 2053 "M!M elif MOC S
00000040: 4f44 6565 7246 247d 2b2b 2b2b 5b2a 2f2f ODeerF$}++++[*//
00000050: 2f5c 0a20 2f2b 2023 5c0a 2062 6173 656e /\. /+ #\. basen
00000060: 616d 6520 2224 2872 6561 646c 696e 6b20 ame "$(readlink
00000070: 2f70 726f 632f 2424 2f65 7865 2922 7c72 /proc/$$/exe)"|r
00000080: 6576 3b3a 3c3c 2745 4f46 2720 233e 3e5c ev;:<<'EOF' #>>\
00000090: 0a31 2b2f 2f2f 2020 2020 2020 2020 2020 .1+///
000000a0: 2020 2020 2020 2020 4f5c 0a2f 2a20 1b67 O\./* .g
000000b0: 6763 476d 6956 1b5a 5a3b 6f6f 6f22 6c6f gcGmiV.ZZ;ooo"lo
000000c0: 4722 3b3f 3d30 2553 2131 316f 6f6f 3c22 G";?=0%S!11ooo<"
000000d0: 3e3c 3e22 0a23 6465 6669 6e65 2053 2243 ><>".#define S"C
000000e0: 2220 2020 2020 2020 2f2f 410a 2369 6664 " //A.#ifd
000000f0: 6566 205f 5f63 706c 7573 706c 7573 2f2f ef __cplusplus//
00000100: 6c0a 2066 2829 3b20 2020 2020 2020 2020 l. f();
00000110: 2020 202f 2f69 0a23 696e 636c 7564 653c //i.#include<
00000120: 6373 7464 696f 3e2f 2f63 0a23 6465 6669 cstdio>//c.#defi
00000130: 6e65 2053 222b 2b43 2220 2f2f 650a 2069 ne S"++C" //e. i
00000140: 6e74 2f2f 2f20 2020 2020 2020 2020 220a nt/// ".
00000150: 2365 6e64 6966 2f2f 2020 2020 2020 205c #endif// \
00000160: 2e0a 2369 6664 6566 205f 5f4f 424a 435f ..#ifdef __OBJC_
00000170: 5f0a 2364 6566 696e 6520 5322 432d 6576 _.#define S"C-ev
00000180: 6974 6365 6a62 4f22 0a23 656e 6469 660a itcejbO".#endif.
00000190: 206d 6169 6e28 297b 7072 696e 7466 2853 main(){printf(S
000001a0: 292f 2a2f 6d61 696e 2829 7b69 6d70 6f72 )/*/main(){impor
000001b0: 7420 7374 642e 7374 6469 6f3b 2244 222e t std.stdio;"D".
000001c0: 7772 6974 652f 2a2a 2f3b 7d2f 2a7d 3c0a write/**/;}/*}<.
000001d0: 3e20 2076 0a39 3939 2039 3939 2039 390a > v.999 999 99.
000001e0: 3939 3920 3939 3920 390a 3939 3976 3c3e 999 999 9.999v<>
000001f0: 0a76 2020 3c3e 2265 6675 6e67 652d 3938 .v <>"efunge-98
00000200: 222c 2c2c 2c2c 2c2c 2c2c 3779 332d 763c ",,,,,,,,,7y3-v<
00000210: 0a3e 2020 235e 4776 2020 2020 2020 2020 .> #^Gv
00000220: 2020 2020 2020 2020 2040 2c22 4222 5f22 @,"B"_"
00000230: 5472 222c 2c40 0a20 2020 763c 5b5f 225d Tr",,@. v<[_"]
00000240: 4265 6675 6e67 652d 3933 223e 2c2c 2c2c Befunge-93">,,,,
00000250: 2c2c 2c2c 2c2c 403c 0a20 2020 3e23 3c22 ,,,,,,@<. >#<"
00000260: 4265 6675 6e67 652d 3936 223e 205e 7624 Befunge-96"> ^v$
00000270: 4730 3031 0a76 2020 2c2c 2c2c 2c22 3739 G001.v ,,,,,"79
00000280: 2d65 676e 7566 6542 2220 5f20 2020 2020 -egnufeB" _
00000290: 2020 2020 2020 2020 2020 2020 2076 3c0a v<.
000002a0: 3e20 202c 2c2c 2c2c 4023 2c2c 2c2c 2237 > ,,,,,@#,,,,"7
000002b0: 392d 6567 6e75 6665 7264 6175 5122 5f76 9-egnuferdauQ"_v
000002c0: 2321 2447 3030 3031 3c3e 0a20 2020 2020 #!$G0001<>.
000002d0: 2040 2c2c 2c2c 2c2c 2c2c 2c2c 2c22 3739 @,,,,,,,,,,,"79
000002e0: 2d65 676e 7566 6572 5422 3c3e 0a2e 6c20 -egnuferT"<>..l
000002f0: 2020 2020 2020 2020 2020 2e20 2020 2e2a . .*
00000300: 2f2f 2f7b 7d5d e28e 9ac2 bfe2 81b5 6c61 ///{}]........la
00000310: 6f63 7261 6843 c2a6 2b2b 2b2b 5b2d 3c2b ocrahC..++++[-<+
00000320: 2b2b 2b2b 3e5d 3c5b 2d3c 2b2b 2b2b 2b2b ++++>]<[-<++++++
00000330: 3c2b 2b2b 2b2b 3c2b 2b2b 2b2b 3e3e 3e5d <+++++<+++++>>>]
00000340: 3c3c 3c2b 2b2b 2b2b 2b2b 2e3e 2d2e 3e2d <<<+++++++.>-.>-
00000350: 2d2d 2e3c 3c2d 2d2d 2d2d 2e2b 2b2b 2b2b --.<<-----.+++++
00000360: 2b2b 2b2e 2d2d 2d2d 2d2e 3e2d 2d2e 3e2d +++.-----.>--.>-
00000370: 2d2d 2e3c 2b2e 3e3e 3e28 2828 2828 2828 --.<+.>>>(((((((
00000380: 2828 2828 2928 2928 2929 7b7d 297b 7d29 (((()()()){}){})
00000390: 7b7d 297b 7d28 2929 7b7d 2928 2828 2928 {}){}()){})((()(
000003a0: 2928 2928 2929 7b7d 297b 7d29 5b28 285b )()()){}){})[(([
000003b0: 5d5b 5d29 7b7d 297b 7d28 295d 2928 5b5d ][]){}){}()])([]
000003c0: 2829 297b 7d29 5b5d 2829 2928 285b 5b5d ()){})[]())(([[]
000003d0: 5b5d 2829 5d28 5b5d 2829 2828 2828 285b []()]([]()((((([
000003e0: 5d5b 5d5b 5d29 297b 7d7b 7d29 5b5d 297b ][][])){}{})[]){
000003f0: 7d29 2929 5b5d 2829 2928 7b20 2d7d 5f3d })))[]())({ -}_=
00000400: 2229 223b 2821 293d 7365 713b 6d61 696e ")";(!)=seq;main
00000410: 7c6c 6574 2062 215f 3d22 223d 7075 7453 |let b!_=""=putS
00000420: 7472 2428 2222 2122 736e 7265 7474 6150 tr$(""!"snrettaP
00000430: 676e 6142 2b22 292b 2b69 6e69 7422 6c6c gnaB+")++init"ll
00000440: 656b 7361 4828 227b 2d0a 2f2f 544a 7269 eksaH("{-.//TJri
00000450: 2438 416c 7c3f 6c7a 3d61 3230 2d7d 2d2d $8Al|?lz=a20-}--
00000460: 292a 2f2f 2ff0 9f92 ac69 6a6f 6d65 f09f )*///....ijome..
00000470: 92ac e29e a1f0 9f98 ad45 6d6f 7469 6e6f .........Emotino
00000480: 6d69 636f 6ef0 9f98 b2e2 8faa e28f ace2 micon...........
00000490: 8fa9 402c 6b61 2238 392d 6567 6e75 6665 ..@,ka"89-egnufe
000004a0: 6e55 22 nU"
```
[Answer]
# 45. [Spoon](https://github.com/MarquisdeGeek/spoon), 3743 bytes
```
void /*-{-- #hR!X-@ P^h~~X@@0D 0D"hv!X-@ PZh +X5 "M!M eliF MOC SODeerF$}++++[*///opfzzfzzfzzfzzzfzzfzfzfffzffzzzzzffzfzzzffzfzzzfzfzfzzfzfzzzfzfzfzzfzfzfffzzfzfzzzfzffff⠆⡆⠆⡆⠆⡆⠆⡆⠆⡆⠆⡆⠆⡆\
/+ #\
basename "$(readlink /proc/$$/exe)"|rev;:<<'EOF' #>>\
1+/// O\
/* ggcGmiVZZ;ooo"loG";?=0%S!11ooo<"><>"
#define S"C" //A
#ifdef __cplusplus//l
f(); //i
#include<cstdio>//c
#define S"++C" //e
int/// "
#endif// \.
#ifdef __OBJC__
#define S"C-evitceJbO"
#endif
main(){printf(S)/*/main(){import std.stdio;"D".write/**/;}/*}<
> vwWWWWwWWWWWwvwWWwWWWwvwWWwWWWwvwWWwWWWwvwWWwWWWwvwWWwWWWwvwWWwWWWwvWwwwwwwwwwwwWWWwWWWWWWwWWWWWWWwWWWWWWWWWwWWWWWWWWWWWWwWWWWWWWWWWwWWWWWWWWWWWWWWWWWwWWWWWWWWWWWWWWWWWWwWWWWWWWWWWWWWWWWWWwWWWWWWWWWWWWWWWWWWWwwWWWWWWWWWWWWWWWWWWWWwwwwwwWWWWWWWWWWWWWWWWWWWWWwwwwwWWWWWWWWWWWWWWWWWWWWWWwwwwwwwwwww
999 999 99
999 999 9
999v<>0000110110
v <>"efunge-98",,,,,,,,,7y3-v< @
> #^Gv @,"B"_"Tr",,@
v<[_"]Befunge-93">,,,,,,,,,,0|@<
>#<"Befunge-96"> ^v$G001
v ,,,,,"79-egnufeB" _ v<
> ,,,,,@# ,"79-egnuferT"_v# $G0001<>
<>10000G$v
#@,,,,,,,,,,,,,,@#"79-egnuferdauQ"_100000G$v
,,"79-egnufetniuQ"_1000000G$!v@,,,,,,,,,,,,
"79-egnufetpeS"_"Sexefunge-97"#@,,,,,,,,,,,,@#,
<>"v"@
@,"F","u","n","c","t","o","i","d"<> red down two red left one yellow up green down yellow up green down red up three red right two yellow down yellow down blue left green down red down one yellow down blue left green down red down two red left one yellow up yellow down blue left green down red left one red down three yellow down yellow down blue left green down red up two green down yellow up yellow down blue left red up three red right two yellow down yellow down blue left 0001110000100000100010000010000010100000100000000010001000100000100010000010000010100000100000100010000010001000100000000010001000001000100011000010001000100000100011000010000010001000001000100000100000100000100010000010001000001000100000000010001000001000100010000000110000110000011000001001100000100010001000100010000001001101110000001100111100011001100000001001110011110000110111000001000000010000000100000001000000010000000100000001000000010001100011011110001000100010000010001010000100000001000100000001000000010000000100000001000000010000000100000000100110
.L . . *///{}]⎚F¹laocrahC«▲²²²²²⌂↨α↨ß↨²²⌂↨←ß≤▼→▼←≥→⌂↨σ→→→↨ß→→→↨π→→→→→↨¡ß¡→→↨δ→↨ß→→→→↨µ→→→↨¡φ↨επ⌂↨¡ß¡→→→↨¡πσ▲⌂↨¡σµ¡→↨¡α¡→↨¡π¡▲▲▲¡▲▲▲¡σ▲¡δ¡φ▲▲▲▲¡ε▼▼¡»+[-++++[-<+++++>]<[-<++++++<+++++<+++++>>>]<<<+++++++.>-.>---.<<-----.++++++++.-----.>--.>---.<+.>>>](()()()()())<>(()())<>{({}[()])<>({({})({}[()])}{})<>}<>((){[()](<{}((((((((((()()()){}){}){}){}()){})((()()()()){}){})[(([][]){}){}()])([]()){})[]())(([[][]()]([]()((((([][][])){}{})[]){})))[]())>)}{}){{}(<((((((((((((((()()()){}){}){}){}()){})((()()()()){}){})[(([][]){}){}()])([]()){})[]())[[]()()()])[])[[]()()()()])[][][][()])((((((()()()){}()){}){}){})[()()])>)}{}({ -}_=")";(!)=seq;main|let b!_=""=putStr$(""!"snrettaPgnaB+")++init"lleksaH("{-
//HHT-"NUb4`BJJndO-}--)[-]<>\[\<>\\/<>\/\[/\/\<><><>\[/\/\/<>\//\/<><><><><>\\]/\//\//\/\]/\/\\./]s*//∙SAVNACp💬ijome💬➡😭Emotinomicon😲⏪⏬⏩@,ka"89-egnufenUsssssaaaaaeeeeeeeeeepaeeeeeeeeeecisaeeeeeeejiiiiiiiijeeeeeeeeeeeeeeeeeejzaciiiiiiiiiiiiijeeeaceeacewuuuweejiiiijiiiiiiiiiiijeeeaaaakeeaaaawvw⠀⠖⠗⠎⢎⢦⢦⠮"
```
Prints:
* `D` in D
* `emmoS` in Somme
* `><>` in ><>
* `C` in C
* `laocrahC` in Charcoal
* `miV` in Vim
* `C-evitceJbO` in ObJective-C
* `89-egnufeB` in Befunge-98
* `39-egnufeB` in Befunge-93
* `eliF MOC SODeerF` in FreeDOS COM file
* `><>loG` in Gol><>
* `89-egnufenU` in Unefunge-98
* `79-egnufeB` in Befunge-97
* `69-egnufeB` in Befunge-96
* `kcufniarb` in brainfuck
* `89-egnuferT` in Trefunge-98
* `kalf-niarb` in brain-flak
* `hsab` in bash
* `lleksaH` in Haskell
* `hsz` in zsh
* `ijome` in emoji
* `snrettaPgnaB+lleksaH` in Haskell+BangPatterns
* `++C` in C++
* `nocimonitomE` in Emotinomicon
* `hsk` in ksh
* `hsad` in dash
* `79-egnuferT` in Trefunge-97
* `ecilA` in Alice
* `79-egnuferdauQ` in Quadrefunge-97
* `99` in 99
* `79-egnufetniuQ` in Quintefunge-97
* `kcufniarb cilobmys` in symbolic brainfuck
* `79-egnufexeS` in Sexefunge-97
* `senots` in stones
* `79-egnufetpeS` in Septefunge-97
* `diotcnuF` in Functoid
* `ssarG` in Grass
* `kcuhpla` in alphuck
* `SAVNAC` in CANVAS
* `egaugnal sseleman` in nameless language
* `LIve` in evil
* `V` in V
* `elliarb` in braille
* `68xalfniarb` in BrainFlaX86
* `NOOPS` in Spoon
[Try it online!](https://tio.run/##rTvbchvHlc@cX8hLa0gLMwQGQ5ASRUIAwjslryQyoixpDUDwYKYBDDmYgecCkKKZcm2qVJuqrTiVB@/lYS1v7ab2kmxVXPHD1npflHf7H/gDyR9oz@nuueBCSXYyJGa6z71Pn76cxqBtBL3Xr@fJpmURg9CuEXVd4x4JPagNPOes63ghCWkQkp7huzQISPuMPLDpznN6fOK1pXmy7TmOMQgokbc9i8rEcC0ib/rdqE/dMJBJQM3Q9tyAdDyftGkYUp/Q0wH1beqaVJJMIyQ1YgKv5LhEC1iR3YrtDpkn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VU4jHlPOuGLy1FAcOkKlTDI7sHRbh4NOFVwWfWcuLeXCNk@zpZ4QLAm5N3ijEjHBqBJmZpBR0dNCnKBRN@pT34DBiwkeDm/24yiW1GSiB0mf2wPFN9wuVbDnCtBxq3BfgySpnvWQ4BMtj2uiRUmVWdxk25tskNZFRsOMZAdj/BxOyRAx22HqHBvRDD9rQgr9M1TSM1zLYZnxmDpWgR0hvqAFo@iv6NkuDrTMiJMj98TF72szfGU@3KCe7P2EfAWPXg98u2u7hkOSoWowH7bPyEZ66grbRPGOFtqLb98XYQ9onoApPfQye73O0Eurt27duKnfWCutr4n1omOfttjZs4KckHmwt00LxHGrOM@DUyWCR6qOm25q8StCqMMspus5cLCCJ5CckS1Z6mKO5JAPRdY1tmgAPUy7kH9GfX4IS9nhLJbZa7c2O1oNKO5LIPRgb4HvwqGQZEaWZayysCuY4/EmlHPTgip/PU9bWWZ15HCQHhWVxXsS2CSw2lFhi2SXA43xOHW7mbClczJO7MF76zfzK8sqmiDWNPGjnqlT3fhAl7c/c5xbDAYOrFq5hptj3ndSB036hnVJ1jPsZ3ypWyTeYvTKZmCX1/Ll8nK@fOPWotYv3JalyB0ZbFIH/FLJMKl97A0CRT2/qDfxlxugDgTC6MCfyQR86u9Qn5KRTjzA@Fy1Er8BWyCb4o3c6/yHZdqeY5xAI5hJ1SuiCPAB9GYaKDnxnUjfGChiejHLRCZFuc46NDa7WWBtVdX6crn5Zh2wHXMtVbwQqvAfJ/GOliHzRdZ6eRn3IkCG0hi9ADEswFT19epKYfWWuboiVZIvwSFCKPuFV9zfMP/hbxKhczCdglxOJeyNUMvLcOFlkopGevs0xF8nkd4kFmclk3idCTheuWs5otVmKeypM8hbSNwdEMUsB6qkaRq@MPV9zU8NJbVaFcUViYLy/h8)
Next answer must not exceed 4865 bytes.
## Explanation
Spoon is just brainfuck, but it uses stings of 1 and 0 as tokens. However, the interpreter lets you change the 0s and 1s to any other ascii characters (it sadly crashes with unicode), so for this polyglot I've set 0=z and 1=f (those letters were chosen because they play fairly well with alphuck and evil).
Since the Spoon interpreter can't handle unicode, we have to make sure Spoon is terminated before any unicode characters are encountered (or fork/fix the interpreter). Currently, it's near the end of the first line, so this shouldn't be too much of a problem.
Note that Spoon must currently be tested manually. There is an interpreter [on Github](https://github.com/MarquisdeGeek/spoon) or you can ping me in [the chat](https://chat.stackexchange.com/rooms/55553/polyglot-development) and if I'm online I can test it for you. This answer uses `spoon.exe /0z /1f polyglot` as the interpreter command.
Also, I trimmed down the evil code a bit by mixing it in to the alphuck that it was previously adjacent to. Only saved 5 characters, but may as well keep the byte count low where we can.
## Hexdump
```
00000000: 766f 6964 202f 2a2d 7b2d 2d20 2368 5221 void /*-{-- #hR!
00000010: 582d 4020 505e 687e 7e58 4040 3044 2030 X-@ P^h~~X@@0D 0
00000020: 4422 6876 2158 2d40 2050 5a68 202b 5835 D"hv!X-@ PZh +X5
00000030: 2022 4d21 4d20 656c 6946 204d 4f43 2053 "M!M eliF MOC S
00000040: 4f44 6565 7246 247d 2b2b 2b2b 5b2a 2f2f ODeerF$}++++[*//
00000050: 2f6f 7066 7a7a 667a 7a66 7a7a 667a 7a7a /opfzzfzzfzzfzzz
00000060: 667a 7a66 7a66 7a66 6666 7a66 667a 7a7a fzzfzfzfffzffzzz
00000070: 7a7a 6666 7a66 7a7a 7a66 667a 667a 7a7a zzffzfzzzffzfzzz
00000080: 667a 667a 667a 7a66 7a66 7a7a 7a66 7a66 fzfzfzzfzfzzzfzf
00000090: 7a66 7a7a 667a 667a 6666 667a 7a66 7a66 zfzzfzfzfffzzfzf
000000a0: 7a7a 7a66 7a66 6666 66e2 a086 e2a1 86e2 zzzfzffff.......
000000b0: a086 e2a1 86e2 a086 e2a1 86e2 a086 e2a1 ................
000000c0: 86e2 a086 e2a1 86e2 a086 e2a1 86e2 a086 ................
000000d0: e2a1 865c 0a20 2f2b 2023 5c0a 2062 6173 ...\. /+ #\. bas
000000e0: 656e 616d 6520 2224 2872 6561 646c 696e ename "$(readlin
000000f0: 6b20 2f70 726f 632f 2424 2f65 7865 2922 k /proc/$$/exe)"
00000100: 7c72 6576 3b3a 3c3c 2745 4f46 2720 233e |rev;:<<'EOF' #>
00000110: 3e5c 0a31 2b2f 2f2f 2020 2020 2020 2020 >\.1+///
00000120: 2020 2020 2020 2020 2020 4f5c 0a2f 2a20 O\./*
00000130: 1b67 6763 476d 6956 1b5a 5a3b 6f6f 6f22 .ggcGmiV.ZZ;ooo"
00000140: 6c6f 4722 3b3f 3d30 2553 2131 316f 6f6f loG";?=0%S!11ooo
00000150: 3c22 3e3c 3e22 0a23 6465 6669 6e65 2053 <"><>".#define S
00000160: 2243 2220 2020 2020 2020 2f2f 410a 2369 "C" //A.#i
00000170: 6664 6566 205f 5f63 706c 7573 706c 7573 fdef __cplusplus
00000180: 2f2f 6c0a 2066 2829 3b20 2020 2020 2020 //l. f();
00000190: 2020 2020 202f 2f69 0a23 696e 636c 7564 //i.#includ
000001a0: 653c 6373 7464 696f 3e2f 2f63 0a23 6465 e<cstdio>//c.#de
000001b0: 6669 6e65 2053 222b 2b43 2220 2f2f 650a fine S"++C" //e.
000001c0: 2069 6e74 2f2f 2f20 2020 2020 2020 2020 int///
000001d0: 220a 2365 6e64 6966 2f2f 2020 2020 2020 ".#endif//
000001e0: 205c 2e0a 2369 6664 6566 205f 5f4f 424a \..#ifdef __OBJ
000001f0: 435f 5f0a 2364 6566 696e 6520 5322 432d C__.#define S"C-
00000200: 6576 6974 6365 4a62 4f22 0a23 656e 6469 evitceJbO".#endi
00000210: 660a 206d 6169 6e28 297b 7072 696e 7466 f. main(){printf
00000220: 2853 292f 2a2f 6d61 696e 2829 7b69 6d70 (S)/*/main(){imp
00000230: 6f72 7420 7374 642e 7374 6469 6f3b 2244 ort std.stdio;"D
00000240: 222e 7772 6974 652f 2a2a 2f3b 7d2f 2a7d ".write/**/;}/*}
00000250: 3c0a 3e20 2076 7757 5757 5777 5757 5757 <.> vwWWWWwWWWW
00000260: 5777 7677 5757 7757 5757 7776 7757 5777 WwvwWWwWWWwvwWWw
00000270: 5757 5777 7677 5757 7757 5757 7776 7757 WWWwvwWWwWWWwvwW
00000280: 5777 5757 5777 7677 5757 7757 5757 7776 WwWWWwvwWWwWWWwv
00000290: 7757 5777 5757 5777 7657 7777 7777 7777 wWWwWWWwvWwwwwww
000002a0: 7777 7777 7757 5757 7757 5757 5757 5777 wwwwwWWWwWWWWWWw
000002b0: 5757 5757 5757 5777 5757 5757 5757 5757 WWWWWWWwWWWWWWWW
000002c0: 5777 5757 5757 5757 5757 5757 5757 7757 WwWWWWWWWWWWWWwW
000002d0: 5757 5757 5757 5757 5777 5757 5757 5757 WWWWWWWWWwWWWWWW
000002e0: 5757 5757 5757 5757 5757 5777 5757 5757 WWWWWWWWWWWwWWWW
000002f0: 5757 5757 5757 5757 5757 5757 5757 7757 WWWWWWWWWWWWWWwW
00000300: 5757 5757 5757 5757 5757 5757 5757 5757 WWWWWWWWWWWWWWWW
00000310: 5777 5757 5757 5757 5757 5757 5757 5757 WwWWWWWWWWWWWWWW
00000320: 5757 5757 5777 7757 5757 5757 5757 5757 WWWWWwwWWWWWWWWW
00000330: 5757 5757 5757 5757 5757 5777 7777 7777 WWWWWWWWWWWwwwww
00000340: 7757 5757 5757 5757 5757 5757 5757 5757 wWWWWWWWWWWWWWWW
00000350: 5757 5757 5757 7777 7777 7757 5757 5757 WWWWWWwwwwwWWWWW
00000360: 5757 5757 5757 5757 5757 5757 5757 5757 WWWWWWWWWWWWWWWW
00000370: 5777 7777 7777 7777 7777 7777 0a39 3939 Wwwwwwwwwwww.999
00000380: 2039 3939 2039 390a 3939 3920 3939 3920 999 99.999 999
00000390: 390a 3939 3976 3c3e 3030 3030 3131 3031 9.999v<>00001101
000003a0: 3130 0a76 2020 3c3e 2265 6675 6e67 652d 10.v <>"efunge-
000003b0: 3938 222c 2c2c 2c2c 2c2c 2c2c 3779 332d 98",,,,,,,,,7y3-
000003c0: 763c 2040 0a3e 2020 235e 4776 2020 2020 v< @.> #^Gv
000003d0: 2020 2020 2020 2020 2020 2020 2040 2c22 @,"
000003e0: 4222 5f22 5472 222c 2c40 0a20 2020 763c B"_"Tr",,@. v<
000003f0: 5b5f 225d 4265 6675 6e67 652d 3933 223e [_"]Befunge-93">
00000400: 2c2c 2c2c 2c2c 2c2c 2c2c 307c 403c 0a20 ,,,,,,,,,,0|@<.
00000410: 2020 3e23 3c22 4265 6675 6e67 652d 3936 >#<"Befunge-96
00000420: 223e 205e 7624 4730 3031 0a76 2020 2c2c "> ^v$G001.v ,,
00000430: 2c2c 2c22 3739 2d65 676e 7566 6542 2220 ,,,"79-egnufeB"
00000440: 5f20 2020 2020 2020 2020 2020 2020 2020 _
00000450: 2020 2076 3c0a 3e20 202c 2c2c 2c2c 4023 v<.> ,,,,,@#
00000460: 2020 2020 2020 2c22 3739 2d65 676e 7566 ,"79-egnuf
00000470: 6572 5422 5f76 2320 2447 3030 3031 3c3e erT"_v# $G0001<>
00000480: 0a20 2020 2020 2020 2020 2020 2020 2020 .
00000490: 2020 2020 2020 2020 2020 2020 2020 203c <
000004a0: 3e31 3030 3030 4724 760a 2020 2020 2023 >10000G$v. #
000004b0: 402c 2c2c 2c2c 2c2c 2c2c 2c2c 2c2c 2c40 @,,,,,,,,,,,,,,@
000004c0: 2322 3739 2d65 676e 7566 6572 6461 7551 #"79-egnuferdauQ
000004d0: 225f 3130 3030 3030 4724 760a 2020 2020 "_100000G$v.
000004e0: 2020 2020 2020 2020 2020 2020 2020 2020
000004f0: 2020 2020 2020 2020 2020 2c2c 2237 392d ,,"79-
00000500: 6567 6e75 6665 746e 6975 5122 5f31 3030 egnufetniuQ"_100
00000510: 3030 3030 4724 2176 402c 2c2c 2c2c 2c2c 0000G$!v@,,,,,,,
00000520: 2c2c 2c2c 2c0a 2020 2020 2020 2020 2020 ,,,,,.
00000530: 2020 2020 2020 2020 2020 2020 2020 2020
00000540: 2020 2020 2020 2020 2020 2020 2020 2020
00000550: 2020 2237 392d 6567 6e75 6665 7470 6553 "79-egnufetpeS
00000560: 225f 2253 6578 6566 756e 6765 2d39 3722 "_"Sexefunge-97"
00000570: 2340 2c2c 2c2c 2c2c 2c2c 2c2c 2c2c 4023 #@,,,,,,,,,,,,@#
00000580: 2c0a 2020 2020 2020 2020 2020 2020 2020 ,.
00000590: 2020 2020 2020 2020 2020 2020 2020 2020
000005a0: 203c 3e22 7622 400a 2040 2c22 4622 2c22 <>"v"@. @,"F","
000005b0: 7522 2c22 6e22 2c22 6322 2c22 7422 2c22 u","n","c","t","
000005c0: 6f22 2c22 6922 2c22 6422 3c3e 2072 6564 o","i","d"<> red
000005d0: 2064 6f77 6e20 7477 6f20 7265 6420 6c65 down two red le
000005e0: 6674 206f 6e65 2079 656c 6c6f 7720 7570 ft one yellow up
000005f0: 2067 7265 656e 2064 6f77 6e20 7965 6c6c green down yell
00000600: 6f77 2075 7020 6772 6565 6e20 646f 776e ow up green down
00000610: 2072 6564 2075 7020 7468 7265 6520 7265 red up three re
00000620: 6420 7269 6768 7420 7477 6f20 7965 6c6c d right two yell
00000630: 6f77 2064 6f77 6e20 7965 6c6c 6f77 2064 ow down yellow d
00000640: 6f77 6e20 626c 7565 206c 6566 7420 6772 own blue left gr
00000650: 6565 6e20 646f 776e 2072 6564 2064 6f77 een down red dow
00000660: 6e20 6f6e 6520 7965 6c6c 6f77 2064 6f77 n one yellow dow
00000670: 6e20 626c 7565 206c 6566 7420 6772 6565 n blue left gree
00000680: 6e20 646f 776e 2072 6564 2064 6f77 6e20 n down red down
00000690: 7477 6f20 7265 6420 6c65 6674 206f 6e65 two red left one
000006a0: 2079 656c 6c6f 7720 7570 2079 656c 6c6f yellow up yello
000006b0: 7720 646f 776e 2062 6c75 6520 6c65 6674 w down blue left
000006c0: 2067 7265 656e 2064 6f77 6e20 7265 6420 green down red
000006d0: 6c65 6674 206f 6e65 2072 6564 2064 6f77 left one red dow
000006e0: 6e20 7468 7265 6520 7965 6c6c 6f77 2064 n three yellow d
000006f0: 6f77 6e20 7965 6c6c 6f77 2064 6f77 6e20 own yellow down
00000700: 626c 7565 206c 6566 7420 6772 6565 6e20 blue left green
00000710: 646f 776e 2072 6564 2075 7020 7477 6f20 down red up two
00000720: 6772 6565 6e20 646f 776e 2079 656c 6c6f green down yello
00000730: 7720 7570 2079 656c 6c6f 7720 646f 776e w up yellow down
00000740: 2062 6c75 6520 6c65 6674 2072 6564 2075 blue left red u
00000750: 7020 7468 7265 6520 7265 6420 7269 6768 p three red righ
00000760: 7420 7477 6f20 7965 6c6c 6f77 2064 6f77 t two yellow dow
00000770: 6e20 7965 6c6c 6f77 2064 6f77 6e20 626c n yellow down bl
00000780: 7565 206c 6566 7420 3030 3031 3131 3030 ue left 00011100
00000790: 3030 3130 3030 3030 3130 3030 3130 3030 0010000010001000
000007a0: 3030 3130 3030 3030 3130 3130 3030 3030 0010000010100000
000007b0: 3130 3030 3030 3030 3030 3130 3030 3130 1000000000100010
000007c0: 3030 3130 3030 3030 3130 3030 3130 3030 0010000010001000
000007d0: 3030 3130 3030 3030 3130 3130 3030 3030 0010000010100000
000007e0: 3130 3030 3030 3130 3030 3130 3030 3030 1000001000100000
000007f0: 3130 3030 3130 3030 3130 3030 3030 3030 1000100010000000
00000800: 3030 3130 3030 3130 3030 3030 3130 3030 0010001000001000
00000810: 3130 3030 3131 3030 3030 3130 3030 3130 1000110000100010
00000820: 3030 3130 3030 3030 3130 3030 3131 3030 0010000010001100
00000830: 3030 3130 3030 3030 3130 3030 3130 3030 0010000010001000
00000840: 3030 3130 3030 3130 3030 3030 3130 3030 0010001000001000
00000850: 3030 3130 3030 3030 3130 3030 3130 3030 0010000010001000
00000860: 3030 3130 3030 3130 3030 3030 3130 3030 0010001000001000
00000870: 3130 3030 3030 3030 3030 3130 3030 3130 1000000000100010
00000880: 3030 3030 3130 3030 3130 3030 3130 3030 0000100010001000
00000890: 3030 3030 3131 3030 3030 3131 3030 3030 0000110000110000
000008a0: 3031 3130 3030 3030 3130 3031 3130 3030 0110000010011000
000008b0: 3030 3130 3030 3130 3030 3130 3030 3130 0010001000100010
000008c0: 3030 3130 3030 3030 3031 3030 3131 3031 0010000001001101
000008d0: 3131 3030 3030 3030 3131 3030 3131 3131 1100000011001111
000008e0: 3030 3031 3130 3031 3130 3030 3030 3030 0001100110000000
000008f0: 3130 3031 3131 3030 3131 3131 3030 3030 1001110011110000
00000900: 3131 3031 3131 3030 3030 3031 3030 3030 1101110000010000
00000910: 3030 3031 3030 3030 3030 3031 3030 3030 0001000000010000
00000920: 3030 3031 3030 3030 3030 3031 3030 3030 0001000000010000
00000930: 3030 3031 3030 3030 3030 3031 3030 3030 0001000000010000
00000940: 3030 3031 3030 3031 3130 3030 3131 3031 0001000110001101
00000950: 3131 3130 3030 3130 3030 3130 3030 3130 1110001000100010
00000960: 3030 3030 3130 3030 3130 3130 3030 3031 0000100010100001
00000970: 3030 3030 3030 3031 3030 3031 3030 3030 0000000100010000
00000980: 3030 3031 3030 3030 3030 3031 3030 3030 0001000000010000
00000990: 3030 3031 3030 3030 3030 3031 3030 3030 0001000000010000
000009a0: 3030 3031 3030 3030 3030 3031 3030 3030 0001000000010000
000009b0: 3030 3030 3130 3031 3130 0a2e 4c20 2020 0000100110..L
000009c0: 202e 202e 2020 2020 2020 2020 202a 2f2f . . *//
000009d0: 2f7b 7d5d e28e 9aef bca6 c2b9 6c61 6f63 /{}]........laoc
000009e0: 7261 6843 c2ab e296 b2c2 b2c2 b2c2 b2c2 rahC............
000009f0: b2c2 b2e2 8c82 e286 a8ce b1e2 86a8 c39f ................
00000a00: e286 a8c2 b2c2 b2e2 8c82 e286 a8e2 8690 ................
00000a10: c39f e289 a4e2 96bc e286 92e2 96bc e286 ................
00000a20: 90e2 89a5 e286 92e2 8c82 e286 a8cf 83e2 ................
00000a30: 8692 e286 92e2 8692 e286 a8c3 9fe2 8692 ................
00000a40: e286 92e2 8692 e286 a8cf 80e2 8692 e286 ................
00000a50: 92e2 8692 e286 92e2 8692 e286 a8c2 a1c3 ................
00000a60: 9fc2 a1e2 8692 e286 92e2 86a8 ceb4 e286 ................
00000a70: 92e2 86a8 c39f e286 92e2 8692 e286 92e2 ................
00000a80: 8692 e286 a8c2 b5e2 8692 e286 92e2 8692 ................
00000a90: e286 a8c2 a1cf 86e2 86a8 ceb5 cf80 e28c ................
00000aa0: 82e2 86a8 c2a1 c39f c2a1 e286 92e2 8692 ................
00000ab0: e286 92e2 86a8 c2a1 cf80 cf83 e296 b2e2 ................
00000ac0: 8c82 e286 a8c2 a1cf 83c2 b5c2 a1e2 8692 ................
00000ad0: e286 a8c2 a1ce b1c2 a1e2 8692 e286 a8c2 ................
00000ae0: a1cf 80c2 a1e2 96b2 e296 b2e2 96b2 c2a1 ................
00000af0: e296 b2e2 96b2 e296 b2c2 a1cf 83e2 96b2 ................
00000b00: c2a1 ceb4 c2a1 cf86 e296 b2e2 96b2 e296 ................
00000b10: b2e2 96b2 c2a1 ceb5 e296 bce2 96bc c2a1 ................
00000b20: c2bb 2b5b 2d2b 2b2b 2b5b 2d3c 2b2b 2b2b ..+[-++++[-<++++
00000b30: 2b3e 5d3c 5b2d 3c2b 2b2b 2b2b 2b3c 2b2b +>]<[-<++++++<++
00000b40: 2b2b 2b3c 2b2b 2b2b 2b3e 3e3e 5d3c 3c3c +++<+++++>>>]<<<
00000b50: 2b2b 2b2b 2b2b 2b2e 3e2d 2e3e 2d2d 2d2e +++++++.>-.>---.
00000b60: 3c3c 2d2d 2d2d 2d2e 2b2b 2b2b 2b2b 2b2b <<-----.++++++++
00000b70: 2e2d 2d2d 2d2d 2e3e 2d2d 2e3e 2d2d 2d2e .-----.>--.>---.
00000b80: 3c2b 2e3e 3e3e 5d28 2829 2829 2829 2829 <+.>>>](()()()()
00000b90: 2829 293c 3e28 2829 2829 293c 3e7b 287b ())<>(()())<>{({
00000ba0: 7d5b 2829 5d29 3c3e 287b 287b 7d29 287b }[()])<>({({})({
00000bb0: 7d5b 2829 5d29 7d7b 7d29 3c3e 7d3c 3e28 }[()])}{})<>}<>(
00000bc0: 2829 7b5b 2829 5d28 3c7b 7d28 2828 2828 (){[()](<{}(((((
00000bd0: 2828 2828 2828 2928 2928 2929 7b7d 297b (((((()()()){}){
00000be0: 7d29 7b7d 297b 7d28 2929 7b7d 2928 2828 }){}){}()){})(((
00000bf0: 2928 2928 2928 2929 7b7d 297b 7d29 5b28 )()()()){}){})[(
00000c00: 285b 5d5b 5d29 7b7d 297b 7d28 295d 2928 ([][]){}){}()])(
00000c10: 5b5d 2829 297b 7d29 5b5d 2829 2928 285b []()){})[]())(([
00000c20: 5b5d 5b5d 2829 5d28 5b5d 2829 2828 2828 [][]()]([]()((((
00000c30: 285b 5d5b 5d5b 5d29 297b 7d7b 7d29 5b5d ([][][])){}{})[]
00000c40: 297b 7d29 2929 5b5d 2829 293e 297d 7b7d ){})))[]())>)}{}
00000c50: 297b 7b7d 283c 2828 2828 2828 2828 2828 ){{}(<((((((((((
00000c60: 2828 2828 2829 2829 2829 297b 7d29 7b7d ((((()()()){}){}
00000c70: 297b 7d29 7b7d 2829 297b 7d29 2828 2829 ){}){}()){})((()
00000c80: 2829 2829 2829 297b 7d29 7b7d 295b 2828 ()()()){}){})[((
00000c90: 5b5d 5b5d 297b 7d29 7b7d 2829 5d29 285b [][]){}){}()])([
00000ca0: 5d28 2929 7b7d 295b 5d28 2929 5b5b 5d28 ]()){})[]())[[](
00000cb0: 2928 2928 295d 295b 5d29 5b5b 5d28 2928 )()()])[])[[]()(
00000cc0: 2928 2928 295d 295b 5d5b 5d5b 5d5b 2829 )()()])[][][][()
00000cd0: 5d29 2828 2828 2828 2829 2829 2829 297b ])((((((()()()){
00000ce0: 7d28 2929 7b7d 297b 7d29 7b7d 295b 2829 }()){}){}){})[()
00000cf0: 2829 5d29 3e29 7d7b 7d28 7b20 2d7d 5f3d ()])>)}{}({ -}_=
00000d00: 2229 223b 2821 293d 7365 713b 6d61 696e ")";(!)=seq;main
00000d10: 7c6c 6574 2062 215f 3d22 223d 7075 7453 |let b!_=""=putS
00000d20: 7472 2428 2222 2122 736e 7265 7474 6150 tr$(""!"snrettaP
00000d30: 676e 6142 2b22 292b 2b69 6e69 7422 6c6c gnaB+")++init"ll
00000d40: 656b 7361 4828 227b 2d0a 2f2f 4848 542d eksaH("{-.//HHT-
00000d50: 224e 5562 3460 424a 4a6e 644f 2d7d 2d2d "NUb4`BJJndO-}--
00000d60: 295b 2d5d 3c3e 5c5b 5c3c 3e5c 5c2f 3c3e )[-]<>\[\<>\\/<>
00000d70: 5c2f 5c5b 2f5c 2f5c 3c3e 3c3e 3c3e 5c5b \/\[/\/\<><><>\[
00000d80: 2f5c 2f5c 2f3c 3e5c 2f2f 5c2f 3c3e 3c3e /\/\/<>\//\/<><>
00000d90: 3c3e 3c3e 3c3e 5c5c 5d2f 5c2f 2f5c 2f2f <><><>\\]/\//\//
00000da0: 5c2f 5c5d 2f5c 2f5c 5c2e 2f5d 732a 2f2f \/\]/\/\\./]s*//
00000db0: e288 9953 4156 4e41 43ef bd90 f09f 92ac ...SAVNAC.......
00000dc0: 696a 6f6d 65f0 9f92 ace2 9ea1 f09f 98ad ijome...........
00000dd0: 456d 6f74 696e 6f6d 6963 6f6e f09f 98b2 Emotinomicon....
00000de0: e28f aae2 8fac e28f a940 2c6b 6122 3839 .........@,ka"89
00000df0: 2d65 676e 7566 656e 5573 7373 7373 6161 -egnufenUsssssaa
00000e00: 6161 6165 6565 6565 6565 6565 6570 6165 aaaeeeeeeeeeepae
00000e10: 6565 6565 6565 6565 6563 6973 6165 6565 eeeeeeeeecisaeee
00000e20: 6565 6565 6a69 6969 6969 6969 696a 6565 eeeejiiiiiiiijee
00000e30: 6565 6565 6565 6565 6565 6565 6565 6565 eeeeeeeeeeeeeeee
00000e40: 6a7a 6163 6969 6969 6969 6969 6969 6969 jzaciiiiiiiiiiii
00000e50: 696a 6565 6561 6365 6561 6365 7775 7575 ijeeeaceeacewuuu
00000e60: 7765 656a 6969 6969 6a69 6969 6969 6969 weejiiiijiiiiiii
00000e70: 6969 6969 6a65 6565 6161 6161 6b65 6561 iiiijeeeaaaakeea
00000e80: 6161 6177 7677 e2a0 80e2 a096 e2a0 97e2 aaawvw..........
00000e90: a08e e2a2 8ee2 a2a6 e2a2 a6e2 a0ae 22 .............."
```
[Answer]
# 50. Alice & Bob, 4211 bytes
```
void /*-{-- #hR!X-@ P^h~~X@@0D 0D"hv!X-@ PZh +X5 "M!M eliF MOC SODeerF$}++++-+[*///opfzzfzzfzzfzzzfzzfzfzfffzffzzzzzffzfzzzffzfzzzfzfzfzzfzfzzzfzfzfzzfzfzfffzzfzfzzzfzffff⠆⡆⠆⡆⠆⡆⠆⡆⠆⡆⠆⡆⠆⡆\
/+ #\
basename "$(readlink /proc/$$/exe)"|rev;:<<'EOF' #>>\
1+/// O\
/* ggcGmiVZZ;ooo"loG";?=0%S!11ooo<"><>"
#define S"C" //A
#ifdef __cplusplus//l
f(); //i
#include<cstdio>//c
#define S"++C" //e
int/// "
#endif// \.
#ifdef __OBJC__
#define S"C-evitceJbO"
#endif
main(){printf(S)/*/main(){import std.stdio;"D".write/**/;}/*}<
> vwWWWWwWWWWWwvwWWwWWWwvwWWwWWWwvwWWwWWWwvwWWwWWWwvwWWwWWWwvwWWwWWWwvWwwwwwwwwwwwWWWwWWWWWWwWWWWWWWwWWWWWWWWWwWWWWWWWWWWWWwWWWWWWWWWWwWWWWWWWWWWWWWWWWWwWWWWWWWWWWWWWWWWWWwWWWWWWWWWWWWWWWWWWwWWWWWWWWWWWWWWWWWWWwwWWWWWWWWWWWWWWWWWWWWwwwwwwWWWWWWWWWWWWWWWWWWWWWwwwwwWWWWWWWWWWWWWWWWWWWWWWwwwwwwwwwww
999 999 99
999 999 9
999v<>0000110110
v <>"efunge-98",,,,,,,,,7y3-v< @
> #^Gv @,"B"_"Tr",,@
v<[_"]Befunge-93">,,,,,,,,,,0|@<
>#<"Befunge-96"> ^v$G001
v ,,,,,"79-egnufeB" _ v<
> ,,,,,@# ,"79-egnuferT"_v# $G0001<>
<>10000G$v
#@,,,,,,,,,,,,,,@#"79-egnuferdauQ"_100000G$v
,,"79-egnufetniuQ"_1000000G$!v@,,,,,,,,,,,,
"79-egnufetpeS"_"Sexefunge-97"#@,,,,,,,,,,,,@#,
<>"v"@
& I8 H I d $$$
a&8g&3g4g6R9PPPPPP<
>"gnalokniM"OOOOOOOOO.
@,"F","u","n","c","t","o","i","d"<> red down two red left one yellow up green down yellow up green down red up three red right two yellow down yellow down blue left green down red down one yellow down blue left green down red down two red left one yellow up yellow down blue left green down red left one red down three yellow down yellow down blue left green down red up two green down yellow up yellow down blue left red up three red right two yellow down yellow down blue left 0001110000100000100010000010000010100000100000000010001000100000100010000010000010100000100000100010000010001000100000000010001000001000100011000010001000100000100011000010000010001000001000100000100000100000100010000010001000001000100000000010001000001000100010000000110000110000011000001001100000100010001000100010000001001101110000001100111100011001100000001001110011110000110111000001000000010000000100000001000000010000000100000001000000010001100011011110001000100010000010001010000100000001000100000001000000010000000100000001000000010000000100000000100110
01 & && &&& & {}]⎚F¹laocrahC«▲²²²²²⌂↨α↨ß↨²²⌂↨←ß≤▼→▼←≥→⌂↨σ→→→↨ß→→→↨π→→→→→↨¡ß¡→→↨δ→↨ß→→→→↨µ→→→↨¡φ↨επ⌂↨¡ß¡→→→↨¡πσ▲⌂↨¡σµ¡→↨¡α¡→↨¡π¡▲▲▲¡▲▲▲¡σ▲¡δ¡φ▲▲▲▲¡ε▼▼¡»😭Emotinomicon😲⏪⏬⏩+-+[-++++[-<+++++>]<[-<++++++<+++++<+++++>>>]>+{}[<<<<+++++++.>-.>---.<<-----.++++++++.-----.>--.>---.<+.>>->-]<+[<<+.<++++++++++++.>>+.<+++.<--.>+.--------.<++++.>+.>>{}]>]<>(()()()()())<>(()())<>{({}[()])<>({({})({}[()])}{})<>}<>((){[()](<{}<>{}{<>(((((()(((((()()()){}){}){}){}){})()(()()()()()){})[()()()])[(()()()){}])()())((((((()()()()){}){}){})(()()()){})[(()()()){}])((((()((((()()()){}){}){}){}){})()((()()()){}){})[()((()()()){}){}])<>(())}(()){{}((((((((((()()()){}){}){}){}()){})((()()()()){}){})[(([][]){}){}()])([]()){})[]())(([[][]()]([]()((((([][][])){}{})[]){})))[]())<>}<>>)}{}){{}(<((((((((((((((()()()){}){}){}){}()){})((()()()()){}){})[(([][]){}){}()])([]()){})[]())[[]()()()])[])[[]()()()()])[][][][()])((((((()()()){}()){}){}){})[()()])>)}{}({ -}_=")+;;+;+;+;+;;+;+;;+;;;+;;+;+;+;+;+;+;;;+;;+;;+;;+;;+;;;+;;+;+;;+;+";x--?y
=y;y="yrruC";(!)=seq;main=let b!_=""in putStr$(""!"snrettaPgnaB+")++y--?"lleksaH"
--N'Zi(Tji8=@/BmU2)[-]<>\[\<>\\/<>\/\[/\/\<><><>\[/\/\/<>\//\/<><><><><>\\]/\//\//\/\]/\/\\./]s*///∙SAVNACp💬ijome💬➡@,ka"89-egnufenUsssssaaaaaeeeeeeeeeepaeeeeeeeeeecisaeeeeeeejiiiiiiiijeeeeeeeeeeeeeeeeeejzaciiiiiiiiiiiiijeeeaceeacewuuuweejiiiijiiiiiiiiiiijeeeaaaakeeaaaawvw;+;;+;+;;;;+;+;;+;;+;+;;;+;;+;⠀⠖⠗⠎⢎⢦⢦⠮"
```
Prints:
* `D` in D
* `emmoS` in Somme
* `><>` in ><>
* `C` in C
* `laocrahC` in Charcoal
* `miV` in Vim
* `C-evitceJbO` in ObJective-C
* `89-egnufeB` in Befunge-98
* `39-egnufeB` in Befunge-93
* `eliF MOC SODeerF` in FreeDOS COM file
* `><>loG` in Gol><>
* `89-egnufenU` in Unefunge-98
* `79-egnufeB` in Befunge-97
* `69-egnufeB` in Befunge-96
* `kcufniarb` in brainfuck
* `89-egnuferT` in Trefunge-98
* `kalf-niarb` in brain-flak
* `hsab` in bash
* `lleksaH` in Haskell
* `hsz` in zsh
* `ijome` in emoji
* `snrettaPgnaB+lleksaH` in Haskell+BangPatterns
* `++C` in C++
* `nocimonitomE` in Emotinomicon
* `hsk` in ksh
* `hsad` in dash
* `79-egnuferT` in Trefunge-97
* `ecilA` in Alice
* `79-egnuferdauQ` in Quadrefunge-97
* `99` in 99
* `79-egnufetniuQ` in Quintefunge-97
* `kcufniarb cilobmys` in symbolic brainfuck
* `79-egnufexeS` in Sexefunge-97
* `senots` in stones
* `79-egnufetpeS` in Septefunge-97
* `diotcnuF` in Functoid
* `ssarG` in Grass
* `kcuhpla` in alphuck
* `SAVNAC` in CANVAS
* `egaugnal sseleman` in nameless language
* `LIve` in evil
* `V` in V
* `elliarb` in braille
* `68xalfniarb` in BrainFlaX86
* `NOOPS` in Spoon
* `yrruC` in Curry
* `gnalokniM` in Minkolang
* `epyhniarb` in Brainhype
* `kcufloob` in boolfuck
* `bob & ecila` in Alice & Bob
[Try it online!](https://tio.run/##rTvbctvIlc/CL@SlDWlEQCQIUbJliSIZ3W3P2pZieWyvKZoBgSYJCQQYXEjRGk1NbaqmNlVbmak8zF4edma2dlN7SbYqU5mHrc2@OO@Zf9APJH/gPae7ceFFtmcSSAS6z71Pn76cJtgygu7r1/Nk27KIQWjHiDqucZ@EHtT6njPqOF5IQhqEpGv4Lg0C0hqRhzbde0lPz7yWNE92Pccx@gEl8q5nUZkYrkXkbb8T9agbBjIJqBnanhuQtueTFg1D6hN63qe@TV2TSpJphKRGTOCVHJdoASuyW7HVJvNkh7Yjt0O1jdUpfO/MAYIHtnvmOYbbkUIvMruk79ugWALT7DYZeRExsG2xQQXSM84oCSKfYit7nmW3RwQsLPZHJPBI2AV7wi4dAQsltms6kUUtKCCQOKBLombXI5pL5IWSDKZz3gx0BaGWF4xDVxEaeL0e1dr2@TjuJuKeFPtGaHYlqT8Ku567Opv4jm8EQVkKfaKZFhk@HZAK8x3isc2m1@vbDoXuY02zwfYB9QPoAeK1yY5v2O5dwzwjCiseOMaz9TVCfxLZA8MB/6hSq4WItmMAjUouJEJ6Z5YNXReDtZYXueATwJh9onv9UGe4LojVl4rdYDapNRMcgH2aTXKBfqLUXxjay23teeNEveeGtEN9/aQEpdUVvZ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qaZqGb8V9V/NTQ0mtVkVxRaKgvP8H)
Next answer must not exceed 5474 bytes.
## Explanation
*Alice & Bob* is very similar to Brain-Flak, but instead of [left and right](https://chat.stackexchange.com/transcript/240?m=45963981#45963981) stacks it has Alice's stack and Bob's queue. When Bob's queue is active loops (ie. `{code}`) get executed if zero is the top of the stack which is a good way to distinguish these.
I ended up with the following code:
```
<>
{ switch to bob who loops on zero; thus Brain-Flak won't execute but Alice & Bob will
<> switch back to stack
PUSH "bob & ecila"
<>(()) switch to queue and push 1 to terminate loop
}
(()) push 1, st. Brain-Flak executes the loop, but Alice & Bob won't since we're on the queue
{
{} pop the 1
PUSH "kalf-niarb"
<> switch stacks to terminate loop
}
<> switch to stack for both
```
[Try it with Brain-Flak](https://tio.run/##dZJNTsMwEIX3PsVb0UZqkbqmqlQWXCLywgkusWriENsKEPXsYezU1KUljuTJmz/lm6l6odpG1Mdp2u7YCMAOytUNnEFlKgyNgTamszAtvmVvnuAab/Ec8tYvWhwxmHbhID9l7Z1E5R32WtUSD3gOBZTWDNtdqltRr1DcOjJWEFqbQbVv@DI@yKJ2EBbqAOUWeRuGZXyKdNEpxtPVG5xFOkEoZ5OT8Svy2VhmdfJKyzw7T7o0/7f3laf8q/AicCCpyBh/eOklRPuKztsGm6A52b@rVhDMQJ6dWMyZ/SsC95jTP3O3NJY5fnU7gjggq1pSBrnoZZhlCI/N2cgwnoDOdFHcJNL3/3X@uiFHrEpe8hRDvEp@psgj7TK4yRH1WDoIlEExMSrEFnN03JcEKS6KvcvlslVpoXAwPe2ta6ZpWu9/AA "Brain-Flak (BrainHack) – Try It Online") or [try it with Alice & Bob!](https://tio.run/##dZJNTsMwEIX3PsVb0UZqkbqmqkQXXCLywgkusWriENsKEPXsYezU1KUljuTJmz/lmxFa1XJdmWqatjs2ArCDcnUDZ0AqhsZAG9NZmBbfsjdPcI232PdCtesXLY4YTLtwkJ@y9k6i8g7PoSgesA8FlNYM212qW4n6GIpbR8YKQmszqPYNX8YHWdQOwkIdoNwib8OwjE@RLjrFeLp6g7NIJwjlbHIyfkU@G8usTl5pmWfnSZfm//a@8pR/FV4EDiQVGeMPL72EaF/RedtgEzQn@3fVCoIZyLMTizmzf0XgHnP6Z@6WxjLHr25HEAdkVUvKIBe9DLMM4bE5GxnGE9CZLoqbRPr@v85fN@SIVclLnmKIV8nPFHmkXQY3OaIeSweBMigmRoXYYo6O@5IgxUWxd7lctiotFA6mp711zTRNa/ED "Alice & Bob – Try It Online")
## Hexdump
```
00000000: 766f 6964 202f 2a2d 7b2d 2d20 2368 5221 void /*-{-- #hR!
00000010: 582d 4020 505e 687e 7e58 4040 3044 2030 X-@ P^h~~X@@0D 0
00000020: 4422 6876 2158 2d40 2050 5a68 202b 5835 D"hv!X-@ PZh +X5
00000030: 2022 4d21 4d20 656c 6946 204d 4f43 2053 "M!M eliF MOC S
00000040: 4f44 6565 7246 247d 2b2b 2b2b 2d2b 5b2a ODeerF$}++++-+[*
00000050: 2f2f 2f6f 7066 7a7a 667a 7a66 7a7a 667a ///opfzzfzzfzzfz
00000060: 7a7a 667a 7a66 7a66 7a66 6666 7a66 667a zzfzzfzfzfffzffz
00000070: 7a7a 7a7a 6666 7a66 7a7a 7a66 667a 667a zzzzffzfzzzffzfz
00000080: 7a7a 667a 667a 667a 7a66 7a66 7a7a 7a66 zzfzfzfzzfzfzzzf
00000090: 7a66 7a66 7a7a 667a 667a 6666 667a 7a66 zfzfzzfzfzfffzzf
000000a0: 7a66 7a7a 7a66 7a66 6666 66e2 a086 e2a1 zfzzzfzffff.....
000000b0: 86e2 a086 e2a1 86e2 a086 e2a1 86e2 a086 ................
000000c0: e2a1 86e2 a086 e2a1 86e2 a086 e2a1 86e2 ................
000000d0: a086 e2a1 865c 0a20 2f2b 2023 5c0a 2062 .....\. /+ #\. b
000000e0: 6173 656e 616d 6520 2224 2872 6561 646c asename "$(readl
000000f0: 696e 6b20 2f70 726f 632f 2424 2f65 7865 ink /proc/$$/exe
00000100: 2922 7c72 6576 3b3a 3c3c 2745 4f46 2720 )"|rev;:<<'EOF'
00000110: 233e 3e5c 0a31 2b2f 2f2f 2020 2020 2020 #>>\.1+///
00000120: 2020 2020 2020 2020 2020 2020 4f5c 0a2f O\./
00000130: 2a20 1b67 6763 476d 6956 1b5a 5a3b 6f6f * .ggcGmiV.ZZ;oo
00000140: 6f22 6c6f 4722 3b3f 3d30 2553 2131 316f o"loG";?=0%S!11o
00000150: 6f6f 3c22 3e3c 3e22 0a23 6465 6669 6e65 oo<"><>".#define
00000160: 2053 2243 2220 2020 2020 2020 2f2f 410a S"C" //A.
00000170: 2369 6664 6566 205f 5f63 706c 7573 706c #ifdef __cpluspl
00000180: 7573 2f2f 6c0a 2066 2829 3b20 2020 2020 us//l. f();
00000190: 2020 2020 2020 202f 2f69 0a23 696e 636c //i.#incl
000001a0: 7564 653c 6373 7464 696f 3e2f 2f63 0a23 ude<cstdio>//c.#
000001b0: 6465 6669 6e65 2053 222b 2b43 2220 2f2f define S"++C" //
000001c0: 650a 2069 6e74 2f2f 2f20 2020 2020 2020 e. int///
000001d0: 2020 220a 2365 6e64 6966 2f2f 2020 2020 ".#endif//
000001e0: 2020 205c 2e0a 2369 6664 6566 205f 5f4f \..#ifdef __O
000001f0: 424a 435f 5f0a 2364 6566 696e 6520 5322 BJC__.#define S"
00000200: 432d 6576 6974 6365 4a62 4f22 0a23 656e C-evitceJbO".#en
00000210: 6469 660a 206d 6169 6e28 297b 7072 696e dif. main(){prin
00000220: 7466 2853 292f 2a2f 6d61 696e 2829 7b69 tf(S)/*/main(){i
00000230: 6d70 6f72 7420 7374 642e 7374 6469 6f3b mport std.stdio;
00000240: 2244 222e 7772 6974 652f 2a2a 2f3b 7d2f "D".write/**/;}/
00000250: 2a7d 3c0a 3e20 2076 7757 5757 5777 5757 *}<.> vwWWWWwWW
00000260: 5757 5777 7677 5757 7757 5757 7776 7757 WWWwvwWWwWWWwvwW
00000270: 5777 5757 5777 7677 5757 7757 5757 7776 WwWWWwvwWWwWWWwv
00000280: 7757 5777 5757 5777 7677 5757 7757 5757 wWWwWWWwvwWWwWWW
00000290: 7776 7757 5777 5757 5777 7657 7777 7777 wvwWWwWWWwvWwwww
000002a0: 7777 7777 7777 7757 5757 7757 5757 5757 wwwwwwwWWWwWWWWW
000002b0: 5777 5757 5757 5757 5777 5757 5757 5757 WwWWWWWWWwWWWWWW
000002c0: 5757 5777 5757 5757 5757 5757 5757 5757 WWWwWWWWWWWWWWWW
000002d0: 7757 5757 5757 5757 5757 5777 5757 5757 wWWWWWWWWWWwWWWW
000002e0: 5757 5757 5757 5757 5757 5757 5777 5757 WWWWWWWWWWWWWwWW
000002f0: 5757 5757 5757 5757 5757 5757 5757 5757 WWWWWWWWWWWWWWWW
00000300: 7757 5757 5757 5757 5757 5757 5757 5757 wWWWWWWWWWWWWWWW
00000310: 5757 5777 5757 5757 5757 5757 5757 5757 WWWwWWWWWWWWWWWW
00000320: 5757 5757 5757 5777 7757 5757 5757 5757 WWWWWWWwwWWWWWWW
00000330: 5757 5757 5757 5757 5757 5757 5777 7777 WWWWWWWWWWWWWwww
00000340: 7777 7757 5757 5757 5757 5757 5757 5757 wwwWWWWWWWWWWWWW
00000350: 5757 5757 5757 5757 7777 7777 7757 5757 WWWWWWWWwwwwwWWW
00000360: 5757 5757 5757 5757 5757 5757 5757 5757 WWWWWWWWWWWWWWWW
00000370: 5757 5777 7777 7777 7777 7777 7777 0a39 WWWwwwwwwwwwww.9
00000380: 3939 2039 3939 2039 390a 3939 3920 3939 99 999 99.999 99
00000390: 3920 390a 3939 3976 3c3e 3030 3030 3131 9 9.999v<>000011
000003a0: 3031 3130 0a76 2020 3c3e 2265 6675 6e67 0110.v <>"efung
000003b0: 652d 3938 222c 2c2c 2c2c 2c2c 2c2c 3779 e-98",,,,,,,,,7y
000003c0: 332d 763c 2040 0a3e 2020 235e 4776 2020 3-v< @.> #^Gv
000003d0: 2020 2020 2020 2020 2020 2020 2020 2040 @
000003e0: 2c22 4222 5f22 5472 222c 2c40 0a20 2020 ,"B"_"Tr",,@.
000003f0: 763c 5b5f 225d 4265 6675 6e67 652d 3933 v<[_"]Befunge-93
00000400: 223e 2c2c 2c2c 2c2c 2c2c 2c2c 307c 403c ">,,,,,,,,,,0|@<
00000410: 0a20 2020 3e23 3c22 4265 6675 6e67 652d . >#<"Befunge-
00000420: 3936 223e 205e 7624 4730 3031 0a76 2020 96"> ^v$G001.v
00000430: 2c2c 2c2c 2c22 3739 2d65 676e 7566 6542 ,,,,,"79-egnufeB
00000440: 2220 5f20 2020 2020 2020 2020 2020 2020 " _
00000450: 2020 2020 2076 3c0a 3e20 202c 2c2c 2c2c v<.> ,,,,,
00000460: 4023 2020 2020 2020 2c22 3739 2d65 676e @# ,"79-egn
00000470: 7566 6572 5422 5f76 2320 2447 3030 3031 uferT"_v# $G0001
00000480: 3c3e 0a20 2020 2020 2020 2020 2020 2020 <>.
00000490: 2020 2020 2020 2020 2020 2020 2020 2020
000004a0: 203c 3e31 3030 3030 4724 760a 2020 2020 <>10000G$v.
000004b0: 2023 402c 2c2c 2c2c 2c2c 2c2c 2c2c 2c2c #@,,,,,,,,,,,,,
000004c0: 2c40 2322 3739 2d65 676e 7566 6572 6461 ,@#"79-egnuferda
000004d0: 7551 225f 3130 3030 3030 4724 760a 2020 uQ"_100000G$v.
000004e0: 2020 2020 2020 2020 2020 2020 2020 2020
000004f0: 2020 2020 2020 2020 2020 2020 2c2c 2237 ,,"7
00000500: 392d 6567 6e75 6665 746e 6975 5122 5f31 9-egnufetniuQ"_1
00000510: 3030 3030 3030 4724 2176 402c 2c2c 2c2c 000000G$!v@,,,,,
00000520: 2c2c 2c2c 2c2c 2c0a 2020 2020 2020 2020 ,,,,,,,.
00000530: 2020 2020 2020 2020 2020 2020 2020 2020
00000540: 2020 2020 2020 2020 2020 2020 2020 2020
00000550: 2020 2020 2237 392d 6567 6e75 6665 7470 "79-egnufetp
00000560: 6553 225f 2253 6578 6566 756e 6765 2d39 eS"_"Sexefunge-9
00000570: 3722 2340 2c2c 2c2c 2c2c 2c2c 2c2c 2c2c 7"#@,,,,,,,,,,,,
00000580: 4023 2c0a 2020 2020 2020 2020 2020 2020 @#,.
00000590: 2020 2020 2020 2020 2020 2020 2020 2020
000005a0: 2020 203c 3e22 7622 400a 2026 2049 3820 <>"v"@. & I8
000005b0: 4820 4920 2064 2020 2020 2020 2424 240a H I d $$$.
000005c0: 6126 3867 2633 6734 6736 5239 5050 5050 a&8g&3g4g6R9PPPP
000005d0: 5050 3c0a 3e22 676e 616c 6f6b 6e69 4d22 PP<.>"gnalokniM"
000005e0: 4f4f 4f4f 4f4f 4f4f 4f2e 0a20 402c 2246 OOOOOOOOO.. @,"F
000005f0: 222c 2275 222c 226e 222c 2263 222c 2274 ","u","n","c","t
00000600: 222c 226f 222c 2269 222c 2264 223c 3e20 ","o","i","d"<>
00000610: 7265 6420 646f 776e 2074 776f 2072 6564 red down two red
00000620: 206c 6566 7420 6f6e 6520 7965 6c6c 6f77 left one yellow
00000630: 2075 7020 6772 6565 6e20 646f 776e 2079 up green down y
00000640: 656c 6c6f 7720 7570 2067 7265 656e 2064 ellow up green d
00000650: 6f77 6e20 7265 6420 7570 2074 6872 6565 own red up three
00000660: 2072 6564 2072 6967 6874 2074 776f 2079 red right two y
00000670: 656c 6c6f 7720 646f 776e 2079 656c 6c6f ellow down yello
00000680: 7720 646f 776e 2062 6c75 6520 6c65 6674 w down blue left
00000690: 2067 7265 656e 2064 6f77 6e20 7265 6420 green down red
000006a0: 646f 776e 206f 6e65 2079 656c 6c6f 7720 down one yellow
000006b0: 646f 776e 2062 6c75 6520 6c65 6674 2067 down blue left g
000006c0: 7265 656e 2064 6f77 6e20 7265 6420 646f reen down red do
000006d0: 776e 2074 776f 2072 6564 206c 6566 7420 wn two red left
000006e0: 6f6e 6520 7965 6c6c 6f77 2075 7020 7965 one yellow up ye
000006f0: 6c6c 6f77 2064 6f77 6e20 626c 7565 206c llow down blue l
00000700: 6566 7420 6772 6565 6e20 646f 776e 2072 eft green down r
00000710: 6564 206c 6566 7420 6f6e 6520 7265 6420 ed left one red
00000720: 646f 776e 2074 6872 6565 2079 656c 6c6f down three yello
00000730: 7720 646f 776e 2079 656c 6c6f 7720 646f w down yellow do
00000740: 776e 2062 6c75 6520 6c65 6674 2067 7265 wn blue left gre
00000750: 656e 2064 6f77 6e20 7265 6420 7570 2074 en down red up t
00000760: 776f 2067 7265 656e 2064 6f77 6e20 7965 wo green down ye
00000770: 6c6c 6f77 2075 7020 7965 6c6c 6f77 2064 llow up yellow d
00000780: 6f77 6e20 626c 7565 206c 6566 7420 7265 own blue left re
00000790: 6420 7570 2074 6872 6565 2072 6564 2072 d up three red r
000007a0: 6967 6874 2074 776f 2079 656c 6c6f 7720 ight two yellow
000007b0: 646f 776e 2079 656c 6c6f 7720 646f 776e down yellow down
000007c0: 2062 6c75 6520 6c65 6674 2030 3030 3131 blue left 00011
000007d0: 3130 3030 3031 3030 3030 3031 3030 3031 1000010000010001
000007e0: 3030 3030 3031 3030 3030 3031 3031 3030 0000010000010100
000007f0: 3030 3031 3030 3030 3030 3030 3031 3030 0001000000000100
00000800: 3031 3030 3031 3030 3030 3031 3030 3031 0100010000010001
00000810: 3030 3030 3031 3030 3030 3031 3031 3030 0000010000010100
00000820: 3030 3031 3030 3030 3031 3030 3031 3030 0001000001000100
00000830: 3030 3031 3030 3031 3030 3031 3030 3030 0001000100010000
00000840: 3030 3030 3031 3030 3031 3030 3030 3031 0000010001000001
00000850: 3030 3031 3030 3031 3130 3030 3031 3030 0001000110000100
00000860: 3031 3030 3031 3030 3030 3031 3030 3031 0100010000010001
00000870: 3130 3030 3031 3030 3030 3031 3030 3031 1000010000010001
00000880: 3030 3030 3031 3030 3031 3030 3030 3031 0000010001000001
00000890: 3030 3030 3031 3030 3030 3031 3030 3031 0000010000010001
000008a0: 3030 3030 3031 3030 3031 3030 3030 3031 0000010001000001
000008b0: 3030 3031 3030 3030 3030 3030 3031 3030 0001000000000100
000008c0: 3031 3030 3030 3031 3030 3031 3030 3031 0100000100010001
000008d0: 3030 3030 3030 3031 3130 3030 3031 3130 0000000110000110
000008e0: 3030 3030 3131 3030 3030 3031 3030 3131 0000110000010011
000008f0: 3030 3030 3031 3030 3031 3030 3031 3030 0000010001000100
00000900: 3031 3030 3031 3030 3030 3030 3130 3031 0100010000001001
00000910: 3130 3131 3130 3030 3030 3031 3130 3031 1011100000011001
00000920: 3131 3130 3030 3131 3030 3131 3030 3030 1110001100110000
00000930: 3030 3031 3030 3131 3130 3031 3131 3130 0001001110011110
00000940: 3030 3031 3130 3131 3130 3030 3030 3130 0001101110000010
00000950: 3030 3030 3030 3130 3030 3030 3030 3130 0000001000000010
00000960: 3030 3030 3030 3130 3030 3030 3030 3130 0000001000000010
00000970: 3030 3030 3030 3130 3030 3030 3030 3130 0000001000000010
00000980: 3030 3030 3030 3130 3030 3131 3030 3031 0000001000110001
00000990: 3130 3131 3131 3030 3031 3030 3031 3030 1011110001000100
000009a0: 3031 3030 3030 3031 3030 3031 3031 3030 0100000100010100
000009b0: 3030 3130 3030 3030 3030 3130 3030 3130 0010000000100010
000009c0: 3030 3030 3030 3130 3030 3030 3030 3130 0000001000000010
000009d0: 3030 3030 3030 3130 3030 3030 3030 3130 0000001000000010
000009e0: 3030 3030 3030 3130 3030 3030 3030 3130 0000001000000010
000009f0: 3030 3030 3030 3031 3030 3131 300a 3031 0000000100110.01
00000a00: 2026 2026 2620 2626 2620 2020 2020 2620 & && &&& &
00000a10: 7b7d 5de2 8e9a efbc a6c2 b96c 616f 6372 {}]........laocr
00000a20: 6168 43c2 abe2 96b2 c2b2 c2b2 c2b2 c2b2 ahC.............
00000a30: c2b2 e28c 82e2 86a8 ceb1 e286 a8c3 9fe2 ................
00000a40: 86a8 c2b2 c2b2 e28c 82e2 86a8 e286 90c3 ................
00000a50: 9fe2 89a4 e296 bce2 8692 e296 bce2 8690 ................
00000a60: e289 a5e2 8692 e28c 82e2 86a8 cf83 e286 ................
00000a70: 92e2 8692 e286 92e2 86a8 c39f e286 92e2 ................
00000a80: 8692 e286 92e2 86a8 cf80 e286 92e2 8692 ................
00000a90: e286 92e2 8692 e286 92e2 86a8 c2a1 c39f ................
00000aa0: c2a1 e286 92e2 8692 e286 a8ce b4e2 8692 ................
00000ab0: e286 a8c3 9fe2 8692 e286 92e2 8692 e286 ................
00000ac0: 92e2 86a8 c2b5 e286 92e2 8692 e286 92e2 ................
00000ad0: 86a8 c2a1 cf86 e286 a8ce b5cf 80e2 8c82 ................
00000ae0: e286 a8c2 a1c3 9fc2 a1e2 8692 e286 92e2 ................
00000af0: 8692 e286 a8c2 a1cf 80cf 83e2 96b2 e28c ................
00000b00: 82e2 86a8 c2a1 cf83 c2b5 c2a1 e286 92e2 ................
00000b10: 86a8 c2a1 ceb1 c2a1 e286 92e2 86a8 c2a1 ................
00000b20: cf80 c2a1 e296 b2e2 96b2 e296 b2c2 a1e2 ................
00000b30: 96b2 e296 b2e2 96b2 c2a1 cf83 e296 b2c2 ................
00000b40: a1ce b4c2 a1cf 86e2 96b2 e296 b2e2 96b2 ................
00000b50: e296 b2c2 a1ce b5e2 96bc e296 bcc2 a1c2 ................
00000b60: bbf0 9f98 ad45 6d6f 7469 6e6f 6d69 636f .....Emotinomico
00000b70: 6ef0 9f98 b2e2 8faa e28f ace2 8fa9 2b2d n.............+-
00000b80: 2b5b 2d2b 2b2b 2b5b 2d3c 2b2b 2b2b 2b3e +[-++++[-<+++++>
00000b90: 5d3c 5b2d 3c2b 2b2b 2b2b 2b3c 2b2b 2b2b ]<[-<++++++<++++
00000ba0: 2b3c 2b2b 2b2b 2b3e 3e3e 5d3e 2b7b 7d5b +<+++++>>>]>+{}[
00000bb0: 3c3c 3c3c 2b2b 2b2b 2b2b 2b2e 3e2d 2e3e <<<<+++++++.>-.>
00000bc0: 2d2d 2d2e 3c3c 2d2d 2d2d 2d2e 2b2b 2b2b ---.<<-----.++++
00000bd0: 2b2b 2b2b 2e2d 2d2d 2d2d 2e3e 2d2d 2e3e ++++.-----.>--.>
00000be0: 2d2d 2d2e 3c2b 2e3e 3e2d 3e2d 5d3c 2b5b ---.<+.>>->-]<+[
00000bf0: 3c3c 2b2e 3c2b 2b2b 2b2b 2b2b 2b2b 2b2b <<+.<+++++++++++
00000c00: 2b2e 3e3e 2b2e 3c2b 2b2b 2e3c 2d2d 2e3e +.>>+.<+++.<--.>
00000c10: 2b2e 2d2d 2d2d 2d2d 2d2d 2e3c 2b2b 2b2b +.--------.<++++
00000c20: 2e3e 2b2e 3e3e 7b7d 5d3e 5d3c 3e28 2829 .>+.>>{}]>]<>(()
00000c30: 2829 2829 2829 2829 293c 3e28 2829 2829 ()()()())<>(()()
00000c40: 293c 3e7b 287b 7d5b 2829 5d29 3c3e 287b )<>{({}[()])<>({
00000c50: 287b 7d29 287b 7d5b 2829 5d29 7d7b 7d29 ({})({}[()])}{})
00000c60: 3c3e 7d3c 3e28 2829 7b5b 2829 5d28 3c7b <>}<>((){[()](<{
00000c70: 7d3c 3e7b 7d7b 3c3e 2828 2828 2828 2928 }<>{}{<>(((((()(
00000c80: 2828 2828 2829 2829 2829 297b 7d29 7b7d ((((()()()){}){}
00000c90: 297b 7d29 7b7d 297b 7d29 2829 2828 2928 ){}){}){})()(()(
00000ca0: 2928 2928 2928 2929 7b7d 295b 2829 2829 )()()()){})[()()
00000cb0: 2829 5d29 5b28 2829 2829 2829 297b 7d5d ()])[(()()()){}]
00000cc0: 2928 2928 2929 2828 2828 2828 2829 2829 )()())((((((()()
00000cd0: 2829 2829 297b 7d29 7b7d 297b 7d29 2828 ()()){}){}){})((
00000ce0: 2928 2928 2929 7b7d 295b 2828 2928 2928 )()()){})[(()()(
00000cf0: 2929 7b7d 5d29 2828 2828 2829 2828 2828 )){}])((((()((((
00000d00: 2829 2829 2829 297b 7d29 7b7d 297b 7d29 ()()()){}){}){})
00000d10: 7b7d 297b 7d29 2829 2828 2829 2829 2829 {}){})()((()()()
00000d20: 297b 7d29 7b7d 295b 2829 2828 2829 2829 ){}){})[()((()()
00000d30: 2829 297b 7d29 7b7d 5d29 3c3e 2828 2929 ()){}){}])<>(())
00000d40: 7d28 2829 297b 7b7d 2828 2828 2828 2828 }(()){{}((((((((
00000d50: 2828 2829 2829 2829 297b 7d29 7b7d 297b ((()()()){}){}){
00000d60: 7d29 7b7d 2829 297b 7d29 2828 2829 2829 }){}()){})((()()
00000d70: 2829 2829 297b 7d29 7b7d 295b 2828 5b5d ()()){}){})[(([]
00000d80: 5b5d 297b 7d29 7b7d 2829 5d29 285b 5d28 []){}){}()])([](
00000d90: 2929 7b7d 295b 5d28 2929 2828 5b5b 5d5b )){})[]())(([[][
00000da0: 5d28 295d 285b 5d28 2928 2828 2828 5b5d ]()]([]()((((([]
00000db0: 5b5d 5b5d 2929 7b7d 7b7d 295b 5d29 7b7d [][])){}{})[]){}
00000dc0: 2929 295b 5d28 2929 3c3e 7d3c 3e3e 297d )))[]())<>}<>>)}
00000dd0: 7b7d 297b 7b7d 283c 2828 2828 2828 2828 {}){{}(<((((((((
00000de0: 2828 2828 2828 2829 2829 2829 297b 7d29 ((((((()()()){})
00000df0: 7b7d 297b 7d29 7b7d 2829 297b 7d29 2828 {}){}){}()){})((
00000e00: 2829 2829 2829 2829 297b 7d29 7b7d 295b ()()()()){}){})[
00000e10: 2828 5b5d 5b5d 297b 7d29 7b7d 2829 5d29 (([][]){}){}()])
00000e20: 285b 5d28 2929 7b7d 295b 5d28 2929 5b5b ([]()){})[]())[[
00000e30: 5d28 2928 2928 295d 295b 5d29 5b5b 5d28 ]()()()])[])[[](
00000e40: 2928 2928 2928 295d 295b 5d5b 5d5b 5d5b )()()()])[][][][
00000e50: 2829 5d29 2828 2828 2828 2829 2829 2829 ()])((((((()()()
00000e60: 297b 7d28 2929 7b7d 297b 7d29 7b7d 295b ){}()){}){}){})[
00000e70: 2829 2829 5d29 3e29 7d7b 7d28 7b20 2d7d ()()])>)}{}({ -}
00000e80: 5f3d 2229 2b3b 3b2b 3b2b 3b2b 3b2b 3b3b _=")+;;+;+;+;+;;
00000e90: 2b3b 2b3b 3b2b 3b3b 3b2b 3b3b 2b3b 2b3b +;+;;+;;;+;;+;+;
00000ea0: 2b3b 2b3b 2b3b 2b3b 3b3b 2b3b 3b2b 3b3b +;+;+;+;;;+;;+;;
00000eb0: 2b3b 3b2b 3b3b 2b3b 3b3b 2b3b 3b2b 3b2b +;;+;;+;;;+;;+;+
00000ec0: 3b3b 2b3b 2b22 3b78 2d2d 3f79 0a20 3d79 ;;+;+";x--?y. =y
00000ed0: 3b79 3d22 7972 7275 4322 3b28 2129 3d73 ;y="yrruC";(!)=s
00000ee0: 6571 3b6d 6169 6e3d 6c65 7420 6221 5f3d eq;main=let b!_=
00000ef0: 2222 696e 2070 7574 5374 7224 2822 2221 ""in putStr$(""!
00000f00: 2273 6e72 6574 7461 5067 6e61 422b 2229 "snrettaPgnaB+")
00000f10: 2b2b 792d 2d3f 226c 6c65 6b73 6148 220a ++y--?"lleksaH".
00000f20: 2d2d 4e27 5a69 2854 6a69 383d 402f 426d --N'Zi(Tji8=@/Bm
00000f30: 5532 295b 2d5d 3c3e 5c5b 5c3c 3e5c 5c2f U2)[-]<>\[\<>\\/
00000f40: 3c3e 5c2f 5c5b 2f5c 2f5c 3c3e 3c3e 3c3e <>\/\[/\/\<><><>
00000f50: 5c5b 2f5c 2f5c 2f3c 3e5c 2f2f 5c2f 3c3e \[/\/\/<>\//\/<>
00000f60: 3c3e 3c3e 3c3e 3c3e 5c5c 5d2f 5c2f 2f5c <><><><>\\]/\//\
00000f70: 2f2f 5c2f 5c5d 2f5c 2f5c 5c2e 2f5d 732a //\/\]/\/\\./]s*
00000f80: 2f2f 2fe2 8899 5341 564e 4143 efbd 90f0 ///...SAVNAC....
00000f90: 9f92 ac69 6a6f 6d65 f09f 92ac e29e a140 ...ijome.......@
00000fa0: 2c6b 6122 3839 2d65 676e 7566 656e 5573 ,ka"89-egnufenUs
00000fb0: 7373 7373 6161 6161 6165 6565 6565 6565 ssssaaaaaeeeeeee
00000fc0: 6565 6570 6165 6565 6565 6565 6565 6563 eeepaeeeeeeeeeec
00000fd0: 6973 6165 6565 6565 6565 6a69 6969 6969 isaeeeeeeejiiiii
00000fe0: 6969 696a 6565 6565 6565 6565 6565 6565 iiijeeeeeeeeeeee
00000ff0: 6565 6565 6565 6a7a 6163 6969 6969 6969 eeeeeejzaciiiiii
00001000: 6969 6969 6969 696a 6565 6561 6365 6561 iiiiiiijeeeaceea
00001010: 6365 7775 7575 7765 656a 6969 6969 6a69 cewuuuweejiiiiji
00001020: 6969 6969 6969 6969 6969 6a65 6565 6161 iiiiiiiiiijeeeaa
00001030: 6161 6b65 6561 6161 6177 7677 3b2b 3b3b aakeeaaaawvw;+;;
00001040: 2b3b 2b3b 3b3b 3b2b 3b2b 3b3b 2b3b 3b2b +;+;;;;+;+;;+;;+
00001050: 3b2b 3b3b 3b2b 3b3b 2b3b e2a0 80e2 a096 ;+;;;+;;+;......
00001060: e2a0 97e2 a08e e2a2 8ee2 a2a6 e2a2 a6e2 ................
00001070: a0ae 22 .."
```
[Answer]
# 5. [Charcoal](https://github.com/somebody1234/Charcoal), 136 bytes
```
void main(){//\
/*;ooo"><>"
printf("C")/*/import std.stdio;"D".write/**/;}/*
J'zvSfN0cb&)}kf ;K-+ ,+;q,+;60d}[}q(-6+:puupd"*///⎚laocrahC
```
[Try it online!](https://tio.run/##DcMxDoIwFADQnVM0HRSK8JkcrGHBSRMXR11qK6ER@KUWTDS9ggfweF6k8pInG2ElijaECbUindB9nLwBLhEwjoi03JY0Mlb3ro5pRRNgoDuD1pGHU/lcI6c7mj@tdjdgDLgHFu2Xr@lUHwt5XST@XhN@yFKySvkwXxfKn/0QZ@t0Y8bRKMoA4Pf5tgKlFU0Vwh8 "Charcoal – Try It Online")
Prints **laocrahC** in Charcoal, **C** in C, **><>** in ><>, **emmoS** in Somme, and **D** in D
Next answer cannot exceed **176** bytes (136 + 40).
## Explanation
`⎚` clears the canvas, `laocrahC` prints `laocrahC`
[Answer]
# 11. Gol><>, 306 bytes
```
void /*hL!X-@ P^h~~X@@0D 0D"hp!X-@ PZh )X5 M!M elif MOC SODeerF$*/main(){//\
/+\
1+///\
/*SmiVZZ;ooo"loG";?=0%S!11ooo"><>"
#define S""
#ifdef __OBJC__
#define S"-evitcejbO"
#endif
printf("C"S)/*/import std.stdio;"D".write/**/;}/*
>"Befunge-98";"Befunge-93";,,,,,,,,,,@
nq]j\m7-;l(e[KtR:R*///⎚laocrahC
```
Prints:
* `D` in D
* `emmoS` in Somme
* `><>` in ><>
* `C` in C
* `laocrahC` in Charcoal
* `miV` in Vim
* `C-evitcejbO` in Objective-C
* `89-egnufeB` in Befunge-98
* `39-egnufeB` in Befunge-93
* `elif MOC SODeerF` in FreeDOS COM file
* `><>loG` in Gol><>
[Try it online!](https://tio.run/##rRnbVttI8hn9wrxUBEES2JYNCSEGMwHbJOxA4MRklgk4Hllq2Qq6eHUBM5nMJ@wH7Oftj2SruluybJzMnN3lHKC7637tantoJeOvX1fh0HHAAjayslFonUIa4W4S@Q8jP0ohZUkKYysOWZLA8AHeeqzzG/t0Gw2VVWhHvm9NEgZqO3KYClbogHoYj7KAhWmiQsLs1IvCBNwohiFLUxYDm05Y7LHQZopiWykcgI20Shpl9hgmsYeECrL2XHiIMrBIt5xhBQLrlkGSxYy0DCLHcx8AJdQmD5BEkI6RXzpmD0jCwAttP3OYgws6BN8LbxVmjyOohqCuNVQULWhLp1t06kQJnSqnh29fvz983R2cvO10r1oN5eiXy26vpa7p9zZU7X1S3FAVNwu5meBb4SizRkw3PisrnKe6CmvzXGqw1qjAGueE/kT3qsrK@fvLi/eXxHiIMUHWXBNkvdK9uui2L7sdggmOqPjvMbsjIProGg8EtQpPWrjJCVTo75HZobIiVemi4@0U/VHgVGCEEc7pCXHqpdBQVlxPWVkwHuXrC6ZsNgzSQnCvws2vktPNr@Ry7uCDPKJfKKbjNJ0kTdMceek4G9bsKDAv44eT9DzE2DAzjR@8NMrXjJmBlWDGmPexNcGcSZBD7mFQKS9VULlwvlZmMDR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It@vNUnWJo@d/zu3jMm6rqPKzOkqqT58f07dpaM6Q@dE9cd3ZnXGVxbdUoZ2XzUftjgNe7MwYLLbicsPBq7/UTQRT22nOMp6enPnGFk9D@bEibppQmsBmYx0VnSGpHPaXqaozKrL5MdnME5KkQI8m3xUiG4yh0MsMX1RsWskfaCzMAhZbWLz0wKPy5t@I8kdNKXsI9TdvosdWOGI6Ra6CgdvBv7v4SLoue0jSScvznbSo2HKN@3y8KSfptXzRcCX5x2LiUzi9hMR1x9Y5V9EcvqwhpfEDCRlboePzl/GcOL7BiZC@FcAq@ok9dKnQShWnZuFtGN2HZbqmKDfcF7Of5K8b/wE)
Next answer must not exceed 397 bytes.
## Hexdump
```
00000000: 766f 6964 202f 2a68 4c21 582d 4020 505e void /*hL!X-@ P^
00000010: 687e 7e58 4040 3044 2030 4422 6870 2158 h~~X@@0D 0D"hp!X
00000020: 2d40 2050 5a68 2029 5835 2020 4d21 4d20 -@ PZh )X5 M!M
00000030: 656c 6966 204d 4f43 2053 4f44 6565 7246 elif MOC SODeerF
00000040: 242a 2f6d 6169 6e28 297b 2f2f 5c0a 202f $*/main(){//\. /
00000050: 2b5c 0a31 2b2f 2f2f 5c0a 2f2a 1b53 6d69 +\.1+///\./*.Smi
00000060: 561b 5a5a 3b6f 6f6f 226c 6f47 223b 3f3d V.ZZ;ooo"loG";?=
00000070: 3025 5321 3131 6f6f 6f22 3e3c 3e22 0a23 0%S!11ooo"><>".#
00000080: 6465 6669 6e65 2053 2222 0a23 6966 6465 define S"".#ifde
00000090: 6620 5f5f 4f42 4a43 5f5f 0a23 6465 6669 f __OBJC__.#defi
000000a0: 6e65 2053 222d 6576 6974 6365 6a62 4f22 ne S"-evitcejbO"
000000b0: 0a23 656e 6469 660a 7072 696e 7466 2822 .#endif.printf("
000000c0: 4322 5329 2f2a 2f69 6d70 6f72 7420 7374 C"S)/*/import st
000000d0: 642e 7374 6469 6f3b 2244 222e 7772 6974 d.stdio;"D".writ
000000e0: 652f 2a2a 2f3b 7d2f 2a0a 3e22 4265 6675 e/**/;}/*.>"Befu
000000f0: 6e67 652d 3938 223b 2242 6566 756e 6765 nge-98";"Befunge
00000100: 2d39 3322 3b2c 2c2c 2c2c 2c2c 2c2c 2c40 -93";,,,,,,,,,,@
00000110: 0a6e 715d 6a5c 6d37 2d3b 6c28 655b 4b74 .nq]j\m7-;l(e[Kt
00000120: 523a 522a 2f2f 2fe2 8e9a 6c61 6f63 7261 R:R*///...laocra
00000130: 6843 hC
```
**NOTE:** the template file has been changed to run a different Befunge-93 interpretation that does not have problems with bounding box size.
## How??
I rearranged some code to avoid `0/0` in Befunge-93 (which will prompt for input), and added some code to distinguish ><> and Gol><> by using the `S%` command(s). In Gol><>, both portions will be skipped as `S%` is one command, but in ><> it's `S` then `%`, so only `S` will be skipped, then modulo is used to get different results. The `/+ ... +/` are D-specific nesting comments.
[Answer]
# 18. bash, 643 bytes
```
void /*hO!- #X-@ P^h~~X@@0D 0D"hs!X-@ PZh +X5 "M!M elif MOC SODeerF$++[*/main(){//\
/+ #\
echo hsab<<'EOF' #>>
1+///\
/*ggcGmiVZZ;ooo"loG";?=0%S!11ooo<"><>"
#define S""
#ifdef __OBJC__
#define S"-evitcejbO"
#endif
printf("C"S)/*/import std.stdio;"D".write/**/;}/*<<
"rT";#z_"B",@>2+; > ][ v;#;8k,7y2-;@,, <<<
>"Befunge-96"#^Z00G#^_$4->1+>,,,,,,,,,,@
n*'um{ZKg,5kzy |Fa*///}]⎚¿⁵laocrahC¦++++[-<+++++>]<[-<++++++<+++++<+++++>>>]<<<+++++++.>-.>---.<<-----.++++++++.-----.>--.>---.<+.>>>((((((((((()()()){}){}){}){}()){})((()()()()){}){})[(([][]){}){}()])([]()){})[]())(([[][]()]([]()((((([][][])){}{})[]){})))[]())@,ka"89-egnufenU"
```
Prints:
* `D` in D
* `emmoS` in Somme
* `><>` in ><>
* `C` in C
* `laocrahC` in Charcoal
* `miV` in Vim
* `C-evitcejbO` in Objective-C
* `89-egnufeB` in Befunge-98
* `39-egnufeB` in Befunge-93
* `elif MOC SODeerF` in FreeDOS COM file
* `><>loG` in Gol><>
* `89-egnufenU` in Unefunge-98
* `79-egnufeB` in Befunge-97
* `69-egnufeB` in Befunge-96
* `kcufniarb` in brainfuck
* `89-egnuferT` in Trefunge-98
* `kalf-niarb` in brain-flak
* `hsab` in bash
[Try it online!](https://tio.run/##rRrbctNI9jn6hXnpyAFJsWTZDgnBsT3kCuwASZEww@IYjyy1bBFdXLoQG8hU7Q/sB@wH7B/s81bNp8yPsOd0t2T5AkztbiB2d59rn2u3lKGVjL98qZBDxyEWoSMrG4XWc5JGMJtE/mzkRylJaZKSsRWHNEnIcEZeevTkI31/Ew2lCjmOfN@aJJTIx5FDZWKFDpEP41EW0DBNZJJQO/WiMCFuFJMhTVMaEzqd0NijoU0lybZS0iU20Ep@SIyEDdlHbeiSCjmibhaOqPFoR0qjzB6TSewBYwlEey6ZRRmxUPdcoE4C64aSJIsp7iKIHM@dEdCgNpmRJCLpGOSlYzoDEkq80PYzhzowwEXie@GNRO1xRIyQyFsNGVTjtKXVJq46UbK4uoOrSRQE1HC9KcKkySwdR@HO0urzw5dPXh8@OR08e3ly@qbTkI7@enV62ZG31FubGHYbt67JEuyaGY74VjjKrBFVtU/SBpMnV8jWIpca2WroZItxAg@Bw2RpYwi@BYZM426UpZMsFQzE5j7H9EMXfWGn1Ml5L68boS9tgKU3iR1MCGdDciC5f389AKgO0KKhtMH5/hJH4Uhg1chTOnWyYNIC6HTqkFw515M2lswDZlGXNlttaGAfoa5Brn/dUjGIOBPt@ld0JnNdN4@VO4yWcZpOkpZpjrx0nA1rdhSYV/HsWXoegtepmcYzL43yMaVmYCUQq@ZtbE0gWhPgkHuCyJgRMpGZCmwszWEnAHAChxhxFrI4LgMvMRQAIc4gj8xokposOPhnLR6uEHTbXUDPI4lRuF4yZh8Y0sv4x4DNsGwjtW1z6IUmfK9X5hhy2o4svyAR82KwTsDPXgD4H7ygyFUY11IIga7p0A9mmPk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FNzXWO6FQBBnk/QrMVyCY/Q22YGruMfxtrQGjZ2X8B7O2e6r5duEJm4TyJ/jIE39EavW4o1YhygKOzA5Tjz3Cdwu2GHxduz5lDHjx7eQ3gKSPY5VJgyJNIbI6fl1jx8UGSpw34JLyRBawg0DCKmACHBc4Tdavpw/PS53a9FUlNehF8BRAR9YsPehabNBineQ0FlwzHqKUqroXyUWNgS6YlIQS8xxmXgtzC6FYGinRfjTspboStzOo2KMMbyc4jqS7tRbpeziS7vf5/ZuHbcKqPygDpLq090zfLMM2xlSP7pFrnv7c64i@dYqtPeotVLuGODh3pzBcikuFxxo/aVqwpnaTmse8XjlzCc2vxqKR40waZHSCWx@rMOk0wSVQ/80lTGnwj2vks0tIUgK9GjyTSGiwGgS3szgRkWnen5Bo2EW0NiC5MULHqY3@@sBdqkpRQ@ifvQmamyFI6qi53Rw3B587sMlqVe2kKATO89nYkfFlGncZ8ebcpD2xI2GKckejPHncGoJiekOpXMhoxl8XUFK4xkKGVuh47Ob8YI4NoETIb56gSz6ic5OMdFKGSdn4U0Y3YZluhZPN5gXZz/BX9W@LD8wLJ4V2vzynT8orCUTH@qhch1CquJzP4T3DCjXFaBIsoA/@KT8jxr4uzNPPMyk4Glo5fhSSUqtGDYNjOXDxGvtV1utZrX14OG2EegHslTURlnm3tftRbdzcnZE6PCXX8ZOk0eBj5gotyWOzLAnX4PziddKDIbs97w@x59XQyypyb1Hu9WdZv5Mm7@M56xkXfz5wH8A)
Next answer must not exceed 835 bytes.
## Hexdump
```
00000000: 766f 6964 202f 2a68 4f21 2d20 2358 2d40 void /*hO!- #X-@
00000010: 2050 5e68 7e7e 5840 4030 4420 3044 2268 P^h~~X@@0D 0D"h
00000020: 7321 582d 4020 505a 6820 2b58 3520 224d s!X-@ PZh +X5 "M
00000030: 214d 2065 6c69 6620 4d4f 4320 534f 4465 !M elif MOC SODe
00000040: 6572 4624 2b2b 5b2a 2f6d 6169 6e28 297b erF$++[*/main(){
00000050: 2f2f 5c0a 202f 2b20 235c 0a20 6563 686f //\. /+ #\. echo
00000060: 2068 7361 623c 3c27 454f 4627 2023 3e3e hsab<<'EOF' #>>
00000070: 0a31 2b2f 2f2f 5c0a 2f2a 1b67 6763 476d .1+///\./*.ggcGm
00000080: 6956 1b5a 5a3b 6f6f 6f22 6c6f 4722 3b3f iV.ZZ;ooo"loG";?
00000090: 3d30 2553 2131 316f 6f6f 3c22 3e3c 3e22 =0%S!11ooo<"><>"
000000a0: 0a23 6465 6669 6e65 2053 2222 0a23 6966 .#define S"".#if
000000b0: 6465 6620 5f5f 4f42 4a43 5f5f 0a23 6465 def __OBJC__.#de
000000c0: 6669 6e65 2053 222d 6576 6974 6365 6a62 fine S"-evitcejb
000000d0: 4f22 0a23 656e 6469 660a 7072 696e 7466 O".#endif.printf
000000e0: 2822 4322 5329 2f2a 2f69 6d70 6f72 7420 ("C"S)/*/import
000000f0: 7374 642e 7374 6469 6f3b 2244 222e 7772 std.stdio;"D".wr
00000100: 6974 652f 2a2a 2f3b 7d2f 2a3c 3c0a 2022 ite/**/;}/*<<. "
00000110: 7254 223b 237a 5f22 4222 2c40 3e32 2b3b rT";#z_"B",@>2+;
00000120: 2020 3e20 2020 205d 5b20 763b 233b 386b > ][ v;#;8k
00000130: 2c37 7932 2d3b 402c 2c20 3c3c 3c0a 3e22 ,7y2-;@,, <<<.>"
00000140: 4265 6675 6e67 652d 3936 2223 5e5a 3030 Befunge-96"#^Z00
00000150: 4723 5e5f 2434 2d3e 312b 3e2c 2c2c 2c2c G#^_$4->1+>,,,,,
00000160: 2c2c 2c2c 2c40 0a6e 2a27 756d 7b5a 4b67 ,,,,,@.n*'um{ZKg
00000170: 2c35 6b7a 7920 7c46 612a 2f2f 2f7d 5de2 ,5kzy |Fa*///}].
00000180: 8e9a c2bf e281 b56c 616f 6372 6168 43c2 .......laocrahC.
00000190: a62b 2b2b 2b5b 2d3c 2b2b 2b2b 2b3e 5d3c .++++[-<+++++>]<
000001a0: 5b2d 3c2b 2b2b 2b2b 2b3c 2b2b 2b2b 2b3c [-<++++++<+++++<
000001b0: 2b2b 2b2b 2b3e 3e3e 5d3c 3c3c 2b2b 2b2b +++++>>>]<<<++++
000001c0: 2b2b 2b2e 3e2d 2e3e 2d2d 2d2e 3c3c 2d2d +++.>-.>---.<<--
000001d0: 2d2d 2d2e 2b2b 2b2b 2b2b 2b2b 2e2d 2d2d ---.++++++++.---
000001e0: 2d2d 2e3e 2d2d 2e3e 2d2d 2d2e 3c2b 2e3e --.>--.>---.<+.>
000001f0: 3e3e 2828 2828 2828 2828 2828 2829 2829 >>((((((((((()()
00000200: 2829 297b 7d29 7b7d 297b 7d29 7b7d 2829 ()){}){}){}){}()
00000210: 297b 7d29 2828 2829 2829 2829 2829 297b ){})((()()()()){
00000220: 7d29 7b7d 295b 2828 5b5d 5b5d 297b 7d29 }){})[(([][]){})
00000230: 7b7d 2829 5d29 285b 5d28 2929 7b7d 295b {}()])([]()){})[
00000240: 5d28 2929 2828 5b5b 5d5b 5d28 295d 285b ]())(([[][]()]([
00000250: 5d28 2928 2828 2828 5b5d 5b5d 5b5d 2929 ]()((((([][][]))
00000260: 7b7d 7b7d 295b 5d29 7b7d 2929 295b 5d28 {}{})[]){})))[](
00000270: 2929 402c 6b61 2238 392d 6567 6e75 6665 ))@,ka"89-egnufe
00000280: 6e55 22 nU"
```
## Explanation
I added `- #` to the DOS code, which modifies a register just before it is overwritten. Similarly, the second line also got a `#`. This is necessary to make bash ignore the backslashes. Everything below is a heredoc that is ignored by `echo`. The two `<<` that introduce the heredoc needed to be balanced with `#>>` for Brain-flak.
Then, I noticed that Vim broke, so I changed the `S` (substitute line) to a `ggcG` (go to the top and change from here to the bottom).
Additionally, after fixing Somme some other small changes were necessary to make Brain-flak happy.
[Answer]
# 22. Haskell+BangPatterns, 814 bytes
```
void /*-{-- #hR!X-@ P^h~~X@@0D 0D"hv!X-@ PZh +X5 "M!M elif MOC SODeerF$}++++[*/main(){//\
/+ #\
[ "$(basename "$(readlink /proc/$$/exe)")" = "bash" ] && echo hsab || echo hsz<<'EOF' #>>
1+///\
/*ggcGmiVZZ;ooo"loG";?=0%S!11ooo<"><>"
#define S""
#ifdef __OBJC__
#define S"-evitcejbO"
#endif
printf("C"S)/*/import std.stdio;"D".write/**/;}/*<<
"rT";#z_"B",@>2+; > ][ v;#;8k,7y2-;@,, <<<
>"Befunge-96"#^Z00G#^_$4->1+>,,,,,,,,,,@(
n4j\Ys`9)|bF4I*`p|*///]⎚¿⁵laocrahC¦++++[-<+++++>]<[-<++++++<+++++<+++++>>>]<<<+++++++.>-.>---.<<-----.++++++++.-----.>--.>---.<+.>>>((((((((((()()()){}){}){}){}()){})((()()()()){}){})[(([][]){}){}()])([]()){})[]())(([[][]()]([]()((((([][][])){}{})[]){})))[]())({ -}_=")";(!)=seq;main|let b!_=""=putStr$(""!"snrettaPgnaB+")++"lleksaH"-- *///💬ijome💬➡@,ka"89-egnufenU"
```
Prints:
* `D` in D
* `emmoS` in Somme
* `><>` in ><>
* `C` in C
* `laocrahC` in Charcoal
* `miV` in Vim
* `C-evitcejbO` in Objective-C
* `89-egnufeB` in Befunge-98
* `39-egnufeB` in Befunge-93
* `elif MOC SODeerF` in FreeDOS COM file
* `><>loG` in Gol><>
* `89-egnufenU` in Unefunge-98
* `79-egnufeB` in Befunge-97
* `69-egnufeB` in Befunge-96
* `kcufniarb` in brainfuck
* `89-egnuferT` in Trefunge-98
* `kalf-niarb` in brain-flak
* `hsab` in bash
* `lleksaH` in Haskell
* `hsz` in zsh
* `ijome` in emoji
* `snrettaPgnaB+lleksaH` in Haskell+BangPatterns
[Try it online!](https://tio.run/##rTrLdtvIcmvhF@6mBWoMQAQIkrJliSJ5raetxLZ0LM9cX1M0BwSaJCw8GDwkyrLuOfmBLLLMIjnZZJVt1jnnfsp8Qf7AqeoHCD48M@cmtEV2dz27qrqqC@TQSSffvlXIoecRh9Cxk48j5zXJYphN4@B@HMQZyWiakYmTRDRNyfCevPXpyRf6@SYeKhVyHAeBM00pUY9j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@XL8kF3uVqLoqL9GPkhXBXwgQX7vjlrNkjxHS9UFhyzmqKVMvp3iYUNga6YFMQKc1wuvnZnTSEY2msR/rSsJaoSt/O4GGMMLx9xE0l36q3S6eJLz36b26d13Cqg8tM6SKrPnp3hN/ewnSEN4jvkurs35yoO31qFdvdbK@mOAZ7vzhksp@JywoHSX8omnKnrteYRjy2nnLi8NRSPGmHSIqUb2Pxah4fOEFQe/d1U1pwK97xKNreEICnQ4@mvChEJxlCwM4OOis5M2aDRKA9p4sDhxQYPjzf7dQZrakrRg6hf/KmeONGY6ug5Exy3C@970CT1yhYSdGLnciZ2VEyZxn12vSkHaU90NExJ9mCMP4fTS0hMd0idCyeawdclpCy5RyETJ/IC1hkviGMTuBHit0Rwiv6e3p/iQSudODWPbqL4LirTtfhxg3lx9xP8dePb8gPD4lmhy5tv@aCwlk4DyIfadQRHFZ/7IbxnQbquAEWah/zBJ@U/GuHfTfriYSYFT0Mpx@@/lMxJYNP4Jc5h6rf2qq1Ws9p6@nzbCs0DVSlyo6py75vuots5ObsidPj3dNZOk0dBgJgotyWuzLCnwID7id9KLYYc9Pw@x59nQ0yp6Q/7z6o7TflMm//YgbNSTfHzjP8F)
Next answer must not exceed 1058 bytes.
## Explanation
Reuses the idea of [this answer](https://codegolf.stackexchange.com/a/153892/48198): Defining a top-level operator `(!)=seq` which gets used in case of Haskell with BangPatterns enabled and otherwise the `let`-clause shadows that definition.
## Hexdump
```
00000000: 766f 6964 202f 2a2d 7b2d 2d20 2368 5221 void /*-{-- #hR!
00000010: 582d 4020 505e 687e 7e58 4040 3044 2030 X-@ P^h~~X@@0D 0
00000020: 4422 6876 2158 2d40 2050 5a68 202b 5835 D"hv!X-@ PZh +X5
00000030: 2022 4d21 4d20 656c 6966 204d 4f43 2053 "M!M elif MOC S
00000040: 4f44 6565 7246 247d 2b2b 2b2b 5b2a 2f6d ODeerF$}++++[*/m
00000050: 6169 6e28 297b 2f2f 5c0a 202f 2b20 235c ain(){//\. /+ #\
00000060: 0a20 5b20 2224 2862 6173 656e 616d 6520 . [ "$(basename
00000070: 2224 2872 6561 646c 696e 6b20 2f70 726f "$(readlink /pro
00000080: 632f 2424 2f65 7865 2922 2922 203d 2022 c/$$/exe)")" = "
00000090: 6261 7368 2220 5d20 2626 2065 6368 6f20 bash" ] && echo
000000a0: 6873 6162 207c 7c20 6563 686f 2068 737a hsab || echo hsz
000000b0: 3c3c 2745 4f46 2720 233e 3e0a 312b 2f2f <<'EOF' #>>.1+//
000000c0: 2f5c 0a2f 2a1b 6767 6347 6d69 561b 5a5a /\./*.ggcGmiV.ZZ
000000d0: 3b6f 6f6f 226c 6f47 223b 3f3d 3025 5321 ;ooo"loG";?=0%S!
000000e0: 3131 6f6f 6f3c 223e 3c3e 220a 2364 6566 11ooo<"><>".#def
000000f0: 696e 6520 5322 220a 2369 6664 6566 205f ine S"".#ifdef _
00000100: 5f4f 424a 435f 5f0a 2364 6566 696e 6520 _OBJC__.#define
00000110: 5322 2d65 7669 7463 656a 624f 220a 2365 S"-evitcejbO".#e
00000120: 6e64 6966 0a70 7269 6e74 6628 2243 2253 ndif.printf("C"S
00000130: 292f 2a2f 696d 706f 7274 2073 7464 2e73 )/*/import std.s
00000140: 7464 696f 3b22 4422 2e77 7269 7465 2f2a tdio;"D".write/*
00000150: 2a2f 3b7d 2f2a 3c3c 0a20 2272 5422 3b23 */;}/*<<. "rT";#
00000160: 7a5f 2242 222c 403e 322b 3b20 203e 2020 z_"B",@>2+; >
00000170: 2020 5d5b 2076 3b23 3b38 6b2c 3779 322d ][ v;#;8k,7y2-
00000180: 3b40 2c2c 203c 3c3c 0a3e 2242 6566 756e ;@,, <<<.>"Befun
00000190: 6765 2d39 3622 235e 5a30 3047 235e 5f24 ge-96"#^Z00G#^_$
000001a0: 342d 3e31 2b3e 2c2c 2c2c 2c2c 2c2c 2c2c 4->1+>,,,,,,,,,,
000001b0: 4028 0a6e 346a 5c59 7360 3929 7c62 4634 @(.n4j\Ys`9)|bF4
000001c0: 492a 6070 7c2a 2f2f 2f5d e28e 9ac2 bfe2 I*`p|*///]......
000001d0: 81b5 6c61 6f63 7261 6843 c2a6 2b2b 2b2b ..laocrahC..++++
000001e0: 5b2d 3c2b 2b2b 2b2b 3e5d 3c5b 2d3c 2b2b [-<+++++>]<[-<++
000001f0: 2b2b 2b2b 3c2b 2b2b 2b2b 3c2b 2b2b 2b2b ++++<+++++<+++++
00000200: 3e3e 3e5d 3c3c 3c2b 2b2b 2b2b 2b2b 2e3e >>>]<<<+++++++.>
00000210: 2d2e 3e2d 2d2d 2e3c 3c2d 2d2d 2d2d 2e2b -.>---.<<-----.+
00000220: 2b2b 2b2b 2b2b 2b2e 2d2d 2d2d 2d2e 3e2d +++++++.-----.>-
00000230: 2d2e 3e2d 2d2d 2e3c 2b2e 3e3e 3e28 2828 -.>---.<+.>>>(((
00000240: 2828 2828 2828 2828 2928 2928 2929 7b7d (((((((()()()){}
00000250: 297b 7d29 7b7d 297b 7d28 2929 7b7d 2928 ){}){}){}()){})(
00000260: 2828 2928 2928 2928 2929 7b7d 297b 7d29 (()()()()){}){})
00000270: 5b28 285b 5d5b 5d29 7b7d 297b 7d28 295d [(([][]){}){}()]
00000280: 2928 5b5d 2829 297b 7d29 5b5d 2829 2928 )([]()){})[]())(
00000290: 285b 5b5d 5b5d 2829 5d28 5b5d 2829 2828 ([[][]()]([]()((
000002a0: 2828 285b 5d5b 5d5b 5d29 297b 7d7b 7d29 ((([][][])){}{})
000002b0: 5b5d 297b 7d29 2929 5b5d 2829 2928 7b20 []){})))[]())({
000002c0: 2d7d 5f3d 2229 223b 2821 293d 7365 713b -}_=")";(!)=seq;
000002d0: 6d61 696e 7c6c 6574 2062 215f 3d22 223d main|let b!_=""=
000002e0: 7075 7453 7472 2428 2222 2122 736e 7265 putStr$(""!"snre
000002f0: 7474 6150 676e 6142 2b22 292b 2b22 6c6c ttaPgnaB+")++"ll
00000300: 656b 7361 4822 2d2d 202a 2f2f 2ff0 9f92 eksaH"-- *///...
00000310: ac69 6a6f 6d65 f09f 92ac e29e a140 2c6b .ijome.......@,k
00000320: 6122 3839 2d65 676e 7566 656e 5522 a"89-egnufenU"
```
[Answer]
# 28. Alice, 1024 bytes
```
void /*-{-- #hR!X-@ P^h~~X@@0D 0D"hv!X-@ PZh +X5 "M!M elif MOC SODeerF$}++++[*///\
/+ #\
basename "$(readlink /proc/$$/exe)"|rev;:<<'EOF' #>>\
1+/// O\
/* ggcGmiVZZ;ooo"loG";?=0%S!11ooo<"><>"
#define S"C" //A
#ifdef __cplusplus//l
f(); //i
#include<cstdio>//c
#define S"++C" //e
int/// "
#endif// \.
#ifdef __OBJC__
#define S"C-evitcejbO"
#endif
main(){printf(S)/*/main(){import std.stdio;"D".write/**/;}/*}
@,,"rT",,,,,,,,,+1_;#:< v+;#!<
"rT";#z_"B",@>5k$2+;> [$v;#;8k,7y2-;@,,<<
>"Befunge-96"#^000G #^_$$3->,,,,,,,,,,@]
DT . . *///{}]⎚¿⁵laocrahC¦++++[-<+++++>]<[-<++++++<+++++<+++++>>>]<<<+++++++.>-.>---.<<-----.++++++++.-----.>--.>---.<+.>>>((((((((((()()()){}){}){}){}()){})((()()()()){}){})[(([][]){}){}()])([]()){})[]())(([[][]()]([]()((((([][][])){}{})[]){})))[]())({ -}_=")";(!)=seq;main|let b!_=""=putStr$(""!"snrettaPgnaB+")++init"lleksaH(" {-
//+JAvY2a3*M;G0JeD-} -- )*///💬ijome💬➡😭Emotinomicon😲⏪⏬⏩@,ka"89-egnufenU"
```
Prints:
* `D` in D
* `emmoS` in Somme
* `><>` in ><>
* `C` in C
* `laocrahC` in Charcoal
* `miV` in Vim
* `C-evitcejbO` in Objective-C
* `89-egnufeB` in Befunge-98
* `39-egnufeB` in Befunge-93
* `elif MOC SODeerF` in FreeDOS COM file
* `><>loG` in Gol><>
* `89-egnufenU` in Unefunge-98
* `79-egnufeB` in Befunge-97
* `69-egnufeB` in Befunge-96
* `kcufniarb` in brainfuck
* `89-egnuferT` in Trefunge-98
* `kalf-niarb` in brain-flak
* `hsab` in bash
* `lleksaH` in Haskell
* `hsz` in zsh
* `ijome` in emoji
* `snrettaPgnaB+lleksaH` in Haskell+BangPatterns
* `++C` in C++
* `nocimonitomE` in Emotinomicon
* `hsk` in ksh
* `hsad` in dash
* `79-egnuferT` in Trefunge-97
* `ecilA` in Alice
[Try it online!](https://tio.run/##rTrLcttIkmfhF@ZSAtkGIAIESdmyzNdYEiXbPbalsNQ9HlM0BwSKJCw8OHhIlNXqiPmB7Yg9bexhO/ayEbsxe9mIPW/EfIq/YP7Am1lVAMGH3R27Q1tkVeWzMrMys0COrHj6@XOJHDgOsQidWOkksF6SJITZLPRuJ16YkITGCZlaUUDjmIxuyWuX9j7SD1fhSCqRo9DzrFlMiXwUOlQmVuAQ@SCapD4NklgmMbUTNwxiMg4jMqJJQiNC5zMauTSwqSTZVkK6xAZayQuIEbMhe6uOxqREDuk4DSbUeLIrJWFqT8kscoGxBKLdMbkNU2Kh7plAnfjWFSVxGlHchR867viWgAbV2S2JQ5JMQV4ypbdAQokb2F7qUAcGuEg8N7iSqD0NiREQuVyXQTVOW1ht4KoTxsuru7gah75PjbE7R5g0u02mYbC7svry4PWz7w6eHQ9fvO4dv@3UpcM/XByfd@SyemMTw27j1jVZgl0zwxHPCiapNaGqdidtMXlyiZSXuVRJua6TMuMEHgKHyRnumzQI3GBC2GYeNKStEbgc5LCNdMM0maWJwBV7/iGi1110kZ1QJ2Ozum4EnrQFDtgmtj8jnA3JgOTBg80AoGqhoQNpi/P9fRSCbhyrSp7TuZP6syZA53OHZMqNXWlrxWpgLXXFBpW6puW7NsjlH8sqxhZnol3@EX3MjNDNQugeg2iaJLO4aZoTN5mmo6od@uZFdPsiOQ0gGKiZRLduEmZjSk3fiiGEzZvImkEQx8AhcxCR8aDIRGYqsLG0gPUA4PgOMaI0YOFdBJ5jhABClMLxMsNZYrKY4e/VaLRG0G13AT0LMEYxduMpe8NIX8U/AmyGZRuJbZsjNzDhc7MyR3DU7dDychI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JbFDK1AsdjN@MlcWwCHSF@7wWn6Hf09hgPWuHEyWlwFYQ3QZGuyY8bzPPeT/BXtc@rDwzzZ4U2v3xnDwqr8cyDfKhcBnBU8bkfwvsGpOsSUMSpzx98Uv4zJP4VryseZlLwNJRy/EZPSqwINg2M5YPYbe5Xms1Gpfnw8Y7h6y1ZynOjLHPv6/ay2zk5axE6/JtHY7fBo8BDTJTbFC0z7MnToD9xm7HBkL2@O@D4i2yIKTX@5smjym4je6bNfyfDWcm6@GXP/wI)
Next answer must not exceed 1331 bytes.
## Explanation
Once I got **Alice** working (which nicely can reuse a lot of code) **Somme** was annoying, the code to fix it would have been `Sc+JAvY2a3*[;G>JeD` which breaks **Brain-Flak**. What I did, was to split the last line into two which gives us two unused lines to fix **Somme**1, this only required smallish fixes for **Brain-Flak**.
## Hexdump
```
00000000: 766f 6964 202f 2a2d 7b2d 2d20 2368 5221 void /*-{-- #hR!
00000010: 582d 4020 505e 687e 7e58 4040 3044 2030 X-@ P^h~~X@@0D 0
00000020: 4422 6876 2158 2d40 2050 5a68 202b 5835 D"hv!X-@ PZh +X5
00000030: 2022 4d21 4d20 656c 6966 204d 4f43 2053 "M!M elif MOC S
00000040: 4f44 6565 7246 247d 2b2b 2b2b 5b2a 2f2f ODeerF$}++++[*//
00000050: 2f5c 0a20 2f2b 2023 5c0a 2062 6173 656e /\. /+ #\. basen
00000060: 616d 6520 2224 2872 6561 646c 696e 6b20 ame "$(readlink
00000070: 2f70 726f 632f 2424 2f65 7865 2922 7c72 /proc/$$/exe)"|r
00000080: 6576 3b3a 3c3c 2745 4f46 2720 233e 3e5c ev;:<<'EOF' #>>\
00000090: 0a31 2b2f 2f2f 2020 2020 2020 2020 2020 .1+///
000000a0: 2020 2020 2020 2020 4f5c 0a2f 2a20 1b67 O\./* .g
000000b0: 6763 476d 6956 1b5a 5a3b 6f6f 6f22 6c6f gcGmiV.ZZ;ooo"lo
000000c0: 4722 3b3f 3d30 2553 2131 316f 6f6f 3c22 G";?=0%S!11ooo<"
000000d0: 3e3c 3e22 0a23 6465 6669 6e65 2053 2243 ><>".#define S"C
000000e0: 2220 2020 2020 2020 2f2f 410a 2369 6664 " //A.#ifd
000000f0: 6566 205f 5f63 706c 7573 706c 7573 2f2f ef __cplusplus//
00000100: 6c0a 2066 2829 3b20 2020 2020 2020 2020 l. f();
00000110: 2020 202f 2f69 0a23 696e 636c 7564 653c //i.#include<
00000120: 6373 7464 696f 3e2f 2f63 0a23 6465 6669 cstdio>//c.#defi
00000130: 6e65 2053 222b 2b43 2220 2f2f 650a 2069 ne S"++C" //e. i
00000140: 6e74 2f2f 2f20 2020 2020 2020 2020 220a nt/// ".
00000150: 2365 6e64 6966 2f2f 2020 2020 2020 205c #endif// \
00000160: 2e0a 2369 6664 6566 205f 5f4f 424a 435f ..#ifdef __OBJC_
00000170: 5f0a 2364 6566 696e 6520 5322 432d 6576 _.#define S"C-ev
00000180: 6974 6365 6a62 4f22 0a23 656e 6469 660a itcejbO".#endif.
00000190: 206d 6169 6e28 297b 7072 696e 7466 2853 main(){printf(S
000001a0: 292f 2a2f 6d61 696e 2829 7b69 6d70 6f72 )/*/main(){impor
000001b0: 7420 7374 642e 7374 6469 6f3b 2244 222e t std.stdio;"D".
000001c0: 7772 6974 652f 2a2a 2f3b 7d2f 2a7d 0a20 write/**/;}/*}.
000001d0: 2020 402c 2c22 7254 222c 2c2c 2c2c 2c2c @,,"rT",,,,,,,
000001e0: 2c2c 2b31 5f3b 233a 3c20 762b 3b23 213c ,,+1_;#:< v+;#!<
000001f0: 0a20 2272 5422 3b23 7a5f 2242 222c 403e . "rT";#z_"B",@>
00000200: 356b 2432 2b3b 3e20 2020 5b24 763b 233b 5k$2+;> [$v;#;
00000210: 386b 2c37 7932 2d3b 402c 2c3c 3c0a 3e22 8k,7y2-;@,,<<.>"
00000220: 4265 6675 6e67 652d 3936 2223 5e30 3030 Befunge-96"#^000
00000230: 4720 235e 5f24 2433 2d3e 2c2c 2c2c 2c2c G #^_$$3->,,,,,,
00000240: 2c2c 2c2c 405d 0a44 5420 2020 2020 2020 ,,,,@].DT
00000250: 2020 2e20 202e 2020 202a 2f2f 2f7b 7d5d . . *///{}]
00000260: e28e 9ac2 bfe2 81b5 6c61 6f63 7261 6843 ........laocrahC
00000270: c2a6 2b2b 2b2b 5b2d 3c2b 2b2b 2b2b 3e5d ..++++[-<+++++>]
00000280: 3c5b 2d3c 2b2b 2b2b 2b2b 3c2b 2b2b 2b2b <[-<++++++<+++++
00000290: 3c2b 2b2b 2b2b 3e3e 3e5d 3c3c 3c2b 2b2b <+++++>>>]<<<+++
000002a0: 2b2b 2b2b 2e3e 2d2e 3e2d 2d2d 2e3c 3c2d ++++.>-.>---.<<-
000002b0: 2d2d 2d2d 2e2b 2b2b 2b2b 2b2b 2b2e 2d2d ----.++++++++.--
000002c0: 2d2d 2d2e 3e2d 2d2e 3e2d 2d2d 2e3c 2b2e ---.>--.>---.<+.
000002d0: 3e3e 3e28 2828 2828 2828 2828 2828 2928 >>>((((((((((()(
000002e0: 2928 2929 7b7d 297b 7d29 7b7d 297b 7d28 )()){}){}){}){}(
000002f0: 2929 7b7d 2928 2828 2928 2928 2928 2929 )){})((()()()())
00000300: 7b7d 297b 7d29 5b28 285b 5d5b 5d29 7b7d {}){})[(([][]){}
00000310: 297b 7d28 295d 2928 5b5d 2829 297b 7d29 ){}()])([]()){})
00000320: 5b5d 2829 2928 285b 5b5d 5b5d 2829 5d28 []())(([[][]()](
00000330: 5b5d 2829 2828 2828 285b 5d5b 5d5b 5d29 []()((((([][][])
00000340: 297b 7d7b 7d29 5b5d 297b 7d29 2929 5b5d ){}{})[]){})))[]
00000350: 2829 2928 7b20 2d7d 5f3d 2229 223b 2821 ())({ -}_=")";(!
00000360: 293d 7365 713b 6d61 696e 7c6c 6574 2062 )=seq;main|let b
00000370: 215f 3d22 223d 7075 7453 7472 2428 2222 !_=""=putStr$(""
00000380: 2122 736e 7265 7474 6150 676e 6142 2b22 !"snrettaPgnaB+"
00000390: 292b 2b69 6e69 7422 6c6c 656b 7361 4828 )++init"lleksaH(
000003a0: 2220 7b2d 0a2f 2f2b 4a41 7659 3261 332a " {-.//+JAvY2a3*
000003b0: 4d3b 4730 4a65 442d 7d20 2d2d 2029 2a2f M;G0JeD-} -- )*/
000003c0: 2f2f f09f 92ac 696a 6f6d 65f0 9f92 ace2 //....ijome.....
000003d0: 9ea1 f09f 98ad 456d 6f74 696e 6f6d 6963 ......Emotinomic
000003e0: 6f6e f09f 98b2 e28f aae2 8fac e28f a940 on.............@
000003f0: 2c6b 6122 3839 2d65 676e 7566 656e 5522 ,ka"89-egnufenU"
```
---
1: Alternatively I could have worked around by inserting the dots in an unused Alice section, like [this](https://tio.run/##rTrbcttIds/CL@xLC9QYgAgQJGXLMm9rXW3P2pbK0sx6TdFcEGiQsHDh4iJR1miq9gcyVXlK5SFTeUlVUpuXVOU5Vfsp/oL9A@ec7gYIXuyZSpa2yO4@1z59@lxAjqxk8vlzhew7DrEIHVvZOLRekjSC2TTyb8d@lJKUJimZWHFIk4SMbslrjx59pB@uopFUIYeR71vThBL5MHKoTKzQIfJ@PM4CGqaJTBJqp14UJsSNYjKiaUpjQmdTGns0tKkk2VZKesQGWskPiZGwIXurjVxSIQfUzcIxNZ7sSGmU2RMyjT1gLIFozyW3UUYs1D0XqJPAuqIkyWKKuwgix3NvCWhQm96SJCLpBOSlE3oLJJR4oe1nDnVggIvE98IridqTiBghkbcaMqjGaUurTVx1omRxdQdXkygIqOF6M4RJ09t0EoU7S6sv918/@27/2fHwxeuj47fdhnTwh4vj8668pd7YxLA7uHVNlmDXzHDEt8JxZo2pqt1JG0yeXCFbi1xqZKuhky3GCU4IDkzOcd9kYeiFY8I286ApbYzgyEEO20gvytJplgpcsecfYnrdwyOyU@rkbJbXjdCXNuAANokdTAlnQ3IgefBgPQCo2mjoUNrgfH8fR6Abx6qR53TmZMG0BdDZzCG5cq4nbSxZDaylLtmg2tC0YtcGufzjloq@xZlol3/EM2ZG6OUudI9ONEnTad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Jpgsqhv5rKmFPhnlfJ5pYQJAV6NP2qEBFgNAk7M@io6EzPGzQaZgGNLbi82ODh9WY/6GFNTcl7EPWjN1VjKxxTFU9Oh4Pbhfc9aJL6ZQsJOrHzfCZ2VEyZxgNW3pSdtC86GqYkezDGn8OpJSSmO4TOhRvN4OsCUhrfopCJFTo@64wXxLEJVIT4xRbcot/R22O8aKUbJ2fhVRjdhGW6Fr9uMC9qP8Ff1T4vPzAsnhXavPnOHxTWkqkP8VC5DOGq4nM/hPcNCNcVoEiygD/4pPx3Rvw7XE88zKRw0pDK8Ss7KbVi2DQwlvcTr7VXbbWa1dbDx9tGoLdlqYiNssxPX7cXj52TsxKhy79aNHaa3At8xES5LVEyw558DeoTr5UYDNnvewOOP4@GGFKTb548qu4082fa/IcwnJWsi5/u/C8)
[Answer]
# 29. Quadrefunge-97, 1156 bytes
```
void /*-{-- #hR!X-@ P^h~~X@@0D 0D"hv!X-@ PZh +X5 "M!M elif MOC SODeerF$}++++[*///\
/+ #\
basename "$(readlink /proc/$$/exe)"|rev;:<<'EOF' #>>\
1+/// O\
/* ggcGmiVZZ;ooo"loG";?=0%S!11ooo<"><>"
#define S"C" //A
#ifdef __cplusplus//l
f(); //i
#include<cstdio>//c
#define S"++C" //e
int/// "
#endif// \.
#ifdef __OBJC__
#define S"C-evitcejbO"
#endif
main(){printf(S)/*/main(){import std.stdio;"D".write/**/;}/*}
v <>"efunge-98",,,,,,,,,7y3-v<
> #^Gv @,"B"_"Tr",,@
v<[_"]Befunge-93">,,,,,,,,,,@<
>#<"Befunge-96"> ^v$G001
v ,,,,,"79-egnufeB" _ v<
> ,,,,,@#,,,,"79-egnuferdauQ"_v#!$G0001<>
@,,,,,,,,,,,"79-egnuferT"<>
8X. . .*///{}]⎚¿⁵laocrahC¦++++[-<+++++>]<[-<++++++<+++++<+++++>>>]<<<+++++++.>-.>---.<<-----.++++++++.-----.>--.>---.<+.>>>((((((((((()()()){}){}){}){}()){})((()()()()){}){})[(([][]){}){}()])([]()){})[]())(([[][]()]([]()((((([][][])){}{})[]){})))[]())({ -}_=")";(!)=seq;main|let b!_=""=putStr$(""!"snrettaPgnaB+")++init"lleksaH(" {-
//28aZV8s&|?lz=a20-} -- )*///💬ijome💬➡😭Emotinomicon😲⏪⏬⏩@,ka"89-egnufenU"
```
Prints:
* `D` in D
* `emmoS` in Somme
* `><>` in ><>
* `C` in C
* `laocrahC` in Charcoal
* `miV` in Vim
* `C-evitcejbO` in Objective-C
* `89-egnufeB` in Befunge-98
* `39-egnufeB` in Befunge-93
* `elif MOC SODeerF` in FreeDOS COM file
* `><>loG` in Gol><>
* `89-egnufenU` in Unefunge-98
* `79-egnufeB` in Befunge-97
* `69-egnufeB` in Befunge-96
* `kcufniarb` in brainfuck
* `89-egnuferT` in Trefunge-98
* `kalf-niarb` in brain-flak
* `hsab` in bash
* `lleksaH` in Haskell
* `hsz` in zsh
* `ijome` in emoji
* `snrettaPgnaB+lleksaH` in Haskell+BangPatterns
* `++C` in C++
* `nocimonitomE` in Emotinomicon
* `hsk` in ksh
* `hsad` in dash
* `79-egnuferT` in Trefunge-97
* `ecilA` in Alice
* `79-egnuferdauQ` in Quadrefunge-97
[Try it online!](https://tio.run/##rTrbcttKcs/CL@zLCNQRAJEgSMqWaYrksa62d21La/mcdUzRXBAYkrBw4eIiUZa1VfmBnKo8pfKQrbykKqnNS6rynKr9FH/B/oHTPRcQvNjn1Ca0Rc5MX6e7p7sH5NBOJl@@lMiB6xKb0LGdjUP7BUkjmE0j/3bsRylJaZKSiR2HNEnI8Ja88ujxR/rhKhoqJXIU@b49TShRjyKXqsQOXaIexOMsoGGaqCShTupFYUJGUUyGNE1pTOhsSmOPhg5VFMdOSZc4QKv4ITETNmRv1eGIlMghHWXhmJqPd5U0ypwJmcYeMFZAtDcit1FGbNRdCqyQwL6iJMliirsIItcb3RLQoDq9JUlE0gnISyf0Fkgo8ULHz1zqwgAXie@FVwp1JhExQ6Ju1VVQjdMWVhu46kbJ4uouriZREFBz5M0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obbCGK7/H8bK0Bo31S3gP52ybevE2YYjbBPLnOEhTe8yytfgSvkM0jTVMrhvPfQK3C9Ys3kw8nzJmvH0L6Q0gOZNYZ8KQyGCInJ5f93ijyFCB@xZcSoZQEq4YQEgFRIDjCr/R8mX59UGxWouiov0QegG0CvjAgv0yI23USf5rCKgsOGY1RStk9K8SCxsCXT7JiRXmuEz8QIVdCsHQbovwp2UtUZW4ncf5GGN4@YhXkHS31iqcLr708Oe5vV/HrQQqP6iBpNrs4Sn@xgW2M6R@dINc95pzruLwrVVo73FrJd0xwKO9OYPlVFxMOFD6C9mEM3Xc1jzi8copJw6/GopHjTBpkUIHNm/r8NAZgsqlv5jKnFPhnlfJ5pYQJDl6NP2mEJFgDAVvZnCjorOKvKDRMAtobMPhxQseHm/2OyZ2qSlED6J@9KZ6bIdjqqPnKuC4PXhvwiWpV7SQoBM7lzOxo3zKNO6z9qYYpD1xo2FKsgdj/DmcXkBiukPqXDjRDL4uIaXxLQqZ2KHrs5vxgjg2gY4Qv3uDU/QbenuCB61w4tQsvAqjm7BI1@LHDeZ57yf468aX5QeG@bNCh1@@5YPCajL1IR9qlyEcVXzuh/CeCem6BBRJFvAHn5T/vIp/de2Jh5kUPA2lHL9VVFI7hk0DY/Ug8VrNcqvVKLcePNoxg8q@quS5UVW59yvOots5OWsROvzbT3O3waPAR0yU2xItM@zJN6A/8VqJyZD9ntfn@PNsiCk1@e7xw/JuQz7T5r//4azUivjF0v8C)
Next answer must not exceed 1502 bytes.
## Hexdump
```
00000000: 766f 6964 202f 2a2d 7b2d 2d20 2368 5221 void /*-{-- #hR!
00000010: 582d 4020 505e 687e 7e58 4040 3044 2030 X-@ P^h~~X@@0D 0
00000020: 4422 6876 2158 2d40 2050 5a68 202b 5835 D"hv!X-@ PZh +X5
00000030: 2022 4d21 4d20 656c 6966 204d 4f43 2053 "M!M elif MOC S
00000040: 4f44 6565 7246 247d 2b2b 2b2b 5b2a 2f2f ODeerF$}++++[*//
00000050: 2f5c 0a20 2f2b 2023 5c0a 2062 6173 656e /\. /+ #\. basen
00000060: 616d 6520 2224 2872 6561 646c 696e 6b20 ame "$(readlink
00000070: 2f70 726f 632f 2424 2f65 7865 2922 7c72 /proc/$$/exe)"|r
00000080: 6576 3b3a 3c3c 2745 4f46 2720 233e 3e5c ev;:<<'EOF' #>>\
00000090: 0a31 2b2f 2f2f 2020 2020 2020 2020 2020 .1+///
000000a0: 2020 2020 2020 2020 4f5c 0a2f 2a20 1b67 O\./* .g
000000b0: 6763 476d 6956 1b5a 5a3b 6f6f 6f22 6c6f gcGmiV.ZZ;ooo"lo
000000c0: 4722 3b3f 3d30 2553 2131 316f 6f6f 3c22 G";?=0%S!11ooo<"
000000d0: 3e3c 3e22 0a23 6465 6669 6e65 2053 2243 ><>".#define S"C
000000e0: 2220 2020 2020 2020 2f2f 410a 2369 6664 " //A.#ifd
000000f0: 6566 205f 5f63 706c 7573 706c 7573 2f2f ef __cplusplus//
00000100: 6c0a 2066 2829 3b20 2020 2020 2020 2020 l. f();
00000110: 2020 202f 2f69 0a23 696e 636c 7564 653c //i.#include<
00000120: 6373 7464 696f 3e2f 2f63 0a23 6465 6669 cstdio>//c.#defi
00000130: 6e65 2053 222b 2b43 2220 2f2f 650a 2069 ne S"++C" //e. i
00000140: 6e74 2f2f 2f20 2020 2020 2020 2020 220a nt/// ".
00000150: 2365 6e64 6966 2f2f 2020 2020 2020 205c #endif// \
00000160: 2e0a 2369 6664 6566 205f 5f4f 424a 435f ..#ifdef __OBJC_
00000170: 5f0a 2364 6566 696e 6520 5322 432d 6576 _.#define S"C-ev
00000180: 6974 6365 6a62 4f22 0a23 656e 6469 660a itcejbO".#endif.
00000190: 206d 6169 6e28 297b 7072 696e 7466 2853 main(){printf(S
000001a0: 292f 2a2f 6d61 696e 2829 7b69 6d70 6f72 )/*/main(){impor
000001b0: 7420 7374 642e 7374 6469 6f3b 2244 222e t std.stdio;"D".
000001c0: 7772 6974 652f 2a2a 2f3b 7d2f 2a7d 0a76 write/**/;}/*}.v
000001d0: 2020 3c3e 2265 6675 6e67 652d 3938 222c <>"efunge-98",
000001e0: 2c2c 2c2c 2c2c 2c2c 3779 332d 763c 0a3e ,,,,,,,,7y3-v<.>
000001f0: 2020 235e 4776 2020 2020 2020 2020 2020 #^Gv
00000200: 2020 2020 2020 2040 2c22 4222 5f22 5472 @,"B"_"Tr
00000210: 222c 2c40 0a20 2020 763c 5b5f 225d 4265 ",,@. v<[_"]Be
00000220: 6675 6e67 652d 3933 223e 2c2c 2c2c 2c2c funge-93">,,,,,,
00000230: 2c2c 2c2c 403c 0a20 2020 3e23 3c22 4265 ,,,,@<. >#<"Be
00000240: 6675 6e67 652d 3936 223e 205e 7624 4730 funge-96"> ^v$G0
00000250: 3031 0a76 2020 2c2c 2c2c 2c22 3739 2d65 01.v ,,,,,"79-e
00000260: 676e 7566 6542 2220 5f20 2020 2020 2020 gnufeB" _
00000270: 2020 2020 2020 2020 2020 2076 3c0a 3e20 v<.>
00000280: 202c 2c2c 2c2c 4023 2c2c 2c2c 2237 392d ,,,,,@#,,,,"79-
00000290: 6567 6e75 6665 7264 6175 5122 5f76 2321 egnuferdauQ"_v#!
000002a0: 2447 3030 3031 3c3e 0a20 2020 2020 2040 $G0001<>. @
000002b0: 2c2c 2c2c 2c2c 2c2c 2c2c 2c22 3739 2d65 ,,,,,,,,,,,"79-e
000002c0: 676e 7566 6572 5422 3c3e 0a38 582e 2020 gnuferT"<>.8X.
000002d0: 2020 2020 2020 2020 2e20 2020 2e2a 2f2f . .*//
000002e0: 2f7b 7d5d e28e 9ac2 bfe2 81b5 6c61 6f63 /{}]........laoc
000002f0: 7261 6843 c2a6 2b2b 2b2b 5b2d 3c2b 2b2b rahC..++++[-<+++
00000300: 2b2b 3e5d 3c5b 2d3c 2b2b 2b2b 2b2b 3c2b ++>]<[-<++++++<+
00000310: 2b2b 2b2b 3c2b 2b2b 2b2b 3e3e 3e5d 3c3c ++++<+++++>>>]<<
00000320: 3c2b 2b2b 2b2b 2b2b 2e3e 2d2e 3e2d 2d2d <+++++++.>-.>---
00000330: 2e3c 3c2d 2d2d 2d2d 2e2b 2b2b 2b2b 2b2b .<<-----.+++++++
00000340: 2b2e 2d2d 2d2d 2d2e 3e2d 2d2e 3e2d 2d2d +.-----.>--.>---
00000350: 2e3c 2b2e 3e3e 3e28 2828 2828 2828 2828 .<+.>>>(((((((((
00000360: 2828 2928 2928 2929 7b7d 297b 7d29 7b7d (()()()){}){}){}
00000370: 297b 7d28 2929 7b7d 2928 2828 2928 2928 ){}()){})((()()(
00000380: 2928 2929 7b7d 297b 7d29 5b28 285b 5d5b )()){}){})[(([][
00000390: 5d29 7b7d 297b 7d28 295d 2928 5b5d 2829 ]){}){}()])([]()
000003a0: 297b 7d29 5b5d 2829 2928 285b 5b5d 5b5d ){})[]())(([[][]
000003b0: 2829 5d28 5b5d 2829 2828 2828 285b 5d5b ()]([]()((((([][
000003c0: 5d5b 5d29 297b 7d7b 7d29 5b5d 297b 7d29 ][])){}{})[]){})
000003d0: 2929 5b5d 2829 2928 7b20 2d7d 5f3d 2229 ))[]())({ -}_=")
000003e0: 223b 2821 293d 7365 713b 6d61 696e 7c6c ";(!)=seq;main|l
000003f0: 6574 2062 215f 3d22 223d 7075 7453 7472 et b!_=""=putStr
00000400: 2428 2222 2122 736e 7265 7474 6150 676e $(""!"snrettaPgn
00000410: 6142 2b22 292b 2b69 6e69 7422 6c6c 656b aB+")++init"llek
00000420: 7361 4828 2220 7b2d 0a2f 2f32 3861 5a56 saH(" {-.//28aZV
00000430: 3873 267c 3f6c 7a3d 6132 302d 7d20 2d2d 8s&|?lz=a20-} --
00000440: 2029 2a2f 2f2f f09f 92ac 696a 6f6d 65f0 )*///....ijome.
00000450: 9f92 ace2 9ea1 f09f 98ad 456d 6f74 696e ..........Emotin
00000460: 6f6d 6963 6f6e f09f 98b2 e28f aae2 8fac omicon..........
00000470: e28f a940 2c6b 6122 3839 2d65 676e 7566 ...@,ka"89-egnuf
00000480: 656e 5522 enU"
```
Thanks to @NieDzejkob and @BMO for help with fixing brainfuck, Alice, and BrainFlak in chat!
# Changes
I redid the funge section, and applied the fixes supplied by @BMO for Alice, BrainFlak, and Brainfuck.
[Answer]
# 31. Quintefunge-97, 1251 bytes
```
void /*-{-- #hR!X-@ P^h~~X@@0D 0D"hv!X-@ PZh +X5 "M!M elif MOC SODeerF$}++++[*///\
/+ #\
basename "$(readlink /proc/$$/exe)"|rev;:<<'EOF' #>>\
1+/// O\
/* ggcGmiVZZ;ooo"loG";?=0%S!11ooo<"><>"
#define S"C" //A
#ifdef __cplusplus//l
f(); //i
#include<cstdio>//c
#define S"++C" //e
int/// "
#endif// \.
#ifdef __OBJC__
#define S"C-evitcejbO"
#endif
main(){printf(S)/*/main(){import std.stdio;"D".write/**/;}/*}<
> v
999 999 99
999 999 9
999v<>
v <>"efunge-98",,,,,,,,,7y3-v<
> #^Gv @,"B"_"Tr",,@
v<[_"]Befunge-93">,,,,,,,,,,@<
>#<"Befunge-96"> ^v$G001
v ,,,,,"79-egnufeB" _ v<
> ,,,,,@# ,"79-egnuferT"_v# $G0001<>
<>10000G$v
#@,,,,,,,,,,,,,,@#"79-egnuferdauQ"_"Quintefunge-97"
.l . *///{}]⎚¿⁵laocrahC¦++++[-<+++++>]<[-<++++++<+++++<+++++>>>]<<<+++++++.>-.>---.<<-----.++++++++.-----.>--.>---.<+.>>>((((((((((()()()){}){}){}){}()){})((()()()()){}){})[(([][]){}){}()])([]()){})[]())(([[][]()]([]()((((([][][])){}{})[]){})))[]())({ -}_=")";(!)=seq;main|let b!_=""=putStr$(""!"snrettaPgnaB+")++init"lleksaH("{-
//TJrf$8AlzKx5?x?I-}--)*///💬ijome💬➡😭Emotinomicon😲⏪⏬⏩@,ka"89-egnufenU"
```
Prints:
* `D` in D
* `emmoS` in Somme
* `><>` in ><>
* `C` in C
* `laocrahC` in Charcoal
* `miV` in Vim
* `C-evitcejbO` in Objective-C
* `89-egnufeB` in Befunge-98
* `39-egnufeB` in Befunge-93
* `elif MOC SODeerF` in FreeDOS COM file
* `><>loG` in Gol><>
* `89-egnufenU` in Unefunge-98
* `79-egnufeB` in Befunge-97
* `69-egnufeB` in Befunge-96
* `kcufniarb` in brainfuck
* `89-egnuferT` in Trefunge-98
* `kalf-niarb` in brain-flak
* `hsab` in bash
* `lleksaH` in Haskell
* `hsz` in zsh
* `ijome` in emoji
* `snrettaPgnaB+lleksaH` in Haskell+BangPatterns
* `++C` in C++
* `nocimonitomE` in Emotinomicon
* `hsk` in ksh
* `hsad` in dash
* `79-egnuferT` in Trefunge-97
* `ecilA` in Alice
* `79-egnuferdauQ` in Quadrefunge-97
* `99` in 99
* `79-egnufetniuQ` in Quintefunge-97
[Try it online!](https://tio.run/##rTrLcttIkmfhF@ZSAtUGIBIEKdmyRJFsvWXN2JbGUvd4TdEcECiSsPDg4CFRVmsi5gemI/a0sYed2MtG7MbsZSP2vBHzKf6C@QNvZj1A8GF3R@/SFllV@azMrMwskH07GX3@XCL7rktsQod2NgztlySNYDaO/PuhH6UkpUlKRnYc0iQh/Xvy2qNHH@mHm6ivlMhh5Pv2OKFEPYxcqhI7dIm6Hw@zgIZpopKEOqkXhQkZRDHp0zSlMaGTMY09GjpUURw7JW3iAK3ih8RM2JC9VfsDUiIHdJCFQ2rubCpplDkjMo49YKyAaG9A7qOM2Ki7FFghgX1DSZLFFHcRRK43uCegQXV8T5KIpCOQl47oPZBQ4oWOn7nUhQEuEt8LbxTqjCJihkRdq6ugGqctrG7gqhsls6ubuJpEQUDNgTdBmDK@T0dRuDm3@nL/9el3@6fHvbPXR8dvW3Xl4B@uji9b6pp@5xDTaeLWDVWBXTPDEd8Oh5k9pLrxoKwweWqJrM1yqZK1eoWsMU7gIXCYKnHfZGHohUPCNvNkQ1npg8tBDttIO8rScZYKXLHnH2J620YXOSl1JZv5dTP0lRVwwCpxgjHhbIgEkidPlgOAahcNHSornO/v4gh041hV8oJO3CwYNwA6mbhEKjfwlJU5q4G19DkblOuGke/aJNe/X9MxtjgT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jP5FYmFDoMsnObHCHJeJ396wSyEY2m0Q/rSsIaoSt/MwH2MMzx/xCpJu1hqF08WXnv00t/fLuJVA5ac1kFSbPDvBn@/AdvrUj@6Q69b2lKs4fEsV2tppLKQ7Bni@NWUwn4qLCQdKfyGbcKaO25hGPF455cThV0PxqBEmDVLowKZtHR46Q1C59GdTmVMq3PMi2dQSgiRHj8ZfFSISjKHgzQxuVHRSkRc0GmYBjW04vHjBw@PNfqLFLjWF6EHUj95Yj@1wSHX0XAUctwXv23BJ6hQtJOjEzuVM7CifMo27rL0pBmlH3GiYkuzBGH8OpxeQmO6QOmdONIMvS0hpfI9CRnbo@uxmPCOOTaAjxK/24BT9ht4f40ErnDg1C2/C6C4s0jX4cYN53vsJ/rrxef6BYf6s0OGXb/mgsJqMfciH2nUIRxWf@yG8Y0K6LgFFkgX8wSflvxzj38p74mEmBU9DKccvLZXUjmHTwFjdT7zGdrnR2Cg3nj5fN4PKrqrkuVFVufcrzqzbOTlrEVr8y1Vzc4NHgY@YKLchWmbYk29Af@I1EpMh@x2vy/Gn2RBTavLNzrPy5oZ8ps1/2sRZqRXxY6z/BQ)
Next answer must not exceed 1626 bytes.
## Hexdump
```
00000000: 766f 6964 202f 2a2d 7b2d 2d20 2368 5221 void /*-{-- #hR!
00000010: 582d 4020 505e 687e 7e58 4040 3044 2030 X-@ P^h~~X@@0D 0
00000020: 4422 6876 2158 2d40 2050 5a68 202b 5835 D"hv!X-@ PZh +X5
00000030: 2022 4d21 4d20 656c 6966 204d 4f43 2053 "M!M elif MOC S
00000040: 4f44 6565 7246 247d 2b2b 2b2b 5b2a 2f2f ODeerF$}++++[*//
00000050: 2f5c 0a20 2f2b 2023 5c0a 2062 6173 656e /\. /+ #\. basen
00000060: 616d 6520 2224 2872 6561 646c 696e 6b20 ame "$(readlink
00000070: 2f70 726f 632f 2424 2f65 7865 2922 7c72 /proc/$$/exe)"|r
00000080: 6576 3b3a 3c3c 2745 4f46 2720 233e 3e5c ev;:<<'EOF' #>>\
00000090: 0a31 2b2f 2f2f 2020 2020 2020 2020 2020 .1+///
000000a0: 2020 2020 2020 2020 4f5c 0a2f 2a20 1b67 O\./* .g
000000b0: 6763 476d 6956 1b5a 5a3b 6f6f 6f22 6c6f gcGmiV.ZZ;ooo"lo
000000c0: 4722 3b3f 3d30 2553 2131 316f 6f6f 3c22 G";?=0%S!11ooo<"
000000d0: 3e3c 3e22 0a23 6465 6669 6e65 2053 2243 ><>".#define S"C
000000e0: 2220 2020 2020 2020 2f2f 410a 2369 6664 " //A.#ifd
000000f0: 6566 205f 5f63 706c 7573 706c 7573 2f2f ef __cplusplus//
00000100: 6c0a 2066 2829 3b20 2020 2020 2020 2020 l. f();
00000110: 2020 202f 2f69 0a23 696e 636c 7564 653c //i.#include<
00000120: 6373 7464 696f 3e2f 2f63 0a23 6465 6669 cstdio>//c.#defi
00000130: 6e65 2053 222b 2b43 2220 2f2f 650a 2069 ne S"++C" //e. i
00000140: 6e74 2f2f 2f20 2020 2020 2020 2020 220a nt/// ".
00000150: 2365 6e64 6966 2f2f 2020 2020 2020 205c #endif// \
00000160: 2e0a 2369 6664 6566 205f 5f4f 424a 435f ..#ifdef __OBJC_
00000170: 5f0a 2364 6566 696e 6520 5322 432d 6576 _.#define S"C-ev
00000180: 6974 6365 6a62 4f22 0a23 656e 6469 660a itcejbO".#endif.
00000190: 206d 6169 6e28 297b 7072 696e 7466 2853 main(){printf(S
000001a0: 292f 2a2f 6d61 696e 2829 7b69 6d70 6f72 )/*/main(){impor
000001b0: 7420 7374 642e 7374 6469 6f3b 2244 222e t std.stdio;"D".
000001c0: 7772 6974 652f 2a2a 2f3b 7d2f 2a7d 3c0a write/**/;}/*}<.
000001d0: 3e20 2076 0a39 3939 2039 3939 2039 390a > v.999 999 99.
000001e0: 3939 3920 3939 3920 390a 3939 3976 3c3e 999 999 9.999v<>
000001f0: 0a76 2020 3c3e 2265 6675 6e67 652d 3938 .v <>"efunge-98
00000200: 222c 2c2c 2c2c 2c2c 2c2c 3779 332d 763c ",,,,,,,,,7y3-v<
00000210: 0a3e 2020 235e 4776 2020 2020 2020 2020 .> #^Gv
00000220: 2020 2020 2020 2020 2040 2c22 4222 5f22 @,"B"_"
00000230: 5472 222c 2c40 0a20 2020 763c 5b5f 225d Tr",,@. v<[_"]
00000240: 4265 6675 6e67 652d 3933 223e 2c2c 2c2c Befunge-93">,,,,
00000250: 2c2c 2c2c 2c2c 403c 0a20 2020 3e23 3c22 ,,,,,,@<. >#<"
00000260: 4265 6675 6e67 652d 3936 223e 205e 7624 Befunge-96"> ^v$
00000270: 4730 3031 0a76 2020 2c2c 2c2c 2c22 3739 G001.v ,,,,,"79
00000280: 2d65 676e 7566 6542 2220 5f20 2020 2020 -egnufeB" _
00000290: 2020 2020 2020 2020 2020 2020 2076 3c0a v<.
000002a0: 3e20 202c 2c2c 2c2c 4023 2020 2020 2020 > ,,,,,@#
000002b0: 2c22 3739 2d65 676e 7566 6572 5422 5f76 ,"79-egnuferT"_v
000002c0: 2320 2447 3030 3031 3c3e 0a20 2020 2020 # $G0001<>.
000002d0: 2020 2020 2020 2020 2020 2020 2020 2020
000002e0: 2020 2020 2020 2020 203c 3e31 3030 3030 <>10000
000002f0: 4724 760a 2020 2020 2023 402c 2c2c 2c2c G$v. #@,,,,,
00000300: 2c2c 2c2c 2c2c 2c2c 2c40 2322 3739 2d65 ,,,,,,,,,@#"79-e
00000310: 676e 7566 6572 6461 7551 225f 2251 7569 gnuferdauQ"_"Qui
00000320: 6e74 6566 756e 6765 2d39 3722 0a2e 6c20 ntefunge-97"..l
00000330: 2020 2020 2020 202e 2020 2020 2020 202a . *
00000340: 2f2f 2f7b 7d5d e28e 9ac2 bfe2 81b5 6c61 ///{}]........la
00000350: 6f63 7261 6843 c2a6 2b2b 2b2b 5b2d 3c2b ocrahC..++++[-<+
00000360: 2b2b 2b2b 3e5d 3c5b 2d3c 2b2b 2b2b 2b2b ++++>]<[-<++++++
00000370: 3c2b 2b2b 2b2b 3c2b 2b2b 2b2b 3e3e 3e5d <+++++<+++++>>>]
00000380: 3c3c 3c2b 2b2b 2b2b 2b2b 2e3e 2d2e 3e2d <<<+++++++.>-.>-
00000390: 2d2d 2e3c 3c2d 2d2d 2d2d 2e2b 2b2b 2b2b --.<<-----.+++++
000003a0: 2b2b 2b2e 2d2d 2d2d 2d2e 3e2d 2d2e 3e2d +++.-----.>--.>-
000003b0: 2d2d 2e3c 2b2e 3e3e 3e28 2828 2828 2828 --.<+.>>>(((((((
000003c0: 2828 2828 2928 2928 2929 7b7d 297b 7d29 (((()()()){}){})
000003d0: 7b7d 297b 7d28 2929 7b7d 2928 2828 2928 {}){}()){})((()(
000003e0: 2928 2928 2929 7b7d 297b 7d29 5b28 285b )()()){}){})[(([
000003f0: 5d5b 5d29 7b7d 297b 7d28 295d 2928 5b5d ][]){}){}()])([]
00000400: 2829 297b 7d29 5b5d 2829 2928 285b 5b5d ()){})[]())(([[]
00000410: 5b5d 2829 5d28 5b5d 2829 2828 2828 285b []()]([]()((((([
00000420: 5d5b 5d5b 5d29 297b 7d7b 7d29 5b5d 297b ][][])){}{})[]){
00000430: 7d29 2929 5b5d 2829 2928 7b20 2d7d 5f3d })))[]())({ -}_=
00000440: 2229 223b 2821 293d 7365 713b 6d61 696e ")";(!)=seq;main
00000450: 7c6c 6574 2062 215f 3d22 223d 7075 7453 |let b!_=""=putS
00000460: 7472 2428 2222 2122 736e 7265 7474 6150 tr$(""!"snrettaP
00000470: 676e 6142 2b22 292b 2b69 6e69 7422 6c6c gnaB+")++init"ll
00000480: 656b 7361 4828 227b 2d0a 2f2f 544a 7266 eksaH("{-.//TJrf
00000490: 2438 416c 7a4b 7835 3f78 3f49 2d7d 2d2d $8AlzKx5?x?I-}--
000004a0: 292a 2f2f 2ff0 9f92 ac69 6a6f 6d65 f09f )*///....ijome..
000004b0: 92ac e29e a1f0 9f98 ad45 6d6f 7469 6e6f .........Emotino
000004c0: 6d69 636f 6ef0 9f98 b2e2 8faa e28f ace2 micon...........
000004d0: 8fa9 402c 6b61 2238 392d 6567 6e75 6665 ..@,ka"89-egnufe
000004e0: 6e55 22 nU"
```
# Explanation
Uses the relative get command, `G` with enough arguments to distinguish it from the other befunges.
[Answer]
# 37. Grass, 2542 bytes
```
void /*-{-- #hR!X-@ P^h~~X@@0D 0D"hv!X-@ PZh +X5 "M!M elif MOC SODeerF$}++++[*///\
/+ #\
basename "$(readlink /proc/$$/exe)"|rev;:<<'EOF' #>>\
1+/// O\
/* ggcGmiVZZ;ooo"loG";?=0%S!11ooo<"><>"
#define S"C" //A
#ifdef __cplusplus//l
f(); //i
#include<cstdio>//c
#define S"++C" //e
int/// "
#endif// \.
#ifdef __OBJC__
#define S"C-evitcejbO"
#endif
main(){printf(S)/*/main(){import std.stdio;"D".write/**/;}/*}<
> vwWWWWwWWWWWwvwWWwWWWwvwWWwWWWwvwWWwWWWwvwWWwWWWwvwWWwWWWwvwWWwWWWwvWwwwwwwwwwwwWWWwWWWWWWwWWWWWWWwWWWWWWWWWwWWWWWWWWWWWWwWWWWWWWWWWwWWWWWWWWWWWWWWWWWwWWWWWWWWWWWWWWWWWWwWWWWWWWWWWWWWWWWWWwWWWWWWWWWWWWWWWWWWWwwWWWWWWWWWWWWWWWWWWWWwwwwwwWWWWWWWWWWWWWWWWWWWWWwwwwwWWWWWWWWWWWWWWWWWWWWWWwwwwwwwwwww
999 999 99
999 999 9
999v<>
v <>"efunge-98",,,,,,,,,7y3-v< @
> #^Gv @,"B"_"Tr",,@
v<[_"]Befunge-93">,,,,,,,,,,0|@<
>#<"Befunge-96"> ^v$G001
v ,,,,,"79-egnufeB" _ v<
> ,,,,,@# ,"79-egnuferT"_v# $G0001<>
<>10000G$v
#@,,,,,,,,,,,,,,@#"79-egnuferdauQ"_100000G$v
,,"79-egnufetniuQ"_1000000G$!v@,,,,,,,,,,,,
"79-egnufetpeS"_"Sexefunge-97"#@,,,,,,,,,,,,@#,
<>"v"@
@,"F","u","n","c","t","o","i","d"<> red down two red left one yellow up green down yellow up green down red up three red right two yellow down yellow down blue left green down red down one yellow down blue left green down red down two red left one yellow up yellow down blue left green down red left one red down three yellow down yellow down blue left green down red up two green down yellow up yellow down blue left red up three red right two yellow down yellow down blue left
.L .. *///{}]⎚F¹laocrahC«▲²²²²²⌂↨α↨ß↨²²⌂↨←ß≤▼→▼←≥→⌂↨σ→→→↨ß→→→↨π→→→→→↨¡ß¡→→↨δ→↨ß→→→→↨µ→→→↨¡φ↨επ⌂↨¡ß¡→→→↨¡πσ▲⌂↨¡σµ¡→↨¡α¡→↨¡π¡▲▲▲¡▲▲▲¡σ▲¡δ¡φ▲▲▲▲¡ε▼▼¡»++++[-<+++++>]<[-<++++++<+++++<+++++>>>]<<<+++++++.>-.>---.<<-----.++++++++.-----.>--.>---.<+.>>>((((((((((()()()){}){}){}){}()){})((()()()()){}){})[(([][]){}){}()])([]()){})[]())(([[][]()]([]()((((([][][])){}{})[]){})))[]())({ -}_=")";(!)=seq;main|let b!_=""=putStr$(""!"snrettaPgnaB+")++init"lleksaH("{-
//HHT-@^srEqRMM~dO-}--)*///💬ijome💬➡😭Emotinomicon😲⏪⏬⏩@,ka"89-egnufenU"
```
Prints:
* `D` in D
* `emmoS` in Somme
* `><>` in ><>
* `C` in C
* `laocrahC` in Charcoal
* `miV` in Vim
* `C-evitcejbO` in Objective-C
* `89-egnufeB` in Befunge-98
* `39-egnufeB` in Befunge-93
* `elif MOC SODeerF` in FreeDOS COM file
* `><>loG` in Gol><>
* `89-egnufenU` in Unefunge-98
* `79-egnufeB` in Befunge-97
* `69-egnufeB` in Befunge-96
* `kcufniarb` in brainfuck
* `89-egnuferT` in Trefunge-98
* `kalf-niarb` in brain-flak
* `hsab` in bash
* `lleksaH` in Haskell
* `hsz` in zsh
* `ijome` in emoji
* `snrettaPgnaB+lleksaH` in Haskell+BangPatterns
* `++C` in C++
* `nocimonitomE` in Emotinomicon
* `hsk` in ksh
* `hsad` in dash
* `79-egnuferT` in Trefunge-97
* `ecilA` in Alice
* `79-egnuferdauQ` in Quadrefunge-97
* `99` in 99
* `79-egnufetniuQ` in Quintefunge-97
* `kcufniarb cilobmys` in symbolic brainfuck
* `79-egnufexeS` in Sexefunge-97
* `senots` in stones
* `79-egnufetpeS` in Septefunge-97
* `diotcnuF` in Functoid
* `ssarG` in Grass
[Try it online!](https://tio.run/##rTrbbttIls/mL8xLmXJHpCWKkp04tixpfLcz68Se2N3JxlY0FFmUGPOi5kW247jR2AEaGGCxPZiHxmIfttHA7mIvsw/TmH5YbD9l3jv/4B/Y@YPsOVW86eIk3TO0RVWde506VXUOxa4W9N@@LZB1wyAaoT0t6rnaPgk96A08@7JneyEJaRCSvua7NAhI95I8sujWS/rizOsKBbLp2bY2CCgRNz2DikRzDSKu@73IoW4YiCSgemh5bkBMzyddGobUJ/RiQH2LujoVBF0LSYvowCvYLlEC1mS3StckBbJBzcjtUWVlUQi9SO@TgW@BYAFUWya59CKioe2JwjJxtDNKgsinOArHMyzzkoAFlcElCTwS9kFf2KeXwEKJ5ep2ZFADGggktuWeCVTve0RxiThXE8E0zpuDLiDU8IJR6CJCA89xqGJaF4gTBpdh33MXR6EJx66vBUFdCH2i6AY5fzIkDeYExAvC/vqj3Y/Xd7c7Dx5tbT9t1oSNvz3ePmqKc9K5DgyMVBYFcA3zLrE1txdpPSrJV8IMUyEWyNyolAqZq5XJHJME0wizKia0jyPXtdweYSO@syDMdCEuQA8bbcuLwkEUxrSxY175dNjCedRDaiRixuGKawszMEuzRHcGhIshCZLcuTMdAVyrOBuuMMPlPvE9sI1TVcgevTAiZ1AH7MWFQRLjTEuYGfMaeEsa80GpJsvpqBVy@qs5CQOQC5FPf4WBwJzQSuLsGiOtH4aDoK6qPSvsR92K7jnqsX/5IDxwIWKoGvqXVuglbUpVRwsgztVzXxtApAcgIZkgIuJqEonITGBtIcNtAcJwDKL4kcvWQB55hGEEBH4Ea1D1BqHKAovfK353gqHVaAF5EoWMw7SCPrvhchin3wRqRqUroa6rXctV4Xu6MZuwH@ieZqcscT9tTFPw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 5221 void /*-{-- #hR!
00000010: 582d 4020 505e 687e 7e58 4040 3044 2030 X-@ P^h~~X@@0D 0
00000020: 4422 6876 2158 2d40 2050 5a68 202b 5835 D"hv!X-@ PZh +X5
00000030: 2022 4d21 4d20 656c 6966 204d 4f43 2053 "M!M elif MOC S
00000040: 4f44 6565 7246 247d 2b2b 2b2b 5b2a 2f2f ODeerF$}++++[*//
00000050: 2f5c 0a20 2f2b 2023 5c0a 2062 6173 656e /\. /+ #\. basen
00000060: 616d 6520 2224 2872 6561 646c 696e 6b20 ame "$(readlink
00000070: 2f70 726f 632f 2424 2f65 7865 2922 7c72 /proc/$$/exe)"|r
00000080: 6576 3b3a 3c3c 2745 4f46 2720 233e 3e5c ev;:<<'EOF' #>>\
00000090: 0a31 2b2f 2f2f 2020 2020 2020 2020 2020 .1+///
000000a0: 2020 2020 2020 2020 4f5c 0a2f 2a20 1b67 O\./* .g
000000b0: 6763 476d 6956 1b5a 5a3b 6f6f 6f22 6c6f gcGmiV.ZZ;ooo"lo
000000c0: 4722 3b3f 3d30 2553 2131 316f 6f6f 3c22 G";?=0%S!11ooo<"
000000d0: 3e3c 3e22 0a23 6465 6669 6e65 2053 2243 ><>".#define S"C
000000e0: 2220 2020 2020 2020 2f2f 410a 2369 6664 " //A.#ifd
000000f0: 6566 205f 5f63 706c 7573 706c 7573 2f2f ef __cplusplus//
00000100: 6c0a 2066 2829 3b20 2020 2020 2020 2020 l. f();
00000110: 2020 202f 2f69 0a23 696e 636c 7564 653c //i.#include<
00000120: 6373 7464 696f 3e2f 2f63 0a23 6465 6669 cstdio>//c.#defi
00000130: 6e65 2053 222b 2b43 2220 2f2f 650a 2069 ne S"++C" //e. i
00000140: 6e74 2f2f 2f20 2020 2020 2020 2020 220a nt/// ".
00000150: 2365 6e64 6966 2f2f 2020 2020 2020 205c #endif// \
00000160: 2e0a 2369 6664 6566 205f 5f4f 424a 435f ..#ifdef __OBJC_
00000170: 5f0a 2364 6566 696e 6520 5322 432d 6576 _.#define S"C-ev
00000180: 6974 6365 6a62 4f22 0a23 656e 6469 660a itcejbO".#endif.
00000190: 206d 6169 6e28 297b 7072 696e 7466 2853 main(){printf(S
000001a0: 292f 2a2f 6d61 696e 2829 7b69 6d70 6f72 )/*/main(){impor
000001b0: 7420 7374 642e 7374 6469 6f3b 2244 222e t std.stdio;"D".
000001c0: 7772 6974 652f 2a2a 2f3b 7d2f 2a7d 3c0a write/**/;}/*}<.
000001d0: 3e20 2076 7757 5757 5777 5757 5757 5777 > vwWWWWwWWWWWw
000001e0: 7677 5757 7757 5757 7776 7757 5777 5757 vwWWwWWWwvwWWwWW
000001f0: 5777 7677 5757 7757 5757 7776 7757 5777 WwvwWWwWWWwvwWWw
00000200: 5757 5777 7677 5757 7757 5757 7776 7757 WWWwvwWWwWWWwvwW
00000210: 5777 5757 5777 7657 7777 7777 7777 7777 WwWWWwvWwwwwwwww
00000220: 7777 7757 5757 7757 5757 5757 5777 5757 wwwWWWwWWWWWWwWW
00000230: 5757 5757 5777 5757 5757 5757 5757 5777 WWWWWwWWWWWWWWWw
00000240: 5757 5757 5757 5757 5757 5757 7757 5757 WWWWWWWWWWWWwWWW
00000250: 5757 5757 5757 5777 5757 5757 5757 5757 WWWWWWWwWWWWWWWW
00000260: 5757 5757 5757 5757 5777 5757 5757 5757 WWWWWWWWWwWWWWWW
00000270: 5757 5757 5757 5757 5757 5757 7757 5757 WWWWWWWWWWWWwWWW
00000280: 5757 5757 5757 5757 5757 5757 5757 5777 WWWWWWWWWWWWWWWw
00000290: 5757 5757 5757 5757 5757 5757 5757 5757 WWWWWWWWWWWWWWWW
000002a0: 5757 5777 7757 5757 5757 5757 5757 5757 WWWwwWWWWWWWWWWW
000002b0: 5757 5757 5757 5757 5777 7777 7777 7757 WWWWWWWWWwwwwwwW
000002c0: 5757 5757 5757 5757 5757 5757 5757 5757 WWWWWWWWWWWWWWWW
000002d0: 5757 5757 7777 7777 7757 5757 5757 5757 WWWWwwwwwWWWWWWW
000002e0: 5757 5757 5757 5757 5757 5757 5757 5777 WWWWWWWWWWWWWWWw
000002f0: 7777 7777 7777 7777 7777 0a39 3939 2039 wwwwwwwwww.999 9
00000300: 3939 2039 390a 3939 3920 3939 3920 390a 99 99.999 999 9.
00000310: 3939 3976 3c3e 0a76 2020 3c3e 2265 6675 999v<>.v <>"efu
00000320: 6e67 652d 3938 222c 2c2c 2c2c 2c2c 2c2c nge-98",,,,,,,,,
00000330: 3779 332d 763c 2040 0a3e 2020 235e 4776 7y3-v< @.> #^Gv
00000340: 2020 2020 2020 2020 2020 2020 2020 2020
00000350: 2040 2c22 4222 5f22 5472 222c 2c40 0a20 @,"B"_"Tr",,@.
00000360: 2020 763c 5b5f 225d 4265 6675 6e67 652d v<[_"]Befunge-
00000370: 3933 223e 2c2c 2c2c 2c2c 2c2c 2c2c 307c 93">,,,,,,,,,,0|
00000380: 403c 0a20 2020 3e23 3c22 4265 6675 6e67 @<. >#<"Befung
00000390: 652d 3936 223e 205e 7624 4730 3031 0a76 e-96"> ^v$G001.v
000003a0: 2020 2c2c 2c2c 2c22 3739 2d65 676e 7566 ,,,,,"79-egnuf
000003b0: 6542 2220 5f20 2020 2020 2020 2020 2020 eB" _
000003c0: 2020 2020 2020 2076 3c0a 3e20 202c 2c2c v<.> ,,,
000003d0: 2c2c 4023 2020 2020 2020 2c22 3739 2d65 ,,@# ,"79-e
000003e0: 676e 7566 6572 5422 5f76 2320 2447 3030 gnuferT"_v# $G00
000003f0: 3031 3c3e 0a20 2020 2020 2020 2020 2020 01<>.
00000400: 2020 2020 2020 2020 2020 2020 2020 2020
00000410: 2020 203c 3e31 3030 3030 4724 760a 2020 <>10000G$v.
00000420: 2020 2023 402c 2c2c 2c2c 2c2c 2c2c 2c2c #@,,,,,,,,,,,
00000430: 2c2c 2c40 2322 3739 2d65 676e 7566 6572 ,,,@#"79-egnufer
00000440: 6461 7551 225f 3130 3030 3030 4724 760a dauQ"_100000G$v.
00000450: 2020 2020 2020 2020 2020 2020 2020 2020
00000460: 2020 2020 2020 2020 2020 2020 2020 2c2c ,,
00000470: 2237 392d 6567 6e75 6665 746e 6975 5122 "79-egnufetniuQ"
00000480: 5f31 3030 3030 3030 4724 2176 402c 2c2c _1000000G$!v@,,,
00000490: 2c2c 2c2c 2c2c 2c2c 2c0a 2020 2020 2020 ,,,,,,,,,.
000004a0: 2020 2020 2020 2020 2020 2020 2020 2020
000004b0: 2020 2020 2020 2020 2020 2020 2020 2020
000004c0: 2020 2020 2020 2237 392d 6567 6e75 6665 "79-egnufe
000004d0: 7470 6553 225f 2253 6578 6566 756e 6765 tpeS"_"Sexefunge
000004e0: 2d39 3722 2340 2c2c 2c2c 2c2c 2c2c 2c2c -97"#@,,,,,,,,,,
000004f0: 2c2c 4023 2c0a 2020 2020 2020 2020 2020 ,,@#,.
00000500: 2020 2020 2020 2020 2020 2020 2020 2020
00000510: 2020 2020 203c 3e22 7622 400a 2040 2c22 <>"v"@. @,"
00000520: 4622 2c22 7522 2c22 6e22 2c22 6322 2c22 F","u","n","c","
00000530: 7422 2c22 6f22 2c22 6922 2c22 6422 3c3e t","o","i","d"<>
00000540: 2072 6564 2064 6f77 6e20 7477 6f20 7265 red down two re
00000550: 6420 6c65 6674 206f 6e65 2079 656c 6c6f d left one yello
00000560: 7720 7570 2067 7265 656e 2064 6f77 6e20 w up green down
00000570: 7965 6c6c 6f77 2075 7020 6772 6565 6e20 yellow up green
00000580: 646f 776e 2072 6564 2075 7020 7468 7265 down red up thre
00000590: 6520 7265 6420 7269 6768 7420 7477 6f20 e red right two
000005a0: 7965 6c6c 6f77 2064 6f77 6e20 7965 6c6c yellow down yell
000005b0: 6f77 2064 6f77 6e20 626c 7565 206c 6566 ow down blue lef
000005c0: 7420 6772 6565 6e20 646f 776e 2072 6564 t green down red
000005d0: 2064 6f77 6e20 6f6e 6520 7965 6c6c 6f77 down one yellow
000005e0: 2064 6f77 6e20 626c 7565 206c 6566 7420 down blue left
000005f0: 6772 6565 6e20 646f 776e 2072 6564 2064 green down red d
00000600: 6f77 6e20 7477 6f20 7265 6420 6c65 6674 own two red left
00000610: 206f 6e65 2079 656c 6c6f 7720 7570 2079 one yellow up y
00000620: 656c 6c6f 7720 646f 776e 2062 6c75 6520 ellow down blue
00000630: 6c65 6674 2067 7265 656e 2064 6f77 6e20 left green down
00000640: 7265 6420 6c65 6674 206f 6e65 2072 6564 red left one red
00000650: 2064 6f77 6e20 7468 7265 6520 7965 6c6c down three yell
00000660: 6f77 2064 6f77 6e20 7965 6c6c 6f77 2064 ow down yellow d
00000670: 6f77 6e20 626c 7565 206c 6566 7420 6772 own blue left gr
00000680: 6565 6e20 646f 776e 2072 6564 2075 7020 een down red up
00000690: 7477 6f20 6772 6565 6e20 646f 776e 2079 two green down y
000006a0: 656c 6c6f 7720 7570 2079 656c 6c6f 7720 ellow up yellow
000006b0: 646f 776e 2062 6c75 6520 6c65 6674 2072 down blue left r
000006c0: 6564 2075 7020 7468 7265 6520 7265 6420 ed up three red
000006d0: 7269 6768 7420 7477 6f20 7965 6c6c 6f77 right two yellow
000006e0: 2064 6f77 6e20 7965 6c6c 6f77 2064 6f77 down yellow dow
000006f0: 6e20 626c 7565 206c 6566 740a 2e4c 2020 n blue left..L
00000700: 2020 2020 2020 2020 202e 2e20 2020 2a2f .. */
00000710: 2f2f 7b7d 5de2 8e9a efbc a6c2 b96c 616f //{}]........lao
00000720: 6372 6168 43c2 abe2 96b2 c2b2 c2b2 c2b2 crahC...........
00000730: c2b2 c2b2 e28c 82e2 86a8 ceb1 e286 a8c3 ................
00000740: 9fe2 86a8 c2b2 c2b2 e28c 82e2 86a8 e286 ................
00000750: 90c3 9fe2 89a4 e296 bce2 8692 e296 bce2 ................
00000760: 8690 e289 a5e2 8692 e28c 82e2 86a8 cf83 ................
00000770: e286 92e2 8692 e286 92e2 86a8 c39f e286 ................
00000780: 92e2 8692 e286 92e2 86a8 cf80 e286 92e2 ................
00000790: 8692 e286 92e2 8692 e286 92e2 86a8 c2a1 ................
000007a0: c39f c2a1 e286 92e2 8692 e286 a8ce b4e2 ................
000007b0: 8692 e286 a8c3 9fe2 8692 e286 92e2 8692 ................
000007c0: e286 92e2 86a8 c2b5 e286 92e2 8692 e286 ................
000007d0: 92e2 86a8 c2a1 cf86 e286 a8ce b5cf 80e2 ................
000007e0: 8c82 e286 a8c2 a1c3 9fc2 a1e2 8692 e286 ................
000007f0: 92e2 8692 e286 a8c2 a1cf 80cf 83e2 96b2 ................
00000800: e28c 82e2 86a8 c2a1 cf83 c2b5 c2a1 e286 ................
00000810: 92e2 86a8 c2a1 ceb1 c2a1 e286 92e2 86a8 ................
00000820: c2a1 cf80 c2a1 e296 b2e2 96b2 e296 b2c2 ................
00000830: a1e2 96b2 e296 b2e2 96b2 c2a1 cf83 e296 ................
00000840: b2c2 a1ce b4c2 a1cf 86e2 96b2 e296 b2e2 ................
00000850: 96b2 e296 b2c2 a1ce b5e2 96bc e296 bcc2 ................
00000860: a1c2 bb2b 2b2b 2b5b 2d3c 2b2b 2b2b 2b3e ...++++[-<+++++>
00000870: 5d3c 5b2d 3c2b 2b2b 2b2b 2b3c 2b2b 2b2b ]<[-<++++++<++++
00000880: 2b3c 2b2b 2b2b 2b3e 3e3e 5d3c 3c3c 2b2b +<+++++>>>]<<<++
00000890: 2b2b 2b2b 2b2e 3e2d 2e3e 2d2d 2d2e 3c3c +++++.>-.>---.<<
000008a0: 2d2d 2d2d 2d2e 2b2b 2b2b 2b2b 2b2b 2e2d -----.++++++++.-
000008b0: 2d2d 2d2d 2e3e 2d2d 2e3e 2d2d 2d2e 3c2b ----.>--.>---.<+
000008c0: 2e3e 3e3e 2828 2828 2828 2828 2828 2829 .>>>((((((((((()
000008d0: 2829 2829 297b 7d29 7b7d 297b 7d29 7b7d ()()){}){}){}){}
000008e0: 2829 297b 7d29 2828 2829 2829 2829 2829 ()){})((()()()()
000008f0: 297b 7d29 7b7d 295b 2828 5b5d 5b5d 297b ){}){})[(([][]){
00000900: 7d29 7b7d 2829 5d29 285b 5d28 2929 7b7d }){}()])([]()){}
00000910: 295b 5d28 2929 2828 5b5b 5d5b 5d28 295d )[]())(([[][]()]
00000920: 285b 5d28 2928 2828 2828 5b5d 5b5d 5b5d ([]()((((([][][]
00000930: 2929 7b7d 7b7d 295b 5d29 7b7d 2929 295b )){}{})[]){})))[
00000940: 5d28 2929 287b 202d 7d5f 3d22 2922 3b28 ]())({ -}_=")";(
00000950: 2129 3d73 6571 3b6d 6169 6e7c 6c65 7420 !)=seq;main|let
00000960: 6221 5f3d 2222 3d70 7574 5374 7224 2822 b!_=""=putStr$("
00000970: 2221 2273 6e72 6574 7461 5067 6e61 422b "!"snrettaPgnaB+
00000980: 2229 2b2b 696e 6974 226c 6c65 6b73 6148 ")++init"lleksaH
00000990: 2822 7b2d 0a2f 2f48 4854 2d40 5e73 7245 ("{-.//HHT-@^srE
000009a0: 7152 4d4d 7e64 4f2d 7d2d 2d29 2a2f 2f2f qRMM~dO-}--)*///
000009b0: f09f 92ac 696a 6f6d 65f0 9f92 ace2 9ea1 ....ijome.......
000009c0: f09f 98ad 456d 6f74 696e 6f6d 6963 6f6e ....Emotinomicon
000009d0: f09f 98b2 e28f aae2 8fac e28f a940 2c6b .............@,k
000009e0: 6122 3839 2d65 676e 7566 656e 5522 a"89-egnufenU"
```
[Answer]
# 39. Canvas, 2667 bytes
```
void /*-{-- #hR!X-@ P^h~~X@@0D 0D"hv!X-@ PZh +X5 "M!M elif MOC SODeerF$}++++[*///op\
/+ #\
basename "$(readlink /proc/$$/exe)"|rev;:<<'EOF' #>>\
1+/// O\
/* ggcGmiVZZ;ooo"loG";?=0%S!11ooo<"><>"
#define S"C" //A
#ifdef __cplusplus//l
f(); //i
#include<cstdio>//c
#define S"++C" //e
int/// "
#endif// \.
#ifdef __OBJC__
#define S"C-evitceJbO"
#endif
main(){printf(S)/*/main(){import std.stdio;"D".write/**/;}/*}<
> vwWWWWwWWWWWwvwWWwWWWwvwWWwWWWwvwWWwWWWwvwWWwWWWwvwWWwWWWwvwWWwWWWwvWwwwwwwwwwwwWWWwWWWWWWwWWWWWWWwWWWWWWWWWwWWWWWWWWWWWWwWWWWWWWWWWwWWWWWWWWWWWWWWWWWwWWWWWWWWWWWWWWWWWWwWWWWWWWWWWWWWWWWWWwWWWWWWWWWWWWWWWWWWWwwWWWWWWWWWWWWWWWWWWWWwwwwwwWWWWWWWWWWWWWWWWWWWWWwwwwwWWWWWWWWWWWWWWWWWWWWWWwwwwwwwwwww
999 999 99
999 999 9
999v<>
v <>"efunge-98",,,,,,,,,7y3-v< @
> #^Gv @,"B"_"Tr",,@
v<[_"]Befunge-93">,,,,,,,,,,0|@<
>#<"Befunge-96"> ^v$G001
v ,,,,,"79-egnufeB" _ v<
> ,,,,,@# ,"79-egnuferT"_v# $G0001<>
<>10000G$v
#@,,,,,,,,,,,,,,@#"79-egnuferdauQ"_100000G$v
,,"79-egnufetniuQ"_1000000G$!v@,,,,,,,,,,,,
"79-egnufetpeS"_"Sexefunge-97"#@,,,,,,,,,,,,@#,
<>"v"@
@,"F","u","n","c","t","o","i","d"<> red down two red left one yellow up green down yellow up green down red up three red right two yellow down yellow down blue left green down red down one yellow down blue left green down red down two red left one yellow up yellow down blue left green down red left one red down three yellow down yellow down blue left green down red up two green down yellow up yellow down blue left red up three red right two yellow down yellow down blue left
.L .. *///{}]⎚F¹laocrahC«▲²²²²²⌂↨α↨ß↨²²⌂↨←ß≤▼→▼←≥→⌂↨σ→→→↨ß→→→↨π→→→→→↨¡ß¡→→↨δ→↨ß→→→→↨µ→→→↨¡φ↨επ⌂↨¡ß¡→→→↨¡πσ▲⌂↨¡σµ¡→↨¡α¡→↨¡π¡▲▲▲¡▲▲▲¡σ▲¡δ¡φ▲▲▲▲¡ε▼▼¡»++++[-<+++++>]<[-<++++++<+++++<+++++>>>]<<<+++++++.>-.>---.<<-----.++++++++.-----.>--.>---.<+.>>>((((((((((()()()){}){}){}){}()){})((()()()()){}){})[(([][]){}){}()])([]()){})[]())(([[][]()]([]()((((([][][])){}{})[]){})))[]())({ -}_=")";(!)=seq;main|let b!_=""=putStr$(""!"snrettaPgnaB+")++init"lleksaH("{-
//HHT-@^srEqRMM~dO-}--)*//∙SAVNACp💬ijome💬➡😭Emotinomicon😲⏪⏬⏩@,ka"89-egnufenUsssssaaaaaeeeeeeeeeepaeeeeeeeeeecisaeeeeeeejiiiiiiiijeeeeeeeeeeeeeeeeeejiiiiiiiiiiiiijeeeeeeeejiiiijiiiiiiiiiiij"
```
Prints:
* `D` in D
* `emmoS` in Somme
* `><>` in ><>
* `C` in C
* `laocrahC` in Charcoal
* `miV` in Vim
* `C-evitceJbO` in ObJective-C
* `89-egnufeB` in Befunge-98
* `39-egnufeB` in Befunge-93
* `elif MOC SODeerF` in FreeDOS COM file
* `><>loG` in Gol><>
* `89-egnufenU` in Unefunge-98
* `79-egnufeB` in Befunge-97
* `69-egnufeB` in Befunge-96
* `kcufniarb` in brainfuck
* `89-egnuferT` in Trefunge-98
* `kalf-niarb` in brain-flak
* `hsab` in bash
* `lleksaH` in Haskell
* `hsz` in zsh
* `ijome` in emoji
* `snrettaPgnaB+lleksaH` in Haskell+BangPatterns
* `++C` in C++
* `nocimonitomE` in Emotinomicon
* `hsk` in ksh
* `hsad` in dash
* `79-egnuferT` in Trefunge-97
* `ecilA` in Alice
* `79-egnuferdauQ` in Quadrefunge-97
* `99` in 99
* `79-egnufetniuQ` in Quintefunge-97
* `kcufniarb cilobmys` in symbolic brainfuck
* `79-egnufexeS` in Sexefunge-97
* `senots` in stones
* `79-egnufetpeS` in Septefunge-97
* `diotcnuF` in Functoid
* `ssarG` in Grass
* `kcuhpla` in alphuck
* `SAVNAC` in Canvas
[Try Canvas online!](https://dzaima.github.io/Canvas/?u=dm9pZCUyMC8qLSU3Qi0tJTIwJTIzaFIlMjFYLUAlMjBQJTVFaCU3RSU3RVhAQDBEJTIwMEQlMjJodiUyMVgtQCUyMFBaaCUyMCtYNSUyMCUyMk0lMjFNJTIwZWxpZiUyME1PQyUyMFNPRGVlckYlMjQlN0Q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MjklN0IlN0QlMjklMjglMjglMjglMjklMjglMjklMjglMjklMjglMjklMjklN0IlN0QlMjklN0IlN0QlMjklNUIlMjglMjglNUIlNUQlNUIlNUQlMjklN0IlN0QlMjklN0IlN0QlMjglMjklNUQlMjklMjglNUIlNUQlMjglMjklMjklN0IlN0QlMjklNUIlNUQlMjglMjklMjklMjglMjglNUIlNUIlNUQlNUIlNUQlMjglMjklNUQlMjglNUIlNUQlMjglMjklMjglMjglMjglMjglMjglNUIlNUQlNUIlNUQlNUIlNUQlMjklMjklN0IlN0QlN0IlN0QlMjklNUIlNUQlMjklN0IlN0QlMjklMjklMjklNUIlNUQlMjglMjklMjklMjglN0IlMjAtJTdEXyUzRCUyMiUyOSUyMiUzQiUyOCUyMSUyOSUzRHNlcSUzQm1haW4lN0NsZXQlMjBiJTIxXyUzRCUyMiUyMiUzRHB1dFN0ciUyNCUyOCUyMiUyMiUyMSUyMnNucmV0dGFQZ25hQislMjIlMjkrK2luaXQlMjJsbGVrc2FIJTI4JTIyJTdCLSUwQS8vSEhULUAlNUVzckVxUk1NJTdFZE8tJTdELS0lMjkqLy8ldTIyMTlTQVZOQUMldUZGNTAvJXVEODNEJXVEQ0FDaWpvbWUldUQ4M0QldURDQUMldTI3QTEldUQ4M0QldURFMkRFbW90aW5vbWljb24ldUQ4M0QldURFMzIldTIzRUEldTIzRUMldTIzRTlAJTJDa2ElMjI4OS1lZ251ZmVuVXNzc3NzYWFhYWFlZWVlZWVlZWVlcGFlZWVlZWVlZWVlY2lzYWVlZWVlZWVqaWlpaWlpaWlqZWVlZWVlZWVlZWVlZWVlZWVlamlpaWlpaWlpaWlpaWlqZWVlZWVlZWVqaWlpaWppaWlpaWlpaWlpaWolMjI_,v=3)
[Try it online!](https://tio.run/##rTrbcttGls/CL8xLC1RMQCQIUrJliSIZ3W1nbEtjKbbXEs0BgSYJCRcGF0qyrFRqpiq1U7W1Sc1DancfNpWq3a29zD5MavIwtdkXz3v8D/qBmT/wntPdAMGLbCezkAh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9lWh4RKfLPUtYHF9xiXi/L9LHkbM0IxQsnSxvUCQqx13rOnyyODnNpOGT5AvS5GkoIgrqNbb28K2FIO5H18RwBo/Ru8ASrrSO48fSFDKWL2EdzsUuK9lqQhXVBMrnNMhTXmG7tXhbsE7yeZYwWVYwnBOoLliyeNqzHcqE8fTNo6dAZPYChSlDJpURcn5e7vFEkZGC9DkoStpwJJwwhNAKhIBHCK9oOTj5lTh7WotDJf@xZ7uQKuADC/aeabRQIelrm3CyYJudKfnMjn4ts/Ah8KWdlFliExeL121ZUQiOtqqEPy2rilOJ@7mbtjGGx5d4EVkXy9XM6uKgW@@W9nyatByYfLMMmspnt3bwjV0YTps6/ilKXVoeShWLb6pBSyvVie2OIW4vDQWMb8XZDQeO/sxuwoWaVnUY8VhyJh2Tl4biUSN0qiSTgQ3TOlx0quCy6HtzaUMuHPMk29ATgiUl9/tvVSI2GFXCygwqKnpWTAo06sUuDQxYvFjg4fJmb2WzoiYTPUj6wu4rgeF1qYIzV4SJW4L7MhRJh1kPCT4x8qQnRpR2mcVNlt5kg/RQVDTMSPZgjD@HUzJEzHbYOkdWNMNP25Ci4ByV9AzPclhlPKKOdSAjxFcsYBX9nJ5v40LLrDg59k48/O0nw1flyw36ae4n5Cvqm/EHhumzQpMX38mDwlLYd2A/zB95sFTxuR/iDzXYrnPAEcYuf/BJ@cvi/I0oWzzMpDDTcJTjyyMSfykJBMvroV1dLlSrC4XqzdvzmltclaV0b5RlPvtFc3TaOTtLEer8JRdtcYFHgYOUqLcqUmYYk6NCfmJXQ40RO4d2k9MPd0PcUsMPVm4VFheSZ9r8RWUuSi6KV6v/Dw)
Next answer must not exceed 3467 bytes.
## Hexdump
```
00000000: 766f 6964 202f 2a2d 7b2d 2d20 2368 5221 void /*-{-- #hR!
00000010: 582d 4020 505e 687e 7e58 4040 3044 2030 X-@ P^h~~X@@0D 0
00000020: 4422 6876 2158 2d40 2050 5a68 202b 5835 D"hv!X-@ PZh +X5
00000030: 2022 4d21 4d20 656c 6966 204d 4f43 2053 "M!M elif MOC S
00000040: 4f44 6565 7246 247d 2b2b 2b2b 5b2a 2f2f ODeerF$}++++[*//
00000050: 2f6f 705c 0a20 2f2b 2023 5c0a 2062 6173 /op\. /+ #\. bas
00000060: 656e 616d 6520 2224 2872 6561 646c 696e ename "$(readlin
00000070: 6b20 2f70 726f 632f 2424 2f65 7865 2922 k /proc/$$/exe)"
00000080: 7c72 6576 3b3a 3c3c 2745 4f46 2720 233e |rev;:<<'EOF' #>
00000090: 3e5c 0a31 2b2f 2f2f 2020 2020 2020 2020 >\.1+///
000000a0: 2020 2020 2020 2020 2020 4f5c 0a2f 2a20 O\./*
000000b0: 1b67 6763 476d 6956 1b5a 5a3b 6f6f 6f22 .ggcGmiV.ZZ;ooo"
000000c0: 6c6f 4722 3b3f 3d30 2553 2131 316f 6f6f loG";?=0%S!11ooo
000000d0: 3c22 3e3c 3e22 0a23 6465 6669 6e65 2053 <"><>".#define S
000000e0: 2243 2220 2020 2020 2020 2f2f 410a 2369 "C" //A.#i
000000f0: 6664 6566 205f 5f63 706c 7573 706c 7573 fdef __cplusplus
00000100: 2f2f 6c0a 2066 2829 3b20 2020 2020 2020 //l. f();
00000110: 2020 2020 202f 2f69 0a23 696e 636c 7564 //i.#includ
00000120: 653c 6373 7464 696f 3e2f 2f63 0a23 6465 e<cstdio>//c.#de
00000130: 6669 6e65 2053 222b 2b43 2220 2f2f 650a fine S"++C" //e.
00000140: 2069 6e74 2f2f 2f20 2020 2020 2020 2020 int///
00000150: 220a 2365 6e64 6966 2f2f 2020 2020 2020 ".#endif//
00000160: 205c 2e0a 2369 6664 6566 205f 5f4f 424a \..#ifdef __OBJ
00000170: 435f 5f0a 2364 6566 696e 6520 5322 432d C__.#define S"C-
00000180: 6576 6974 6365 4a62 4f22 0a23 656e 6469 evitceJbO".#endi
00000190: 660a 206d 6169 6e28 297b 7072 696e 7466 f. main(){printf
000001a0: 2853 292f 2a2f 6d61 696e 2829 7b69 6d70 (S)/*/main(){imp
000001b0: 6f72 7420 7374 642e 7374 6469 6f3b 2244 ort std.stdio;"D
000001c0: 222e 7772 6974 652f 2a2a 2f3b 7d2f 2a7d ".write/**/;}/*}
000001d0: 3c0a 3e20 2076 7757 5757 5777 5757 5757 <.> vwWWWWwWWWW
000001e0: 5777 7677 5757 7757 5757 7776 7757 5777 WwvwWWwWWWwvwWWw
000001f0: 5757 5777 7677 5757 7757 5757 7776 7757 WWWwvwWWwWWWwvwW
00000200: 5777 5757 5777 7677 5757 7757 5757 7776 WwWWWwvwWWwWWWwv
00000210: 7757 5777 5757 5777 7657 7777 7777 7777 wWWwWWWwvWwwwwww
00000220: 7777 7777 7757 5757 7757 5757 5757 5777 wwwwwWWWwWWWWWWw
00000230: 5757 5757 5757 5777 5757 5757 5757 5757 WWWWWWWwWWWWWWWW
00000240: 5777 5757 5757 5757 5757 5757 5757 7757 WwWWWWWWWWWWWWwW
00000250: 5757 5757 5757 5757 5777 5757 5757 5757 WWWWWWWWWwWWWWWW
00000260: 5757 5757 5757 5757 5757 5777 5757 5757 WWWWWWWWWWWwWWWW
00000270: 5757 5757 5757 5757 5757 5757 5757 7757 WWWWWWWWWWWWWWwW
00000280: 5757 5757 5757 5757 5757 5757 5757 5757 WWWWWWWWWWWWWWWW
00000290: 5777 5757 5757 5757 5757 5757 5757 5757 WwWWWWWWWWWWWWWW
000002a0: 5757 5757 5777 7757 5757 5757 5757 5757 WWWWWwwWWWWWWWWW
000002b0: 5757 5757 5757 5757 5757 5777 7777 7777 WWWWWWWWWWWwwwww
000002c0: 7757 5757 5757 5757 5757 5757 5757 5757 wWWWWWWWWWWWWWWW
000002d0: 5757 5757 5757 7777 7777 7757 5757 5757 WWWWWWwwwwwWWWWW
000002e0: 5757 5757 5757 5757 5757 5757 5757 5757 WWWWWWWWWWWWWWWW
000002f0: 5777 7777 7777 7777 7777 7777 0a39 3939 Wwwwwwwwwwww.999
00000300: 2039 3939 2039 390a 3939 3920 3939 3920 999 99.999 999
00000310: 390a 3939 3976 3c3e 0a76 2020 3c3e 2265 9.999v<>.v <>"e
00000320: 6675 6e67 652d 3938 222c 2c2c 2c2c 2c2c funge-98",,,,,,,
00000330: 2c2c 3779 332d 763c 2040 0a3e 2020 235e ,,7y3-v< @.> #^
00000340: 4776 2020 2020 2020 2020 2020 2020 2020 Gv
00000350: 2020 2040 2c22 4222 5f22 5472 222c 2c40 @,"B"_"Tr",,@
00000360: 0a20 2020 763c 5b5f 225d 4265 6675 6e67 . v<[_"]Befung
00000370: 652d 3933 223e 2c2c 2c2c 2c2c 2c2c 2c2c e-93">,,,,,,,,,,
00000380: 307c 403c 0a20 2020 3e23 3c22 4265 6675 0|@<. >#<"Befu
00000390: 6e67 652d 3936 223e 205e 7624 4730 3031 nge-96"> ^v$G001
000003a0: 0a76 2020 2c2c 2c2c 2c22 3739 2d65 676e .v ,,,,,"79-egn
000003b0: 7566 6542 2220 5f20 2020 2020 2020 2020 ufeB" _
000003c0: 2020 2020 2020 2020 2076 3c0a 3e20 202c v<.> ,
000003d0: 2c2c 2c2c 4023 2020 2020 2020 2c22 3739 ,,,,@# ,"79
000003e0: 2d65 676e 7566 6572 5422 5f76 2320 2447 -egnuferT"_v# $G
000003f0: 3030 3031 3c3e 0a20 2020 2020 2020 2020 0001<>.
00000400: 2020 2020 2020 2020 2020 2020 2020 2020
00000410: 2020 2020 203c 3e31 3030 3030 4724 760a <>10000G$v.
00000420: 2020 2020 2023 402c 2c2c 2c2c 2c2c 2c2c #@,,,,,,,,,
00000430: 2c2c 2c2c 2c40 2322 3739 2d65 676e 7566 ,,,,,@#"79-egnuf
00000440: 6572 6461 7551 225f 3130 3030 3030 4724 erdauQ"_100000G$
00000450: 760a 2020 2020 2020 2020 2020 2020 2020 v.
00000460: 2020 2020 2020 2020 2020 2020 2020 2020
00000470: 2c2c 2237 392d 6567 6e75 6665 746e 6975 ,,"79-egnufetniu
00000480: 5122 5f31 3030 3030 3030 4724 2176 402c Q"_1000000G$!v@,
00000490: 2c2c 2c2c 2c2c 2c2c 2c2c 2c0a 2020 2020 ,,,,,,,,,,,.
000004a0: 2020 2020 2020 2020 2020 2020 2020 2020
000004b0: 2020 2020 2020 2020 2020 2020 2020 2020
000004c0: 2020 2020 2020 2020 2237 392d 6567 6e75 "79-egnu
000004d0: 6665 7470 6553 225f 2253 6578 6566 756e fetpeS"_"Sexefun
000004e0: 6765 2d39 3722 2340 2c2c 2c2c 2c2c 2c2c ge-97"#@,,,,,,,,
000004f0: 2c2c 2c2c 4023 2c0a 2020 2020 2020 2020 ,,,,@#,.
00000500: 2020 2020 2020 2020 2020 2020 2020 2020
00000510: 2020 2020 2020 203c 3e22 7622 400a 2040 <>"v"@. @
00000520: 2c22 4622 2c22 7522 2c22 6e22 2c22 6322 ,"F","u","n","c"
00000530: 2c22 7422 2c22 6f22 2c22 6922 2c22 6422 ,"t","o","i","d"
00000540: 3c3e 2072 6564 2064 6f77 6e20 7477 6f20 <> red down two
00000550: 7265 6420 6c65 6674 206f 6e65 2079 656c red left one yel
00000560: 6c6f 7720 7570 2067 7265 656e 2064 6f77 low up green dow
00000570: 6e20 7965 6c6c 6f77 2075 7020 6772 6565 n yellow up gree
00000580: 6e20 646f 776e 2072 6564 2075 7020 7468 n down red up th
00000590: 7265 6520 7265 6420 7269 6768 7420 7477 ree red right tw
000005a0: 6f20 7965 6c6c 6f77 2064 6f77 6e20 7965 o yellow down ye
000005b0: 6c6c 6f77 2064 6f77 6e20 626c 7565 206c llow down blue l
000005c0: 6566 7420 6772 6565 6e20 646f 776e 2072 eft green down r
000005d0: 6564 2064 6f77 6e20 6f6e 6520 7965 6c6c ed down one yell
000005e0: 6f77 2064 6f77 6e20 626c 7565 206c 6566 ow down blue lef
000005f0: 7420 6772 6565 6e20 646f 776e 2072 6564 t green down red
00000600: 2064 6f77 6e20 7477 6f20 7265 6420 6c65 down two red le
00000610: 6674 206f 6e65 2079 656c 6c6f 7720 7570 ft one yellow up
00000620: 2079 656c 6c6f 7720 646f 776e 2062 6c75 yellow down blu
00000630: 6520 6c65 6674 2067 7265 656e 2064 6f77 e left green dow
00000640: 6e20 7265 6420 6c65 6674 206f 6e65 2072 n red left one r
00000650: 6564 2064 6f77 6e20 7468 7265 6520 7965 ed down three ye
00000660: 6c6c 6f77 2064 6f77 6e20 7965 6c6c 6f77 llow down yellow
00000670: 2064 6f77 6e20 626c 7565 206c 6566 7420 down blue left
00000680: 6772 6565 6e20 646f 776e 2072 6564 2075 green down red u
00000690: 7020 7477 6f20 6772 6565 6e20 646f 776e p two green down
000006a0: 2079 656c 6c6f 7720 7570 2079 656c 6c6f yellow up yello
000006b0: 7720 646f 776e 2062 6c75 6520 6c65 6674 w down blue left
000006c0: 2072 6564 2075 7020 7468 7265 6520 7265 red up three re
000006d0: 6420 7269 6768 7420 7477 6f20 7965 6c6c d right two yell
000006e0: 6f77 2064 6f77 6e20 7965 6c6c 6f77 2064 ow down yellow d
000006f0: 6f77 6e20 626c 7565 206c 6566 740a 2e4c own blue left..L
00000700: 2020 2020 2020 2020 2020 202e 2e20 2020 ..
00000710: 2a2f 2f2f 7b7d 5de2 8e9a efbc a6c2 b96c *///{}]........l
00000720: 616f 6372 6168 43c2 abe2 96b2 c2b2 c2b2 aocrahC.........
00000730: c2b2 c2b2 c2b2 e28c 82e2 86a8 ceb1 e286 ................
00000740: a8c3 9fe2 86a8 c2b2 c2b2 e28c 82e2 86a8 ................
00000750: e286 90c3 9fe2 89a4 e296 bce2 8692 e296 ................
00000760: bce2 8690 e289 a5e2 8692 e28c 82e2 86a8 ................
00000770: cf83 e286 92e2 8692 e286 92e2 86a8 c39f ................
00000780: e286 92e2 8692 e286 92e2 86a8 cf80 e286 ................
00000790: 92e2 8692 e286 92e2 8692 e286 92e2 86a8 ................
000007a0: c2a1 c39f c2a1 e286 92e2 8692 e286 a8ce ................
000007b0: b4e2 8692 e286 a8c3 9fe2 8692 e286 92e2 ................
000007c0: 8692 e286 92e2 86a8 c2b5 e286 92e2 8692 ................
000007d0: e286 92e2 86a8 c2a1 cf86 e286 a8ce b5cf ................
000007e0: 80e2 8c82 e286 a8c2 a1c3 9fc2 a1e2 8692 ................
000007f0: e286 92e2 8692 e286 a8c2 a1cf 80cf 83e2 ................
00000800: 96b2 e28c 82e2 86a8 c2a1 cf83 c2b5 c2a1 ................
00000810: e286 92e2 86a8 c2a1 ceb1 c2a1 e286 92e2 ................
00000820: 86a8 c2a1 cf80 c2a1 e296 b2e2 96b2 e296 ................
00000830: b2c2 a1e2 96b2 e296 b2e2 96b2 c2a1 cf83 ................
00000840: e296 b2c2 a1ce b4c2 a1cf 86e2 96b2 e296 ................
00000850: b2e2 96b2 e296 b2c2 a1ce b5e2 96bc e296 ................
00000860: bcc2 a1c2 bb2b 2b2b 2b5b 2d3c 2b2b 2b2b .....++++[-<++++
00000870: 2b3e 5d3c 5b2d 3c2b 2b2b 2b2b 2b3c 2b2b +>]<[-<++++++<++
00000880: 2b2b 2b3c 2b2b 2b2b 2b3e 3e3e 5d3c 3c3c +++<+++++>>>]<<<
00000890: 2b2b 2b2b 2b2b 2b2e 3e2d 2e3e 2d2d 2d2e +++++++.>-.>---.
000008a0: 3c3c 2d2d 2d2d 2d2e 2b2b 2b2b 2b2b 2b2b <<-----.++++++++
000008b0: 2e2d 2d2d 2d2d 2e3e 2d2d 2e3e 2d2d 2d2e .-----.>--.>---.
000008c0: 3c2b 2e3e 3e3e 2828 2828 2828 2828 2828 <+.>>>((((((((((
000008d0: 2829 2829 2829 297b 7d29 7b7d 297b 7d29 ()()()){}){}){})
000008e0: 7b7d 2829 297b 7d29 2828 2829 2829 2829 {}()){})((()()()
000008f0: 2829 297b 7d29 7b7d 295b 2828 5b5d 5b5d ()){}){})[(([][]
00000900: 297b 7d29 7b7d 2829 5d29 285b 5d28 2929 ){}){}()])([]())
00000910: 7b7d 295b 5d28 2929 2828 5b5b 5d5b 5d28 {})[]())(([[][](
00000920: 295d 285b 5d28 2928 2828 2828 5b5d 5b5d )]([]()((((([][]
00000930: 5b5d 2929 7b7d 7b7d 295b 5d29 7b7d 2929 [])){}{})[]){}))
00000940: 295b 5d28 2929 287b 202d 7d5f 3d22 2922 )[]())({ -}_=")"
00000950: 3b28 2129 3d73 6571 3b6d 6169 6e7c 6c65 ;(!)=seq;main|le
00000960: 7420 6221 5f3d 2222 3d70 7574 5374 7224 t b!_=""=putStr$
00000970: 2822 2221 2273 6e72 6574 7461 5067 6e61 (""!"snrettaPgna
00000980: 422b 2229 2b2b 696e 6974 226c 6c65 6b73 B+")++init"lleks
00000990: 6148 2822 7b2d 0a2f 2f48 4854 2d40 5e73 aH("{-.//HHT-@^s
000009a0: 7245 7152 4d4d 7e64 4f2d 7d2d 2d29 2a2f rEqRMM~dO-}--)*/
000009b0: 2fe2 8899 5341 564e 4143 efbd 90f0 9f92 /...SAVNAC......
000009c0: ac69 6a6f 6d65 f09f 92ac e29e a1f0 9f98 .ijome..........
000009d0: ad45 6d6f 7469 6e6f 6d69 636f 6ef0 9f98 .Emotinomicon...
000009e0: b2e2 8faa e28f ace2 8fa9 402c 6b61 2238 ..........@,ka"8
000009f0: 392d 6567 6e75 6665 6e55 7373 7373 7361 9-egnufenUsssssa
00000a00: 6161 6161 6565 6565 6565 6565 6565 7061 aaaaeeeeeeeeeepa
00000a10: 6565 6565 6565 6565 6565 6369 7361 6565 eeeeeeeeeecisaee
00000a20: 6565 6565 656a 6969 6969 6969 6969 6a65 eeeeejiiiiiiiije
00000a30: 6565 6565 6565 6565 6565 6565 6565 6565 eeeeeeeeeeeeeeee
00000a40: 656a 6969 6969 6969 6969 6969 6969 696a ejiiiiiiiiiiiiij
00000a50: 6565 6565 6565 6565 6a69 6969 696a 6969 eeeeeeeejiiiijii
00000a60: 6969 6969 6969 6969 696a 22 iiiiiiiiij"
```
[Answer]
# 38. alphuck, 2656 bytes
```
void /*-{-- #hR!X-@ P^h~~X@@0D 0D"hv!X-@ PZh +X5 "M!M elif MOC SODeerF$}++++[*///op\
/+ #\
basename "$(readlink /proc/$$/exe)"|rev;:<<'EOF' #>>\
1+/// O\
/* ggcGmiVZZ;ooo"loG";?=0%S!11ooo<"><>"
#define S"C" //A
#ifdef __cplusplus//l
f(); //i
#include<cstdio>//c
#define S"++C" //e
int/// "
#endif// \.
#ifdef __OBJC__
#define S"C-evitceJbO"
#endif
main(){printf(S)/*/main(){import std.stdio;"D".write/**/;}/*}<
> vwWWWWwWWWWWwvwWWwWWWwvwWWwWWWwvwWWwWWWwvwWWwWWWwvwWWwWWWwvwWWwWWWwvWwwwwwwwwwwwWWWwWWWWWWwWWWWWWWwWWWWWWWWWwWWWWWWWWWWWWwWWWWWWWWWWwWWWWWWWWWWWWWWWWWwWWWWWWWWWWWWWWWWWWwWWWWWWWWWWWWWWWWWWwWWWWWWWWWWWWWWWWWWWwwWWWWWWWWWWWWWWWWWWWWwwwwwwWWWWWWWWWWWWWWWWWWWWWwwwwwWWWWWWWWWWWWWWWWWWWWWWwwwwwwwwwww
999 999 99
999 999 9
999v<>
v <>"efunge-98",,,,,,,,,7y3-v< @
> #^Gv @,"B"_"Tr",,@
v<[_"]Befunge-93">,,,,,,,,,,0|@<
>#<"Befunge-96"> ^v$G001
v ,,,,,"79-egnufeB" _ v<
> ,,,,,@# ,"79-egnuferT"_v# $G0001<>
<>10000G$v
#@,,,,,,,,,,,,,,@#"79-egnuferdauQ"_100000G$v
,,"79-egnufetniuQ"_1000000G$!v@,,,,,,,,,,,,
"79-egnufetpeS"_"Sexefunge-97"#@,,,,,,,,,,,,@#,
<>"v"@
@,"F","u","n","c","t","o","i","d"<> red down two red left one yellow up green down yellow up green down red up three red right two yellow down yellow down blue left green down red down one yellow down blue left green down red down two red left one yellow up yellow down blue left green down red left one red down three yellow down yellow down blue left green down red up two green down yellow up yellow down blue left red up three red right two yellow down yellow down blue left
.L .. *///{}]⎚F¹laocrahC«▲²²²²²⌂↨α↨ß↨²²⌂↨←ß≤▼→▼←≥→⌂↨σ→→→↨ß→→→↨π→→→→→↨¡ß¡→→↨δ→↨ß→→→→↨µ→→→↨¡φ↨επ⌂↨¡ß¡→→→↨¡πσ▲⌂↨¡σµ¡→↨¡α¡→↨¡π¡▲▲▲¡▲▲▲¡σ▲¡δ¡φ▲▲▲▲¡ε▼▼¡»++++[-<+++++>]<[-<++++++<+++++<+++++>>>]<<<+++++++.>-.>---.<<-----.++++++++.-----.>--.>---.<+.>>>((((((((((()()()){}){}){}){}()){})((()()()()){}){})[(([][]){}){}()])([]()){})[]())(([[][]()]([]()((((([][][])){}{})[]){})))[]())({ -}_=")";(!)=seq;main|let b!_=""=putStr$(""!"snrettaPgnaB+")++init"lleksaH("{-
//HHT-@^srEqRMM~dO-}--)*///💬ijome💬➡😭Emotinomicon😲⏪⏬⏩@,ka"89-egnufenUsssssaaaaaeeeeeeeeeepaeeeeeeeeeecisaeeeeeeejiiiiiiiijeeeeeeeeeeeeeeeeeejiiiiiiiiiiiiijeeeeeeeejiiiijiiiiiiiiiiij"
```
Prints:
* `D` in D
* `emmoS` in Somme
* `><>` in ><>
* `C` in C
* `laocrahC` in Charcoal
* `miV` in Vim
* `C-evitceJbO` in ObJective-C
* `89-egnufeB` in Befunge-98
* `39-egnufeB` in Befunge-93
* `elif MOC SODeerF` in FreeDOS COM file
* `><>loG` in Gol><>
* `89-egnufenU` in Unefunge-98
* `79-egnufeB` in Befunge-97
* `69-egnufeB` in Befunge-96
* `kcufniarb` in brainfuck
* `89-egnuferT` in Trefunge-98
* `kalf-niarb` in brain-flak
* `hsab` in bash
* `lleksaH` in Haskell
* `hsz` in zsh
* `ijome` in emoji
* `snrettaPgnaB+lleksaH` in Haskell+BangPatterns
* `++C` in C++
* `nocimonitomE` in Emotinomicon
* `hsk` in ksh
* `hsad` in dash
* `79-egnuferT` in Trefunge-97
* `ecilA` in Alice
* `79-egnuferdauQ` in Quadrefunge-97
* `99` in 99
* `79-egnufetniuQ` in Quintefunge-97
* `kcufniarb cilobmys` in symbolic brainfuck
* `79-egnufexeS` in Sexefunge-97
* `senots` in stones
* `79-egnufetpeS` in Septefunge-97
* `diotcnuF` in Functoid
* `ssarG` in Grass
* `kcuhpla` in alphuck
[Try it online!](https://tio.run/##rTrbbhtHls/qX5iXUlMxu0U2m5RsWaJIju62M7alsZzYG4nmNLuLZEt9YfpCSZEVBDNAgAEWm8E8BIt92CDA7mIvsw8TTB4GmyfPe/IP@oGdP/CeU1V94UW2k9mW2Kw69zp1quqcZneNcPD6dYFsWhYxCO0bcd8zHpLIh97Qdy76jh@RiIYRGRiBR8OQdC/IY5vufEJPTv2uVCDbvuMYw5ASedu3qEwMzyLyZtCPXepFoUxCaka274Wk5wekS6OIBoSeD2lgU8@kkmQaEWkRE3glxyNayJrsVun2SIFs0V7s9am2tixFfmwOyDCwQbAEqu0eufBjYqDticIycY1TSsI4oDgK17fs3gUBCyrDCxL6JBqAvmhAL4CFEtszndiiFjQQSBzbO5WoOfCJ5hF5oSaDaZw3B11CqOWH49BlhIa@61KtZ58jThpeRAPfWx6HJhz3AiMM61IUEM20yNmzEWkwJyBekh5uPr73wea93c6Dxzu7z5s1aevvnu4eNuUF5cwEBkaqyhK4hnmXOIbXj40@VdRLaY6pkAtkYVxKhSzUymSBSYJphFmVE9onsefZXp@wEd9akua6EBegh4225cfRMI4ErXDMy4COWjiPZkStRMwkXPMcaQ5maZ6Y7pBwMSRBklu3ZiOAax1nw5PmuNxngQ@2caoKuU/Prdgd1gF7fm6RxLieLc1NeA28pUz4oFRT1XTUGjn@1YKCAciFqMe/wkBgTmglcXaFkTaIomFY1/W@HQ3ibsX0Xf1pcPEg2vcgYqgeBRd25CdtSnXXCCHO9bPAGEKkhyAhmSAi42qSicxMYG0pw@0AwnItogWxx9ZAHnmIYQQEQQxrUPeHkc4Ci98rQXeKodVoAXkShYyjZ4cDdsPlMEm/DdSMytQi09S7tqfD92xjtmE/MH3DSVlEP23MUvCh7QL9yHbTdQ7tSgQh0NItOtK92HHIUutWDWMD50Wg8zL2u@/jjjKiGprbR/vOid89EUCTy9X8PIypAJEVfQKYF5xuNKvJmLophPmi1@3aU0PKtqcJL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fRFSyUveBtYVLEpDqHiTlZJfaw0ODxgNnB3YU8lGh7R6XLPE5YnV1wi3h@K9HHsLM0JBUunyxsUicpx17oJnyxOTjNt@DT5kjR9GoqIgnqNrT18byCIh9ENMZzDY/QusYQrreP4sTSDjOVLWIdzsatKvppQRTWB8jkN8lTX2G4t3tdrkmKRJUyWFWRzAtUFSxbPBrZDmTCevnn0DIjMQaAwZcikMkLOz8s9nigyUpC@AEVJF46EU4YQWoEQ8AjhFS0HJz8N509rcagUP/BsF1IFfGDB3vSMlmokfXESThZsszOlmNvRb2QWPgS@tJMyS2ziYvHCKysKwdFWnfCnZXVxKnE/99M2xvDkEi8j63K1nltdHHTn7dJezJJWAJNvV0FT9fzOHr4zC8PpUsc/Q6krq5lUsfhmGrSyVp/a7hji7komYHIrzm84cPTndhMu1LTqWcRjyZl0TF4aikeN0KmTXAaWpXW46FTBZdF35tIyLhzzNFvmCcGSkvvDNyoRG4wqYWUGFRU9LycFGvVilwYGLF4s8HB5s/eiWVGTix4k/cQeKoHh9amCM1eGiVuB@yoUSUd5Dwk@MfKkJ0aUdpnFbZbe5IP0SFQ0zEj2YIw/h1NyRMx22DrHVjTDz9qQouAClQwMz3JYZTymjnUgI8T3KmAV/YJe7OJCy604OfZOPfzBJ8dX58sN@mnuJ@Qr6uvJB4bps0KTF9/Jg8JKOHRgPywee7BU8bkf4o802K4LwBHGLn/wSfnr2vydJFs8zKQw03CU4xsjEn8tCATLm6FdXy3V60ul@u27i5pbXpeldG@UZT77ZXN82jk7SxGa/M0WbXmJR4GDlKi3LlJmGJOjQn5i10ONETtHdpvTZ7shbqnhe2t3SstLyTNt/qowFyWXxcvN/wc)
Next answer must not exceed 3452 bytes.
## Hexdump
```
00000000: 766f 6964 202f 2a2d 7b2d 2d20 2368 5221 void /*-{-- #hR!
00000010: 582d 4020 505e 687e 7e58 4040 3044 2030 X-@ P^h~~X@@0D 0
00000020: 4422 6876 2158 2d40 2050 5a68 202b 5835 D"hv!X-@ PZh +X5
00000030: 2022 4d21 4d20 656c 6966 204d 4f43 2053 "M!M elif MOC S
00000040: 4f44 6565 7246 247d 2b2b 2b2b 5b2a 2f2f ODeerF$}++++[*//
00000050: 2f6f 705c 0a20 2f2b 2023 5c0a 2062 6173 /op\. /+ #\. bas
00000060: 656e 616d 6520 2224 2872 6561 646c 696e ename "$(readlin
00000070: 6b20 2f70 726f 632f 2424 2f65 7865 2922 k /proc/$$/exe)"
00000080: 7c72 6576 3b3a 3c3c 2745 4f46 2720 233e |rev;:<<'EOF' #>
00000090: 3e5c 0a31 2b2f 2f2f 2020 2020 2020 2020 >\.1+///
000000a0: 2020 2020 2020 2020 2020 4f5c 0a2f 2a20 O\./*
000000b0: 1b67 6763 476d 6956 1b5a 5a3b 6f6f 6f22 .ggcGmiV.ZZ;ooo"
000000c0: 6c6f 4722 3b3f 3d30 2553 2131 316f 6f6f loG";?=0%S!11ooo
000000d0: 3c22 3e3c 3e22 0a23 6465 6669 6e65 2053 <"><>".#define S
000000e0: 2243 2220 2020 2020 2020 2f2f 410a 2369 "C" //A.#i
000000f0: 6664 6566 205f 5f63 706c 7573 706c 7573 fdef __cplusplus
00000100: 2f2f 6c0a 2066 2829 3b20 2020 2020 2020 //l. f();
00000110: 2020 2020 202f 2f69 0a23 696e 636c 7564 //i.#includ
00000120: 653c 6373 7464 696f 3e2f 2f63 0a23 6465 e<cstdio>//c.#de
00000130: 6669 6e65 2053 222b 2b43 2220 2f2f 650a fine S"++C" //e.
00000140: 2069 6e74 2f2f 2f20 2020 2020 2020 2020 int///
00000150: 220a 2365 6e64 6966 2f2f 2020 2020 2020 ".#endif//
00000160: 205c 2e0a 2369 6664 6566 205f 5f4f 424a \..#ifdef __OBJ
00000170: 435f 5f0a 2364 6566 696e 6520 5322 432d C__.#define S"C-
00000180: 6576 6974 6365 4a62 4f22 0a23 656e 6469 evitceJbO".#endi
00000190: 660a 206d 6169 6e28 297b 7072 696e 7466 f. main(){printf
000001a0: 2853 292f 2a2f 6d61 696e 2829 7b69 6d70 (S)/*/main(){imp
000001b0: 6f72 7420 7374 642e 7374 6469 6f3b 2244 ort std.stdio;"D
000001c0: 222e 7772 6974 652f 2a2a 2f3b 7d2f 2a7d ".write/**/;}/*}
000001d0: 3c0a 3e20 2076 7757 5757 5777 5757 5757 <.> vwWWWWwWWWW
000001e0: 5777 7677 5757 7757 5757 7776 7757 5777 WwvwWWwWWWwvwWWw
000001f0: 5757 5777 7677 5757 7757 5757 7776 7757 WWWwvwWWwWWWwvwW
00000200: 5777 5757 5777 7677 5757 7757 5757 7776 WwWWWwvwWWwWWWwv
00000210: 7757 5777 5757 5777 7657 7777 7777 7777 wWWwWWWwvWwwwwww
00000220: 7777 7777 7757 5757 7757 5757 5757 5777 wwwwwWWWwWWWWWWw
00000230: 5757 5757 5757 5777 5757 5757 5757 5757 WWWWWWWwWWWWWWWW
00000240: 5777 5757 5757 5757 5757 5757 5757 7757 WwWWWWWWWWWWWWwW
00000250: 5757 5757 5757 5757 5777 5757 5757 5757 WWWWWWWWWwWWWWWW
00000260: 5757 5757 5757 5757 5757 5777 5757 5757 WWWWWWWWWWWwWWWW
00000270: 5757 5757 5757 5757 5757 5757 5757 7757 WWWWWWWWWWWWWWwW
00000280: 5757 5757 5757 5757 5757 5757 5757 5757 WWWWWWWWWWWWWWWW
00000290: 5777 5757 5757 5757 5757 5757 5757 5757 WwWWWWWWWWWWWWWW
000002a0: 5757 5757 5777 7757 5757 5757 5757 5757 WWWWWwwWWWWWWWWW
000002b0: 5757 5757 5757 5757 5757 5777 7777 7777 WWWWWWWWWWWwwwww
000002c0: 7757 5757 5757 5757 5757 5757 5757 5757 wWWWWWWWWWWWWWWW
000002d0: 5757 5757 5757 7777 7777 7757 5757 5757 WWWWWWwwwwwWWWWW
000002e0: 5757 5757 5757 5757 5757 5757 5757 5757 WWWWWWWWWWWWWWWW
000002f0: 5777 7777 7777 7777 7777 7777 0a39 3939 Wwwwwwwwwwww.999
00000300: 2039 3939 2039 390a 3939 3920 3939 3920 999 99.999 999
00000310: 390a 3939 3976 3c3e 0a76 2020 3c3e 2265 9.999v<>.v <>"e
00000320: 6675 6e67 652d 3938 222c 2c2c 2c2c 2c2c funge-98",,,,,,,
00000330: 2c2c 3779 332d 763c 2040 0a3e 2020 235e ,,7y3-v< @.> #^
00000340: 4776 2020 2020 2020 2020 2020 2020 2020 Gv
00000350: 2020 2040 2c22 4222 5f22 5472 222c 2c40 @,"B"_"Tr",,@
00000360: 0a20 2020 763c 5b5f 225d 4265 6675 6e67 . v<[_"]Befung
00000370: 652d 3933 223e 2c2c 2c2c 2c2c 2c2c 2c2c e-93">,,,,,,,,,,
00000380: 307c 403c 0a20 2020 3e23 3c22 4265 6675 0|@<. >#<"Befu
00000390: 6e67 652d 3936 223e 205e 7624 4730 3031 nge-96"> ^v$G001
000003a0: 0a76 2020 2c2c 2c2c 2c22 3739 2d65 676e .v ,,,,,"79-egn
000003b0: 7566 6542 2220 5f20 2020 2020 2020 2020 ufeB" _
000003c0: 2020 2020 2020 2020 2076 3c0a 3e20 202c v<.> ,
000003d0: 2c2c 2c2c 4023 2020 2020 2020 2c22 3739 ,,,,@# ,"79
000003e0: 2d65 676e 7566 6572 5422 5f76 2320 2447 -egnuferT"_v# $G
000003f0: 3030 3031 3c3e 0a20 2020 2020 2020 2020 0001<>.
00000400: 2020 2020 2020 2020 2020 2020 2020 2020
00000410: 2020 2020 203c 3e31 3030 3030 4724 760a <>10000G$v.
00000420: 2020 2020 2023 402c 2c2c 2c2c 2c2c 2c2c #@,,,,,,,,,
00000430: 2c2c 2c2c 2c40 2322 3739 2d65 676e 7566 ,,,,,@#"79-egnuf
00000440: 6572 6461 7551 225f 3130 3030 3030 4724 erdauQ"_100000G$
00000450: 760a 2020 2020 2020 2020 2020 2020 2020 v.
00000460: 2020 2020 2020 2020 2020 2020 2020 2020
00000470: 2c2c 2237 392d 6567 6e75 6665 746e 6975 ,,"79-egnufetniu
00000480: 5122 5f31 3030 3030 3030 4724 2176 402c Q"_1000000G$!v@,
00000490: 2c2c 2c2c 2c2c 2c2c 2c2c 2c0a 2020 2020 ,,,,,,,,,,,.
000004a0: 2020 2020 2020 2020 2020 2020 2020 2020
000004b0: 2020 2020 2020 2020 2020 2020 2020 2020
000004c0: 2020 2020 2020 2020 2237 392d 6567 6e75 "79-egnu
000004d0: 6665 7470 6553 225f 2253 6578 6566 756e fetpeS"_"Sexefun
000004e0: 6765 2d39 3722 2340 2c2c 2c2c 2c2c 2c2c ge-97"#@,,,,,,,,
000004f0: 2c2c 2c2c 4023 2c0a 2020 2020 2020 2020 ,,,,@#,.
00000500: 2020 2020 2020 2020 2020 2020 2020 2020
00000510: 2020 2020 2020 203c 3e22 7622 400a 2040 <>"v"@. @
00000520: 2c22 4622 2c22 7522 2c22 6e22 2c22 6322 ,"F","u","n","c"
00000530: 2c22 7422 2c22 6f22 2c22 6922 2c22 6422 ,"t","o","i","d"
00000540: 3c3e 2072 6564 2064 6f77 6e20 7477 6f20 <> red down two
00000550: 7265 6420 6c65 6674 206f 6e65 2079 656c red left one yel
00000560: 6c6f 7720 7570 2067 7265 656e 2064 6f77 low up green dow
00000570: 6e20 7965 6c6c 6f77 2075 7020 6772 6565 n yellow up gree
00000580: 6e20 646f 776e 2072 6564 2075 7020 7468 n down red up th
00000590: 7265 6520 7265 6420 7269 6768 7420 7477 ree red right tw
000005a0: 6f20 7965 6c6c 6f77 2064 6f77 6e20 7965 o yellow down ye
000005b0: 6c6c 6f77 2064 6f77 6e20 626c 7565 206c llow down blue l
000005c0: 6566 7420 6772 6565 6e20 646f 776e 2072 eft green down r
000005d0: 6564 2064 6f77 6e20 6f6e 6520 7965 6c6c ed down one yell
000005e0: 6f77 2064 6f77 6e20 626c 7565 206c 6566 ow down blue lef
000005f0: 7420 6772 6565 6e20 646f 776e 2072 6564 t green down red
00000600: 2064 6f77 6e20 7477 6f20 7265 6420 6c65 down two red le
00000610: 6674 206f 6e65 2079 656c 6c6f 7720 7570 ft one yellow up
00000620: 2079 656c 6c6f 7720 646f 776e 2062 6c75 yellow down blu
00000630: 6520 6c65 6674 2067 7265 656e 2064 6f77 e left green dow
00000640: 6e20 7265 6420 6c65 6674 206f 6e65 2072 n red left one r
00000650: 6564 2064 6f77 6e20 7468 7265 6520 7965 ed down three ye
00000660: 6c6c 6f77 2064 6f77 6e20 7965 6c6c 6f77 llow down yellow
00000670: 2064 6f77 6e20 626c 7565 206c 6566 7420 down blue left
00000680: 6772 6565 6e20 646f 776e 2072 6564 2075 green down red u
00000690: 7020 7477 6f20 6772 6565 6e20 646f 776e p two green down
000006a0: 2079 656c 6c6f 7720 7570 2079 656c 6c6f yellow up yello
000006b0: 7720 646f 776e 2062 6c75 6520 6c65 6674 w down blue left
000006c0: 2072 6564 2075 7020 7468 7265 6520 7265 red up three re
000006d0: 6420 7269 6768 7420 7477 6f20 7965 6c6c d right two yell
000006e0: 6f77 2064 6f77 6e20 7965 6c6c 6f77 2064 ow down yellow d
000006f0: 6f77 6e20 626c 7565 206c 6566 740a 2e4c own blue left..L
00000700: 2020 2020 2020 2020 2020 202e 2e20 2020 ..
00000710: 2a2f 2f2f 7b7d 5de2 8e9a efbc a6c2 b96c *///{}]........l
00000720: 616f 6372 6168 43c2 abe2 96b2 c2b2 c2b2 aocrahC.........
00000730: c2b2 c2b2 c2b2 e28c 82e2 86a8 ceb1 e286 ................
00000740: a8c3 9fe2 86a8 c2b2 c2b2 e28c 82e2 86a8 ................
00000750: e286 90c3 9fe2 89a4 e296 bce2 8692 e296 ................
00000760: bce2 8690 e289 a5e2 8692 e28c 82e2 86a8 ................
00000770: cf83 e286 92e2 8692 e286 92e2 86a8 c39f ................
00000780: e286 92e2 8692 e286 92e2 86a8 cf80 e286 ................
00000790: 92e2 8692 e286 92e2 8692 e286 92e2 86a8 ................
000007a0: c2a1 c39f c2a1 e286 92e2 8692 e286 a8ce ................
000007b0: b4e2 8692 e286 a8c3 9fe2 8692 e286 92e2 ................
000007c0: 8692 e286 92e2 86a8 c2b5 e286 92e2 8692 ................
000007d0: e286 92e2 86a8 c2a1 cf86 e286 a8ce b5cf ................
000007e0: 80e2 8c82 e286 a8c2 a1c3 9fc2 a1e2 8692 ................
000007f0: e286 92e2 8692 e286 a8c2 a1cf 80cf 83e2 ................
00000800: 96b2 e28c 82e2 86a8 c2a1 cf83 c2b5 c2a1 ................
00000810: e286 92e2 86a8 c2a1 ceb1 c2a1 e286 92e2 ................
00000820: 86a8 c2a1 cf80 c2a1 e296 b2e2 96b2 e296 ................
00000830: b2c2 a1e2 96b2 e296 b2e2 96b2 c2a1 cf83 ................
00000840: e296 b2c2 a1ce b4c2 a1cf 86e2 96b2 e296 ................
00000850: b2e2 96b2 e296 b2c2 a1ce b5e2 96bc e296 ................
00000860: bcc2 a1c2 bb2b 2b2b 2b5b 2d3c 2b2b 2b2b .....++++[-<++++
00000870: 2b3e 5d3c 5b2d 3c2b 2b2b 2b2b 2b3c 2b2b +>]<[-<++++++<++
00000880: 2b2b 2b3c 2b2b 2b2b 2b3e 3e3e 5d3c 3c3c +++<+++++>>>]<<<
00000890: 2b2b 2b2b 2b2b 2b2e 3e2d 2e3e 2d2d 2d2e +++++++.>-.>---.
000008a0: 3c3c 2d2d 2d2d 2d2e 2b2b 2b2b 2b2b 2b2b <<-----.++++++++
000008b0: 2e2d 2d2d 2d2d 2e3e 2d2d 2e3e 2d2d 2d2e .-----.>--.>---.
000008c0: 3c2b 2e3e 3e3e 2828 2828 2828 2828 2828 <+.>>>((((((((((
000008d0: 2829 2829 2829 297b 7d29 7b7d 297b 7d29 ()()()){}){}){})
000008e0: 7b7d 2829 297b 7d29 2828 2829 2829 2829 {}()){})((()()()
000008f0: 2829 297b 7d29 7b7d 295b 2828 5b5d 5b5d ()){}){})[(([][]
00000900: 297b 7d29 7b7d 2829 5d29 285b 5d28 2929 ){}){}()])([]())
00000910: 7b7d 295b 5d28 2929 2828 5b5b 5d5b 5d28 {})[]())(([[][](
00000920: 295d 285b 5d28 2928 2828 2828 5b5d 5b5d )]([]()((((([][]
00000930: 5b5d 2929 7b7d 7b7d 295b 5d29 7b7d 2929 [])){}{})[]){}))
00000940: 295b 5d28 2929 287b 202d 7d5f 3d22 2922 )[]())({ -}_=")"
00000950: 3b28 2129 3d73 6571 3b6d 6169 6e7c 6c65 ;(!)=seq;main|le
00000960: 7420 6221 5f3d 2222 3d70 7574 5374 7224 t b!_=""=putStr$
00000970: 2822 2221 2273 6e72 6574 7461 5067 6e61 (""!"snrettaPgna
00000980: 422b 2229 2b2b 696e 6974 226c 6c65 6b73 B+")++init"lleks
00000990: 6148 2822 7b2d 0a2f 2f48 4854 2d40 5e73 aH("{-.//HHT-@^s
000009a0: 7245 7152 4d4d 7e64 4f2d 7d2d 2d29 2a2f rEqRMM~dO-}--)*/
000009b0: 2f2f f09f 92ac 696a 6f6d 65f0 9f92 ace2 //....ijome.....
000009c0: 9ea1 f09f 98ad 456d 6f74 696e 6f6d 6963 ......Emotinomic
000009d0: 6f6e f09f 98b2 e28f aae2 8fac e28f a940 on.............@
000009e0: 2c6b 6122 3839 2d65 676e 7566 656e 5573 ,ka"89-egnufenUs
000009f0: 7373 7373 6161 6161 6165 6565 6565 6565 ssssaaaaaeeeeeee
00000a00: 6565 6570 6165 6565 6565 6565 6565 6563 eeepaeeeeeeeeeec
00000a10: 6973 6165 6565 6565 6565 6a69 6969 6969 isaeeeeeeejiiiii
00000a20: 6969 696a 6565 6565 6565 6565 6565 6565 iiijeeeeeeeeeeee
00000a30: 6565 6565 6565 6a69 6969 6969 6969 6969 eeeeeejiiiiiiiii
00000a40: 6969 6969 6a65 6565 6565 6565 656a 6969 iiiijeeeeeeeejii
00000a50: 6969 6a69 6969 6969 6969 6969 6969 6a22 iijiiiiiiiiiiij"
```
# Changes
Added alphuck code near the end, and some scattered throughout the code. Capitalized the `J` for Objective-C, to avoid output. The `sssss` is to balance five open `p`s (those are alphuck's `[]`).
[Answer]
# 40. [Nameless language](https://esolangs.org/wiki/Nameless_language), 3241 bytes
```
void /*-{-- #hR!X-@ P^h~~X@@0D 0D"hv!X-@ PZh +X5 "M!M elif MOC SODeerF$}++++[*///op\
/+ #\
basename "$(readlink /proc/$$/exe)"|rev;:<<'EOF' #>>\
1+/// O\
/* ggcGmiVZZ;ooo"loG";?=0%S!11ooo<"><>"
#define S"C" //A
#ifdef __cplusplus//l
f(); //i
#include<cstdio>//c
#define S"++C" //e
int/// "
#endif// \.
#ifdef __OBJC__
#define S"C-evitceJbO"
#endif
main(){printf(S)/*/main(){import std.stdio;"D".write/**/;}/*}<
> vwWWWWwWWWWWwvwWWwWWWwvwWWwWWWwvwWWwWWWwvwWWwWWWwvwWWwWWWwvwWWwWWWwvWwwwwwwwwwwwWWWwWWWWWWwWWWWWWWwWWWWWWWWWwWWWWWWWWWWWWwWWWWWWWWWWwWWWWWWWWWWWWWWWWWwWWWWWWWWWWWWWWWWWWwWWWWWWWWWWWWWWWWWWwWWWWWWWWWWWWWWWWWWWwwWWWWWWWWWWWWWWWWWWWWwwwwwwWWWWWWWWWWWWWWWWWWWWWwwwwwWWWWWWWWWWWWWWWWWWWWWWwwwwwwwwwww
999 999 99
999 999 9
999v<>0000110110
v <>"efunge-98",,,,,,,,,7y3-v< @
> #^Gv @,"B"_"Tr",,@
v<[_"]Befunge-93">,,,,,,,,,,0|@<
>#<"Befunge-96"> ^v$G001
v ,,,,,"79-egnufeB" _ v<
> ,,,,,@# ,"79-egnuferT"_v# $G0001<>
<>10000G$v
#@,,,,,,,,,,,,,,@#"79-egnuferdauQ"_100000G$v
,,"79-egnufetniuQ"_1000000G$!v@,,,,,,,,,,,,
"79-egnufetpeS"_"Sexefunge-97"#@,,,,,,,,,,,,@#,
<>"v"@
@,"F","u","n","c","t","o","i","d"<> red down two red left one yellow up green down yellow up green down red up three red right two yellow down yellow down blue left green down red down one yellow down blue left green down red down two red left one yellow up yellow down blue left green down red left one red down three yellow down yellow down blue left green down red up two green down yellow up yellow down blue left red up three red right two yellow down yellow down blue left 0001110000100000100010000010000010100000100000000010001000100000100010000010000010100000100000100010000010001000100000000010001000001000100011000010001000100000100011000010000010001000001000100000100000100000100010000010001000001000100000000010001000001000100010000000110000110000011000001001100000100010001000100010000001001101110000001100111100011001100000001001110011110000110111000001000000010000000100000001000000010000000100000001000000010001100011011110001000100010000010001010000100000001000100000001000000010000000100000001000000010000000100000000100110
.L . . *///{}]⎚F¹laocrahC«▲²²²²²⌂↨α↨ß↨²²⌂↨←ß≤▼→▼←≥→⌂↨σ→→→↨ß→→→↨π→→→→→↨¡ß¡→→↨δ→↨ß→→→→↨µ→→→↨¡φ↨επ⌂↨¡ß¡→→→↨¡πσ▲⌂↨¡σµ¡→↨¡α¡→↨¡π¡▲▲▲¡▲▲▲¡σ▲¡δ¡φ▲▲▲▲¡ε▼▼¡»++++[-<+++++>]<[-<++++++<+++++<+++++>>>]<<<+++++++.>-.>---.<<-----.++++++++.-----.>--.>---.<+.>>>((((((((((()()()){}){}){}){}()){})((()()()()){}){})[(([][]){}){}()])([]()){})[]())(([[][]()]([]()((((([][][])){}{})[]){})))[]())({ -}_=")";(!)=seq;main|let b!_=""=putStr$(""!"snrettaPgnaB+")++init"lleksaH("{-
//HHT-"NUb4`BJJndO-}--)s*//∙SAVNACp💬ijome💬➡😭Emotinomicon😲⏪⏬⏩@,ka"89-egnufenUsssssaaaaaeeeeeeeeeepaeeeeeeeeeecisaeeeeeeejiiiiiiiijeeeeeeeeeeeeeeeeeejiiiiiiiiiiiiijeeeeeeeejiiiijiiiiiiiiiiij"
```
Prints:
* `D` in D
* `emmoS` in Somme
* `><>` in ><>
* `C` in C
* `laocrahC` in Charcoal
* `miV` in Vim
* `C-evitceJbO` in ObJective-C
* `89-egnufeB` in Befunge-98
* `39-egnufeB` in Befunge-93
* `elif MOC SODeerF` in FreeDOS COM file
* `><>loG` in Gol><>
* `89-egnufenU` in Unefunge-98
* `79-egnufeB` in Befunge-97
* `69-egnufeB` in Befunge-96
* `kcufniarb` in brainfuck
* `89-egnuferT` in Trefunge-98
* `kalf-niarb` in brain-flak
* `hsab` in bash
* `lleksaH` in Haskell
* `hsz` in zsh
* `ijome` in emoji
* `snrettaPgnaB+lleksaH` in Haskell+BangPatterns
* `++C` in C++
* `nocimonitomE` in Emotinomicon
* `hsk` in ksh
* `hsad` in dash
* `79-egnuferT` in Trefunge-97
* `ecilA` in Alice
* `79-egnuferdauQ` in Quadrefunge-97
* `99` in 99
* `79-egnufetniuQ` in Quintefunge-97
* `kcufniarb cilobmys` in symbolic brainfuck
* `79-egnufexeS` in Sexefunge-97
* `senots` in stones
* `79-egnufetpeS` in Septefunge-97
* `diotcnuF` in Functoid
* `ssarG` in Grass
* `kcuhpla` in alphuck
* `SAVNAC` in CANVAS
* `egaugnal sseleman` in nameless language
[Try it online!](https://tio.run/##rTvbchtHds@cX9iX5oAWZggMhiAligQBmHdJjiRyRdpSDELwYKYBDDkX7Fx4Ec0tV7bKla1Kxa59cCV5iMtVSSqXzcO61g9bcV6079Y/8Ad2/0A5p7vnggsl2ZsRMeg@9z59uvucwahrhIPXrwtkw7KIQWjfiPue8ZBEPvSGvnPRd/yIRDSMyMAIPBqGpHtBHtt0@wU9PvG7UoFs@Y5jDENK5C3fojIxPIvIG0E/dqkXhTIJqRnZvheSnh@QLo0iGhB6PqSBTT2TSpJpRKRJTOCVHI9oIWuyW6XbIwWySXux16fa6pIU@bE5IMPABsESqLZ75MKPiYG2JwrLxDVOKAnjgOIoXN@yexcELKgML0jok2gA@qIBvQAWSmzPdGKLWtBAIHFs70Si5sAnmkfkuaoMpnHeHHQRoZYfjkKXEBr6rku1nn2OOGl4EQ18b2kUmnDcC4wwrElRQDTTImdPT0mdOQHxkvRw4/G9Dzfu7XQePN7eedaoSpt/fbhz0JDnlDMTGBipKkvgGuZd4hhePzb6VFEvpRmmQi6QuVEpFTJXLZM5JgmmEWZVTmifxJ5ne33CRnxrUZrpQlyAHjbaph9HwzgStMIxnwb0tInzaEbUSsSMwzXPkWZglmaJ6Q4JF0MSJLl1azoCuNZwNjxphst9GvhgG6eqkPv03IrdYQ2w5@cWS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x3DHF3ORMwvhXnNxw4@nO7CRdqWrUs4rHkTDomLw3Fo0bo1EguA8vSOlx0quCy6DtzaRkXjnmSLfOEYEnJ/eEblYgNRpWwMoOKip6XkwKNerFLAwMWLxZ4uLzZfxFgRU0uepD0hT1UAsPrUwVnrgwTtwz3FSiSWnkPCT4x8qQnRpR2mcVtlt7kg7QlKhpmJHswxp/DKTkiZjtsnSMrmuGnbUhRcIFKBoZnOawyHlHHOpAR4gs6sIr@il7s4ELLrTg59k48/L0wx1fjyw36ae4n5Cv46HUvsPu2ZzgkXaoG82H3gqxnT10hTRTv6KC9@M5wBXJA8wRMGaCX2Qvuhl5dvnv39h399kp1dUWcFz37vMOeOCvICZUHe0euTByvgfs8OFUi@EjV8bKkFn@igj7sYrpeBAcr@ASSM7IjS50vkiLyociWxg4NoIdtF@rP2OUPYSl7OItt9rKgzR6thhTzEgg9yC3wXSgUku7IsoxdFnZlczTehHJuWtjgr2dpS4usjxwO0qOimvidHocEVjsqpEh2LdQYj9Oy2ylbtifjxh6@t3qntLSoogniTBP/UWHiqW7yQJePP/c4txIOHTi1ikdekXnfyRw07hs2JXnPsP/MkrlF4iNGr2yEdm2lVKstlmq3785rbnlNlmLvzGCbOuAXqoZJ7WN/GCrq5VWrje@bgzoQCKsDX@4P@dbfowElZzrxARNw1Ury2l2ZbIj3CG8R9q60tusYJzAIZlLjhigCfAizmQVKUfwS4hpDRWwvZo3IpCK32IQmZrfLbKyq2lqstd@sA9Ixz1LFC4EK/y8VfKJlqHyRtVVbxFwEyFAaoxcghgWYqv4f)
Next answer must not exceed 4213 bytes.
## Changes
~~I wrote an interpreter for the newly added language which I added to the TIO (`nameless.hs`).~~ (@Dennis just added the interpreter to TIO, [try it here](https://tio.run/#nameless))
I changed the `somme-fix.py` such that it tries to avoid characters which clash with others (such as **Brain-Flak** etc.) and such that it doesn't need manual fiddling with the last two lines.
## Explanation
This language is basically just **brainfuck** differently encoded (every instruction is 4 characters of `0`s and `1`s), but it extends the instruction set by a few instructions. To no-op all the instructions resulting from intial code I inserted `00 0011 0110` right where the **99** code is which is equivalent to closing `p` (reset pointer) and the instructions `-[` to set the cell to 0 and skip all the remaining code.
Later (after the stones code) follows the closing `]` and the code which is basically this (`a` adds the value of the next instruction to the cell and `p` as above):
```
>a++>a+a+>>aaa++>a+a+>aa+++>>aa++->aaa+->a++>aa+>a++>aa++>>aa+++>->p<a+[>aaaaa<-]>--p[[>+]-p-]>.>.>.>.>.>.>.>.[-]aaaa++a.>..>.>.>.>.>.>.>+
```
[Try it online!](https://tio.run/##VY3LCcAwDEMHEuoEwYuYHHTIrS2B7I/zK4VgjCU9gV895S6tRZiAsYKZ9OupVgJw5dy9ifb9KIxWk@CzJSVmI6u7IbMOc53jzFpvNMzJEBFsHQ "nameless language – Try It Online")
## Hexdump
```
00000000: 766f 6964 202f 2a2d 7b2d 2d20 2368 5221 void /*-{-- #hR!
00000010: 582d 4020 505e 687e 7e58 4040 3044 2030 X-@ P^h~~X@@0D 0
00000020: 4422 6876 2158 2d40 2050 5a68 202b 5835 D"hv!X-@ PZh +X5
00000030: 2022 4d21 4d20 656c 6966 204d 4f43 2053 "M!M elif MOC S
00000040: 4f44 6565 7246 247d 2b2b 2b2b 5b2a 2f2f ODeerF$}++++[*//
00000050: 2f6f 705c 0a20 2f2b 2023 5c0a 2062 6173 /op\. /+ #\. bas
00000060: 656e 616d 6520 2224 2872 6561 646c 696e ename "$(readlin
00000070: 6b20 2f70 726f 632f 2424 2f65 7865 2922 k /proc/$$/exe)"
00000080: 7c72 6576 3b3a 3c3c 2745 4f46 2720 233e |rev;:<<'EOF' #>
00000090: 3e5c 0a31 2b2f 2f2f 2020 2020 2020 2020 >\.1+///
000000a0: 2020 2020 2020 2020 2020 4f5c 0a2f 2a20 O\./*
000000b0: 1b67 6763 476d 6956 1b5a 5a3b 6f6f 6f22 .ggcGmiV.ZZ;ooo"
000000c0: 6c6f 4722 3b3f 3d30 2553 2131 316f 6f6f loG";?=0%S!11ooo
000000d0: 3c22 3e3c 3e22 0a23 6465 6669 6e65 2053 <"><>".#define S
000000e0: 2243 2220 2020 2020 2020 2f2f 410a 2369 "C" //A.#i
000000f0: 6664 6566 205f 5f63 706c 7573 706c 7573 fdef __cplusplus
00000100: 2f2f 6c0a 2066 2829 3b20 2020 2020 2020 //l. f();
00000110: 2020 2020 202f 2f69 0a23 696e 636c 7564 //i.#includ
00000120: 653c 6373 7464 696f 3e2f 2f63 0a23 6465 e<cstdio>//c.#de
00000130: 6669 6e65 2053 222b 2b43 2220 2f2f 650a fine S"++C" //e.
00000140: 2069 6e74 2f2f 2f20 2020 2020 2020 2020 int///
00000150: 220a 2365 6e64 6966 2f2f 2020 2020 2020 ".#endif//
00000160: 205c 2e0a 2369 6664 6566 205f 5f4f 424a \..#ifdef __OBJ
00000170: 435f 5f0a 2364 6566 696e 6520 5322 432d C__.#define S"C-
00000180: 6576 6974 6365 4a62 4f22 0a23 656e 6469 evitceJbO".#endi
00000190: 660a 206d 6169 6e28 297b 7072 696e 7466 f. main(){printf
000001a0: 2853 292f 2a2f 6d61 696e 2829 7b69 6d70 (S)/*/main(){imp
000001b0: 6f72 7420 7374 642e 7374 6469 6f3b 2244 ort std.stdio;"D
000001c0: 222e 7772 6974 652f 2a2a 2f3b 7d2f 2a7d ".write/**/;}/*}
000001d0: 3c0a 3e20 2076 7757 5757 5777 5757 5757 <.> vwWWWWwWWWW
000001e0: 5777 7677 5757 7757 5757 7776 7757 5777 WwvwWWwWWWwvwWWw
000001f0: 5757 5777 7677 5757 7757 5757 7776 7757 WWWwvwWWwWWWwvwW
00000200: 5777 5757 5777 7677 5757 7757 5757 7776 WwWWWwvwWWwWWWwv
00000210: 7757 5777 5757 5777 7657 7777 7777 7777 wWWwWWWwvWwwwwww
00000220: 7777 7777 7757 5757 7757 5757 5757 5777 wwwwwWWWwWWWWWWw
00000230: 5757 5757 5757 5777 5757 5757 5757 5757 WWWWWWWwWWWWWWWW
00000240: 5777 5757 5757 5757 5757 5757 5757 7757 WwWWWWWWWWWWWWwW
00000250: 5757 5757 5757 5757 5777 5757 5757 5757 WWWWWWWWWwWWWWWW
00000260: 5757 5757 5757 5757 5757 5777 5757 5757 WWWWWWWWWWWwWWWW
00000270: 5757 5757 5757 5757 5757 5757 5757 7757 WWWWWWWWWWWWWWwW
00000280: 5757 5757 5757 5757 5757 5757 5757 5757 WWWWWWWWWWWWWWWW
00000290: 5777 5757 5757 5757 5757 5757 5757 5757 WwWWWWWWWWWWWWWW
000002a0: 5757 5757 5777 7757 5757 5757 5757 5757 WWWWWwwWWWWWWWWW
000002b0: 5757 5757 5757 5757 5757 5777 7777 7777 WWWWWWWWWWWwwwww
000002c0: 7757 5757 5757 5757 5757 5757 5757 5757 wWWWWWWWWWWWWWWW
000002d0: 5757 5757 5757 7777 7777 7757 5757 5757 WWWWWWwwwwwWWWWW
000002e0: 5757 5757 5757 5757 5757 5757 5757 5757 WWWWWWWWWWWWWWWW
000002f0: 5777 7777 7777 7777 7777 7777 0a39 3939 Wwwwwwwwwwww.999
00000300: 2039 3939 2039 390a 3939 3920 3939 3920 999 99.999 999
00000310: 390a 3939 3976 3c3e 3030 3030 3131 3031 9.999v<>00001101
00000320: 3130 0a76 2020 3c3e 2265 6675 6e67 652d 10.v <>"efunge-
00000330: 3938 222c 2c2c 2c2c 2c2c 2c2c 3779 332d 98",,,,,,,,,7y3-
00000340: 763c 2040 0a3e 2020 235e 4776 2020 2020 v< @.> #^Gv
00000350: 2020 2020 2020 2020 2020 2020 2040 2c22 @,"
00000360: 4222 5f22 5472 222c 2c40 0a20 2020 763c B"_"Tr",,@. v<
00000370: 5b5f 225d 4265 6675 6e67 652d 3933 223e [_"]Befunge-93">
00000380: 2c2c 2c2c 2c2c 2c2c 2c2c 307c 403c 0a20 ,,,,,,,,,,0|@<.
00000390: 2020 3e23 3c22 4265 6675 6e67 652d 3936 >#<"Befunge-96
000003a0: 223e 205e 7624 4730 3031 0a76 2020 2c2c "> ^v$G001.v ,,
000003b0: 2c2c 2c22 3739 2d65 676e 7566 6542 2220 ,,,"79-egnufeB"
000003c0: 5f20 2020 2020 2020 2020 2020 2020 2020 _
000003d0: 2020 2076 3c0a 3e20 202c 2c2c 2c2c 4023 v<.> ,,,,,@#
000003e0: 2020 2020 2020 2c22 3739 2d65 676e 7566 ,"79-egnuf
000003f0: 6572 5422 5f76 2320 2447 3030 3031 3c3e erT"_v# $G0001<>
00000400: 0a20 2020 2020 2020 2020 2020 2020 2020 .
00000410: 2020 2020 2020 2020 2020 2020 2020 203c <
00000420: 3e31 3030 3030 4724 760a 2020 2020 2023 >10000G$v. #
00000430: 402c 2c2c 2c2c 2c2c 2c2c 2c2c 2c2c 2c40 @,,,,,,,,,,,,,,@
00000440: 2322 3739 2d65 676e 7566 6572 6461 7551 #"79-egnuferdauQ
00000450: 225f 3130 3030 3030 4724 760a 2020 2020 "_100000G$v.
00000460: 2020 2020 2020 2020 2020 2020 2020 2020
00000470: 2020 2020 2020 2020 2020 2c2c 2237 392d ,,"79-
00000480: 6567 6e75 6665 746e 6975 5122 5f31 3030 egnufetniuQ"_100
00000490: 3030 3030 4724 2176 402c 2c2c 2c2c 2c2c 0000G$!v@,,,,,,,
000004a0: 2c2c 2c2c 2c0a 2020 2020 2020 2020 2020 ,,,,,.
000004b0: 2020 2020 2020 2020 2020 2020 2020 2020
000004c0: 2020 2020 2020 2020 2020 2020 2020 2020
000004d0: 2020 2237 392d 6567 6e75 6665 7470 6553 "79-egnufetpeS
000004e0: 225f 2253 6578 6566 756e 6765 2d39 3722 "_"Sexefunge-97"
000004f0: 2340 2c2c 2c2c 2c2c 2c2c 2c2c 2c2c 4023 #@,,,,,,,,,,,,@#
00000500: 2c0a 2020 2020 2020 2020 2020 2020 2020 ,.
00000510: 2020 2020 2020 2020 2020 2020 2020 2020
00000520: 203c 3e22 7622 400a 2040 2c22 4622 2c22 <>"v"@. @,"F","
00000530: 7522 2c22 6e22 2c22 6322 2c22 7422 2c22 u","n","c","t","
00000540: 6f22 2c22 6922 2c22 6422 3c3e 2072 6564 o","i","d"<> red
00000550: 2064 6f77 6e20 7477 6f20 7265 6420 6c65 down two red le
00000560: 6674 206f 6e65 2079 656c 6c6f 7720 7570 ft one yellow up
00000570: 2067 7265 656e 2064 6f77 6e20 7965 6c6c green down yell
00000580: 6f77 2075 7020 6772 6565 6e20 646f 776e ow up green down
00000590: 2072 6564 2075 7020 7468 7265 6520 7265 red up three re
000005a0: 6420 7269 6768 7420 7477 6f20 7965 6c6c d right two yell
000005b0: 6f77 2064 6f77 6e20 7965 6c6c 6f77 2064 ow down yellow d
000005c0: 6f77 6e20 626c 7565 206c 6566 7420 6772 own blue left gr
000005d0: 6565 6e20 646f 776e 2072 6564 2064 6f77 een down red dow
000005e0: 6e20 6f6e 6520 7965 6c6c 6f77 2064 6f77 n one yellow dow
000005f0: 6e20 626c 7565 206c 6566 7420 6772 6565 n blue left gree
00000600: 6e20 646f 776e 2072 6564 2064 6f77 6e20 n down red down
00000610: 7477 6f20 7265 6420 6c65 6674 206f 6e65 two red left one
00000620: 2079 656c 6c6f 7720 7570 2079 656c 6c6f yellow up yello
00000630: 7720 646f 776e 2062 6c75 6520 6c65 6674 w down blue left
00000640: 2067 7265 656e 2064 6f77 6e20 7265 6420 green down red
00000650: 6c65 6674 206f 6e65 2072 6564 2064 6f77 left one red dow
00000660: 6e20 7468 7265 6520 7965 6c6c 6f77 2064 n three yellow d
00000670: 6f77 6e20 7965 6c6c 6f77 2064 6f77 6e20 own yellow down
00000680: 626c 7565 206c 6566 7420 6772 6565 6e20 blue left green
00000690: 646f 776e 2072 6564 2075 7020 7477 6f20 down red up two
000006a0: 6772 6565 6e20 646f 776e 2079 656c 6c6f green down yello
000006b0: 7720 7570 2079 656c 6c6f 7720 646f 776e w up yellow down
000006c0: 2062 6c75 6520 6c65 6674 2072 6564 2075 blue left red u
000006d0: 7020 7468 7265 6520 7265 6420 7269 6768 p three red righ
000006e0: 7420 7477 6f20 7965 6c6c 6f77 2064 6f77 t two yellow dow
000006f0: 6e20 7965 6c6c 6f77 2064 6f77 6e20 626c n yellow down bl
00000700: 7565 206c 6566 7420 3030 3031 3131 3030 ue left 00011100
00000710: 3030 3130 3030 3030 3130 3030 3130 3030 0010000010001000
00000720: 3030 3130 3030 3030 3130 3130 3030 3030 0010000010100000
00000730: 3130 3030 3030 3030 3030 3130 3030 3130 1000000000100010
00000740: 3030 3130 3030 3030 3130 3030 3130 3030 0010000010001000
00000750: 3030 3130 3030 3030 3130 3130 3030 3030 0010000010100000
00000760: 3130 3030 3030 3130 3030 3130 3030 3030 1000001000100000
00000770: 3130 3030 3130 3030 3130 3030 3030 3030 1000100010000000
00000780: 3030 3130 3030 3130 3030 3030 3130 3030 0010001000001000
00000790: 3130 3030 3131 3030 3030 3130 3030 3130 1000110000100010
000007a0: 3030 3130 3030 3030 3130 3030 3131 3030 0010000010001100
000007b0: 3030 3130 3030 3030 3130 3030 3130 3030 0010000010001000
000007c0: 3030 3130 3030 3130 3030 3030 3130 3030 0010001000001000
000007d0: 3030 3130 3030 3030 3130 3030 3130 3030 0010000010001000
000007e0: 3030 3130 3030 3130 3030 3030 3130 3030 0010001000001000
000007f0: 3130 3030 3030 3030 3030 3130 3030 3130 1000000000100010
00000800: 3030 3030 3130 3030 3130 3030 3130 3030 0000100010001000
00000810: 3030 3030 3131 3030 3030 3131 3030 3030 0000110000110000
00000820: 3031 3130 3030 3030 3130 3031 3130 3030 0110000010011000
00000830: 3030 3130 3030 3130 3030 3130 3030 3130 0010001000100010
00000840: 3030 3130 3030 3030 3031 3030 3131 3031 0010000001001101
00000850: 3131 3030 3030 3030 3131 3030 3131 3131 1100000011001111
00000860: 3030 3031 3130 3031 3130 3030 3030 3030 0001100110000000
00000870: 3130 3031 3131 3030 3131 3131 3030 3030 1001110011110000
00000880: 3131 3031 3131 3030 3030 3031 3030 3030 1101110000010000
00000890: 3030 3031 3030 3030 3030 3031 3030 3030 0001000000010000
000008a0: 3030 3031 3030 3030 3030 3031 3030 3030 0001000000010000
000008b0: 3030 3031 3030 3030 3030 3031 3030 3030 0001000000010000
000008c0: 3030 3031 3030 3031 3130 3030 3131 3031 0001000110001101
000008d0: 3131 3130 3030 3130 3030 3130 3030 3130 1110001000100010
000008e0: 3030 3030 3130 3030 3130 3130 3030 3031 0000100010100001
000008f0: 3030 3030 3030 3031 3030 3031 3030 3030 0000000100010000
00000900: 3030 3031 3030 3030 3030 3031 3030 3030 0001000000010000
00000910: 3030 3031 3030 3030 3030 3031 3030 3030 0001000000010000
00000920: 3030 3031 3030 3030 3030 3031 3030 3030 0001000000010000
00000930: 3030 3030 3130 3031 3130 0a2e 4c20 2020 0000100110..L
00000940: 202e 202e 2020 2020 2020 2020 202a 2f2f . . *//
00000950: 2f7b 7d5d e28e 9aef bca6 c2b9 6c61 6f63 /{}]........laoc
00000960: 7261 6843 c2ab e296 b2c2 b2c2 b2c2 b2c2 rahC............
00000970: b2c2 b2e2 8c82 e286 a8ce b1e2 86a8 c39f ................
00000980: e286 a8c2 b2c2 b2e2 8c82 e286 a8e2 8690 ................
00000990: c39f e289 a4e2 96bc e286 92e2 96bc e286 ................
000009a0: 90e2 89a5 e286 92e2 8c82 e286 a8cf 83e2 ................
000009b0: 8692 e286 92e2 8692 e286 a8c3 9fe2 8692 ................
000009c0: e286 92e2 8692 e286 a8cf 80e2 8692 e286 ................
000009d0: 92e2 8692 e286 92e2 8692 e286 a8c2 a1c3 ................
000009e0: 9fc2 a1e2 8692 e286 92e2 86a8 ceb4 e286 ................
000009f0: 92e2 86a8 c39f e286 92e2 8692 e286 92e2 ................
00000a00: 8692 e286 a8c2 b5e2 8692 e286 92e2 8692 ................
00000a10: e286 a8c2 a1cf 86e2 86a8 ceb5 cf80 e28c ................
00000a20: 82e2 86a8 c2a1 c39f c2a1 e286 92e2 8692 ................
00000a30: e286 92e2 86a8 c2a1 cf80 cf83 e296 b2e2 ................
00000a40: 8c82 e286 a8c2 a1cf 83c2 b5c2 a1e2 8692 ................
00000a50: e286 a8c2 a1ce b1c2 a1e2 8692 e286 a8c2 ................
00000a60: a1cf 80c2 a1e2 96b2 e296 b2e2 96b2 c2a1 ................
00000a70: e296 b2e2 96b2 e296 b2c2 a1cf 83e2 96b2 ................
00000a80: c2a1 ceb4 c2a1 cf86 e296 b2e2 96b2 e296 ................
00000a90: b2e2 96b2 c2a1 ceb5 e296 bce2 96bc c2a1 ................
00000aa0: c2bb 2b2b 2b2b 5b2d 3c2b 2b2b 2b2b 3e5d ..++++[-<+++++>]
00000ab0: 3c5b 2d3c 2b2b 2b2b 2b2b 3c2b 2b2b 2b2b <[-<++++++<+++++
00000ac0: 3c2b 2b2b 2b2b 3e3e 3e5d 3c3c 3c2b 2b2b <+++++>>>]<<<+++
00000ad0: 2b2b 2b2b 2e3e 2d2e 3e2d 2d2d 2e3c 3c2d ++++.>-.>---.<<-
00000ae0: 2d2d 2d2d 2e2b 2b2b 2b2b 2b2b 2b2e 2d2d ----.++++++++.--
00000af0: 2d2d 2d2e 3e2d 2d2e 3e2d 2d2d 2e3c 2b2e ---.>--.>---.<+.
00000b00: 3e3e 3e28 2828 2828 2828 2828 2828 2928 >>>((((((((((()(
00000b10: 2928 2929 7b7d 297b 7d29 7b7d 297b 7d28 )()){}){}){}){}(
00000b20: 2929 7b7d 2928 2828 2928 2928 2928 2929 )){})((()()()())
00000b30: 7b7d 297b 7d29 5b28 285b 5d5b 5d29 7b7d {}){})[(([][]){}
00000b40: 297b 7d28 295d 2928 5b5d 2829 297b 7d29 ){}()])([]()){})
00000b50: 5b5d 2829 2928 285b 5b5d 5b5d 2829 5d28 []())(([[][]()](
00000b60: 5b5d 2829 2828 2828 285b 5d5b 5d5b 5d29 []()((((([][][])
00000b70: 297b 7d7b 7d29 5b5d 297b 7d29 2929 5b5d ){}{})[]){})))[]
00000b80: 2829 2928 7b20 2d7d 5f3d 2229 223b 2821 ())({ -}_=")";(!
00000b90: 293d 7365 713b 6d61 696e 7c6c 6574 2062 )=seq;main|let b
00000ba0: 215f 3d22 223d 7075 7453 7472 2428 2222 !_=""=putStr$(""
00000bb0: 2122 736e 7265 7474 6150 676e 6142 2b22 !"snrettaPgnaB+"
00000bc0: 292b 2b69 6e69 7422 6c6c 656b 7361 4828 )++init"lleksaH(
00000bd0: 227b 2d0a 2f2f 4848 542d 224e 5562 3460 "{-.//HHT-"NUb4`
00000be0: 424a 4a6e 644f 2d7d 2d2d 2973 2a2f 2fe2 BJJndO-}--)s*//.
00000bf0: 8899 5341 564e 4143 efbd 90f0 9f92 ac69 ..SAVNAC.......i
00000c00: 6a6f 6d65 f09f 92ac e29e a1f0 9f98 ad45 jome...........E
00000c10: 6d6f 7469 6e6f 6d69 636f 6ef0 9f98 b2e2 motinomicon.....
00000c20: 8faa e28f ace2 8fa9 402c 6b61 2238 392d ........@,ka"89-
00000c30: 6567 6e75 6665 6e55 7373 7373 7361 6161 egnufenUsssssaaa
00000c40: 6161 6565 6565 6565 6565 6565 7061 6565 aaeeeeeeeeeepaee
00000c50: 6565 6565 6565 6565 6369 7361 6565 6565 eeeeeeeecisaeeee
00000c60: 6565 656a 6969 6969 6969 6969 6a65 6565 eeejiiiiiiiijeee
00000c70: 6565 6565 6565 6565 6565 6565 6565 656a eeeeeeeeeeeeeeej
00000c80: 6969 6969 6969 6969 6969 6969 696a 6565 iiiiiiiiiiiiijee
00000c90: 6565 6565 6565 6a69 6969 696a 6969 6969 eeeeeejiiiijiiii
00000ca0: 6969 6969 6969 696a 22 iiiiiiij"
```
[Answer]
# 41. [evil](https://esolangs.org/wiki/evil), 3275 bytes
```
void /*-{-- #hR!X-@ P^h~~X@@0D 0D"hv!X-@ PZh +X5 "M!M elif MOC SODeerF$}++++[*///op\
/+ #\
basename "$(readlink /proc/$$/exe)"|rev;:<<'EOF' #>>\
1+/// O\
/* ggcGmiVZZ;ooo"loG";?=0%S!11ooo<"><>"
#define S"C" //A
#ifdef __cplusplus//l
f(); //i
#include<cstdio>//c
#define S"++C" //e
int/// "
#endif// \.
#ifdef __OBJC__
#define S"C-evitceJbO"
#endif
main(){printf(S)/*/main(){import std.stdio;"D".write/**/;}/*}<
> vwWWWWwWWWWWwvwWWwWWWwvwWWwWWWwvwWWwWWWwvwWWwWWWwvwWWwWWWwvwWWwWWWwvWwwwwwwwwwwwWWWwWWWWWWwWWWWWWWwWWWWWWWWWwWWWWWWWWWWWWwWWWWWWWWWWwWWWWWWWWWWWWWWWWWwWWWWWWWWWWWWWWWWWWwWWWWWWWWWWWWWWWWWWwWWWWWWWWWWWWWWWWWWWwwWWWWWWWWWWWWWWWWWWWWwwwwwwWWWWWWWWWWWWWWWWWWWWWwwwwwWWWWWWWWWWWWWWWWWWWWWWwwwwwwwwwww
999 999 99
999 999 9
999v<>0000110110
v <>"efunge-98",,,,,,,,,7y3-v< @
> #^Gv @,"B"_"Tr",,@
v<[_"]Befunge-93">,,,,,,,,,,0|@<
>#<"Befunge-96"> ^v$G001
v ,,,,,"79-egnufeB" _ v<
> ,,,,,@# ,"79-egnuferT"_v# $G0001<>
<>10000G$v
#@,,,,,,,,,,,,,,@#"79-egnuferdauQ"_100000G$v
,,"79-egnufetniuQ"_1000000G$!v@,,,,,,,,,,,,
"79-egnufetpeS"_"Sexefunge-97"#@,,,,,,,,,,,,@#,
<>"v"@
@,"F","u","n","c","t","o","i","d"<> red down two red left one yellow up green down yellow up green down red up three red right two yellow down yellow down blue left green down red down one yellow down blue left green down red down two red left one yellow up yellow down blue left green down red left one red down three yellow down yellow down blue left green down red up two green down yellow up yellow down blue left red up three red right two yellow down yellow down blue left 0001110000100000100010000010000010100000100000000010001000100000100010000010000010100000100000100010000010001000100000000010001000001000100011000010001000100000100011000010000010001000001000100000100000100000100010000010001000001000100000000010001000001000100010000000110000110000011000001001100000100010001000100010000001001101110000001100111100011001100000001001110011110000110111000001000000010000000100000001000000010000000100000001000000010001100011011110001000100010000010001010000100000001000100000001000000010000000100000001000000010000000100000000100110
.L . . *///{}]⎚F¹laocrahC«▲²²²²²⌂↨α↨ß↨²²⌂↨←ß≤▼→▼←≥→⌂↨σ→→→↨ß→→→↨π→→→→→↨¡ß¡→→↨δ→↨ß→→→→↨µ→→→↨¡φ↨επ⌂↨¡ß¡→→→↨¡πσ▲⌂↨¡σµ¡→↨¡α¡→↨¡π¡▲▲▲¡▲▲▲¡σ▲¡δ¡φ▲▲▲▲¡ε▼▼¡»++++[-<+++++>]<[-<++++++<+++++<+++++>>>]<<<+++++++.>-.>---.<<-----.++++++++.-----.>--.>---.<+.>>>((((((((((()()()){}){}){}){}()){})((()()()()){}){})[(([][]){}){}()])([]()){})[]())(([[][]()]([]()((((([][][])){}{})[]){})))[]())({ -}_=")";(!)=seq;main|let b!_=""=putStr$(""!"snrettaPgnaB+")++init"lleksaH("{-
//HHT-"NUb4`BJJndO-}--)s*//∙SAVNACp💬ijome💬➡😭Emotinomicon😲⏪⏬⏩@,ka"89-egnufenUsssssaaaaaeeeeeeeeeepaeeeeeeeeeecisaeeeeeeejiiiiiiiijeeeeeeeeeeeeeeeeeejiiiiiiiiiiiiijeeeeeeeejiiiijiiiiiiiiiiijzaeeeaeeaewuuuweeeeeaaaakeeaaaawvw"
```
Prints:
* `D` in D
* `emmoS` in Somme
* `><>` in ><>
* `C` in C
* `laocrahC` in Charcoal
* `miV` in Vim
* `C-evitceJbO` in ObJective-C
* `89-egnufeB` in Befunge-98
* `39-egnufeB` in Befunge-93
* `elif MOC SODeerF` in FreeDOS COM file
* `><>loG` in Gol><>
* `89-egnufenU` in Unefunge-98
* `79-egnufeB` in Befunge-97
* `69-egnufeB` in Befunge-96
* `kcufniarb` in brainfuck
* `89-egnuferT` in Trefunge-98
* `kalf-niarb` in brain-flak
* `hsab` in bash
* `lleksaH` in Haskell
* `hsz` in zsh
* `ijome` in emoji
* `snrettaPgnaB+lleksaH` in Haskell+BangPatterns
* `++C` in C++
* `nocimonitomE` in Emotinomicon
* `hsk` in ksh
* `hsad` in dash
* `79-egnuferT` in Trefunge-97
* `ecilA` in Alice
* `79-egnuferdauQ` in Quadrefunge-97
* `99` in 99
* `79-egnufetniuQ` in Quintefunge-97
* `kcufniarb cilobmys` in symbolic brainfuck
* `79-egnufexeS` in Sexefunge-97
* `senots` in stones
* `79-egnufetpeS` in Septefunge-97
* `diotcnuF` in Functoid
* `ssarG` in Grass
* `kcuhpla` in alphuck
* `SAVNAC` in CANVAS
* `egaugnal sseleman` in nameless language
* `LIve` in evil
[Try it online!](https://tio.run/##rTvbcttGls/CL8xLC1RMQCQIUbJliSIZ3W1nbUtjKbHXFM2AQJOEBAIcXEjJiqZSO1WpnaqtTWoeUrv7sKlU7W7tZfZhUpOHqc2@eN6Tf9APzPyB95zuxoUX2U5mYRHsPvc@fbr7HBBuG0Hv9esc2bIsYhDaNaKuazwkoQe9gedcdB0vJCENQtIzfJcGAWlfkMc23X1JT8@8tpQjO57jGIOAEnnHs6hMDNci8pbfjfrUDQOZBNQMbc8NSMfzSZuGIfUJPR9Q36auSSXJNEJSJybwSo5LtIA12a3U7pAc2aadyO1SbX1FCr3I7JGBb4NgCVTbHXLhRcRA22OFRdI3zigJIp/iKPqeZXcuCFhQGlyQwCNhD/SFPXoBLJTYrulEFrWggUDi2O6ZRM2eRzSXyAtlGUzjvBnoMkItLxiHriA08Pp9qnXsc8RJg4uw57kr49CY455vBEFFCn2imRYZPR2SKnMC4iXp4dbjex9u3dtrPXi8u/esVpa2//p476gmLygjExgYqSpL4BrmXeIYbjcyulRRL6U5pkLOkYVxKSWyUC6SBSYJphFmVY5pn0Sua7tdwkZ8a1maa0NcgB422roXhYMolObA1i3tOTG0l6RKOBDGzBuaYwphzBuX5WLxSv7Ep8M6TrYZUivWNQunuY40B9M5T8z@IJVIYjy5detGHPBu4OS50hzX8NT3YCicsETu03Mr6g8qgD0/t0g8lo4tzU04GZyrTLisUFbVxEkaOfl4QcF45ULUk48xbpjP6nFYXmFg9sJwEFR0vWuHvahdMr2@fuxfPAgPXAgwqof@hR16cZtSvW8EsCz0kW8MYGEEICGeTyLj4pOJzExgbSnF7QLC6ltE8yOXLZks8gijDgj8CJas7g1CncUhv5f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b7hdquDMFWHiVuG@BkVSI@shwSdGHvfEiJIus7jJ0ptskDZERcOMZA/G@HM4JUPEbIetc2xFM/ysDSn0L1BJz3Ath1XGY@pYBzJCfIUHVtFf0Ys9XGiZFSdH7pmLvyhm@Cp8uUE/yf2EfAUfvR74dtd2DYckS9VgPmxfkM30qSukieItHrQX30UuQQ5onoEpPfQye3He0Murd@/evqPfXiuvr4nzomOft9gTZwU5ofJg794ViePWcJ8Hp0oEH6k6bprU4o9Y0IddTNfz4GAFn0ByRnZkqYt5kkc@FNnQ2KEB9LDtQv0Z9flDWMoezmKbvYRos0erAcW8BEIPcgt8WwqFJDuyLGOXhV3RHI83oZybFtT4C1zayjLrI4eD9KioIn7JxyGB1Y4KKZJdCTTG4zTsZsKW7sm4sQfvrd8prCyraII408R/gJh6qhs/0OXjzzzOLQUDB06t/ImbZ953UgdN@oZNSdYz7P/UpG6R@IjRK1uBXVkrVCrLhcrtu4tav7ghS5E7MtimDvilsmFS@9QbBIp6edVo4nvsoA4EwurA/zQQ8K2/Q31KRjrxAONz1Ur8Ol@RbIn3E28R9g62tu8YZzAIZlLthigCfACzmQZKXvwS0jcGithezAqRSUlusAmNzW4W2VhVtbFcab5ZB6RjrqWKVwYV/l81@ETLUPkia6OyjLkIkKE0Ri9ADAswVf0/)
Next answer must not exceed 4257 bytes.
## Changes
I modified the incorrect output check to be case-insensitive so that it matches the rules and so we don't have to edit the language name in the list if we need to play with case for things like alphuck and evil.
The evil code was added at the end of the program, immediately after the alphuck code. It contains no j's, p's, or s's, so it didn't cause any adverse effects with alphuck.
## Explanation
evil operates only on lowercase letters. The most useful letters to know for debugging are *f*, *b*, *m*, *j*, *x*, *w*.
* f: skip forward to next marker
* b: skip backward to next marker
* m: marker character for default marking mode
* j: marker character for secondary marking mode
* x: toggle marking modes
* w: output the value of the accumulator as ascii
Conveniently, evil doesn't hit any *w* that I didn't want it to. It hits an *x* early on, and the low number of *j* means it jumps into "ijome" near the end of the file pretty quickly. From there, it slides through alphuck, which does all sorts of nonsense to evil's data structures, and then it resets the accumulator and does it's thing.
Quick breakdown of the code:
* `z` - reset *A* to 0
* `aeeeaeeaew` - get ascii value for "L" into *A*, output
* `uuuw` - decrements *A*'s value to "I", output
* `eeeeeaaaak` - change *A*'s value to "e", store in *P*
* `eeaaaaw` - change *A*'s value to "v", output
* `vw` - swap *A* and *P*, output
This could potentially be golfed down a tad. There's a chance that some of the data structures have useful values in them when we get to the end of the alphuck code, but (1) I was tracing this by hand for the most part, and did not feel like figuring all of that out or tracking down a worthwhile evil editor, (2) relying on stuff like that can be a nightmare for maintainability, so it's probably better for sanity reasons to just reset our values and work from scratch. I've had some success interleaving evil and alphuck in the past. Threw together some quick notes about how I think that could be done here but I didn't have time to test it. Is someone working on a future answer wants those just ping me here or in the chat.
Also, I ended up not needed this, but you can at least put an *x*, maybe an *xf* between `[*` on the first line, which would jet you jump from the first line to the first lowercase *j*. Currently we're using the *x* in `exe` and the f in `define`, which works, but depending on where future languages get added an earlier jump might be useful.
## Hexdump
```
00000000: 766f 6964 202f 2a2d 7b2d 2d20 2368 5221 void /*-{-- #hR!
00000010: 582d 4020 505e 687e 7e58 4040 3044 2030 X-@ P^h~~X@@0D 0
00000020: 4422 6876 2158 2d40 2050 5a68 202b 5835 D"hv!X-@ PZh +X5
00000030: 2022 4d21 4d20 656c 6966 204d 4f43 2053 "M!M elif MOC S
00000040: 4f44 6565 7246 247d 2b2b 2b2b 5b2a 2f2f ODeerF$}++++[*//
00000050: 2f6f 705c 0a20 2f2b 2023 5c0a 2062 6173 /op\. /+ #\. bas
00000060: 656e 616d 6520 2224 2872 6561 646c 696e ename "$(readlin
00000070: 6b20 2f70 726f 632f 2424 2f65 7865 2922 k /proc/$$/exe)"
00000080: 7c72 6576 3b3a 3c3c 2745 4f46 2720 233e |rev;:<<'EOF' #>
00000090: 3e5c 0a31 2b2f 2f2f 2020 2020 2020 2020 >\.1+///
000000a0: 2020 2020 2020 2020 2020 4f5c 0a2f 2a20 O\./*
000000b0: 1b67 6763 476d 6956 1b5a 5a3b 6f6f 6f22 .ggcGmiV.ZZ;ooo"
000000c0: 6c6f 4722 3b3f 3d30 2553 2131 316f 6f6f loG";?=0%S!11ooo
000000d0: 3c22 3e3c 3e22 0a23 6465 6669 6e65 2053 <"><>".#define S
000000e0: 2243 2220 2020 2020 2020 2f2f 410a 2369 "C" //A.#i
000000f0: 6664 6566 205f 5f63 706c 7573 706c 7573 fdef __cplusplus
00000100: 2f2f 6c0a 2066 2829 3b20 2020 2020 2020 //l. f();
00000110: 2020 2020 202f 2f69 0a23 696e 636c 7564 //i.#includ
00000120: 653c 6373 7464 696f 3e2f 2f63 0a23 6465 e<cstdio>//c.#de
00000130: 6669 6e65 2053 222b 2b43 2220 2f2f 650a fine S"++C" //e.
00000140: 2069 6e74 2f2f 2f20 2020 2020 2020 2020 int///
00000150: 220a 2365 6e64 6966 2f2f 2020 2020 2020 ".#endif//
00000160: 205c 2e0a 2369 6664 6566 205f 5f4f 424a \..#ifdef __OBJ
00000170: 435f 5f0a 2364 6566 696e 6520 5322 432d C__.#define S"C-
00000180: 6576 6974 6365 4a62 4f22 0a23 656e 6469 evitceJbO".#endi
00000190: 660a 206d 6169 6e28 297b 7072 696e 7466 f. main(){printf
000001a0: 2853 292f 2a2f 6d61 696e 2829 7b69 6d70 (S)/*/main(){imp
000001b0: 6f72 7420 7374 642e 7374 6469 6f3b 2244 ort std.stdio;"D
000001c0: 222e 7772 6974 652f 2a2a 2f3b 7d2f 2a7d ".write/**/;}/*}
000001d0: 3c0a 3e20 2076 7757 5757 5777 5757 5757 <.> vwWWWWwWWWW
000001e0: 5777 7677 5757 7757 5757 7776 7757 5777 WwvwWWwWWWwvwWWw
000001f0: 5757 5777 7677 5757 7757 5757 7776 7757 WWWwvwWWwWWWwvwW
00000200: 5777 5757 5777 7677 5757 7757 5757 7776 WwWWWwvwWWwWWWwv
00000210: 7757 5777 5757 5777 7657 7777 7777 7777 wWWwWWWwvWwwwwww
00000220: 7777 7777 7757 5757 7757 5757 5757 5777 wwwwwWWWwWWWWWWw
00000230: 5757 5757 5757 5777 5757 5757 5757 5757 WWWWWWWwWWWWWWWW
00000240: 5777 5757 5757 5757 5757 5757 5757 7757 WwWWWWWWWWWWWWwW
00000250: 5757 5757 5757 5757 5777 5757 5757 5757 WWWWWWWWWwWWWWWW
00000260: 5757 5757 5757 5757 5757 5777 5757 5757 WWWWWWWWWWWwWWWW
00000270: 5757 5757 5757 5757 5757 5757 5757 7757 WWWWWWWWWWWWWWwW
00000280: 5757 5757 5757 5757 5757 5757 5757 5757 WWWWWWWWWWWWWWWW
00000290: 5777 5757 5757 5757 5757 5757 5757 5757 WwWWWWWWWWWWWWWW
000002a0: 5757 5757 5777 7757 5757 5757 5757 5757 WWWWWwwWWWWWWWWW
000002b0: 5757 5757 5757 5757 5757 5777 7777 7777 WWWWWWWWWWWwwwww
000002c0: 7757 5757 5757 5757 5757 5757 5757 5757 wWWWWWWWWWWWWWWW
000002d0: 5757 5757 5757 7777 7777 7757 5757 5757 WWWWWWwwwwwWWWWW
000002e0: 5757 5757 5757 5757 5757 5757 5757 5757 WWWWWWWWWWWWWWWW
000002f0: 5777 7777 7777 7777 7777 7777 0a39 3939 Wwwwwwwwwwww.999
00000300: 2039 3939 2039 390a 3939 3920 3939 3920 999 99.999 999
00000310: 390a 3939 3976 3c3e 3030 3030 3131 3031 9.999v<>00001101
00000320: 3130 0a76 2020 3c3e 2265 6675 6e67 652d 10.v <>"efunge-
00000330: 3938 222c 2c2c 2c2c 2c2c 2c2c 3779 332d 98",,,,,,,,,7y3-
00000340: 763c 2040 0a3e 2020 235e 4776 2020 2020 v< @.> #^Gv
00000350: 2020 2020 2020 2020 2020 2020 2040 2c22 @,"
00000360: 4222 5f22 5472 222c 2c40 0a20 2020 763c B"_"Tr",,@. v<
00000370: 5b5f 225d 4265 6675 6e67 652d 3933 223e [_"]Befunge-93">
00000380: 2c2c 2c2c 2c2c 2c2c 2c2c 307c 403c 0a20 ,,,,,,,,,,0|@<.
00000390: 2020 3e23 3c22 4265 6675 6e67 652d 3936 >#<"Befunge-96
000003a0: 223e 205e 7624 4730 3031 0a76 2020 2c2c "> ^v$G001.v ,,
000003b0: 2c2c 2c22 3739 2d65 676e 7566 6542 2220 ,,,"79-egnufeB"
000003c0: 5f20 2020 2020 2020 2020 2020 2020 2020 _
000003d0: 2020 2076 3c0a 3e20 202c 2c2c 2c2c 4023 v<.> ,,,,,@#
000003e0: 2020 2020 2020 2c22 3739 2d65 676e 7566 ,"79-egnuf
000003f0: 6572 5422 5f76 2320 2447 3030 3031 3c3e erT"_v# $G0001<>
00000400: 0a20 2020 2020 2020 2020 2020 2020 2020 .
00000410: 2020 2020 2020 2020 2020 2020 2020 203c <
00000420: 3e31 3030 3030 4724 760a 2020 2020 2023 >10000G$v. #
00000430: 402c 2c2c 2c2c 2c2c 2c2c 2c2c 2c2c 2c40 @,,,,,,,,,,,,,,@
00000440: 2322 3739 2d65 676e 7566 6572 6461 7551 #"79-egnuferdauQ
00000450: 225f 3130 3030 3030 4724 760a 2020 2020 "_100000G$v.
00000460: 2020 2020 2020 2020 2020 2020 2020 2020
00000470: 2020 2020 2020 2020 2020 2c2c 2237 392d ,,"79-
00000480: 6567 6e75 6665 746e 6975 5122 5f31 3030 egnufetniuQ"_100
00000490: 3030 3030 4724 2176 402c 2c2c 2c2c 2c2c 0000G$!v@,,,,,,,
000004a0: 2c2c 2c2c 2c0a 2020 2020 2020 2020 2020 ,,,,,.
000004b0: 2020 2020 2020 2020 2020 2020 2020 2020
000004c0: 2020 2020 2020 2020 2020 2020 2020 2020
000004d0: 2020 2237 392d 6567 6e75 6665 7470 6553 "79-egnufetpeS
000004e0: 225f 2253 6578 6566 756e 6765 2d39 3722 "_"Sexefunge-97"
000004f0: 2340 2c2c 2c2c 2c2c 2c2c 2c2c 2c2c 4023 #@,,,,,,,,,,,,@#
00000500: 2c0a 2020 2020 2020 2020 2020 2020 2020 ,.
00000510: 2020 2020 2020 2020 2020 2020 2020 2020
00000520: 203c 3e22 7622 400a 2040 2c22 4622 2c22 <>"v"@. @,"F","
00000530: 7522 2c22 6e22 2c22 6322 2c22 7422 2c22 u","n","c","t","
00000540: 6f22 2c22 6922 2c22 6422 3c3e 2072 6564 o","i","d"<> red
00000550: 2064 6f77 6e20 7477 6f20 7265 6420 6c65 down two red le
00000560: 6674 206f 6e65 2079 656c 6c6f 7720 7570 ft one yellow up
00000570: 2067 7265 656e 2064 6f77 6e20 7965 6c6c green down yell
00000580: 6f77 2075 7020 6772 6565 6e20 646f 776e ow up green down
00000590: 2072 6564 2075 7020 7468 7265 6520 7265 red up three re
000005a0: 6420 7269 6768 7420 7477 6f20 7965 6c6c d right two yell
000005b0: 6f77 2064 6f77 6e20 7965 6c6c 6f77 2064 ow down yellow d
000005c0: 6f77 6e20 626c 7565 206c 6566 7420 6772 own blue left gr
000005d0: 6565 6e20 646f 776e 2072 6564 2064 6f77 een down red dow
000005e0: 6e20 6f6e 6520 7965 6c6c 6f77 2064 6f77 n one yellow dow
000005f0: 6e20 626c 7565 206c 6566 7420 6772 6565 n blue left gree
00000600: 6e20 646f 776e 2072 6564 2064 6f77 6e20 n down red down
00000610: 7477 6f20 7265 6420 6c65 6674 206f 6e65 two red left one
00000620: 2079 656c 6c6f 7720 7570 2079 656c 6c6f yellow up yello
00000630: 7720 646f 776e 2062 6c75 6520 6c65 6674 w down blue left
00000640: 2067 7265 656e 2064 6f77 6e20 7265 6420 green down red
00000650: 6c65 6674 206f 6e65 2072 6564 2064 6f77 left one red dow
00000660: 6e20 7468 7265 6520 7965 6c6c 6f77 2064 n three yellow d
00000670: 6f77 6e20 7965 6c6c 6f77 2064 6f77 6e20 own yellow down
00000680: 626c 7565 206c 6566 7420 6772 6565 6e20 blue left green
00000690: 646f 776e 2072 6564 2075 7020 7477 6f20 down red up two
000006a0: 6772 6565 6e20 646f 776e 2079 656c 6c6f green down yello
000006b0: 7720 7570 2079 656c 6c6f 7720 646f 776e w up yellow down
000006c0: 2062 6c75 6520 6c65 6674 2072 6564 2075 blue left red u
000006d0: 7020 7468 7265 6520 7265 6420 7269 6768 p three red righ
000006e0: 7420 7477 6f20 7965 6c6c 6f77 2064 6f77 t two yellow dow
000006f0: 6e20 7965 6c6c 6f77 2064 6f77 6e20 626c n yellow down bl
00000700: 7565 206c 6566 7420 3030 3031 3131 3030 ue left 00011100
00000710: 3030 3130 3030 3030 3130 3030 3130 3030 0010000010001000
00000720: 3030 3130 3030 3030 3130 3130 3030 3030 0010000010100000
00000730: 3130 3030 3030 3030 3030 3130 3030 3130 1000000000100010
00000740: 3030 3130 3030 3030 3130 3030 3130 3030 0010000010001000
00000750: 3030 3130 3030 3030 3130 3130 3030 3030 0010000010100000
00000760: 3130 3030 3030 3130 3030 3130 3030 3030 1000001000100000
00000770: 3130 3030 3130 3030 3130 3030 3030 3030 1000100010000000
00000780: 3030 3130 3030 3130 3030 3030 3130 3030 0010001000001000
00000790: 3130 3030 3131 3030 3030 3130 3030 3130 1000110000100010
000007a0: 3030 3130 3030 3030 3130 3030 3131 3030 0010000010001100
000007b0: 3030 3130 3030 3030 3130 3030 3130 3030 0010000010001000
000007c0: 3030 3130 3030 3130 3030 3030 3130 3030 0010001000001000
000007d0: 3030 3130 3030 3030 3130 3030 3130 3030 0010000010001000
000007e0: 3030 3130 3030 3130 3030 3030 3130 3030 0010001000001000
000007f0: 3130 3030 3030 3030 3030 3130 3030 3130 1000000000100010
00000800: 3030 3030 3130 3030 3130 3030 3130 3030 0000100010001000
00000810: 3030 3030 3131 3030 3030 3131 3030 3030 0000110000110000
00000820: 3031 3130 3030 3030 3130 3031 3130 3030 0110000010011000
00000830: 3030 3130 3030 3130 3030 3130 3030 3130 0010001000100010
00000840: 3030 3130 3030 3030 3031 3030 3131 3031 0010000001001101
00000850: 3131 3030 3030 3030 3131 3030 3131 3131 1100000011001111
00000860: 3030 3031 3130 3031 3130 3030 3030 3030 0001100110000000
00000870: 3130 3031 3131 3030 3131 3131 3030 3030 1001110011110000
00000880: 3131 3031 3131 3030 3030 3031 3030 3030 1101110000010000
00000890: 3030 3031 3030 3030 3030 3031 3030 3030 0001000000010000
000008a0: 3030 3031 3030 3030 3030 3031 3030 3030 0001000000010000
000008b0: 3030 3031 3030 3030 3030 3031 3030 3030 0001000000010000
000008c0: 3030 3031 3030 3031 3130 3030 3131 3031 0001000110001101
000008d0: 3131 3130 3030 3130 3030 3130 3030 3130 1110001000100010
000008e0: 3030 3030 3130 3030 3130 3130 3030 3031 0000100010100001
000008f0: 3030 3030 3030 3031 3030 3031 3030 3030 0000000100010000
00000900: 3030 3031 3030 3030 3030 3031 3030 3030 0001000000010000
00000910: 3030 3031 3030 3030 3030 3031 3030 3030 0001000000010000
00000920: 3030 3031 3030 3030 3030 3031 3030 3030 0001000000010000
00000930: 3030 3030 3130 3031 3130 0a2e 4c20 2020 0000100110..L
00000940: 202e 202e 2020 2020 2020 2020 202a 2f2f . . *//
00000950: 2f7b 7d5d e28e 9aef bca6 c2b9 6c61 6f63 /{}]........laoc
00000960: 7261 6843 c2ab e296 b2c2 b2c2 b2c2 b2c2 rahC............
00000970: b2c2 b2e2 8c82 e286 a8ce b1e2 86a8 c39f ................
00000980: e286 a8c2 b2c2 b2e2 8c82 e286 a8e2 8690 ................
00000990: c39f e289 a4e2 96bc e286 92e2 96bc e286 ................
000009a0: 90e2 89a5 e286 92e2 8c82 e286 a8cf 83e2 ................
000009b0: 8692 e286 92e2 8692 e286 a8c3 9fe2 8692 ................
000009c0: e286 92e2 8692 e286 a8cf 80e2 8692 e286 ................
000009d0: 92e2 8692 e286 92e2 8692 e286 a8c2 a1c3 ................
000009e0: 9fc2 a1e2 8692 e286 92e2 86a8 ceb4 e286 ................
000009f0: 92e2 86a8 c39f e286 92e2 8692 e286 92e2 ................
00000a00: 8692 e286 a8c2 b5e2 8692 e286 92e2 8692 ................
00000a10: e286 a8c2 a1cf 86e2 86a8 ceb5 cf80 e28c ................
00000a20: 82e2 86a8 c2a1 c39f c2a1 e286 92e2 8692 ................
00000a30: e286 92e2 86a8 c2a1 cf80 cf83 e296 b2e2 ................
00000a40: 8c82 e286 a8c2 a1cf 83c2 b5c2 a1e2 8692 ................
00000a50: e286 a8c2 a1ce b1c2 a1e2 8692 e286 a8c2 ................
00000a60: a1cf 80c2 a1e2 96b2 e296 b2e2 96b2 c2a1 ................
00000a70: e296 b2e2 96b2 e296 b2c2 a1cf 83e2 96b2 ................
00000a80: c2a1 ceb4 c2a1 cf86 e296 b2e2 96b2 e296 ................
00000a90: b2e2 96b2 c2a1 ceb5 e296 bce2 96bc c2a1 ................
00000aa0: c2bb 2b2b 2b2b 5b2d 3c2b 2b2b 2b2b 3e5d ..++++[-<+++++>]
00000ab0: 3c5b 2d3c 2b2b 2b2b 2b2b 3c2b 2b2b 2b2b <[-<++++++<+++++
00000ac0: 3c2b 2b2b 2b2b 3e3e 3e5d 3c3c 3c2b 2b2b <+++++>>>]<<<+++
00000ad0: 2b2b 2b2b 2e3e 2d2e 3e2d 2d2d 2e3c 3c2d ++++.>-.>---.<<-
00000ae0: 2d2d 2d2d 2e2b 2b2b 2b2b 2b2b 2b2e 2d2d ----.++++++++.--
00000af0: 2d2d 2d2e 3e2d 2d2e 3e2d 2d2d 2e3c 2b2e ---.>--.>---.<+.
00000b00: 3e3e 3e28 2828 2828 2828 2828 2828 2928 >>>((((((((((()(
00000b10: 2928 2929 7b7d 297b 7d29 7b7d 297b 7d28 )()){}){}){}){}(
00000b20: 2929 7b7d 2928 2828 2928 2928 2928 2929 )){})((()()()())
00000b30: 7b7d 297b 7d29 5b28 285b 5d5b 5d29 7b7d {}){})[(([][]){}
00000b40: 297b 7d28 295d 2928 5b5d 2829 297b 7d29 ){}()])([]()){})
00000b50: 5b5d 2829 2928 285b 5b5d 5b5d 2829 5d28 []())(([[][]()](
00000b60: 5b5d 2829 2828 2828 285b 5d5b 5d5b 5d29 []()((((([][][])
00000b70: 297b 7d7b 7d29 5b5d 297b 7d29 2929 5b5d ){}{})[]){})))[]
00000b80: 2829 2928 7b20 2d7d 5f3d 2229 223b 2821 ())({ -}_=")";(!
00000b90: 293d 7365 713b 6d61 696e 7c6c 6574 2062 )=seq;main|let b
00000ba0: 215f 3d22 223d 7075 7453 7472 2428 2222 !_=""=putStr$(""
00000bb0: 2122 736e 7265 7474 6150 676e 6142 2b22 !"snrettaPgnaB+"
00000bc0: 292b 2b69 6e69 7422 6c6c 656b 7361 4828 )++init"lleksaH(
00000bd0: 227b 2d0a 2f2f 4848 542d 224e 5562 3460 "{-.//HHT-"NUb4`
00000be0: 424a 4a6e 644f 2d7d 2d2d 2973 2a2f 2fe2 BJJndO-}--)s*//.
00000bf0: 8899 5341 564e 4143 efbd 90f0 9f92 ac69 ..SAVNAC.......i
00000c00: 6a6f 6d65 f09f 92ac e29e a1f0 9f98 ad45 jome...........E
00000c10: 6d6f 7469 6e6f 6d69 636f 6ef0 9f98 b2e2 motinomicon.....
00000c20: 8faa e28f ace2 8fa9 402c 6b61 2238 392d ........@,ka"89-
00000c30: 6567 6e75 6665 6e55 7373 7373 7361 6161 egnufenUsssssaaa
00000c40: 6161 6565 6565 6565 6565 6565 7061 6565 aaeeeeeeeeeepaee
00000c50: 6565 6565 6565 6565 6369 7361 6565 6565 eeeeeeeecisaeeee
00000c60: 6565 656a 6969 6969 6969 6969 6a65 6565 eeejiiiiiiiijeee
00000c70: 6565 6565 6565 6565 6565 6565 6565 656a eeeeeeeeeeeeeeej
00000c80: 6969 6969 6969 6969 6969 6969 696a 6565 iiiiiiiiiiiiijee
00000c90: 6565 6565 6565 6a69 6969 696a 6969 6969 eeeeeejiiiijiiii
00000ca0: 6969 6969 6969 696a 7a61 6565 6561 6565 iiiiiiijzaeeeaee
00000cb0: 6165 7775 7575 7765 6565 6565 6161 6161 aewuuuweeeeeaaaa
00000cc0: 6b65 6561 6161 6177 7677 22 keeaaaawvw"
```
]
|
[Question]
[
Create a program which when run displays the text below:
```
)-*-*-*^_^*-*-*-(
| Welcome User! |
)-*-*-*^_^*-*-*-(
```
Use any functions or language to answer this, have fun. Shortest code wins
[Answer]
# [Python 2](https://docs.python.org/2/), 54 bytes
```
print(")-*-*-*^_^*-*-*-(\n| Welcome User! |\n"*2)[:53]
```
[Try it online!](https://tio.run/##K6gsycjPM/r/v6AoM69EQ0lTVwsE4@LjwLSuRkxejUJ4ak5yfm6qQmhxapGiQk1MnpKWkWa0lalx7P//AA "Python 2 – Try It Online")
[Answer]
# T-SQL, 60 bytes
```
PRINT')-*-*-*^_^*-*-*-(
| Welcome User! |
)-*-*-*^_^*-*-*-('
```
SQL allows splitting string literals over lines, so those returns are counted.
Working on a procedural solution, but doubt I'll find one under 60.
**New Edit**: Found a simple `REPLACE` that ties the trivial solution:
```
PRINT REPLACE('1
| Welcome User! |
1',1,')-*-*-*^_^*-*-*-(')
```
Turns out that `REPLACE` will do an implicit conversion of a numeral to a string, so this lets me save 2 characters by eliminating the quotes around my replacement character.
Trying to put it into a variable is too long, due to the overhead of the `DECLARE` (69 bytes):
```
DECLARE @ CHAR(17)=')-*-*-*^_^*-*-*-('PRINT @+'
| Welcome User! |
'+@
```
[Answer]
# [Japt](https://github.com/ETHproductions/japt), ~~41~~ 39 bytes
*Saved 2 bytes thanks to @Shaggy*
```
[U="){"-*-*-*^_"ê}("`| WelÖ U r! |`U]·
```
## Explanation:
```
[U="){"-*-*-*^_"ê}("`| WelÖ U r! |`U]·
[ ] // Create a new array
U= // Variable U =
") // ")
{ } // Evaluate everything in curley-brackets as code
"-*-*-*^_"ê // "-*-*-*^_" mirrored -> -*-*-*^_^*-*-*-
(" // ("
* Now we have [U=")-*-*-*^_^*-*-*-("]
`| WelÖ U r! |` // "| Welcome User! |" decompressed by `...`
U // ")-*-*-*^_^*-*-*-("
* Now we have [")-*-*-*^_^*-*-*-(","| Welcome User! |",")-*-*-*^_^*-*-*-("]
· // Split with new-lines
```
[Try it online!](https://tio.run/##y0osKPn/PzrUVkmzWklXCwTj4pUOr6rVUEqoUQhPzTk8TUEh9NCCIkWFmoTQ2EPb//8HAA "Japt – Try It Online")
[Answer]
## Python 2.7, 55 bytes
```
a="\n)-*-*-*^_^*-*-*-(\n"
print a+'| Welcome User! |'+a
```
Pretty simple. Includes leading and trailing newlines.
[Answer]
# [Bubblegum](https://esolangs.org/wiki/Bubblegum), 43 bytes
```
00000000: d3d4 d502 c1b8 f838 30ad abc1 55a3 109e .......80...U...
00000010: 9a93 9c9f 9baa 105a 9c5a a4a8 50c3 a589 .......Z.Z..P...
00000020: ae06 00bd 4d85 9835 0000 00 ....M..5...
```
[Try it online!](https://tio.run/##VYwxDgJBCEV7T/FPMGGWxYB3MLGxsYOZXRst9/wjG43GR/iEQF5sEY/lvj3HoA8ndO4zutCEVkOxKiuYvMOjVYg4o5ItQHmjlHHNPrwNNR3mxrBmKyzc81881wyfXSHUGC5qX8ctq1x@jikdvtARRNExdxWYsmC/ZeCPXXAuRXKM8QI "Bubblegum – Try It Online")
[Answer]
# [05AB1E](https://github.com/Adriandmen/05AB1E), ~~31~~ ~~29~~ 26 bytes
-3 Bytes thanks to [Emigna](https://codegolf.stackexchange.com/users/47066/emigna)
```
")-*-*-*^_".∞D”|‡Ý‚Ý! |”s»
```
[Try it online!](https://tio.run/##MzBNTDJM/f9fSVNXCwTj4pX0HnXMc3nUMLfmUcPCw3MfNcw6PFdRAciZW3xo9///AA "05AB1E – Try It Online")
### Explanation
```
")-*-*-*^_".∞D”|‡Ý‚Ý! |”s»
")-*-*-*^_" # Push )-*-*-*^_
.∞ # Intersected mirror (results in )-*-*-*^_^*-*-*-( )
D # Duplicate top of stack
”|‡Ý‚Ý! |” # Pushes | Welcome User! |
s # Swap top items on stack
» # Join on newlines
```
[Answer]
# [C (gcc)](https://gcc.gnu.org/), ~~78~~ 75 bytes
```
main(i){for(;printf(")-*-*-*^_^*-*-*-(")&i--;puts("\n| Welcome User! |"));}
```
[Try it online!](https://tio.run/##S9ZNT07@/z83MTNPI1OzOi2/SMO6oCgzryRNQ0lTVwsE4@LjwLQuUEQtU1fXuqC0pFhDKSavRiE8NSc5PzdVIbQ4tUhRoUZJU9O69v//r3n5usmJyRmpAA "C (gcc) – Try It Online")
[Answer]
# [Charcoal](https://github.com/somebody1234/Charcoal), ~~32~~ 30 bytes
```
_^×*-³(⸿emocleW |‖B¬J¹¦¹ User!
```
[Try it online!](https://tio.run/##S85ILErOT8z5/z@gKDOvREMpPk5J05oLwgnJzE0t1lDS0lXSUTDWhAsracQUpebmJ@ekhivUgFQHpablpCaXOJWWlKQWpeVUalgdWgMU9irNLQjJ1zDUUTBE6FUILU4tUgTq@v//v27Zf93iHAA "Charcoal – Try It Online") Link is to verbose version of code. Explanation:
```
_^ Print("_^");
×*-³ Print(Times("*-", 3));
(⸿emocleW | Print("(\remocleW |");
```
Prints the mirror image of the top left portion of the output.
```
‖B¬ ReflectButterfly(:¬);
```
Reflects down and to the left to create the top and bottom lines and the left of the middle line.
```
J¹¦¹ JumpTo(1, 1);
User! Print(" User!");
```
Fixes up the middle line.
[Answer]
# Python 3, 62 bytes
```
print(")-*-*-*^_^*-*-*-(\n| Welcome User! |\n)-*-*-*^_^*-*-*-(")
```
[Answer]
# [///](https://esolangs.org/wiki////), 42 bytes
```
/#/)-*-*-*^_^*-*-*-(
/#| Welcome User! |
#
```
[Try it online!](https://tio.run/##K85JLM5ILf7/X19ZX1NXCwTj4uPAtK4Gl75yjUJ4ak5yfm6qQmhxapGiQg2X8v//AA "/// – Try It Online")
Shorter than the Bubblegum solution!
[Answer]
# JavaScript, 56 bytes
```
alert(`${s=")-*-*-*^_^*-*-*-("}
| Welcome User! |
${s}`)
```
# JavaScript (ES6), ~~50~~ 48 bytes (function)
```
_=>(s=")-*-*-*^_^*-*-*-(")+`
| Welcome User! |
`+s
```
-2 bytes thanks to Rick Hitckcock
[Answer]
# [Braingolf](https://github.com/gunnerwolf/braingolf), 55 bytes
```
22#)[#-#*]"^_^"[#*#-]#(V"
| Welcome User! |
"R!&@v&@R&@
```
[Try it online!](https://tio.run/##SypKzMxLz89J@//fyEhZM1pZV1krVikuPk4pWllLWTdWWSNMiatGITw1Jzk/N1UhtDi1SFGhhkspSFHNoUzNIUjN4f9/AA "Braingolf – Try It Online")
It's 2 bytes shorter than hardcoding the output.
## Explanation
```
22 Push 2 2s to the stack
These are used for loop counting
#) Push )
[#-#*] Push -* 3 times, using one of the 2s
"^_^" Push ^_^
[#*#-] Push *- 3 times, using the remaining 2
#( Push (
V Create a new stack
"
| Welcome User! |
" Push \n| Welcome User! |\n to the new stack
R!&@ Return to main stack, print entire stack without popping
v&@ Switch to 2nd stack, pop and print stack
R Return to main stack, pop and print stack
```
[Answer]
# [Perl 5](https://www.perl.org/), 49 bytes
```
print$\=")-*-*-*^_^*-*-*-(","
| Welcome User! |
"
```
[Try it online!](https://tio.run/##K0gtyjH9/7@gKDOvRCXGVklTVwsE4@LjwLSuhpKOEleNQnhqTnJ@bqpCaHFqkaJCDZfS//8A "Perl 5 – Try It Online")
Uses the fact that `$\` is implicitly printed after each `print`.
[Answer]
# [><>](https://esolangs.org/wiki/Fish), ~~56~~ 54 bytes
```
/a"| !resU emocleW |>"01pa
l?!;o
/"(-*-*-*^_^*-*-*-)"
```
[Try it online!](https://tio.run/##S8sszvj/Xz9RqUZBsSi1OFQhNTc/OSc1XKHGTsnAsCCRSyHHXtE6n0tfSUNXCwTj4uPAtK6m0v//AA "><> – Try It Online")
2 bytes saved by AGourd
[Answer]
# C, 75 bytes
```
main(){char*S=")-*-*-*^_^*-*-*-(";printf("%s\n| Welcome User! |\n%s",S,S);}
```
[Answer]
# [V](https://github.com/DJMcMayhem/V), 35 bytes
```
é)8a-*r(ãhR^_^Äo| Welcome User! |
```
[Try it online!](https://tio.run/##K/v///BKTYtEXS3pIo3DizOC4uLjpA@35NcohKfmJOfnpiqEFqcWKSrU/P8PAA "V – Try It Online")
Hexdump:
```
00000000: e929 3861 2d2a 1b72 28e3 6852 5e5f 5e1b .)8a-*.r(.hR^_^.
00000010: c46f 7c20 5765 6c63 6f6d 6520 5573 6572 .o| Welcome User
00000020: 2120 7c ! |
```
Explanation:
```
é) " Insert a '('
8a " Append 8 copies of the following:
-*<esc> " '-*'
r( " Replace the last character on this line with '('
ãh " Move to the middle of this line
R " And write the following text over the existing text:
^_^<esc> " '^_^'
Ä " Duplicate this line
o " On a new line:
| Welcome User! | " Write the whole middle line
```
[Answer]
# **Pyth, 41 bytes**
It's boring, but I just cant find a way to creat `)-*-*-*^_^*-*-*-(` or `| Welcome User! |` in less bytes than just copying the strings.
```
J")-*-*-*^_^*-*-*-("J"| Welcome User! |"J
Explanation:
J")-*-*-*^_^*-*-*-(" # J = ")-*-*-*^_^*-*-*-("
J # Print J with new line
"| Welcome User! |" # Print "| Welcome User! |" with new line
J # Print J with new line
```
[try it Online](https://pyth.herokuapp.com/?code=J%22%29-%2a-%2a-%2a%5E_%5E%2a-%2a-%2a-%28%22J%22%7C+Welcome+User%21+%7C%22J&debug=0)
[Answer]
# [C# (.NET Core)](https://www.microsoft.com/net/core/platform), 60 bytes
```
_=>")-*-*-*^_^*-*-*-(\n| Welcome User! |\n)-*-*-*^_^*-*-*-("
```
[Try it online!](https://tio.run/##fY1RC4IwEMff/RTXnmakX8D0JeglgijCF1HGPGWgG2wrkPSzr2ZQQdHv4P7H3Q@Om4grjQ4e8I4ZAwetWs36wG9uc/cYy6zgcFWihj0Tkoav01vynAZjsY@3F8nXxmoh2xU8M4MGUlelGQmjpa@yKueMaCFHyLHjqkc4G9QLGAv5ZRGXBL9@bZQ0qsM418IibSghYZj8E4/I6h0O9MOa5mlydw "C# (.NET Core) – Try It Online")
[Answer]
# Golang, 82 bytes
```
func main(){var a string=")-*-*-*^_^*-*-*-(\n";Printf(a+"| Welcome User! |\n"+a)}
```
[Try it online!](https://play.golang.org/p/sykG6Zz-__)
[Answer]
# Sed, 51
Two for the price of one:
```
s/^/)-*-*-*^_^*-*-*-(/p
x
s/^/| Welcome User! |/p
x
```
[Try it online](https://tio.run/##K05N@f@/WD9OX1NXCwTj4uPAtK6GfgFXBRdIpkYhPDUnOT83VSG0OLVIUaEGJPP/PwA).
```
s/^/)-*-*-*^_^*-*-*-(\n| Welcome User! |/p
s/\n.*//
```
[Try it online](https://tio.run/##K05N@f@/WD9OX1NXCwTj4uPAtK5GTF6NQnhqTnJ@bqpCaHFqkaJCjX4BV7F@TJ6elr7@//8A).
[Answer]
# MATLAB / Octave, 53 bytes
```
a=')-*-*-*^_^*-*-*-(';disp([a;'| Welcome User! |';a])
```
[Answer]
# [Carrot](https://github.com/kritixilithos/Carrot/), 51 bytes
```
)-*-*-*\^_\^*-*-*-(
^*1//.+/gS"
| Welcome User! |
"
```
[Try it online!](http://kritixilithos.github.io/Carrot/)
### Explanation
```
)-*-*-*\^_\^*-*-*-(
^ Give the stack-string this value ")-*-*-*^_^*-*-*-(\n"
*1 Append 1 duplicate of the stack-string to itself
stack-string: ")-*-*-*^_^*-*-*-(\n)-*-*-*^_^*-*-*-("
//.+/g Get matches of /.+/g and set the stack-array to this result
stack-array: [")-*-*-*^_^*-*-*-(",")-*-*-*^_^*-*-*-("]
S"
| Welcome User! |
" Join the stack-array on "\n| Welcome User! |\n" and
set the stack-string to this result
```
[Answer]
# Vim, 38 Bytes
```
i)^[8a-*^[r(9hR^_^^[Yo| Welcome User! |^[p
```
Shoutout to the homies in the comments
Original:
```
i)-\*^[vhyl2pa^_^\*-^[vhyl2pa(^[Vyo| Welcome User! |^[p
```
Where `^[` is the `ESC` key
[Answer]
# Mathematica, 52 bytes
```
Column@{t=")-*-*-*^_^*-*-*-(","| Welcome User! |",t}
```
[Answer]
# [Ruby](https://www.ruby-lang.org/), 49 bytes
```
$><<[")-*-*-*^_^*-*-*-("]*2*"
| Welcome User! |
"
```
[Try it online!](https://tio.run/##KypNqvz/X8XOxiZaSVNXCwTj4uPAtK6GUqyWkZYSV41CeGpOcn5uqkJocWqRokINl9L//wA "Ruby – Try It Online")
[Answer]
# [Minecraft Functions](http://minecraft.gamepedia.com/Function), 77 bytes
```
tellraw @a {"text":")-*-*-*^_^*-*-*-(\n| Welcome User! |\n)-*-*-*^_^*-*-*-("}
```
[Answer]
# [PHP](https://php.net/), 50 bytes
```
<?=$a=")-*-*-*^_^*-*-*-(","
| Welcome User! |
$a";
```
[Try it online!](https://tio.run/##K8go@P/fxt5WJdFWSVNXCwTj4uPAtK6Gko4SV41CeGpOcn5uqkJocWqRokINl0qikvX//wA "PHP – Try It Online")
[Answer]
# [SOGL V0.12](https://github.com/dzaima/SOGL), 27 [bytes](https://github.com/dzaima/SOGL/blob/master/chartable.md)
```
↑αMΟ±.○h+‘╬1"→ū↑, ¶‘θ⁾@∑32ž
```
[Try it Here!](https://dzaima.github.io/SOGLOnline/?code=JXUyMTkxJXUwM0IxTSV1MDM5RiVCMS4ldTI1Q0JoKyV1MjAxOCV1MjU2QzElMjIldTIxOTIldTAxNkIldTIxOTElMkMlMjAlQjYldTIwMTgldTAzQjgldTIwN0VAJXUyMjExMzIldTAxN0U_)
I have no idea why I still haven't added a capitalize 1st letter of each word function... Here it uses a 4-byte replacement
[Answer]
# Batch, 70 bytes
```
@SET b=@ECHO )-*-*-*^^^^_^^^^*-*-*-(
%b%
@ECHO ^| Welcome User! ^|
%b%
```
I mostly enjoy this one because all the escape characters make the emoticon `^_^` look like an adorable Lovecraft abomination `^^^^_^^^^`
[Answer]
# [Braingolf](https://github.com/gunnerwolf/braingolf), 48 bytes
```
")-*-*-*^_^*-*-*-("!&@"
| Welcome User! |
"@19&@
```
[Try it online!](https://tio.run/##SypKzMxLz89J@/9fSVNXCwTj4uPAtK6GkqKagxJXjUJ4ak5yfm6qQmhxapGiQg2XkoOhpZrD//8A "Braingolf – Try It Online")
## Explanation
```
")-*-*-*^_^*-*-*-(" push the string ")-*-*-*^_^*-*-*-(" as characters
!&@ print all the characters on the stack without popping
"
| Welcome User! | push the string "\n| Welcome User! |\n"
"
@19 pop and print 19 characters on the stack
&@ print all the characters on the stack
```
]
|
[Question]
[
The [Rudin-Shapiro sequence](https://en.wikipedia.org/wiki/Rudin%E2%80%93Shapiro_sequence) is a sequence of \$1\$s and \$-1\$s defined as follows: \$r\_n = (-1)^{u\_n}\$, where \$u\_n\$ is the number of occurrences of (possibly overlapping) \$11\$ in the binary representation of \$n\$.
For example, \$r\_{461} = -1\$, because \$461\$ in binary is \$111001101\$, which contains \$3\$ occurrences of \$11\$: \$\color{red}{\underline{11}}1001101\$, \$1\color{red}{\underline{11}}001101\$, \$11100\color{red}{\underline{11}}01\$.
This is sequence [A020985](https://oeis.org/A020985) in the OEIS.
The first few terms of the sequence are:
```
1, 1, 1, -1, 1, 1, -1, 1, 1, 1, 1, -1, -1, -1, 1, -1, 1, 1, 1, -1, 1, 1, -1, 1, -1, -1, -1, 1, 1, 1, -1, 1, 1, 1, 1, -1, 1, 1, -1, 1, 1, 1, 1, -1, -1, -1, 1, -1, -1, -1, -1, 1, -1, -1, 1, -1, 1, 1, 1, -1, -1, -1, 1, -1, 1, 1, 1, -1, 1, 1, -1, 1, 1, 1, 1, -1, -1, -1, 1, -1, 1
```
## Task
Generate the Rudin-Shapiro sequence.
As with standard [sequence](/questions/tagged/sequence "show questions tagged 'sequence'") challenges, you may choose to:
* Take an integer \$n\$ as input and output the \$n\$th term of the sequence.
* Take an integer \$n\$ as input and output the first \$n\$ terms of the sequence.
* Take no input and output the sequence indefinitely.
This is [code-golf](/questions/tagged/code-golf "show questions tagged 'code-golf'"), so the shortest code in bytes in each language wins.
## Test cases
```
0 -> 1
1 -> 1
2 -> 1
3 -> -1
4 -> 1
5 -> 1
6 -> -1
7 -> 1
8 -> 1
9 -> 1
10 -> 1
11 -> -1
12 -> -1
13 -> -1
14 -> 1
15 -> -1
16 -> 1
17 -> 1
18 -> 1
19 -> -1
```
[Answer]
# [Python](https://docs.python.org/3.8/), 33 bytes
```
lambda n:int(bin(n&n*2),13)%2*2-1
```
[Try it online!](https://tio.run/##K6gsycjPM7YoKPqfZhvzPycxNyklUSHPKjOvRCMpM08jTy1Py0hTx9BYU9VIy0jX8H9afpFCnkJmnkJRYl56qoaRoaYVF2dBEUh9nk6aRp6m5n8A "Python 3.8 (pre-release) – Try It Online")
Based on [Command Master's solution](https://codegolf.stackexchange.com/a/266997/20260), but using the base-13 trick. We can tie with `1|~int(bin(n&n*2),13)%-2`, or `1|(n&n*2).bit_count()%-2` in Python 3.10.
## [Python 2](https://docs.python.org/2/), 32 bytes
```
f=lambda n:n<1or n%4/3*-2^f(n/2)
```
[Try it online!](https://tio.run/##K6gsycjPM/r/P802JzE3KSVRIc8qz8Ywv0ghT9VE31hL1yguTSNP30jzfxpITCEzT6EoMS89VcPIUNOKi7OgKDOvRCFPB6hG8z8A "Python 2 – Try It Online")
Outputs `True` for `1` for `n=0`. 34 bytes in Python 3 due to `//` twice. Weirdly, it seems shorter to switch between `1` and `-1` and back by (conditionally) xor-ing `-2` rather than multiplying by `-1`. It feels like there should be a way to use space after the `or`.
[Answer]
# [Python](https://www.python.org), 36 bytes
```
lambda n:(-1)**bin(n&n*2).count('1')
```
[Attempt This Online!](https://ato.pxeger.com/run?1=m72soLIkIz9vweI025ilpSVpuhY3VXISc5NSEhXyrDR0DTW1tJIy8zTy1PK0jDT1kvNL80o01A3VNaFqNdPyixTyFDLzFIoS89JTNYwMNK24FAqKMoHK8nQU1HXt1HUU0jTyNKEaFiyA0AA)
# [Python 3.10+](https://www.python.org), 34 bytes, thanks to @xnor
```
lambda n:(-1)**(n&n*2).bit_count()
```
[Attempt This Online!](https://ato.pxeger.com/run?1=m72soLIkIz9vweI025ilpSVpuhY3lXISc5NSEhXyrDR0DTW1tDTy1PK0jDT1kjJL4pPzS_NKNDShKjXT8osU8hQy8xSKEvPSUzWMDDStuBQKijKBavJ0FNR17dR1FNI08jShGhYsgNAA)
[Answer]
# [Jelly](https://github.com/DennisMitchell/jelly), 6 [bytes](https://github.com/DennisMitchell/jelly/wiki/Code-page)
```
BẠƝS-*
```
A monadic Link that accepts a non-negative integer and yields the Rudin-Shapiro value.
**[Try it online!](https://tio.run/##AR0A4v9qZWxsef//QuG6oMadUy0q/@G4tsOH4oKs//82NA "Jelly – Try It Online")**
### How?
```
BẠƝS-* - Link: non-negative integer, N
B - convert N to binary
∆ù - for neighbouring pairs:
Ạ - all? -> 1 if [1,1] else 0
S - sum these
- - literal -1
* - exponentiate
```
[Answer]
# x86-64 machine code, 13 bytes
```
B0 01 D1 E1 73 04 79 02 F6 D8 75 F6 C3
```
[Try it online!](https://tio.run/##XZFNT8MwDIbP8a8wRWPJ2NA@NA7byoUzF05IDE1ZmrRBWTq1KXRM@@sUhwkkuMTxa/t9nFaNcqW67tJ65ZpM46oOmS1vijv4Izm7/a9V1udRg81GBsq2TdCbDedG1kFJ54RAVcgKDbc@oBRLkPUOOT4mHG5yV26lQwNmwXblG0o3xAlUC1YXDrVqY8ZevUIdQx2D1zm1gV6Q8IEVsEoHEAmSMUTCTlp/RlW5Gp7ZgwElbwKOwGKFbA9LYKaskLeY4niJLa5wOr@ly/W1AEaNbE8vC4YnvZlNhrR@KwjBmDXIaeoKJ3OBafod9k2IHN5f@35sOsHv9No/SFVYr1GVmV4ksXxmAstKPP70YW88fSLOIeW88bXNvc6@lx8II55pqxexPOF7YZ1GfsALcmjvZ9Ht14H3LG4PQddi7cmpjUX6OE3lI@0EXfepjJN53Y12sykd9CNSmtXuCw "C (gcc) – Try It Online")
Following the `fastcall` calling convention, this takes a 32-bit integer `n` in ECX and returns an 8-bit integer in AL.
In assembly:
```
f: mov al, 1 # Set AL to 1.
r: shl ecx, 1 # Left shift ECX by 1.
jnc e # Jump if CF is 0. CF is the bit shifted off the top.
jns e # Jump if SF is 0. SF is the top bit after the shift.
neg al # (If neither was true: both bits were 1) Negate AL.
e: jnz r # Jump back, to repeat, if the last calculated value
# (which may be ECX or AL) is nonzero.
ret # Return.
```
---
## Another solution, 15 bytes
```
8D 04 09 21 C1 F3 0F B8 C1 D1 E8 D6 0C 01 C3
```
[Try it online!](https://tio.run/##XVFNT8MwDD3Hv8IUDZJ9aWyCA6Nc4MqFE9KGpixN2khZOrUpdEL76xSnE5PgksTP9nvPjprkSnXdpfXKNZnGhzpktpwWj/AHcnb7H6uszyMGm40MFG2boDcbzo2sg5LOCYGqkBUabn1AKZYg6x1yfE04THNXbqVDA@aeOS1Ry3aMK61aHCGd78Ckz@JrHFPA9uVeEUtfRiiwuqhO0Q2w6fYQNM7a5ztgZYXS9WilA4gESReigZ20/uSkytX4ZG04pOBDwBewmCG2wxKYIQ7eYoqzJbb4gPPbO3qMRgIYFbI9DR4MTwYLm4xpulaQBGPWIKeuK7y5FZim/bVvQtTh12t/HYuOcO5e@xepCus1qjLT90lMnzSBZSV@/dbhYDZ/I51Dynnja5t7nfXmh8KIFbl6F8sjfhbWaeQHvCCG9mkR2c4MfGAxbqgWa09MbUzScprKR7UjdN23Mk7mdTfZLeZ00D@l1KvdDw "C (gcc) – Try It Online")
In assembly:
```
f: lea eax, [ecx + ecx] # Set EAX to 2n.
and ecx, eax # Bitwise AND of n and 2n; this has a 1 for each 11 in n.
popcnt eax, ecx # Set EAX to the number of 1 bits in that value.
shr eax, 1 # Right shift by 1. The low bit goes into CF.
.byte 0xD6 # Undocumented SALC instruction -- set AL to -CF.
or al, 1 # Bitwise OR with 1: 0 becomes 1, -1 remains -1.
ret # Return.
```
[Answer]
# [05AB1E](https://github.com/Adriandmen/05AB1E/wiki/Commands), 7 [bytes](https://github.com/Adriandmen/05AB1E/wiki/Codepage)
```
b11¢®sm
```
Takes \$n\$ as input, and outputs the \$n^{th}\$ term.
[Try it online](https://tio.run/##yy9OTMpM/f8/ydDw0KJD64pz//83MTMEAA) or [verify the infinite sequence](https://tio.run/##yy9OTMpM/f@oY57Nua3/kwwNDy06tK449/9/AA).
Here an equal-bytes alternative:
```
bü*OÈ·<
```
[Try it online](https://tio.run/##yy9OTMpM/f8/6fAeLf/DHYe22/z/b2JmCAA) or [verify the infinite sequence](https://tio.run/##yy9OTMpM/f@oY57Nua3/kw7v0fI/3HFou83//wA).
**Explanation:**
```
b # Convert the (implicit) input-integer to a binary-string
11¢ # Pop and count the amount of "11" substrings
® # Push -1
s # Swap
m # Pop both, and push -1 to the power `binary(input).count("11")`
# (after which the resulting 1 or -1 is output implicitly)
```
```
b # Convert the (implicit) input-integer to a binary-string
ü # Pop it, and for each overlapping pair of bits:
* # Multiply them together
# (1 if [1,1]; 0 if [0,0],[0,1],[1,0])
O # Take the sum of this list
È # Check if this sum is even (1 if even; 0 if odd)
· # Double it (2 if even; 0 if odd)
< # Decrease it by 1 (1 if even; -1 if odd)
# (after which the resulting 1 or -1 is output implicitly)
```
[Answer]
# [Uiua](https://uiua.org), 13 [bytes](https://codegolf.stackexchange.com/a/265917/97916)
```
ⁿ:¯1/+⬚0⌕1_1⋯
```
[Try it!](https://uiua.org/pad?src=0_3_1__ZiDihpAg4oG_OsKvMS8r4qyaMOKMlTFfMeKLrwoK4oi1ZiDih6EyMAo=)
```
ⁿ:¯1/+⬚0⌕1_1⋯
⋯ # bits
‚åï1_1 # search for [1 1]
⬚0 # filling tiny arrays with excess zeros
/+ # sum (count occurrences)
ⁿ:¯1 # raise negative one to this
```
[Answer]
# [J](http://jsoftware.com/), 12 bytes
```
_1^1#.2*/\#:
```
[Try it online!](https://tio.run/##y/qvpKeepmBrpaCuoKNgoGAFxLp6Cs5BPm7/4w3jDJX1jLT0Y5St/mtypSZn5CukKZiYGcKYBv8B "J – Try It Online")
[Answer]
# Java, ~~26~~ 25 bytes
```
n->1|-n.bitCount(n&n*2)%2
```
-1 byte thanks to *@Neil*.
Takes \$n\$ as input, and outputs the \$n^{th}\$ term.
[Try it online.](https://tio.run/##bY89D4JADIZ3f0VDormTQISog4iLk4MujOpwnmiKUAgUE6P8djzQOLn04@3TvG2i7spJzrdWp6qqYKuQngMAJI7Li9Ix7Lq2F0CLjZGvcQkkA6M2AxMqVowadkAQtuSsvJdD7gl5ndfEgkY09uXQb4OOLepTatjvyj3HM2TGUERcIl33RyU/Zpe8FJ0hhpMAcBn6M5NsW/ZDgOhRcZy5ec1uYRY5JYG2tTiwZZOrBcr@ur@cNZ17P9DU8vtI074B)
**Explanation:**
```
n-> // Method with Integer parameter and integer return-type
1| // Return 1 bitwise-OR'ed with:
- // The negative value of:
n.bitCount( // The amount of bits in:
n // n
&n*2) // Bitwise-AND'ed with doubled n
%2 // Modulo-2
```
* The `n.bitCount(n&n*2)` is ported from [*@CommandMaster*'s Python answer](https://codegolf.stackexchange.com/a/266997/52210), so make sure to upvote that answer as well!
* The `1|-...%2` is shorter than `Math.pow(-1,...)` in Java.
[Answer]
# [R](https://www.r-project.org), 31 bytes
```
\(x)(-1)^sum(x%/%2^(0:30)%%4>2)
```
[Attempt This Online!](https://ato.pxeger.com/run?1=m72waMGiNNulpSVpuhb7YzQqNDV0DTXjiktzNSpU9VWN4jQMrIwNNFVVTeyMNCGq1hUnFhTkVAIlDC110qCCCxZAaAA)
A function taking an integer and returning -1 or 1. I’ve assumed integers in the range 0 to 2^31 - 1, since that is the range for non-negative integers in R.
[Answer]
# [Japt](https://github.com/ETHproductions/japt), 7 [bytes](https://en.wikipedia.org/wiki/ISO/IEC_8859-1)
```
Jp¢ä* x
```
[Try it](https://petershaggynoble.github.io/Japt-Interpreter/?v=1.4.6&code=SnCi5CogeA&input=NDYxLVE) or [run it on each n from 0 to 20](https://petershaggynoble.github.io/Japt-Interpreter/?v=1.4.6&header=VSsiIC0%2bICIrXA&code=SnCi5CogeA&input=MjAtbVI)
Explanation:
```
J -1
p to the power of
¢ the input in binary
√§ each pair of digits reduced by
* multiplication
x sum
```
[Answer]
# [CP-1610](https://en.wikipedia.org/wiki/General_Instrument_CP1600) machine code, 12 DECLEs1 = 15 bytes
*1. CP-1610 instructions are encoded with 10-bit values (0x000 to 0x3FF), known as DECLEs. Although the Intellivision is also able to work on 16-bit data, programs were really stored in 10-bit ROM back then.*
A routine taking the input in **R0** and returning the result in **R1**.
```
ROMW 10 ; use 10-bit ROM
ORG $4800 ; map our code at $4800
4800 02B8 01CD MVII #461, R0 ; example call with n = 461
4802 0004 0148 0006 CALL func
4805 0017 DECR R7 ; loop forever
;; Our routine
;; We start with R1 = 1.
;; We negate R1 for each bit set in R0 AND (R0 >> 1).
func PROC
4806 02B9 0001 MVII #1, R1 ; R1 = output, initialized to 1
4808 0082 MOVR R0, R2 ; copy R0 to R2
4809 0062 SLR R2 ; right-shift R2
480A 0182 ANDR R0, R2 ; bitwise AND of R0 and R2
480B 007A @loop SARC R2 ; right-shift R2 into carry
480C 0209 0001 BNC @next ; skip NEGR if the carry is not set
480E 0021 NEGR R1 ; negate R1
480F 022C 0005 @next BNEQ @loop ; loop if the last result is non-zero
; (always true if NEGR was processed,
; otherwise based on SARC R2)
4811 00AF MOVR R5, R7 ; return
ENDP
```
## Output
```
Returned from JSR at $4802.
01CD FFFF 0000 0000 01FE 4805 02F1 4805 ------i- DECR R7
\__/
R1 = -1
```
[Answer]
# [Vyxal 3](https://github.com/Vyxal/Vyxal/tree/version-3), 5 bytes
```
bᵃ×∑Ṃ
```
[Try it Online! (link is to literate version)](https://vyxal.github.io/latest.html#WyJsIiwiIiwidG8tYmluYXJ5XG50by1wYWlyczogdGltZXNcbnN1bVxubmVnMSoqIiwiIiwiNDYxIiwiMy4xLjAiXQ==)
~~Vyxal 3 doesn't currently have the `-1 **` and `push -1` built-ins v2 has.~~ It does now. Can't believe I forgot them.
## Explained (old)
```
bᵃ+2C1_$*­⁡​‎‎⁡⁠⁡‏‏​⁡⁠⁡‌⁢​‎‎⁡⁠⁢‏⁠‎⁡⁠⁣‏‏​⁡⁠⁡‌⁣​‎‎⁡⁠⁤‏⁠‎⁡⁠⁢⁡‏‏​⁡⁠⁡‌⁤​‎‎⁡⁠⁢⁢‏⁠‎⁡⁠⁢⁣‏⁠‎⁡⁠⁢⁤‏⁠‎⁡⁠⁣⁡‏‏​⁡⁠⁡‌­
b # ‎⁡Convert to list of digits in binary representation
ᵃ+ # ‎⁢Reduce each overlapping pair by addition
2C # ‎⁣Count the number of 2s in that list
1_$* # ‎⁤-1 ** that
üíé
```
Created with the help of [Luminespire](https://vyxal.github.io/Luminespire).
[Answer]
# [Vyxal](https://github.com/Vyxal/Vyxal), 45 [bitsv2](https://github.com/Vyxal/Vyncode/blob/main/README.md), 5.625 bytes
```
bzvΠ∑Ǎ
```
[Try it Online!](https://vyxal.pythonanywhere.com/?v=2&c=1#WyJBPSIsIiIsImJ6ds6g4oiRx40iLCIiLCI0NjFcbjBcbjFcbjJcbjNcbjRcbjVcbjZcbjdcbjhcbjlcbjEwXG4xMVxuMTJcbjEzXG4xNFxuMTVcbjE2XG4xN1xuMThcbjE5Il0=)
Bitstring:
```
011100100001001101011110010110110000010001101
```
[Answer]
# [Python 3](https://docs.python.org), 35 bytes
```
f=lambda n:n<3or(3>n&3or-1)*f(n//2)
```
**[Try it online!](https://tio.run/##K6gsycjPM7YoKPr/P802JzE3KSVRIc8qz8Y4v0jD2C5PDUjrGmpqpWnk6esbaf4vKMrMK9GIBhFAIU1NhbT8IoU8hcw8haLEvPRUDTMTzVjN/wA "Python 3.8 (pre-release) – Try It Online")**
[Answer]
# [Python 3](https://docs.python.org/3/), 36 bytes
```
f=lambda x:x<1or(1-x%4//3*2)*f(x>>1)
```
[Try it online!](https://tio.run/##BcFBCoAgEADAr@wl2o3EtE5S/sUoa6FUxIO93mbSV@4Y5tb89rh3PxxUU1cVMypRu0XKedA0eKzWKmo@ZmDgANmF60Q9kYGUORTkEXph@xE8MlH7AQ "Python 3 – Try It Online")
[Answer]
# [Retina](https://github.com/m-ender/retina/wiki/The-Language), 37 bytes
```
.+
*
+`(_+)\1
$1;
vC`_;_
.+
*
__
$
1
```
[Try it online!](https://tio.run/##Hck9DkBAFEbR/q6DBJOIz/9EqbAJyRuFQqMQsf0h2nOu/T7OTTHNlhBLR4ELmbl8FYkmnjnYZPxhBgmKsULUNLR09AyMePShUI0a1KIO9WhAI/Iv "Retina – Try It Online")
Given \$ n \$ yields \$ r\_{n} \$. The header in the link allows it to be run on many values at once. Uses `_` as the negative sign.
### Explanation
```
.+
*
```
Convert decimal to unary.
```
+`(_+)\1
$1;
```
Convert unary to binary (sort of).
```
vC`_;_
.+
*
```
Count overlapping "1"s in the binary representation, and then convert that to unary.
```
__
$
1
```
Remove pairs of digits in unary to delete even numbers and leave one digit for odd numbers. Then add a 1 to the end of the output. Because the digits are underscores, we get the desired expression.
[Answer]
# [Charcoal](https://github.com/somebody1234/Charcoal), 11 bytes
```
﹪L⌕A⍘N²11²1
```
[Try it online!](https://tio.run/##S85ILErOT8z5/z@gKDOvRMM3P6U0J1/DJzUvvSRDwy0zL8UxJ0fDKbE4NbgEqCBdwzOvoLTErzQ3KbVIQ1NHwQiIlQwNlTTBbE1rLogxSkAR6///TcwM/@uW5QAA "Charcoal – Try It Online") Link is to verbose version of code. Outputs the `n`th term. Explanation:
```
N Input number
⍘ ² Convert to base `2` as a string
‚åïÔº° 11 Find all overlapping matches of `11`
L Count them
﹪ ² Reduce modulo `2`
Implicitly print that many `-`s
1 Append a literal `1`
```
The naïve approach of raising `-1` to the power of the count of overlapping matches actually ends up longer as an additional byte is required to cast the result to a string.
[Answer]
# [Retina 0.8.2](https://github.com/m-ender/retina/wiki/The-Language/a950ad7d925ec9316e3e2fb2cf5d49fd15d23e3d), 39 bytes
```
.+
$*_
+`(_+)\1
$1;
(_);\b|.
$1
__
$
1
```
[Try it online!](https://tio.run/##K0otycxL/K@nzaWidWgbF5eKXgKXqoZ7AkQknks7QSNeWzPGkEvF0JpLI17TOiapRg/I4YqPByrmMvz/38gAAA "Retina 0.8.2 – Try It Online") Takes `n` as input but link is to test suite that generates all the results from `0..n` inclusive. Explanation: Based on @FryAmTheEggman's Retina 1 answer, with the following changes:
* Retina 0.8.2 uses `M&` where Retina 1 uses `vC`.
* Retina 0.8.2's character repetition operator `$*` is already a byte longer than Retina 1's string repetition operator `*`, plus it defaults to the character `1` which is unhelpful, so an explicit character is needed. Fortunately the latter only makes a difference on the last use.
* I then golfed a byte off by replacing the count and subsequent unary conversion stage with a replace stage. (This would also work in the Retina 1 answer, but there it wouldn't affect the byte count.)
[Answer]
# JavaScript (ES6), 26 bytes
Returns the \$n\$-th term of the sequence. Relies on arithmetic underflow to stop the recursion.
```
f=n=>n?(-n%4/3|1)*f(n/2):1
```
[Try it online!](https://tio.run/##y0osSyxOLsosKNHNy09J/f8/zTbP1i7PXkM3T9VE37jGUFMrTSNP30jTyvB/Wn6RRk5qiUKegq2CgTWQslEwAtHa2poK1VwKCsn5ecX5Oal6OfnpGgmJGirVebWaQKUq1UATNGsTNK25av8DAA "JavaScript (Node.js) – Try It Online")
### Commented
```
f = n => // f is a recursive function taking the input n
n ? // if n is not zero:
( //
-n % 4 // the sign of n % m is the sign of n in JS,
// so this gives a value in ]-4, 0]
/ 3 // we turn this into a value in ]-4/3, 0]
// this is ‚â§ -1 if the 2 least significant bits
// of the integer part of n are set
| 1 // a bitwise OR with 1 gives either:
// -1 for ]-4/3, -1]
// 1 for ]-1, 0]
) //
* // we multiply by the result of ...
f(n / 2) // ... a recursive call with n / 2
// once we have n < 1, the final result is not
// changed anymore; and once n is small enough,
// n / 2 will eventually be evaluated to 0
: // else:
1 // stop the recursion
```
[Answer]
# TI-BASIC, 25 bytes
```
prod(1-2seq(3=4fPart(int(Ans/2^I)/4),I,0,Ans
```
Takes input in `Ans`.
[Answer]
# Google Sheets / Microsoft Excel, ~~47~~ 46 bytes
```
=-1^len(substitute(base(bitor(A1,2*A1),2),0,))
```
Put \$n\$ in cell `A1` and the formula in `B1`.
Using the method in Command Master's [Python answer](https://codegolf.stackexchange.com/a/266997/119296), with -1 byte thanks to [m90](https://codegolf.stackexchange.com/users/104752/m90).
In spreadsheets, operator precedence is sometimes different from what one would expect. The unary minus will get evaluated before exponentiation, so `-1^2` === `(-1)^2` === `1` rather than `-1`.
[Answer]
# [AWK](https://www.gnu.org/software/gawk/), 37 bytes
```
{for(;$1>1;$1/=2)a+=$1%4>=3}$0=(-1)^a
```
[Attempt This Online!](https://ato.pxeger.com/run?1=m704sTx7wYKlpSVpuhY3VavT8os0rFUM7QyBhL6tkWaitq2KoaqJna1xrYqBrYauoWZcIkQxVM-CxSZmhhAmAA) or [try more test cases.](https://ato.pxeger.com/run?1=LYs7CsJAAAX7OceKCRLM2182yOYogk0aC0EUC_EkNguSQ-U2CcRmimHm-7u8rqVMz8fYpHn_Hm_36mQ0aMUx29rYQzba-SG7j2lz1ag-G7vl_6vMoUVYHJ5ApCPRo1UKWeSQRwFF1KGEenzUdi8)
Takes `n` from stdin and prints the `n`th term to stdout. Multiple-case version has `a` replaced with `$2` so that it works across test cases.
Awk numbers are floating-point numbers. The for loop observes the 0th and 1st bits while the given number is shifted to the right. Both bits are 1 if and only if the current number modulo 4 (floating-point) is at least 3.
[Answer]
# [APL (Dyalog Classic)](https://www.dyalog.com/), ~~17~~ 15 bytes
```
×/¯1*2∧/⊢⊤⍨2⍴⍨!
```
[Try it online!](https://tio.run/##SyzI0U2pTMzJT9dNzkksLs5M/v8/TeFR2wSFw9P1D6031DJ61LFc/1HXokddSx71rjB61LsFSClypRNUA@T//6@uYKCgrpOmYMBVklpcUgzW9Kh3s6EllwZYQFMn2lDPNDb90AqofO9chYKi1JKSSoW0/KLcxJKSzLx0AA "APL (Dyalog Classic) – Try It Online")
Written as a tacit function. While this would technically work for all n, it will run out of memory very quickly, as it computes n as a binary number with n! digits. This is simply to avoid the edge case of n=0, so the following code works equivalently and much more efficiently for positive n (only using n digits).
```
×/¯1*2∧/⊢⊤⍨2⍴⍨⊢
```
Would be interested if there were a workaround to this issue that doesn't increase byte count.
EDIT: I swapped the Power and the Reduce and changed from a Plus reduction to a Times reduction to remove parentheses.
[Answer]
# APL+WIN, 26 bytes
Prompts for integer:
```
¯1*+/2=2+/((⌈2⍟2⌈n)⍴2)⊤n←⎕
```
[Try it online! Thanks to Dyalog Classic](https://tio.run/##SyzI0U2pTMzJT9dNzkksLs5M/v@ob6qvz6O2CcZcQJanP5BlyPWooz3t/6H1hlra@ka2Rtr6GhqPejqMHvXONwLSeZqPercYaT7qWpIHVAzU9B@onOt/GpcBVxqXIRAbAbExEJuYGXJxAQA "APL (Dyalog Classic) – Try It Online")
[Answer]
# [Vyxal 3L](https://github.com/Vyxal/Vyxal/tree/version-3), 28 bytes
```
2to-base count: */+-1swap **
```
[Try it Online!](https://vyxal.github.io/latest.html#WyJsIiwiIiwiMnRvLWJhc2UgY291bnQ6ICovKy0xc3dhcCAqKiIsIiIsIjQ2MSIsIjMuMC4wIl0=)
I know the byte counter says "10 literate bytes", but that's going to be changed in the future to properly accommodate literate mode golfing.
Anyhow, I thought this might be a fun opportunity to try out literate mode golfing and see how it plays out. And it's definitely interesting - I started with 32 bytes using the exact SBCS method, but found that adding some extra commands made it shorter. Aliases!
The `3L` stands for Vyxal 3 Literate Mode. It's different to Vyxal 3 `l` flag, as 3L (in theory) has a dedicated executable. I say in theory because I may or may not have forgotten to actually make it a release binary - it can still be run from mill though.
## Explained
```
2to-base count: */+-1swap **­⁡​‎‎⁡⁠⁡‏⁠‎⁡⁠⁢‏⁠‎⁡⁠⁣‏⁠‎⁡⁠⁤‏⁠‎⁡⁠⁢⁡‏⁠‎⁡⁠⁢⁢‏⁠‎⁡⁠⁢⁣‏⁠‎⁡⁠⁢⁤‏‏​⁡⁠⁡‌⁢​‎‎⁡⁠⁣⁢‏⁠‎⁡⁠⁣⁣‏⁠‎⁡⁠⁣⁤‏⁠‎⁡⁠⁤⁡‏⁠‎⁡⁠⁤⁢‏⁠‎⁡⁠⁤⁣‏⁠‎⁡⁠⁤⁤‏⁠‎⁡⁠⁢⁡⁡‏‏​⁡⁠⁡‌⁣​‎‎⁡⁠⁢⁡⁢‏⁠‎⁡⁠⁢⁡⁣‏‏​⁡⁠⁡‌⁤​‎‎⁡⁠⁢⁡⁤‏⁠‎⁡⁠⁢⁢⁡‏⁠‎⁡⁠⁢⁢⁢‏⁠‎⁡⁠⁢⁢⁣‏⁠‎⁡⁠⁢⁢⁤‏⁠‎⁡⁠⁢⁣⁡‏‏​⁡⁠⁡‌⁢⁡​‎‎⁡⁠⁢⁣⁣‏⁠‎⁡⁠⁢⁣⁤‏‏​⁡⁠⁡‌­
2to-base # ‎⁡Convert input to base 2. Shorter than `to-binary`
count: * # ‎⁢Reduce overlaps by multiplication. The space is needed so that the "*" is recognised as an individual word.
/+ # ‎⁣Reduce that by addition. `/+` beats `sum` by a byte
-1swap # ‎⁤Push -1 under that value
** # ‎⁢⁡And exponentate
üíé
```
Created with the help of [Luminespire](https://vyxal.github.io/Luminespire).
[Answer]
# [Perl 5](https://www.perl.org/) -p, 35 bytes
```
$_=(-1)**unpack"%b*",pack N,$_&2*$_
```
[Try it online!](https://tio.run/##FcvNCoJAGEbh/bmKEIsaFHw/Z0ZddAvdglS0iESHfm6/yXaHB066PaeQczke97UOzn3mdL4@iu3FFdW/NqeqHHfmyjHnBmG0eAKRjp4BrShkqEUeBRRRh3o0YA22Poa1mMcCPuq7pPd9mV@5TtMP "Perl 5 – Try It Online")
[Answer]
# [GolfScript](http://www.golfscript.com/golfscript/), 18 bytes
```
~..+&2base{},,-1\?
```
[Try it online!](https://tio.run/##S8/PSStOLsosKPn/v05PT1vNKCmxOLW6VkdH1zDG/v9/EzNDAA "GolfScript – Try It Online") or [try numbers 0 to 30](https://tio.run/##S8/PSStOLsosKPlvbKBTraSkrfe/Tk9PW80oKbE4tbpWR0fXMMb@v5KCrZ2CUoy2dq1qntZ/AA "GolfScript – Try It Online").
`-1` raised to the power (`\?`) of the number of truthy items (`{},,`) of the binary representation (`2base`) of the bitwise AND (`&`) of the input (`~`) and it doubled (`..+`).
Here’s a solution that doesn’t use bitwise operations:
# [GolfScript](http://www.golfscript.com/golfscript/), 27 bytes
```
~2base.);\(;+2/{{*}*},,/-1\?
```
[Try it online!](https://tio.run/##S8/PSStOLsosKPn/v84oKbE4VU/TOkbDWttIv7paq1arVkdH1zDG/v9/EzNDAA "GolfScript – Try It Online") or [try numbers 0 to 30](https://tio.run/##S8/PSStOLsosKPlvbKBTraSkrfe/zigpsThVT9M6RsNa20i/ulqrVqtWR0fXMMb@v5KCrZ2CUoy2dq1qntZ/AA "GolfScript - Try It Online").
Full program.
Explanation ~~coming soon to a theater near you~~ has arrived at a codeblock near you!
```
~ # Eval the input (reading it as a number)
2base # Concert it to a list of binary digits
. # Duplicate
); # Remove the last of the copy
\(; # Remove the first of the original
+ # Concatenate them
2/ # Split into groups of size two
{ },, # Number of pairs where following is true:
{*}* # Reduce by multiplication
-1\? # Raise -1 to this power
```
No builtin for overlapping pairs, so this instead makes two copies - one with the first digit removed and one with the last removed - concatenates them, and splits into nonoverlapping pairs.
[Answer]
# [Desmos](https://desmos.com/calculator), ~~48~~ ~~44~~ 43 bytes
*-4 bytes building off of a suggestion made by [@Yousername](https://codegolf.stackexchange.com/users/91262/yousername)!*
*-1 more byte also from [@Yousername](https://codegolf.stackexchange.com/users/91262/yousername) building off of my 44 byte golf*
```
f(k)=‚àè_{n=0}^ksgn(5-2mod(floor(k/2^n),4))
```
[Try It On Desmos!](https://www.desmos.com/calculator/iuig6cilnb?nographpaper)
[Try It On Desmos! - Prettified](https://www.desmos.com/calculator/qjegwaifz4?nographpaper)
[Answer]
# [C (gcc)](https://gcc.gnu.org/), ~~42~~ 28 bytes
```
f(n){n=n?f(n/2)^n%4/3*-2:1;}
```
[Try it online!](https://tio.run/##jZFfa4MwEMDf@ykOQUiswdVuD5tzexj7FNOBxKSTtbGYwGTiV192VauztKMhOS6/@5fccbbh3FpJFG1UrJ5RCUL6rtzbYO2x8GEVtbZQBnZZoQiFZgG4DkDUe8GNyN9SiKFZ@dBvdkab7mzi7NQ2006cL2e8utYFdK7G1a/8N6qNul7xUmkD/COrPJSCf4qqb5mT1K9hUt@/4LlzfPh7XztDtCwrIId2FyoXNYbdRIP6CLr4FqUkx0HQYADeSCJYLjtv2iXrh3ccoMFsnTGaYY1YEkPnVCAdJ95FpZPDvkIXSRw3B/YEKF2dKPyR8UH746d1HIt0SNsuWvvD5TbbaMu@LNvufgE "C (gcc) – Try It Online")
*Port of [xnor](https://codegolf.stackexchange.com/users/20260/xnor)'s [Python 2 answer](https://codegolf.stackexchange.com/a/267001)*
*Saved a whopping 14 bytes thanks to [att](https://codegolf.stackexchange.com/users/81203/att)!!!*
[Answer]
# [AWK](https://www.gnu.org/software/gawk/manual/gawk.html), 67 65 59 58 56 bytes
```
{d=and($1,$1*2);for(b=z;d/=2;)b=d%2b}$1=(-1)^gsub(1,1,b)
```
[Try it online!](https://tio.run/##DchLCgIxEAXA/TtHhEQi4@v5htBXEdIEXQgKigwoc/aMtayy3lv7VS2P6h2j41FCvj5f3vSba6eSg2k9iG2O6k8Ml9v7Y56R0UJrZxCCHgNGTJixIIH/JChgDw7gCE7gDC5g2gE "AWK – Try It Online")
* -2 bytes, didn't use the regex indicator in `gsub()`, just passed `1` as first arg
* -6 bytes, removed `int()` function, then used `d/=2` instead of `d=d/2`
* -1 byte, moved the divisor of `d` in the conditional statement
* -2 bytes, moved the `$1` assignment
This works for multiple record input. If your file would only have a single record you could save `3` `4` bytes by replacing the initialization of `b` in the `for()` loop with the initialization of `d`.
---
# [AWK](https://www.gnu.org/software/gawk/manual/gawk.html), 53 52 bytes
```
{for(d=and($1,$1*2);d/=2;)b=d%2b}$1=(-1)^gsub(1,1,b)
```
[Try it online!](https://tio.run/##DchBCoMwEAXQ/T9HCkmJ2D9qVGSuUnAI7aLQQkUEi2ePfcs3b69iupff4/P1Wed39o7R8SphyrXKFEzzRexwVF8x3J/Lap6R0UIpNxCCBi06JPQYMIL/JChgA7ZgByawBwdwPAE "AWK – Try It Online")
* -1 byte, moved the `$1` assignment
I'm not completely familiar with each and every rules allowed for golfing. So in this case I moved the initialization of `b` in the header. This allow having multiple record read in one go. Secondary I moved the `1` at the end of the line to the footer. We already have our value stored in the current record, adding `1` at the end of the line trigger the default `awk` block `{print $0}` so it's only useful for printing.
Any insight of the rule on both of these subjects are more than welcome !
]
|
[Question]
[
In this challenge, your input is an integer value. Your task is to find the sum of the range of the sum of the range of n.
Examples:
```
Input -> Output
1 -> 1
2 -> 6
3 -> 21
4 -> 55
5 -> 120
6 -> 231
7 -> 406
8 -> 666
9 -> 1035
10 -> 1540
```
This challenge should be fairly simple to complete in most languages :)
Have fun!
[Answer]
# [JavaScript (Node.js)](https://nodejs.org), 17 bytes
```
x=>(x*x-~x)**2>>3
```
[Try it online!](https://tio.run/##DcY5DoAgEADAr2zJIcajVPgLQTBrCGvAGCq/jlQzl31tcRnvRyU6fAu6VW1YFVV9lQuxGLO2QBkYgoZ5A4S9O/VIycFRKhT9GOlkOEBgyHn7AQ "JavaScript (Node.js) – Try It Online")
Thanks [Kevin Cruijssen](https://codegolf.stackexchange.com/users/52210/kevin-cruijssen) for -1 byte.
[Answer]
# [C (gcc)](https://gcc.gnu.org/), 22 bytes
*With unsequenced modification and access to `n`*
```
f(n){n*=~n;n=--n*n/8;}
```
[Try it online!](https://tio.run/##DcpLCsIwFEbhce4qfiqFpG18jYQ0XYkTSYxe0Bup1UmpW48dHfg4wd5CKCVpMbM0/idOvLXSyO7klrJhCY9PvKJ/T5Hz9j4QsUz0vLDob@ZoaCa1CtgRqZRHaIbHwYHRr907tC0bUuo1rlvSVW2PEXZAHc9SdeAOSbMxjpbyBw "C (gcc) – Try It Online")
# [C (clang)](http://clang.llvm.org/), 26 bytes
*With unsequenced modification and access to `n`*
```
f(n){n*=~n;return--n*n/8;}
```
[Try it online!](https://tio.run/##DcpNCoMwEEDhdeYUg0VI1PRvVYh6km4kMe2AnZQ0diP26mlWDz6e1XaZ@JGzl6w2boYfmzinNbLW3PDpZvZ8ILbL6mbsP8lROD5HAOIEr4lYfgM5BRuIIkgGQPgQURIOeDFI2JeeDbYtKRDiHcvmZVXrq0M9Yu3uXHVIHXpJShnY8x8 "C (clang) – Try It Online")
# [C89](http://clang.llvm.org/), 28 bytes
```
f(n){n*=~n;return(n-2)*n/8;}
```
[Try it online!](https://tio.run/##DY3LCoMwEADP2a9YLEKipg9Plqhf0oskxi7YtUTtReynN/U0MAyM1XbseIjRS1YbZ82XTeiXNbBkXaqML5XZ44nYjqvrsZ4XR9P52QIQL/DqiOVnIqdgA3EYJAMg/BRQEjZ4M0hYH7wazHNSIMQ7HJmXSapLh7rF1D04KZAK9JKUMrDHn/VjN8xRH7PGVvc/ "C (clang) – Try It Online")
## Explanation
```
f(n){n*=~n;return--n*n/8;} // function which takes and returns an integer
n*=~n; // n *= -(n + 1); here (n = -(n*n + n))
--n // decrement n; here (n = -(n*n + n + 1))
return n*n/8; // return (n*n + n + 1)^2 / 8
```
[Answer]
# [Wolfram Language (Mathematica)](https://www.wolfram.com/wolframscript/), 15 bytes
```
#@*#&@Tr@*Range
```
[Try it online!](https://tio.run/##y00syUjNTSzJTE78n277X9lBS1nNIaTIQSsoMS899X9AUWZeiYK@Q7q@A1jAwdD0/38A "Wolfram Language (Mathematica) – Try It Online")
-1 byte from @att
# [Wolfram Language (Mathematica)](https://www.wolfram.com/wolframscript/), 16 bytes
```
(f=Tr@*Range)@*f
```
[Try it online!](https://tio.run/##y00syUjNTSzJTE78n277XyPNNqTIQSsoMS89VdNBK@1/QFFmXomCvkO6vgNY0MHQ9P9/AA "Wolfram Language (Mathematica) – Try It Online")
[Answer]
# [APL (Dyalog Unicode)](https://www.dyalog.com/), 6 bytes
Anonymous tacit prefix function.
```
+/∘⍳⍣2
```
[Try it online!](https://tio.run/##SyzI0U2pTMzJT///X1v/UceMR72bH/UuNvqf9qhtwqPevkddzY961zzq3XJovfGjtomP@qYGBzkDyRAPz@D/aYdWPOpdBdRhaAAA "APL (Dyalog Unicode) – Try It Online")
`+/` the sum
`∘` of
`⍳` the range
`⍣2` twice
[Answer]
# [Japt](https://github.com/ETHproductions/japt) [`-x`](https://codegolf.meta.stackexchange.com/a/14339/), 5 [bytes](https://en.wikipedia.org/wiki/ISO/IEC_8859-1)
```
õ x õ
```
[Try it](https://petershaggynoble.github.io/Japt-Interpreter/?v=1.4.6&flags=LXg&code=9SB4IPU&input=MTA)
[Answer]
# [Brain-Flak](https://github.com/DJMcMayhem/Brain-Flak), 32 bytes
```
({({}[()])()}{})
({({}[()])()}{})
```
[Try it online!](https://tio.run/##SypKzMzTTctJzP7/X6Nao7o2WkMzVlNDs7a6VpMLXeD/f2MA "Brain-Flak – Try It Online")
(The newline isn't needed, but is included because it makes the answer pretty)
Polygonal numbers are one of the things that brain-flak uniquely excels at. This is just the code that calculates the N-th triangular number, repeated twice.
```
# Push (the sum of...)
(
# While the top of stack is not 0...
{
# Decrement the top of the stack by 1
# This adds n-1 to the running counter
({}[()])
# Plus 1 (to the running counter)
()
}
# Pop the stack (which should contain a 0 now)
{}
)
```
[Answer]
# [Haskell](https://www.haskell.org/), 17 bytes
```
g.g
g n=sum[1..n]
```
[Try it online!](https://tio.run/##y0gszk7NyfmfZhvzP10vnStdIc@2uDQ32lBPLy/2f25iZp6CrUJBUWZeiYKKQm5igUKaAkjO0CD2/7/ktJzE9OL/uskFBQA "Haskell – Try It Online")
Just implementing the definition seems to be shorter than arithmetical expressions such as
**21 bytes**
```
f n=((n^2+n+1)^2-1)/8
```
[Try it online!](https://tio.run/##y0gszk7Nyfn/P00hz1ZDIy/OSDtP21AzzkjXUFPf4n9uYmaegq1CQVFmXomCikJuYoFCmkK0oZ6eoUHs/3/JaTmJ6cX/dZMLCgA "Haskell – Try It Online")
With floats:
**17 bytes**
```
g.g
g n=n*(n+1)/2
```
[Try it online!](https://tio.run/##y0gszk7NyfmfZhvzP10vnStdIc82T0sjT9tQU9/of25iZp6CrUJBUWZeiYKKQm5igUKaQrShnp6hQez/f8lpOYnpxf91kwsKAA "Haskell – Try It Online")
[Answer]
# [Nibbles](http://golfscript.com/nibbles/index.html), 2 bytes (4 nibbles)
```
+,+,
```
[Attempt This Online!](https://ato.pxeger.com/run?1=m708LzMpKSe1eMGCpaUlaboWS7R1tHUgTKjIgoUmEAYA)
### Explanation
```
+,+,$
$ Input number (implicit)
, Range from 1 to that number
+ Sum
, Range from 1 to that number
+ Sum
```
[Answer]
# [Binary Lambda Calculus](https://tromp.github.io/cl/Binary_lambda_calculus.html), 125 bits = 15.625 bytes
```
01000001 11001110 10000101 01100001 10010000 00000101 10011111 01110010
11110111 10110000 00001110 01011110 11010000 10110001 00000100 00010
```
[Verify it online!](https://ato.pxeger.com/run?1=pVdRb9s2EH7bg37F1Q1gEbGNSMCAoo09pN0GdMiKAh32EhuFLFG2EFnSJCqx2_Rn7GkvfRn2n_prdnckJcpOtwEDgpg83n338Xg8nv74axs1tzLPP3_55ruP06dwHRWbNtpI-DGX-2ydy9dFo6Iilg08nX7ysl1V1gre1jJvEwnbLMmKjQfgQ7Ru8FdYjVdloeoyn11VVZ7FkcruJKvlWaquQhxO4CpXsi54CfzZTDxm_nNZRAkb3pVZwmZIr05c3e8jFZGiVvDBv1yIk_VX26jm1ay5yqttxFBm_KbdnehfZ41i_TQrktdFIvenLqPDWhrMn1pWn0Balzsz6bXlut3MfqmjWKsrMxKeV8h7dagkvI3qRtYQwRzlZuK_UzVGF6YLuDHjCURihWYRRvUAz5_3dqj0FXWj7BvVSkDDXir89bzMHC_82BaxKmuLeL-VNXFMd1EFKa65AGTe0TzTOj7_69SFgMpBd9Lg2EPV1hL2Q0wfltA422nMdvZiRVEDk0aQ9qwC0Y_DIUUewhFoUhoxLtRyF0yglg2CXE4Ry-gNNELWCLVGCGTTrddStXVh1VKG0tpGRTix4Jw-joKlDovFHAH-F_1j9iYBUqPiMHdpudfxiJzcVepwekLv-XDoRACcLQRw-bDoZuFxtgz30cUazs9J2UyE93HaU_P17cZshvkCzMSeNgotz51LlPNKS2gJgyCLxKyZ9DFCrGtejPXhJV8pn0oFUXtZlrmggXHEJcToVbVMKJ-le2E3dCaWC-AU_Aiew9pmI8AN-Gu6lPDgIESwsvoYzE51pUkRJcvomIi5NoaTv5_P8UBNBNGsLwjGUAusBpliKbqTuMYY5LDMMN5oe2Oju3LsI6tApmmZJ5gHeNZCJ8ifrUqnz754vydYHeE6hjn8ihxfF0pu0PgB35YdiR-oGtAA_xJZZ3dExn-3Le8n8MNvwptO4Q7tFnDhYYzaWAbgE1CGcYQ3pdrSHroVAlW0Eke4DStWUKbIkSoxqDFtgYd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d4XXApiDKc9CkCOrbleDPQ4W35ZoeFZNeZ4_iiR7GJO2AhdDd6WfzY37_Bg)
Encodes the following lambda term:
```
main = 2 rangesum where
succ = \n f x. f (n f x)
pair = \x y f. f x y
snd = \p. p (\x y. y)
update = \p. p (\x y f. f (succ x) (x succ y))
rangesum = \n. snd (n update (pair 1 0))
```
This is a function that takes a positive integer in Church numeral and outputs the answer in the same form. The numbers that appear in the Haskell-like code above are also Church numerals, e.g. `2 = \f x. f (f x)`.
[Answer]
# [Charcoal](https://github.com/somebody1234/Charcoal), 10 bytes
```
I÷⍘12320N⁸
```
[Try it online!](https://tio.run/##S85ILErOT8z5/z@gKDOvRMM5sbhEwzOvxCWzLDMlVcMpsTg1uAQok66hZGhkbGSgpKPgmVdQWuJXmpuUWqShqamjYKGpqWn9/7/Jf92yHAA "Charcoal – Try It Online") Link is to verbose version of code. Explanation:
```
12320 Literal string `12320`
⍘ Interpret as base
N First input as a number
÷ Integer divide by
⁸ Literal integer `8`
I Cast to string
Implicitly print
```
The boring solution is 8 bytes:
```
IΣ…·Σ…·N
```
[Try it online!](https://tio.run/##S85ILErOT8z5/z@gKDOvRMM5sbhEI7g0V8MzLzmntDizLDUoMS89FZuQZ15BaYlfaW5SapGGJgRY//9v8l@3LAcA "Charcoal – Try It Online") Link is to verbose version of code. Explanation: `InclusiveRange` prefers two arguments, but fortunately we can arrange to use the one-argument version (twice, saving two bytes).
```
N First input as a number
…· Inclusive range from `1` to that
Σ Take the sum
…· Inclusive range from `1` to that
Σ Take the sum
I Cast to string
Implcitly print
```
[Answer]
# [05AB1E](https://github.com/Adriandmen/05AB1E/wiki/Commands), 4 [bytes](https://github.com/Adriandmen/05AB1E/wiki/Codepage)
```
LOLO
```
[Try it online](https://tio.run/##yy9OTMpM/f/fx9/H//9/QwMA) or [verify all test cases](https://tio.run/##yy9OTMpM/R/i6mevpPCobZKCkr3ffx9/H///Ov8B).
**Explanation:**
```
L # Push a list in the range [1, (implicit) input-integer]
O # Sum this list together
L # Pop and push a list in the range [1, sum]
O # Sum this list together again
# (after which the result is output implicitly)
```
Laughing Out Loud! Out??
An equal-bytes alternative could be: `2FLO`, where `2F` is loop 2 times:
[Try it online](https://tio.run/##yy9OTMpM/f/fyM3H//9/QwMA) or [verify all test cases](https://tio.run/##yy9OTMpM/R/i6mevpPCobZKCkr3ffyM3H///tTr/AQ).
[Answer]
# [Vyxal](https://github.com/Vyxal/Vyxal), 4 bytes
```
ɾ∑ɾ∑
```
[Try it Online!](https://vyxal.pythonanywhere.com/?v=1#WyJBIiwiIiwiyb7iiJHJvuKIkSIsIiIsIjFcbjJcbjNcbjRcbjVcbjZcbjdcbjhcbjkiXQ==)
Uses the straightforward approach: `ɾ` gets the range from 1 through its argument, and `∑` sums. Rinse and repeat.
[Answer]
# [Pyth](https://github.com/isaacg1/pyth), 4 bytes
```
sSsS
```
[Try it online!](https://tio.run/##K6gsyfj/vzi4OPj/f0MDAA "Pyth – Try It Online")
### Explanation
```
sSsSQ # implicitly add Q
# implicitly assign Q = eval(input())
SQ # range 1 to Q
s # sum
S # range 1 to result
s # sum
```
Extra nice since when pronounced out loud it is the sound a python makes.
[Answer]
# [R](https://www.r-project.org), 19 bytes
```
\(n)sum(1:sum(1:n))
```
[Attempt This Online!](https://ato.pxeger.com/run?1=m72waMGiNNulpSVpuhabYzTyNItLczUMrSBknqYmROZmVpqGoaaCsoIhV5qGEYhhBmQYgxhGICETEMvUFMgyBasyMgAyzcDSxiB5cxDTxACkyQKs2wzEtASrNTAG6TM0AHNMTQwgNi5YAKEB)
[Answer]
# brainf\*\*k, 110 bytes
```
,[>+>+>+<<<-]>>>[-[>+>+<<-]>>[-<<+>>]<<[-<+>]>[-<+>]<]<[>+>+>+<<<-]>>>[-[>+>+<<-]>>[-<<+>>]<<[-<+>]>[-<+>]<]<.
```
[Try it online!](https://tio.run/##SypKzMxLK03O/v9fJ9pOGwRtbGx0Y@3s7KJ1oyFcEC9a18ZG284u1sYGyNK2i7WDUDaxNuTp0vv/3wQA "brainfuck – Try It Online")
Probably not the shortest implementation but I'm too lazy to make this shorter lol...
Like most other b\*\*\*\*fuck programs, it doesn't output the answer. Instead, it prints the ascii character corresponding to the numeric answer.
Check [this](https://visual-brainfuck-web.netlify.app/) out to see the running process.
[Answer]
# [Desmos](https://desmos.com/calculator), ~~21~~ 20 bytes
```
N=nn+n
f(n)=N(N+2)/8
```
[Try It On Desmos!](https://www.desmos.com/calculator/bn7v7e6r8o)
[Answer]
# Java, ~~18~~ 17 bytes
```
n->(n=n*n-~n)*n/8
```
Port of [*@tsh*' JavaScript answer](https://codegolf.stackexchange.com/a/260979/52210), so make sure to upvote him/her as well.
-1 byte thanks to *@tsh*.
[Try it online.](https://tio.run/##LU5BDoIwELz7ig2nlgaUmxHrD@TC0XioBcwiLIQWEmPw67Ugl9ns7OzM1GpSUV28nG6UMXBVSJ8dAJIth0rpErJlXQnQbEHiqWfmnQdjlUUNGRBIR9GFkaSQoi/xkPZHly6afnw0XrNJpw4LaH0Iy@2A9LzdFf8HVN2w2qNMUsCzTA5@CMHXI0D@NrZs4260ce8fbUMMRXCCQFDse/Gt1Ox@)
`(n=n*n-~n)` could alternatively be `(n+=n*n+1)` for the same byte-count:
[Try it online.](https://tio.run/##LU4xDoMwDNx5hcWUEIGKupWGH5SFseqQBqhMwSASkKqKt6eBspzl8/nuWrWouK3eTnfKGLgppG8AgGTrqVG6hmJbdwI025B45pk18GCssqihAALpKM4ZCUkRiZRHlOdnl22icX52XnRolwEr6H0KK@2E9Lo/FP8nNMO0@6NMM8CrTE9@CMH3I0D5Mbbuk2G2yegfbUcMRXiBUFDii/Gj1ep@)
**Explanation:**
```
n-> // Method with integer as both parameter and return-type
(n= // Replace `n` with:
n*n // `n` squared
-~n) // `+n+1`
*n // Square that new `n`
/8 // Integer-divide that by 8 to get the result
```
---
A literal implementation would be **56 bytes** in comparison:
```
n->{int t=0;for(;n>0;)t+=n--;for(;t>0;)n+=t--;return n;}
```
[Try it online.](https://tio.run/##LY69DoMwDIR3nsJiShSBYG0a3qAsjFWHlJ8qFAwKBqlCPDtNgOUsfyefr9WLjtrqu5edniZ4aINrAGCQatvosobcrweAknlFLh3ZAicTaTIl5ICgdoyy1fukEtkMlknMEslJKIyiE5AHKBQ5YGuaLQLKbZc@apzfnYu6EpfBVNC7Lqwga/DzfGl@9vBB/otRqQRzV2nihhD8MAGK30R1Hw8zxaM7pA6ZEeENQoGxq8@v7tv@Bw)
**Explanation:**
```
n->{ // Method with integer as both parameter and return-type
int t=0; // Temp-integer, starting at 0
for(;n>0;) // Loop `n` down until it's 0:
t+=n // Add the current `n` to the temp-integer `t`
--; // And then decrease `n` by 1
// (at this point, `n=0`)
for(;t>0;) // Now loop `t` down until it's 0:
n+=t // Add the current `t` to `n`
--; // And then decrease `t` by 1
return n;} // Return the modified `n` as result
```
[Answer]
# [PARI/GP](https://pari.math.u-bordeaux.fr), 16 bytes
-2 byte thanks to [@tsh](https://codegolf.stackexchange.com/users/44718/tsh).
```
n->(1+n^2+n)^2\8
```
[Attempt This Online!](https://ato.pxeger.com/run?1=m728ILEoMz69YMHiNAXbpaUlaboWG_J07TQMtfPijLTzNOOMYiwgwjdV0vKLNPIUbBUMdRQMDXQUCooy80qAAkoKunZAIk0jT1NTE6J2wQIIDQA)
[Answer]
# [Python](https://www.python.org), 23 bytes
-7 bytes thanks to `c--`'s suggestion based on `tsh`'s answer.
```
lambda n:(n*n-~n)**2//8
```
[Attempt This Online!](https://ato.pxeger.com/run?1=m72soLIkIz9vweI025ilpSVpuhbbcxJzk1ISFfKsNPK08nTr8jS1tIz09S0gsjdV0vKLFPIUMvMUihLz0lM1DHUUDA01rbgUFAqKMvNKNNI08jQ1IWoXLIDQAA)
# [Python](https://www.python.org), 38 bytes
```
lambda n:sum(range(sum(range(n+1))+1))
```
[Attempt This Online!](https://ato.pxeger.com/run?1=m72soLIkIz9vweI025ilpSVpuhY31XISc5NSEhXyrIpLczWKEvPSUzUQrDxtQ01NEIaqVknLL1LIU8jMU4DIG-ooGBpqWnEpKBQUZeaVaKRp5MHULlgAoQE)
[Answer]
# [Haskell](https://www.haskell.org/), 21 bytes
```
t n=sum[1..sum[1..n]]
```
[Try it online!](https://tio.run/##y0gszk7Nyfn/v0Qhz7a4NDfaUE8PSuXFxv7PTczMsy0oyswrUclNLFAoiTbQ07OM/Q8A "Haskell – Try It Online")
[Answer]
# x86-16 machine code, 13 bytes
```
00000000: 8ad8 43f6 e340 f7e0 b103 d3e8 c3 ..C..@.......
```
Listing:
```
8A D8 MOV BL, AL ; BL = x
43 INC BX ; BL = x + 1
F6 E3 MUL BL ; AX = x * (x + 1)
40 INC AX ; AX = x * (x + 1) + 1
F7 E0 MUL AX ; AX = AX * AX
B1 03 MOV CL, 3
D3 E8 SHR AX, CL ; AX = AX >> 3
C3 RET ; return to caller
```
Callable with input `n` in `AL`, output in `AX`.
Uses the formula `(x*(x+1)+1)^2>>3`.
[](https://i.stack.imgur.com/0E2N5.png)
[Answer]
# [Julia](https://julialang.org), 16 bytes
```
!n=(n^2-~n)^2÷8
```
[Attempt This Online!](https://ato.pxeger.com/run?1=m700qzQnM3HBgqWlJWm6FhsU82w18uKMdOvyNOOMDm-3gAjvScsvUsi0NbQyNOBSUCgoyswrycnTUMzU5ErNS4EogZkAAA)
The formula looks a bit shorter than directly writing out the sums.
[Answer]
# [Go](https://go.dev), ~~41~~ 37 bytes
```
func(n int)int{n=n*n-^n
return n*n/8}
```
[Attempt This Online!](https://ato.pxeger.com/run?1=m70oPX_BTcWCxOTsxPRUhdzEzDyuzNyC_KISPaW03BIlLq6yxCKFNNulpSVpuhY3VdNK85I18hQy80o0gbg6zzZPK083Lo-rKLWktChPAcjTt6iFKrYAKQYbqaGpUM2Vll-kkGlla2itkGljaAAktbWBogFFQHNy8jQydRTSNDI1NblquaD6FyyA0AA)
* -4 bytes by @c--
[Answer]
# [Arturo](https://arturo-lang.io), 18 bytes
```
$=>[∑1..∑1..&]
```
[Try it!](http://arturo-lang.io/playground?xCX3JW)
[Answer]
# [Factor](https://factorcode.org/) + `math.unicode`, 21 bytes
```
[ [1,b] Σ [1,b] Σ ]
```
[Try it online!](https://tio.run/##S0tMLskv@h8a7OnnbqWQm1iSoVeUmJeeWgxhl@ZlJuenpCoUpxaWpuYlA4ULilJLSioLijLzShSsubgMDRSiDXWSYv9HQ2iFc4sRjNj/uYkFCnr/AQ "Factor – Try It Online")
[Answer]
# [Husk](https://github.com/barbuz/Husk), 2 bytes
```
‼Σ
```
[Try it online!](https://tio.run/##yygtzv7//1HDnnOL////bwoA "Husk – Try It Online")
```
‼ # Apply function twice:
Σ # Triangular number
```
(the more-boring [`ΣΣ`](https://tio.run/##yygtzv7//9zic4v///9vCgA) is also 2 bytes...)
[Answer]
# C, 65 bytes
`f(n){int i=10;for(;i>1;)n+=i--;for(;n>1;)i+=n--;printf("%d",i);}`
## Earlier attempts
### 73 bytes
`main(){int i=0,n=10;for(;n>0;)i+=n--;for(;i>0;)n+=i--;printf("%d\n",n);}`
### 70 bytes
`main(n){int i=10;for(;i>1;)n+=i--;for(;n>1;)i+=n--;printf("%d\n",i);}`
[Answer]
# [><> (Fish)](https://esolangs.org/wiki/Fish), 13 bytes
* -2 bytes thanks to Bubbler
```
i:1+*2,:1+*2,n;
```
[Try it](https://mousetail.github.io/Fish/#eyJ0ZXh0IjoiaToxKyo6MisqOCxuOyIsImlucHV0IjoiMyIsInN0YWNrIjoiIiwic3RhY2tfZm9ybWF0IjoibnVtYmVycyIsImlucHV0X2Zvcm1hdCI6Im51bWJlcnMifQ==)
Just the triangle number formula copied twice
[Answer]
# [Thunno 2](https://github.com/Thunno/Thunno2), 4 bytes
```
RSRS
```
[Attempt This Online!](https://ato.pxeger.com/run?1=m728JKM0Ly_faGm0UqpS7IKlpSVpuhZLgoKDgpcUJyUXQwUWLLSAMAA)
Range, sum, range, sum.
[Answer]
# [Lua](https://www.lua.org/), 24 bytes
```
print((...^2-~...)^2//8)
```
[Try it online!](https://tio.run/##yylN/P@/oCgzr0RDQ09PL85Itw5IacYZ6etbaP7//9/QAAA "Lua – Try It Online")
Based off [tsh's answer](https://codegolf.stackexchange.com/a/260979/117588), though it's been modified a bit to better fit Lua.
]
|
[Question]
[
Since this is a [answer-chaining](/questions/tagged/answer-chaining "show questions tagged 'answer-chaining'") challenge, you might want to sort answers by [oldest](https://codegolf.stackexchange.com/questions/207490/the-ascii-character-countdown?answertab=oldest#tab-top).
---
Your task is simple: Choose any printable ASCII character that's not chosen in the previous answers. And then, you need to print your chosen character in your program to standard output. (You can ONLY print your chosen character, without printing other garbage to STDOUT)
## The catch
Let's say you picked `x` as your chosen character, and your answer is the answer numbered y. You have to insert y x's into the previous source code, at any position you like. For the first answer, the previous answer is the empty program.
## An example
Answers have to start with the number 1. So for example, I chose the character `#`, and I posted a 1 byte answer in /// that prints the `#` mark.
```
#
```
And then, the second answer (numbered 2) has to insert 2 of their picked `x` character into the previous source code, such that the modified code will print their `x` character. So assume this is written in Keg:
```
x#x
```
And then, the third answer has to do the same, and so on, until 95 is reached.
## Answer format
I'd love to see an explanation of your code as well, preferably with an online interpreter link!
```
# [{Language name}]({link-to-language}), {code-length} bytes
\$y= {The number of your answer}\$. Used so far: <code>{Characters used in answers so far}</code>
{your code}
```
## The winning criterion & other rules
* The first user whose answer stays without a succeeding answer for a month wins the challenge. If that's not satisfied, the first person who reaches the number 95 wins the challenge.
* You are not allowed to put any other character in your code other than printable ASCII characters.
* You need to wait 2 answers before you post a new answer after your submission.
* Please make sure your answer is valid. If yours is not valid, chaining answers aren't allowed to be posted.
* You can answer in a language that is used in previous answers.
* You could *only* insert y `x`'s into the source code.
* Your are not allowed to take input.
* Your program can output to STDERR, as long as the output to STDOUT is as intended.
[Answer]
# [2sable](https://github.com/Adriandmen/2sable), 36 bytes
```
//9#999999//,#,#,221'/,#q',#q,qq2///
```
\$y=8\$. Used so far: `1'2q#,9/`
[Try it online.](https://tio.run/##MypOTMpJ/f9fX99S2RIM9PV1lIHQyMhQHcgqVAdincJCI319/f//AQ)
Maybe this opens up some other languages that use `//` to comment. :)
**Explanation:**
[2sable](https://github.com/Adriandmen/2sable) is an old version of [05AB1E (legacy)](https://github.com/Adriandmen/05AB1E/tree/fb4a2ce2bce6660e1a680a74dd61b72c945e6c3b) (which of itself is an old version of [05AB1E](https://github.com/Adriandmen/05AB1E)).
The legacy version outputs a leading newline however: [try it online](https://tio.run/##MzBNTDJM/f9fX99S2RIM9PV1lIHQyMhQHcgqVAdincJCI319/f//AQ).
And the latest 05AB1E version outputs three leading newline: [try it online](https://tio.run/##yy9OTMpM/f9fX99S2RIM9PV1lIHQyMhQHcgqVAdincJCI319/f//AQ).
```
// # Divide twice, no-ops with an empty stack
9 # Push 9
# # Pop and split it by spaces
# (since it contains no spaces, it only pops)
999999 # Push 999999
/ # Divide the empty stack by this, popping the integer
/ # No-op divide again with an empty stack
, # No-op print (which would output a newline in the
# newer versions)
#,#, # Some more no-ops
221 # Push 221
'/ '# Push "/"
, # Pop and print this "/" to STDOUT
# # Split the 221 on spaces, so it just pops
q # Exit the program
',#q,qq2/// '# No-ops
```
[Answer]
# Polyglot, 3 bytes
```
1''
```
\$y=2\$. Used thus far: `1'`.
This works in a bunch of stack-based languages, which basically all do the following:
```
1 # Push a 1 to the stack
'' # Push the string "'" to the stack
# (output the top of the stack implicitly as result)
```
[Try it online](https://tio.run/##S87PzU0sSfz/31Bd/f9/AA) in [,,,](https://github.com/totallyhuman/commata/wiki/Commands).
[Try it online](https://tio.run/##yy9OTMpM/f/fUF39/38A) in [05AB1E](https://github.com/Adriandmen/05AB1E/wiki/Commands).
[Try it online](https://petershaggynoble.github.io/Japt-Interpreter/?v=2.0a0&code=MScn) in [Japt](https://github.com/ETHproductions/japt).
etc.
>
> *Tip: Using a similar stack-based language, it's easy to insert almost any character by interleaving.*
>
>
>
[Answer]
# [05AB1E](https://github.com/Adriandmen/05AB1E), 10 bytes
\$y=4\$. Used so far: `1'2q`
```
221'q'qqq2
```
[Try it online!](https://tio.run/##yy9OTMpM/f/fyMhQvVC9sLDQ6P9/AA "05AB1E – Try It Online")
```
221 # push 221 to the stack
'q'q # push character q (twice for good measure)
q # quit; implicitly print top-of-stack q
q2 # no-ops
```
[Answer]
# [05AB1E](https://github.com/Adriandmen/05AB1E/wiki/Commands), 15 bytes
```
###221'#q'#qqq2
```
\$y=5\$. Used thus far: `1'2q#`
[Try it online.](https://tio.run/##yy9OTMpM/f9fWVnZyMhQXbkQiAoLjf7/BwA)
Maybe this opens up some other languages that use `#` to comment. :)
**Explanation:**
```
### # Split by spaces three times (no-ops without input)
221 # Push integer 221
'# '# Push character "#"
q # Stop the program
# (after which the top of the stack is output implicitly as result)
'#qqq2 '# No-ops
```
[Answer]
# [Befunge-98](https://esolangs.org/wiki/Funge-98), 45 bytes
\$y=9\$. Used so far: `1'2q#,9/j`
```
//9#999999//j,#,#,221'j/,#qjjjjj'j,#jq,qq2///
```
[Try it online!](https://tio.run/##S0pNK81LT9W1tNAtqAQz///X17dUtgQDff0sHWUgNDIyVM/S11EuzAIBdaBgVqFOYaGRvr7@//8A "Befunge-98 (PyFunge) – Try It Online")
### Explanation
Mainly (ab)uses `j` to skip sections we don't want to execute.
```
// # Divide twice (no-ops, as 0/0 is 0 in Befunge-98)
9 # Push 9
#9 # No-op (skipped by #)
99999 # Push more 9s
/ # Divide, results in 9/9 = 1
/ # Divide, results in 9/1 = 9
j # Jump forward 9 instructions
,#,#,221' # (not executed)
j # Jump forward 9 instructions
/,#qjjjjj # (not executed)
'j # Push the character 'j'
, # Print the character
#j # No-op
q # Quit program
,qq2/// # (not executed)
```
[Answer]
# [Trigger](http://yiap.nfshost.com/esoteric/trigger/trigger.html), 55 bytes
\$y=10\$. Used so far: `1'2q#,9/j\`
```
\//9#9\99999//j,\\\#,#,221'j/\,#\\qjjjjj'j,#\jq,qq2/\//
```
[Try it online!](https://tio.run/##FcshDsAwDATBxxiEnHSqmf9ytIpq5qj/d5JBS/Zf35zv6hYZFoqLTEgyGNyfkRRMqrxGns5ClfM83Rs "Trigger – Try It Online")
This took a lot longer than I'm willing to admit...
[Answer]
# [Befunge-98](https://esolangs.org/wiki/Funge-98), 21 bytes
```
#,#,#,221',#q',#q,qq2
```
\$y=6\$. Used so far: `1'2q#,`
[Try it online!](https://tio.run/##S0pNK81LT9W1tPj/X1kHBI2MDNV1lAtBWKew0Oj/fwA "Befunge-98 (FBBI) – Try It Online")
```
# # Skip the next instruction
, # (skipped)
#, # (skipped)
#, # (skipped)
221 # Push 2, 2, 1 onto the stack
', # Push character ','
#q # (skipped by #)
', # Push character ','
#q # (skipped)
, # Output character
q # Quit program
q2 # (not executed)
```
[Answer]
# [R](https://www.r-project.org/), 28 bytes
```
9#999999,#,#,221',#q',#q,qq2
```
\$y=7\$. Used so far: `1'2q#,9`
[Try it online!](https://tio.run/##K/r/31LZEgx0lIHQyMhQXUe5EIR1CguN/v8HAA "R – Try It Online")
Based on a combination of [functions may output via their return values](https://codegolf.meta.stackexchange.com/questions/2447/default-for-code-golf-input-output-methods/2456?r=SearchResults&s=1%7C106.8617#2456) and the fact that R functions naturally output their return values to STDOUT (albeit with some prepended characters to indicate index of the outputed value), I hope that this is Ok.
Explanation:
```
9 # integer value 9; output by default
# # comment character; everything after this (on the same line) is ignored
999999,#,#,221',#q',#q,qq2
# not run
```
Big thank-you to Kevin Cruijssen for putting the `#` character at the beginning of answer #5, which (as he suspected) was critical to make this answer work!
[Answer]
# [Befunge-98 (FBBI)](https://github.com/catseye/FBBI), 66 bytes
\$y=11\$. Used so far: `1'2q#,9/j\;`
```
;\//9#9\99999//j,\\\#,#,221;';;j/\;,;#\\;qjjjjj'j,#\jq,qq2/\//;;;;
```
[Try it online!](https://tio.run/##FcsxCoAwDAXQw2ToEgl2Mvyr/EmoQoZCBs8f27e/ezzffMfhVxVo5uL0zSyUpKho7ycaEEYohETG1kKFkZrZbU0sVT8 "Befunge-98 (FBBI) – Try It Online")
`;` is the comment character in Befunge, and this program works by running `';,q` with inapplicable parts commented out. Doesn't work in Pyfunge for reasons I can't figure out.
[Answer]
# [Befunge-98](https://esolangs.org/wiki/Funge-98), 253 bytes
\$y=22\$. Used so far: `1'2q#,9/j\;0"35s46%7*x`
```
*7%7*77%*7*77%666666%x*77*7%*7*77%6*666666666655555555555555444444%***4%44*4*444444xxxx"033333%33333333s;s\/s/90*%35*s46#"9\s99%%9%90s9/"/j0s,\"\*0\"#s,#,22s01;"*'s"*;0;j/x\xxxx"s;xxx,0;%#x\"\;xxqsj*j"0j%%jj'j,#\"j%qs,q0q2/"\%s//s;0;%;;0"s77*77777xxxxxx
```
[Try it online!](https://tio.run/##Vc9RCsMgDADQu0RCIVjMWlsnXsWvQTfIx1gJA3d6Z2UU9gIhCSbgbbu/n49tjNfx9ellrRQwUAhIPa8dllbTOaP1tPzxHRKRR@@pRVca4PmA848mzU5dZMJ5IfWrgZg1RsSIkTU6cMJqM2TiDEatsdOkfElAgwIlTuJK7pc1tWw5oSnteWt2FRJgQRQZxJoMgrvanffJQUZ1Tts@psSgx78Opav1Cw "Befunge-98 (PyFunge) – Try It Online")
After running the part before the first `x`, the top of the stack is `6 0` (from the code `666%`). Thus, the `x` instruction sets the *program delta* to (6, 0), meaning that the instruction pointer moves right 6 spaces every step. This skips over most of the remaining instructions, leaving `%%66554*44"33s0s\9/,\,;*x",\q0'j0%0"7x` to be executed. `%%66544*44` does some stack manipulation, `"33s0s\9/,\,;*x"` pushes the string `x*;,\,/9\s0s33`, and `,` prints the first character of that string, which is `x`. Finally, `\` swaps the top two elements of the stack (which we don't care about) and `q` ends the program.
[Answer]
# [Japt](https://github.com/ETHproductions/japt), 6 [bytes](https://en.wikipedia.org/wiki/ISO/IEC_8859-1)
\$y=3\$ Used so far: `1'2`
```
221''2
```
[Test it](https://petershaggynoble.github.io/Japt-Interpreter/?v=1.4.6&code=MjIxJycy)
## Explanation
The code is transpiled to `221, "'", 2` and Japt only implicitly prints the last expression so outputs 2
[Answer]
# [///](https://esolangs.org/wiki////), 1 byte
\$y=1\$ Used so far: `1`
```
1
```
[Try it online!](https://tio.run/##K85JLM5ILf7/3/D/fwA "/// – Try It Online")
Just to start things off.
**Explanation:**
```
1 # since this isn't a / or \, the character is simply printed and removed.
# no characters left so the program terminates.
```
[Answer]
# [Keg](https://github.com/JonoCode9374/Keg), `-hr`, 78 bytes
\$y=12\$. Used so far: `1'2q#,9/j\;0`
```
0;\//90#9\999909//j0,\\0\#,#,2201;';0;j/\;,0;#\\;qjj0jjj'j,#\jq,q0q2/\//;0;;;0
```
[Try it online!](https://tio.run/##DcwxDsMwDEPRw2jwokKMN4NX4RokYCf3/oDqPz/87/10g6paiKV1wqoyUoIiI@fExUHQJSYYErcN28MZ8s6NPessDiLR3Z/39wc "Keg – Try It Online")
And this kids, is why we use languages where single digits auto push! This pushes a whole bunch of stuff, a 0, then prints the t.o.s using the `-hr` flag.
[Answer]
# [Trigger](http://yiap.nfshost.com/esoteric/trigger/trigger.html), 190 bytes
\$y=19\$. Used so far: `1'2q#,9/j\;0"35s46%`
```
%%%666666%%%6666666666655555555555555444444%4%444444444"033333%33333333s;s\/s/90%35s46#"9\s99%%9%90s9/"/j0s,\"\0\"#s,#,22s01;"'s";0;j/\"s;,0;%#\"\;qsjj"0j%%jj'j,#\"j%qs,q0q2/"\%s//s;0;%;;0"s
```
[Try it online!](https://tio.run/##VctLCsMwDATQu8gM2Rik5gdGV/G2hGrnTO/vuqEt9M1GDKPn@TiO@9k7gP3yOy7bn/WCkS@x5Q3LB51VqcWwbFz3JKWyFKCgGIuKhjFXqVYlMac8z7Sby0Rx89Aq9GyONCbeGCEWQMQUeVSBxtyszSoVVOX4gbsJe38B "Trigger – Try It Online")
Here's hoping using `%` makes a lot of languages a lot harder to use
[Answer]
# [Trigger](http://yiap.nfshost.com/esoteric/trigger/trigger.html), 276 bytes
\$y=23\$. Used so far: `1'2q#,9/j\;0"35s46%7*x@`
```
@@@*@@@@@@@@7%7*77%*7*77%666666%@x*77*7%*7*7@7%6*@666666666655555555555555444444%*@**4%44*4*444444xx@xx"033333%33333333s;s\/s@/90*%35*s46#"9\s99%%9%90s9/"/j0s,\"\*0\"#s,#,22s01;"*'s"*;0;j/@x\xxxx"s;x@xx,0;%#x\"\;xxqsj*j"0j%%jj'j,#\"j%qs,q0q2/"\%s@//s;0;%;;0"s77*77777@xxxxxx@@
```
[Try it online!](https://tio.run/##Vc/NasMwDADgd5ERBWGwlrgJRhc9iK@lVLdUO@jtM8crg30Cg4R@8Pf79Xw@3uepqqQfO@6070jz3SbUGAn9FkfDRrr9uf9TJyQlqlgrjZgiNAJ4veD64eK9uJbGhOudvG4JWvfWEBs29lagGHvu0Ik7JM8pL4vzlwDdHEhYrGj0GMDlOpFZMMUYkIjDjQzYEM1ullMHw8PzwcdSoOM4XHysQBEGv/530ZhUz/MH "Trigger – Try It Online")
Hopefully `@` makes even more languages harder to use.... looking at you Befunge-98
[Answer]
# [Trigger](http://yiap.nfshost.com/esoteric/trigger/trigger.html), 351 bytes
\$y=26\$. Used so far: `1'2q#,9/j\;0"35s46%7*x@f8.`
```
...ffffffffff.ffffffffffffff.88888.88888.88888.8888.88@.@@*@@@@@@@@7.%7*77%*7*77%666666%@x*78.8.87*7%*7*.7@7%6*@66666666.6655555555555555444444%*@**4%44*4*444444xx@xx".033333%33333333s;s\/s@/90*%35*s46#".9\s99%%9%90s9/"/j0s,.\"\*0\"#s,#,22s01;"*'s"*;0;j/@x.\.xxxx"s;x@xx..,0;%#x\"\;xxqsj*j"0j%%jj'j,#\"j%qs,q0q28/"\%s@//s;0;%;;0"s.77*7.7777@xxxxxx@@..
```
[Try it online!](https://tio.run/##Zc/BagQhDAbgd8kQFoLEdHZ2HPGSB/HaLvU2mx7y9lNHhtLST/hRowa/Xp/P5/vrOJj548ev6Vhup3/ZQ1mV9JIYE6WENHIdUJ1SP8lb3zwrnLTXSNcLr@vjj2VAUqIFl4X6GNzVHVjuJ7xfrFiNpjEL4f1BtqwTcK6WM2LGLJYjxCYWuEIlqTBZmMI8m7wVoJsBFSktqnNl78DK2Yc5SMHJ@6XivlujBtIQW7u1MFVouFvYZZ@3CBV7/2j9HSxFwDj1r/ZISX1QZT6Obw "Trigger – Try It Online")
We're out of digits now, that should make things a little more interesting. I think we've made every language other than Trigger unusable at this point...
[Answer]
# HTML, 630 bytes
\$y = 35\$, Used so far: `1'2q#,9/j;0"35s46%7*[[email protected]](/cdn-cgi/l/email-protection)`&Hb=cd<`
```
<<dddcccccccccccccccccccccccccccccdc==d=b=b=b=`HH&&&a&&a&a&&.&&&&&&&&&&&&&&&&&&&&&aaaaaaaaaaaaaaaaaaaaaaaa..ffffffffff.ffffffffffffff.88888.88888.88888.8888.88@.@@*@@@@@@@@7.%7*77%*7*77%666666%@x*78.8.87*7%*7*.7@7%6*@66666666.66555555b55HHbHHHHHHHHHHHHHHHHHHHHHHHHHH555555444444%*@**4%44*4*444444xx@xx".==033333%33333333s;s\/s@/90*%35*s46#".9\s99%%9%90s9/"/j0s,.`\`ccdc"`\*0\"#s,`#,22s01;"*'s"*;0;j/@x.\.xxxx"s;x@xx..,0;%#x\"\;xxqsj*j"0j%%jj'j,#\"j%qs,q0q28/"\%s@//s;0;%;;0"s.77*7.========================7777@xxxxxx@@..```````````````````````bbbbbbbbbbbbbbbbbbbbbbbbbbdddddddddddddddddddddddddddd<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
```
Save as `index.html` and run with `w3m -dump index.html`, so it goes to stdout as expected.
`<dd....` is an un-closed html tag, which rendered into nothing. So the first `<` character rendered as HTML content.
[w3m](http://w3m.sourceforge.net/) is an old school browser which use text I/O to render HTML. As this question is requiring stdout output. I'm also surprised that w3m may successfully parse and render such a malformed HTML.
[Answer]
# [Keg](https://github.com/JonoCode9374/Keg), `-hr`, 105 bytes
\$y=14\$. Used so far: `1'2q#,9/j\;0"3`
```
"03333333333333;\//903#"9\999909/"/j0,\"\0\"#,#,2201;"'";0;j/\";,0;#\"\;qjj"0jjj'j,#\"jq,q0q2/"\//;0;;;0"
```
[Try it online!](https://tio.run/##TYwxDsMwDAP/Qg9ZVIh1JkNf0Vo0YCfn/4CisbcRR9zv860Cz38i3RfPgZWr4XK4aIlkYtiwOfkOHAiGPBHGGG1jS6CkQ9Zb2zb3dHSunxFEVb2u@wE "Keg – Try It Online") or [Check it!](https://tio.run/##TYwxDgIxDAR7nrEp0ljyXlJF/gINokNuOOkK3KDofsRT@FhwyXSjHe37fO6vY63z/v08rre1wP6PuepgLxg@Eg6FBsXhdBQp0ho3Q4XRQh0mtJKrzQgwImpIekyZnE2Rd1maEZettllkaHha/wE)
[Answer]
# [Trigger](http://yiap.nfshost.com/esoteric/trigger/trigger.html), 231 bytes
\$y=21\$. Used so far: `1'2q#,9/j\;0"35s46%7*`
```
*7%7*77%*7*77%666666%*77*7%*7*77%6*666666666655555555555555444444%***4%44*4*444444"033333%33333333s;s\/s/90*%35*s46#"9\s99%%9%90s9/"/j0s,\"\*0\"#s,#,22s01;"*'s"*;0;j/\"s;,0;%#\"\;qsj*j"0j%%jj'j,#\"j%qs,q0q2/"\%s//s;0;%;;0"s77*77777
```
[Try it online!](https://tio.run/##Vc/BCsMwCAbgdzFIQQK6NmsIvkquo8xb6t4/S8M22CcI/ujB1/k8jsfZO2XMlDPS7Ps0hjF9I9p/7n/ShESUMCUaNYFsF9w@XL2ycxHC7U6e9gCleimIBYt4YWATjxUqSYXgMcR1dbkp0OJAKmpcwTWKYhhb2tzIQAzRbLE4MsPmsUlbGSo6s48jVBXw65FL728 "Trigger – Try It Online")
This language is really weird. I got this working by pure luck after about an hour
[Answer]
# [Keg](https://github.com/JonoCode9374/Keg), `-hr`, 325 bytes
\$y=25\$. Used so far: `1'2q#,9/j\;0"35s46%7*x@f8`
```
ffffffffffffffffffffffff888888888888888888888@@@*@@@@@@@@7%7*77%*7*77%666666%@x*78887*7%*7*7@7%6*@666666666655555555555555444444%*@**4%44*4*444444xx@xx"033333%33333333s;s\/s@/90*%35*s46#"9\s99%%9%90s9/"/j0s,\"\*0\"#s,#,22s01;"*'s"*;0;j/@x\xxxx"s;x@xx,0;%#x\"\;xxqsj*j"0j%%jj'j,#\"j%qs,q0q28/"\%s@//s;0;%;;0"s77*77777@xxxxxx@@
```
[Try it online!](https://tio.run/##dc/NigMhDADgd4mEQrCYztix4iUP4rXdxT1Nc8nbW0fKwsL2C@QQ8kN@7l@9Pz64/UdESN4SJkoJaeZtQjFKo22UZn30bCTbr@sfcUISoogx0ojJTMyA1wOub1q0BpWQmXC9ksbNQa6aM2LGzJoDhMbqK1TiCk6988uifClAJwUqXFoQqzaAluOE54LOxkAx27VRA26IrZ2adxUa7up33pdbgIrjctCxA0th0HT8PIhNIr338/fzBQ "Keg – Try It Online")
(no explanation because I have no idea how Keg works)
[Answer]
# [Stax](https://github.com/tomtheisen/stax), 91 bytes
\$y=13\$. Used so far: `1'2q#,9/j\;0"`
```
"0;\//90#"9\999909/"/j0,\"\0\"#,#,2201;"'";0;j/\";,0;#\"\;qjj"0jjj'j,#\"jq,q0q2/"\//;0;;;0"
```
[Try it online!](https://tio.run/##DYwhDsQwEAP/4oCSldYNi/yVJaVmUQ/c79M1G83I7@/5nwOqMhcHVq0eVyLNKBQLI0bMyVu4IMpZUFCjrbYN2r4czd6xuWei37qUiHM@ "Stax – Try It Online")
I know that OPs aren't intended to answer their own questions, but after seeing that nobody has the enthusiasm to add the quote character...
[Answer]
# [Keg](https://github.com/JonoCode9374/Keg), - hr, 171 bytes
\$y=18\$. Used so far: `1'2q#,9/j\;0"35s46`
```
66666666666666666555555555555554444444444444444"03333333333333s;s\/s/9035s46#"9\s99990s9/"/j0s,\"\0\"#s,#,22s01;"'s";0;j/\"s;,0;#\"\;qsjj"0jjj'j,#\"jqs,q0q2/"\s//s;0;;;0"s
```
[Try it online!](https://tio.run/##Xco7DsMwDATRu1CFGwbcyB9A4FXYBgnoSt77Q1GZ@JWDOV/vMY67/c92I1h/0RlGa1h3bkeRFmwT2EwsQQ0JhBRq0VqJp8tCcXhaCF3hZR7emSnIzCV1huzUjl5NgmacuzuEY4zH5/oC "Keg – Try It Online")
[Answer]
# [Keg](https://github.com/JonoCode9374/Keg) `-hr`, 153 bytes
\$y = 17\$, Used so far: `1'2q#,9/j\;0"35s4`
```
555555555555554444444444444444"03333333333333s;s\/s/9035s4#"9\s99990s9/"/j0s,\"\0\"#s,#,22s01;"'s";0;j/\"s;,0;#\"\;qsjj"0jjj'j,#\"jqs,q0q2/"\s//s;0;;;0"s
```
[Try it online!](https://tio.run/##XcoxDgIxDETRu0yKbYxssrtF5Ku4XYFMFeb@MimBV3791/WoOn8cf2D7NzpDqcP2k0fDCI7FOBSaRgmEBRqlSe@0u2Mj3Dw1QBfztg6fzIRl5payQk7KtNkVQVWu3d3Aqro93x8 "Keg – Try It Online")
[Answer]
# [Stax](https://github.com/tomtheisen/stax), 136 bytes
\$y = 16\$, Used so far: `1'2q#,9/j\;0"35s`
```
55555555555555"03333333333333s;s\/s/9035s#"9\s99990s9/"/j0s,\"\0\"#s,#,22s01;"'s";0;j/\"s;,0;#\"\;qsjj"0jjj'j,#\"jqs,q0q2/"\s//s;0;;;0"s
```
[Try it online!](https://tio.run/##VcohDsQwDETRu0xAiSXPpiqIfBWTpWbRFOzts4Htg19f9/e31vUCnk8KpcsHz0sNIzU2aji8KEskE03WrHfxEziEYJQnFMZo@4ipKrCqjrIdasomZ3ek3LX3CEJr/QE "Stax – Try It Online")
[Answer]
# [Octave](https://www.gnu.org/software/octave/), 210 bytes
\$y=20\$. Used so far: `1'2q#,9/j\;0"35s46%7`
```
7%777%777%666666%777%777%6666666666655555555555555444444%4%444444444"033333%33333333s;s\/s/90%35s46#"9\s99%%9%90s9/"/j0s,\"\0\"#s,#,22s01;"'s";0;j/\"s;,0;%#\"\;qsjj"0j%%jj'j,#\"j%qs,q0q2/"\%s//s;0;%;;0"s7777777
```
[Try it online!](https://tio.run/##XctNCgIxDAXgu6SE2RQS58dScpVsRNxkI@WJ1691Rhf6PbJIeLlfH5fnrffCpRxz3v2tu@3HuuORL9LljZcPGFwgVXnZsJ4TVUetzJWrogpJKLKTq1NCTnmeoSejCWRqIU6wrMZpVKwhgjSYI6bI4xTckJu2WcgZIhg/bKaEcuj9BQ "Octave – Try It Online")
Except for MATLAB/Octave, you mean?
[Answer]
# [Keg](https://github.com/JonoCode9374/Keg), `-hd`, 300 bytes
\$y=24\$ Used so far: `1'2q#,9/j\;0"35s46%7*x@f`
```
ffffffffffffffffffffffff@@@*@@@@@@@@7%7*77%*7*77%666666%@x*77*7%*7*7@7%6*@666666666655555555555555444444%*@**4%44*4*444444xx@xx"033333%33333333s;s\/s@/90*%35*s46#"9\s99%%9%90s9/"/j0s,\"\*0\"#s,#,22s01;"*'s"*;0;j/@x\xxxx"s;x@xx,0;%#x\"\;xxqsj*j"0j%%jj'j,#\"j%qs,q0q2/"\%s@//s;0;%;;0"s77*77777@xxxxxx@@
```
[Try it online!](https://tio.run/##dc9LasQwDADQu8iIAeFiNfEkGG10EC87H9xV0Ea39zjuUOiiT2CQ0Ad/3x693/@hqqRvO@6070jz3SZUHwn9FEfDRrr9uv6RJyQlypgzjZjc1R14PeH6ZmI1mabChOuVLG8BSrVSEAsWtpIgNbZYoRJXCBZDXBbjTwG6GJCwtKRefQCT80RkweBjQNwPa9SAG2JrlxZDhYaHxYOPJUHFcTjZWIEiDHb@76Q@qfbeP55fLw "Keg – Try It Online")
Harder? It actually made it easier. `@` starts a function in Keg, and because there aren't any closing `ƒ`s (and there won't be because it ain't ascii), everything after the first `@` is ignored. What a clanger!
[Answer]
# [Trigger](http://yiap.nfshost.com/esoteric/trigger/trigger.html), 378 bytes
\$y = 27\$, Used so far: `1'2q#,9/j\;0"35s46%7*[[email protected]](/cdn-cgi/l/email-protection)`
```
aaa.aaaaaaaaaaaaaaaaaaaaaaaa..ffffffffff.ffffffffffffff.88888.88888.88888.8888.88@.@@*@@@@@@@@7.%7*77%*7*77%666666%@x*78.8.87*7%*7*.7@7%6*@66666666.6655555555555555444444%*@**4%44*4*444444xx@xx".033333%33333333s;s\/s@/90*%35*s46#".9\s99%%9%90s9/"/j0s,.\"\*0\"#s,#,22s01;"*'s"*;0;j/@x.\.xxxx"s;x@xx..,0;%#x\"\;xxqsj*j"0j%%jj'j,#\"j%qs,q0q28/"\%s@//s;0;%;;0"s.77*7.7777@xxxxxx@@..
```
[Try it online!](https://tio.run/##dc/BasQgEAbgd5kwLAwyTpNsjHiZB/GSQ7vUW3Z68O2zRkJpKf2EH3XUwa/n5@Px/jyObdt4@wfzx7cf075cT3@yhbIq6SUwBgoBqefSoVYK7SSvbfOscNBWI10uvCz3X@YOSYlmnGdqo6tVawWW6YTTxZJlb@qjEE53snkZgGO2GBEjRrHowRcxxxkySYbB3ODG0eQtAd0MKEkqXitnrg1YOvswO0k41HYp1bpboQJSEEu5FTdkKLib22UfVw8ZW39v7R1MScA4tK@2CEFrp8p8HC8 "Trigger – Try It Online")
[Answer]
# [Keg](https://github.com/JonoCode9374/Keg), `-rn`, 406 bytes
\$y=28\$, `1'2q#,9/j;0"35s46%7*[[email protected]](/cdn-cgi/l/email-protection)``
```
`aaa.aaaaaaaaaaaaaaaaaaaaaaaa..ffffffffff.ffffffffffffff.88888.88888.88888.8888.88@.@@*@@@@@@@@7.%7*77%*7*77%666666%@x*78.8.87*7%*7*.7@7%6*@66666666.6655555555555555444444%*@**4%44*4*444444xx@xx".033333%33333333s;s\/s@/90*%35*s46#".9\s99%%9%90s9/"/j0s,.`\`"`\*0\"#s,`#,22s01;"*'s"*;0;j/@x.\.xxxx"s;x@xx..,0;%#x\"\;xxqsj*j"0j%%jj'j,#\"j%qs,q0q28/"\%s@//s;0;%;;0"s.77*7.7777@xxxxxx@@..```````````````````````
```
[Try it online!](https://tio.run/##dc/dasUgDAfwd0kJB4KLru2pFW/yIF7Yi23gYNCTG9@@s1LGxraf8EdN8OP95e048rZtvP2D@fXLt2lfrqdf2UJYhOTiGT15j9Rz6VAq@dbJa9s8K@yl1UiWCy/L/Ye5QxKiGeeZ2uhqlVqB3XTC6aJRk1WxwRFOd9J5GYBD0hAQAwanwYItTg3nlCEncgkGNXkw46juOQLdFCi6WKxUTlwb0HjexWxcxKEmSLHWXQsVcAWxlFsxQ4KCu5rd7eNqIWF7g9V2DsboQNm377bwXmonwpz/dhzH0@PjEw "Keg – Try It Online")
Hehe. I used the power of strings to essentially make those `.`s nops.
[Answer]
# [Gol><>](https://github.com/Sp3000/Golfish), 465 bytes
\$y=30\$, Used so far: `1'2q#,9/j;0"35s46%7*[[email protected]](/cdn-cgi/l/email-protection)`&H`
```
`HH&&&a&&a&a&&.&&&&&&&&&&&&&&&&&&&&&aaaaaaaaaaaaaaaaaaaaaaaa..ffffffffff.ffffffffffffff.88888.88888.88888.8888.88@.@@*@@@@@@@@7.%7*77%*7*77%666666%@x*78.8.87*7%*7*.7@7%6*@66666666.6655555555HHHHHHHHHHHHHHHHHHHHHHHHHHHH555555444444%*@**4%44*4*444444xx@xx".033333%33333333s;s\/s@/90*%35*s46#".9\s99%%9%90s9/"/j0s,.`\`"`\*0\"#s,`#,22s01;"*'s"*;0;j/@x.\.xxxx"s;x@xx..,0;%#x\"\;xxqsj*j"0j%%jj'j,#\"j%qs,q0q28/"\%s@//s;0;%;;0"s.77*7.7777@xxxxxx@@..```````````````````````
```
[Try it online!](https://tio.run/##fdDBasQgEAbgd5kwWRjCaJNsjHiZYx7CQ/aybaWwhLn49qmxoRS67af8qCMqvj4@7u/6tu/rsrRtezt6CW6fuf2B@f7tx7BO58OvLCEsQnJyjI6cQ6o5VSiZXNnJc1k8Kuyk1EimE0/T9bT842vHWCEJ0YjjSKVVOUvOwHY44HDSoNGoGG8JhyvpODXAPqr3iB69VW/AJKsdr3GFNZKN0Gi3Nl3fq30JQBcFCjYkI5kj5wI0HHcxdzZgkyPEkPOmiRLYhJjSJXVNhISbdpvd@tlAxPIGo@UcDMGCsitfUcI5yZUI8/rcvn8C "Gol><> – Try It Online")
## Explanation
```
` Push codepoint of next character:
H 'H'
H Halt, printing TOS as a character
```
[Answer]
# [Trigger](http://yiap.nfshost.com/esoteric/trigger/trigger.html), 496 bytes
\$y=31\$, Used so far: `1'2q#,9/j;0"35s46%7*[[email protected]](/cdn-cgi/l/email-protection)`&Hb`
```
bbb`HH&&&a&&a&a&&.&&&&&&&&&&&&&&&&&&&&&aaaaaaaaaaaaaaaaaaaaaaaa..ffffffffff.ffffffffffffff.88888.88888.88888.8888.88@.@@*@@@@@@@@7.%7*77%*7*77%666666%@x*78.8.87*7%*7*.7@7%6*@66666666.66555555b55HHbHHHHHHHHHHHHHHHHHHHHHHHHHH555555444444%*@**4%44*4*444444xx@xx".033333%33333333s;s\/s@/90*%35*s46#".9\s99%%9%90s9/"/j0s,.`\`"`\*0\"#s,`#,22s01;"*'s"*;0;j/@x.\.xxxx"s;x@xx..,0;%#x\"\;xxqsj*j"0j%%jj'j,#\"j%qs,q0q28/"\%s@//s;0;%;;0"s.77*7.7777@xxxxxx@@..```````````````````````bbbbbbbbbbbbbbbbbbbbbbbbbb
```
[Try it online!](https://tio.run/##ddDBasQgEAbgd5kwWRjCaHeTGPEyxzyEh2ygXeotOz349qmxSyl091N@1BEVv@6ft9v7fd/XdV3muW3b69FLcPvM9QXmj19/hnU6Hf5lCWERkgfH6Mg5pJpjhZLJlZ08lcWjwk5KjWR84HEcqnUY5nmdX/rZ1VdIQtRj31NpVc6SM7C9HPDyoEGjUTHeEl4G0n5sgH1U7xE9eqvegElWO17iAkskG6HRbmm681ntWwA6KVCwIRnJHDkXoOG4i7mzAZscIYacN02UwCbElE6payIk3LTb7HaeDEQsbzBazsEQLCi78hklnJNciTAvz60v7fs3 "Trigger – Try It Online")
]
|
[Question]
[
**Task:** Crack the scrambled code for multiplying the square root of an integer ***n*** by the square of it!
You must post a comment in the **[cops' thread](https://codegolf.stackexchange.com/questions/115036/cops-square-times-square-root)** with a link to your working source, mentioning clearly that you have ***Cracked it***. In your answer's title, you must include the link to the original answer.
## Rules:
* You may only change the order of the characters in the original source.
* Safe answers cannot be cracked anymore.
* The other rules mentioned in the cops' thread
* ***Please edit the answer you crack***
---
## WINNER: Emigna - 10 submissons (had some trouble counting)
*Honorable mentions: Notjagan, Plannapus, TEHTMI*
[Answer]
# JavaScript (ES7), [Neil](https://codegolf.stackexchange.com/a/115127)
```
_26_=>_26_**6.25**.5
```
The hard part, of course, was figuring out what to do with all the extra characters. (And also not posting this solution in the wrong thread, like I accidentally did at first. Oopsie...)
[Answer]
# Python, 15 bytes, [Mr. Xcoder](https://codegolf.stackexchange.com/a/115064/41805)
```
lambda x:x**2.5
```
Pretty simple. Just takes `x` and raises it to the `2.5`th power.
[Answer]
## OCaml, 13 bytes, [shooqie](https://codegolf.stackexchange.com/a/115068/55508)
```
fun f->f**2.5
```
[Try it online!](https://tio.run/nexus/ocaml#@19QlJlXEp@Wk59YoqGRVpqnkKZrl6alZaRnqqlgqaf5/z8A "OCaml – TIO Nexus")
[Answer]
# Python 3, 44 bytes, [Kyle Gullion](https://codegolf.stackexchange.com/a/115855/15858)
Those `*`s were quite misleading. Very clever!
```
lambda i:i**(lambda o,r:o/r)(*map(ord,'i*'))
```
Due to the quite limited character set I would be very surprised if there were any other valid solutions beyond trivial renaming or reordering of arguments.
[Answer]
# [C++ (gcc)](https://gcc.gnu.org/), 100 bytes, [Mr. Xcoder](https://codegolf.stackexchange.com/a/115067/66323)
```
#include<math.h>
#include"iostream"
using namespace std;int main(){float n;cin>>n;cout<<pow(n,2.5);}
```
[Try it online!](https://tio.run/nexus/cpp-gcc#NcgxCsMwDADAPa8w6ZJAmyGQIdj4L0JRa0EshVimQ@mzO7tdOh1cu7DgXjcKGSxNKXb/6FmLnQS572pheTiBTOUAJFds8yzmMrAM4@u@K5gTjywx/tBqIRz6HOQ6T8vo362tH9EbAib6Ag "C++ (gcc) – TIO Nexus")
[Answer]
## Haskell, [Leo](https://codegolf.stackexchange.com/a/115077/34531)
```
x=exp.(2.5*).log
```
A pointfree function named `x`. Usage: `x 4` -> `32.0`
[Answer]
# [Inform 7](https://en.wikipedia.org/wiki/Inform#Inform_7), [corvus\_192](https://codegolf.stackexchange.com/a/115121)
Cool, an Inform7 entry. :) I just had to give this one a try.
I'm pretty sure this is the intended solution:
```
R is a room.
To f (n - number): say "[n * n * real square root of n]".
```
Note that this solution only works if compiled with the Glulx back-end, due to the use of the `real square root of` function.
---
BTW, the double quotes and square brackets are actually unnecessary; just `say n * n * real square root of n` would work just as well. The periods at the end of the commands could be omitted, too; or we could keep the first period and get rid of the newlines instead. Other parts of the code we could trim away include the article "a" before "room" and the spaces before the parentheses and after the colon. Fortunately, since we've got a spare pair of brackets, we can always use them to comment out all these extra characters. ;) So this is a valid solution, too:
```
R is room.To f(n - number):say n * n * real square root of n[
" a . "
]
```
---
To test this solution interactively, it's convenient to append something like the following test harness to the code:
```
Effing is an action applying to one number.
Understand "f [number]" as effing.
Carry out effing: f the number understood.
```
After compiling and running the program, you can type e.g. `f 4. f 6. f 9. f 25` at the `>` prompt and receive something like the following output:
```
Welcome
An Interactive Fiction
Release 1 / Serial number 170404 / Inform 7 build 6L38 (I6/v6.33 lib 6/12N) SD
R
>f 4. f 6. f 9. f 25
32.0
88.18164
243.0
3125.0
>
```
BTW, I just noticed that Inform (or presumably, rather, Glulx) rounds the last decimal place of `f 6` wrong: the correct value is *much* closer to 88.18163 than to 88.18164. Fortunately, I don't think this affects the correctness of the solution(s), especially since the challenge specified "any rounding mechanism of your choice". :)
[Answer]
## Mathematica, [Greg Martin](https://codegolf.stackexchange.com/a/115103/66104 "name")
```
f[y_]:=With[{x=
#&@@{#(#)#^(1/(1+1))&@y,#&@@@{1^(1),-1}}
},Print[#,".",IntegerString[Round@#2,10,3]]&@@QuotientRemainder[1000x,1000]]
```
Thanks for leaving the rounding stuff intact!
Explanation: `#(#)#^(1/(1+1))&@y` does the main work of multiplying `y` squared, aka `y(y)`, and `y`'s square root, `y^(1/(1+1))`. The `#&@@@{1^(1),-1}` bit is just junk to use up the other letters, and `#&@@` picks out the useful bit from the junk.
[Answer]
# [MATL](https://github.com/lmendo/MATL), 12 bytes, [Luis Mendo](https://codegolf.stackexchange.com/a/115071/49958)
```
10'U&+:'n/^P
```
Calculate 10/4 = 2.5 with 4 coming from string length. Use this as an exponent. P is a no-op here.
[Answer]
# [NO](https://github.com/ValyrioCode/NO), 41 bytes, [This Guy](https://codegolf.stackexchange.com/a/115253/47066)
```
NOOOOOO?NOOOOOOOOOOO!nnOOOOO
NOOOOOOOO?no
```
[Answer]
## [R, Steadybox](https://codegolf.stackexchange.com/a/115093/26905)
```
y<-function(p)(p^(1/2)*p^2);
```
seems to be an anagram of `funny(p1)-tio(^*^)/pc(2)<p2;`
[Answer]
# Python 2, 60 bytes, [Anthony Pham](https://codegolf.stackexchange.com/a/115118/63641)
```
print (input()**(5.0/(2*5554448893999/5554448893840))-0)
```
Based on discarding characters through Python 2's float division (the default for `/` between integers).
[Answer]
# C, 50 bytes, [Dave](https://codegolf.stackexchange.com/a/115130/66323)
```
double b(float \ufa2d){return pow(\ufa2d,25e-1);%>
```
[Try it online!](https://tio.run/nexus/c-gcc#U87MS84pTUlVsCkuScnM18uw@5@SX5qUk6qQpJGWk59YohBTmpZolKJZXZRaUlqUp1CQX64BEdIxMk3VNdS0VrX7n5lXopCbmJmnoalQzcVZUATkp2koqabF5CnpAA0yMtXUtOaq/f8vOS0nMb34v25OLgA "C (gcc) – TIO Nexus")
This requires `-lm` compiler flag, but I don't know how it would be possible to solve this without it.
[Answer]
# R, [Flounderer](https://codegolf.stackexchange.com/a/115133/6741)
This is a crack of the 33 bytes solution of @Flounderer
```
scan()^(floor(pi)-1/2)-sin(7*0e1)
```
Usage:
```
> scan()^(floor(pi)-1/2)-sin(7*0e1)
1: 4
2:
Read 1 item
[1] 32
> scan()^(floor(pi)-1/2)-sin(7*0e1)
1: 6
2:
Read 1 item
[1] 88.18163
> scan()^(floor(pi)-1/2)-sin(7*0e1)
1: 9
2:
Read 1 item
[1] 243
> scan()^(floor(pi)-1/2)-sin(7*0e1)
1: 25
2:
Read 1 item
[1] 3125
```
[Answer]
# RProgN 2, [ATaco](https://codegolf.stackexchange.com/a/115120/63641)
```
]2^\š*
```
Apparently StackExchange needs extra characters, so here you go.
[Answer]
# HODOR, 198, [This Guy](https://codegolf.stackexchange.com/a/115262/67716)
```
Walder
Hodor?!
hodor.
Hodor, Hodor Hodor Hodor Hodor Hodor Hodor Hodor, Hodor Hodor,
hodor,
Hodor, Hodor Hodor Hodor Hodor Hodor Hodor, Hodor Hodor,
Hodor, Hodor Hodor Hodor, hodor!,
HODOR!!
HODOR!!!
```
Explanation:
```
Start
read input into accumulator
copy accumulator to storage
Do math, option 7(nth root), n=2
swap storage and accumulator
Do math, option 6(nth power), n=2
Do math, option 3(times), storage
output accumulator as a number
end
```
note: I had to make some modifications to the get interpreter to run on my machine (the one you have posted doesn't seem to accept lowercase h, among some other things)
Also, I don't seem to have enough rep to comment, so if someone could let @This Guy know, I would be grateful
I think this fixed the error, the code now starts with Walder instead of Wylis, which adds the extra byte
[Answer]
## C#, 172 bytes, [raznagul](https://codegolf.stackexchange.com/a/115069/32628)
Hardest part was figuring out what to do with all the leftovers.
```
using System;using S=System.Console;class PMabddellorttuuv{static void Main(){S.Write(Math.Pow(double.Parse(S.ReadLine()),2.5));Func<double> o;int q=1,M=q*2,b,e;q*=(q*M);}}
```
[Answer]
# EXCEL, 26 Bytes [pajonk](https://codegolf.stackexchange.com/questions/115036/cops-square-times-square-root/115233#115233)
```
=SQRT(A1)*A1^2/1/ISNA(IP2)
```
A1 as input
IP2 contain a second input with a #N/A Error
in this case ISNA(IP2) belongs to 1
For an additional `()`
we can do this
```
=SQRT(A1)*A1^2/ISNA(PI(1/2))
```
[Answer]
## Python 3.6, 64 bytes, [Mr. Xcoder](https://codegolf.stackexchange.com/a/115339/44706)
```
php38af4r2aoot2srm0itpfpmm0726991i= (lambda x:x**2.5*1*1/1);
```
Maybe not what was intended, but works ;)
```
$ python3
Python 3.6.1 (default, Apr 4 2017, 09:36:47)
[GCC 4.2.1 Compatible Apple LLVM 7.0.2 (clang-700.1.81)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> php38af4r2aoot2srm0itpfpmm0726991i= (lambda x:x**2.5*1*1/1);
>>> php38af4r2aoot2srm0itpfpmm0726991i(6)
88.18163074019441
>>> php38af4r2aoot2srm0itpfpmm0726991i(4)
32.0
>>> php38af4r2aoot2srm0itpfpmm0726991i(25)
3125.0
```
Not enough rep to comment on the cops' thread's answer yet, sorry... Would appreciate if someone could do it for me, thanks!
[Answer]
# [Röda](https://github.com/fergusq/roda/tree/roda-0.12), 28 bytes, [fergusq](https://codegolf.stackexchange.com/a/115053/49958)
```
f(n){push n^0.5,n^2|product}
```
[Answer]
# Python 2.7, [Koishore Roy](https://codegolf.stackexchange.com/a/115778/64121)
```
s=e=x=y=input()**0.5
print'%.3f'%(y**(5.0))
```
[Answer]
# R, [Flounderer](https://codegolf.stackexchange.com/a/115133/6741)
This is a crack of @Flounderer's 31-byte solution:
```
`[.`=function(`]`)`]`^`[`(lh,9)
```
Ok that was a tough one. It creates a function called ``[.``. The argument to the function is called ``]`` which is elevated to power 2.5 by using the 9th element of the built-in time-serie `lh` ("a regular time series giving the luteinizing hormone in blood samples at 10 mins intervals from a human female, 48 samples." that is used as example in one of R's base packages). `lh[9]` is here on top of it replaced by its equivalent ``[`(lh, 9)`. De-obfuscated by substituting `f` for the function name and `n` for the argument name, the function then becomes `f=function(n)n^lh[9]`.
Usage:
```
> `[.`=function(`]`)`]`^`[`(lh,9)
> `[.`(4)
[1] 32
> `[.`(6)
[1] 88.18163
> `[.`(9)
[1] 243
> `[.`(25)
[1] 3125
```
[Answer]
# Python 2, 44 bytes, [Anthony Pham](https://codegolf.stackexchange.com/a/115074/64505)
```
print int(raw_input())**(0+000000000000.5*5)
```
Takes input from raw\_input, converts to int and raises to power 2.5
[Answer]
# JavaScript, [**fəˈnɛtɪk**](https://codegolf.stackexchange.com/questions/115036/cops-square-times-square-root/115058#115058)
```
n=>n**("ggggg".length*2**(-"g".length))// ""((((((()))))))***,-...;;=====>Seeeeegggghhhhhhhhhilllnnnnnnorrrsstttttttttttu{}
```
Gets 5/2 through 5 times 2 to the negative first power, where 5 and 1 were received from the length of strings. Took the easy way out in a sense by commenting out the extraneous characters.
[Answer]
## C#, 112 bytes, [Jan Ivan](https://codegolf.stackexchange.com/a/115174/47066)
```
using System;class P{static void Main(){var b=Math.Pow(double.Parse(Console.ReadLine()),2.5);Console.Write(b);}}
```
[Answer]
# [05AB1E](https://github.com/Adriandmen/05AB1E), 47 bytes, [Okx](https://codegolf.stackexchange.com/a/115194/47066)
```
).2555BFHIJJKKKPQRS``„cg…ghi…lsw…x}T…Áöž«‚¹n¹t*
```
[Try it online!](https://tio.run/nexus/05ab1e#@6@pZ2Rqaurk5uHp5eXt7R0QGBSckPCoYV5y@qOGZekZmUAyp7gcSFbUhgDJw42Htx3dd2j1o4ZZh3bmHdpZovX/vxkA "05AB1E – TIO Nexus")
[Answer]
## [Fireball](https://github.com/okx-code/Fireball), 8 bytes, [Okx](https://codegolf.stackexchange.com/a/115196/56341)
```
♥²♥1Z/^*
```
Explanation:
```
♥²♥1Z/^*
♥² Push first input squared.
♥ Push first input again.
1Z/ Push 1/2
^ First input to the 1/2th
* Multiply square and root
```
Not sure if it works. I have currently no java on my laptop. :(
[Answer]
# [Haskell](https://www.haskell.org/), 64 bytes, [@nimi](https://codegolf.stackexchange.com/a/115124/56433)
```
product.(<$>(($(succ.cos$0))<$>[(flip<$>flip)id$id,recip])).(**)
```
[Try it online!](https://tio.run/nexus/haskell#FYwxDoAgDAC/0oGhJYY4OCov8AfGwRRJmigQwPcjTHe54ZqHDVKO7uNqcFUWUWH5mA3Homaing70j6QuAyROiZvyzZJOIoNaU3svCf2T78vtAawdSwkVDPi2/A "Haskell – TIO Nexus") That was a fun one. I first found `product.(<$>(($succ(cos$0))<$>[id,recip])).(**)` which behaves correctly and than had to fit `flip flip <$> () $ id .` somewhere into it.
[Answer]
# R, [steadybox](https://codegolf.stackexchange.com/a/115224/6741)
```
a222=function(s)(s**0.5)*s**2**1
```
Usage:
```
> a222=function(s)(s**0.5)*s**2**1
> a222(4)
[1] 32
> a222(6)
[1] 88.18163
> a222(9)
[1] 243
> a222(25)
[1] 3125
```
[Answer]
# [05AB1E](https://github.com/Adriandmen/05AB1E), 22 bytes, [P. Knops](https://codegolf.stackexchange.com/a/115240/47066)
```
n¹t*qA9¥="'?:@->%#[{!.
```
[Try it online!](https://tio.run/nexus/05ab1e#@593aGeJVqGj5aGltkrq9lYOunaqytHVinr//5sBAA "05AB1E – TIO Nexus")
**Explanation**
```
n # square of input
* # times
¹t # square root of input
q # end program
```
The rest of the operations never get executed.
We could have done it without the `q` as well by having `?` after the calculation and escaping the equality sign for example with `'=`.
]
|
[Question]
[
Given a non-negative number `n`, sort the digits of `n` by their first occurrence in [pi](http://www.piday.org/million/).
Input can be taken via function cli argument, or STDIN and as a string, char[] or integer. You may output via return value, exit status or STDOUT.
[Answer]
# [Python 3](https://docs.python.org/3/), ~~40~~ 39 bytes
1 byte thanks to Jonathan Allan.
```
lambda s:sorted(s,key="145926870".find)
```
[Try it online!](https://tio.run/nexus/python3#@59mm5OYm5SSqFBsVZxfVJKaolGsk51aaatkaGJqaWRmYW6gpJeWmZei@b@gKDOvRENJSS8rPzNPI01DydDI2MTUzNzC0gDBUtLU1PwPAA "Python 3 – TIO Nexus")
[Answer]
# [05AB1E](https://github.com/Adriandmen/05AB1E), ~~10~~ ~~9~~ 7 bytes
Saved 1 byte thanks to *Leaky Nun* noting that filtering out duplicates is unnecessary.
Saved 2 bytes thanks to *Adnan*.
```
žqRvy†J
```
[Try it online!](https://tio.run/nexus/05ab1e#@390X2FQWeWjhgVe//9bmlsYGhmbmJoZAAA "05AB1E – TIO Nexus")
**Explanation**
```
žq # push pi to 15 decimals (contains all digits but 0)
R # reverse
vy # for each char in pi
†J # move it's occurrences in the input to the front
```
[Answer]
# Pyth, ~~8~~ 6 bytes
```
ox+.n0
```
[Try it here.](//pyth.herokuapp.com?code=ox%2B.n0&test_suite=1&test_suite_input=%221023456789%22%0A%22123456789%22%0A%223218204911386623457%22%0A%220%22%0A%221%22)
*-1 thanks to [Leaky Nun](/u/48934): The input will provide the `0` if it's ever needed.*
*Trivial -1 thanks to [Jakube](/u/29577): Backtick not needed (ah, how did I miss that, HOW?!?).*
[Answer]
# [Jelly](https://github.com/DennisMitchell/jelly), 10 bytes
```
“ṀSṪw’ṾiµÞ
```
[Try it online!](https://tio.run/nexus/jelly#ASYA2f//4oCc4bmAU@G5qnfigJnhub5pwrXDnv///yIxMjM0NTY3ODkwIg "Jelly – TIO Nexus")
Takes input as a string of digits.
*-3 bytes thanks to @ETHproductions*
**Explanation**
```
“ṀSṪw’ṾiµÞ
µ - Separate chain into function “ṀSṪw’Ṿi and sort atom Þ.
Þ - Sort the input by
i - Each digit's index in:
“ṀSṪw’ - the literal 3145926870 ...
Ṿ - transformed into the list 3,1,4,5,9,2,6,8,7,0
```
[Answer]
# [Japt](https://github.com/ETHproductions/japt), ~~10~~ 9 bytes
8 bytes of code, +1 for the `-P` flag.
```
–!bMP+U
```
[Try it online!](https://tio.run/nexus/japt#@39ozeGNikm@Adqh//8rGRoZm5iamVtYGigp6AYAAA "Japt – TIO Nexus") Takes input as a string.
### Explanation
```
–!bMP+'0 // Implicit input
¬ // Split the input into chars.
ñ // Sort each char in the resulting list by
!b // its index in
MP+U // Math.PI + the input.
-P // Join the result back into a single string.
// Implicit: output result of last expression
```
[Answer]
## JavaScript (ES6), 54 bytes
```
f=
s=>[...s].sort((a,b)=>k[a]-k[b],k=`9150236874`).join``
```
```
<input oninput=o.textContent=f(this.value)><pre id=o>
```
Uses strings for I/O.
[Answer]
# [Jelly](https://github.com/DennisMitchell/jelly), ~~8~~ 7 [bytes](https://github.com/DennisMitchell/jelly/wiki/Code-page)
-1 byte thanks to Dennis (use any existing `0` in the input, clever.)
```
ØP;ṾiµÞ
```
**[Try it online!](https://tio.run/nexus/jelly#@394RoD1w537Mg9tPTzv////SoZGxiamZuYWlgZKAA "Jelly – TIO Nexus")**
### How?
```
ØP;ṾiµÞ - Main link: string s (char list)
µÞ - sort the characters, c, of s by:
i - first index of c in:
ØP - pi yield: 3.141592653589793
; - concatenate with left: [3.141592653589793, c]
Ṿ - un-evaluate: "3.141592653589793,c" (a char list with the digit character c)
if any c is 0 ^ it will then be to the right of all others
```
[Answer]
# [CJam](https://sourceforge.net/p/cjam), ~~15~~ ~~12~~ ~~10~~ 8 bytes
```
r{P`#c}$
```
[Try it online!](https://tio.run/nexus/cjam#@19UHZCgnFyr8v@/oYGRsYmpmbmFJQA "CJam – TIO Nexus")
*-3: Use a string based on the `P` pi variable instead of a literal.*
*-2: Decided I don't need to uniquify at all, since finding an index takes the first occurrence anyways.*
*-2: Thanks to [jimmy23013](/u/25180) for an interesting approach using x mod 65536.*
Explanation:
```
r{P`#c}$ e# Takes an input token
r e# Take the integer as a string
{P`#c} e# Sorting key:
P e# Push P (defaults to 3.141592653589793)
` e# Convert to string representation
# e# Find char's index in the string we made
e# A '.' will never be found in an integer, but it doesn't matter, since the shifting preserves ideal sorting.
e# A '0' will be indexed as -1.
c e# Convert index to char
e# This first calculates index % 65536, and then converts to char. We need this because otherwise 0 would be indexed as -1, i.e. smallest index.
e# We don't need to convert back to integer, since we can use lexicographical sorting.
$ e# Sort with key
```
[Answer]
# [C (clang)](http://clang.llvm.org/), ~~85~~ 73 bytes
```
*z=L"9150236874"-48;s(*a,*b){return z[*a]-z[*b];}f(*t,n){qsort(t,n,4,s);}
```
[Try it online!](https://tio.run/##FYvfCoMgHEbve4ofwkBFoT9WRvQGvUHrwqIicG5LR1D06nPu5uPjcM7IR63M4j09mhZVSR6nWSFLgbiQtcVUMTqQc5vcZzNwdFT1POzQ19eMqWOGnG/73BwOlwlmSX35h1oNJtEZAazGget6aKBFSZqJvChlFVeyLHKRpUmM6iDNIYZ9tHoy2BHyR68tlDNGN23vBjFwgV7@O85aLdbz/Qc "C (clang) – Try It Online")
[Answer]
# PHP, 71 Bytes
The [regex solution](https://codegolf.stackexchange.com/questions/118100/sort-digits-by-their-first-occurrence-in-pi/118149#118149) is shorter
```
for(;~$c=_3145926870[$i++];)echo str_repeat($c,substr_count($argn,$c));
```
or
```
for(;~$c=_3145926870[$i++];)echo str_pad("",substr_count($argn,$c),$c);
```
[Online Versions](http://sandbox.onlinephpfunctions.com/code/728aba9d6915f74931bd96ea75f033286bb7187c)
## PHP, 78 Bytes
```
for(;~$c=$argn[$i++];)$j[strpos("3145926870",$c)].=$c;ksort($j);echo join($j);
```
## PHP, 112 Bytes
```
$a=str_split($argn);usort($a,function($x,$y){return strpos($d="3145926870",$x)<=>strpos($d,$y);});echo join($a);
```
[Online Version](http://sandbox.onlinephpfunctions.com/code/85430db5d9fd31f443de242338c6cfba544313fd)
[Answer]
# Ruby, 50 bytes
```
n=gets;"3145926870".each_char{|c|$><<c*n.count(c)}
```
[Answer]
# [C (gcc)](https://gcc.gnu.org/), 78 bytes
```
f(char*s){for(char*d="3145926870",*p;*d;d++)for(p=s;*p;)*p++-*d||putchar(*d);}
```
[Try it online!](https://tio.run/nexus/c-gcc#JYtNDoMgGAXXcoqGFR@0ifxDiIcxJaQuaonYlXp2KnY3mTevJvJ8jQstsKXP8uc4YMmV9sI42@M7zYHGEBmDVuShhNMAzYw9aNz3/F3bi9AI4ajTvN7e4zQTQBvqEsE9F1JpY53HEFB31oXgC9vYcy6ElEppbYy1zvkrO@oP "C (gcc) – TIO Nexus")
[Answer]
# [MATL](https://github.com/lmendo/MATL), 14 bytes
```
YP99Y$uj!y=sY"
```
[Try it online!](https://tio.run/nexus/matl#@x8ZYGkZqVKapVhpWxyp9P@/oZGxiamZuYWlAQA "MATL – TIO Nexus")
### Explanation with an example
The symbol `;` is used as row separator in matrices. So `[1 2 3]` is a row vector, `[1; 2; 3]` is a column vector, and `[1 2; 3 4]` is a square matrix. The latter can also be represented, for clarity, as
```
[1 2;
3 4]
```
Consider input `2325` as an example.
```
YP % Push approximation of pi as a double (predefined literal)
% 3.14159265358979
99Y$ % Variable-precision arithmetic with 99 digits. Gives a string.
% The input 3.14159265358979 is recognized as representing pi
% STACK: '3.141592653589793238462 ··· 707'
u % Unique entries, keeping order of their first appearance
% STACK: '3.145926870'
j % Input line as a string
% STACK: '3.145926870', '2352'
! % Transpose
% STACK: '3.145926870', ['2'; '3';'5'; '2']
y % Duplicate the second-top element in the stack
% STACK: '3.145926870', ['2'; '3';'5'; '2'], '3.145926870'
= % Test for equality, with broadcast. This gives a matrix with
% all pairwise comparisons)
% STACK: '3.145926870', [0 0 0 0 0 0 1 0 0 0 0;
% 1 0 0 0 0 0 0 0 0 0 0;
% 0 0 0 0 1 0 0 0 0 0 0;
% 0 0 0 0 0 0 1 0 0 0 0]
s % Sum of each column
% STACK: '3.145926870', [1 0 0 0 1 0 2 0 0 0 0]
Y" % Run-length decoding. Implicitly display
% STACK: '3522'
```
[Answer]
# C# Interactive, 37 36 Bytes
```
i.OrderBy(c=>"145926870".IndexOf(c))
```
Actually you have to execute this in the C# interactive for proper results, but I guess this is what you meant with *exit status*. The variable *i* actually is the input variable (it can be for example a string), so it's basically the method parameter.
I think the code itself is pretty straight forward.
[Answer]
# PHP, 66 65 bytes
Saved 1 byte thanks to Titus.
```
while(~$d=_3145926870[++$i])echo preg_filter("/[^$d]/",'',$argn);
```
[Answer]
# [APL (Dyalog Unicode)](https://www.dyalog.com/), 13 [bytes](https://github.com/abrudz/SBCS)
```
{⍵[⍵⍋⍨14⍕○1]}
```
[Try it online!](https://tio.run/##SyzI0U2pTMzJT///v/pR79ZoIH7U2/2od4WhyaPeqY@mdxvG1v5Pe9Q24VFv36O@qZ7@j7qaD603ftQ2EcgLDnIGkiEensH/0xTUDQ2MjE1MzcwtLNW5QFxjU3MIy8DIxMxCHQA "APL (Dyalog Unicode) – Try It Online")
`○1` Pi times 1.
`14⍕` convert to a string with 14 decimal digits. This includes all unique digits except 0.
`⍵⍋⍨` the indices that would sort the input string `⍵` according to order given by the previous string.
`⍵[...]` index with those indices into the input to sort it.
[Answer]
# [05AB1E](https://github.com/Adriandmen/05AB1E), ~~5~~ 6 bytes
Had to realise that `0` is not present in the standard length pi constant.
```
Σтžsyk
```
[Try it online!](https://tio.run/nexus/05ab1e#@39u8cWmo/uKK7P//7e0MDczNTE2MjQAAA "05AB1E – TIO Nexus")
```
Σтžsyk
Σ Sort by the result of code
тžs Push 100 digits of pi
yk Index of digit in pi
```
[Answer]
# Java 7, 110 bytes
```
String c(String s){String r="";for(char i:"3145926870".toCharArray())r+=s.replaceAll("[^"+i+"]","");return r;}
```
**Explanation:**
```
String c(String s){ // Method with String parameter and String return-type
String r=""; // Result String
for(char i:"3145926870".toCharArray()) // Loop over the characters of "3145926870"
r+=s.replaceAll("[^"+i+"]",""); // Append the result-String with all the occurrences of the current character
// End of loop (implicit / single-line body)
return r; // Return the result-String
} // End of method
```
**Test code:**
[Try it here.](https://tio.run/nexus/java-openjdk#LY5NC4JAFEX3/YrHW81giB@ZY9JCWrdqKQbTZDUwqbwZAwl/u03g7nDvhXOVkdbC@bsBsE46rWC5ONLdExRbwfLvSnRELB89MfWSBPqAabzLimQv8ghD1598WhHJiXFOwdGG1A5GqrYyhmF9xUAH2OAWkZfUupE6oHJeAIbxZrx49X96fYe31N3qrxuQ/P8P4DJZ177DfnTh4CtnOqaYrKOG89IP5s28LHGS7rJ9LopIpEUm4jwRHuIf)
```
class M{
static String c(String s){String r="";for(char i:"3145926870".toCharArray())r+=s.replaceAll("[^"+i+"]","");return r;}
public static void main(String[] a){
System.out.println(c("12345678908395817288391"));
}
}
```
**Output:**
```
33311145599922688888770
```
[Answer]
## Clojure, 38 bytes
```
#(sort-by(zipmap"3145926870"(range))%)
```
Input in string, returns a sequence of characters. `zipmap` creates a "dictionary" object, which can be used in a function context as well.
```
(f "1234")
(\3 \1 \4 \2)
```
If input digits were guaranteed to be unique then you could simply do `#(filter(set %)"3145926870")`.
[Answer]
# PHP, 69 68
```
for(;(~$d=$argn[$j++])||~$c=_3145926870[$i+++$j=0];)$c==$d&&print$d;
```
Still beaten by [preg\_filter](https://codegolf.stackexchange.com/a/118149/29637) but I thought it was quite nice itself. Maybe someone can golf off some bytes.
[Answer]
# [Husk](https://github.com/barbuz/Husk), 4 bytes
```
Ö€İπ
```
[Try it online!](https://tio.run/##yygtzv7///C0R01rjmw43/D///9oQx0THVMdSx0jHTMdCx1zHYNYAA "Husk – Try It Online")
Input as a list of digits.
[Answer]
# [Pip](https://github.com/dloscutoff/pip), 10 bytes
```
PI.0@?_SKa
```
[Try it online!](https://tio.run/##K8gs@P8/wFPPwME@Ptg78f///4ZGxiamZuYWlgaGRmYWAA "Pip – Try It Online")
### Explanation
```
SKa Sort the command-line argument a by this key function:
@?_ Index of first occurrence in
PI.0 Pi (3.141592653589793) concatenated with 0
```
If the `0` isn't added, `PI@?0` returns nil, which behaves... [strangely](https://tio.run/##K8gs@P8/wNPBPj7YO/H///@GRsYmpmbmFpYGhkZmFgA)... when used as a sorting key.
[Answer]
# [Vyxal](https://github.com/Vyxal/Vyxal), 8 bytes
```
µ»×₍+=»ḟ
```
[Try it Online!](https://vyxal.pythonanywhere.com/?v=2#WyIiLCIiLCLCtcK7w5figo0rPcK74bifIiwiIiwiMTIzNDU2Nzg5MDEyMzQ1Njc4OTAiXQ==)
`µ` Sort by
`ḟ` first index in
`»×₍+=»` compressed integer 145926870
[Answer]
# [Perl 6](https://perl6.org), 34 bytes
```
*.comb.sort:{3145926870.index: $_}
```
[Try it](https://tio.run/nexus/perl6#Ky1OVSgz00u25sqtVFBLzk9JVbD9r6WXnJ@bpFecX1RiVW1saGJqaWRmYW6gl5mXklphpaASX/vfmqs4sVIBpF5DJV5TLys/M08hLb9IISczL7VYQ/PQbrARGvoxKdr6IB5IwX9DI2MTUzNzC0sDC2NLUwtDcyMLIMMQAA "Perl 6 – TIO Nexus")
```
*\ # WhateverCode lambda (this is the parameter)
.comb # split into digits
.sort: { # sort by
3145926870.index: $_ # its index in this number
}
```
[Answer]
# k, 19 bytes
```
{x@<"3145926870"?x}
```
Explanation:
```
{ } /function(x)
"3145926870"?x /for each x: "3145926870".index(x)
< /get indices with which to sort
x@ /sort x by those indices
```
[Answer]
# [Japt](https://github.com/ETHproductions/japt), 6 [bytes](https://en.wikipedia.org/wiki/ISO/IEC_8859-1)
Input as a string, output as an array of digit strings
```
¬nUiMP
```
[Try it](https://petershaggynoble.github.io/Japt-Interpreter/?v=1.4.6&code=rG5VaU1Q&input=IjAxMjM0NTY3ODk4NzY1NDMyMTAi)
[Answer]
# TI-Basic, 100 bytes
```
Input Str1
seq(expr(sub(Str1,I,1)),I,1,length(Str1→A
seq(1+sum(not(cumSum(Ans(I)={3,1,4,5,9,2,6,8,7}))),I,1,dim(Ans→B
SortD(ʟB,ʟA
sum(seq(₁₀^(I-1)ʟA(I),I,1,dim(ʟA
```
Takes input as a string. Outputs a number that is stored in `Ans` and is displayed at the end.
]
|
[Question]
[
In typography, a [counter](https://en.wikipedia.org/wiki/Counter_%28typography%29) is the area of a letter that is entirely or partially enclosed by a letter form or a symbol. A closed counter is a counter that is entirely enclosed by a letter form or symbol. You must write a program takes a string as input and prints the total number of closed counters in the text.
Your input:
* May be a command line input, or from STDIN, but you must specify which.
* Will consist entirely of the printable ASCII characters, meaning all ASCII values between 32 and 126 inclusive. This does include spaces. [More information.](http://www.asciitable.com/)
Now, this does vary slightly between fonts. For example, the font you're reading this in considers 'g' to have one closed counter, whereas the google font has 'g' with two closed counters. So that this is not an issue, here are the official number of closed counters per character.
All the symbols with no closed counters:
```
!"'()*+,-./12357:;<=>?CEFGHIJKLMNSTUVWXYZ[\]^_`cfhijklmnrstuvwxyz{|}~
```
Note that this includes space.
Here are all the symbols with one closed counter:
```
#0469@ADOPQRabdegopq
```
And here are all the symbols with 2 closed counters:
```
$%&8B
```
And last but not least, here are some sample inputs and outputs.
`Programming Puzzles and Code-Golf` should print `13`
`4 8 15 16 23 42` should print `5`
`All your base are belong to us` should print `12`
`Standard loopholes apply` should print `12`
`Shortest answer in bytes is the winner!` should print `8`
[Answer]
## Python 3, 63
```
print(sum(map(input().count,"#0469@ADOPQRabdegopq$%&8B$%&8B")))
```
A straightforward approach. Iterates over each character with a closed counter, summing the number of occurrences, doing so twice for characters with two closed counters. It would be the same length to instead write
```
"#0469@ADOPQRabdegopq"+"$%&8B"*2
```
Python 3 is needed to avoid `raw_input`.
[Answer]
# CJam, ~~41~~ ~~39~~ ~~37~~ 34 bytes
```
"$%&8Badopq#0469@Rbeg"_A<eu+qfe=1b
```
*Thanks to @jimmy23013 for golfing off 3 bytes!*
[Try it online.](http://cjam.aditsu.net/#code=%22%24%25%268Badopq%230469%40Rbeg%22_A%3Ceu%2Bqfe%3D1b&input=4%208%2015%2016%2023%2042)
### How it works
```
"$%&8Badopq#0469@Rbeg" e# Push that string.
_A< e# Retrieve the first 10 characters.
eu+ e# Convert to uppercase and append.
e# This pushes "$%&8Badopq#0469@Rbeg$%&8BADOPQ".
q e# Read from STDIN.
fe= e# Count the occurrences of each character.
1b e# Base 1 conversion (sum).
```
[Answer]
# Pyth, 31 bytes
```
sm@tjC"cúÁ-ÈN%³rØ|"3Cdz
```
[Demonstration.](https://pyth.herokuapp.com/?code=sm%40tjC%22c%C3%BA%C3%81-%C2%85%15%C3%88%17N%25%C2%91%C2%B3%C2%9Cr%C3%98%1F%C2%87%7C%C2%AD%223Cdz&input=Programming%20Puzzles%20and%20Code-Golf&debug=0)
Note that the code may not be displayed properly due to the use of non-ASCII characters. The correct code is at the link.
I made a lookup table of the output desired for each input character, rotated it by 32 to make use of Pyth's modular indexing, stuck a 1 at the beginning, and interpreted it as a base 3 number, giving the number `2229617581140564569750295263480330834137283757`. I then converted this number to base 256 and converted it to a string, which is the string used in the answer.
[Answer]
# sed, 51
With golfing help from @manatwork and @TobySpeight:
```
s/[$%&8B]/oo/g
s/[^#0469@ADOPQRabdegopq]//g
s/./1/g
```
Input from STDIN. With [this meta-question in mind](https://codegolf.meta.stackexchange.com/questions/5343/can-numeric-input-output-be-in-unary), the output is in unary:
```
$ echo 'Programming Puzzles and Code-Golf
4 8 15 16 23 42
All your base are belong to us
Standard loopholes apply
Shortest answer in bytes is the winner!' | sed -f countercounter.sed
1111111111111
11111
111111111111
111111111111
11111111
$
```
[Answer]
# Perl, 41
```
$_=y/#0469@ADOPQRabdegopq//+y/$%&8B//*2
```
`41` characters +1 for the `-p` flag.
This uses [y///](http://perldoc.perl.org/perlop.html#Quote-Like-Operators) to count the characters.
```
echo 'Programming Puzzles and Code-Golf' | perl -pe'$_=y/#0469@ADOPQRabdegopq//+y/$%&8B//*2'
```
[Answer]
# GNU APL, 39 bytes
```
+/⌈20÷⍨26-'$%&8B#0469@ADOPQRabdegopq'⍳⍞
```
Try it online in [GNU APL.js](http://baruchel.hd.free.fr/apps/apl/#code=%2B%2F%E2%8C%8820%C3%B7%E2%8D%A826-'%24%25%268B%230469%40ADOPQRabdegopq'%E2%8D%B3%E2%8D%9E).
### How it works
```
⍞ Read input.
'$%&8B#0469@ADOPQRabdegopq'⍳ Compute the indexes of the input characters
in this string. Indexes are 1-based.
26 == 'not found'
26- Subtract each index from 26.
20÷⍨ Divide those differences by 20.
⌈ Round up to the nearest integer.
+/ Add the results.
```
[Answer]
# JavaScript, 86
I/O via popup. Run the snippet in any ~~d~~recent browser to test.
```
for(c of prompt(t=0))c='$%&8B#0469@ADOPQRabdegopq'.indexOf(c),~c?t+=1+(c<5):0;alert(t)
```
[Answer]
# K, ~~54~~ ~~43~~ ~~42~~ 37 bytes
```
+//(30#"$%&8B#0469@ADOPQRabdegopq"=)'
```
Cut off 5 bytes thanks to @JohnE!
## Older version:
```
f:+/(#&"#0469@ADOPQRabdegopq$%&8B$%&8B"=)'
```
## Original:
```
f:+/{2-(5="$%&8B"?x;20="#0469@ADOPQRabdegopq"?x;0)?0}'
```
[Answer]
# C, 127 bytes
```
n;f(char*i){char*o="#0469@ADOPQRabdegopq",*t="$%&8B";for(;*i;i++)if(strchr(o,*i))n++;else if(strchr(t,*i))n+=2;printf("%d",n);}
```
Pretty straightforward. Ungolfed version:
```
int num = 0;
void f(char* input)
{
char *one="#0469@ADOPQRabdegopq";
char *two="$%&8B";
for(;*input;input++)
if(strchr(one, *input)) //If current character is found in first array
num ++;
else if(strchr(two, *input))//If cuurent character is found in second array
num += 2;
printf("%d", num);
}
```
**Test it [here](http://rextester.com/RKIC56361)**
If function arguments are not allowed, then the `stdin` version takes up to 141 bytes:
```
n;f(){char*o="#0469@ADOPQRabdegopq",*t="$%&8B",i[99],*p;gets(i);for(p=i;*p;p++)if(strchr(o,*p))n++;else if(strchr(t,*p))n+=2;printf("%d",n);}
```
Note that the above version assumes that the input is atmost 98 characters long.
**Test it [here](http://rextester.com/OOLU87201)**
Command-line arguments version (143 bytes):
```
n;main(c,v)char**v;{char*o="#0469@ADOPQRabdegopq",*t="$%&8B",*p=v[1];for(;*p;p++)if(strchr(o,*p))n++;else if(strchr(t,*p))n+=2;printf("%d",n);}
```
**Test it [here](http://rextester.com/INAN16332)**
[Answer]
# Python 2, ~~96~~ ~~90~~ ~~75~~ 67+2 = 69 Bytes
Can't think of any other way to do this... is what I would have thought until I saw xnor's solution. I'll post what I had anyways.
*Thanks to FryAmTheEggman for saving 6 bytes*
Alright, now I'm happy with this.
*Thanks to xnor for the find trick, saving 4 bytes.*
Added two bytes since input needs to be enclosed in quotes.
```
print sum('#0469@ADOPQRabdegopq$%&8B'.find(x)/20+1for x in input())
```
[Answer]
# Java, 162
```
class C{public static void main(String[]a){System.out.print(-a[0].length()+a[0].replaceAll("[#0469@ADOPQRabdegopq]","..").replaceAll("[$%&8B]","...").length());}}
```
Well if it *has* to be a full program... It's just a one-liner that matches characters and replaces them with a longer string. Then, returns the difference in length from the original. Unfortunately, java doesn't really have anything to just count the number of matches.
Here it is with line breaks:
```
class C{
public static void main(String[]a){
System.out.print(
-a[0].length() +
a[0].replaceAll("[#0469@ADOPQRabdegopq]","..")
.replaceAll("[$%&8B]","...")
.length()
);
}
}
```
[Answer]
# Pyth - 35 bytes
Uses the obvious method of in first + \*2 in second. Thanks @FryTheEggman.
```
s/Lz+"#0469@ADOPQRabdegopq"*2"$%&8B
```
[Try it here online](http://pyth.herokuapp.com/?code=s%2FLz%2B%22%230469%40ADOPQRabdegopq%22*2%22%24%25%268B&input=4+8+15+16+23+42&debug=1).
[Answer]
# Javascript, ~~114~~ 95 bytes
```
alert(prompt().replace(/[#046@ADOPQRabdegopq]/g,9).replace(/[$%&8B]/g,99).match(/9/g).length)
```
Thanks to Ismael Miguel for helping me golf this.
[Answer]
# Ruby, 59 bytes
```
a=gets;p a.count('#0469@ADOPQRabdegopq')+2*a.count('$%&8B')
```
Input from command line or stdin. Shortest so far using a non-esoteric language.
Update: chilemagic beat me
[Answer]
# [Retina](https://github.com/mbuettner/retina), 44 bytes
```
1
[#0469@ADOPQRabdegopq]
1
[$%&8B]
11
[^1]
<empty line>
```
Gives output in unary.
Each line should go to its own file or you can use the `-s` flag. E.g.:
```
> echo "pp&cg"|retina -s counter
11111
```
The pairs of lines (pattern - substitute pairs) do the following substitution steps:
* Remove `1`'s
* Substitute 1-counter letters with `1`
* Substitute 2-counter letters with `11`
* Remove everything but the `1`'s
[Answer]
# J, 43
As a function:
```
f=:[:+/[:,30$'$%&8B#0469@ADOPQRabdegopq'=/]
f 'text goes here'
6
```
# 46 bytes (command line)
As a standalone command-line program:
```
echo+/,30$'$%&8B#0469@ADOPQRabdegopq'=/>{:ARGV
```
Save the above line as `counter2.ijs` and call from the command line:
```
$ jconsole counter2.ijs 'Programming Puzzles and Code Golf'
13
```
[Answer]
# Julia, ~~77~~ 74 bytes
```
t=readline();length(join(t∩"#0469@ADOPQRabdegopq")*join(t∩"\$%&8B")^2)
```
This reads text from STDIN and prints the result to STDOUT.
Ungolfed + explanation:
```
# Read text from STDIN
t = readline()
# Print (implied) to STDOUT the length of the intersection of t with the
# 1-closed counter list joined with the duplicated intersection of t with
# the 2-closed counter list
length(join(t ∩ "#0469@ADOPQRabdegopq") * join(t ∩ "\$%&8B")^2)
```
Example:
```
julia> t=readline();length(join(t∩"#0469@ADOPQRabdegopq")*join(t∩"\$%&8B")^2)
Programming Puzzles and Code Golf
13
```
[Answer]
# [rs](https://github.com/kirbyfan64/rs), 56 bytes
```
_/
[#0469@ADOPQRabdegopq]/_
[$%&8B]/__
[^_]/
(_+)/(^^\1)
```
[Live demo.](http://kirbyfan64.github.io/rs/index.html?script=_%2F%0A%5B%230469%40ADOPQRabdegopq%5D%2F_%0A%5B%24%25%268B%5D%2F__%0A%5B%5E_%5D%2F%0A(_%2B)%2F(%5E%5E%5C1)&input=Programming%20Puzzles%20and%20Code-Golf%0A4%208%2015%2016%2023%2042%0AAll%20your%20base%20are%20belong%20to%20us%20%0AStandard%20loopholes%20apply%0AShortest%20answer%20in%20bytes%20is%20the%20winner!)
[Answer]
GNU APL, 37 characters
```
+/,⍞∘.=30⍴'$%&8B#0469@ADOPQRabdegopq'
```
construct a character vector which contains 2-counter characters twice (30⍴)
compare each input char with every character in the vector (∘.=)
sum up ravelled matches (+/,)
[Answer]
# Javascript ~~159~~, 130 Bytes
```
function c(b){return b.split("").map(function(a){return-1!="$%&8B".indexOf(a)?2:-1!="#0469@ADOPQRabdegopq".indexOf(a)?1:0}).reduce(function(a,b){return a+b})};
```
unminified:
```
function c(b) {
return b.split("").map(function(a) {
return -1 != "$%&8B".indexOf(a) ? 2 : -1 != "#0469@ADOPQRabdegopq".indexOf(a) ? 1 : 0
}).reduce(function(a, b) {
return a + b
})
};
```
With the help of @edc65:
```
function c(b){return b.split('').reduce(function(t,a){return t+(~"$%&8B".indexOf(a)?2:~"#0469@ADOPQRabdegopq".indexOf(a)?1:0)},0)}
```
[Answer]
# Haskell, 117
```
a="#0469@ADOPQRabdegopq"
b="$%&8B"
c n[]=n
c n(x:s)
|e a=f 1
|e b=f 2
|True=f 0
where
e y=x`elem`y
f y=c(n+y)s
```
c is a function `c :: Int -> String -> Int` which takes a counter and a string and goes through the string one letter at a time checking if the current letter is a member of the 1 point array or the 2 point array and calls itself for the rest of the string after incrementing the counter the appropriate amount.
Call with counter = 0 in ghci:
```
ghci> c 0 "All your base are belong to us"
12
```
[Answer]
# C#, 157
```
void Main(string s){int v=0;v=s.ToCharArray().Count(c=>{return "#0469@ADOPQRabdegopq".Contains(c)||"$%&8B".Contains(c)?++v is int:false;});Console.Write(v);}
```
Ungolfed:
```
void Main(string s)
{
int v = 0;
v = s.ToCharArray()
.Count(c =>
{
return "#0469@ADOPQRabdegopq".Contains(c) || "$%&8B".Contains(c) ? ++v is int:false;
});
Console.Write(v);
}
```
Converting the string into a char array, then seeing if each char is in either counter. If it is in the second one, I just have it incrementing the counter again.
[Answer]
# Erlang, 103 bytes
This is a complete program that runs using escript. The first line of the file must be blank (adding 1 byte).
```
main([L])->io:write(c(L,"#0469@ADOPQRabdegopq")+2*c(L,"$%&8B")).
c(L,S)->length([X||X<-L,S--[X]/=S]).
```
Sample run:
```
$ escript closed.erl 'Shortest answer in bytes is the winner!'
8$
```
[Answer]
# C, 99 bytes
```
n;f(char*i){for(char*o="#0469@ADOPQRabdegopq$%&8B",*t=o+20;*i;)n+=2-!strchr(o,*i)-!strchr(t,*i++);}
```
# Explanation
I further golfed [the answer of Cool Guy](/a/51923/39490); it got too long to be a comment. Instead of the `if`/`else`, I took advantage of `!` converting a pointer to bool. I also made `o` include `t` so that I could add "is in `o`" and "is in `t`" for the total number of counters.
# Expanded code
```
#include <string.h>
int num = 0;
void f(char* input)
{
char *one = "#0469@ADOPQRabdegopq" "$%&8B";
char *two = strchr(one, '$');
while (*input) {
num += 2 - !strchr(one, *input) - !strchr(two, *input));
++input;
}
}
```
Output is in `num`, which must be cleared before each call.
# Test program and results
```
#include <stdio.h>
int main() {
const char* a[] = {
"Programming Puzzles and Code-Golf",
"4 8 15 16 23 42",
"All your base are belong to us",
"Standard loopholes apply",
"Shortest answer in bytes is the winner!",
NULL
};
for (const char** p = a; *p; ++p) {
n=0;f(*p);
printf("%3d: %s\n", n, *p);
}
return 0;
}
```
```
13: Programming Puzzles and Code-Golf
5: 4 8 15 16 23 42
12: All your base are belong to us
12: Standard loopholes apply
8: Shortest answer in bytes is the winner!
37: n;f(char*i){for(char*o="#0469@ADOPQRabdegopq$%&8B",*t=o+20;*i;)n+=2-!strchr(o,*i)-!strchr(t,*i++);}
```
The code itself contains 37 counters by its own metric.
]
|
[Question]
[
Obviously this challenge would be trivial with separate functions and libraries, so they aren't allowed.
Your code must conform to an ECMAscript specification (any spec will do), so no browser-specific answers.
The array must be accessible after it is instantiated.
I have an answer that I'll withhold for now.
**Note:** this challenge is specific to javascript because it is notoriously inconvenient to make multi-dimensional arrays in javascript.
[Answer]
# Javascript, 34 bytes
```
for(r=[b=[i=10]];i--;r[i]=b)b[i]=1
```
Since it's apparently OK to make the rows equal by reference, I guess it's apparently OK to rely on that fact. This helps us shave off one for-loop by building the table at the same time as its rows. So, here's my new contestant.
Since `r[0]` and `b[0]` are overwritten during the loop, they can contain garbage. This gives us another free execution slot to shave off some commas. Sadly, `r=b=[]` won't do, since then they are equal by-ref.
Also, it scales well (99x99 is still 34 bytes), doesn't require ES5 (the new functions have terribly long names, anyways), and as a bonus, it's unreadable :-)
[Answer]
# ECMAScript 6 - 33 Characters
```
x=(y=[..."1111111111"]).map(x=>y)
```
Outputs a 10x10 array of "1"s.
This abuses the fact that the string "1111111111" has all the requisite properties to be treated as if it is an array so you can use the spread operator `...` to transform it into an array of characters and then map it to a copy of the array with each element referencing the "original".
Or with only one variable name (for 35 characters):
```
x=(x=x=>[..."1111111111"])().map(x)
```
Or for extra confusion (but at 45 characters)
```
x=[];x[9]=x;x=[...x].map(y=>[...x].map(x=>1))
```
or (43 characters)
```
y=y=>[...x].map(x=>y);x=[];x[9]=x;x=y(y(1))
```
[Answer]
# 44 bytes
```
for(a=[i=10];i;)a[--i]=[1,1,1,1,1,1,1,1,1,1]
```
Previous version:
```
for(a=i=[];i^10;)a[i++]=[1,1,1,1,1,1,1,1,1,1]
```
[Answer]
# 45 characters
```
x=[a=[1,1,1,1,1,1,1,1,1,1],a,a,a,a,a,a,a,a,a]
```
Each element points to the same array, but the spec doesn't mention anything against that!
[Answer]
# Javascript ES6, 30
```
(x=i=>Array(10).fill(i))(x(1))
```
ES6 in action :)
[Answer]
## Javascript, 51
```
a=[];for(i=10;i;i--,a.push([1,1,1,1,1,1,1,1,1,1]));
```
Or if all indices are allowed to point to the same array:
## Javascript, 41
```
a=[1,1,1,1,1,1,1,1,1,1];a=a.map(a.sort,a)
```
[Answer]
# JavaScript, 45 44 Bytes
Best I have so far. (Still trying).
```
x=[];while(x.push([1,1,1,1,1,1,1,1,1,1])-10);
```
Shorter (thanks mellamokb!)
```
for(x=[];x.push([1,1,1,1,1,1,1,1,1,1])-10;);
```
[Answer]
## Javascript, 47
Since my original solution has been beaten, I will now post it.
```
for(a=[],i=10;i--;a[i]='1111111111'.split(''));
```
Unfortunately, `0x3FF.toString(2)` isn't quite as efficient as just listing the string out, which isn't quite as efficient as just statically declaring the array.
You can shave off one character this way (**46**):
```
for(a=[],i=10;i--;a[i]=[1,1,1,1,1,1,1,1,1,1]);
```
You can save 2 more characters like so: (**44**)
```
for(a=[i=10];i--;)a[i]=[1,1,1,1,1,1,1,1,1,1]
```
Another 44 byte solution using JS 1.8 function expression closures (FF only atm):
```
x=(x=[1,1,1,1,1,1,1,1,1,1]).map(function()x)
```
[Answer]
# JavaScript, 57 bytes
```
r=eval("["+(A=Array(11)).join("["+A.join("1,")+"],")+"]")
```
Before golfing:
```
a=Array(11).join("1,");
b=Array(11).join("["+a+"],")
c=eval("["+b+"]")
```
Note: This needs ES5, so don't expect much from IE.
[Answer]
# 54
This has already been beaten, but here's my solution:
```
function x(){return[1,1,1,1,1,1,1,1,1,1]}x=x().map(x)
```
[Answer]
# 39 bytes
Using array comprehension in ECMAScript 7:
```
x=[x for(y in x=[1,1,1,1,1,1,1,1,1,1])]
```
[Answer]
**56 characters**
Rather long answer, but will be better for 100x100 etc.
```
for(a=[[i=k=0]];++i<100;m?0:a[k=i/10]=[1])a[k][m=i%10]=1
```
[Answer]
# Javascript, 36 chars (ECMA 6)
```
(a=[b=[]]).fill(b.fill(a[9]=b[9]=1))
```
Tested in my browser (Firefox on Ubuntu) and in the Codecademy Javascript interpreter
[Answer]
# ES6, 54
It's not the shortest, but I thought I'd go for a different approach to what's already here.
```
a=(''+{}).split('').slice(0,10).map(_=>a.map(_=>1))
```
>
> Cast an object to a string `"[object Object]"`
>
> Split the string into chars ["[", "o", "b", ... "]" ]
>
> Grab a slice of just 10
>
> Map the result of mapping 1 onto the initial slice
>
>
>
[Answer]
# 61 for fun
```
eval("r=["+("["+(Array(11).join("1,"))+"],").repeat(11)+"]")
```
[Answer]
# Javascript - 64 63 59 characters
```
for(var a=b=[],i=100;i-->0;b[i%10]=1)if(i%10==0){a[i/10]=b;b=[]}
```
```
for(var a=b=[i=100];i-->0;b[i%10]=1)if(i%10==0){a[i/10]=b;b=[]}
```
One char saved by hiding the iterator in the array.
```
for(a=b=[1],i=100;i--;b[i%10]=1)if(i%10==0){a[i/10]=b;b=[]}
```
Saved some chars with Jans suggestions.
Readable version:
```
for(var a = b = [i = 100]; i-- > 0; b[i % 10] = 1) {
if(i % 10 == 0) {
a[i / 10] = b;
b = [];
}
}
```
Yes, it's not the shortest solution, but another approach without using readymade `[1,1,1,1,1,1,1,1,1,1]` arrays.
[Answer]
**Javascript 69 characters (for now)**
```
b=[]
a=[]
for(i=100;i-->0;){
a.push(1)
if(i%10===0){b.push(a);a=[]}
}
```
[Answer]
## JavaScript 73
```
function h(){s="1111111111",r=[10],i=-1;while(++i<10){r[i]=s.split("");}}
```
[Answer]
## Javascript ES6, 53
```
x="1".repeat(100).match(/.{10}/g).map(s=>s.split(""))
```
But the ones in the array are strings :)
[Answer]
## Javscript ES6, 53
```
x=eval("["+("["+"1,".repeat(10)+"],").repeat(10)+"]")
```
[Answer]
# JavaScript (ES6), 35 bytes
```
A=Array(10).fill(Array(10).fill(1))
```
]
|
[Question]
[
### [Related](https://codegolf.stackexchange.com/questions/89621/random-golf-of-the-day-7-a-distinctly-random-character)
You are a manager at a large number factory. You want to show everyone your business is doing well, by showing randomly chosen samples. Unfortunately, your business is not doing that well. But luckily, you have a bit of ingenuity...
---
Write a program or function that when given an array of unique, positive numbers, which may include floats, returns a random number from the array, with **bigger numbers having a higher probability of being chosen \$\left(a\_n > a\_m \implies P(a\_n) > P(a\_m)\right)\$**, **no two numbers being chosen with the same probability \$\left(P(a\_n) \not = P(a\_m)\right)\$**, and **all numbers having a non-zero chance of being chosen \$\left(P(a\_n) \not = 0\right)\$**. Anyways, this is [code-golf](/questions/tagged/code-golf "show questions tagged 'code-golf'"), so shortest code wins!
[Answer]
# [Python](https://www.python.org), 41 bytes
```
lambda l:choices(l,l)
from random import*
```
[Attempt This Online!](https://ato.pxeger.com/run?1=m72soLIkIz9vweI025ilpSVpuhY3NXMSc5NSEhVyrJIz8jOTU4s1cnRyNLnSivJzFYoS81KAVGZuQX5RiRZEw9aCosy8Eo00jWhDHSMdYx0THdNYTU2I3IIFEBoA) or [run it 100000 times](https://ato.pxeger.com/run?1=m72soLIkIz9vweI025ilpSVpuhY3NXMSc5NSEhVyrJIz8jOTU4s1cnRyNLnSivJzFYoS81KAVGZuQX5RiRZUQxBYKjk_Jyc1uSQzP68YJs9VUJSZV6LhnF-aV5JapBGdphFtqGOkY6xjomMaqxltEJuWX6QQr5CZBzI3PVXD0AAENGM1NSEmL1gAoQE)
Uses the list itself as the weights.
[Answer]
# [R](https://www.r-project.org/), 27 bytes
(Or 20 bytes in R>=4.1 using `\` instead of `function`)
```
function(x)-sample(-x,1,,x)
```
[Try it online!](https://tio.run/##K/qfZvs/rTQvuSQzP0@jQlO3ODG3ICdVQ7dCx1BHp0Lzf5mtoZWhAVdJYhJQtDixoCCnUgMkAgY6cJ2ZmmkaZZqamv8B "R – Try It Online")
The 4th argument of R’s `sample` function is `prob`=“a vector of probability weights for obtaining the elements of the vector being sampled”.
Unfortunately, a “convenience” feature of `sample` changes its behaviour when its first argument is a single positive number, so we need to negate it here to avoid this, and then re-negate the result.
——
# [R](https://www.r-project.org/), 31 bytes
(Or 24 bytes in R>=4.1 using `\` instead of `function`)
```
function(x)max(-sample(-x,2,T))
```
[Try it online!](https://tio.run/##K/qfZvs/rTQvuSQzP0@jQjM3sUJDtzgxtyAnVUO3QsdIJ0RT83@ZraGVoQFXSWISULQ4saAgp1IDJAIGOnDdmZppGmWaQPUA "R – Try It Online")
Return the highest of two random picks.
[Answer]
# [Python](https://www.python.org), 64 bytes (also supports negative numbers)
```
lambda l:sorted(l)[int(len(l)*random()**.5)]
from random import*
```
[Attempt This Online!](https://ato.pxeger.com/run?1=NYxNCsIwFIT3PUWWeSGV1h8QQRC8gPtapLaJBpL3QpouPIubguidvI2t1dnMMMN895e_xSth_9Db47OLOl2_d7Zy56ZidtNSiKrhFgqDkVuFQxShwoYcByFmKygTHcixqWPG-eEhfpzDd6rJWlVHQ9j-98SHkbenDqMKvNC8SHOZyblcyGUJmgI7MYMj9aJ4no2CEmDi9v3kHw)
## Explanation
Sort the list, the pick a random element.
The square root biases the result towards the end of the list.
[Answer]
# [J](https://www.jsoftware.com), 8 bytes
```
#~{~1?+/
```
[Attempt This Online!](https://ato.pxeger.com/run?1=m70wa8FNVUtFK8NYM0UrS3V1LiU99TQFWysFdQUdBQMFKyDW1VNwDvJxW1pakqZrsUK5rrrO0F5bH8LdpMmVmpyRr5CmYKhgpGCsYKJgCpFYsABCAwA)
* `1?+/` Sum the numbers and then choose a random index between 0 and the sum
* `#~{~` Take that index from a new array formed by duplicating each number as many times as itself. Eg, `#~ 1 2 3` gives `1 2 2 3 3 3`, and we choose a random index from the interval \$[0,6)\$.
[Answer]
# WolframLanguage, 63 48 bytes
*Thanks to att* for shaving of 15
```
Sort[#][[Floor@Log2[Random[](2^Tr[1^#]2-3)+2]]]&
```
Original answer:
```
f[r_]:=Sort[r][[Floor@Log[2,RandomReal[{2,2^(Length@r+1)-1}]]]]
```
Sorts the array and picks a random number between `2` and `2^(l+1)-1`, where `l` is the length of the list. Then takes the logarithm to get the array index. This gives each number a twice as high probability to be chosen as the previous one.
## Example
`{1, 2, 3, 4, 5, 6, 7, 8, 9, 10}`
For a run of 2\*10^7 repetitions:
`{{1, 19562}, {2, 39068}, {3, 78145}, {4, 156309}, {5, 313362}, {6, 625087}, {7, 1249297}, {8, 2504498}, {9, 5005805}, {10, 10008867}}`
[](https://i.stack.imgur.com/GFavC.png)
[Answer]
# [JavaScript (Node.js)](https://nodejs.org), 41 bytes
```
a=>a.sort()[a.length*Math.random()**.5|0]
```
[Try it online!](https://tio.run/##BcE7DsIwDADQnVNkjKNg8WnZgsTCxgmqDlabtqBgIyeCInH38N6D3pQHvb/KlmWMdQqVwpkwixYLHWGKPJfF3agsqMSjPC04h@1v19fVBMPxY65JqJyaiyp9bbf3B3/0jW972AzCWVLEJLOd7ApQ/w "JavaScript (Node.js) – Try It Online") or [run it 100000 times](https://tio.run/##Hcy/DoIwEMfxnae4sQVtQMFBrImLm09AGC78N7VnSqMY5Nlr5YZPbvl97/jCsTLD02411Y1rpUN5RjGSsYwXKFSjO9uHN7S9MKhrejAehiL7xqUjkDAnR4g3sFvdr6armXfJg5YMsEHGOQynJP6f/6KIwzz5dct084arIrSH9GIMfliR@JpP@Y6PlJznQMVUQiQhWYKK9EiqEYo6Rtz9AA)
Takes an `Float64Array` (so the sorting works properly). Port of bsoelch's Python answer.
[+10 bytes](https://tio.run/##DccxDoMwDADAva/waEeJRZE6pj/oCxCDgQCt0rhKooqhf09ZTrqXfKXM@fmpLukS2uqb@Ltw0VwRxU50zk00CMeQtrqbh9Sds6RF30jG8O3Xje0AD4PrLbirhc7CaT9eZk1FY@CoG654ELU/) to take a regular array.
[Answer]
# [Vyxal](https://github.com/Vyxal/Vyxal), 4 bytes
```
℅?℅∴
```
[Try it Online!](https://vyxal.pythonanywhere.com/?v=2#WyIiLCIiLCLihIU/4oSF4oi0IiwiIiwiWzEsMiwzLDQsNSwxMF0iXQ==)
Return the highest of two random picks
```
‚ÑÖ # Random choice of single item from input array
? # Input (again)
‚ÑÖ # Random choice of single item from this
∴ # Maximum of these two values
```
[Answer]
# [Ruby](https://www.ruby-lang.org/), ~~32~~ 24 bytes
```
->l{(l+l).sample(2).max}
```
[Try it online!](https://tio.run/##JctBCsMgEEDRvafIUul0cAyFbuxFxEUaEghqK00CNsazG5ou/4P/WZ/fOup6ffjM/cULnLsQ/cCVwNClUp02BApauMEdqAVFlpHEZQrDnGMzGmcLY5vmhEhSyt8W859j487a024SbNi/19fCk7ClHg "Ruby – Try It Online")
Thanks to Dominic van Essen for -4 bytes and the idea to get to -8.
[Answer]
# [Jelly](https://github.com/DennisMitchell/jellylanguage), 3 bytes
```
X»X
```
[Attempt This Online!](https://ato.pxeger.com/run?1=m700KzUnp3LBgqWlJWm6FksiDu2OWFKclFwMFVgfrRRtqGOkY6xjomMaqxQLFQYA)
Distribution over 1000 runs: [Attempt This Online!](https://ato.pxeger.com/run?1=m700KzUnp3LBgqWlJWm6FksiDu2OWFKclFy8Kfzhru4T2w-3P2pa83DnIp9jMxMgStZHK0Ub6hjpGOuY6JjGKsVCdQIA)
Uses [Dominic van Essen's insight](https://codegolf.stackexchange.com/a/264847/56178): pick a random element (`X`), twice, then take the larger of them (`»`).
[Answer]
# [JavaScript (Node.js)](https://nodejs.org), 58 bytes
```
a=>a.sort((a,b)=>b-a).filter(_=>Math.random()<.5)[0]||a[0]
```
[Try it online!](https://tio.run/##VY5BTsMwEEXX5BR/OVamVgwUqFJH4gCcIIrQtE3AyI2RYypVtGcPprDpLOYv/ryn@ZCDTNvoPtNiDLt@HuwsthE9hZiIhDfKNpuFKD04n/pIr7Z5kfSuo4y7sCe11kvVVt3pJHnPvk/Yhq8xTbB4jlGOZMyF9VSpuhhCBP0eudxXdY41TJWnRlk6he/i5g9vB2oN45Zxx7hnLBkPjEfGE2PFmelUh9LC1MX52mou1pxXznEKvtc@vJHj/w9b16niPP8A "JavaScript (Node.js) – Try It Online")
Sorts the numbers, filters them randomly, then chooses the largest one.
[Answer]
# [Raku](https://raku.org), 13 bytes
```
*.roll(2).max
```
[Attempt This Online!](https://ato.pxeger.com/run?1=m72kKDG7dMHy3EoFtTQF26WlJWm6Fmu19Iryc3I0jDT1chMrIGI3ba25ihMrFTTSNKINdYx0jHVMdExjNSsqFAwNgEBTLzknsbg4M61SQ0tTrzi_qASotUBDW0uvLDGnNFUTYsiCBRAaAA)
Picks two elements independently and returns the max of the two.
[Answer]
# [Charcoal](https://github.com/somebody1234/Charcoal), 10 bytes
```
FAFι⊞υιI‽υ
```
[Try it online!](https://tio.run/##S85ILErOT8z5/z8tv0hBwzOvoLREQ1NTAczL1FQIKC3O0CjVUcjUtOYKKMrMK9FwTiwu0QhKzEvJz9Uo1dTUtP7/PzraUEfBSEfBWEfBJDb2v25ZDgA "Charcoal – Try It Online") Link is to verbose version of code. Explanation:
```
FA
```
Loop over the input numbers.
```
Fι⊞υι
```
Push each number that many times to the predefined empty list.
```
I‽υ
```
Output a random number from that list.
8 bytes using the newer version of Charcoal on ATO:
```
I‽ΣEAEιι
```
[Attempt This Online!](https://ato.pxeger.com/run?1=m70iOSOxKDk_MWfBgqWlJWm6FjeNAooy80o0nBOLSzSCEvNS8nM1gktzNXwTCzQ88wpKSzQ0dRRAnEwdhUxNMLBeUpyUXAzVvzxaSbcsRyl2XXS0oY6CkY6CsY6CSWwsRBIA "Charcoal – Attempt This Online") Link is to verbose version of code. Explanation:
```
Ôº° Input list
E Map over elements
ι Current element
E Map over implicit range
ι Outer element
Σ Flatten
‚ÄΩ Random element
I Cast to string
Implicitly print
```
A port of @JoyalMathew's JavaScript answer in straight succinct Charcoal is only 6 bytes:
```
I⌈∨Φθ‽
```
[Try it online!](https://tio.run/##ASoA1f9jaGFyY29hbP//77yp4oyI4oiozqbOuOKAvf//W1sxLCAyLCAzLCA0XV0 "Charcoal – Try It Online") Explanation:
```
θ Input list
Φ Filtered by
‚ÄΩ Random coin flip
‚à® If empty then implicitly use input list
‚åà Take the maximum
I Cast to string
Implicitly print
```
[Answer]
# [Wolfram Language (Mathematica)](https://www.wolfram.com/wolframscript/), 19 bytes
```
RandomChoice[#->#]&
```
[Try it online!](https://tio.run/##Lcy/CsIwEMfx3acILThFuK6WSsEXKNUtZjhrQgP5I@l18OljjLnpN9z345BW5ZDMgkkPaUb/Cu66BrMo0Z4urTymKRpPoiG1ETP@vdP54Rte1nALkcY7Pq0S/3RWaIXkHUje5DfZH2oedsoBC5p1ABwAGEWDditYZaz9VEyPxc/O76Ts0xc "Wolfram Language (Mathematica) – Try It Online") Like other languages, the builtin can use weights, so the input can serve as the weights as well. Works with nonnegative real numbers.
[Answer]
# [Factor](https://factorcode.org), 35 bytes
```
[ [ dup <array> ] map-flat random ]
```
[Attempt This Online!](https://ato.pxeger.com/run?1=NYw9CsJAFAb7nOID6wQXDf5iKzY2ok1I8Ug2sGQ3WV5eiiCexGYbc6fcRjBYDQPDvMeKCmk5TI_77XI970HMNHSoNTfaomidN1Zz0ouxRozuwNSUrYNnLTJ4No3gEEVPqB1WSFOoDdZQUEuoFK9PL1W8nRYZMpS9x_H3PyGHIx9XluQ_zOd0LMhaJLOEMPML)
Create n copies of each n, and select one at random (uniformly).
For instance, `{ 5 1 2 }` becomes `{ 5 5 5 5 5 1 2 2 }`.
[Answer]
# [Julia](https://julialang.org), 37 bytes
```
!l=rand([fill.(sort(l),keys(l))...;])
```
[Attempt This Online!](https://ato.pxeger.com/run?1=m700qzQnM3HBgqWlJWm6FjdVFXNsixLzUjSi0zJzcvQ0ivOLSjRyNHWyUyuLgbSmnp6edawmVHF0joKtQrSBnqGOgZ4REBvHchUBRQytDA0MDBT0auwU4nXtFHO4Cooy80py8jSKosFSsZowET2NHAU9WzuF5PzSvBI9DT1bW5Bd0UWxmlArYO4CAA)
sort the list and repeat each element by their index before randomly choosing a number
### with integers only, 25 bytes
```
!l=rand([fill.(l,l)...;])
```
[Attempt This Online!](https://ato.pxeger.com/run?1=m700qzQnM3HBgqWlJWm6FjsVc2yLEvNSNKLTMnNy9DRydHI09fT0rGM1IfI3Q3MUbBWiDXWMdIxjuYqAbEMrQwMDAwW9GjuFeF07xRyugqLMvJKcPI2iaLBUrCZMBGiagp6tnUJyfmleiZ6Gnq2tRo6mTnRRrCbUcJgjAA)
directly repeat each number by itself
[Answer]
# [Jelly](https://github.com/DennisMitchell/jelly), 4 bytes
```
·π¢xJX
```
A monadic Link that accepts a list of distinct floats and outputs a random one.
**[Try it online!](https://tio.run/##y0rNyan8///hzkUVXhH///@PNtQz1VEwNDUwAJMgQkfBQM/QNBYA "Jelly – Try It Online")** Or see the results of [10,000 runs](https://tio.run/##y0rNyan8///hzkUVXhH/D7dXP9q47sR2EyD/6KQi9///o430THUUjPSMQIQJiDADEYYgwjgWAA "Jelly – Try It Online").
### How?
Weights by the count of lesser-or-equal values.
The probability of picking the \$a^{\text{th}}\$ most minor of \$n\$ numbers is \$\frac{2a}{n(n+1)}\$.
For example given `[2.5, 2.2, 2.4, 2.6, 2.1, 2.3]` (\$n(n+1)=6(6+1)=42\$):
$$P(2.1)=\frac{1}{21}, P(2.2)=\frac{2}{21}, \cdots , P(2.6)=\frac{6}{21}$$
```
·π¢xJX - Link: list of numbers, A
·π¢ - sort {A} -> [a1, a2, a3, ...]
J - indices {A} -> [1, 2, 3, ...]
x - {sorted A} times {indices of A} -> [a1, a2, a2, a3, a3, a3, ...]
X - uniform random choice
```
[Answer]
# [Vyxal](https://github.com/Vyxal/Vyxal), 3 bytes
```
øḊ℅
```
[Try it Online!](https://vyxal.pythonanywhere.com/?v=2#WyIiLCIiLCLDuOG4iuKEhSIsIiIsIlsxLDIsMyw0LDVdIl0=)
## Explained
```
øḊ℅­⁡​‎‎⁡⁠⁡‏⁠‎⁡⁠⁢‏‏​⁡⁠⁡‌⁢​‎‎⁡⁠⁣‏‏​⁡⁠⁡‌­
øḊ # ‎⁡Run length decode the input, using the input as both character source and lengths. Basically, zip and run length decode
℅ # ‎⁢Choose randomly from that list.
üíé
```
Created with the help of [Luminespire](https://vyxal.github.io/Luminespire).
[Answer]
# [05AB1E](https://github.com/Adriandmen/05AB1E/wiki/Commands), 5 [bytes](https://github.com/Adriandmen/05AB1E/wiki/Codepage)
```
{.s˜Ω
```
[Try it online.](https://tio.run/##yy9OTMpM/f@/Wq/49JxzK///jzbUMdIx0jPXMY4FAA)
Or alternatively, a port of [*@DominicVanEssen*'s second R answer](https://codegolf.stackexchange.com/a/264847/52210) is 5 bytes as well:
```
ΩIΩ‚à
```
[Try it online.](https://tio.run/##yy9OTMpM/f//3ErPcysfNcw6vOD//2hDHSMdIz1zHeNYAA)
**Explanation:**
```
{ # Sort the (implicit) input-list from lowest to highest
.s # Pop and push a list of its suffixes
Àú # Flatten it
Ω # Pop and push a random item from this list
# (which is output implicitly as result)
```
```
Ω # Push a random item from the (implicit) input-list
I # Push the input-list
Ω # Pop and push another random item from it
‚Äö # Pair the two together
à # Pop and push its maximum
# (which is output implicitly as result)
```
[Answer]
# [MathGolf](https://github.com/maxbergmark/mathgolf/blob/master/math_golf.txt), 4 [bytes](https://github.com/maxbergmark/mathgolf/blob/master/code_page.py)
```
‼ww╙
```
[Try it online.](https://tio.run/##y00syUjPz0n7//9Rw57y8kdTZ/7/H22oY6RjpGeuYxwLAA)
Port of [*@DominicVanEssen*'s second R answer](https://codegolf.stackexchange.com/a/264847/52210).
**Explanation:**
```
‼ # Apply the next two builtins separately on the current stack:
w # Pop and push a random item from the given (implicit) input-list
w # Same
‚ïô # Pop the top two items on the stack, and leave its maximum
# (after which the entire stack is output implicitly as result)
```
[Answer]
# [Uiua](https://uiua.org), 11 bytes
```
⊡⌊×↥⚂⚂⧻.⊏⍏.
```
[Try it online!](https://www.uiua.org/pad?src=V2VpZ2h0IOKGkCDiiqHijIrDl-KGpeKaguKaguKnuy7iio_ijY8uCldlaWdodCBbNCAyLjIgMi4zIDMgNiA4XQo=)
Built on a similar principle to lots of others others (randomly pick two items and use the max), but tweaked slightly
## Explanation
```
⊏⍏. # sort the array
⧻. # get its length
↥⚂⚂ # max of two random numbers [0,1)
√ó # multiply to scale to [0,len)
‚ä°‚åä # floor and index into array
```
[Answer]
# [Perl 5](https://www.perl.org/) `-pa`, 44 bytes
```
@b=map{($_)x++$,}sort{$a-$b}@F;$_=$b[rand@b]
```
[Try it online!](https://tio.run/##K0gtyjH9/98hyTY3saBaQyVes0JbW0Wntji/qKRaJVFXJanWwc1aJd5WJSm6KDEvxSEp9v9/QwUjBWMFEwVTPaN/@QUlmfl5xf91fU31DAwN/usWJAIA "Perl 5 – Try It Online")
[Answer]
# [JavaScript (Node.js)](https://nodejs.org), 47 bytes
```
a=>a.sort((a,b)=>b-a)[.4/Math.random()|0]||a[0]
```
[Try it online!](https://tio.run/##HctLDoIwFIXhOau4wzZAbRUnYtmBK2g6uLwUglxTiCEB1l4rZ/DnTL4evzhVrvvM6Uh141vtURcoJnIzY5iUXBdlityI7PTA@SUcjjW9Gd@k3TY00noCDau6gUzgfPRyNDt6Dd3zqCUHrNMyh@6u5H/hxTGHdQm6ZUYFHGRgwVieA5nFQqxB7VFF40RDIwZ6MuL@Bw "JavaScript (Node.js) – Try It Online")
# [JavaScript (V8)](https://v8.dev/), 53 bytes
```
a=>Math.max(...a.map(_=>a[a.length*Math.random()|0]))
```
[Try it online!](https://tio.run/##HY3NCoJAFIX3PsVdzmQNTj8Q2fgAQbVoKRIXc3RCHRlFDPPZ7eZZfBw4fJw39timzjTdpj/OWs2ooit2hahwYEIIpNKwp4owRlFmdd4Vq2V3WL9sxfg3SDifLSgY5QmCNWwX7hbuFx6IU@hp64AZFYRgzjL4h5rvcxgHsjWLJclkkkZOwkOw8ZCAr0BOXmrr1paZKG3OLo/7TbSdM3Vu9IdZ@v8B "JavaScript (V8) – Try It Online")
]
|
[Question]
[

**Antiferromagnetism** is what IBM researchers used to jump from a *1 terabyte disk* to a *100 terabyte disk* in the same amount of atoms.
In materials that exhibit antiferromagnetism, the magnetic moments of atoms or molecules, usually related to the spins of electrons, align in a regular pattern with neighboring spins (on different sublattices) pointing in opposite directions.
Your job is to write a program that draws the ordering of antiferromagnetic atoms like the picture shown above. You must be able to have at least four sets of pairs, though you may have more.
Each pair must be shown as follows, though they must be **actual arrows**:
```
up down
down up
up down
```
Your output can be in ascii art or graphical output.
You can make only a function or a whole program, but it must take an input and draw that many pairs. Examples with *only words*:
Input: 1
```
up down
down up
up down
```
Input: 2
```
up down up down
down up down up
up down up down
```
Acceptable arrows:
* `↑` and `↓`
* `⇅` and `⇵`
* `/|\` and `\|/`
Please put your answers in **Language, X bytes** format, as it's easy to read. The least amount of bytes wins!
[Answer]
# APL, ~~18~~ 12 bytes
```
⍉(2×⎕)3⍴'↑↓'
```
This constructs a 2n x 3 matrix, where n is the input (`⎕`), filled with the characters `↑` and `↓`. The transpose (`⍉`) of this matrix is then printed.
You can [try it online](http://baruchel.hd.free.fr/apps/apl/#code=%E2%8D%89(2%C3%97%E2%8E%95)3%E2%8D%B4'%E2%86%91%E2%86%93').
[Answer]
# Pyth, 15 bytes (11 chars)
```
V3.>*Q"↑↓"N
```
Try it online: [Demonstration](http://pyth.herokuapp.com/?code=V3.%3E*Q%22%E2%86%91%E2%86%93%22N&input=4&debug=0)
### Explanation:
```
implicit: Q = input number
V3 for N in [0, 1, 2]:
"↑↓" string "↑↓"
*Q repeat Q times
.> N rotate the string by N
```
[Answer]
# Java, ~~313~~ 296 bytes
Here's an example that displays arrows graphically:
```
import java.awt.*;void f(int n){new Frame(){public void paint(Graphics g){for(int k=0,l,m,o;k<n*6;o=k%6,l=o/2*10+32,m=k/6*20+(k++%2==0?19:29),g.fillPolygon(new int[]{m+4,m,m+4,m+4,m+6,m+6,m+10},o==1|o==2|o==5?new int[]{l+9,l+5,l+5,l,l,l+5,l+5}:new int[]{l,l+5,l+5,l+9,l+9,l+5,l+5},7));}}.show();}
```
In a more readable format:
```
import java.awt.*;
void f(int n) {
new Frame() {
public void paint(Graphics g) {
for (int k = 0, l, m, o; k < n*6;){
o = k % 6;
l = o / 2 * 10 + 32;
m = k / 6 * 20 + (k++ % 2 == 0 ? 19 : 29);
g.fillPolygon(new int[] {m+4,m,m+4,m+4,m+6,m+6,m+10},
o == 1 || o == 2 || o == 5 ?
new int[] {l+9,l+5,l+5,l,l,l+5,l+5} :
new int[] {l,l+5,l+5,l+9,l+9,l+5,l+5},
7);
}
}
}.show();
}
```
The display for 5 as input:

You'll have to resize the window that appears to see the arrows. I tried to make it so that none of them would appear "chopped off" by the window's inside border, but it may appear that way on certain platforms.
[Answer]
# CJam, 18 bytes (14 chars)
```
ri3*"↑↓"*3/zN*
```
Generate the columns (which form a repeating pattern) then transpose.
[Try it online](http://cjam.aditsu.net/#code=ri3*%22%E2%86%91%E2%86%93%22*3%2FzN*&input=4).
---
**Alternative 18 bytes:**
```
3,ri"↑↓"*fm>N*
```
Rotate the string `"↑↓"*n` by 0, 1 or 2 times.
[Answer]
## CJam (15 chars, 19 bytes)
```
ri"↑↓"*_(+1$]N*
```
[Online demo](http://cjam.aditsu.net/#code=ri%22%E2%86%91%E2%86%93%22*_%28%2B1%24%5DN*&input=4)
[Answer]
## **Befunge, 71 bytes**
My first answer, so please be gentle with me :o)
Annoying alignment issues resulted in a few wasted bytes, if you have any improvements for me I'd love to hear them!
```
&::3>:2% #v_0#v" \|/ "<
>\^,*52<> 0#v" /|\ "<
:#^_$1-:#^_@ >:#,_$\1-
```
Input: 4
```
/|\ \|/ /|\ \|/ /|\ \|/ /|\ \|/
\|/ /|\ \|/ /|\ \|/ /|\ \|/ /|\
/|\ \|/ /|\ \|/ /|\ \|/ /|\ \|/
```
[Answer]
# CJam, 14 bytes
```
0000000: 332c 7269 2218 1922 2a66 6d3e 4e2a 3,ri".."*fm>N*
```
This requires a supporting terminal that renders [code page 850](https://en.wikipedia.org/wiki/Code_page_850) like this:

The non-pointy part of the code turned out to be identical to [@Sp3000's alternative version](https://codegolf.stackexchange.com/a/52912).
---
# CJam, 17 bytes
```
ri"⇅⇵⇅"f*N*
```
Cheaty double arrow version, with credits to @DigitalTrauma.
[Try it online.](http://cjam.aditsu.net/#code=ri%22%E2%87%85%E2%87%B5%E2%87%85%22f*N*&input=3)
[Answer]
# Pyth, 16 bytes (12 chars)
```
J"↑↓"V3*~_JQ
```
Example:
```
Input: 4
Output:
↑↓↑↓↑↓↑↓
↓↑↓↑↓↑↓↑
↑↓↑↓↑↓↑↓
```
[Answer]
# Python 2, ~~131~~ 122 bytes
```
from turtle import*
for k in range(input()*6):z=k/3+k%3&1;pu();goto(k/3*32,z*32^k%3*64);pd();seth(z*180+90);fd(32);stamp()
```
Well... I beat ~~C~~ Java I guess?
[](https://i.stack.imgur.com/yCgtB.png)
---
I've chosen height `32` for the arrows, which is pretty large, so after a while the turtle starts drawing offscreen. If you want everything to fit for large inputs, you can either make the arrows smaller by replacing the `32`s, or use `screensize()` (I'm not sure if there's a meta post on offscreen output...)
[Answer]
# GNU sed, 25 bytes
I found the `⇅` and `⇵` unicode arrow symbols, which allow more shortening and [they have been allowed by this comment](https://codegolf.stackexchange.com/questions/52903/antiferromagnetic-ordering?noredirect=1#comment126360_52903):
```
h
s/1/⇅/g
H
G
s/1/⇵/g
```
[Input is in unary](https://codegolf.meta.stackexchange.com/q/5343/11259), so e.g. 4 is `1111`:
```
$ echo 1 | sed -f antiferro.sed
⇅
⇵
⇅
$ echo 1111 | sed -f antiferro.sed
⇅⇅⇅⇅
⇵⇵⇵⇵
⇅⇅⇅⇅
$
```
---
Previous answer in case `⇅` and `⇵` are disallowed:
# GNU sed, 39 bytes
```
s/1/↑↓/g
s/.*/&a&↑\n&/
s/a↑/\n/
```
[Answer]
# Swift 2, 66 bytes
```
let f={n in(0..<n*3).map{print("↑↓",appendNewline:$0%n==n-1)}}
```
If Swift would be just a liiiitle bit less verbose, it wouldn't even be that bad for golfing (I'm looking at you, named parameter `appendNewline`)
[Answer]
# Ruby 39 (or 44) characters, 43 (or 48) bytes
According to <https://mothereff.in/byte-counter> the arrow characters are 3 bytes each!
```
->(n){a=['↑↓'*n]*3;a[1]=a[1].reverse;a}
```
An anonymous function which returns an array. If the function has to print the array, it should end with `puts a` for 5 more bytes.
Example use
```
f=->(n){a=['↑↓'*n]*3;a[1]=a[1].reverse;a}
puts f.call(6)
```
Gives
```
↑↓↑↓↑↓↑↓
↓↑↓↑↓↑↓↑
↑↓↑↓↑↓↑↓
```
[Answer]
# J, ~~41~~ ~~35~~ 32 bytes (28 characters)
```
3$(,:|.)(2*".1!:1[1)$ucp'↑↓'
```
I have never programmed anything in J so this took me a while, and it's most definitely not the best way to do it.
This waits for you to input a number when run before outputing the arrows.
[Answer]
# Javascript (ES6), 66 63 53 47 bytes (62 55 49 41 characters)
```
f=n=>`⇅
⇵
⇅`.replace(/./g,'$&'.repeat(n))
```
Props to [Digital Trauma](https://codegolf.stackexchange.com/questions/52903/antiferromagnetic-ordering/52930) for finding the ⇅ and ⇵ characters and allowing me to shave off more bytes.
[Answer]
## J, 30 bytes
```
|:((2*".1!:1<1),3)$ucp'↑↓'
```
[Answer]
# C, ~~169~~ ~~170~~ ~~162~~ ~~125~~ ~~123~~ ~~105~~ ~~119~~ 107 bytes
So, I though I might as well give this a go, even though this is obviously not the winner :)
Golfed:
```
n,i,j;main(){n=getchar();n=atoi(&n);for(;j++<3;){for(i=0;i++<n;)printf("%.3s ","⇅⇵"+(j%2)*3);puts("");}}
```
Ungolfed:
```
#include <stdio.h>
#include <stdlib.h>
/* n -> Number of columns, i & j -> Loop counters */
n,i,j;
main()
{
/* Get the number of iterations from stdin */
n = getchar();
n = atoi(&n); /* Thanks @AndreaBiondo */
for (; j++ < 3;)
{
/* Print rows of arrows */
for (i = 0; i++ < n;)
printf("%.3s ","⇅⇵" + (j % 2) * 3);
/* Print a newline */
puts("");
}
}
```
Example:
```
Input: 4
⇵ ⇵ ⇵ ⇵
⇅ ⇅ ⇅ ⇅
⇵ ⇵ ⇵ ⇵
```
### Update:
See it run [here](http://ideone.com/zHfFEo)
[Answer]
# Octave, 37 bytes
***EDIT:*** corrected from the earlier stripe-antiferromagnetic version. Thanks @beta-decay for catching my mistake.
```
f=@(n)repmat(["⇅";"⇵";"⇅"],1,n)
```
Defines a function `f(n)`. Sample output:
```
octave:4> f(1)
ans =
⇅
⇵
⇅
octave:5> f(5)
ans =
⇅⇅⇅⇅⇅
⇵⇵⇵⇵⇵
⇅⇅⇅⇅⇅
```
[Answer]
# [05AB1E](https://github.com/Adriandmen/05AB1E/wiki/Commands), ~~17~~ 11 [bytes](https://github.com/Adriandmen/05AB1E/wiki/Codepage)
```
ƵηSnŽXæ+ç×»
```
Bug-fixed and -6 bytes thanks to *@ovs*.
Uses `⇅` and `⇵`.
[Try it online](https://tio.run/##AR0A4v9vc2FiaWX//8a1zrdTbsW9WMOmK8Onw5fCu///Mw) or [verify some more test cases](https://tio.run/##yy9OTMpM/W/qquSZV1BaYqWgZO@nw6XkX1oC4en4/T@29dz24LyjeyMOL9M@vPzw9EO7/@sc2mb/HwA).
**Slightly larger simplified approach - 15 bytes in UTF-8 (8 characters):**
```
"⇅⇵"ĆS×»
```
[Try it online](https://tio.run/##yy9OTMpM/f9f6VF766P2rUpH2oIPTz@0@/9/YwA) or [verify some more test cases](https://tio.run/##yy9OTMpM/W/qquSZV1BaYqWgZO@nw6XkX1oC4en4/Vd61N76qH2r0pG24MPTD@3@r3Nom/1/AA).
**Explanation:**
Unfortunately the 05AB1E codepage doesn't contain the arrow characters, so we have to create them ourselves or use UTF-8 encoding for the entire program.
```
Ƶη # Push compressed integer 171
S # Convert it to a list of digits: [1,7,1]
n # Square each: [1,49,1]
ŽXæ+ # Add compressed integer 8644 to each: [8645,8693,8645]
ç # Convert them to characters with these codepoints: ["⇅","⇵","⇅"]
× # Repeat each character the (implicit) input amount of times as strings
» # And join this list of strings by newlines
# (after which it is output implicitly as result)
"⇅⇵" # Push string "⇅⇵"
Ć # Enclose, appending it's own head: "⇅⇵⇅"
S # Convert it to a list of characters: ["⇅","⇵","⇅"]
×» # Same as above
```
[See this 05AB1E tip of mine (section *How to compress large integers?*)](https://codegolf.stackexchange.com/a/166851/52210) to understand why `Ƶη` is `171` and `ŽXæ` is `8644`.
[Answer]
## CoffeeScript, 60 bytes (58 chars)
Comprehensions make it easy without recursion:
```
f=(n,x='')->x+='\n⇵⇅'[i%(n+1)&&1+i%2]for i in[1..n*3+2];x
```
[Answer]
# Ruby, 33 bytes
As a function:
```
f=->n{[s="↑↓"*n,s.reverse,s]}
```
Example:
```
> puts f[3]
↑↓↑↓↑↓
↓↑↓↑↓↑
↑↓↑↓↑↓
```
# Ruby, 37 bytes
Full program which takes input from stdin:
```
puts s="↑↓"*gets.to_i,s.reverse,s
```
[Answer]
## ><>, 55 Bytes
```
"⇅⇵⇅"{:&3*1-:0(?;\
|.!09v!?%&:&:{o:}/
oa{~}/|.!09
```
Try it online [here](http://fishlanguage.com/playground), inputting the desired length as initial stack value.
Non ⇅⇵ solution, 59 Bytes:
```
"↓↑"{:&3*>1-:0(?;{:{\
|.!09v!?%&:&:oo}}@:/
9oa{$}/|.!0
```
[Answer]
# BBC BASIC, 70 bytes
```
INPUTx:n$=STRING$(x,"/|\\|/"):PRINTn$:PRINTSTRING$(x,"\|//|\"):PRINTn$
```
This can probably be golfed more
[Answer]
# C, 97 bytes
Takes the input from the first command-line parameter, e.g. `main 4`. Supports up to `357913940` pairs. In C you can't use multibyte characters as `char`s but they work fine as strings.
```
i,n;main(c,v)char**v;{n=atoi(v[1]);for(i=6*n+3;i--;)printf("%s",i%(2*n+1)?i%2?"↓":"↑":"\n");}
```
It is smaller as a function, but the other C answers were complete programs so I did that too. It would be 69 bytes:
```
i;f(n){for(i=6*n+3;i--;)printf("%s",i%(2*n+1)?i%2?"↓":"↑":"\n");}
```
[Answer]
# Python 2, 47 bytes
Port of [my BBC BASIC answer](https://codegolf.stackexchange.com/a/52997/30525), taking advantage of how Python can easily reverse strings.
```
n=r"/|\\|/"*input();print n+"\n"+n[::-1]+"\n"+n
```
[Answer]
# C, 117 89 85 bytes
```
i;main(j,v)char**v;{j=2*atol(v[1])+1;for(;i++<3*j;)printf(i%j?i%2?"↑":"↓":"\n");}
```
Ungolfed:
```
i;
main(j,v)
char**v; // Credit to @AndreaBiondo for brilliant idea that I will use a lot in future golfed programs :)
{
j = 2*atol(v[1])+1;
for(;i++<3*j;)
printf(i%j?i%2?"↑":"↓":"\n");
}
```
[Answer]
## JavaScript (ES6), 66 bytes (62 chars)
That includes the Unicode character counted as three bytes each as well as the mandatory newline counted as one byte.
Uses recursion as inspired by [this answer](https://codegolf.stackexchange.com/a/52876/22867). I tried it non-recursively but generating a defined array took too many characters, although someone else might know how to do it better than me.
```
f=n=>(g=(a,i)=>i?g(`
↓↑`[i%(n*2+1)&&1+i%2]+a,i-1):a)('',n*6+2)
```
### Demo
As with all ES6 answers, they are demonstrable in Firefox, Edge, and Safari 9 only at time of writing:
```
f = n => (g = (a, i) => i ? g(`
↓↑` [i % (n * 2 + 1) && 1 + i % 2] + a, i - 1) : a)('', n * 6 + 2)
console.log = x => document.getElementById('O').innerHTML += x + '\n';
console.log(f(1));
console.log(f(2));
console.log(f(4));
console.log(f(32));
```
```
<pre><output id=O></output></pre>
```
[Answer]
# Java, 150 bytes
```
static void g(int n){n*=2;f(n,0);f(n,1);f(n,0);}static void f(int n,int d){String l="";for(n+=d;n-->d;)l+=(n%2==0)?"↓":"↑";System.out.println(l);}
```
Output of `g(2)`:
```
↑↓↑↓
↓↑↓↑
↑↓↑↓
```
[Answer]
# [Japt](https://github.com/ETHproductions/japt) [`-R`](https://codegolf.meta.stackexchange.com/a/14339/), 13 [bytes](https://en.wikipedia.org/wiki/ISO/IEC_8859-1)
Went through a good few different methods but couldn't do better than 16 then I realised a port of [Kevin's solution](https://codegolf.stackexchange.com/a/212215/58974) would come in a bit shorter.
```
#«ì £çX²d8644
```
[Try it](https://petershaggynoble.github.io/Japt-Interpreter/?v=1.4.6&flags=LVI&code=I6vsIKPnWLJkODY0NA&input=Mw)
[Answer]
# [Vyxal](https://github.com/Vyxal/Vyxal) `Dj`, 11 bytes
```
‛↑↓3*½ÞTvṅ*
```
[Try it Online!](https://lyxal.pythonanywhere.com?flags=Dj&code=%E2%80%9B%E2%86%91%E2%86%933*%C2%BD%C3%9ETv%E1%B9%85*&inputs=42&header=&footer=)
-1 thanks to Aaron Miller
[Answer]
# Python 2, ~~45~~ 55 bytes
edit: modified arrows
Pretty straightforward approach. Doesn't work with unicode arrows, though.
```
def f(n):x=" /|\\ \\|/"*n;print x+"\n "+x[::-1]+"\n"+x
```
]
|
[Question]
[
Write the shortest function to convert an IP address into it's integer representation and output it as an integer.
To change an IPv4 address to it's integer representation, the following calculation is required:
* Break the IP address into it's four octets.
* `(Octet1 * 16777216) + (Octet2 * 65536) + (Octet3 * 256) + (Octet4)`
**Sample Input**
```
192.168.1.1 10.10.104.36 8.8.8.8
```
**Sample Output**
```
3232235777 168454180 134744072
```
[Answer]
## PHP - 21 Characters
```
<?=ip2long($argv[1]);
```
[Answer]
## MySQL - 20 Characters
```
SELECT INET_ATON(s);
```
[Answer]
# Ruby (no builtins/eval) - 47
```
s=->s{s.split(".").inject(0){|a,b|a<<8|b.to_i}}
```
Test:
```
s["192.168.1.1"]
3232235777
```
[Answer]
**C: 79 characters**
```
main(i,a)char**a;{i=i<<8|strtol(a[1],a+1,0);*a[1]++?main(i,a):printf("%u",i);}
```
EDIT: removed C++, would not compile without headers; with GCC, the `printf` and `strtol` function calls trigger built-in functions, hence headers can be skipped. Thx to @ugoren for the tips. This will compile as is without additional options to `gcc`.
EDIT2: `return` is actually redundant :)
[Answer]
## Golfscript -- 16 chars
```
{[~]2%256base}:f
```
As a standalone program, this is even shorter at 11.
```
~]2%256base
```
Extremely straightforward. Evaluates the input string (`~`) and puts it into an array `[]`. Since the `.`s in the string duplicate the top of the stack, we only take every other term in the array (`2%`). We now have an array which basically represents a base 256 number, so we use a built-in function to do the conversion. (`256base`).
[Answer]
## Befunge - 2x11 = 22 characters
So close, Befunge will win one day.
```
>&+~1+#v_.@
^*4*8*8<
```
### Explanation
The biggest distinguishing feature of [Befunge](http://en.wikipedia.org/wiki/Befunge) is that instead of being a linear set of instructions like most languages; it is a 2d grid of single character instructions, where control can flow in any direction.
```
> v
^ <
```
These characters change the direction of control when they are hit, this makes the main loop.
```
&+~1+
```
This inputs a number and pushes it onto the stack (`&`), pops the top two values off the stack, adds them and pushes them back onto the stack (`+`), inputs a single character and places its ascii value on the stack (`~`), then pushes 1 onto the stack and adds them (`1+`).
The interpreter I've been using returns -1 for end of input, some return 0 instead so the `1+` part could be removed for them.
```
#v_.@
```
The `#` causes the next character to be skipped, then the `_` pops a value off the stack and if it is zero sends control right, otherwise sends it left. If the value was zero `.` pops a value off the stack and outputs it as an integer and `@` stops the program. Otherwise `v` sends control down to the return loop.
```
^*4*8*8<
```
This simply multiplies the top value of the stack by 256 and returns control to the start.
[Answer]
# Ruby (40)
```
q=->x{x.gsub(/(\d+)\.?/){'%02x'%$1}.hex}
```
->
```
q["192.168.1.1"]
=> 3232235777
```
[Answer]
## Ruby - 46 chars
```
require"ipaddr"
def f s;IPAddr.new(s).to_i;end
```
[Answer]
# AWK in ~47 chars
First-timer here... Um, not sure how to count this, but without the 'echo' it's 47 chars in AWK. (Not exactly bogey golf, but it's in the hole.)
```
echo $addr | /bin/awk -F\. '{print $1*16777216+$2*65536+$3*256+$4}'
```
Full day early for #tbt, too, so I actually met a schedule!!! \*8-)
Banner day.
[Answer]
# Bash - 46
### Table of content
You will find 4 differently golfed version:
>
>
> ```
> echo $[_=32,`printf "%d<<(_-=8)|" ${1//./ }`0] # 46chr
> set -- ${1//./ };echo $[$1<<24|$2<<16|$3<<8|$4] # 47chr
> v=('|%d<<'{24,16,8,0});printf -vv "${v[*]}" ${1//./ };echo $[0$v] # 65chr
> mapfile -td. i<<<$1;for((a=o=0;a<4;o+=i[a]<<(3-a++)*8)){ :;};echo $o # 68chr
>
> ```
>
>
## New version! 2018-11-15 More golfed, 46 char
```
echo $[_=32,`printf "%d<<(_-=8)|" ${1//./ }`0]
```
### Explanation
* I used `$_` for more golfing.
* Syntax `${1//./ }`will substitute every dots `.` by spaces .
* so `printf`will render something like `192<<(_-=8)|168<<(_-=8)|1<<(_-=8)|1<<(_-=8)|`
* then we will add a `0` after last **OR** `|` and
* preset `_` to **32**. [bash](/questions/tagged/bash "show questions tagged 'bash'") will read construct from left to right, so `$((_-=8))` make `24` at 1st *shift*, `16` on second, and so on.
in action:
```
set -- 192.168.1.1
echo $[_=32,`printf "%d<<(_-=8)|" ${1//./ }`0]
3232235777
```
For fun: trying to get `$_` content, after this:
>
>
> ```
> echo $_
> 3232235777
>
> ```
>
> ;-b
>
>
>
> ```
> set -- 192.168.1.1
> echo $_ $[_=32,`printf "%d<<(_-=8)|" ${1//./ }`0] $_
> 192.168.1.1 3232235777 0
>
> ```
>
> Ok, that's correct *`32 - 4 x 8 = 0`*
>
>
>
In a function:
```
ip2int() {
echo $[_=32,`printf "%d<<(_-=8)|" ${1//./ }`0]
}
ip2int 192.168.1.1
3232235777
ip2int 255.255.255.255
4294967295
ip2int 0.0.0.0
0
```
### or into a loop: -> 60
```
ip2int() {
for i;do
echo $[_=32,`printf "%d<<(_-=8)|" ${i//./ }`0]
done
}
ip2int 192.168.1.1 10.10.104.36 8.8.8.8 1.1.1.1 255.255.255.255 0.0.0.0
3232235777
168454180
134744072
16843009
4294967295
0
```
## bash (v4.1+): 47
***First post***
```
set -- ${1//./ };echo $[$1<<24|$2<<16|$3<<8|$4]
```
Explanation:
* Syntax `${1//./ }`will substitute every dots `.` by spaces .
* `set --` set *positional parameters* (`$@=($1 $2 $3...)`)
* So `set -- ${1//./ }` will split `$1` by dots and set `$1`, `$2`, `$3` and `$4` if string containg `3` dots (and no spaces).
in action:
```
set -- 192.168.1.1
set -- ${1//./ };echo $[$1<<24|$2<<16|$3<<8|$4]
3232235777
```
or in a function:
```
ip2int() {
set -- ${1//./ }
echo $[$1<<24|$2<<16|$3<<8|$4]
}
ip2int 192.168.1.1
3232235777
ip2int 0.0.0.0
0
```
### or into a loop: -> 61
```
for i;do set -- ${i//./ };echo $[$1<<24|$2<<16|$3<<8|$4];done
```
in action:
```
ip2int() {
for i;do
set -- ${i//./ }
echo $[$1<<24|$2<<16|$3<<8|$4]
done
}
ip2int 192.168.1.1 10.10.104.36 8.8.8.8 1.1.1.1 0.0.0.0
3232235777
168454180
134744072
16843009
0
```
## Another version differently golfed: 65
```
v=('|%d<<'{24,16,8,0});printf -vv "${v[*]}" ${1//./ };echo $[0$v]
```
Sample:
```
ip2int() {
v=('|%d<<'{24,16,8,0});printf -vv "${v[*]}" ${1//./ };echo $[0$v]
}
ip2int 255.255.255.255
4294967295
ip2int 10.10.104.36
168454180
```
In a loop (+14): 82
```
ip2int() {
for i;do
v=('|%d<<'{24,16,8,0})
printf -vv "${v[*]}" ${1//./ }
echo $[0$v]
done
}
```
**\* or a little more ugly: 70\***
```
v=('|%d<<'{24,16,8});printf -vv "${v[*]}" ${1//./ };echo $[0${v%<<2*}]
```
where `printf` give some string like `|192<<24 |168<<16 |1<<8|1<<24 |0<<16 |0<<8` we have to cut at last `<<2...`.
## golfed with `mapfile`, longer: 68
```
ip2int() {
mapfile -td. i<<<$1;for((a=o=0;a<4;o+=i[a]<<(3-a++)*8)){ :;};echo $o
}
```
or with loop: 82
```
ip2int() {
for a;do
mapfile -td. i<<<$a;for((a=o=0;a<4;o+=i[a]<<(3-a++)*8)){ :;};echo $o
done
}
```
[Answer]
## Golfscript - 21 chars
```
{'.'/{~}%{\256*+}*}:f
```
[Answer]
## Python 56 45
```
c=lambda x:eval('((('+x.replace('.','<<8)+'))
```
[Answer]
## C++ - lots of chars
```
#include <boost/algorithm/string.hpp>
#include <string>
#include <vector>
uint f(std::string p)
{
std::vector<std::string> x;
boost::split(x,p,boost::is_any_of("."));
uint r=0;
for (uint i = 0; i < x.size(); i++)
r=r*256+atoi(x[i].c_str());
return r;
}
```
[Answer]
## PowerShell ~~66~~ 61
Variation on Joey's answer:
```
filter I{([ipaddress](($_-split'\.')[3..0]-join'.')).address}
PS C:\> '192.168.1.1' | I
3232235777
PS C:\> '10.10.104.36' | I
168454180
PS C:\> '8.8.8.8' | I
134744072
```
[Answer]
# Powershell, ~~47~~ 43 bytes
```
$args-split'\.'|%{$r=([long]$r-shl8)+$_};$r
```
Test script:
```
$f = {
$args-split'\.'|%{$r=([long]$r-shl8)+$_};$r
}
@(
,("192.168.1.1",3232235777)
,("10.10.104.36",168454180)
,("8.8.8.8",134744072)
) | % {
$s,$expected = $_
$result = &$f $s
"$($result-eq$expected): $result"
}
```
Output:
```
True: 3232235777
True: 168454180
True: 134744072
```
[Answer]
### Windows PowerShell, 70
Naïve approach:
```
filter I{[int[]]$x=$_-split'\.'
$x[0]*16MB+$x[1]*64KB+$x[2]*256+$x[3]}
```
With using System.Net.IPAddress: **76**
```
filter I{([ipaddress]($_-replace('(.+)\.'*3+'(.+)'),'$4.$3.$2.$1')).address}
```
Test:
```
> '192.168.1.1'|I
3232235777
```
[Answer]
## Befunge-93 - 36 characters
```
&"~"2+::8****&884**:**&884***&++++.@
```
[Answer]
# Perl : DIY ( for oneliners. )(40)
```
$j=3;$i+=($_<<($j--*8))for split/\./,$x;
```
# Use value in $i
# DIY Function(65):
```
sub atoi{my($i,$j)=(0,3);$i+=($_<<($j--*8))for split'.',shift;$i}
```
[Answer]
## Haskell - 14 chars
```
(.) a=(256*a+)
```
usage in GHCi:
```
Prelude> let (.) a=(256*a+)
Prelude> 192. 168. 0. 1
3232235521
```
The only problem is that you have to put spaces left or right of the dot, otherwise the numbers will be interpreted as floating point.
[Answer]
## C# – 77 chars
```
Func<string,uint>F=s=>s.Split('.').Aggregate(0u,(c,b)=>(c<<8)+uint.Parse(b));
```
[Answer]
## JavaScript (45 characters)
Requires support for the `.reduce()` Array method introduced in ES5 and [arrow functions](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/arrow_functions).
```
f=(x)=>x.split('.').reduce((p,c)=>p<<8|c)>>>0
```
[Answer]
# [05AB1E](https://github.com/Adriandmen/05AB1E), 5 [bytes](https://github.com/Adriandmen/05AB1E/blob/master/docs/code-page.md)
```
'.¡₁β
```
[Try it online!](https://tio.run/##yy9OTMpM/f9fXe/QwkdNjec2/f9vaKAHRiZ6xmYA)
[Answer]
**C# - 120 Characters**
```
float s(string i){var o=i.Split('.').Select(n=>float.Parse(n)).ToList();return 16777216*o[0]+65536*o[1]+256*o[2]+o[3];}
```
My first code golf - be gentle ;)
[Answer]
# D: 84 Characters
```
uint f(S)(S s)
{
uint n;
int i = 4;
foreach(o; s.split("."))
n += to!uint(o) << 8 * --i;
return n;
}
```
[Answer]
# Python 3.2 (69)
```
sum((int(j)*4**(4*i)) for i,j in enumerate(input().split('.')[::-1]))
```
[Answer]
# PHP (no builtins/eval) - 54
```
<foreach(explode(".",$argv[1])as$b)$a=@$a<<8|$b;echo$a;
```
[Answer]
## Perl, 14 characters:
```
sub _{unpack'L>',pop}
# Example usage
print _(10.10.104.36) # prints 168454180
```
[Answer]
# [Stax](https://github.com/tomtheisen/stax), 9 [bytes](https://github.com/tomtheisen/stax/blob/master/docs/packed.md#packed-stax)
```
üL▼ü╛tΓi╨
```
[Run and debug it](https://staxlang.xyz/#p=814c1f81be74e269d0&i=192.168.1.1%0A10.10.104.36%0A8.8.8.8&a=1&m=2)
[Answer]
# [Perl 6](https://github.com/nxadm/rakudo-pkg), 16 bytes
```
{:256[m:g/\d+/]}
```
[Try it online!](https://tio.run/##K0gtyjH7n1upoJamYPu/2srI1Cw61ypdPyZFWz@29n9xYqVCmoZKvKZCWn6Rgo2hpZGeoZmFnqGeoYKhgR4YmegZmylY6IGh3X8A "Perl 6 – Try It Online")
[Answer]
# [C (gcc)](https://gcc.gnu.org/) `-m32` / POSIX, 33 bytes
```
f(a){inet_aton(a,&a);a=ntohl(a);}
```
[Try it online!](https://tio.run/##LY3NCoMwEITP@hSL0JL4kzZaxGJ9EislBKMBTYqml0pevWkqZfewMzt8w7OBc@cEYniTqjcPZrRCLD0yXLNGGT1O/lVbNzOpEIYtDPjIFohN20EDG0T0mhNaVoQSGqVensm@F1KUP12RfSKwdRgIvQCSyoBszjXI2yrfvRbI4NP/ig32fpLsRcFz8VmBosPrrjzLB1vZYexBNrTuw8XEhtVlc5F/AQ "C (gcc) – Try It Online")
On a big-endian platform, you could simply define a macro with `-Df=inet_aton` for **13 bytes**.
]
|
[Question]
[
Given a string like `[[[],[[]]],[]]`, made of only commas and square brackets, your challenge is to determine whether it represents a list.
A list is either:
* `[]`, the empty list
* At least one list, joined with commas and wrapped in square brackets.
You may use any three characters instead of `[,]`.
You may output as:
* Any two consistent values representing truthy and falsy
* One consistent value representing either truthy or falsy, and anything else as the other.
Output by erroring/not erroring *is* allowed, although `eval`-like solutions may be trickier than you think. Sometimes erroring and sometimes returning is *not*.
This is [code-golf](/questions/tagged/code-golf "show questions tagged 'code-golf'"), shortest wins!
### Truthy
```
[[]]
[[],[]]
[[[[]],[[],[[]]],[]],[]]
[[[[]]]]
[]
```
### Falsy
```
]
[[][]]
[,]
,
[],[]
[[[]][[]]]
[[],]
,[]
[[]
[,[]]
[][]
[[],
```
[Answer]
# JavaScript, 10 bytes
```
JSON.parse
```
Outputs via the presence or absence of an error.
[Try it online!](https://tio.run/##lY4/C4MwEMX3fIo4mUDqXJC4denQDh1twCAJtYiG5CoW8bOn8aTQtTfcn/fg9@6pJx1a3zk4TMdoZTzfrpfCaR9MBBNABlkthKYC/168gZcfaJZZFni5ot5qaB/M8K9pdR9M8lbS1LVSJDWxz@0UeKYFxR9DqaYIru@A5fch54Ud/Ukn8ExlRZ3vBmDbP2zmnJdkF9LSYABihCKCYBhBIlIx/h90/AA)
[Answer]
# Python3, 70 bytes:
```
def f(s):
try:return s==str(eval(s)).replace(' ','')
except:return 0
```
[Try it online!](https://tio.run/##VY9BasMwEEXX8SkGbySBCAnZlBhdIRdIvVCSMRUYWcxMSnN6V6PgRTbS4/8nxC8v@Vny6avQuj5wgsmyO3cg9DoTypMycAgsZPE3zrVze8IyxztaA8Yb4zrAvzsW2fTDyqHv@@56HcfhqJffSCPfggot/qgajsNB32hewevplVRtVW2a/PaaoN9NC0GClGFKsyDZy5LRA@@5zEms@c7G1V276OEGAdKWD3XALjIjSZ0eHYRaZrE31xVSMIIsDEWdh3HrPw)
[Answer]
# [PARI/GP](https://pari.math.u-bordeaux.fr), 0 bytes
Takes input from `stdin`, returns truthy iff `stderr` is empty.
PARI/GP automatically parses and evals everything from the `stdin`.
[Attempt This Online!](https://ato.pxeger.com/run?1=m728ILEoMz69YMGCpaUlaboWaNSy6OjY6NhYCA8A)
[Answer]
# Haskell + [hgl](https://gitlab.com/WheatWizard/haskell-golfing-library), 26 bytes
```
f=opn*>isP f ʃ_*>cls
```
```
x1 f
```
Uses the characters `()_`.
Creates a parser object and uses `x1` to determine if some input matches the parser.
# 25 bytes
```
f('(':')':>x)=mF f$' '|\x
```
Uses the characters `()` .
Returns `True` on valid inputs and errors on invalid ones.
This version is 1 byte shorter but I'm not sure if it's allowed by the rules. If you call the function expecting a bool, e.g.
```
f x::Bool
```
It will work. However by default ghci infers `()` as the type, which does not meet the output specifications of the challenge. So you need to call it either with a type signature or in a context in which ghc can infer it's type to be `Bool`.
# Relfections
* hgl has a `unwords` function. It could be made a pattern like in the curry answer:
```
f('(':')':>Uw x)=mF f x
```
* It's rather annoying that `wR`, the `words` function trims leading spaces. There is a 23 byte answer which would work if `wR` didn't do this.
```
f('(':')':>x)=mF f$wR x
```
* `mF` should have an infix.
* `isP` should have an infix.
* `isP` should have a flip.
[Answer]
# [APL (Dyalog Unicode)](https://www.dyalog.com/), 5 bytes
Anonymous tacit prefix function taking input as `[,]` with output by erroring/not erroring.
```
⎕JSON
```
[Try it online!](https://tio.run/##SyzI0U2pTMzJT////1HfVK9gf7//aY/aJmg86u171NX8qHfNo94th9YbP2qbCJQODnIGkiEensGa1QZWVgaPulsMH3UtftS7C4y21v5PU4@Ojo1V5wLTOnAmSFAHLAJkgMVR5aBsMAnTDVOgA6Z0IAp0omG6YmPBGmFWQRTBZGPVAQ "APL (Dyalog Unicode) – Try It Online") (wrapped in error trapping code to give 0 when erroring and 1 when not erroring)
Attempts to convert from JSON.
[Answer]
# [Python](https://www.python.org), 19 bytes (@dingledooper)
```
eval("set"+input())
```
[Attempt This Online!](https://ato.pxeger.com/run?1=TU07DsIwDN1zimAJKVbEgFhQmVlhYEJMVeVCJJRGwUXtWVi6wAU4TW5D6nZgsd_Xfn1Cz7fGD2lRN1E77byOpb-SWW-wUJpjX1BHlQGAd8v1avulZ3k38CAG63xo2SBOTlrmEO5CdJ4NnPcnQKWpqyhwMYuHI8zhIV1Mbqo87LRHaoVmIOKfMQJUEhfRorJKqkp8ycixbJj5xw8)
### Old [Python](https://www.python.org), 22 bytes
```
def f(s):eval("set"+s)
```
[Attempt This Online!](https://ato.pxeger.com/run?1=lZAxDsIwDEXFmlNYXkhoYEa5SslQtYmoqNIoCag9C0sXOAKH4TQkqSoVMbHY_v6y_eT7047h3JtpelyD3h9fjdKgqWdC3aqOolcBC89m873Z6t4BDNAaQMSylJLEwOecJM8yFrm5MlIh48zB264NFE8GmSg1HQ5O2a6qFd2hZMhWsqRfkhfImKxMA9a1Jq7oL8gISUQLUKbJN7kknGQyks9nhMwajV8QAgDBjeJvnjSohlrZINZU87-Wp34A)
This takes a string composed of the characters "(+)" and signals by erroring/not erroring.
#### How?
Why can't we just use `eval`?
1. trailing commas
2. missing outer brackets
Both will be tolerated by `eval`.
To address 1 we replace `,` with `+`.
To address 2 we switch from `[]` to `()` and prepend `set`.
### Old [Python](https://www.python.org), 28 bytes
```
def f(s):eval(s+","+s[1:-1])
```
[Attempt This Online!](https://ato.pxeger.com/run?1=bZBBDoMgEEX3nGIyK6ho4q7hKpSFUUhNDRKkjZ6lGzftKXqRXqMnKGJMTNoNzJ_5M2_g_nRTOPd2nh_XYPLjq9EGDB2Y0Leqo0OGHLNBliIvFVst74_pPcAIrQVElFIpEg--3ovkScYgJXeFJVCxpxhc1waKJ4tMSEPHwmvXVbWmB-QZMqYq24DzrY2m_oKMkIW5IRMvTeWKcJLYJAESJG0TC78oAgDBT2Kd_IfLFocea-2C2OPXl2-f9AU)
This takes a string composed of the characters "[+]" (note that we have cheekily but legally replaced "," with "+") and signals by erroring/not erroring.
I'm not 100% sure this is correct but it works on all test cases.
[Answer]
# [Stax](https://github.com/tomtheisen/stax), ~~22~~ 23 [bytes](https://github.com/tomtheisen/stax/blob/master/docs/packed.md#packed-stax)
```
Ç╥╫ÜΦªt┌¢♣☺¢+╬ï▼6◘-6¡Zq
```
[Run and debug it](https://staxlang.xyz/#p=80d2d79ae8a674da9b05019b2bce8b1f36082d36ad5a71&i=%5B%5B%5D%5D%0A%5B%5B%5D,%5B%5D%5D%0A%5B%5B%5B%5B%5D%5D,%5B%5B%5D,%5B%5B%5D%5D%5D,%5B%5D%5D,%5B%5D%5D%0A%5B%5B%5B%5B%5D%5D%5D%5D%0A%5B%5D%0A%5D%0A%5B%5B%5D%5B%5D%5D%0A%5B,%5D%0A,%0A%5B%5D,%5B%5D%0A%5B%5B%5B%5D%5D%5B%5B%5D%5D%5D%0A%5B%5B%5D,%5D%0A,%5B%5D%0A%5B,%5B%5D%5D&a=1&m=2)
### Approach
* Repeatedly
+ Replace `"[[]]"` with `"[]"`
+ ~~Replace `",[]]"` with `"]"`~~
+ Replace `"[[],["` with `"[["`
* Is result equal to `"[]"`?
[Answer]
# [Curry (PAKCS)](https://www.informatik.uni-kiel.de/%7Epakcs/), 29 bytes
```
f('[':unwords a++"]")=all f a
```
[Try it online!](https://tio.run/##Sy4tKqrULUjMTi7@/z9NQz1a3ao0rzy/KKVYIVFbWylWSdM2MSdHIU0h8X9uYmaegi2QqRQNBLGxCkAChEEsCFb6DwA "Curry (PAKCS) – Try It Online")
Uses a space instead of `,`. Returns `True` for truth, and nothing otherwise.
---
# [Curry (PAKCS)](https://www.informatik.uni-kiel.de/%7Epakcs/), 53 bytes
```
f('[':a++"]")=g a
f"[]"=1
g(a++',':b)=f a*g b
g a=f a
```
[Try it online!](https://tio.run/##Sy4tKqrULUjMTi7@/z9NQz1a3SpRW1spVknTNl0hkStNKTpWydaQK10DKKquo26VpGmbppCola6QxAWUB7H/5yZm5inYKqQpKEUDQWysDpAAYRALgpX@AwA "Curry (PAKCS) – Try It Online")
Returns `1` for truth, and nothing otherwise.
[Answer]
# [Whython](https://github.com/pxeger/whython), 36 bytes
```
lambda s:eval(s)>=[]!=",]"not in s?0
```
Returns `True` for valid lists, `False` or `0` for invalid lists. [Attempt This Online!](https://ato.pxeger.com/run?1=XZBNCsIwEIX3OcUYXDQQwaUUogepWVSb0kJNJBl_ehY3BRHP5Gm0SdsUXM1778v8kMf7VrVYGd09S7F_XbBcbT7LJj8dihxcqq55kzi2FZlcCMol1Qah1uB26_HtF5VDBwIyAjSTlPuSySj4rH3MQ9SLAP7gaGJvpHyofJov-eAnF_f2HWFQ3O6VJKWx4O_0p4d7UwJnW2tMvOOgdCEoUEYAbduzEZYBsz5W96M640xooqw1llE2fEPXDfUH)
### Explanation
```
lambda s:eval(s)>=[]!=",]"not in s?0
lambda s: # Anonymous function that takes s, a string
eval(s) # Python eval
>=[] # True if the result is a list, error if tuple
!= # Keep the comparison chain going
",]"not in s # Check that there are no extra commas
?0 # If anything raised an error, return 0
```
[Answer]
# [Yacc](https://en.wikipedia.org/wiki/Yacc), 22 bytes
```
s:'['b']'b:l|l:s|s','l
```
[Try it online!](https://tio.run/##LY2xCsIwFEX3fMUDCWmlxr2Wbrr6ASVDkoY2EBrIexWD9dtjFYcDl3OHYzTOxWqCrhPX@01AHzySzIwj6USAjPOCrRiEEUqYNmyhxQ1FI0LhnB38YsM6OuiQRh/l3LNH9CPk7FKKqbKzTnCsL8wvtMvgnlX9So7WtMDk6HtX9eXN9jTL2lr416d9ZknaSAunkJk8axlXKsOgmh9KfQA) (note: Yacc is installed on TIO, but doesn't have a TIO wrapper, so I had to write one myself; I also wrapped the function into a full program. The wrapper outputs by exit code.)
Function submission. (I originally forgot PPCG allowed functions to be sumbitted, so the first version of this was a full program with a lot of boilerplate. Submitting it as a function obviously makes more sense.)
This is a function/parser named `s` that reads input from `yacc`'s usual input source. It does the `yacc` equivalent of throwing an exception if the input is not a list, or returns normally if the input is a list. (It doesn't explicitly return a value – Yacc uses "implicit int" like in C, so these parsers are technically returning integers, but we don't set the return value to anything in particular.)
This function uses `[`, `]`, `,` as suggested by the question, but could easily be adapted to use any three characters (although some choices would make the program longer due to needing to be escaped).
## Explanation
Yacc is a language for writing parsers; you provide a description of syntactically legal input and it generates a parser for you. This program contains three parsers, `s`, `b` and `l`:
```
s:'['b']'b:l|l:s|s','l
s: An "s" is
'[' an opening square bracket
b then a "b"
']' then a closing square bracket;
b: A "b" is
l| either an "l", or {an empty string};
l: An "l" is
| either
s an "s"
| or
s an "s"
',' followed by a comma
l followed by another "l"
```
A direct translation of the question to Yacc would be `s:'['']'|'['l']'l:s|s','l`, but factoring out the brackets from the two branches of `s` into a separate rule `b` allows the program to be a byte shorter.
Yacc programs don't normally look this condensed; they're normally written with more whitespace, and semicolons between rules. However, the semicolons are optional, and whitespace is optional except between two identifiers (and I arranged this program so that it never had two identifiers in a row, allowing all the whitespace to be golfed off). A weird side effect of this flexibility is that Yacc's syntax is very hard to parse due to false positives (e.g. `b:l|l` is a valid rule, but `b:l|l:` has to be parsed as `b:l|; l:` despite that), and in fact, it isn't sufficiently powerful to write a parser for its own syntax (it's powerful, but its syntax is weird enough that it needs even more power to parse). It's helpful in golfing, though!
[Answer]
# Regex (Perl / PCRE), 21 bytes
```
^(<(((?1),)*(?1))?>)$
```
Uses the characters `<>,`. (Avoids `[]` as they would require being `\`-escaped.)
[Try it online!](https://tio.run/##VY0/a8MwEMV3fYojFpFUVBwPXSxZJpB27JSxVDhBAYPqpJIzFON@dfek0JIu9@e93727uOCflo8voEHB5M/HzgMtFa6N3m33WzOT0zlw2jcbpY3CXokJ@hMqYrqEfhhh9Tas1AzUQwPxeogj4lY@VrIS7jOZ0N7pG3QE1ECtIoBBwPFwvf4jPBKVGBwr2O8DnpDmG0oayl60bB@urgZgNXvpfMSRCTVj2I2mXsFs7fPrztrlnWvOeVsJKR5SE60RdFkKSBkwujjCsYsuEqK1ManIW0@rzCsOWbwz0mAIKSD//xeTMzIpDZEk55F8lA/zBzSymCAUfwA "Perl 5 – Try It Online") - Perl
[Try it on regex101](https://regex101.com/r/M0oflp/1) - PCRE1
[Try it online!](https://tio.run/##XZFRb5swEMff@RRXBxW7cpMQdZsSB3jY6BSpSipa7WXpLIpMQQOCbKd7mPrZs7P70LUP2Of//e93ZzM242mdjc0IoYYEyIzAFEatnqRWY1dWikaz6UUmZVN2VlaHfmw7pfd0z8S@mJmIQ4RfjaJ8Us4wWDVYQ6W83tzkUjIOMUMkmR1bIoL6j26tonf33/Ki4OT2a5Ev4Jkw8T6BGGPLwdLIOeSPvLjb7LYR@@gj@wFrg3ZopVGWkrHSavpYVr@txkV2bd9awoFcLZZXy89fFstPzl4fNA3bZC7CLqlxauNwmy0T7C@0NQ27n8bqTg0Yscv4IUl8GzSb4yNmUOZzfhkz4d0tU1VzcBYBSI1FAKgDfWOcnyNy/nCWRJMIW4R94h@4L23V0FBztAhwkNeH70pjpdIap2RnyW2Rf5fbncTr7oqM5E5fAVnRsM/IvT6qFeCJXJedwRCvBy84gKeRsCPi5cOvo0ycftE1pTSLGWcXbmNZysLTaQKOB1YZC1VplAmC9TpN3cJfd3fk/oiBF/9LuCANggn4Wd5hPMM7eRrwwPMCX@QLfQdMeNGZUPwH "PHP – Try It Online") - PCRE2 v10.33
Like the regex in the Raku answer, this uses recursion. Unlike Raku, standard regex has no concept of "separator" characters, so there's no concise way of implementing a comma-separated list, and the recursive call `(?1)` needs to be in two places.
There are many alternatives of the same length:
### Regex (Perl / PCRE), 21 bytes
```
^(<((?1)(,(?2))?)?>)$
```
Also uses the characters `<>,`.
[Try it online!](https://tio.run/##VY3NasMwEITveoolFpEEKo4LvVi2RCDtsaccS4UTFDCoTio5h2LcV3dXCi3pZX9mvp29uOCflo8voEHB5M/HzgMtFa5ts9vut3omp3PgtG83qtEKeyUm6E@oiOkS@mGE1duwUjNQDy3E6yGOiFv5UMlKuM9kgrnTN@gIqIFaRQCDgOPhev1HeCQqMThWsN8HPCHtN5Q0lL0wbB@urgZgNXvpfMSRCTVj2I2mXsFs7fPrztrlnTecm0pwyc2jEEYYLeiyFJAyYHRxhGMXXSSkabRORd56WmVeccjinZEGTUgB@f@/mJyRSamJJDmP5KN8mD@gkcUEofgD "Perl 5 – Try It Online") - Perl
[Try it online!](https://tio.run/##XZHBbtswDIbvfgpWMWppUJM46DYkiu3D5g4BhqRwi12WTnANuRbmOIakbIehz55R6mFrD5apnz8/UtLYjed1MXYjxAYyIDMCUxiNepJGjX3dKJrMpu8KKbu6d7I5HkbdK7Oneyb21cwmHBL8WhTlk/KGwanBWSrlzeZrKSXjkDJEktlJExG1v412it7dfy6ripPbT1W5gF@EidcJxFhXD44m3iG/ldXdZrdN2Fsf2Q9YG@lBS6scJWNj1PSxbn46g4vs9UE7woFcL5bXyw8fF8v33t4eDY11Nhdxn7U4tfW4zZYJ9gd0S@P@u3WmVwNG7Cp9yLLQBs329IgZlPmcX6VMBLdmqumO3iIAqamIAHWg/xiXl4icP1xkySTBFvEhCxd8qF3T0dhwtAjwkJeL72vrpDIGp2QX2W1VfpHbncTj7qqClF5fAVnR@FCQe3NSK8Adual7iyEeD55xgEAjcU/E85uno0ycf9A1pUXKKKfFgrGCFTmLz@cJeB44ZR00tVU2itbrPPcLf/n7LQ9bDIL4X8IHeRRNIMzyChMYwcnziEeBF4WiUBg6YCKI3oTiXw "PHP – Try It Online") - PCRE
Uses `(?2)` recursion instead of `*` repetition for the comma-separated list.
### Regex (Perl / PCRE), 21 bytes
```
^(a((?1),)*(?1)?\Bz)$
```
Uses the characters `az,` in order to take advantage of the `\B` non-word-boundary assertion.
[Try it online!](https://tio.run/##VY0/b8IwEMV3f4oTsbCNXIUMLDEhoqIdOzGiWi4yUiQ3gB2GJkq/eno2akWX@/Pe795drHer6fMLqFcwuPPROKC5wrVa77b77WYkp7PntKmWar1R2AsxQHNCRQwX37QdzA7tTI1AHVQQbh@hQ1zLp0IWwl6jCfWDvkRHQAlUKwIYBBwP5/M/wiFRiNayjP0@4BGpviGnPm9Ezfb@ZksAVrJX4wKOTKgRw@40dQpGrV/edlpP79xwXhdCikVs9eG5F3SaMogZ0NnQwdEEGwgxpu9jkfceV5lWHJL4YMShJySD9P9fTMpIpOyJJCmPpKN0mD6gkcQIofgD "Perl 5 – Try It Online") - Perl
[Try it online!](https://tio.run/##XZFva9swEMbf@1NcFVNLRc0/uo1EM4Zt7giMpLhlb5ZOqEZuxGzHSEoHGf3s2Ul9sbUvLJ2ee@53J3nYDaePxbAbILWQA5kQGMNg9aO0emhVrWk2GV8UUu5U62W97wbTarulWya21cRlHDL8GhTlow6G3uveOyrl9epbKSXjMGOIJJODISJpflvjNb29@1JWFSc3n6tyDk@EidcJxDivek@z4JDfy@p2tVln7K2PbHusTUxvpNOekqG2evyg6l/e4iJb0xlPOJCr@eJq8f7DfPEu2Ju9panJpyJt8wandgG3WjPB/oBpaNr@cN62useIXc7u8zy2QbM7PGAGZT7llzMmotswXe/2wSIAqTORAOpA/zHOzxE5vT/Ls1GGLdIujw/cKV/vaGo5WgQEyMvDt8p5qa3FKdlZflOVX@V6I/G6m6ogZdCXQJY07QpyZw96CXgi16p1GOL14BkHiDSStkQ8v/l1lInTT6ooLWaMs4uwFdtPR5aeTiMIPPDaeaiV0y5JlDoew8Jf9nDk8YhBFP9LhOCYJCOIs7zCREZ08mPCk8hLYlEsjB0wEcVgQvEv "PHP – Try It Online") - PCRE
Without the use of `\B`, there would be nothing stopping a comma-separated list ending in a comma from being accepted, as the `(?1)?` is optional independently of whether or not `((?1),)*` matched anything.
The `\B` prevents this; if any list ended with a comma, the sequence `,z` would be part of it, so all we need to do is prohibit this sequence. `\Bz` accomplishes this, as `a` and `z` are word-characters but `,` is not, thus there is no word boundary in the middle of `az` or `zz` but there is one in `,z`.
### Regex (Perl / PCRE), 21 bytes
```
^(a\B(?1)?(,(?1))*z)$
```
Also uses the characters `az,`. Mirror version of the above.
[Try it online!](https://tio.run/##VY0/b8IwEMV3f4oTsbCNXIUMLDEhoqIdOzGiWi4yUiQ3gB2GJkq/eno2akWX@/Pe795drHer6fMLqFcwuPPROKC5wrVa77b77WYkp7PntKmWar1R2AsxQHNCRQwX37QdzA7tTI1AHVQQbh@hQ1zLp0IWwl6jCfWDvkRHQAlUKwIYBBwP5/M/wiFRiNayjP0@4BGpviGnPm9Ezfb@ZksAVrJX4wKOTKgRw@40dQpGrV/edlpP79wcnnldiJrL2MSiF3SaMogZ0NnQwdEEGwgxpu9jkfceV5lWHJL4YMShJySD9P9fTMpIpOyJJCmPpKN0mD6gkcQIofgD "Perl 5 – Try It Online") - Perl
[Try it online!](https://tio.run/##XZFva9swEMbf@1NcFVNLRc0/uo1EM4Zt7giMpLhlb5ZOqEZuxGzHSEoHGf3s2Ul9sbUvLJ2ee@53J3nYDaePxbAbILWQA5kQGMNg9aO0emhVrWk2GV8UUu5U62W97wbTarulWya21cRlHDL8GhTlow6G3uveOyrl9epbKSXjMGOIJJODISJpflvjNb29@1JWFSc3n6tyDk@EidcJxDivek@z4JDfy@p2tVln7K2PbHusTUxvpNOekqG2evyg6l/e4iJb0xlPOJCr@eJq8f7DfPEu2Ju9panJpyJt8wandgG3WjPB/oBpaNr@cN62useIXc7u8zy2QbM7PGAGZT7llzMmotswXe/2wSIAqTORAOpA/zHOzxE5vT/Ls1GGLdIujw/cKV/vaGo5WgQEyMvDt8p5qa3FKdlZflOVX@V6I/G6m6ogZdCXQJY07QpyZw96CXgi16p1GOL14BkHiDSStkQ8v/l1lInTT6q2n2gxYwXlYWMXR5aeTiMIPPDaeaiV0y5JlDoew8Jf9nDk8YhBFP9LhOCYJCOIs7zCREZ08mPCk8hLYlEsjB0wEcVgQvEv "PHP – Try It Online") - PCRE
### Regex (Perl / PCRE), 21 bytes
```
^(<(\B(?1)|\b,\B)*z)$
```
[Try it online!](https://tio.run/##VY0/b8IwEMV3f4oTsbBduQoZusQJEYh27MQY1QrISJHcQO0wNGn61dOzUSu63J/3fvfuYpx9mt8/gToFoz0fGws0VbiWxW6z36wncjo7TttypYq1wp6JEdoTKmK8uLbrYVF3CzUBtVCCvx58j7iWj5nMhPkIJlR3@godATlQrQhgEHA8XC7/CItEJjrDEvb7gAek/IaUurQVFdu7q8kBWM5eGutxZEJNGHajqVUwaf38utN6fuMFr7e8ysRXfZD1VjwMgs5zAiEDeuN7ODbeeEKKYhhCkbceVhlXHKJ4Z4RhICSB@P9fTMyIpByIJDGPxKN4GD@gEcUAofgD "Perl 5 – Try It Online") - Perl
[Try it online!](https://tio.run/##XZFva9swEMbf@1NcFVNLRc0/uo1EMYZu7giUpLhlb@ZOOEZpxGzHSMoGWfvZs5P6YmtfWD4999zvTlK/60@LrN/1EBtIgYwIDKE36kka1TdVrWgyGl5kUu6qxsl63/a6UaakJRNlMbIJhwS/LYrySXlD51TnLJXyZnmbS8k4TBgiyeigiYi2v412it4/fMmLgpO7z0U@hV@EibcJxFhXdY4m3iG/5cX9cr1K2HsfKTusjXSnpVWOkr42arip6p/O4CIb3WpHOJCr6exq9vHTdPbB27d7Q2OdjkXcpFuc2nrccsUE@wN6S@Pmu3WmUR1G7HLymKahDZrtYYMZlPmYX06YCG7NVL3be4sApE5EBKgD/cc4P0fk@PEsTQYJtojbNFxwW7l6R2PD0SLAQ14vvqmsk8oYnJKdpXdF/lWu1hKPuy4yknt9DmRO4zYjD@ag5oA7clM1FkM8HrzgAIFG4oaIl3dPR5k4/aALWl7TbMKeyw0vr9nFkcWn0wA8D5yyDurKKhtFi8Xx6Bf@@vdbHrYYBPG/hA@OUTSAMMsbTGAEJz9GPAq8KBSFwtABE0H0JhT/Ag "PHP – Try It Online") - PCRE
Uses the characters `<z,` in order to take advantage of the `\b` and `\B` word- and non-word-boundary assertions.
### Regex (Perl / PCRE), 21 bytes
```
^(a((?1)\B|\B,\b)*>)$
```
Uses the characters `a>,`. Mirror version of the above.
[Try it online!](https://tio.run/##VY0/b8IwEMV3f4oTsbBduQoZusTEEYh27MQY1QrISJHcQO0wVGn61dOzUSu63J/3fvfuYr17mt8/gXoFozsfWwc0V7hW691mv9ETOZ09p121UmutsBdihO6EihgvvusHWDT9Qk1AHVQQrocwIG7kYyELYT@iCfWdvkJHQAnUKAIYBBwPl8s/wiFRiN6yjP0@4BGpviGnPu9Ezfb@aksAVrKX1gUcmVATht1o6hRMxjy/7oyZ33jLeV2IZvvVbGVzEA9a0HnOIGbAYMMAxzbYQEjbah2LvPW4yrTikMQ7Iw6akAzS/38xKSORUhNJUh5JR@kwfUAjiRFC8Qc "Perl 5 – Try It Online") - Perl
[Try it online!](https://tio.run/##XZFRb9MwEMff8ylubrTYk9c21QC1Jq00lqFKqJ2yiRcyLDdylog0jWwXHmCfvZy9B9ge4pz/97/fne2hGU4fV0MzQGwgAzIhMIbB6Cdp9NCpStNkMr5YSdmozsnqsB/aTpuSlkyUxcQmHBL8ahTlk/aG3uneWSrl7fpLLiXjkDJEksmxJSKqf5nWaXr/cJMXBSd3n4p8Bj8JE68TiLFO9Y4m3iG/5sX9ertJ2FsfKXusjdq@lVY7SobK6PFOVT@cwUV27b51hAO5ms2v5u8/zObvvL0@GBq32VTEXVbj1Nbj1hsm2G9oaxp336wzne4xYpfpY5aFNmi2xx1mUOZTfpkyEdwt01Vz8BYBSE1FBKgD/cc4P0fk9PEsS0YJtoj3WbjgvXJVQ2PD0SLAQ14uvlPWSW0MTsnOsrsi/yw3W4nH3RYrknt9AWRB4/2KPJijXgDuyK3qLIZ4PHjGAQKNxB0Rz2@ejjJx@k4VpauUldd/ymte7tjFksWn0wg8D5y2DipltY0ipZZLv/CXv9/ysMUgiP8lfLCMohGEWV5hAiM4@TLiUeBFoSgUhg6YCKI3ofgX "PHP – Try It Online") - PCRE
# Regex (.NET), ~~35~~ ~~33~~ 29 bytes
```
^((a)+(?<-2>z)+(?(2),\b|$))+$
```
Uses the characters `az,` in order to take advantage of the `\b` word-boundary assertion.
[Try it online!](https://tio.run/##dY5BT8MwDIXv@RVWGqmJlqKxY8dgEhI3btzGkLLi0UihLWmnooz99pJ4QoMDl/jZfu9zunZE39fo3CT8auPxDT@3ZdngKNf59CKlUTN5d1MsbkMScqH08@5LKDUTU77W/L5976zDV66WIqzmy33r0VS1FA5sA8I23WFQRwZg91IEdRy9HbCo2344Rf81LSC6C/wAzqFoPQi3mW@pz7iClD0Buh5JAlwIUDRt/KizDQIXkkD@6tEMVY19ZKqYzp/8AUuA/IeRP5hYyzhQPKHZf0Th2GnKIOVhwLirTI89Y8aEkB59rqnV1EZBw1@LJAJjGdDRPxhikFMHphnxGIUoSBfigobJRNZwbvVFfQM "PowerShell – Try It Online")
Based on the old [**35 byte** one-liner](https://codegolf.stackexchange.com/revisions/248700/2) in [Neil's Retina answer](https://codegolf.stackexchange.com/a/248700/17216).
*-1 byte by using the characters `<>,` instead of `[],`, because `[` needed to be `\`-escaped*
*-1 byte by using an illegal character, instead of `$.`, as the impossible condition to assert Group 2 being empty at the end*
*-4 bytes by using the characters `az,` instead of `<>,`, obviating the need for explicitly asserting Group 2 is empty at the end*
```
^ # Assert that we're at the beginning of the string.
(
(a)+ # Capture at least one "a" on the Group 2 stack.
(?<-2>z)+ # Match at least one "z", popping an entry from the Group 2
# stack for each one we match.
(?(2),\b|$) # If the Group 2 stack is non-empty, match a "," followed by a
# word boundary (since "," is a non-word character, this means
# it must be followed by a word character, i.e. [0-9A-Za-z_]),
# else assert that we're at the end of the string.
)+ # Loop the above at least 1 time.
$ # Assert that we're at the end of the string. The Group 2
# conditional at the end of the above loop guarantees that the
# only way to end the loop at the end of the string is for
# Group 2 to be empty, due to the "\b" in its non-empty
# clause. So there's no need to explicitly assert here
# something like "(?(2)$.)" (which would assert something
# impossible in the case that Group 2 is non-empty).
```
Note that if the `<>,` characters are still used, it can be **32 bytes**:
```
^((<)+(?<-2>>)+(?(2),(?!$)|$))+$
```
[Try it online!](https://tio.run/##dY5BT8MwDIXv@RUmjdRES9HYseuySUjcuHGbhlQVj0YKbUk7FW3st5fEExo7cImf7fc@p2tH9H2Nzk3Cr7Ye3/Frl@cNjnKTTq9SFmom10W2MCYKuVBaru@E@hZKzcSUbjR/bD866/CNq6U4rubLfeuxrGopHNgGhG26w6BODMDupTiq0@jtgFnd9sM5@B9oAcGd4SdwDlnrQbjtfEd9whXE7BnQ9UgS4EqArGnDX51tELiQBPL3z@VQ1dgHpgrp9MUfMAdIfxnpUxlqHgaKRzT7jygcO08JxDwMGHZV2WPPWFEYEx99qbHV1AZBwz@LKAxjCdDRGwwxyKkN04x4jEIUpAthQcNoIqu5tPqqfgA "PowerShell – Try It Online")
### \$\large\textit{Anonymous functions}\$
# [Perl](https://www.perl.org/), 33 bytes
```
sub{pop=~/^(<(((?1),)*(?1))?>)$/}
```
[Try it online!](https://tio.run/##VU49b4MwEN39K05gBbtylDB0wWCWqEOHdmjHqhGNTIoEhNpGVYToX6dnI1Xp4nv3vs6DNu39MloN1pnm5CR4/F2ZvunPdt0eX56fVnSoXJVlh7EbtJHQXYHWxWLHj2m4DMXP7p3ljLEy5YLf@cFLxeluXmR9May70qbYy1xJnCmfoKkZbfg0mKZ3EL31kZxDZQsFYCf@h9Gj2KYi5frL61De8HtUOGRAj5IAdgFrdX92nxjfbP58LfpS3uskTvhEj0UUyfUeo/VWoc7L5NWMOgNIsuShai3ChMsZO1cjbSXMSwzeBU5bB6fKaktInivlH7FOv4qwIgjkjeCBIiSGcOFfTegITqGIIKGPhFAIhgsoBNKbkPwF "Perl 5 – Try It Online")
# [R](https://www.r-project.org/), ~~49~~ ~~48~~ ~~44~~ 39 bytes
```
\(L)grepl('^(<(((?1),)*(?1))?>)$',L,,1)
```
[Attempt This Online!](https://ato.pxeger.com/run?1=VY49TsQwEIV7n2LYoPUMMhLp0OZnO6qUSDQrpJC1F0uRN_IkTRBH4AQ0CxJX4C57G2yHAhqP58333sz7hz99muprGs317VnusKGD10OP8hFLRNzmpOgqFtrWdClVo1ROv_g3VzcFzJWxvcYVj3vrVlQIc_TYgHXA0zB4zfzQemfdgdHrdt9YpxlnInoRANYgU9eOKHdOUsFVXiyq657bEEOwXoecJx5Do_Kw-6KSmSSIHmt0zxpNwJS895PeAEgl79qgbkASxawINlS8iq4_BnimYrn-dH7LIJpg1DwGjDULUZZ1HR-11Niq1IZPEv8M4qcWIoO08F9MykikqoUSKU8kUzKmDWGQxAgFcbnqBw)
*-1 byte thanks to Giuseppe*
*-4 bytes by using `grepl()` instead of `sum(grep())` or `any(grep())`*
*-5 bytes by using a new anonymous function syntax introduced in R v4.1.0*
# [PowerShell](https://github.com/TryItOnline/TioSetup/wiki/Powershell), ~~46~~ 42 bytes
```
$args-match'^((a)+(?<-2>z)+(?(2),\b|$))+$'
```
[Try it online!](https://tio.run/##dU3LTsMwELz7K1bJitiqLZUeWwo3voAbD8lUmyaSSYqdKpJDvj3YW6HCgcvuzM5jT/1IPjTk3IL1flrQ@mMwH3Y4NNWblFat5MOd2dzHDORG6Zf3L1RqhdUy7zDu17u692QPjUQHbQfYdqfzoCYB0NYSo5pG3w5kmj4Mc/LfsgDJbegTigJM7wHd8/qVeVkoyNkZyAViCHBtANP1HY2u7QgKlLnoBuuUT6nqyZ9pC1D9ZKtHm/Y2HVSRK8V/TejEvJSQ8zBQ0g42UBDC2hjz0JedqWaaAB9/CRlEIUrgp39quIOdOgotuE9wiIP8IQl8zCa2xgvVV/QN "PowerShell – Try It Online")
[Answer]
# [Vyxal](https://github.com/Vyxal/Vyxal) `P`, 8 bytes
```
øBEÞfSȧ=
```
[Try it Online!](https://vyxal.pythonanywhere.com/#WyJhUOG5oCIsIsabIiwiw7hCRcOeZlPIpz0iLCJuJFwiYCUgLT4gJWAkJTtcXFxuaiIsIltbXV1cbltbXSxbXV1cbltbW1tdXSxbW10sW1tdXV0sW11dLFtdXVxuW1tbW11dXV1cbltdXG5dXG5bW11bXV1cblssXVxuLFxuW10sW11cbltbW11dW1tdXV1cbltbXSxdXG4sW10iXQ==)
Still shorter than JavaScript! The link is a test suite, hence the additional flags - those are just to wrap all inputs into a list (`a`) and to treat all inputs as strings (`S with updot` - it's the equivalent of wrapping every input in quotation marks).
## Explained
```
øBEÞfSȧ=
øBE # wrap the input in square brackets and try to evaluate it as a python literal
Þf # attempt to flatten the list by a level - if the input was listlike (that is, valid for this challenge or valid as a python tuple), this will undo the `øB`. Otherwise it leaves the string as is
S # convert the result of the above to string. The P flag makes it so that square brackets and commas are used for lists instead of the angular brackets and pipes Vyxal uses.
ȧ= # remove any whitespace and test to see if this new string is equal to the original input.
```
[Answer]
# [R](https://www.r-project.org), 101 bytes
```
\(x,y='',s=\(p,b,x)sub(p,b,x,,,T)){while(y!=(y=x)){x=s('[[],[]','[[]',y);x=s('[[]]','[]',x)};y=='[]'}
```
[Attempt This Online!](https://ato.pxeger.com/run?1=VZA9DsIwDIX3nKJMSZDZkSrfgq1EqEWpQOpQNalIhHoSljIwcqDehvwCXeKXz3nPch7PYV7eehjlSUulVYHFmdGqEoIC8RW-0kMIxInA172kBeWEtHWnVok5LjsgFIgOl5NihAhJeXZ8lLsxGV-jbnf7RR6ZAYuUgsIj66EBw9XYRAUAB87vt8u1k8xukFk07m5QsbSUm-0TwfIy08DcYfhUWkSvpzRsq-q-7yz7fRS0nCT4t6yj0THPsX4A)
Text replacement solution,
'[[],[]' -> '[[]'
'[[]]' -> '[]'
Earlier attempts at this were using far too many `\\` to escape `[`/`]`.
[Answer]
# [Wolfram Language (Mathematica)](https://www.wolfram.com/wolframscript/), 31 bytes
```
{Times=N}~Block~ToExpression@#&
```
[Try it online!](https://tio.run/##VY3NCsIwEITveYwUelqfQCpF0aMo9lZ6CGFLQ38iTQpC2Lx6tKkRvOwMM/Oxo7AdjsIqKUJbBFepEU1xJX8ctOx9pc@v54zGKD2VWR7ui0Jb3mY12TrbHU4dyr5uy2xfzQvCRQwGmyb3Dykm7xh3johDVPjZNYSYfEzM/7uvXy/jCU8LiALbAlzCiCKZfm2j1BJnxMIb "Wolfram Language (Mathematica) – Try It Online")
Uses `{,}`. Returns by presence/absence of an error.
Missing arguments are interpreted as `Null`, but will raise an error message.
Juxtaposition is a valid operation (`Times`), so we use `Block` to turn it into `N`. Since `N` only handles one or two arguments, it errors when passed three or more arguments. When `N` has exactly two arguments, the second argument must be of the form `precision` or `{precision,accuracy}`, where `precision` and `accuracy` are numbers. Input is guaranteed to never have numbers, so the 2-argument form is also guaranteed to error.
[Answer]
# [Retina 0.8.2](https://github.com/m-ender/retina/wiki/The-Language/a950ad7d925ec9316e3e2fb2cf5d49fd15d23e3d), ~~39~~ ~~35~~ 23 bytes
```
<<>>
<>
}`<<>,<
<<
^<>$
```
[Try it online!](https://tio.run/##TYw7DoBACET7OYcmW3CECaewI5i1sLCxMLaeHVlsbODNB679Ps4t5taWbt6pQaqCiqcnCUFipU4RZu7IId8eUkomlPkLBjiqXqY4BHWKyqtTzzIwfwE "Retina 0.8.2 – Try It Online") Takes `<,>` characters but link is to test suite that converts from `[]` for convenience. Explanation: Port of @recursive's Stax solution.
```
<<>>
<>
```
Remove an empty list that's the only element of a list.
```
<<>,<
<<
```
Remove an empty list that's the first element of a list.
```
}`
```
Repeat until there are no more elements to remove.
```
^<>$
```
Check that we finished with an empty list.
Escaping means that it takes 29 bytes to use `[,]` characters:
```
\[\[]]
[]
}`\[\[],\[
[[
^\[]$
```
[Try it online!](https://tio.run/##TYwhEoBADAN93gEzJ/oPHpGWOQQCg2CwvL2UnEE1yaa59vs4t5xbW3o6nRFg4OnS5gSJteSUScFKx/2syZZQ@ANjRnWFFjDoFeLqaKwA4wU "Retina 0.8.2 – Try It Online") Link includes test cases.
Previous 35-byte one-liner:
```
^((\[)+(?<-2>])+(?(2),|$))+(?(2)$.)
```
[Try it online!](https://tio.run/##K0otycxL/K@q4Z7wP05DIyZaU1vD3kbXyC4WxNAw0tSpUdGEMlX0NP//j46OjeUCEjoQGsTVAXOBDLAgkgSIEcsFVg4W1Inl0uECa@UCy4PVgA0DSkTHAgA "Retina 0.8.2 – Try It Online") Link includes test cases. Explanation:
```
^(
```
Start matching at the beginning of the string.
```
(\[)+
```
Count the number of `[`s.
```
(?<-2>])+
```
Count some `]`s, but no more than the number of `[`s so far.
```
(?(2),|$)
```
After each run of `[`s and `]`s, if there are still unbalanced `]`s, then there must be a `,` next, otherwise we must be at the end of the string.
```
)+
```
Repeat as many times as necessary.
```
(?(2)$.)
```
Check that there weren't more `[`s than `]`s.
[Answer]
# [Rust](https://www.rust-lang.org/) (compile-time), 43 bytes
```
macro_rules!v{([$($a:tt),*])=>($(v!{$a})*)}
```
[Try it online!](https://tio.run/##KyotLvn/PzcxuSg/vqg0J7VYsaxaI1pFQyXRqqREU0crVtPWTkNFo0yxWiWxVlNLs/Y/kBkdHasDxrFgXMtVUJqkkJankJuYmaehqVBd@x8A "Rust – Try It Online")
This is a Rust macro (the compile-time equivalent of a function) named `v!`. Use as `v!{…}`, where `…` is the string you want to check (without delimiters – string literals are opaque to the usual sort of Rust macro). I used `[`, `,`, `]` as in the question, although this could easily be adapted to use almost any Rust token in place of `,` and/or `()` rather than `[]`.
Outputs via error/non-error: an invalid list causes a compile time error, a valid list causes no error (and the macro expands to an empty declaration).
## Explanation
```
macro_rules!v{([$($a:tt),*])=>($(v!{$a})*)}
macro_rules!v{ } Macro declaration
([ ]) Match something surrounded by []
$( ) * which consists of 0 or more
$a:tt balanced token trees $a
, separated by commas
=>( ) and replace it with,
$( $a )* for each $a,
v!{$a} a recursive call to v!{$a}
```
We verify the structure of the outermost list, then recurse into the inner lists to make sure that those are also correct. Rust macros have a `:tt` builtin that matches brackets, which makes it easy to use the strategy of parsing out the elements first and recursing over them afterwards. The base case of the recursion is that when we match a zero-length list, the replacement expands into zero macro calls, because the loop in the replacement runs for zero iterations.
Note that Rust normally allows a trailing comma on lists, so we do actually have to write our own verification macro rather than using something that Rust has predefined.
[Answer]
# [Factor](https://factorcode.org/) + `json.reader`, 5 bytes
```
json>
```
[Try it online!](https://tio.run/##TY@xDgIhDIZ3nqK5mTg4auJqXFyME2EgXC@iF7gr4MUYnx2ht9zS9v/@tmkHY1Ogcr9drucDPGPwO0LTI8FEmNJnIucT2OCT89kkF3yEiHNGbzHCvMALyeMILsBRiHn5CqW0bkGuuUnJshYMN0YrtOB2hlILKXhUsM89vKwaFf5AgSrtylPpKUzQJcrYwXqlru5@xYMZ44YT2vCuP2lAYx/lDw "Factor – Try It Online")
Outputs by the presence of an error.
[Answer]
# [Rust](https://rust-lang.org), 406 bytes
```
fn a(d:&str)->bool{let c=d.chars().collect::<Vec<_>>();let c=c.as_slice();let b=c.iter().fold((0,0),|mut a,&i|{if i=='['{a.0+=1}else if i==']'{a.1+=1}a});let m=c.windows(2).any(|a|a[0]==']'&&a[1]=='[');let mut j=false;c.iter().fold(0,|a,&i|{if i=='['{a+1}else if i==']'{a-1}else if i==','&&a==0{j=true;a}else{a}});let o=c.windows(3).find(|a|a[1]==','&&(a[0]!=']'||a[2]!='['));b.0==b.1&&!m&&!j&&o.is_none()}
```
[Try it online!](https://play.rust-lang.org/?version=stable&mode=debug&edition=2021&gist=3e6a38be3206b06750a387eb52281d5f)
Not a golfing language by any means, but it's worth giving it a try.
It can be golfed down a lot as it's currently using a really naïve approach.
[Answer]
# [05AB1E](https://github.com/Adriandmen/05AB1E/wiki/Commands), 10 [bytes](https://github.com/Adriandmen/05AB1E/wiki/Codepage)
```
„,]å≠i.E}˜
```
No error as truthy; error (`** (Protocol.UndefinedError) protocol Enumerable not implemented for ...`) as falsey.
[Try it online](https://tio.run/##yy9OTMpM/f//UcM8ndjDSx91LsjUc609Pef/fyUlpejoWJ1YIA0A) or [verify all test cases](https://tio.run/##yy9OTMpM/V@m5JlXUFpipaBkX6nDpeRfWgLjufx/1DBPJ/bw0kedCzL1XGtPz/lve2h9YKaSX75CalFRfpHS4dVKXK5BQf5Bikq1Ooe22f@PVoqOjo1V0gFROjAWSEgHLABkgIVRpCBMIKGgBNUJldUBkTpgSZ1oqPrYWLAWqA1gBVCpWKVYAA). (Wrap the single TIO input in `"""` quotes to get the input as string, instead of implicitly as (possibly faulty) list.)
**Explanation:**
```
i } # If
# the (implicit) input-string
≠ # does NOT
å # contain the substring
„,] # ",]":
.E # Evaluate the (implicit) input-string as Elixir
# (implicit else)
# (implicitly use the input-string)
˜ # Flatten (results in [] for lists; or an error for strings)
```
The if-statement is for edge-case `[[],]`, which unfortunately is a valid Elixir/Python list that evaluates to `[[]]`. If it wasn't for this test cases, `.E˜` would have been enough in the new version of 05AB1E: [verify all test cases](https://tio.run/##yy9OTMpM/V@m5JlXUFpipaBkX6nDpeRfWgLj/ddzPT3nv@2h9YGZSn75CqlFRflFSodXK3G5BgX5Bykq1eoc2mb/P1opOjo2VkkHROnAWCAhHbAAkAEWRpGCMIGEghJUJ1RWB0TqgCV1oqHqY2PBWqA2gBVApWKVYgE).
And it could even have been 1 [byte](https://github.com/Adriandmen/05AB1E/wiki/Codepage) in the [legacy version of 05AB1E](https://github.com/Adriandmen/05AB1E/tree/fb4a2ce2bce6660e1a680a74dd61b72c945e6c3b) using the `-e`/`--eval` flag: [verify all test cases](https://tio.run/##ZU4xDsIwENvziuPEGCgIsaAKFspIRdeqQ0ojNRJqopKCGPgJP2Bg4wEw8qhAAy1BTGeffT6nbJubNdMwhbXMeF9uWSo4@D4E4YJgsGObimmegShUpSeAM0owrPSHmMfJzG@XlaC4lMDLUpZ4PyMJoiiMOnikt@uM1Elkn4sNh5KzOopkkgCog85lMQJPKu0Nxiwdcu/9v68OP3V6dSMfuvay4AYR4zhJXoO8IXVZLVG7fAEr/clf2gAnzDHTBtHWT2MnKklsmlOkPXBsFj0B).
[Answer]
# Haskell (GHCi), 0 bytes
Takes input from `stdin`, returns truthy iff `stderr` is empty.
[Answer]
# [Raku](https://raku.org/), 31 bytes
```
{($^a~~/"["<~~>*%",""]"/)~~$^a}
```
This is a function which takes the string as input and produces typical Raku Booleans (`True` or `False`).
Let's break it down. First, better spacing
```
{ ($^a ~~ /"[" <~~> * % "," "]"/) ~~ $^a}
```
First, `$^a` is a sort of special syntax for declaring lambdas without explicitly mentioning their arguments, so this is equivalent to the single-argument function
```
-> $a { ($a ~~ /"[" <~~> * % "," "]"/) ~~ $a}
```
Now, `~~` is a terribly clever thing in Raku called the smart-match operator. At a high-level, it's going to evaluate its right-hand side and then call the `.ACCEPTS` method on the right-hand side with the left-hand side as argument. We use it twice here: The leftmost application is on a regex object and will do a regular expression match. The rightmost application is on the input string and will perform ordinary string equality.
We're going to do a regex match against that regular expression enclosed in `/`. That match will return either a special regex `Match` object, or `Nil` if the match fails. We then compare that for string equality. A `Match` object stringifies as the substring it matched, so we're simply checking whether the match that was found is in fact the *whole* string. `Nil`, on the other hand, stringifies to `""`, and as per the comments the empty string is not valid input, so `$^a` will never compare equal to that.
Now let's look at the regex itself.
```
/"[" <~~> * % "," "]"/
```
If you haven't seen Raku regexes before, it may be best to forget everything you know about regular expressions, because the syntax is only superficially similar. Anything enclosed is quotes is matched literally, so `"["`, `","`, and `"]"` are matched literally. `*` works like it does in most regex languages: It's the Kleene star and matches zero or more. `%` is a modifier on `*` which delimits multiple matches by the thing on its right (in our case, a comma). Finally, `<~~>` is the recursive matcher, which matches the entire regular expression again. So, in summary
```
/ # Start of regex
"[" # Match an opening bracket
* # Then match zero or more...
% "," # delimited by commas...
<~~> # of the current regular expression recursively
"]" # Finally, match a closing bracket
/ # End of regex
```
[Answer]
# [SNOBOL4 (CSNOBOL4)](http://www.snobol4.org/csnobol4/), 84 bytes
```
L ='[]' | ('[' *L ARBNO(',' *L) ']')
INPUT POS(0) L RPOS(0) :F(END)
OUTPUT =1
END
```
[Try it online!](https://tio.run/##K87LT8rPMfn/n9NHwVY9OlZdoUZBQz1aXUHLR8ExyMnPX0NdB8TRVFCPVdfk4vT0CwgNUQjwD9Yw0FTwUQiCsDit3DRc/VyA8v6hISAFtoZcQP7//zrRsQA "SNOBOL4 (CSNOBOL4) – Try It Online")
Prints 1 for truthy and nothing for falsey.
Recursive pattern matching is pretty slick.
[Verify all test cases](https://tio.run/##dZCxCsMgEIZn8xS3nRaHFjoFMqREaUFMMDoUcelcmqFr392atBQS7SDnfXf89989H9Ntuh9jJJ2QFy0oSmoZMlKnUEmioEEfEF5A0SPsFLTmpHuKfE4YYEBWEQtDP9I9AwXm8yO1pEZYZ3QqS2gOSfCbR0t6Zwdnk7Q1zp6vNVY/JOk8j62BD9yHnCaeCn55YWn525bjFUDZqlFsjRR8FPT5lvBsFC@slJQWY4VdM8HSRRIRuotv).
[Answer]
# Javascript, ~~79~~ ~~78~~ 77 bytes
```
f=s=>eval("r=/(<(<>,)+<>>)|(<<>>)/;r.test(s)&&f(s.replace(r,'<>'))||s=='<>'")
```
uses the characters `<,>` and returns `true`/`false`
saved 1 byte thanks to @RadvylfPrograms
saved 1 byte by using recursion and joining expressions
[Try it online!](https://tio.run/##tU@7boQwEKzjr7BOp2OtONDnbH9JCixio4ssjLy@a4BvJ3hJwaVIl2afM7OzX/ZhsUu3Mb8N8dOtXq@ojXvYAKekG1CgjBSvyhgxgyqpuaY6O8yA4nLxgHVyY7CdgyQrZSoh5hm1LuVJrDndHXLN20JlW5B7Lq2kditoeFiUwrQ1juGWofoYKnFl3gbclUiGwNIwyUiSEY@4dGRb0PC3CuvigDG4OsQeqmKOd7boYrYp052YoHzHo@dkXkzs5chqz1PZL@/8PHmCiqXdiE3zDOvhBygKsj8gl2cX9NlfNvbX/8HH@g0)
[Answer]
# [Charcoal](https://github.com/somebody1234/Charcoal), 29 bytes
```
Fθ≔⪫⪪⪫⪪θ[[]]¦[]¦[[],[¦[[θ⁼θ[]
```
[Try it online!](https://tio.run/##S85ILErOT8z5/z8tv0hBo1BTwbG4ODM9T8MrPzNPI7ggJ7MEmVmoo6AUHR0bq6QJYkCp6FidaCgLRBVqWnMFFGXmlWi4FpYm5hRDNAHValr//x8NVAQyQAesC8gAkhCsFPtftywHAA "Charcoal – Try It Online") Link is to verbose version of code. Outputs a Charcoal boolean, i.e. `-` for valid, nothing for invalid. Explanation: Boring port of @recursive's Stax answer.
```
Fθ
```
Repeat more than enough times...
```
≔⪫⪪⪫⪪θ[[]]¦[]¦[[],[¦[[θ
```
... remove the first or only element of a list if it's an empty list.
```
⁼θ[]
```
Check that we're left with an empty list.
Less boring 34 byte solution:
```
›⬤⁺,θ№,[[]],⁺ι§⁺θ,κ⊙θ∧κ⁼№…θκ[№…θκ]
```
[Try it online!](https://tio.run/##ZU67CsMwDPwVo0kB9Qs6GVNKt@zGg0kMCRFO7Txovt5VHOjSA91wd5KuG3zuZs@ltHmMKz5z8GvIqJmx5W1BICCVGlJm3sQHsta5U6vuSEqvr9iHz5VOpGRB0lMjEDMep6ZjjxOpR9o8L3hdMkfHwQzz@wxMkgULvzf/poOm4l6KBWtrC6FaR/gacOW28xc "Charcoal – Try It Online") Link is to verbose version of code. Outputs a Charcoal boolean, i.e. `-` for valid, nothing for invalid. Explanation:
```
, Literal string `,`
⁺ Concatenated with
θ Input string
⬤ All characters satisfy
,[[]], Literal string `,[[]],`
№ Contains
ι Current character
⁺ Concatenated with
θ Input string
⁺ Concatenated with
, Literal string `,`
§ Indexed by
κ Current index
› And not
θ Input string
⊙ All characters satisfy
κ Current index
∧ Logical And
№ Count of
[ Literal string `[`
…θκ In current prefix
⁼ Equals
№ Count of
] Literal string `]`
…θκ In current prefix
Implicitly print
```
Note that by default Charcoal tries to parse an input in a JSON-like format so to defeat that you need to wrap the input in JSON i.e. prepend `["` and append `"]`.
[Answer]
# C, 178 bytes
```
int v(char *s){int d=1;for(s++;*s!='\0';s++){if(d==0)return 0;if(*s=='{')d++;if(*s=='}'){d--;if(*(s+1)=='{')return 0;}if(*s==','&&!(*(s-1)=='}'&&*(s+1)=='{'))return 0;}return!d;}
```
]
|
[Question]
[
**Challenge**
Given two positive integers \$1 \le m \le 12\$ and \$1\le d \le 31\$, representing a month and days into the month, output the amount of days that have passed since January 1st, on a non-leap year. You can assume that the number of days passed will always be constrained by the number of days in the month (so \$m = 2, d = 31\$ will never be an input)
This is [code-golf](/questions/tagged/code-golf "show questions tagged 'code-golf'") so the shortest code in bytes wins.
**Examples**
For example, \$m = 2, d = 11\$ represents February 11th. This is the 42nd day of the year (31 days in January + 11 days), so the output is 42.
[Answer]
# [Haskell](https://www.haskell.org/), 27 bytes
```
m%d=div(275*m)9-30+d-mod 2m
```
[Try it online!](https://tio.run/##VY5NS8NAEIbv@RXvwUCi2dDdUEVxb0HRc2@lyNRZ6@J@lM0qFPzvMTUHI8Nc3mfm4X2n4cM4N1p/jCmjp0ztxnoz@pI1269K3awvfX0rutUVCx8Zyo@ebNAcC@CYbMi4gCwlIASeKXxSOkEumCrlDB/MPs10iaUqu5n35tX4vUnoZFH8JhszZJBzYDoNd4snCoztW4r@KWRzSOQw9YXWsPie9l5gK9u2u17vGjiTUb00vuEaGjk@JnOIyVI4e5j7SY3qn8sKWU/wnP0dq5WSmGY3/gA "Haskell – Try It Online")
This is a “closed-form” answer (in a C-like language it would be `275*m/9-30+d-2%m`).
[Answer]
# JavaScript (ES6), ~~ 40 37 ~~ 36 bytes
Expects `(day)(month)`.
```
d=>g=m=>--m?31-(4/m&2)+~m%9%2+g(m):d
```
[Try it online!](https://tio.run/##y0osSyxOLsosKNHNy09J/Z9m@z/F1i7dNtfWTlc3197YUFfDRD9XzUhTuy5X1VLVSDtdI1fTKuV/cn5ecX5Oql5OfrpGmoahJhBpcqEKGoNEjTCEDYHCQNH/AA "JavaScript (Node.js) – Try It Online")
### How?
This is a recursive function that computes the number of days in each full month (i.e. lower than \$m\$), sums them all together and finally adds \$d\$ on the last iteration.
We use `4 / m & 2` to distinguish between February and all other months:
* For January, `4 / 1 & 2` is `4 & 2`, which is \$0\$
* For February, `4 / 2 & 2` is `2 & 2`, which is \$2\$
* For \$m>2\$, `4 / m & 2` is \$0\$ because \$0<4/m<2\$
We use `~m % 9 % 2` to subtract \$1\$ for months that do not have \$31\$ days:
```
m | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11
~m | -2 | -3 | -4 | -5 | -6 | -7 | -8 | -9 | -10 | -11 | -12
mod 9 | -2 | -3 | -4 | -5 | -6 | -7 | -8 | 0 | -1 | -2 | -3
mod 2 | 0 | -1 | 0 | -1 | 0 | -1 | 0 | 0 | -1 | 0 | -1
```
(This also works for December, but we never have to compute the total number of days in this month.)
[Answer]
# [Gaia](https://github.com/splcurran/Gaia), 6 bytes
A dyadic function taking the month above the day. Gaia has a nice collection of date/time builtins.
```
(∂k<Σ+
```
[Try it online!](https://tio.run/##S0/MTPz/X@NRR1O2zbnF2v9TUw8tedTe8T/aSMHQMBYA "Gaia – Try It Online")
```
( # decrement the month
∂k # push list [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31] (builtin)
< # take the first month-1 elements from this list
Σ # sum them
+ # add the day
```
[Answer]
# JavaScript, 33 bytes
```
m=>d=>((m+9)%12*51+99)*.6%365+d|0
```
[Try it online!](https://tio.run/##BcFRCoMwDADQf0/RHyExTBaHQuniXcRacRgzVPzZdvbuvddwDce4L@/ztlmccpKs0kfpAZQ8ltxULZP3WNVd@ehait97TrY7UOGgT@EmKBG6T@HcaNth61SvNkMCRWDEUPzyHw "JavaScript (Node.js) – Try It Online")
[Answer]
# [JavaScript (Node.js)](https://nodejs.org), 35 32 bytes
```
m=>d=>--m*31+d-'003344555667'[m]
```
[Try it online!](https://tio.run/##y0osSyxOLsosKNHNy09J/Z9m@z/X1i7F1k5XN1fL2FA7RVfdwMDY2MTE1NTUzMxcPTo39n9yfl5xfk6qXk5@ukaahqEmEGlac6GKGgFFsQgbAsWNQeL/AQ "JavaScript (Node.js) – Try It Online")
Thanks to [A username](https://codegolf.stackexchange.com/users/100664/a-username) for pro golf tips!
[Answer]
# [C (gcc)](https://gcc.gnu.org/), ~~47~~ 27 bytes
```
f(d,m){m=275*m/9-30+d-2%m;}
```
[Try it online!](https://tio.run/##bZBta4NADMff91MEQfCRVp0bxbk3Y59iypB7qLKdFk@YnfjV53L2lFp2cEeS3z/JJcQ/ETJN3KKesAeRhk@xI/ZHPzq41A9NkYxTVXcgiqq27N2wAzwq0DHZfdD3HFIYgsALvCgYky0VVxoiDMIbyPozIx3TyQ@KR4@xFpCyaB18GflkLSpAaYysfwuz/viKNzY8uPUjQ2fypgVL1a9qynpMOyTafAZZ/bCGW0tne68DzhpJwHVntQ3XIZffCqykx5l5nmwwXTD9F0vEarcg7C1gCNZF3GeeW5RwyxBN3ZUoNLEALS6zBf6LepXbcOhKBhdWtGDKrMbNCBR6IL11gyxNZa57j7tx@iX8qzjJyf/@Aw "C (gcc) – Try It Online")
Uses formula from [Lynn](https://codegolf.stackexchange.com/users/3852/lynn)'s [Haskell answer](https://codegolf.stackexchange.com/a/230724/9481).
[Answer]
# [Bash](https://www.gnu.org/software/bash/), 16
```
date -d$1/1 +%-j
```
Input is given on the command-line as slash-separated integers, with month first.
[Try it online!](https://tio.run/##S0oszvj/PyWxJFVBN0XFUN9QQVtVN@v///9G@oaGAA "Bash – Try It Online")
[Answer]
## Excel formula, 18 Bytes
```
=DATE(1,A1,B1)-366
```
* Cell `A1` contains the input month.
* Cell `B1` contains the input day.
Saved 8 bytes from answer by Crissov by evaluating the offset as 366, then added 2 bytes by converting named ranges `m` and `d` into cell references.
If leap years were allowed, then it could be shortened to a single function `=DATE(0,A1,B1)`
[Answer]
# [Python 3](https://docs.python.org/3/), ~~60~~ ~~55~~ 51 bytes, 1-based month
`lambda` function that accepts the month (1-based) and the day.
*-5 bytes*: used a "31-days" default month, and the list s accounts for the cumulate (absolute) difference between the actual days of months and 31
*-4 bytes*: the list is removed from the function parameters, thanks to *@Hunaphu* and *@mic\_e*
```
lambda m,d,a=[3,0,3,2,3,2,3,3,2,3,2]:28*(m-1)+sum(a[:m-1])+d # original version
lambda m,d,s=[0,0,3,3,4,4,5,5,5,6,6,7]:31*m-31-s[m-1]+d
lambda m,d:31*m-31-[0,0,3,3,4,4,5,5,5,6,6,7][m-1]+d
```
[Try it online!](https://tio.run/##K6gsycjPM/6fZhvzPycxNyklUSFXJ8XK2FArV9fYUDfaQMdAxxgITYDQFAzNgNA8NjpX1zBWO@V/QVFmXolGmoaRjqGhpuZ/AA "Python 3 – Try It Online")
Explanation *(original version)*:
* `m,d`: input month and day
* `a[...]`: list of days to add to the "base" 28-day month, from january to novemeber, passed as optional argument
* `28*(m-1)`: the total number of days in the previous "28-days" months
* `+sum(a[:m-1])`: add the remaining days of the previous months (as difference actual days - 28)
* `+d`: add the days of the selected month
---
# [Python 3](https://docs.python.org/3/), ~~56~~ ~~50~~ 46 bytes, 0-based month
*-4 bytes (compared to 1-based month number)*: if 0-based month number is allowed as input
*-6 bytes*: used the "31-days" approach
*-4 bytes*: the list is removed from the function parameters, thanks to *@Hunaphu* and *@mic\_e*
```
lambda m,d,a=[3,0,3,2,3,2,3,3,2,3,2]:28*(m)+sum(a[:m])+d # original version
lambda m,d,s=[0,0,3,3,4,4,5,5,5,6,6,7]:31*m-s[m]+d
lambda m,d:31*m-[0,0,3,3,4,4,5,5,5,6,6,7][m]+d
```
[Answer]
# [Japt](https://github.com/ETHproductions/japt), 16 [bytes](https://en.wikipedia.org/wiki/ISO/IEC_8859-1)
Well, this ain't right :\ Normally Japt would be ruling the roost in a date based challenge but not this time, despite all the tricks I can muster. Which makes me seriously worried that, after 16 long months, I've lost my edge when it comes to golfing on me phone over a few pints down the boozer!
```
ÒÐBì)nÐUi¹z864e5
```
[Try it](https://petershaggynoble.github.io/Japt-Interpreter/?v=1.4.6&code=0tBC7Clu0FVpuXo4NjRlNQ&input=WzIsMTFd)
[Answer]
# [Factor](https://factorcode.org/), 29 bytes
```
[ 1 -rot <date> day-of-year ]
```
[Try it online!](https://tio.run/##S0tMLskv@h8a7OnnbqWQnJiTmpeSWKSQnVqUl5qjUFCUWlJSWVCUmVeiYM3FZaRgaPg/WsFQQbcov0TBJiWxJNVOISWxUjc/TbcyFagt9j/QhBwFvf8A "Factor – Try It Online")
* `1 -rot <date>` Create a timestamp from the year 1 and the two inputs. (1 is not a leap year according to Factor's calendar vocabulary.) This is the shortest way I know of to create a timestamp object from a month and day.
* `day-of-year` Factor has a builtin for this once you have a timestamp.
[Answer]
# [APL (Dyalog Unicode)](https://www.dyalog.com/), 11 bytes
Full program. Prompts for `[month,day]`
```
1⎕DT⊂1900,⎕
```
[Try it on TryAPL!](https://tryapl.org/?clear&q=%E2%88%86%E2%86%902%2011%20%E2%8B%84%201%E2%8E%95DT%E2%8A%821900%2C%E2%88%86&run) (`⎕` is stdin, but is emulated with the variable `∆` since TryAPL doesn't allow stdin)
`‚éï`‚ÄÉprompt for `[month,day]`; `[2,11]`
`1900,`‚ÄÉprepend `1900`; `[1900,2,11]`
`⊂` enclose to represent as scalar time stamp; `[[1900,2,11]]`
`1‚éïDT`‚ÄÉconvert DateTime to days since 1899-12-31; `42`
[Answer]
# [Red](http://www.red-lang.org), 36 bytes
```
func[m d][pick to now reduce[d m]11]
```
[Try it online!](https://tio.run/##BcG7CcAwDAXAPlO8FeQyY6QVqiwJTPAHYZPxlbswzceU5fI7/YzKHSq8Wn2xJ8b8EKanGiu6EEmuaGPDUUCUPw "Red – Try It Online")
[Answer]
# [Vyxal](https://github.com/Lyxal/Vyxal) `s`, 14 bytes
```
‹»HȦð9E»fẎ28+p
```
[Try it Online!](https://lyxal.pythonanywhere.com?flags=s&code=%E2%80%B9%C2%BBH%C8%A6%C3%B09E%C2%BBf%E1%BA%8E28%2Bp&inputs=6%0A19&header=&footer=) Port of [@caird's Jelly solution](https://codegolf.stackexchange.com/a/230714/80050)
```
‹»HȦð9E»fẎ28+p
»HȦð9E» Push compressed integer 303232332323
f Convert to digits
‹ Ẏ Slice [0:m-1]
28+ Add 28 to each list element
p Prepend to the day of the month
```
`s` flag: Sums the top of the stack and outputs the sum.
[Answer]
# [Jelly](https://github.com/DennisMitchell/jelly), ~~16~~ 15 bytes
```
“LɓịNH’D+28⁸;ḣS
```
[Try it online!](https://tio.run/##ASgA1/9qZWxsef//4oCcTMmT4buLTkjigJlEKzI44oG4O@G4o1P///8xOf82 "Jelly – Try It Online")
Takes \$d\$ then \$m\$ on the command line
```
“LɓịNH’D+28⁸;ḣS - Main link. Takes d on the left and m on the right
“LɓịNH’ - Compressed integer; 303232332323
D - Convert to digits; [3, 0, 3, 2, 3, 2, 3, 3, 2, 3, 2, 3]
+28 - Plus 28 to each; [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]
⁸; - Prepend d; [d, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]
·∏£ - Take the first m
S - Sum
```
[Answer]
# [Pip](https://github.com/dloscutoff/pip), 24 bytes
```
b+$+A*"
"@<Da
```
The code contains unprintable characters. Here's a hexdump:
```
00000000: 622b 242b 412a 221f 1c1f 1e1f 1e1f 1f1e b+$+A*".........
00000010: 1f1e 1f22 403c 4461 ..."@<Da
```
If you put that into `xxd -r`, save the results in a file, and then run the file as Pip code with the two inputs as command-line arguments, you can [try it here!](https://replit.com/@dloscutoff/pip) Or, here's a 25-byte version in Pip Classic: [Try it online!](https://tio.run/##K8gs@P8/SVtF21FLSV5GXg4IwYSSg42ubuL///8Njf4bGwIA "Pip – Try It Online")
### Explanation
```
a (month) and b (day) are command-line arguments
"" String containing characters with codes 31, 28, 31, 30, etc.
A* Get the ASCII code of each character
Da Decrement a
@< The first (^ that many) items of the list of charcodes
$+ Sum
b+ Add b
```
[Answer]
# [Vyxal](https://github.com/Lyxal/Vyxal), 17 bytes
```
»∇ė{»4τ28+¦0p?‹i+
```
[Try it Online!](https://lyxal.pythonanywhere.com?flags=&code=%C2%BB%E2%88%87%C4%97%7B%C2%BB4%CF%8428%2B%C2%A60p%3F%E2%80%B9i%2B&inputs=12%0A31&header=&footer=)
Works now, and -2.
[Answer]
# [Desmos](https://desmos.com/calculator), ~~90~~ ~~82~~ 59 bytes
```
f(m,d)=total([0,31,28,31,30,31,30,31,31,30,31,30][1...m])+d
```
*Saved 23 bytes 'cause I was so dumb... I've been trying to do some clever list manipulation to save bytes, but it never came to my mind to just put the list itself.*
### Very Brief Explanation:
`[0,31,28,31,30,31,30,31,31,30,31,30]`: The number of days in each month(excluding December), with an extra `0` element at the beginning.
`total( ... [1...m])+d`: Sum of the first `m` elements of the list explained above, then add `d`.
[Try It On Desmos!](https://www.desmos.com/calculator/euru1vs9z5)
[Try It On Desmos! - Prettified](https://www.desmos.com/calculator/zxsenq72of)
## Solution using [Lynn's "closed form" formula](https://codegolf.stackexchange.com/a/230724/96039), 34 bytes
```
f(m,d)=floor(275m/9)-30+d-mod(2,m)
```
[Answer]
This works on my PowerShell 5 on my computer; I can't get it working on TIO:
## PowerShell 5, 97 bytes
```
function s($m,$d){1+(New-Timespan -st (Get-Date -day 1 -mo 1) -e (Get-Date -day $d -mo $m)).Days}
```
Call as `s 2 11` for the example date (month before day-of-month).
### *Golfed by @mazzy, 82 bytes*
# [PowerShell](https://github.com/TryItOnline/TioSetup/wiki/Powershell), 82 bytes
```
param($m,$d)1+(New-Timespan -st (Date -day 1 -mo 1) -e (Date -day $d -mo $m)).Days
```
[Try it online!](https://tio.run/##TcgxCoAwDADAr2To0KAR4hucnfxAoAGFRosVSl8fwckbr1xN77przu5FbrEYbAwJeYirNtoO01rkBKoPxEUeBUrSgYHsAkYg/XdI3wdDnBbp1d1nYH4B "PowerShell – Try It Online")
*The golfing relies on an alias or implementation of command (`Date`) that does not exist in a default Windows 10 installation of PowerShell 5. The TIO PowerShell is PowerShell 6 on Linux.*
[Answer]
# [R](https://www.r-project.org/), 57 bytes
**(my own attempt)**
```
function(m,d){F[c(8:14,2:8)]=30:31;F[3]=28;sum(F[1:m],d)}
```
[Try it online!](https://tio.run/##K/qfklgZn58WX5maWGT7P600L7kkMz9PI1cnRbPaLTpZw8LK0ETHyMpCM9bW2MDK2NDaLdo41tbIwrq4NFfDLdrQKjcWqLQW2RgNIx1DQ00uZBFDIx1jQ83/AA "R – Try It Online")
An alternative [R](https://www.r-project.org/) solution to [pajonk's answer](https://codegolf.stackexchange.com/a/230743/95126), without using any date built-ins.
---
# [R](https://www.r-project.org/), 34 bytes
**(port of [Lynn's answer](https://codegolf.stackexchange.com/a/230724/95126))**
```
function(m,d)(275*m)%/%9-30+d-2%%m
```
[Try it online!](https://tio.run/##K/qfklgZn58WX5maWGT7P600L7kkMz9PI1cnRVPDyNxUK1dTVV/VUtfYQDtF10hVNRdZvYaRjqGhJheyiKGRjrGh5n8A "R – Try It Online")
[Answer]
# [K (ngn/k)](https://bitbucket.org/ngn/k), ~~25~~ 20 bytes
**Solution:**
```
{+/y,x#28+4\3390446}
```
[Try it online!](https://tio.run/##y9bNS8/7/z/Nqlpbv1KnQtlAx8hC2yTG2NjSwMTErPZ/moKeuoKGhqG1oaGmtYaRtZEFkDI0sjY21NT8DwA "K (ngn/k) – Try It Online")
**Explanation:**
*Assumes months are 0-indexed!*
Naive approach, there are likely better ones out there.
```
{+/y,x#28+4\3390446} / the solution
{ } / lambda taking implicit x, y args
4\3390446 / creates 3 0 3 2 3 2 3 3 2 3 2 from base-4
28+ / add 28 to each item (vectorised)
x# / take 'month' items from this list (January = 0)
y, / prepend 'days'
+/ / sum up
```
**Edits:**
* **-5 bytes**; using deltas against 28 instead of days-per-month
**Extra:**
* **+2 bytes** for 1-indexed month `{+/y,x#0,28+4\3390446}`
[Answer]
# [Charcoal](https://github.com/somebody1234/Charcoal), 20 bytes
```
I⁺↨E…”)“M⟧₂”⊖N⁻³¹ι¹N
```
[Try it online!](https://tio.run/##XYw7CsMwEESvIlytQAFvXKaL0qRw8BU2yoIFsiz0MeT0G7kNwzwYeIxbKbudgsiSfaxgqVRYQitwp8IwUwL7dYHtuicYxmnEnhODUQ92mTeOlT/wjKnVV9venEFrbdTsYz@Z0Ch/Tuz9c/RN5KoQ5XKEHw "Charcoal – Try It Online") Link is to verbose version of code. Explanation:
```
”)“M⟧₂” Compressed string `03010100101`
… Truncated to length
N Month as an integer
‚äñ Decremented
E Map over characters
³¹ Literal integer `31`
⁻ Subtract
ι Current value
‚Ü® ¬π Take the sum
⁺ Plus
N Day as an integer
I Cast to string
Implicitly print
```
Base 1 conversion is used in case the list is empty (i.e. January).
[Answer]
# [Perl 5](https://www.perl.org/) (`-p`), 36 bytes
```
/ /;$_=strftime"%-j",(0)x3,$',$`-1,0
```
[Try it online!](https://tio.run/##K0gtyjH9/19fQd9aJd62uKQorSQzN1VJVTdLSUfDQLPCWEdFXUclQddQx@D/f0MFQy4jBUNDLkMjBWPDf/kFJZn5ecX/dXMK/uv6BvgHe0bATQAA "Perl 5 – Try It Online")
[Answer]
# [MATL](https://github.com/lmendo/MATL), 9 bytes
```
14Liq:)hs
```
[**Try it online!**](https://tio.run/##y00syfn/39DEJ7PQSjOj@P9/Iy5DQwA "MATL – Try It Online")
### Explanation
```
14L % Push [31 28 31 30 31 30 31 31 30 31 30 31]: month lengths (predefined literal)
i % Input: month, m
q % Subtract 1
: % Inclusive range from 1 to that
) % Index into the array of month lengths: gives its first m-1 terms
h % Implicit input: day, d. Concatenate with previous array
s % Sum of array. Implicit display
```
[Answer]
# [R](https://www.r-project.org/), 40 bytes
```
function(m,d)format(ISOdate(1,m,d),"%j")
```
[Try it online!](https://tio.run/##K/qfZvs/rTQvuSQzP08jVydFMy2/KDexRMMz2D8lsSRVw1AHJKijpJqlpPk/Dcg11ORK0zDSMTTU/A8A "R – Try It Online")
Using buildins, returning as string.
---
Returning as a number (also using buildins):
### [R](https://www.r-project.org/), 44 bytes
```
function(m,d)as.POSIXlt(ISOdate(1,m,d))$yd+1
```
[Try it online!](https://tio.run/##K/qfZvs/rTQvuSQzP08jVydFM7FYL8A/2DMip0TDM9g/JbEkVcNQByShqVKZom34Pw3INdTkStMw0jE01PwPAA "R – Try It Online")
[Answer]
# [PHP](https://php.net/), 42 bytes
```
fn($m,$d)=>date(z,mktime(0,0,0,$m,$d,1))+1
```
[Try it online!](https://tio.run/##K8go@G9jX5BRwMWlkmb7Py1PQyVXRyVF09YuJbEkVaNKJze7JDM3VcNABwTBcjqGmprahv@tubhSkzPyFVTSNIx0FAwNNa3/AwA "PHP – Try It Online")
Pretty much builtin. The year parameter could be omitted, but the current year would then be used. To avoid a leap year `1` was used (it actually corresponds to 2001 according to the doc). `1` is added because the result is zero indexed.
This is satisfying, the byte count is The Answer, which is also the answer to the test case!
1 byte shorter but less satisfying:
# [PHP](https://php.net/), 41 bytes
```
fn($m,$d)=>date(z,strtotime("1-$m-$d"))+1
```
[Try it online!](https://tio.run/##BcExDoAgDADAnVcQ06GNMNQV0bcYgeCANMrk5@udVNF1lyrGQIlaboTmIFHc0jEyfu4dz@jjahkn9tA8pIloZg3G5LN2CwUXZ5kp6A8 "PHP – Try It Online")
[Answer]
# [Python 3](https://docs.python.org/3/), 41 bytes
```
lambda m,d:31*~-m-(539785049600>>3*m&7)+d
```
[Try it online!](https://tio.run/##K6gsycjPM/6fZhvzPycxNyklUSFXJ8XK2FCrTjdXV8PU2NLcwtTAxNLMwMDOzlgrV81cUzvlf0FRZl6JRpqGsY6hoabmfwA "Python 3 – Try It Online")
# [Python 3](https://docs.python.org/3/), 41 chars, 50 bytes
```
lambda m,d:d+ord('0\x00>v¬¥√∞ƒÆ≈™∆®«¶»¢…† ú'[m])/2
```
[Try it online!](https://tio.run/##AU4Asf9weXRob24z/2Y9XP9sYW1iZGEgbSxkOmQrb3JkKCcwXHgwMD52wrTDsMSuxarGqMemyKLJoMqcJ1ttXSkvMv9wcmludChmKDMsMTEpKf8 "Python 3 – Try It Online")
[Answer]
## Excel, ~~30~~ 24 bytes
* `=DATE(1,m,d)-DATE(1,1,0)` [24]
* `=DAYS(DATE(1,m,d),DATE(1,1,0))` [30]
Edit: I used the year 2001 before, because I do not trust Excel with dates before 1905.
[Answer]
# [Mathematica](https://www.wolfram.com/mathematica/), 30 bytes
```
{1}~DateDifference~{1,#,#2+1}&
```
[Try it here!](https://tio.run/##y00syUjNTSzJTE78n2b7v9qwts4lsSTVJTMtLbUoNS85ta7aUEdZR9lI27BW7X9AUWZeiUNatKGOYSwXjGOkY4jEM9YxNEHwDI10jA1j/wMA)
Returns as a quantity object:
[](https://i.stack.imgur.com/tF0Re.png)
Using the `DateDifference` builtin and the fact that `{y}` is treated as January 1st on year `y`. I thought of `{1}~DateDifference~{##}&` at first, but sadly `DateDifference` starts from 0 days instead of 1.
[Answer]
# Java, 141 bytes
```
int d(int d,int m){for(int i=1;i<m;i++){switch(i){case(2):d+=28;break;case(4):case(6):case(9):case(11):d+=30;break;default:d+=31;}}return d;}
```
]
|
[Question]
[
A ragged list is a (finite depth) list where each element is either a positive integer or a ragged list.
A ragged list is *properly tiered* if it contains either all positive integers or all properly tiered ragged lists.
For example `[1,2,3,6]` is properly tiered because it is a list of only positive integers. `[[1,2],[[1]],[[6],[[]]]]` is also properly tiered, because it has 3 elements which are all properly tiered lists themselves. Note that all the lists don't have to be the same depth.
The list `[[1,2],[[6],4]]` is *not* properly tiered because one of it's elements is a ragged list which contains a mixture of lists and positive integers.
## Task
Take a ragged list via any natural format and determine if it is a properly tiered list. You should output one of two consistent values, the first if the input is a properly tiered list and the second if it is not.
This is [code-golf](/questions/tagged/code-golf "show questions tagged 'code-golf'") so your goal is to minimize the size of your source code as measured in bytes.
## Test cases
```
[] -> Yes
[1,2,3,6] -> Yes
[[1,2],[[1]],[[6],[[]]]] -> Yes
[[]] -> Yes
[1,[2]] -> No
[[1,2],[[6],4]] -> No
[[1,[2]],[[3],4]] -> No
[1,[]] -> No
```
[Answer]
# [JavaScript (Node.js)](https://nodejs.org), 39 bytes
*-1 thanks to [@emanresuA](https://codegolf.stackexchange.com/users/100664/emanresu-a)*
Returns *false* for valid, *true* for invalid.
```
a=>/\d,\[|],\d/.test(JSON.stringify(a))
```
[Attempt This Online!](https://ato.pxeger.com/run?1=m70kLz8ldcGiNNulpSVpuhY31RNt7fRjUnRiomtidWJS9PVKUotLNLyC_f30ikuKMvPSM9MqNRI1NSHKbzH6JOfnFefnpOrl5KdrpGlExypgBZqaCvr6CpGpxVxo6g11jHSMdczQteFUD9IQqwOkYkGkGYiIBQLc6mOxugiPe6KNsGiBqPfLx-UcoENMkLThUQ4yHqjBGFkDTDkkUBcsgNAA)
Or **23 bytes** if we simply take a string as input:
```
a=>/\d,\[|],\d/.test(a)
```
[Attempt This Online!](https://ato.pxeger.com/run?1=m70kLz8ldcGiNNulpSVpuhbbE23t9GNSdGKia2J1YlL09UpSi0s0EjUhsrcYo5Lz84rzc1L1cvLTNdI0lKJjlRSwAk1NBX19hcjUYi50HYY6RjrGOmYYGnHrAGmJ1QFSsSDSDETEAoESHh2x2N2Fz1XRRtg0QXT45eN0FNA5Jsga8WkAWQHUYoyiBaYBEsQLFkBoAA)
---
# [JavaScript (Node.js)](https://nodejs.org), 41 bytes
Returns *false* for valid, *true* for invalid.
```
f=(a,q)=>a.some(b=>q-(q=!b.at)||!q&&f(b))
```
[Attempt This Online!](https://ato.pxeger.com/run?1=m70kLz8ldcGiNNulpSVpuhY3NdNsNRJ1CjVt7RL1ivNzUzWSbO0KdTUKbRWT9BJLNGtqFAvV1NI0kjQ1IRpuMfok5-cV5-ek6uXkp2ukaUTHKmAFmpoK-voKkanFXGjqDXWMdIx1zNC14VQP0hCrA6RiQaQZiIgFAtzqY7G6CI97oo2waIGo98vH5RygQ0yQtOFRDjIeqMEYWQNMOSRQFyyA0AA)
Or:
```
f=(a,q)=>a.some(b=>q-(q=!b.at)|f(q?[]:b))
```
[Attempt This Online!](https://ato.pxeger.com/run?1=m70kLz8ldcGiNNulpSVpuhY3NdNsNRJ1CjVt7RL1ivNzUzWSbO0KdTUKbRWT9BJLNGvSNArto2OtkjQ1IRpuMfok5-cV5-ek6uXkp2ukaUTHKmAFmpoK-voKkanFXGjqDXWMdIx1zNC14VQP0hCrA6RiQaQZiIgFAtzqY7G6CI97oo2waIGo98vH5RygQ0yQtOFRDjIeqMEYWQNMOSRQFyyA0AA)
[Answer]
# [Python](https://www.python.org), ~~61~~ ~~40~~ ~~39~~ ~~35~~ 32 bytes
```
f=lambda l:l*-1or[l.sort(key=f)]
```
[Attempt This Online!](https://ato.pxeger.com/run?1=bZDBSsQwEIbx2qfILa2kxd2VRRYq7EUQZBH2JCGH2k4xmG1Cksr2KXwAL73oO61PY7KxtIWdw4T55v8zmXz9qM6-yabvv1tbp3cnVOeiOLxWBRIbcZ0upKYiM1Lb-B26vE5Y0P1e3fCDchiZzkRRLTUSvAHEGw8yYyvebCLkwoKxZWGAIDgqKC1UKD9rnUhzFSeZUYLbGKP0HuFk5nFK-ChEPNRJFNq6C3f70GBaYZ2ynsiGZlHathCuiV_A4DOGYwnKXvBj0FpqfMG7kzgMVpo3Nqb4Yfv4hAnCz9v9HjM6Lpb_uxiZ7B0mJOHj-tMnZX5V96CILsiSrMh6BJ4w4g7m89on5mLss6mZLkO5k6PTeW5n1IscX824w0MR3vUH)
Errors if the list is not properly tiered, otherwise returns `[]`.
---
-1 byte from @Mukundan314
-5 bytes from @loopy walt for various cleverness
-3 bytes from @Mukundan314
[Answer]
# [BQN](https://mlochbaum.github.io/BQN/), ~~17~~ 15 bytes[SBCS](https://github.com/mlochbaum/BQN/blob/master/commentary/sbcs.bqn)
Thanks to DLosc for -2 bytes!
```
{1<‚â°ùï©?‚à߬¥ùï䬮ùï©;‚â°ùï©}
```
[Run online!](https://mlochbaum.github.io/BQN/try.html#code=RuKGkHsxPOKJofCdlak/4oinwrTwnZWKwqjwnZWpO+KJofCdlal9CgpGwqjin6gK4p+o4p+pCuKfqDEsMiwzLDbin6kK4p+o4p+oMSwy4p+pLOKfqOKfqDHin6nin6ks4p+o4p+oNuKfqSzin6jin6jin6nin6nin6nin6kK4p+o4p+o4p+p4p+pCuKfqDEs4p+oMuKfqeKfqQrin6jin6gxLDLin6ks4p+o4p+oNuKfqSw04p+p4p+pCuKfqOKfqDEs4p+oMuKfqeKfqSzin6jin6gz4p+pLDTin6nin6kK4p+p)
`≡` gives the nesting depth of a list:
`1<‚â°ùï©?` If the depth is larger than 1 (ùï© contains at least one list):
¬†¬†¬†¬†`‚à߬¥ùï䬮ùï©` Are all the elements in the list properly tiered?
Else, if ùï© is either an integer or a list of integers:
¬†¬†¬†¬†`‚â°ùï©` Return the depth (1 for a list, 0 for an integer)
[Answer]
# [Brachylog](https://github.com/JCumin/Brachylog), ~~8~~ 7 bytes
```
ℕᵐ|ċᵐ↰ᵐ
```
[Try it online!](https://tio.run/##SypKTM6ozMlPN/r//1HL1IdbJ9Qc6QaSj9o2AMn//6OjDXWMYnWAVCyINAMRsUAAAA "Brachylog – Try It Online")
### Explanation
```
ℕᵐ The input is a list of only integers
| Or
ċᵐ The input is a list of only lists
↰ᵐ Recursive call on each sub-list
```
[Answer]
# [Typescript](https://www.typescriptlang.org/), 19 bytes
```
type A=number[]|A[]
```
[Try it online!](https://www.typescriptlang.org/play?ssl=1&ssc=20&pln=1&pc=1#code/C4TwDgpgBAggvAOwK4FsBGEBOBtAugHxjwChiAbCYKAQwC5Yo4oTrHmBGAGgCZOBmTgDZcxVk2zYu3XJwntcMicNl4FIsc1Wi2k2dPU7d0lcoAsC7eN3Z9KvjPMHxXVUA)
Type system shows an error whenever the typed variable doesn't conform to the requirements.
[Answer]
# [05AB1E](https://github.com/Adriandmen/05AB1E/wiki/Commands), 19 (or 2..) [bytes](https://github.com/Adriandmen/05AB1E/wiki/Codepage)
```
d"Ð1åi˜Që®δ.V"©.Vß_
```
Outputs `0` for truthy and `1` for falsey.
[Try it online](https://tio.run/##ASwA0/9vc2FiaWX//2Qiw5Axw6Vpy5xRw6vCrs60LlYiwqkuVsOfX///WzEsWzJdXQ) or [verify all test cases](https://tio.run/##yy9OTMpM/V9Waa@k8KhtkoKSfeX/FKXDEwwPL808PSfw8OpD685t0QtTOrRSL@zw/Pj/Ov@jo2N1FKINdYx0jHXMQEwQO1YHSMWCSDMQEQsEIJlYiNJoo1hkhUAlJjABsFR0tDFMCCgC1AsA).
If the challenge would have used the default truthy/falsey definition instead of overwriting the meta, it could have been **2 [bytes](https://github.com/Adriandmen/05AB1E/wiki/Codepage)** instead [by erroring](https://codegolf.meta.stackexchange.com/questions/2447/default-for-code-golf-input-output-methods/11908#11908):
```
¸P
```
Gives an error† as falsey value, or not as truthy value.
[Try it online](https://tio.run/##yy9OTMpM/f//0I6A//@jDXWijWJjAQ) or [verify all test cases](https://tio.run/##S0oszvifnFiiYKeQnJ@SqpdfnJiUmapgY6Pg6u/GZa@k8KhtkoKS/f9DOwL@6xzaZs8FEuYqz8jMSVUoSk1MUcjM40rJ51JQ0M8vKNGH6IZSaAbaKKiA1eal/o@O5Yo21DHSMdYxA7JAzFgdIBULIs1ARCwQcIEokLpoo1gkVUB5EygfJAEUMYaKAAWAFAA) (somewhat.. the falsey test cases contain rubbish output and lack trailing newline. Not sure how to properly try-catch the inner Elixir errors in 05AB1E.)
**Explanation:**
```
d # Convert each value in the (implicit) input-list to a 1
# (with a >=0 check)
"..." # Push the recursive string defined below
© # Store it in variable `®` (without popping)
.V # Evaluate and execute it as 05AB1E code
ß # Pop and push the flattened minimum
# (0 for falsey; 1 or "" for truthy)
_ # Check that this value is equal to 0 (1 if 0; 0 otherwise)
# (after which the result is output implicitly)
Ð # Triplicate the current list
1åi # If it contains a 1 as item:
ÀúQ # Check if the list is unchanged when flattened (thus all are 1s,
# without inner lists)
ë # Else:
δ # Map over each inner list:
® .V # And do a recursive call to `®`
¸ # Wrap the (implicit) input-list into a list
P # Take the product of each inner-most list,
# which will error if an inner list contains both integers and lists
# (implicitly output the result if it didn't error)
```
† The (Elixir) error is either an `ArithmeticError: bad argument in arithmetic expression` or an `UndefinedError: protocol Enumerable not implemented for int.` depending on how deep the integer causing the error is.
[Answer]
# [Vyxal](https://github.com/Vyxal/Vyxal), 11 bytes
```
λÞjṅ[Þj|vxA
```
[Try it Online!](https://vyxal.pythonanywhere.com/#WyJBIiwiIiwizrvDnmrhuYVbw55qfHZ4QSIsIiIsIltdXG5bMSwyLDMsNl1cbltbMSwyXSxbWzFdXSxbWzZdLFtbXV1dXVxuW1tdXVxuWzEsWzJdXVxuW1sxLDJdLFtbNl0sNF1dXG5bWzEsWzJdXSxbWzNdLDRdXVxuWzEsW11dIl0=)
[Answer]
# [K (ngn/k)](https://codeberg.org/ngn/k), 21 bytes
```
*/^9 56?4/'6!3':`j@^:
```
[Try it online!](https://ngn.codeberg.page/k#eJxLs9LSj7NUMDWzN9FXN1M0VrdKyHKIs+LiSlNIyLJXio5VgrEMdYx0jHXMEAIgkVgdIBULIs1ARCwQIORjkTVHG8ViagVqMkEVBikDShijSgDFQTwuLn2u6FgFXTuFyNRiLriL4AI4XISQj0XWDLIKxPXL50JzEJIointg4mDnQDgAXLpSqw==)
Uses a similar idea to Arnauld and Neil's regex approach, but without regex.
```
*/^9 56?4/'6!3':`j@^: Input: a ragged list
^: change all numbers to zeros
`j@ JSON stringify (which contains only `[]0,`)
3': get all length-3 contiguous substrings
6! each charcode mod 6 (`[]0,` -> 1 3 0 2)
4/' base 4 each
^9 56? test if each number is not one of 9 or 56 (which can only appear if
the substring "0,[" or "],0" appear in the string respectively)
*/ 1 if all true (or empty), 0 otherwise
```
[Answer]
# [Jelly](https://github.com/DennisMitchell/jelly), 9 bytes
```
߀ŒḊ⁺Ḋ$?P
```
[Try it online!](https://tio.run/##y0rNyan8///w/EdNa45Oerij61HjLiCpYh/w/3C7ZuT//9GxOgrRhjpGOsY6ZiAmiB2rA6RiQaQZiIgFApBMLERptFEsskKgEhOYAFgqOtoYJgQUiY0FAA "Jelly – Try It Online")
Port of [ovs's BQN solution](https://codegolf.stackexchange.com/a/251421/85334).
```
ŒḊ The depth of the argument (0 if integer)
? unless
⁺ the depth of the argument
Ḋ is greater than 1 (range [2 .. depth] is nonempty)
ß in which case recur
€ on each element
P and take the product of the results.
```
[Answer]
# [Python](https://www.python.org), 54 bytes
```
f=lambda x:x*0==0 or all((y*0==x[0]*0)&f(y)for y in x)
```
[Attempt This Online!](https://ato.pxeger.com/run?1=m72soLIkIz9vwYKlpSVpuhY3zdJscxJzk1ISFSqsKrQMbG0NFPKLFBJzcjQ0KkHcimiDWC0DTbU0jUrNNKBMpUJmnkKFJlT30RAFW4VoLgWF6FgdEGmoY6RjrGMG4YB4sTpAKhZEmoGIWCCAyMXGcsVycbnBtBvqRBvFomoDajBBCIGlo6ONEYJAMYghIGdVgJwVYgUULyjKzCvRSNOo0NTkgrCVdIFASROhzg1NHcQzsCABAA)
We can get it a little shorter with Whython, because iterating through a number is an error:
# [Whython](https://github.com/pxeger/whython), 46 bytes
```
f=lambda x:all((y*0==x[0]*0)&f(y)for y in x)?1
```
[Attempt This Online!](https://ato.pxeger.com/run?1=m728PKOyJCM_b8GCpaUlaboWN_XSbHMSc5NSEhUqrBJzcjQ0KrUMbG0rog1itQw01dI0KjXT8osUKhUy8xQqNO0NobqOhijYKkRzKShEx-qASEMdIx1jHTMIB8SL1QFSsSDSDETEAgFELjaWK5aLyw2m3VAn2igWVRtQgwlCCCwdHW2MEASKQQwBOawC5LAQK6B4QVFmXolGmkaFpiYXhK2kCwRKmgh1bmjqIJ6BBQUA)
[Answer]
# [R](https://www.r-project.org), 56 bytes
```
f=\(x)`if`(all(y<-Map(is.list,x)),all(Map(f,x)),!any(y))
```
[Attempt This Online!](https://ato.pxeger.com/run?1=m72waMGiNNulpSVpuhY3LdJsYzQqNBMy0xI0EnNyNCptdH0TCzQyi_VyMotLdCo0NXVAwiCxNDBPMTGvUqNSUxOi_xajcJoGSKWGpqaygq6dQmRqMRdUxFDHSMdYxwxTAiarqYPE1UTmmSFzNEEAqxlYxA0hGo1gUn75-GwF2mOCUyXMICT1xljVQ5UiJCBhs2ABhAYA)
Checks whether all elements are lists. If so, recurses, otherwise none of the elements may be a list.
Utilises the [fact](https://codegolf.stackexchange.com/a/242180/55372) that `all` and `any` work on depth-1 lists so we may use `Map` over `sapply`.
[Answer]
# Rust, ~~147~~ ~~131~~ 123 bytes
-18 bytes thanks to @alephaalpha for reminding me `matches!` exists
-8 bytes thanks to @bubbler for reminding me `Vec` impelments `Deref<Target=[T]>` and @alephaalpha for reminding me you can use `if` in `matches!`.
```
enum E{a(u8),b(Vec<E>)}fn f(e:&[E])->bool{e.iter().all(|m|matches!(m,E::a(_)))|e.iter().all(|m|matches!(m,E::b(k)if f(k)))}
```
[Playground Link](https://play.rust-lang.org/?version=stable&mode=debug&edition=2021&gist=5946618338e3c51fab2c91121e712b4c)
[Answer]
# [Ruby](https://www.ruby-lang.org/), ~~21~~ 16 bytes
```
p !/\],\d|\d,\[/
```
[Try it online!](https://tio.run/##KypNqvz/v0BBUT8mVicmpSYmRScmWv///@hYrmhDHSMdYx0zIAvEjNUBUrEg0gxExAIBF4gCqYs2ikVSBZQ3gfJBEkARY7DIv/yCksz8vOL/unkA "Ruby – Try It Online")
* Thanks to @Dom Hastings for saving 6.
* Fixed output to be of two consistent values.
Using Regexp.
Takes a string array literal and return *true* if list is tiered, *false* otherwise.
**Or 50 bytes**
Checking recursively.
```
f=->l{l.all?{|e|e*0==0}||l.all?{|e|e*0==[]&&f[e]}}
```
[Try it online!](https://tio.run/##KypNqvz/P81W1y6nOkcvMSfHvromtSZVy8DW1qC2pgZNKDpWTS0tOjW2tvZ/gUKaXjJQUiM6VlNBWUHXTiEytZgLLqoQbahjpGOsY4ZDFiQdqwOkYkGkGYiIBQIcimNx2hFtBJfzy8dmAdBoE9xKQNqBioxRFf0HAA "Ruby – Try It Online")
[Answer]
# [Wolfram Language (Mathematica)](https://www.wolfram.com/wolframscript/), ~~28~~ ~~24~~ 19 bytes
```
Min[0#/.{0...}->1]&
```
[Try it online!](https://tio.run/##y00syUjNTSzJTE78n2b73zczL9pAWV@v2kBPT69W184wVu1/QFFmXkm0sq5dmoNyrFpdcHJiXl01V3WtDle1oY6RjrGOGYgJYtfqAKlaEGkGImqBACQDIkFqq41qkVUC1ZjABMBS1dXGYCGu2v8A "Wolfram Language (Mathematica) – Try It Online")
Returns `1` if the list is properly tiered, or `0` otherwise.
Checks that integers are only present in non-nested lists.
```
0# zero integers
/.{0...}->1 turn lists of 0s into 1
Min[ ] 0s remaining?
```
[Answer]
# [Factor](https://factorcode.org) + `json`, ~~ 58 38~~  37 bytes
```
[ >json R/ ],\d|\d,\[/ re-contains? ]
```
`>json` postdates the Factor builds on TIO and ATO, so have a picture of running this in Factor's REPL:
[](https://i.stack.imgur.com/XcS74.gif)
If we're allowed to take input as a string, `>json` can be removed for -6 bytes.
[Answer]
# JavaScript, 36 bytes
```
f=a=>a.some?.(v=>v.at!=a[0].at|f(v))
```
Return `false` for valid, `true` for invalid.
```
f=a=>a.some?.(v=>v.at!=a[0].at|f(v))
update = () => { try { output.value = input.value.trim().split('\n').map(x => [JSON.parse(x.split('->')[0]), x.split('->')[1].trim() !== 'Yes']).map(([i, e]) => f(i) + ' ' + e).join('\n'); } catch {} }
update();
input.oninput = update;
```
```
<div style="display: flex">
<textarea id=input style="flex: 0 0 50%; font: inherit; padding: 10px;">[] -> Yes
[1,2,3,6] -> Yes
[[1,2],[[1]],[[6],[[]]]] -> Yes
[[]] -> Yes
[1,[2]] -> No
[[1,2],[[6],4]] -> No
[[1,[2]],[[3],4]] -> No
[1,[]] -> No</textarea>
<output id=output style="flex: 1 1 0; white-space: pre; padding: 15px;"></output>
</div>
```
[Answer]
# [jq](https://stedolan.github.io/jq/), 35 bytes
```
[..|map(type)?|unique|length]|max<2
```
[Try it online!](https://tio.run/##yyr8/z9aT68mN7FAo6SyIFXTvqY0L7OwNLUmJzUvvSQjFihTYWMEVBTLFW2oY6RjrGMGZIGYsTpAKhZEmoGIWCDgAlEgddFGsUiqgPImUD5IAihiDBUBCsTGAgA "jq – Try It Online")
Below, "E" indicates where `map(type)` produces an error. This is supressed with `?`.
```
input: [1,[2,3]]
[..]: [[1,[2,3]], 1, [2,3], 2, 3]
[|map(type)]: [["number","array"], E, ["number", "number"], E, E]
[|unique]: [["number","array"], ["number"]]
[|length]: [2, 1]
|max<2: false
```
[Answer]
# [Retina 0.8.2](https://github.com/m-ender/retina/wiki/The-Language/a950ad7d925ec9316e3e2fb2cf5d49fd15d23e3d), 12 bytes
```
1`\d,\[|],\d
```
[Try it online!](https://tio.run/##K0otycxL/K@q4Z7w3zAhJkUnJromVicm5f//6FiuaEMdIx1jHTMgC8SM1QFSsSDSDETEAgEXiAKpizaKRVIFlDeB8kESQBFjsAgA "Retina 0.8.2 – Try It Online") Link includes test cases. Outputs `0` for a properly tiered list. Explanation: Same approach as @Arnauld, just check for an integer next to a list. Would cost 3 bytes to output `1` for a properly tiered list.
[Answer]
# [Charcoal](https://github.com/somebody1234/Charcoal), 27 bytes
```
⊞υθFυFι⊞υ⁺⟦⟧κ⬤υΦ²⬤ι⁼μ⁼ν⁺⟦⟧ν
```
[Try it online!](https://tio.run/##TYuxDsIwDER3vsKjI5mBwtaJAebsloeoAjXCpGpS8/uGgkDccqd7d8OY6jAldY/WRjSCOfSb61QBLcDbc4Avi2oNWQhu4bWKNZcFj6orOmddLhU7grXIBKfZkja8/1L5@5fwUe/OzDviToSY90IHEfHtQ58 "Charcoal – Try It Online") Link is to verbose version of code. Explanation:
```
⊞υθFυFι⊞υ⁺⟦⟧κ
```
Enumerate the ragged list and all of its elements but replacing integers with empty lists (which are always properly tiered).
```
⬤υΦ²⬤ι⁼μ⁼ν⁺⟦⟧ν
```
Check that all lists contain either only integers or only sublists (or both, in the case of empty lists).
[Answer]
# [Wolfram Language (Mathematica)](https://www.wolfram.com/wolframscript/), 26 bytes
```
FreeQ[a_/;!SameQ@@Head/@a]
```
[Try it online!](https://tio.run/##y00syUjNTSzJTE78n2b7360oNTUwOjFe31oxODE3NdDBwSM1MUXfITH2f0BRZl5JtLKCrp1CWrRybKyCmoK@A5dCdXWtDpeCQrWhjoKRjoKxjoIZhA8WqNUBMWrBlBmYrAUCiHwtXF@1US26HpBiEyRRsBIg0xhJHCQMNO0/AA "Wolfram Language (Mathematica) – Try It Online")
Checks if the input contains any list whose elements do not have the same head (`List` or `Integer`).
[Answer]
# [Ruby](https://www.ruby-lang.org/), ~~40 36~~ 29 bytes
```
f=->l{l*0!=0&&!l.uniq(&f)[1]}
```
[Try it online!](https://tio.run/##KypNqvz/P81W1y6nOkfLQNHWQE1NMUevNC@zUEMtTTPaMLb2f4FCWnS0oY6RjnFsLBecEw3kQblAVTrRYGlUAbCS2P8A "Ruby – Try It Online")
### Why?
First check if l is a list (`l*0!=0`)
Then map f on l and check that the result is the same for all elements. By applying `uniq` directly on the list, instead of `l.map(&f).uniq` we can just check if there is a second element (`uniq` returns elements of the list instead of `true` or `false`). If we map the function first, we must check that the size is 2, because if we check the second element, it could be `false`, which is not what we want.
[Answer]
# [PARI/GP](https://pari.math.u-bordeaux.fr), 38 bytes
```
f(a)=(#a>#b=[f(x)|x<-a,#x'==#x])*#b||b
```
[Attempt This Online!](https://ato.pxeger.com/run?1=m728ILEoMz69YMGCpaUlaboWN9XSNBI1bTWUE-2Uk2yj0zQqNGsqbHQTdZQr1G1tlStiNbWUk2pqkqCq2xILCnIqNRIVdO0UCooy80qATCUQR0kBZI6mjkJ0dCyQMNQx0jHWMQMxQexYHSAVCyLNQEQsEIBVQpRGG8UiKwQqMYEJgKWio41hQkARoF5NiGtgfgAA)
Returns `0` for valid, `1` for invalid.
---
# [PARI/GP](https://pari.math.u-bordeaux.fr), 40 bytes
```
f(a)=[#x'==#x|x<-a]&&[x'===0||f(x)|x<-a]
```
[Attempt This Online!](https://ato.pxeger.com/run?1=m728ILEoMz69YMGCpaUlaboWNzXSNBI1baOVK9RtbZUraipsdBNj1dSiQVxbg5qaNI0KTYggVH1bYkFBTqVGooKunUJBUWZeCZCpBOIoKYBM0tRRiI6OBRKGOkY6xjpmICaIHasDpGJBpBmIiAUCsEqI0mijWGSFQCUmMAGwVHS0MUwIKALUqwlxDcwXAA)
Returns `0` for valid, `1` for invalid.
[Answer]
# [Pyth](https://github.com/isaacg1/pyth), 13 bytes
```
:w"\d,\[|],\d
```
[Try it online!](https://tio.run/##K6gsyfiv/N@qXCkmRScmuiZWJybl///oWK5oQx0jHWMdMyALxIzVAVKxINIMRMQCAReIAqmLNopFUgWUN4HyQRJAEWOoCFAgNhYA "Pyth – Try It Online")
Outputs `False` if list is properly tiered and `True` otherwise
[Answer]
# [JavaScript (Node.js)](https://nodejs.org), 37 bytes
```
f=v=>v.every?.(u=>!u.at)|v.every?.(f)
```
[Attempt This Online!](https://ato.pxeger.com/run?1=m70kLz8ldcGCpaUlaboWN1XTbMts7cr0UstSiyrt9TRKbe0US_USSzRrEGJpmhDFtxh9kvPzivNzUvVy8tM10jSiYxWwAk1NBX19hcjUYi409YY6RjrGOmbo2nCqB2mI1QFSsSDSDETEAgFu9bFYXYTHPdFGWLRA1Pvl43IO0CEmSNrwKAcZD9RgjKwBphwSqLCYAAA)
Outputs `1` for properly tiered list, `0` for lists that is not properly tiered, or integers (only used for recursive case)
[Answer]
# [Whython](https://github.com/pxeger/whython), 36 bytes
```
f=lambda l:sum(l)>=0?all(map(f,l))?0
```
[Attempt This Online!](https://ato.pxeger.com/run?1=bZCxasMwEIbp6mfooKEgGZSQJiWUgBOyBAodCulmNKiOTASyLaRzGz9Lh3opfab0aSpFLlVCb5C4-7__dKf3r7d9B_um7vvPFsrR_fGmzBSvXnYcqYVtK6LSZTZZcaVIxTUpqUrT1SSw31fXstKNAWQ7myRlY5CStUCy9oWxhZ2sFwlyAcJCwa2gSBy0KEDsUHZiHWSkJunYaiWBYDRaIpyeeRwpXrkiv3maBNl0obcPI2yrwJFlhHlBHAqh4R8QC2Mag08CL6DlyhXdMCQQwyPayBpIjjfrh0dMEX5ab7eY5X9LZIOZ0WjHoUX4pP74kTO_1rNpRZLf0imd0XlU8SVG3cX8OfcHcxEB7MyfT0O-4cpGdme8uxQ86qTZpeSUKA9z_gA)
*Test harness stolen from the one [Mukundan314](https://codegolf.stackexchange.com/users/91267/mukundan314) contributed to [Adam's Python answer](https://codegolf.stackexchange.com/a/251427/16766)*
### Explanation
```
f= # f is
lambda l: # a function that takes one argument l:
sum(l) # Sum the list (errors unless all items are numbers)
>=0 # If that worked, return True
? # If that errored,
map(f,l) # Recurse on each item (errors if l is not a list)
all( ) # If that worked, return True if every item returned True
? # If that errored (l is not a list),
0 # Return 0 (falsey)
```
The only time the function returns `0` is when it is called on an integer. If it is called on a list, it will always return either `True` or `False`.
]
|
[Question]
[
Your submission must take a list of numbers (in whatever list format your language supports, or using multiple function / command-line parameters) or a string of numbers separated by any character that is not `0123456789`. In one language, it must add all of them and output the sum. In another language, it must output them *subtracted from each other in order.* Example:
```
12
5
7
2
```
In one language, it must output `26`, and in another it must output `-2`. Note that all numbers inputted will be positive integers less than `100`. There will never be more than `20` numbers provided, so you will never output greater than `2000` or less than `-1899`. Any questions? Comment below!
[Answer]
# Python 2 / 3, 52 bytes
```
lambda l:sum(l[:1]+[x*int(1-(1/2)*4)for x in l[1:]])
```
`int(1-(1/2)*4)` returns `1` in Python 2 because `1/2` evaluates first to `0`, and then `0 * 4 = 0`.
`int(1-(1/2)*4)` returns `-1` in Python 3 because `1/2` evaluates first to `0.5`, and then `int(0.5 * 4) = int(2.0) = 2`.
[Answer]
# C and C++ (both from GCC), ~~81~~ ~~75~~ 73 bytes
```
int c;int f(int*a,int l){auto d=.5;c=*a++;for(;--l;a++)c+=*a-4*d**a;c=c;}
```
Takes a pointer to array and length.
**Explanation:** *still using @Steadybox' explanation :p* In C, `auto d=.5` declares an integer variable with the auto storage class (which is the default), which is then initialized to 0, whereas in C++11 it declares a double, which is initialized to 0.5.
**C - plus language:** [Try it online!](https://tio.run/nexus/c-gcc#FYzLCsIwFET3fkWpCHkWLC0urvFHxMUlMRhIE6npKvTb683mcGYY5gipdBYaPSMKVM0jr7iV3DkzzGCNQCnB55WB1hEocCup1JNwQiANLOzHOSQbN/e@/4oLefg8Tu1pwZAYr03x@TL1OqpZ3dS4w3el0rP@4nrlGaqJc3r5Aw "C (gcc) – TIO Nexus")
**C++ - minus language:** [Try it online!](https://tio.run/nexus/cpp-gcc#FYzLCsIwFET3fkWpCHkWLC0urvFHxMUlMRhIE6npKvTb683mcGYY5gipdBYaPSMKVM0jr7iV3DkzzGCNQCnB55WB1hEocCup1JNwQiANLOzHOSQbN/e@/4oLefg8Tu1pwZAYr03x@TL1OqpZ3dS4w3el0rP@4nrlGaqJc3r5Aw "C++ (gcc) – TIO Nexus")
[Answer]
# [Jelly](https://github.com/DennisMitchell/jelly) / [05AB1E](https://github.com/Adriandmen/05AB1E), 3 bytes
```
00000000: c6 71 53 .qS
```
This is a hexdump (xxd) of the submitted program.
[Try it online!](https://tio.run/nexus/bash#@19RkaKgW6Rgp1BcmqubkpmWpleQn1PJpZ9fUKKflZqTUwkhFdJQFSioRxsa6SiY6iiY6ygYxapzpSZn5HMVVJZk5OcZK4B1G5g6Ohm6Qim9gkoFXd3kAkMjUyM0k2xsbNBN@//fAAqsFJLNFMwNFUyNFYgFeoXBAA "Bash – TIO Nexus")
## Jelly: Sum
Jelly uses the [Jelly code page](https://github.com/DennisMitchell/jelly/wiki/Code-page), so it sees the following characters.
```
İqS
```
[Try it online!](https://tio.run/nexus/jelly#@39kQ2Hw////ow2NdBRMdRTMdRSMYgE "Jelly – TIO Nexus")
### How it works
```
İqS Main link. Argument: A (array)
İ (ignored)
q Unrecognized token. This breaks the link; nothing to the left is executed.
S Take the sum of A.
```
## 05AB1E: Difference
05AB1E uses [Windows-1252](https://en.wikipedia.org/wiki/Windows-1252#Character_set), so it sees the following characters.
```
ÆqS
```
[Try it online!](https://tio.run/nexus/05ab1e#@3@4rTD4//9oQyMdBVMdBXMdBaNYAA "05AB1E – TIO Nexus")
### How it works
```
Æ Take the difference of the input.
q Quit.
S (ignored)
```
[Answer]
# [05AB1E](https://github.com/Adriandmen/05AB1E) / [Jelly](https://github.com/DennisMitchell/jelly), 5 bytes
```
00000000: 4f71 7f5f 2f Oq._/
```
[Try it online! (05AB1E)](https://tio.run/nexus/05ab1e#@@9fWB@v//9/tKGRjoKpjoK5joJRLAA "05AB1E – TIO Nexus")
[Try it online! (Jelly)](https://tio.run/nexus/jelly#@@9fyBWv/////2hDIx0FUx0Fcx0Fo1gA "Jelly – TIO Nexus")
**05AB1E sees**:
```
Oq_/
```
Explanation:
```
Oq_/ 1 implicit argument.
O Take the sum of the first input item.
q Quit.
_/ Not functional.
```
**Jelly sees**:
```
Oq
_/
```
Explanation:
```
_/ Main link. Arguments: z
_/ Subtract z's elements in order.
Oq Helper link. Not functional.
```
[Answer]
# [Actually](https://github.com/Mego/Seriously) / [Jelly](https://github.com/DennisMitchell/jelly), 4 bytes
```
00000000: e4 81 5f 2f .._/
```
This is a hexdump (xxd) of the submitted program. It cannot be tested in raw form online; TIO doesn't support the CP437 encoding.
## Actually: Sum
Actually uses [CP 437](https://en.wikipedia.org/wiki/Code_page_437#Character_set), so it sees the following characters.
```
Σü_/
```
[Try it online!](https://tio.run/nexus/actually#@39u8eE98fr//xsa6SiY6iiY6ygYAQA "Actually – TIO Nexus")
### How it works
```
Σ Take the sum on the input.
ü Print and empty the stack.
_ Natural logarithm. Ignored since the stack is empty.
/ Float division. Ignored since the stack is empty.
```
## Jelly: Difference
Jelly uses the [Jelly code page](https://github.com/DennisMitchell/jelly/wiki/Code-page), so it sees the following characters.
```
ỵ¹_/
```
[Try it online!](https://tio.run/nexus/jelly#@/9w99ZDO@P1////b2iko2Cqo2Cuo2AEAA "Jelly – TIO Nexus")
### How it works
```
ỵ¹_/ Main link. Argument: A (array)
ỵ Unrecognized token. Splits the link.
¹ Identity; yield A.
_/ Reduce (/) A by subtraction (_).
```
[Answer]
# Python 2 and 3, ~~44~~ 41 bytes
```
lambda l:eval(l.replace(' ','-+'[1/2>0]))
```
Takes space-separated numbers.
---
-3 bytes thanks to @JonathanAllan
Try it online: [Python 2 (minus)](https://tio.run/nexus/python2#S7ON@Z@TmJuUkqiQY5ValpijkaNXlFqQk5icqqGuoK6jrqutHm2ob2RnEKup@b@gKDOvRCFNQ8nQSMFUwVzBSEnzPwA)
[Python 3 (plus)](https://tio.run/nexus/python3#S7ON@Z@TmJuUkqiQY5ValpijkaNXlFqQk5icqqGuoK6jrqutHm2ob2RnEKup@b@gKDOvRCNNQ8nQSMFUwVzBSAkoCAA)
[Answer]
# [CJam](https://sourceforge.net/p/cjam)/[Jelly](https://github.com/DennisMitchell/jelly), 6 bytes
```
q~:-
S
```
### CJam
```
q~ e# Read a list from input
:- e# Reduce by subtraction
S e# Push a space
e# Implicit output
```
[Try it online!](https://tio.run/nexus/cjam#@19YZ6XLFfz/f7ShkYKpgrmCUSwA "CJam – TIO Nexus")
### Jelly
(using UTF-8, not the Jelly code page)
`q~:-` is the helper link. Since it doesn't get called, it really doesn't matter what it does. `S` computes the sum of an array.
[Try it online!](https://tio.run/nexus/jelly#@19YZ6XLFfz///9oQyMdBVMdBXMdBaNYAA "Jelly – TIO Nexus")
[Answer]
# JavaScript / Cubix, 36 bytes
```
//.!v+u;$I^@O<.Iu
a=>eval(a.join`-`)
```
# Try it!
The JavaScript function can be tested using the snippet below, the Cubix program can be tested [here](https://ethproductions.github.io/cubix/?code=Ly8uIXYrdTskSV5ATzwuSXUKYT0+ZXZhbChhLmpvaW5gLWAp&input=MywgMSwgNCwgMSwgNQ==).
# How does this work?
## JavaScript
The first line is a line comment to JavaScript, since it starts with two slashes, so JavaScript only sees the bottom line (`a=>eval(a.join`-`)`), which takes an array as input, joins it with minus signs inbetween, and then runs that as code, resulting in the subtraction of all elements in the array.
```
let f=
//.!v+u;$I^@O<.Iu
a=>eval(a.join`-`)
console.log(f([1,2,3,4,5]))
console.log(f([3,1,4,1,5]))
```
## Cubix
Cubix sees the following cube (notice that Cubix ignores all whitespace):
```
/ / .
! v +
u ; $
I ^ @ O < . I u a = > e
v a l ( a . j o i n ` -
` ) . . . . . . . . . .
. . .
. . .
. . .
```
### The Beginning
The IP starts on the third line, pointing east. It hits the `'I'` command, which takes a number from the input, and pushes it to the stack. Then, it is redirected by `'^'` into the sum-loop.
### Sum-loop
I removed all characters not part of the sum loop, and replaced them by no-ops (`'.'`). The IP initally arrives on the second line, pointing east.
```
. . .
! v +
u ; $
. . . . . . I u . . . .
. . . . . . . . . . . .
. . . . . . . . . . . .
. . .
. . .
. . .
```
First, the `'!'` command checks the top element. If that is `0` (i.e. we have reached the end of the input), the next instruction (`'v'`) is executed, reflecting the IP out of the loop. If we have not yet reached the end of the input, we add the top two items together (`'+'`, the second item is the sum up to that point, the top item the new input). Then, the IP wraps to another face of the cube, into the `'u'` character, which causes the IP to make a u-turn, and execute a `'I'` command (read another input integer), while pointing north. The IP wraps back to the top face, skips (`'$'`) the delete instruction (`';'`) and makes another u-turn, back to the point at which we started.
### The End
If the IP is reflected out of the loop, the following characters are executed:
```
. . .
. v .
. ; .
. . @ O < . . . . . . .
. . . . . . . . . . . .
. . . . . . . . . . . .
. . .
. . .
. . .
```
These instructions delete the top element (which is zero), and then output the top element (the sum) as an integer. Then the `'@'` command is reached, so the program ends.
[Answer]
# JS (ES6), [CGL (CGL Golfing Language)](http://codepen.io/programmer5000/pen/zwYrVd), ~~32~~ 26 bytes
```
x=>eval(x.join`-`)
//-⨥
```
JS does the subtraction and CGL does the addition.
## JS:
```
x=>eval(x.join`-`)
```
An anonymous function that subtracts each element in the array using `Array#reduce`.
```
//-⨥
```
A comment.
## CGL
```
x=>eval(x.join`-`)
```
What looks like a space on the first line is actually a non-breaking space, a comment in CGL. The first line is ignored.
```
//-⨥
```
The `/`s do nothing. The `-` decrements the current stack pointer so it is pointing to input. `⨥` adds the current stack (input) together, pushes that to the next stack, and increments the current stack. It is implicitly outputted.
[Answer]
# JavaScript (ES6) / QBasic, ~~84~~ 83 bytes
```
'';f=x=>eval(x.join`+`)/*
INPUT a
FOR i=1 TO 2
i=0
INPUT n
a=a-n
PRINT a
NEXT i
'*/
```
Another solution with the comment hack!
JavaScript computes the sum. It takes in an array containing numbers as input. Outputs as function `return`. You can call the function like `alert(f([10,20,30]))`.
QBasic computes the difference. Repeatedly asks for input. As soon as you enter a value, it outputs the difference of all the numbers you have entered 'til the time of hitting `Enter` and again asks for input. Keeps on doing the same until the end of everything.
---
## How does it work?
In QBasic (a language of structured BASIC family; it does not require line numbers), `'` marks the beginning of a comment which goes till the end of the line. Whereas in JavaScript, it marks the start of a string. So, the whole first line is marked as a comment in QBasic but in JavaScript, the line is executed (and this line contains the JavaScript part that adds the numbers as well as a `/*` at the end which starts a comment in order to hide the rest of the QBasic code from JavaScript interpreter.)
The code from second line to second-last line contains the QBasic code to compute the difference of all the input numbers (the code is very self-explanatory).
The last line contains `'*/`. `'` causes the QBasic interpreter to interpret the following code as a comment, whereas in JavaScript, it does not have any effect as it is a part of a comment (which was started at the end of the first line). The following code (`*/`) causes JavaScript to end the comment which was started in the first line, but it is not executed in QBasic because QBasic thinks it's a part of a comment.
---
[Answer]
# Python 2 and 3, 33 bytes
```
lambda l,*r:l+sum(r)*(1/2>0 or-1)
```
Takes input as separate parameters.
---
[Python 2.](https://tio.run/nexus/python2#S7ON@Z@TmJuUkqiQo6NVZJWjXVyaq1GkqaVhqG9kZ6CQX6RrqPm/oCgzr0QjTcPQSEfBVEfBXEfBSFPzPwA)
[Python 3.](https://tio.run/nexus/python3#S7ON@Z@TmJuUkqiQo6NVZJWjXVyaq1GkqaVhqG9kZ6CQX6RrqPm/oCgzr0QjTcPQSEfBVEfBXEfBSFPzPwA)
[Answer]
# [Brain-Flak / Brain-Flueue](https://github.com/DJMcMayhem/Brain-Flak), 20 bytes
```
({}<([({{}})]){}>{})
```
[Try it online! (Brain-Flak) (plus)](https://tio.run/nexus/brain-flak#@69RXWujEa1RXV1bqxmrWV1rV12r@f@/oZGCuYKpgtF/3ZykosTMvLScxOyvefm6yYnJGakA "Brain-Flak – TIO Nexus")
[Try it online! (Brain-Flueue) (minus)](https://tio.run/nexus/brain-flak#@69RXWujEa1RXV1bqxmrWV1rV12r@f@/oZGCuYKpgtF/3ZykosTMvLSc0tTS1K95@brJickZqQA "Brain-Flueue – TIO Nexus")
## Explanation
The only difference between Brain-Flak and Brain-Flueue is that Brain-Flueue replaces the two stacks (last in first out) used in Brain-Flak with two queues (first in first out). Naturally this program uses this difference.
### Annotated Code
```
( ) Push the sum of...
{} the first input,
< > zero,
{} the remaining sum (see below)
([ ]) Push the of below line
({{}}) Pop all the input sans first, push the sum
{} Pop (in Brain-Flak, this discards the negative sum,
in Brain-Flueue, the positive)
```
[Answer]
# [Whispers v2](https://github.com/cairdcoinheringaahing/Whispers)/[Add++](https://github.com/cairdcoinheringaahing/AddPlusPlus), 72 bytes
```
D,f,@:,v¦Ω_
y:''
Dx,]getchar,`y,+x,`x
$f>y
> Input
>> ∑1
>> Output 2
```
[Try it online! (Whispers v2)](https://tio.run/##K8/ILC5ILSo2@v/fRSdNx8FKp@zQsnMr47kqrdTVuVwqdGLTU0uSMxKLdBIqdbQrdBIquFTS7Cq57BQ88wpKS7js7BQedUw0BNH@pSVAEQWgSdGGRjoKpjoK5joKRrEA "Whispers v2 – Try It Online")
[Try it online! (Add++)](https://tio.run/##S0xJKSj4/99FJ03HwUqn7NCycyvjuSqt1NW5XCp0YtNTS5IzEot0Eip1tCt0Eiq4VNLsKrnsFDzzCkpLuOzsFB51TDQE0f6lJUARBaP//6MNjXQUTHUUzHUUjGIB "Add++ – Try It Online")
Both are encoded as UTF-8, despite Add++ having it's own code page. Whispers takes the sum, Add++ takes the difference. This assumes that both languages take input from STDIN. Add++ exits with an error after having output the difference, which is [allowed by default](https://codegolf.meta.stackexchange.com/a/4781/66833).
## How it works (Whispers)
Whispers is very nice to polyglot, as it simply ignores every line that doesn't begin with `>`. As a result, the executed code is
```
> Input
>> ∑1
>> Output 2
```
This simply takes in input, calculates its sum and outputs it.
## How it works (Add++)
Add++ will error as soon as it reaches `> Input`, so only the stuff before that matters:
```
D,f,@:,v¦Ω_
y:''
Dx,]getchar,`y,+x,`x
$f>y
```
Taking input from STDIN is much longer in Add++ than from ARGV, but I wanted to be consistent across languages. Add++ doesn't have a builtin for reading from STDIN, aside from the `]getchar` command, which simply reads in a character (similar to brainfucks `,` command), and assigns it to the active variable (in this case `x`). Therefore, in order to read something from STDIN, we need the following structure:
```
y:''
Dx,]getchar,`y,+x,`x
```
As `]getchar` returns the empty string when it reaches the end of the input, we can use a do-while loop to read each character in. We start by declaring a variable `y` equal to the empty string. Next, we enter a do-while loop that runs until `x` is falsey (i.e. the empty string). This loop reads in a character from STDIN and concatenates it to `y`. Eventually, `y` is equal to the contents of STDIN.
Next, we define and run a function on the input:
```
D,f,@:,v¦Ω_
$f>y
```
As there is no way to evaluate a string in non-functional Add++ code, we're stuck with `y` as a string, rather than an array, which is what we need. Therefore, we have to pass the string into a function:
```
$f>y
```
The function itself is fairly basic to understand:
```
D,f, ; Define a function which...
@:, ; Takes 1 argument and outputs its return value
; This argument is the unevaluated string input, and the : flag saves a byte when it comes to outputting the final result
v ; Evaluate the input (convert from a string to an array)
¦Ω_ ; Reduce that array by subtraction
; Return and output this value
```
Very simply, both languages ignore each other's code, either due to how the code is parsed, or by erroring before it's actually reached.
[Answer]
# [Befunge-93](https://github.com/catseye/Befunge-93) / [Befunge-98](https://esolangs.org/wiki/Funge-98) [(FBBI)](https://github.com/catseye/FBBI), 23 bytes
```
#<&01v>-.@.+
~^#+&_^#+1
```
[Try it online! (Befunge-93) (minus)](https://tio.run/##S0pNK81LT/3/X9lGzcCwzE5Xz0FPm6suTllbLR5IGP7/b2ikYKpgrmAEAA)
[Try it online! (Befunge-98) (plus)](https://tio.run/##S0pNK81LT9W1tPj/X9lGzcCwzE5Xz0FPm6suTllbLR5IGP7/b2ikYKpgrmAEAA)
(Note: there must not be trailing whitespace in the input.)
### Explanation (both languages)
The control flow is the same in both languages until we reach EOF.
```
#<&01v>-.@.+
#< # (skipped)
& # Get the first number
0 # Push 0
1 # Push 1
v # Go down to the next line
~^#+&_^#+1
_ # The top 1 is nonzero, so the we go to the left
(begin loop)
& Get the next number
+ Add it to the running total (which starts as the 0 we pushed)
^# (skipped)
~ Get the next separator character
+1 Add 1
^# (skipped)
_ The separator plus 1 is nonzero, so we keep going left
(repeat)
```
By the time we run out of input, the top stack element is the sum of all the numbers but the first, and the first number is underneath it. When we reach EOF, the control flow diverges, because Befunge-93 pushes `-1`, while Befunge-98 reflects the instruction pointer.
### Explanation continued (Befunge-93)
```
~^#+&_^#+1
& # Get the last number
+ # Add it to the running total
^# # (skipped)
~ # On EOF: push -1
+1 # Add 1 to get 0
^# # (skipped)
_ # The top of the stack is 0, so we turn to the right
^ # Go up to the first line
#<&01v>-.@.+
> # Turn to the right
- # Subtract, from the first number, the sum of all the others
. # Print the result
@ # End the program
```
### Explanation continued (Befunge-98)
```
~^#+&_^#+1
& # Get the last number
+ # Add it to the running total
^# # (skipped)
~ # On EOF: reverse direction
^ # Go up to the first line
#<&01v>-.@.+
< # Turn to the left
# # No-op
+ # Αdd the first number to the sum of all the others
. # Output the result
@ # End the program
```
[Answer]
# JavaScript ES6/ES10, 29 bytes
```
x=>eval(x.join(x.at?'+':'-'))
```
[Try it online!](https://tio.run/##y0osSyxOLsosKNHNy09J/e9m@7/C1i61LDFHo0IvKz8zD0glltira6tbqeuqa2r@t1ZIzs8rzs9J1cvJT9dw04g21DHSMdYx0TGNBcoCAA "JavaScript (Node.js) – Try It Online")
Decide if `Array.prototype.at` exist
# x86 16-bit/32-bit, 15 bytes
```
lodsw
xchg ax, dx
jmp b
a: lodsw
mov bx, 0 ; skip next instruction in 32-bit
neg ax
add dx, ax
b: loop a
ret
```
[Answer]
# Python 3 / Javascript, 55 bytes
```
1//1;"""
f=(l)=>eval(l.join`-`)//""";f=lambda l:sum(l)
```
Javascript function taken from [Luke's Javascript / Cubix answer](https://codegolf.stackexchange.com/a/117016/58915). Python function is trivial. Works by abusing the fact that // is an operator in python and a line commentor in javascript, and then using """ to comment out the javascript section.
## Running the code
In Python:
```
1//1;"""
f=(l)=>eval(l.join`-`)//""";f=lambda l:sum(l)
print(f([1, 2, 3]))
```
In Javascript:
```
1//1;"""
f=(l)=>eval(l.join`-`)//""";f=lambda l:sum(l)
console.log(f([1, 2, 3]));
```
]
|
[Question]
[
# Briefing
Aliens have settled on earth and strangely enough, their alphabet is the exact same as ours. Their language is also very similar to ours with some very distinct and easy to compute differences.
# Challenge
Take a string and output the alien's language equivalent. The translation works as such:
Swap all the vowels in the word with the corresponding:
```
Vowel | With
--------+--------
a | obo
e | unu
i | ini
o | api
u | iki
```
You may also write another translator to translate Alien->English, this is optional however.
# Examples
```
Input: Shaun
Output: Shoboikin
Input: Java
Output: Jobovobo
Input: Hello, World!
Output: Hunullapi, Wapirld!
```
If the vowel is capitalized then you capitalize the first letter..
```
Input: Alan
Output: Obolobon
Input: Australia
Output: Oboikistroboliniobo
```
# Rules
* Standard loopholes apply
* Must work for text that contains new lines
* You can either write a function, lambda, or full program
Capingrobotikilobotiniapins apin wrinitining thunu runuvunursunu trobonslobotapir!
[Answer]
# Haskell, ~~100~~ 91 bytes
```
(>>= \x->last$[x]:[y|(z:y)<-words"aobo eunu iini oapi uiki AObo EUnu IIni OApi UIki",z==x])
```
[Answer]
# TI-Basic, 173 + 59 + 148 = 380 bytes
*Hopefully the aliens use TI-83/84 calculators ;)*
**Main Program, 173 bytes**
**BONUS:** Keep second or third line depending on whether your want a normal or reverse translator.
```
"("+Ans+")‚ÜíStr1
"@a~obo@A~Obo@e~unu@E~Unu@i~ini@I~Ini@o~api@O~Api@u~iki@U~Iki@‚ÜíStr2 <-- English to Alien
"@obo~a@Obo~A@unu~e@Unu~E@ini~i@Ini~I@api~o@Api~O@iki~u@Iki~U@‚ÜíStr2 <-- Alien to English
For(I,2,length(Ans
If "@"=sub(Str2,I-1,1
Then
Str1+"~"+sub(Str2,I,inString(Str2,"@",I)-I
prgmQ
Ans‚ÜíStr1
End
End
```
**Subprogram (`prgmQ`), 59 bytes:**
```
Ans‚ÜíStr9
inString(Ans,"~
sub(Str9,Ans,length(Str9)-Ans+1‚ÜíStr8
Str9
prgmR
Repeat Str9=Ans+Str8
Ans+Str8‚ÜíStr9
prgmR
End
```
**Subprogram (`prgmR`), 148 bytes:**
```
Ans‚ÜíStr0
inString(Ans,"~‚ÜíZ
inString(Str0,"~",Ans+1‚ÜíY
inString(sub(Str0,1,Z-1),sub(Str0,Z+1,Ans-Z-1‚ÜíX
sub(Str0,1,-1+inString(Str0,"~
If X
sub(Str0,1,X-1)+sub(Str0,Y+1,length(Str0)-Y)+sub(Str0,X+length(sub(Str0,Z+1,Y-Z-1)),Z-X-length(sub(Str0,Z+1,Y-Z-1
```
P.S. `~` represents token `0x81` and `@` represents token `0x7F`, learn more [here](http://tibasicdev.wikidot.com/one-byte-tokens).
P.P.S. Part of why these programs have a high byte count is because `sub(`, `inString(`, `length(`, and all lowercase letters are two bytes each...
[Answer]
# Perl, 56 bytes
Includes +1 for `-p`
Give input on STDIN
`alien.pl`:
```
#!/usr/bin/perl -p
s%\w%"`"&$&|("A\x0fboE\x15nuI\x09niO\x01piU\x09ki"=~/\u$&\K.../,$&)%eg
```
Works as shown, but replace the `\xXX` escapes by the actual character to get the claimed score
[Answer]
# sed 89
```
s,a,&b\n,gi
s,i,&n\r,gi
s,o,&p\r,gi
s,u,&k\r,gi
s,e,&n\f,gi
y,aeouAEOU\n\r\f,ouaiOUAIoiu,
```
[Answer]
# Python, ~~99~~ ~~95~~ 93 bytes
```
lambda s:"".join(("ouiaiOUIAI bnnpkbnnpk ouiiiouiii"+c)["aeiouAEIOU".find(c)::11] for c in s)
```
[On ideone.com...](http://ideone.com/QGS0cF)
Pretty simple. Just take the index we find each character at in the vowel list and use it to pull the three characters we need. If it's not found, `.find()` returns `-1` so just stick the current character on the end of the string. The spaces are necessary so any letter `"a"` doesn't include the added `c`. The translated vowels are grouped by letter order (the first letter of every translation, then the second, then the third).
[Answer]
# [05AB1E](https://github.com/Adriandmen/05AB1E), ~~28~~ ~~27~~ 20 bytes
```
žÀ.•₅%~≠#ùÛãú•3ôD™«‡
```
[Try it online!](https://tio.run/##yy9OTMpM/f//6L7DDXqPGhY9ampVrXvUuUD58M7Dsw8vPrwLKGZ8eIvLo5ZFh1Y/alj4/7@SkpJHak5Ovo4CV3h@UU6KIlAAAA "05AB1E – Try It Online")
**Unuxplobonobotiniapin**
```
žÀ # the string "aeiouAEIOU"
.•₅%~≠#ùÛãú• # the string "obounuiniapiiki"
3ô # split in pieces of 3
D™« # concatenate with a title-case copy
‡ # transliterate
```
[Answer]
# PHP , 91 Bytes
```
<?=strtr($argv[1],[A=>Obo,E=>Unu,I=>Ini,O=>Api,U=>Iki,a=>obo,e=>unu,i=>ini,o=>api,u=>iki]);
```
[Answer]
# Python, 129 bytes
```
lambda s:"".join([str,str.capitalize][ord(l)<91]({"a":"obo","e":"unu","i":"ini","o":"api","u":"iki"}.get(l.lower(),l))for l in s)
```
[See it running on ideone.com](http://ideone.com/N3WxvZ)
Here's a more nicely formatted version:
```
lambda s: \
"".join(
[str, str.capitalize][ord(l) < 91](
{"a":"obo", "e":"unu", "i":"ini", "o":"api", "u":"iki"}
.get(l.lower(), l)
)
for l in s)
```
The most interesting parts are `{ ... }.get(l.lower(), l)` which tries to look up the letter stored in `l` converted to lower case in the dictionary and either returns the translated version (if found), or else the original letter,
and `[str, str.capitalize][ord(l) < 91]( ... )` which checks whether the original letter was a capital letter (ASCII code point lower than 91) and then either calls the `str()` function with the letter as argument (if it wasn't a capital letter, does nothing) or the `str.capitalize()` function (converts the first letter of the argument string to upper case).
[Answer]
## Batch, 215 bytes
```
@echo off
set/pt=
set s=
:l
if "%t%"=="" echo(%s%&exit/b
set c=%t:~0,1%
for %%a in (obo.a unu.e ini.i api.o iki.u Obo.A Unu.E Ini.I Api.O Iki.U)do if .%c%==%%~xa set c=%%~na
set s=%s%%c%
set t=%t:~1%
goto l
```
Takes input on STDIN. Processing character-by-character has the convenience of being case-sensitive.
[Answer]
# Pyth, 42 bytes
```
#sXw"aeiouAEIOU"+Jc"obounuiniapiiki"3mrd3J
```
A program that takes input on STDIN and prints the output.
[Try it online](https://pyth.herokuapp.com/?code=%23sXw%22aeiouAEIOU%22%2BJc%22obounuiniapiiki%223mrd3J&input=Shaun%0AJava%0AHello%2C+World%21%0AAlan%0AAustralia&debug=0)
**How it works**
```
#sXw"aeiouAEIOU"+Jc"obounuiniapiiki"3mrd3J Program.
# Loop until error statement:
w Get w, the next line of the input
"obounuiniapiiki" Yield string literal "obounuiniapiiki"
c 3 Split that into groups of three characters
J Assign that to J and yield J
mrd3J Map title case over J
+ Merge the lower and title groups
"aeiouAEIOU" Yield string literal "aeiouAEIOU"
X Translate w from that to the three-character
groups
s Concatenate that
Implicitly print
```
[Answer]
# C, 167 bytes
I really didn't want to break my habit of always doing main functions when coding C, but this is substantially shorter than the version with a main and this way I got another letter to spell what I wanted!
## Golfed
```
a;l;i;e(char*n){for(;i=*n++;l=i>90,i-=32*l,a=!(i-65)+2*!(i-69)+3*!(i-73)+4*!(i-79)+5*!(i-85),printf(a?"%c%c%c":"%c",(a?"HOUIAI"[a]:i)+l*32,"ibnnpk"[a],"!ouiii"[a]));}
```
## Commented
```
a;l;i;
e(char*n)
{
for(;
i = *n++; /* Get char and advance */
l = i>90, /* Is lowercase? */
i -= 32*l, /* Make uppercase */
/* Is 1,2,3,4,5 depeding on the vowel and 0 for no vowel */
a = !(i-65) + 2*!(i-69) + 3*!(i-73) + 4*!(i-79) + 5*!(i-85),
printf(a?"%c%c%c":"%c", /* Print 1 or 3 chars? */
(a?"HOUIAI"[a]:i)+l*32, /* Print appropriate char+case */
"ibnnpk"[a], /* Print appropriate char */
"!ouiii"[a])); /* Print appropriate char */
}
```
There is something special about C and how horrible you can be with pointers and such.
[Answer]
# [C (gcc)](https://gcc.gnu.org/), ~~150 141 136~~ 134 bytes
```
a;i;e(char*n){for(char*v=" AEIOUIAI",*t;i=*n++;printf(&a))t=index(v,i-i/96*32),a=t?t-v:0,a=a?v[a+3]|L" 潢畮楮楰楫"[a]<<8|i&32:i;}
```
[Try it online!](https://tio.run/##S9ZNT07@/z/ROtM6VSM5I7FIK0@zOi2/CMIus1VScHT19A/1dPRU0tEqsc601crT1rYuKMrMK0nTUEvU1CyxzcxLSa3QKNPJ1M3UtzTTMjbS1Em0LbEv0S2zMgCyEu3LohO1jWNrfJQUnu1d9HzqumdLgWjDs6WrlaITY21sLGoy1YyNrDKta//nJmbmaWhWc6VqKAVnJJbmKWlaF5SWFGsoARkgQa/EskR0MY/UnJx8HYXw/KKcFEV0ScecRAxDHEuLS4oSczJBJnHV/gcA "C (gcc) – Try It Online")
Based on the answer by @algmyr and -8 thanks to @ASCII-only
Less golfed version
```
a;i;
e(char*n){
for(char*v=" AEIOUIAI",*t;i=*n++;printf(&a))
t=index(v,i-i/96*32),
a=t?t-v:0,
a=a?v[a+3]|L" 潢畮楮楰楫"[a]<<8|i&32:i;
}
```
[Answer]
## [Retina](http://github.com/mbuettner/retina), 60 bytes
Byte count assumes ISO 8859-1 encoding.
```
[A-Z]
»$&
T`L`l
i
ini
u
iki
e
unu
a
·b·
o
api
·
o
T`»l`_L`».
```
[Try it online!](http://retina.tryitonline.net/#code=W0EtWl0KwrskJgpUYExgbAppCmluaQp1CmlraQplCnVudQphCsK3YsK3Cm8KYXBpCsK3Cm8KVGDCu2xgX0xgwrsu&input=SGVsbG8sIEF1c3RyYWxpYSE)
[Answer]
## Javascript (ES6), ~~94~~ ~~93~~ 92 bytes
```
s=>s.replace(/[aeiou]/gi,c=>"OUIAIouiai"[n="AEIOUaeiou".search(c)]+"bnnpk"[n%=5]+"ouiii"[n])
```
*Saved 1 byte thanks to edc65*
*Saved 1 byte thanks to Neil*
### Demo
```
let f =
s=>s.replace(/[aeiou]/gi,c=>"OUIAIouiai"[n="AEIOUaeiou".search(c)]+"bnnpk"[n%=5]+"ouiii"[n])
function translate() {
document.getElementById("o").value = f(document.getElementById("i").value);
}
translate();
```
```
<input id="i" size=80 oninput="translate()" value="Hello, World!"><br><input id="o" size=80 disabled>
```
[Answer]
## Java 8, 172 bytes
```
String f(String s){String v="AEIOUaeiou",r="OboUnuIniApiIkiobounuiniapiiki",o="";for(char c:s.toCharArray()){int n=v.indexOf(c);o+=n>-1?r.substring(n*3,n*3+3):c;}return o;}
```
ungolfed:
```
String f(String s){
String v="AEIOUaeiou",r="OboUnuIniApiIkiobounuiniapiiki",o="";
for(char c:s.toCharArray()){
int n=v.indexOf(c);
o+=n>-1?r.substring(n*3,n*3+3):c;
}
return o;
}
```
And Alien back to English (171 bytes):
```
String g(String s){String[] v="AEIOUaeiou".split(""),r="Obo Unu Ini Api Iki obo unu ini api iki".split(" ");for(int i=0;i<v.length;i++)s=s.replaceAll(r[i],v[i]);return s;}
```
Ungolfed:
```
String g(String s){
String[] v="AEIOUaeiou".split(""),r="Obo Unu Ini Api Iki obo unu ini api iki".split(" ");
for(int i=0;i<v.length;i++)s=s.replaceAll(r[i],v[i]);
return s;
}
```
[Answer]
## Tcl, 75 bytes
String to be translated is in the variable `s`.
```
string map {A Obo a obo E Unu e unu I Ini i ini O Api o api U Iki u iki} $s
```
[Answer]
# Mathematica, 128 bytes
```
#~StringReplace~{"a"->"obo","A"->"Obo","e"->"unu","E"->"Unu","i"->"ini","I"->"Ini","o"->"api","O"->"Api","u"->"iki","U"->"Iki"}&
```
Not sure whether a shorter program can be obtained by using `IgnoreCase->True` together with a case check.
[Answer]
**C 178 bytes**
```
char*p[256],*a="obo\0unu\0ini\0api\0iki\0Obo\0Unu\0Ini\0Api\0Iki",*b="aeiouAEIOU";main(c){for(c=0;b[c];++c)p[b[c]]=a+4*c;for(;(c=getchar())>0;)p[c]?printf("%s",p[c]):putchar(c);}
```
[Answer]
# C, ~~163~~ ~~162~~ 159 bytes
```
char*t="aeiou";n,k;q(char*x){for(;*x;n<0||(*x=t[n>1?n%2?0:2:n+3])&&k>90||(*x-=32),printf("%c%.2s",*x++,n<0?"":&"bonunipiki"[2*n]))n=strchr(t,tolower(k=*x))-t;}
```
[Answer]
# C#, 133 121 bytes
```
s=>{int i;return string.Concat(s.Select(c=>(i ="AIUEOaiueo".IndexOf(c))>-1?"OboIniIkiUnuApioboiniikiunuapi".Substring(i*3,3):c+""));}
```
# Edit (thanks to `milk`)
thank you :) I actually know this overload but somehow completely forgot it when writing this..
```
s=>string.Concat(s.Select((c,i)=>(i="AIUEOaiueo".IndexOf(c))>-1?"OboIniIkiUnuApioboiniikiunuapi".Substring(i*3,3):c+""));
```
[Answer]
**C, ~~207~~ 202 bytes** (thanks to Cyoce)
```
#include <stdio.h>
#define r(c,t) case c:printf(t);continue;
int main(){int c;while(~(c=getchar())){switch(c){r('a',"obo")r('e',"unu")r('i',"ini")r('o',"api")r('u',"iki")default:putchar(c);}}return 0;}
```
1) I hate to omit type before any kind of declarations
2) I don't really like to put unusable code (without main() function)
**Usage:**
```
c89 cg.c -o cg; echo "Testing" | ./cg
```
[Answer]
# Swift 2.2 196 bytes
¯\\_(ツ)\_/¯
### Golfed
```
var r = ["a":"obo","e":"unu","i":"ini","o":"api","u":"iki"];var q={(s:String) in var o = "";for var i in s.lowercaseString.characters{o += r[String(i)] != nil ? r[String(i)]!:String(i)};print(o);}
```
### unGolfed
```
var r = ["a":"obo","e":"unu","i":"ini","o":"api","u":"iki"]
var q={(s:String) in
var o = ""
for var i in s.lowercaseString.characters {
o += r[String(i)] != nil ? r[String(i)]!:String(i)
}
print(o)
}
```
[Answer]
# [Perl 6](https://perl6.org), ~~ 84 ~~ 82 bytes
```
{my%o=<a obo e unu i ini o api u iki>;S:i:g[<{%o.keys}>]=%o{$/.lc}.samecase($/~'a')}
```
```
{my%o=<a obo e unu i ini o api u iki>;S:i:g[<[aeiou]>]=%o{$/.lc}.samecase($/~'a')}
```
## Expanded:
```
# bare block lambda with implicit parameter ÔΩ¢$_ÔΩ£
{
# create the mapping
my %v = <a obo e unu i ini o api u iki>;
# replace vowels in ÔΩ¢$_ÔΩ£
S
:ignorecase
:global
[
<[aeiou]>
]
= # replace them with:
%v{ $/.lc }
# change it to be the same case as what was matched, and a lowercase letter
.samecase( $/ ~ 'a' )
}
```
## Usage:
```
my &english-to-alien = {my%o=<a obo e unu i ini o api u iki>;S:i:g[<[aeiou]>]=%o{$/.lc}.samecase($/~'a')}
say english-to-alien 'Australia'; # Oboikistroboliniobo
```
[Answer]
## C - 192 bytes
(newlines added for clarity)
```
int c,j,b;main(){
char*f[]={"bo","nu","ni","pi","ki",""},
s[]={14,16,0,-14,-12};
while(c=getchar()){for(b=j=0;j<10;++j)
{if(c=="aeiouAEIOU"[j]){c+=s[j%=5];b=1;break;}}
printf("%c%s",c,f[b?j:5]);}}
```
Just lookup tables and a boolean switch.
Lookup each letter in table (string) of vowels; if found, then modify it according to the rule in table `s`. Print each character followed by a string: if a vowel was found, print the character modified by the value in `s` followed by the rest of the syllable stored in table `f`; if a vowel was not found, print the original character and an empty string.
[Answer]
# Ruby, 102 93 91 88 78 bytes
```
gsub(/[#{b='aeiouAEIOU'}]/){'obounuiniapiikiOboUnuIniApiIki'[b.index($&)*3,3]}
```
*Explanation:*
Execute the line like `ruby -pe "gsub(/[#{b='aeiouAEIOU'}]/){'obounuiniapiikiOboUnuIniApiIki'[b.index($&)*3,3]}"`, next up type, for example, `Australia` it should output: `Oboikistroboliniobo`.
It's pretty straightforward, replace all vowels with a substring based on the index of the to-be replaced vowel in (b), times 3 and the next 3 characters in the translation string.
[Answer]
# TI-BASIC, ~~201~~ ~~197~~ 195 bytes
```
Ans+" ‚ÜíStr1:"AEIOUaeiou‚ÜíStr2:"OUIAIouiai‚ÜíStr3:"bonunipiki‚ÜíStr4:1‚ÜíX:While X<length(Str1:inString(Str2,sub(Str1,X,1‚ÜíA:5fPart(.2A‚ÜíB:If A:sub(Str1,1,X-1)+sub(Str3,A,1)+sub(Str4,2B-1,2)+sub(Str1,X+1,length(Str1)-X‚ÜíStr1:X+1+2(A>0‚ÜíX:End:sub(Str1,1,length(Str1)-1
```
To think that I'd find another TI-BASIC answer here!
Anyway, the input is an English string in `Ans`.
The output is the translated string.
**Examples:**
```
"HE
HE
prgmCDGF1A
HUnu
"Hello
Hello
prgmCDGF1A
Hunullapi
```
**Explanation:**
(Newlines added for readability. Multiple lines from the same line will be denoted with a `:` in the following code block.)
```
Ans+" ‚ÜíStr1 ;append a space to the input string and store the result
; in "Str1"
"AEIOUaeiou‚ÜíStr2 ;store the upper- and lowercase vowels in "Str2"
"OUIAIouiai‚ÜíStr3 ;store the beginning letter of each corresponding translated
; vowel in "Str3"
"bonunipiki‚ÜíStr4 ;store the remaining letters of each translated vowel
; in "Str4"
1‚ÜíX ;store 1 in "X"
While X<length(Str1 ;loop until all English letters have been checked
inString(Str2,sub(Str1,X,1‚ÜíA ;get the current letter and store its index in "Str2"
; into "A"
5fPart(.2A‚ÜíB ;get which translated vowel end should be used
; B ranges from 1 to 5
If A ;if the current letter is a vowel
sub(Str1,1,X-1) ;extract the substring of the input before the
; current letter
: +sub(Str3,A,1) ;append the translated vowel start
: +sub(Str4,2B-1,2) ;append the translated vowel end
: +sub(Str1,X+1,length(Str1)-X ;append the remaining substring of the input
: ‚ÜíStr1 ;store the result of these concatenations into "Str1"
X+1+2(A>0‚ÜíX ;check if A>0 (if the current letter was a vowel)
; if true, increment "X" by three
; if false, increment "X" by one
End
sub(Str1,1,length(Str1)-1 ;remove the trailing space and store the result in "Ans"
;implicit print of "Ans"
```
---
**Notes:**
* TI-BASIC is a tokenized language. Character count does ***not*** equal byte count.
* Lowercase letters in TI-BASIC are two bytes each.
]
|
[Question]
[
This is a rather easy challenge.
# Challenge
Input will contain a string (not `null` or empty) of maximum length 100. Output the number of vowels in each word of the string, separated by spaces.
# Rules
* The string will not be more than 100 characters in length.
* The string will only contain alphabets `A-Z` , `a-z` and can also contain spaces.
* Input must be consumed from the `stdin` or command line arguments.
* Output must be outputted in the `stdout`.
* You can write a full program, or a function that takes input from the `stdin` and outputs the result.
* The vowels that your program/function needs to count are `aeiou` and `AEIOU`.
# Test Cases
```
This is the first test case --> 1 1 1 1 1 2
one plus two equals three --> 2 1 1 3 2
aeiou AEIOU --> 5 5
psst --> 0
the quick brown fox jumped over the lazy dog --> 1 2 1 1 2 2 1 1 1
```
# Scoring
This is [code-golf](/questions/tagged/code-golf "show questions tagged 'code-golf'"), so the shortest submission (in bytes) wins.
[Answer]
# C, ~~113 108 103~~ 96 bytes
Thanks [@andrea-biondo](https://codegolf.stackexchange.com/users/40702/andrea-biondo "@andrea-biondo") for a particularly nice 5 byte saving.
```
main(a,v,c)char**v;{do{for(a=0;c=*v[1]++%32;2016%(c+27)||a++);printf("%d ",a);}while(v[1][-1]);}
```
This still feels sort of bloated so hopefully I can get it down quite some bytes later tonight.
The interesting part is perhaps that
```
!(124701951%((c-65&31)+33))
```
will be `1` if `c` is an (upper or lower case) ASCII vowel, and `0` for other characters `a-zA-Z`. The subexpression `c-65&31` maps `'a'` and `'A'` to `0`, `'b'` and `'B'` to `2`, etc. When we add `33` the vowels correspond to the numbers `33, 37, 41, 47, 53` respectively, all of which are (conveniently) prime. In our range only such numbers will divide `124701951 = 33*37*41*47*53`, ie only for vowels will the remainder of `124701951%(...)` be zero.
EDIT: In this way one can consider the expression `!(n%((c-65&31)+s))` where `(n,s) = (124701951, 33)` as determining whether the character `c` is a vowel. In the comments [@andrea-biondo](https://codegolf.stackexchange.com/users/40702/andrea-biondo "@andrea-biondo") pointed out that the pair `(n,s) = (2016,28)` can also be used in this expression to determine vowelhood. I'll leave the current explanation in terms of primes above, but the reason this shorter pairing works is again because in the range 28--53 the only numbers with prime factors entirely in the set of prime factors of 2016 are 28, 32, 36, 42, 48, which correspond precisely to the vowels.
EDIT2: Another 5 bytes saved since `(c-65&31)+28` can be shortened to `c%32+27`.
EDIT3: Converted to a do-while loop to finally get it below 100 bytes.
Test cases:
```
$ ./vowelc "This is the first test case"
1 1 1 1 1 2
$ ./vowelc "one plus two equals three"
2 1 1 3 2
$ ./vowelc "aeiou AEIOU"
5 5
$ ./vowelc "psst"
0
```
[Answer]
# Pyth, 17 bytes
```
jdml@"aeiou"dcrzZ
```
Straightforward solution. Try it online: [Demonstration](https://pyth.herokuapp.com/?code=jdml%40%22aeiou%22dcrzZ&input=This+is+the+first+test+case&debug=0) or [Test harness](https://pyth.herokuapp.com/?code=zFz.zp%22%20--%3E%20%22%3C%2Bz*31d31%0Ajdml%40%22aeiou%22dcrzZ&input=Test%20Cases%3A%0AThis%20is%20the%20first%20test%20case%0Aone%20plus%20two%20equals%20three%0Aaeiou%20AEIOU%0Apsst&debug=0)
### Explanation:
```
z input
r Z convert to lower-case
c split at spaces
m map each word d to:
@"aeiou"d filter d for chars in "aeiou"
l length
jd join by spaces and implicitly print
```
[Answer]
# CJam, ~~21~~ 19 bytes
```
r{el_"aeiou"--,Sr}h
```
**How it works**:
```
r{ }h e# Read the first word and enter a do-while loop
el_ e# Convert the word into lower case and take a copy of it
"aeiou" e# All small caps vowels
- e# Remove all vowels from the copied word
- e# Remove all non-vowels from the original word
, e# At this point, we have a string with all vowels of the word
e# Simply take its length
S e# Put a space after the number of vowel
r e# Read the next word. This serves as the truthy condition for the
e# do-while loop for us as if there are no word left, this returns
e# null/falsy and the do-while loop is exited
```
[Try it online here](http://cjam.aditsu.net/#code=r%7Bel_%22aeiou%22--%2CSr%7Dh&input=psst%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20)
[Answer]
# R, ~~44~~ 43 bytes
```
cat(nchar(gsub("[^aeiou]","",scan(,""),T)))
```
Ungolfed + explanation:
```
# Read a string from STDIN. scan() automatically constructs a vector
# from input that contains spaces. The what= argument specifies that
# a string will be read rather than a numeric value. Since it's the
# second specified argument to scan(), we can simply do scan(,"").
s <- scan(what = "")
# For each word of the input, remove all consonants using gsub(),
# which is vectorized over its input argument.
g <- gsub("[^aeiou]", "", s, ignore.case = TRUE)
# Print the number of remaining characters in each word to STDOUT
# using cat(), which automatically separates vector values with a
# single space.
cat(nchar(g))
```
[Answer]
# Python 3, 65 bytes
```
print(*[sum(c in'aeiouAEIOU'for c in w)for w in input().split()])
```
Very straightforward, fairly readable. `w` stands for word, `c` stands for character.
[Answer]
# Perl, 35 34 31
```
say map{lc=~y/aeiou//.$"}split
```
`30` characters `+1` for `-n`.
Like a lot of Perl code, this works from right to left.
`split` will split the inputted line on whitespace.
`map` will run the code between `{}` on each word that was split.
`lc` makes the word lower case.
`=~y/aeiou//` will give us the count of vowels.
`.$"` will append a space to the word.
`say` then prints all the words!
Run with:
```
echo 'aeiou AEIOU' | perl -nE'say map{lc=~y/aeiou//.$"}split'
```
[Answer]
# Ruby, 38 bytes
```
$><<$*.map{|x|x.count'AIUEOaiueo'}*' '
```
Usage:
```
mad_gaksha@madlab /tmp/ $ ruby t.rb This is the first test case
1 1 1 1 1 2
```
[Answer]
# Perl: 30 characters
(Kind of forces the rules: the numbers in the output are separated with as many spaces as the input words were.)
```
s|\w+|@{[$&=~/[aeiou]/gi]}|ge
```
Sample run:
```
bash-4.3$ while read s; do printf '%-30s --> ' "$s"; perl -pe 's|\w+|@{[$&=~/[aeiou]/gi]}|ge' <<< "$s"; done < test-case.txt
This is the first test case --> 1 1 1 1 1 2
one plus two equals three --> 2 1 1 3 2
aeiou AEIOU --> 5 5
psst --> 0
```
### Perl: 27 characters
(Just to show how short would be if I didn't forget about `y///`'s return value. Again. Now go and upvote [chilemagic](https://codegolf.stackexchange.com/users/29438/chilemagic)'s [answer](https://codegolf.stackexchange.com/a/50573) which reminded me about `y///`'s return value. Again.)
```
s|\w+|lc($&)=~y/aeiou//|ge
```
[Answer]
# JavaScript (*ES6*), 68
I/O via popup. Run the snippet in Firefox to test.
```
// As requested by OP
alert(prompt().replace(/\w+/g,w=>w.replace(/[^aeiou]/ig,'').length))
// Testable
f=s=>s.replace(/\w+/g,w=>w.replace(/[^aeiou]/ig,'').length)
test=[
['This is the first test case','1 1 1 1 1 2']
,['one plus two equals three','2 1 1 3 2']
,['aeiou AEIOU', '5 5']
]
out=x=>O.innerHTML+=x+'\n'
test.forEach(t=>{
r=f(t[0])
out('Test '+ ['Fail','OK'][0|r==t[1]]
+'\nInput: '+ t[0]
+'\nOutput: '+r
+'\nCheck: '+t[1]+'\n')
})
```
```
<pre id=O></pre>
```
[Answer]
# Rebol - 70
```
print map-each n split input" "[c: 0 find-all n charset"aeiou"[++ c]c]
```
[Answer]
## PowerShell, 35 bytes
```
%{($_-replace"[^aeiou]",'').length}
```
Kinda boring, but actually competing for once? (PowerShell is case insentitive by default, woo)
[Answer]
# Bash - 85
```
while read l;do for w in $l;do x=${w//[^aouieAOUIE]};echo -n ${#x}\ ;done;echo;done
```
## Explanation
* `read l` read one line from input
* `for w in l` splits the line into words using whitespace separator
* `x=${w//[^aouieAOUIE]/}` deletes all except vowels from the word
* `${#x}` is the length of resulting string === number of vowels
[Answer]
# Julia, ~~76~~ ~~72~~ ~~69~~ 65 bytes
```
for w=split(readline()) print(count(i->i∈"aeiouAEIOU",w)," ")end
```
Ungolfed + explanation:
```
# Read a string from STDIN and split it into words
s = split(readline())
# For each word in the string...
for w in s
# Get the number of vowels of any case in the word
c = count(i -> i ∈ "aeiouAEIOU", w)
# Print the number of vowels identified
print(c, " ")
end
```
This will include a single trailing space, which I'm told is legit.
[Answer]
# Mathematica, 95 bytes
Not going to win any contests, but...
```
Print@StringRiffle[ToString[#~StringCount~Characters@"aeiouAEIOU"]&/@StringSplit@InputString[]]
```
[Answer]
# golflua, 55 bytes
```
~@W I.r():l():gm("%w+")_,c=W:g("[aeiou]",'')I.w(c,' ')$
```
Basic pattern matching of vowels after forced lowercase. An (ungolfed) Lua equivalent would be
```
line=io.read()
for word in line:lower():gmatch("%w+") do
_,c=word:gsub("[aeiou]",'')
io.write(c," ")
end
```
[Answer]
## **R**, 139 bytes
Read/write stdout() is terrible
```
s=function(x,y)strsplit(x,y)[[1]]
write(unlist(Map(function(x)sum(x%in%s("AIUEOaiueo","")),Map(s,s(readLines("stdin")," "),"")),),stdout())
```
[Answer]
# Python 3, 72 bytes
Inspired by [@randomra](https://codegolf.stackexchange.com/users/7311/randomra)'s [answer](https://codegolf.stackexchange.com/a/50574/34736). It's ~~the same length~~
slightly longer, but using regex instead of list comprehension. It's also less readable.
```
import re
print(*map(len,re.sub("[^aeiou ]","",input(),0,2).split(" ")))
```
[Answer]
# PHP - 94
```
foreach(explode(' ',$argv[1]) as$d){preg_match_all('/[aeiou]/i',$d,$v);echo count($v[0]).' ';}
```
Ungolfed version
```
$a = explode(' ',$argv[1]);
foreach($a as $d) {
preg_match_all('/[aeiou]/i', $d, $v);
echo count($v[0]).' ';
}
```
[Answer]
# Objective-C, 223 bytes
```
-(void)p:(NSString*)s{NSArray*a=[s componentsSeparatedByString:@" "];for(NSString*w in a){int c=0;for(int i=0;i<w.length;i++){if([@"aeiouAEIOU"containsString:[w substringWithRange:NSMakeRange(i,1)]]){c++;}}NSLog(@"%d",c);}}
```
Not the most compact language, but it works.
Uncompressed version:
```
- (void)p:(NSString*)s{
NSArray*a=[s componentsSeparatedByString:@" "];
for (NSString*w in a) {
int c=0;
for (int i=0;i<w.length;i++) {
if ([@"aeiouAEIOU" containsString:
[w substringWithRange:NSMakeRange(i, 1)]]) {
c++;
}
}
NSLog(@"%d",c);
}
}
```
[Answer]
# Matlab, 73 bytes
Your challenge is not very clear (but it is interesting). I'm assuming
* By "vowel" you mean `a`, `e`, `i`, `o`, `u`.
* The string does not contain leading or trailing spaces
Code:
```
diff(find(regexprep([' ' input('','s') ' '],'[^aeiouAEIOU ]','')==' '))-1
```
[Answer]
# [rs](https://github.com/kirbyfan64/rs), 50 bytes
This doesn't quite count; rs was uploaded around 2 weeks after this was posted. However, evidently this wouldn't win anything anyway, so it's still cool.
```
*[aeiou]/_
(^| )[^_\s]+ |$/ 0
[^_\s0]/
(_+)/(^^\1)
```
[Live demo.](http://kirbyfan64.github.io/rs/index.html?script=*%5Baeiou%5D%2F_%0A(%5E%7C%20)%5B%5E_%5Cs%5D%2B%20%7C%24%2F%200%0A%5B%5E_%5Cs0%5D%2F%0A(_%2B)%2F(%5E%5E%5C1)&input=This%20is%20the%20first%20test%20case%0Aone%20plus%20two%20equals%20three%0Aaeiou%20AEIOU%0Apsst)
The implementation is rather straightforward:
```
*[aeiou]/_ Replace all vowels with underscores.
(^| )[^_\s]+ |$/ 0 Replace words that have no vowels with a zero.
[^_\s0]/ Remove all other letters.
(_+)/(^^\1) Convert the underscore sequences into numbers (e.g. '___' to 3).
```
[Answer]
# Perl, ~~60~~ 45
```
$/=" ";while(<>){$n=()=/[aeiou]/gi;print"$n "
```
Thanks to kirbyfan64sos for saving me 15 bytes - that really helped!
Note there's an extra space at the end of the output.
[Answer]
# Haskell, ~~76~~ 68 bytes
```
f=interact$unwords.map(show.length).filter(`elem`"aeiouAEIOU").words
```
Straightforward implementation, not sure if there is anything to golf here.
[Answer]
# [APL (Dyalog Extended)](https://github.com/abrudz/dyalog-apl-extended), 2̶9̶ 28 bytes
```
{+/¨(∊∘'aeiou'⊢)¨' '(≠⊆⊢)⌊⍵}
+/¨ ⍝ sum each word's vowel bit array
(∊∘'aeiou'⊢)¨ ⍝ for each word, check for vowels
' '(≠⊆⊢) ⍝ split string on spaces
⌊⍵ ⍝ convert to lowercase
```
-1 thanks to Razetime
[Try it online!](https://tio.run/##JU1LDgFBFNw7xds1EXEGEhIrGw7Q9BuGNm/0hxliOxkTEktLsXIBF3CUvgg9Lam8VKWqXvFUdkTOJS06mBlMBIrvN3LF7djufl5NV1auvDOOMVnmqmfr82LAmu78cFVRa3ep3PV98h1gQyLoc8Uank@WsQYPs0SIYqUNGPRnzjUGnxKEVFof2BPg1nJZZxX@3bAHvcFoPA061doEUr/b2ni@hpmifQIRZbCymxQF0A5VmJP8kIOgBfsB "APL (Dyalog Extended) – Try It Online")
[Answer]
# KDB(Q), 30 bytes
```
{sum@'lower[" "vs x]in"aeiou"}
```
# Explanation
```
" "vs x / split x string by space
lower[ ] / lower case
in"aeiou" / check vowel
sum@' / sum each booleans
{ } / lambda
```
# Test
```
q){sum@'lower[" "vs x]in"aeiou"}"This is the first test case"
1 1 1 1 1 2i
```
[Answer]
# Smalltalk - 66 72
This is in Smalltalk/X; the names for stdin and stdout may be different in squeak/pharo.
```
Stdin nextLine subStrings do:[:w|(w count:[:c|c isVowel])print.' 'print]
```
In Smalltalk/X (and many other dialects), symbols understand #value:, so it can be abbreviated to 66 chars:
```
Stdin nextLine subStrings do:[:w|(w count:#isVowel)print.' 'print]
```
If coded as a function which get the string as argument "s":
```
[:s|s subStrings do:[:w|(w count:#isVowel)print.' 'print]]
```
Of course, in real code, one would use a utility function "f", which returns a vector of the counts, and print that. However, the output format is then not exactly what the challenge asked for:
```
f := [:s|s subStrings collect:[:w|(w count:#isVowel)]].
(f value: Stdin nextLine) print.
```
[Answer]
# Python 2, 76 bytes
I made this before I saw any other solution, then checked to find two P3 solutions that are shorter :( Darn P2 limitations.
```
print' '.join(`sum(y in'aeiouAEIOU'for y in x)`for x in raw_input().split())
```
[Answer]
# SAS, 72
```
data;infile stdin;file stdout;input c$@@;x=countc(c,'aeiou','i');put x@;
```
The restrictive I/O format for this one really hurts this one as it is responsible for 25 of the bytes here.
[Answer]
## PowerShell, 65 bytes
```
($input-split'\s'|%{($_-split''-match'a|e|i|o|u').count})-join' '
```
test by using the pattern below after saving as `vowels.ps1`
```
"the quick brown fox" | vowels.ps1
```
This way it is an actual script and not just a code snippet thereby satisfying constraint:
*"Input must be consumed from the stdin or command line arguments."*
[Answer]
# [Jelly](https://github.com/DennisMitchell/jelly), 7 bytes
```
Ḳf€ØcL€
```
[Try it online!](https://tio.run/##HU07DsIwFLuKlZlLMCCEhMQCBwjtC00JfW0@LWVk4QocgomJvSeBi4SkkmXLsmXXZMwY4/fzVr/7a3oW2yRxeiRexyj2lXZI8BVBaes8PCUqpCOxgOCG0JqQ8oFBXZAmVy3NoSTNAcvVZnfItnXOZ81TXdDFGUfLQwPFV9Th0lIJ7snOV0beRpR8En8 "Jelly – Try It Online")
Found with help from [Mr. Xcoder](https://codegolf.stackexchange.com/users/59487/mr-xcoder) in [chat](https://chat.stackexchange.com/rooms/57815/jelly-hypertraining)
## Explanation
```
Ḳf€ØcL€ - Main link. Argument: s (a string) e.g. "aeiou AEIOU"
Ḳ - Split the input on spaces ["aeiou", "AEIOU"]
Øc - Generate the string "AEIOUaeiou"
f€ - Filter out consonants from €ach ["aeiou", "AEIOU"]
L€ - Length of €ach [5, 5]
```
If the output *must* be space-separated, then append a `K` to the end
]
|
[Question]
[
# Specifications
Given a number `n`, output an ASCII "meme arrow" (greater-than symbol, `>`) of size `n`.
`n` will always be a positive integer, greater than 0.
## Examples
`n = 2`
```
\
\
/
/
```
`n = 5`
```
\
\
\
\
\
/
/
/
/
/
```
# Sample code
Here is a sample program, written in Crystal, that returns the correct results. Run it as `./arrow 10`.
`arrow.cr`:
```
def f(i)
i.times { |j|
j.times { print ' ' }
puts "\\"
}
i.times { |j|
(i-j-1).times { print ' ' }
puts '/'
}
end
f(ARGV[0].to_i)
```
# Rules
* This is [code-golf](/questions/tagged/code-golf "show questions tagged 'code-golf'"). The shortest answer wins. However, I will not select an answer, because the shortest answer may change over time.
* Standard loopholes are not allowed.
[Answer]
# [Canvas](https://github.com/dzaima/Canvas), 2 [bytes](https://github.com/dzaima/Canvas/blob/master/files/chartable.md)
```
\═
```
[Try it here!](https://dzaima.github.io/Canvas/?u=JXVGRjNDJXUyNTUw,i=NQ__,v=8)
[Answer]
# [C (gcc)](https://gcc.gnu.org/), 56 bytes
```
f(n,i){for(i=-n;n;printf("%*c\n",i?++i+n:n--,i?92:47));}
```
[Try it online!](https://tio.run/##S9ZNT07@/z9NI08nU7M6Lb9II9NWN886z7qgKDOvJE1DSVUrOSZPSSfTXls7UzvPKk9XF8i2NLIyMdfUtK79n5uYmaehWc2VpmGkaQ0kTYFk7X8A "C (gcc) – Try It Online")
```
f(n,i){for(i=-n;i;printf("%*c\n", ++i+n , 92 )); //first print descending '\'s
for( ;n;printf("%*c\n", n--, 47));} // then print returning '/'s
```
[Answer]
# [Python 2](https://docs.python.org/2/), 54 bytes
```
f=lambda n,p='':n*'?'and p+'\\\n'+f(n-1,p+' ')+p+'/\n'
```
[Try it online!](https://tio.run/##K6gsycjPM/r/P802JzE3KSVRIU@nwFZd3SpPS91ePTEvRaFAWz0mJiZPXTtNI0/XUAfIVVDX1AZS@kDB/wVFmXklCmkamXkFpSUampr/TQE "Python 2 – Try It Online")
Outputs with a trailing newline.
[Answer]
# [C# (Visual C# Interactive Compiler)](http://www.mono-project.com/docs/about-mono/releases/5.0.0/#csc), 66 bytes
```
n=>new int[n*2].Select((a,b)=>"".PadLeft(b<n?b:n*2+~b)+"\\/"[b/n])
```
Saved a byte thanks to @someone.
[Try it online!](https://tio.run/##JY0xb4MwEIXn8itOnnw1hbZjwO7USq0YKmXIAAw2OSJLySGB02z56/Rapu/u6dN7w/I0LHH9uPJQR0755ztfLzT7cKZ6SXPkk3OjXdk6phuI0fLja1/s6UxD0trnAa1Tqvj2x4bGpEPNb2EnjrkHNKrrStWGkntcq@xnikdItCQtPeARrIPDHBM1kUl7MKB2HSvhtlx8TZG1kigftUf8E@TBKhun@b8jgoWXSlALn@UwBrOHbQKr9Rc "C# (Visual C# Interactive Compiler) – Try It Online")
[Answer]
# [Perl 5](https://www.perl.org/) `-p`, 36 bytes
```
$\=($q=$"x$_)."\\
$\$q/
"while$_--}{
```
[Try it online!](https://tio.run/##K0gtyjH9/18lxlZDpdBWRalCJV5TTykmhkslRqVQn0upPCMzJ1UlXle3tvr/f@N/@QUlmfl5xf91fU31DAwN/usWAAA "Perl 5 – Try It Online")
[Answer]
# [05AB1E](https://github.com/Adriandmen/05AB1E), 6 bytes
```
'\3.Λ∊
```
[Try it online!](https://tio.run/##yy9OTMpM/f9fPcZY79zsRx1d//@bAgA "05AB1E – Try It Online")
**Explanation**
```
.Λ # draw
'\ # the string "\"
# of length input
3 # in the south-eastern direction
∊ # then vertically mirror it
```
[Answer]
# [PowerShell](https://github.com/TryItOnline/TioSetup/wiki/Powershell), ~~44~~ 41 bytes
```
filter f{if($_){'\'
--$_|f|%{" $_"}
'/'}}
```
[Try it online!](https://tio.run/##K8gvTy0qzkjNyfn/Py0zpyS1SCGtOjNNQyVes1o9Rp1LV1clviatRrVaSUElXqmWS11fvbb2v6GenhlQDCRlraCuXvsfAA "PowerShell – Try It Online")
[Answer]
# C64Mini/C64 BASIC (and other CBM BASIC variants), 52 tokenized BASIC bytes used
```
0INPUTN:N=N-1:FORI=0TON:PRINTTAB(I)"\":NEXT:FORI=NTO0STEP-1:PRINTTAB(I)"/":NEXT
```
Here is the non-obfuscated version for exaplantion:
```
0 INPUT N
1 LET N=N-1
2 FOR I=0 TO N
3 PRINT TAB(I);"\"
4 NEXT I
5 FOR I=N TO 0 STEP -1
6 PRINT TAB(I);"/"
7 NEXT I
```
What ever number is entered into `N` in line zero is reduced by one as the `TAB` command is zero-indexed; The `FOR/NEXT` loops in lines two through to four and five through to seven then output the upper and lower part if the `meme` arrow respectively (represented by a shifted `M` and shifted `N` in graphics mode [source](http://sta.c64.org/cbm64pet.html))
[](https://i.stack.imgur.com/e3Wzf.png)
[Answer]
# [MarioLANG](https://github.com/tomsmeding/MarioLANG), 719 677 bytes
```
+
+
+
+
+
+ ((((+)+++++)))<
+>======================"
+)++++++)+++++++++++((-[!)
========================#=-
) 
This was harder than expected...
[Answer]
# [brainfuck](https://github.com/TryItOnline/brainfuck), 125 bytes
```
++++++++++[->+>+++++++++>+++<<<]>>++>++>,[->[->+<<<.>>]<<<.<.>>>>>[-<+>]<+<]<<[--<<+>>]<<+>>>>>[-[-<+<.>>]<<<<<.>.>>>[->+<]>]
```
[Try it online!](https://tio.run/##PYxBCoBADAMfVLsvKPnI0oMKgggeBN9fk0Xtpcmk6XLN@7nd61Fl/3SH4XdSEZHA0JgY64KsAaklwekeRmBB2N2DTrm9oeKvom4blI8SWfUA "brainfuck – Try It Online")
```
++++++++++[->+>+++++++++>+++<<<]>>++>++> ; Initialize with " \"
, ; Get input
[-> ; loop and decrement n
[->+<<<.>>] ; output number of spaces, copy n
<<<. ; output \
<. ; output newline
>>>>
>[-<+>]<+ ; copy copy of n back to original place
<]
<<[--<<+>>]<<+>> ; change "\" to "/"
>>>
[ ; second loop for bottom half
- ; decrement n
[-<+<.>>] ; output n spaces
<<<<<.>. ; output \ and newline
>>>[->+<]> ; copy n back
]
```
[Answer]
# [Ruby](https://www.ruby-lang.org/), ~~111~~ ~~99~~ ~~77~~ ~~73~~ ~~68~~ ~~64~~ ~~57~~ 56 bytes
-12 bytes thanks to [Benjamin Urquhart](https://codegolf.stackexchange.com/users/84303/benjamin-urquhart), -43 thanks to [manatwork](https://codegolf.stackexchange.com/users/4198/manatwork) and -2 bytes thanks to [Value Ink](https://codegolf.stackexchange.com/users/52194/value-ink).
```
->i{s=[];puts (0...i).map{|j|s=(p=' '*j)+?/,*s;p+?\\},s}
```
[Try it online!](https://tio.run/##KypNqvyfZvtf1y6zutg2Ota6oLSkWEHDQE9PL1NTLzexoLomq6bYVqPAVl1BXStLU9teX0er2LpA2z4mplanuPY/WL26sZU6V1q0cSwXmKsUk2dqpQQUMI39DwA "Ruby – Try It Online")
Explanation:
```
f=->i{ # instead of a function, use a lambda
s=[] # needs a helper variable *now*, for scope
puts( # puts takes arbitrary num of args; \n after each
(0...i).map{|j| # not from 0 to i but from 0 to i-1 (*three* dots)
s=(
p=' '*j # p will remain in scope inside of .map,
)
+?/ # character literal instead of string
,*s # essentially appending to the array
p+?\\ # p is what's returned by .map, not s!
}, # up until here, 1st arg to display
s # NOW, as the *2nd* arg, s is displayed
)
}
```
# Alternative (but longer) Solutions
A friend read this answer and then tried to come up with a couple more approaches. Putting them here, too, so that they're not lost to the vast interwebs.
## inject and unshift, 72 bytes
```
->n{puts (0...n).inject([]){|s,i|i=' '*(n-1-i);s.unshift i+?\\;s<<i+?/}}
```
[Try it online!](https://tio.run/##KypNqvyfZvtf1y6vuqC0pFhBw0BPTy9PUy8zLys1uUQjOlazuqZYJ7Mm01ZdQV1LI0/XUDdT07pYrzSvOCMzrUQhU9s@Jsa62MYGyNCvrf0PNkTd2EqdKy3aOJYLzFWKyTO1UgIKmMb@BwA "Ruby – Try It Online")
## downto, inject and unshift, 80 bytes
```
->n{puts n.downto(1).map{|i|' '*(i-1)}.inject([]){|s,i|s<<i+?/;s.unshift i+?\\}}
```
[Try it online!](https://tio.run/##KypNqvyfZvtf1y6vuqC0pFghTy8lvzyvJF/DUFMvN7GguiazRl1BXUsjU9dQs1YvMy8rNblEIzpWs7qmWCezptjGJlPbXt@6WK80rzgjM61EAciNiamt/Q82TN3YSp0rLdo4lgvMVYrJM7VSAgqYxv4HAA "Ruby – Try It Online")
## intriguing, two non-nested loops, 127 bytes
```
->n{
r=->s,c{s[0..-(c+1)],s[-c..-1]=s[c..-1],s[0..c-1];s};
n.times{|i|puts r[' '*n+?\\,n-i]}
n.times{|i|puts r[' '*n+?/,i+1]}
}
```
[Try it online!](https://tio.run/##dYqxDsIgFEV3vqLpgsoDJU2XNtQPARaJTRgkhtcOhvLtSHB2O@fcG/fHp6yq8CUkEhVfEFxCfROCnxyTZwuouasmrUL9A2i7qzRjnkkQm389MR3@eO8bdlHTjl4CuxsDgXub/z@u4Jmsh1xap8NEyaoHS5r2JoxTX8Noyxc "Ruby – Try It Online")
[Answer]
# [Charcoal](https://github.com/somebody1234/Charcoal), 5 bytes
```
↘N‖M↓
```
[Try it online!](https://tio.run/##S85ILErOT8z5/z@gKDOvRMPKJb88LygzPaNER8Ezr6C0xK80Nym1SENT05orKDUtJzW5xDezqCi/CKJS0/r/f9P/umU5AA "Charcoal – Try It Online") Link is to verbose version of code. Explanation:
```
↘N
```
Input a number and print a diagonal line of `\`s of that length.
```
‖M↓
```
Reflect the line vertically.
[Answer]
# T-SQL code, 80 bytes
```
DECLARE @ INT=3
,@z INT=0
x:PRINT
space(@-abs(@[[email protected]](/cdn-cgi/l/email-protection)))+char(92-@z/@*45)SET
@z+=1IF @z<@*2GOTO x
```
**[Try it online](https://data.stackexchange.com/stackoverflow/query/1062368/ascii-meme-arrow-generator)**
# T-SQL query, 96 bytes
In order to make this work online i had to make some minor alterations.
Spaces in the beginning of a row doesn't display in the online snippet. So I am using ascii 160 instead. When running in management studio, it is possible to change the settings to show result as text, which would result in the correct spaces in this posted script.
```
DECLARE @ INT=3
SELECT space(@-abs(@-number-.5))+char(92-number/@*45)FROM
spt_values WHERE number<@*2and'p'=type
```
**[Try it online](https://data.stackexchange.com/stackoverflow/query/1062337/ascii-meme-arrow-generator)**
[Answer]
# [MAWP](https://esolangs.org/wiki/MAWP), 69 bytes
```
%@!0//[!1A]%[1A[1A84W;]%99W25WM1M;25W;]%[!1A]~[1A[1A84W;]%67W5M;25W;]
```
I am not going to golf this further bcause funny number. Sorry, guys.
[Try it!](https://8dion8.github.io/MAWP/v1.1?code=%25%40!0%2F%2F%5B!1A%5D%25%5B1A%5B1A84W%3B%5D%2599W25WM1M%3B25W%3B%5D%25%5B!1A%5D%7E%5B1A%5B1A84W%3B%5D%2567W5M%3B25W%3B%5D&input=5)
[Answer]
# APL(NARS), 40 chars, 80 bytes
```
{f←{⍺,⍨⍵⍴' '}⋄⊃('\'f¨k),('/'f¨⌽k←¯1+⍳⍵)}
```
test:
```
h←{f←{⍺,⍨⍵⍴' '}⋄⊃('\'f¨k),('/'f¨⌽k←¯1+⍳⍵)}
h 2
\
\
/
/
h 5
\
\
\
\
\
/
/
/
/
/
```
[Answer]
# [TypeScript](https://www.typescriptlang.org)'s type system, 87 bytes
```
//@ts-nocheck
type F<N,S="">=N extends[{},...infer N]?`
${S}\\${F<N,`${S} `>}
${S}/`:""
```
[Try it at the TypeScript playground](https://www.typescriptlang.org/play?#code/PTACBcGcFoDsHsDGALApog1gWAFDgJ4AOqABAGIA8AcgDQDKAvAERMB8DVJqAHuKrABNIAbQDeAXxoA6GQEtYAM1QAnElQC6AfgAGuACSi64gDrGDlWtoNGS21uP2HxwbQC4WuXAWIkAsgHkAVToAUQB9fwA1EIAlMN8QkgZyCmEARhoMrMz1VlwQEkIAQ0g+EjRlUnB4EkhUUkR4ZUrEcAAbfFd84HLwcEJIVxAi6qlCblQAcxUpRoBbYGUAV1hNNIY5gHYABgwAGQAvAA42gUQAcSKAVgAFfCOAFgA3fERIvYAmRDCACToqYqBNpFABG8AA6lR8B9IgBNJ4AKVksLme3wZF8AEEQm0AJIxGKIMjwBQAFVxZARIUxPxC0Aw8AAipjuAAtACOjKWkzIAGF8JjtpjMbggA)
Takes input as a unary number represented by a tuple type N. If I instead took the unary number as a string type of spaces, this becomes **71 bytes:**
```
type F<S,O=''>=S extends` ${infer S}`?F<S,`${S}\\
${O&string}${S}/
`>:O
```
[Try it at the TS playground](https://www.typescriptlang.org/play?#code/C4TwDgpgBAYgPAZQDQHkC8AiDA+NCoQAewEAdgCYDOABlACQDeAlqQGYQBOUCAvtQPzxk1RrwA6YgLAAoRigBklYBxYBzHqJ4B6GdWwAuFDJmhIUALIoAqggCiAfRQA1WwCV7521DSw4GKAEBODJaWlBgAIZK0AAWnNDAAPZQlBDQAMaJHBwQ6cAANiD6IWExwMBglPqhEUkAdGCEEKqcdZkAtlocAK6k-ACMaO0A7AAMANYAMgBeABz55OkA4hEArAAKILMALABuIOlOkwBM6fYAEggAcpFW+REARokA6lcgx04Amu0AUkyzMQAKgBBABCPzsVgAGqCIudRiBQQhXGDCLYAMLjUEAERgqkSCAitihHGBwIAiqpzMCZEA)
I like the shorter version better because it's tail-recursive and just overall really elegant, but I think the I/O format is a little cheaty.
[Answer]
# [Vyxal](https://github.com/Vyxal/Vyxal/tree/version-2), 8 bytes
```
ɾ\\↳↲øṀ§
```
[Try it Online!](https://vyxal.pythonanywhere.com/?v=2&c=1#WyIiLCIiLCLJvlxcXFzihrPihrLDuOG5gMKnIiwiIiwiNSJd)
```
↳ # Right-pad
\\ # \
ɾ # To length each of range(1, n+1)
↲ # Left-pad each to length n
øṀ # Mirror, flipping slashes
§ # Vertical join, transposing and joining by newlines
```
[Answer]
# [Retina 0.8.2](https://github.com/m-ender/retina/wiki/The-Language/a950ad7d925ec9316e3e2fb2cf5d49fd15d23e3d), 32 bytes
```
.+
$* ¶$&$*
\G.
¶$`\
r`.\G
$'/¶
```
[Try it online!](https://tio.run/##K0otycxL/P9fT5tLRUvh0DYVNSDFFeOuxwVkJ8RwFSXoxbhzqajrH9r2/78pAA "Retina 0.8.2 – Try It Online") Explanation:
```
.+
$* ¶$&$*
```
Generate two lines of `n` spaces.
```
\G.
¶$`\
```
Turn the top line into a `\` diagonal.
```
r`.\G
$'/¶
```
Turn the bottom line into a `/` diagonal.
[Answer]
# [C (gcc)](https://gcc.gnu.org/), ~~67~~ 65 bytes
-2 bytes thanks to ceilingcat
```
f(n,i){for(i=~n;i++<n;)i&&printf("%*c\n",n-abs(i)+1,"/\\"[i<0]);}
```
[Try it online!](https://tio.run/##FcrNCsIwDADgs3sKKTgS2@IPeOp8EuuhBjICW5TN29gefXGevstHsSUyY9AgOPF7ALkvmsT7RhNKXX8G0S@DOxwpqwsay2sEQX8J7pSze0hzfmKabVv7vogCVlO1Y7hh@nPdmG0l7ko7Wuz6Hw "C (gcc) – Try It Online")
[Answer]
# [Python 2](https://docs.python.org/2/), ~~85~~ ~~84~~ ~~81~~ ~~80~~ 75 bytes
```
def a(n):l="for i in range(n):print' '*";exec l+"i+'\\\\'\n"+l+"(n+~i)+'/'"
```
[Try it online!](https://tio.run/##FcgxCoAwDEDRq4Qsac0gCC6KN3EpWjUgaSkVdPHqtf7t/fjkI2hXyuo3cEbtcE64hQQCopCc7v6fMYlmAmpw9Ldf4GQUprlGsyJXGuVXLFNLWJwRjVc21pb@Aw "Python 2 – Try It Online")
[Answer]
# [PowerShell](https://github.com/TryItOnline/TioSetup/wiki/Powershell), 50 bytes
```
param($n)0..--$n|%{' '*$_+'\'}
$n..0|%{' '*$_+'/'}
```
[Try it online!](https://tio.run/##K8gvTy0qzkjNyfmvkmZb/b8gsSgxV0MlT9NAT09XVyWvRrVaXUFdSyVeWz1GvZZLJU9PzwBJTF@99n8tF5ehnp4ZUFRNJU1BJd5aQR0oCgA "PowerShell – Try It Online")
Will look into making it so it only goes through the range once. Not bad for the no brain method though.
[Answer]
# Twig, 115 bytes
Builds the string backwards, "returning" it in the end.
Uses a macro to generate all the results.
```
{%macro a(N,s="")%}{%for i in N..1%}{%set s=('%'~i~'s
'~s~'%'~i~'s
')|format('\\','/')%}{%endfor%}{{s}}{%endmacro%}
```
This macro has to be in a file, and imported like this:
```
{% import 'macro.twig' as a %}
{{ a.a(<value>) }}
```
You can try it on <https://twigfiddle.com/5hzlpz> (click on "Show raw result").
[Answer]
# [Haskell](https://www.haskell.org/), ~~52~~ 49 bytes
-3 bytes thanks to [Sriotchilism O'Zaic](https://codegolf.stackexchange.com/users/56656/sriotchilism-ozaic).
```
unlines.g
g 0=[]
g n="\\":map(' ':)(g$n-1)++["/"]
```
[Try it online!](https://tio.run/##y0gszk7Nyflfraus4OPo5x7q6O6q4BwQoKCsW8vFlZuYmadgq5CSz6WgUFBaElxS5JOnoKKgZGSlhCqSpmCEpsQUU4kpF1ca0LSY/6V5OZl5qcV66VzpCga20bFAKs9WKSZGySo3sUBDXUHdSlMjXSVP11BTWztaSV8p9v9/AA "Haskell – Try It Online")
[Answer]
# [Pyth](https://github.com/isaacg1/pyth), 19 bytes
```
VQ+*dN\\)V_Q+*dhN\/
```
[Try it online!](https://tio.run/##K6gsyfj/PyxQWyvFLyZGMywexMrwi9H//98YAA)
TIL multiplying a string by a negative value multiplies it by its absolute value.
[Answer]
# [Python 3](https://docs.python.org/3/), ~~90~~ 83 bytes
```
lambda n:'\n'.join([' '*i+'\\'for i in range(n)]+[' '*(n+~i)+'/'for i in range(n)])
```
[Try it online!](https://tio.run/##bcrBDkExEEbhvaeY3cyokEZsbnKfRC0qlBH@Nk0tRHj1CgsLsf3OKbd2zFj2NIZ@jpftLhIGDuD5KRtkzcRTcxwCp1zJyEA14rAX6MZ9qsA9TR0v/hzaf8zPvDM0MZRrE1UdJlTqWxJjvNuD9Qtiqt2vXg "Python 3 – Try It Online")
-7 bytes thanks to @squid
[Answer]
# Rockstar, 133 bytes
Try it online [here](https://codewithrockstar.com/online)!
```
F takes N,S
If N is 0
Give back N
Say S+"\"
Let T be S+" "
Let M be N-1
F taking M,T
Say S+"/"
Listen to X
F taking X,""
```
Since Rockstar is not famous for string operations, it takes relatively lots of code to do it (recursively was even longer).
The size of the arrow is taken as input.
[Answer]
# [PHP](https://php.net/), ~~79~~ ~~63~~ 61 bytes
```
function f($x,$s=''){if($x)echo"$s\\
",f($x-1,"$s "),"$s/
";}
```
[Try it online!](https://tio.run/##K8go@G9jXwAk00rzkksy8/MU0jRUKnRUim3V1TWrM0EczdTkjHwlleKYGC4lHZCArqEOkKugpAmi9LmUrGv/p2koqCQWpZdFG8YqaFr//28KAA "PHP – Try It Online")
Recursive in PHP.
### *-12 bytes* by [@manatwork](https://codegolf.stackexchange.com/questions/186548/ascii-meme-arrow-generator/187012#comment448006_187012)
[Answer]
# [\/\/>](https://github.com/torcado194/worm), 74 bytes
```
jp100o
-84*}!o:?!x1
@+:q:p=?x:o~$:0(pa"\/"q?$~}}:
x2-:p$1-y$:0(?
.{suh?!;2
```
**Explanation:** (lines rotated based on start point)
```
jp100o //setup
:?!x1-84*}! //add leading spaces, loop and decrement until 0
~$:0(pa"\/"q?$~}}:@+:q:p=?x:o //add correct slash, go back to loop or switch sides
$:0(?x2-:p$1-y //flip direction state or continue to print
{suh?!;2. //remove extra data and print stack
```
[Answer]
# [Python 3](https://docs.python.org/3/), 55 bytes
```
f=lambda n,i="":n and i+"\\\n"+f(n-1,i+" ")+i+"/\n"or""
```
[Try it online!](https://tio.run/##K6gsycjPM/7/P802JzE3KSVRIU8n01ZJySpPITEvRSFTWykmJiZPSTtNI0/XUAfIVVDS1AZS@kDB/CIlpf8FRZl5JRppGoaamlwwthES2xiJbWigqfkfAA "Python 3 – Try It Online")
[Answer]
# [Erlang (escript)](http://erlang.org/doc/man/escript.html), 69 bytes
Port of xnor's Python answer.
```
r(0,_)->"";r(I,X)->X++"\\\n"++r(I-1,X++" ")++X++"/\n".
r(I)->r(I,"").
```
[Try it online!](https://tio.run/##Sy3KScxL100tTi7KLCj5z/W/SMNAJ15T105JybpIw1MnAsiM0NZWiomJyVPS1gYK6RrqgAQUlDS1tUEMfaCEHhdQAqgSpENJSVPvf25iZp5GdKymgq6dQma@VVp5UWZJqkaRhqkmUBIA "Erlang (escript) – Try It Online")
]
|
[Question]
[
First line is made with `ceil(n/2)` elements where each element is: `<space><odd-number><space>`
Second line is made with `ceil(n/2)` elements, but each element is `/ \` only.
You may assume `n >= 0` and `n <= 10`.
### Examples
Input: 3
```
1 3
/ \/ \
```
Input: 10
```
1 3 5 7 9
/ \/ \/ \/ \/ \
```
---
Example in Python 3, 103 bytes:
```
lambda a:print("".join([" "+str(i)+" "for i in range(1,a+1,2)]+["\n"]+["/ \\"for i in range(1,a+1,2)]))
```
Shortest code in bytes wins :)
[Answer]
# [05AB1E](http://github.com/Adriandmen/05AB1E), ~~19~~ ~~15~~ ~~14~~ 12 bytes
05AB1E uses [CP-1252](http://www.cp1252.com) encoding.
Saved 4 bytes thanks to *Adnan*.
Saved 2 bytes thanks to *carusocomputing*
```
ÅÉðìDg…/ \×»
```
[Try it online!](http://05ab1e.tryitonline.net/#code=w4XDicOww6xEZ-KApi8gXMOXwrs&input=MTA)
**Explanation**
```
ÅÉ # list of uneven number up to input
ðì # prepend a space to each
Dg # get length of list
…/ \ # push the string "/ \"
× # repeat the string length-list times
» # join rows by spaces and columns by newlines
```
[Answer]
## Pyke, 16 bytes
```
S2%idm+dJil*"/ \
```
[Try it here!](http://pyke.catbus.co.uk/?code=S2%25idm%2BdJil%2a%22%2F+%5C&input=10)
### 17 bytes and more awesome
```
S2%i`~Bd.:il*"/ \
```
[Try it here!](http://pyke.catbus.co.uk/?code=S2%25i%60%7EBd.%3Ail%2a%22%2F+%5C&input=10)
This uses IMHO an AWESOME algorithm for making sure the first line is correctly aligned.
```
S - range(1, input+1)
2% - ^[::2]
i - i = ^
` - str(^)
~Bd.: - ^.translate("><+-.,[]", " ") <-- awesome bit here
il - len(i)
*"/ \ - ^ * "/ \"
```
This replaces all the characters in the stringified list with spaces. `~B` contains all the characters in the Brain\*\*\*\* language and this is the first time I've used this variable.
The program ``~Bd.:` does this:
```
`~Bd.: - input = [1, 3, 5, 7]
` - str(input) # stack now ["[1, 3, 5, 7]"]
~B - "><+-.,[]" # stack now ["[1, 3, 5, 7]", "><+-.,[]"]
d - " " # stack now ["[1, 3, 5, 7]", "><+-.,[]", " "]
.: - translate() # stack now [" 1 3 5 7 "]
```
[Answer]
## Python 2, 63 bytes
```
lambda n:' '.join(n%2*`n`for n in range(n+1))+'\n'+-~n/2*'/ \\'
```
Little trick for the first line: it don't print the even numbers, but take them as an empty string, which leads to starting empty space (0 would be there), and double spaces between the numbers without any modification on the range, the downside is a leading space in the even numbered `n`
[Answer]
# Python ~~2~~ 3, ~~67~~ ~~65~~ ~~63~~ 60 Bytes
Nothing too crazy here, ~~I think the first section can probably be done shorter but I'm not quite sure how~~. I use the fact that in this case `-~n/2` will work for `ceil`.
```
lambda n:-~n//2*' %d '%(*range(1,n+1,2),)+'\n'+-~n//2*'/ \\'
```
Below are alternative 61 and 65 byte solutions in Python 2:
```
lambda n:-~n/2*' %d '%tuple(range(1,n+1,2))+'\n'+-~n/2*'/ \\'
lambda n:' '+' '.join(map(str,range(1,n+1,2)))+'\n'+-~n/2*'/ \\'
```
*Thanks to Rod for saving 2 bytes and Artyer for saving another byte by switching version :)*
[Answer]
## JavaScript (ES6), 55 bytes
```
f=n=>n%2?f(n-1).replace(`
`,` ${n}
/ \\`):n?f(n-1):`
`
```
```
<input type=number min=1 max=10 oninput=o.textContent=f(this.value)><pre id=o>
```
Note the space on the end of the second line.
[Answer]
## Python 2, 53 bytes
```
lambda n:" 1 3 5 7 9"[:-~n/2*3]+'\n'+-~n/2*"/ \\"
```
Takes advantage of the restriction `n <= 10` to generate the top line by chopping off a piece from a hardcoded string.
The outputs for 1 to 10 are
```
1
/ \
1
/ \
1 3
/ \/ \
1 3
/ \/ \
1 3 5
/ \/ \/ \
1 3 5
/ \/ \/ \
1 3 5 7
/ \/ \/ \/ \
1 3 5 7
/ \/ \/ \/ \
1 3 5 7 9
/ \/ \/ \/ \/ \
1 3 5 7 9
/ \/ \/ \/ \/ \
```
The output for 0 is two empty lines.
[Answer]
# Vim, ~~73~~ ~~59~~ 56 bytes
This is a really high byte count IMO for what seems like a simple problem. I feel like I'm missing something obvious.
```
caw="/2*2
caw1357911/"
DYp:s;.;/ \\;g
k:s// & /g
```
[Try it online!](http://v.tryitonline.net/#code=AWNhdxI9EiIvMioyChsBY2F3MTM1NzkxMRsvEiIKRFlwOnM7LjsvIFxcO2cKazpzLy8gJiAvZwo&input=Ng)
Unprintables:
```
^Acaw^R=^R"/2*2 # Transform a number into the next odd number (3->5,4>5)
^[^Acaw1357911^[/^R" # Insert 1357911, delete everything after the number above
DYp:s;.;/ \\;g # Duplicate the line, replace numbers with / \
k:s// & /g # On the line above, add spaces around numbers
<trailing newline>
```
[Answer]
# Mathematica, 65 bytes
```
" "<>Range[1,#,2]~StringRiffle~" "<>"
"<>"/ \\"~Table~⌈#/2⌉&
```
Anonymous function. Takes a number as input and returns a string as output. The Unicode characters, respectively, are U+2308 LEFT CEILING for `\[LeftCeiling]` and U+2309 RIGHT CEILING for `\[RightCeiling]`.
[Answer]
# WinDbg, 100 bytes
```
.echo;.for(r$t1=1;@$t1<=2*@$t0+@$t0%2;r$t1=@$t1+2){j@$t1<=@$t0 .printf"\b %d \n",@$t1;.printf"/ \\"}
```
Input is done by setting a value in the pseudo-register `$t0`.
Looks like it's shortest here just to print the string as it's being built rather than try to build it first and display the whole thing. I'd have a shorter solution if WinDbg would let me write to address `0`.
How it works:
```
.echo; * Print a new line that'll be deleted
.for(r$t1=1; @$t1 <= 2*@$t0+@$t0%2; r$t1=@$t1+2) * Enumerate 1 to 4*ceil($t0/2), count by 2
{
j@$t1<=@$t0 * If $t1 <= $t0...
.printf"\b %d \n",@$t1; * ...Print $t1 (and newline for last n)
.printf"/ \\" * ...Else print the / \'s
}
```
Output for each value of `n`:
```
0:000> .for(r$t0=0;b>@$t0;r$t0=@$t0+1){.printf"\n\nn=%d\n",@$t0; .echo;.for(r$t1=1;@$t1<=2*@$t0+@$t0%2;r$t1=@$t1+2){j@$t1<=@$t0 .printf"\b %d \n",@$t1;.printf"/ \\"}}
n=0
n=1
1
/ \
n=2
1
/ \
n=3
1 3
/ \/ \
n=4
1 3
/ \/ \
n=5
1 3 5
/ \/ \/ \
n=6
1 3 5
/ \/ \/ \
n=7
1 3 5 7
/ \/ \/ \/ \
n=8
1 3 5 7
/ \/ \/ \/ \
n=9
1 3 5 7 9
/ \/ \/ \/ \/ \
n=10
1 3 5 7 9
/ \/ \/ \/ \/ \
```
[Answer]
# ><> (FISH), ~~69~~ ~~60~~ ~~68~~ 55 bytes
```
5|v&+%1:,2
1->:?!v:
8~v!?l<on$o:*4
a&/o
1->:?!;"\ /"ooo
```
[Paste it into this online interpreter!](https://fishlanguage.com/playground)
The number 5 on the first line is your input value (hard coded as 5, replaced by 0-a or i for user input).
Edit 1: Moved new line placement into the first line space (was empty) to save 9 bytes overall on space from a new line.
Edit 2: As noted by user7150406 the output was wrong (no spaces printing) this has been fixed with a loss of 8 bytes.
Edit 3: completely changed the logic, there is no point checking if the number is odd - rather put all numbers on the stack and remove every second one. Byte saved 13!
[Answer]
# Java, 118 112 Bytes
*Edit: Saved 6 Bytes thanks to @peech*
Golfed:
```
String M(int n){String o=" ";int i=1;n+=1;for(;i<n;i+=2)o+=i+" ";o+="\n";for(i=0;i<n/2;i++)o+="/ \\";return o;}
```
Ungolfed:
```
public String M(int n)
{
String o = " ";
int i=1;
n += 1;
for (; i < n;i+=2)
o += i + " ";
o += "\n";
for (i = 0; i < n/2; i++)
o += "/ \\";
return o;
}
```
Testing:
```
OddMountains om = new OddMountains();
System.out.println(om.M(1));
System.out.println();
System.out.println(om.M(3));
System.out.println();
System.out.println(om.M(5));
System.out.println();
System.out.println(om.M(7));
System.out.println();
System.out.println(om.M(10));
1
/ \
1 3
/ \/ \
1 3 5
/ \/ \/ \
1 3 5 7 9
/ \/ \/ \/ \/ \
```
[Answer]
# C#6, 95 bytes
```
n=>{var o="";int i=1;for(;i<=n;i+=2)o+=$" {i} ";o+='\n';for(i=1;i<=n;i+=2)o+="/ \\";return o;};
```
Full lambda:
```
Func<int, string> a = n=>
{
var o="";int i=1;
for(;i<=n;i+=2)
o+=$" {i} ";
o+='\n';
for(i=1;i<=n;i+=2)
o+="/ \\";
return o;
};
```
[Answer]
# CJam, ~~26~~ 23 bytes
```
Sri,:)2%_S2**N@,"/ \\"*
```
[Test it!](//cjam.aditsu.net#code=Sri%2C%3A)2%25_S2**N%40%2C%22%2F%20%5C%5C%22*&input=10)
*-3 thanks to 8478 (Martin Ender)*
[Answer]
## Game Maker Language (GM 8.0), 97 bytes
```
m=ceil(argument0/2)e=""for(i=1;i<2*m;i+=2)e+=" "+string(i)+" "return e+"#"+string_repeat("/ \",m)
```
Given that the input is at most 10, `chr(48+i)` will work in place of `string(i)`, although the number of bytes is the same.
Readable:
```
m = ceil(argument0/2)
e = ""
for (i = 1; i < 2*m; i += 2 )
e += " " + string(i) + " "
return e + "#" + string_repeat("/ \", m)
```
[Answer]
# Pyth, ~~24~~ 22 bytes
```
K-SQyMS5+dj*2dK*lK"/ \
```
*Thanks to 42545 (ETHproductions) for -1 byte*
[Online interpreter](//pyth.herokuapp.com?code=K-SQyMS5%2Bdj%2a2dK%2alK%22%2F+%5C)
[11 test cases](//pyth.herokuapp.com?code=K-SQyMS5%2Bdj%2a2dK%2alK%22%2F+%5C&test_suite=1&test_suite_input=0%0A1%0A2%0A3%0A4%0A5%0A6%0A7%0A8%0A9%0A10)
[Answer]
## ><> (Fish) ~~52~~ ~~63~~ 62 bytes
```
<v!?:-1:!?-1%2:
>~la}}" "72.
v!?-2lno<o" "
o
>:?!;"\ /"ooo1-
```
[Try it online!](https://fishlanguage.com/playground/DyA4LoRgBNpqBdTS3)
To use simply place `n` on the stack and away you go!
Much of this is taken from @Teal-Pelican's answer :).
Edit: The output is actually not aligned correctly in either ><> submission! Fixing...
Edit2: I had to sacrifice some bytes, but the output is actually correct now.
Edit3: No more fun with `\` `/` mirrors and I save 1 byte.
**Output:**
```
1 3 5 7 9
/ \/ \/ \/ \/ \
```
[Answer]
# C, ~~100~~ ~~79~~ 77 bytes
```
#define P(s)for(i=0;i++<n;printf(s,i++));puts("");
i;f(n){P(" %d ")P("/ \\")}
```
[Answer]
# R, ~~70~~ ~~69~~ ~~68~~ 58 bytes
```
cat(paste("",z<-seq(,scan(),2)),"\n");for(i in z)cat("/ \\")
3:
#> 1 3
#> / \/ \
10:
#> 1 3 5 7 9
#> / \/ \/ \/ \/ \
```
[Answer]
# Bash, ~~64~~, ~~59~~, ~~57~~, ~~51~~, ~~49~~, ~~48~~, 45 bytes
EDIT:
* minus 3 bytes (use $1 instead of STDIN)
* one more byte off by replacing `-s ""` with `-s\`
* minus 2 bytes by replacing *printf* with *seq -f* (Thanks @Adam!)
* refactored to script instead of function (to beat the **><>**)
* removed superfluous spaces
* optimized the *sed* expression a bit
**Golfed**
Chunk (45 byte):
```
seq -f" %g " -s\ 1 2 $1|sed 'p;s| . |/ \\|g'
```
Function (original version) (57 bytes):
```
M() { printf " %s %.0s" `seq 1 $1`|sed 'p;s| . |/ \\|g';}
```
**Test**
```
--- mountains.sh ----
#!/bin/bash
seq -f" %g " -s\ 1 2 $1|sed 'p;s| . |/ \\|g'
>./mountains.sh 10
1 3 5 7 9
/ \/ \/ \/ \/ \
>M 10
1 3 5 7 9
/ \/ \/ \/ \/ \
```
[Answer]
# [Befunge 93](http://esolangs.org/wiki/Befunge), 64 bytes
[Try it Online!](http://befunge-98.tryitonline.net/#code=ICY2MXAxICAgdisyLCwsIi8gXCIKX3YjIWAiICI6PCsyLiwiICI6CiA8XnAwMHAxMCJ8PCIKQCA-OTErLCQxdg&input=OQ)
```
&61p1 v+2,,,"/ \"
_v#!`" ":<+2.," ":
<^p00p10"|<"
@ >91+,$1v
```
[Answer]
# Ruby ~~82~~ 60 Bytes
Quick and dirty Ruby solution could definitely be better optimized if I was better with Ruby
```
puts "",1.step($*[0].to_i,2).map{|x|$><<" #{x} ";"/ \\"}*""
```
Usage: prog.rb 10
Output:
```
1 3 5 7 9
/ \/ \/ \/ \/ \
```
edit: numerous edits and optimisations by @Manatwork!
[Answer]
# JavaScript (ES6), ~~66~~ 64 bytes
```
n=>(f=n=>n?f(n-1)+(n%2?n+s:s):s=" ")(n)+`
`+"/ \\".repeat(++n/2)
```
Recursively builds the first line, then appends the second. The first line is built with the observation that it's simply the range **[0...n]** with each item **n** transformed to a space if even, or **n** concatenated with a space if odd.
[Answer]
# Python 2, 60 bytes
Saved 6 bytes thanks to @Kade!
```
lambda s:" "+" ".join(`range(s+1)`[4::6])+"\n"+-~s/2*"/ \\"
```
[Answer]
## Batch, 107 bytes
```
@set s=
@set t=
@for /l %%i in (1,2,%1)do @call set s=%%s%% %%i&call set t=%%t%%/ \
@echo%s%
@echo %t%
```
[Answer]
# Scala, 99 95 Bytes
```
(? :Int)=>for(i<-0 to 1)println(1 to ?filter(c=>c%2>0)map(c=>if(i<1)s" $c "else"/ \\")mkString)
```
Ungolfed
```
(? :Int) =>
for (i<-0 to 1)
println(
1 to ?filter(c=>c%2>0)
map(c=>if(i<1)s" $c "else"/ \\")
mkString
)
```
[Answer]
# Ruby, 48 bytes
```
->x{" 1 3 5 7 9 "[0..3*x-=x/2]+?\n+"/ \\"*x}
```
[Answer]
# Octave, 45 bytes
`f=@(n)reshape(sprintf(' /%d \',1:2:n),2,[]);`
Test:
f(8)
```
1 3 5 7
/ \/ \/ \/ \
```
[Answer]
## [QBIC](https://drive.google.com/drive/folders/0B0R1Jgqp8Gg4clFlNEYwWGxEVnc), 35 bytes
```
:[1,a,2|X=X+!b$+@ | Y=Y+@/ \|]?X ?Y
```
Explanation:
```
: gets a CMD line param as INT 'a'
[1,a,2| FOR b = 1 to a STEP 2
X=X+!b$+@ | Add to X$ the counter of our FOR loop and a trailing space
Leading space is provided by the cast-to-string function.
Y=Y+@/ \| Add to Y$ the mountain.
] Close the first possible language construct (IF, DO or FOR). In this case: NEXT
?X ?Y Print X$, Print Y$. The space adds a newline in the resulting QBASIC.
```
[Answer]
# [Kitanai](http://esolangs.org/wiki/Kitanai), 140 bytes
```
$0[0]$1[int(input":")]$2[""]$3[""]$0#?(mod@2)($2[add(add(@" ")(string($0@)))" "]
$3[add@"/ \"])?(neq@($1@))([add@1]&1)print($2@)print($3@)%
```
[Answer]
# Perl, 46 + 2 (`-pl` flag) = 48 bytes
```
@_=map$_%2?$_:"",0..$_;$_="@_$/"."/ \\"x(@_/2)
```
Using:
```
perl -ple '@_=map$_%2?$_:"",0..$_;$_="@_$/"."/ \\"x(@_/2)' <<< 7
```
Or 52 bytes:
```
@_=map$_%2?$_:"",0..pop;print"@_$/","/ \\"x(@_/2),$/
```
Using:
```
perl -e '@_=map$_%2?$_:"",0..pop;print"@_$/","/ \\"x(@_/2),$/' 7
```
]
|
[Question]
[
Here is an easy-intermediate challenge for anyone interested!
# What is that?
A thing me and brother do a bit too often is this:
One of us has a problem and asks the other to explain how to do certain stuff. The other just says the following carelessly:
```
How to <verb> in <n> easy steps!
(Newline mandatory)
Step 1 - Do not <verb>.
Step 2 - Do not <verb>.
Step 3 - Do not <verb>.
.
.
.
Step <n> - <verb>. (Capitalised)
```
For example, if my brother could not find a pen to write with (Do not ask me why) and asked `How do I find a pen?`, I would probably answer:
```
How to find a pen in 10 easy steps!
Step 1 - Do not find a pen.
Step 2 - Do not find a pen.
Step 3 - Do not find a pen.
Step 4 - Do not find a pen.
Step 5 - Do not find a pen.
Step 6 - Do not find a pen.
Step 7 - Do not find a pen.
Step 8 - Do not find a pen.
Step 9 - Do not find a pen.
Step 10 - Find a pen.
```
Sarcasm alert!
Now isn't that ***so*** accurate and helpful!
`<verb>` is the problem one of us wants to achieve.
`<n>` is a random number that we choose (for your information, we mostly use 10 as `<n>`, but that is not important for this challenge).
# So what?
Your challenge is to write a usual program or function using standard I/O and golfing rules that takes in a string formatted with `"How do I <v>?"` as input, and then print or return the (accurate) how-to article specified according to the rules displayed above, where `<verb>` is `<v>` from the input, and `<n>` is any random natural number from the range 1 to 10 (inclusive) generated by your program. When `<n>` is 1, remove the ending s in `...steps!`.
Standard loopholes are not allowed!
---
*Note: There might be some cases where sentences will be illogical, like in the case of `How do I find my pen?`. Outputting `How to find my pen in <n> easy steps` is fine!*
---
Here is another example for further clarity:
Input -
```
How do I make coffee?
```
*Example* output -
```
How to make coffee in 3 easy steps!
Step 1 - Do not make coffee.
Step 2 - Do not make coffee.
Step 3 - Make coffee.
```
## Good luck!
[Answer]
# LaTeX, 269 bytes
```
\input tikz.tex\let\s\pgfmathsetmacro\pgfmathsetseed{\number\pdfrandomseed}\def\u#1{\uppercase{#1}}\def\f
How do I #1?{\s\n{random(0,9)}\s\m{int(\n+1)}How to #1 in \m~easy
step\ifnum\m>1s!\\\\\foreach\i in{1,...,\n}{Step \i~- Do not #1.\\}\else!\\\\\fi
Step \m~- \u#1.}
```
Random numbers aren't very nice to handle in LaTeX.
Example output:
[](https://i.stack.imgur.com/tzbyr.png)
[Answer]
# [Bash](https://www.gnu.org/software/bash/) + [coreutils seq](https://www.gnu.org/software/coreutils/manual/html_node/seq-invocation.html), 128
* Thanks to @NahuelFouilleul for some good golfing suggestions.
```
v=${1:9}
v=${v%?}
s=s
echo "How to $v in $[m=(n=$$%10)+1] easy step${s::n}!
`seq -f"Step %g - Do not $v." $n`
Step $m - ${v^}."
```
[Try it online!](https://tio.run/##HY3BCoJAFEX38xW34QlFKLlMGNy0qHXLKLSc0oVvjCdGyHz7NLa73APn3GtpQ5gMzXmx92oZU1J6JUaUfbQO@ug@GB1oQsegS2/WbIiSfLfZ5lfYWr6Q0Q40S1GwXylViX0jfepzfJG8kOLgwG6MikyDuFJ/Qn0ksXbzmQ4hLJnG4YRnxw1qDJbLHw "Bash – Try It Online")
[Answer]
# [APL (Dyalog Extended)](https://github.com/abrudz/dyalog-apl-extended), 99 bytes
Full program. Prompts for string from stdin.
```
∊'How to'(¯1↓v←8↓⌽'.'@1⌽⍞)' in'n'easy step','s!'↓⍨1=n←?10
⍬
{∊'Step'⍵'- Do not'v}⍤0⍳n-1
∊'Step'n'-',⌈@2⊢v
```
[Try it online!](https://tio.run/##SyzI0U2pTMzJT9dNrShJzUtJTfn/qKO9AEh0qXvklyuU5KtrHFpv@KhtctmjtgkWQPpRz151PXUHQyD9qHeeprpCZp56nnpqYnGlQnFJaoG6jnqxojpIXe8KQ9s8oCZ7QwOuR71ruKpBZgaDlDzq3aquq@CSr5CXX6JeVvuod4nBo97NebqGXHAleeq66jqPejocjB51LSoDuem/AhgUcIGclZKv4KmQlpmXopCoUJCaZ8@lq6vLhaEgNzE7VSE5Py0tNdUeAA "APL (Dyalog Extended) – Try It Online")
`∊` **ϵ**nlists (flattens) the list of components of each line. By default, numbers are printed with one spaces between them and adjacent text. Lines are implicitly printed.
The variable parts are:
### `,'s!'↓⍨1=n←?10`
`?10` random number in range 1–10
`n←` assign to `n`
### `¯1↓v←8↓⌽'.'@1⌽⍞`
`⍞` prompt for string
`⌽` reverse
`'.'@1` replace the character **at** index 1 with a period.
`⌽` reverse
`8↓` drop the first 8 characters ("How do I")
`v←` assign to `v`
`¯1↓` drop the last character (".")
### `⍬`
`⍬` empty numeric list (prints as empty line)
### `{`…`⍵`…`}⍤0⍳n-1`
`n-1` subtract 1 from `n`
`⍳` indices 1–(n−1)
`{`…`}⍤0` merge into a matrix the results from applying the following lambda on each element:
`⍵` the argument (current index)
### `'Step'n'-',⌈@2⊢v`
`⊢v` on `v`…
`⌈@2` uppercase the second character (there's a leading space in `v`)
…`,` prepend the components
[Answer]
# [C (gcc)](https://gcc.gnu.org/), 186 bytes
```
n;f(m){char*s;scanf("%m[^?]",&s);for(printf("How to%s in %d easy step%s!\n\n",memcpy(++s," Do not",7)+7,m=++n,"s"+!(n=time()%10));n--;printf("Step %d -%s.\n",m-n,(n||(1[s+=7]^=32),s)));}
```
[Try it online!](https://tio.run/##NY7NagMhFEZf5UawaNXSNItZyJBNF@m6y/yAOJoK9TrMlYSQ5NVrJ4VuPzjnfN4cvW8NbRRZXv2Xm57JkncYBeN5e1jvmX4iaWOZxDglrPO@KWeohRMkBD5AcHQBqmHktNjhDpnOIfvxIpQizeC9AJbKdCdVp3OvFGpGTC0E9jXlICRfvkpp0Rj7H/icZQ@z4fTy5zOoBd5uYrkl1Xf7Q796k5rkjN3bjEB2CcWppEHCFaKQFu7t8XIo8AEx4QAOxoDrHx@/3ZGaOf8C "C (gcc) – Try It Online")
*+14 bytes due to removing the last `s` in `...steps!` when `n=1`*
*-2 bytes by using `lseek`*
*-2 bytes by changing conditions*
*-1 byte by removing a space `m- --n` → `m-n--`*
*-3 bytes thanks to **Arnauld***
*-1 byte by changing the last condition from `n+1` to `!n`*
*-31 bytes thanks to **ErikF***
*-2 bytes by removing `s` in `%m[^?]s` and by removing space in `"Do not "`*
*-2 bytes thanks to **ceilingcat***
*-1 byte thanks to **ErikF***
[Answer]
# [Ruby](https://www.ruby-lang.org/) `-p`, ~~141~~ ~~140~~ ~~137~~ 131 bytes
*Saved 3 bytes by using `$$%10` instead of `rand(10)`, a golf suggested by @NahuelFouilleul in comments on other answers.*
```
$_="How to #{v=$_[9..-2]} in #{n=1+$$%10} easy ste#{:ps[0,n]}!
"+(1..n).map{|i|"
Step #{i} - #{i<n ?'Do not '+v:v.capitalize}."}*''
```
[Try it online!](https://tio.run/##FY5BC4IwGEDv/oqvuVhlDu2WJF461LmjiCybMMpttGWY7q@37PTgwYP3fF0H73Gdo5N6g1UQjn2O63JPabyrHAg5G5mnEcbLNHHAmRnAWB6OmTZlspWVWwQoWqWUyjXtmB4nMaHgYrmeQ@Eg/uMgoSBHBVJZIFGf9bRhWlj2EB/uKHIbQrz/D9wUnKFjdw6NalvOi6/SVihpfKx/ "Ruby – Try It Online")
[Answer]
# Scala, ~~195~~ 188 bytes
* Saved 7 bytes thanks to [@corvus\_192](https://codegolf.stackexchange.com/users/46901/corvus-192)
```
q=>{val(r,s"How do I $v?")=(math.random*10).toInt+1->q
1 to r-1 map{i=>s"Step $i - Do not $v."}mkString(s"How to $v in $r easy ste${"ps"take r}!\n\n","\n",s"\nStep $r - ${v.capitalize}.")}
```
Here it is in [Scastie](https://scastie.scala-lang.org/RKyIhY0vRKaWs8y4mz9viw), but double newlines don't work there for whatever reason.
[Equivalent version](https://tio.run/##JY4xT8MwFIT3/IqH5cGBxCIjSAmqxEAHpq5dXhMHTJNn134ESpTfHtx2Oel0uu8utjjg6g5fpmV4R0tgftlQF2Hj/ZxNOED/DDsOlj6gbmBDZ6jXU93MKVKhmPJajcifOiB1bryvHnPNbkv8UJXNScfvQ7x21VORnP0zZZVnFbCDUFYwop9t3USxY@NBWijh1QE5BjlpsYzH27CK4s39XEpygnRRBjAYzxDZyFn4KBiPBsJyt6c9iUJcJCa9UUOiynnSLXrLOKQPixb5svqE5oFUr670zsEWeksdIHhDLyLPs2X9Bw) with newlines in TIO (modified for Scala 2.10)
[Answer]
# JavaScript (ES6), 159 bytes
```
s=>(g=i=>i?g(i-1)+`
Step ${i} - ${i-n?'Do not'+s:s[1].toUpperCase()+s.slice(2)}.`:`How to${s=s.slice(8,-1)} in ${n} easy step${n>1?'s':''}!
`)(n=new Date%10+1)
```
[Try it online!](https://tio.run/##Nc0xa8MwEAXg3b/iGlIk4dhUnYpB9pAMzRwylYKFcjZKHJ3JiYQS9Nsde@j0eDz43tneLbubH2MR6IRTZyY2teyNN7VveukLrfI2O0QcYf30CYolitCIHUGgKHKu@Ef/lpGO44i3rWWUKueSB@9QfqpUtlX7TQ@ItH6y@R@@NjOcwIeZCwnQ8h/wfDK3WjeCRSVEestaJYMJ@ICdjfiuP3KtJkeBacByoF52crXYJ4I9XO0FwVHXITYrpaYX "JavaScript (Node.js) – Try It Online")
[Answer]
# [C# (Visual C# Interactive Compiler)](http://www.mono-project.com/docs/about-mono/releases/5.0.0/#csc), 180 bytes
```
s=>{int y=new Random().Next(10)+1,i=0;for(Write($"How to{s=s[8..^1]} in {y} easy step{(y<2?"":"s")}!\n");i++<y;)Write($"\nStep {i} - {(i<y?$"Do not"+s:(char)(s[1]^32)+s[2..])}.");}
```
-1 byte thanks to Dominic van Essen
+13 bytes due to having to remove the "s" in steps if the random number = 1.
-2 bytes due to Julian
-2 bytes due to Neil
[Try it online!](https://tio.run/##NY6xasMwFAD3fsWryCChRsTuUmIrptChXTq0QwfHAWPLyRv6FPwEqRD6dtcUOt9x3MDbgXF5HgJ6qjnMSOfDZBe2h4QUIFpyN/joafTfUpl39xNksVO6eEC7qyY/y68Zg5Mb8epvEHxiy@2TMaeiy4AEKWZwPUfg4K5JxrpshNgLFirfH0moCrWuY6X@K0f6XEVImGELSWIdm4148UA@CM17OVz6WUlui@70WCrNbWlMp7JZS3mp7ib59zF6eIMJaYQero6alS6/ "C# (Visual C# Interactive Compiler) – Try It Online")
[Answer]
# [PowerShell Core](https://github.com/PowerShell/PowerShell), 188 bytes
```
$q=$args.Substring(8,"$args".Length-9)
$r=(Random 10)+1
"How to$q in $r easy step$(('s','')[$r-eq1])!`n"
1..$r|%{"Step $_ - "+("Do not$q.","$($q[1]|% t*g|% tou*t)$($q|% s*g 2).")[$_-eq$r]}
```
Line by line
1. Isolates the task `make coffee` with the initial space
2. Generates a random number in the range 1..10
3. Prints the title with an extra new line and the conditional s
4. Prints the steps
```
{"Step $_ - "
+("Do not$q.", # if it is not the last line
"$($q[1]|% t*g|% tou*t)$($q|% s*g 2))." # if if is the last line, first char uppercase and the rest of the string
)[$_-eq$r]} # "is it the last line" condition
```
[Try it online!](https://tio.run/##VU89b8IwFNz9K16fHo0diNV0aoeIpUMrdSojQmCIExDgR2wjVAG/PXXYupx0p9N9nPhifdjaw6HYsLc9NVDBtaeuIuPboGfndYh@51r5NsGHhPrbujZui3clyFfyx7iaj1C@qHEp8JMvEJk62DkgD9aEXwjRnkjKLGSTLFNz8oXtyoV6WjkUpdbkb6MrzpIJaAkF4FjiB4PjSJ3G1Cqpm5eL2whi3g7I5zyqQU0k5C28Ko0pdpliyS/u/V2I5/TjsaVm@IKj2VvYcNNYO0WBQ@9/g7emBgNr5v0U@/4P "PowerShell Core – Try It Online")
[Answer]
# [CJam](https://sourceforge.net/p/cjam), 92 bytes
```
"How to "q9>);:Q" in "Amr):T" easy step"T1>'s*'!NT{"
Step "U)" - "T(U=!"do not "*Q+(eu\'.}fU
```
[Try it online!](https://tio.run/##FcyxCsIwGEXh3ae4/Ze0FQVHK1bEQV2EYrK5hDa1lTRREykiPnuM6znw1Tc5hEAHO8Jb0GNZZquiIvQGtB2eWcEJSro3nFd34ouSuZwlJ/6hyTkWkMgIMxBPxTqhxsJYD8qraapeFzb/tiKEPx7PEWNUfdc77GyjsLe6Rd1JrZW5qs0P "CJam – Try It Online")
[Answer]
# [C (gcc)](https://gcc.gnu.org/), ~~194~~ ~~193~~ ~~192~~ ~~190~~ 189 bytes
Thanks to Petr Fiedler, Neil and ceilingcat for the suggestions.
By using the method in [Petr Fiedler's answer](https://codegolf.stackexchange.com/a/213626/98712), I don't have to use counted strings and store the first character. I've never used `sscanf` to create a copy of a string before, but it really works well. (Not needed here, but another neat thing about using the `scanf` family to get a string is that you can use the `%n` specifier to get the string length at the same time!)
```
i,j;f(char*s){sscanf(s,"%m[^?]",&s);for(printf("How to%s in %d easy step%s!\n",memcpy(s+=2,"Do not",6)+6,i=++j,"s"+!(j=time(0)%10));i--;printf("\nStep %d - %s.",j-i,(i||(*(s+=7)^=32),s)));}
```
[Try it online!](https://tio.run/##NY@xasMwFEX3fMWLQEWynkqaQDoYk6VDO3dsGhCK5MqtJONnGkKSX69qF7rdM5wD1@rW2lICdrUX9sMMFckLkTXJC0LG49th987wjmTt8yD6IaTRC/acTzBmThAS8CM4Q2eg0fWclvvEMLpo@7Mg1ayRPWVIeWS4lWqLoVGqQ0ZMLUXXjCE6sZL8YSVlHbSu//v79DrV5rQGTvcMOx1QhOtVVHP1UR6azVoiycm7lcmBaEIS8zBDaxHmK1BVE3xLuCwAvKiU@sN6cStlPnDM8DJ5nw4oRwc2e@/c7sf6L9NS0adf "C (gcc) – Try It Online")
## Original method: 194 bytes
So that I don't have to copy the string to uppercase the first character, I grab the first character of the phrase and then adjust the start of the string to the character after that. I then print up to the character just before the question mark to complete the phrase.
```
i,j,l,c;f(char*s){for(c=*(s+=9),printf("How to %c%.*s in %d easy step%s!\n\n",c,l=strlen(++s)-1,s,i=++j,"s"+!(j=time(0)%10));i--;printf("Step %d - %s%c%.*s.\n",j-i,i?"Do not ":"",c-32*!i,l,s));}
```
[Try it online!](https://tio.run/##NY89T8MwFEX3/ooXS5b8WbUwQRR1YYCZtUv0aqcOiV3lWVSo6l/HOCC2d4d7zrtoB8RSghnNZLD1As/9okjefFoEdkqQ7p6kuSwhZi/Ya7pCTsCRbxVBiMBP4Hr6Asruwqk5xmNkBs3UUV4mF4XWJO3ekAmd1qNhxHQjxi6H2Ymd5PudlG2wtv0XvFfOCrXA6c@yXYmjDSYc2EuCmDKwZ1Yl9vFBNaG@TZVxL7UPcx@iWI9@GdDAugWUquFTwm0D4IXS@je2m3sp65pTgrfa@3BAaXaAyXvnDt/op36gYq8/ "C (gcc) – Try It Online")
[Answer]
# [Python 2](https://docs.python.org/2/), 157 bytes
```
x=input()[9:-1]
n=id(0)%19/2+1
i=1
print'How to %s in %d easy ste%s!\n'%(x,n,'ps'[:n])
exec"print'Step %d -'%i,('Do not %s.'%x)[i/n*7:].capitalize();i+=1;"*n
```
[Try it online!](https://tio.run/##Jc2xDoIwEIDhnac4SZq2CmpdjBji4qCzIzIQOOJFvTa2xurLo8QH@P7fvcPF8moYYknsnkHpalPkpk64pE4ttTCbxWpmEipN4h7EQR7sC4IF4YEYRAfY@Df4gMJPziyFihln0nlZFVzrBCO26R@eAroR5FJQpuTeAtvw68yliLqiBU/XRT1vG0ehudEHld7SrDTbdMrDkI7bzsIR7s0VobV9j7hLvw "Python 2 – Try It Online")
`id(0)%19/2+1` is not uniform, but it has a nonzero chance of giving each number, unlike `id(0)%10+1`.
[Answer]
# [Perl 5](https://www.perl.org/) `-n`, 129 bytes
```
chop;/I /;say"How to $' in ",$b=0|1+rand 10," easy step",'s'x($b>1),"!
";say"Step $_ - ",ucfirst"Do not "x($b>$_).$',"."for 1..$b
```
[Try it online!](https://tio.run/##HY27DoIwFEB3v@J606QSS6EDE1EXBxmc/ADCoygJ6W3aGiXx263gfM7JsdpNRYzdg2yZVZCVvpnxQi8IBIzDaAAFaw/5R@1dY3pQuUDQjZ/BB21RcM/fO9YeVSJwu8F/flsIsBrSpX12w@h8wDOBoQD4l1mdSMYFShzIgZKStTGu056ggjutcz9pbU9fsmEk42N6LWSu8pia6Qc "Perl 5 – Try It Online")
[Answer]
# [Charcoal](https://github.com/somebody1234/Charcoal), ~~89~~ ~~85~~ ~~82~~ 80 bytes
```
≔✂S⁹±¹¦¹θ≔‽χηHow to θ in I⊕η easy step∧ηs¦!⸿F⊕η«⸿Step I⊕ι - ⭆⁺×Do not ‹ιηθ⎇λκ↥κ.
```
[Try it online!](https://tio.run/##dZAxT8MwEIXn5FdcM10kF9ERMaAKBioVhAhsXazkklhNbcc2oAr1twcnbpOoEoMH333vvbvLa25yxZuuW1srKolZI3LCjdRfLnNGyApTBncMXqnijnDlf/1r0/v4rHjnslAHXN36cu3Lb17lMHlWP@AUJGOlnXog5KzxyK3zibmhA0lHBdZpOmOJ2yNYR3pSrKWHGCQ2mYGLndmZnimVgWs/@I2jM5d5qyE9@ideDPEXHJYBFiXglqxF0a85GF6QJwVSuYBF07Jj/ybMFZ2AGkszZbjwC9fYMvggI7k5YsNgz@BTazI5t4T7NMwzugWv@NR1/Y0LBRsohSyAgyb5EHfL7@YP "Charcoal – Try It Online") Link is to verbose version of code. This feels ~~far too~~ long. Explanation:
```
≔✂S⁹±¹¦¹θ
```
Extract the verb from the input.
```
≔‽χη
```
Get a random number from 0 to 9, which represents the number of "Do not"s.
```
How to θ in I⊕η easy step∧ηs¦!⸿
```
Print the header, but only output the `s` if the random number wasn't 0 (1 step).
```
F⊕η«
```
Repeat for each step.
```
⸿Step I⊕ι -
```
Start a new line and print the part common to each step. (For the first step this double-spaces the list of steps from the header.)
```
⭆⁺×Do not ‹ιηθ⎇λκ↥κ
```
Except for the last step, prefix `Do not` to the verb. Uppercase the first letter of the result.
```
.
```
Finish the step with a `.`.
[Answer]
# [Python 3](https://docs.python.org/3/), ~~160~~ ~~170~~ ~~168~~ 167 bytes
```
p=print
a=input()[9:-1]
n=id(a)%99%10+1
s="Step %d - %%s."
p(f"How to {a} in {n} easy ste{'ps'[:n]}!\n")
for i in range(1,n):p(s%i%f"Do not {a}")
p(s%n%a.capitalize())
```
[Try it online!](https://tio.run/##FY2xCsIwFAD3fMUzEEzQFotTC8HFQWfH2iHYVB/oy6OJSC399mrX47jjIT0C7eeZLfdISTiLxO@kTV1WWdEIsthqZ1RZqmK3KUS08pI8g2ohA6ViLgXrTp7CB1KA0U2ABCNN4F0cICY/rjmu64qaaXUlaUQXesBF6h3dvS62ZCrWUaHq5DEAhbRU/uICSbn85hiTe@LXa2PmeTm1Ac7QIbXwGoA9HX4 "Python 3 – Try It Online")
[Answer]
# [05AB1E](https://github.com/Adriandmen/05AB1E/wiki/Commands), 74 [bytes](https://github.com/Adriandmen/05AB1E/wiki/Codepage)
```
TLΩÐD≠'s×sI8.$¨©“€ß€„ÿ€† ÿ‡šŠ¥ÿ!
“ˆG®N“Š¥ ÿ - Do€–ÿ.“ˆ}®™s“Š¥ ÿ -ÿ.“ˆ¯.ª»
```
[Try it online.](https://tio.run/##yy9OTMpM/f8/xOfcysMTXB51LlAvPjy92NNCT@XQikMrHzXMedS05vB8IPGoYd7h/WB6gQKQ0bDw6MKjCw4tPbxfkQuo6nSb@6F1fkAGSAwor6Cr4JIPVj358H49sILaQ@v0Dq0qRlYDkzq0HihzaPf//x755Qop@QqeCrmJ2akKyflpaamp9gA)
**Explanation:**
```
TL # Push a list in the range [1,10]
Ω # Pop and push a random value from this list
ÐD # Triplicate + Duplicate, so 4 copies are on the stack
≠ # Check if the top copy is NOT equal to 1 (0 if 1; 1 if [2,10])
's× '# Repeat "s" that many times
s # Swap so one random integer copy is at the top again
I # Push the input
8.$ # Remove the first 8 characters ("How do I")
¨ # Remove the last character ("?")
© # Store this verb in variable `®` (without popping)
“€ß€„ÿ€† ÿ‡šŠ¥ÿ!\n“ # Push dictionary string "how toÿ in ÿ easy stepÿ!\n",
# where the `ÿ` are filled with the top three values on the stack
# from left to right
ˆ # Pop and add this string to the global_array
G # Pop another random copy, and loop `N` in the range [1, n):
® # Push the verb from variable `®`
N # Push `N`
“Š¥ ÿ - Do€–ÿ.“ # Push dictionary string "step ÿ - Do not ÿ.",
# where the `ÿ` are filled with the top two values again
ˆ # Pop and add this string to the global_array
} # After the loop:
® # Push the verb again
.ª # Sentence capitalize it
s # Swap so another random integer copy is at the top of the stack
“Š¥ ÿ -ÿ.“ # Push dictionary string "step ÿ - ÿ.",
# where the `ÿ` are once again filled automatically
ˆ # Pop and push this string to the global_array as well
¯ # Then push the global_array
.ª # Sentence capitalize each string (without changing existing caps)
» # And join this list by newlines
# (after which the result is output implicitly)
```
[See this 05AB1E tip of mine (section *How to use the dictionary?*)](https://codegolf.stackexchange.com/a/166851/52210) to understand why `“€ß€„ÿ€† ÿ‡šŠ¥ÿ!\n“` is `"how toÿ in ÿ easy stepÿ!\n"`; `“Š¥ ÿ - Do€–ÿ.“` is `"step ÿ - Do not ÿ."`; and `“Š¥ ÿ -ÿ.“` is `"step ÿ - ÿ."`.
[Answer]
# [Notepad++](https://notepad-plus-plus.org), 147 keystrokes
```
<Enter><Enter>
i<Ctrl-D><Ctrl-D><Ctrl-D><Ctrl-D><Ctrl-Shift-End><Ctrl-D><Left><Left><Ctrl-Shift-End>
<Alt-E><Down><Down><Down><Down><Down><Down><Down><Down><Down><Down><Right>r
<Right><Enter><Ctrl-F>i$<Enter><Esc><Ctrl-Shift-End><Del>
<Ctrl-G>3<Enter>
<Alt-E><Alt-C><Alt-N><Ctrl-A>1<Tab>1<Enter>
<Ctrl-H><Space>?I$<Tab><Del><Alt-A><Esc>
<Ctrl-End><Shift-Up><Ctrl-C>
<Ctrl-Home><End><Backsp><Ctrl-V><Space>easy<Space>steps!
<Left><Ctrl-Left><Up><Ctrl-Right><Shift-End><Ctrl-C>
<Ctrl-H>\d+$<Tab>Step<Space>$0<Space>-<Space><Ctrl-V>.<Alt-A>
-(.+\r)<Tab>- Do not$1<Alt-A>
(1<Space>.+p)s<Tab>$1<Alt-A><Esc>
<Right><Del><Space>in<Space><Home><Ctrl-Right><Del>t<Ctrl-Right><Del><Del>
<Ctrl-End><Shift-Home><Ctrl-Shift-Right><Ctrl-Alt-Shift-U>
```
(Newlines inserted only for ease of reading.)
### Caveats
This solution requires version 7.9 of Notepad++ (at the time of writing, the most recent version), which added keyboard shortcuts to the Column Editor window.
The solution expects:
* the question text to be in the buffer with the cursor at the end and no trailing newline;
* the file to use Windows line endings;
* the Replace dialog to have the following settings: Regular expression search ON, match whole word OFF, match case ON;
* the Column Editor dialog to have the following settings: repeat BLANK, decimal format ON;
* and the Go To dialog to be in Line mode.
I believe all of these restrictions can be worked around, at the cost of extra keystrokes.
### How??
```
<Enter><Enter>
```
Add a couple of newlines after the question text.
```
i<Ctrl-D><Ctrl-D><Ctrl-D><Ctrl-D><Ctrl-Shift-End><Ctrl-D>
```
Insert an `i` on the bottom blank line, and then use `Ctrl``D`uplicate to make it 9 lines, each containing a single `i`.
```
<Left><Left><Ctrl-Shift-End>
```
Select those lines.
```
<Alt-E><Down><Down><Down><Down><Down><Down><Down><Down><Down><Down><Right>r
```
Open the Edit menu, go down to the Convert Case submenu, and select ranDOm CasE.
(As far as I know, this is the only source of randomness in Notepad++. I have no idea why it's even in there, but it's there, so we're gonna use it.)
We now have nine lines each containing either `i` or `I` at random.
```
<Right><Enter>
```
Add a blank line at the end.
```
<Ctrl-F>i$<Enter><Esc>
```
Find the first line that contains a lowercase `i`. If there is no lowercase `i`, the cursor stays on the blank line at the end.
```
<Ctrl-Shift-End><Del>
```
Delete everything from there to the end of the file.
We now have the original question, a blank line, 0 to 9 lines of `I`, and another blank line.
```
<Ctrl-G>3<Enter>
```
Go to line 3 (the first `I` line).
```
<Alt-E><Alt-C><Alt-N><Ctrl-A>1<Tab>1<Enter>
```
Open the Column Editor dialog and insert a number at the beginning of each line from the cursor to the end of the file, starting at 1, with an increment of 1. The numbered lines will be every line with an `I` plus the blank line at the end. Thus, we end up inserting the numbers 1 to N, where N is a random number between 1 and 10.
```
<Ctrl-H><Space>?I$<Tab><Del><Alt-A><Esc>
```
Delete the `I` after each number.
```
<Ctrl-End><Shift-Up><Ctrl-C>
```
Copy the last number (N).
```
<Ctrl-Home><End><Backsp><Ctrl-V><Space>easy<Space>steps!
```
Go to the end of the first line, delete the question mark, and insert the number plus the text `easy steps!`.
```
<Left><Ctrl-Left><Up><Ctrl-Right>
```
Position the cursor at the beginning of the first word after "How do I".
```
<Shift-End><Ctrl-C>
```
Select to the end of the line and copy (the action that I want to know how to do).
```
<Ctrl-H>
```
Replace:
```
\d+$<Tab>Step<Space>$0<Space>-<Space><Ctrl-V>.<Alt-A>
```
... each number `X` with `Step X - [action].`...
```
-(.+\r)<Tab>- Do not$1<Alt-A>
```
... the action on each instruction line except the last with `Do not [action]`...
```
(1<Space>.+p)s<Tab>$1<Alt-A><Esc>
```
... and `1 easy steps` with `1 easy step`.
```
<Right><Del><Space>in<Space>
```
Delete the newline between the action and `N easy steps` and replace it with `in` .
```
<Home><Ctrl-Right><Del>t<Ctrl-Right><Del><Del>
```
Change `do` to `to` and delete the `I` .
```
<Ctrl-End><Shift-Home><Ctrl-Shift-Right><Ctrl-Alt-Shift-U>
```
Go to the last line, select all but the first word, and convert to sentence case. This uppercases the first character of the action (e.g. `Find a pen` instead of `find a pen`).
[Answer]
# [Stax](https://github.com/tomtheisen/stax), 79 [bytes](https://github.com/tomtheisen/stax/blob/master/docs/packed.md#packed-stax)
```
Çφ`¶J╙╜úº╢ßJ╒♂é↔1S├p$@¢☺<ME⌡┐α∟0/δ-/⌂╙Γâ∙╗-ó≡æñ↕S-α.Wì*°yf╞≈♣⌐Y/)\┬░╛₧níë╛♂9=%▀
```
[Run and debug it](https://staxlang.xyz/#p=80ed60144ad3bda3a7b6e14ad50b821d3153c37024409b013c4d45f5bfe01c302feb2d2f7fd3e283f9bb2da2f091a412532de02e578d2af87966c6f705a9592f295cc2b0be9e6ea189be0b393d25df&i=How+do+I+make+coffee%3F)
Can probably be shortened by a lot. I'm not too familiar with string manipulation in stax yet.
Since stax does not have a random number function, this program uses the length of the string as **n**.
[Answer]
# [PowerShell Core](https://github.com/PowerShell/PowerShell), ~~163~~ 161 bytes
-2 bytes thanks @Julian
```
$q="$args"-replace'^.+I|\?$'
$r=Random 10
$s='s'*!!$r++
"How to$q in $r easy step$s!
"
1..$r|%{"Step $_ -$(' do not'*($_-ne$r)+$q-replace'^ .',{"$_"|% tou*r})."}
```
[Try it online!](https://tio.run/##RY3LbsIwEADv/orNapEhIVb5gIhDDy1Xeq2ILLI8JDebrAMIEb7dRFx6HWlmOrmxxhOHUO5FOSXqKySvx4ilchf8nu3OFZvxd03WkFZb3zbyB6sPQ7Gy0eZZRloUBr/lBoNQD@cWSIF9vEMcuKOYGTQr50jH2QN/JgRUQ0lzC41AK4PN51SXLZMuCur/t@Ds8oFU4zibypdcnwuHz5TS@zW5G4gSrgwePqXhLwmHNb4A "PowerShell Core – Try It Online")
[Answer]
# [Japt](https://github.com/ETHproductions/japt) [`-R`](https://codegolf.meta.stackexchange.com/a/14339/), 79 [bytes](https://en.wikipedia.org/wiki/ISO/IEC_8859-1)
```
A=ö)Îç¤i`How {=s8J} {A±1} ey ¡ep` ·cAÆi`Do not` ·i¢iUÅÎu¹gAg°X)i`Sp {X} -
```
[Try it](https://petershaggynoble.github.io/Japt-Interpreter/?v=1.4.6&flags=LVI&code=QT32Kc7npGlgSG93IJF7PXM4Sn0giCB7QbExfSBlhnkgoWVwYCC3Y0HGaWBEbyBub3RgILdpomlVxc51uWdBZ7BYKWlgU5JwIHtYfSAtIA&input=IkhvdyBkbyBJIG1ha2UgY29mZmVlPyI)
[Answer]
# [Red](http://www.red-lang.org), 180 bytes
```
func[s][t: n: 0
parse s["How do I "copy t to"?"]print["How to"t"in"n:
random 10"easy steps!^/"]append t"."repeat i
n - 1[print["Step"i"- Do not"t]]t/1:
t/1 - 32 print["Step"n"-"t]]
```
[Try it online!](https://tio.run/##Tc4xawMxDIbh3b/iq/br5drNyy0dmrUZjQvmLIMpkY2tEvLrL24baBYN0oN4G8f9g6PzpgWJ5Tx35ggpF5Ms9vQtm@veqYVYHEwNrTO6o/dyQSw4grZSr1BooZV8bVn07zoWSllI7P0zlgNx6Fd05dqfPmfyoVaWCKVnalw5KLIRTFjc/dFpUMo04a2MJiX1XufFmjEGe33BoxOafsCe8J93Dl@MraTEvJL51SAyjyTlkRAwSlbabw "Red – Try It Online")
[Answer]
# [Pyth](https://github.com/isaacg1/pyth), 95 bytes
```
A,P>z9hOT%."\ny6¶†Õ8Âù<û¡*SŠÄ™‘uü'iyÃ",GHVtH%." t²aD–ñö«É ?6^ó",hNG;%." t
8ݧGeµè‡",HrG4
```
[Try it online!](https://tio.run/##AZUAav9weXRo//9BLFA@ejloT1QlLiJcbnk2wrbChsOVOMOCw7k8w7sEwqEqU8KKw4TCmcKRdcO8J2l5w4MQIixHSFZ0SCUuIiB0wrJhRMKWw7EEw7bCq8OJID82XhcTw7MiLGhORzslLiIgdAYeOMOdwqcER2XCtcOowociLEhyRzT//0hvdyBkbyBJIG1ha2UgY29mZmVlPw "Pyth – Try It Online")
## Explanation
```
A, # Set...
P>z9 # ...G to the verb...
hOT # ...and H to the number of steps.
%."\ny6¶†Õ8Âù<û¡*SŠÄ™‘uü'iyÃ",GH # Print "How to <G> in <H> easy steps!" with 2 trailing newlines.
%." t²aD–ñö«É ?6^ó",hNG # Print "Step <N> - Do not <G>."...
VtH ; # ...H-1 times.
%." t8ݧGeµè‡",HrG4 # Print "Step <H> - <G>."
```
[Answer]
# [05AB1E](https://github.com/Adriandmen/05AB1E), ~~99~~ 90 bytes
*-9 bytes by using `„` (two-char string) and `…` (three-char string).*
```
ð¡3.$ðý¨U…€ß€„ .ªX«ð«„€† «TLΩ©«ð«„‡š›Ž«®i¨}…!
«®F„Š¥ ™«N>«… - «N>®QiX.ª«ë…€·€– .ª«X«}„.
«
```
[Try it online!](https://tio.run/##yy9OTMpM/f//8IZDC431VA5vOLz30IrQRw3LHjWtOTwfSDxqmKegd2hVxKHVQCWrgTyw2AKFQ6tDfM6tPLQSId6w8OjCRw27ju49tPrQusxDK2qBpihycYF4bkD5owsOLVV41LLo0Go/O5CGZQq6CmD2usDMCKANQINWQ@w9tB1sx2QFsCjQZqBJ8/SABv3/75FfrpCSr@CpkJuYnaqQnJ@WlppqDwA "05AB1E – Try It Online")
]
|
[Question]
[
Who doesn't love the Pythagorean theorem \$a^2+b^2=c^2\$? Write the shortest method you can in any language that takes in value `a` and `b` and prints out `The hypotenuse of this right triangle is c`. Keep `c` to only three decimal places.
[Answer]
## APL (54)
```
'The hypotenuse of this right triangle is',3⍕.5*⍨+/⎕*2
```
Test:
```
'The hypotenuse of this right triangle is',3⍕.5*⍨+/⎕*2
⎕:
9 10
The hypotenuse of this right triangle is 13.454
```
Explanation:
* `⎕*2`: raise the values in the input to the second power
* `+/`: take the sum
* `.5*⍨`: raise the result to the 0.5th power
* `3⍕`: round to 3 decimal places
[Answer]
# TI-BASIC, ~~76~~ ~~55~~ ~~53~~ 52 bytes
```
Input :Disp "THE HYPOTENUSE OF THIS RIGHT TRIANGLE IS
Fix 3:R▶Pr(X,Y
```
No, a closing parentheses is not required. Also, less bytes than that APL answer :)
[Answer]
# Python 2.7 - 76 Characters
```
print'The hypotenuse of this right triangle is %.3f'%abs(input()+1j*input())
```
**Explanation**
$$|a+bi| = \sqrt{a^2 + b^2} = c \\
\implies a^2 + b^2 = c^2$$
**PJ on hypotenuse**
>
> Teacher: "Can you tell me, what is hypotenuse?"
>
>
> LJ: "Hypotenuse, an easy question. If there's a high profile party last night, and you
> read it in the news paper, its called High Party
> News"
>
>
>
[Answer]
# [Sclipting](http://esolangs.org/wiki/Sclipting), 46 characters
```
글坼各갠方終加감半方갾밈乘增貶껠矽녆둥긆둹댆뭴뉖멵댶넠닶눠덆둩댲걲늖덨덂건댦땡닦덬뉒걩댲밀⓶
```
Expects the input as two numbers (can be fractional!) separated by a space.
This is shorter than APL, despite having to use a few inconvenient tricks.
## Explanation
```
글坼 | split at space
各 | for each...
갠方 | to the power of two
終
加 | add
감半方 | to the power of one half
갾밈乘 | multiply by 1000
增貶 | increment, then decrement (kludge for rounding)
껠矽 | insert '.' at 4th-last character position
녆둥긆둹댆뭴뉖멵댶넠닶눠덆둩댲걲늖덨덂건댦땡닦덬뉒걩댲밀⓶ | "The hypotenuse..."
```
[Answer]
# dc 54
Tangents the score of the APL answer!
```
2^r2^+3kv[The hypotenuse of this right triangle is ]Pp
```
Test:
```
$ dc
3 4
2^r2^+3kv[The hypotenuse of this right triangle is ]Pp
The hypotenuse of this right triangle is 5.000
```
[Answer]
## C, 77 or 99
77 characters if input can just be the function arguments:
```
f(a,b){printf("The hypotenuse of this right triangle is %.3f\n",hypot(a,b));}
```
99 if input must be read from stdin:
```
a,b;f(){scanf("%d %d",&a,&b);printf("The hypotenuse of this right triangle is %.3f\n",hypot(a,b));}
```
A big thanks to @Yimin Rong!
[Answer]
**Powershell**
Just to see if i could...
```
echo "The hypotenuse of this right triangle is " ([math]::round([math]::sqrt(([math]::pow(([double](Read-Host -p "A")),2) + [math]::pow(([double](Read-Host -p "B")),2))),3))
```
[Answer]
# Ruby, ~~94~~ ~~90~~ 82 chars
```
p "The hypotenuse of this right triangle is %.3f"%(Math.sqrt(gets.to_i**2+gets.to_i**2))
```
Update (thanks for the comments):
```
p "The hypotenuse of this right triangle is %.3f"%(gets.to_i**2+gets.to_i**2)**0.5
```
[Answer]
# [Whispers v2](https://github.com/cairdcoinheringaahing/Whispers), ~~133~~, 93 bytes
```
> Input
> Input
> "The hypotenuse of this right triangle is %.3f"
>> 1⊿2
>> 3%4
>> Output 5
```
[Try it online!](https://tio.run/##K8/ILC5ILSo2@v/fTsEzr6C0hAtBK4VkpCpkVBbkl6TmlRanKuSnKZQA1SsUZaZnlCiUFGUm5qXnpCoARVT1jNOUuOzsFAwfde03AjGMVU1AlH9pCdAsBdP//425TAE "Whispers v2 – Try It Online")
~~The major part of this program is calculating the decimal point's index and truncating to 3 digits.~~ -40 bytes from Leo!
[Answer]
## MATLAB ~~79~~ 74
```
@(a,b)sprintf('The hypotenuse of this right triangle is %.3f',norm([a b]))
```
[Answer]
# Python 2.7 - 80 chars
```
print'The hypotenuse of this right triangle is %.3f'%(input()**2+input()**2)**.5
```
[Answer]
# C++ - 90
```
void h(int a,int b){printf("The hypotenuse of this right triangle is %.3f\n",hypot(a,b));}
```
[Answer]
# Perl 6 (~~68~~ 74 bytes)
```
{printf "The hypotenuse of this right triangle is %.3f
",sqrt [+] @_ X**2}
```
`{}` declares a lambda function. `[+]` is sum operator, `X**` is cross power operator (for example, `1, 2 X+ 10, 20` gives `11, 21, 12, 22`). In this case, cross power operator takes one argument, so the result has the same length as `@_`. `@_` contains all function arguments.
If it's disallowed to have function that may take wrong number of arguments (unsafe), it's possible to replace `[+] @_ X**2` with `$^a**2+$^b**2`, where `$^a` and `$^b` are placeholder arguments.
[Answer]
**Javascript (97)**
```
x=prompt;a=x(),b=x();x('The hypotenuse of this right triangle is '+Math.sqrt(a*a+b*b).toFixed(3))
```
[Answer]
## C, 100 chars (beats the other C solution by 1!)
A ridiculously inefficient algorithm.
```
x;f(a,b){for(;x-a*a-b*b;x=rand());printf("The hypotenuse of this right triangle is %.3f",sqrt(x));}
```
[Answer]
## DELPHI / PASCAL
### With indent (157)
```
program p;
{$APPTYPE CONSOLE}
var a,b:integer;
begin
readln(a,b);
writeln('the hypotenuse of this right triangle is',sqrt(b*b+a*a):2:3);
end.
```
[Answer]
## EcmaScript 6, 82 79
```
f=(a,b)=>"The hypotenuse of this right triangle is "+Math.hypot(a,b).toFixed(3)
```
Usage:
```
f(3, 5)
> "The hypotenuse of this right triangle is 5"
```
**Update:** Switch to `Math.hypot()`
[Answer]
**Golfscript (~~69 67 66~~ 65)**
This would be much easier if floating point was actually supported without resorting to workarounds... :)
```
~'The hypotenuse of this right triangle is '@.*@.*+2-1??+.'.'?4+<
```
[A link to test it](http://golfscript.apphb.com/?c=OyIzIDUiCgp%2BJ1RoZSBoeXBvdGVudXNlIG9mIHRoaXMgcmlnaHQgdHJpYW5nbGUgaXMgJ0AuKkAuKisyLTE%2FPysuJy4nPzQrPA%3D%3D).
[Answer]
# Python 2 (79)
```
def p(a,b):print'The hypotenuse of this right triangle is %.3d'%((a*a+b*b)**.5)
```
[Answer]
# AWK — ~~84~~ 78 characters
```
awk '{printf"The hypotenuse of this right triangle is %.3f\n",($1^2+$2^2)^.5}'
```
Thanks to Wasi for suggesting ^ operator and removing ()!
e.g.
```
$ echo 3 4 | awk '{printf"The hypotenuse of this right triangle is %.3f\n",($1^2+$2^2)^.5}'
The hypotenuse of this right triangle is 5.000
```
[Answer]
# PowerShell: 111
**Golfed Code**
```
1..2|%{sv $_ (read-host)};"The hypotenuse of this right triangle is $("{0:N3}"-f[math]::sqrt($1/1*$1+$2/1*$2))"
```
**Walkthrough**
`1..2|%{sv $_ (read-host)};` Gets two inputs interactively from the user, and stores them in $1 and $2. Might be able to cut some length by using arguments or pipeline inputs instead.
`"The hypotenuse of this right triangle is` Required text in the output, per the challenge specifications.
`$(`...`)"` Encapsulated code block will be processed as script before being included in the output.
`"{0:N3}"-f` Formats output from the next bit of code as a number with exactly three digits after the decimal point.
`[math]::sqrt(`...`)` Gets the square root of the encapsulated value.
`$1/1*$1+$2/1*$2` Serves as our "a^2+b^2". Multiplying a number by itself is the shortest way to square it in PowerShell, but the variables need to be divided by 1 first to force them to integers. Otherwise, they are treated as text and 3\*3+4\*4 would be 3334444 instead of 25.
[Answer]
## JavaScript: 83
```
i=prompt,'The hypotenuse of this right triangle is '+Math.hypot(i(),i()).toFixed(3)
```
Currently the shortest JS implementation using `stdin` :D
Works only on Firefox 27.0+ (EcmaScript 6)
## JavaScript: 78
If we can use just two variables (as lot of scripts do here):
```
a=2,b=3,'The hypotenuse of this right triangle is '+Math.hypot(a,b).toFixed(3)
```
[Answer]
# dc, 55
```
3k?d*?d*+v[The hypotenuse of this right triangle is ]Pp
```
[Answer]
## Java, 112
(Also prints out a No Such Method error, though I'm not sure if this is against the rules)
```
class A{static{int a=1,b=1;System.out.printf("The hypotenuse of this right triangle is %.3f",Math.hypot(a,b));}}
```
## Java, 149
(No error)
```
class A{static{int a=1,b=1;System.out.printf("The hypotenuse of this right triangle is %.3f",Math.hypot(a,b));}public static void main(String[] a){}}
```
[Answer]
**C#**
**Method Only (114)**
```
void H(double a, double b)
{
Console.Write("The hypotenuse of this right triangle is {0:N3}", Math.Sqrt(a * a + b * b));
}
```
**Complete Program (171)**
```
using System;
class P
{
static void H(double a, double b)
{
Console.Write("The hypotenuse of this right triangle is {0:N3}", Math.Sqrt(a * a + b * b));
}
static void Main()
{
H(3, 4);
}
}
```
**Complete Program (without using method - 141)**
```
using System;class P{static void Main(){double a=3,b=4;Console.Write("The hypotenuse of this right triangle is {0:N3}",Math.Sqrt(a*a+b*b));}}
```
[Answer]
# JavaScript 118 106 93
Unlike @micha's solution, mine takes in two variables via function and sends the alert of the result.
`function(a,b){m=Math;c=d=>d*d,e=1e3;alert("The hypotenuse of this right triangle is "+m.round(m.sqrt(c(a)+c(b))*e)/e)}`
`function(a,b){e=1e3;alert("The hypotenuse of this right triangle is "+Math.round(Math.sqrt(a*a+b*b)*e)/e)}`
Fat arrow functions to the rescue!
`h=(a,b,e=1e3)=>"The hypotenuse of this right triangle is "+Math.round(Math.sqrt(a*a+b*b)*e)/e`
[Answer]
### c64 basic v2, 60 66 bytes
```
0inputa,b:?"The hypotenuse of this right triangle is";sQ(a*a+b*b)
```
Screenshot:
[](https://i.stack.imgur.com/W0ZLnm.png)
[How to try it.](https://codegolf.stackexchange.com/a/142638/14149)
[Answer]
# R, ~~61~~ 76 bytes
```
cat("The hypotenuse of this right triangle is",round(sqrt(sum(scan()^2)),3))
```
`cat` displays its content to STDOUT.
The `scan()` function takes user's input from keyboard. This input exists as a vector, on which the `^2` is applied (`^`function is vectorized), and the `sum()` sums the elements of the vector. `sqrt` outputs the square-root, which is rounded to 3 decimal places by `round(,3)`
Thanks to @caird coinheringaahing for noticing that the previous answer didn't round.
[Answer]
# [OML](https://github.com/ConorOBrien-Foxx/OML), 57 bytes
```
"The hypotenuse of this right triangle is "shnhn+A6`*N3eD
```
[Try it online!](https://tio.run/##y8/N@f9fKSQjVSGjsiC/JDWvtDhVIT9NoSQjs1ihKDM9o0ShpCgzMS89J1UBKKJUnJGXkaftaJag5Wec6vL/v6GCIQA "OML – Try It Online")
## Part 1
This simply outputs the string
```
"The hypotenuse of this right triangle is "s
```
## Part 2
```
hnhn+A6`*N3eD
hn take input and square it
hn take another input and square it
+ add them
A6` push 10^6
* multiply the sum with that number
N take integer square root
3eD output with three places of precision
implicit output
```
[Answer]
# [Jelly](https://github.com/DennisMitchell/jelly), 32 characters
```
,²S½ær3µ,“¡ÆC⁷⁺ɱSoṿȤç½?⁶Ẏtḍỵŀ»ṚK
```
[Try it online!](https://tio.run/##AUsAtP9qZWxsef//LMKyU8K9w6ZyM8K1LOKAnMKhw4ZD4oG34oG6ybFTb@G5v8ikw6fCvT/igbbhuo504biN4bu1xYDCu@G5mkv///8z/zQ "Jelly – Try It Online")
There is probably a better string compression that allows me to get around needing to join with spaces but I was having trouble finding it.
**Explanation:**
```
,²S½ær3µ,“...»ṚK Example inputs: 3, 4
, Pair the inputs. Result: [3, 4]
² Square them. Result: [9, 16]
S Sum them. Result: 25
½ Get the square root of the sum. Result: 5
ær3 Round to 3 decimal places. Result: 5
µ Take the result of that... Result: 5
“...» ...and the compressed string Result: "The hypotenuse of this right triangle is"
, And put them into a pair. Result: [5, "The hypotenuse of this right triangle is"]
Ṛ Reverse that. Result: ["The hypotenuse of this right triangle is", 5]
k Join it with spaces. Result: "The hypotenuse of this right triangle is 5.0"
Implicit output.
```
]
|
[Question]
[
*Inspired by [this question](https://stackoverflow.com/questions/38991478/remove-first-encountered-elements-from-a-list) on Stackoverflow.*
---
### The task
Let's have two lists/arrays of integers: `L1` and `L2` of equal length. You need to identify in `L2` the position of first occurrence of each number and remove from `L1` the values on the corresponding positions. Then print/output the modified `L1`.
Any reasonable input/ouput format is accepted as long as the lists are distinguishable.
### Example
```
L1 = [1 2 3 4 5 6 7 8 9]
L2 = [2 3 3 5 5 4 3 7 1]
First occurence of each number in L2:
L2 = [2 3 3 5 5 4 3 7 1]
^ ^ ^ ^ ^ ^
Corresponding elements to remove from L1:
L1 = [1 2 3 4 5 6 7 8 9]
^ ^ ^ ^ ^ ^
Output result:
[3 5 7]
```
### Test cases
```
Input -- Output
[1,2,3,4,5,6,7,8,9];[2,3,3,5,5,4,3,7,1] -- [3,5,7]
[1,1,1];[1,2,3] -- []
[2,2,2];[1,1,1] -- [2,2]
[-1,0,2,123456];[-1,0,-1,0] -- [2,123456]
[1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40];[1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1] -- [2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40]
```
[Answer]
# [APL(Dyalog Unicode)](https://dyalog.com), ~~8~~ 6 bytes [SBCS](https://github.com/abrudz/SBCS)
```
/⍨∘~∘≠
```
[Try it on APLgolf!](https://razetime.github.io/APLgolf/?h=AwA&c=03/Uu@JRx4w6IH7UuQAA&f=rY4xCsJAEEV7T2EXhS9mZnY3CbmBhRaWIa0eQqyEgAFFC3ux8gJewKPsSfwJsbGWgWX2/fnzZxubyy6eb4v1ahnbw2Y@9O9nUiaTeLzHtontYxpPr/0oNtcthUqgMDh4BGTIUdRl1REj8eRGKnUy7iZZVHtHT5Sd9kSGmZkgJRQ15wOV/t89w4afLEgKoZcOgziIhwQIE3NIAeUuehhiUAf10ADNoDm0gKUwgXElr@WhHhZgGSyHFXDp97D/VZ18AA&i=AwA&r=tryAPL&l=apl-dyalog-extended&m=train&n=f)
A function submission which takes L1 on the left and L2 on the right.
-2 bytes from Bubbler.
## Explanation
```
/⍨∘~∘≠
/⍨ remove elements from L! identified by:
~ the bitwise negation of
≠ unique mask of L2
```
[Answer]
# [Python 2](https://docs.python.org/2/), 49 bytes
A cool new approach from [@kops](https://codegolf.stackexchange.com/users/101474/kops), which outputs by modifying the input.
```
def f(a,b):
while b:b.pop()in b or a.pop(len(b))
```
[Try it online!](https://tio.run/##vY9NasMwEIX3PsXsIsFL8Iz8m5Ab5AYmFJs6xODaInUaenp35MSrbksRCM2b7z3N@O/pOg4yz@/thS6mRmP3ET2uXd9Ss292fvTGdgM1NN6oXsq@HUxj7fyEWPFu8KDxPnk60q1@vGl9n4zdffq@m8yGtlva2IhODDqJMh@1N@1X3SM4V@qwscq8UkLXhLdKF6PGk@jL37ph0hg6HhdwrhgChwQpMuQoUJ4PVVCcKqnqTlU@hwGqIOXnSC16FFusz5aqopUsKq@GIETVlhFrj8UlaabAUodrhV6d6Pcs4Biscco4cAJOwRlYJyrAJURz1aPfOEgCSSEZJIcUkBIuhmM4jdRtdJEULoPL4Qq4Ekm8zvp3Z13oH3f4AQ "Python 2 – Try It Online")
### [Python 2](https://docs.python.org/2/), 51 bytes
```
lambda a,b:[x for x in a[::-1]if b.pop()in b][::-1]
```
[Try it online!](https://tio.run/##vY/daoNAEIXvfYq5i8IxOLv@B98gb2ClrDQSweiSmiZ9ejtr4lVvSxlYdr45Z37s93yeRrV01dsymEv7YcigLesHddOVHtSPZOqyDLnpO2r3drJ@IKxtnnC5n/vhRFx6orSg6TZbquhq7u@S32Y/2H/aoZ/9HYUh7QKPjgw6KtFcjPVPX2aAc26qwy4QzauLq/ruL8he@3Gmzn/aA6qqVbXUDAWNGAlSZMhRNIfaES0kEa6FcuOm1w5ljScWCZGt1mdJqJJMrZQ3gwNeHTIiqbHScZKKYM3ds4leFe/3LuAILO1Eo8ExOAGnYNkoBxdQ0lc8MkZDxVAJVAqVQeVQBXQEzdDSUq6RQxLoFDqDzqELxNG269/FdtA/3vAD "Python 2 – Try It Online")
We can determine whether an element stays in `L1` by whether the corresponding element in `L2` is its first occurrence. This is done with `b.pop()in b`, which pops the last element from `L2` and checks if it still exists in the list.
Because we process the elements in reverse, `[::-1]` needs to be used twice. It makes the final code a lot larger than I had hoped, but I am not able to come up with a shorter approach.
[Answer]
# [Haskell](https://www.haskell.org/), ~~65~~ ~~52~~ 51 bytes
```
f[]
f z(a:s)(b:t)=[a|b`elem`z]++f(b:z)s t
f _[]_=[]
```
[Try it online!](https://tio.run/##vY/NboMwEITvPMUeIoHVoY1tIL/01EulvIGLGichKSoBBD5FffbSJQ299FpVli37m9nx7pvt3vOy7ItzU7eOnqyz95uic94pfemPJvOOdAnsshPBbulEauzHbpuX@Xl7ye7ujgwvoiPHrleTvaYm68@2qNJD7REFpfTRinXYNbYKHlJ/5Yv15PGUu01R5Wwoc8cm5aP2BaU02sgXwaGtG5LUilUpWWpzeyCOWy7Nc@WyVal@oPqB9ci@qyPi2JvGnzVtUTmaUHDiIBoCUqrBd94Kw/UmCDYPQ/RGQkEjQowEM8yxyFZmIJpJzFwzlRmFIZkBzTKPS3ix7Vr6LTFV/FJXKseCAXgmlJiyJpWO4oQN1/dwjKab4v3uBXIKyXHs0ZARZAyZQHJHc8gFFOdyDX@joSKoGCqBmkHNoRbQU2gJzZE8DQ8SQyfQM@g59ALRdOz179Y40D/O8Lk/lvbU9eG@ab4A "Haskell – Try It Online")
The solution is the anonymous function which calls `f` applied to the empty list: `f[]`. `f` keeps track of which elements of L2 we've seen already and only adds the corresponding element of L1 to the result if we haven't seen L2's head yet.
`import Data.List` for the builtins turns out to be too expensive:
### [Haskell](https://www.haskell.org/), 65 bytes
```
((map fst.((\\)<*>nubBy((.snd).(==).snd))).).zip
import Data.List
```
[Try it online!](https://tio.run/##ZY/LboMwEEX3fMUsImFXFxrbPPIii6qbSv0DwoIGQlEJIKCL9uNLB/KQqgoZjc@9cz3znvYfeVWN5bltuoGe0yF1X8t@sIroMApxTls69YMrxOEgdw/7@vPt6UsIt68z6YooknMlpSvd77K1HOdvynhOyzrKGotIVMpGJ3dO36a1eIzsrS13i32RD69lnbOhygc2aRuNLSmim41sKbKuaUlRJ7eVYqnL04w4brOJX@oh2Vb6DvUdNjd26faIY68aP9Z2ZT3QgkTBQTQFRNSAaz4aU3kVJJunJcZYQcPAg48AIVZYJ9t4IoaJz9wwVQk5DsUTChOLW/hj29x6kZhqvumZqlvDBKzYUViyprTx/IAN83363UxXxfo/C9QSiuPYY6A8KB8qgOKJVlBraM7lHn7GQHvQPnQAHUKvoNcwSxgFw5G8DS/iwwQwIcwKZg1veZn153iq0qIfnWPb/gI "Haskell – Try It Online")
### How?
```
((map fst.((\\)<*>nubBy((.snd).(==).snd))).).zip
zip -- zip the lists
(\\) -- delete from the zipped lists
nubBy -- the first occurence of each element under the equivalence class defined by:
((.snd).(==).snd) -- equality of the second element of each pair
map fst -- take the first element of each pair from the resulting list
```
and then a lot of punctuation to send the right arguments to the right places...
[Answer]
# [R](https://www.r-project.org/), 29 bytes
```
function(x,y)x[duplicated(y)]
```
[Try it online!](https://tio.run/##ZY3RCoMwDEXf9xUFXxqI0tQ6UfYnpQ@jWhCGE1HQr@9S3WBsuZDAvSfJHIO45TGso1@G5yg33GGz3To9Bn9f@k7u4GKQ1DbopcaSVbEMzxoJQByV2WTX7hKkl4QsQGrLd/pdmT0hjSzADw0/EIcnlxMqRkmXprom/jBS453EnUmCqTUK537ik0YB/H/WoiiEUS6@AA "R – Try It Online")
A rare case, where obscure `duplicated` function appears to be useful...
[Answer]
# [Jelly](https://github.com/DennisMitchell/jelly), 5 bytes
```
ŒQ¬Tị
```
[Try it online!](https://tio.run/##y0rNyan8///opMBDa0Ie7u7@//9/tJGOMRCaAqEJkDbXMYz9H22oAxI1AYqZAUUsdCxj/wMA "Jelly – Try It Online")
## Explanation
```
ŒQ¬Tị Main dyadic link
ŒQ Distinct sieve - replace first occurences with 1 and other occurences with 0
¬ Negate
T Get the indices with truthy elements
ị Index into the other array
```
[Answer]
# [J](http://jsoftware.com/), 6 bytes
```
#~1-~:
```
[Try it online!](https://tio.run/##PY7BCsJADETvfsVgD9tCtphNt60LngRPnvwBD2KQXvyD/vqa7aoME8i8DGTJ@94pTgkOhAOS2fc4366X3Kzs15S73fPxekMQMcEntEyBhAaKNNJEMx07KNqSiWXRiFjO355zpcSb1BwgFQSTkbBJ68WPcJAhjgXf2T76B1r3MvIH "J – Try It Online")
Filter by `#~` the complement of `1-` the nub sieve `~:`
[Answer]
# [R](https://www.r-project.org/), ~~59~~ ~~35~~ 34 bytes
*Edit: -1 byte thanks to Giuseppe ...but now outgolfed by [Kirill L's answer](https://codegolf.stackexchange.com/a/223575/95126)*
```
function(a,b)a[match(b,b)<seq(!b)]
```
[Try it online!](https://tio.run/##vZDBasMwEETv/gqXXCQYg3dXkm1Iv6SUYAuH5hCHOE5@312lpTXUhx5CEAgxu29Ws@M89sfTrd/tD@Nl2vVDfJ331yFOh9NgWnS2fTu2U/wwnb63l/5sXjr7/gcy0RAYAgePgAo1GotokiQqeS2IymRtvsmLIo8myZXNVp30JPpu@UusNrP28FczLe2TutZfEEpFiMX5kLi7kK4l@13O/pMTVIJ0tlICciAPCiANW4MasI5TRv8jYAf24ACuwDW4gZQQgqilLkp35CEBUkFqSANX/iR73FnmfGKQbP4E "R – Try It Online")
`match(x,y)` finds the index of the first element in `y` equal to each element of `x`.
So, `match(b,b)` is equal to the index of each element if it's the first one with a particular value, otherwise it it'll be equal to an earlier index where that value was previously encountered.
`seq(!b)` is golfy shorthand for `seq_along(b)`, and returns a sequence of integers `1...b` (in other words, the indices of each element of `b`). Note that we need the `!` because `seq` defaults to outputting a sequence of `b` integers if `b` contains only a single numeric element; therefore, we use `!` to first convert the argument to a `logical`-type vector (where this can't happen).
[Answer]
# [AWK](https://www.gnu.org/software/gawk/manual/gawk.html), ~~30~~ 29 bytes
```
{a[++n]=b[$1]++}n>FNR&&a[++m]
```
[Try it online!](https://tio.run/##S0oszvifnJ@Saqv@vzoxWls7L9Y2KVrFMFZbuzbPzs0vSE0NJJob@1@dKzU5I19B3VDBSMFYwUTBVMFMwVzBQsFSXcFOwccQKguSMwbKmQJVGAPlDcGyRlyJ5dkKumUKQcG26grqCkoqICuVgBJAnf8B "Bash – Try It Online") *(Thanks very much to [Jonah](https://codegolf.stackexchange.com/users/15469/jonah) for the TIO link)*
Takes input as two files L1 and L2, with one number per line in each (or, with the `-v RS=' '` option, space-separated on a single line).
[Answer]
# [Haskell](https://www.haskell.org/), ~~44~~ 43 bytes
* -1 byte thanks to [Unrelated String](https://codegolf.stackexchange.com/users/85334/unrelated-string).
```
x!y=[a|(i,a)<-zip[0..]x,y!!i`elem`take i y]
```
[Try it online!](https://tio.run/##vY/daoNAEIXv8xQrBKJwTJ1df5PY@0LfQIQsZEmXbFSMF0npu9vRVij0tpSBhfnOObMzb/p2Mc6N4917lJX@8C10cAjfbVdF2219x8Pz7NE4cz0O@mKEFY96vGrbiFKc2pUQHGg5cOt04z@VG7EJDuvnsxlebWNYdmbwHcHJoFws@01gWel62wxrvzf6JBztdtVLM5iz6evAm6E/aOsEB39KZTlLp77thBJtwHOmZcaKIKEQI0GKDDmKel9NRDFJmCumVIswFNWEsnrFES62zdEviankTs6UlsAEVlVIiFgjqeIkZcPcT89i@lZWv3cBRSAexx4FikEJKAXxRjmogOS5nOFvFGQMmUCmkBlkDllARVAExSP5Gj4kgUqhMqgcqkAcLbv@XS0H/eMNnw "Haskell – Try It Online")
## How?
```
x!y= -- (!) is a function that takes lists x and y as input
[a| -- and returns the list of all the elements a
(i,a)<-zip[0..]x, -- where a is the i-th element of x
y!!i`elem`take i y] -- and the i-th element of y is not a "first occurrence" in y
```
[Answer]
# [JavaScript (Node.js)](https://nodejs.org), 40 bytes
```
a=>b=>a.filter((_,i)=>b.indexOf(b[i])<i)
```
[Try it online!](https://tio.run/##rY9BasMwEEX3OYkEP8YzI8k21LlCD2BMcRI7KBi7JCHk9u6oLV00XgaBFk9/nv6cu3t3PVzi5207zcd@Geqlq3f7etdlQxxv/cWYD0SrKIvTsX@8D2bfxNa@Rbsc5uk6j302ziczmIbAEDh4BBQoUbXWNAmJIq8PophaazdPg5T4r2ElwMr5J0Crhi0h1wyxOB9S8Buka/W7fz1BOUjFKhCQA3lQAGnZElSBVa0zWkHADuzBAVyAS3AFySEEUaUuqjt6SIAUkBJSweV/tV930k7LFw "JavaScript (Node.js) – Try It Online")
[Answer]
# [Arturo](https://arturo-lang.io/), 67 bytes
```
$[a b][loop reverse unique map b'x[index b x]'i[remove.index'a i]a]
```
[Try it on the Arturo Playground!](https://arturo-lang.io/playground/?vENS7f#)
[Answer]
# [Red](http://www.red-lang.org), 69 bytes
```
func[a b][foreach c unique b[change at a index? find b c none]trim a]
```
[Try it online!](https://tio.run/##rZA5bsQwDEV7n@JdIIApek2TC0yVVmDhRc64iCcxxkBu73AwdpkuIqDlkZ@f0JrG/T2N0bLplX3aliF29Ban25q64crAtszfW6KPw7VbPhLdnY55GdPPG5Of9F603JZk93X@pLP91MaLcAkWM3xFIaAUlFTUNLRGfBB1UjpXp2JnrYcdmoMFvwc7c0/2IuSOJWhRVna8H5v94YnkiOtdo0iBlEiFuHODtATv5ho3UkJBKAkVoSY0hBbNUUG9pU/tA5dohdZog7YU@Tnc/4VlFr/WW5@YeH7m/gs "Red – Try It Online")
[Answer]
# [Vyxal](https://github.com/Lyxal/Vyxal), 5 bytes
```
ÞU†Tİ
```
[Try it Online!](http://lyxal.pythonanywhere.com?flags=&code=%C3%9EU%E2%80%A0T%C4%B0&inputs=%5B2%2C3%2C3%2C5%2C5%2C4%2C3%2C7%2C1%5D%0A%5B1%2C2%2C3%2C4%2C5%2C6%2C7%2C8%2C9%5D&header=&footer=)
Same as the APL and Jelly answer.
## Explained
```
ÞU†Tİ
ÞU # unique mask over second list
† # vectorised not over that
Tİ # and index the truthy indices into the first list
```
[Answer]
# [05AB1E](https://github.com/Adriandmen/05AB1E/wiki/Commands), 8 [bytes](https://github.com/Adriandmen/05AB1E/wiki/Codepage)
```
DÙõ.;.ïÏ
```
I have the feeling this could be shorter, but 05AB1E's builtin might not be the most suitable for this challenge.
\$L2\$ as first input, \$L1\$ as second.
[Try it online](https://tio.run/##yy9OTMpM/f/f5fDMw1v1rPUOrz/c//9/tJGOMRCaAqEJkDbXMYzlijbUAYmaAMXMgCIWOpaxAA) or [verify all test cases](https://tio.run/##rZAxCsJAFESvElKPIf//3U2CRRpvsSyoYGFlERByAVvBzlNYeYLcxIvESYJgYSkDu8sbZnf2n7rd/ngYz32bZ6/LLcvbftuNm@E@PIt1MTyG64gxxqgwylOOewVJiIKJOrJAUqNJCVlc8GxTHyRzQmnpglaCEtNCPJ8VouZ8@Er8T7/aQkoIPT5sEAfxkADh32pIA2UlZljYoA7qoQFaQWtoAythAuOVnAtH4mEBVsFqWANXppTe).
**Explanation:**
```
D # Duplicate the first (implicit) input-list L2
Ù # Uniquify the values in the copied list
õ.; # Replace the first occurrences of the values in L2 to an empty string
.ï # Check for each item whether it's an integer (1 if an integer; 0 if an empty
# string)
Ï # Only keep the values at the truthy indices in the (implicit) input-list L1
# (after which the resulting list is output implicitly)
```
[Answer]
# [Python 3](https://docs.python.org/3/), 76 bytes
```
f=lambda a,b,c=[],i=0:i<len(a)and f(a,b,c+[a[i]]*(b.index(b[i])!=i),i+1)or c
```
[Try it online!](https://tio.run/##NY5LDsIwDET3nMLsEjog0rTlI3KSKIukHxGpBIRYwOmDQ4UtjeznseXH53W9J53zZGZ/C4Mnj4DeWIdo9ud4mcckvPRpoEn8RpX1Njq3EWEX0zC@ReBWrk2UiJWS9yf1eWL1oEAxkRVWoYZGgxYdDjji5GAL0Uxa5pqpchJUrJwOtOwsrOayXpj6@7YKe8aq1k3b8blfX8RJd14Rx@MZ00uUpylIucpf "Python 3 – Try It Online")
[Answer]
# [Charcoal](https://github.com/somebody1234/Charcoal), 10 bytes
```
IΦθ›κ⌕η§ηκ
```
[Try it online!](https://tio.run/##S85ILErOT8z5/z@gKDOvRMM5sbhEwy0zpyS1SKNQR8G9KDURxMzWUXDLzEvRyNBRcCzxzEtJrQAxszXBwPr//@hoQx0jHWMdEx1THTMdcx0LHctYnWiQiDFQxBQobgwUNYyN/a9blgMA "Charcoal – Try It Online") Link is to verbose version of code. Explanation: Port of @tsh's JavaScript answer.
```
θ First list
Φ Filtered where
κ Current index
› Is greater than
⌕ First index of
κ Current index
§ Element of
η Second list
η In second list
I Cast to string
Implicitly print
```
[Answer]
# [Python 3.8 (pre-release)](https://docs.python.org/3.8/), 53 bytes
```
lambda a,b:[x for x,y in zip(a,b)if b==(b:={*b}-{y})]
```
[Try it online!](https://tio.run/##rU/RaoNAEHzvV9yjhgm4u3d6BvwS64NSpEJrRPIQE/LtdiIUGp/LwsHN7MzOTMvl8zxanOa1r97Xr/a7@2hdi@5UX11/nt0VixtGdxumhGg69K6rqqQ7VfdD9zjel0farNM8jJekT2qBwuARkKNARNmgfiJGJBA3otKk6dsfBYdbm/KFUSK6MbLTHAUZSVHzIefG9n8@O@ddFkgGoReVBvGQAMkhTBQhJZSe1PCoQT00QHNoAY3QEpbBBEZLtmGRAMthBSzCSvjsN@j/DcusPw "Python 3.8 (pre-release) – Try It Online")
A little better
[Answer]
# [Husk](https://github.com/barbuz/Husk), 9 bytes
```
M!-m←ηk¹ŀ
```
[Try it online!](https://tio.run/##yygtzv7/31dRN/dR24Rz27MP7Tza8P///2hdQx0DHRARC2Ub6RgaGZuYmsUCAA "Husk – Try It Online")
## Explanation
```
M!-m←ηk¹ŀ
k key
η the indices of each element on their value.
m← take the first index of each key
- remove this from
ŀ the input, converted to indices.
M map each index to
! the respective element in the second array
```
[Answer]
# [Python 3](https://docs.python.org/3/), 108 bytes
```
k={y.index(x)for x in y};n='z=[v for i,v in enumerate(z)if i not in k]';exec(n);n=n.replace("z","y");exec(n)
```
[Try it online!](https://tio.run/##NcvBCsIwEATQu1@x5NINhEKtIlLyJaWHUrcaWrclxpJE/PaYHmQOA2@YNbjHwnWKoGE2L4e25zthpa5SHkLG9qjqnHPOKfdFVV2a9CeUhm/k0ctxseDBMIRvw7qIut1gN6O2XYnfT7K9I4zSjGCAF7f71BUNeRqQZb5xaWmd@4FQRKFEEPI/ptUadhhVkOkH "Python 3 – Try It Online")
Define two lists z and y
[Answer]
# [Pyth](https://github.com/isaacg1/pyth), 8 7 bytes
```
.DExLQ{
```
Input is L2 and L1, separated by newlines
-1 because Pyth has a built-in for evaluated input I forgot about
[Try it online!](https://tio.run/##K6gsyfj/X8/FtcInsPr//2gjHWMgNAVCEyBtrmMYyxVtqAMSNQGKmQFFLHQsY//lF5Rk5ucV/9dNAQA "Pyth – Try It Online")
[Answer]
# [Wolfram Language (Mathematica)](https://www.wolfram.com/wolframscript/), 35 bytes
```
#[[Union@@Rest/@PositionIndex@#2]]&
```
[Try it online!](https://tio.run/##rY4xa8NADIV3/4qCwdMLtaS7sz003JottHQyHkzqUA@5QHxDwFz@uiu77dK5CAT6pPf0Ln38HC59HE/9cn5Z8rZ9D@M1eP86TPHZH6/TGHU@hI/h7nPuumI53sYQ23y3P3ufd8Xj7dSHx5zNM4EhMLBwqFCjScie5pWJMqsbUU5J8XqstR1ssm@4I5Q6EYuxbltuZG2/qj8vQCVInVQkIAOyIAfSNzWoAaudahgsYAO2YAeuwDW4gZQQgqilRtR0FuIgFaSGNDDlT7x/rZSytHwB "Wolfram Language (Mathematica) – Try It Online")
[Answer]
# [Perl 5](https://www.perl.org/), 36 bytes
```
sub{my%s;grep$s{+shift}++,@{+shift}}
```
[Try it online!](https://tio.run/##vVFta4MwEP7urwjitkqfgZcYXyZl/o@uDAbaubXq1MFK6W93Z2o7O/pxLIHk8rxccpc6aza63@6cfNG3ny/77e6mTdZNVjvtft6@Fnl3mM@RnuJDn1h51cwswWNpVrEkSCj40AgQIkK8wsgMuGJcM6uYozMzoOHKHEbsJxtNdCb3@XTVIFkiJ4apfWCuee4JHttIKl8HZ7VBh2XiHyXXX/qrbpAH4uvZpUA@SIMCENcdgWJIvpI9/CYF6UNqyAAyhIwgYygPiqA4JfeM26WhAqgQKoKK4XuXFf7dvPisfyvm2E/L3Ztgu5s5m6LtCGaTcLKv2l2kznMy8um66ha3Tn7SpUehe@Trpig78VYV5ewOdxjErsg@JohJKB6FXb3b4kHYZdUJDiHsp9JOrEP/DQ "Perl 5 – Try It Online")
[Answer]
# [Arturo](https://arturo-lang.io), 44 bytes
```
$[a,b][i:0select a=>[in? b\[i]take b i'i+1]]
```
[Try it](http://arturo-lang.io/playground?IMFklu)
```
$[a,b][ ; a function taking two lists a and b
i:0 ; set i to 0
select a=>[ ; select elements from a where...
in? b\[i]take b i ; the ith element of b is found in b's elements that come before index i
'i+1 ; increment i
] ; end select
] ; end function
```
[Answer]
# [Japt](https://github.com/ETHproductions/japt), 8 [bytes](https://en.wikipedia.org/wiki/ISO/IEC_8859-1)
```
gVðÏÀVbX
```
[Try it](https://petershaggynoble.github.io/Japt-Interpreter/?v=1.4.6&code=Z1bwz8BWYlg&input=WzEgMiAzIDQgNSA2IDcgOCA5XQpbMiAzIDMgNSA1IDQgMyA3IDFd)
```
k϶VbVgY
```
[Try it](https://petershaggynoble.github.io/Japt-Interpreter/?v=1.4.6&code=a8%2b2VmJWZ1k&input=WzEgMiAzIDQgNSA2IDcgOCA5XQpbMiAzIDMgNSA1IDQgMyA3IDFd)
]
|
[Question]
[
## Task
Provide two programs/functions `A` and `B` (not necessarily in the same language) with the following properties:
* Either program, when given its own source code as input, produces an accepting output.
* Either program, when given the *other* program's source code as input, produces a rejecting output.
It doesn't matter what happens when you provide either program with an input that is not `A` or `B`. Accepting or rejecting is defined as per [here](https://codegolf.meta.stackexchange.com/a/19205/115910):
* output truthy/falsy using your language's convention (swapping is allowed), or
* use two distinct, fixed values to represent true (affirmative) or false (negative) respectively.
Both programs must use the same method of output. Additionally, if you use truthy/falsy and they are swapped for one program, they must be swapped for both programs.
If you decide to write a function instead of a full program, you must do so for both programs.
## Scoring
Your score is the sum of the byte counts of both programs. This is code golf, so the lowest score wins.
[Answer]
# [Jelly](https://github.com/DennisMitchell/jellylanguage), 1 byte
##### Program A, 1 byte
```
Ṇ
```
##### Program B, 0 bytes
##### Outputs
Falsy = accepting; truthy = rejecting
* [A inputted into A](https://tio.run/##y0rNyan8///hzrb/YBIA): `0` (falsy)
* [B inputted into A](https://tio.run/##y0rNyan8///hzrb///8DAA): `1` (truthy)
* [A inputted into B](https://tio.run/##y0rNyan8DwIPd7YBAA): `Ṇ` (truthy as it is a non-empty string)
* [B inputted into B](https://tio.run/##y0rNyan8DwIA): (falsy as it is an empty string)
##### Explanation
* The string `Ṇ` (program A) is truthy as it is a non-empty string
* The string (program B) is falsy as it is an empty string
* In Jelly, an empty program just outputs exactly what was input. So program B produces a truthy output when program A is inputted, and a falsy output when it is given itself as input
* In Jelly, `Ṇ` is the logical NOT operator. It outputs a falsy output (`0`) when a truthy input is given, but a truthy output (`1`) when a falsy input is given. Therefore, it produces a falsy output when given itself as input, and a truthy output when program B is inputted
[Answer]
# [APL (Dyalog Unicode)](https://www.dyalog.com/), ~~10~~ ~~7~~ 6 bytes
Anonymous tacit prefix functions, returning `⊣` for true and `⊢` for false.
### A: `⊣/⊢`
 `⊢` is an identity function, and returns the given source as-is
 `⊣/` returns the leftmost character (lit. left-identity reduction), i.e. `⊣` when given A's source and `⊢` when given B's source.
### B: `⊢/⊣`
 `⊣` is an identity function, and returns the given source as-is
 `⊢/` returns the rightmost character (lit. right-identity reduction), i.e. `⊢` when given A's source and `⊣` when given B's source.
[Try it online!](https://tio.run/##SyzI0U2pTMzJT////1HXYv1HXYu4gBhIL/7v@KhtwqPevkddzY961zzq3XJovemjtomP@qYGBzkDyRAPz2AuJww1Juhq/juqQ01W5wIxwYarczkhRJ3gogA "APL (Dyalog Unicode) – Try It Online")
[Answer]
# [Retina 0.8.2](https://github.com/m-ender/retina/wiki/The-Language/a950ad7d925ec9316e3e2fb2cf5d49fd15d23e3d), 2 bytes
Program A:
```
A
```
Program B:
```
B
```
* [Try it online!](https://tio.run/##K0otycxL/P/fEYgA "Retina 0.8.2 – Try It Online") Program A with Program A as input.
* [Try it online!](https://tio.run/##K0otycxL/P/f8f9/JwA "Retina 0.8.2 – Try It Online") Program A with Program B as input.
* [Try it online!](https://tio.run/##K0otycxL/P/f6f9/RwA "Retina 0.8.2 – Try It Online") Program B with Program A as input.
* [Try it online!](https://tio.run/##K0otycxL/P/fCYgA "Retina 0.8.2 – Try It Online") Program B with Program B as input.
Explanation: Each program counts the number of `A`s or `B`s in the input respectively, which will be truthy for itself and falsy for the other program.
[Answer]
# [Pip](https://github.com/dloscutoff/pip), ~~6~~ 5 bytes
* -1 thanks to DLosc
Outputs 0 for truthy and 1 for falsy.
### Program A, 2 bytes
```
+q
```
### Program B, 3 bytes
```
1-q
```
### Test cases
* [Program A, Input A](https://tio.run/##K8gs@P9fuxCEAQ "Pip – Try It Online")
* [Program A, Input B](https://tio.run/##K8gs@P9fu/D/f0PdQgA "Pip – Try It Online")
* [Program B, Input A](https://tio.run/##K8gs@P/fULfw/3/tQgA "Pip – Try It Online")
* [Program B, Input B](https://tio.run/##K8gs@P/fULcQTAAA "Pip – Try It Online")
### Explanation
`+q` forces the input into an integer. `+q` evaluates to 0, and `1-q` evaluates to 1.
`1-q` subtracts the input from 1, once again forcing it into an integer. `+q` will therefore be 1, and `1-q` will therefore be 0.
[Answer]
# [R](https://www.r-project.org), ~~26~~ 24 bytes
### Program A, 12 bytes
```
\(x)x<"\\(y"
```
[Attempt This Online!](https://ato.pxeger.com/run?1=m72waMEiR9ulpSVpuhZrYjQqNCtslGJiNCqVIEI3NR011GPg4mAZdU0uiGCVZpUdQhCiYcECCA0A)
### Program B, 12 bytes
```
\(z)z>"\\(y"
```
[Attempt This Online!](https://ato.pxeger.com/run?1=m72waMEiJ9ulpSVpuhZrYjSqNKvslGJiNCqVIEI3NZ001IH8Cs0KG6A4WEZdkwsiCFUMFYRoWLAAQgMA)
Two anonymous functions differing by the name of the variable. We then check whether the function text (essentially the variable name) is smaller or bigger (lexicographically) than the beginning of the function (`\` escaped and `(`) with `y` appended.
[Answer]
# [Python 2](https://docs.python.org/2/), 16 + 15 = ~~49~~ ~~46~~ ~~44~~ ~~40~~ 31 bytes
[crossed out 44 is still regular 44 :(](https://codegolf.stackexchange.com/a/239777/106959)
I don't think there's a optimal way to golf this.
`-1` for Truthy, `0` for Falsy
## Program A
```
0
print~-input()
```
[Input A](https://tio.run/##K6gsycjPM/r/34CroCgzr6RONzOvoLREQxNTBAA "Python 2 – Try It Online")
[Input B](https://tio.run/##K6gsycjPM/r/34CroCgzr6RONzOvoLREQ/P/f0OICEwAAA "Python 2 – Try It Online")
## Program B
```
1
print-input()
```
[Input A](https://tio.run/##K6gsycjPM/r/35CroCgzr0Q3M6@gtERD8/9/A4hAHUwEAA "Python 2 – Try It Online")
[Input B](https://tio.run/##K6gsycjPM/r/35CroCgzr0Q3M6@gtERDE0MAAA "Python 2 – Try It Online")
-2 bytes thanks to [Ji≈ôi](https://codegolf.stackexchange.com/users/101306/ji%c5%99%c3%ad)
-9 thanks to [tsh](https://codegolf.stackexchange.com/users/44718/tsh) by changing the version.
[Answer]
# [Vyxal](https://github.com/Vyxal/Vyxal), 4 bytes
### Program A, 2 bytes
```
0c
```
### Program B, 2 bytes
```
1c
```
### Test cases
* [Program A, Input A](https://vyxal.pythonanywhere.com/#WyIiLCIiLCIwYyIsIiIsIjBjIl0=)
* [Program A, Input B](https://vyxal.pythonanywhere.com/#WyIiLCIiLCIwYyIsIiIsIjFjIl0=)
* [Program B, Input A](https://vyxal.pythonanywhere.com/#WyIiLCIiLCIxYyIsIiIsIjBjIl0=)
* [Program B, Input B](https://vyxal.pythonanywhere.com/#WyIiLCIiLCIxYyIsIiIsIjFjIl0=)
### Explanation
`0c` checks whether `0` is in the input, and `1c` checks whether `1` is in the input.
[Answer]
# JavaScript (ES6), 2x7 = 14 bytes
Both functions return a Boolean value.
A: `s=>s>{}`
B: `S=>S<{}`
[Try it online!](https://tio.run/##y0osSyxOLsosKNHNy09J/e9oy1Vsa1dsV13L5WT7P9jWLtimuvZ/cn5ecX5Oql5OfrqGo4ajXkl@cElRZl66hqamJheqpBNuSSd8Op3QdP4HAA "JavaScript (Node.js) – Try It Online")
[Answer]
# [Zsh](https://www.zsh.org/), 6 + 6 = 12 bytes
```
grep A
```
[Attempt This Online!](https://ato.pxeger.com/run?1=m724qjhjwUKNpaUlaboWy9KLUgsUHCGczZp2-impZfp5pTk5XKnJGfkKKvYQmQUo6gA)
```
grep B
```
[Attempt This Online!](https://ato.pxeger.com/run?1=m724qjhjwUKNpaUlaboWy9KLUgsUnCCczZp2-impZfp5pTk5XKnJGfkKKvYQmQUQdY4QHgA)
Output is via exit code.
[Answer]
# ><>, 10 bytes
```
0"i=n;
```
And
```
1io;
```
[Try it](https://mousetail.github.io/Fish/#eyJ0ZXh0IjoiMFwiaT1uOyIsImlucHV0IjoiMFwiaT0iLCJzdGFjayI6IiIsInN0YWNrX2Zvcm1hdCI6Im51bWJlcnMiLCJpbnB1dF9mb3JtYXQiOiJjaGFycyJ9)
## Explanation
First we push a 0 or a 1. This is useless, but identifies the programs.
Then we push the string `"0=n;0"` (because strings wrap around). This means the `0` or `1` character code will be the last character on the stack.
We get the first character of the output program, and print if they are equal we print 1, otherwise 0.
The second program is similar except we can just print the first character of the first program so we can skip the `=` to save 1 byte.
[Answer]
# [Motorola MC14500B](https://en.wikipedia.org/wiki/Motorola_MC14500B) Machine Code, 3 bytes
Outputs `0` for truthy and `1` for falsy.
### Program A, 1.5 bytes
```
118
```
Disassembled:
```
1 ; Read input from the I/O pin into RR.
1 ; Read input from the I/O pin into RR.
8 ; Output RR to the I/O pin.
```
### Program B, 1.5 bytes
```
428
```
Disassembled:
```
4 ; Read input from the I/O pin and store (RR AND (NOT INPUT)) into RR.
2 ; Read input from the I/O pin and store (NOT INPUT) into RR.
8 ; Output RR to the i/O pin.
```
### Explanation
Program A outputs the second bit of input, which is 0 for Program A and 1 for Program B.
Program B outputs the complement of the second bit of input, which is 1 for Program A and 0 for Program B.
[Answer]
# Haskell, 21 bytes
#### function A, 11 bytes
`even.length`
#### function B, 10 bytes
`odd.length`
[Answer]
# [Brachylog](https://github.com/JCumin/Brachylog), 2 bytes
```
0
```
[Try it online!](https://tio.run/##SypKTM6ozMlPN/r/3wCIAA "Brachylog – Try It Online")
```
1
```
[Try it online!](https://tio.run/##SypKTM6ozMlPN/r/3xCIAA "Brachylog – Try It Online")
With inspiration from [Neil's Retina answer](https://codegolf.stackexchange.com/a/256059/85334). Both full programs succeed on themselves and fail on each other. Each program unifies the input (and output) with the single numeric literal in the body, which matches the syntax for providing numbers as input.
[Answer]
# [Brainbool](https://github.com/TryItOnline/brainfuck), 6 bytes
A: `1,.`
B: `,+.`
[A with A input](https://ato.pxeger.com/run?1=m70yqSgxMy8pPz9nwYKlpSVpuhaLDXX0ICyowAKECAA)
[A with B input](https://ato.pxeger.com/run?1=m70yqSgxMy8pPz9nwYKlpSVpuhaLDXX0ICyowILFOtpQEQA)
[B with B input](https://ato.pxeger.com/run?1=m70yqSgxMy8pPz9nwYKlpSVpuhaLdbT1ICyowAKECAA)
[B with A input](https://ato.pxeger.com/run?1=m70yqSgxMy8pPz9nwYKlpSVpuhaLdbT1ICyowILFhjpQEQA)
**A explanation:**
```
1 this is comment used for "1" input
, reads character
. and print it back
```
**B explanation:**
```
, reads character; also it is used as "0" input
+ negates the value
. print the value
```
[Answer]
# [MATL](https://github.com/lmendo/MATL) (both programs), score 4
Program A: `oo`
Program B: `I\`
Each program with itself as input outputs a *truthy* result, specifically a numeric array containing *positive integers*. Each program with the other as input outputs a *falsy* result, specifically a numeric arrray containing *at least a zero entry*. See truthy/falsy [criteria](https://codegolf.stackexchange.com/a/95057/36398) in MATL, or use this truthy/falsy [test](https://tio.run/##bc07DoAgEATQnlNsY2j1BB6EUBB/rFkIYZfCwrNjR/xNPW8mOKFaR3ikA1zBYEiEEwpgTEWs0pKL@EO3UirsQTwysGSMmzrfMwvxovTqiBv7c/bj4nz7n3dO5A5bqxmgtxc).
* [Program A with input A](https://tio.run/##y00syfn/Pz///3/1/Hx1AA)
* [Program A with input B](https://tio.run/##y00syfn/Pz///391zxh1AA)
* [Program B with input A](https://tio.run/##y00syfn/3zPm/3/1/Hx1AA)
* [Program B with input B](https://tio.run/##y00syfn/3zPm/391zxh1AA).
### How it works
Program A:
```
o % Implicit input. Convert codepoints to numbers. Gives numeric vector
o % Modulo 2 of each entry. Implicit display
```
Program B:
```
I % Push 3
\ % Implicit input. Modulo (3, of code points). Gives numeric vector. Implicit display
```
[Answer]
# [Desmos](https://desmos.com/calculator), 34 bytes
### Program A, 17 bytes
```
A(l)=\{l[2]=65\}
```
### Program B, 17 bytes
```
B(l)=\{l[2]=66\}
```
Input is a list of character codepoints, and output is `1` for truthy (accepting) and `undefined` for falsey (rejecting).
This is just the first strategy I thought of; there might be better ways out there.
[Try It On Desmos!](https://www.desmos.com/calculator/hgprnijd4r)
[Try It On Desmos! - Prettified](https://www.desmos.com/calculator/2lekd6ww2b)
[Answer]
# [brainfuck](https://github.com/TryItOnline/brainfuck), 7 bytes
Outputs `,` for truthy and `F` for falsy.
### Program A, 3 bytes
```
,F.
```
### Program B, 4 bytes
```
F,,.
```
### Test cases
* [Program A, Input A](https://tio.run/##SypKzMxLK03O/v9fx00PTAAA)
* [Program A, Input B](https://tio.run/##SypKzMxLK03O/v9fx03v/383HR09AA)
* [Program B, Input A](https://tio.run/##SypKzMxLK03O/v/fTUdH7/9/HTc9AA)
* [Program B, Input B](https://tio.run/##SypKzMxLK03O/v/fTUdHD0ICAA)
### Explanation
Program A retrieves and prints the first byte of input, and Program B retrieves and prints the second byte of input. An `F` char (no-op) is inserted into each program in the opposite position of which the program prints out (so that Program A's F is the second char and Program B's F is the first char).
[Answer]
# Java 19 using exit codes, 146 (73 + 73)
```
interface A{static void main(String[]a){System.exit(a[1].charAt(0)%65);}}
```
```
interface B{static void main(String[]a){System.exit(a[1].charAt(0)%66);}}
```
Run it with variations of:
```
cat A.java | xargs java B
echo $?
```
# Java 19 using standard out, 158 (79 + 79) bytes
```
interface A{static void main(String[]a){System.out.print(a[1].charAt(0)==65);}}
```
```
interface B{static void main(String[]a){System.out.print(a[1].charAt(0)==66);}}
```
Run it with variations of:
```
cat A.java | xargs java A
```
[Answer]
# [05AB1E](https://github.com/Adriandmen/05AB1E), ~~6~~ 4 [bytes](https://github.com/Adriandmen/05AB1E/wiki/Codepage)
* -2 thanks to Kevin Cruijssen
### Program A, ~~3~~ 2 [bytes](https://github.com/Adriandmen/05AB1E/wiki/Codepage)
```
0å
```
### Program B, ~~3~~ 2 [bytes](https://github.com/Adriandmen/05AB1E/wiki/Codepage)
```
1å
```
### Test cases
* [Program A, Input A](https://tio.run/##yy9OTMpM/f/f4PBSMAEA)
* [Program A, Input B](https://tio.run/##yy9OTMpM/f/f4PDS//8NDy8FAA)
* [Program B, Input A](https://tio.run/##yy9OTMpM/f/f8PDS//8NDi8FAA)
* [Program B, Input B](https://tio.run/##yy9OTMpM/f/f8PBSMAEA)
### Explanation
`0å` checks whether `0` is in the input, and `1å` checks whether `1` is in the input.
[Answer]
# [R](https://www.r-project.org), 11+12 = 23 bytes
**prog a (11 bytes)**
```
scan(,'')>F
```
[prog a with itself as input](https://ato.pxeger.com/run?1=m72waMGCpaUlaboWq4uTE_M0dNTVNe3ccInA1AIA) = `TRUE`
[prog a with prog b as input](https://ato.pxeger.com/run?1=m72waMGCpaUlaboWq4uTE_M0dNTVNe3cICJrFDGEYIoB) = `FALSE`
**prog b (12 bytes)**
```
!scan(,'')>F
```
[prog a with prog a as input](https://ato.pxeger.com/run?1=m72waMGCpaUlaboWaxSLkxPzNHTU1TXt3CBCqzFEYIoB) = `FALSE`
[prog a with itself as input](https://ato.pxeger.com/run?1=m72waMGCpaUlaboWaxSLkxPzNHTU1TXt3HAKwVQDAA) = `TRUE`
[Answer]
# x86\_32 machine code, 6 bytes
Takes input in ESI (interpreted as a uint8\_t \*), and outputs to AL `0xAC` for truthy and `0x46` for falsy.
[Try it online!](https://tio.run/##lVTfb9owEH73X3FCk2g3AoRWHQJtUve2tz1Waitkxxdw68SZ7bRh2v/Ozk5IQF0figCd78d332f7LLjbHQ6Y7QyM7oXyDq4Wj4ytwe@Ug1fuwFi1VSXXeg8310ApwEsJhZEqVyjBGxBIRUmM5B4t5FxpVW5DKFeUywnu1djn4LtJxN4jNMubDaE5o2uvTMmYwywYMPXYeAb02WojuIaN89x6xqSA8e0Y1lDyAuGiNB5qR/3FHvK6zNb9Slr1QiSoeWVV6QG5U3p/GTT9LKuaysi73PjPIQWdmoCp/YkfuJ4yvooctJFOREuVWUiOtsWOz48jn4@Bi9UbyKFRBG9Ft2mFeQHMmglcD0tREbCVJHMdFpBAZahBK5tby/eAGgssPdPGVC3QGnJTU4Yq0HWOLXraJbO1vBjAOfWSdF4S7gn7kdKe6qICLqVNYsV5g2Od0BOIZ3tPCEka6jrt4UgTILaY06/MsM0TmBuLERedG3AiBpWGsi/LR0LVLEYps5V@Hbadoj2HEzkqHMMgJhzBuZiYELv@j7pTb6i/wyz9@hFqGQ1QNIMR9jguuiCBYzi5Dvqdhos5NaSJoAZ1gVZlND4Q5oC7TKm2UVW7Xbgtx7ZxBM6PNjB0e7d5tcrjyZWiUBpCXprTDQw3r2NAUVHnQ0gOIY1lEGnqrlvXnvoEvQ4yGmZB1zNQa@@@h3mznPe5lalOeT8jVhCuLr0Z0SUx64ufyj8xNnTqxaWdOGxUS6QxttVGf2FYyL/JjET4BvMzJidPkOSex1gnbgU07A@jX@2gwN2km/W7Fdw9jCZUfnuaTnuxAvxdwyeay@ORDujWDPhhhAmdnshJ9xXx2xkj@J6b/Gox5a5grKR/6NeQmNY2kOSoyWJaQu9qg5AUFNqoq@UNY9NZ9DHWvvaj3gN/ISM5iVikZDaNhKSGJBv8aZqkYRVe2MTC2M0uptPL2bx5SGfjw@Ef "Bash – Try It Online")
### Function A, 3 bytes
```
08049001 <a>:
8049001: ac lodsb
8049002: 46 inc esi
8049003: c3 ret
```
### Function B, 3 bytes
```
08049005 <b>:
8049005: 46 inc esi
8049006: ac lodsb
8049007: c3 ret
```
### Explanation
Function A copies the first byte of input to AL with `lodsb`. Function B copies the second byte of input to AL by first incrementing ESI before executing `lodsb`.
When Function A is run with itself or Function B is run with itself, the first/second byte (respectively) is copied to AL, which in both cases ends up being `0xAC`.
When Function A is run with B or Function B is run with A, the opposite byte (`0x46`) is copied to AL.
[Answer]
# [Thue](https://esolangs.org/wiki/Thue), 39 + 39 bytes
```
a::=b
b::=~1
c::=:::
A::=d
d::=~0
::=
c
```
[True](https://tio.run/##K8koTf3/P9HKyjaJKwlI1hlyJQMpKysrLkcgncKVAhI04AKSXMn/uYhVCQA "Thue – Try It Online") [False](https://tio.run/##K8koTf3/P9HKyjaJKwlI1hlyJQMpKysrLkcgncKVAhI04AKSXMn/uf6DBJ24nCAqnaEqQdpduFwQKp0B "Thue – Try It Online")
```
A::=B
B::=~1
C::=:::
a::=D
D::=~0
::=
C
```
[True](https://tio.run/##K8koTf3/39HKytaJywlI1hlyOQMpKysrrkQg7cLlAhI04AKSXM7/uYhVCQA "Thue – Try It Online") [False](https://tio.run/##K8koTf3/39HKytaJywlI1hlyOQMpKysrrkQg7cLlAhI04AKSXM7/uf6DBJO4kiAqk6EqQdpTuFIQKpMB "Thue – Try It Online")
Has an additional newline (actually two) because of TIO implementation issue.
Truthy = `11` or `1\n1` depending on the implementation, in this case, `1\n1\n`
Falsy = `0`
[Answer]
# POSIX Shell + Utilities, 8+9=17 bytes
```
$ cat ff?; echo; wc -c ff?
cmp $0 -
cmp $0 -
9 ff1
8 ff2
17 total
$ ./ff1 < ff1; echo $?
0
$ ./ff1 < ff2; echo $?
1
$ ./ff2 < ff1; echo $?
1
$ ./ff2 < ff2; echo $?
0
```
Some cmp implementations would allow dropping the `-`, for a score of 6+7=13 bytes.
[Answer]
# [Charcoal](https://github.com/somebody1234/Charcoal), 6 bytes
Program A:
```
№SA
```
Program B:
```
№SB
```
* [Try it online!](https://tio.run/##S85ILErOT8z5//9Ry7T3ezY7whkA "Charcoal – Try It Online") Program A with Program A as input.
* [Try it online!](https://tio.run/##S85ILErOT8z5//9Ry7T3ezY7whhOAA "Charcoal – Try It Online") Program A with Program B as input.
* [Try it online!](https://tio.run/##S85ILErOT8z5//9Ry7T3ezY7wRiOAA "Charcoal – Try It Online") Program B with Program A as input.
* [Try it online!](https://tio.run/##S85ILErOT8z5//9Ry7T3ezY7wRkA "Charcoal – Try It Online") Program B with Program B as input.
Explanation: Each program counts the number of `A`s or `B`s in the input respectively, which will be truthy for itself and falsy for the other program.
[Answer]
# [sed](https://www.gnu.org/software/sed/), 35 bytes
### Program A, 17 bytes
```
s/s.*/1/;s/;.*/0/
```
### Program B, 18 bytes
```
;s/s.*/0/;s/;.*/1/
```
### Test cases
* [Program A, Input A](https://tio.run/##K05N0U3PK/3/v1i/WE9L31DfuljfGsgw0MciBAA)
* [Program A, Input B](https://tio.run/##K05N0U3PK/3/v1i/WE9L31DfuljfGsgw0P//3xoiZgATM9QHAA)
* [Program B, Input A](https://tio.run/##K05N0U3PK/3/37pYv1hPS99AH8iwBjIM9f//hwgZwoQM9AE)
* [Program B, Input B](https://tio.run/##K05N0U3PK/3/37pYv1hPS99AH8iwBjIM9bGJAQA)
### Explanation
Program B starts with `;` to distinguish it from Program A.
Program A replaces lines starting with `s` with `1`, and replaces lines starting with `;` with `0`.
Program B replaces lines starting with `s` with `0`, and replaces lines starting with `;` with `1`.
[Answer]
# [gbz80](https://rgbds.gbdev.io/docs/v0.6.0/gbz80.7) [machine code](https://gbdev.io/gb-opcodes/optables/) functions, 8 bytes
(Registers and flags will be referred to in lowercase letters, and the functions in uppercase letters.)
These functions require that the function to test is pointed to by `hl`. Their truthiness is output in the `z` flag: true is a match, false is a non-match.
## Function A, 4 bytes:
```
3e 3e be c9
```
Disassembly:
```
ld a, $3e ; 3e is the opcode of "ld a, d8"
cp [hl]
ret
```
## Function B, 4 bytes:
```
00 af be c9
```
Disassembly:
```
nop
xor a ; set a to 0
cp [hl]
ret
```
We're just checking the first byte of the function using two different ways to set `a` to a constant.
[Answer]
# [PUBERTY](https://esolangs.org/wiki/PUBERTY), 241 bytes
Outputs `0` for truthy and `I` for falsy.
### Program A, 118 bytes
```
0
It is May 1, 1000, :: PM.q is in his bed, bored.His secret kink is t.Soon the following sounds become audible.oh yes
```
### Program B, 123 bytes
```
I
0
It is May 1, 1000, :: PM.q is in his bed, bored.His secret kink is t.Soon the following sounds become audible.oh oh yes
```
### Explanation
Both start with no-ops for simple processing. This answer works in the same way as my [brainfuck](https://codegolf.stackexchange.com/a/256090/92496) answer. Program A prints out the first char of input (not including newlines, which are required for the input to be registered) and Program B prints out the second.
[Answer]
# [GNU sed](https://www.gnu.org/software/sed/), 10 bytes
## Program A: 5 bytes
```
/a/q1
```
## Program B: 5 bytes
```
/b/q1
```
Run with `sed -nf <program_filename> <input_filename>` Both programs output [via their exit code](https://www.gnu.org/software/sed/), where 0 is accepting (or "friend") and 1 is rejecting (or "foe").
By default, `sed` outputs with exit code 0. However, the `q` command in GNU sed can terminate with a different exit code. Program A searches the input text for the letter `a` (which exists in Program A but not Program B). If it's present, then we terminate early with exit code 1. If not, we terminate at the end with the default exit code of 0. Program B does the exact same thing, except that it searches for letter `b` instead of `a`.
[Answer]
# TI-Basic, 8 bytes
### Program A, 5 bytes
```
6-length(Ans
```
### Program B, 3 bytes
```
length(Ans
```
Both programs take input from `Ans` as a string. Both output `2` for truthy and `4` for falsy.
[Answer]
# [Thunno](https://github.com/Thunno/Thunno), \$1\log\_{256}(96)\approx\$ 0.82 bytes
Port of Lecdi's Jelly answer. Falsy = accepting; Truthy = rejecting.
### Program A, \$1\log\_{256}(96)\approx\$ 0.82 bytes
```
!
```
### Program B, 0 bytes
### Test cases
* [Program A, Input A](https://ato.pxeger.com/run?1=m72sJKM0Ly9_wYKlpSVpuhYLFSE0lLsAxgcA)
* [Program A, Input B](https://ato.pxeger.com/run?1=m72sJKM0Ly9_wYKlpSVpuhYLFSE0lLtgIReEAQA)
* [Program B, Input A](https://ato.pxeger.com/run?1=m72sJKM0Ly9_wYKlpSVpuhZo1EJFCAMA)
* [Program B, Input B](https://ato.pxeger.com/run?1=m72sJKM0Ly9_wYKlpSVpuhZo1EIuCAMA)
### Explanation
`!` is the operator for logical `not`.
]
|
[Question]
[
Given a word, treat every letter as its number in English alphabet (so `a` becomes 1, `b` becomes 2, `z` becomes 26 and so on), and check if all of them, including duplicates, are pairwise [coprime](https://en.wikipedia.org/wiki/Coprime_integers).
The input is exactly one word of lowercase English letters. The output is the fact if the word is coprime: any truthy/falsey values, but only two variants of them. Standard loopholes are forbidden.
Test cases:
* `man`: `True`
* `day`: `True` (thanks to Ørjan Johansen)
* `led`: `False` (`l=12` and `d=4` have `gcd=4`)
* `mana`: `True` (though `a` occurs multiple times, 1 and 1 are coprimes)
* `mom`: `False` (`gcd(13,13)=13)`)
* `of`: `False` (thanks to xnor; though `15∤6`, `gcd(15,6)=3`)
* `a`: `True` (if no pairs of letters, treat the word as coprime too)
This is a [code-golf](/questions/tagged/code-golf "show questions tagged 'code-golf'"), so the shortest code in bytes wins!
[Answer]
# [Wolfram Language (Mathematica)](https://www.wolfram.com/wolframscript/), 36 bytes
```
CoprimeQ@@LetterNumber@Characters@#&
```
[Try it online!](https://tio.run/##FYdNDkAwEEbvUomVK0ia2CKsxeLDSJsYZIyV6NWrNu@HoY4Y6mfEtYzVcYpn6q2tSZWkvXkisZWDYE5/2SyPnfhdhzU0OMNjGLspzEZLYmr8OjgR5h3jBw "Wolfram Language (Mathematica) – Try It Online")
---
# [Wolfram Language (Mathematica)](https://www.wolfram.com/wolframscript/), 33 bytes
* Thanks to [Misha Lavrov](https://codegolf.stackexchange.com/users/74672/misha-lavrov) for this three bytes shorter version.
```
CoprimeQ@@(ToCharacterCode@#-96)&
```
[Try it online!](https://tio.run/##y00syUjNTSzJTE78n2b73zm/oCgzNzXQwUEjJN85I7EoMbkktcg5PyXVQVnX0kxT7X9AUWZeSXRanW9iQV21Um5inpKOUk5qCpAEshNBVH4ukExUqo39DwA "Wolfram Language (Mathematica) – Try It Online")
[Answer]
# [Jelly](https://github.com/DennisMitchell/jelly), 10 bytes
```
ØaiⱮgþ`P$Ƒ
```
[Try it online!](https://tio.run/##y0rNyan8///wjMTMRxvXpR/elxCgcmzi/4e7tygcbn/UtEYh8v//3MQ8rpzUFC4gnciVm5/LlQgA "Jelly – Try It Online")
### How it works
```
ØaiⱮgþ`P$Ƒ Main link. Argument: s (string)
Øa Yield "abc...xyz".
iⱮ Find the 1-based index of each c of s in "abc...xyz".
$Ƒ Call the monadic chain to the left.
Yield 1 if the result is equal to the argument, 0 if not.
gþ` Take the GCDs of all pairs of indices, yielding a matrix.
P Take the columnwise product.
For coprimes, the column corresponding to each index will contain the
index itself (GCD with itself) and several 1's (GCD with other indices),
so the product is equal to the index.
```
[Answer]
# [Haskell](https://www.haskell.org/), 48 bytes
```
((==).product<*>foldr1 lcm).map((-96+).fromEnum)
```
[Try it online!](https://tio.run/##JYy7DkIhEAX7@xWGCtRLYmNiInaWfoEas4GLEndhw@P3RYzNnGnOvKC8F8Tuza1LaYzSnJNrth7XJ5/Q5d0KLSlNwFLOh/1GaZ8TnWMj1UPkVou5CoIotgIXNzgcfpNoEMR9mghCNCNweUjOIVbt1f/ZP9YjPEufLfMX "Haskell – Try It Online")
Very straightforward: converts the string to a list of numbers and then checks whether the product is equal to the LCM.
[Answer]
# [Pyth](https://github.com/isaacg1/pyth), 9 bytes
```
{Ism{PhxG
```
[Test suite](http://pyth.herokuapp.com/?code=%7BIsm%7BPhxG&test_suite=1&test_suite_input=%22man%22%0A%22day%22%0A%22led%22%0A%22mana%22%0A%22mom%22%0A%22of%22%0A%22a%22&debug=0)
Explanation:
```
{Ism{PhxG | Full code
{Ism{PhxGdQ | With implicit variables filled
------------+------------------------------------------
m Q | For each char d in the input:
{P | list the unique prime factors of
hx d | the 1-based index of d in
G | the lowercase alphabet
s | Group all prime factors into one list
{I | Output whether the list has no duplicates
```
did Pyth just outgolf Jelly?
[Answer]
# Python 2 - ~~122~~ 118 bytes
*-4 bytes thanks to @JonathanAllan*
This is honestly terrible, but I've spent way too long to not post this.
```
from fractions import*
def f(n):r=reduce;n=[ord(i)-96for i in n];return r(lambda x,y:x*y/gcd(x,y),n)==r(int.__mul__,n)
```
[Try it Online](https://tio.run/##DchLCsMgEADQfU8xu4whbaGLQhM8SSli/LRCHGWiEE9vs3u83Mov0aN3zymCZ21KSLRDiDlxGS/WefBIYmbJzlbjFpLvxBaDuL6ePjEECAT0WdiVygSMm46r1XBMbT7Gdv8ai6fFREJKxkDlplSsm1Ln9MxnoMdBr2YQov8B)
[Answer]
# [05AB1E](https://github.com/Adriandmen/05AB1E), 11 bytes
```
Ç96-2.Æ€¿PΘ
```
[Try it online!](https://tio.run/##yy9OTMpM/V9TVvn/cLulma6R3uG2R01rDu0PODfjv87/3MQ8rpzUFC4gnciVm5/LlciVn8aVklgJAA "05AB1E – Try It Online")
**Explanation**
```
Ç96- # convert to character codes and subtract 96
2.Æ # get all combinations of size 2
€¿ # gcd of each pair
P # product of gcds
Θ # is true
```
[Answer]
# [Brachylog](https://github.com/JCumin/Brachylog), 11 bytes
```
ạ{-₉₆ḋd}ᵐc≠
```
[Try it online!](https://tio.run/##ASsA1P9icmFjaHlsb2cy///huqF7LeKCieKChuG4i2R94bWQY@KJoP//Im1hbmEi "Brachylog – Try It Online")
## Explanation
```
ạ{-₉₆ḋd}ᵐc≠
ạ Split the input into its character codes
{ }ᵐ For each one
-₉₆ Subtract 96 (a -> 1, b -> 2 etc.)
ḋd And find the unique (d) prime factors (ḋ)
c Combine them into one list
≠ And assert they are all different
```
[Answer]
# [Python 2](https://docs.python.org/2/), ~~77~~ ~~68~~ 64 bytes
```
lambda a:all(sum(ord(v)%96%i<1for v in a)<2for i in range(2,26))
```
[Try it online!](https://tio.run/##HchBCsIwEEDRtZ5iNiUzkI1ZFCz1JOpiJI0GkklJasHTR8fV5/31s72KuB4ut544PzwDT5wStnfGUj3uNJzHIc6nUCrsEAWYZqeIisryXNBZNxJ1vU3v1WQWY8GkxWt@4n9L1rC5T8fDWqNs0CwEbNS/ "Python 2 – Try It Online")
Basically, (some pair in the input is not co-prime) if and only if (there is a number i > 1 which divides more than one of the inputs).
[Answer]
# [Python 3](https://docs.python.org/3/), ~~61~~ 59 bytes
Using python bytes as argument:
```
lambda s:all(sum(c%96%x<1for c in s)<2for x in range(2,24))
```
The last divisor to check is 23, the largest prime below 26.
[Try it online!](https://tio.run/##JYzLDoMgEEX3/YrZGCBxU9o0qdEv0S4GhdaEh4Fpol9Pha7OPYt7toM@wd@yGaZs0akFIXVoLU9fx@fm@Wj2/mpChBlWD0n0ssheJKJ/ay5beRcik06UYIBRMYeetaCY1Uvl6fgfwVUie11KhUqlHjvY4uqJG05n6wc "Python 3 – Try It Online")
Thanks to @Dennis for saving two bytes.
[Answer]
# [JavaScript (Node.js)](https://nodejs.org), 60 bytes
```
f=(s,v=23)=>n=v<2||f(s,v-1)&&Buffer(s).every(c=>c%32%v||n--)
```
[Try it online!](https://tio.run/##bcpBCsIwEADAu/9omwVTMD1qevAnId0VJd1IogtC/p5Wj5LrMA8nLvt0f740xwVrJavyUayZwM5s5WJKoa/oE/T99U2ESWUYUTB9lLez7ybTSSmsNVQfOceAY4g3RWpYHQ8A58MfB1xavG/X9Li2@HfrBg "JavaScript (Node.js) – Try It Online")
* Using the idea of `Buffer` from [Shieru Asakoto](https://codegolf.stackexchange.com/users/71546/shieru-asakoto)'s [post](https://codegolf.stackexchange.com/a/172876/44718).
* Thanks to [Arnauld](https://codegolf.stackexchange.com/users/58563/arnauld), saved 5 bytes.
[Answer]
# [Perl 6](https://github.com/nxadm/rakudo-pkg), ~~34~~ 32 bytes
*-2 bytes thanks to nwellnhof*
```
{[lcm](@_)==[*] @_}o{.ords X-96}
```
[Try it online!](https://tio.run/##Hce9CoAgFAbQuZ7i4xJRUY1Bg9BjBCEimZNm2BRir24/0@EcmzdDshdKDYYUFrNaXk2iZmxpOCYRXeidVyfmbhxi0s6DrNypBZlNfbyTv85@SELIs1NeoEKA7r7UeUwP "Perl 6 – Try It Online")
An anonymous codeblock that takes a string and returns True or False. If the lowest common multiple of the letters is equal to the product of the letters than they share no common divisors.
### Explanation:
```
{.ords X-96} # Convert the letters to a list of numbers
{ }o # Pass result to the next codeblock
[lcm](@_) # The list reduced by the lcm
== # Is equal to?
[*] @_ # The list reduced by multiplication
```
[Answer]
# J, 36 bytes
```
[:(1 =[:*/-.@=@i.@##&,+./~)_96+a.&i.
```
## Ungolfed
```
[: (1 = [: */ -.@=@i.@# #&, +./~) _96 + a.&i.
```
## Explanation
```
[: ( ) _96 + a.&i. NB. apply fn in parens to result of right
_96 + a.&i. NB. index within J's ascii alphabet, minus 96.
NB. gives index within english alphabet
(1 = ) NB. does 1 equal...
( [: */ ) NB. the product of...
( #&, ) NB. Flatten the left and right args, and then copy
( +./~) NB. right arg = a table of cross product GCDs
( -.@=@i.@# ) NB. the complement of the identity matrix.
NB. this removes the diagonal.
```
[Try it online!](https://tio.run/##y/qvpKeepmBrpaCuoKNgoGAFxLp6Cs5BPm7/o600DBVso6209HX1HGwdMvUclJXVdLT19Os04y3NtBP11DL1/mtypSZn5CsAFSqkKajnJuapowskoorAuAZQBfm5qAI5qSnqXEDwHwA "J – Try It Online")
[Answer]
# [Jelly](https://github.com/DennisMitchell/jelly), 11 bytes
```
ŒcO_96g/€ỊẠ
```
[Try it online!](https://tio.run/##y0rNyan8///opGT/eEuzdP1HTWse7u56uGvB////cxPzEgE "Jelly – Try It Online")
* Thanks to Dennis for NOTing my booleans
---
```
ŒcO_96g/€ỊẠ
Œc All pairs of characters without replacement
O Code point of each character
_96 Subtract 96. a->1, b->2, etc.
€ For each pair:
g/ Get the greatest common denominator
Ị abs(z)<=1? If they are all 1 then this will give a list of 1s
Ạ "All". Gives 1 if they are coprime, 0 if not.
```
[Answer]
# [MATL](https://github.com/lmendo/MATL), 10 bytes
```
96-YF&fdA&
```
Outputs `1` for coprime, `0` otherwise.
[Try it online!](https://tio.run/##y00syfn/39JMN9JNLS3FUe3/f/XcxDx1AA) Or [verify all test cases](https://tio.run/##y00syfmf8N/STDfSTS0txVHtf4RLVEXIf/XcxDx1LvWUxEogmZOaAiSBIokgKj8XSOanAYlEdQA).
### Explanation
Consider input `'man'` for example.
```
96- % Implicit input: string. Subtract 96 from (the codepoint of) each element
% STACK: [13 1 14]
YF % Exponents of prime factoriation. Each number produces a row in the result
% STACK: [0 0 0 0 0 1;
0 0 0 0 0 0;
1 0 0 1 0 0]
&f % Two-output find: pushes row and column indices of nonzeros
% STACK: [3; 3; 1], [1; 4; 6]
d % Consecutive differences
% STACK: [3; 3; 1], [3; 2]
A % All: gives true if the array doesn't contain zeros
% STACK: [3; 3; 1], 1
& % Alternative in/out specification: the next function, which is implicit
% display, will only take 1 input. So only the top of the stack is shown
```
[Answer]
# Markov algorithm, as interpreted by [eMain](https://freeshell.de//~jcm/projects/live/emain/em-interpreter.html) (~~474~~ ~~484~~ 463 bytes, ~~76~~ ~~78~~ 76 rules)
```
a->
d->b
f->bc
h->b
i->c
j->be
l->bc
n->bg
o->ce
p->b
q->q
r->bc
t->be
u->cg
v->bk
x->bc
y->e
z->bm
cb->bc
eb->be
gb->bg
kb->bk
mb->bm
qb->bq
sb->bs
wb->bw
ec->ce
gc->cg
kc->ck
mc->cm
qc->cq
sc->cs
wc->cw
ge->eg
ke->ek
me->em
qe->eq
se->es
we->ew
kg->gk
mg->gm
qg->gq
sg->gs
wg->gw
mk->km
qk->kq
sk->ks
wk->kw
qm->mq
sm->ms
wm->mw
sq->qs
wq->qw
ws->sw
bb->F
cc->F
ee->F
gg->F
kk->F
mm->F
qq->F
ss->F
ww->F
b->
c->
e->
g->
k->
m->
q->
s->
w->
FF->F
TF->F
!->.
->!T
```
The first 17 rules factor the "composite letters" into their "prime letter" factors, ignoring multiplicity. (E.g., `t` becomes `be` because 20 factors as a product of a power of 2 and a power of 5.)
The next 36 rules (such as `cb->bc`) sort the resulting prime factors.
The next 9 rules (such as `bb->F`) replace a repeated prime factor by `F`, then 9 more rules (such as `b->`) get rid of the remaining single letters.
At this point, we either have an empty string, or a string of one or more `F`s, and the last rule `->!T` adds a `!T` at the beginning. Then the rules `FF->F` and `TF->F` simplify the result to either `!T` or `!F`. At this point, the `!->.` rule applies, telling us to get rid of `!` and halt: returning `T` for a coprime word, and `F` otherwise.
(Thanks to bodqhrohro for pointing out a bug in the earlier version that caused this code to give an empty string on input `a`.)
[Answer]
# [Python 3](https://docs.python.org/3/), ~~90~~ 89 bytes
*-1 byte by numbermaniac*
```
f=lambda q,*s:s==()or all(math.gcd(ord(q)-96,ord(w)-96)<2for w in s)and f(*s)
import math
```
[Try it online!](https://tio.run/##HYzNCsIwEITvfYq9JVuqBwXBYp5EPKymsYH8tMlC8eljt6dvBma@5cdzTtfWnAkU35ZgHfo6VmM05gIUgo7E8/n7sToXq1c83W@DpE0SPi5un23gE1SkZMHpvmLn45ILg1wbT5UrGHiqSEkNoMJkBXujgzkKSL06cbG4js8IS/GJ9a5kxPYH "Python 3 – Try It Online")
Use as `f(*'man')`.
[Answer]
# [Retina 0.8.2](https://github.com/m-ender/retina/wiki/The-Language/a950ad7d925ec9316e3e2fb2cf5d49fd15d23e3d), 45 bytes
```
;
{`\w
#$&
}T`l`_l
M`;(##+)\1*;(#*;)*\1+;
^0
```
[Try it online!](https://tio.run/##K0otycxL/K@q4Z7wn8uaqzohppxLWUWNqzYkISchPofLN8FaQ1lZWzPGUAvI0LLW1Iox1LbmijP4/z83MY8rJzWFC0gncuXm53IlAgA "Retina 0.8.2 – Try It Online") Explanation:
```
;
```
Insert separators between each letter and at the start and end.
```
{`\w
#$&
```
Prepend a `#` to each letter.
```
}T`l`_l
```
Move each letter 1 back in the alphabet, deleting the `a`s. Then repeat the above operations until all the letters have been deleted. This converts each letter to its 1-based alphabet index in unary.
```
M`;(##+)\1*;(#*;)*\1+;
```
Test whether any two values share a common factor greater than 1. (This can find more than one pair of letters with a common factor, e.g. in the word `yearling`.)
```
^0
```
Check that no common factors were found.
[Answer]
# R + pracma library, 75 bytes
`function(w){s=utf8ToInt(w)-96;all(apply(outer(s,s,pracma::gcd),1,prod)==s)}`
I'm using the `gcd` function in the `pracma` library as to my knowledge R does not have a built-in for that. I'm using the approach of comparing the product of the gcds to the numbers themselves.
## 65 bytes (credit: @J.Doe)
`function(w)prod(outer(s<-utf8ToInt(w)-96,s,pracma::gcd))==prod(s)`
[Answer]
# [Japt](https://github.com/ETHproductions/japt), 14 bytes
```
;à2 e_®nR+CÃrj
```
[Try it online!](https://ethproductions.github.io/japt/?v=1.4.6&code=O+AyIGVfrm5SK0PDcmo=&input=LW0gWwpbJ20nLCdhJywnbiddLApbJ2wnLCdlJywnZCddLApbJ20nLCdhJywnbicsJ2EnXSwKWydtJywnbycsJ20nXSwKWydhJ10KXQ==)
Takes input as an array of characters.
### How it works
```
;à2 e_m_nR+C} rj
; Use alternative predefined variables (in this case, C = "a-z")
à2 Get all pairs
e_ Does all pairs satisfy that...
m_ when the character pair is mapped over...
nR+C} conversion from "a-z" to [1..26]
rj then the two numbers are coprime?
```
[Answer]
# [Ruby](https://www.ruby-lang.org/), 56 bytes
```
->s{s.bytes.combination(2).all?{|a,b|2>(a-96).gcd(a-b)}}
```
[Try it online!](https://tio.run/##KypNqvyfZhvzX9euuLpYL6myJLVYLzk/NykzL7EkMz9Pw0hTLzEnx766JlEnqcbITiNR19JMUy89OQXIStKsrf0frZ6bmKeuo6Cek5oCooC8RDCdnwuiIOwq9Vi93MSC6pqKmgKFtOiK2Nr/AA "Ruby – Try It Online")
[Answer]
# Java 10, 86 bytes
```
a->{var r=1>0;for(int i=1,s=0;++i<24;r&=s<2,s=0)for(var c:a)s+=c%96%i<1?1:0;return r;}
```
Port of [*@Vincent*'s Python 3 answer](https://codegolf.stackexchange.com/a/172872/52210).
[Try it online.](https://tio.run/##ZZBBasMwEEX3OcVgSJFxY@xQCo2slNJ1s8mydDGR5VapLQVJNpjgbQ/QI/Yiruy4C6cbgd7/zDzmiA2ujvlnz0u0Fl5QqvMCQConTIFcwG74Ahy0LgUq4IR/oHl9AwypD7qFf6xDJznsQAHrcbU9N2jAsHSb0EIb4meBZOmtZQmNIpmt76i5YTZbDyQcGkOfbzC0EePLh/ulzNLHdJNQI1xtFBja9XRYdKoPpV807Wu0zKHywmTvjFTvo9TF1gnrSFChCkbLP1CKfA58A6@IrubgKs@xnQNdBP8uMZqN8cUM7OS1b60TVaxrF5984EpFbBTAz9c3BJGKObGx08/@wE/GYEvCcBrd9b8)
**Explanation:**
```
a->{ // Method with character-array parameter and boolean return-type
var r=1>0; // Result-boolean, starting at true
for(int s=0, // Sum integer, starting at 0
i=1;++i<24 // Loop `i` in the range (1, 24)
; // After every iteration:
r&=s<2, // If the sum is >= 2: change the result to false
s=0) // And reset the sum to 0
for(var c:a) // Inner loop over the input-characters
s+=c%96%i<1? // If the current character modulo-96 is divisible by `i`
1 // Increase the sum by 1
: // Else
0; // Leave the sum the same
return r;} // Return the result-boolean
```
[Answer]
# Japt, 13 bytes
Takes input as a character array.
```
®c uHÃà2 e_rj
```
[Try it](https://ethproductions.github.io/japt/?v=1.4.6&code=rmMgdUjD4DIgZV9yag==&input=WyJtIiwiYSIsIm4iXQ==) or [verify all test cases](https://ethproductions.github.io/japt/?v=1.4.6&code=rAquYyB1SMPgMiBlX3Jq&input=WwoibWFuIgoiZGF5IgoibGVkIgoibWFuYSIKIm1vbSIKIm9mIgoiYSIKXQotbVI=)
[Answer]
# [Pyt](https://github.com/mudkip201/pyt), ~~23~~ 18 bytes
```
ą1Ĩ6²-⁺ϼƑ⁻ž⁺ĐỤŁ⇹Ł=
```
[Try it online!](https://tio.run/##AS0A0v9weXT//8SFMcSoNsKyLeKBus@8xpHigbvFvuKBusSQ4bukxYHih7nFgT3//2E "Pyt – Try It Online")
```
ą implicit input (string); convert to array of characters
1Ĩ6²-⁺ use bug in arbitrary-base radix interpretation code to
convert lowercase letters to integers
ϼ get unique prime factors for each number
Ƒ flatten array
⁻ž⁺ remove all 1s
ĐỤŁ⇹Ł= is the resulting list the same length as the list of its
unique elements?; implicit print
```
#### Original Approach (23 bytes)
```
ą1Ĩ6²-⁺ĐĐɐǤƑ⁻⇹ŁřĐɐ≠Ƒ*↑¬
```
[Try it online!](https://tio.run/##ATkAxv9weXT//8SFMcSoNsKyLeKBusSQxJDJkMekxpHigbvih7nFgcWZxJDJkOKJoMaRKuKGkcKs//9tb20 "Pyt – Try It Online")
```
ą implicit input (string); convert to array of characters
1Ĩ6²-⁺ abuses bug in arbitrary-base radix interpretation code to
convert lowercase letters to integers
Đ duplicate top of stack
ĐɐǤ get all GCD pairs
Ƒ⁻ flatten array, and decrement each element
⇹ swap top two items on stack
ŁřĐɐ≠Ƒ creates matrix of all 1s except for the main diagonal,
which contains only 0s; then flattens that array
*↑¬ multiplies element-wise the two arrays, gets the max, and
logically negates that value
```
Outputs "True" if coprime, "False" if not
[Answer]
# [Vyxal](https://github.com/Vyxal/Vyxal), 9 bytes
```
øA2ḋvġΠċ¬
```
[Try it Online (with test cases)](https://vyxal.pythonanywhere.com/#WyJBIiwiIiwiw7hBMuG4i3bEoc6gxIvCrCIsIiIsIm1hblxuZGF5XG5sZWRcbm1hbmFcbm1vbVxub2ZcbmEiXQ==)
```
øA # convert letters to index in alphabet
2ḋ # get all combinations of length 2
vġ # get the gcd of each
Π # get the product of this list
ċ # inequality to 1
¬ # logical not
```
Probably golfable.
[Answer]
# q, 121 111 bytes
```
{$[1=count x;1b;1b=distinct{r:{l:{$[0~y;:x;.z.s[y;x mod y]]}[y;]'[x];2>count l where l<>1}[x;]'[x]}[1+.Q.a?x]]}
```
[Answer]
# [JavaScript (Node.js)](https://nodejs.org), ~~87~~ 82 bytes
```
a=>!/\b(11+)\1* (1+ )*\1+\b/.exec(Buffer(a).map(x=>w+=" ".padEnd(x-95,1),w="")&&w)
```
[Try it online!](https://tio.run/##bcoxDoIwFADQ3VPUDuR/CiUdHIgpg4m36PKhrdFAS0Clt6@6GtaX96A3rcNyn591iNZlrzPp7tiYHpQSaFTJQAmGpVHC9I10yQ1weXnvFiCUE82QdLcJzRmXM9lrsJDq9lQprDbNORbFhvk8xLDG0ckx3sADnyhwxMM/j87u8XfTrsdpj383fwA "JavaScript (Node.js) – Try It Online")
### Original approach (87B)
```
a=>!(b=Buffer(a)).some((x,i)=>b.some((y,j)=>i-j&&(g=(p,q)=>q?g(q,p%q):p)(x-96,y-96)>1))
```
[Try it online!](https://tio.run/##bcrdCsIgGMbx8@6iQeN9QQedBBUadCduU1E2P@aK7erNoKPw5IH/j8eKt0jDYsJKnR9lViwLxo/Qs@dLKbmAQOySnyXARgwy3v9qJ7aUobZtQTMIJJaMDw2RhFPEW0DY6PVC9jLIz4j5PniX/CS7yWtQ0MzCNYiHf57kWOPyFlX3c42/3/wB "JavaScript (Node.js) – Try It Online")
[Answer]
# [Stax](https://github.com/tomtheisen/stax), 16 [bytes](https://github.com/tomtheisen/stax/blob/master/docs/packed.md#packed-stax)
```
è'B╕i4à!ùà╫æor4Z
```
[Run and debug it](https://staxlang.xyz/#p=8a2742b8693485219785d7916f72345a&i=man%0Aday%0Aled%0Amana%0Amom%0Aof%0Aa&m=2)
**Explanation**
```
2S{M{$e96-mm{E:!m|A #Full program, unpacked, implicit input
2S #Generate all combinations of size 2
{ m #Map for each element
M #Split into size of 1 element
{ m #Map for each element
$e #Convert to number
96- #Subtract 96
{ m #Map for each element
E:! #Explode array onto stack, are they coprime
|A #Are all elements of array truthy
```
Outputs 1 for True, 0 For false.
There is probably a better way to do the converting to number part, but it works.
[Answer]
# APL(NARS), 16 chars, 32 bytes
```
{(×/p)=∧/p←⎕a⍳⍵}
```
This use method other used that LCM()=×/, it is fast but overflow if input array is enough long;
other alternative solutions a little slower:
```
{1=×/y∨y÷⍨×/y←⎕a⍳⍵}
{1=≢,⍵:1⋄1=×/{(2⌷⍵)∨1⌷⍵}¨{x←97-⍨⎕AV⍳⍵⋄(,x∘.,x)∼⍦x,¨x}⍵}
```
this below it seems 10 times faster(or+) than just above functions
```
∇r←h m;i;j;k;v
r←i←1⋄k←≢v←97-⍨⎕AV⍳m
A: →F×⍳i>k⋄j←i+1⋄→C
B: →E×⍳1≠(j⌷v)∨i⌷v⋄j←j+1
C: →B×⍳j≤k
D: i←i+1⋄→A
E: r←0
F:
∇
```
i prefer this last because it is easier, faster, trusted (becaise less overflow possiblity), easier to write, and how it has to be (even if it has some bytes more...)
[Answer]
# [Thunno](https://github.com/Thunno/Thunno), \$ 13 \log\_{256}(96) \approx \$ 10.70 bytes
```
O96-2zQ.AgP1=
```
[Attempt This Online!](https://ato.pxeger.com/run?1=m72sJKM0Ly9_wYKlpSVpuhZr_S3NdI2qAvUc0wMMbSFiUKkFi3MT8yBMAA)
Port of Emigna's 05AB1E answer.
#### Explanation
```
O96-2zQ.AgP1= # Implicit input
O # Ordinal of each character in the input
96- # Subtract 96 from each
2zQ # Combinations of length 2
.Ag # GCD of each pair
P # Product of this list
1= # Equals 1?
# Implicit output
```
]
|
[Question]
[
A [sign sequence](https://en.wikipedia.org/wiki/Sign_sequence) is an infinite sequence consisting entirely of \$1\$ and \$-1\$. These can be constructed a number of ways, for example:
* Alternating signs: \$1, -1, 1, -1, ...\$
* \$-1\$ for primes, \$1\$ for non-primes: \$1, -1, -1, 1, -1, 1, -1, ...\$
* All \$1\$s: \$1, 1, 1, ...\$
Your task is to write a piece of code that outputs a deterministic sign sequence that no other answer already outputs. You *must* include a proof that your sequence is unique from all sequences posted *before yours* and that your sequence only contains \$1\$ and \$-1\$. You do not have to worry about keeping up to date for newer answers, as they must ensure their sequences are unique, not you.
You may output in any reasonable manner, including (but not limited to):
* Outputting an infinite list/generator/tuple of values
* Outputting the next value in the sequence each time your code is run
* Outputting the sequence infinitely
You may *not* take any input (unless [necessary](https://codegolf.meta.stackexchange.com/q/12681/66833)), so outputing the first \$n\$ terms or the \$n\$th term is not allowed.
I've included my implementation of a sequence as the first answer, to ensure that all answers have to provide a proof of uniqueness.
---
This is a [popularity-contest](/questions/tagged/popularity-contest "show questions tagged 'popularity-contest'"), so the answer with the most votes wins. You should aim to do the following things in your answer:
* Be creative. Avoid simply outputting constant runs of \$1\$s or \$-1\$s or outputting one value when a number is *insert common numeric property here* and the other when not (e.g. primes or Fibonacci numbers).
* Avoid copying others. While all sequences must be unique, aim to be innovative, rather than simply slightly modify another user's sequence (for example, swapping the placements of \$1\$ and \$-1\$)
* Make it clear what your program is doing. Not everyone can read a Jelly, R or Java answer, but they can read an explanation of the answer, as well as an explanation of how/why you chose this specific sequence and the proof of uniqueness included in your answer
Voters should consider the following when casting their votes:
* How creative is the sequence? Has it been done to death before, or is it something you've never seen before?
+ Is the sequence using some properties of \$1\$ and \$-1\$ to be generated, or is it just applying the \$\text{sgn}\$ function to other sequences?
* Is it unique, or is it simply a slight modification on a sequence that many other users have done? If it is a modification, is it uncreative, or has the author seen a property that others haven't?
* How clever is the implementation of the sequence, and how well explained is it? For this, consider both the actual code of the answer and the algorithm it implements. If the code uses a language specific trick you find particularly impressive, it may be worth an upvote. If the implementation of the algorithm is so general than any language could be used, yet is still creative and unique, it's probably worth an upvote. However, if the code is overly convoluted when a simpler method would work, or if the algorithm is incredibly inefficient when a better version exists, consider casting a downvote.
Furthermore, while you may not be able to understand the 10 bytes of 05AB1E posted, if explained well, you should be able to get a solid understanding of how those 10 bytes implement the chosen sequence, and how clever it is. And while you may be able to fluently read Python, if poorly coded with no explanation, you may not be able to fully understand how that program works. Consider this factor when voting.
Voters should *not* vote for an answer for any of the following reasons:
* The program is written in your favourite/least favourite language
+ Voting for the use of tricks within a language are fine. Voting for an answer *because of* the language, is not an acceptable reason
* The program is short/long/written with ASCII characters/written without ASCII characters
* You recognize the user who wrote the answer and you love/hate them
* Any other reason not specified above (e.g. "This answer uses the `e` character, I love it!")
[Answer]
# [05AB1E](https://github.com/Adriandmen/05AB1E), 14 bytes
```
∞v®yÒgm=Ox<.±,
```
[Try it online!](https://tio.run/##yy9OTMpM/f//Uce8skPrKg9PSs@19a@w0Tu0Uef/fwA "05AB1E – Try It Online")
*My first non-trivial 05AB1E answer! Happy for suggestions to improve it.*
The code prints two interleaved sign sequences, both related to the [Pólya conjecture](https://en.wikipedia.org/wiki/P%C3%B3lya_conjecture). In 1919, George Pólya conjectured that the majority (no less than half) of positive integers up to any finite limit \$\ge2\$ have an odd number of prime factors, counted with multiplicity. Mathematically, the summatory Liouville function \$L(n)\$ ([A002819](https://oeis.org/A002819)) was posited to satisfy the inequality
$$
L(n)=\sum\_{k=1}^n\lambda(k)\le0\
$$
for all \$n\ge2\$, wherein
$$
\lambda(k)=(-1)^{\Omega(k)}=\begin{cases}-1,\ \text{$k$ has an odd number of prime factors}\\\phantom{-}1,\ \text{$k$ has an even number of prime factors}\end{cases}
$$
is the [Liouville function](https://en.wikipedia.org/wiki/Liouville_function) ([A008836](https://oeis.org/A008836)), related to the parity of the number of prime factors of \$k\$, and \$\Omega(k)\$ is the prime-factor-counting [omega function](https://en.wikipedia.org/wiki/Prime_omega_function) that respects multiplicity.
The Pólya conjecture was shown to be false in 1958 when Brian Haselgrove proved the existence of an enormous counterexample near \$n=\exp(831.847)\approx1.845\times10^{361}\$. Subsequently, it has been shown that the smallest counterexample is \$n=906\,150\,257\$, and that the conjecture fails for most values of \$n\$ in the range \$906\,150\,257\le n \le 906\,488\,079\$. It is also now known that \$L(n)\$ changes sign infinitely often.
The code prints two values for each integer \$n\ge1\$:
$$
\DeclareMathOperator{\sgn}{sgn}
\begin{gather}
\lambda(n), \tag{1} \\
\sgn\bigl[2L(n)-1\bigr]. \tag{2}
\end{gather}
$$
The first value is the \$n\$th term of [A008836](https://oeis.org/A008836). The second value, chosen to avoid zeros in \$L(n)\$, is (arguably) more interesting. Given the results quoted above, we see that sequence \$(2)\$ alternates between \$-1\$ and \$1\$ infinitely often. However, of its first \$906\,150\,257\$ values, only two (the first and the last) are \$1\$; the intervening \$906\,150\,255\$ values are all \$-1\$.
### Commented code
```
∞v # iterate over all positive integers y
® # push -1
yÒ # push list of prime factors of y (with duplicates)
g # length of this list; yields Ω(y)
m # exponentiate top two stack items; yields -1**Ω(y) = λ(y)
= # print λ(y), keeping it on the stack
O # sum the stack; yields L(y)
x< # push 2*L(y)-1, keeping L(y) on the stack
.±, # print the sign
```
[Answer]
# [Wolfram Language (Mathematica)](https://www.wolfram.com/wolframscript/)
```
primesUpTo[n_] := Select[Range[n], PrimeQ];
sumsOfTwoPrimes[n_] := Union @@ Outer[Plus, primesUpTo[n], primesUpTo[n]];
GoldbachConjectureHoldsFor[n_] := MemberQ[sumsOfTwoPrimes[n], n];
BooleanToSign[TrueOrFalse_] := 2 Boole[TrueOrFalse] - 1;
Do[Print[ BooleanToSign@GoldbachConjectureHoldsFor[2n] ], {n, ∞}]
```
[Try it online!](https://tio.run/##fY5LigJBEET3fYo8QLvQpSI0o@hshvbTropCyp5UW6oypT7MQtx7Cg83F6kpFUEdcJmRES/CKL9Fo3xTqxj3tjHoFvuKBS0ldPswR421FzNFGxQkc5hcLFPZy1wwrlxXP3xV3D2woIYJigLK4NGKiQ4uh0eufDkTasz6e6Xq7YBpl9qCxc@kuBHbO/ULzQrtVPwrTTRKhA9mjYoqnjcbEpUNWNqR0g5v8Q5cDY8PCS1o97JsyCKxyAt4YhRvNnVIQuo9UA6/p/NRxhj/AA "Wolfram Language (Mathematica) – Try It Online")
* `primesUpTo` generates a list of all primes up to `n`, and then `sumsOfTwoPrimes` generates all sums of two such primes.
* This allows `GoldbachConjectureHoldsFor` to check whether `n` is the sum of two primes. (The function works for all `n`, though the Goldbach conjecture itself is concerned only with even `n`.)
* `GoldbachConjectureHoldsFor` returns `True` or `False`, which `BooleanToSign` converts to `1` or `-1` respectively.
* Therefore `BooleanToSign@GoldbachConjectureHoldsFor[2n]` returns `1` if the [Goldbach conjecture](https://en.wikipedia.org/wiki/Goldbach%27s_conjecture) holds for `2n` and `-1` otherwise.
* The `Do[Print[ ... ], {n, ∞}]` prints (in principle) the infinite list of results.
For those looking not to repeat earlier sequences, this sequence starts with a `-1` and then contains only `1`s forever thereafter ... or does it?!
[Answer]
# [Python 3](https://docs.python.org/3/), 84 bytes
```
s=b's=%r\nwhile[print(c%%2*2-1)for c in s%%s]:0'
while[print(c%2*2-1)for c in s%s]:0
```
[Try it online!](https://tio.run/##K6gsycjPM/7/v9g2Sb3YVrUoJq88IzMnNbqgKDOvRCNZVdVIy0jXUDMtv0ghWSEzT6FYVbU41spAnQtVGYYqkKL//wE "Python 3 – Try It Online")
Quine, which outputs 1 or -1 according to the last bit of each byte of the quine, repeating infinitely. Starts `1 1 -1 1 1 1 1 -1 -1 -1`
Previously ~~107~~ 91 bytes. I know it's not [code-golf](/questions/tagged/code-golf "show questions tagged 'code-golf'"), but I couldn't resist golfing it a bit. This does change the sequence slightly but no other sequences are the same so it doesn't affect the competition
[Answer]
# [C (gcc)](https://gcc.gnu.org/), 38 bytes
```
int f() {
return (rand() & 2) - 1;
}
```
[Try it online!](https://tio.run/##RY7BCoMwEETvfsUQsCSoEL2VNB8jsSl7aCrbeCp@u27SQk@7zLxhJgyPEI6DUkbUBp8G4HveOEHznBaRLpgMBoyu2Sv2nCn9yPhi6KIRPKyTc8Noy9N1XwJYWYCoVTstUL2UkDGuOhQljFYS8B5Xg3XLb61Utff/EFuaTw "C (gcc) – Try It Online")
This could be golfed into 21 bytes (`f(n){n=(rand()&2)-1;}`) but this question is not tagged as [code-golf](/questions/tagged/code-golf "show questions tagged 'code-golf'").
In C, random without seeds behave *deterministically* which actually fit the requirement of this question. I don't know how the sequence is generated. But it does generate a list which only contains 1's and -1's, some how.
First 100 generated values are:
```
1 1 -1 1 -1 1 1 -1 -1 -1
1 1 1 1 1 1 -1 1 -1 -1
1 -1 1 -1 1 1 1 1 1 1
-1 1 1 1 -1 1 -1 -1 1 1
-1 -1 -1 1 -1 -1 1 -1 1 1
-1 1 1 -1 -1 -1 1 1 -1 -1
-1 -1 -1 1 -1 -1 1 -1 -1 -1
-1 1 1 -1 1 1 1 -1 1 1
1 -1 -1 1 -1 -1 1 1 1 1
-1 -1 -1 -1 1 -1 1 1 1 1
```
[Answer]
# [Wolfram Language (Mathematica)](https://www.wolfram.com/wolframscript/), 56 bytes
Outputs the sequence infinitely.
Returns 1 if ***n*** is a quadratic residue of p=nextPrime(n) and -1 if ***n*** is a quadratic nonresidue of p.
In number theory, an integer n is called a quadratic residue modulo p if it is congruent to a perfect square modulo p; i.e., if there exists an integer x such that:
\$ {\displaystyle x^{2}\equiv n{\pmod {p}}} \$
Otherwise, q is called a quadratic nonresidue modulo n.
```
Do[p=NextPrime[n,1];Print@Mod[n^((p-1)/2),p,-1],{n,∞}]
```
[Try it online!](https://tio.run/##y00syUjNTSzJTE78/98lP7rA1i@1oiSgKDM3NTpPxzDWGsjMK3HwzU@JzovT0CjQNdTUN9LUKdDRNYzVqc7TedQxrzb2P1iRgkN6tKFB7P//AA "Wolfram Language (Mathematica) – Try It Online")
Let p be an odd prime and gcd(n,p)=1. Then n is a quadratic residue or nonresidue of p according to whether
\$ n^{\frac {p - 1} {2}} \equiv \text {1 (mod p) } \$ or \$ \text{ } n^{\frac {p - 1} {2}} \equiv \text {-1 (mod p)} \$
This is also known as the \$ \text {Legendre symbol (a/b)} \$ and the built-in Mathematica for this is:
```
JacobiSymbol[n,p]
```
Here are the first 100.000 n acuumulated
[](https://i.stack.imgur.com/S7dYM.png)
[Answer]
# [Ruby](https://www.ruby-lang.org/en/)
When I saw this challenge I immediately thought of the ["diagonal infinite proof thing"](https://www.google.com/search?q=diagonal+infinite+proof+thing), appearantly also known as **[Cantor's diagonal argument](https://en.wikipedia.org/wiki/Cantor%27s_diagonal_argument)**.
My idea was to
1. reimplement each of the *N* previous sequences, in the order that they were submitted
2. create a new sequence where each ith element differs from the ith element of the ith previous sequence.
So long as Cantor's diagonal argument is correct (it is), then this should create a new sequence which is different from all the previous sequences.
Starting off with some usefull helpers:
```
def sgn(n) = n >= 0 ? 1 : -1 # New Ruby 3 syntax
def flatten_binary(seq) = seq.map(&:to_s).flat_map(&:chars).map(&:to_i).map { sgn _1 - 1 }
z = 0.step.lazy
n = 1.step.lazy
```
Step 1 turned out to be *a whole lot* of work, espacially as a few of the other answers simply flew over my head. Therefore I've cheated a little bit: Luckily, almost every answer provided a link and/or some copypastable start of the prefix, so for 13 of the sequences I've just copied them over and hardcoded the *N* first elements directly. These are marked with `TODO` in the following piece of code.
To spice things up along the way , I've also tried to interpret each submission and give them their own appropriate names:
```
sequences = [
# caird coinheringaahing's tangent
n.map { sgn Math.tan(_1) },
# user100177's lazy duo - TODO
[1, -1, 1, 1 ,1, -1].cycle,
[1, 1, -1, 1, -1, 1].cycle,
# Dingus's first non-trivial 05AB1E answer - TODO
[1, 1, -1, -1, -1, -1, 1, -1, -1, -1, 1, -1, -1, -1, -1, -1, 1, -1, 1, -1, -1, -1, -1, -1, -1, -1, 1, -1, 1].cycle,
# Noodle9's zigzag
[-1,1].cycle,
# ZaMoC's Rudin-Shapiro Sequence - TODO
[1, 1, -1, 1, 1, -1, 1, 1, 1, 1, -1, -1, -1, 1, -1, 1, 1, 1, -1, 1, 1, -1, 1, -1, -1, -1, 1, 1, 1].cycle,
# user99151's unity
[1].cycle,
# hakr14's undocumented string
n.flat_map { |i| [-1] + [1]*i },
# Greg Martin's Goldbach conjecture - TODO
[-1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1].cycle,
# pxeger's quine - TODO
[1, 1, -1, 1, 1, 1, 1, -1, -1, -1, 1, -1, 1, -1, 1, 1, -1, -1, 1, -1, -1, -1, 1, 1, 1, -1, -1, -1].cycle,
# Command Master's infinite quad
[1, -1, -1, -1].cycle,
# Xi'an's kempnerial
n.map { _1.digits.include?(9) ? 1 : -1 },
# tsh's pseudo random numbers - TODO
[1, 1, -1, 1, -1, 1, 1, -1, -1, -1, 1, 1, 1, 1, 1, 1, -1, 1, -1, -1, 1, -1, 1, -1, 1, 1, 1, 1, 1].cycle,
# Command Master's bidecimals
flatten_binary(Enumerator.produce(2) { _1.to_s(2).to_i }.lazy.drop(1)),
# ovs's gray codes - TODO
[1, 1, -1, 1, 1, -1, -1, 1, 1, 1, -1, -1, 1, -1, -1, 1, 1, 1, -1, 1, 1, -1, -1, -1, 1, 1, -1, -1].cycle,
# Kaddath.
"Kaddath".unpack('H*')[0].to_i(16).to_s(2).chars.map{ |c| sgn(c.to_i - 1)}.cycle,
# Zaelin Goodman's Harshad numbers - TODO
[1, 1, 1, 1, 1, 1, 1, 1, 1, 1, -1, 1, -1, -1, -1, -1, -1, 1, -1, 1, 1, -1, -1, 1, -1, -1, 1, -1].cycle,
# mazzy's tripartite function
z.map { sgn(_1 % 3 - 2) },
# Kevin Cruijssen's Kolakoski sequence - TODO
[-1, 1, 1, -1, -1, 1, -1, 1, 1, -1, 1, 1, -1, -1, 1, -1, -1, 1, 1, -1, 1, -1, -1, 1, -1, 1, 1, -1, -1].cycle,
# ZaMoC's quadratic residue - TODO
[-1, -1, -1, 1, -1, -1, -1, -1, 1, -1, -1, 1, 1, -1, 1, 1, 1, -1, -1, -1, -1, -1, 1, 1, 1, -1, -1, 1].cycle,
# SketchySketch's Liouville function - TODO
[1, -1, -1, 1, -1, 1, -1, -1, 1, 1, -1, -1, -1, 1, 1, 1, -1, -1, -1, -1, 1, 1, -1, 1, 1, 1, -1, -1, -1].cycle,
# bb94's blazin' prefix
z.map { -sgn(420 <=> _1) },
# user100690's unoriginal solution
n.flat_map { |i| [1]*i + [-1] },
# SjoerdPennings's quinvigintal alternation
([1]*25 + [-1]*25).cycle,
# Sheik Yerbouti's period
"This is a unique sequence\0".bytes.lazy.cycle.map { _1 % 2 * 2 - 1 },
# elementiro's pie hole - TODO
[1, -1, -1, 1, -1, -1, 1, -1, -1, -1, -1, 1, 1, 1, 1, 1, 1, -1, 1, 1, -1, 1, -1, 1, -1, 1, -1, -1, -1].cycle,
# DanielOnMSE's square-free semi-primes - TODO
[-1, -1, -1, 1, -1, -1, -1, 1, -1, 1, -1, -1, -1, 1, -1, -1, -1, -1, -1, 1, -1, -1, -1, 1, -1, 1, 1, -1].cycle,
]
```
Step two is pretty trivial:
```
sequences.cycle.each do |sequence|
next_number = sequence.peek
print "#{next_number * -1}, "
# advance all to next position
sequences.each(&:next)
end
```
Prints an infinite sequence starting with:
```
-1, 1, 1, 1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GcSo8w6UgHPOn0UMTB17AHmHs55PnAqcUzZlK-Z3WaOO5kBGbSD3hoDeZtRLWt6Guq_SyvXxkfNvaihnugULN_XQdUs1QqgJQm_21dQVE1xM0Xjhb_hGyn7hMpzyKnjK-2XnlXVXZUFWIvs6No9HATpoRnSBoXECicMzvCxXQsSWw3-_BjyevYP3wcTjoZTNMKuJBOi6BllGal9DmoMom1MvlwMqsXN9JVP4vKATNNp3PiKk1ZcgWi4ihBMvNtezy_kG-nq7ahQSHyCfwO6qRJO-Wb4mqpSX25oeQE93TJLWTlkpzVaB_9prOaGZQZ-ezpa0Vr1PB92GHvtTIS6gYoT0G0uHBmucIoYywdtuqa6u8qUs3vWrXzpngGF2Jy-u3hEdTrSvsjBXa-GLeSRSPn1FpPSVXP_06nRfRrwDeFs67eWrRHkFoBi4eBQtbI3hvhksSpGPxo8RJECckpSiEgebW56LaDvl52IVmgxS2gPlTZtmGRREYmdmDRGqeF80TCOu-9f2xVWg3UPiNxvJNIn-heHyx-A8)
[Answer]
# [Jelly](https://github.com/DennisMitchell/jelly), 8 bytes
```
‘ÆTṠṄaƲß
```
[Try it online!](https://tio.run/##ARoA5f9qZWxsef//4oCYw4ZU4bmg4bmEYcayw5///w "Jelly – Try It Online")
This outputs the series generated by \$f(n) = \text{sgn}(\tan(n+1))\$ as \$n = 0, 1, 2, 3, ...\$, separated by newlines. This only yields \$0\$ iff \$\tan(n+1) = 0\$, which only happens when \$n = 2k\pi-1\$ for some integer \$k\$. As this is only an integer when \$k = 0\$ and \$n = -1\$, this never happens.
## How it works
```
‘ÆTṠṄaƲß - Main link. Takes an integer n (initially 0) on the left
‘ - Yield n+1
Ʋ - To n+1:
ÆT - tan(n+1)
Ṡ - sgn(tan(n+1))
Ṅ - Print and return sgn(tan(n+1))
a - Replace sgn(tan(n+1)) with n+1
ß - Recursively call
```
[Answer]
# [Wolfram Language (Mathematica)](https://www.wolfram.com/wolframscript/), 32 bytes
```
Do[Print@RudinShapiro@n,{n,∞}]
```
[Try it online!](https://tio.run/##y00syUjNTSzJTE78n2773yU/OqAoM6/EIag0JTMvOCOxILMo3yFPpzpP51HHvNrY////AwA "Wolfram Language (Mathematica) – Try It Online")
***[Rudin-Shapiro Sequence](https://mathworld.wolfram.com/Rudin-ShapiroSequence.html)***
[Answer]
# [Bash](https://www.gnu.org/software/bash/), 5 bytes
This outputs all items in the sequence \$1, 1, 1, 1, ...\$ [... the rules do not explicitly forbid it.](https://codegolf.stackexchange.com/a/199534/99151)
```
yes 1
```
[Try it online!](https://tio.run/##S0oszvj/vzK1WMHw/38A "Bash – Try It Online")
[Answer]
# [Python 3](https://docs.python.org/3/)
```
def gray(n):
return n ^ n>>1
previous = n = 0
while True:
n += 1
bitcount = bin(gray(n)).count('1')
print(bitcount - previous)
previous = bitcount
```
[Try it online!](https://tio.run/##PY3BCsIwEETv@Yq5NUEUgzch/QrPgtXVBmQT1kTp18cYTG@zbx8zcUlz4EMpN7rjIZdFszkqQChlYTDO4HG0SkWhtw/5BVehw159Zv8knCTTz0elGwfb4uTTNWRO1Zs863@t2TWoBzuYpkXx9VzlLfpGf6@L3SnlCw "Python 3 – Try It Online")
Sequence starts with `1 1 -1 1 1 -1 -1 1 1 1 -1`.
These are the differences in the number of set bits between adjacent [gray codes](https://en.wikipedia.org/wiki/Gray_code). This happens to be the same sequence as:
* The [Jacobi symbol](https://en.wikipedia.org/wiki/Jacobi_symbol) \$(\frac{-1} n)\$, [A034947](https://oeis.org/A034947)
* The [regular paperfolding](https://en.wikipedia.org/wiki/Regular_paperfolding_sequence)/[dragon curve](https://en.wikipedia.org/wiki/Dragon_curve#Gray-code_method) sequence with `-1` instead of `0`, which can be constructed in the following way:
1. Start with a single `1`
2. Reverse the current sequence of `1` and `-1` and negate every value. Join the original and modified sequence with a `1`. Repeat step 2.
`1` ->
`1 **1** -1` ->
`1 1 -1 **1** 1 -1 -1` ->
`1 1 -1 1 1 -1 -1 **1** 1 1 -1 -1 1 -1 -1` -> ...
Bonus implementation in [Coconut](http://coconut-lang.org/) using this construction:
```
sequence = [1]
print(1)
while True:
new = sequence |> reversed |> map$(-) |> list |> x->[1]+x
new |*> print$(sep='\n')
sequence.extend(new)
```
[Try it online!](https://tio.run/##PYzLCsIwFET3@YosCk2UCt0KzVe4qy4kHTBQb2MeNov@e0wKdjZ34J45etELxZCzxyeCNPjAx/7BrDMURC/Z@jIz@M1FXBkvIawFOehNcYcvnMdU@/tpG9HJWmfjQ72pU0V4Tsd6Oym@6xvhYYf2Tq3cn3/pBSmAJlFgmfMP "Coconut – Try It Online")
[Answer]
# JavaScript, 120 bytes
```
k=>{f=n=>{a=0;if(!(n-1))return 1;for(i=0;++i<n;)if(!(n%i))a += f(i);return 0.5<a?-1:1};for(i=0;++i<k;)console.log(f(i))}
```
Print the Liouville function \$f(n)\$ for every integer \$n\$, [OEIS A008836](http://oeis.org/A008836).
## Explain
The recurrence formula `f(1)=1; n > 1: f(n) = sign(1/2 - Sum_{d<n, d|n} f(d))`.
```
k=>{ // starts a function
f=n=>{ // function for recurrence
a=0; // init accumulator
if(!(n-1)) return 1; // end of recurrence
for (i = 0; ++i<n;) // start loop, from 1 to n-1
if(!(n%i)) a += f(i); // if n is divisible by i, add f(i) to a
return 0.5<a?-1:1 // return sign(1/2 - a)
};
for (i = 0; ++i<k;) console.log(f(i)) // print the sequence
}
```
[Answer]
# [Haskell](https://www.haskell.org/), 55 bytes
```
a=1: -1:(zipWith(*)a$tail b)
b=1:1:(zipWith(*)b$tail a)
```
[Try it online!](https://tio.run/##y0gszk7Nyfn/P9HW0EpB19BKoyqzIDyzJENDSzNRpSQxM0chSZMrCSiJIpUEkUrU/J@bmJmnYGWl4OmvoKHJBebZKqTkcykoFBRl5pUoqCiUJGanKhiaKiRiEUv6DwA "Haskell – Try It Online")
`a` is the infinite sequence here. Neither is very interesting - `a` is `[1,-1,1,1,1,-1]` repeated forever and `b` is `[1,1,-1,1,-1,1]` repeated forever. However, I think this shows how cool Haskell's laziness is: you have two infinite lists dependent on each other. `a` starts with `1` and `-1`, and the rest of it is found by multiplying `a` by the tail of `b`. Similarly, `b` starts with `1` and `1`, and the rest of it is found by multiplying `b` by the tail of `a`.
So the third element of `a` would be `1 * 1 = 1` and for `b` it would be `1 * -1 = -1`. The fourth elements would be `-1 * -1 = 1` for `a` and `1 * 1 = 1` for `b`, and so on.
[Answer]
# [Pyth](https://github.com/isaacg1/pyth), 10 bytes
```
#V=hZ_1VZ1
```
[Try it online!](https://tio.run/##K6gsyfj/XznMNiMq3jAsyvD/fwA "Pyth – Try It Online")
---
Sequence is `-1,1,-1,1,1,-1,1,1,-1,1,1,1,-1,1,1,1,-1,1,1,1...`, or `(-1,(1)*n)*n` for n in [1, ∞).
[Answer]
# [PHP](https://php.net/), 127 bytes
```
$k = base_convert(unpack('H*', "Kaddath")[1], 16, 2);
for(;;$i = $i==strlen($k) ? 0 : $i){
echo ($k[$i++] ? 1 : -1) . "\n";
}
```
[Try it online!](https://tio.run/##DYtBC8IgAEbv@xUfIkybRXbokMmuQT9hjTBnOBZONusS/Xbz8g7v8aKP@dzGQjpB42FWd7dz@LglsXeIxk6svmxqAXI1w2CSJ7yTvYA8Chy4qp7zwpSiY3npqPWalpcLjE4cLfY4Fcm/FeCsn1F0R8em6UuTpW0lxw7kFoiqfjn/AQ "PHP – Try It Online")
It first converts the string `"Kaddath"` to a binary string (`"1001011011000010110010001100100011000010111010001101000"`) then loops on the string to produce the repeated sequence by outputting `1` for each `1` and `-1` for each `0`
Nothing sensational I fear, just warming up for the new golfing year!
EDIT: clearer code formatting, some parts were golfed by habit
[Answer]
# [Wolfram Language (Mathematica)](https://www.wolfram.com/wolframscript/), 256 bytes
Classifies every square-free semi-prime as a 1 or a -1.
```
f[n_]:=Return[SquareFreeQ[n]&&PrimeOmega[n]==2];
g[n_]:=Return[Map[First,FactorInteger[n]]];
h[{a_,b_}]:=Return[List[a*ModularInverse[a,b], b*ModularInverse[b,a]]];
i[{c_,d_}]:=Return[If[Max[{c,d}] == c,-1, 1]];
Do[If[f[n], Print@i[h[g[n]]], 0], {n,∞}]
```
[Try it online!](https://tio.run/##XY@xbsJADIb3PMVNDJUrQUfQSR1QJCQQLYzWKXISk5xELu3lgpCi7DwFD9cXuRqWFgYPtr//t/@GQs0NBVtQjAd0mZnrHYfeO9x/9@Q59cyf6Mxk8uFtw9uGK5JW6zezSKoHwYa@MLW@C5BSEVq/coEr9kIbYWscKIM8G/8Ea9sFpJdNW/ZHEvzEvmMkyA2o/HmcA919LA5FBuV/n9VBbp9lDuVolNaqgNcZqNkNX7a3tSQTT0ngwrvFGqv7U6CmUoODn8t1NEkSY/wF "Wolfram Language (Mathematica) – Try It Online")
First 10 terms
```
-1,-1,-1,1,-1,-1,-1,1,-1,1...
```
Which correspond to classification of the following square-free semi-primes:
```
6, 10, 14, 15, 21, 22, 26, 33, 34, 35...
```
Sequence definition:
Let \$n\$ be a Square-Free Semiprime, and let \$p\$ and \$q\$ be the two distinct prime numbers (positive) that uniquely produce \$n\$:
$$n = pq$$
It follows from [Bezout's Identity](https://mathworld.wolfram.com/BezoutsIdentity.html) that \$\exists a, b \in \mathbb{Z} \$ such that:
$$ap + bq = 1$$
Now, as both \$p\$ and \$q\$ are positive, it follows that \$a\$ and \$b\$ have opposite signs. Possible values for \$a\$ and \$b\$ can be given by the modular equations
$$ ap \equiv 1 \mod q $$
$$ bq \equiv 1 \mod p $$
Whereby choosing a representative for \$a\$ or \$b\$ enforces the choice for the representative of the other.
Let \$c\$ be the smallest positive representative of \$a\$'s equivalence class.
Similarly, let \$d\$ be the smallest positive representative of \$b\$'s equivalence class.
Thus, it follows that:
$$ cp + dq = 1 + n$$
Now we can decide on a binary classification of \$n\$ conditioned on the following:
$$cp > dq$$
Or in other words which prime number contributes the most to the sum: \$ cp + dq = 1 + n\$
As it is arbitrary, we let \$p < q\$ (One of the primes is always smaller than the other as they are not equal, otherwise \$n\$ would not be square-free), thus if \$cp > dq\$ we produce a \$-1\$, otherwise a \$1\$.
**EXAMPLE**
Consider the semi-prime \$n = 21\$ which is uniquely factorised by \$3\$ and \$7\$. By definition we assign the smaller prime to the variable \$p\$.
$$p = 3$$
$$q = 7$$
Now we can find infinitely many pairs of integers \$a\$ and \$b\$ such that:
$$ 3a + 7b = 1$$
These values can be found by the extended-Euclidiean algorithm (An algorithm used to solve modular equations like the ones listed previously). Let's find one of these pairs, specifically the one where \$a\$ and \$b\$ have the smallest magnitude. In this case it is easy to verify (and verbose to show via the extended-Euclidean algorithm) that the two such values are:
$$a = -2$$
$$b = 1$$
Now if we were to add \$n\$ to both sides of \$ap + bq = 1\$
We get:
$$pq + ap + bq = 1 + n$$
$$(q + a)p + bq = 1 + n$$
Thus we let \$c = q + a\$ and \$d = b\$
For the specific example this yields:
$$c = 5$$
$$d = 1$$
Resulting in:
$$5\*3 + 1\*7 = 1 + 21$$
\$3 < 7\$ and \$5\*3 > 1\*7\$ thus by definition we classify \$21\$ as a \$-1\$.
[Answer]
# [C (gcc)](https://gcc.gnu.org/), 14 bytes
```
n=1;f(){n=-n;}
```
[Try it online!](https://tio.run/##PYxBCsMgFET3nmIICEoU4trYk3RTDIa/6G9Iugue3XxpyWxmeDwm@zXn1jiFWIw9OXmOtRF/8X4RG6tOBUn57DCdEhKmKDUjTDLGkSx@Tk9XDlHkK95w2wUXM@gF/gG9PHlwIIfj71RV2wU "C (gcc) – Try It Online")
Next value is returned every time \$f\$ is called.
First answer to repeat alternating signs: \${-1, 1, -1, 1 \dots}\$
[Answer]
# [R](https://cran.r-project.org/), 33 bytes
Inspired from an [earlier code-golf challenge](https://codegolf.stackexchange.com/a/217127/85958), on the Kempner series, this R code print out `1` when integer contains the digit 9 and `-1` otherwise:
```
while(T<-T+1)show(2*grepl(9,T)-1)
```
[Try it online!](https://tio.run/##K/r/vzwjMydVI8RGN0TbULM4I79cw0grvSi1IEfDUidEU9dQ8/9/AA "R – Try It Online")
[Answer]
# [05AB1E](https://github.com/Adriandmen/05AB1E)
```
2[bxS<»,
```
[Try it online!](https://tio.run/##yy9OTMpM/f/fKDqpItjm0G6d//8B "05AB1E – Try It Online")
Repeatedly converts `a` to binary, replaces 0 with -1 and then set the new `a` to `a` in binary interpreted in base-10, starting with `a=2`.
EDIT: Turns out it is [A008559](https://oeis.org/A008559)
Explaination:
```
2 Pushes 2
[ infinite loop
b convert to binary (e.g. "10")
x pushes tos and itself doubled.
as strings is 05AB1E are numbers, 10 gets interpreted as a number
(e.g. 10, 20)
S converts the top of the stack to a string of characters (e.g. ["2", "0"])
< subtract 1, which vectorizes.
because in 05AB1E strings are numbers, it subtract 1 from each of the digits
» join by newlines
, print
```
[Answer]
# [PowerShell](https://github.com/TryItOnline/TioSetup/wiki/Powershell), 20 bytes
```
for(){2*!(++$x%3)-1}
```
[Try it online!](https://tio.run/##K8gvTy0qzkjNyfn/Py2/SEOz2khLUUNbW6VC1VhT17D2/38A "PowerShell – Try It Online")
`1` for divisible by 3, `-1` for other
[Answer]
# [PowerShell](https://github.com/TryItOnline/TioSetup/wiki/Powershell), 68 45 43 bytes
-an enormous 23 bytes thanks to Mazzy! The madlad.
Prints 1 when the integer is a Harshad number (it is divisible by the sum of it's own digits).
```
for(;){2*!(++$x%($x-replace'','+0'|iex))-1}
```
[Try it online!](https://tio.run/##K8gvTy0qzkjNyfn/Py2/SMNapUI3p0TB0MDAQLPaSEtRQ1tbpUJVAyhalFqQk5icqq6uo65toF6TmVqhqalrWPv/PwA "PowerShell – Try It Online")
Link is to a longer version of the code that terminates after 1000 signs
[Answer]
# Java
My lambda functions below outputs the Kolakoski sequence ([A000002](http://oeis.org/A000002)), where the `1` and `2` are mapped to `-1` and `1` respectively.
The Kolakoski sequence is a self-referential sequence which defines: \$a(n)\$ is the length of the \$n^{th}\$ run, starting at \$a(1)=1\$. Here a visual of the sequence, with the runs underneath it (both lines form the same exact sequence of 1s and 2s):
```
1 2 2 1 1 2 1 2 2 1 2 2 1 1 2 1 1 2 2 1 2 1 1 2 1 ...
— ——— ——— — — ——— — ——— ——— — ——— ——— — — ——— — —
1 2 2 1 1 2 1 2 2 1 2 2 1 1 2 1 1 ...
```
Which results in the following lambda function in Java:
```
import java.util.*; // Required import for List/ArrayList/Arrays
()->{ // Method without parameter nor return-type:
List<Integer> sequence = new ArrayList(Arrays.asList(1,2,2));
// Start the sequence at 1,2,2
for(int i=2;;i++){ // Loop `i` from 2 upwards indefinitely:
int valueToPrint = sequence.get(i-2); // Get the `i-2`'th value from the sequence
System.out.print(valueToPrint*2-3 // Convert 1 to -1 and 2 to 1, and print it
+ " "); // with space delimiter
int valueToAdd = i % 2 == 0 ? // If `i` is even:
1 // Create a value 1
: // Else (`i` is odd instead):
2; // Create a value 2
sequence.add(valueToAdd); // Add that value to the sequence
if(sequence.get(i) == 2) // And if the `i`'th value of the sequence is 2:
sequence.add(valueToAdd); }} // Add that same value again
```
[Try it online.](https://tio.run/##jVRhi5tAEP1@v2I4KNVLNNV@i/VKKKUc3B2l6bfjINvsmGyqu3Z3TQghvz0dV2uSXoQsijvKvnnvzTgrtmbBiv8@iKJU2sKK4rCyIg/vEri8RiP4gX8qoZFDeypTGh6FsaOJ1mx73Jmbec6MgScm5O4GQEiLOmNzhOc6BFgrwWHu@QlFe7rpMpZZMYdnkJDCwfOD@x1cs4jWE9ql4rAR9KgslEyzAikjSOKn0VZaBnZb4pjS1CQ/PRCfBep7MCQIJfFKQeIGOhleIyNkxkXRMB7GvmN77SJaMLWMTLJLPOZhFhwYIZF5HhkDIo2TRAwG/q4f6VGpEmZiBplWBcRQlRumuSFjOWZCCov5duzY1Yhrllf4U33XdZB2ycMFWk8EsZ84TPiGDbkZvZu9t8vmXJPilLTDnW6NxSIkf8OyxvVOk9zFwceOK3xRco0kPAKrIIiASU6UaR8N3d6dB2F73BzALdz6yRsPXH3BlHUbccxFQar1/5onnJNiAe8oY5rCB/h8jvGQORuFAVyjHPdQiHrKQNo0MktlbL2KLgOM@@oIX3OD4LUUFJEVknxl3O@jEidXUokdQFdrxrl39OSSnbVVdsla6@r6vCm6yLzz5vFrU2P/Ap0JFVZkbT@ddJPKzn8Akh3/09pPdr8/19pxNfRnt8hsQdPlkDTTo6x@5TQ92iHixktBn72ppWZbvLwyvxk8Muymzv7wFw)
Golfed this would be **109 bytes**:
```
v->{var s="122";for(int i=1;;s+=(s.charAt(i)>49?11:1)<<i%2)System.out.print((s.charAt(++i-2)-48)*2-3+" ");}
```
[Try it online.](https://tio.run/##RY9NCsIwEIX3nmIoCIklhUQXaqziAXQjuBEXY1o1WlNJ0oBIz17jDwgzDG@YeXzvggHZpbh2qkLnYIXaPHsA2vjSHlGVsH5LgFDrAhTZvkegMu7a2LGcR68VrMFADl1g82dACy5PuBCJPNaWRC/QOZfSpTlxmTqjXXqi6Xw0WXA@5XQ2031BNw/ny1tWNz672/hD/rdpqpmgbDSmA8GGaQIJlW0nvwD35lBFgB/Hh/MWU5CNjy6n3R7pN4HJFDFNVf3g2@4F)
**Explanation:**
```
v->{ // Method with empty unused parameter and no return-type
var s="122"; // Sequence-String, starting at 1,2,2
for(int i=1; // Loop from `i` upwards indefinitely:
; // After every iteration:
s+= // Append to the sequence-String:
(s.charAt(i)>49? // If the `i`'th digit is a 2:
11 // Use 11
: // Else (the `i`'th digit is a 1 instead)
1) // Use a 1
<<i%2) // And bitwise left-shift it by `i` modulo-2
// (1 and 11 are 1 and 1011 in binary respectively.
// Left-shifting this by 0 for even `i` won't change them,
// but left-shifting them by 1 for odd `i` would become
// binary 10 and 10110, which are the integers 2 and 22)
System.out.print( // Print:
(s.charAt(++i-2) // The `i-2`'th character
// (after we've first increased `i` by 1 with `++i`)
-48) // converted from character to integer
*2-3 // and transformed from 1/2 to -1/1 respectively
+" ");} // Appended with a space delimiter
```
[Answer]
# [Raku](https://raku.org/)
```
(|(1 xx 420), -1, |(1 xx *))
```
Returns `-1` for the 421st element and `1` elsewhere.
[Answer]
# JavaScript - 92 bytes
```
x=[];for(i=1;i<Infinity;i++){x.push(...new Array(i).fill("1"));x.push("-1")};console.log(x);
```
Not the most original solution, but the shortest JavaScript one to date...
The array we end up with will never actually be printed, but if you replace `Infinity` with something else like `10`, you can see the pattern.
The `i`-th iteration of the infinite loop adds `i` 1s to the array then adds a `-1`.
[Answer]
# BRASCA, 23 bytes
```
1[25S[1n{]x25S[01-n{]x]
```
[Try it online!](https://tio.run/##zVt7c9s2Ev9fnwK1rpVUS7aUR5P4LPfsJL26reOM5U57o1F5EAlJTEmCJUHLmrT96uku@BBfEsH4qZnEEgHs/vaBxQJYuiux4M7Tl673ybRd7gnir/wusalYNGYet4kwbUbiJosxN3zsUceAP1ED/oJ/c9aIHgiP6mxK9d8bDd2ivk9OPOrr9DV@P2gQ@Ozs7IwEdOgSj81NXzDPJ0CFXFHPpFOL@dBBdjTYjGia6ZhC09o@s2adg4ZswE9T0pADEzJJI3be82WHIRlPss8pPOtnH00zj9Y8jj1GlgwYUMN05oRdMQ@0hl@pT/QFBVmR77d5xh500WxuMKD7HbV8lsL93nSZ0TMdYlBBk8fmjDhcmgCGA7M906dCrNqdg6RLij500HA4kF@PQJTtzvjgoDeYZAbNuEe0LtEIMGVOYDOPCtbOkcoxKmGG9vIDSyDTbMsYWXYLT/M4spbZo67LHKPNPaMdEu50ku4MdFYlOXjJWqvfU3SiyDhTxhzighEEM8iKiZx9qIWqWmlxj6KNLhemT5amZRFfcPABCt/EgpEpGPx3JojLfVOY3Ml53HJhWkyzOHd9IPrxrwxFRnR0CHRYJOVyZO5lCWAPLWopeqkeOlQsd/N94C8I2HMKnQWXVKVmk8njQgct7CDN3cXeKUMXjYHtaepX1AoY4bO1syOnEi7YHvHAr1uZoMVlp85mQaZcCIgywHmrWFrYr0o60/GZJ9r9sEu1gEoIcESW/2bJ1wCKwnOXyMCaY8HdOOblY0RCNjtDPCYCz0k5TXESRV1SwJBNOO1yaCpVwN208PcAsx9rbAQzEAHFcT/B5DOhxQ8jk8Q/s/jip2QI04nulEQaGke5tYJCrPnR07LR0@LolM@lsbf8yAVLJzDGqduSKDMFQxk75XL364pbJD3tlCulH5nwApdSn5WKLFvyTpXiE/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tx8SbviqWD12vSy7XQV2Y2T3C5a99mTNbFhbvF3dYc77BSa9WzdYmZ1SbzCpsNAmqRKh0vXQlcW0pdJOctLCknxXsh7dqai9XOlM8zQs7JetrsfkQYefvJ6Hr4BFZUbFCvfymmOczEUBmpf4ToApIOWakeWCObB15sDYk94qTNAVsJ3BrtioqDuuV8cUvoZWQHOOrOXdvDyvNUVDPUgWipsicLkKgOaZvJqIX1LLv5ymFFrYtc5cQX5kqymHCY01LJ4XuCL3wkgxSkYD38o/EA7RkDlxmiNus/DlviVzBFl63Jl38YSVL8E4BDjxLNwwRd15e3FxfnFAyobn7jTDAcnrq3sQBm0qNACXP9xOiRDW15/aeMuH/iLz90bdhHzjlehnnujR4caFer0toxt2J5/@AQ)
Outputs 25 `1`'s, then 25 `-1`'s, then repeats.
[Answer]
# [C (gcc)](https://gcc.gnu.org/), 111 bytes
```
int i;
int main( void ){
printf("%d ", "This is a unique sequence"[i++ % 26] % 2 * 2 - 1);
main();
}
```
[Try it online!](https://tio.run/##JUw7CoAwFNt7ilAQ6m/QwcVruIlDqVXfYP27iGevTw35EAIxaW@M9@R2UCnEm6Mmp3BO1CK8hABjXnnolAxayASyGmgDU@NwtBwWm2V3xsqa4hgB8qJ5HRErRRaW/833zOX2/gE "C (gcc) – Try It Online")
The program prints the following sequence periodically
```
-1 -1 1 1 -1 1 1 -1 1 -1 1 -1 1 1 1 1 -1 1 1 1 1 1 -1 1 1 -1
```
[Here it becomes evident](https://tio.run/##S9ZNT07@/z8zr0Qh05qLC0TnJmbmaSiU5WemKGhWc3EpAEFBEVAiTUNJNUVBSUdBKSQjs1gBiBIVSvMyC0tTFYpTgWRecqpSdKa2toKqgpFZLIhU0AJiXQVDTWuIMYoamapGZpoKamoKBaUlxRpKSjAZsJ1ATu3//wA)
Any bonus point for being 111 bytes?
[Answer]
# [Pyt](https://github.com/mudkip201/pyt), 17 bytes
```
1`ĐĐĐŚ⇹ąŁ+|2*⁻ƥ⁺ł
```
[Try it online!](https://tio.run/##K6gs@f/fMOHIBBA8OutR@84jrUcbtWuMtB417j629FHjrqNN//8DAA "Pyt – Try It Online")
Starting at n=1, outputs 1 if n is divisible by the sum of its digits PLUS its length when written in base 10, otherwise outputs -1.
Sequence begins: [-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,1,-1,-1,-1,-1,-1,1,-1,-1,-1,1]
```
1 push 1
` ł do... while top of stack is truthy
ĐĐĐ Đuplicate three times
Ś digit Śum
⇹ swap top two items on stack
ąŁ convert to ąrray of digits; get Łength
+ add
| does the sum divide n?
2*⁻ coerce boolean to integer, double and decrement
ƥ ƥrint
⁺ increment
```
It is different from all of the previous sequences:
* It differs from [caird coinheringaahing's Jelly answer](https://codegolf.stackexchange.com/a/217176/116013) in the first output (-1 vs 1)
* It differs from [user100177's Haskell answer](https://codegolf.stackexchange.com/a/217177/116013) in the first output (-1 vs 1)
* It differs from [Dingus's 05AB1E answer](https://codegolf.stackexchange.com/a/217178/116013) in the first output (-1 vs 1)
* It differs from [Noodle9's C answer](https://codegolf.stackexchange.com/a/217179/116013) in the second output (-1 vs 1)
* It differs from [ZaMoC's Wolfram Language answer](https://codegolf.stackexchange.com/a/217180/116013) in the first output (-1 vs 1)
* It differs from [user99151's Bash answer](https://codegolf.stackexchange.com/a/217206/116013) in the first output (-1 vs 1)
* It differs from [hakr14's Pyth answer](https://codegolf.stackexchange.com/a/217208/116013) in the second output (-1 vs 1)
* It differs from [Greg Martin's Wolfram Language answer](https://codegolf.stackexchange.com/a/217212/116013) in the second output (-1 vs 1)
* It differs from [pxeger's Python answer](https://codegolf.stackexchange.com/a/217214/116013) in the first output (-1 vs 1)
* It differs from [Command Master's 05AB1E answer](https://codegolf.stackexchange.com/a/217215/116013) in the first output (-1 vs 1)
* It differs from [Xi'an ні війні's R answer](https://codegolf.stackexchange.com/a/217222/116013) in the 8th output (-1 vs 1)
* It differs from [tsh's C answer](https://codegolf.stackexchange.com/a/217228/116013) in the first output (-1 vs 1)
* It differs from [Command Master's 05AB1E answer](https://codegolf.stackexchange.com/a/217229/116013) in the first output (-1 vs 1)
* It differs from [ovs's Python 3 answer](https://codegolf.stackexchange.com/a/217246/116013) in the first output (-1 vs 1)
* It differs from [Kaddath's PHP answer](https://codegolf.stackexchange.com/a/217275/116013) in the first output (-1 vs 1)
* It differs from [Zaelin Goodman's PowerShell answer](https://codegolf.stackexchange.com/a/217348/116013) in the first output (-1 vs 1)
* It differs from [mazzy's PowerShell answer](https://codegolf.stackexchange.com/a/217365/116013) in the third output (-1 vs 1)
* It differs from [Kevin Cruijssen's Java answer](https://codegolf.stackexchange.com/a/217423/116013) in the second output (-1 vs 1)
* It differs from [ZaMoC's Wolfram Language answer](https://codegolf.stackexchange.com/a/217426/116013) in the fourth output (-1 vs 1)
* It differs from [atzlt's JavaScript answer](https://codegolf.stackexchange.com/a/218426/116013) in the first output (-1 vs 1)
* It differs from [bb94's Raku answer](https://codegolf.stackexchange.com/a/218428/116013) in the first output (-1 vs 1)
* It differs from [user100690's Javascript answer](https://codegolf.stackexchange.com/a/218447/116013) in the first output (-1 vs 1)
* It differs from [SjoerdPennings's BRASCA answer](https://codegolf.stackexchange.com/a/218934/116013) in the first output (-1 vs 1)
* It differs from [anotherOne's C answer](https://codegolf.stackexchange.com/a/218944/116013) in the third output (-1 vs 1)
* It differs from [elementiro's MATLAB/Octave answer](https://codegolf.stackexchange.com/a/226524/116013) in the first output (-1 vs 1)
* It differs from [DanielOnMSE's Wolfram Language answer](https://codegolf.stackexchange.com/a/226722/116013) in the fourth output (-1 vs 1)
* It differs from [daniero's Ruby answer](https://codegolf.stackexchange.com/a/240639/116013) in the second output (-1 vs 1)
[Answer]
# [05AB1E](https://github.com/Adriandmen/05AB1E), 4 bytes
```
₄Þ·<
```
[Try it online!](https://tio.run/##yy9OTMpM/f//UVPL4XmHttv8/w8A "05AB1E – Try It Online")
Prints [1, -1, -1, -1] repeated forever
```
₄ push 1000
Þ repeat infinitly - [1, 0, 0, 0, 1, 0, 0, 0, ...]
· double - [2, 0, 0, 0, 2, 0, 0, 0, ...]
< substract 1 - [1, -1, -1, -1, 1, -1, -1, -1, ...]
```
[Answer]
# MATLAB/Octave
```
SymbPi = sym(pi);
detail = sym(1);
while 1
bool = isAlways(mod(SymbPi,2*detail) > detail);
if bool
fprintf('1,');
else
fprintf('-1,');
end
detail = detail / 2;
end
```
[Try it online!](https://tio.run/##y08uSSxL/f8/uDI3KSBTwVahuDJXoyBT05orJbUkMTMHKmIIFCjPyMxJVTDkUgCCpPx8kFRmsWNOeWJlsUZufooGxAgdIy2ITk0FOwUoyxqsJzMNrA3MBoK0gqLMvJI0DXVDHXWoitSc4lQMaV0k@bwUMA13GpShr2BkzQWU/P8fAA "Octave – Try It Online")
In theory can work forever but at some point it raches maximal precision.
Utilizes π number. In each loop iteration it calculates remainder from division by `2*detail` and checks whether its bigger than `detail`. `detail` is halved each iteration so it's: 1, 0.5, 0.25, 0.125, 0.0625 ... We're basically converting π to binary form. And for each so calculated boolean if it's true we print `1,` if not `-1,`.
Also, I used `fprintf` instead of classic `disp` just so everything will be nicely in one line.
]
|
[Question]
[
Happy New Year 2024!
2024 is a [**tetrahedral number**](https://en.wikipedia.org/wiki/Tetrahedral_number). A tetrahedral number is a number that can be represented in the form \$n(n+1)(n+2)/6\$ for some positive integer \$n\$. Or, equivalently, they are the sum of the first \$n\$ [triangular numbers](https://codegolf.stackexchange.com/q/122087/9288). They are also the number of objects in a triangular pyramid which has \$n\$ objects on each of its edges.
For example, \$10\$ is a tetrahedral number because \$10 = \frac{3 \times 4 \times 5}{6}\$.
Here are the first few tetrahedral numbers:
```
1, 4, 10, 20, 35, 56, 84, 120, 165, 220, 286, 364, 455, 560, 680, 816, 969, 1140, 1330, 1540, 1771, 2024, ...
```
This is sequence [A000292](https://oeis.org/A000292) in the OEIS.
## Task
Given a positive integer \$n\$, determine whether \$n\$ is a tetrahedral number.
This is [code-golf](/questions/tagged/code-golf "show questions tagged 'code-golf'"), so the shortest code in bytes in each language wins.
This is also a [decision-problem](/questions/tagged/decision-problem "show questions tagged 'decision-problem'"), so you may use your language's convention for truthy/falsy (swapping truthy and falsy is allowed), or use two distinct, fixed values to represent true or false.
[Answer]
# [R](https://www.r-project.org/), ~~32~~ ~~31~~ 29 bytes
```
function(n)n%in%choose(3:n,3)
```
[Try it online!](https://tio.run/##K/qfpmCj@z@tNC@5JDM/TyNPM081M081OSM/vzhVw9gqT8dY83@ahqGBJheQBBFGIMIYRJho/gcA "R – Try It Online")
Based on the observation on wiki or OEIS that \$Te\_n={{n+2}\choose{3}}\$; `:` ranges downwards for the case of \$n=1\$.
[Answer]
# [Vyxal 3](https://github.com/Vyxal/Vyxal/tree/version-3) `R`, 3 bytes
```
@@c
```
[Try it Online! (link is to literate version)](https://vyxal.github.io/latest.html#WyJsUiIsIiIsImN1bS1zdW0gY3VtLXN1bSBjb250YWlucyIsIiIsIjEwIiwiMy40LjAiXQ==)
Simply cumulative sum twice, and check if the input is in that.
R flag casts num to range for cumsum
[Answer]
# [Retina 0.8.2](https://github.com/m-ender/retina/wiki/The-Language/a950ad7d925ec9316e3e2fb2cf5d49fd15d23e3d), 26 bytes
```
.+
$*
(^(1)|(?<2>1\2)\1)+$
```
[Try it online!](https://tio.run/##K0otycxL/K@q4Z7wX0@bS0WLSyNOw1CzRsPexsjOMMZIM8ZQU1vl/39DLiMuYy4TLlMuMy5zLgsuSy5DAwA "Retina 0.8.2 – Try It Online") Link includes test cases. Explanation: The first stage just converts to unary; the second stage adds successive triangular numbers to see if this will exactly consume the unary number. The `?<2>` syntax reuses capturing group `2`; the equivalent in Perl is to use alternative capture group numbering:
# [Perl 5](https://www.perl.org/) `-p`, 33 bytes
```
$_=(1x$_)=~/((?|^(1)|(1\2)\1))+$/
```
[Try it online!](https://tio.run/##K0gtyjH9/18l3lbDsEIlXtO2Tl9Dw74mTsNQs0bDMMZIM8ZQU1NbRf//f0MuIy5jLhMuUy4zLnMuCy5LLkODf/kFJZn5ecX/dQtyAA "Perl 5 – Try It Online") Link includes test cases.
[Answer]
# [MATL](https://github.com/lmendo/MATL), 6 bytes
```
t:tY+m
```
Try at [**MATL online!**](https://matl.io/?code=t%3AtY%2Bm&inputs=2024&version=22.8.0)
### How it works
This uses the fact (see [OEIS](https://oeis.org/A000292)) that tetrahedral numbers are
>
> the convolution of the natural numbers with themselves
>
>
>
It suffices to compute the convolution of the finite sequence 1, 2, ..., *n* with itself. Also, it is not necessary to discard the "transient" (non-valid part) at the end of the convolution result, because all the values there exceed *n* and thus cannot cause false positives.
```
t % Implicit input: n. Duplicate
: % Range: gives [1 2 ... n]
t % Duplicate
Y+ % Convolution
m % Ismember. Implicit output
```
[Answer]
# [Vyxal](https://github.com/Vyxal/Vyxal/tree/version-2) `R`, 23 [bitsv2](https://github.com/Vyxal/Vyncode/blob/main/README.md), 2.875 bytes
```
¦¦c
```
[Try it Online!](https://vyxal.pythonanywhere.com/?v=2&c=1#WyJSPSIsIiIsIsKmwqZjIiwiIiwiMTAiXQ==)
Bitstring:
```
10110100000101111100100
```
Same as my vyxal 3 answer but with the funny haha fracbyte encoding.
[Answer]
# JavaScript (ES7), 28 bytes
*-2 thanks to [@tsh](https://codegolf.stackexchange.com/users/44718/tsh)*
Returns a falsy value for tetrahedral.
```
n=>(n*=6)+(n**=1/3,~n)**3-~n
```
[Try it online!](https://tio.run/##Dcg7DoMwEEXRnlW80p9AAkRpYNgLInYEsmYQoDR8tm5cnas79f9@HZZx3nKWr4ueIlOn2NBH24Sh8lk/LtbG1PnF0cuigtvAIJRNoiVUr@qd0lqNPQO8Yo3jwCC8SnBFkF86TXbGGw "JavaScript (Node.js) – Try It Online")
### Method
Computes:
$$k=\left\lfloor (6n)^{1/3}\right\rfloor$$
And tests whether:
$$(k+1)^3-k-1=6n$$
[Answer]
# [Ruby](https://www.ruby-lang.org/), 41 bytes
```
->n{n*=6;a=(n**3**-1).to_i;n==a*-~a*a+=2}
```
[Try it online!](https://tio.run/##KypNqvyfZvtf1y6vOk/L1sw60VYjT0vLWEtL11BTryQ/PtM6z9Y2UUu3LlErUdvWqPa/iYFeSWZuanF1TWZNgUJ0pk5adGZsbO1/AA "Ruby – Try It Online")
Finds the cube root of `n*6` rounded down,then applies the formula `a*(a+1)*(a+2)` to see if this equals `n*6`
[Answer]
# [Jelly](https://github.com/DennisMitchell/jelly), 4 bytes
```
RÄÄċ
```
[Try it online!](https://tio.run/##y0rNyan8/z/ocMvhliPd////NzIwMgEA "Jelly – Try It Online")
A monadic link taking an integer and returning 1 for tetrahedral and 0 for not. Similar to many of the other answers: range, cumsum, cumsum, count.
[Answer]
# [Uiua](https://uiua.org) [SBCS](https://www.uiua.org/pad?src=0_7_1__IyBTaW5nbGUtYnl0ZSBjaGFyYWN0ZXIgZW5jb2RpbmcgZm9yIFVpdWEgMC44LjAKIyBXcml0dGVuIGhhc3RpbHkgYnkgVG9ieSBCdXNpY2stV2FybmVyLCBAVGJ3IG9uIFN0YWNrIEV4Y2hhbmdlCiMgMjcgRGVjZW1iZXIgMjAyMwojIEFQTCdzICLijbUiIGlzIHVzZWQgYXMgYSBwbGFjZWhvbGRlci4KCkNPTlRST0wg4oaQICJcMOKNteKNteKNteKNteKNteKNteKNteKNteKNtVxu4o214o21XHLijbXijbXijbXijbXijbXijbXijbXijbXijbXijbXijbXijbXijbXijbXijbXijbXijbXijbUiClBSSU5UQUJMRSDihpAgIiAhXCIjJCUmJygpKissLS4vMDEyMzQ1Njc4OTo7PD0-P0BBQkNERUZHSElKS0xNTk9QUVJTVFVWV1hZWltcXF1eX2BhYmNkZWZnaGlqa2xtbm9wcXJzdHV2d3h5ent8fX7ijbUiClVJVUEg4oaQICLiiJjCrMKxwq_ijLXiiJril4vijIrijIjigYXiiaDiiaTiiaXDl8O34pe_4oG_4oKZ4oan4oal4oig4oSC4qe74paz4oeh4oqi4oeM4pmtwqTii6_ijYnijY_ijZbiipriipviip3ilqHii5XiiY3iip_iioLiio_iiqHihq_imIfihpnihpjihrvil6vilr3ijJXiiIriipfiiKfiiLXiiaHiip7iiqDijaXiipXiipziipDii4XiipniiKnCsOKMheKNnOKKg-KqvuKKk-KLlOKNouKsmuKNo-KNpOKGrOKGq-Kags63z4DPhOKInuK4ruKGkOKVreKUgOKVt-KVr-KfpuKfp-KMnOKMn-KVk-KVn-KVnCIKQVNDSUkg4oaQIOKKgiBDT05UUk9MIFBSSU5UQUJMRQpTQkNTIOKGkCDiioIgQVNDSUkgVUlVQQoKRW5jb2RlIOKGkCDiipc6U0JDUwpEZWNvZGUg4oaQIOKKjzpTQkNTCgpQYXRoVUEg4oaQICJ0ZXN0MS51YSIKUGF0aFNCQ1Mg4oaQICJ0ZXN0Mi5zYmNzIgoKRW5jb2RlVUEg4oaQICZmd2EgUGF0aFNCQ1MgRW5jb2RlICZmcmFzCkRlY29kZVNCQ1Mg4oaQICZmd2EgUGF0aFVBIERlY29kZSAmZnJhYgoKIyBFeGFtcGxlczoKIwojIFdyaXRlIHRvIC51YSBmaWxlOgojICAgICAmZndhIFBhdGhVQSAi4oqP4o2PLuKKneKWveKJoOKHoeKnuyziipdAQi4iCiMgRW5jb2RlIHRvIGEgLnNiY3MgZmlsZToKIyAgICAgRW5jb2RlVUEgUGF0aFVBCiMgRGVjb2RlIGEgLnNiY3MgZmlsZToKIyAgICAgRGVjb2RlU0JDUyBQYXRoU0JDUwo=), 10 bytes
```
‚àä:\+\++1‚á°.
```
[Try it!](https://uiua.org/pad?src=0_7_1__ZiDihpAg4oiKOlwrXCsrMeKHoS4KCmYgOQpmIDEwCuKKmuKItWbih6EzMDAK)
Port of lyxal's [Vyxal 3 answer](https://codegolf.stackexchange.com/a/268900/97916).
```
‚àä:\+\++1‚á°.
. # duplicate
‚á° # range
+1 # increment
\+\+ # cumulative sum twice
‚àä: # is the input in this?
```
[Answer]
# [Python](https://www.python.org), 42 bytes
```
lambda n:n*6in(y**3-y for y in range(n+2))
```
[Attempt This Online!](https://ato.pxeger.com/run?1=m72soLIkIz9vweI025ilpSVpuhY3tXISc5NSEhXyrPK0zDLzNCq1tIx1KxXS8osUKhUy8xSKEvPSUzXytI00NaE6wHKZCDlTA02rgqLMvBKNTJ00jUyYugULIDQA)
Returns True/False. Saves a few bytes by shifting the closed formula by 1.
[Answer]
# TI-BASIC, 14 bytes
```
max(Ans=cumSum(cumSum(cumSum(1 or rand(Ans
```
Takes input in `Ans`. Works on numbers that are within the list size limit.
---
### 20 bytes
```
Input N
int(³√(6N
Ans³+3Ans²+2Ans=6N
```
Based on [Arnauld's answer](https://codegolf.stackexchange.com/a/268930).
[Answer]
# [C++](https://isocpp.org/), 63 57 bytes
(-6 bytes thanks to AZTECCO)
```
[](int n){for(int i=n+3;i--;)n*=n!=-~i*i*~-i/6;return n;}
```
[Try it online!](https://tio.run/##RYzLboMwEEX38xWTdINBVmweFpFNf6TtwnJINCgMCOxVlPw6Jd10de7VfYR5luHu@bZ9EId7uvToaFrj0vvxE9JKfEP2Y7/OPvS4xosF8ClOGLHbvn4y4ogsHtdp@ZPUcVFZktIKzjs@dPJFOeUvSSdjlz6mhZHtc7Pv8uiJs//tgB1qu8OhVkpZLIpB0DU7xGwQIkwpOjc4d/zm4/6goQatoFRQNdAYaHe7G20aKHeWrYHK1FA371SBaRW02sDZnOEX "C++ (clang) – Try It Online")
This swaps truthy/falsy, so it returns an integer greater than 0 for non-tetrahedral numbers, and 0 for tetrahedral numbers.
63 byte version:
```
[](int n){for(int i=n+2;i-->0;)if(n==-~i*i*~-i/6)n=0;return n;}
```
[Try it online!](https://tio.run/##RcyxDoIwFIXhnae44tJCGouDS1teRB2aUsht5JZAOxl5dQQXp/Mv53PTJNzL0rCdkdwrdx40xiXN3o5tkRekAciOfpms87CkThWFzSlCArPdnwwpAfF3H@dfoqH6qlCIViqOPSNjxIoVVqvAy42TkWr2Kc8EpD6bOi6jRWJ/IYCBRu2joZFSKqjrcEinxALnLuakddC6fFC5C18 "C++ (clang) – Try It Online")
[Answer]
# [Python 3](https://docs.python.org/3/), 49 bytes
```
lambda x:any(x==n*-~n*(n+2)/6for n in range(x+1))
```
[Try it online!](https://tio.run/##K6gsycjPM/6fZqsQ8z8nMTcpJVGhwioxr1KjwtY2T0u3Lk9LI0/bSFPfLC2/SCFPITNPoSgxLz1Vo0LbUFPzP0gwEyFoaGCgacWloFBQlJlXopGpk6aRCVQEAA "Python 3 – Try It Online")
No extra work, just the original formula
# [Python 3](https://docs.python.org/3/), 47 bytes swapping T/F
```
lambda x:all(x+n*~n*(n+2)/6for n in range(x+1))
```
[Try it online!](https://tio.run/##K6gsycjPM/6fZqsQ8z8nMTcpJVGhwioxJ0ejQjtPqy5PSyNP20hT3ywtv0ghTyEzT6EoMS89FShpqKn5HySYiRA0NDDQtOJSUCgoyswr0cjUSdPIBCoCAA "Python 3 – Try It Online")
[Answer]
# [Desmos](https://desmos.com/calculator), 31 bytes
```
f(k)=‚àè_{n=1}^k(6k-nnn-3nn-2n)
```
[Try It On Desmos!](https://www.desmos.com/calculator/dqqxirzaqn)
[Try It On Desmos! - Prettified](https://www.desmos.com/calculator/uhkwhdwnwy)
Returns `0` if it is a tetrahedral number, otherwise it returns a non-zero integer. For 5 more bytes, you can make it return `0` if it is a tetrahedral number, and `1` otherwise:
### 36 bytes
```
f(k)=‚àè_{n=1}^ksgn(6k-nnn-3nn-2n)^2
```
[Try It On Desmos!](https://www.desmos.com/calculator/yhasqxhiig)
[Try It On Desmos! - Prettified](https://www.desmos.com/calculator/assasnly28)
[Answer]
# [Haskell](https://www.haskell.org) + [hgl](https://gitlab.com/wheatwizard/haskell-golfing-library), 12 bytes
```
e*^xc scp<e0
```
[Attempt This Online!](https://ato.pxeger.com/run?1=m708I7E4OzUnZ8GuzNyC_KIShYCi1JzSlFQFDU0umMjS0pI0XYt1abapWnEVyQrFyQU2qQYQwf25iZl5CrYKKflcCgoFRQoqCmkKJgimJUTVggUQGgA)
## Explanation
* `e0` integers from 0 to the input
* `xc scp` perform cumulative sums twice
* `e` determine if the input is an element.
## Reflection
It is infuriating I don't have a way to check for membership in an infinite monotonic list. I would have sworn I had implemented it, but I've spent a long time looking and I can't find it.
It wouldn't save bytes here, in fact if it were 3 bytes it would make this longer by a byte, but it should exist because it will be useful in the future.
[Answer]
# [Perl 5](https://www.perl.org/) `-p`, 44 bytes
```
$i++while($;=$i*($i+1)*($i+2)/6)<$_;$_=$_==$
```
[Try it online!](https://tio.run/##HYhBCoAgFAX37xx/oUWkVlaYZ3EVJEhJBd2@nwTDDExezzQwRa9ccV0/W0yrIOcpVqIMLf8Y2Vq5UHAUfMETs4ZBhx4DLEZMmKEVjHqPfMdjv7jJ6QM "Perl 5 – Try It Online")
[Answer]
# [Haskell](https://www.haskell.org/), 32 bytes
```
f n=elem(6*n)[k^3-k|k<-[1..n+1]]
```
[Try it online!](https://tio.run/##y0gszk7Nyfn/P00hzzY1JzVXw0wrTzM6O85YN7sm20Y32lBPL0/bMDb2f25iZp6CrUJuYoGvQkFRZl6JgopCWmZOSWqRQpoCSJmhgYFB7H8A "Haskell – Try It Online")
Check whether \$6n\$ is of the form \$k^3-k\$.
**32 bytes**
```
q=scanl1(+)
f n=elem n$q$q[1..n]
```
[Try it online!](https://tio.run/##y0gszk7Nyfn/v9C2ODkxL8dQQ1uTK00hzzY1JzVXIU@lUKUw2lBPLy/2f25iZp6CrUJuYoGvQkFRZl6JgopCWmZOSWqRQpoCSI2hgYFB7H8A "Haskell – Try It Online")
Using the cumulative-sum-twice method from other answers.
[Answer]
# Mathematica, ~~34~~ ~~33~~ 32 bytes
Outputs truthy/falsy reversed.
```
k^3-k-6#/.k->‚åä(6#)^(1/3)‚åã+1&
```
[Try this online!](https://tio.run/##y00syUjNTSzJTE78/z@gKDOvxCE4NSc1uSQ6KDEvPdXByMDIRMfA1jY7zlg3W9dMWV8vW9fuUU@XhpmyZpyGob6x5qOebm1Dtdj//wE)
[Answer]
# [Scala 3](https://www.scala-lang.org/), 41 bytes
```
x=>(0 to x).exists(n=>x==n*(n+1)*(n+2)/6)
```
[Attempt This Online!](https://ato.pxeger.com/run?1=fYsxTsNAFET7nGJkpdgFDA5ICFlsJOgoQEhAFaX4SWzro_VftLsGR5FPQhMKaLhJbpDbEGJqipnRaOa9f4U5WTr7niSpuDfykky3Gzd7LuYRt8SC1QBYFCXqXVHkq5DjyntaTh6iZ6mmOseTcITZP4HSeSjGZYoMjUS2GGWZ_huBlx0UraiQDPkIwxWHR88kVWPJ3y891bwge9fUs8Ir1l2i91w36PVKFv8QOdSNRDO-ds4WJNrgs4llerHVrRmrDNGh1cdFyyEGJWbcGiMHSg5H-tdP9cm57oGPrs_1us8f)
[Answer]
# [Charcoal](https://github.com/somebody1234/Charcoal), 20 bytes
```
NθW‹↨υ¹θ⊞υ⁺Lυ↨υ⁰⁼Συθ
```
[Try it online!](https://tio.run/##S85ILErOT8z5/98zr6C0xK80Nym1SKNQ05qrPCMzJ1VBwye1uFjDKbE4VaNUR8FQU0ehUFNTIaC0OAPED8gpLQaqyEsvAXKBcjB1BpqaQBMCijLzSjRcC0sTc4o1gktzwUqA2q3//zc0@K9blgMA "Charcoal – Try It Online") Link is to verbose version of code. Outputs a Charcoal boolean, i.e. `-` for tetrahedral, nothing if not. Explanation:
```
Nθ
```
Input `n`.
```
W‹↨υ¹θ
```
Until the sum reaches `n`, ...
```
⊞υ⁺Lυ↨υ⁰
```
... push successive triangular numbers to the predefined empty list.
```
⁼Συθ
```
See whether `n` was reached exactly.
[Answer]
# x86 32-bit machine code, 11 bytes
```
99 31 C9 01 CA 41 29 D0 77 F9 C3
```
[Try it online!](https://tio.run/##XVHJTsMwED3HXzEEVbKbpiotp26XnrlwQgJUOV4SI9cpiQOOqv46YdJFiM5h7HmzvOex2O/TXIiuuzdO2EYqWNZemnJcrMk/yJrsFquMy3uMqOBV5SDexHDYbrnHTNZ4td1SqnntBbeWMTDOg6a952xxJLzeAYXnmJJxbsuMW9BEzyMhP0kUygqUCKPekWoecSlByUscoYTzpW4yULyHJUYfHCoSVcoTFgNbENJT7bhxZ84qFyMQBa9gOMTgi5EDAbQ@GWAF6cMIWjwnixP8XRirgCZJgOUKHifshPa2x3d7TeOBgXQNA/Pm4hGgCE0DY@fma8mbe@KiME6BKKWax5d0@KORJRyu1TCYTF9wVruitHG1yZ2SJ8VDptlrSJJ33NtVWAt3OCRsZjeUQFFX1npVs7OwSx730uAfIe2RdN2P0JbndZfuZlN0@BcrbFf2Fw "C++ (gcc) – Try It Online")
Following the `regparm(1)` calling convention, this function takes a number in EAX and returns a number in EAX, which uses reversed truthy/falsy – it is 0 for tetrahedral numbers and nonzero otherwise.
In assembly:
```
f: cdq # Set EDX to 0 by sign-extending EAX.
xor ecx, ecx # Set ECX to 0.
r: add edx, ecx # Add ECX to EDX. EDX will run through the triangular numbers.
inc ecx # Add 1 to ECX.
sub eax, edx # Subtract EDX from EAX.
ja r # Jump back, to repeat, if EAX remains positive.
ret # Return.
```
[Answer]
# [Raku](https://raku.org), 48 bytes
```
->\a{^‚àû .map(->\n{(n**3-n)/6}).first(*>=a)-a};
```
[Attempt This Online!](https://ato.pxeger.com/run?1=LY7dCoIwFIBf5SAhm7i16dRJ6JNEsptBhD_YvAix694hCC-KnqnbnqRNu_nO73c492evTsP8ri_gayheg9FEfhgp92o8fG8PoLXqkC2bETVBEJMGb9MJU33szwYFZaEwUdPu7129TQVFCZuK-po2rUHYo91gQLc9IB5CFIIIgUfMIk1s7bKYWQiHxCFPczvlwu3EsaMQTkqWTpbZM1xKaWUWiYXJYjK8fjHPa_wB)
Generate the sequence itself until it reaches a value greater than or equal to the input. Then return the difference, i.e., return 0 if it hits the input, and a positive integer otherwise; True/False is therefore swapped.
[Answer]
# [Python](https://www.python.org), ~~80 64 55 51 47~~ 45 bytes
```
lambda x:x*6in[k*~k*~-~k for k in range(x+1)]
```
[Attempt This Online!](https://ato.pxeger.com/run?1=m72soLIkIz9vweI025ilpSVpuhY3dXMSc5NSEhUqrCq0zDLzorO16oBIty5bIS2_SCFbITNPoSgxLz1Vo0LbUDMWqkkbJJeJkDPUMTQw1LTiUshMU0jTyASxFAqKMvNKgGyIlgULIDQA)
Based off of Aiden Chow's Desmos answer.
[Answer]
# [Go](https://go.dev), ~~80~~ 75 bytes
```
func(x int)int{for i:=1;i<=x;i++{if 6*x==i*(i+1)*(i+2){return 1}}
return 0}
```
[Attempt This Online!](https://ato.pxeger.com/run?1=hVHbSgMxEMXXfMWwUNi0UTbbdu3FCII-iNBKu28qstSmhLbZErNSWPZLfCmCH-Mn1K9xst0KBS8PmSRnZs45mby-zdLN1lslk3kym8IyUZqo5So19sSTS-sR8pIYkCDeMyuPO9sbmemJvwalLcWVy9SA6gneV2di3VeNRq4kRPW1EKruqwanLoY0N1ObGQ28KEh1DIod5efRh-MspX0KObFGPUNPwN2DE-AMWgx4wCDE1WwzaEcMOg5zAI8QCd0p7CDejFoF0amNDzhcFnPYygCLTjF2kdZ1dYOAF4TcGqxbaN8TQsA4vhjFEI-ux4BXjxL3yEdmHaFJNI6ptJiTdO4g6VtK8NXpXAgOeUklfa_2BOIcMPo1S--1x8AyrMHNZFNakOJQFK4GlzvNSnSfpT-6Gwz_drifQe6mMTzwWQJCBP9YLcsYyGTx_JvdbxOVi-pHN5vd_gU)
Loops over all numbers from \$1\$ to \$x\$ inclusive and sees if \$6x = i(i+1)(i+2)\$.
-5 from Joao-3 by using `int` as the return type instead.
[Answer]
# [05AB1E](https://github.com/Adriandmen/05AB1E/wiki/Commands), 7 [bytes](https://github.com/Adriandmen/05AB1E/wiki/Codepage)
```
LηOηOIå
```
[Try it online](https://tio.run/##yy9OTMpM/f/f59x2fyDyPLz0/38jAyMTAA) or [verify the first 100 test cases](https://tio.run/##yy9OTMpM/X@xydXPXknhUdskBSV7v/8@57b7A5Hf4aX/df4DAA).
**Explanation:**
Similar as other answers.
```
L # Push a list in the range [1, (implicit) input]
ηOηO # Cumulative sum twice:
η # Get the prefixes of this list
O # Sum each prefix
ηO # And again
Iå # Check if the input is in this list
# (which is output implicitly as result)
```
[Answer]
# [PowerShell](https://github.com/TryItOnline/TioSetup/wiki/Powershell), 76 bytes
```
$a=$b=1;while($b-ge1){$b=$_*6/$a/($a+1)/($a+2);if($b-eq1){return !0};$a++}!1
```
[Try it online!](https://tio.run/##HYpRCoMwEESvssIWjCK60foTPEuJsFUh2DYqfmjOHtfCwAxv3vezs19Gdi6i9cNyPg4ZHfYdmX2cHKfYFwOTOgThK2tLtGWKNif1L63M9L4d/onjed38DEkVjHx5SCiGGAkaoAq0BJ5ANej2Ag "PowerShell – Try It Online")
[Answer]
# [APL(Dyalog Unicode)](https://dyalog.com), ~~10 9~~8 bytes [SBCS](https://github.com/abrudz/SBCS)
```
⊢∊+\⍣2⍤⍳
```
[Try it on APLgolf!](https://razetime.github.io/APLgolf/?h=AwA&c=e9S16FFHl3bMo97FRo96lzzq3QwA&f=K0ktLil@1DbhUe9mI1OuEhBPJ9pAzzQ27dAKMI/rUd9UoLy6Olf1o96tj3r2P@pdAZQDsmtBegyMTAE&i=AwA&r=tryapl&l=apl-dyalog-extended&m=train&n=f)
-1 byte thanks to att.
A tacit function which takes an integer on the right and returns 1 if tetrahedral and 0 if not.
Same method as the Vyxal and Uiua answers.
```
⊢∊+\⍣2⍤⍳­⁡​‎‎⁡⁠⁢⁤‏‏​⁡⁠⁡‌⁢​‎‎⁡⁠⁤‏⁠‎⁡⁠⁢⁡‏‏​⁡⁠⁡‌⁣​‎‎⁡⁠⁢⁢‏⁠‎⁡⁠⁢⁣‏‏​⁡⁠⁡‌⁤​‎‎⁡⁠⁡‏⁠‎⁡⁠⁢‏‏​⁡⁠⁡‌­
⍤⍳ # ‎⁡range, then
+\ # ‎⁢cumulative sums,
⍣2 # ‎⁣twice
⊢∊ # ‎⁤input is member
üíé
```
Created with the help of [Luminespire](https://vyxal.github.io/Luminespire).
[Answer]
# APL(NARS), 64 chars
```
r‚ÜêB w;y;z
y←⌈3√w←w×6⋄r←0⋄→3
y-‚Üê1
‚Üí2√ó‚ç≥w<z‚Üêy√ó(y+1)√óy+2
→0×⍳w>z⋄r←1
```
9+17+4+19+11+4=64
`f(y)=y×(y+1)×(y+2)=y^3+3y^2+2y` is a crescent function and from `y0=⌈(6w)^(1/3) => (y0)^3≥6w =>(y0)^3+3(y0)^2+2(y0)>6w`
so it is possible begin the loop in that point `y0` and decrease `y0` until `(y0)^3+3(y0)^2+2(y0)‚â§6w`
```
a⊂⍨B¨a←⍳123
1 4 10 20 35 56 84 120
```
it seems is possible to use big rational and big float too
```
B 45487864677774111x
0
B 45487864677774111x√ó(45487864677774111x+1)√ó(45487864677774111x+2)√∑6
1
```
[Answer]
# [dc](https://www.gnu.org/software/bc/manual/dc-1.05/html_mono/dc.html), 50 bytes
```
[1pq]st[0pq]sf[1+dd1+d1+**6/dln=tln<flxx]sx?sn0lxx
```
[Try it online!](https://tio.run/##S0n@/z/asKAwtrgk2gBEpUUbaqekALGhtpaWmX5KTp5tSU6eTVpORUVscYV9cZ4BkPX/v6GhiQEA)
This solution outputs 1 for truthy, and 0 for falsy.
[Answer]
# [Rattle](https://github.com/DRH001/Rattle), ~~27~~ 26 bytes
```
|r`[=#-s+2*~*#/6[\=1q]]3`=
```
[Try it Online!](https://www.drh001.com/rattle/?flags=&code=%7Cr%60%5B%3D%23-s%2B2*%7E*%23%2F6%5B%5C%3D1q%5D%5D3%60%3D&inputs=35)
Outputs 1 if the number is tetrahedral, 0 otherwise.
# Explanation
```
| take input
r` set input to "\" (variable)
[ ... ]3` loop int("3"+str(N)) times where N is the input. The 3 catches the edge case of 1.
=# set the top of the stack to i, where i is the loop count
- decrement
s save to memory
+2 increment by 2
*~ multiply by the value in memory (performing (i-1)(i+1))
*# multiply by i to obtain (i-1)(i)(i+1), effectively the same
as n(n+1)(n+2) but with shifted indices
/6 divide by 6
[\...] if equal to "\" (the original input)
=1 set the top of the stack to 1
q quit and implicitly print the top of the stack
= if the loop exits without quitting, the number is not tetrahedral
(set top of stack to 0 then print implicitly)
```
There may be a way to get this shorter. I might come back later to try to get the byte count down (someone else should try too!).
]
|
[Question]
[
Given the battery level `L` in the range `0-5`, your code should draw the following ASCII art.
When `L=0`:
```
############
# ###
# ###
# ###
############
```
When `L=1`:
```
############
### ###
### ###
### ###
############
```
When `L=2`:
```
############
##### ###
##### ###
##### ###
############
```
And etc. You can change the character `#` to any other (except space), it's up to you. Trailing spaces are allowed.
This is a code-golf challenge so the shortest solution wins.
[Answer]
# Google Sheets, 124 bytes
```
=substitute(query({rept("#",12);sort(if({1;1;1},"#"&rept("#",A1*2)&rept("-",10-A1*2)&"###"));rept("#",12)},,9)," ",char(10))
```
## 89 bytes if it's okay for the output to be displayed in separate cells
```
={rept("#",12);sort(if({1;1;1},"#"&rept("#",A1*2)&rept("-",10-A1*2)&"###"));rept("#",12)}
```
[Try it here](https://docs.google.com/spreadsheets/d/1SXPf7wZDsl1N_OzFFD6DDKilnr5chz527Z7B2bhodmg/edit#gid=0)
[Answer]
# [brainfuck](https://github.com/TryItOnline/brainfuck), ~~266 245~~ 242 bytes
-21 bytes thanks to @emanresu A's suggestion to use `ÿ` instead of `!` (since `ÿ`'s charcode is the same as the glider reference value `255` on an 8 bit bf interpreter like TIO's).
-3 bytes by removing unnecessary code (at the expense of a pretty memory layout).
```
-[-[-<]>>+<]>->>+++++[<++>-]->++++[<...>-]<<.>+>-[>+<-----]>---<,>[<->-]<[<+>-]<[>->+>->+>->+<<<<<<-]+++++[>+>>+>>+<<<<<-]->>>>>>>-<+[[[-<+]-.>+[->+]-<[+[-<+]-..>+[->+]-<-]>+<-<[+[-<+]-<<..>>>+[->+]-<-]+[-<+]-...<.>>+[->+]<->]<<+]++++[>...<-]
```
[Try it online!](https://tio.run/##RY5dCgIxDIQPFCd4gNCLhDyoIIiwD4Lnr1/bdTf9CZlJMnP/3F7b8/t4967kRLVmfCKNyDBrKrVVuDtVhDfQpFMjaJfi0jI0WGZmYon9X8xQraVg8@4gYjMUlokHKyGQjJUibUdOCEGUDwY7zvTJHhOO0R3HGr6tlv6gVL1ffw "brainfuck – Try It Online")
Uses a glider and fancy loop tricks to print the middle 3 rows. Uses `ÿ` instead of `#` since that is allowed by the challenge.
Ungolfed:
```
memory layout
(pni = 5 minus inp)
3 4 5 6 7 8 9 10 11 12
' ' \n ÿ pni inp pni inp pni inp ÿ
' ' = 32
-[-[-<]>>+<]>-
\n = 10
>>+++++[<++>-]
ÿ = 255
-
print top row of ÿs
>++++[<...>-]<<.>+
get input
>-[>+<-----]>---<,>[<->-]<[<+>-]<
copy to loop cells
[>->+>->+>->+<<<<<<-]
+++++[>+>>+>>+<<<<<-]
create glider refs
->>>>>>>-<+
main loop
[
glider collision guard
exit the loop when all loop variables are exhausted
[-
print first ÿ
+[-<+]-.>
+[->+]-
print ÿs in battery
<[
+[-<+]-..>
+[->+]-
<-
]
move glider back one cell
>+<-
print spaces in battery
<[
+[-<+]-<<..>>>
+[->+]-
<-
]
print last 3 ÿs and \n
+[-<+]-...<.>>
+[->+]
move glider back one cell
<->
]<<+
]
print last row of ÿs
++++[>...<-]
```
[Answer]
# [Python](https://www.python.org), 46 bytes
```
lambda n:[s:="#"*12,*3*[f'#{"##"*n:10}###'],s]
```
[Attempt This Online!](https://ato.pxeger.com/run?1=m72soLIkIz9vweI025ilpSVpuhY39XISc5NSEhXyrKKLrWyVlJW0DI10tIy1otPUlauVlIH8PCtDg1plZWX1WJ3iWKgurbT8IoU8hcw8haLEvPRUDTNNK63cxAKNgqLMvBKdNI08TU0dMFtDE6JjwQIIDQA)
Outputs a list of lines, as [allowed by standard I/O rules](https://codegolf.meta.stackexchange.com/a/17095).
\$ -9 -1 = -10 \$ thanks to @xnor
---
## [Python](https://www.python.org), 76 bytes
```
lambda n,r=f"#{' '*10}#".replace:[a:=r(" ","#")]+[r(" ","#",2*n)+"##"]*3+[a]
```
[Attempt This Online!](https://ato.pxeger.com/run?1=m72soLIkIz9vweI025ilpSVpuhY3fXISc5NSEhXydIps05SUq9UV1LUMDWqVlfSKUgtyEpNTraITrWyLNJQUlHSUlJU0Y7Wj4RwdI608TW0lZWWlWC1j7ejEWKiZWmn5RQp5Cpl5CkWJeempGmaaVlq5iQUaBUWZeSU6aRp5mpo6YLaGJkTHggUQGgA)
Did you know Python's `str.replace` method has a third parameter to limit the maximum number of replacements that will be performed? You do now!
[Answer]
# C (POSIX), 83 bytes
```
#define s"\n############"
#define r"\n%1$-11s###"
f(i){printf(s r r r s,s+12-i*2);}
```
I was originally tweaking [ErikF's answer](https://codegolf.stackexchange.com/a/243364/8927) but ended up making more substantial changes, so it felt like a new separate answer. Note that this saves some space by printing a newline *before* the output, which [has been approved](https://codegolf.stackexchange.com/questions/243337/draw-a-battery-indicator#comment547981_243337).
Uses compile-time string concatenation to compress the output template, then uses `printf` to fill in the correct amount of the bar.
## Breakdown:
### `r` template pattern
```
\n - print a literal newline
% s - followed by a string
1$ - from the first argument (POSIX extension)
- - padded with trailing spaces
11 - to at least 11 characters
### - followed by 3 literal hash symbols
```
### `printf` call
```
printf(
s r r r s, // concatenate define'd strings into full pattern
s + 12 - i * 2 // first argument: fragment of s (last i * 2 + 1 characters)
);
```
### Expanded
```
f(i) {
printf(
"\n############\n%1$-11s###\n%1$-11s###\n%1$-11s###\n############",
"\n############" + 12 - i * 2
);
}
```
[Try it online](https://tio.run/##TczBCsIwDAbge58idAqttWB32KX6Jl6kWyUHu9FML6PPXmNFMIGQ/B8k2HsItXbjFDFNQPKaur@S4ieZZe921jlqeVSotyVjWqMiyK3pSMb1Fg@99qUyweOGSb1mHDVsAiDOWX1ivJw84HngYcyXGPmjb9vyXElJ2a4iSn0D)
---
As an interesting alternative, this version uses hex values to draw the shape, so it's limited to `f` characters, but avoids the initial newline. It is the same size (83 bytes):
```
#define r"%2$-11lxfff\n"
f(i){printf("%lx\n"r r r"%1$lx",(1l<<48)-1,(16l<<i*8)-1);}
```
[Answer]
# [Charcoal](https://github.com/somebody1234/Charcoal), 18 bytes
```
UO⊕⊗N³-¹²↘‖O↓UO±³-
```
[Try it online!](https://tio.run/##LY0xDoMwEAT7vAJRnSUogC5paSgCET@wnYtBOs7IOjvPdyyFalcz0q7ddLBeU86LIc8OJrYBD2TBN4w@Gio58RlljofBAEqpphqaqm5r9bi9ws4CXV/q0yeE@@i/vO5uk0JW/BBaWRIG0uffFXwdzei0IAzq2sq5z22iHw "Charcoal – Try It Online") Link is to verbose version of code. Explanation:
```
UO⊕⊗N³
```
Draw the fullness of the top half of the battery.
```
-¹²↘
```
Draw the line at the top of the battery and leave the cursor at the top right of the 3×3 square end.
```
‖O↓
```
Reflect to complete the fullness and sides of the battery. (This also moves the cursor to the bottom right of the 3×3 square end.)
```
UO±³-
```
Draw the 3×3 square end.
[Answer]
# [*Acc!!*](https://github.com/dloscutoff/Esolangs/tree/master/Acc!!), 152 bytes
```
N-46
Count i while i-2 {
Count l while (l-3)*i {
Count c while c-14 {
Write 32+1/((c+3)/2%7/_+1)
}
Write 10
}
Count h while h-12 {
Write 33
}
Write 10
}
```
Uses exclamation points. [Try it online!](https://tio.run/##S0xOTkr6/99P18SMyzm/NK9EIVOhPCMzJ1UhU9dIoRoqlgMV08jRNdbUyoSLJ0PFk3UNTYCC4UWZJakKxkbahvoaGsnaxpr6Rqrm@vHahppctVBJQwMgE6I5A6o5Q9fQCKHZGEXp//9GAA "Acc!! – Try It Online")
### Explanation
This was fun to golf. The verbose syntax of *Acc!!* drove me to combine as many `Count while` and `Write` statements as possible, which required some interesting expressions to encapsulate the logic.
```
N-46
```
Read a character from stdin and store its codepoint minus 46 in the accumulator. If the input number is `L`, the accumulator now holds the value `L+2`.
```
Count i while i-2 {
...
}
```
Do the following twice:
```
Count l while (l-3)*i {
```
Do the following (output the middle part of the battery) three times, but only on the second iteration of the `i` loop:
```
Count c while c-14 {
```
Do the following (output a character in the middle part of the battery) fourteen times:
```
Write 32+1/((c+3)/2%7/_+1)
```
Write either a space or an exclamation point, based on the loop index `c` and the accumulator value `_`.
Observe that we want to output some number of exclamation points, then some number of spaces, then three more exclamation points. This looks like a slice into a periodic function. Since we want to add exclamation points in pairs, let's aim for something like this:
```
0 1
01234567890123456789
!!!!..........!!!!..
```
where `!` means "definitely maps to `!`" and `.` means "might map to either `!` or depending on the accumulator value."
We want to run our loop from 3 to 16 in this function; since loop variables in *Acc!!* always start at zero, we'll just add 3 to the loop variable `c`.
Next, we combine the pairs of characters that will always be the same by int-dividing by 2:
```
0123456789
!!.....!!.
```
We can get the periodic behavior if we take this input mod 7:
```
0123456
!!.....
```
Now it's just a matter of adjusting the cutoff depending on the input value. Conceptually, we want exclamation points if this number is less than `L+2`, and spaces if it is greater than or equal to `L+2`. Conveniently, `L+2` is the value in the accumulator. Inconveniently, *Acc!!* doesn't have comparison operators, so we'll have to abuse some arithmetic:
With integer division, and assuming `b` is always positive, `a/b` is `0` if `a<b` and some positive number otherwise. To turn 0 vs positive into 1 vs 0, we can add 1 (making it 1 vs greater than 1) and then int-divide 1 by that quantity. End result: `1/(a/b+1)` is `1` if `a<b` and `0` otherwise.
In our case, we have `a = (c+3)/2%7` and `b = _` (the accumulator). Substituting those into the above expression and adding to `32` gives exclamation point (ASCII 33) or space (ASCII 32) exactly where we want them.
```
}
Write 10
}
```
Close the `c` loop, write a newline, and close the `l` loop.
```
Count h while h-12 {
Write 33
}
Write 10
```
Output the top/bottom of the battery: Loop 12 times and write exclamation point; then write a newline.
[Answer]
# [Pari/GP](http://pari.math.u-bordeaux.fr/), 82 bytes
```
n->[print(l)|l<-[s="############",e=Strchr([35-3*(j>n+n&j<11)|j<-[0..13]]),e,e,s]]
```
[Try it online!](https://tio.run/##K0gsytRNL/ifZvs/T9cuuqAoM69EI0ezJsdGN7rYVkkZCSjppNoGlxQlZxRpRBub6hpraWTZ5WnnqWXZGBpq1mQBNRjo6Rkax8Zq6qQCYXFs7P80DQNNrjQNQxBhBCKMQYQJiDDV/A8A "Pari/GP – Try It Online")
This code is most probably not the shortest possible, as this is my first time golfing in Pari/GP.
Thanks @alephalpha for -14 bytes.
[Answer]
# [Vyxal](https://github.com/Vyxal/Vyxal), 18 bytes
```
d×*₀↲×p14e:"×12*p∞
```
[Try it Online!](https://vyxal.pythonanywhere.com/#WyIiLCIiLCJkw5cq4oKA4oayw5dwMTRlOlwiw5cxMipw4oieIiwi4oGLIiwiMyJd)
```
d # Input * 2
×* # That many asterisks
₀↲ # Pad the left to length 10 with spaces
×p # Prepend an asterisk
14e # Extend to length 14 by appending the first char
:" # Pair with itself
p # Prepend to this...
×12* # 12 asterisks
∞ # Palindromise the result
```
[Answer]
# [Retina 0.8.2](https://github.com/m-ender/retina/wiki/The-Language/a950ad7d925ec9316e3e2fb2cf5d49fd15d23e3d), 55 bytes
```
.+
#$&$*_10$* ###¶
+`(_*)_
##$1
.+¶
12$*#¶$&$&$&12$*#
```
[Try it online!](https://tio.run/##K0otycxL/P9fT5tLWUVNRSve0EBFS0FZWfnQNi7tBI14Lc14BQUuZWUVQy49baCYoZGKFlAOqBQIwZz//40A "Retina 0.8.2 – Try It Online") Explanation:
```
.+
#$&$*_10$* ###¶
```
Produce a body row of the empty battery but include `L` `_`s.
```
+`(_*)_
##$1
```
For each `_`, delete two spaces and add two `#`s.
```
.+¶
12$*#¶$&$&$&12$*#
```
Triplicate the row and wrap it in lines of 12 `#`s.
[Answer]
# [C (gcc)](https://gcc.gnu.org/) with `-lm`, ~~93~~ 91 bytes
* -2 thanks to ceilingcat
Uses `9` as the fill character. I make use of 10*n*-1 producing *n* nines when *n*>0.
```
*s="999999999999";f(i,j){for(puts(s),j=3;j--;printf("%-11.f999\n",exp10(i-~i)-1));puts(s);}
```
[Try it online!](https://tio.run/##TU3LCsIwELznK0JAyNquNAiCrP0TLyWasqGP0FQRSv10YwoenMMwDPOw2Fqb0j7W6vwHRU5z6WFx46TDY446QunrI3lEChMPs9Nqh8YcXE5fB1XeX8FUmvHNgAaAfiVaUw7LvuFBP0e@gVyElJvFJLLa9rmuSPLllKkoQOZnILGmj3Vd08aEXf8F "C (gcc) – Try It Online")
[Answer]
# Python 3.8, ~~85~~ ~~72~~ ~~68~~ ~~49~~ 46 bytes
```
lambda l,a="##":[a*6,*3*[f'#{l*a:10}###'],a*6]
```
Outputs a list of strings, as allowed by [standard I/O rules](https://codegolf.meta.stackexchange.com/a/17095)
[Try it online!](https://tio.run/##HcnBCkBAEADQX9nMwe40B1LSli/BYcSi1tg2F8m3L7m9euE610OqJsTk2j553seJlSduM4DMdow1YYWdy@H2yLYsHgDIB/piSO6IStQmKrIss66NxZ2DDnGTk5wWY@i3NukF)
-13 thx to @Aiden chow
-4 thx to @ovs
-3 thx to @Aiden chow
[Answer]
# [Julia 1.0](http://julialang.org/), ~~57 51~~ 48 bytes
```
c='#';!n=[c^12,(h=rpad(c*c^2n,11)*c^3;),h,h,c^12]
```
[Try it online!](https://tio.run/##FcpBCoAgEADAr5QFapmwRZdEPxIKYgeLRSIKOvR3K@Y624WrhzvnoGlFVZn0HBz0gkV97H5hwTFo@8QFAG@CGxQX8fMfm2EaC/kY7Mx@rOnEJNlMUNdIVImKEMvzCw "Julia 1.0 – Try It Online")
-3 MarcMush
[Answer]
# Excel, ~~82~~ 74 bytes
It [Taylor Rained](https://codegolf.stackexchange.com/questions/243337/draw-a-battery-indicator/243408?noredirect=1#comment547967_243408) 8 bytes.
```
=LET(a,REPT("#",12),b,MID(a&REPT(" ",10),12-2*A1,11)&"###
",a&"
"&b&b&b&a)
```
Input of `L` is in the cell `A1`. Output is wherever the formula is. For best results, make sure the column is wide enough, text wrapping is on, and the font is monospace. The output will be correct regardless but this makes that fact visually apparent.
* `LET(a,REPT("#",12)` defines `a` to be 12 number signs in a row. Combining `LET()` and `REPT()` only saves us 1-3 bytes but savings are savings.
* `b,MID(a&REPT(" ",10),12-2*A1,11)&"###\n"` has a lot going one but the summary is this:
+ Create a string of 12 `#` and 10 spaces.
+ Find the right spot (based on the input) in the middle of that string to start pulling characters.
+ Pull 11 characters (1 `#` + 2\*input `#` + however many spaces).
+ Add `###` and a line break.
+ Set the resulting string to the variable `b`.
* `a&"\n"&b&b&b&a` concatenates the pieces into an output.
[](https://i.stack.imgur.com/IIzxY.png)
[Answer]
# C++, 267 bytes
```
#include<iostream>
#define c std::cin
#define o std::cout
#define h()o<<H<<'\n'
#define L 12
#define H 111111111111
#define M 1
typedef int I;
I main(){I l;c>>l;h();for(I i=0;i<3;i++){o<<M;for(I j=0;j<l*2;j++){o<<1;}for(I k=0;k<L-l*2-2;k++){o<<' ';}o<<111<<'\n';}h();}
```
[Try it Online!](https://tio.run/##TY7LCoMwEEX3fsWAC7UiNHbnpK4r6B90IzG24yORNl0U8dttRAmd3T1nmDtimpKHEOvqkxLDp5Gc9Nu8ZD3mnt/IlpQEAW/TZJkg5ZA@kP4Yx55hpDm/cR7cVeBoCSx14QbsbxyugHnmO0kbgZSBAgsYa1JhNBcwoMjzAe11bPUrLICuZyR@QYrjaLaN1cE7yzs@nFLsDsNw2VVvVc/LxMokxf7QAQS4bGuM7U/jsrUs68p@)
First time golfing in C++, not sure if it's good or not.
[Answer]
# JavaScript, 76 70 bytes
-6 thanks to Hannesh
```
_=>(a=`############
`)+`#${'##'.repeat(_).padEnd(10)}###
`.repeat(3)+a
```
[Try it Online!](https://tio.run/##y0osSyxOLsosKNHNy09J/f8/zTbe1k4j0TZBGQlwJWhqJyirVKsrK6vrFaUWpCaWaMRr6hUkprjmpWgYGmjWghXBpIw1tRP/p@UXaWTaGlhn2phZZ2pra1ZzKSgk5@cV5@ek6uXkp2ukaWRqanLV/gcA)
[Answer]
# [brainfuck](https://github.com/TryItOnline/brainfuck), 202 bytes
```
+++++[>++>++++++<<-]>>++>-............<<.>>>>++++[->+++<]>>>>>+++++++[<+++++++>-],<--[>-<-]>[<+<+<+>>>-]<<<[<[-<+<+>>]<[>+<-]>>[<<++<-->>>-]<<-[-<<.>>]<[-<<.>>]<...<<.>>>>>>>[[<+>-]>]<<[<]>>]<[<<<.>>>-]
```
[Try it online!](https://tio.run/##TU27CsNADPugq7J0FfoR4yEJBEqhQ6Hff5Uvj1YeTtbJ0vKeH6/tsz57b4VQaxqskUjViukP5CRpWAL1MHUKpfEgQt4IhFAxlmvsQ5IMBvY96cZRFPSpLw4P7Kiq5EV@7UY40kbLTsvh4/6L7P3@BQ "brainfuck – Try It Online")
first, I try to comment this shorter bytes brainfuck to first brainfuck(245 bytes) comment, but i don't have enough reputation. so i decide to comment here and give the link to [that first comment](https://codegolf.stackexchange.com/a/243350/111206).
also if I can, I will try to expaining this code later
[Answer]
# [Python 3](https://docs.python.org/3/), 86 bytes
```
a,b="#"*12,int(input())
c="#"+"#"*2*b+" "*(10-2*b)+"###"
print("\n".join([a,c,c,c,a]))
```
[Try it online!](https://tio.run/##K6gsycjPM/7/P1EnyVZJWUnL0EgnM69EIzOvoLREQ1OTKxkkqg2SMdJK0lZSUNLSMDTQBbI1gYLKykpcBUUg9UoxeUp6WfmZeRrRiTrJYJgYq6n5/78RAA "Python 3 – Try It Online")
Quick and dirty, but it works.
[Answer]
# [Charcoal](https://github.com/somebody1234/Charcoal), 49 bytes
```
P×-¹²P↓×-⁵≔Nα↓→F³«P×-×α²↓»P×-¹¹Fχ«→»P↑×-⁴F³«↑P×-³`
```
[Try It Online!](https://tio.run/##S85ILErOT8z5/9@3NKckM6AoM69EIyQzN7VYQ0lXSUfB0EhTkwtJysolvzxPRwFJhSlQgWNxcWZ6noZnXkFpiV9pblJqkYamjkIiUGd@WSpED4wdlJmeUaLJ5ZZfpKBhrFnNxYndXggzUUcBaL8mUBGSObVcOJxqqAk2V8PQQFOhGqYHah@KJqvQAhQvmEA1QtwD1hZaoInLacZA1bX//5v81y3LAQA) Link is to verbose version of code.
My second Charcoal answer!
Uses "`-`" instead of "`#`" because if I change, The Output uses both "-" and "#".
## Explanation:
TODO: Understand the code and explain
[Answer]
# [05AB1E](https://github.com/Adriandmen/05AB1E/wiki/Commands), ~~19~~ 18 [bytes](https://github.com/Adriandmen/05AB1E/wiki/Codepage)
```
X12×$·×Tj7bìĆRD».∊
```
Outputs `1` instead of `#`.
[Try it online](https://tio.run/##ASUA2v9vc2FiaWX//1gxMsOXJMK3w5dUajdiw6zEhlJEwrsu4oiK//8y) or [verify all test cases](https://tio.run/##yy9OTMpM/W96bJKSZ15BaYmVgpK9nw6Xkn9pCYSn8z/C0OjwdEO/Q9sPTw/JMk86vOZIW5DLod16jzq6/usc2mb/HwA).
**Explanation:**
```
X # Push 1
12 # Push 12
× # Repeat the "1" 12 times: 111111111111
$ # Push 1 and the input
· # Double the input
× # Repeat the "1" that many times
Tj # Pad it with leading spaces up to length 10
7bì # Prepend the binary of 7: 111
Ć # Enclose; append its own head
R # Reverse it
D # Duplicate it
» # Join the stack with newline delimiter
.∊ # Mirror it vertically with overlap
# (after which the result is output implicitly)
```
[Answer]
# [Noether](https://github.com/beta-decay/Noether), 76 bytes
```
I~l12("#"P!i)?3(0~rl2*1+("#"P!r)0~r11l2*-(r0{>}{" "P}!r)"###"P?!k)12("#"P!y)
```
[Try it online!](https://tio.run/##y8tPLclILfr/37Mux9BIQ0lZKUAxU9PeWMOgrijHSMtQGyJUpAnkGxoCRXQ1igyq7WqrlRSUAmqB4krKykAF9orZmjDtlZr//xsBAA "Noether – Try It Online")
[Answer]
# [Java (JDK)](http://jdk.java.net/), 98, 95 bytes
```
L->{System.out.format("%s"+"%2$-11s###\n".repeat(3)+"%1$s","############\n","#".repeat(L-~L));}
```
[Try it online!](https://tio.run/##TY9BS8QwEIXv@yuGdBcSaoN18RTrxZNQT3tUDzGbLqltUpLJgpT61@soi@zAMPC@x@NNr8@66o@fqxl0SvCinYd5AzDlj8EZSKiRzjm4I4zE@AGj86fXd9DxlARZewqQGd0gu@wNuuDls8en4FMebYQOmrWtHufDV0I7ypBRdiGOGjnbJVay3d22qutUFMWbZzLayRLaCwL1NrEbVlwNOUj4d7XVdyuEWlZFfQEoFrjzCA4auFV0Hpp75cpSzH@cHFIbYyfkTqiLdFVrosdw8PzCls3vLusP "Java (JDK) – Try It Online")
[Answer]
# [Perl 5](https://www.perl.org/), 63 bytes
```
$_=($s='#'x12 .$/).('#'.'#'x($x=2*$_).$"x(10-$x)."###\n")x3 .$s
```
[Try it online!](https://tio.run/##FcpBCoAgEEDR/ZwidEANmlJz6U2CVi2CMMkWc/qmWv7Hr9t1JBFcs8WWjTbsQ0c4OrJf0A8WOYceV0eo2PppQHaktNZLUY7jdzeRCTwEiDBDes5672dpMtTjBQ "Perl 5 – Try It Online")
[Answer]
# J, ~~50~~ ~~46~~ 44 bytes
```
(a,3 1#(a=:12#'#'),:~'# #'#~(>:,10&-,3:)@+:)
```
Found that building row by row can be shorter.
[Try it online!](https://tio.run/##y/qvpKeepmBrpaCuoKNgoGAFxLp6Cs5BPm7/NRJ1jBUMlTUSba0MjZTVldU1dazq1JUVgMw6DTsrHUMDNV0dYytNB20rzf@aXFypyRn5CmkKhhCGujpMwPg/AA "J – Try It Online")
[Answer]
# [Lua](https://www.lua.org), 87 bytes
```
x,b=...,"\n"d=b.rep a=d("#",12)print(a..b..d(b.format("%-11s###\n",d("#",1+2*x)),3)..a)
```
[Attempt This Online!](https://ato.pxeger.com/run?1=m704pzRxwYKlpSVpuhY3wyt0kmz19PR0lGLylFJsk_SKUgsUEm1TNJSUlXQMjTQLijLzSjQS9fSS9PRSNJL00vKLchNLNJRUdQ0Ni5WVlYG6dKCKtY20KjQ1dYw19fQSNSHGQ21ZHG0UC2UCAA)
[](https://i.stack.imgur.com/fa3i5.png)
My alternate approach before the format string was 6 bytes longer at **93 bytes**:
```
x,b=...,"\n"d,f=b.rep,''a=d("#",12)print(a..b..d(d("#",1+2*x)..d(" ",10-2*x).."###"..b,3)..a)
```
[Answer]
# [Pip](https://github.com/dloscutoff/pip), 29 bytes
```
i:00YPiX6L3P[iJiXa.sXt-2*ai]y
```
[Attempt This Online!](https://ato.pxeger.com/run?1=m724ILNgwYKlpSVpuhZ7M60MDCIDMiPMfIwDojO9MiMS9YojSnSNtBIzYyshaqBKF0cbxUKZAA)
[Answer]
# APL+WIN, 51 bytes
Prompts for n
```
t←14↑12⍴'#'⋄v←3 14⍴' '⋄v[;(⍳1+2×⎕),11+⍳3]←'#'⋄t⍪v⍪t
```
[Try it online! Thanks to Dyalog Classic](https://tio.run/##SyzI0U2pTMzJT9dNzkksLs5M/v@ob6qvz6O2CcZcQJanP5BlyPWooz3tfwmIafKobaKh0aPeLerK6o@6W8pAChWAokABBbBAtLXGo97NhtpGh6cD9WvqGBpqA/nGsUCFEC0lj3pXlQFxyX@gqVz/07gMuIBaudK4DKG0EZQ2htImUNqUCwA "APL (Dyalog Classic) – Try It Online")
[Answer]
# [PowerShell](https://github.com/TryItOnline/TioSetup/wiki/Powershell), 45 bytes
```
%{'#'*12;"#{0,-10}###`n"-f('##'*$_)*3+'#'*12}
```
[Try it online!](https://tio.run/##K8gvTy0qzkjNyflvoKdnWvNftVpdWV3L0MhaSbnaQEfX0KBWWVk5IU9JN01DXRkooxKvqWWsDVFT@/8/AA "PowerShell – Try It Online")
Try it in a PS console (Windows or Core):
```
0..5|%{'#'*12;"#{0,-10}###`n"-f('##'*$_)*3+'#'*12}
```
## Explanation
`%` is an Alias for the Cmdlet "ForEach-Object", which accepts input from the pipeline and processes each incoming object inside the ScriptBlock `{...}`
`'#'*12;` First line, PowerShell can "multiply" strings; the `;` terminates the command, output is implicit.
`"#{0,-10}###`n"` The level row; `{0,-10}` is a placeholder where the first argument of the following `-f` format operator will be inserted. `-10` will print the string inserted left-aligned, and padded to a length of 10. The ``n` is a newline.
`-f('##'*$_)` Inserts the actual level into the row using the `-f` format operator; `$_` is the current input value.
`*3` Multiplies the level row created by `"#{0,-10}###`n"-f('##'*$_)` three times
`+'#'*12` Adds the last line to the level rows created above.
Output is implicit.
[Answer]
# [Canvas](https://github.com/dzaima/Canvas), 23 [bytes](https://github.com/dzaima/Canvas/blob/master/files/chartable.md)
```
2×╵#×α⁵∔ ×#3×)∑3*#⁶×q;O
```
[Try it here!](https://dzaima.github.io/Canvas/?u=JXVGRjEyJUQ3JXUyNTc1JTIzJUQ3JXUwM0IxJXUyMDc1JXUyMjE0JTIwJUQ3JTIzJXVGRjEzJUQ3JXVGRjA5JXUyMjExJXVGRjEzJXVGRjBBJTIzJXUyMDc2JUQ3JXVGRjUxJXVGRjFCJXVGRjJG,i=Mw__,v=8)
### Explanation:
```
2×╵ push input*2+1 (called n)
#× repeat '#' n times
α⁵∔ × repeat ' ' 11-n times
#3× repeat '#' 3 times
)∑ join
3* repeat 3 times vertically
#⁶× repeat '#' 12 times
q;O print without popping, reverse stack, print stack
```
[Answer]
# [CJam](https://sourceforge.net/p/cjam), 38 bytes
```
li2*:I;'#:OC*N+_O_I*+AI-S*+O3*+N+3*\++
```
[Try it online!](https://tio.run/##S85KzP3/PyfTSMvK01pd2crfWctPO94/3lNL29FTN1hL299YS9tP21grRlv7/38jAA "CJam – Try It Online")
]
|
[Question]
[
This is the cops' thread. For the robbers' thread, go [here](https://codegolf.stackexchange.com/questions/64521/find-the-nested-source-codes-robbers).
# Introduction
For this Cops/Robbers challenge, the cops will write output-producing programs and interweave them together. It is the robber's job to pick apart the cops' programs to produce the desired outputs.
# Cop rules
The cops may use up to 256 bytes total to write between 2 and 8 (inclusive) programs, all of which *must* produce some output. All programs written must be in the same language. The cops will "interweave" their programs together to make it harder for the robbers to figure out what the programs are.
Now for a description of interweaving. Consider the strings representing the different programs. The process of interweaving is the repeated pulling off of the first character of any of the programs and concatenating it to the end of a new string until no characters in any of the programs are left. For example, if two programs are `lion` and `TIGER`, a possible interweaving is `TIliGoEnR`. However, the programs cannot be scrambled in any way, so `RoITEnlGi` is not acceptable.
It should be noted that when the characters of all but one program are removed from the results of an interweaving, the remaining program would be shown intact. Removing the letters `TIGER` from `TIliGoEnR` results in `lion`.
All of the cops' programs and outputs must contain *only* printable ASCII characters (20-7E) and newlines. Programs must not contain errors and must run in 10 seconds on a reasonable machine. For any submission, there must be a free interpreter of the language somewhere. Adding comments to the submissions is not allowed, as are hashing and other forms of cryptography. Blank programs are not allowed (Sorry [Stuck](https://codegolf.stackexchange.com/questions/55422/hello-world/55425#55425)).
The cop will post the interweaved code, the language, the number of different programs used, and the output for each program. A big thanks to Martin for writing [this CJam script](http://cjam.aditsu.net/#code=qN%2F%7Bmr((o_%7Ba%7D%26%2B%7Dh&input=abcdefg%0AABCDEFG%0A0123456) to automatically interweave your programs.
Programs are deemed safe after one week has elapsed from the time of posting. At that point, the cops must post the individual programs in order to receive points.
# Scoring
There are two components that are added together when scoring a safe submission.
* 256 divided by the quantity 2 raised to the power of the number of programs used.
* Round the number of bytes in the interweaving **up** to the nearest power of 2 and divide it into 256.
For example, if the entry `TIliGoEnR` (9 bytes) were safe, it would receive 256/2^2+256/16=80 points.
When a cop's submission is cracked, the cop loses 16 points. The cop must indicate that their submission has been cracked.
The winner of the cops' challenge will be the person with the most points after a sufficient period of time for people to participate.
# Leaderboard
This is a work in progress that was adapted by [intrepidcoder](https://codegolf.stackexchange.com/users/45393/intrepidcoder) from [this question](https://codegolf.stackexchange.com/q/60328/45393).
To make sure that your answer shows up, please start your answer with a headline, using the **exact** Markdown template:
```
# Language Name, N programs, M bytes; Score ###/### (if safe/cracked)
```
Anything after a semicolon will be ignored, so you can put your score there.
If your submission is safe put a header like this:
```
# Language Name, safe, N programs, M bytes; Score ###
```
If it is cracked, put a header like this:
```
# Language Name, [cracked](link-to-crack), N programs, M bytes; Score -16
```
```
/* Configuration */
var QUESTION_ID = 64520; // Obtain this from the url
// It will be like http://XYZ.stackexchange.com/questions/QUESTION_ID/... on any question page
var ANSWER_FILTER = "!t)IWYnsLAZle2tQ3KqrVveCRJfxcRLe";
var COMMENT_FILTER = "!)Q2B_A2kjfAiU78X(md6BoYk";
var OVERRIDE_USER = 43444; // This should be the user ID of the challenge author.
var SECONDSINDAY = 86400;
var SAFECUTOFFDAYS = 7;
var SORTBYTIME = true;
var SUBTRACTCRACKEDPOINTS = true;
var EXPIREDTIME = 1448232502000;
/* App */
var SAFE_REG = /<h\d>.*?[sS][aA][fF][eE].*<\/\h\d>/;
var POINTS_REG = /<h\d>.*(\d+)\s*program.*<\/h\d>/i; // /(?:<=|‚â§|<=)\s?(?:<\/?strong>)?\s?(\d+)/
// var POINTS_REG_ALT = /<h\d>.*?(\d+)(?=[^\n\d<>]*(?:<(?:s>[^\n<>]*<\/s>|[^\n<>]+>)[^\n\d<>]*)*<\/h\d>)/;
var LENGTH_REG = /<h\d>.*?((\d+)\s*byte).*<\/h\d>/i;
var CRACKED_HEADER_REG = /<h\d>.*[Cc][Rr][Aa][Cc][Kk][Ee][Dd].*<\/h\d>/;
var CRACKED_COMMENT_REG = /(.*[Cc][Rr][Aa][Cc][Kk][Ee][Dd].*<a href=.*)|(.*<a href=.*[Cc][Rr][Aa][Cc][Kk][Ee][Dd].*)/
var OVERRIDE_REG = /^Override\s*header:\s*/i;
var LANGUAGE_REG = /<h\d>\s*(.+?),.*<\/h\d>/;
var LANGUAGE_REG_ALT = /<h\d>\s*(<a href=.+<\/a>).*<\/h\d>/
var LANGUAGE_REG_ALT_2 = /<h\d>\s*(.+?)\s.*<\/h\d>/;
var LANGUAGE_REG_ALT_3 = /<h\d>(.+?)<\/h\d>/;
var answers = [],
answers_hash, answer_ids, answer_page = 1,
more_answers = true,
comment_page;
function answersUrl(index) {
return "//api.stackexchange.com/2.2/questions/" + QUESTION_ID + "/answers?page=" + index + "&pagesize=100&order=desc&sort=creation&site=codegolf&filter=" + ANSWER_FILTER;
}
function commentUrl(index, answers) {
return "//api.stackexchange.com/2.2/answers/" + answers.join(';') + "/comments?page=" + index + "&pagesize=100&order=desc&sort=creation&site=codegolf&filter=" + COMMENT_FILTER;
}
function getAnswers() {
jQuery.ajax({
url: answersUrl(answer_page++),
method: "get",
dataType: "jsonp",
crossDomain: true,
success: function(data) {
answers.push.apply(answers, data.items);
answers_hash = [];
answer_ids = [];
data.items.forEach(function(a) {
a.comments = [];
var id = +a.share_link.match(/\d+/);
answer_ids.push(id);
answers_hash[id] = a;
});
if (!data.has_more) more_answers = false;
comment_page = 1;
getComments();
}
});
}
function getComments() {
jQuery.ajax({
url: commentUrl(comment_page++, answer_ids),
method: "get",
dataType: "jsonp",
crossDomain: true,
success: function(data) {
data.items.forEach(function(c) {
answers_hash[c.post_id].comments.push(c);
});
if (data.has_more) getComments();
else if (more_answers) getAnswers();
else process();
}
});
}
getAnswers();
function getAuthorName(a) {
return a.owner.display_name;
}
function process() {
var valid = [];
var open = [];
answers.forEach(function(a) {
var body = a.body.replace(/(<h\d>.*);.*(<\/h\d>)/,"$1$2"); // Ignore all text after a semicolon.
var cracked = false;
a.comments.forEach(function(c) {
var was_safe = (c.creation_date + (SECONDSINDAY * SAFECUTOFFDAYS) > a.creation_date);
if (CRACKED_COMMENT_REG.test(c.body) && !was_safe)
cracked = true;
});
if (CRACKED_HEADER_REG.test(body)) cracked = true;
// if (SUBTRACTCRACKEDPOINTS||!cracked) {
var createDate = a.creation_date;
var currentDate = Date.now() / 1000;
var timeToSafe = (createDate + (SECONDSINDAY * SAFECUTOFFDAYS) - currentDate) / SECONDSINDAY;
var SafeTimeStr = (timeToSafe > 2) ? (Math.floor(timeToSafe) + " Days") :
(timeToSafe > 1) ? ("1 Day") :
(timeToSafe > (2 / 24)) ? (Math.floor(timeToSafe * 24) + " Hours") :
(timeToSafe > (1 / 24)) ? ("1 Hour") :
"<1 Hour";
var expired = createDate > (EXPIREDTIME);
var safe = timeToSafe < 0;
var programs = body.match(POINTS_REG);
var length = body.match(LENGTH_REG);
safe = safe && !cracked
isOpen = !(cracked || safe);
if (programs && length) {
var safepoints = (256/Math.pow(2,parseInt(programs[1],10)) +
256/Math.pow(2,Math.ceil(Math.log2(parseInt(length[1],10)))));
var crackedpoints = Math.pow(2, parseInt(programs[1],10),2) +
Math.pow(2,Math.floor(Math.log2(parseInt(length[1],10))));
valid.push({
user: getAuthorName(a),
numberOfSubmissions: (safe && !expired) ? 1 : 0,
points: (safe && !expired) ? safepoints : 0,
open: (isOpen && !expired) ? 1 : 0,
cracked: (cracked && !expired) ? 1 : 0,
expired: (expired) ? 1 : 0
});
}
if ((isOpen || expired) && programs) {
var language = body.match(LANGUAGE_REG);
if (!language) language = body.match(LANGUAGE_REG_ALT);
if (!language) language = body.match(LANGUAGE_REG_ALT_2);
if (!language) language = body.match(LANGUAGE_REG_ALT_3);
open.push({
user: getAuthorName(a),
safePts: programs ? safepoints : "???",
crackedPts: programs ? crackedpoints : "???",
language: language ? language[1] : "???",
link: a.share_link,
timeToSafe: timeToSafe,
timeStr: (expired) ? "Challenge closed" : SafeTimeStr
});
}
// }
});
if (SORTBYTIME) {
open.sort(function(a, b) {
return a.timeToSafe - b.timeToSafe;
});
} else {
open.sort(function(a, b) {
var r1 = parseInt(a.length);
var r2 = parseInt(b.length);
if (r1 && r2) return r1 - r2;
else if (r1) return r2;
else if (r2) return r1;
else return 0;
});
}
var pointTotals = [];
valid.forEach(function(a) {
var index = -1;
var author = a.user;
pointTotals.forEach(function(p) {
if (p.user == author) index = pointTotals.indexOf(p);
});
if (index == -1) {
if (SUBTRACTCRACKEDPOINTS && a.cracked) a.points -= 16;
pointTotals.push(a);
}
else {
pointTotals[index].points += a.points;
pointTotals[index].numberOfSubmissions += a.numberOfSubmissions;
pointTotals[index].cracked += a.cracked;
pointTotals[index].expired += a.expired;
pointTotals[index].open += a.open;
if (SUBTRACTCRACKEDPOINTS && a.cracked) pointTotals[index].points -= 16;
}
});
pointTotals.sort(function(a, b) {
if (a.points != b.points)
return b.points - a.points;
else if (a.numberOfSubmissions != b.numberOfSubmissions)
return b.numberOfSubmissions - a.numberOfSubmissions;
else if (a.open != b.open)
return b.open - a.open;
else if (a.cracked != b.cracked)
return a.cracked - b.cracked;
else return 0;
});
pointTotals.forEach(function(a) {
var answer = jQuery("#answer-template").html();
answer = answer
.replace("{{NAME}}", a.user)
.replace("{{SAFE}}", a.numberOfSubmissions)
.replace("{{OPEN}}", a.open)
.replace("{{CLOSED}}", a.expired)
.replace("{{CRACKED}}", a.cracked)
.replace("{{POINTS}}", a.points);
answer = jQuery(answer);
jQuery("#answers").append(answer);
});
open.forEach(function(a) {
var answer = jQuery("#open-template").html();
answer = answer
.replace("{{NAME}}", a.user)
.replace("{{SAFE}}", a.safePts)
.replace("{{CRACKED}}", a.crackedPts)
.replace("{{LANGUAGE}}", a.language)
.replace("{{TIME}}", a.timeStr)
.replace("{{LINK}}", a.link);
answer = jQuery(answer);
jQuery("#opensubs").append(answer);
});
}
```
```
body {
text-align: left !important
}
#answer-list {
padding: 10px;
width: 350px;
float: left;
}
#open-list {
padding: 10px;
width: 470px;
float: left;
}
table thead {
font-weight: bold;
vertical-align: top;
}
table td {
padding: 5px;
}
```
```
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<link rel="stylesheet" type="text/css" href="//cdn.sstatic.net/codegolf/all.css?v=83c949450c8b">
<div id="answer-list">
<h2>Leaderboard</h2>
<table class="answer-list">
<thead>
<tr>
<td>Author</td>
<td>Safe</td>
<td>Open</td>
<td>Cracked</td>
<td>Late Entry</td>
<td>Score</td>
</tr>
</thead>
<tbody id="answers">
</tbody>
</table>
</div>
<div id="open-list">
<h2>Open submissions</h2>
<table class="open-list">
<thead>
<tr>
<td>Author</td>
<td>Points if Safe</td>
<td>Points if Cracked</td>
<td>Language</td>
<td>Time Remaining</td>
<td>Link</td>
</tr>
</thead>
<tbody id="opensubs">
</tbody>
</table>
</div>
<table style="display: none">
<tbody id="answer-template">
<tr>
<td>{{NAME}}</td>
<td>{{SAFE}}</td>
<td>{{OPEN}}</td>
<td>{{CRACKED}}</td>
<td>{{CLOSED}}</td>
<td>{{POINTS}}</td>
</tr>
</tbody>
</table>
<table style="display: none">
<tbody id="open-template">
<tr>
<td>{{NAME}}</td>
<td>{{SAFE}}</td>
<td>{{CRACKED}}</td>
<td>{{LANGUAGE}}</td>
<td>{{TIME}}</td>
<td><a target="_parent" href="{{LINK}}">Link</a>
</td>
</tr>
</tbody>
</table>
```
[Answer]
## [Hexagony](https://github.com/mbuettner/hexagony), 6 programs, 53 bytes; Score 8/96 (if safe/cracked)
```
[&;//&z
;!X;!!/@!
@)6!< @[!.J
@a5|9o;""
|@!!!@]
```
Even if this goes safe, it will be very few points for me, but I thought I'd provide a nice puzzle for robbers to bank some points. :) I have no idea how easy or hard this actually is.
Here are the outputs:
```
Jazz
```
```
XX88XX88
```
```
1234562345610
```
```
111111111111111111111111
```
```
9999999999999999999999999999999999
```
```
66566565665656566565656566565656565665
```
[Answer]
# JavaScript, [cracked](https://codegolf.stackexchange.com/a/64618/45393), 2 programs, 110 bytes; Score -16
```
+(![]+!![])[[]+[]]+(![]+[])+[+[]]+(!![]+[])[[+[]]+[]]+(!![]+[])+[+[]]+(+(![]+!![])[])[+[]]+(![]+[])+[+[]](+[])
```
üòà good luck with this one.
Note: I recommend running on a modern browser (basically not IE)
**Output, first program:**
```
ffttff
```
**Output, second program:**
```
1010
```
[Answer]
# [BitShift](https://esolangs.org/wiki/BitShift), [cracked](https://codegolf.stackexchange.com/a/64563/41257), 2 programs, 110 bytes; Score -16
### Interweaved programs
```
10011110011111001011101110110110110110011001100010110000010010011100101111000111100110111101011110011101001100
```
### Output, first program
```
! ?
```
### Output, second program
```
? !
```
I'm so sorry
[Answer]
# [Vitsy](https://github.com/VTCAKAVSMoACE/Vitsy), [cracked](https://codegolf.stackexchange.com/a/64597/44713), 2 programs, 15 bytes; Score -16
### Interweaved Programs
```
a'5oF'2\\aI/NZO
```
[Vitsy](https://github.com/VTCAKAVSMoACE/Vitsy) is so pretty, so clean. Look into its source, and be awed.
### Output, first program
```
NaNo
```
### Output, second program
```
```
That's 121 newlines.
[Answer]
# Java, [cracked](https://codegolf.stackexchange.com/a/64576/32700), 2 programs, 155 bytes; Score -16
### Interleaved programs
```
cliantsesr fai{pce ubc{stlaic sttatiic voidc mavioin(Sd tmariinn(Stg[rin]g)g{Syst[em]n.)o{ut.prSiysntemtln.out.(prin"Hell"\u002bg.tlen(gth)"By;e!\n}")};}}
```
### Output, first program
```
Hell0
```
And trailing newline.
### Output, second program
```
Bye!
```
And trailing newline.
## Original programs
### First
```
class i{public static void main(String[]g){System.out.println("Hell"\u002bg.length);}}
```
### Second
```
interface c{static void main(String[]n){System.out.print("Bye!\n");}}
```
[Answer]
# Pyth, safe, 2 programs, 63 bytes; Score 68
### Interweaved programs
```
V8j5kIqlPN1[C7=3+Z1d=G"<"C38p5)IqdZ21=ZNB;C-jk[C9Zd\</.5n0T1dG2
```
### First program
Output:
```
I <3 U
```
Program:
```
jk [C73d"<"3pdC-95T
j # Join
k # Standard variable: ""
[ # Creates a new list
C73 # Char 73 = I
d # Standard variable: " "
"<" # String: "<"
3 # Number 3
pd # Prints " ", the leading whitespace
C # Char
-95T # -95T = 95 - 10 = 85. Char 85 = U
```
### Second program
Output
```
I <3 U2
```
Program:
```
V85IqlPN1=+Z1=GC85)IqZ21=ZNB;jk[CZd\</.n01dG2
# implicit Z = 0
V85 # For N in range(85)
I # If
qlPN1 # Length of the prime factors of N equals 1
=+Z1 # Z = Z + 1
=GC85 # G = Char 85 = U
) # Ends the if statement
IqZ21 # If Z equals 21(th prime)
=ZN # Z = N (73)
B # Break out of the for loop
; # Infinite ), to close open parentheses
jk # Join ""
[ # New list
CZ # Char Z = Char 73 = I
d # Standard variable: " "
\< # Single character '<'
/ # Floored division
.n0 # Pi, 3.14159...
1 # Divide by 1 and round down
d # Standard variable: " "
G # G = C85 = U
2 # Number 2
```
[Answer]
# CJam, safe, 2 programs, 250 bytes; Score 65
### Interweaved programs
```
"":9(x5M/Cle-Dn,1'AFjsQYirG3@+,~unY</CyUAJ!`L.Xkdq'hF_X&=-`!SnxM!hqv~'GW!4!qIfp$h,ld-;i0JM79Xs'orb@#+sE${?.Eet""""/4M.D:}~Cc^est+2]c9>^W<O%8rR(kg)(ra-P{^Fthm?WF[#KJfRxOe-5zYueb~SiX@tnFyb2-M}G8@0;Z.$u']Qc0R{\.M9V$_NyTc,HR]y""22{{'' ffmm9955bb\\}}****
```
### Output, first program
```
169004397811215505136757551914260640157209814479670875629464038264532260025741074366481672115039451444875174892900756838476896193165147376670615268045482935802126657286722969566601154866449492847343470441618498401
```
### Output, second program
```
236156588886135909534842810119847991195053526225488685859715966203756668582804035289768525426132740118856398404195457578486865119219669643999456580063310899697265496162944335336660228420754397359091438096239696929
```
## Solution
### First program
```
"9(M/l-n'FsQrG@~n<CyA`.XdhF&-`SMhq~W!qI$hd-0M7X'b#sE{Ee""/MD~c^s2]>^O%r(gra{FhmW#KfOezYbSi@Fy-}G0;$u]cR.9V_TcRy"2{' fm95b\}**
```
[Try it online!](http://cjam.tryitonline.net/#code=IjkoTS9sLW4nRnNRckdAfm48Q3lBYC5YZGhGJi1gU01ocX5XIXFJJGhkLTBNN1gnYiNzRXtFZSIiL01EfmNeczJdPl5PJXIoZ3Jhe0ZobVcjS2ZPZXpZYlNpQEZ5LX1HMDskdV1jUi45Vl9UY1J5IjJ7JyBmbTk1Ylx9Kio&input=)
### Second program
```
":x5CeD,1AjYi3+,uY/UJ!Lkq'_X=!nx!v'G4!fp,l;iJ9sor@+$?.t""4.:}Cet+c9W<8Rk)(-P^t?F[JRx-5ue~Xtnb2M8@Z.'Q0{\M$Ny,H]"2{' fm95b\}**
```
[Try it online!](http://cjam.tryitonline.net/#code=Ijp4NUNlRCwxQWpZaTMrLHVZL1VKIUxrcSdfWD0hbnghdidHNCFmcCxsO2lKOXNvckArJD8udCIiNC46fUNldCtjOVc8OFJrKSgtUF50P0ZbSlJ4LTV1ZX5YdG5iMk04QFouJ1Ewe1xNJE55LEhdIjJ7JyBmbTk1Ylx9Kio&input=)
### How it works
Both programs have this format:
```
"…""…"2{' fm95b\}**
2{ }* Do the following twice:
'fm Subtract the char code of ' ' from each character.
95b Convert from base 95 to integer.
\ Swap the two topmost stack elements.
This pushes two prime numbers on the stack.
* Compute their product.
```
De-interweaving the programs should require either brute force or factoring the semi-primes.
[Answer]
# Befunge, Safe, 2 programs, 228 bytes; Score 65
## Interweaved programs
```
7b*2"!+:,l9ooa"v +2^*<>+:::v,v
1- v2:,+9 -,\,,<$+":4b*,
v>"i g>:nb:"^,2$+,1'g#
+0^"gs "-*< :-*,n,
v\,a3+v
-9*b6-3b ,*a<b:u,+|11 B'<
,:+>19v>,:'m+:9,:+3a^:,:a+"c*@9a, >': 'e^
<^;*+<v" gr"< ^
>@,"+*or:\*:3pa, g"^0>'f^8<;
```
## Output, first program
```
Output, first program
```
## Output, second program
```
Befunge programming is cool!
```
I doubt this will be a easy one to crack. In fact you should just give up now.
Who needs 132 points anyway?
## Answer
Program 1:
```
7b*2+:,9a+2*+:::,1-:,\5-,\,,4b*,v>::,2+,'+0g\1-:,\,3+v
-9*bb,,+1,:+1,:+9,:+3,:+c*9a,: '<^; @,+*:\*:3a,g08<;
```
>
> Output, first program
>
>
>
Program 2:
```
"!loo"v ^<>vv
v2+9 <$+":
>"i gnb"^$1g#
^"s "*< -*n,
va6-3 *a<b:u|1 B'<
>9v>'m:a^:a"@ >'e^
*+<v"gr"<^
>"orp "^>'f^
```
>
> Befunge programming is cool!
>
>
>
[Answer]
# PHP, [cracked](https://codegolf.stackexchange.com/a/64751/41859), 2 programs, 71 bytes; Score -16
**Interleaved**
```
$ec=tchR;$ho =qs;$cu=$ho.$tc.e_me.$tha(.'p^l/it]';e.cchoo.$c('[$$h'));;
```
**Output**
*1st program*
```
Array
```
*2nd program*
```
\^/\]co\[\$
```
---
**Note**: `Notices` should be suppressed.
[Answer]
# JavaScript ES6, [cracked](https://codegolf.stackexchange.com/questions/64521/find-the-interwoven-source-codes-robbers/64760#64760), 2 programs, 255 bytes; Score -16
Good job @Bas! GG.
```
trvya{"fru nxcti;on{;ale"r;Otb(j(fe=c>t(.kfe.yrs(efv)e}rcsate(cf+h(e~)~{ff,=Mast=h>!.posw?f((12),:M"a"t;hal.Ee)r))t)((nfe(wf A(rfr(a0y/(909)) +.f(7/f5il)l()0))+.fma(pf()(x,+`i$,{ff)}=>i`/.s3p)l).ijt`o`.imn(ap"("e)=.>repela.cceh(/ar.Co.d/egA,t""())*)2}3))}
```
## Output 1:
```
36666666666666643333333333333336323666666666666668333333333333333231366666666666666833333333333333323026666666666666682333333333333332292666666666666668233333333333333228266666666666666823333333333333322726666666666666682333333333333332262666666666666668233333333333333225266666666666666823333333333333322426666666666666682333333333333332232666666666666668233333333333333222266666666666666823333333333333322126666666666666682333333333333332201666666666666668133333333333333219166666666666666813333333333333321816666666666666681333333333333332171666666666666668133333333333333216166666666666666613333333333333341516666666666666661333333333333334141666666666666666133333333333333413166666666666666613333333333333341216666666666666661333333333333334111666666666666666133333333333333410666666666666666333333333333334966666666666666633333333333333486666666666666673333333333333337666666666666667333333333333333666666666666666733333333333333356666666666666673333333333333334666666666666666533333333333333353666666666666666533333333333333352666666666666666733333333333333331666666666666666633333333333333330
```
## Output 2:
```
2645,1403,1426,759,2645,1449,2346,920,1127,943,1334,782,782
```
[Answer]
# JavaScript (ES6), safe, 2 programs, 255 bytes; Score 65
### Interleaved programs
```
aalleerrtt((l=[](+(!l[=[l])+="(l "=l+[]l][[+l>=+1l]]=l+=>(l>l=>l=l<l,")"+l+(l(=l>l>=l)=+ (l)l+= +l)l+=>((ll==l)>(l=l)+l++ ()l+>l()+(l=>l(l===l>l=l)(l()l>=l)+))+""(l +(=""l=+)+(l+l(=)l<)+(=l+)+l++(ll=<<l)+++l)(l+=(=l(==ll)=>l+<l()(ll=))))(l<=l)<l)+(+l<l)))
```
### Output of First Program
```
false12truetruetruefalse
```
### Output of Second Program
```
falsefalseundefinedtruetruetruetruefalse116truetruefalse
```
I tried to use the characters `(l)+=<>` as much as possible. The rest is just type conversion.
### First program
```
alert((l=[l=" "][+l>=+1]=l=>l>=l<l,""+l(l=l>=l)+ +l)+((l>=l++ )+((l=>l=l>=l)(l>=l))+(l="")+(l+=l<=l)+l+(l=l)+(l==(l=>l<l)(l))))
```
### Second program
```
alert((l=[]+![])+(l=l+[l][l]+(l>=l)+(l>=l)+ (l=l=>l==l)(l)+l(l>l)+(l==l(l))+"" +(l=+l())+(++l<<++l)+(l==l)+(l=(l<=l)<l)+(+l<l)))
```
[Answer]
# Ruby, [cracked](https://codegolf.stackexchange.com/a/64726/2537), 2 programs, 64 bytes; Score -16
**Interleaved**
```
p w,%=?(w.ord,40,?)(;"jb inv inv is{2").bytes{|*b|?aput%?c} b-w}
```
**Output**
*1st program*
```
"bananas"
```
*2nd program*
```
BANANAS
```
Both outputs have trailing newlines.
[Answer]
# Malbolge, 2 programs, 194 bytes; Score 65
## Interweaved
```
D'`D$'#`pK~A5:]|3!W1ICw;A|RXsWP0xgN;BLeJmd[c#bGa!`3p%n$BS9?~m*,+N)6ii9E%CAxw"Y!Xtbslw2SR|n^gf)9ex+ZLphuan`s_l%F2bS[ZRYn}@gVfUey+SL;QPba`O_s^$[MZR_K^JWO{N>G=kY.XJQuCHUAT@65d>QJ&nN<0;FjJ,H@G@9d]JQ
```
## Output 1
```
haha nope
```
## Output 2
```
malbolge
```
---
It was only a matter of time.
# Programs
## O1
```
D'`A:]\!I;|XWxgBedcba`pn9m*6iiE%CA"!bw|^)9xZpunsl2SRngfe+Lba`_^$\[Z_^W{>=YXQuUT65QJnN0FjJ,HG@dQ
```
## O2
```
D'`$#pK\~5|3W1CwARsP0N;LJm[#G!3%$BS?~,+N)9xwYXtsl2SRngfe+Lha`_%Fb[ZY}@VUyS;QPOsMRKJONGk.JCHA@d>&<;@9]J
```
[Answer]
# Perl, safe, 2 programs, 102 bytes; Score 66
```
sprint""@(u{[|<$/{W)xor$^ldH&~!<]#3,/H-61+e#]l#:l7o#3:3}>]3$^WS}[_$#:,=(~s#30-)3;)^#,]$")]>=">reverse]
```
---
**First Output**
```
Hello, World!
```
**Second Output**
```
Hello, World!
```
---
**Solution**
First Program:
>
> `print@{[<{World!,Hello}>]}[$,=~s)),$")=>rvrs]`
>
>
>
Second Program:
>
> `s""(u|$/)x$^H&~<]#3/-61+#]#:7#3:33$^WS_#:(#30-3;^#]]>"eee`
>
>
>
[Answer]
# Pyth, 2 programs, 61 bytes; Score 68/36 (if safe/cracked)
**Interleaved programs**
```
*vsC{`.m`DsPCd..[Gn9`T2vjkpv`/JmsC\Pid~T.n1tt`.VJp~T%n*TCG731
```
**Output, first program**
```
491670984540320247032212137862815
```
**Output, second program**
```
46252265449938954198657919684976120662891392853344868455756073
1063494620552721403954429737131814326362865215612332412466411486182225511644503132172962643458535768453543651970155938693047567602310634946205527214039544297371318143263628652156123324124664114861822255116445031321729626434585357684535
```
Shouldn't be too hard.
[Answer]
# PHP, [cracked](https://codegolf.stackexchange.com/a/64705/41859), 3 programs, 31 bytes; Score -16
This should be an easy one using 3 programs.
**Interleaved**
```
print ppprrriiinnnttt!!$x'0';;;
```
**Output**
*1st program*
```
1
```
*2nd program*
```
1
```
*3rd program*
```
1
```
---
**Note**: `Notices` should be suppressed.
[Answer]
# JavaScript ES6, 2 programs, 225 bytes; Score 65/132 (if safe/cracked)
Interweaved:
```
alaelretrt((((cb=>c=>b.replace(/.replace[a-(/[azA-Z]-z]/gi/g,a,s=>String=>String.fromCharCode(s.fromCharCode(("Z">=a.charCodeAt(0)?90:122)>=(a=a.charCodeAt(0+(s.toLowerCase())+13)?a<'n'?13:-13:a-26)))))))((""gfvbznfcyrg""))))
```
First output:
```
simple
```
Second output:
```
toast
```
[Answer]
# Brainfuck, 4 programs, 251 bytes; 17/144 (if safe/cracked)
**Interweaved programs**
```
--[+++++--+[----++[+-->+[+++++><-]--++->->---<>--]<]+>><.+-+[-+.--[+-++]+.>->-+.-+-.>-+<-<][]>[----+---+>->->.-+<+<]]>>+--..++----+-++-.---+--++-+..----.-----.-.--.--++..-+++++.++-+++[-++-[-->>++++++<+]<>-+.++]++>.+[->++++.<]>+.[--->+<]>++.---.------.
```
**Output, first program**
`Eridan`
**Output, second program**
`Ampora`
**Output, third program**
`PPCG`
**Output, fourth program**
`Code Golf`
[Answer]
# [Microscript II](http://esolangs.org/wiki/Microscript_II), safe, 2 programs, 44 bytes; score 68
Interleaved sources:
```
6$4sv{{3@0s>s"`+`"}s<s3320s*{1+s+K+s<}*p}*h`
```
Output, first program:
```
>=<;:9876543210/.-,+*)('&%$#"! >=<;:9876543210/.-,+*)('&%$#"! >=<;:9876543210/.-,+*)('&%$#"! >=<;:9876543210/.-,+*)('&%$#"! >=<;:9876543210/.-,+*)('&%$#"! >=<;:9876543210/.-,+*)('&%$#"! >=<;:9876543210/.-,+*)('&%$#"! >=<;:9876543210/.-,+*)('&%$#"! >=<;:9876543210/.-,+*)('&%$#"! >=<;:9876543210/.-,+*)('&%$#"! >=<;:9876543210/.-,+*)('&%$#"! >=<;:9876543210/.-,+*)('&%$#"! >=<;:9876543210/.-,+*)('&%$#"! >=<;:9876543210/.-,+*)('&%$#"! >=<;:9876543210/.-,+*)('&%$#"! >=<;:9876543210/.-,+*)('&%$#"! >=<;:9876543210/.-,+*)('&%$#"! >=<;:9876543210/.-,+*)('&%$#"! >=<;:9876543210/.-,+*)('&%$#"! >=<;:9876543210/.-,+*)('&%$#"! >=<;:9876543210/.-,+*)('&%$#"! >=<;:9876543210/.-,+*)('&%$#"! >=<;:9876543210/.-,+*)('&%$#"! >=<;:9876543210/.-,+*)('&%$#"! >=<;:9876543210/.-,+*)('&%$#"! >=<;:9876543210/.-,+*)('&%$#"! >=<;:9876543210/.-,+*)('&%$#"! >=<;:9876543210/.-,+*)('&%$#"! >=<;:9876543210/.-,+*)('&%$#"! >=<;:9876543210/.-,+*)('&%$#"! >=<;:9876543210/.-,+*)('&%$#"! >=<;:9876543210/.-,+*)('&%$#"! >=<;:9876543210/.-,+*)('&%$#"! >=<;:9876543210/.-,+*)('&%$#"! >=<;:9876543210/.-,+*)('&%$#"! >=<;:9876543210/.-,+*)('&%$#"! >=<;:9876543210/.-,+*)('&%$#"! >=<;:9876543210/.-,+*)('&%$#"! >=<;:9876543210/.-,+*)('&%$#"! >=<;:9876543210/.-,+*)('&%$#"! >=<;:9876543210/.-,+*)('&%$#"! >=<;:9876543210/.-,+*)('&%$#"! >=<;:9876543210/.-,+*)('&%$#"! >=<;:9876543210/.-,+*)('&%$#"! >=<;:9876543210/.-,+*)('&%$#"! >=<;:9876543210/.-,+*)('&%$#"! >=<;:9876543210/.-,+*)('&%$#"! >=<;:9876543210/.-,+*)('&%$#"! >=<;:9876543210/.-,+*)('&%$#"! >=<;:9876543210/.-,+*)('&%$#"! >=<;:9876543210/.-,+*)('&%$#"! >=<;:9876543210/.-,+*)('&%$#"! >=<;:9876543210/.-,+*)('&%$#"! >=<;:9876543210/.-,+*)('&%$#"! >=<;:9876543210/.-,+*)('&%$#"! >=<;:9876543210/.-,+*)('&%$#"! >=<;:9876543210/.-,+*)('&%$#"! >=<;:9876543210/.-,+*)('&%$#"! >=<;:9876543210/.-,+*)('&%$#"! >=<;:9876543210/.-,+*)('&%$#"! >=<;:9876543210/.-,+*)('&%$#"! >=<;:9876543210/.-,+*)('&%$#"! >=<;:9876543210/.-,+*)('&%$#"! >=<;:9876543210/.-,+*)('&%$#"!
```
Output, second program:
```
[5.477225575051661,2.340347319320716,1.5298193747370035,1.2368586720951604,1.1121414802511236,1.0545811871312343,1.026928034056542,1.0133745773683798,1.0066650770580947,1.0033270040510693,1.001662120702919,1.0008307153074985,1.0004152714285695,1.0002076141624645,1.0001038016938364,1.000051899500139,1.0000259494133834,1.0000129746225213,1.0000064872902181,1.0000032436398485,1.0000016218186092,1.0000008109089757,1.0000004054544056,1.0000002027271822,1.000000101363586,1.0000000506817917,1.0000000253408956,1.0000000126704478,1.000000006335224,1.000000003167612]
```
---
And here's the answer:
Program 1:
```
64s{30s>""s<32s{1+s>K+s<}*p}*h
```
Program 2:
```
$v{@s`+`}s30*`
```
[Answer]
# Javascript, safe, 2 programs, 106 bytes; Score 66
```
alert(2ale98374rt("q883wope2jv+sjn[d]s^234j8kfdk7j9b|12f8ns7"[9]98+"jskfsd3"2+13()3892721+[]+{}*6^5|27&3))
```
### Output 1
```
-35655169
```
### Output 2
```
njskfsd7
```
## Solution
### Program 1
```
alert(2983748832+[]^234879|1287983213)
```
### Program 2
```
alert("qwopejvsjndsjkfdkjbfns"[9]+"jskfsd"+(3892721+[]+{}*6^5|27&3))
```
[Answer]
# [Japt](https://github.com/ETHproductions/Japt), safe, 3 programs, 63 bytes; Score 36
The version of the interpreter that this was built for can be found [here](http://ethproductions.github.io/japt/?v=8e7dc20f23074b672116cbf5dfd52d55c1660ca4). Unfortunately, I've lost the originals, so I'll have to see if I can crack it myself...
### Interweaved programs
```
"AARoooLv mLv m@(_y6Xpp33* ay%2%|v2n"+95+'H+2 m@(Xdcq)q -A d
```
### Output 1
```
112221174199804510029601998159214179608538147196191138431341951029363738456410116231158105100149362111411782137669714451962921697122751841161758017110476673747582101138199681951421371867326511541191741031345182116631134159
```
That's *222* digits, in case you were wondering.
### Output 2
```
R!2,tR+dE34N('QM!2'e4Xx;e>+2YGaNsw`4Xs,Gk?(,Q>XFmta:d'Gk:xm~RNxwQklZ;tM+sm~M?ZEea?dw~ !(;`
```
### Output 3
```
Hello, World!
```
[Answer]
# JavaScript, 2 programs, 255 bytes; Score 65/132 (if safe/cracked)
```
a=c(([]o[0]+[][0n]+[][0]s+[][0o]+"l")e+(((new .Date)+"l").osplit(" g")[8])+"".match((/aa/)+t([0o][1]+"b")).split(")").join("('").split("bn");Vconssole.blog(aA=[1]=.toUpperCase()+a[7]+a[13]+" '))"+a[4].toUpperCase()+"`"+a[5]+" "+a[15]+a[16]+a[17;]+a[018]);
```
First program output:
```
And I`m fine
```
Second Program output:
```
null
```
The second programs output is text and not JavaScript's:`null`
This should be easy for the robbers.
[Answer]
# [Vitsy](https://github.com/VTCAKAVSMoACE/Vitsy/tree/b66ca18fca2f2cf0076c1788d363cf0c795fd810), 4 programs, 228 bytes; Score 17
(Uses an older version, which is linked)
Heeeyyyy @VoteToClose. I don't expect this one to be up long, but you never know… I love your language, now that I'm using it a lot!
## Interweaved program
```
1E2P-0P1E^l*312359121E4/13+1*-205+-5Pv*92t\9\[931[2-\D+\*12/]1N5*[t22*^50\+[\72C]\[[2r***t]PC^s]]2TNL2l\*2v2-D2E12[+48/3*-]2\**v+i8+1D+++NL*5N]-*4Z525L5L2*26E/-{'^2N6+l"015v52\2[{v/\[1*12]/r+^ZDs"6p'TO2N{^v]1v{\/3N\[52*]*4-^*N\*
```
# Output 1
```
2014794345195992700000000000000000000000000.00000049.2129129367736101
```
# Output 2
```
679:;=>@ABDEFHIJLMNPQSTUWXY[\]_`b
```
# Output 3
```
44.5'+26
```
# Output 4
```
100000.315464876785728777498798913309289000000000000000000000000000000000000000000000000.000000
```
---
Good luck! I used the online interpreter, but it should work in the safe jar.
---
# Programs
# O1
```
El94+*2+Pt*t7\[rP^]N2248*2*8**2LLE{^N0v\[v1+DpN{v]v\N
```
# O2
```
EPP^*E/3-05-v\[32\[52]***vDE2/-v++]Z
```
# O3
```
12-1313111159991-\+12/152*0+\[2*]2Ll2-1+\+DN5-552*/-'+"5522\[*]rZ"6'O
```
# O4
```
0252*2\[D*]N2^\[CtCs]T2\[3]*i1++LN452626l1{/12/^sT2^1{/3\[52*]*4-^*N\*
```
[Answer]
# Candy, safe, 2 programs, 85 bytes; Score 66
See: [Candy](https://github.com/dale6john/candy)
```
75~z43+/k20*416+k-1612+1++k2
8343-k92k*4+5k~7*Ak70kR(4122
5612=x53bAR2((hkDXhZ*h)))ZZ??
```
Outputs:
`51450000`
`1609944`
Update: This is the two programs followed by their interleaving:
```
7 ~z4 /k 0 41 +k 612 +k28 4 -k92k 4 5k~ Ak70k 41225612 53 2( kD Z*h) Z ?
5 3+ 2 * 6 -1 +1+ 3 3 * + 7* R( =x bAR (h Xh )) Z?
75~z43+/k20*416+k-1612+1++k28343-k92k*4+5k~7*Ak70kR(41225612=x53bAR2((hkDXhZ*h)))ZZ??
```
[Answer]
# [Foo](https://esolangs.org/wiki/Foo), 6 programs, 197 bytes; Score 5/192 (if safe/cracked)
Interweaved code:
```
&(@@11&5@@756&@04$+110)c5*@@1$*1+c52$&&@+15*@@2c$(c61>(51/6+10)@<*2$0c*-$0+6c*$6@1$+$c-01c@1c4$c$@/2&-)$50c++c(+$@2*$c2($+6c+c>0*(>+42&$1c+1$6+c--2@<$<5)c>$c>+7$$cc)-<++1+11$$cc)@2(32/$c)&+5*2$c"B"
```
Output from 1st program:
```
@
B
```
Note the tab on first line and trailing space on second line
Output from 2nd program:
```
<83.-
```
Note that the first line is blank
Output from 3rd program:
```
<=$)
```
Output from 4th program:
```
72}
```
Output from 5th program:
```
$#%*+&
```
Output from 6th program:
```
Foo
```
There is only one interpreter for Foo which i know of, you can find it [here](http://foo.tryitonline.net/)
[Answer]
# Python 2, 8 programs, 92 bytes; Score: -16
Another easy one:
```
ppprirnriipnnprtp rrpti"piirnrinio"ntt n n"bt"Tunht" t"is ""dot n"t ohhe"el""w lo"aleal"l"s"
```
8 outputs:
```
This
hello
well
no
alas
but
oh
done
```
[Answer]
# JavaScript, 8 programs, 233 bytes; Score 2/384 (if safe/cracked)
OK, now I'm being evil:
```
aalaaalaalllelreeereatlrterlreer(trtr(t(("t(t(!ft(!u\(untc!(y!t[0![p(!ty2!0p6ioee]a[8+0[0tbon(\o!fuo0)fb0 0 |(|h!6["t!Z5y!{!ze"[)0pb}b]01e]+"+")"+o\uo[]0]o0b1f110 al)]4d+1")+)]cl)"("\o!fu0u))0.4slc\incu00c6e(4,f"t)8))ion(){}+![])+"")
```
1st Output:
```
false
```
2nd Output:
```
true
```
3rd Output:
```
heLLo
```
4th Output:
```
2015
```
5th Output:
```
0
```
6th Output:
```
good
```
7th Output:
```
fine
```
8th Output:
```
string
```
[Answer]
# Python 2, safe 2 programs, 148 bytes; Score 65
```
execexec'prin'""it`sum(map(ormpd,(stor.rparrt""('""thellitio"on.__n"'ame_)'_*".3**/7".__len.__()re)pl[ace++-2(]))**061`[+*+2]'.re'"_pl'a)ce(*"+:")
```
Output 1:
```
Hello world...
```
Output 2:
```
188381387815229576775053627587460257651836527329727069542076068076585927926328856199896
```
Program 1:
```
exec'""import""(\'""hello""\')'.replace(*'"_')
```
Program 2:
```
exec'print`sum(map(ord,(str.rpartition.__name__*".3**/7".__len__())[++-2]))**061`[++2]'.replace(*"+:")
```
]
|
[Question]
[
# What is the *Fibonacci Rectangular Prism Sequence*?
The Fibonacci Rectangular Prism Sequence is a sequence derived from the Fibonacci sequence starting with one. The first 3 numbers of the Fibonacci sequence (starting with one) are 1, 1, and 2, so the first number of the Fibonacci Rectangular Prism Sequence is the square of the diagonal length of a rectangular prism (X in [this picture](https://i.stack.imgur.com/Y3nrm.png)) with the dimensions 1x1x2. The next number of the Fibonacci Rectangular Prism Sequence is the square of the diagonal length of a prism with the dimensions 1x2x3, followed by the square of the diagonal of 2x3x5, and so on. The formula for each number in the series would be [A127546](https://oeis.org/A127546):
$$a(n)={F\_n}^2 + {F\_{n+1}}^2 + {F\_{n+2}}^2$$
where \$F\_n\$ is the nth number of the Fibonacci sequence. The convention is that \$F\_0\$ is 0, and \$F\_1\$ is 1. (See [A000045](https://oeis.org/A000045) for more information about the Fibonacci sequence.)
# Your Challenge:
Write code that takes an index \$n\$ and outputs the \$n\$'th element of the sequence. It’s [code-golf](/questions/tagged/code-golf "show questions tagged 'code-golf'"), so the shortest code wins!
# Test cases:
```
0 ==> 2
1 ==> 6
2 ==> 14
3 ==> 38
4 ==> 98
5 ==> 258
6 ==> 674
7 ==> 1766
8 ==> 4622
9 ==> 12102
10 ==> 31682
```
# Leaderboard:
```
var QUESTION_ID=214423,OVERRIDE_USER=98932,ANSWER_FILTER="!t)IWYnsLAZle2tQ3KqrVveCRJfxcRLe",COMMENT_FILTER="!)Q2B_A2kjfAiU78X(md6BoYk",answers=[],answers_hash,answer_ids,answer_page=1,more_answers=!0,comment_page;function answersUrl(d){return"https://api.stackexchange.com/2.2/questions/"+QUESTION_ID+"/answers?page="+d+"&pagesize=100&order=desc&sort=creation&site=codegolf&filter="+ANSWER_FILTER}function commentUrl(d,e){return"https://api.stackexchange.com/2.2/answers/"+e.join(";")+"/comments?page="+d+"&pagesize=100&order=desc&sort=creation&site=codegolf&filter="+COMMENT_FILTER}function getAnswers(){jQuery.ajax({url:answersUrl(answer_page++),method:"get",dataType:"jsonp",crossDomain:!0,success:function(d){answers.push.apply(answers,d.items),answers_hash=[],answer_ids=[],d.items.forEach(function(e){e.comments=[];var f=+e.share_link.match(/\d+/);answer_ids.push(f),answers_hash[f]=e}),d.has_more||(more_answers=!1),comment_page=1,getComments()}})}function getComments(){jQuery.ajax({url:commentUrl(comment_page++,answer_ids),method:"get",dataType:"jsonp",crossDomain:!0,success:function(d){d.items.forEach(function(e){e.owner.user_id===OVERRIDE_USER&&answers_hash[e.post_id].comments.push(e)}),d.has_more?getComments():more_answers?getAnswers():process()}})}getAnswers();var SCORE_REG=function(){var d=String.raw`h\d`,e=String.raw`\-?\d+\.?\d*`,f=String.raw`[^\n<>]*`,g=String.raw`<s>${f}</s>|<strike>${f}</strike>|<del>${f}</del>`,h=String.raw`[^\n\d<>]*`,j=String.raw`<[^\n<>]+>`;return new RegExp(String.raw`<${d}>`+String.raw`\s*([^\n,]*[^\s,]),.*?`+String.raw`(${e})`+String.raw`(?=`+String.raw`${h}`+String.raw`(?:(?:${g}|${j})${h})*`+String.raw`</${d}>`+String.raw`)`)}(),OVERRIDE_REG=/^Override\s*header:\s*/i;function getAuthorName(d){return d.owner.display_name}function process(){var d=[];answers.forEach(function(n){var o=n.body;n.comments.forEach(function(q){OVERRIDE_REG.test(q.body)&&(o="<h1>"+q.body.replace(OVERRIDE_REG,"")+"</h1>")});var p=o.match(SCORE_REG);p&&d.push({user:getAuthorName(n),size:+p[2],language:p[1],link:n.share_link})}),d.sort(function(n,o){var p=n.size,q=o.size;return p-q});var e={},f=1,g=null,h=1;d.forEach(function(n){n.size!=g&&(h=f),g=n.size,++f;var o=jQuery("#answer-template").html();o=o.replace("{{PLACE}}",h+".").replace("{{NAME}}",n.user).replace("{{LANGUAGE}}",n.language).replace("{{SIZE}}",n.size).replace("{{LINK}}",n.link),o=jQuery(o),jQuery("#answers").append(o);var p=n.language;p=jQuery("<i>"+n.language+"</i>").text().toLowerCase(),e[p]=e[p]||{lang:n.language,user:n.user,size:n.size,link:n.link,uniq:p}});var j=[];for(var k in e)e.hasOwnProperty(k)&&j.push(e[k]);j.sort(function(n,o){return n.uniq>o.uniq?1:n.uniq<o.uniq?-1:0});for(var l=0;l<j.length;++l){var m=jQuery("#language-template").html(),k=j[l];m=m.replace("{{LANGUAGE}}",k.lang).replace("{{NAME}}",k.user).replace("{{SIZE}}",k.size).replace("{{LINK}}",k.link),m=jQuery(m),jQuery("#languages").append(m)}}
```
```
body{text-align:left!important}#answer-list{padding:10px;float:left}#language-list{padding:10px;float:left}table thead{font-weight:700}table td{padding:5px}
```
```
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <link rel="stylesheet" type="text/css" href="https://cdn.sstatic.net/Sites/codegolf/primary.css?v=f52df912b654"> <div id="language-list"> <h2>Winners by Language</h2> <table class="language-list"> <thead> <tr><td>Language</td><td>User</td><td>Score</td></tr></thead> <tbody id="languages"> </tbody> </table> </div><div id="answer-list"> <h2>Leaderboard</h2> <table class="answer-list"> <thead> <tr><td></td><td>Author</td><td>Language</td><td>Size</td></tr></thead> <tbody id="answers"> </tbody> </table> </div><table style="display: none"> <tbody id="answer-template"> <tr><td>{{PLACE}}</td><td>{{NAME}}</td><td>{{LANGUAGE}}</td><td><a href="{{LINK}}">{{SIZE}}</a></td></tr></tbody> </table> <table style="display: none"> <tbody id="language-template"> <tr><td>{{LANGUAGE}}</td><td>{{NAME}}</td><td><a href="{{LINK}}">{{SIZE}}</a></td></tr></tbody> </table>
```
[Answer]
# [MathGolf](https://github.com/maxbergmark/mathgolf), 6 bytes
This is not really interesting (but it is the shortest answer).
```
3r+f²Σ
```
## Explanation
3, range, +, Fibonacci, square, sum.
[Try it online!](https://tio.run/##y00syUjPz0n7/9@4SDvt0KZzi///NzQy/g8A "MathGolf – Try It Online")
[Answer]
# [Python 2](https://docs.python.org/2/), 33 bytes
```
lambda n:((3-5**.5)/2)**~n//5*4+2
```
[Try it online!](https://tio.run/##K6gsycjPM/qfZhvzPycxNyklUSHPSkPDWNdUS0vPVFPfSFNLqy5PX99Uy0QbqCq/SCFTITNPoSgxLz1Vw9BA04pLQaGgKDOvRCNNI1NT878RAA "Python 2 – Try It Online")
**34 bytes**
```
lambda n:(5**.5/2+1.5)**-~n//5*4+2
```
[Try it online!](https://tio.run/##K6gsycjPM/qfZhvzPycxNyklUSHPSsNUS0vPVN9I21DPVFNLS7cuT1/fVMtEG6gsv0ghUyEzT6EoMS89VcPQQNOKS0GhoCgzr0QjTSNTU/O/EQA "Python 2 – Try It Online")
Outputs floats. Based on the [closed form by Lynn](https://codegolf.stackexchange.com/questions/214423/the-fibonacci-rectangular-prism-sequence#comment501891_214423), simplified to:
$$ f(n) = 4 \left \lfloor{\frac{\phi^{2n+2}}{5}}\right \rfloor + 2.$$
We further convert \$\phi^{2n+2} = (\phi^2)^{n+1} = (\phi+1)^{n+1}\$, writing \$\phi+1\$ as \$\frac{\sqrt{5}}{2}+1.5\$. We could also try writing it out as \$2.61803398875...\$ to some precision. The limited precision of floats will cause deviations for large enough outputs for any version of this solution.
**44 bytes**
```
f=lambda n:2*(n<1)or(f(n-1)+f(n-2))*2-f(n-3)
```
[Try it online!](https://tio.run/##FcsxDoAgDEDR3VN0pBgSqRvRw2AUbaKFEBZPX2X6b/nlbVcWUk3rHZ9tjyCBrJHFY64mGXEexx5CtOS6ZtSUKzCwQI1yHsZPGAaAUlna/zCi0gc "Python 2 – Try It Online")
An alternative recursive formula that gets rid of the \$(-1)^n\$ term by recursing one step further back.
$$ f(n) = 2f(n-1) + 2f(n-2)-f(n-3)$$
where \$f(n)=2\$ for \$n<1\$.
**44 bytes**
```
f=lambda n:2*(n<1)or 3*f(n-1)-f(n-2)+n%2*4-2
```
[Try it online!](https://tio.run/##FckxCoAwDADA3VdkEZJKwUanoo@paLSgaSkuvr7qdMPl5z6Scq0yn@Fa1gDq2aBOjlKBwQiqdWR/mDpt2YyWq3wXISqUoPuGriffAOQS9UbBSFT5BQ "Python 2 – Try It Online")
Uses a recursive formula, with base case \$f(-1)=f(0)=2\$. Writes `n%2*4-2` for `-2*(-1)**n`.
[Answer]
# JavaScript (ES6), 34 bytes
*Saved 2 bytes thanks to [@user](https://codegolf.stackexchange.com/users/95792/user) and 3 more bytes thanks to [@xnor](https://codegolf.stackexchange.com/users/20260/xnor)*
The following recursive formula is given for \$n>3\$ on [OEIS](https://oeis.org/A127546), but it actually works for \$n>1\$:
$$a(n) = 3a(n-1)-a(n-2)-2(-1)^n$$
As noticed by xnor, we can also make it work for \$a(1)\$ by defining \$a(-1)=a(0)=2\$.
```
f=n=>n<1?2:3*f(n-1)-f(n-2)+n%2*4-2
```
[Try it online!](https://tio.run/##FcxBDoIwEEbhPaeYBSQdmhpbXQnFq9AgNRryjwHjpunZK6y@zct7h1/YpvX1@RrIYy4levgBvb2726WNCsayOXCs0bj2alyJsiqQp3NHoJ7sodZMqSKaBJss82mRpxqDqhMy72md9gfnkbsqlz8 "JavaScript (Node.js) – Try It Online")
[Answer]
# [05AB1E](https://github.com/Adriandmen/05AB1E/wiki/Commands), ~~9~~ 7 [bytes](https://github.com/Adriandmen/05AB1E/wiki/Codepage)
```
2Ý+ÅfnO
```
[Try it online](https://tio.run/##yy9OTMpM/f/f6PBc7cOtaXn@//8bGgAA) or [verify all test cases](https://tio.run/##yy9OTMpM/R9ybJKfvZLCo7ZJCkr2fv@NDs/VPtyaluf/X@c/AA).
**Explanation:**
```
2Ý # Push list [0,1,2]
+ # Add each to the (implicit) input-integer: [n,n+1,n+2]
Åf # Get the Fibonacci numbers at those indices: [F(n),F(n+1),F(n+2)]
n # Square each: [F(n)²,F(n+1)²,F(n+2)²]
O # Sum them together: F(n)²+F(n+1)²+F(n+2)²
# (after which the result is output implicitly)
```
---
---
For funsies and since I was curious, here are the ports of the approaches used in [*@Razetime*'s Husk](https://codegolf.stackexchange.com/a/214425/52210) and [*@Arnauld*'s JavaScript](https://codegolf.stackexchange.com/a/214424/52210) answers:
**10 [bytes](https://github.com/Adriandmen/05AB1E/wiki/Codepage):**
```
∞<Åfü3nOIè
```
[Try it online](https://tio.run/##yy9OTMpM/f//Ucc8m8OtaYf3GOf5ex5e8f@/oQEA) or [verify all test cases](https://tio.run/##AScA2P9vc2FiaWX/VMaSTj8iIOKGkiAiP//iiJ48w4Vmw7wzbk9Ow6j/LP8).
**11 [bytes](https://github.com/Adriandmen/05AB1E/wiki/Codepage)**
```
₂Sλè3*₂®Nm·Æ
```
[Try it online](https://tio.run/##yy9OTMpM/f//UVNT8Lndh1cYawFZh9b55R7afrjt/39DAwA) or [verify all test cases](https://tio.run/##yy9OTMpM/R9ybJKfvZLCo7ZJCkr2fv8fNTUFn9t9eIWxFpB1aJ1f7qHth9v@1@r8BwA).
**Explanation:**
```
∞ # Push an infinite positive list: [1,2,3,4,5,...]
< # Decrease each by 1 to let it start at 0: [0,1,2,3,4,...]
Åf # Get the 0-based Fibonacci number: [0,1,1,2,3,...]
ü3 # Create overlapping triplets: [[0,1,1],[1,1,2],[1,2,3],[2,3,5],[3,5,8],..]
n # Square each inner value: [[0,1,1],[1,1,4],[1,4,9],[4,9,25],[9,25,64],...]
O # Sum each: [2,6,14,38,98,...]
Iè # Index the input-integer into the list
# (after which the result is output implicitly)
λ # Start a recursive environment
è # to output the 0-based (implicit) input'th value implicitly afterwards,
₂S # starting at a(0)=2,a(1)=6
# (`₂S`: push builtin 26, convert it to a list of digits)
# And we calculate every following a(n) as follows:
# (implicitly push the value of a(n-1)
3* # Multiply it by 3: 3*a(n-1)
₂ # Push a(n-2)
® # Push -1
Nm # to the power of the current n: (-1)**n
· # Double it: 2*(-1)**n
Æ # Reduce the three values on the stack by subtracting:
# 3*a(n-1)-a(n-2)-2*(-1)**n
```
[Answer]
# [Husk](https://github.com/barbuz/Husk), 8 bytes
```
ṁ□↑3↓Θİf
```
[Try it online!](https://tio.run/##ASIA3f9odXNr/23igoHFgDEx/@G5geKWoeKGkTPihpPOmMSwZv// "Husk – Try It Online")
```
ṁ□↑3↓Θİf
Θİf # fibonacci sequence starting with zero
↓ # remove first n elements (n = input)
↑3 # get first 3 elements of what's left
ṁ□ # square each of them & sum
```
[Answer]
# [Haskell](https://www.haskell.org/), 34 bytes
```
f=2:scanl(+)2f
a n=f!!n^2-2*(-1)^n
```
[Try it online!](https://tio.run/##BcFBCoAgEADAe69Yb1oousfAl0TCEkmSLpL9f515aLx3rSI54j4u4qo3g3kh4JiV4oQWV22DSSyNCkOE/hX@QTfqQHB454I/jUw "Haskell – Try It Online")
Uses the \$a(n)=4F^2\_{n+1}-2(-1)^n\$ formula.
# [Haskell](https://www.haskell.org/), 34 bytes
```
(0!1!!)
a!b|c<-a+b=a^2+b^2+c^2:b!c
```
[Try it online!](https://tio.run/##DcM7CoAwEAXA3lPsdooo0VLMSfzAy@IPowRj6dldHZgVcZ@8V9heU8MVc5aA3SNtgdxZjHXu/jLWjWPRA9tJlsK1nTelBwKBOlOWlRkyfWX2WKIWEsIH "Haskell – Try It Online")
Uses the \$a(n)=F\_n^2+F\_{n+1}^2+F\_{n+2}^2\$ formula.
[Answer]
# [J](http://jsoftware.com/), 20 bytes
*-3 thanks to FrownyFrog*
```
1#.2^~2&(+/@$,$)&1 1
```
[Try it online!](https://tio.run/##y/qvpKeepmBrpaCuoKNgoGAFxLp6Cs5BPm7/DZX1jOLqjNQ0tPUdVHRUNNUMFQz/a3JxpSZn5CukKRkoZOopGBr8BwA "J – Try It Online")
* `2& f &1 1` Execute f `n` times with `2` as left argument and `1 1` as right argument.
* `+/@$,$` Sum first `2` elements of the list, and prepend it to itself
* `1#.2^~` Square and sum.
[Answer]
# [Husk](https://github.com/barbuz/Husk), 9 bytes
```
!Ẋoṁ□ėΘİf
```
[Try it online!](https://tio.run/##ARwA4/9odXNr//8h4bqKb@G5geKWocSXzpjEsGb///85 "Husk – Try It Online")
1-indexed.
## Explanation
```
!Ẋoṁ□ėΘİf
İf infinite fibonacci sequence
Θ prepend a 0
Ẋo map the following over triplets of values
ė make list of 3 elements
ṁ□ sum their squares
! index into this list using input
```
[Answer]
# [K (ngn/k)](https://bitbucket.org/ngn/k), ~~27~~ 25 bytes
```
{+/t*t:x({x,+/x}1_)/|2\6}
```
[Try it online!](https://tio.run/##y9bNS8/7/z/Nqlpbv0SrxKpCo7pCR1u/otYwXlO/xijGrPZ/mrqioeF/AA "K (ngn/k) – Try It Online")
```
{ } \ function with parameter x
2\6 \ 6 to binary -? 1 1 0
| \ reverse -> 0 1 1
x( )/ \ repeat the function in () n times
1_ \ drop the first number and
{ } \ apply this function to the remaining list
+/x \ sum
x, \ append to the list
t: \ assign to t
t* \ square
+/ \ sum
```
I managed to shave off 2 bytes after seeing @[xash's J solution](https://codegolf.stackexchange.com/a/214437/75681) - please upvote their solution!
[Answer]
# [R](https://www.r-project.org/), 37 35 31 bytes
Nothing original, given the previous answers:
```
(((3+5^.5)/2)^(scan()+1)/5)%/%1*4+2
```
was 35 bytes, but Guiseppe got rid of four parentheses
```
((3+5^.5)/2)^(scan()+1)%/%5*4+2
```
[Try it online!](https://tio.run/##K/r/X0NDw1jbNE7PVFPfSDNOozg5MU9DU9tQU99UU1Vf1VDLRNvovwmXoSGXoeV/AA "R – Try It Online")
[Answer]
# [Charcoal](https://github.com/somebody1234/Charcoal), ~~24~~ 23 bytes
```
F²⊞υ²FN⊞υ⁻⊗Σ…⮌υ²§υ±³I⊟υ
```
[Try it online!](https://tio.run/##RY2xDsIgFEV3v4LxkehS4@RkcOlgQ/QLKH1KEwrNg9fo1yO4uNzh3Jx7rTNko/GlPCMJ6KTQnBzwXnTyvPuxPqycB15GJJD//jYHTnCNPHqc4MELqI/1qFxc4Y4bUkJg2XZkzUvuw4TvJg74MhnhWHm90DSHDMqkDLqa3GApp3LY/Bc "Charcoal – Try It Online") Link is to verbose version of code Uses @xnor's recurrence relation. Explanation:
```
F²⊞υ²
```
Start with the `-1`th and `0`th terms of the sequence.
```
FN
```
Generate as many additional terms as required.
```
⊞υ⁻⊗Σ…⮌υ²§υ±³
```
Push twice the sum of the last two terms minus the previous. (On the first loop, there aren't enough terms, but Charcoal indexes cyclically, so it still finds `2` as desired. I could have just started with 3 terms; it makes no difference.)
```
I⊟υ
```
Output the final term, which is the desired result.
Alternative 23-byte solution generates the Fibonacci series:
```
⊞υ⁰F⁺²N⊞υ⊕↨…υι¹IΣXE³⊟υ²
```
[Try it online!](https://tio.run/##Ncw9DgIhEEDhfk9BOZNgomustpNqizUkngARwyb8BRiNp0corN@Xp63KOirXmqRigTg74jK9YmYgHRWYOVtDonoj/zAZEJH94Rp0Nt6Eap5wVcWA@GpnhI1p1B05O3W@TDLvoYJQpcKdPMj46aNNJThzJgfGTmcctrVLO7zdDw "Charcoal – Try It Online") Link is to verbose version of code. Explanation:
```
⊞υ⁰
```
Start with the first term of the sequence.
```
F⁺²N
```
Extend the sequence until we have all the necessary terms.
```
⊞υ⊕↨…υι¹
```
Each term is one more than the sum of all the terms except the previous. I use base conversion from base 1 to avoid the edge case of the empty list.
```
IΣXE³⊟υ²
```
Pop the last three terms, square them, and print the sum.
[Answer]
# [Jelly](https://github.com/DennisMitchell/jelly), 8 bytes
```
3Ḷ+µÆḞ²S
```
[Try it online!](https://tio.run/##ARoA5f9qZWxsef//M@G4tivCtcOG4biewrJT////NQ "Jelly – Try It Online")
I feel like it's possible to save a byte here, but I'm not sure how. (EDIT: Apparently the answer was to use 05AB1E; [@Kevin Cruijssen's answer](https://codegolf.stackexchange.com/a/214426), which was written in parallel with this one, uses the same builtins in the same order but 05AB1E happens to parse it the way we'd want.)
You probably shouldn't upvote this answer; it's just a direct translation of the specification and contains no clever golfing tricks. I was just interested in how long it would come out to in Jelly.
## Explanation
```
3Ḷ+µÆḞ²S
3Ḷ [0,1,2]
+ add {the input} to {each elemeent}
µ (fix for parser ambiguity)
ÆḞ take the Fibonacci number whose index is {each element}
² square {each element}
S sum the resulting list {and output it}
```
[Answer]
# [Python 2](https://docs.python.org/2/), 47 bytes
I tried a few other methods, like the recurrence realtion [used by Arnauld](https://codegolf.stackexchange.com/a/214424/64121) and the formaula provided by [Emeric Deutsch](https://oeis.org/wiki/User:Emeric_Deutsch) on the OEIS page, but a literal implemention seems to be the shortest.
```
f=lambda n,a=0,b=1:n+2and(n<2)*b*b+f(n-1,b,a+b)
```
[Try it online!](https://tio.run/##BcExDoAgDAXQ3VN0bAUTYTRymDaIkujXEBdPj@8933vciL2XdOplWQle0@wthQUuKjJjjTLaaK4wpuDNqzPp5W5UqYKaYt84zLIMRE@reLlwFenxBw "Python 2 – Try It Online")
[Answer]
# [Japt](https://github.com/ETHproductions/japt) [`-x`](https://codegolf.meta.stackexchange.com/a/14339/), 9 [bytes](https://en.wikipedia.org/wiki/ISO/IEC_8859-1)
```
3ÆMgX+U ²
```
[Try it](https://petershaggynoble.github.io/Japt-Interpreter/?v=1.4.6&flags=LXg&code=M8ZNZ1grVSCy&input=MTA)
[Answer]
# [C (gcc)](https://gcc.gnu.org/), ~~42~~ 38 bytes
Saved 4 bytes thanks to [xnor](https://codegolf.stackexchange.com/users/20260/xnor)!!!
```
f(n){n=n<1?2:3*f(n-1)-f(n-2)+n%2*4-2;}
```
[Try it online!](https://tio.run/##VZDNboMwDIDvPIWFhJRAojWBpu3SbIdpTwEcKggbh6UV6QEN8ezMMNqtkWzHn39ku@IfVTVNDXF0cMYdxat8TmN0uaB8NpImLpJxxqUep9Zd4evUOkKDIQB8M7D9xVZXW@elGSQDxUBkDNI9gwOK3KJSOyRipzCWKYlJQooNmlSovRz10qr6PHUxdHkJBoaw6N9l0R/eULYhg/9@Gq4VzbkDMk/Qutr2WLbR6/cIvv2254bcZqNPK4jvREOSLNkUfne57eOw0xLQD9gjns/0SC3S@wGWqvIv4dJhSkPCqAb@AqgjX7iQOeZZl3tjbLl2G4Nx@gE "C (gcc) – Try It Online")
Uses [Arnauld](https://codegolf.stackexchange.com/users/58563/arnauld)'s formula from his [JavaScript answer](https://codegolf.stackexchange.com/a/214424/9481).
[Answer]
# [Arn](https://github.com/ZippyMagician/Arn), [16 bytes](https://github.com/ZippyMagician/Arn/wiki/Carn)
```
╗¤û°œJ–¬▀ôƒìÚ„")
```
[Try it!](https://zippymagician.github.io/Arn?code=Mis0Kjp2KHBoaV4oKjIrMikvNQ==&input=MAoxCjIKMwo0CjUKNgo3CjgKOQ==&flags=)
# Explained
Unpacked: `2+4*:v(phi^(*2+2)/5`
Uses the same closed-form variant [@xnor](https://codegolf.stackexchange.com/users/20260/xnor) uses.
```
2
+ Plus
4
* Times
:v Floor of
(
phi The golden ratio
^ Exponentiated by
(
_ Variable ≡ STDIN; implied
*
2
+
2
)
/ Divided by
5
) Implied
```
Also for fun:
# [Arn](https://github.com/ZippyMagician/Arn) `-l`, [22 bytes](https://github.com/ZippyMagician/Arn/wiki/Carn)
```
ñf©¶─[•«DWLšií▬Xy®┐Vÿ"
```
[Try it!](https://zippymagician.github.io/Arn?code=djoxWzIgMnsqMy0gLTIqXzFeKyt2fS0+KzI=&input=MAoxCjIKMwo0CjUKNgo3CjgKOQ==&flags=bA==)
# Explained
Unpacked: `v:1[2 2{*3- -2*_1^++v}->+2`
Sequence definition, the `-l` flag returns the last entry
[Answer]
# Scala, 53 bytes
```
def f(n:Int):Int=if(n>0)3*f(n-1)+n%2*4-2-f(n-2)else 2
```
[Try it online](https://scastie.scala-lang.org/S6yAEfstQhm7ADhPeGG5aQ)
This one uses the method used in [@Arnauld's answer](https://codegolf.stackexchange.com/a/214424/95792).
---
# Dotty, 84 bytes
```
n=>{def f:Stream[Int]=0#::1#::f.zip(f.tail).map(_+_);f.slice(n,n+3).map(x=>x*x).sum}
```
[Try it online](https://scastie.scala-lang.org/Oy4an6b0RCuQp6yUQS2APA)
[Answer]
# [Retina](https://github.com/m-ender/retina/wiki/The-Language), 39 bytes
```
K`_¶_
"$+"+L$`(_+¶)(_+)
$2$1$&
%`_
$=
_
```
[Try it online!](https://tio.run/##K0otycxLNPz/3zsh/tC2eC4lFW0lbR@VBI147UPbNIGkJpeKkYqhihqXakI8l4otV/z//6YA "Retina – Try It Online") No test suite because of the way the program uses history. Explanation:
```
K`_¶_
```
Replace the input with the first terms (in unary) of the Fibonacci sequence.
```
"$+"+`
```
Repeat `n` times...
```
L$`(_+¶)(_+)
$2$1$&
```
... sum the first two terms and drop terms after the third.
```
%`_
$=
```
Square each term separately.
```
_
```
Take the sum and convert to decimal.
[Answer]
# [Perl 5](https://www.perl.org/), 51 bytes
```
sub a{my$n=pop;(2)[$n]||3*a($n-1)-a($n-2)+$n%2*4-2}
```
[Try it online!](https://tio.run/##ZY9Ra4MwFIXf/RWXkkHSKdSo0TZY@rqHve1NpLgtK8JMgolj0va3uyYbDNK8hHzn5J57tBg/i0UqMHbs3yxfzPQK3XmYkay10hxT0iDZXi7ZusNIJilJ/E3JI5IPdJ0n9LpMRsCLMHa3e1aj4NEww8He3jWGZgP1HmgbR/B/mtRBFkDqYJoHNHM0qwKaO7oNaeGzihAzn1aGk0ufV7Jwj8rxnNFw6a3303Rz18Z3zFJW0Zbw6EON2NcnZ28bZox6qWMkvjWpD@jI/zCgk7J151XyC3uDHfTeePUk9WTByZAke2@HLwNOXN0@XKN3JcXRRfXyxJcf "Perl 5 – Try It Online")
Just a translation of Arnaulds Javascript answer.
]
|
[Question]
[
Inspiring myself on [a recent challenge](https://codegolf.stackexchange.com/q/200950/75323), we ought to compute a sequence that is very close to [A160242](http://oeis.org/A160242).
# Task
Your task is to generate the sequence \$ \{s\_i\}\_{i=0}^\infty \$:
`1, 2, 1, 1, 2, 2, 2, 1, 1, 2, 2, 2, 2, 2, 1, 1, 2, 2, 2, 2, 2, 2, 2, 1, ...`
Which is more easily understandable in this format:
```
1 2 1
1 2 2 2 1
1 2 2 2 2 2 1
1 2 2 2 2 2 2 2 1 ...
```
Another way to think of it is, this sequence is the concatenation of blocks \$b\_i, 0 \leq i\$ where block \$b\_i\$ is a `1`, followed by \$2i + 1\$ `2`s, followed by another `1`.
# Input
If your program takes input, the input is a non-negative integer `n`, telling you how far you should go in computing the sequence.
The sequence can
* be 0-indexed, so that \$s\_0 = 1, s\_1 = 2, s\_2 = 1, ... \$
* be 1-indexed, so that \$s\_1 = 1, s\_2 = 2, s\_3 = 1, ... \$
# Output
Your code may do one of the following:
* indefinitely print the sequence
* print/return the term `n` as given by the input
* print/return all the terms up to the term `n` as given by the input
# Test cases
(the test cases are 0-indexed)
```
0 -> 1
1 -> 2
2 -> 1
3 -> 1
4 -> 2
5 -> 2
6 -> 2
7 -> 1
8 -> 1
9 -> 2
10 -> 2
11 -> 2
12 -> 2
13 -> 2
14 -> 1
15 -> 1
16 -> 2
17 -> 2
18 -> 2
19 -> 2
20 -> 2
21 -> 2
22 -> 2
23 -> 1
24 -> 1
25 -> 2
26 -> 2
27 -> 2
28 -> 2
29 -> 2
```
---
This is [code-golf](/questions/tagged/code-golf "show questions tagged 'code-golf'") so the shortest submission in bytes, wins! If you liked this challenge, consider upvoting it... And happy golfing!
[Answer]
# JavaScript (ES7), ~~25 24~~ 23 bytes
Returns the \$n\$-th term, 1-indexed.
```
n=>n>(++n**.5|0)**2?2:1
```
[Try it online!](https://tio.run/##BcFRCoMwDADQq@QzaTVYhz9CK55jjFE6FUXTUocg7O7de5u//Bnymr61xM9UZlvEOnGotSjF3a8hpdqh7U0JUc64T7zHBZ/MPObsb3w09OLDJ8R3BUJgHcwooMEQUfkD "JavaScript (Node.js) – Try It Online")
### How?
We have \$a(n)=2\$ iff the difference between \$n+1\$ and the previous square is greater than \$1\$:
$$n+1-\left\lfloor \sqrt{n+1}\right\rfloor^2>1$$
which boils down to:
$$n>\left\lfloor \sqrt{n+1}\right\rfloor^2$$
[Answer]
# [Jelly](https://github.com/DennisMitchell/jelly), 6 bytes
```
,‘ƲE‘
```
[Try it online!](https://tio.run/##y0rNyan8/1/nUcOMw22HNrkC6f9GBkGH2x81rfkPAA "Jelly – Try It Online")
# Explanation
```
,‘ƲE‘ Main Link: N
, pair with
‘ increment [N, N + 1]
Ʋ is it a square? [issq(N), issq(N + 1)]
E are both equal (N and N+1 cannot both be square, so if one is square, it will return 0, and if both are not square, it will return 1)
‘ increment (if N or N+1 is square, return 1; otherwise, return 2)
(implicit input)
```
[Answer]
# [Python 2](https://docs.python.org/2/), 24 bytes
```
lambda n:2-(-n%n**.5<.5)
```
[Try it online!](https://tio.run/##K6gsycjPM/qfbhvzPycxNyklUSHPykhXQzdPNU9LS8/URs9U839afpFCnkJmnkJRYl56qoahjomBphUXZ0FRZl6JQp6OQrpGnuZ/AA "Python 2 – Try It Online")
Outputs the \$n\$'th value one-indexed.
We use an arithmetic expression to identify indices `n` that are either perfect square or one below a perfect square. To do so, we use a measure that's roughly of the distance between `n` and the next perfect square, given by `-n%n**.5`.
For squares, we have `-n%n**.5==0` because `n` is an even multiple of its square root, that is for `n=k*k`, `-(k*k)%k==0`. If `n` is one less than a perfect square, then the remainder is `<0.5`, if it's two less, it's be between `0.5` and `1`, and so on. So, the condition `-n%n**.50.5` accepts only perfect squares and numbers one less.
[Answer]
# [Python 3.8 (pre-release)](https://docs.python.org/3.8/), 31 bytes
```
i=0
while i:=100*i+121:print(i)
```
[Try it online!](https://tio.run/##K6gsycjPM7YoKPr/P9PWgKs8IzMnVSHTytbQwEArU9vQyNCqoCgzr0QjU/P/fwA "Python 3.8 (pre-release) – Try It Online")
Print the sequence infinitely, with a questionable format.
The following version output the first `n` terms of the sequence:
### [Python 3](https://docs.python.org/3/), 56 bytes
```
lambda n:"".join(f"{1:2<{-~i*2}}1"for i in range(n))[:n]
```
[Try it online!](https://tio.run/##K6gsycjPM/6fZhvzPycxNyklUSHPSklJLys/M08jTana0MrIplq3LlPLqLbWUCktv0ghUyEzT6EoMS89VSNPUzPaKi/2f0FRZl6JRpqGgaYmF4xtiMxGkTAA8v4DAA "Python 3 – Try It Online")
**Input**: Non-negative integer `n`
**Output**: the first `n` terms of the sequence, concatenated into a string.
**Explanation**
A different approach using only string formatting instead of @Arnauld's closed-form formula.
* `f"{1:2<{x}}1"` evaluates to `"122..21"` with `x-1` characters `"2"`. (The first `"1"` is left justified to a block of width `x`, with `"2"` being the fill character).
* `-~i*2` is equivalent to `(i+1)*2`
Thus `f"{1:2<{-~i*2}}1"` evaluates to the string `"122..21"` with `i*2+1` characters `"2"`.
[Answer]
# [R](https://www.r-project.org/), ~~27~~ 25 bytes
-1 byte thanks to Giuseppe
```
1+all((scan()+1:2)^.5%%1)
```
[Try it online!](https://tio.run/##K/r/31A7MSdHQ6M4OTFPQ1Pb0MpIM07PVFXVUPO/kfF/AA "R – Try It Online")
Uses the fact that \$s\_n=1\$ iff \$n+1\$ or \$n+2\$ is a perfect square.
[Answer]
# Symja, ~~38~~ 33 bytes
```
f(x_):=If(Mod(-(x^.5),1)*x<1,1,2)
```
[Y'all can try it here](https://symjaweb.appspot.com/input?i=f%28x%5f%29%3a%3dIf%28Mod%28%2d%28x%5e%2e5%29%2c1%29%2ax%3c1%2c1%2c2%29%3b%20f%2829%29)
This is just a port of xnor's (who helped me save 5 bytes) Python 2 answer in Symja. This took a while to generate, as I had to properly understand what the formula was, due to operator precedence. Anyhow, enjoy!
[Answer]
# [Python 2](https://docs.python.org/2/): 52 bytes
```
def g(n):return(2,1)[not((n+1)**.5%1and(n+2)**.5%1)]
```
[Try it online!](https://tio.run/##Lcw7CoAwEAXA2pwijbCrIiRgoVcRCyEf07zIEgtPHxUsp5nzLkeGrdX5oCOBF/HlEpAdDK/IhQi94a4bp9bscK/sL95qyKKhE7TsiJ7szItqTkko9F1c1QM)
Returns the nth term in the sequence.
Also using the fact that the nth term = 1 <=> (n+1) or (n+2) is square as Robin Ryder pointed out.
[Answer]
# [PowerShell](https://github.com/TryItOnline/TioSetup/wiki/Powershell), 23 bytes
```
for(){$i++;1;,2*$i++;1}
```
[Try it online!](https://tio.run/##K8gvTy0qzkjNyfn/Py2/SEOzWiVTW9va0FrHSAvCqv3/HwA "PowerShell – Try It Online")
Prints the sequence indefinitely.
[Answer]
# [APL (Dyalog Unicode)](https://www.dyalog.com/), 67 bytes
This answer returns the entire sequence up to the requested value.
```
f←{(⊃,/1,¨⌽¨1,¨2⍴⍨¨1+2×1-⍨⍳1+⌈⍟⍵)[⍳⍵]}
```
[Try it online!](https://tio.run/##SyzI0U2pTMzJT///P@1R24RqjUddzTr6hjqHVjzq2XtoBYhh9Kh3y6PeFUCOttHh6Ya6QPaj3s2G2o96Oh71zn/Uu1UzGsgH0rG1QEMUDLnSFIyA2BiITYDYFIgNDUAEiGUEYhmBWMYglrEpAA "APL (Dyalog Unicode) – Try It Online")
Decomposition/Explanation:
```
f← ⍝ assign the name f to
{ } ⍝ a dfn that takes a single argument
⍟⍵ ⍝ The natural logarithm of the argument,
⌈ ⍝ rounded up to the next integer,
1+ ⍝ and add 1 (giving N), then
⍳ ⍝ generate the sequence 1..N,
1-⍨ ⍝ and subtract 1 from each term (0..N-1)...
⍝ ⍨ means to swap the arguments to
⍝ - (the standard subtraction function), so
⍝ 1-⍨N is the same as N-1.
2× ⍝ ... then multiply each term in the sequence by 2,
1+ ⍝ and add 1
¨ ⍝ then take each term in the sequence, and
2⍴⍨ ⍝ generate a vector of that many 2s
⍝ ⍨ means to swap the arguments to
⍝ ⍴ the "shape" function. For simple numeric
⍝ values of A and B, A⍴B means to generate a
⍝ vector of A repeats of B.
⍝ We now have a vector of vectors of 2s.
¨ ⍝ For each of those vectors,
1, ⍝ prepend a 1, then
¨ ⍝ for each vector,
⌽ ⍝ reverse it (so that the 1 is on the 'back end'), then
1,¨ ⍝ for each (now reversed with a 1) vector, prepend a 1, and
,/ ⍝ concatenate all the vectors. For reasons I don't quite
⍝ understand, this generates an enclosed object, so
⊃ ⍝ unenclose (disclose) it into a 'real' vector, and
( ) ⍝ treat all that as an object...
[ ] ⍝ ...which can be subscripted. If the subscript is
⍝ a single integer, it will return just that item from
⍝ the array; if it's a vector, it will return all of the
⍝ requested values, in the order specified by the vector.
⍳⍵ ⍝ This subscript is a vector, of the integers 1 to the original
⍝ argument to the function, so it will generate the entire
⍝ sequence up to the ⍵th term. If I only wanted the single
⍝ term, I would omit the ⍳, which would give me only the ⍵th term.
```
FIRST GOLFING (courtesy ngn):
# [APL (Dyalog Unicode)](https://www.dyalog.com/), 65 bytes
```
f←{⍵↑(⊃,/1,¨⌽¨1,¨2⍴⍨¨1+2×1-⍨⍳1+⌈⍟⍵)}
```
[Try it online!](https://tio.run/##SyzI0U2pTMzJT///P@1R24TqR71bH7VN1HjU1ayjb6hzaMWjnr2HVoAYRo96tzzqXQHkaBsdnm6oC2Q/6t1sqP2op@NR73ygNs1aoBEKhlxpCkZAbAzEJkBsCsSGBiACxDICsYxALGMQy9gUAA "APL (Dyalog Unicode) – Try It Online")
Explanation of golfing:
```
[⍳⍵] is the same as [1 2 3 4 5 6 ... ⍵],
which is the first ⍵ items of the vector being subscripted.
That's the same as
⍵↑ "Take" the first ⍵ items. Savings, 2bytes.
```
SECOND GOLFING (my own discovery):
# [APL (Dyalog Unicode)](https://www.dyalog.com/), 63 bytes
```
f←{⍵↑⊃,/1,¨⌽¨1,¨2⍴⍨¨1+2×1-⍨⍳1+⌈⍟⍵}
```
[Try it online!](https://tio.run/##SyzI0U2pTMzJT///P@1R24TqR71bH7VNfNTVrKNvqHNoxaOevYdWgBhGj3q3POpdAeRoGx2ebqgLZD/q3Wyo/ain41HvfKCuWqABCoZcaQpGQGwMxCZAbArEhgYgAsQyArGMQCxjEMvYFAA "APL (Dyalog Unicode) – Try It Online")
Explanation of golfing: The expression that was formerly subscripted does not need to be parenthesized if using `⍵↑` instead of `[⍳⍵]`. Savings, 2bytes.
[Answer]
# [GolfScript](http://www.golfscript.com/golfscript/), 16 bytes
Port of Surculose Sputum's Python answer.
```
0{100*121+.p.}do
```
[Try it online!](https://tio.run/##S8/PSStOLsosKPn/36Da0MBAy9DIUFuvQK82Jf//fwA "GolfScript – Try It Online")
[Answer]
# [Perl 6](https://github.com/nxadm/rakudo-pkg), ~~28~~ 27 bytes
```
{flat (1,2,2 xx$++*2,1)xx*}
```
[Try it online!](https://tio.run/##K0gtyjH7n1upoJamYPu/Oi0nsURBw1DHSMdIoaJCRVtby0jHULOiQqv2f3FipUKahmZ0nJFB7H8A "Perl 6 – Try It Online")
Anonymous codeblock returning a lazy infinite list. I wish I could do `2 xx++$++` or some combination of it, but i can't figure it out.
[Answer]
# [Python 3](https://docs.python.org/3/), 37 bytes
```
i=1
while 1:print('1'+'2'*i+'1');i+=2
```
[Try it online!](https://tio.run/##K6gsycjPM/7/P9PWkKs8IzMnVcHQqqAoM69EQ91QXVvdSF0rUxvI0rTO1LY1@v8fAA "Python 3 – Try It Online")
[Answer]
# [Husk](https://github.com/barbuz/Husk), ~~14 12~~ 10 bytes
```
ṁ`Jḋ3MRİ12
```
[Try it online!](https://tio.run/##yygtzv7//@HOxgSvhzu6jX2DjmwwNPr/HwA "Husk – Try It Online")
Infinite list.
-1 byte from Dominic Van Essen.
-2 bytes from Zgarb using voodoo magic.
[Answer]
# [Wolfram Language (Mathematica)](https://www.wolfram.com/wolframscript/), 42 bytes
```
If[#==1||(d=NumberQ@*Sqrt)@#||d[#+1],1,2]&
```
returns 1 if n=1 or n is a perfect square or n+1 is a perfect square
[Try it online!](https://tio.run/##y00syUjNTSzJTE78n2773zMtWtnW1rCmRiPF1q80Nym1KNBBK7iwqETTQbmmJiVaWdswVsdQxyhW7X9AUWZeiYJDerSRSSwXgmMZ@/8/AA "Wolfram Language (Mathematica) – Try It Online")
[Answer]
# [05AB1E](https://github.com/Adriandmen/05AB1E/wiki/Commands), 6 [bytes](https://github.com/Adriandmen/05AB1E/wiki/Codepage)
```
>‚ŲË>
```
Port of [*@HyperNeutrino*'s Jelly answer](https://codegolf.stackexchange.com/a/200991/52210), so make sure to upvote him!
Outputs the result for the 1-based input \$n\$.
[Try it online](https://tio.run/##yy9OTMpM/f/f7lHDrMOthzYd7rb7/98cAA) or [verify all the first \$n\$ outputs](https://tio.run/##yy9OTMpM/e/qd3iCvZLCo7ZJCkr2/@0eNcw63Hpo0@Fuu/86/w0NDAA).
Printing the infinite sequence is **~~9~~ 8 [bytes](https://github.com/Adriandmen/05AB1E/wiki/codepage)** (based on the 6-byter above):
```
∞ü‚Ų€Ë>
```
[Try it online.](https://tio.run/##ARwA4/9vc2FiaWX//@KInsO84oCaw4XCsuKCrMOLPv//)
Previous **9 [bytes](https://github.com/Adriandmen/05AB1E/wiki/codepage)** variations for the infinite sequence:
* `Y∞иXδš€û˜`: [Try it online.](https://tio.run/##ARwA4/9vc2FiaWX//1niiJ7QuFjOtMWh4oKsw7vLnP//)
* `ÅÉÅ2Xδ.ø˜`: [Try it online.](https://tio.run/##yy9OTMpM/f//cOvhzsOtRhHntugd3nF6zv//AA)
**Explanation:**
```
> # Increase the (implicit) input-integer by 1
‚ # Pair it with the (implicit) input-integer: [input, input+1]
Ų # Check for both whether they're a square (which will be either both falsey,
# or just one of the two is truthy)
Ë # Check if both are equal (so both falsey) (1 if truhy; 0 if falsey)
> # And increase that by 1 (2 if truthy; 1 if falsey)
# (after which the result is output implicitly)
∞ # Push an infinite positive list: [1,2,3,...]
ü‚ # Pair each overlapping pair together: [[1,2],[2,3],[3,4],...]
Ų # Check for each whether it's a square
€Ë # Check for each pair whether they're equal
> # Increase it by 1
# (after which it is output implicitly as result)
∞ # Push an infinite positive list: [1,2,3,...]
Y и # Repeat a 2 that many times as list: [[2],[2,2],[2,2,2],...]
δ # For each inner list:
X š # Prepend a 1: [[1,2],[1,2,2],[1,2,2,2],...]
€ # For each inner list:
û # Palindromize it: [[1,2,1],[1,2,2,2,1],[1,2,2,2,2,2,1],...]
˜ # Flatten the list of lists: [1,2,1,1,2,2,2,1,1,2,2,2,2,2,1,...]
# (after which it is output implicitly as result)
ÅÉ # Push all odd numbers equal to or less than the given argument,
# which will be an infinite sequence without argument: [1,3,5,...]
Å2 # Create for each value a list with that many 2s: [[2],[2,2,2],[2,2,2,2,2],...]
δ # For each inner list:
X .ø # Surround it with 1s: [[1,2,1],[1,2,2,2,1],[1,2,2,2,2,2,1],...]
˜ # Flatten the list of lists: [1,2,1,1,2,2,2,1,1,2,2,2,2,2,1,...]
# (after which it is output implicitly as result)
```
[Answer]
# [C (gcc)](https://gcc.gnu.org/), 56 bytes
```
i,c;main(){main(i--<-2?i=c+=2:putchar(49+(c+~i&&i+3)));}
```
*-1 byte thanks to [RGS](https://codegolf.stackexchange.com/users/75323/rgs)!*
*-8 bytes thanks to [ceilingcat](https://codegolf.stackexchange.com/users/52904/ceilingcat)!*
[Try it online!](https://tio.run/##S9ZNT07@/z9TJ9k6NzEzT0OzGkxl6ura6BrZZ9oma9saWRWUliRnJBZpmFhqayRr12WqqWVqG2tqalrX/v8PAA "C (gcc) – Try It Online")
# [C (gcc)](https://gcc.gnu.org/), 46 bytes
```
i;f(n){for(i=0;n--;)printf("%d",i=i*100+121);}
```
Stretches the rules and only works up to \$n=4\$.
[Try it online!](https://tio.run/##DclBCoAgEADAu68QIditBI1ui48JxdhDGhJdpLdvznWiPWMUYcpQsOfagIOjYi3h3bg8GcyUzMqBZ@/c4jeP9MkIfR1c4K2cUHWlhww7kvrkBw "C (gcc) – Try It Online")
[Answer]
# [Charcoal](https://github.com/somebody1234/Charcoal), 11 bytes
```
↷²1W¹«2P1D2
```
[Try it online!](https://tio.run/##S85ILErOT8z5/z8gsyy/JCgzPaNEw0jTmiugKDOvREPJUAnILs/IzElV0DDUVKjm4oRKGIEkOH1Lc0oyC5CUcrqU5hZogBjI6mr///@vW5YDAA "Charcoal – Try It Online") Link is to verbose version of code. Prints the infinite sequence. Explanation:
```
↷²
```
Change the default direction to downwards, so that everything now prints vertically by default.
```
1
```
Output `1` to the canvas.
```
W¹«
```
Loop forever.
```
2
```
Output `2` to the canvas.
```
P1
```
Output `1` to the canvas, but don't move the cursor.
```
D
```
Copy the canvas to STDOUT.
```
2
```
Replace the `1` with a `2`.
[Answer]
# [dc](https://www.gnu.org/software/bc/manual/dc-1.05/html_mono/dc.html), 18 bytes
```
?d2+vd*rvd*-d/2r-p
```
[Try it online!](https://tio.run/##S0n@/98@xUi7LEWrCIh1U/SNinQL/v83BwA "dc – Try It Online")
This uses 0-based indexing, and it computes the *n*th value in the sequence for index *n*. Input is on stdin, and output is on stdout.
It computes $$2 -K\_{\neq0}\big(\lfloor{\sqrt{n+2}}\rfloor-\lfloor{\sqrt{n}}\rfloor\big),$$ where \$K\_{\neq0}\$ is the function that maps 0 to 0, and any non-zero number to 1. (\$K\_{\neq0}\$ isn't built into dc, but you can compute it by dividing a number by itself, as long as you're careful with the stack when its argument is 0.)
There may be spurious output on stderr (due to division by 0).
Here's a [TIO link to the test suite](https://tio.run/##S0oszvifkuycn5JqG/PfPsVIuyxFqwiIdVP0jYp0C/6n5Rcp5Clk5ilUG@jpGVnWWiuk5HMpKCikJmfkK@jmKSip5CnY2ikogcRSkhV0U4EiEPOUbGxsgLJKXCn5ean/AQ).
[Answer]
# [W](https://github.com/A-ee/w), 7 [bytes](https://github.com/A-ee/w/wiki/Code-Page)
The long length doesn't really matter to me. W doesn't have a square-checking built-in.
```
φßéW!r♀
```
Uncompressed:
```
){Q1m!=r)
```
## Explanation
```
) % Increment the input. [input + 1]
{ % Pair with the input. [input, input + 1]
Q % Find the square root.[sqrt(input), sqrt(input + 1)]
1m % Modulo 1. (Find the digits after the decimal point.)
! % Are the digits 0? (True, it's a square number. Otherwise,
% it can't be a square number.)
=r % Reduce by equality.
) % Increment the result.
```
[Answer]
# [PowerShell](https://github.com/TryItOnline/TioSetup/wiki/Powershell), 55 bytes
```
$i=0;1.."$args"|%{$i+=2;write-host "1,$('2,'*$i)1," -n}
```
[Try it online!](https://tio.run/##K8gvTy0qzkjNyfn/XyXT1sDaUE9PSSWxKL1YqUa1WiVT29bIurwosyRVNyO/uERByVBHRUPdSEddSyVT01BHSUE3r/b///9mAA "PowerShell – Try It Online")
[Answer]
# [C (clang)](http://clang.llvm.org/), ~~80~~ 75 bytes
```
j,k=1;main(int a,char**b){for(a=atoi(b[1]);j<a;k+=2,j+=k);return(1<j-a)+1;}
```
[Try it online!](https://tio.run/##BcExEoMgEAXQq6QEgQJTrpzESfFl1AC6ziBWjlfP5r3o4gZeRbItwdOOxCpxe8HGL2rXTfpejqoQ0I6kptF/NOUBVEzobTahaKpzuyorP2QHbTw9IvL@xWXDeooDn@kP "C (clang) – Try It Online")
This one takes an input N at the terminal and returns the Nth value. This is zero-indexed.
# [C (gcc)](https://gcc.gnu.org/), ~~48~~ 44 bytes
```
j,k=1;f(a){for(;j<a;k+=2,j+=k);a=(1<j-a)+1;}
```
[Try it online!](https://tio.run/##LYzBDoIwEETvfMWGhKSlbQJ63NYv8bKWFLdoMeCN8OtWQN9tJm/Gm977nKMeXItBkFzCOAmMlnBQ7qSjcoNEcqK10ZBULa75SZwEpzeQ9nea6vomlwI29o7BQYNHPJ7YnhtUiv/KzmvaxCDKqgNzgaq7plIDawiCpfxN12LNHx8e1M/ZUJr5Cw "C (gcc) – Try It Online")
Same basic function here, but modified to just be a function to not take the hit from main's arg-list and converting a string to an integer. Switched over to GCC to take advantage of undefined behavior that avoids need for explicit return.
[Answer]
# [MAWP 0.0](https://esolangs.org/wiki/MAWP), 16 bytes
```
[1:![2:1A]%1:2M]
```
[Answer]
# [Python 3](https://docs.python.org/3/), ~~39~~ 34 bytes
```
i=1
while 1:print(1,*[2]*i,1);i+=2
```
Prints the sequence infinitely. Thanks to @SurculoseSputum for saving me 5 bytes.
[Try it online!](https://tio.run/##K6gsycjPM/7/P9PWkKs8IzMnVcHQqqAoM69Ew1BHK9ooVitTx1DTOlPb1uj/fwA "Python 3 – Try It Online")
[Answer]
# Brainfuck, 72
```
+++++++[>+++++++<-]>[>+>+<<-]>>+[<.>>+[>+>+<<-]>[<<.>>-]>[<<+>>-]<<<<.>]
```
Might be able to make it shorter but here's my shot. Prints indefinetly
1. Initialize first two cells with (ASCII values for) 1 and 2
2. Start a loop (looping on the 2 cell but it doesn't really matter)
1. Print the 1
2. Increase the count, and then copy the count to the next two cells
3. Use one of the counts to print the twos (decreases the count until 0, then exits loop)
4. Copy the second copy of the count back to where it was before
5. Print a final 1
[Answer]
# [C (gcc)](https://gcc.gnu.org/) -lm, ~~57~~ \$\cdots\$ ~~52~~ 50 bytes
Saved 2 bytes thanks to [ceilingcat](https://codegolf.stackexchange.com/users/52904/ceilingcat)!!!
```
t;s(n){t=sqrt(n);n=n!=t*t;};f(n){n=1+s(n)*s(n+1);}
```
[Try it online!](https://tio.run/##FYpBCsMgEEX3OcU0EHBiXFjoamJP0k0wGAaSaavuglevNZvP473vzeZ9rZmSEjyzS9@YG5E4ubk8ZioUriLO6usyttEWqdRjYVF4dhDeUbFkYGeJ5/uDtGb8xKaC6ocVzBOG9SX9BDxBUIxIXak/H/ZlS9Xsxx8 "C (gcc) – Try It Online")
Returns the nth term in the sequence.
[Answer]
# [Bash](https://www.gnu.org/software/bash/), ~~64~~ ~~61~~ 41 bytes
Saved 20 bytes thanks to [S.S. Anne](https://codegolf.stackexchange.com/users/89298/s-s-anne)!!!
```
s=2;while :;do echo 1 $s 1;s+=' 2 2';done
```
[Try it online!](https://tio.run/##S0oszvj/v9jWyLo8IzMnVcHKOiVfITU5I1/BUEGlWMHQuljbVl3BSMFIHSiRl/r/PwA "Bash – Try It Online")
Infinitely prints the sequence.
[Answer]
# [Perl 5](https://www.perl.org/), 35 + 1 (-p) = 36 bytes
```
$_=(map{(1,2,(2,2)x$_,1)}0..$_)[$_]
```
[Try it online!](https://tio.run/##K0gtyjH9/18l3lYjN7GgWsNQx0hHw0jHSLNCJV7HULPWQE9PJV4zWiU@9v9/I8t/@QUlmfl5xf91CwA "Perl 5 – Try It Online")
Reads input `n` from stdin. Simplisticly builds a list of the first at least `n` elements (actually the first `2n+3` elements), then prints the `n`th element.
# [Perl 5](https://www.perl.org/), 30 + 1 (-p) = 31 bytes
```
$_=$_+1>(($_+2)**0.5|0)**2?2:1
```
Smarter and more efficient way of doing it with Arnauld's formula from above (but adjusted to be 0-indexed instead of 1-indexed, because that's how I like it).
[Try it online!](https://tio.run/##K0gtyjH9/18l3lYlXtvQTkMDSBlpamkZ6JnWGABpI3sjK8P//40s/@UXlGTm5xX/1y0AAA "Perl 5 – Try It Online")
[Answer]
# [dirt](https://github.com/0xB0C5/dirt) (verbose mode), 17 bytes
```
"1
2
1"|1"
2
2".*
```
Run as `dirt ones_and_twos.dirt -v -i ""`
Outputs each element of the sequence on a new line.
Alternatively, if we allow new lines between some but not all elements,
## dirt (verbose mode), questionable format, 13 bytes
```
"121"|1"22".*
```
prints
```
121
12221
1222221
122222221
12222222221
1222222222221
122222222222221
12222222222222221
...
```
[Answer]
# [cQuents](https://github.com/stestoltz/cQuents), 21 bytes
```
_+(Tr$)%1)=Tr_+$)%1))
```
[Try it online!](https://tio.run/##Sy4sTc0rKf7/P15bI6RIRVPVUNM2pCheG8zS/P8fAA "cQuents – Try It Online")
Port of the jelly answer.
## Explanation
```
r$) r_+$) # Root (defaults to square root)
%1 %1 # Modulo 1 (only taking the decimal part)
T ) T ) # Ceiling (round up if there is a decimal part)
( = ) # Equal (same as jelly answer)
_+ # Successor (same as jelly answer)
```
# List output, 15 bytes
```
1,D2)*_-(k*2),1
```
[Try it online!](https://tio.run/##Sy4sTc0rKf7/31DHxUhTK15XI1vLSFPH8P9/AA "cQuents – Try It Online")
Playing with the output a bit, we can golf off 6 bytes.
Instead of outputting `1,2,2,2,1`, it outputs `1,[2,2,2],1`.
## Explanation
```
1, # A one
D2) # Digits of 2 (which is of course, just 2)
*_-(k*2) # Multiplied by k*2-1 (it's multiplying a list)
,1 # Another one
```
[Answer]
# Haskell, 36 bytes
```
do n<-[0..];'1':([1..n]>>"22")++"21"
```
[Try it online!](https://tio.run/##y0gszk7NyfmfZhvzPyVfIc9GN9pATy/WWt1Q3Uoj2lBPLy/Wzk7JyEhJU1tbychQ6X9uYmaebUFpSXBJkYKKQklidqqCqYFC2v9/yWk5ienF/3WTCwoA "Haskell – Try It Online")
This expression evaluates to an infinite string.
]
|
[Question]
[
[Vyxal](https://github.com/Vyxal/Vyxal) is a golfing language that has 500+ different commands (achieved through overloads), and is a known beater of Jelly, 05AB1E and most golfing languages.
Henceforth, it seems like a good idea to share some of the tips and tricks of the industry used to get terse programs in Vyxal.
One tip per answer, and no stupid tips like "oh remove comments and whitespace".
[Answer]
# Brackets/Structures autocomplete
*Totally not stolen from Tips for golfing in keg because Vyxal totally isn't supposed to be keg but 69 times better*
If you have a structure (e.g. if/for/while/function/lambda) that has nothing after it, and EOF follows, you can remove the closing bracket/semicolon. Note that this only applies if you are submitting a full program.
For example:
```
9(0,)
```
Can be shortened to:
```
9(0,
```
And:
```
{:1=[1,]}
```
Can be shortened to:
```
{:1=[1,
```
[Answer]
# Compress your strings and numbers
Nobody likes long strings. And nobody likes long numbers either. Luckily there's two ways of compressing strings and one way to compress numbers.
## Dictionary Compression
Fun fact: Vyxal has access to a roughly 20k word "dictionary" (read: a list of words) which can be used to shorten strings with a) common English words or b) common 3 letter combinations.
To access the words in this dictionary, you need to get the String Compression Code (SCC) of the word and place it inside a normal string (the backtick ones). String Compression Code is simply a way of saying "the base 10 index of the word within the dictionary list converted to a bijective base-1611".
You can get the SCC of a word by using `øD`. For example:
```
`Hello`øD
```
([Try it Online!](http://lyxal.pythonanywhere.com?flags=&code=%60Hello%60%C3%B8D&inputs=3&header=&footer=))
Tells you the SCC for `Hello` is `ƈṡ`. However, `øD` will also return the dictionary compression of a given string:
```
`Hello, World!`øD
```
Is turned into `ƈṡ, ƛ€!`.
`øD` is fully optimised and will always give you the shortest possible result. For example, [compressing `abcdef`](https://lyxal.pythonanywhere.com?flags=&code=%60abcdef%60%C3%B8D&inputs=&header=&footer=) will return `ėġḣ²`.
## Base-255 Compression
But what if your string is a bunch of random letters that aren't in the dictionary at all? `øD` becomes useless for obvious reasons. In this case, you would use `«` delimited strings.
These strings take everything inside of them, converts it from a bijective base-255 (the vyxal codepage minus `«`) to base 10. It then converts that result to a bijective base-27 (the lower case alphabet plus space). **Important: only stings containing lower case letters and spaces can be Base255 compressed**3.
To get the Base255 compression of a string, you can use `øc`:
```
`ahroebeodbslnwksozlzbeoxbeodbsonwkdbdi`øc
```
Tells you that the compression is `«∧pŀQb⟨ż₄∑ṄḞḊjẎɾ71(⁼~∇Ċβ«`.
## But what about numbers???
`»` strings have got you covered. `øC` will take an integer and return it converted to a bijective base-255 (the vyxal code page minus `»`:
```
69694204206969øC
```
Gives you `»A⟩¾Ǐø7»`
1: The bijective base 161 is simply the vyxal code page minus all printable ascii. This is so that SCCs can be embedded inside strings without creating a new string type.
2: Yeah, SCCs don't need to be surrounded by spaces - they can be inside ascii (`a÷×b`) or even next to each other (`£÷¬¶`). This is very intentional.
3: I originally allowed for upper and lower case inside base 255 strings, but found that strings are usually shorter when only allowing lower case.
[Answer]
# Use `₃` and `Ḣ` for certain length checks
Say you have a string and you want to check whether its length is greater than 1, and the output only needs to be truthy or falsy.
You could go `L1>` for three bytes. Or, you could go `Ḣ` for 1 byte.
Ḣ slices off the first character of a string and returns the rest, so running on a length 1 string returns an empty string, which is falsy; on a length ≥2 string, it returns a truthy non-empty string.
What about length >2? Just use `ḢḢ`, with the same logic as before, and still saving a byte.
Length = 1? There's literally a builtin for this - `₃` on strings or lists returns true only if the length is 1.
Length = 2? Just combine the two (`Ḣ₃`) - if you lop off a character and that string becomes length 1, it must've been length 2.
[Answer]
# Use `-` as a check for recursive functions
When recursing over a deep list, `-` will return a falsy value (0 / empty string) for scalars and a truthy value (list of 0) for lists.
[Example of this in use](https://codegolf.stackexchange.com/a/240692/100664)
Note that this only works when you don't have empty lists.
`Iȧ` does work for empty lists, returning a falsy value (empty string) for integers and a truthy value (list of lists) for lists. Thanks to lyxal for this one.
[Answer]
# Remember that mapping/filtering/reducing all cast numbers to ranges
Okay so say you want to apply something over the range `[1, n]` using `M`ap, `F`ilter or `R`educe (or `ḭ`nverse reduce/foldr). Your first instinct might be to do this:
```
ɾλ....;M # or whatever command you're using
```
This is unnecessary, as the functional programming commands all cast numbers to `range` before doing their job, so:
```
λ....;M
```
is equivalent.
"But what if my range isn't `[1, n]`, but instead `[0, n]` or `[1, n)` for example? Won't I need the corresponding range command?"
Well yes, but actually no if you use flags:
>
> `M` Make implicit range generation start at 0 instead of 1
>
>
> `m` Make implicit range generation end at n-1 instead of n
>
>
>
(source: flag help generated using the `-h` flag).
[Answer]
# Custom base decompression
When you're compressing a large amount of data with a limited charset, as in [here](https://codegolf.stackexchange.com/a/226068/100664), you can use a base-255 integer (`»...»`) and the custom base decompression function `τ`.
For example, say you want to compress this ascii-art:
```
/
/ \
\ \
\ / \
/ /
/ \ /
\ \
\ / \
/ /
/ \ /
\ \
\ / \
/ /
/ \ /
\ \
\ /
/
```
You can just map 0 to `\`, 1 to `/`, and 2 to to get 576780841113635223227691120919222477677740273185690732841 in base-3, which compresses to `»ɾĠ^;√⟑•ȮṙDǓ…⟩P½≠1⅛²ė"÷₆Ŀ»`.
Then, you can take out your compression guide `\/` , and append τ to turn it into base-3 with those as values.
Finally, you can split into 17 pieces (for 17 lines) and output joined by newlines - [Try it Online!](http://lyxal.pythonanywhere.com?flags=&code=%C2%BB%C9%BE%C4%A0%5E%3B%E2%88%9A%E2%9F%91%E2%80%A2%C8%AE%E1%B9%99D%C7%93%E2%80%A6%E2%9F%A9P%C2%BD%E2%89%A01%E2%85%9B%C2%B2%C4%97%22%C3%B7%E2%82%86%C4%BF%C2%BB%60%5C%5C%2F%20%60%CF%8417%2F%E2%81%8B&inputs=&header=&footer=)
[Answer]
# Use the nameless variable
Vyxal has variables, set by `→` and accessed by `←`. But did you know that there's a nameless variable?
You can access this by just going `←` followed by a non-alphabetic character (it doesn't matter what, and that will still be run). Ditto with setting.
It works in for loops - try [`4(|←,)`](https://lyxal.pythonanywhere.com/?flags=&code=4%28%7C%E2%86%90%2C%29&inputs=&header=&footer=).
In other words, it's an extra register that can easily save you a couple of bytes.
[Answer]
# Use the multi-element lambdas if your lambda body is 1-3 bytes
Say you have the following:
```
λǐṅ;Ẋ
```
You can turn this into
```
‡ǐṅẊ
```
Because `‡` combines the next two elements (built-ins) into a single lambda. `⁽` is for 1 element lambdas (good for when you want to reduce/filter/map a built-in without using `v`) and `≬` is for 3 element lambdas.
[Answer]
# Use `\` for single byte strings and `‛` for two byte strings
Sometimes you'll need a string of either one or two characters. You could do the following:
```
`A`
`AB`
```
But that has an extra backtick at the end. Instead, you can do this:
```
\A
‛AB
```
## Important
`\` pushes the next character as a string no matter what it is. `‛` will treat it as if the next two characters were wrapped in backticks (meaning that it will dictionary uncompress a single string compression code).
[Answer]
# Use of filter lambda
Filter lambda (`'`) can filter out the items which are not truthy from the stack, so you don't need a lambda map and close it and then find out the Truthy indices.
This is a code using the lambda map
```
ƛǐG5>;T›
```
But if you use filter lambda, it can be shortened to
```
'ǐG5>
```
the last 3 commands are no longer needed!
[Answer]
# Use the register instead of a variable
Sometimes, you're using a variable over and over again, and it's using so many bytes, right? Well, if you only have 1 variable, you can use the register instead, and save a byte every time you use it!
For example, say you want to do `x * 2` and `x ^ x`. You *could* do:
```
3→x ←xd, ←x←xe,
```
This saves 3 to `x`, then retrieves it and doubles it, then retrieves twice, and exponentiates. However, `x` is being used 4 times, so that's 8 bytes in variable references alone! Using the register will shorten this code a lot:
```
3£ ¥d, ¥¥e,
```
Instead of saving to and retrieving from a variable, we're using the register, which can be accessed using only 1 byte. Anytime you're using variables, you can replace one of the variables with the register to save some bytes!
[Answer]
# Converting characters to numbers in [resticted-source](/questions/tagged/resticted-source "show questions tagged 'resticted-source'")
When you want to convert characters to numbers, you have to use `C`, right? Well, there's another way. You can also use `b`. The `b` command, when used on a string, will convert each character to its ASCII value, then convert that to binary. You can then use `B` to convert that back to a decimal value!
```
`EEEE` b vB
```
[Try it Online!](https://lyxal.pythonanywhere.com?flags=&code=%60EEEE%60%20b%20vB&inputs=&header=&footer=)
It's not too often that you'll be able to use `bB` and not be able to use `C`, but this can be quite useful in [the right circumstances](https://codegolf.stackexchange.com/a/235769/101522).
[Answer]
# Utilise the Short Dictionary
*Note: This is a 2.6.x+ feature only*
Newer versions of Vyxal have a neat little feature where 1 character SCCs are indexed into a special "short" dictionary of overlyspecialised "words". Here's a list of all the current entries:
```
\d+ λ
-?\d+ ƛ
\d+\.\d+ ¬
-?\d+(\.\d*)? ∧
[A-Za-z0-9\.,;:!?()"'%\-]+ ⟑
^\S+@\S+$ ∨
[A-Za-z0-9] ⟇
[A-Za-z] ÷
[a-z] ×
[A-Z] «
[0-9] »
[aeiou] °
[aeiouy] •
[bcdfghjklmnpqrstvwxyz] ß
\w+ †
.* €
[^A-z0-9] ½
[^A-Z] ∆
[^a-z] ø
[^0-9] ↔
[^aeiou] ¢
[^aeiouy] ⌐
[^bcdfghjklmnpqrstvwxyz] æ
(.+) ʀ
\W ʁ
\w ɾ
\S ɽ
\s Þ
\W+ ƈ
\w+ ∞
\S+ ¨
\s+ ↑
((www\.|(http|https|ftp|news|file)+\:\/\/)[_.a-z0-9-]+\.[a-z0-9\/_:@=.+?,##%&~-]*[^.|\'|\# |!|\(|?|,| |>|<|;|\)]) ↓
?<= ∴
?!= ∵
?<! ›
https://www.google.com ‹
https://www.google.com/query?q= ∷
https://www.duckduckgo.com ¤
https://www.duckduckgo.com/?q= ð
https://www.bing.com →
https://www.bing.com/?q= ←
https://codegolf.stackexchange.com/q/ β
https://codegolf.stackexchange.com/a/ τ
https://stackoverflow.com/q/ ȧ
https://stackoverflow.com/a/ ḃ
₁ƛ₍₃₅kF½*∑∴, ċ
:ɾ:Ẋv∑Ȯẇ ḋ
:ɾ:Ẋƛ⁽=R;Ȯẇ ė
isdo ḟ
›‹²… ġ
n't ḣ
cos(x) ḭ
sin(x) ŀ
tan(x) ṁ
acos(x) ṅ
asin(x) ȯ
atan(x) ṗ
x^2 ṙ
x^3 ṡ
x+1 ṫ
x-1 ẇ
```
So for example:
```
`β223918`
```
would return the address of this question (because `β` decompresses as `https://codegolf.stackexchange.com/q/`).
[Answer]
# For reverse sorting, use `µ...⌐`
If the last operation you do in a program is to sort something in a certain way then reverse it, you can save a byte by using `µ...⌐` - take the one's complement before sorting. This only works when the preceding value is numeric.
[An example](https://codegolf.stackexchange.com/a/245347/100664).
[Answer]
# If there are not enough arguments on the stack, fillers will be taken based on the context
What I mean: if there are not enough arguments on the stack to perform an action, the extra arguments will come either from the input (in the "main" program), or from the function/lambda arguments. I discovered this while golfing [this](https://codegolf.stackexchange.com/a/243235/107299) answer. I was trying to find a way to tie with 05AB1E, and I had this code:
```
:↵':²"Ṡ≈;i
```
I was wondering how I could remove those duplicate elements, and I decided to look at the source code. And then I found the docstring for `pop()`: `Pops (count) items from iterable. If there isn't enough items within iterable, input is used as filler`. Looking at `get_input()`, you see that it either reads the input from STDIN, or from the lambda arguments. That allowed me to shave off two bytes and my code became this:
```
↵'²"Ṡ≈;i
```
[Answer]
# Use string interpolation
Apparently automatic string interpolation (`Π`) has been incorporated into Vyxal from v2.13.3 onwards.
When used inside a string, `Π` pops a value from the stack and interpolates it into the string.
For example:
```
1 2+ `Answer: Π`
```
[returns `Answer: 3`](https://vyxal.pythonanywhere.com/?v=2&c=1#WyIiLCIiLCIxIDIrIGBBbnN3ZXI6IM6gYCIsIiIsIiJd)
As always, you can [escape `Π`](https://vyxal.pythonanywhere.com/?v=2&c=1#WyIiLCIiLCIxIDIrIGBBbnN3ZXI6IFxczqBgIiwiIiwiIl0=) by using a backlash.
]
|
[Question]
[
**Closed**. This question needs [details or clarity](/help/closed-questions). It is not currently accepting answers.
---
**Want to improve this question?** Add details and clarify the problem by [editing this post](/posts/185483/edit).
Closed 4 years ago.
[Improve this question](/posts/185483/edit)
The challenge is to write a deterministic program (any language/OS) which takes no arguments or other input and **behaves differently in a debugger from how it behaves when not being debugged**.
For example, the program may output something when being debugged but not output anything when not being debugged. Or output something different in each case. Or it may crash when being debugged but not crash when not being debugged. Or vice-versa.
Caveats and clarifications:
* Timing differences do not count.
* Interpreted languages are permitted.
* To emphasize determinism: the behaviour must be exactly reproducible both in and out of debugging context.
* The presence of the debugger itself should the only difference between the two cases.
+ Telling the debugger to add inputs (stdin or argv ENV or whatever) is cheating, the debugger should run the program "as-is".
+ Changing the environment (e.g. running in a virtual machine or different OS, or changing OS settings such as memory limits) between debug and non-debug runs is not permitted.
Shortest code wins. I may award a bounty which reveals something interesting about how debuggers work.
[Answer]
# x86 and x64\_64 machine language on Linux and OSX, 1 byte
```
0x0: CC int3
```
[Try it online!](https://tio.run/##S9ZNT07@/z83MTPP1sjAxPr//3/JaTmJ6cX/datSK1KTi0sSk7MB "C (gcc) – Try It Online")
`int 3` throws a `SIGTRAP` which will cause a debugger to stop as if it encountered a breakpoint. Outside of a debugger, the kernel terminates the process (thanks to @Ruslan for the correction).
# [C (gcc)](https://gcc.gnu.org/) (x86 Linux and OSX), ~~14 11~~ 9 bytes
```
main=204;
```
[Try it online!](https://tio.run/##S9ZNT07@/z83MTPP1sjAxPr//3/JaTmJ6cX/datSK1KTi0sSk7MB "C (gcc) – Try It Online")
The integer `204` corresponds to the `int 3` instruction; the TIO link is the same as above.
[Answer]
# [APL (Dyalog Unicode)](https://www.dyalog.com/), 0 bytes
In Dyalog APL, debugger vs no debugger is choosen by running one's workspace in either the IDE interpreter or the runtime interpreter.
Loading a completely empty default settings workspace into the IDE interpreter, immediately drops the user into REPL mode as applications must actively shut down the interpreter for it to quit:
[](https://i.stack.imgur.com/NUaFt.png)
However, the runtime interpreter does not have a REPL mode, and so if an application comes to an end (for example because it is completely empty) and does not explicitly shut down the interpreter, it implicitly has attempted to reach REPL mode ("the APL session"), and complains:
[](https://i.stack.imgur.com/36Xlk.png)
[Answer]
# JavaScript on Firefox, 69 bytes
**WARNING**: This script may hang your browser! Do NOT test it with other browsers (e.g. Chrome) as it may crash your tab / browser.
```
for(console.log(a={},i=99);--i;a=a.a={k:new Int8Array(1e9)});alert(1)
```
How: When debugger is enabled with `console` tab activated. `console.log` makes memory leak possible, and the program will run out of memory soon. When debugger is disabled, GC would clear memory allocated, and you would see an alert with text `1` finally.
[Answer]
## MSVC (64-bit), ~~50~~ 35 bytes
```
main(){return IsDebuggerPresent();}
```
Exits with code 0 normally but 1 under the debugger (note that WinDbg does not automatically display the exit code but you can fake it by examining the stack). Edit: Saved 15 bytes thanks to @Ruslan.
[Answer]
# T-SQL, 6 bytes
```
sp_who
```
Always returns an extra row under the executing user's name when the debugger is active.
[Answer]
# Python, 29 bytes
```
import sys
sys.modules['pdb']
```
Without debugger (`python3 /tmp/foo.py`):
```
Traceback (most recent call last):
File "/tmp/foo.py", line 2, in <module>
sys.modules['pdb']
KeyError: 'pdb'
```
With debugger (`python3 -m pdb /tmp/foo.py`):
```
(empty output)
```
because `pdb` is loaded into an app-visible module in the second case.
[Answer]
# JavaScript, 17 bytes
```
debugger
alert(1)
```
[`debugger`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/debugger) stops execution if the debugger console is open, else it does nothing
[Answer]
# Java, ~~131 102~~ 100 bytes
```
v->(java.lang.management.ManagementFactory.getRuntimeMXBean().getInputArguments()+"").split(":jdwp")
```
When running without a debugger this function returns an array of length 1. When running with a debugger, this returns an array of length 2 (greater than 1).
[Try it online!](https://tio.run/##PZBBS8QwEIXv/RWhp4TtBrzu2gVFFjzsxQURRGTaxphuOgnJpFJk/7o1XVZvj5k3w/deDyOsnVfYd6e5tRAjO4BB9l0wFgnItKzPFpnIWPmRsCXjUO6v4vbZma46UjCoX992DFg9j@sdv5xYQC0HQNBqUEjy8C/30JILk9SKnhKSGdTh5V4BcrGMHtEnugs6LdbIxaoshYzeGuLlpu@@fCnmbeFTYzPclXHMHGzI4PwPBoKOYklxnCKpQbpE0ucVWeTlg2qS1ipsWMlWjIME7@3EMVkrpFWo6ZPt2I0Q2@JcnOcf55e0cV7nAPmDaS4cNQXA6F2guqP36NqToiqqMKpQT1VMMdfa1fgL "Java (OpenJDK 8) – Try It Online")
This technically detects if you *could* attach a debugger; not if one is currently connected... Not sure if that's valid
-23 bytes thanks to [Olivier Grégoire](https://codegolf.stackexchange.com/users/16236/olivier-gr%C3%A9goire) for mentioning that I can cut down on what I search for in the runtime parameters and for lambda-izing my answer
-5 bytes thanks to [Benjamin Urquhart](https://codegolf.stackexchange.com/users/84303/benjamin-urquhart) for noting that calling `toString` is dumb when I can let Java implicitly convert
-2 bytes thanks to [Benjamin Urquhart](https://codegolf.stackexchange.com/users/84303/benjamin-urquhart) for changing the return type
[Answer]
# [Robotalk](https://en.wikipedia.org/wiki/RoboWar), 22 bytes
```
debug l: chronon l ifg
```
If the debugger is active, the `debug` instruction pauses execution until the end of the current game tick. In this case, the variable "chronon" is always 1 or greater when read, and the program executes an infinite loop. If the debugger isn't active, `debug` is a one-cycle no-op. "Chronon" is now 0 when read, the "ifg" branch isn't taken, and execution reaches the end of the code, which is an error condition.
[Answer]
# MATLAB, 6 bytes
`dbquit`
When stopped in the debugger, this will quit debugging mode.
When not under debug, it will print an error message that it cannot be used when not stopped in the debugger.
It should be noted this only works for evaluation in the command window (one of the three ways of running MATLAB code). It won't work in a function or script as once you try to run the script or function, you stop being in debug mode during execution.
The closest you can get to something that will run in a function/script as well would be:
# MATLAB, 22 bytes
```
feature('IsDebugMode')
```
This is an undocumented command in MATLAB. If you are stopped in the debugger in a script or function, and then call another function (or command evaluation) that contains the above line, it will return true.
Outside the debugger it will return false.
If you were however to just run a script/function containing the above, even if you add a breakpoint at the start of the script/function and step through, it will return false, because again, once you start executing you stop being in the debugger temporarily.
]
|
[Question]
[
## Challenge
Using data from the API [here](http://www.medalbot.com/api/v1/medals), output the names of the three countries with the most Olympic gold medals at the 2016 Rio Olympic Games (i.e. the first element of the returned list).
For example, at the time of posting (18:23 UTC+1, Monday, 15th August), the USA, the UK and China have the most gold medals, so the output would be:
```
United States
Great Britain
China
```
The country names must be separated by newlines and you may have a leading or trailing newlines.
Once the Olympics have finished, the program does not have to work as expected.
URL shorteners are disallowed but JSON parsing libraries are allowed.
**This is code golf, so the shortest code in bytes wins.**
I'm going to keep trying to get an Olympics themed challenge in here
## Leaderboard
```
var QUESTION_ID=89919,OVERRIDE_USER=30525;function answersUrl(e){return"https://api.stackexchange.com/2.2/questions/"+QUESTION_ID+"/answers?page="+e+"&pagesize=100&order=desc&sort=creation&site=codegolf&filter="+ANSWER_FILTER}function commentUrl(e,s){return"https://api.stackexchange.com/2.2/answers/"+s.join(";")+"/comments?page="+e+"&pagesize=100&order=desc&sort=creation&site=codegolf&filter="+COMMENT_FILTER}function getAnswers(){jQuery.ajax({url:answersUrl(answer_page++),method:"get",dataType:"jsonp",crossDomain:!0,success:function(e){answers.push.apply(answers,e.items),answers_hash=[],answer_ids=[],e.items.forEach(function(e){e.comments=[];var s=+e.share_link.match(/\d+/);answer_ids.push(s),answers_hash[s]=e}),e.has_more||(more_answers=!1),comment_page=1,getComments()}})}function getComments(){jQuery.ajax({url:commentUrl(comment_page++,answer_ids),method:"get",dataType:"jsonp",crossDomain:!0,success:function(e){e.items.forEach(function(e){e.owner.user_id===OVERRIDE_USER&&answers_hash[e.post_id].comments.push(e)}),e.has_more?getComments():more_answers?getAnswers():process()}})}function getAuthorName(e){return e.owner.display_name}function process(){var e=[];answers.forEach(function(s){var r=s.body;s.comments.forEach(function(e){OVERRIDE_REG.test(e.body)&&(r="<h1>"+e.body.replace(OVERRIDE_REG,"")+"</h1>")});var a=r.match(SCORE_REG);a&&e.push({user:getAuthorName(s),size:+a[2],language:a[1],link:s.share_link})}),e.sort(function(e,s){var r=e.size,a=s.size;return r-a});var s={},r=1,a=null,n=1;e.forEach(function(e){e.size!=a&&(n=r),a=e.size,++r;var t=jQuery("#answer-template").html();t=t.replace("{{PLACE}}",n+".").replace("{{NAME}}",e.user).replace("{{LANGUAGE}}",e.language).replace("{{SIZE}}",e.size).replace("{{LINK}}",e.link),t=jQuery(t),jQuery("#answers").append(t);var o=e.language;/<a/.test(o)&&(o=jQuery(o).text()),s[o]=s[o]||{lang:e.language,user:e.user,size:e.size,link:e.link}});var t=[];for(var o in s)s.hasOwnProperty(o)&&t.push(s[o]);t.sort(function(e,s){return e.lang>s.lang?1:e.lang<s.lang?-1:0});for(var c=0;c<t.length;++c){var i=jQuery("#language-template").html(),o=t[c];i=i.replace("{{LANGUAGE}}",o.lang).replace("{{NAME}}",o.user).replace("{{SIZE}}",o.size).replace("{{LINK}}",o.link),i=jQuery(i),jQuery("#languages").append(i)}}var ANSWER_FILTER="!t)IWYnsLAZle2tQ3KqrVveCRJfxcRLe",COMMENT_FILTER="!)Q2B_A2kjfAiU78X(md6BoYk",answers=[],answers_hash,answer_ids,answer_page=1,more_answers=!0,comment_page;getAnswers();var SCORE_REG=/<h\d>\s*([^\n,]*[^\s,]),.*?(\d+)(?=[^\n\d<>]*(?:<(?:s>[^\n<>]*<\/s>|[^\n<>]+>)[^\n\d<>]*)*<\/h\d>)/,OVERRIDE_REG=/^Override\s*header:\s*/i;
```
```
body{text-align:left!important}#answer-list,#language-list{padding:10px;width:290px;float:left}table thead{font-weight:700}table td{padding:5px}
```
```
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <link rel="stylesheet" type="text/css" href="//cdn.sstatic.net/codegolf/all.css?v=83c949450c8b"> <div id="answer-list"> <h2>Leaderboard</h2> <table class="answer-list"> <thead> <tr><td></td><td>Author</td><td>Language</td><td>Size</td></tr></thead> <tbody id="answers"> </tbody> </table> </div><div id="language-list"> <h2>Winners by Language</h2> <table class="language-list"> <thead> <tr><td>Language</td><td>User</td><td>Score</td></tr></thead> <tbody id="languages"> </tbody> </table> </div><table style="display: none"> <tbody id="answer-template"> <tr><td>{{PLACE}}</td><td>{{NAME}}</td><td>{{LANGUAGE}}</td><td>{{SIZE}}</td><td><a href="{{LINK}}">Link</a></td></tr></tbody> </table> <table style="display: none"> <tbody id="language-template"> <tr><td>{{LANGUAGE}}</td><td>{{NAME}}</td><td>{{SIZE}}</td><td><a href="{{LINK}}">Link</a></td></tr></tbody> </table>
```
[Answer]
# C (+sockets), ~~433~~ ~~429~~ ~~280~~ ~~276~~ ~~270~~ 259 bytes
```
#define H"medalbot.com"
char**p,B[999],*b=B;main(f){connect(f=socket(2,1,getaddrinfo("www."H,"80",0,&p)),p[4],16);send(f,"GET http://"H"/api/v1/medals HTTP/1.1\r\nHost:"H"\r\n\r\n",69);read(f,b,998);for(f=3;f--;puts(p))b=strchr(p=strstr(++b,"_n")+9,34),*b=0;}
```
So it turns out that C isn't great at downloading resources from the internet and parsing them as JSON. Who knew?
This code is (naturally) super lax with error checking, so I guess if medalbot.com wanted to send malicious data they'd be able to trigger buffer overflows, etc. Also the latest code expects certain values for the constants (e.g. `AF_INET = 2`) which will *probably* be the case everywhere, but it's not guaranteed.
Here's the original code which isn't so fragile (but still isn't very robust or safe):
```
#include<netdb.h>
#define H"medalbot.com"
char*b,*B,d[999];struct addrinfo*p,h;main(f){h.ai_socktype=SOCK_STREAM;getaddrinfo("www."H,"80",&h,&p);f=socket(p->ai_family,p->ai_socktype,p->ai_protocol);connect(f,p->ai_addr,p->ai_addrlen);send(f,"GET http://"H"/api/v1/medals HTTP/1.1\r\nHost: "H":80\r\nConnection: close\r\n\r\n",92,0);recv(f,d,998,0);for(f=0,b=d;f<3;++f)B=strstr(b,"_n")+9,b=strchr(B,'}'),*strchr(B,'"')=0,puts(B);}
```
Breakdown:
```
// No imports needed whatsoever!
#define H"medalbot.com" // Re-use the host in multiple places
char**p, // This is actually a "struct addrinfo*"
B[999], // The download buffer (global to init with 0)
*b=B; // A mutable pointer to the buffer
main(f){
// Hope for the best: try the first suggested address with no fallback:
// (medalbot.com runs on Heroku which has dynamic IPs, so we must look up the
// IP each time using getaddrinfo)
f=socket(2,1,getaddrinfo("www."H,"80",0,&p));
// 2 = AF_INET
// 1 = SOCK_STREAM
// (may not match getaddrinfo, but works anyway)
// 0 = IP protocol (getaddrinfo returns 0 on success)
connect(f,p[4],16); // struct addrinfo contains a "struct sockaddr" pointer
// which is aligned at 32 bytes (4*8)
// Send the HTTP request (not quite standard, but works. 69 bytes long)
send(f,"GET http://"H"/api/v1/medals HTTP/1.1\r\nHost:"H"\r\n\r\n",69);
// (omit flags arg in send and hope 0 will be assumed)
read(f,b,998); // Get first 998 bytes of response; same as recv(...,0)
// Loop through the top 3 & print country names:
// (p is re-used as a char* now)
for(f=3;f--;puts(p)) // Loop and print:
p=strstr(++b,"_n")+9, // Find "country_name": "
b=strchr(p,34), // Jump to closing "
*b=0; // Set the closing " to \0
}
```
This isn't very nice for the server since we don't send `Connection: close\r\n` as part of the HTTP request. It also omits the `Accept` header since medalbot.com doesn't seem to be using compression in any case, and misses the space after `Host:` (again, the server seems to be OK with this). It doesn't seem as though anything else can be removed though.
---
Once the olympics end, the most likely behaviour for this program is to segfault trying to read memory location 9. Unless an evil hacker takes over the domain, in which case the most likely behaviour is for it to set some byte to 0 in the address info structs, which probably isn't too dangerous actually. But who can tell with these evil hackers?
[Answer]
# bash + w3m + grep + cut, ~~65~~ ~~59~~ ~~58~~ 54 bytes
```
w3m medalbot.com/api/v1/medals|grep -m3 m|cut -d\" -f4
```
* 6 bytes less thanks to @Joe's suggestions.
* 1 byte less thanks to @YOU.
* 4 bytes less thanks to [@manatwork](https://codegolf.stackexchange.com/questions/89919/quick-golf-the-gold-leader/89933#comment219449_89927)'s suggestion that *the medalbot API seems to work without www. subdomain too*.
[Answer]
## PowerShell v4+, ~~88~~ 69 bytes
```
(ConvertFrom-Json(iwr medalbot.com/api/v1/medals))[0..2].country_name
```
Uses `iwr` (the alias for [`Invoke-WebRequest`](https://technet.microsoft.com/en-us/library/hh849901.aspx)) to grab the API. We feed that as the input parameter to the [`ConvertFrom-Json`](https://technet.microsoft.com/en-us/library/hh849898(v=wps.630).aspx) built-in that pulls the JSON text into a custom object array. We encapsulate that object array in parens, take the first three elements `[0..2]`, and take the `.country_name` of each thereof.
Requires at least v4+ for the multiple-object-properties, else we'd need to use something like `|Select "country_name"` instead. Requires at least v3+ for the `ConvertFrom-Json` built-in.
```
PS C:\Tools\Scripts\golfing> .\olympics-gold-leader.ps1
United States
Great Britain
China
```
[Answer]
# R, 98, 112, 108 bytes
golfed 4 thanks to @miff
```
a=jsonlite::fromJSON(readLines("http://www.medalbot.com/api/v1/medals"))
cat(a$c[order(-a$g)[1:3]],sep="\n")
```
First line imports data using a JSON library. Second line grabs the relevant country names. It sorts the countries by gold medals in increasing order, reverses the indices, and takes the first 3, printing them.
[Answer]
# JavaScript (ES6), 122 Bytes
```
fetch`http://www.medalbot.com/api/v1/medals`.then(a=>a.json()).then(b=>alert(b.slice(0,3).map(c=>c.country_name).join`\n`))
```
Due to a [browser safety issue](https://developer.mozilla.org/en-US/docs/Web/HTTP/Access_control_CORS), this code must be run on `medalbot.com`. It does not however take advantage of that and could potentially be run elsewhere. Also note that I inserted the `\n` character, but am only counting is as one, because I could replace it with one
# Node.js (ES6), 173 Bytes
```
require("http").get("http://www.medalbot.com/api/v1/medals",s=>s.on("data",d=>t+=d,t="").on("end",q=>console.log(JSON.parse(t).slice(0,3).map(a=>a.country_name).join`\n`)))
```
This would have been so much shorter if the API returned the data all in one stretch, but since it returns in two sections, I must concatenate the parts and combine them, and then parse them.
# Node.js (ES6) + Request, 138 Bytes
```
require("request")("http://www.medalbot.com/api/v1/medals",(e,r,b)=>console.log(JSON.parse(b).slice(0,3).map(a=>a.country_name).join`\n`))
```
Better, but still not as good as the browser version. Thanks fetch API! [Request](http://npmjs.org/request) is a popular HTTP client library used to simplify requests, and you can see that take effect here.
[Answer]
# [bash](https://www.gnu.org/software/bash/) + [w3m](http://w3m.sourceforge.net/) + [jq](https://stedolan.github.io/jq/), ~~83~~ 59 bytes
```
w3m medalbot.com/api/v1/medals|jq -r '.[:3][].country_name'
```
Thanks to Jordan for three bytes.
Thanks to YOU for 24 more bytes! Turns out the data is sorted. Wow. :D
[Answer]
# Java 8, ~~261~~ 258 bytes
This uses a lambda to save a couple bytes and the net library to get the webpage. Other than that is just Java.
```
()->{try{for(int i=0;i<3;System.out.println(new java.util.Scanner(new java.net.URL("http://www.medalbot.com/api/v1/medals").openConnection().getInputStream()).useDelimiter("\\A").next().split("\n")[i++*9+3].replaceAll(".* \"|\",","")));}catch(Exception e){}}
```
Here is my (old) POJO for testing (and golfing):
```
class QuickGolf {
static void f(h x){x.g();}
static interface h{ void g(); }
static void main(String[] args){
f(
()->{try{for(int i=0;i<3;i++){System.out.println(new java.util.Scanner(new java.net.URL("http://www.medalbot.com/api/v1/medals").openConnection().getInputStream()).useDelimiter("\\A").next().split("\n")[i*9+3].substring(21).replace("\",",""));}}catch(Exception e){}}
);
}
}
```
---
**Update**
* **-3** [16-08-17] Move print statement *into* for loop
* **-5** [16-08-16] Improved regex replace
* **-9** [16-08-16] Removed `java.net` import
[Answer]
# [MATL](https://github.com/lmendo/MATL), 67 bytes
```
'http://www.medalbot.com/api/v1/medals'Xi'(?<="c.+e": ")[^"]+'XX3:)
```
This doesn't work online because function `Xi` (`urlread`) is disallowed.
Example run:
```
>> matl
> 'http://www.medalbot.com/api/v1/medals'Xi'(?<="c.+e": ")[^"]+'XX3:)
>
United States
Great Britain
China
```
### Explanation
This reads the contents as a string and then applies the regex `'(?<="c.+e": ")[^"]+'` to extract country names. The regex uses look-behind with `"c.+e"` instead of `"country_name"` to reduce code length.
```
'http://www.medalbot.com/api/v1/medals' % Push string representing the URL
Xi % Read URL contents as a string
'(?<="c.+e": ")[^"]+' % String for regex matching
XX % Apply regex
3:) % Get first 3 results
```
[Answer]
# Python 3, ~~202~~, 164 bytes.
Python 3 does not do short url/json handling. :/
Didn't realize the API already sorts by gold count
```
from urllib.request import*
import json
print('\n'.join(x['country_name']for x in json.loads(urlopen('http://www.medalbot.com/api/v1/medals').read().decode())[:3]))
```
[Answer]
# Python 2, 120 113 bytes
```
from urllib import*
for x in list(urlopen("http://www.medalbot.com/api/v1/medals"))[3:26:9]:
print x[21:-4]
```
Thanks @Nick T and @Value Ink
[Answer]
# JavaScript + jQuery, ~~114~~ 100 bytes
```
$.get("www.medalbot.com/api/v1/medals",a=>alert(a[0][c='country_name']+'\n'+a[1][c]+'\n'+a[2][c]))
```
For the reason of Cross Origin Requests, this must be run from the `medalbot.com` domain (with jQuery).
### History
* *-14 bytes thanks to @YetiCGN*
* *-2 bytes thanks to Yay295*
[Answer]
# Ruby, ~~97~~ 79 + `-rnet/http` (11) = 90 bytes
Uses a modification of the regex pattern from [Luis Mendo's MATL answer](https://codegolf.stackexchange.com/a/89928/52194), further optimized by @Jordan, since Ruby doesn't support quantifiers in lookbehinds.
-18 bytes from @Jordan.
```
puts Net::HTTP.get("www.medalbot.com","/api/v1/medals").scan(/"c.+"(.+)"/)[0,3]
```
[Answer]
# PowerShell, 60
```
(iwr medalbot.com/api/v1/medals|convertfrom-json)[0..2]|% c*
```
Same basic idea as TimmyD (didn't see their answer before I posted), but quite a bit shorter :-)
[Answer]
# Mathematica ~~96~~ 66 bytes
@alephalpha found a way to work directly from the file (without saving it), thereby saving 30 bytes!
```
Import["http://www.medalbot.com/api/v1/medals","RawJSON"][[;;3,2]]
```
`Import` imports the file as a Raw JSON file.
`[[;;3,2]]`takes rows 1-3, second entry (country name).
[Answer]
# PHP, ~~205 139 124 116 111~~ 109 bytes
I just wanted to use the new spaceship operator for PHP 7 once (**EDIT**: It's superfluous, as sorting isn't required):
```
<?$d=json_decode(file_get_contents('http://www.medalbot.com/api/v1/medals'),1);usort($d,function($a,$b){$g='gold_count';return$b[$g]<=>$a[$g];});$c='country_name';foreach([0,1,2]as$i){echo$d[$i][$c]."\n";}
```
If we omit the unneccesary sorting step and assume the API delivers the data already sorted by gold\_count descending (as it would seem), we can shorten this further:
```
while($i<3)echo json_decode(file_get_contents('http://medalbot.com/api/v1/medals'))[+$i++]->country_name."
";
```
Note: The line break within the string is intentional to save a byte from \n
## History
* Ommitted some quotes and braces that will throw notice's, removed the $c variable for country\_name index. Thanks to @manatwork for these tipps to save even more characters.
* Thanks to @jeroen for pointing out the shorter while loop, also switched to object access to go from 124 to 116
* Saved 5 more bytes by calling the API within the loop. Granted, it takes longer and clobbers the API, but it's Code Golf. Needs PHP 5.5 to work because of array dereferencing.
* Saved 2 more bytes by removing the short open tag, as [per this meta answer](https://codegolf.meta.stackexchange.com/a/7146/58556)
[Answer]
# BASH + w3m + core utils, 70 bytes
```
w3m www.medalbot.com/api/v1/medals|grep -m3 tr|cut -f6- -d\ |tr -d \",
```
Looks like the output comes sorted already. Just need to throw out all of the extra text.
[Answer]
## CJam (57 bytes)
```
"http://www.medalbot.com/api/v1/medals"gN/3>9%3<{'"/3=N}%
```
Online demo not available because it fetches content from the web. This cheats by not actually parsing JSON, but assuming that the structure won't change. (But then so do most of the existing answers, in different ways).
[Answer]
# Python 2, 117 bytes
```
from requests import *
for x in get('http://www.medalbot.com/api/v1/medals').json()[:3]:
print(x['country_name'])
```
[Answer]
# Clojure, 122 bytes
```
(fn[](mapv #(println(%"country_name"))(take 3(read-string(.replace(slurp"http://www.medalbot.com/api/v1/medals")":""")))))
```
No JSON library used :). Reads string from the URL, replaces colons with empty string and evals the string which results into Clojure map. Takes first 3 elements and maps eagerly function which prints `country_name` property of each elements.
[Answer]
# Java 8 ~~386~~ ~~384~~ 459 bytes
2 bytes saved from @Easterly Irk
My first code golf submission so I'm sure there's a way to save plenty of bytes, but oh well :)
It uses Gson to read the JSON
Requires:
```
import java.util.*;
import java.io.*;
```
Golfed code:
```
void p()throws Exception{List<A> a=new com.google.gson.Gson().fromJson(new InputStreamReader((InputStream)((new java.net.URL("http://www.medalbot.com/api/v1/medals").openConnection())).getContent()),new com.google.gson.reflect.TypeToken<List<A>>(){}.getType());a.sort((b,c)->c.gold_count.compareTo(b.gold_count));for(int i=0;i<3;)System.out.println(a.get(i++).country_name);}class A{String country_name;Integer gold_count;}
```
Ungolfed Code:
```
void p() throws Exception {
List<A> a = new com.google.gson.Gson().fromJson(new InputStreamReader((InputStream)((new java.net.URL("http://www.medalbot.com/api/v1/medals").openConnection())).getContent()),new com.google.gson.reflect.TypeToken<List<A>>(){}.getType());
a.sort((b, c) -> c.gold_count.compareTo(b.gold_count));
for(int i=0; i<3;)
System.out.println(a.get(i++).country_name);
}
class A {
String country_name;
Integer gold_count;
}
```
[Answer]
## R, 97 95 bytes
```
t=rjson::fromJSON(f="http://www.medalbot.com/api/v1/medals")
for(i in 1:3)cat(t[[c(i,2)]],"\n")
```
Little improvement over user5957401's answer, no sorting required, and shorter library name.
Also my first attempt at golfing ;)
[Answer]
# [Kotlin (Script)](https://kotlinlang.org), ~~125~~ ~~121~~ 119 bytes
```
java.net.URL("http://medalbot.com/api/v1/medals").readText().lines().filter{'m' in it}.take(3).map{println(it.split('"')[3])}
```
Runnable with `kotlinc -script <filename>` or through IDEA as \*.kts file.
now, if we make a VERY big assumption about the format, including numbers of lines, we can trim it to:
```
java.net.URL("http://medalbot.com/api/v1/medals").readText().lines().slice(setOf(3,12,21)).map{println(it.split('"')[3])}
```
or even
```
java.net.URL("http://medalbot.com/api/v1/medals").readText().lines().slice(3..21 step 9).map{println(it.split('"')[3])}
```
Thanks to folks at Kotlin slack team for helping me trim a couple dozens of bytes!
[Answer]
## Javascript 167 bytes
```
x=new XMLHttpRequest();x.open("GET","http://www.medalbot.com/api/v1/medals",false);x.send()
i=-3;while(i++)console.log(JSON.parse(x.responseText)[i+2]["country_name"])
```
]
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.