title: Compute the RFC 2550 timestamp

text:
# Question
Title: Compute the RFC 2550 timestamp
RFC 2550 is a satirical proposal (published on April 1, 1999) for a space-efficient ASCII representation of timestamps that can support any date (even those prior to the beginning of the universe and those past the predicted end of the universe). The algorithm for computing a RFC 2550-compliant timestamp is as follows (note: all ranges include the start but exclude the end - 0 to 10,000 means all `n` where `0 <= n < 10000`):

* **Year format**
* Years 0 to 10,000: a 4-digit decimal number, left-padded with zeroes.
* Years 10,000 to 100,000: a 5-digit decimal number, prefixed with the character A.
* Years 100,000 to 1030: the decimal number for the year, prefixed with the uppercase ASCII letter whose index in the English alphabet is equal to the number of digits in the decimal year, minus 5 (B for 6-digit years, C for 7-digit years, etc.).
* Years 1030 to 1056: the same format as 10,000 to 1030, starting the letters over with A, and additionally prefixing a caret (`^`) to the string (so the year 1030 is represented by `^A1000000000000000000000000000000`, and the year 1031 is represented by `^B10000000000000000000000000000000`).
* Years 1056 to 10732: the year is prefixed by two carets and two ASCII uppercase letters. The uppercase letters form a base-26 number representing the number of digits in the year, minus 57.
* Years 10732 onwards: the same format for 1056 to 10732 is used, extending it by adding an additional caret and uppercase letter when necessary.
* BCE years (prior to Year 0): compute the year string of the absolute value of the year. Then, replace all letters by their base-26 complement (A \<-\> Z, B \<-\> Y, etc.), replace all digits by their base-10 complement (0 \<-\> 9, 1 \<-\> 8, etc.), and replace carets with exclamation marks (`!`). If the year string is 4 digits or less (i.e. -1 to -10,000), prepend a forward slash (`/`). If the year string is not prefixed by a forward slash or an exclamation mark, prepend an asterisk (`*`).
* **Months, days, hours, minutes, and seconds**: since these values are only ever 2 digits at the most, they are simply appended to the right of the year string, in decreasing order of significance, left-padded with zeroes if necessary to form 2-digit strings.
* **Additional precision**: if additional precision (in the form of milliseconds, microseconds, nanoseconds, etc.) is needed, those values are left-padded with zeroes to 3 digits (because each value is `1/1000` of the previous value, and thus is at most `999`) and appended to the end of the timestamp, in decreasing order of significance.

This format has the benefit of lexical sorting being equivalent to numeric sorting of the corresponding timestamp - if time A comes before time B, then the timestamp for A will come before the timestamp for B when lexical sorting is applied.

##The challenge

Given an arbitrarily-long list of numeric values (corresponding to time values in decreasing order of significance, e.g. `[year, month, day, hour, minute, second, millisecond]`), output the corresponding RFC 2550 timestamp.

##Rules

* Solutions must work for any given input. The only limitations should be time and available memory.
* Input may be taken in any reasonable, convenient format (such as a list of numerics, a list of strings, a string delimited by a single non-digit character, etc.).
* The input will always contain at least one value (the year). Additional values are always in decreasing order of significance (e.g. the input will never contain a day value without a month value, or a second value followed by a month value).
* Input will always be a valid time (e.g. there won't be any timestamps for February 30th).
* Builtins which compute RFC 2550 timestamps are forbidden.

##Examples

These examples use input as a single string, with the individual values separated by periods (`.`).

```
1000.12.31.13.45.16.8 -> 10001231134516008
12.1.5.1 -> 0012010501
45941 -> A45941
8675309.11.16 -> C86753091116
47883552573911529811831375872990.1.1.2.3.5.8.13 -> ^B478835525739115298118313758729900101020305008013
4052107100422150625478207675901330514555829957419806023121389455865117429470888094459661251.2.3.5.7.11 -> ^^BI40521071004221506254782076759013305145558299574198060231213894558651174294708880944596612510203050711
-696443266.1.3.6.10.15.21.28 -> *V3035567330103061015021028
-5342 -> /4657
-4458159579886412234725624633605648497202 -> !Q5541840420113587765274375366394351502797

```

##Reference implementation

```
#!/usr/bin/env python

import string

# thanks to Leaky Nun for help with this
def base26(n):
    if n == 0:
        return ''
    digits = []
    while n:
        n -= 1
        n, digit = divmod(n, 26)
        digit += 1
        if digit < 0:
            n += 1
            digit -= 26
        digits.append(digit)
    return ''.join(string.ascii_uppercase[x-1] for x in digits[::-1])

year, *vals = input().split('.')

res = ""
negative = False

if year[0] == '-':
    negative = True
    year = year[1:]

if len(year) < 5:
    y = "{0:0>4}".format(year)
elif len(year) <= 30:
    y = "{0}{1}".format(string.ascii_uppercase[len(year)-5], year)
else:
    b26len = base26(len(year)-30)
    y = "{0}{1}{2}".format('^'*len(b26len), b26len, year)

if negative:
    y = y.translate(str.maketrans(string.ascii_uppercase+string.digits+'^', string.ascii_uppercase[::-1]+string.digits[::-1]+'!'))
    if len(year) == 4:
        y = '/' + y
    if y[0] not in ['/', '!']:
        y = '*' + y

res += y
for val in vals[:5]: #month, day, hour, minute, second
    res += '{0:0>2}'.format(val)

for val in vals[5:]: #fractional seconds
    res += '{0:0>3}'.format(val)

print(res)

```

# Answer
> 5 votes
# Befunge, ~~418~~ 384 bytes

It's hard to tell in advance how large a Befunge program is likely to end up, and when I started working on this I thought it might actually have some chance of competing. Turns out I was wrong.

```
~:59*-!:00p:2*1\-10p:9*68*+20p>0>#~$_v
68*-:0\`30p\>>:"P"%\"P"/9+p30g#v_1+:~>
0\`v`\0:\p04<<:+1g04-$<_\49+2*v>0>+#1:#\4#g\#0`#2_130p040p5-::01-`\49+2*-:
v:$_\50p\$:130g:1+30p:!^!:-1\*<>g*"A"++\49+2*/50g1-:
_$1+7g00g40g!**:!>_40g:!v!:\g8<^00*55*g01%*2+94:p05
|#9/"P"\%"P":<:_,#!>#:<$_1-00g^v3$\_\#`\0:>#g+
>10g*20g+,1+:^v\&\0+2`4:_@#`<0+<
/*v*86%+55:p00<_$$>:#,_$1+~0^
^!>+\55+/00g1-:^

```

Try it online!

# Answer
> 4 votes
## JavaScript (ES6), 325 bytes

```
f=
s=>s.split`.`.map((n,i)=>i?`00${n}`.slice(i>5?-3:-2):n<'0'?g(n.slice(1),'!','*','/').replace(/\w/g,c=>c>'9'?(45-parseInt(c,36)).toString(36):9-c):g(n),g=(n,c='^',d='',e='',l=n.length)=>l<5?e+`000${n}`.slice(-4):l<31?d+(l+5).toString(36)+n:h(l-30,c)+n,h=(n,c)=>n?c+h(--n/26|0,c)+(n%26+10).toString(36):'').join``.toUpperCase()
;
```

```
<input oninput=o.value=f(this.value);><input id=o>
```

Shockingly long.

# Answer
> 3 votes
# Java 11, ~~653~~ ~~640~~ ~~637~~ ~~623~~ ~~618~~ ~~595~~ 589 bytes

```
s->{String e="",r=e,q="ABCDEFGHIJKLMNOP",z=q+"QRSTUVWXYZ",y="0123456789",x;int i=0,f=0,t,u,v;for(var p:s){p=p.charAt(v=0)<46?p.substring(f=1):p;t=p.length();if(i++<1){r+=(t<5?"0".repeat(4-t):t<32?(char)(t+60):t<58?"^"+(char)(t+33+(v=1)):e);if(t>57){for(v=2,u=675;u<t-57;u*=26)v++;r+="^".repeat(v);x=e;for(var c:Long.toString(t-57,26).toUpperCase().split(e))x+=z.charAt((y+q).indexOf(c));r+=x;}r+=p;if(f>0){x=t<5?"/":t<32?"*":"!".repeat(v);for(int c:r.getBytes())x+=c>93?e:new StringBuffer(y+z).reverse().charAt((z+y).indexOf(c));r=x;}}else r+=i>6?t<2?"00"+p:t<3?0+p:p:t<2?0+p:p;}return r;}

```

Input as `String`-array and return-type as `String`.

Turned out to be quite long (as expected), but can definitely be golfed some more. I'm just glad it works after fiddling with it for quite a while..
-5 bytes thanks to *@ceilingcat*.

Try it here.

**Explanation:**

* `for(var p:s){`: Loop over the parts
    + `p=p.charAt(0)<46?p.substring(f=1):p;`: Determine if it's negative, and if it is, remove the minus sign and set a flag to reduce bytes
    + `t=p.length();`: Get the amount of digits
    + `if(i++<1){`: If it's the first number (the year):
        - `t<5?"0".repeat(4-t)`: If it's in the range \\$\[0, 100000)\\$: add leading zeroes if necessary
        - `t<32?(char)(t+60)`: If it's in the range \\$\[100000, 10^{30})\\$: Add a leading letter
        - `t<58?"^"+(char)(t+33+(v=1))`: If it's in the range \\$\[10^{30}, 10^{732})\\$: Add a literal `"^"` (and set `v` to 1) + leading letter
        - `if(t>57)for(v=2,u=675;u<t-57;u*=26)v++;r+="^".repeat(v)`: Add the appropriate amount of literal `"^"` (and set `v` to that amount), plus `x=e;for(var c:Long.toString(t-57,26).toUpperCase().split(e))x+=z.charAt((y+q).indexOf(c));r+=x;`: leading letters (base-26 to alphabet conversion)
        - `r+=p;`: Add the year itself to the result-String
        - `if(f>0){`: If the year was negative:
            * `x=t<5?"/":t<32?"*":"!".repeat(v);`: Create a temp String `x` with the correct `/`, `*` or `v` amount of `!`
            * `for(int c:r.getBytes())x+=c>93?e:new StringBuffer(y+z).reverse().charAt((z+y).indexOf(c));`: Do the conversion (A↔Z, B↔Y, 0↔9, 1↔8, etc.)
            * `r=x;`: And then set the result to this temp String `x`
    + `else`: If it's the month, days, hours, minutes, seconds, milliseconds, microseconds, nanoseconds, or smaller:
        - `i>6?t<2?"00"+p:t<3?0+p:p`: If it's milliseconds or smaller: Add leading zeroes if necessary
        - `:t<2?0+p:p;`: Else (month, days, hours, minutes, seconds): Add single leading zero if necessary
* `return r`: Return the result

# Answer
> 3 votes
# Perl 5, ~~328 322 317~~ 301 + 1 (`-a`) = 302 bytes

```
$_=shift@F;if(($l=y/-//c)<5){s/^/0 x(4-$l)/e}elsif($l<57){s/^/'^'x($l>30).chr 65+($l-5)%26/e}else{$l-=57;do{s/\^*\K/'^'.chr 65+$l%26/e}while$l=int$l/26;s/^\^\K\D-?\d/^A$&/}if(s/-//){s%^....$%/$&%;eval join'',reverse'!/',0..9,A..Z,"y/A-Z0-9^/";s%^[^!/]%*$&%}printf$_.'%02d'x(@F>5?5:@F).'%03d'x(@F-5),@F

```

Try it online!

**Ungolfed**

```
$_=shift@F; # Store the year in the default variable for easier regex

if(($l=y/-//c)<5){      # if the length of the year is less than 5
    s/^/0 x(4-$l)/e         # pad with leading zeros to 4 digits
}elsif($l<57){          # if the length is less than 57
    s/^/'^'x($l>30).chr 65+($l-5)%26/e  # put a carat at the front if there are more than 30 characters
                        # and map the length minus 5 to A-Z
}else{
    $l-=57;         # offset the length by 57
    do{
        s/\^*\K/'^'.chr 65+$l%26/e # put a carat at the front and map the length to base 26 (A-Z)
    }while$l=int$l/26;  # until the length is down to 0
    s/^\^\K\D-?\d/^A$&/ # insert an extra '^A' to pad the result to at least 2 characters if there was only 1
}
if(s/-//){          # if the year is negative
    s%^....$%/$&%;          # put a '/' in front of a 4 digit year
    eval join'',reverse'!/',0..9,A..Z,"y/A-Z0-9^/"; # map A-Z,0-9, and ^ to Z-A,9-0, and ! respectively
    s%^[^!/]%*$&%           # add a * at the front if there are no other indicators
}
printf$_.           # output the year
'%02d'x(@F>5?5:@F).             # followed by the month, day, hour, and minutes, padded to 2 digits
'%03d'x(@F-5),@F                # followed by fractional seconds, padded to three digits

```

# Answer
> 2 votes
# Excel VBA, ~~500~~ ~~486~~ ~~485~~ 461 Bytes

## Anonymous VBE Immediate Window Function

Anonymous VBE immediate window function that takes input as year from `[A1]`, month from `[B1]`, days from `[C1]`, hours from `[D1]`, minutes from `[E1]`, seconds from `[F1]` and an optional extra precision array from `[G1:Z1]`, calculates the RFC2550 timestamp and outputs to the VBE immediate window. Makes use of the declared helper function below.

```
n=Left([A1],1)="-":y=Mid([A1],1-n):l=Len(y):o=IIf(l<5,Right("000"&y,4),IIf(l<31,"",String(Len(b(l-30)),94))&B(l-IIf(l<31,4,30))&y):For Each c In[B1:Z1]:j=j+1:p=p+IIf(c,Format(c,IIf(j>5,"000","00")),""):Next:If n Then For i=1To Len(o):c=Asc(Mid(o,i,1)):Mid$(o,i,1)=Chr(IIf(c<60,105,155)-c):Next:?IIf(l<5,"/",IIf(InStr(1,o,"="),"","*"))Replace(o,"=","!")p:Else?o;p

```

**Helper Function**

Declared helper function that takes an input number and returns that number in base-26 such that `1->A` and `26->Z`

Must be placed into a public module.

```
Function b(n)
While n
n=n-1
d=n Mod 26+1
d=d+26*(d<0)
n=n\26-(d<0)
b=Chr(64+d)+b
Wend
End Function

```

**Usage**

Must be used in a clear module, or the module must be cleared before execution as the vars `j`, `o` and `p` are assumed to be in their default, uninitialized state at the beginning of execution of the code. For `j`, which is a `Variant\Integer` variable, this default value is `0` and for `o` and `p`, which are `Variant\String` variables, this default value is the empty string (`""`).

Input, an array of strings, is taken from `1:1` on the ActiveSheet and output is to the VBE immediate window.

**Sample I/O**

```
[A1:F1]=Split("4052107100422150625478207675901330514555829957419806023121389455865117429470888094459661251.2.3.5.7.11",".")
n=Left([A1],1)="-":y=Mid([A1],1-n):l=Len(y):o=IIf(l<5,Right("000"&y,4),IIf(l<31,"",String(Len(b(l-30)),94))&B(l-IIf(l<31,4,30))&y):For Each c In[B1:ZZ1]:j=j+1:p=p+IIf(c,Format(c,IIf(j>5,"000","00")),""):Next:If n Then For i=1To Len(o):c=Asc(Mid(o,i,1)):Mid$(o,i,1)=Chr(IIf(c<60,105,155)-c):Next:?IIf(l<5,"/",IIf(InStr(1,o,"="),"","*"))Replace(o,"=","!")p:Else?o;p
^^BI40521071004221506254782076759013305145558299574198060231213894558651174294708880944596612510203050711021028

Cells.Clear:j=0:o="":p="" '' clear the worksheet and vars
[A1:H1]=Array("-696443266","1","3","6","10","15","21","28")
n=Left([A1],1)="-":y=Mid([A1],1-n):l=Len(y):o=IIf(l<5,Right("000"&y,4),IIf(l<31,"",String(Len(b(l-30)),94))&B(l-IIf(l<31,4,30))&y):For Each c In[B1:ZZ1]:j=j+1:p=p+IIf(c,Format(c,IIf(j>5,"000","00")),""):Next:If n Then For i=1To Len(o):c=Asc(Mid(o,i,1)):Mid$(o,i,1)=Chr(IIf(c<60,105,155)-c):Next:?IIf(l<5,"/",IIf(InStr(1,o,"="),"","*"))Replace(o,"=","!")p:Else?o;p
*V3035567330103061015021028

Cells.Clear:j=0:o="":p="" '' clear the worksheet and vars
[A1]="45941"
n=Left([A1],1)="-":y=Mid([A1],1-n):l=Len(y):o=IIf(l<5,Right("000"&y,4),IIf(l<31,"",String(Len(b(l-30)),94))&B(l-IIf(l<31,4,30))&y):For Each c In[B1:ZZ1]:j=j+1:p=p+IIf(c,Format(c,IIf(j>5,"000","00")),""):Next:If n Then For i=1To Len(o):c=Asc(Mid(o,i,1)):Mid$(o,i,1)=Chr(IIf(c<60,105,155)-c):Next:?IIf(l<5,"/",IIf(InStr(1,o,"="),"","*"))Replace(o,"=","!")p:Else?o;p
A45941

Cells.Clear:j=0:o="":p="" '' clear the worksheet and vars
[A1:F1]=Split("4052107100422150625478207675901330514555829957419806023121389455865117429470888094459661251.2.3.5.7.11",".")
n=Left([A1],1)="-":y=Mid([A1],1-n):l=Len(y):o=IIf(l<5,Right("000"&y,4),IIf(l<31,"",String(Len(b(l-30)),94))&B(l-IIf(l<31,4,30))&y):For Each c In[B1:ZZ1]:j=j+1:p=p+IIf(c,Format(c,IIf(j>5,"000","00")),""):Next:If n Then For i=1To Len(o):c=Asc(Mid(o,i,1)):Mid$(o,i,1)=Chr(IIf(c<60,105,155)-c):Next:?IIf(l<5,"/",IIf(InStr(1,o,"="),"","*"))Replace(o,"=","!")p:Else?o;p
^^BI40521071004221506254782076759013305145558299574198060231213894558651174294708880944596612510203050711

```

# Answer
> 2 votes
# Jelly, ~~165~~ 126 bytes

```
ḣ5ṫ€3
ØD,“^ /*!”,ØA
_µ‘l26Ċṗ@€ØAẎị@
Lµç30;€”^UZFµç4⁶;µ®L>30¤?µḟ®L>4¤?;®AṾ€¤µL=4”/x2£FiÐ€ị€2£UF¤µ®S<0¤¡
4R¬+DU$UµḢ©Ç;Ñ;ṫ6ṫ€2$$F

```

Try it online!

Line 4 does the year formatting with help from lines 2 and 3. The first and last line deal with zero padding the elements of the input to their proper lengths then concatenating them with the formatted year.

* `_µ‘l26Ċṗ@€ØAẎị@` finds the base 26 prefix. It takes the cartesian power of the alphabet (`ØA`) for each number between 1 and ceil(log26(floor(log10(year))-n+1)) (where n is either 30 or 4) then gets indexes into this list with floor(log10(year))-n (`ị@`).
* `ç30;€”^UZF` formats years \>= 1030 (`®L>30¤?`)
* `ç4⁶;` formats years \< 1030. (*Edit*: Saved a byte by using `⁶;` instead of `;@⁶`)
* ~~`1RḊ`~~  gives an empty prefix for years \< 105 (`®L>4¤?`). It takes the list of digits then filters out every element in itself. Just using this to yield `[]` because  doesn't work here. ~~This just evaluates to `[]`.  and `[]` don't work here and I couldn't find another 2 bytes that return an empty list.~~
* `;®AṾ€¤` appends the year to the prefix then flattens it.
* `L=4”/x` prefixes a `/` if the length of the year is 4 in the do statement of `®S<0¤¡`.
* `2£FiÐ€¹ị€2£UF¤` takes the complements of `A .. Z`, `0 .. 9` and `^ /*!` if the year is negative (`®S<0¤¡`).  refers to the second link, `ØD,“^ *!”,ØA` which is the list `[['0' .. '9'], ['^',' ','/','*','!'], ['A' .. 'Z']]`. With a formatted year like `^C125...` this link finds the index of each character in the flattened version of  then uses those indices to construct a new string from the flattened version of  where each sublist is reversed, i.e. `['9' .. '0','!','*','/',' ','^','Z' .. 'A']`, yielding `!X874...`. `/` maps to itself because it is prefixed before everything has its complement taken.
* ~~`L=4a®S<0x@”/;` adds a `/` to the beginning of negative years in `[-9999 .. -0001]`. My guess is this can be shortened.~~ I ended up including this in the previous do statement (`¡`) and saved 7 bytes because then I didn't need to test for negative years twice.

~~There are a lot of uses of `¡` in line 4 and I think they could be compressed by using `?` instead but I'm not sure how to get those to work.~~ I got `?` to work and saved a few bytes.

James Holderness pointed out that my first submission didn't handle years with 30 digits correct. It turned out the bug was for any year that needed a `Z` in the base 26 prefix. It turns out I couldn't use  because when you convert 26 to base 26 it gives you `[1,0]` instead of `26` (duh). Instead I used ordered pairs with replacement. I don't think there is an atom for that but if there is I can save a few bytes. Fixing this ended up costing me ~40 bytes. Definitely my longest Jelly program yet. *Edit*: Found a shorter way to do the cartesian product. I realized that I wasn't sure that the last one worked for prefixes with more than two letters anyway but the new way does work.

Sorry for the many times I've edited this post, I just keep discovering ways of shortening it.

# Answer
> 0 votes
# 05AB1E, 104 bytes

```
εþNĀiN6@Ìjð0:ëg©Ž¾S₃в@DUO0®4α×®60+ç®34+ç'^ì®57-D<₂®Ým675*@OÌ'^×sAuÅвJ«)ćèyÄ«y0‹ižK'^ìžL'!ì‡„/*õªX2£Oèì]J

```

Input as a list of integers.

Based on my Java answer.

Try it online or verify all test cases.

**Explanation:**

```
ε                          # Map over each integer `y` of the (implicit) input-list
 þ                         #  Only leave digits (same as absolute value `Ä`, but results in a string)
  NĀi                      #  If the 0-based map-index is NOT 0 (so not the year):
     N6@                   #   Check if the map-index is >= 6 (1 if truthy; 0 if falsey),
                           #   thus milliseconds or smaller
        Ì                  #   Increase that by 2
         j                 #   Add leading spaces to abs(y) to make the length (N>=6)+2 long
                           #   (note that builtin `j` requires the first argument to be a string,
                           #    hence the use of `þ` over `Ä` earlier)
          ð0:              #   And replace those leading spaces with 0s
    ë                      #  Else (the map-index is 0, thus the year):
     g                     #   Pop the absolute value, and push its length
      ©                    #   Store this length in variable `®` (without popping)
       Ž¾S                 #   Push compressed integer 48223
          ₃в               #   Convert it to base-95 as list: [5,32,58]
            @              #   Check for each if they're >= the length (1 if truthy; 0 if falsey)
             DU            #   Store a copy of those checks in variable `X`
               O           #   Sum the checks to get the amount of truthy values
      ®                    #   Push the length from `®` again
       4α                  #   Take its absolute difference with 4
     0   ×                 #   Repeat 0 that many times as string
     ®                     #   Push the length `®` again
      60+                  #   Add 60
         ç                 #   Convert it to an ASCII character with this codepoint
     ®                     #   Push the length `®` again
      34+                  #   Add 34
         ç                 #   Convert it to an ASCII character with this codepoint
          '^ì             '#   Prepend "^"
     ®                     #   Push the length `®` again
      57-                  #   Subtract 57
         D                 #   Duplicate it
          <                #   Decrease it by 1 (thus `®`-58)
            ®Ý             #   Push a list in the range [0,`®`]
           ₂  m            #   Take 26 to the power of each value in this list
               675*        #   Multiply each by 675
                   @       #   Check for each if the `®`-58 is >= the value
                    O      #   Sum those checks
                     Ì     #   Increase it by 2
                      '^× '#   Have that many "^"
      s                    #   Swap so `®`-57 is at the top of the stack again
       AuÅв                #   Convert it to base-"ABCDEFGHIJKLMNOPQRSTUVWXYZ",
                           #   basically convert it to base-26 and index it into the alphabet
           J               #   And join those characters together to a single string
            «              #   After which we'll append it to the "^"-string
     )                     #   Wrap all values on the stack into a list
      ć                    #   Extract head; pop and push remainder-list and the first item separated,
                           #   where the first item is the sum of truthy values we calculated earlier
       è                   #   Use that to 0-based index into the remainder-list
        yÄ                 #   Push the absolute value of integer `y` again
          «                #   And append it to the string
     y0‹i                  #   If integer `y` is negative:
         žK                #    Push string "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"
           '^ì            '#    Prepend a leading "^"
         žL                #    Push string "zyxwvutsrqponmlkjihgfedcbaZYXWVUTSRQPONMLKJIHGFEDCBA9876543210"
           '!ì            '#    Prepend a leading "!"
              ‡            #    Transliterate all characters in the string
         „/*               #    Push string "/*"
            õª             #    Convert it to a list of characters, and append "": ["/","*",""]
              X            #    Push the list of checks we saved in variable `X`
               2£          #    Only leave the first two checks
                 O         #    Sum those
                  è        #    Use it to 0-based index into the ["/","*",""]
                   ì       #    And prepend it in front of the string
]                          # Close all if-statements and the map
 J                         # And join all mapped strings together
                           # (after which the result is output implicitly)

```

See this 05AB1E tip of mine (sections *How to compress large integers?* and *How to compress integer lists?*) to understand why `Ž¾S` is `48223`; `Ž¾S₃в` is `[5,32,58]`; and `is`.

---
Tags: code-golf, string, date
---


# Question
Title: Create a Muriel-like language and implementation
Muriel is a language where the only way to loop is to create a quine and execute it. Your job is to create your own language with this property and an implementation of it in a pre-existing language.

We will define a Muriel-like language like as follows:

1. It has a built-in command for executing code in its own language, similar to Muriel's `@` command or python's `exec`.
2. It is Turing complete.
3. If you remove the built-in execution command it is no longer Turing complete.

Muriel is Muriel-like with `@` as its built-in execution command. Smurf is also Muriel-like (its built-in execution command is `x`). Python is *not* Muriel-like, since it is still Turing complete if you remove `exec`.

Your job is to create a Muriel-like programming language, and then to provide an implementation of it in a language of your choice. Your score is the length of the implementation, which you are trying to minimize.

Notes:

1. Your built-in execution does not need to function exactly like Muriel. It is up to you how it handles termination of the child program, errors, scoping, etc...
2. The language you write the implementation can not *itself* be Muriel-like. (This is so that `@` is not a valid entry.) It also must have existed before this post.

# Answer
# Python 3 and "The minimum TC subset of Underload but with the characters changed to `2019`~~, reversed, and with a `0` on top~~", ~~156~~ 129 bytes

```
c,n,*s=input(),0,[]
while c:
 i,*c=c;q="6">i
 if n:n+=q*int(i)-q;s[n and-1]+=i,
 elif q:n="1"<i;s+=s[-1]*(1-n),
 else:c=s.pop()+c

```

Try it online!

Explanations in the header, ungolfed code in the footer.
> 3 votes

# Answer
# CJam, CFU analogue of the `():~^` subset of Underload, 12 bytes

```
q_"_\~\""--~

```

CJam already happens to be a stack-based language with an eval instruction, which makes it a good candidate for having a Muriel-like subset.

In particular, we define a subset with the following instructions:

* `"..."`: Push a string `...` to the stack. Quotes and backslashes inside the string can be escaped using backslashes. Equivalent to Underload's `()`.
* `_`: Duplicate the top stack value. Equivalent to Underload's `:`.
* `\`: Swap the top two stack values. Not strictly necessary for Turing-completeness, but we need to permit backslashes anyway. Equivalent to Underload's `~`.
* `~`: Execute the top stack value. Equivalent to Underload's `^`.

Explanation of the code:

```
q            | read input
  "_\~\""-   | remove all these characters: "_\~
 _        -  | remove all characters in the resulting string from the input
           ~ | execute the result

```
> 1 votes

---
Tags: code-golf, quine, language-design
---


title: Let's Encrypt It!

text:
# Question
Title: Let's Encrypt It!
# Note

This is the encryption challenge. The decryption challenge can be found here.

# Challenge

The challenge is to encrypt a given string, using the rules as specified below. The string will only contain **lowercase alphabets**, **digits**, and/or **blank spaces**.

# Equivalent of a Character

Now, firstly you would need to know how to find the "equivalent" of each character.

If the character is a consonant, this is the way of finding it's equivalent:

```
1) List all the consonants in alphabetical order
    b c d f g h j k l m n p q r s t v w x y z
2) Get the position of the consonant you are finding the equivalent of.
3) The equivalent is the consonant at that position when starting from the end.

```

eg: 'h' and 't' are equivalents of each other because 'h', 't' are in the 6th position from start and end respectively.

The same procedure is followed to find the equivalent of vowels/digits. You list all the vowels or the digits (starting from 0) in order and find the equivalent.

Given below is the list of the equivalents of all the characters:

```
b <-> z
c <-> y
d <-> x
f <-> w
g <-> v
h <-> t
j <-> s
k <-> r
l <-> q
m <-> p
n <-> n

a <-> u
e <-> o
i <-> i

0 <-> 9
1 <-> 8
2 <-> 7
3 <-> 6
4 <-> 5

```

# Rules of Encrypting

1. You start moving from the left and go towards the right.
2. If the character is a consonant/digit, then its equivalent is taken and if it is a blank space, then a blank space is taken.
3. If the character is a vowel, you take it's equivalent and start to move in the opposite direction. For example, if you are moving right and encounter a vowel, encrypt that character then skip to the rightmost unencrypted character and begin encrypting in the left direction, and vice versa.
4. You shouldn't consider a character in the same position twice. The steps should be followed until all the characters in the input are covered.
5. The total number of characters in the input(including blank spaces) should be equal to the total number of characters in the output.

**Please note that the encrypted characters appear in the output in the order in which they were encrypted.**

Now let me encrypt a string for you.

```
String = "tre d1go3t is"
Moving left to right
"t" -> "h"
"r" -> "k"
"e" -> "o"
Vowel encountered. Now moving right to left.
"s" -> "j"
"i" -> "i"
Vowel encountered. Now moving left to right.
" " -> " "
"d" -> "x"
"1" -> "8"
"g" -> "v"
"o" -> "e"
Vowel encountered. Now moving right to left.
" " -> " "
"t" -> "h"
"3" -> "6"

Output -> "hkoji x8ve h6"

```

# Examples

```
"flyspy" -> "wqcjmc"
"hero" -> "toek"
"heroic" -> "toyike"
"ae" -> "uo"
"abe" -> "uoz"
"the space" -> "htoo jmuy"
"a d1g13t" -> "uh68v8x "
"we xi12" -> "fo78i d"
"this is a code" -> "htioj ixej uy "

```

You may also choose to use uppercase alphabets instead of lowercase.

# Scoring

This is , so the shortest code wins!

# Answer
# JavaScript (Node.js), ~~173~~ ... ~~166~~ ~~156~~ ... ~~124~~ 123 bytes

-28 byte Thanks Arnauld

```
f=([q,...s])=>q?(c="aeioubcdfghjklmpqrstvwxyz",t=c.search(q),q=="0"|+q?9-q:~t?c[(t<5?4:29)-t]:q)+f(~t&&t<5?s.reverse():s):s

```

Try it online!

In the first iteration the `String` will be changed to `Array`, and subsequent iterations will continue to use `Array`. Voilà!

Original Approach (166 bytes):

```
f=(s,i=0,r=s.length,d=1,c="bcdfghjklmnpqrstvwxyz",v="aeiou")=>(d^=!!(t=~v.search(q=s[d?i:r])),q<"0"|q>"9"?c[20-c.search(q)]||v[5+t]||q:9-q)+(i<r-1?f(s,i+d,r-!d,d):"")

```
> 4 votes

# Answer
# 05AB1E, 22 bytes

```
vćžNÂ‡žMÂ‡žhÂ‡D?žMsåiR

```

Try it online! or as a Test suite

**Explanation**

```
v                        # for each char in input
 ć                       # extract the head of the current string (initially input)
  žNÂ‡                   # transform consonants
      žMÂ‡               # transofrm vowels
          žhÂ‡           # transform numbers
              D?         # print a copy of the current char
                žMsåi    # if the current char is a vowel
                     R   # reverse the rest of the string

```
> 4 votes

# Answer
# C, 196 bytes

```
#define C(k,m)for(i=m;i--;)k[i]-c||putchar(k[m+~i],r^=m==5);
r;p(c,i){C("bcdfghjklmnpqrstvwxyz",21)C("0123456789",10)C("aeiou",5)C(" ",1)}f(S){char*s=S,*t=s+strlen(s);for(r=1;s<t;)p(r?*s++:*--t);}

```

Try it online!
> 1 votes

# Answer
# Clean, ~~221~~ ~~206~~ ~~198~~ ~~190~~ ~~186~~ 178 bytes

```
import StdEnv
r=reverse
l=['bcdfghjklm01234aeou56789pqrstvwxyz']
$s#(a,b)=span(\e=all((<>)e)['aeiou'])s
|s>[]=[j\\e<-a++b%(0,0),i<-['in ':l]&j<-['in ':r l]|e==i]++ $(init(r b))=s

```

Try it online!
> 1 votes

# Answer
# , 132 bytes

```
f=:3 :0
c=.(u:97+i.26)-.v=.'aeiou'
d=.u:48+i.10
g=.;"0|.
a=.''
while.*#y do.a=.a,{.y rplc(g c),(g d),g v
y=.|.^:({:a e.v)}.y
end.a
)

```

Try it online!

A verbose explicit verb this time.

Explanation:

`c=.(u:97+i.26)` makes a list a-z

`v=.'aeiou'` makes a list of vowels

`-.` removes the vowels from the list of letters

`d=.u:48+i.10` makes a list of digits

`g=.;"0|.` a utility verb for creating a list of boxed pairs of replacement symbols

```
   g d
┌─┬─┐
│0│9│
├─┼─┤
│1│8│
├─┼─┤
│2│7│
├─┼─┤
│3│6│
├─┼─┤
│4│5│
├─┼─┤
│5│4│
├─┼─┤
│6│3│
├─┼─┤
│7│2│
├─┼─┤
│8│1│
├─┼─┤
│9│0│
└─┴─┘

```

`a=.''` a list to store the result

`while.*#y do.a=.a,{.y rplc(g c),(g d),g v` while the length of the list is \> 0 take a symbol, replace it and append it to the result

`y=.|.^:({:a e.v)}.y` drop one symbol from the beginning of the list and if the symbol is a vowel, reverse the list

`end.` ends the `while` loop

`a` returns the result
> 1 votes

# Answer
# Stax, 24 bytes

```
╥j•td╢Ä;Sµ*ûⁿvÉ╫î▓J o╩π╗

```

Run it

Here is the ascii representation of the same program.

```
VcGVdGVvGwB]qVvs#!Hv*c}cr\$|t

```

It translates each character class first, then begins a while loop. In the loop, it outputs the next character, and conditionally reverses the rest of the string if a vowel is encountered.

```
VcG                             Push lowercase consonants and jump to trailing }
   VdG                          Push digits and jump to trailing }
      VvG                       Push lowercase vowels and jump to trailing }
         wB]qVvs#!Hv*c          While; run this block until popped value is falsy
          B]                    Split first character off string
            q                   Output with no newline; keep on the stack
             Vvs#               1 if letter is a vowel, 0 otherwise
                 !Hv            Not, Double, then Decrement
                                    -1 for vowels, 1 otherwise
                    *           Multiply string. -1 causes reversal
                     c          Copy value to be popped as while condition
                      }         Jump target from above.  Return when done.
                       cr\$     Copy, reverse, zip, and flatten.
                           |t   Translate: use string as a character map
                                    for replacements

```
> 1 votes

# Answer
# Brachylog, ~~43~~ 39 bytes

```
hX∧Ḅ;Ṿ,Ị,Ṣ∋C↔;Cz∋[X,H]&{h∈Ṿ&b↔|b}↰↔,H↔|

```

Try it online!

I only bothered finishing this grand mess because I'm struggling to make Jelly cooperate...
> 1 votes

# Answer
# Retina, ~~78~~ 69 bytes

```
T`b-df-hj-maed\oup-tv-z`Ro
/[aeiou]/{*>0L`.*?[aeiou]
0`.*?[aeiou]

V`

```

Try it online! Link includes test cases. Explanation:

```
T`b-df-hj-maed\oup-tv-z`Ro

```

Swap each character with its equivalent. The `Ro` causes the string to transliterate to its reverse. The middle consonant `n` and vowel `i` map to themselves so don't need to be listed. The first 10 consonants are listed first and the last 10 last so that they transliterate to each other. The first and last two vowels then surround the digits. (The `o` is normally special so it has to be quoted here.)

```
/[aeiou]/{

```

Repeat while a vowel remains.

```
*>0L`.*?[aeiou]

```

Output the text up to the vowel.

```
0`.*?[aeiou]

```

Delete the text up to the vowel.

```
V`

```

Reverse the remaining text. When there are no vowels left, this is then implicitly output, however for the purposes of the test cases, the header outputs the text at the end of each line.
> 0 votes

---
Tags: code-golf, string, encryption
---


title: The ASCII character countdown!

text:
# Question
Title: The ASCII character countdown!
Since this is a challenge, you might want to sort answers by oldest.

---

Your task is simple: Choose any printable ASCII character that's not chosen in the previous answers. And then, you need to print your chosen character in your program to standard output. (You can ONLY print your chosen character, without printing other garbage to STDOUT)

## The catch

Let's say you picked `x` as your chosen character, and your answer is the answer numbered y. You have to insert y x's into the previous source code, at any position you like. For the first answer, the previous answer is the empty program.

## An example

Answers have to start with the number 1. So for example, I chose the character `#`, and I posted a 1 byte answer in /// that prints the `#` mark.

```
#

```

And then, the second answer (numbered 2) has to insert 2 of their picked `x` character into the previous source code, such that the modified code will print their `x` character. So assume this is written in Keg:

```
x#x

```

And then, the third answer has to do the same, and so on, until 95 is reached.

## Answer format

I'd love to see an explanation of your code as well, preferably with an online interpreter link!

```
# [{Language name}]({link-to-language}), {code-length} bytes

\$y= {The number of your answer}\$. Used so far: <code>{Characters used in answers so far}</code>

    {your code}

```

## The winning criterion & other rules

* The first user whose answer stays without a succeeding answer for a month wins the challenge. If that's not satisfied, the first person who reaches the number 95 wins the challenge.
* You are not allowed to put any other character in your code other than printable ASCII characters.
* You need to wait 2 answers before you post a new answer after your submission.
* Please make sure your answer is valid. If yours is not valid, chaining answers aren't allowed to be posted.
* You can answer in a language that is used in previous answers.
* You could *only* insert y `x`'s into the source code.
* Your are not allowed to take input.
* Your program can output to STDERR, as long as the output to STDOUT is as intended.

# Answer
> 8 votes
# 2sable, 36 bytes

```
//9#999999//,#,#,221'/,#q',#q,qq2///

```

\\$y=8\\$. Used so far: `1'2q#,9/`

Try it online.

Maybe this opens up some other languages that use `//` to comment. :)

**Explanation:**

2sable is an old version of 05AB1E (legacy) (which of itself is an old version of 05AB1E).

The legacy version outputs a leading newline however: try it online.
And the latest 05AB1E version outputs three leading newline: try it online.

```
//                                    # Divide twice, no-ops with an empty stack
  9                                   # Push 9
   #                                  # Pop and split it by spaces
                                      # (since it contains no spaces, it only pops)
    999999                            # Push 999999
          /                           # Divide the empty stack by this, popping the integer
           /                          # No-op divide again with an empty stack
            ,                         # No-op print (which would output a newline in the
                                      # newer versions)
             #,#,                     # Some more no-ops
                 221                  # Push 221
                    '/               '# Push "/"
                      ,               # Pop and print this "/" to STDOUT
                       #              # Split the 221 on spaces, so it just pops
                        q             # Exit the program
                         ',#q,qq2/// '# No-ops

```

# Answer
> 7 votes
# Polyglot, 3 bytes

```
1''

```

\\$y=2\\$. Used thus far: `1'`.

This works in a bunch of stack-based languages, which basically all do the following:

```
1    # Push a 1 to the stack
 ''  # Push the string "'" to the stack
     # (output the top of the stack implicitly as result)

```

Try it online in ,,,.
Try it online in 05AB1E.
Try it online in Japt.
etc.

> *Tip: Using a similar stack-based language, it's easy to insert almost any character by interleaving.*

# Answer
> 7 votes
# 05AB1E, 10 bytes

\\$y=4\\$. Used so far: `1'2q`

```
221'q'qqq2

```

Try it online!

```
221         # push 221 to the stack
   'q'q     # push character q (twice for good measure)
       q    # quit; implicitly print top-of-stack q
        q2  # no-ops

```

# Answer
> 6 votes
# 05AB1E, 15 bytes

```
###221'#q'#qqq2

```

\\$y=5\\$. Used thus far: `1'2q#`

Try it online.

Maybe this opens up some other languages that use `#` to comment. :)

**Explanation:**

```
###              # Split by spaces three times (no-ops without input)
   221           # Push integer 221
      '#        '# Push character "#"
        q        # Stop the program
                 # (after which the top of the stack is output implicitly as result)
         '#qqq2 '# No-ops

```

# Answer
> 6 votes
# Befunge-98, 21 bytes

```
#,#,#,221',#q',#q,qq2

```

\\$y=6\\$. Used so far: `1'2q#,`

Try it online!

```
#                         # Skip the next instruction
 ,                        # (skipped)
  #,                      # (skipped)
    #,                    # (skipped)
      221                 # Push 2, 2, 1 onto the stack
         ',               # Push character ','
           #q             # (skipped by #)
             ',           # Push character ','
               #q         # (skipped)
                 ,        # Output character
                  q       # Quit program
                   q2     # (not executed)

```

# Answer
> 6 votes
# Befunge-98, 45 bytes

\\$y=9\\$. Used so far: `1'2q#,9/j`

```
//9#999999//j,#,#,221'j/,#qjjjjj'j,#jq,qq2///

```

Try it online!

### Explanation

Mainly (ab)uses `j` to skip sections we don't want to execute.

```
//                                              # Divide twice (no-ops, as 0/0 is 0 in Befunge-98)
  9                                             # Push 9
   #9                                           # No-op (skipped by #)
     99999                                      # Push more 9s
          /                                     # Divide, results in 9/9 = 1
           /                                    # Divide, results in 9/1 = 9
            j                                   # Jump forward 9 instructions
             ,#,#,221'                          # (not executed)
                      j                         # Jump forward 9 instructions
                       /,#qjjjjj                # (not executed)
                                'j              # Push the character 'j'
                                  ,             # Print the character
                                   #j           # No-op
                                     q          # Quit program
                                      ,qq2///   # (not executed)

```

# Answer
> 6 votes
# Trigger, 55 bytes

\\$y=10\\$. Used so far: `1'2q#,9/j\`

```
\//9#9\99999//j,\\\#,#,221'j/\,#\\qjjjjj'j,#\jq,qq2/\//

```

Try it online!

This took a lot longer than I'm willing to admit...

# Answer
> 5 votes
# , 28 bytes

```
9#999999,#,#,221',#q',#q,qq2

```

\\$y=7\\$. Used so far: `1'2q#,9`

Try it online!

Based on a combination of functions may output via their return values and the fact that R functions naturally output their return values to STDOUT (albeit with some prepended characters to indicate index of the outputed value), I hope that this is Ok.

Explanation:

```
9               # integer value 9; output by default
 #              # comment character; everything after this (on the same line) is ignored
  999999,#,#,221',#q',#q,qq2
                # not run

```

Big thank-you to Kevin Cruijssen for putting the `#` character at the beginning of answer #5, which (as he suspected) was critical to make this answer work!

# Answer
> 5 votes
# Befunge-98 (FBBI), 66 bytes

\\$y=11\\$. Used so far: `1'2q#,9/j\;`

```
;\//9#9\99999//j,\\\#,#,221;';;j/\;,;#\\;qjjjjj'j,#\jq,qq2/\//;;;;

```

Try it online!

`;` is the comment character in Befunge, and this program works by running `';,q` with inapplicable parts commented out. Doesn't work in Pyfunge for reasons I can't figure out.

# Answer
> 5 votes
# Befunge-98, 253 bytes

\\$y=22\\$. Used so far: `1'2q#,9/j\;0"35s46%7*x`

```
*7%7*77%*7*77%666666%x*77*7%*7*77%6*666666666655555555555555444444%***4%44*4*444444xxxx"033333%33333333s;s\/s/90*%35*s46#"9\s99%%9%90s9/"/j0s,\"\*0\"#s,#,22s01;"*'s"*;0;j/x\xxxx"s;xxx,0;%#x\"\;xxqsj*j"0j%%jj'j,#\"j%qs,q0q2/"\%s//s;0;%;;0"s77*77777xxxxxx

```

Try it online!

After running the part before the first `x`, the top of the stack is `6 0` (from the code `666%`). Thus, the `x` instruction sets the *program delta* to (6, 0), meaning that the instruction pointer moves right 6 spaces every step. This skips over most of the remaining instructions, leaving `%%66554*44"33s0s\9/,\,;*x",\q0'j0%0"7x` to be executed. `%%66544*44` does some stack manipulation, `"33s0s\9/,\,;*x"` pushes the string `x*;,\,/9\s0s33`, and `,` prints the first character of that string, which is `x`. Finally, `\` swaps the top two elements of the stack (which we don't care about) and `q` ends the program.

# Answer
> 4 votes
# ///, 1 byte

\\$y=1\\$ Used so far: `1`

```
1

```

Try it online!

Just to start things off.

**Explanation:**

```
1     # since this isn't a / or \, the character is simply printed and removed.
      # no characters left so the program terminates.

```

# Answer
> 4 votes
# Japt, 6 bytes

\\$y=3\\$ Used so far: `1'2`

```
221''2

```

Test it

## Explanation

The code is transpiled to `221, "'", 2` and Japt only implicitly prints the last expression so outputs 2

# Answer
> 4 votes
# Keg, `-hr`, 78 bytes

\\$y=12\\$. Used so far: `1'2q#,9/j\;0`

```
0;\//90#9\999909//j0,\\0\#,#,2201;';0;j/\;,0;#\\;qjj0jjj'j,#\jq,q0q2/\//;0;;;0

```

Try it online!

And this kids, is why we use languages where single digits auto push! This pushes a whole bunch of stuff, a 0, then prints the t.o.s using the `-hr` flag.

# Answer
> 4 votes
# Trigger, 190 bytes

\\$y=19\\$. Used so far: `1'2q#,9/j\;0"35s46%`

```
%%%666666%%%6666666666655555555555555444444%4%444444444"033333%33333333s;s\/s/90%35s46#"9\s99%%9%90s9/"/j0s,\"\0\"#s,#,22s01;"'s";0;j/\"s;,0;%#\"\;qsjj"0j%%jj'j,#\"j%qs,q0q2/"\%s//s;0;%;;0"s

```

Try it online!

Here's hoping using `%` makes a lot of languages a lot harder to use

# Answer
> 4 votes
# Trigger, 276 bytes

\\$y=23\\$. Used so far: `1'2q#,9/j\;0"35s46%7*x@`

```
@@@*@@@@@@@@7%7*77%*7*77%666666%@x*77*7%*7*7@7%6*@666666666655555555555555444444%*@**4%44*4*444444xx@xx"033333%33333333s;s\/s@/90*%35*s46#"9\s99%%9%90s9/"/j0s,\"\*0\"#s,#,22s01;"*'s"*;0;j/@x\xxxx"s;x@xx,0;%#x\"\;xxqsj*j"0j%%jj'j,#\"j%qs,q0q2/"\%s@//s;0;%;;0"s77*77777@xxxxxx@@

```

Try it online!

Hopefully `@` makes even more languages harder to use.... looking at you Befunge-98

# Answer
> 4 votes
# Trigger, 351 bytes

\\$y=26\\$. Used so far: `1'2q#,9/j\;0"35s46%7*x@f8.`

```
...ffffffffff.ffffffffffffff.88888.88888.88888.8888.88@.@@*@@@@@@@@7.%7*77%*7*77%666666%@x*78.8.87*7%*7*.7@7%6*@66666666.6655555555555555444444%*@**4%44*4*444444xx@xx".033333%33333333s;s\/s@/90*%35*s46#".9\s99%%9%90s9/"/j0s,.\"\*0\"#s,#,22s01;"*'s"*;0;j/@x.\.xxxx"s;x@xx..,0;%#x\"\;xxqsj*j"0j%%jj'j,#\"j%qs,q0q28/"\%s@//s;0;%;;0"s.77*7.7777@xxxxxx@@..

```

Try it online!

We're out of digits now, that should make things a little more interesting. I think we've made every language other than Trigger unusable at this point...

# Answer
> 4 votes
# HTML, 630 bytes

\\$y = 35\\$, Used so far: `1'2q#,9/j;0"35s46%7*x@f8.a`&Hb=cd<`

<<dddcccccccccccccccccccccccccccccdc==d=b=b=b=`HH&&&a&&a&a&&.&&&&&&&&&&&&&&&&&&&&&aaaaaaaaaaaaaaaaaaaaaaaa..ffffffffff.ffffffffffffff.88888.88888.88888.8888.88@.@@*@@@@@@@@7.%7*77%*7*77%666666%@x*78.8.87*7%*7*.7@7%6*@66666666.66555555b55HHbHHHHHHHHHHHHHHHHHHHHHHHHHH555555444444%*@**4%44*4*444444xx@xx".==033333%33333333s;s\/s@/90*%35*s46#".9\s99%%9%90s9/"/j0s,.`\`ccdc"`\*0\"#s,`#,22s01;"*'s"*;0;j/@x.\.xxxx"s;x@xx..,0;%#x\"\;xxqsj*j"0j%%jj'j,#\"j%qs,q0q28/"\%s@//s;0;%;;0"s.77*7.========================7777@xxxxxx@@..```````````````````````bbbbbbbbbbbbbbbbbbbbbbbbbbdddddddddddddddddddddddddddd<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<</code></pre>

Save as `index.html` and run with `w3m -dump index.html`, so it goes to stdout as expected.

`<dd....` is an un-closed html tag, which rendered into nothing. So the first `<` character rendered as HTML content.

w3m is an old school browser which use text I/O to render HTML. As this question is requiring stdout output. I'm also surprised that w3m may successfully parse and render such a malformed HTML.

# Answer
> 3 votes
# Keg, `-hr`, 105 bytes

\\$y=14\\$. Used so far: `1'2q#,9/j\;0"3`

```
"03333333333333;\//903#"9\999909/"/j0,\"\0\"#,#,2201;"'";0;j/\";,0;#\"\;qjj"0jjj'j,#\"jq,q0q2/"\//;0;;;0"

```

Try it online! or Check it!

# Answer
> 3 votes
# Trigger, 231 bytes

\\$y=21\\$. Used so far: `1'2q#,9/j\;0"35s46%7*`

```
*7%7*77%*7*77%666666%*77*7%*7*77%6*666666666655555555555555444444%***4%44*4*444444"033333%33333333s;s\/s/90*%35*s46#"9\s99%%9%90s9/"/j0s,\"\*0\"#s,#,22s01;"*'s"*;0;j/\"s;,0;%#\"\;qsj*j"0j%%jj'j,#\"j%qs,q0q2/"\%s//s;0;%;;0"s77*77777

```

Try it online!

This language is really weird. I got this working by pure luck after about an hour

# Answer
> 3 votes
# Keg, `-hr`, 325 bytes

\\$y=25\\$. Used so far: `1'2q#,9/j\;0"35s46%7*x@f8`

```
ffffffffffffffffffffffff888888888888888888888@@@*@@@@@@@@7%7*77%*7*77%666666%@x*78887*7%*7*7@7%6*@666666666655555555555555444444%*@**4%44*4*444444xx@xx"033333%33333333s;s\/s@/90*%35*s46#"9\s99%%9%90s9/"/j0s,\"\*0\"#s,#,22s01;"*'s"*;0;j/@x\xxxx"s;x@xx,0;%#x\"\;xxqsj*j"0j%%jj'j,#\"j%qs,q0q28/"\%s@//s;0;%;;0"s77*77777@xxxxxx@@

```

Try it online!

(no explanation because I have no idea how Keg works)

# Answer
> 2 votes
# Stax, 91 bytes

\\$y=13\\$. Used so far: `1'2q#,9/j\;0"`

```
"0;\//90#"9\999909/"/j0,\"\0\"#,#,2201;"'";0;j/\";,0;#\"\;qjj"0jjj'j,#\"jq,q0q2/"\//;0;;;0"

```

Try it online!

I know that OPs aren't intended to answer their own questions, but after seeing that nobody has the enthusiasm to add the quote character...

# Answer
> 2 votes
# Stax, 136 bytes

\\$y = 16\\$, Used so far: `1'2q#,9/j\;0"35s`

```
55555555555555"03333333333333s;s\/s/9035s#"9\s99990s9/"/j0s,\"\0\"#s,#,22s01;"'s";0;j/\"s;,0;#\"\;qsjj"0jjj'j,#\"jqs,q0q2/"\s//s;0;;;0"s

```

Try it online!

# Answer
> 2 votes
# Keg `-hr`, 153 bytes

\\$y = 17\\$, Used so far: `1'2q#,9/j\;0"35s4`

```
555555555555554444444444444444"03333333333333s;s\/s/9035s4#"9\s99990s9/"/j0s,\"\0\"#s,#,22s01;"'s";0;j/\"s;,0;#\"\;qsjj"0jjj'j,#\"jqs,q0q2/"\s//s;0;;;0"s

```

Try it online!

# Answer
> 2 votes
# Keg, - hr, 171 bytes

\\$y=18\\$. Used so far: `1'2q#,9/j\;0"35s46`

```
66666666666666666555555555555554444444444444444"03333333333333s;s\/s/9035s46#"9\s99990s9/"/j0s,\"\0\"#s,#,22s01;"'s";0;j/\"s;,0;#\"\;qsjj"0jjj'j,#\"jqs,q0q2/"\s//s;0;;;0"s

```

Try it online!

# Answer
> 2 votes
# Octave, 210 bytes

\\$y=20\\$. Used so far: `1'2q#,9/j\;0"35s46%7`

```
7%777%777%666666%777%777%6666666666655555555555555444444%4%444444444"033333%33333333s;s\/s/90%35s46#"9\s99%%9%90s9/"/j0s,\"\0\"#s,#,22s01;"'s";0;j/\"s;,0;%#\"\;qsjj"0j%%jj'j,#\"j%qs,q0q2/"\%s//s;0;%;;0"s7777777

```

Try it online!

Except for MATLAB/Octave, you mean?

# Answer
> 2 votes
# Keg, `-hd`, 300 bytes

\\$y=24\\$ Used so far: `1'2q#,9/j\;0"35s46%7*x@f`

```
ffffffffffffffffffffffff@@@*@@@@@@@@7%7*77%*7*77%666666%@x*77*7%*7*7@7%6*@666666666655555555555555444444%*@**4%44*4*444444xx@xx"033333%33333333s;s\/s@/90*%35*s46#"9\s99%%9%90s9/"/j0s,\"\*0\"#s,#,22s01;"*'s"*;0;j/@x\xxxx"s;x@xx,0;%#x\"\;xxqsj*j"0j%%jj'j,#\"j%qs,q0q2/"\%s@//s;0;%;;0"s77*77777@xxxxxx@@

```

Try it online!

Harder? It actually made it easier. `@` starts a function in Keg, and because there aren't any closing `ƒ`s (and there won't be because it ain't ascii), everything after the first `@` is ignored. What a clanger!

# Answer
> 2 votes
# Trigger, 378 bytes

\\$y = 27\\$, Used so far: `1'2q#,9/j\;0"35s46%7*x@f8.a`

```
aaa.aaaaaaaaaaaaaaaaaaaaaaaa..ffffffffff.ffffffffffffff.88888.88888.88888.8888.88@.@@*@@@@@@@@7.%7*77%*7*77%666666%@x*78.8.87*7%*7*.7@7%6*@66666666.6655555555555555444444%*@**4%44*4*444444xx@xx".033333%33333333s;s\/s@/90*%35*s46#".9\s99%%9%90s9/"/j0s,.\"\*0\"#s,#,22s01;"*'s"*;0;j/@x.\.xxxx"s;x@xx..,0;%#x\"\;xxqsj*j"0j%%jj'j,#\"j%qs,q0q28/"\%s@//s;0;%;;0"s.77*7.7777@xxxxxx@@..

```

Try it online!

# Answer
> 2 votes
# Keg, `-rn`, 406 bytes

\\$y=28\\$, `1'2q#,9/j;0"35s46%7*x@f8.a``

<pre><code>`aaa.aaaaaaaaaaaaaaaaaaaaaaaa..ffffffffff.ffffffffffffff.88888.88888.88888.8888.88@.@@*@@@@@@@@7.%7*77%*7*77%666666%@x*78.8.87*7%*7*.7@7%6*@66666666.6655555555555555444444%*@**4%44*4*444444xx@xx".033333%33333333s;s\/s@/90*%35*s46#".9\s99%%9%90s9/"/j0s,.`\`"`\*0\"#s,`#,22s01;"*'s"*;0;j/@x.\.xxxx"s;x@xx..,0;%#x\"\;xxqsj*j"0j%%jj'j,#\"j%qs,q0q28/"\%s@//s;0;%;;0"s.77*7.7777@xxxxxx@@..```````````````````````

Try it online!

Hehe. I used the power of strings to essentially make those `.`s nops.

# Answer
> 2 votes
# Gol\>\<\>, 465 bytes

\\$y=30\\$, Used so far: `1'2q#,9/j;0"35s46%7*x@f8.a`&H`

`HH&&&a&&a&a&&.&&&&&&&&&&&&&&&&&&&&&aaaaaaaaaaaaaaaaaaaaaaaa..ffffffffff.ffffffffffffff.88888.88888.88888.8888.88@.@@*@@@@@@@@7.%7*77%*7*77%666666%@x*78.8.87*7%*7*.7@7%6*@66666666.6655555555HHHHHHHHHHHHHHHHHHHHHHHHHHHH555555444444%*@**4%44*4*444444xx@xx".033333%33333333s;s\/s@/90*%35*s46#".9\s99%%9%90s9/"/j0s,.`\`"`\*0\"#s,`#,22s01;"*'s"*;0;j/@x.\.xxxx"s;x@xx..,0;%#x\"\;xxqsj*j"0j%%jj'j,#\"j%qs,q0q28/"\%s@//s;0;%;;0"s.77*7.7777@xxxxxx@@..```````````````````````
</code></pre>

Try it online!

## Explanation

```
`   Push codepoint of next character:
 H  'H'
  H Halt, printing TOS as a character

```

# Answer
> 2 votes
# Trigger, 496 bytes

\\$y=31\\$, Used so far: `1'2q#,9/j;0"35s46%7*x@f8.a`&Hb`

<pre><code>bbb`HH&&&a&&a&a&&.&&&&&&&&&&&&&&&&&&&&&aaaaaaaaaaaaaaaaaaaaaaaa..ffffffffff.ffffffffffffff.88888.88888.88888.8888.88@.@@*@@@@@@@@7.%7*77%*7*77%666666%@x*78.8.87*7%*7*.7@7%6*@66666666.66555555b55HHbHHHHHHHHHHHHHHHHHHHHHHHHHH555555444444%*@**4%44*4*444444xx@xx".033333%33333333s;s\/s@/90*%35*s46#".9\s99%%9%90s9/"/j0s,.`\`"`\*0\"#s,`#,22s01;"*'s"*;0;j/@x.\.xxxx"s;x@xx..,0;%#x\"\;xxqsj*j"0j%%jj'j,#\"j%qs,q0q28/"\%s@//s;0;%;;0"s.77*7.7777@xxxxxx@@..```````````````````````bbbbbbbbbbbbbbbbbbbbbbbbbb

Try it online!

# Answer
> 2 votes
# Trigger, 528 bytes

\\$y=32\\$, Used so far: `1'2q#,9/j;0"35s46%7*x@f8.a`&Hb=`

===b=b=b=`HH&&&a&&a&a&&.&&&&&&&&&&&&&&&&&&&&&aaaaaaaaaaaaaaaaaaaaaaaa..ffffffffff.ffffffffffffff.88888.88888.88888.8888.88@.@@*@@@@@@@@7.%7*77%*7*77%666666%@x*78.8.87*7%*7*.7@7%6*@66666666.66555555b55HHbHHHHHHHHHHHHHHHHHHHHHHHHHH555555444444%*@**4%44*4*444444xx@xx".==033333%33333333s;s\/s@/90*%35*s46#".9\s99%%9%90s9/"/j0s,.`\`"`\*0\"#s,`#,22s01;"*'s"*;0;j/@x.\.xxxx"s;x@xx..,0;%#x\"\;xxqsj*j"0j%%jj'j,#\"j%qs,q0q28/"\%s@//s;0;%;;0"s.77*7.========================7777@xxxxxx@@..```````````````````````bbbbbbbbbbbbbbbbbbbbbbbbbb
</code></pre>

Try it online!

# Answer
> 2 votes
# Explode, 741 bytes

\\$y=38\\$. Used thus far: `1'2q#,9/j;0"35s46%7*x@f8.a`&Hb=cd<AB`  (trailing space)

<pre><code>AAB<<dddcccccccccccccccccccccccccccccdc==d=b=b=b=`HH&AAAAAAAAAAAAAAAAAAAAAAB&&a&&a&a&&.&&&&&&&&&&&&&&&&&&&&&aaaaaaaaaaaaaaaaaaaaaaaa..ffffffffff.ffffffffffffff.88888.88888.88888.8888.88@.@@*@@@@@@@@7.%7*77%*7*77%6AAAB66666%@x*78.8.87*7%*7*.7@7%6*@66666666.66555555b55HHbHHHHHHHHHHHHHHHHHHHHHHHHHH555555444444%*@**4%44*4*444444xx@xx".==033333%33333333s;s\/s@/90*%35*s46#".9\s99%%9%90s9/"/j0s,.`AB\`ABccdcAAAAAAAB"`\*0\"#s,`#,22s01;"*'s"*;0;j/@x.\.xxxx"s;x@xx..,0;%#x\"\;xxqsj*j"0j%%jj'j,#\"j%qs,q0q28/"\%s@//s;0;%;;0"s.77*7.========================7777@xxxxxx@@..```````````````````````bbbbbbbbbbbbbbbbbbbbbbbbbbdddddddddddddddddddddddddddd<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<BBBBBBBBBBBBBBBBBBBBBBBBBBBBBB                                      B

Try it online.

**Explanation:**

I just went looking for some random languages that might work, to have something different than Keg and Trigger in the chain. I had never heard about Explode prior, but apparently the tape starts with the amount of spaces equal to the number of lines of the program; which is a single line, thus a single space in this case.
This tape is printed implicitly when the program terminates. Since the program (apparently) doesn't modify the tape in any way, this single space the tape started with is output as our result.

I might try to analyze what each character actually does in the program above, or try to use the language Explode for another challenge, but this will do for now.

# Answer
> 1 votes
# Keg, `-hr`, 120 bytes

\\$y = 15\\$, Used so far: `1'2q#,9/j\;0"35`

```
55555555555555"03333333333333;\//9035#"9\999909/"/j0,\"\0\"#,#,2201;"'";0;j/\";,0;#\"\;qjj"0jjj'j,#\"jq,q0q2/"\//;0;;;0"

```

Try it online!

Yeah, you can pretty much tell that I'm gonna do this a lot.

# Answer
> 1 votes
# Trigger, 435 bytes

\\$y = 29\\$, Used so far: `1'2q#,9/j;0"35s46%7*x@f8.a`&`

`&&&a&&a&a&&.&&&&&&&&&&&&&&&&&&&&&aaaaaaaaaaaaaaaaaaaaaaaa..ffffffffff.ffffffffffffff.88888.88888.88888.8888.88@.@@*@@@@@@@@7.%7*77%*7*77%666666%@x*78.8.87*7%*7*.7@7%6*@66666666.6655555555555555444444%*@**4%44*4*444444xx@xx".033333%33333333s;s\/s@/90*%35*s46#".9\s99%%9%90s9/"/j0s,.`\`"`\*0\"#s,`#,22s01;"*'s"*;0;j/@x.\.xxxx"s;x@xx..,0;%#x\"\;xxqsj*j"0j%%jj'j,#\"j%qs,q0q28/"\%s@//s;0;%;;0"s.77*7.7777@xxxxxx@@..```````````````````````
</code></pre>

Try it online!

It seriously looks like Trigger and Keg are the only viable choices now. The second-twelfth bytes do the magic; it jumps to the second ".", so I could hide my ampersands.

Also, it looks like the "used so far" bit is broken now.

# Answer
> 1 votes
# Trigger, 595 bytes

\\$y = 34\\$, Used so far: `1'2q#,9/j;0"35s46%7*x@f8.a`&Hb=c`

<pre><code>dddcccccccccccccccccccccccccccccdc==d=b=b=b=`HH&&&a&&a&a&&.&&&&&&&&&&&&&&&&&&&&&aaaaaaaaaaaaaaaaaaaaaaaa..ffffffffff.ffffffffffffff.88888.88888.88888.8888.88@.@@*@@@@@@@@7.%7*77%*7*77%666666%@x*78.8.87*7%*7*.7@7%6*@66666666.66555555b55HHbHHHHHHHHHHHHHHHHHHHHHHHHHH555555444444%*@**4%44*4*444444xx@xx".==033333%33333333s;s\/s@/90*%35*s46#".9\s99%%9%90s9/"/j0s,.`\`ccdc"`\*0\"#s,`#,22s01;"*'s"*;0;j/@x.\.xxxx"s;x@xx..,0;%#x\"\;xxqsj*j"0j%%jj'j,#\"j%qs,q0q28/"\%s@//s;0;%;;0"s.77*7.========================7777@xxxxxx@@..```````````````````````bbbbbbbbbbbbbbbbbbbbbbbbbbdddddddddddddddddddddddddddd

Try it online!

# Answer
> 1 votes
# Keg `-rn`, 703 bytes

\\$y=37\\$, Used so far: `1'2q#,9/j;0"35s46%7*x@f8.a`&Hb=cd<AB`

AAB<<dddcccccccccccccccccccccccccccccdc==d=b=b=b=`HH&AAAAAAAAAAAAAAAAAAAAAAB&&a&&a&a&&.&&&&&&&&&&&&&&&&&&&&&aaaaaaaaaaaaaaaaaaaaaaaa..ffffffffff.ffffffffffffff.88888.88888.88888.8888.88@.@@*@@@@@@@@7.%7*77%*7*77%6AAAB66666%@x*78.8.87*7%*7*.7@7%6*@66666666.66555555b55HHbHHHHHHHHHHHHHHHHHHHHHHHHHH555555444444%*@**4%44*4*444444xx@xx".==033333%33333333s;s\/s@/90*%35*s46#".9\s99%%9%90s9/"/j0s,.`AB\`ABccdcAAAAAAAB"`\*0\"#s,`#,22s01;"*'s"*;0;j/@x.\.xxxx"s;x@xx..,0;%#x\"\;xxqsj*j"0j%%jj'j,#\"j%qs,q0q28/"\%s@//s;0;%;;0"s.77*7.========================7777@xxxxxx@@..```````````````````````bbbbbbbbbbbbbbbbbbbbbbbbbbdddddddddddddddddddddddddddd<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<BBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB
</code></pre>

Try it online!

# Answer
> 0 votes
# Keg, `-rn`, 561 bytes

\\$y=33\\$, Used so far: `1'2q#,9/j;0"35s46%7*x@f8.a`&Hb=c`

<pre><code>cccccccccccccccccccccccccccccc===b=b=b=`HH&&&a&&a&a&&.&&&&&&&&&&&&&&&&&&&&&aaaaaaaaaaaaaaaaaaaaaaaa..ffffffffff.ffffffffffffff.88888.88888.88888.8888.88@.@@*@@@@@@@@7.%7*77%*7*77%666666%@x*78.8.87*7%*7*.7@7%6*@66666666.66555555b55HHbHHHHHHHHHHHHHHHHHHHHHHHHHH555555444444%*@**4%44*4*444444xx@xx".==033333%33333333s;s\/s@/90*%35*s46#".9\s99%%9%90s9/"/j0s,.`\`ccc"`\*0\"#s,`#,22s01;"*'s"*;0;j/@x.\.xxxx"s;x@xx..,0;%#x\"\;xxqsj*j"0j%%jj'j,#\"j%qs,q0q28/"\%s@//s;0;%;;0"s.77*7.========================7777@xxxxxx@@..```````````````````````bbbbbbbbbbbbbbbbbbbbbbbbbb

Try it online!

;P

# Answer
> 0 votes
# Keg, `-rn`, 666 bytes

\\$y=36\\$ , Used so far: `1'2q#,9/j;0"35s46%7*x@f8.a`&Hb=cd<A`

AA<<dddcccccccccccccccccccccccccccccdc==d=b=b=b=`HH&AAAAAAAAAAAAAAAAAAAAAA&&a&&a&a&&.&&&&&&&&&&&&&&&&&&&&&aaaaaaaaaaaaaaaaaaaaaaaa..ffffffffff.ffffffffffffff.88888.88888.88888.8888.88@.@@*@@@@@@@@7.%7*77%*7*77%6AAA66666%@x*78.8.87*7%*7*.7@7%6*@66666666.66555555b55HHbHHHHHHHHHHHHHHHHHHHHHHHHHH555555444444%*@**4%44*4*444444xx@xx".==033333%33333333s;s\/s@/90*%35*s46#".9\s99%%9%90s9/"/j0s,.`A\`AccdcAAAAAAA"`\*0\"#s,`#,22s01;"*'s"*;0;j/@x.\.xxxx"s;x@xx..,0;%#x\"\;xxqsj*j"0j%%jj'j,#\"j%qs,q0q28/"\%s@//s;0;%;;0"s.77*7.========================7777@xxxxxx@@..```````````````````````bbbbbbbbbbbbbbbbbbbbbbbbbbdddddddddddddddddddddddddddd<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
</code></pre>

Try it online!

Yet another one. Just like the other one.

# Answer
> 0 votes
# Trigger, 780 bytes

\\$y=39\\$. Used thus far: `1'2q#,9/j;0"35s46%7*x@f8.a`&Hb=cd<AB _`

<pre><code>__AAB<<dddccccccccc___ccccccccccccccccccccdc==d=b=b=b=`HH&_AAAAAAAAA_AAAAAAAA_AAAAAB&&a&_&a&a&&.&&&&&&&&&&&&&&&&&&&&&aaaaaaaaaa__aaaaaaaaa__aaaaa..ffffffffff.ffffffffffffff.88888.88888.88888.8888.88@.@@*@@@@@@@@7.%7*77%*7*77%6AA__AB66666%@x*78.8.87*7%*7*.7@7%6*@66666666.66555555b55HHbHHHHHHHHHHHHHHHHHHHHHHHHHH555555444444%*@**4%4_4*4*444444xx@xx".==033333%33333333s;s\/s@/9_________0*%35*s46#".9\s99%%9%____90s9/_____"/j0s,.`AB\`ABccdcAAAAAAAB"`\*0\"#s,`#,22s01;"*'s"*;0;j/@x.\.xxxx"s;x@xx..,0;%#x\"\;xxq__sj*j"0j%%jj'j,#\"j%qs,q0q28/"\%s@_//s;0;%;;0"s.77*7.========================7777@xxxxxx@@..```````````````````````bbbbbbbbbbbbbbbbbbbbbbbbbbdddddddddddddddddddddddddddd<<<<<<<<<<<<__<<<<<<<<<<<<<<<<<<<<<BBBBBBBBBBBBBBBBBBBBBBBBBBBBBB                                      B

Try it online!

# Answer
> 0 votes
# Trigger, 820 bytes

\\$y=40\\$. Used so far: `1'2q#,9/j\;0"35s46%7*x@f8.a`&Hb=cd<AB _z`. (I have restored `\`, which disappeared from this string earlier in the thread.)

zzz_z_AAzB<<ddzdcccczccccc__z_cccccccczccccccccccccdc==d=b=b=b=`HH&_AAAAzAAAAA_AAAAzAAAA_AAAAAB&&a&_&a&a&&.&&&&z&&&&&z&&&&&z&&&&&&&aaaazaaaaaa__aaaazaaaaa__aaaaa..fffffzfffff.ffffzffffzffffff.88888.88888.88888.8888.88@.@@*@@@@@@@@7.%7*77%*7*77%z6AA__zAB66666%@x*78.8.87*7%*7*.7@7%6*@66666666.66555555b55HHbHHHHHHzHHHHHHHzHHHHHHHHHzHHHH555555444444%*@**4%4_4*4*444444xx@xx".==033333%3333z3333s;s\/s@/9____z_____0*%35*s46#".9\s99%%9%____90s9/_____"/j0s,.`AB\`ABccdcAAzAAAAAB"`\*0\"#s,`#,22s01;"*'s"*;0;j/@x.\.xxxx"s;x@xx..,0;%#x\"\;xxq__sj*j"0j%%jj'j,#\"j%qs,q0q28/"\%s@_//s;0;%;;0"s.77*7.========z================7777@xxxxxx@@..`````````z``````````````bbbbbbbbbbbbbbbbbbbbbbbzbbbddddzddddddddddddddddzdddddddd<<<<<<z<<<<<<__<<<<<<<<<z<<<<<<<<<<<<zBBBBBBBBBBBBzBBBBBBBBBBBBBBBBBB                                      zzBzz

Try it online!

The previous answer has stood unchallenged for three weeks so it's time to spoil the party. The first three characters really sum up how I feel about the inventiveness of the present submission. It's perfectly set up for a `FizzBuzz` finish, however.

---
Tags: restricted-source, answer-chaining
---


title: Draw the Pentaflake

text:
# Question
Title: Draw the Pentaflake
First of all ... I would like to wish everyone a Merry Christmas (sorry if I am a day late for your timezone).

To celebrate the occasion, we are going to draw a snowflake. Because the year is 201**5** and Christmas is on the 2**5**th (for a large portion of persons), we will draw a **Penta**flake. The Pentaflake is a simple fractal composed of pentagons. Here are a few examples (taken from here):

Each Pentaflake has an order n. The Pentaflake of order 0 is simply a pentagon. For all other orders n, a Pentaflake is composed of 5 Pentaflakes of the previous order arranged around a 6th Pentaflake of the previous order. For example, a Pentaflake of order 1 is composed of 5 pentagons arranged around a central pentagon.

# Input

The order `n`. This may be given in any way except that of a predefined variable.

# Output

An image of the order `n` Pentaflake. Must be at least 100px wide and 100px long. It may be saved to a file, displayed to the user, or outputted to `STDOUT`. Any other form of output is not allowed. All image formats existing before this challenge are allowed.

# Winning

As codegolf, the person with the least number of bytes wins.

# Answer
> 16 votes
# Matlab, 226

```
function P(M);function c(L,X,Y,O);hold on;F=.5+5^.5/2;a=2*pi*(1:5)/5;b=a(1)/2;C=F^(2*L);x=cos(a+O*b)/C;y=sin(a+O*b)/C;if L<M;c(L+1,X,Y,~O);for k=1:5;c(L+1,X+x(k),Y+y(k),O);end;else;fill(X+x*F, Y+y*F,'k');end;end;c(0,0,0,0);end

```

Ungolfed:

```
function P(M);
function c(L,X,Y,O);          %recursive function
hold on;
F=.5+5^.5/2;                  %golden ratio
a=2*pi*(1:5)/5;               %full circle divided in 5 parts (angles)
b=a(1)/2;
C=F^(2*L);
x=cos(a+O*b)/C;               %calculate the relative position ofnext iteration
y=sin(a+O*b)/C;
if L<M;                       %current recursion (L) < Maximum (M)? recurse
    c(L+1,X,Y,~O);            %call recursion for inner pentagon
    for k=1:5;
        c(L+1,X+x(k),Y+y(k),O)%call recursion for the outer pentagons
    end;
else;                         %draw
    fill(X+x*F, Y+y*F,'k');
end;
end;
c(0,0,0,0);
end

```

Fifth iteration (already took quite a while to render).

A slight alteration of the code (unfortunately more bytes) results in this beauty=)

Oh, and another one:

# Answer
> 8 votes
## MATLAB, 235 233 217 bytes

**Update:** a bunch of suggestions from **@flawr** helped me lose 16 bytes. Since only this allowed me to beat flawr's solution, and that I wouldn't have found the challenge without flawr's help in the first place, consider this a joint submission by us:)

```
N=input('');f=2*pi/5;c=1.5+5^.5/2;g=0:f:6;p=[cos(g);sin(g)];R=[p(:,2),[-p(2,2);p(1,2)]];for n=1:N,t=p;q=[];for l=0:4,q=[q R^l*[c-1+t(1,:);t(2,:)]/c];end,p=[q -t/c];end,p=reshape(p',5,[],2);fill(p(:,:,1),p(:,:,2),'k');

```

This is another MATLAB solution, this one based on a philosophy of iterated function systems. I was mostly interested in developing the algorithm itself, and I haven't golfed too much on the solution. There's surely room for improvement. (I contemplated using a hard-coded fixed-point approximation for `c`, but that wouldn't be nice.)

Ungolfed version:

```
N=input('');                                % read order from stdin

f=2*pi/5;                                   % angle of 5-fold rotation
c=1.5+5^.5/2;                               % scaling factor for contraction

g=0:f:6;
p=[cos(g);sin(g)];                          % starting pentagon, outer radius 1
R=[p(:,2),[-p(2,2);p(1,2)]];                % 2d rotation matrix with angle f

for n=1:N,                                  % iterate the points
    t=p;
    q=[];
    for l=0:4,
       q=[q R^l*[c-1+t(1,:);t(2,:)]/c];     % add contracted-rotated points
    end,
    p=[q -t/c];                             % add contracted middle block
end,

p=reshape(p',5,[],2);                 % reshape to 5x[]x2 matrix to separate pentagons
fill(p(:,:,1),p(:,:,2),'k');          % plot pentagons

```

Result for `N=5` (with a subsequent `axis equal off` for prettiness, but I hope that doesn't count byte-wise):

# Answer
> 8 votes
## Mathematica, 200 bytes

```
a=RotationTransform
b=Range
r@k_:={Re[t=I^(4k/5)],Im@t}
R@k_:=a[Pi,(r@k+r[k+1])/2]
Graphics@Nest[GeometricTransformation[#,ScalingTransform[{1,1}(Sqrt@5-3)/2]@*#&/@Append[R/@b@5,a@0]]&,Polygon[r/@b@5],#]&

```

The last line is a function which can be applied to an integer `n`.

Mathematica function names are long. Somebody should entropy-encode them and make a new language from it. :)

When applied to `1`:

When applied to `2`:

# Answer
> 8 votes
# Mathematica, 124 bytes

Mathematica supports new syntax for `Table` since version 10: `Table[expr, n]`, which saves another byte. `Table[expr, n]` is equivalent to `Table[expr, {n}]`.

```
f@n_:=(p=E^Array[π.4I#&,5];Graphics@Map[Polygon,ReIm@Fold[{g,s}~Function~Join[.62(.62g#+#&/@s),{-.39g}],p,p~Table~n],{-3}])

```

The core of this function is using complex numbers to do tranformations and then convert them to points by `ReIm`.

Test case:

```
f[4]

```

# Answer
> 4 votes
## Mathematica, ~~199~~ 196 bytes

Edging out Peter Richter's answer by a hair, here's one of my own. It leans heavily on graphics functionality, and less on math and FP. The CirclePoints builtin is new in 10.1.

```
c=CirclePoints;g=GeometricTransformation;
p@0=Polygon@c[{1,0},5];
p@n_:=GraphicsGroup@{
        p[n-1],
        g[
          p[n-1]~g~RotationTransform[Pi/5],
          TranslationTransform/@{GoldenRatio^(2n-1),n*Pi/5}~c~5
        ]
      };
f=Graphics@*p

```

Edit: Thanks to DumpsterDoofus for GoldenRatio

# Answer
> 4 votes
# Mathematica, 130 bytes

```
r=Exp[Pi.4I Range@5]
p=1/GoldenRatio
f@0={r}
f@n_:=Join@@Outer[1##&,r,p(f[n-1]p+1),1]~Join~{-f[n-1]p^2}
Graphics@*Polygon@*ReIm@*f

```

I use a similar technique to njpipeorgan's answer (in fact I stole his `2Pi I/5 == Pi.4I` trick), but implemented as a recursive function.

Example usage (using `%` to access the anonymous function that was output on the last line):

```
 %[5]

```

# Answer
> 3 votes
## Wolfram Language (Mathematica), ~~96~~ ~~90~~ 84bytes

```
Region@Polygon@ReIm@Nest[Join[Tr/@Tuples@{.62p,t=.39#},-t]&,{p=(-1)^(.4Range@5)},#]&

```

---
Tags: code-golf, graphical-output
---


title: Generate Pyramid Scheme code

text:
# Question
Title: Generate Pyramid Scheme code
Pyramid Scheme is a language being developed by @ConorO'Brien. In Pyramid Scheme, the code that you write looks like this:

```
      ^         ^
     / \       /3\
    /   \      ---
   /  +  \
  ^-------^
 /9\     /3\
/123\    ---
-----

```

Now, that code has two obvious qualities: It's difficult to parse, and it's difficult to write. Conor has solved the first one, however it will be your job to solve that second issue.

---

The above code is processed by the PyramidScheme interpreter into a nested string array, like this:

```
[["+", ["9123", "3"]], "3"]

```

Your task is to write a program or function, which given a nested array of strings, outputs or returns the recreated PyramidScheme code. You may assume that the input array will always be valid.

A pyramid is an isosceles triangle. The top is `^`, the sides slope diagonally away with `/` and `\`, and the bottom is `-`. The two bottom corners are either empty or contain the start of other pyramids, which are arguments. The middle is filled with the pyramid's name, ignoring line breaks.

Here's how the parser converts the code into a useable format. First, it scans for a top-level pyramid. If it takes no arguments, it represents it with a single string and moves on. Otherwise, it represents is as an array `["name",[arg1,arg2]]` or `["name",[arg1]]`. The arguments are the pyramids at the bottom left and bottom right of the pyramid, which may be either string or more arrays described as above. You may notice that this somewhat resembles Lisp, in which case you may also have noticed the awful pun that is the language name. After the pyramid is fully represented, the parser moves on to the next one.

This is , shortest code wins!

## Test Cases: These are not the only valid outputs, these are example of valid outputs.

```
[["+", ["9123", "3"]], "3"]

      ^         ^
     / \       /3\
    /   \      ---
   /  +  \
  ^-------^
 /9\     /3\
/123\    ---
-----

```

---

```
[["out", [["chr", ["72"]], ["chr", ["101"]]]], ["out", [["chr", ["108"]]]], ["out", [["chr", ["108"]]]], ["out", [["chr", ["111"]]]]]

        ^      ^     ^     ^
       / \    / \   / \   / \
      /out\  /out\ /out\ /out\
     ^-----^ -----^----- -----^
    / \   / \    / \         / \
   /chr\ /chr\  /chr\       /chr\
  ^----- -----^ -----^     ^-----
 / \         / \    / \   / \
/72 \       /101\  /108\ /111\
-----       -----  ----- -----

```

---

```
[ ["+", [ ["asdfghjkl"], ["do", [ "1" ]] ]] ]

       ^
      / \
     / + \
    /     \
   ^-------^
  /a\     /d\
 /sdf\   /o  \
/ghjkl\ ^-----
-------/1\
       ---

```

Notice in the second test case, the second and third `out` pyramid both have a `["chr", ["108"]]` as a parameter, which is collapsed into one pyramid stack shared by two top-level ones. This is a valid optimization your code may support, but it is completely optional; scoring is not based on the length of your output.

For the curious, the first case displays `9126 3` due to implicit printing of toplevel pyramids, the second one prints `Hello`, and the last one is a syntax error, included just because it has a neat structure.

---

You may assume that the input only contains printable ASCII, excluding spaces, `^`, `/`, `\`, and `-`. The input will always be valid, and contain at least one pyramid. There is no limit on the size of the array or the input strings, however you may write your code as if your language's default integer type was infinite precision and that your computer has arbitrary memory. If taking input as a single string, you may use anything reasonable (comma, space, etc. as long as it's in printable ascii and not `"` or `[]`) to delimit arrays. You do not have to include brackets surrounding the entire thing, and instead take multiple arrays separated by your delimiter.

Your output does not have to be golfed, you may insert extra space or make your pyramids larger than necessary. Toplevel pyramids *should* be on the first line. Output should be a string with newlines or a list of strings.

Anyone who *does* include a version of their code which optimally golfs the pyramids may receive some rep in the form of upvotes/bounties (but probably just upvotes).

# Answer
## Common Lisp - ~~2524~~ 1890 bytes

```
(defun f(i)(let((s(loop as r in i collect(g r)))(n())(output""))(loop until n do(setf n T)(loop as r in s do(if(cdr r)(progn(setf output(c output(e r))(cdr r)(cdr(cdr r)))(setf n()))(setf output(c output(b(car r))))))(setf output(c output(format()"~%"))))output))(defun g(r)(if(stringp r)(d(m(length r))r)(if(<(length r)2)(d(m(length(car r)))(car r))(if(=(length(e r))1)(let((h(g(car(e r))))(p(d(m(length(car r)))(car r))))(let((o(+ 1(position #\^(e h))))(parent_length(car p)))(if(<(-(car h)o)parent_length)(l(cons(+ o parent_length)())(loop as n in(butlast(cdr p))collect(c(b o)n))(cons(c(subseq(e h)0 o)(car(last p)))())(loop as n in(cdr(cdr h))collect(c n(b (- parent_length(-(car h)o))))))(let((i(-(- o 1)parent_length)))(l(cons(car h)())(loop as n in(butlast(cdr p))collect(c(b o)n(b i)))(cons(c(subseq(nth 1 h)0 o)(car(last p))(b i))())(cddr h))))))(let((l-h(g(car(e r))))(r-h(g(e(e r)))))(let((ll(position #\^(e l-h)))(rl(position #\^(e r-h))))(let((lr(-(car l-h)ll 1))(rr(-(car r-h)rl 1)))(let((p(d(max(m(length(car r)))(ceiling(+ lr rl)2))(car r))))(let((m-pad(if(>(car p)(+ lr rl))(-(car p)lr rl)0)))(l(cons(+ ll 1(car p)1 rr)())(loop as n in(butlast(cdr p))collect(c(b(+ 1 ll))n(b(+ 1 rr))))(cons(c(subseq(e l-h)0(+ 1 ll))(car(last p))(subseq(e r-h)rl))())(loop as y in(append(cddr l-h)(make-list(length l-h):initial-element(b(car l-h))))as z in(append(cdr(cdr r-h))(make-list(length r-h):initial-element(b(car r-h))))collect(c y(b m-pad)z))))))))))))(defun d(r n)(cons(+(* 2 r)1)(l(cons(c(b r)"^"(b r))())(loop as i from 1 to r collect(c(b(- r i))"/"(subseq(c n(b(expt i 2)))(expt(- i 1)2)(expt i 2))"\\"(b(- r i))))(cons(make-string(+ 1(* 2 r)):initial-element #\-)()))))(defun m(l)(+ 1(floor(sqrt l))))(defun b(n)(make-string n :initial-element #\space))(defun c(&rest a)(apply 'concatenate 'string a))(defun l(&rest a)(apply 'concatenate 'list a))(defun e(tree)(nth 1 tree))

```

Thanks to @coredump for a number of golfing tricks. Sample output from the question:

```
> (f '(("out" (("chr" ("72")) ("chr" ("101")))) ("out" (("chr" ("108")))) ("out" (("chr" ("108")))) ("out" (("chr" ("111"))))))
          ^               ^          ^          ^
         /o\             /o\        /o\        /o\
        /ut \           /ut \      /ut \      /ut \
       /     \         ^-----     ^-----     ^-----
      /       \       /c\        /c\        /c\
     ^---------^     /hr \      /hr \      /hr \
    /c\       /c\   ^-----     ^-----     ^-----
   /hr \     /hr \ /1\        /1\        /1\
  ^-----    ^-----/08 \      /08 \      /11 \
 /7\       /1\    -----      -----      -----
/2  \     /01 \
-----     -----

> (f '( ("+" ( ("asdfghjkl") ("do" ( "1" )) )) ))
          ^
         /+\
        /   \
       /     \
      /       \
     /         \
    ^-----------^
   /a\         /d\
  /sdf\       /o  \
 /ghjkl\     ^-----
/       \   /1\
---------  /   \
           -----

> (f '(("+" ("9123" "3")) "3"))
       ^        ^
      /+\      /3\
     /   \    /   \
    /     \   -----
   ^-------^
  /9\     /3\
 /123\   /   \
/     \  -----
-------

```

Here is the original, (mostly) ungolfed version:

```
(defun f (input)
    (let ((trees (loop for tree in input collect (g tree)))
          (done nil)
          (output ""))
        (loop while (not done)
            do  (setf done T)
                (loop for tree in trees
                    do  (if (cdr tree)
                            (progn
                                (setf output (conStr output (car (cdr tree))))
                                (setf (cdr tree) (cdr (cdr tree)))
                                (setf done nil))
                            (setf output (conStr output (blank (car tree))))))
                (setf output (conStr output  (format nil "~%"))))
        output))

;creates a single tree
;output is a list, first element is the length of each line, the rest are the lines of text
(defun g (tree)
    (if (stringp tree)
        ;strings should be drawn as just the pyramid for the name
        (draw-body (min-rows (length tree)) tree)

        (if (< (length tree) 2)
            ;lists with no arguments should be drawn as just the pyramid for the name
            (draw-body (min-rows (length (car tree))) (car tree))
            (if (= (length (car (cdr tree))) 1)
                ;single child
                (let ((child (g (car (car (cdr tree))))) (parent (draw-body (min-rows (length (car tree))) (car tree))))
                    (let ((parent_offset (+ 1 (position #\^ (first-line child)))) (parent_length (car parent)))
                        (if (< (- (car child) parent_offset) parent_length)
                            (let ((child-fill (- parent_length (- (car child) parent_offset))))
                                (concatenate 'list
                                    (cons (+ parent_offset parent_length) nil)
                                    (loop for line in (butlast (cdr parent))
                                        collect (conStr (blank parent_offset) line))
                                    (cons (conStr (subseq (nth 1 child) 0 parent_offset) (car (last parent))) nil)
                                    (loop for line in (cdr (cdr child))
                                        collect (conStr line (blank child-fill)))))
                            (let ((parent-fill (- (- parent_offset 1) parent_length)))
                                (concatenate 'list
                                    (cons (car child) nil)
                                    (loop for line in (butlast (cdr parent))
                                        collect (conStr (blank parent_offset) line (blank parent-fill)))
                                    (cons (conStr (subseq (nth 1 child) 0 parent_offset) (car (last parent)) (blank parent-fill)) nil)
                                    (cdr (cdr child)))))))
                ;two children
                (let ((l-child (g (car (car (cdr tree))))) (r-child (g (car (cdr (car (cdr tree)))))))
                    (let ((lc-l-width (position #\^ (first-line l-child))) (rc-l-width (position #\^ (first-line r-child))))
                        (let ((lc-r-width (- (car l-child) lc-l-width 1)) (rc-r-width (- (car r-child) rc-l-width 1)))
                            (let ((parent (draw-body (max (min-rows (length (car tree))) (ceiling (+ lc-r-width rc-l-width) 2)) (car tree))))
                                (let ((m-pad (if (> (car parent) (+ lc-r-width rc-l-width))
                                            (- (car parent) lc-r-width rc-l-width)
                                            0)))
                                    (concatenate 'list
                                        (cons (+ lc-l-width 1 (car parent) 1 rc-r-width) nil)
                                        (loop for line in (butlast (cdr parent))
                                            collect (conStr (blank (+ 1 lc-l-width)) line (blank (+ 1 rc-r-width))))
                                        (cons (conStr (subseq (first-line l-child) 0 (+ 1 lc-l-width)) (car (last parent)) (subseq (first-line r-child) rc-l-width)) nil)
                                        (loop for left in (append (cdr (cdr l-child)) (make-list (length l-child) :initial-element (blank (car l-child))))
                                            for right in (append (cdr (cdr r-child)) (make-list (length r-child) :initial-element (blank (car r-child))))
                                            collect (conStr left (blank m-pad) right))))))))))))

;create a single pyramid
; output is a list, first element is the length of each line, the rest are the lines of text
(defun draw-body (rows name)
    (print rows)
    (print name)
    (cons (+ (* 2 rows) 1)
        (concatenate 'list (cons (conStr (blank rows) "^" (blank rows)) nil)
            (loop for i from 1 to rows
                collect (conStr (blank (- rows i)) "/" (subseq (conStr name (blank (expt i 2))) (expt (- i 1) 2) (expt i 2)) "\\" (blank (- rows i))))
            (cons (make-string (+ 1 (* 2 rows)) :initial-element #\-) nil))))

(defun min-rows (l)
    (+ 1 (floor (sqrt l))))

(defun blank (n)
    (make-string n :initial-element #\space))

(defun conStr (&rest args)
    (apply 'concatenate 'string args))

(defun first-line (tree)
    (car (cdr tree)))

```

Try it Online!
> 28 votes

# Answer
## Python 3, ~41.3KB + tests and examples

So, I didn't realise this was a challenge, and I wrote a whole language which compiles into Pyramid scheme... It's called psll, and you can find it here. It has a bunch of bells and whistles, syntactic sugar constructs: functions (kinda) and strings, compiler optimisation etc.

This is not exactly a competing answer, but I feel it's heavily relevant so I should post it here.
> 10 votes

---
Tags: code-golf, ascii-art, parsing, lisp
---


# Question
Title: Find the index of reflection of a substring of a palindrome
**Problem Statement**: You will receive a substring of a palindromic string. You must return the index of the substring which marks the point of reflection of the original string. You are only provided the substring, which is not necessarily a palindrome because it is not necessarily centered about the middle of the original palindromic string.

**Input**: Substring of length `2n + 1, 1 <= n <= 1000`, which encompasses the center of reflection of some larger palindromic string.

**Output**: Return the index of the substring which marks the point of reflection. May be 0-indexed or 1-indexed.

**Test cases** (character at desired index is bold to show the desired output more clearly):

*Input*

1. manaplana**c**analpan
2. car**o**racati
3. wlatem**y**meta
4. na**s**anita

*Output*

1. 9 (the full string was “a man a plan a canal panama”, with spaces removed)
2. 4 (the full string was “was it a car or a cat i saw”, with spaces removed)
3. 6 (the full string was “mr owl are my metal worm”, with spaces removed)
4. 2 (the full string was “oozy rat in a sanitary zoo”, with spaces removed)

**Winning Criterion**: This is Shortest code in bytes wins.

**Assumption**: Assume there is just a single candidate palindrome

**Restriction**:`0` and `2n` (last index) are invalid output.

# Answer
# , 26 25 bytes

```
[:(-:@i.>./)[:(*/*#)/.=/~

```

Try it online!

## how

`=/~` creates a function table comparing all possible pairs of characters. Taking `'nasanita'` as an example:

```
1 0 0 0 1 0 0 0
0 1 0 1 0 0 0 1
0 0 1 0 0 0 0 0
0 1 0 1 0 0 0 1
1 0 0 0 1 0 0 0
0 0 0 0 0 1 0 0
0 0 0 0 0 0 1 0
0 1 0 1 0 0 0 1

```

Notice the `/`-direction diagonals. If one of those is all ones, it corresponds to an embedded palindrome.

J has an adverb `/.` which lets us to apply a verb to each diagonal.

We choose the verb `(*/*#)` -- the sum multiplied by the length. Thus it will be the length of the diagonal if it's all ones, and 0 otherwise:

```
1 0 0 0 5 0 0 0 0 0 0 0 0 0 1

```

`i.>./` Find the index of the max element within that list. In this case the index of 5 is 4.

`-:@` And divide it by 2.
> 5 votes

# Answer
# Raku, ~~47~~ 40 bytes

```
{m:ex/.+)>.<{$/.flip}>/.max(*.chars).to}

```

Try it online!

Match all palindromes in the string, find the maximum length one, and output its center index.
> 2 votes

# Answer
# Python 2, 65 bytes

```
f=lambda s,n=1:n*(s[n+1:2*n+1]==s[n-1:n-len(s)<<1:-1])or f(s,n+1)

```

Try it online!

---

Consider the string `abcdefg`. Here's what it looks like checking for palindromes around each character:

```
abcdefg
a c
ab de
abc efg
  cd fg
    e g

```

We see for the right string, the index goes from `n+1` to `2*n+1`. The left string is trickier, but looking in reverse (starting from the end of the string) we start at `n-1` and move to `2*(n-len(s))` (this is a negative number that indexes from the back of the string). Since we can assume there is only one viable palindrome candidate, we can terminate early if we find one.

---

### Python 3.8, 72 bytes

```
f=lambda s,t='':(max(k:=s[1:],t).find(min(k,t))==0)*len(t)or f(k,s[0]+t)

```

Try it online!

This approach seemed promising but was just longer.
> 2 votes

# Answer
# Retina, 53 bytes

```
Lv$`((.)+).(?<-2>\2)+(?(2)(?!))
$.1;$.($`$1
N`
L`\d+$

```

Try it online! Link includes test cases. 0-indexed. Explanation:

```
((.)+).(?<-2>\2)+(?(2)(?!))

```

Match and separately capture a number of characters in `\2`, then match the centre character, then match and pop each character from `\2`, ensuring that all matched characters get popped. This therefore ensures that the whole match is a palindrome.

```
Lv$`
$.1;$.($`$1

```

Consider all overlapping matches and output the length of the palindromic prefix and position of the centre (which is the position of the match plus the length of the palindromic prefix).

```
N`

```

Sort in order of length.

```
L`\d+$

```

Take the position of the last (i.e. longest) match.
> 2 votes

---
Tags: code-golf, string, palindrome
---


title: Count Until Overflow

text:
# Question
Title: Count Until Overflow
### The challenge:

Assuming you have \\$ X \\$ collections, each collection \\$ C\_i \\$ has a name \\$ N\_i \\$ and a capacity \\$ N\_i \\$ of elements - Determine which collection will be overflowed first while counting the occurrences of the names in a cyclic list. Also print how many cycles of the list occurred.

**Example**:

4 Collections are available:

* Name: "cat", Capacity: 3
* Name: "dog", Capacity: 4
* Name: "parrot", Capacity: 1
* Name: "otter", Capacity: 5

Given the list: `["dog","cat","parrot","otter","otter","cat","parrot","cat","cat","dog"]`, "parrot" collection will be overflowed first, since we've counted two "parrot"s to the "parrot" collection which has a capacity of 1. At the point of the overflow, there were only 1 dog, 2 cats, 2 otters - these collection are still capable to get more elements. 0 cycles occurred in that case.

Another example that demonstrate the cyclic property:

For the same collections, given the list: `["dog","cat","cat","parrot","otter"]`, "cat" collection will be overflowed first, since after reading the last element "otter", we continue reading the list again from the start ("dog"), and we are reaching 4 cats before any other collection reaches the capacity. 1 cycle occurred in that case.

---

### Assumptions:

* Collections with \\$ C\_i = 0\\$ are possible.
* In case there will never be an overflow, the program should print falsely value.
* It is possible to meet elements in the list that has no collection to be counted into, although you can assume all elements in the list contains `[A-Za-z]` characters only.
* Name of a collection contains `[A-Za-z]` characters only.
* Names of collections and elements are case sensitive.
* It is possible to get no collections or an empty list as an input.

---

### Input:

* A list of collections, each collection has a name and capacity. (You can pass the names and the capacities in two different arguments that keep the relative order).
* A list of elements, each element.

You can pass the input in any sensible way. Possible options:

```
[[["cat",3],["dog",4],["parrot",1],["otter",5]],["dog","cat","parrot","otter","otter","cat","parrot","cat","cat","dog"]]

[["cat",3,"dog",4,"parrot",1,"otter",5],["dog","cat","parrot","otter","otter","cat","parrot","cat","cat","dog"]]

["cat","dog","parrot","otter"],[3,4,1,5],["dog","cat","parrot","otter","otter","cat","parrot","cat","cat","dog"]]

cat,3
dog,4
parrot,1
otter,5
dog,cat,parrot,otter,otter,cat,parrot,cat,cat,dog

```

---

### Output:

* The name of the collection that will overflow first.
* The amount of reading cycles on the list.

or falsely if no collection will ever be overflowed.

---

### Scoring:

Since this is , lowest bytes wins.

---

### Test Cases:

```
[[["cat",3],["dog",4],["parrot",1],["otter",5]],["dog","cat","parrot","otter","otter","cat","parrot","cat","cat","dog"]] --> "parrot",0

[[["cat",3],["dog",4],["parrot",1],["otter",5]],["dog","cat","cat","parrot","otter"]] --> "cat",1

[[["cat",7],["dog",8]],["dog","cat"]] --> "cat",7

[[["cat",7],["dog",8]],["woof","meow"]] --> False

[[["cat",7],["dog",8]],["Cat","Dog"]] --> False

[[["cat",1],["dog",0]],[]] --> False

[[["cat",0],["dog",0],["parrot",1],["otter",5]],["otter","otter","otter","otter","otter","parrot","dog"]] --> "dog",0

[[],["dog","cat"]] --> False

```

# Answer
> 4 votes
# JavaScript (ES6), 63 bytes

Expects `(c)(a)`, where `c` is an object holding the collections (keys = names, values = capacities), and `a` is the list of items.

Returns either `[name, count]` or `0`.

```
(c,e=n=0)=>g=a=>a.every(s=>~--c[e|=c[s],v=s])?e&&g(a,n++):[v,n]

```

Try it online!

### Commented

```
( c,               // c = object describing the collections
  e =              // e = flag to detect whether at least one item requested in the
                   //     list has a non-zero capacity
  n = 0            // n = cycling counter
) =>               //
  g = a =>         // g is a recursive function taking the list of items a[]
    a.every(s =>   // for each value s in a[]:
      ~--c[        //   try to decrement c[s] and apply a bitwise NOT on the result
        e |= c[s], //   set e if c[s] is non-zero (before being decremented)
        v = s      //   set v to s
      ]            //   this yields 0 if and only if c[s] is defined and was set to 0
                   //   (if c[s] is undefined, --c[s] is NaN and ~--c[s] is -1)
    ) ?            // end of every(); if truthy:
      e &&         //   abort if e = 0, so that we don't loop forever
      g(a, n++)    //   otherwise, increment n and do a recursive call
    :              // else:
      [v, n]       //   return the result pair

```

# Answer
> 4 votes
# Io, ~~157~~ 153 bytes

```
method(~,\,(if(X := ~values max,X,0)* ~size)repeat(i,if(~hasKey(x := \at(i% \size)asString)and~atPut(x,~at(x)-1)at(x)<1,return list(x,(i/ \size)round))))

```

Try it online!

## Explanation (Ungolfed)

```
method(a, b,                                    // Take inputs a & b.
    (if(X := a values max, X, 0)                // The max of an empty list is nil, so we gotta return 0 if max is nil.
    * a size) repeat(i,                         // Repeat max of capacities * dict size:
        if(a hasKey(x :=b at(i%b size)asString) //     If the dict a has (x := b's current cyclic index)
           and a atPut(x,a at(x) - 1)at(x) < 1, //     And decrementing that index results in 0:
            return list(x,(i/b size)round)      //         Return [x, iteration # / size of list]
        )
    )                                           // After the Repeat: If nothing is returned from the if expression,
)                                               // a falsy value will be returned by default.

```

# Answer
> 3 votes
# , 99 bytes

```
function(e,k)(which(sapply(rep(e,sum(unlist(k))),function(y)k[[y]]<<-k[[y]]-1)<0)[1]-1)%/%length(e)

```

Try it online!

Accepts 'elements' as a character vector and 'collections' as a named list of capacities.
Returns the element name and the number of full cycles at overflow, or `NA` if overflow never happens.

**How?**

```
overflow=o=
function(e,k)               # e=elements, k=collections
 (which( ... )[1]           # get the first index of...
   sapply(                  # a loop over...
    rep(e,sum(unlist(k))),  # ...lots of repeats of the elements...
     function(y)            # ...at each loop returning...
      k[[y]]<<-k[[y]]-1     # ...the number of free spots left in the collection,
    )<0                     # that is less than zero,
  -1)%/%length(e)           # minus 1, DIV the number of elements
 )                          # (so it's the number of complete loops,
                            # rather than the loop-in-progress)

```

# Answer
> 3 votes
# Charcoal, ~~62~~ 46 bytes

```
¿Φθ№η§ι¹«Ｗ¬Φυ№θκＦη⊞υ⟦№Ｅυ§λ¹κκ⟧⟦⊟§Φυ№θι⁰Ｉ⊖÷ＬυＬη

```

Try it online! Link is to verbose version of code. Takes input as an array of `[capacity, name]` pairs and an array of elements. Explanation:

```
¿Φθ№η§ι¹«

```

If there are no collections with an element, do nothing (falsy value), otherwise:

```
Ｗ¬Φυ№θκ

```

Repeat until an element causes the collection to overflow...

```
Ｆη⊞υ⟦№Ｅυ§λ¹κκ⟧

```

... for each element in the input, push its previous appearance count and the element to the predefined empty list. If the pair appears in the collection, this means that we had already exhausted it and this element now makes the collection overflow.

```
⟦⊟§Φυ№θι⁰Ｉ⊖÷ＬυＬη

```

Get the first element to overflow, plus calculate the number of iterations of the above loop and decrement it, which gives the number of whole cycles.

# Answer
> 2 votes
# Python 3.8, 95 bytes

Input is a dictionary and a list. This outputs an empty set if no collection overflows, a tuple otherwise.

```
f=lambda c,l,n=0:{*c}&{*l}and(c[(x:=l.pop(0))]and f({**c,x:c[x]-1},l+[x],n+1)or(x,n//-~len(l)))

```

Try it online!

In Python 3.9 this will be 2 bytes shorter as `{**c,x:c[x]-1}` can be replaced by `c|{x:c[x]-1}` due to this change.

# Answer
> 2 votes
# 05AB1E, 29 bytes

```
åài¹ÞvÐyk>©è<D0‹iyN¹g÷‚që®ǝë0

```

First input is the list of names, second is a flattened list of collections.

Try it online.

**Explanation:**

```
å                         # Check for each string in the first (implicit) input-list if
                          # it's in the second (implicit) input-list
 ài                       # If any is truthy:
   ¹                      #  Push the first input-list again
    Þ                     #  Cycle it indefinitely
     v                    #  Loop over each name `y`:
      Ð                   #   Triplicate the collection list (which will use the implicit
                          #   second input-list in the first iteration)
       yk                 #   Get the index of name `y` in this list
         >                #   Increase this index by 1
          ©               #   Store it in variable `®` (without popping)
           è              #   Use this index+1 to index into the collection-list again
            <             #   Decrease this integer by 1
             D0‹i         #   If this count is now negative:
                  N       #    Push the loop-index `N`
                   ¹g     #    Push the length of the first input-list
                     ÷    #    Integer-divide the index by this length
                 y    ‚   #    Pair it with name `y`
                       q  #    And exit the program
                          #    (after which this pair is output implicitly as result)
                ë         #   Else (the count is still 0 or positive):
                 ®        #    Push the index from variable `®`
                  ǝ       #    And insert the new count back into the collection-list at
                          #    this index
  ë                       #  Else (none of the names is in the collection-list)
   0                      #   Push a 0
                          #   (after which it is output implicitly as falsey result)

```

NOTE: We could omit the final `ë0` so it will implicitly output the second input as falsey result, since only `1` is truthy in 05AB1E. But this might cause confusion if the second input-list is a single pair, which we might confuse as a truthy pair result instead.

# Answer
> 1 votes
# PHP, ~~106~~ ~~104~~ 102 bytes

```
function($a,$b){for(;$b;++$i)foreach($b as$x)if(!isset($a[$x]))$b=0;elseif(!$a[$x]--)return[$x,$i|0];}

```

Try it online!

More verbosity:

```
function( $a, $b ) {
    for( ; $b; ++$i ) {                 // loop infinitely if original list is not empty
                                        // (and +1 cycle counter)
        foreach( $b as $x ) {           // start/restart cycling of list
            if( ! isset( $a[$x] ) ) {   // if item on list is not in collection...
                $b = 0;                 //   empty the list to return Falsey above
            } elseif( ! $a[$x]-- )      // or if item collection has reached 0...
                return [ $x, $i | 0 ];  //   return the set of item and cycle counter
            }
        }
    }
}

```

# Answer
> 1 votes
# Haskell, ~~274 235~~ 228 bytes

```
a!e=[(x,y-sum[1|x==e])|(x,y)<-a]
u(h:t)
 |and[b>=0|(a,b)<-h]=h:u t
 |1>0=h:[]
s((a,b):t)
 |b<0=a
 |1>0=s t
c#l=let o=u$scanl(!)c$cycle l in(s$last o,length o`div`length l)
c&l
 |or[x`elem`l|(x,y)<-c]=print$c#l
 |1>0=print"False"

```

Try it online!

* Saved 45 bytes thanks to @Zgarb !

`&` If there's any valid entry prints result, otherwise prints False.

`#` produces a list of all steps and returns a tuple of :

* element overflowed(`s`) of last iteration ,
* iterations length / list length

`u` stops infinite list when overflow happens.

`!` decremnts corresponding entry of list cycled

# Answer
> 1 votes
# Husk, 27 bytes

```
?ȯsM÷L⁰▼øfo€⁰→mGλ←`Vḣ¢²o>⁰#

```

Try it online!

Takes two arguments: a list of strings in the format `["dog","dog","cat"]` and a list of number-string pairs in the format `[(2,"dog"),(3,"cat")]`. Prints a number-string pair or nothing. I have checked all test cases and the program passes them. Note that the interpreter doesn't like extra spaces in inputs.

If the second input is an empty list, its type needs to be specified or the interpreter can't deduce it and gives a type error. An empty list of number-string pairs is given as `[]:LPNLC`. Apparently the first input can be empty without any issues.

## Explanation

```
Two arguments, one explicit (list of string, accessed through ⁰ by default, ² inside a lambda),
one implicit (list of pairs).

mGλ←`Vḣ¢²o>⁰#   For each pair (n,x), replace n by index of first overflow.
m               Map over list of pairs:
 G              Replace pair (n,x) by (f n x,x) where f is
  λ             an anonymous function:
                 f takes two arguments, one explicit (n, accessed through ⁰) and one implicit (x)
        ²        First program input.
       ¢         Cycle infinitely
      ḣ          and take prefixes.
    `V           1-based index of first prefix that satisfies:
            #     Number of occurrences of x
         o>⁰      is greater than n.
   ←            Decrement to get 0-based index.

fo€⁰→   Remove pairs whose string never occurs in the list:
f       Filter by
    →   right part
 o€     is an element of
   ⁰    first input.
        Because Husk is lazy, the index calculation is never performed for the removed pairs.

?ȯsM÷L⁰▼ø   Produce output.
?           If the filtered list is empty,
        ø   return the empty string.
 ȯsM÷L⁰▼    Otherwise return this:
       ▼    take lexicographic minimum,
   M        apply on its left part:
    ÷        integer division by
     L⁰      length of first input
 ȯs         cast to string (to keep types consistent).

```

I could save a few bytes by returning `(0,"")` as the falsy value instead of using strings, but it's also a valid "truthy" output and thus ambiguous. Since Husk is strongly typed, I can't return a pair for some inputs and a non-pair for others.

---
Tags: code-golf
---