title: Electronic Piggy Bank

text:
# Question
Title: Electronic Piggy Bank
A piggy bank is a container used to collect coins in. For this challenge use the four US coins: quarter, dime, nickel, and penny.

# Challenge

Your challenge is to create an electronic piggy bank. Write a program (or function) that when run (or called), outputs (or returns) the count of each coin you have, as well as the total amount the coins amount to.

# Input

A string, array, etc...(your choice) of the coins into your piggy bank(case insensitive).

```
 Q - Quarter(Value of 25)
 D - Dime(Value of 10)
 N - Nickel(Value of 5)
 P - Penny(Value of 1)

```

# Output

The count of coins from the input and the total amount, separated by the non-integer delimiter of your choice. (The order in which you output the coin totals does not matter, but the total coin value(sum) must be the last element)

# Examples

```
 Input          ->       Output

 P              ->       1,0,0,0,1 or 0,0,0,1,1 or 0,0,1,0,1 or 1,1
 N              ->       0,1,0,0,5
 D              ->       0,0,1,0,10
 Q              ->       0,0,0,1,25
 QQQQ           ->       0,0,0,4,100
 QNDPQNDPQNDP   ->       3,3,3,3,123
 PPPPPPPPPP     ->       10,0,0,0,10
 PNNDNNQPDNPQND ->       3,6,3,2,113

```

# Rules

Standard loopholes are not allowed.

This is , so the shortest code in bytes for each language wins!

# Answer
> 6 votes
# Python 2, 73 bytes

-3 bytes thanks to @Rod

```
C=map(input().count,'QDNP')
print C+[sum(map(int.__mul__,C,[25,10,5,1]))]

```

Try it online!

# Answer
> 4 votes
# , ~~70~~ 69 bytes

```
function(n)c(x<-table(factor(n,c("P","N","Q","D"))),x%*%c(1,5,25,10))

```

Try it online!

Takes input as a vector of individual characters. Converts them to `factors` and `tabulate`s them, then computes the values with a dot product.

For ease of testing purposes, I've added a way to convert from test cases above to the input that the function is expecting.

This barely beats out storing the coin names as vector `names`, which means that the approach below would be likely be golfier if we had more coin types:

# , ~~71~~ 70 bytes

```
function(n)c(x<-table(factor(n,names(v<-c(P=1,N=5,Q=25,D=10)))),x%*%v)

```

Try it online!

# Answer
> 4 votes
# Python 2, 63 bytes

```
a,b,c,d=map(input().count,'PNDQ')
print a,b,c,d,a+b*5+c*10+d*25

```

Try it online!

---

# Python 2, 63 bytes

```
l=map(input().count,'PNDQ')
a,b,c,d=l
print l+[a+b*5+c*10+d*25]

```

Try it online!

# Answer
> 4 votes
# APL (Dyalog Unicode), ~~28~~ 27 bytes

```
1 5 10 25(⊢,+.×)'PNDQ'+.=¨⊂

```

Try it online!

Tacit function. Takes input as a vector in the format `,'<input>'`.

Thanks to ngn for one byte!

### How?

```
1 5 10 25(⊢,+.×)'PNDQ'+.=¨⊂ ⍝ Main function, tacit.
                          ⊂ ⍝ Enclose
                         ¨  ⍝ Each character of the input
                      +.=   ⍝ Sum the number of matched characters
                'PNDQ'      ⍝ From this string
1 5 10 25(  +.×)            ⍝ Multiply the values with the left argument, then sum them.
          ⊢,                ⍝ And append to the original vector of coins.

```

# Answer
> 3 votes
# Japt, ~~25~~ 22 bytes

*Saved 3 bytes thanks to @Shaggy*

```
`p˜q`¬£èX
pUí*38#éìH)x
```

Test it online! Takes input in lowercase

### Explanation

```
`p˜q`¬         Split the compressed string "pndq" into chars, giving ["p", "n", "d", "q"].
      £        Map each char X to
       èX      the number of occurrences of X in the input.
<newline>      Set variable U to the resulting array.
 Uí*           Multiply each item in U by the corresponding item in
    38#é         38233
        ìH       converted to base-32, giving [1, 5, 10, 25].
           x   Take the sum.
p              Append this to the end of U.
               Implicit: output result of last expression

```

# Answer
> 3 votes
# Jelly, 19 bytes

```
ċÐ€“PNDQ”µæ.“¢¦½ı‘ṭ

```

Try it online!

### How it works

```
ċÐ€“PNDQ”µæ.“¢¦½ı‘ṭ    Main link. Arguments: s (string)
 Ð€“PNDQ”              For each char in "PNDQ":
ċ                        Count the occurrences of the char in s.
                       Collect the results in an array. Call this a.
         µ             Start a new monadic chain. Argument: a
          æ.           Take the dot product of a with
            “¢¦½ı‘       [1, 5, 10, 25].
                  ṭ    Tack this onto the end of a.

```

# Answer
> 3 votes
# MATL, ~~22~~ 20 bytes

```
!'PNDQ'=Xst[l5X25]*s

```

Try it online! Or verify all test cases.

### Explanation with example

Consider input `'PNNDNNQPDNPQND'` as an example. The stack contents are shown upside down, i.e. the top element appears below.

```
!        % Implicit input: string (row vector of chars). Transpose into a
         % column vector of chars
         % STACK: ['P';
                   'N';
                   'N';
                   'D';
                   'N';
                   'N';
                   'Q';
                   'P';
                   'D';
                   'N';
                   'P';
                   'Q';
                   'N';
                   'D']
'PNDQ'   % Push this string (row vector of chars)
         % STACK: ['P';
                   'N';
                   'N';
                   'D';
                   'N';
                   'N';
                   'Q';
                   'P';
                   'D';
                   'N';
                   'P';
                   'Q';
                   'N';
                   'D'],
                  'PNDQ'
=        % Implicit input. Test for equality, element-wise with broadcast
         % STACK: [1 0 0 0;
                   0 1 0 0;
                   0 1 0 0;
                   0 0 1 0;
                   0 1 0 0;
                   0 1 0 0;
                   0 0 0 1;
                   1 0 0 0;
                   0 0 1 0;
                   0 1 0 0;
                   1 0 0 0;
                   0 0 0 1;
                   0 1 0 0;
                   0 0 1 0]
Xs       % Sum of each column
         % STACK: [3 6 3 2]
t        % Duplicate
         % STACK: [3 6 3 2],
                  [3 6 3 2]
[l5X25]  % Push array [1 5 10 25]
         % STACK: [3 6 3 2],
                  [3 6 3 2],
                  [1 5 10 25]
*        % Multiply, element-wise
         % STACK: [3 6 3 2],
                  [3 30 30 50]
s        % Sum
         % STACK: [3 6 3 2],
                  113
         % Implicitly display

```

# Answer
> 3 votes
# APL+WIN, ~~33~~ 27 bytes

5 bytes saved thanks to Adam

Prompts for screen input of coin string.

```
n,+/1 5 10 25×n←+⌿⎕∘.='PNDQ'

```

# Answer
> 3 votes
# JavaScript (ES6), ~~63~~ 61 bytes

*Saved 2 bytes thanks to Shaggy*

Takes input as an array of characters. Outputs `P,N,D,Q,total`.
Inspired by ovs' Python answer.

```
a=>eval(a.join`++,`+`++,[P,N,D,Q,P+N*5+D*10+Q*25]`,P=N=D=Q=0)

```

Try it online!

---

# Original answer, 73 bytes

Takes input as an array of characters. Outputs `Q,D,N,P,total`.

```
a=>a.map(c=>o[o[4]+='521'[i='QDNP'.search(c)]*5||1,i]++,o=[0,0,0,0,0])&&o

```

Try it online!

# Answer
> 3 votes
## Excel (Polish language version), 150 bytes

The input is in A1. The formulas are in cells `B1`-`F1`:

```
cell  formula
------------------------------
B1    =DŁ(A1)-DŁ(PODSTAW(A1;"Q";""))
C1    =DŁ(A1)-DŁ(PODSTAW(A1;"D";""))
D1    =DŁ(A1)-DŁ(PODSTAW(A1;"N";""))
E1    =DŁ(A1)-DŁ(PODSTAW(A1;"P";""))
F1    =B1*25+C1*10+D1*10+E1

```

resulting in output of number of quarters, dimes, nickels, pennys and the sum in cells `B1`, `C1`, `D1`, `E1` and `F1` respectively.

**English language version (162 bytes):**

```
cell  formula
------------------------------
B1    =LEN(A1)-LEN(SUBSTITUTE(A1;"Q";""))
C1    =LEN(A1)-LEN(SUBSTITUTE(A1;"D";""))
D1    =LEN(A1)-LEN(SUBSTITUTE(A1;"N";""))
E1    =LEN(A1)-LEN(SUBSTITUTE(A1;"P";""))
F1    =B1*25+C1*10+D1*10+E1

```

# Answer
> 2 votes
# 05AB1E, ~~30~~ ~~26~~ ~~22~~ ~~21~~ 19 bytes

```
X5T25)s.•50†•S¢=*O=

```

Try it online!

---

```
X                   # Push 1.
 5                  # Push 5.
  T                 # Push 10.
   25               # Push 25.
     )s             # Wrap stack to array, swap with input.
       .•50†•       # Push 'pndq'.
             S      # Push ['p','n','d','q'] (split).
              ¢     # Count (vectorized).
               =    # Print counts, without popping.
                *   # Multiply counts by [1,2,10,25]
                 O  # Sum.
                  = # Print.

```

---

# Dump:

```
Full program: X5T25)s.•50†•S¢=*O=
current >> X  ||  stack: []
current >> 5  ||  stack: [1]
current >> T  ||  stack: [1, '5']
current >> 2  ||  stack: [1, '5', 10]
current >> )  ||  stack: [1, '5', 10, '25']
current >> s  ||  stack: [[1, '5', 10, '25']]
current >> .  ||  stack: [[1, '5', 10, '25'], 'pnndnnqpdnpq']
current >> S  ||  stack: [[1, '5', 10, '25'], 'pnndnnqpdnpq', 'pndq']
current >> ¢  ||  stack: [[1, '5', 10, '25'], 'pnndnnqpdnpq', ['p', 'n', 'd', 'q']]
current >> =  ||  stack: [[1, '5', 10, '25'], [3, 5, 2, 2]]
[3, 5, 2, 2]
current >> *  ||  stack: [[1, '5', 10, '25'], [3, 5, 2, 2]]
current >> O  ||  stack: [[3, 25, 20, 50]]
current >> =  ||  stack: [98]
98
stack > [98]

```

Printed Output:

```
[3, 25, 20, 50]\n98 or [P, N, D, Q]\n<Sum>

```

Because something was printed, the ending stack is ignored.

# Answer
> 2 votes
# C# (.NET Core), ~~163~~ 136 bytes

Thanks to @raznagul for saving alot of bytes there!

```
n=>{var m="";int c=0,i=0,k=0;for(var v=new[]{1,5,10,25};i<4;m+=k+",",c+=k*v[i++],k=0)foreach(var x in n)k+=x=="PNDQ"[i]?1:0;return m+c;}

```

Try it online!

---

Old version:

```
n=>{var v=new[]{1,5,10,25};string l="PNDQ",m="";int c=0,i,j,k;for(i=0;i<4;i++){for(j=0,k=0;j<n.Length;j++)k+=n[j]==l[i]?1:0;m+=k+",";c+=k*v[i];k=0;}m+=c;return m;}

```

Try it online!

# Answer
> 2 votes
# , 29 bytes

```
1 5 10 25(],1#.*)1#.'PNDQ'=/]

```

Try it online!

## Explanation:

`'PNDQ'=/]` creates an equality table

```
   'PNDQ' =/ 'PNNDNNQPDNPQND'
1 0 0 0 0 0 0 1 0 0 1 0 0 0
0 1 1 0 1 1 0 0 0 1 0 0 1 0
0 0 0 1 0 0 0 0 1 0 0 0 0 1
0 0 0 0 0 0 1 0 0 0 0 1 0 0

```

`1#.` finds the sum of each row of the table, thus the number of occurences of each value

```
   1#. 'PNDQ' =/ 'PNNDNNQPDNPQND'
3 6 3 2

```

`1#.*` finds the dot product of its left and right argument

```
    1 5 10 25(1#.*)3 6 3 2
113

```

`],` appends the dot product to the list of values

```
   1 5 10 25(],1#.*)1#.'PNDQ'=/] 'PNNDNNQPDNPQND'
3 6 3 2 113

```

# Answer
> 2 votes
# Vyxal, 18 bytes

```
«∨λð«fvO:»TM»₄τÞ•J

```

Try it Online!

```
«∨λð«fvO:»TM»₄τÞ•J
«∨λð«               # Compressed string "pndq"
     f              # Convert to list of characters
      vO            # For each, how many times does it appear in the input?
        :           # Duplicate it
         »TM»       # Compressed integer 21241
             ₄τ     # To base-26 as list: [1, 5, 10, 25]
               Þ•   # Dot product of this and the other list
                 J  # Append this to the list

```

# Answer
> 1 votes
# Pyth, ~~23~~ ~~27~~ 26 bytes

```
+Jm/Qd"PNDQ"s.b*NYJ[h05T25

```

Saved a byte thanks to @RK. Outputs as \[P, N, D, Q, value\].
Try it here

### Explanation

```
+Jm/Qd"PNDQ"s.b*NYJ[h05T25
 Jm/Qd"PNDQ"                Save the count of each coin (in PNDQ order) as J.
                   [h05T25  [1, 5, 10, 25].
             .b   J       For each pair of count and value...
               *NY          ... take the product...
            s               ... and get the sum.
+                          Stick that onto the list of counts.

```

# Answer
> 1 votes
# Perl 5 `-pF`, 59 bytes

```
for$i(P,N,D,Q){say s:$i:$\+={P,1,Q,25,D,10,N,5}->{$&}:eg}}{

```

Try it online!

# Answer
> 1 votes
# Ruby, 66 bytes

```
->s{t=0;{P:1,N:5,D:10,Q:25}.map{|c,v|t+=v*m=s.count(c.to_s);m}<<t}

```

Try it online!

Not great.

# Answer
> 1 votes
# 05AB1E, 19 bytes

```
"PNDQ"S¢D•Ωт•₂в*O)˜

```

Try it online!

**Explanation**

```
"PNDQ"                # push this string
      S               # split to list of chars
       ¢              # count the occurrences of each in input
        D             # duplicate
         •Ωт•         # push 21241
             ₂в       # convert to a list of base 26 digits
               *      # element-wise multiplication
                O     # sum
                 )˜   # wrap in a flattened list

```

# Answer
> 1 votes
# Java (OpenJDK 8), 148 bytes

```
c->{int q=0,d=0,n=0,p=0;for(char w:c){if(w=='Q')q++;if(w=='D')d++;if(w=='N')n++;if(w=='P')p++;}return ""+q+","+d+","+n+","+p+","+(q*25+d*10+n*5+p);}

```

Try it online!

Well it's only one byte shorter than the other Java submission, but hey- shorter is shorter :D

**Explanation:**

```
int q=0,d=0,n=0,p=0;    //Initialize too many integers
for(char w:c){    //Loop through each coin
  if(w=='Q')q++;if(w=='D')d++;if(w=='N')n++;if(w=='P')p++;    //Increment the correct coin
}return ""+q+","+d+","+n+","+p+","+(q*25+d*10+n*5+p);    //Return each coin count and the total monetary value

```

# Answer
> 1 votes
# Gol\>\<\>, 47 bytes

```
5R0TiE!vD;
5+@P@@t>b%m$.
a+$P$t
PrPrt
9s+r$P$rt

```

Try it online!

The output format is `[P Q N D Value]`.

### How it works

```
5R0TiE!vD;
       >b%m$.

5R0            Repeat command '0' (push 0) 5 times
   T           Set teleport location for later
    i          Input a char
     E         Pop if the last input was EOF; skip next otherwise

               If the last is EOF, the following is run:
      ! D;     Skip 'v', print the contents of the stack from bottom to top, then exit

               Otherwise the following is run:
       v
       >b%m$.  Take the top (input) modulo 11, and jump to (-1, input % 11)
               P%11 = 3, N%11 = 1, D%11 = 2, Q%11 = 4

5+@P@@t        Runs if the input is N
5+             Add 5 to top
  @            Rotate top 3 (the 3rd comes to the top)
   P           Increment the top
  @P@@         Increment the 3rd from top
      t        Teleport to the last 'T'

a+$P$t         Runs if the input is D
a+             Add 10 to top
  $            Swap top two
  $P$          Increment the 2nd from top
     t         Teleport to the last 'T'

PrPrt          Runs if the input is P
P              Increment the top
 r             Reverse the stack
 rPr           Increment the bottom
    t          Teleport to the last 'T'

9s+r$P$rt      Runs if the input is Q
9s+            Add 25 to the top ('s': add 16 to the top)
   r$P$r       Increment the 2nd from bottom
        t      Teleport to the last 'T'

```

# Answer
> 1 votes
# Perl 5 `-p`, 47 bytes

```
#!/usr/bin/perl -p
P1N5D10Q25=~s:\D:$\-=-$'*($n=s/$&//g);say$n:egr

```

Try it online!

# Answer
> 1 votes
# C (clang), 112 bytes

```
f(char *i){int c,d,v[5]={0};for(;c=*i++;v[d=(c|c/2)&3]++,v[4]+="AYJE"[d]-64);for(c=0;c<5;printf("%d,",v[c++]));}

```

Try it online!

Output seq is now of P,Q,D,N,total-value
Works with both lower-case and upper-case inputs.

**Explanation:**

`"AYJE"` or `{64+1,64+25,64+10,64+5}` is. 64+value-of-coin.
`d=(c|c/2)&3` (used as index) has value `1,2,3,0` for `q,d,n,p` inputs respectively, in both upper and lower case.

# Answer
> 1 votes
## Kustom, 146 bytes (sort of)

It's hard to find challenges where this language works lol

```
$tc(count,gv(i),P)$
$tc(count,gv(i),N)$
$tc(count,gv(i),D)$
$tc(count,gv(i),Q)$
$gv(P)$,$gv(N)$,$gv(D)$,$gv(Q)$,$gv(P)+gv(N)*5+gv(D)*10+gv(Q)*25$

```

This is technically not one script, instead each line except the last is a global value, counting one byte extra for the name of each global ("i", "P", "N", "D", and "Q").

# Answer
> 0 votes
# C# (.NET Core), 156 bytes

```
s=>{Func<char,int>f=i=>{return s.Split(i).Length-1;};var a=new[]{f('P'),f('N'),f('D'),f('Q')};return$"{string.Join(",",a)},{a[0]+a[1]*5+a[2]*10+a[3]*25}";};

```

# Answer
> 0 votes
# Java (OpenJDK 8), 149 bytes

```
a->{int[]c={0,0,0,0,0};for(String g:a){if(g=="P")c[0]+=1;if(g=="N")c[1]+=5;if(g=="D")c[2]+=10;if(g=="Q")c[3]+=25;}c[4]=c[0]+c[1]+c[2]+c[3];return c;}

```

Try it online!

# Answer
> 0 votes
# Retina, 50 bytes

```
P
P_
N
N5*
D
D10*
Q
Q25*
^
PNDQ_
O`.
(.)(\1*)
$.2¶

```

Try it online! Outputs in the order D, N, P, Q, total. Explanation:

```
P
P_
N
N5*
D
D10*
Q
Q25*

```

Calculate the total by inserting `_`s corresponding to the value of each coin.

```
^
PNDQ_

```

Insert an extra copy of each character so there is at least one of each to match.

```
O`.

```

Sort the characters into order.

```
(.)(\1*)
$.2¶

```

Count the number of each character after the first.

# Answer
> 0 votes
# SmileBASIC, 70 bytes

```
INPUT C$P=N+D+Q
WHILE""<C$INC VAR(POP(C$))WEND?P,N,D,Q,P+N*5+D*10+Q*25

```

Example:

```
? PNDNDNDQP
2   3   3   1   72

```

Explanation:

```
INPUT COINS$
P=N+D+Q 'create variables
WHILE COINS$>"" 'loop until the coin list is empty
 'pop a character from the coin list
 'and increment the variable with that name
 INC VAR(POP(COINS$))
WEND
PRINT P,N,D,Q,P+N*5+D*10+Q*25

```

# Answer
> 0 votes
# C, 149 bytes

```
f(char*s){int a[81]={},b[]={1,5,10,25},c=0;char*t,*v="PNDQ";for(t=s;*t;a[*t++]++);for(t=v;*t;printf("%d,",a[*t++]))c+=a[*t]*b[t-v];printf("%d\n",c);}

```

Try it online!

C doesn't have associative arrays, so I fake it (very inefficiently, memory-wise!) and then loop through again with a lookup array to add up the coins. It won't calculate foreign currency, though :-)

# Answer
> 0 votes
# Julia, 45 bytes

```
!s=(t=count.(["DNPQ"...],s);[t;[10 5 1 25]t])
```

Attempt This Online!

---
Tags: code-golf
---


title: ASCII Pizza (no pineapple)

text:
# Question
Title: ASCII Pizza (no pineapple)
I like pizza!

# Task

Given the radius of a pizza and a list of ingredients, create the corresponding ascii pizza!

Example size 4 pizza with mozzarella cheese, olives and ham:

```
  #####
 #@@@@M#
#H@O@@@@#
#M@@@H@@#
#@OO@@@@#
#@@H@@@@#
#M@M@@@@#
 #O@@@H#
  #####

```

# Input

A positive integer `r` for the size of the pizza and a (possibly empty) list of ingredients (non-empty strings). The list of ingredients can be given in a series of convenient formats, including but not limited to:

* a list of ingredients, such as `["tomato", "ham", "cheese"]`;
* a list of the initials, such as `["t", "h", "c"]`;
* a list of left- or right-padded ingredients, such as `["tomato", "ham ", "cheese"]` or `["tomato", " ham", "cheese"]`;
* a string with the initials, such as `"thc"`.

# Output specs

The pizza is built on a square of size `2r+1` characters, with the centre character having coordinates `(0,0)` for the purposes of this explanation. All characters in the square have integer coordinates. Then,

* a position is crust `#` if its coordinates `x,y` satisfy \\$r+1 \> \sqrt{x^2 + y^2} \geq r\\$;
* a position is dough `@` if its coordinates `x,y` satisfy \\$ r \> \sqrt{x^2+y^2}\\$.

Then, the ingredients must be put randomly on the pizza. Each ingredient will be represented by its initial and you must place `r` of each ingredient randomly in the dough characters. You can assume there will be enough space in the pizza. Ingredients cannot be placed on top of eachother, so in the final pizza there must be exactly `rl` non-dough symbols, in groups of `r`, if the ingredients list has size `l`.

For the randomness in the distributions of ingredients on top of the pizza, it suffices that for a fixed `r` and ingredient list, all ingredient distributions obeying the specs have non-zero probability of occurring.

# Examples

`r = 1`, no ingredients

```
###
#@#
###

```

---

`r = 2`, no ingredients

```
#####
#@@@#
#@@@#
#@@@#
#####

```

---

`r = 5`, no ingredients

```
  #######
 ##@@@@@##
##@@@@@@@##
#@@@@@@@@@#
#@@@@@@@@@#
#@@@@@@@@@#
#@@@@@@@@@#
#@@@@@@@@@#
##@@@@@@@##
 ##@@@@@##
  #######

```

---

`r = 4`, `ingredients = ["bacon", "mozzarela", "tomato"]`

```
  #####
 #@@b@m#
#@@@@@b@#
#@@@btb@#
#@@@@@@t#
#@@@@@@@#
#@mt@@@@#
 #t@mm@#
  #####

```

Reference implementation

Please include one or two of your favourite pizzas in your answer :)

---

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

# Answer
# APL (Dyalog Extended), ~~55~~ 53 bytesSBCS

−2 thanks to rabbitgrowth.

Anonymous infix lambda. Takes `r` as left argument () and ingredient initials as right argument ().

```
{i@((≢i←⍺/⍵)?≢⍸1=n)@{1=n}'@# '[n←(0⍺,⍺+1)⍸|∘.⌾⍨⍺…-⍺]}

```

\[Try it online!\]\[TIO-k6q7nk2n\]

`{``}` "dfn"; left argument  (leftmost Greek letter), right argument  (rightmost Greek letter)

`'@# '[``]` index the string with:

`-⍺` negate `r`

`⍺…` generate integer range from `r` to `-r`

`∘.⌾⍨` generate table of complex coordinates

`|` magnitudes

`(``)⍸` find the **ɩ**ndices of the \[a,b) **ɩ**ntervals in which the magnitudes fall:

`⍺+1` increment `r`

`0⍺,` prepend `[0,r]`

`n←` store in `n` (1: dough; 2: crust; 3: outside pizza)

`i@(``)@{1=n}` place the characters of `i` (to be defined) **at** the following subset of positions **at** which `n` is 1 (i.e. we have dough):

`1=n` mask where `n` is 1

**ɩ**ndices of trues

count them

`(``)?` pick the following number of random indices from 1 to that:

`⍺/⍵` replicate each ingredient initial letter to `r` copies

`i←` store in `i`

tally that
> 14 votes

# Answer
# MATL, ~~44~~ ~~43~~ ~~40~~ 34 bytes

```
Q_Zvqt!YytGQ<Zc64bG<(i1GY"7MfynZr(

```

Inputs are: `r` and a string with the initials of ingredients.

Try it online with ham, onion, pepper and mushroom! Or maybe try a diet pizza.

### Explanation with example

Consider inputs `3` and `'AP'`.

```
Q     % Implicit input: r. Add 1
      % STACK: 4
_Zv   % Symmetric inverse range
      % STACK: [4 3 2 1 2 3 4]
q     % Subtract 1, element-wise
      % STACK: [3 2 1 0 1 2 3]
t!    % Duplicate, transpose
      % STACK: [3 2 1 0 1 2 3], [3; 2; 1; 0; 1; 2; 3]
Yy    % Hypotenuse, element-wise with broadcast
      % STACK: [4.2426    3.6056    3.1623    3.0000    3.1623    3.6056    4.2426;
                3.6056    2.8284    2.2361    2.0000    2.2361    2.8284    3.6056;
                3.1623    2.2361    1.4142    1.0000    1.4142    2.2361    3.1623;
                3.0000    2.0000    1.0000         0    1.0000    2.0000    3.0000;
                3.1623    2.2361    1.4142    1.0000    1.4142    2.2361    3.1623;
                3.6056    2.8284    2.2361    2.0000    2.2361    2.8284    3.6056;
                4.2426    3.6056    3.1623    3.0000    3.1623    3.6056    4.2426]
t     % Duplicate.
      % STACK: [4.2426    3.6056    3.1623    3.0000    3.1623    3.6056    4.2426;
                3.6056    2.8284    2.2361    2.0000    2.2361    2.8284    3.6065;
                                                ···
                4.2426    3.6056    3.1623    3.0000    3.1623    3.6056    4.2426],
               [4.2426    3.6056    3.1623    3.0000    3.1623    3.6056    4.2426;
                3.6056    2.8284    2.2361    2.0000    2.2361    2.8284    3.6065;
                                                ···
                4.2426    3.6056    3.1623    3.0000    3.1623    3.6056    4.2426]
GQ<   % Less than r plus 1? Element-wise
      % STACK: [4.2426    3.6056    3.1623    3.0000    3.1623    3.6056    4.2426;
                3.6056    2.8284    2.2361    2.0000    2.2361    2.8284    3.6065;
                                                ···
                4.2426    3.6056    3.1623    3.0000    3.1623    3.6056    4.2426],
               [0 1 1 1 1 1 0;
                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;
                0 1 1 1 1 1 0]
Zc    % Replace 0 by space and 1 by '#'
      % STACK: [4.2426    3.6056    3.1623    3.0000    3.1623    3.6056    4.2426;
                3.6056    2.8284    2.2361    2.0000    2.2361    2.8284    3.6065;
                                                ···
                4.2426    3.6056    3.1623    3.0000    3.1623    3.6056    4.2426],
               [' ##### ';
                '#######';
                '#######';
                '#######';
                '#######';
                '#######';
                ' ##### ' ]
64    % Push 64 (ASCII for '@')
      % STACK: [4.2426    3.6056    3.1623    3.0000    3.1623    3.6056    4.2426;
                3.6056    2.8284    2.2361    2.0000    2.2361    2.8284    3.6065;
                                                ···
                4.2426    3.6056    3.1623    3.0000    3.1623    3.6056    4.2426],
               [' ##### ';
                '#######';
                '#######';
                '#######';
                '#######';
                '#######';
                ' ##### ' ],
               64
b     % Bubble up
      % STACK: [' ##### ';
                '#######';
                '#######';
                '#######';
                '#######';
                '#######';
                ' ##### ' ],
               64,
               [4.2426    3.6056    3.1623    3.0000    3.1623    3.6056    4.2426;
                3.6056    2.8284    2.2361    2.0000    2.2361    2.8284    3.6065;
                                                ···
                4.2426    3.6056    3.1623    3.0000    3.1623    3.6056    4.2426]
G<    % Less than r? Element-wise
      % STACK: [' ##### ';
                '#######';
                '#######';
                '#######';
                '#######';
                '#######';
                ' ##### ' ],
               64,
               [0 0 0 0 0 0 0;
                0 1 1 1 1 1 0;
                0 1 1 1 1 1 0;
                0 1 1 1 1 1 0;
                0 1 1 1 1 1 0;
                0 1 1 1 1 1 0;
                0 0 0 0 0 0 0]
(     % Write value 64 (that is, '@') into char matrix at positions indexed by mask
      % STACK: [' ##### ';
                '#@@@@@#';
                '#@@@@@#';
                '#@@@@@#';
                '#@@@@@#';
                '#@@@@@#';
                ' ##### ']
i     % Input: string
      % STACK: [' ##### ';
                '#@@@@@#';
                '#@@@@@#';
                '#@@@@@#';
                '#@@@@@#';
                '#@@@@@#';
                ' ##### '],
               'AP'
1GY"  % Push first input (r) again. Repeat each letter that many times
      % STACK: [' ##### ';
                '#@@@@@#';
                '#@@@@@#';
                '#@@@@@#';
                '#@@@@@#';
                '#@@@@@#';
                ' ##### '],
               'AAAPPP'
7Mf   % Push 0-1 mask again. Linear index (column-major order) of non-zero entries
      % STACK: [' ##### ';
                '#@@@@@#';
                '#@@@@@#';
                '#@@@@@#';
                '#@@@@@#';
                '#@@@@@#';
                ' ##### '],
               'AP',
               [9; 10; 11; ...; 41]
yn    % Duplicate from below. Number of elements
      % STACK: [' ##### ';
                '#@@@@@#';
                '#@@@@@#';
                '#@@@@@#';
                '#@@@@@#';
                '#@@@@@#';
                ' ##### '],
               'AAAPPP',
               [9; 10; 11; ...; 41]
               6
Zr    % Random sample without replacement (example result shown)
      % STACK: [' ##### ';
                '#@@@@@#';
                '#@@@@@#';
                '#@@@@@#';
                '#@@@@@#';
                '#@@@@@#';
                ' ##### '],
               'AAAPPP',
               [13; 18; 11; 24; 30; 25]
(     % Write 'AAAPPP' into char matrix at positions given by the linear indices
      % STACK: [' ##### '
                '#@@@P@#';
                '#@@P@@#';
                '#AAP@@#';
                '#@@@@@#';
                '#A@@@@#';
                ' ##### ']
      % Implicit display

```
> 7 votes

# Answer
# 05AB1E, ~~42~~ ~~41~~ ~~40~~ ~~38~~ 34 bytes

```
ÝRûãnOtï¹.S…# 1sèƶDþ.rI¹и'@Þ«‡¹·>ô

```

Output as a character-matrix.

-2 bytes because the specs changed (character-list input instead of ingredients-list).
-4 bytes thanks to *@Grimmy*.

Try it online or verify all test cases. (The footer  is to pretty-print the result. Feel free to remove it to see the actual character-matrix result.)

**Explanation:**

```
Ý              # Push a list in the range [0, (implicit) input-integer]
 R             # Reverse it to range [input, 0]
  û            # Palindromize this list (i.e. [3,2,1,0] → [3,2,1,0,1,2,3])
   ã           # Take the cartesian product with itself, to get a list of all coordinates
n              # Square both the x and y of each coordinate
 O             # Take the sum of each
  t            # And then the square-root of that
   ï           # Truncate it to an integer
    ¹.S        # And compare each to the first input
               # (-1 if larger than the input; 0 if equals; -1 if smaller)
       …# 1    # Push string "# 1"
           sè  # And index the list into this string, where the -1 is the trailing character
ƶ              # Multiply the 1s by their 1-based index
 Dþ            # Duplicate the list, and only leave the integers (the indices)
   .r          # And randomly shuffle those
     I         # Push the second input-list of ingredient-characters
      ¹и       # Repeat this list the first input amount of times
        '@Þ   '# Push an infinite list of "@"
           «   # Append it to the repeated ingredient-characters
            ‡  # Transliterate the shuffled indices to this list
¹·<            # Push the first input again; double it; and decrease it by 1
               # (alternative: `Dgt` - Duplicate; length; square-root)
   ô           # Split the list into parts of that size
               # (after which the resulting character-matrix is output implicitly)

```
> 6 votes

# Answer
# JavaScript (ES7),  ~~177 175~~  172 bytes

Takes input as `(r)(list)`, where *list* is filled with initials. Returns an array of characters.

```
r=>a=>a.map(i=>(g=i=>(s[p=Math.random()*r**3|0]!='@'||(s[p]=i,--n))&&g(i))(i,n=R),s=[...(g=x=>y+r?` #@
`[x+r?((d=x*x--+y*y)<r*r)+(d<R*R):(--y,x=R,3)]+g(x):'')(y=R=r++)])&&s

```

Try it online!

### Commented

```
r => a =>                     // r = radius, a[] = list of ingredients
  a.map(i =>                  // for each ingredient i in a[]:
    ( g = i => (              //   g is a recursive function taking i
        s[                    //     test s at
          p = Math.random()   //     a random position p in [0 .. r**3 - 1]
              * r**3 | 0      //
        ] != '@' ||           //     abort if it doesn't contain '@'
        (s[p] = i, --n)       //     otherwise, put the ingredient there and decrement n
      ) && g(i)               //     do a recursive call if the above result is truthy
    )(i, n = R),              //   initial call to g with i and n = R
    s = [...                  //   build the base pizza s[]
      ( g = x =>              //   g is another recursive function taking x
        y + r ?               //     if y is not equal to -r:
          ` #@\n`[            //       pick the relevant character:
            x + r ?           //         if x is not equal to -r:
              (               //
                (d = x * x--  //           d = x² + y²; decrement x
                   + y * y)   //
                < r * r       //           add 1 if it's less than r² (-> '#')
              ) +             //
              (d < R * R)     //           add 1 if it's less than R² (-> '@')
            :                 //         else:
              (y--, x = R, 3) //           decrement y, set x = R, append a linefeed
          ] +                 //
          g(x)                //       recursive call
        :                     //     else:
          ''                  //       stop recursion
      )(y = R = r++)          //   initial call to g with x = y = R = r; increment r
    ]                         //
  ) && s                      // end of map(); return s[]

```
> 3 votes

# Answer
# Python 3.8 (pre-release), ~~186~~ ~~177~~ 176 bytes

```
from random import*
def f(r,i=[],s=''):i=['@',*next(zip(*i),[])];t=range(-r,R:=r+1);print([s:=s+[' #'[(d:=x*x+y*y)<R*R],choice(i)][d<r*r]+'\n'*(x==r)for y in t for x in t][-1])

```

Try it online!
> 3 votes

# Answer
# Charcoal, ~~51~~ 48 bytes

```
Ｅ⊕θ⭆Ｅ⊕θ₂⁺×ιι×λλ⎇›θλ@§ #›⊕θλ‖Ｏ↑←ＦηＦθ§≔ＫＡ‽⌕ＡＫＡ@§ι⁰

```

Try it online! Link is to verbose version of code. Now supports full topping names by using a less convenient input format, but could save 2 bytes by switching back to initials. Explanation:

```
Ｅ⊕θ⭆Ｅ⊕θ₂⁺×ιι×λλ⎇›θλ@§ #›⊕θλ

```

Draw the bottom right hand quarter of the pizza base.

```
‖Ｏ↑←

```

Reflect to complete the pizza base.

```
ＦηＦθ

```

Loop through each topping repeatedly.

```
§≔ＫＡ‽⌕ＡＫＡ@§ι⁰

```

Find a random dough character and overwrite it with the first letter of the topping.
> 2 votes

# Answer
# Perl 5 `-al`, 153 bytes

```
@;=map{//;join"",map{($d=sqrt($_**2+$'**2))<$r?++$n&&1:$d>$r+1?$":"#"}@c}@c=-($r=<>)..$r;@F=((@F)x$r,("@")x($n-@F*$r));say s/1/splice@F,rand@F,1/gre for@

```

Try it online!

Takes the initials of the ingredients (space separated) on the first line of input and the radius on the second.
> 1 votes

---
Tags: code-golf, ascii-art, random
---


title: ASCII Character Jumble

text:
# Question
Title: ASCII Character Jumble
Write a program that takes as its input a string consisting of printable characters (ASCII 20-7E) and an integer `n` in \[2,16\] and performs the following modification to the string.

* Each character in the string is converted to its ASCII code (the examples given are in hexadecimal, though base 10 is also acceptable).
* The ASCII codes are converted to base `n` and are concatenated together.
* The new string is split every other character. If there are an odd number of characters, then the last character is removed entirely.
* Printing ASCII codes (in base 16) are converted back into their characters, whereas non-printing ASCII codes are removed.
* The resulting string is printed.

**Test case**

*Input*

```
Hello, World!
6

```

*Steps*

```
Hello, World!
48 65 6C 6C 6F 2C 20 57 6F 72 6C 64 21
2002453003003031125222330331030024453
20 02 45 30 03 00 30 31 12 52 22 33 03 31 03 00 24 45

```

The output of this program is  `E001R"31$E`.

---

This is code golf, so standard rules apply. Shortest code in bytes wins.

# Answer
# Pyth - 22 bytes

Hope to golf a lot more, pretty straightforward.

```
sfq3l`TmCid16csjRQCMz2

```

Try it online here.
> 5 votes

# Answer
# CJam, 33 bytes

```
q~:i\fb:~0+2/W<Gfb:c' ,-'ÿ),127>-

```

Takes input in the form `6 "Hello, World!"`. Test it here.

See Dennis's answer for a similar but better solution with a nice explanation.
> 4 votes

# Answer
# Bash + common linux utils, 118

```
printf %s "$1"|xxd -p|sed -r "s/../\U& /g;y/ /n/;s/^/dc -e$2o16i/e;s/../& /g;s/ .$//;"|xxd -rp|sed 's/[^[:print:]]//g'

```
> 3 votes

# Answer
# JavaScript (ES6), 137 ~~147~~

Using the most verbose functions available in JavaScript

```
f=(s,b)=>alert(s.replace(/./g,x=>x.charCodeAt().toString(b)).match(/../g).map(x=>(x=String.fromCharCode('0x'+x))<='~'&x>' '?x:'').join``)

// Just for test purpose, redefine alert()
alert=x=>document.write('<pre>'+x+'</pre>')

f('Hello, World!',6)
f('PORK',3)
```
> 2 votes

# Answer
# CJam, 24 bytes

```
l:irifbe_2/{Gbc',32>&}/

```

Note that there is a DEL character (0x7F) between `'` and `,`. Try it online in the CJam interpreter.

### How it works

```
l:i                     Read a line from STDIN and cast each char to integer.
   ri                   Read another integer (base) from STDIN.
     fb                 Convert each integer from line 1 to that base.
       e_2/             Flatten and split into chunks of length 2.
                        If the last chunk has only one element, it will get
                        converted into a control character, which will be
                        removed later.
          {         }/  For each digit pair:
           Gb             Convert the pair from base 16 to integer.
             c            Cast to character.
              ',          Push the string of ASCII characters up to '~'.
                32>       Remove the first 32 (control characters).
                   &      Intersect.

```
> 2 votes

# Answer
# Julia, 118 bytes

```
f(s,n)=join(map(i->(c=string(Char(parse(Int,i,16))))^isprint(c),matchall(r"..",join(map(i->base(n,Int(i)),[s...])))))

```

Ungolfed:

```
function f(s::AbstractString, n::Integer)
    # Construct an array of ASCII codes in base n
    v = map(i -> base(n, Int(i)), [s...])

    # Join into a string and get all pairs, truncating
    # to an even length
    m = matchall(r"..", join(v))

    # Parse each pair as an integer in base 16, get the
    # character associated with that code point, convert
    # to a string, and include if it's printable
    x = map(i -> (c = string(Char(parse(Int, i, 16)))^isprint(c), m)

    # Join as a string and return
    return join(x)
end

```
> 1 votes

# Answer
# TeaScript, 23 bytes

TeaScript is JavaScript for golfing

```
£lc¡T(y©K(2)ßC(P(l,16±µ

```

Relatively straight-forward but delightfully short. I can probably golf down a few more characters with some more operators. A few other new features might also be able to be used to cut down some bytes.

# Ungolfed && Explanation

```
x.l(#
    l.c().T(y)
).K(2)
.m(#
    C(
      P(l,16)
    )
).j``

```
> 1 votes

# Answer
# Mathematica, 134 bytes

```
Print@FromCharacterCode@Select[#~FromDigits~16&/@StringPartition[""<>ToCharacterCode@InputString[]~IntegerString~Input[],2],31<#<127&]

```

If a function is allowed:

### Mathematica, 112 bytes

```
FromCharacterCode@Select[#~FromDigits~16&/@StringPartition[""<>ToCharacterCode@#~IntegerString~#2,2],31<#<127&]&

```
> 1 votes

# Answer
# Ruby 92

```
->s,n{o=''
s.chars.map{|x|x.ord.to_s n}.join.scan(/../).map{|x|x>?2&&x<?8&&o<<x.to_i(16)}
o}

```

Online test here.
> 1 votes

# Answer
# Python 2, 174 bytes

```
def J(a,b,i=0):
 h=r=''
 B=lambda n,b:n*'x'and B(n/b,b)+chr(48+n%b+7*(n%b>9))
 for c in a:h+=B(ord(c),b)
 while i<len(h):v=int(h[i:i+2],16);r+=chr(v)*(31<v<127);i+=2
 print r

```

Try it here

Not really the best tool for the job. Since Python has no convert-to-arbitrary-base function, I had to implement my own. That was fun, at least--particularly finding a \[marginally\] shorter expression for the digits than `"0123456789ABCDEF"[n%b]`. For iterating over two characters at a time, I found a `while` loop was slightly shorter than a functional approach.

181 bytes as a full program:

```
B=lambda n,b:n*'x'and B(n/b,b)+chr(48+n%b+7*(n%b>9))
a=raw_input()
b=input()
h=r=''
for c in a:h+=B(ord(c),b)
i=0
while i<len(h):v=int(h[i:i+2],16);r+=chr(v)*(31<v<127);i+=2
print r

```
> 1 votes

# Answer
# Vyxal `s`, 13 bytes

```
C$vτHfṅǒHCkQ↔

```

Try it Online!
> 1 votes

# Answer
## MATLAB, 103 bytes

```
function k(s,n),b=dec2base(s,n)';b(~cumsum(b-'0',1))='';c=base2dec(textscan(b,'%2c'),16)';char(c(c>31))

```

I've written a function *k* that takes a string *s* and an integer *n* as input. e.g.:

```
k('Hello, World!',6)

```

gives

```
 E001R"31$E

```

Most annoying thing I had to work around is leading zeros showing up when converting to base *n*. Getting these out of the array that was to be split after every 2nd character cost quite a lot of bytes. Not sure if it is possible to save any more bytes using this approach.
> 0 votes

# Answer
## PHP - 286 bytes

Put the string in `$s` and the integer in `$b`.

```
<?php $s=$_GET["s"];$b;$m="array_map";echo implode($m(function($v){return ctype_print($v)?$v:"";},$m("chr",$m("hexdec",str_split(strlen(implode($a=$m(function($v){global$b;return base_convert($v,16,$b);},$m("dechex",$m("ord",str_split($s))))))%2==1?substr(implode($a),0,-1):$a,2)))));?>

```

Pass the value to `GET["s"]`.
> 0 votes

# Answer
# Ly, 26 bytes

```
ir[sp>lS<]>ry[puu' oy1G*]p

```

Try it online!

This code uses the `S` instruction to convert the codepoints to digits one input character at a time. Then it just prints pairs of digits delimited with spaces from the accumulation stack.

```
ir
i                          - read input as codepoints
 r                         - reverse stack
  [      ]                 - for each input char/codepoint...
   sp                      - stash codepoint and delete
     >l                    - switch to accum stack, load codepoint
       S                   - convert codepoint to digits
        <                  - switch back to input stack
          >r               - switch to accum stack, reverse digits
            y[          ]  - loop until stack size is <2
              p            - delete loop iterator artifact
               uu          - print two digits
                 ' o       - print a space
                    y1G    - is the stack size >1?
                       *   - multiple to combine top two of stack
                         p - print iterator artifact

```
> 0 votes

---
Tags: code-golf, string, number, printable-ascii, base-conversion
---


title: Number of binary partitions

text:
# Question
Title: Number of binary partitions
We all know that any positive integer can be represented as the sum of powers of two. This is how binary representations work. However there's not just one way to do this. The canonical method, used in binary representations represents it as the sum of *unique* powers of two. For example \\$5=2^0+2^2\\$. However since \\$2^0=1\\$ we can write any number just adding \\$2^0\\$. For example \\$5=2^0+2^0+2^0+2^0+2^0\\$.

How many ways are there to write a given number as the sum of powers of two? Let's write a program to see. We don't want to double count methods that are equivalent under associativity or commutativity, so \\$2^0+2^2\\$ and \\$2^2+2^0\\$ count as the same way because we've just changed the order.

Since this is sequence you may use any of the following IO formats where \\$f(n)\\$ is the number of ways to write \\$n\\$ :

* Take \\$n\\$ as input and output \\$f(n)\\$.
* Take \\$n\\$ as input and output \\$f(x)\\$ for \\$x\\$ up to \\$n\\$ in order.
* Output all \\$f(x)\\$ for every positive integer \\$x\\$ in order.

You may optionally choose to also include \\$f(0)\\$.

This is so the goal is to minimize the size of your source code as measured in bytes.

## Test cases

Here are the first 60 values:

```
1, 2, 2, 4, 4, 6, 6, 10, 10, 14, 14, 20, 20, 26, 26, 36, 36, 46, 46, 60, 60, 74, 74, 94, 94, 114, 114, 140, 140, 166, 166, 202, 202, 238, 238, 284, 284, 330, 330, 390, 390, 450, 450, 524, 524, 598, 598, 692, 692, 786, 786, 900, 900, 1014, 1014, 1154, 1154, 1294, 1294, 1460

```

More can be found at OEIS A018819

# Answer
> 15 votes
# Haskell, 22 bytes

```
l=scanl(+)1$(:[0])=<<l

```

Try it online!

Defines the infinite list `l` of `[f(1),f(2),...]`.

The OEIS says the generating function satisfies \\$A(x^2)=(1-x)A(x)\\$, which rearranges to \\$A(x) = \frac{1}{1-x}A(x^2) \\$. Starting with \\$A(x)\\$, we can interpret \\$A(x^2)\\$ as interspersing a zero after each element, `(:[0])=<<` in Haskell. Then, multiplying by \\$\frac{1}{1-x}\\$ is taking the cumulative sum `scanl1(+)`.

A small adjustment to omit the first initial `1` from the OEIS sequence is to do `scanl(+)1` instead. This also removes a circular dependency in defining that initial element, fixing the issue that \\$A(x) = \frac{1}{1-x}A(x^2) \\$ only defined \\$A\\$ up to a constant multiplier.

Now we put these together as `l=scanl(+)1$(:[0])=<<l`, which defines the elements of the infinite list `l`. Haskell's lazy evaluation allows this infinite list to be defined in terms of itself, as long as each element depends only on earlier elements, which is the case here.

# Answer
> 12 votes
# Python, 31 bytes

```
f=lambda n:n<2or f(n-2)+f(n//2)
```

Attempt This Online!

This can be derived from the recursion below by taking the difference between f(n) and f(n-2) which cancels most of the terms in the sum.

### Old Python, 42 bytes

```
f=lambda n:n<2or sum(map(f,range(n//2+1)))
```

Attempt This Online!

The "obvious" recursion.

### How?

First decide how many 1s. The remainder must be even and we can halve it and any partition of it. This can be done for any even remainder \<=n. The recurrence follows.

### Full program

#### Python, 40 bytes

```
t,*a=1,1
for i in a:print(i);t+=i;a+=t,t
```

Attempt This Online!

#### EDIT: Just seeing that @xnor posted the exact same program a bit earlier.

In theory produces the entire sequence (from term #1).

This can be either viewed as unrolling the recursion at the top of this post or --- as far as I understand --- as a port of the generating function approach a few answers have used. I can't know for sure because these languages are all esoteric to me.

# Answer
> 5 votes
# Perl, ~~83~~ ~~75~~ ~~73~~ ~~59~~ 58 bytes

*-14 bytes thanks to a recursive regex I discovered while working on Sum of Powers of 2*

```
sub{my$i;1x pop~~/^((\1|^.)(\2((?3))\4|))*$(??{++$i})/;$i}

```

Try it online!

This is definitely not the shortest possible Perl function by any means. But the idea here was to make a partition counter with all the logic in a regex, like my previous Fibonacci and Padovan answers.

This counts all the different ways the regex can make a complete match from start to finish, where the input number is provided to the regex in unary, as the length of a string of identical characters.

```
^                  # Anchor to the beginning of the string.
(                  # \1
    # Match \1 multiplied by any power of 2; this will be captured in \1 for use
    # by the next iteration. As such, the value of \1 can only increase to a
    # higher power of 2, or stay the same, but can never go down. In this way we
    # ensure against double counting methods that are equivalent under
    # associativity or commutativity.
    (\1|^.)        # \2 = the power of 2 used by the previous iteration, or 1 if
                   #      this is the first iteration
    (\2((?3))\4|)  # Match \2 * ({any power of 2} - 1)
)*
$                  # Assert we are at the end of the string. If we aren't, the
                   # regex will backtrack and try different power(s) of two to
                   # get here, and this failed attempt won't be counted.
(?{++$i})          # Perl embedded code to increment the partition counter.
\1                 # Attempt to match something that can never match, to force
                   # the regex engine to backtrack. A backreference is used
                   # because if we tried to use "^" or "z", the regex engine
                   # would do smart optimization, which we don't want.

```

The power of 2 logic is based on the regex `x(x((?1))\2|)` (Try it online!), except that the `x`s are replaced with `\2`, to ensure that it never matches a powers of 2 less than those matched on previous iterations of the main loop.

# Regex  (Perl / PCRE2 v10.34+), ~~47~~ ~~39~~ 25 bytes

```
^((\1|^x)(\2((?3))\4|))*$

```

Takes its input in unary, as a string of `x` characters whose length represents the number. Returns its output as the number of ways the regex can match. (The rabbit emoji indicates this output method. It can yield outputs bigger than the input, and is really good at multiplying.)

Try it online! \- Perl v5.28.2
Attempt This Online! \- Perl v5.36+
Attempt This Online! \- PCRE2 v10.40+

# Regex  (Perl / PCRE2), 41 bytes

```
^((?=(?(3)(\3)))((\2|^x)(\4((?5))\6|)))*$

```

Try it online! \- Perl
**Try it online! \- PCRE2 v10.33**
Attempt This Online! \- PCRE2 v10.40+

This is a port of the 25 byte regex. PCRE v10.33 and earlier automatically makes any group containing a nested backreference atomic, so this port works around that by enclosing the main group in a top level group, and copying backreference `\3` into `\2` inside a lookahead before entering group 3. The copy is done inside a conditional, because there isn't necessarily even going to be enough space to match `\3` in a lookahead, and if there isn't, the match on that iteration needs to fail.

# Regex  (Perl / PCRE), 55 bytes

```
^((?=(?(3)(\3)))((\2|^x)(?=(.*))((?(?=\5)\4|\6\6))*))*$

```

Try it online! \- Perl
**Try it online! \- PCRE1**
Try it online! \- PCRE2

PCRE1 complains `recursive call could loop indefinitely` on the 41 byte regex, and that can be worked around, as `^((?=(?(3)(\3)))((\2|^)(x\4((?5))\6|))x)*$` (42 bytes) which works on PCRE2, but the recursive method of matching arbitrary powers of 2 doesn't work on PCRE1 anyway, since it only has atomic subroutine calling. So this 55 byte regex is a port of the earlier **39 byte** non-recursive regex, `^((\1|^x)(?=(.*))((?(?=\3)\2|\4\4))*)*$`.

# Answer
> 4 votes
# Jelly, 5 bytes

```
Hß€S‘

```

A recursive, monadic Link that accepts a non-negative integer and yields the number of binary partitions.

**Try it online!** Or see the test-suite.

### How?

```
Hß€S‘ - Link: integer, n
H     - halve -> n/2
  €   - for each i in [1..floor(n/2)]:
 ß    -   call this Link with argument n=i
   S  - sum
    ‘ - increment

```

# Answer
> 3 votes
# Python, 40 bytes

```
f=lambda n:sum(map(f,range(1,n//2+1)))+1
```

Attempt This Online!

# Answer
> 3 votes
# C (gcc), 27 bytes

```
f(n){n=n<2?:f(n/2)+f(n-2);}

```

Try it online!

*Port of loopy walt's Python answer*

# Answer
> 3 votes
# HOPS, 17 bytes

```
A=1+x*(A+A@(x^2))
```

Attempt This Online!

Based on this formula on OEIS:

> G.f. A(x) satisfies A(x^2) = (1-x) * A(x). - Michael Somos, Aug 25 2003

# Answer
> 3 votes
# Python 3, 40 bytes

```
t,=l=[1]
for x in l:print(x);t+=x;l+=t,t

```

Try it online!

A program that prints the sequence forever. While longer than loopy walt's recursive function, I think this shows off an interesting method of generating the sequence on the fly by running an infinite loop by appending new elements to the list being iterated over, specifically, two copies of the current running sum starting at 1.

# Answer
> 2 votes
# Retina, 22 bytes

```
.+
*
+%Lw`^(_*)(?=\1)

```

Try it online! Link includes test cases. Explanation:

```
.+
*

```

Convert to unary.

```
Lw`^(_*)(?=\1)

```

Replace the input `n` with a list `0..n/2` inclusive.

```
+%`

```

Repeat the above expansion on every value in the list until it turns into a list of all zeros.

```

```

Output the length of the final list.

# Answer
> 2 votes
# APL, 19 bytes

```
{2≥⍵:⍵⋄1++/∇¨⍳⌊⍵÷2}

```

# Answer
> 1 votes
# Charcoal, 15 bytes

```
ＦＮ⊞υ∨¬ιΣ…υ⊕⊘ιＩυ

```

Try it online! Link is to verbose version of code. Outputs the first `n` values (0-indexed). Explanation:

```
ＦＮ

```

Repeat `n` times.

```
⊞υ∨¬ιΣ…υ⊕⊘ι

```

On the first iteration, just push `1` to the predefined empty list, otherwise push the sum of the first half of the list (inclusive).

```
Ｉυ

```

Output the resulting list.

# Answer
> 1 votes
# Ruby, 25 bytes

```
f=->n{1+(1..n/2).sum(&f)}

```

Try it online!

The "original" recursion in Ruby is 1 byte shorter than the optimized function by loopy walt.

# Answer
> 1 votes
# 05AB1E, 7 bytes

```
λN;ï₅₂+

```

Outputs the infinite sequence.
(Should have been 6 bytes without the `ï`, but apparently there is a bug in 05AB1E with decimal values and .)

Try it online.

**Explanation:**

```
λ        # Start a recursive environment,
         # to output the infinite sequence
         # (which is output implicitly at the end)
         # Implicitly starting at a(0)=1
         # Where every following a(n) is calculated as:
 N;      #  Push n/2
   ï     #  (bug workaround: truncate it to an integer)
    ₅    #  Pop and push a(n//2)
     ₂   #  Push a(n-2)
      +  #  Add them together: a(n//2)+a(n-2)

```

# Answer
> 1 votes
# Vyxal, 6 bytes

```
λ½vx∑›

```

Try it Online!

```
λ½vx∑›
λ      # Open a lambda for recursion: f(n)
 ½     #  Halve to n/2
  vx   #  For each x in [1..floor(n/2)], call f(x)
    ∑  #  Sum
     › #  Increment

```

---
Tags: code-golf, number, sequence, binary
---


title: Squash it ... again!

text:
# Question
Title: Squash it ... again!
If you place the positive integers together and read each set of two adjacent digits at the same time, you get: (A136414)

```
12, 23, 34, 45, 56, 67, 78, 89, 91, 10, 1, 11, ...

```

However, if you squash that sequence again:

```
12, 22, 23, 33, 34, 44, 45, 55, 56, 66, 67, 77, 78, 88, 89, 99, 91, 11, 10, 1, 11, 11

```

and so on.

Your task is to output the sequence of the positive integers ***squashed m times***.

# Squashing process

```
[1, 2, 3, 4, 5]
       ↓
    "12345"
       ↓
[12, 23, 34, 45]

```

Python squashing script

# Rules

* You have to receive m (a positive integer) as the input or you can output the sequences for all m
* Numbers in the sequence can appear more than once
* Leading zeros must be removed (eg. `04` is `4`)
* Default sequence rules
* Default Loopholes apply

# Test cases

```
[In]: 1
[Out]: [12, 23, 34, 45, 56, 67, 78, 89, 91, 10, 1, 11, 11, 12, 21, 13, 31, 14, 41, 15, ...]

[In]: 2
[Out]: [12, 22, 23, 33, 34, 44, 45, 55, 56, 66, 67, 77, 78, 88, 89, 99, 91, 11, 10, 1, 11, 11, 11, 11, 11, 12, 22, 21, 11, 13, 33, 31, 11, 14, 44, 41, 11, 15, ...]

[In]: 3
[Out]: [12, 22, 22, 22, 23, 33, 33, 33, 34, 44, 44, 44, 45, 55, 55, 55, 56, 66, 66, 66, 67, 77, 77, 77, 78, 88, 88, 88, 89, 99, 99, 99, 91, 11, 11, 11, 10, 1, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 12, 22, 22, 22, 21, 11, 11, 11, 13, 33, 33, 33, 31, 11, 11, 11, 14, 44, 44, 44, 41, 11, 11, 11, 15, ...]

```

# Answer
# Haskell, 49 bytes

```
f(x:z)=read[x,z!!0]:f z
q=[1..]:map(f.(>>=show))q

```

Attempt This Online!

Haskell loves infinite sequences. Here we get to make an infinite sequence of infinite sequences.

The function `f` takes infinite string of digits and produces numbers formed from the pairs in order. We combine this with `(>>=show)` to get a function which takes an infinite sequence and produces the next. We use recursion to create the infinite list of such sequences starting with `[1..]`.
> 13 votes

# Answer
# 05AB1E, 7 bytes

```
∞IFSü«ï

```

Given \\$m\\$, output the infinite \\$m^{th}\\$ sequence.

Try it online or verify the first 25 results of the first 5 \\$m\\$.

**Explanation:**

```
∞        # Push the infinite list of positive integers: [1,2,3,...]
 IF      # Loop the input `m` amount of times:
   S     #  Convert the list of integers to a flattened list of digits
    ü    #  For each overlapping pair of digits:
     «   #   Append them together
      ï  #  Convert it back to an integer to remove the leading 0s
         # (after which the result is output implicitly)

```
> 6 votes

# Answer
# Python 3.8, ~~121~~ 119 bytes

```
lambda m,n:m<1and n or(n*0==[]or(n:=range(1,n)))and(d:=''.join(map(str,n)))and z(m-1,[int(i+j)for i,j in zip(d,d[1:])])

```

Try it online!

`m` is the number of squashes applied and `n` controls the length of the output.

---

Same idea, except split over two functions (and somehow the exact same number of characters):

```
lambda m,n:y(m,range(1,n))
y=lambda m,a:m<1and a or(d:=''.join(map(str,a)))and y(m-1,[int(i+j)for i,j in zip(d,d[1:])])

```

Try it online!
> 6 votes

# Answer
# APL(Dyalog Unicode), 21 bytes SBCS

Anonymous infix lambda, taking `m` as left argument and the number of elements of the sequence to generate as right argument.

```
{⍵↑{⍎¨2,/∊⍕¨⍵}⍣⍺⍳1+⍵}

```

`{``}` "dfn";  is `m` and  is the number of elements to generate.

`1+⍵` increment the number of elements (to handle the case of 1)

generate the **i**ntegers 1…`m`+1

`{``}⍣⍺` repeat application of the following function, `m` times:

`⍕¨⍵` format each number in the sequence

enlist (flatten)

`2,/` concatenate adjacent characters

`⍎¨` evaluate each

`⍵↑` take as many elements as requested

Try it on APLgolf!
> 5 votes

# Answer
# JavaScript (Node.js), 64 bytes

```
f=(m,n)=>n?[...f(m,n-1),m--?+f(m,n+2).join``.substr(n-1,2):n]:[]

```

Try it online!
> 4 votes

# Answer
# Husk, 11 bytes

```
!¡ȯmdẊeṁdN→

```

Try it online!
> 4 votes

# Answer
# Jelly, 11 bytes

```
ị+D€FVƝƊ⁹¡¥

```

Try it online!

1-indexed, takes \\$m\\$ on the right and \\$n\\$ on the left to give the \\$n\\$th term of the sequence.

It seems like there should be a non-naive method as well, but the patterns that manifest in the single digits may not be as real as they seem.

```
        ⁹¡     Repeat m times
 +        ¥    starting with n + m:
  D€           digits of each
   €           (implicitly rangifies on first iteration),
    F          flatten,
     VƝ        concatenate each pair of adjacent digits into an integer.
ị              Get the n'th element of the result.

```
> 4 votes

# Answer
# Burlesque, 20 bytes

```
J+.ro{im2CO}3MVE!j.+

```

Try it online!

```
J    # Duplicate M
+.ro # Range [1..M+1]
{
 im  # Implode (concatenate digits)
 2CO # Chunks with overlap length 2 ("ABC"2CO -> "AB" "BC")
}
3MV  # Move the 3rd item (N) to top of stack
E!   # Evaluate that many times
j.+  # Keep the top M numbers

```

# Burlesque, 13 bytes (invalid violates default sequence rules)

```
ro{im2CO}x/E!

```

Try it online!

```
ro    # Range 1..N
{
 im   # Implode (concatenate digits)
 2CO  # Chunks with overlap length 2 ("ABC"2CO -> "AB" "BC")
}
x/    # Reorder stack putting `m` on top
E!    # Eval `m` times

```
> 4 votes

# Answer
# Python 2, 96 bytes (@math junkie)

```
def f(n,c=0):
 while n<1:c+=1;yield c
 for s in f(n-1):
  for b in`s`:
    if c:yield int(c+b)
    c=b
```

Attempt This Online!

TIL: Apparently one can mix spaces and tabs in Python 2.

### Old Python 2, 101 bytes

```
def f(n,c=0):
 while n<1:c=c+1;yield c
 for s in f(n-1):
  for b in`s`:
   if c:yield int(c+b)
   c=b
```

Attempt This Online!
> 4 votes

# Answer
# Vyxal, 10 bytes

```
Tɾ$(ṅ2lĖ)Ẏ

```

Try it Online!

Takes `number of items to generate` then `how many times to squash`
> 2 votes

# Answer
# Jelly, 12 bytes

```
‘RDFṡ2ḌƲ⁴¡³ị

```

Try it online!
> 2 votes

# Answer
# Rust + Itertools, 249 bytes

```
use itertools::*;let f=|s:Box<dyn std::iter::Iterator<Item=u32>>|Box::new(s.flat_map(|a|(0..=a.log10()).rev().map(move|t|a/10u32.pow(t)%10)).tuple_windows().map(|k:(u32,u32)|k.0*10+k.1));let g=|n|{let mut k=f(Box::new(1..));for _ in 0..n{k=f(k)};k};

```

Playground link: https://play.rust-lang.org/?version=nightly&mode=debug&edition=2021&gist=11fa065d958a13e4a9d68dc2de7b9b12
> 2 votes

# Answer
# Java 10, ~~143~~ 139 bytes

```
n->m->{int r[]=new int[n],i,j=0;for(;j++<m;){var s="";for(i=0;i<n;r[i]=new Byte(s.substring(i,i+++2)))s+=j<2?i-~i+""+-~i*2:r[i];}return r;}

```

Takes inputs \\$n,m\\$ and outputs the first \\$n\\$ values of the \\$m^{th}\\$ sequence.

Try it online.

**Explanation:**

```
n->m->{                  // Method with two integer parameters & integer-array result
  int r[]=new int[n],    //  Create the result-list of `n` amount of 0s
      i,                 //  Index-integer `i`, uninitialized for now
  j=0,i;for(;j++<m;){    //  Loop `j` in the range [1,m):
    var s="";            //   String `s`, starting empty
    for(i=0;i<n          //   Inner loop `i` in the range [0,n):
        ;                //     After every iteration:
         r[i]=           //      Replace the i'th value in the result-array to:
           new Byte(     //       Convert the following String to an integer,
                         //       (to put it in the integer-array & to remove leading 0s)
            s.substring( //        A substring of String `s`,
              i,i+++2))) //        in the character index-range [i,i+2)
                         //        (and increase `i` by 1 afterwards with `i++`)
      s+=                //    Append to String `s`:
         j<2?            //     If `j` is 1, thus the first iteration of loop `j`:
             i-~i        //      Append (2*i+1) to the String
             +""+-~i*2   //      as well as (2*i+2)
                         //      (so the .substring-indices won't be out-of-bounds)
           :             //     Else:
            r[i];        //      Append the i'th integer of the result-array instead
  }return r;}            //  After the loops: return the result-array

```
> 2 votes

# Answer
# Pyth, 16 bytes

```
LsM.:jkb2<yFShQE

```

Try it online!

Takes `n` (number of elements to generate) then `m` on separate lines.

```
LsM.:jkb2<yFShQE
L                 Create a lambda with variable b:
     jkb           - Concatenate elements of b
                     (e.g. [1,2,3,4] -> "1234")
   .:   2          - Produce all 2-element sub-strings
                     (e.g. "1234" -> ["12","23","34"])
 sM                - Convert to integers
                     (e.g. ["12","23","34"] -> [12,23,34])
            ShQ   Range from 1 to n+1
          yF   E  Apply the above lambda m times
         <        Keep the first n elements

```
> 1 votes

# Answer
# lin, 41 bytes

```
$`1`d \; `it
\ns `' `flat2`xp \; `'
`_` N

```

Try it here! Generates an infinite list of infinite lists.

Pretty-printed output version (run with `-i` flag if using local interpreter):

```
; ( 40`t ) `' 10`t `__ wrap_
$`1`d \; `it
\ns `' `flat2`xp \; `'
`_` N

```

lin is a stack-based language I began working on a few years back, but have recently been dusting off with new features and inspirations.

## Explanation

* `$` 1`d` push infinite list `[1..]`
* `\; `it` iterate infinitely...
    + `\ns `' `flat` convert each number to digit list and flatten
    + `2`xp \; `'` pairwise map...
        - ``_` N` convert pair to number
> 1 votes

# Answer
# Python 2, 102 bytes

```
def z(m,n):a=range(1,n);exec'd="".join(map(str,a));a=[int(i+j)for i,j in zip(d,d[1:])];'*m;return a[m]

```

Try it online!

It's not the shortest Python 2 script here, but the approach is very different to @loopy walt's so I thought it was worth sharing anyways.

The first version of the code, when given an input *n*, returned a sequence containing at least the first *n* elements, but @math junkie pointed out that this is not allowed in the sequence rules.
> 0 votes

---
Tags: code-golf, math, sequence
---


title: All Possible Ties in Tic-Tac-Toe

text:
# Question
Title: All Possible Ties in Tic-Tac-Toe
Your task is to output all possible ways to end a game with a tie (all rows, columns, and diagonals are completely filled and do not have 3 X's or 3 O's, and there are exactly 5 X's and 4 O's in total) in Tic-Tac-Toe (assuming X goes first):

```
OXO  XXO  XOX  OXX
XOX  OOX  XOX  XOO
XOX  XXO  OXO  OXX

XOX  XOX  OXX  XXO
OOX  XOO  XOO  OOX
XXO  OXX  XOX  XOX

XOX  OXX  OXO  XOO
XXO  XXO  OXX  OXX
OXO  OOX  XOX  XXO

OXO  XXO  XOX  OOX
XXO  OXX  OXX  XXO
XOX  XOO  OXO  OXX

```

(It does not need to be arranged in the above way.)

## Rules

* Output can be in any convenient format.
* You may use different characters to represent X and O as long as they are distinct.
* Standard loopholes are forbidden.
* This is , so the shortest code in bytes wins.

# Answer
# Jelly,  ~~16~~  15 bytes

```
“œNZjr⁽⁾ƈ‘+⁹BUƬ

```

A niladic Link that yields a list of lists of lists (a 2 by 8 array of flattened boards) with `1`s representing `X`s and `0`s representing `O`s.

**Try it online!** Or see them in the format and order given in the question here.

### How?

Using only reflection in one axis is terser than using four rotational symmetries like in my original 16-byte code (below).

```
“œNZjr⁽⁾ƈ‘+⁹BUƬ - Link: no arguments
“œNZjr⁽⁾ƈ‘      - Code page indices = [30,78,90,106,114,141,142,156]
          +⁹    - add 256 -> [286, 334, 346, 362, 370, 397, 398, 412]
            B   - to binary
              Ƭ - collect up while distinct applying:
             U  -   reverse each

```

---

##### Previous @16 bytes:

```
“⁾⁽ʠ⁷‘ḤBs€3ZṚ$Ƭ€

```

A niladic Link that yields a list of lists of lists of lists (a 4 by 4 array of 2d boards) with `1`s representing `O`s and `0`s representing `X`s.

**Try it online!** Or see them in the format and order given in the question here.

### How?

```
“⁾⁽ʠ⁷‘ḤBs€3ZṚ$Ƭ€ - Link: no arguments
“⁾⁽ʠ⁷‘           - Code page indices = [142,141,165,135]
      Ḥ          - double -> [284,282,330,270]
       B         - to binary -> [[1,0,0,0,1,1,1,0,0],
                                 [1,0,0,0,1,1,0,1,0],
                                 [1,0,1,0,0,1,0,1,0],
                                 [1,0,0,0,0,1,1,1,0]]
        s€3      - split each into threes -> [[[1,0,0],
                                               [0,1,1],
                                               [1,0,0]],
                                              [[1,0,0],
                                               [0,1,1],
                                               [0,1,0]],
                                              [[1,0,1],
                                               [0,0,1],
                                               [0,1,0]],
                                              [[1,0,0],
                                               [0,0,1],
                                               [1,1,0]]]
               € - for each:
              Ƭ  -   collect up while distinct applying:
             $   -     last two links as a monad:
           Z     -       transpose  }
            Ṛ    -       reverse    } - together these rotate a quarter

```
> 12 votes

# Answer
# Desmos, ~~142~~ ~~138~~ ~~123~~ ~~120~~ ~~112~~ 111 bytes

-8 bytes thanks to @fireflame

-1 byte thanks to @Steffan

```
X=x-[0...3]4+.5
\mod([23312905373,30555191537,48690981746,53478745886]/2^{3\floor(y)+\floor(X)},2)>.99\{0<X<3\}

```

Try It On Desmos!
> 7 votes

# Answer
# ///, 97 bytes

```
/g/ \/\///a/OXOgb/XXOgc/XOXgd/OXXge/XOOgf/OOX /abcdccdbcdaeabcf
cfcefeefbbddbddb
cbadbdccafcbcead

```

Try it online!

I tried rearranging them so that more duplicates would appear together but it didn't save any bytes. I'm sure theres more that can be done here though. Good luck to whoever takes this on in Regenerate, I did not have the guts.

Note: /// programs do not take any input, so don't worry about the input being used in the TIO link, lol.
> 6 votes

# Answer
# Vyxal, 17 bytes

```
»~qǔ:ṙ⁋»₆τ¦₈+b:RJ

```

Try it Online! Port of 05AB1E thanks to Steffan.

```
          ¦       # Cumulative sums of...
        ₆τ        # Base 64 digits of...
»~qǔ:ṙ⁋»          # Compressed integer
           ₈+     # + 256
             b    # Convert each to binary
              :RJ # Append each matrix reversed

```
> 5 votes

# Answer
# Ruby, ~~90 ...~~ 45 bytes

```
"s*.-0	".bytes{|k|puts"%09b"%$.+=k}

```

Try it online!

## How it works:

* If we can flatten the array, this means we only have to output 16 numbers between 115 and 412.
* Instead of using the numbers directly, I sort them and use the successive difference. This limits the range to 1-115, which is within the boundaries of ASCII
> 5 votes

# Answer
# , ~~113~~ ~~111~~ 110 bytes

*Edit: -1 byte, and from that idea -1 more, and then another -1 more, all thanks to pajonk*

```
for(i in 0:511)sum(a<-matrix(i%/%2^(0:8)%%2,3))==5&all(rowSums(rbind(a,t(a),diag(a),a[1:3*2+1]))%%3)&&print(a)

```

Try it online!

Outputs tic-tac-toe matrices using `1`s for Xs and `0`s for Os.

Calculates 3x3 matrices of binary digits of 0...511, and checks whether any of the column sums, row sums, diagonal or antidiagonal are equal to zero modulo 3 (meaning that they're all Xs (3 = 0 mod 3) or all 0s (0)).
> 5 votes

# Answer
# 05AB1E, ~~25~~ ~~19~~ ~~18~~ 15 bytes

```
•“ª?’ì¦¾Ô*•bº9ô

```

-9 bytes thanks to *@CommandMaster*

Outputs the results as a list of flattened strings, each consisting of nine `1`/`0` for `X`/`O` respectively.

Try it online. (Feel free to remove the footer that pretty-prints the results to see the actual result.)

**Explanation:**

```
•“ª?’ì¦¾Ô*• # Push compressed integer 2639961594228296764259
  b         # Convert it to binary: 100011110001110011010011101010101101010110101011100011011100101101100011
   º        # Mirror it: 100011110001110011010011101010101101010110101011100011011100101101100011110001101101001110110001110101011010101101010101110010110011100011110001
    9ô      # Split it into parts of size 9: ["100011110","001110011","010011101","010101101","010110101","011100011","011100101","101100011","110001101","101001110","110001110","101011010","101101010","101110010","110011100","011110001"]
            # (after which the list is output implicitly as result)

```

See this 05AB1E tip of mine (section *How to compress large integers?*) to understand why `•“ª?’ì¦¾Ô*•` is `2639961594228296764259`.
> 2 votes

# Answer
# Python 3, 64 bytes

* -2 bytes suggested by pxeger.

```
for i in'ƍŎţåĞŲñƎŪãƜŚsµ':print(f"{ord(i):09b}")

```

Try it online!

A really boring answer. Or 65 bytes without unprintable.

---

And this is a (somehow) interesting 94 bytes answer:

```
print(*["OXOOXXOX\n"[int(i):][:3]for i in str(0x2267c4d16c9d1787f15058d56ba14c7aacee2a628cf)])

```

-2 bytes suggested by G B. Maybe it can be golfed more.
> 2 votes

# Answer
# brainf\***, 264 bytes

```
-.-.+.-.+.-..+.-.>.<..+...-...+.>.<.-...+...-..>.<.+.-.+..-...+.>.<.-...+..-.+.-.>.<.+.-..+...-..>.<..+...-..+.-.>.<.+.-...+..-.+.>.<.-....+...-.>.<.+.-.+.-..+.-.+.>.<.-.+..-...+.-.>.<.+...-....+.>.<.-.+.-..+.-.+.-.>.<..+..-...+..>.<..-...+..-..>.<.+.-..+.-.+.-.+.

```

Try it online!

Outputs the games separated by nulls. `ÿ` is `O` and `þ` is `X`.
It's hard-coded, manipulating address 1 to switch between `255` (`ÿ`) and `254` (`þ`) as needed. After each game, `>.<` moves the pointer to address 2, prints `0` (null), and returns to address 1. A few bytes were saved by modifying the order of the games.
> 2 votes

# Answer
# Charcoal, 31 bytes

```
Ｆ⪪”{∨I⦄↶r↘G”⁹«⎚⪪ι³Ｆ⁴«Ｄ⟲»»‖Ｆ³«Ｄ⟲

```

Try it online! Link is to verbose version of code. Outputs all 16 3×3 boards consecutively without vertical separation. Explanation:

```
Ｆ⪪”{∨I⦄↶r↘G”⁹«

```

Split the compressed string `OXOXOXXOXXOXOOXXXOXOXXXOOXO` into three substrings of 9 letters and loop over each substring.

Clear the canvas.

```
⪪ι³

```

Split the substring into three substrings of three letters and print each on its own line.

```
Ｆ⁴«

```

Repeat four times:

Output the current canvas state.

Rotate the canvas.

```
»»‖

```

Reflect the last board.

```
Ｆ³«Ｄ⟲

```

Manually output three rotations, and allow the final rotation to implicitly print.

Since the output is difficult to read, here's a 38 byte version which spaces out the boards: Try it online! Link is to verbose version of code.
> 1 votes

# Answer
# Brachylog, 51 bytes

```
ṁ₃{{0|1}ᵐ².c+5∧.{|\|↺ʰ↻ᵗ{bᵐhᵐg}|↺ᵗ↻ʰ↰₄}ᶠ{⊇Ċ≠}ᵐ²∧}ᶠd

```

Try it online!

Absurdly long but at least it's not boring hardcoding. I'm sure there are shorter ways to describe the constraints of the matrix.

### Explanation

```
ṁ₃                                 Take a 3x3 matrix
  {                          }ᶠ    Find all:
   {0|1}ᵐ².                          The matrix is filled with 0s and 1s
   .c+5∧                             The sum of all elements is 5
   .{                      }ᶠ        Find all:
     |                                 The original matrix
      \|                               The transpose
        ↺ʰ↻ᵗ{bᵐhᵐg}|                   The anti-diagonal
                    ↺ᵗ↻ʰ↰₄             The diagonal
   {⊇Ċ≠}ᵐ²∧                          Each row must have at least two different elements
d                                   Remove duplicates

```
> 1 votes

# Answer
# lin, 50 bytes

```
\OX9`/\ \ƎŪãŖţåƍŲñĞµƜŚs <chars g:

```

Try it here! Generates a list of lists where each row is a tied board.

Copy-paste-friendly version for testing (includes pretty-printing):

```
\OX9`/\ ; g: ((( 3cols ( str outln ) map ) ' n\ outln ) map ) '
[173 398 362 227 342 355 229 397 370 241 157 286 181 412 346 115]

```

## Explanation

* `\OX9`/\` get all length-9 sequences of X's and O's
* `\... <chars` convert string to charcodes
* `g:` use charcodes as indices in list of length-9 sequences
> 1 votes

# Answer
# Rust, 168 bytes

```
let g=|m|[7,292,146,180,56,448,73,448,84,273].iter().all(|b|b&m!=*b);let f=||(0..512).filter(|m:&u16|m.count_ones()==4&&g(*m)&&g(!m)).fold((),|_,b|print!("{b:0>9b}
"));
```

Attempt This Online!

Prints the result in binary. 1=X and 0=O
> 0 votes

# Answer
# Retina 0.8.2, 97 bytes

```

9$*0512$*
1
¶$`
+`(1+)\1
$+0
01
1
.+(.{9})
$1
G`(1.*){5}
...
[$&]
A`(\d)(.)*\1(?<-2>.)*(?(2)^)\1

```

Try it online! Outputs each board with the rows marked in the format `[101][101][010]` using `1` for `X` and `0` for `O`. Explanation:

```

9$*0512$*
1
¶$`

```

Count up to 511 in unary, with padding. (`0` gets listed twice, but we'll delete that later anyway.)

```
+`(1+)\1
$+0
01
1

```

Convert to binary.

```
.+(.{9})
$1

```

Trim the result back down to 9 digits.

```
G`(1.*){5}

```

Keep those with (at least) 5 `X`s. (Boards with 6 or more `X`s will always have at least one winning line so will get eliminated anyway.)

```
...
[$&]

```

Split into three groups of three.

```
A`(\d)(.)*\1(?<-2>.)*(?(2)^)\1

```

Omit boards which aren't ties (i.e. wins or invalid). See my answer to Tic-Tac-Toe - X or O? for how the regular expression works.
> 0 votes

# Answer
# Perl 5 `-Mbigint`, 65 bytes

```
say for 0xce63b1b72b558eb54e8f3c5cae35aab53a73->to_bin()=~/.{9}/g

```

Try it online!

Uses `1` for `X` and `0` for `O`; Outputs flat strings, one grid per line.
> 0 votes

---
Tags: code-golf, kolmogorov-complexity, tic-tac-toe
---


title: Where can the cannon go?

text:
# Question
Title: Where can the cannon go?
# Introduction

The game of xiangqi, also known as Chinese chess, is a chess-like game popular in China, Vietnam, Taiwan, and other East Asian countries. The colours of the two sides in xiangqi are red and black. There are seven pieces in xiangqi: the general (`G`), advisor (`A`), elephant (`E`), horse (`H`), chariot (`R`), cannon (`C`), and soldier (`S`). For the purposes of this challenge, uppercase pieces are considered red and lowercase pieces black. Most of these pieces have a rough equivalent in Western chess, but there is one completely unique piece: the cannon.

The cannon moves like a rook in chess or a chariot in xiangqi (moving any number of spaces on either the X or Y axes), but cannot attack this way. Instead, it attacks by jumping along the X or Y axes (the same way it moves) over **one** piece of any colour (friend or foe) and landing on the opposite-coloured piece, which it then captures. Note that like all chess and xiangqi pieces, cannons cannot capture pieces of their own colour.

For example, in the following diagram, the spaces to which the cannon (`C`) can move are marked with `*`, and those to which it can jump and capture are marked with `X`, assuming that there is a black/lowercase piece there.

```
....X....
.........
.........
....h....
....*....
****C**aX
....E....
....X....
....g....
....R....

```

# Challenge

Write a program or function that, given a xiangqi board and the coordinates of a cannon on that board as input, outputs a list of coordinates to which the cannon can move or jump.

The format for all I/O is flexible.

Acceptable formats for the xiangqi board include a newline-separated string, a list of strings, or a string with any other separator not in `aceghrsACEGHRS.`. You may assume the board will always be 9x10, the size of a xiangqi board.

The contents of the board itself will consist of a number of periods (`.`), representing empty points on the board, and characters representing pieces. The piece-to-character mapping is as follows:

```
A -> advisor
C -> cannon
E -> elephant
G -> general
H -> horse
R -> chariot
S -> soldier

```

Uppercase letters represent red pieces, and lowercase letters represent black pieces. Characters not listed here (i.e. not in `aceghrsACEGHRS.`) will not appear in the board.

The format of the input coordinate is flexible, and is not required to match the format of the output coordinates. It can be a list of two integer elements, a 2-tuple, two numbers with any separator, or two characters, for example. It may also be either 0-indexed or 1-indexed. You may assume that the coordinate on the board will always resolve to a cannon (`C` or `c`).

The coordinates to which the cannon can jump and move must appear in the same list in output; distinction between the two is not necessary. Acceptable formats for any individual output coordinates are the same as those for the input coord. The coordinates may be newline-separated, output as a list, or any other representation. No particular order is necessary; the order does not even have to be deterministic.

Note that jumps onto a piece of the same colour (case) of the cannon are not legal, and thus cannot appear in the output.

# Test cases

Note that not all of the test cases are possible xiangqi positions.

```
Input board
Input coordinate (0-indexed)
List of output coordinates

.........
.........
.........
.........
.........
....C....
.........
.........
.........
.........
(4, 5)
[(0, 5), (1, 5), (2, 5), (3, 5), (5, 5), (6, 5), (7, 5), (8, 5), (4, 0), (4, 1), (4, 2), (4, 3), (4, 4), (4, 6), (4, 7), (4, 8), (4, 9)]

.........
.....G...
.........
.........
.....e...
.........
.........
h..R.c..S
.....a...
.........
(5, 7)
[(4, 7), (6, 7), (7, 7), (5, 6), (5, 5), (5, 1)]

..s......
..A...e..
.........
EACCcsh.H
..r......
.....S...
......s..
....C....
..g......
(2, 3)
[(2, 0), (2, 2), (4, 3), (2, 8)]

rheagaehr
.........
.c.....c.
s.s.s.s.s
.........
.........
S.S.S.S.S
.C.....C.
.........
RHEAGAEHR
(7, 7)
[(2, 7), (3, 7), (4, 7), (5, 7), (6, 7), (8, 7), (7, 0), (7, 3), (7, 4), (7, 5), (7, 6), (7, 8)]

```

# Scoring

This is , so the shortest answer (in bytes) wins. Happy golfing!

# Answer
> 3 votes
## Pip, 112 + 1 = 113 bytes

Takes input as command-line arguments: the two coordinates, followed by the 10 lines of the board. Coordinates are 0-based. Outputs coordinates like `67 77`, with a newline between the same-row list and the same-column list. One byte added for the `-s` flag.

```
g@>:2P(f:{Ya@bQ'C?X^z;X^AZa@b:'@aR`\.*@\.*`{aR'.s}Ry.`\.*\w *@`s._@>1R`@ *\w\.*`.y_@<v.s@*s}g@ba).ba.(f;J(Zga)b)

```

Try it online!

### Explanation of somewhat ungolfed version

```
g@>:2
f:{
 Y a@bQ'C ? `[a-z]` `[A-Z]`
 a@b:'@
 aR:`\.*@\.*` {aR'.s}
 aR:y.`\.*\w *@` s._@>1
 aR:`@ *\w\.*`.y _@<v.s
 a@*s
}
P (f g@b a).b
a.(f; J(Zg)@a b)

```

By default, Pip reads command-line args into the list `g`. It also stores the first five arguments in the variables `a` through `e`. Our first two arguments, `a` and `b`, are the coordinates of the cannon; `g` contains the coordinates followed by the rows of the board. To get just the board in `g`, we slice it from index 2 onward and assign back to `g` (`g@>:2`).

Now we define a function `f`. This function takes two arguments: a string representing a row or column of the board, and the index of the cannon in that string. These arguments are available inside the function as `a` and `b`. The function will return a list of all indices that represent spots the cannon can move to or capture.

First, we test whether `a@b` is `C` or `c`. If it's `C`, we're going to want the regex `[a-z]` to match the pieces it can capture. If it's `c`, the regex is `[A-Z]`. (The golfed code generates these regexes from the builtin variables for lower- and uppercase alphabet.) We `Y`ank the appropriate regex into the `y` variable.

We change the cannon's character in the string to `@` (to distinguish it from other cannons in the same row/column).

Next comes a series of regex replacements, which will change every place the cannon can go to a space character. The first regex `\.*@\.*` matches `@` surrounded by any number of periods, all of which represent empty spots to which the cannon can move. The replacement uses a callback function `{aR'.s}` to change all the periods to spaces.

The next regex matches a piece the cannon can capture: either `[a-z]` or `[A-Z]` (depending on which one was yanked into `y` earlier) followed by `\.*\w *@` (any number of periods, one letter, any number of spaces, and `@`). This will match a string like `h..R @` (provided the cannon was `C`). The callback function `s._@>1` slices the first character off and prepends a space.

The third regex is similar, but matches a capturable piece after the cannon rather than before it.

Finally, the function returns `a@*s`, using the find-all operator to get a list of the indices of all spaces.

We now call `f` on the cannon's row and again on the cannon's column. The row's string is `g@b`, with the cannon's index inside the string being `a`. The function returns a list of column numbers, to each of which we append the row number `b`. When the list is printed, the `-s` flag puts a space between the coordinate pairs.

To get the column, we use the `Z`ip operator to transpose `g`, select index `a`, and `J`oin the resulting list of characters into a string. The cannon's index within this string is `b`. The function returns a list of row numbers, to each of which we prepend the column number `a`. This list, being the last expression in the program, is autoprinted.

<sub>(In case anyone was wondering, the expression separator `;` is there to force `J` to parse as a unary operator rather than binary.)</sub>

# Answer
> 2 votes
# Python3, 309 bytes:

```
def f(t,b):
 q=[(*t,0,b[t[0]][t[1]],*i)for i in[(0,1),(0,-1),(1,0),(-1,0)]]
 while q:
  x,y,d,c,X,Y=q.pop(0)
  if 0<=(j:=x+X)<len(b)and 0<=(k:=y+Y)<len(b[0])and d<2:
   if'.'==(S:=b[j][k])and d==0:yield(j,k)
   if'.'!=S and S.isupper()!=c.isupper()and d:yield(j,k);d=2
   q+=[(j,k,[d,1][d<2 and'.'!=S],c,X,Y)]

```

Try it online!

# Answer
> 0 votes
# Python 2, 238 bytes

```
def f(b,r,c,R=range):
 for K in[[(i,c)for i in I]for I in R(r+1,10),R(r)[::-1]]+[[(r,j)for j in J]for J in R(c+1,9),R(c)[::-1]]:
  p=0
  for i,j in K:
	B=b[i][j];Z='.'<B*p;p+='.'<B
	if(p<1)+Z*((b[r][c]<'c')!=('a'>B)):print i,j
	if Z:break

```

Try it online!

#### Ungolfed (301 bytes)

```
def g(a,b,I):
 p=0
 for i,j in I:
  B=b[i][j]
  if p:
   if'A'>B:continue
   if('a'>B)!=a:print(i,j)
   break
  p='.'<B
  if p<1:print(i,j)
def f(b,r,c):
 a=b[r][c]<'c'
 for I in[range(r+1,10),range(r-1,-1,-1)]:g(a,b,[(i,c)for i in I])
 for J in[range(c+1,9),range(c-1,-1,-1)]:g(a,b,[(r,j)for j in J])

```

Try it online!

---
Tags: code-golf, chess, board-game
---


title: Add a hidden language to a polyglot

text:
# Question
Title: Add a hidden language to a polyglot
Inspired/mostly copied but I don't think it's a dupe. Also Inspired.

In this challenge, you will create polyglots that include all languages from previous answers, *and* another language which you won't share and others must guess.

The first language prints 1, the second prints 2, etcetera.

For example, if the first answer was this:

```
print(1)

```

You could crack it as Python 3 (or numerous other languages), then you could write another answer that prints 2 in, say, Befunge-93:

```
2<3 and print(1)#@.2

```

Try it online!

Then, the next person to answer would first have to figure out that this was written in Befunge-93 before posting an answer that printed 1 in Python 3, 2 in Befunge-93 and 3 in a language of their choice. Feel free to share a crack if you don't want to post an answer.

To keep this challenge fluid, you must reveal your language if it has been uncracked for a week, at which point anyone can post another answer.

Please, be nice and try to post answers in languages which can be easily polyglotted.

# Rules

* The criteria for a valid programming language are the same as those of The Programming Language Quiz, Mark II - Cops:

>
* Each answer must run in less than a minute on a reasonable PC.
* Different versions of a language / languages with different flags / whatever are valid as long as you can get them to behave differently. However, flags must be revealed to avoid obscure combinations.
* Cracking a submission consists of finding *any* programming language that prints the correct result, not just the intended one. If a submission is run in any language that was not declared or found to work, there are no requirements to do anything, and future answers must be valid in that language.

## I/O clarifications

The program must output a decimal integer, optionally as a float with a `.0` afterwards. Any reasonable amount of leading/trailing whitespace is acceptable, as is stuff unavoidably printed by the interpreter, or formatting for the integer. Anything else is not.

Ending with an error is allowed as long as that error is printed to stderr, and not standard output - it can't be printed with the number.

## Scoring

The person with the most answers wins.

A chatroom's been created for this challenge.

# Answer
> 9 votes
# 9. Deadfish~, 116 bytes, cracked by pxeger

The previous answer was in Runic Enchantments, but I don't have enough reputation to comment yet.

```
4+0#  @ iiiiiiiiio
print(8-(2*5-3)+(1/2)*10)#+++++P #++++++++++++++++++++++++++++++++++++++++++++++++++.
0+0#  ^
5_3

```

Try it online in:

# Answer
> 7 votes
# 10. FISHQ9+, 137 bytes, cracked by accident

```
4+0#  @ iiiiiiiiio
print(8-(2*5-3)+(1/2)*10+8-4*(2147483647*2%3))#+++++P #++++++++++++++++++++++++++++++++++++++++++++++++++.
0+0#  ^
5_3

```

The previous answer works in Deadfish~.

Try it online in:

---

My intended crack was Crystal before version 0.31.0, which is when Crystal got integer overflow checking by default.

This also works with the version of Crystal on TIO, with `-D disable_overflow`: Try it online!, but I didn't want to reveal that flag (which the rules would have required), so I chose to use an old version of Crystal instead.

(this flag appears to have been removed entirely in the latest versions of Crystal: Attempt This Online!)

# Answer
> 7 votes
# 11. Neutrino, 144 bytes

```
4+0#  @ iiiiiiiiio
print(8-(2*5-3)+(1/2)*10+8-4*(2147483647*2%3))#+++++P #++++++++++++++++++++++++++++++++++++++++++++++++++.
0+0#  ^
-1*-10+4_3

```

Try it online in Ruby, Jelly, Vyxal, rSNBATWPL, Headass, Python 3, brainfuck, Runic Enchantments, Deadfish~. FISHQ9+. I created this interpreter to make testing easier for others, but it also works with the Kotlin implementation that pxeger's answer works with.

Pxeger's post was (not intentionally) in FISHQ9+, using the kotlin interpreter `.jar` file supplied on the esolangs page, run with `java -jar`. When running the REPL and entering the code:

```
######@######## downloads % java -jar FISHQ9P.jar
>> 4+0#  @ iiiiiiiiio
print(8-(2*5-3)+(1/2)*10+8-4*(2147483647*2%3))#+++++P #++++++++++++++++++++++++++++++++++++++++++++++++++.
0+0#  ^
5_310

```

It prints 10 (without a leading newline) after the code. To avoid making testing hell for everyone in future, I will shortly be adding a FISHQ9+ interpreter to DSO.

This works because the `iiiiiiiiio` from answer #9 prints 9, but FISHQ9+ merges HQ9+'s `+` command in which increments it one more time to 10 before printing. Nothing else is printed.

# Answer
> 6 votes
# 7. brainfuck, Exactly 100 Bytes, cracked by aiden chow and continued by Kevin Cruijssen

The last answer was Python 3.

```
print(8 - (2 * 5 - 3) + (1/2) * 10)#+++++P #+++++++++++++++++++++++++++++++++++++++++++++++++++.
5_3

```

# Answer
> 5 votes
# 1. Ruby, 9 bytes, cracked by caird coinheringaahing

```
$><<$$/$$

```

The answer to start things off. Should be fairly easy.

# Answer
> 5 votes
# 4. rSNBATWPL, 26 bytes

```
print(8 - (2 * 5 - 3))
5_3

```

The previous answer was in Vyxal

# Answer
> 5 votes
# 5. Headass, 34 bytes, cracked by emanresu A

```
print(8 - (2 * 5 - 3))#++++++P
5_3

```

Previous answer was in Radvylf Should Not Be Allowed To Write Programming Languages

Thanks emanresu A for adding my language to your web-site :D

# Answer
> 5 votes
# 12. BitCycle, 170 bytes, cracked by Dingus

```
4+0#a /z@ iiiiiiiiio
print(8-(2*5-3)+(1/2)*10+1+1+1+1+1+1+1+1+1+1+1-1-1-1-1-1-1-1-1-1-1-1)#!+++++P #++++++++++++++++++++++++++++++++++++++++++++++++++.
0+0#a ^
-1*-10+4_3

```

Try It Online in Ruby, Jelly, Vyxal, rSNBATWPL, Headass, Python 3, Brainfuck, Runic Enchantments, Deadfish~, FishHQ9+, Neutrino

The code is ran under the `-u` flag. Very easy, definitely gonna get cracked within a few minutes.

# Answer
> 4 votes
# 2. Jelly, 11 bytes, cracked by Steffan

```
$><<$$/$$
2

```

The previous answer was written in Ruby:

Try it online!

# Answer
> 4 votes
# 8. Runic Enchantments, 105 bytes, cracked by 00Her0

```
4+0#  @
print(8-(2*5-3)+(1/2)*10)#+++++P #++++++++++++++++++++++++++++++++++++++++++++++++++.
0+0#  ^
5_3

```

Since *@AidenChow* cracks answers without posting a new one, I took the liberty to post the next in line.

1. Try it online in Ruby.
2. Try it online in Jelly.
3. Try it online in Vyxal.
4. Try it online in Radvylf Should Not Be Allowed To Write Programming Languages.
5. Try it online in Headass.
6. Try it online in Python 3.
7. Try it online in brainfuck.

# Answer
> 4 votes
# 14. Vanilla TeX (initex), 256 bytes, mostly cracked by emanresu A

```
1#+iiiiiiiiiokh-\catcode`\#=6\font\m=cmr10\m
14#\end;
4+0#a /z@ MoOMoOMoOMoOMoOMoOMoO
print(8-(2*5-3)+(1/2)*10+1+1+1+1+1+1+1+1+1+1+1-1-1-1-1-1-1-1-1-1-1-1)#!+++++P #++++++++++++++++++++++++++++++++++++++++++++++++++.
0+0#a ^MoOMoOMoOMoOMoOMoOOOM
-1*-10+4_3

```

This is now available on ATO!

> You can run this on ATO here.

Try it online in:

1. Ruby
2. Jelly
3. Vyxal
4. rSNBATWPL
5. Heada\**
6. Python 3
7. Brainf\***
8. Runic Enchantments
9. Deadfish~
10. FISHQ9+
11. Neutrino
12. BitCycle
13. COW

# Answer
> 4 votes
# 21. PingPong, 294 bytes, cracked by Aiden Chow

```
1# 2:0+:@ iiiiiiiiiokh \#+++++++++++++++O \font\m=cmr10\m14\end ;n+3e
4+0# MoOMoOMoOMoOMoOMoOMoOMoOMoOMoOMoOMoOMoOOOM h$1 o$ h$8 o$
print(8-(2*5-3)+(1/2)*10+1+1+1+1+1+1+1+1+1+1+1-1-1-1-1-1-1-1-1-1-1-1) #!+++++P #+++++++++++++++++++++++++++++++++.-#19$#&
0+0#;print{4} >8z@ S5^7^MOAOF
-1*-10+4_3

```

Try it online!

That's right, the code didn't change at all. Lol

Try it online in Ruby Jelly Vyxal rSN Heada\** Python 3 Brainf\*** Runic Enchantments Deadfish~ FISHQ9+ Neutrino BitCycle COW TeX Brainf\***+ RunR \>\<\> xEec Versert

# Answer
> 3 votes
# 3. Vyxal, 15 bytes, cracked in literally 30 seconds by emanresu A

```
$><<$$/$$
2+3_3

```

The previous answer was written in Jelly.

Try it online in Jelly.

Try it online in Ruby.

# Answer
> 3 votes
# 6. Python 3, 46 bytes, cracked by aiden chow and continued by Nobody

```
print(8 - (2 * 5 - 3) + (1/2) * 10)#+++++P
5_3

```

The previous answer was in Headass.

For the sake of everyone else doing this:

Try it online in Ruby!
Try it online in Jelly!
Try it Online in Vyxal!
Try It Online in rSNBATWPL!
Try It Online in Headass!

# Answer
> 3 votes
# 16. RunR, 286 bytes

```
1#+iiiiiiiiiokh\#+++++++++++++++O\>#\catcode`\#=6\font\m=cmr10\m
14#\end;
4+0#a /z@ MoOMoOMoOMoOMoOMoOMoO
print(8-(2*5-3)+(1/2)*10+1+1+1+1+1+1+1+1+1+1+1-1-1-1-1-1-1-1-1-1-1-1)#!+++++P #++++++++++++++++++++++++++++++++++++++++++++++++++.
0+0#a ^MoOMoOMoOMoOMoOMoOOOMS5^7^MOAOF
-1*-10+4_3

```

# Answer
> 3 votes
# 17. \>\<\>, 329 bytes, cracked by stasoid

```
1#+iiiiiiiiiokh\#+++++++++++++++O\>#\catcode`\#=6\font\m=cmr10\m%\3e
14#\end;                                   ';
4+0#a /z@ MoOMoOMoOMoOMoOMoOMoO            'n
print(8-(2*5-3)+(1/2)*10+1+1+1+1+1+1+1+1+1+1+1-1-1-1-1-1-1-1-1-1-1-1)#!+++++P #++++++++++++++++++++++++++++++++++++++++++++++++++.
0+0#a ^MoOMoOMoOMoOMoOMoOOOMS5^7^MOAOF      \                    \
-1*-10+4_3

```

Try it online in Ruby Jelly Vyxal rSN Heada\** Python 3 Brainf\*** Runic Enchantments Deadfish~ FISHQ9+ Neutrino BitCycle COW TeX Brainf\***+ RunR

# Answer
> 3 votes
# 18. xEec, 271 bytes, cracked by 00Her0

```
1#+iiiiiiiiiokh \#+++++++++++++++O \font\m=cmr10\m14\end ;n+3e
4+0# MoOMoOMoOMoOMoOMoOMoOMoOMoOMoOMoOMoOMoOOOM
print(8-(2*5-3)+(1/2)*10+1+1+1+1+1+1+1+1+1+1+1-1-1-1-1-1-1-1-1-1-1-1) #!+++++P #+++++++++++++++++++++++++++++++++.
0+0# >8z@ S5^7^MOAOF h$1 o$ h$8 o$
-1*-10+4_3

```

Previous answer works in \>\<\>.

# Answer
> 3 votes
# 20. Versert, 294 bytes

```
1# 2:0+:@ iiiiiiiiiokh \#+++++++++++++++O \font\m=cmr10\m14\end ;n+3e
4+0# MoOMoOMoOMoOMoOMoOMoOMoOMoOMoOMoOMoOMoOOOM h$1 o$ h$8 o$
print(8-(2*5-3)+(1/2)*10+1+1+1+1+1+1+1+1+1+1+1-1-1-1-1-1-1-1-1-1-1-1) #!+++++P #+++++++++++++++++++++++++++++++++.-#19$#&
0+0#;print{4} >8z@ S5^7^MOAOF
-1*-10+4_3

```

#19 is AsciiDots.

Fixed rSNBATWPL code according to this.

# Answer
> 2 votes
# 13. COW 214 bytes, cracked by Dingus

```
4+0#a /z@ iiiiiiiiiokhMoOMoOMoOMoOMoOMoOMoO
print(8-(2*5-3)+(1/2)*10+1+1+1+1+1+1+1+1+1+1+1-1-1-1-1-1-1-1-1-1-1-1)#!+++++P #++++++++++++++++++++++++++++++++++++++++++++++++++.
0+0#a ^MoOMoOMoOMoOMoOMoOOOM
-1*-10+4_3

```

Pretty easy, should get cracked fast. I don't know enough languages :/. Try it online in: Ruby Jelly Vyxal rSNBATWPL Heada\** Python 3 Brainf\*** Runic Enchantments Deadfish~ FISHQ9+ Neutrino BitCycle

# Answer
> 2 votes
# 15. BrainF\*ck+, 430 bytes, Should Be Very Easily Cracked By whqwert

```
1#+iiiiiiiiiokh-\ #+++++++++++++++O\ >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>14#+iiiiiiiiiokh-\catcode`\#=6\font\m=cmr10\m
14#\end;
4+0#a /z@ MoOMoOMoOMoOMoOMoOMoO
print(8-(2*5-3)+(1/2)*10+1+1+1+1+1+1+1+1+1+1+1-1-1-1-1-1-1-1-1-1-1-1)#!+++++P #++++++++++++++++++++++++++++++++++++++++++++++++++.
0+0#a ^MoOMoOMoOMoOMoOMoOOOM
-1*-10+4_3

```

For this language it ends in an error, but that is supposed to be allowed.

# Answer
> 2 votes
# 19. AsciiDots, 278 Bytes, Cracked by stasoid

```
1#+iiiiiiiiiokh \#+++++++++++++++O \font\m=cmr10\m14\end ;n+3e
4+0# MoOMoOMoOMoOMoOMoOMoOMoOMoOMoOMoOMoOMoOOOM
print(8-(2*5-3)+(1/2)*10+1+1+1+1+1+1+1+1+1+1+1-1-1-1-1-1-1-1-1-1-1-1) #!+++++P #+++++++++++++++++++++++++++++++++.-#19$#&
0+0# >8z@ S5^7^MOAOF h$1 o$ h$8 o$
-1*-10+4_3

```

Try it online in Ruby Jelly Vyxal rSN Heada\** Python 3 Brainf\*** Runic Enchantments Deadfish~ FISHQ9+ Neutrino BitCycle COW TeX Brainf\***+ RunR \>\<\> xEec

---
Tags: code-challenge, cops-and-robbers, polyglot, answer-chaining, obfuscation
---