title: Big Ben goes BONG

text:
# Question
Title: Big Ben goes BONG
Your task is to create a program that is to mimic Big Ben (Twitter).

### Task

Whenever a new hour has begun (according to your computer's local time or UTC), you have to output `BONG` repeated `hour` times (with a space between the words). For example, when it's 3 o' clock, you have to output `BONG BONG BONG`. The time format follows the 12-hour time format, ie after 12 o' clock, we have 1 and not 13. The program/function must run forever.

Example:

don't output stuff inside the brackets

```
(start: 00:34 for example)
BONG               (01:00)
BONG BONG          (02:00)
(...)
BONG BONG BONG BONG BONG BONG BONG BONG BONG BONG BONG BONG (12:00)
BONG               (01:00 again)
(...)
(it continues forever)

```

### Rules

* Each series of `BONG`s must be separated by a newline
* Leading/trailing newlines are allowed
* However leading/trailing **spaces** are **not** allowed
* The submission must run forever
* Your output may be printed ±3 seconds from the beginning of the hour
* You may **not** assume the program to be run at any specific hour

This is , so the program with the shortest bytecount wins!

# Answer
# 05AB1E, 43 bytes

```
3600žcžb60*+->Lvw}["BONG "ža<12%>×,5°36*.W]

```

Try it online! (lol this won't work, it will timeout in 60 seconds. Download the 05AB1E interpreter for this)

Explanation:

```
3600žcžb60*+->                          # Get amount of seconds (plus one) until next hour
              Lvw}                      # Wait said amount of seconds
                  [                     # Infinite loop start
                   "BONG "ža<12%>×,     # Print "BONG " multiplied by the amount of hours (12-hour clock)
                               5°36*.W  # Wait an hour (3600000 milliseconds)
                                      ] # Infinite loop end

```

This took me a while to golf! I might be able to golf it a little more, but it beats `*><>`, so that's cool :)

Quick version:

```
1Uw["BONG "X<12%>×,wX>U]

```

Will wait one second on start, and one second between BONGs
> 2 votes

# Answer
# Bash, ~~71~~, ~~70~~, 69 bytes

EDITS:

* Optimized the sleep interval computation a bit, -1 byte;
* Replaced backticks with xargs, -1 byte (Thanks @jrtc27 !).

**Golfed**

```
sleep `date +3600-%s%3600|bc`;yes BONG|sed $(date +%I)q|xargs;exec $0

```

**Explained**

```
#Compute the number of seconds left in the current hour and wait.
sleep `date +3600-%s%3600|bc`;

#Print "hour" (1-12) worth of "BONG" strings, one per line,
#use xargs to merge them into a single space-separated string.
yes BONG|sed $(date +%I)q|xargs

#Re-execute itself (in the same process).
exec $0

```

**Test Version**

Works with minutes instead of hours

```
sleep `date +60-%s%60|bc`;yes BONG|sed $(date +%I)q|xargs;exec $0

```
> 18 votes

# Answer
## \*\>\<\>, ~~48~~ ~~47~~ 44 bytes

```
>s?um?uhc%:?!c21.O
v$o" GNOB"oooo$1-:?!
\aofS

```

Try it here! (or this version which does it every minute for testing)

This outputs a number of `BONG`s separated by spaces based on what hour it is (and 13 is 1, etc). There are no trailing space after the final `BONG`, and there is a trailing newline.

*Technically* this doesn't run *forever* (but it basically does). It leaks ~28 bytes per day (ignoring interpreter overhead ...). It would take ~105062 years for it to leak 1GiB.

Approximating for interpreter overhead, the stack is just a slice of `float64`s on the Golang interpreter. So I simply did `28*8` to come up with 224 bytes per day. I divided this number by the number of bytes in a gibibyte (1073741824) then 365 to approximate that it would take 13132.85 years to leak 1 GiB.

**Note about the interpreters**

The online interpreter is in Javascript. The page must be open and visible for it to check the time it currently is and output the BONGs. The Golang interpreter has no such limitation.

### Explanation

```
Main loop:

s?um?u          O     if seconds == 0 && minutes == 0:
      hc%               push hours % 12 (bongs) to the stack
         :?!c           if bongs is 0, push 12 to the stack
             21.        jump to "output bongs" coords (2, 1)

Output bongs:

Begins at `"` because of the jump.

   " GNOB"            push "BONG " to the stack
          oooo        output "BONG"
              $1-     subtract 1 from bongs
v                :?!  if bongs == 0, move to "newline and sleep"
 $o                   output " "

Newline and sleep:

\                     mirror the IP to the right
 ao                   output a newline
   fS                 sleep for 1.6s
\                     mirror to main loop

```
> 8 votes

# Answer
# JavaScript (ES6), ~~99~~ 93 bytes

```
f=_=>setTimeout('alert("BONG ".repeat(new Date/36e5%12|0||12).trim(f()))',36e5-new Date%36e5)

```

This uses UTC time (which lines up with the actual thing). Due to the untestable nature of the code, you can try the following which does the same thing, but every 60 seconds:

```
f=_=>setTimeout('alert("BONG ".repeat(new Date/36e5%12|0||12).trim(f()))',6e4-new Date%6e4)

f()
```

Here's a bonus 99-byte version which uses local time:

```
f=_=>setTimeout('alert("BONG ".repeat(new Date().getHours()%12||12).trim(f()))',36e5-new Date%36e5)

```
> 7 votes

# Answer
# JavaScript(ES6), ~~125~~ ~~123~~ ~~117~~ 115 bytes

*Thanks to @Flp.Tkc for saving 5 bytes!*

*Thanks to @BenAston for saving 2 more bytes!*

```
a=eval(b=`(new Date).getHours()`);setInterval(w=>eval(b)!=a?console.log(Array(++a%12+1).join`BONG `.trim()):"",1e3)

```

### Snack Snippet

```
a=eval(b=`(new Date).getHours()`);setInterval(w=>eval(b)!=a?console.log(Array(++a%12+1).join`BONG `.trim()):"",1e3)
```
> 6 votes

# Answer
## Batch, 142 bytes

```
@timeout/t>nul 1
@if not %time:~3,5%==00:00 %0
@set/ah=-%time:~0,2%%12
@set s=............
@call set s=%%s:~%h%%%
@echo %s:.=BONG %
@%0

```

Since the file runs as an infinite loop, I start with a 1s delay, as I need one anyway after the bongs, and this saves CPU cycles. The `>nul` is positioned carefully to save a byte (`1>nul` would cause the 1 to be eaten by the redirection). We then loop until both minutes and seconds are zero. The bongs are constructed by taking the negative hour modulo 12, and asking for the last `h` characters from a 12-character string. When `h` is zero this actually gives us the whole string, therefore 12 bongs. It then suffices to replace the characters with the word `BONG`. When run it looks something like this (note that the image does not loop, so you'll need to force-reload to see the animation again):
> 5 votes

# Answer
# Bash + Linux crontab, 90

I was hoping this would be shorter than the other shell answers. Still, I think it's an interesting approach:

```
for i in {0..11};{
s+=\ BONG
echo "0 $i,$[i+12] * * * echo$s>/proc/$PPID/fd/1"
}|crontab -

```

The script runs once, populates the crontab, then exits. However, the output from the cronjobs is sent to the terminal from which the script was run. I think this satisfies the *submission must run forever* requirement.

**Warning** \- this will clear out any existing crontab entries, so make sure you have existing ones backed up.

This works on Ubuntu 16.04, which is using Vixie `cron` by default.
> 5 votes

# Answer
## Ruby, 112 99 Bytes

```
loop{sleep 2;n=Time.now;if(n.min==0);puts ('BONG '*n.strftime('%I').to_i).chop;sleep 60-n.sec end}

```

Old Version

```
loop{sleep(2);n=Time.now; if(n.min.zero?) then puts ('BONG ' * n.strftime('%I').to_i).chop;sleep(60-n.sec) end}

```

Thanks to QPaysTaxes for the tips
> 3 votes

# Answer
# Python 2, ~~105~~ 106 bytes

```
import time
h=0
while 1:
 l=time.localtime();c=l[3]%12
 if l[4:6]==(0,0)and h!=c:print('BONG '*c)[:-1];h=c

```

**Edit**

Added one byte by changing \< to != after feedback from @pinkfloydx33. Good spot.

Tested as much as possible locally but doesn't work on TIO as it (obviously) exceeds the 60 second execution limit. Please feel free to test locally :-)

btw, losing that pesky trailing space cost me 7 bytes otherwise this would have been under 100.

In the absence of TIO here is output after waiting an hour. Prog was started at 15:27 with extra debug code to show the time of the print (12 hour format).

```
python bigben.py
time is 4:0:0
BONG BONG BONG BONG
time is 5:0:0
BONG BONG BONG BONG BONG

```

Pretty straightforward but here is an explanation for anyone who is interested.

```
import time                 #Import the time module
h=0                         #Create a variable to store the hour that has just been printed
while 1:                    #Loop forever
 l=time.localtime()         #Get the local time from the time module
 c=l[3]%12                  #Set a variable to the current hour in 12 hour format
 if l[4:6]==(0,0)and h!=c:   #If minutes=0 and hours=0 and the last hour that was printed is not the current hour
  print "time is "+`c`+":"+`l[4]`+":"+`l[5]`    #Debug code to show hour
  print('BONG '*c)[:-1]     #Print 'BONG '*number of hours and lose the space from the end
  h=c                       #Update the last hour that was printed

```
> 3 votes

# Answer
# Python 3 - ~~100~~ ~~97~~ 92 bytes

```
from time import*
while 1:x=3600;sleep(x-time()%x);print(('BONG '*int(strftime("%I")))[:-1])[:-1])

```

Explanation:

```
import time;
while 1:
 t=time;x=3600;
 t.sleep(x-t.time()%x);#sleep for the remaining seconds until the next hour
 print(('BONG '*int(t.strftime("%I")))[:-1])#strftime("%")=nr of hours (1-12). Print the bongs and remove the last char

```
> 3 votes

# Answer
# Ruby, ~~82~~ 81 bytes

```
loop{l=Time.new
puts ("BONG "*(l.hour%12+1)).chop if(l+1).hour!=l.hour
sleep 1}

```

Every second we check whether it's last second of the hour, and BONG accordingly. Could probably be golfed further with some dirty tricks, but I don't know too many. Also it works differently than the other Ruby answer.

One byte saved thanks to courtesy of QPaysTaxes.
> 3 votes

# Answer
# Cheddar v1.0.5, 162 bytes

Cheddar has no built-in time reader/cmd output reader, so I had to improvise!

Golfed:

```
var f=->{IO.exec("time/t>c");(String::IO.read("c")).split(":")};var a=f()[0];for(;1;){var b=f();if(b[0]!=a){var c=Number::(a=b[0]);print("BONG "*c).head(5*c-1);}}

```

Ungolfed:

```
var f=->{
    IO.exec("time/t>c");
    (String::IO.read("c")).split(":")};
var a=f()[0];
for(;1;){
    var b=f();
    if(b[0]!=a){
        var c=Number::(a=b[0]);
        print("BONG "*c).head(5*c-1);
    }
}

```

Explanation:

Due to Cheddar's limited standard library, I had to use cmd to generate the time. I did this by saving the output of "time /t", which prints the time in 12-hour format, to a file named "c". IO.read returns a buffer which I casted to a string and split by ":" which ensured the hour is always in index zero. I saved that whole operation into a lambda expression which saved me 44 bytes. After that point it goes into the logic of "if stored hour doesn't equal current hour, set previous hour to current and print BONG n times, trim off the trailing space."

Cheddar may not be the least verbose language but it can be fun to find workarounds like this!

Sadly this is a Windows-only solution.

**Edit 1:** Saved two bytes by replacing "0\<1" in the for-condition to "1" I didn't expect 1 to evaluate to true in this language!
> 3 votes

# Answer
# C, 238 bytes

```
#include<time.h>
#include<unistd.h>
i,j;f(){time_t t=time(0);struct tm l=*localtime(&t);for(;;){t=time(0),l=*localtime(&t),j=l.tm_hour;sleep(1);if(!(l.tm_min+l.tm_sec)){j=j%12?j<12?j:j-12:12;for(i=0;i<=j;i++)printf("BONG%c",i^j?32:10);}}}

```

I'm not sure if this works correctly, and I'm mobile, and my phone doesn't have a C compiler. (Only works on UNIX-like systems)
> 2 votes

# Answer
# sh, 66 bytes

```
yes 'echo `yes BONG|sed $(date +%I)q`'|sh -s|awk '$0!=a&&a;{a=$0}'

```

**Explained**

```
#Pipe a command into a subshell repeatedly
yes 'some command'|sh -s

#Print "hour" (1-12) worth of "BONG" strings, one per line,
#use backticks to merge them into a single space-separated string.
#(stolen from zeppelin's answer)
echo `yes BONG|sed $(date +%I)q`

#Print every time the output changes
awk '$0!=a&&a;{a=$0}

```
> 2 votes

# Answer
## PowerShell, 62

```
for(){if(0-eq(date -f mmss)){''+,'BONG'*(date -f hh)};sleep 1}

```

Infinite loop, gets the minutes and seconds with `-f`ormat string `mmss` and they're cast to ints when compared with `0-eq`euals. Gets the hour in 12 hour format with `-f`ormat string `hh`. Implicit spaces come from joining a `,'BONG'` array into a string with `''+`.
> 2 votes

# Answer
# R, ~~104~~ 105 bytes

```
f=format;repeat{Sys.sleep(1);q=Sys.time();if(f(q,"%M%S")=="0000")print(rep("BONG",as.double(f(q,"%I"))))}

```

Each second, it will (should) test whether we are at the end of an hour, then print that amount of `BONG`s.
> 1 votes

# Answer
# JavaScript ES2015, ~~100~~ ~~99~~ ~~98~~ ~~96~~ ~~94~~ 88 bytes

```
h=_=>new Date/36e5%12|0,p=h();for(;;)h()!=p&&(p=h(),alert('BONG '.repeat(p||12).trim()))

```

Explanation:

`h` is a function that gets the 12-hour-based hour of the day using the remainder operator (`%12`). `36e5` is the number of milliseconds in one hour using the exponential syntax to save characters. The `new` operator does not require that parentheses are used with functions if there are no arguments, hence `new Date`. JavaScript only has floating point arithmetic, the `|` bitwise OR operator forces the number to be an integer because JS bitwise operators work with the integer subset of the numbers represented by IEEE 754 floating point.

The comma delineates sub-expressions. `p` is initialized to the current hour (`p=h()`).

`for(;;)` is used to check repeatedly whether any `BONG`s should be alerted. Checking is performed as rapidly as the runtime will allow.

If the hour has changed (`h()!=p`), then we update p and then alert the `BONG`s. The logical AND operator is used as a guard (it short-circuits if `h()===p`) to determine if the `BONG`s are output.

`String.prototype.repeat` is new in ES2015 and saves some characters over using something like ES5's `Array.prototype.join`.

`h` returns zero for exact multiples of 12 (i.e. 12pm, 12am), so we change it to 12 using the logical OR `p||12`.

With thanks to Kritixi Lithos and ETHProductions for ideas.
> 1 votes

# Answer
# C, 198 bytes

```
#import<time.h>
h,i;f(){time_t t=time(0);struct tm l=*localtime(&t);for(h=l.tm_hour;;t=time(0),l=*localtime(&t))if(h-l.tm_hour%12){h=l.tm_hour%12;for(i=h?h%12:12;--i;)printf("BONG ");puts("BONG");}}

```
> 1 votes

# Answer
# Javascript ES6 87 bytes

Edit: Shamelessly borrowed @ETHProductions' `new Date/36e5%12|0||12` code to save 6 bytes

```
setInterval('Date().match`:00:00`?alert("BONG ".repeat(new Date/36e5%12|0||12)):5',1e3)
```
> 1 votes

# Answer
# Excel VBA, 97 Bytes

Code Outputs to the VBE Immediates Window

```
Do:DoEvents:n=Now:[A1]=(Hour(n)-1)Mod 12+1:?IIf(Minute(n),"",Trim([Rept("BONG ",A1)])+vbCr);:Loop

```

## Fun version, 147 Bytes (Non-Competing)

While it would be rather difficult to get excel to go BONG, it is pretty straight forward to get excel to go `Beep`. The `Beep` call produces a beeping sound, and the code below uses this to produce beeps indicating the hour, on the hour, separated by 1 second pauses.

```
Sub b:Set a=Application:Do:n=Now

```

If Minute(n)=0 Then:For i=1To(Hour(n)-1)Mod 12+1:Beep:a.Wait(Now+#0:0:1#):Next:a.Wait(n+#0:1#):End If:Loop:End Sub

## Ungolfed Version

```
Public Sub BigBen()
    Dim i As Byte
    Dim n As Date
    Dim w As Worksheet
    Dim a As Excel.Application
    Set a = Application
    Set w = a.ThisWorkbook.Sheets(1)
    Let w.Name = "Big Ben"

    Let w.[A1] = Now
    w.Columns("A:A").AutoFit

    Do
        DoEvents
        Let n = Now
        If Minute(n) = 0 Then

            ''  Print BONG
            Let s = ""
            For i = 1 To Hour(n) Mod 12 Step 1
                Let s = s & "BONG "
            Next i
            Debug.Print Trim(s)

            ''  Go Beep
            For i = 1 To Hour(n) Mod 12 Step 1
                Beep
                a.Wait (Now + #12:00:01 AM#) ''  <- #0:0:1# resolves to #12:00:01 AM#
            Next i

            ''  Keep Ticking After Going BONG
            While Now < n + #12:01:00 AM#    ''  <- #0:1# resolves to #12:01:00 AM#
                Let w.[A1] = Now
                Let a.StatusBar = IIf(Second(Now) Mod 2, "Tick", "Tock")
                DoEvents
            Wend
        End If

        ''  Tick Tock until its time to Go BONG again
        Let a.StatusBar = IIf(Second(n) Mod 2, "Tick", "Tock")
        Let w.[A1] = Now
    Loop

End Sub

```
> 1 votes

# Answer
**C# 234 Bytes**

I'm not planning on winning any prizes here, but a C# implementation is compulsory.

```
using System;
using System.Linq;namespace B{class P{static void Main(){Func<int> h=()=>DateTime.Now.Hour % 12;var p=h();while (true){var t=h();if (t!=p)Console.WriteLine(string.Concat(Enumerable.Repeat("BONG",t== 0?12:t)));p=t;}}}}

```

Ungolfed with comments:

```
using System;
using System.Linq;

namespace B
{
    class P
    {
        static void Main()
        {
            Func<int> h = () => DateTime.Now.Hour % 12; // h(): the hour in the range [0, 11], making this a lambda saves a few chars
            var p = h(); // p: Previous time
            while (true)
            {
                var t = h(); // t: Current time
                if (t != p) // If current hour is different to previous hour
                    Console.WriteLine(string.Concat(Enumerable.Repeat("BONG", t == 0 ? 12 : t))); // Print "BONG" t times (also correcting t = 0 to 12)
                p = t; // Current time is now previous time
            } // Repeat ad nauseum
        }
    }
}

```
> 0 votes

# Answer
# Groovy, 72 bytes

```
{x={new Date().getHours()};y=x();while(1){if(y!=(y==x()){print "BONG "*y}}}

```

How?

Store a method to get current hours.

```
x={new Date().getHours()};

```

Store initial hours.

```
y=x();

```

While true, if current hour not equal previous hour, output current hour multiplied by "BONG " to output current hour of bongs.

```
while(1){if(y!=(y==x()){print "BONG "*y}}

```

+3 bytes `%12` for non-military bongs.
> 0 votes

# Answer
## QBIC, 82 bytes

```
X=$left$|(_d,2){Y=left$$|(_d,2)~Y<>X|x=!Y!%12~x=0|x=12]B=C[x|B=B+@BONG |]?_tB|]X=Y

```

Really need to change the token for code literals (`$`) and implement a substring feature (`left$(x,y)` can be shorter).

The inner workings:

```
In the first part, we want to set X$ to the hour-component
of our system's time. The DATE is implemented in QBIC, but
Substring (LEFT$, RIGHT$ and MID$ in QBasic) is not (yet).
We need to use the QBasic LEFT$ function, and QBIC can do
that using a 'code literal': everything from '$' to '|'
is not parsed by QBIC but passed on to QBasic.
X=               Set X$ to
$left$|(         the leftmost (note the '$' and '|' for the code literal)
_d,2)            2 characters of TIME$ (hh:mm format)
{                DO - infinite loop
Y=left$$|(_d,2)  Set Y$ in the same way
~Y<>X            If Y$ is not equal to X$ the hour has changed
|x=!Y!%12        THEN set x to the modulo 12 of Y$ cast to number
~x=0|x=12]       If Y% happens to be divisible by 12, set x to 12
B=C              Clear B$ (c$ never gets assiged a value)
[x|B=B+@BONG |]  For the given number of hours, add "BONG " to B$
?_tB|            Print B$, trim the trailing space
]                end if
X=Y              Update X$
<DO LOOP is implicitly closed>

```

Update (NC): The `$` is no longer used in QBICs instruction set, so it can now be used freely as code for QBasic without the need for code literals. In this case, it saves 4 bytes, bringing QBIC to 78 bytes:

```
X=left$(_d,2){Y=left$(_d,2)~Y<>X|x=!Y!%12~x=0|x=12]B=C[x|B=B+@BONG `]?_tB|]X=Y

```
> 0 votes

# Answer
## perl, 60 bytes

**Update**

Replaced  `" "` with `$"`, removed `CORE::`, corrected count.

**Golf**

```
say join$",(BONG)x(time/3600%12||12)while sleep -time%3600+1

```

This needs to be run with `perl -E`.

**Remarks**

* In perl, `x while y` is equivalent to `while(y){x}` (where `x` is a single statement) but does not need the brackets. `sleep` is executed the first time before anything is printed.
* `time` uses UTC. The original Big Ben is on summer time (British Summer Time, BST) from the end of March until the end of October.
* One second is added to the wait time in order to ensure that the program waits for at least one second. This means that the BONGs will always be printed one second late, which is legal according to the rules. Let's say you're standing on Westminster Bridge, ca. 300 m away from Big Ben. On the plus side, this also means that the program will print the correct amount of BONGs if it is started at exactly the beginning of an hour (instead of waiting 3600 seconds).
* `sleep` returns the number of seconds waited. This will always be true.
> 0 votes

# Answer
# SmileBASIC, ~~74~~ 67 bytes

```
WAIT 61TMREAD OUT H,M,S?("BONG"+" BONG"*((H+11)MOD 12))*!(M+S)EXEC.

```

Outputs large amounts of "trailing" line breaks ;)

Edit: saved 7 bytes with a better 24-\>12 hour algorithm.
> 0 votes

# Answer
# PHP, 63 bytes

I could save two more bytes with extended ASCII. But I am currently too lazy for that.

```
for(;;sleep(1))+date(is)?:print str_pad("
",5*date(h),"BONG ");

```

prints the BONGs with a leading linebreak precisely at the full hour. Run with `-nr`.
> 0 votes

# Answer
# C, 152

```
int a=0,i,L=25;main(){char s[9];for(i=-1;++i<48;){sprintf(s,"%02i:00:00",i);if(!strcmp(s,__TIME__)&&i!=L)a=L=i,i=-1;printf(a-->0?"BONG ":"\n");}main();}

```

---

Readable:

```
int a=0,i,L=25;

main(){
    char s[9];
    for(i=-1;++i<48;){
        sprintf(s,"%02i:00:00",i);
        if(!strcmp(s,__TIME__)&&i!=L)
            a=L=i,i=-1;
        printf(a-->0?"BONG ":"\n");
    }
    main();
}

```
> 0 votes

# Answer
# x86-16 machine code, IBM PC DOS, ~~62~~ 61 bytes

Binary:

```
00000000: ba0b 01b8 1c25 cd21 f4eb fdb8 092c cd21  .....%.!.....,.!
00000010: 3834 741f 8834 86ca 85d2 7517 86c5 d40c  84t..4....u.....
00000020: 7502 b00c 91b5 00ba 3401 cd21 e2fc ba3a  u.......4..!...:
00000030: 01cd 21cf 424f 4e47 2024 0d0a 24         ..!.BONG $..$

```

Listing:

```
BA 010B     MOV  DX, OFFSET INT_BONG    ; interrupt vector of bong proc
B8 251C     MOV  AX, 0251CH             ; AL = 1CH (timer tick), AH = 25H (set vector)
CD 21       INT  21H                    ; set new interrupt vector
0108    INF_LOOP:
F4          HLT                         ; wait for interrupt
EB FD       JMP  INF_LOOP               ; loop forever
        INT_BONG:                       ; interrupt handler for BONG program
B8 092C     MOV  AX, 2C09H              ; AH = get system time, AL = DOS write string
CD 21       INT  21H                    ; CH = hour, CL = min, DH = sec
38 34       CMP  BYTE PTR[SI], DH       ; compare to previous second
74 21       JZ   DONE                   ; if same second, do nothing
88 34       MOV  BYTE PTR[SI], DH       ; otherwise save new second
        DO_BONG:
86 CA       XCHG CL, DL                 ; DL = min, DH = sec
85 D2       TEST DX, DX                 ; are min and sec 0?
75 19       JNZ  DONE                   ; if so, do nothing
86 C5       XCHG AL, CH                 ; AL = hour, CH = DOS write string
D4 0C       AAM  12                     ; AL = AL % 12, ZF if 0
75 02       JNZ  NOT_MID                ; if not midnight or noon, skip
B0 0C       MOV  AL, 12                 ; if 0, set to 12
        NOT_MID:
91          XCHG AX, CX                 ; CL = hour counter, AH = DOS write string
B5 00       MOV  CH, 0                  ; clear high byte of CX
BA 0139     MOV  DX, OFFSET BONG        ; pointer to BONG string
        BONG_LOOP:
CD 21       INT  21H                    ; write BONG
E2 FC       LOOP BONG_LOOP              ; keep looping
BA 013F     MOV  DX, OFFSET CRLF        ; display CRLF
CD 21       INT  21H                    ; write to stdout
        DONE:
CF          IRET                        ; return from interrupt
        BONG:
            DB   'BONG $'
        CRLF:
            DB   0DH, 0AH,'$'

```

Standalone PC DOS executable COM program. This program "hooks" the `INT 1CH` Timer Tick interrupt which is called every 18.2 times per second (oh really?) by the hardware timer, and then runs our new program in memory. Typically you'd be considerate and set this back to original handler when done but since we don't really care about the system once we start the program, we're not really worrying about that.

Yes, this is more bytes than just a big loop, but hopefully a little bit more "interesting"!

Runtime:

*The next day...*
> 0 votes

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


title: Draw A Reuleaux Triangle!

text:
# Question
Title: Draw A Reuleaux Triangle!
The Reuleaux triangle is the shape formed by the intersection of three circles, with each circle passing through the others' centers. Regardless of rotation, a Reuleaux triangle's width will always equal the radius of the circles:

Image: Wolfram MathWorld

Write a program that takes a width `r` as input and displays a Reuleaux triangle of that width (in pixels).

You must display the shape in isolation, i.e. solid-filled, un-stroked, and over a solid-filled background.

\- Shortest program in bytes wins.

# Answer
## JavaScript + HTML, ~~164~~ 158 + 13 = 171 bytes

```
w=+prompt(f=(x,y)=>x*x+y*y<w*w);C.width=C.height=w*2;for(y=-w;++y<w;)for(x=-w;++x<w;)f(x,y)&f(w-x,y)&f(w/2-x,y-w*.866)&&C.getContext`2d`.fillRect(x+w,y+w,1,1)
```

```
<canvas id=C>
```

I don't know why I enjoy answering these mathy drawing challenges with `<canvas>` so much...
> 21 votes

# Answer
# Love2D, 320 bytes.

```
j=math.rad(60)i="increment"m=math s=m.sin C=m.cos g=love.graphics f="fill"S=g.stencil function love.draw()r=arg[2]c=function(x,y)return function()g.circle(f,x,y,r,r*4)end end X=r/2 Y=0 S(c(X,Y),i,1)S(c(X+C(j)*r,Y+s(j)*r),i,1,true)S(c(X-C(j)*r,Y+s(j)*r),i,1,true)g.setStencilTest("greater",2)g.rectangle(f,0,0,2*r,2*r)end

```

Probably not the optimal solution, it uses Love2D's stencils, setting up the 3 circles, and filling in over where they intersect.

Call via the command line, like `love tri.love 256`

## Example Output
> 13 votes

# Answer
# Python 2, 111 bytes

```
from turtle import*
r=input()
ht()
begin_fill()
c=circle
c(r,60)
seth(120)
c(r,60)
seth(240)
c(r,60)
end_fill()

```
> 10 votes

# Answer
## Mathematica ~~101~~ ~~100~~ 98 Bytes

Taking a different approach than @MichaelSeifert, and probably interpreting this a little more literally with regard to the pixel clause:

```
Image@Boole@Table[And@@(({x,y}∈#~Disk~2)&/@{{0,c=√3},d={1,0},-d}),{x,-1,1,2/#},{y,c-2,c,2/#}]&

```

Usage Example:

```
%@10

```

10 pixels

50 pixels

100 pixels

Saved a byte thanks to @MartinEnder (infix notation) and another 2 bytes by defining d.
> 9 votes

# Answer
## PostScript, ~~96~~ ~~86~~ ~~85~~ ~~75~~ ~~73~~ 72 bytes

```
dup(^@^^Z<^@Z<){sin mul exch dup}forall
0 1 2{newpath 369 arc clip}for fill

```

Takes the input as a value on the stack. `^^` and `^@` represent literal control characters. `(^@^^Z<^@Z<)` is the string of characters with code points 0, 30, 90, 60, 0, 90, and 60, respectively. Those are then interpreted as angles in degrees, because obviously that’s what code points are for.

Saved 10 bytes because `closepath` isn’t needed (both `clip` and `fill` implicitly close the path).

Saved 1 byte by using `repeat` instead of defining a function.

Saved 10 bytes by switching to a completely different approach.

Saved 2 bytes by doing tricks with the stack.

Saved 1 byte by using `0 1 2{}for` instead of `3{}repeat`.
> 7 votes

# Answer
## TeX/TikZ, ~~128~~ ~~121~~ 112 bytes

```
\input tikz\footline{}\tikz\draw[draw=none,fill=red](0,1)\foreach~ in{1,2,3}{[rotate=~*120]arc(0:60:\r pt)};\bye

```

The code is based on this answer at TeX.se.

TeX is vector-based, so doesn't do pixels. The radius is a float with a maximum of about 15 before it hits the edge of the page. It's also not really built for commandline input, so need to be run as

```
pdftex  "\def\r{2} \input rt.tex"

```

where the code above is saved in `rt.tex`
> 6 votes

# Answer
# PHP+SVG, 165 bytes

```
<?$h=3/8*$w=2*$d=2*$r=$_GET[0];$q=$r+sqrt($r**2-($r/2)**2);echo"<svg width=$w height=$w><path d='M$r,$r A$r,$r 0 0 1 $d,$r A$r,$r 0 0 1 $h,$q A$r,$r 0 0 1 $r,$r'/>";

```

## Example Output for Input 128

```
<svg width=512 height=512><path d='M128,128 A128,128 0 0 1 256,128 A128,128 0 0 1 192,238.85125168441 A128,128 0 0 1 128,128'/>
```
> 6 votes

# Answer
## Mathematica, ~~134~~ 131 bytes

**N.B.** This solution is no longer valid, as the question was later edited to require *r* to be measured in pixels. Thanks to Martin Ender for helping me shave off a few bytes in the comments.

```
r=Input[];RegionPlot[And@@((Abs[y+I x-#]^2<3r^2)&/@Table[Exp[2n I/3Pi]r,{n,3}]),{x,-1,1},{y,-1,1},Frame->False,BoundaryStyle->None]

```

The input value must be scaled between 0 and 1 for this code to work. Note that almost a quarter of this code is required to display the shape "in isolation", as this is not Mathematica's default.
> 5 votes

# Answer
# BBC BASIC, 58 bytes

```
I.r:L.r,r,r,r:F.i=0TO9S.PI/1.5PLOT177,r*COS(i),r*SIN(i)N.

```

Download interpreter at http://www.bbcbasic.co.uk/bbcwin/download.html

**Ungolfed**

```
INPUTr                       :REM input a radius
LINEr,r,r,r                  :REM draw a line of length 0 from r,r to r,r to establish a cursor history away from the corner of the screen
FORi=0 TO 9 STEP PI/1.5      :REM in steps of 120 degrees (going round and round the three sides of an equilateral triangle)
  PLOT177,r*COS(i),r*SIN(i)  :REM move relative by r*COS(i),r*SIN(i) and draw a sector with arc between new and last graphics cursor positions,
NEXT                         :REM with the centre of the arc at the penultimate graphics cursor position.

```
> 4 votes

# Answer
## GLSL, ~~298~~ 229 characters

```
precision lowp float;
uniform vec2 resolution;float r=100.;void main(){vec2 p=gl_FragCoord.xy-resolution.xy/2.;float h=sqrt(3.)/4.*r;gl_FragColor=vec4(length(p+vec2(r/2.,h))<r&&length(p+vec2(-r/2.,h))<r&&length(p-vec2(0.,h))<r);}

```

Try it here

Bonus

* Radius can be set by changing `r` variable
* Triangle width is in pixels as requested (you have to make zoom is set to 1x in GLSL sandbox).
> 3 votes

# Answer
## Java + `Processing`, 95 bytes

```
noStroke();arc(r,r,r,r,0,PI/3);arc(r+r/2,r,r,r,2*PI/3,PI);arc(r+r/4,r+r/2.3,r,r,4*PI/3,5*PI/3);

```

Takes input as variable r, outputs a Reuleaux triangle at \\$(r,r)\\$, given an adequately sized canvas.

Code

### As a function with size call, 124 bytes

```
void a(int r){size(r*2,r*2);noStroke();arc(r,r,r,r,0,PI/3);arc(r+r/2,r,r,r,2*PI/3,PI);arc(r+r/4,r+r/2.3,r,r,4*PI/3,5*PI/3);}

```

### Outputs

50

100

200
> 3 votes

# Answer
# JavaScript (ES6) + HTML, 196 + 13 = 209 bytes

Uses a path-based approach instead of a pixel-filling approach.

```
r=>{c.width=c.height=r*2
with(Math)with(c.getContext`2d`)scale(e=r*.578,e),beginPath(a=s=>s*PI/3),moveTo(2,1),[2,4,6].map(s=>arcTo(cos(i=a(s-1))+1,sin(i)+1,cos(j=a(s))+1,sin(j)+1,sqrt(3))),fill()}

```

```
<canvas id=c>

```

```
f=
r=>{c.width=c.height=r*2
with(Math)with(c.getContext`2d`)scale(e=r*.578,e),beginPath(a=s=>s*PI/3),moveTo(2,1),[2,4,6].map(s=>arcTo(cos(i=a(s-1))+1,sin(i)+1,cos(j=a(s))+1,sin(j)+1,sqrt(3))),fill()}

f(200)

//r=>{c.width=c.height=r*2
//with(Math)with(c.getContext`2d`)translate(r,r),scale(r,r),beginPath(a=s=>s*PI/3),S=sqrt(3),moveTo(1/S,0),[2,4,6].map(s=>arcTo(cos(i=a(s-1))/S,sin(i)/S,cos(j=a(s))/S,sin(j)/S,1)),fill()}

//r=>{c.width=c.height=r*2
//with(Math)with(c.getContext`2d`)translate(r,r),scale(r,r),beginPath(),P=PI/2,A=(s,_)=>(_?sin:cos)(s*PI/3)/sqrt(3),moveTo(A(0),0),[2,4,6].map(s=>arcTo(A(s-1),A(s-1,1),A(s),A(s,1),1)),fill()}
```

```
<canvas id=c>
```
> 2 votes

# Answer
# Logo, 53 bytes

```
to t :r filled 0[repeat 3[arc 60 :r fd :r rt 120]]end

```

uses the `filled` command to fill the shape in colour 0 (black.) The code in the outer square brackets is executed without any line being drawn, but Logo keeps track of the turtle movements and fills in the shape once the bracket is exited.

# Logo, ~~64~~ 61 bytes

```
to t :r repeat 3[pd arc 60 :r pu fd :r rt 120]fd 9 fill end

```

Pen Down, draw 60 degree arc with turtle at the centre, Pen Up, move pen to start of arc, turn 120 deg.

Repeat 3 times, then move inside the shape and fill it.

Try at http://turtleacademy.com/playground/en

Call like `cs ht t 100` (clear screen, hide turtle, `t` with r=100.)
> 2 votes

# Answer
# MATL, 35 bytes

```
9Bo&ZQ*3X^/G_G&:t!J*+8L&!-|G<A&e0YG

```

This produces a file called `image.png`. For input `r`, the size of the image is `2*r+1`, and the width of the triangle is `r` as required.

Try it at **MATL Online!** The online interpreter automatically opens the created file and displays the image with arbitrary scaling; click on it to obtain the actual-size version.

Alternatively, here are two example outputs from the offline compiler running on Matlab, with inputs `50` and `100`. The last part of the code `0YG` has been replaced by `IYG` so that the figure is directly displayed (with the right size) instead of written to a file.

### Explanation

```
9B      % Push 9 in binary: [1 0 0 1] with logical values
o       % Convert to double
&ZQ     % Roots of polynomial with coefficients [1 0 0 1], as a 3×1 column vector
*       % Multiply by implicit input r
3X^/    % Divide by sqrt(3). This gives a 3×1 vector with the circle centers
G_G&:   % Push row vector [-r -r+1 ... r-1 r], with size 1×(2*r+1)
t!J*    % Duplicate, transpose, multiply by 1j
+       % Add with broadcast. This gives a (2*r+1)×(2*r+1) 2D-array of complex
        % numbers, which defines the pixel grid
8L      % Push [3 1 2]
&!      % Permute dimensions as indicated. This gives a 1×(2*r+1)×(2*r+1) 3D-array
-|      % Subtract with broadcast. Absolute value. This gives a 3×(2*r+1)×(2*r+1)
        % 3D-array with the distance from each circle center to each grid point
G<      % Less than r? Gives a 3×(2*r+1)×(2*r+1) 3D-array containing true or false
A       % All: this gives a 1×(2*r+1)×(2*r+1) array containing true for
        % columns of the original 3D-array that contained all true values
&e      % Squeeze the first singleton dimension to give a (2*r+1)×(2*r+1) 2D-array
0YG     % Save as image file with default file name

```
> 2 votes

# Answer
## JavaScript (ES6) + SVG (HTML5), 28 + 102 = 130 bytes

```
f=
n=>s.setAttribute('width',n)
```

```
<input type=number value=82 oninput=f(this.value)><br>
<svg id=s width=82 viewbox=0,0,82,82><path d=M0,71a82,82,0,0,0,82,0A82,82,0,0,0,41,0A82,82,0,0,0,0,71>
```

Byte count excludes code needed for convenient user input of desired size.
> 2 votes

# Answer
# MetaPost (~~242~~ 226 Bytes)

```
outputtemplate:="%j-%c.ps";
prologues:=1
beginfig(1);
 len:=1cm;
 path p[];
 p[1]:=len * dir -30 {dir 90} .. len * dir  90;
 p[2]:=p[1] rotated 120;
 p[3]:=p[1] rotated 240;
 fill p[1] -- p[2] -- p[3] -- cycle;
endfig;
end.

```

It may be possible to reduce this somewhat, I'm new to metapost.
> 1 votes

# Answer
# k, ~~141~~ ~~100~~ 98 bytes

```
s:*/2#;l:2*r:.:0:`
`0:(,"P1")," "/'$(,l,l),&/{(s'n+x)</:(s r)-s'y+n:r-!l}./:r*%(0 0;4 0;1 3)%4
\\

```

Input is taken from `stdin`, output is `stderr` (or `stdin` depending on the interpreter) in `pgm` format. For example:

Explanation:

```
s:*/2#               /set s to a squaring function
r:.:0:`              /get user input, set to r
l:2*                 /width/height is 2 times r
r*%(0 0;4 0;1 3)%4   /the coordinates of circle centers
{ }./:               /for each coordinate pair (x, y) get a circle
                     /function to get a circle:
n:r-!l               /  set n to {r, r-1, ..., -(r-1)}
(s'n+x)</:(s r)-s'y+ /  use b^2<r^2-a^2 on all points to get a circle
                     /  where x and y shift the circle right and down
&/                   /get intersections of circles (fold binary and)
(,l,l),              /prepend height and width for PGM format
" "/'$               /convert to string, add spaces
(,"P1"),             /prepend PGM header
`0:                  /output to stderr
\\                   /exit

```
> 1 votes

# Answer
# 05AB1E, 66 bytes

```
’)
¨€(ÿ,60)
lt(60’Ð’€š éà £Ø*
ht()
ï…_œã(ÿÿÿ)
„–_œã()
„ˆ 1:ht()’.e

```

Can't use TIO, since it opens a window and draws the Reuleaux triangle there.

Asks for input, and then opens up a Python turtle window drawing the triangle.

Jonathan Allan's answer gave me the inspiration to do this, although I altered his code a bit.

Essentially, this is a combination of 05AB1E's compressing capabilities and Python's ease of turtle graphics.
> 1 votes

# Answer
## OpenSCAD, 91 bytes

```
module t(r){intersection_for(t=[0,120,240]){rotate(t)translate([r/sqrt(3),0,0])circle(r);}}

```

I'm not sure how kosher this is, as pixels aren't really a well-defined unit in any mesh grid formats that I know of. In stead, the module `t` draws a reuleaux triangle of given radius `r` in whatever native units are in use.

Sample preview output for `t(100)`:
> 1 votes

# Answer
# SmileBASIC, ~~87~~ ~~86~~ ~~85~~ ~~83~~ ~~82~~ ~~81~~ ~~79~~ ~~78~~ ~~77~~ ~~76~~ 75 bytes

```
INPUT R
C.5Y=R*.87C 1C.GPAINT.,0DEF C X
A=X*240GCIRCLE R*X,Y+2,R,A-60,A
END

```

## Ungolfed:

```
INPUT RADIUS
CIRCLE 0.5
Y=RADIUS*(SQR(3)/2)
CIRCLE 1
CIRCLE 0
GPAINT 0,0
DEF CIRCLE X
 ANGLE=X*240
 GCIRCLE RADIUS*X,Y+2,RADIUS,ANGLE-60,ANGLE
END

```
> 1 votes

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


title: plz send teh codez!

text:
# Question
Title: plz send teh codez!
> **Note to Moderators and editors**: This post's title is for effect and should not be changed. The misspelling is intentional and part of the challenge.

# Backstory

The (stereo)typical bad SO question asks something along the lines of "plz send teh codez!" In other words, it asks someone to do the work for the asker and provide a complete solution to a one-time problem. I quote this question on Meta.SE:

> ...its about a specific category of questions which consist of absolutely no research, no effort, and simply ask for the complete solution to a problem. These types of questions generally tend to assume that Stack Overflow is a free coding service...

# So what is your actual challenge? Its simple:

Your program or function, etc. must take input as a string (from STDIN, parameter, etc.) and if the string contains `Plz send teh codez!` output `-1 flag comment` (downvote, flag as off-topic, and comment about how bad a question it is.) Otherwise output `+1` (you are upvoting).

# But wait… there's more!

Your program ***must not*** contain 5 or more of these character sets:

* All special characters (anything not a space, newline (`0x0a`), case-insensitive alphabet, or digit)
* Any digit (0-9)
* Any of `pzcm` (case-insensitive)
* Any of `hten` (case-insensitive)
* Any of `qwryuioasdfgjklxvb`
* Any of `QWRYUIOASDFGJKLXVB`

To be clear, you can only use up to 4 of those charsets.

**Spaces, tabs and newlines are not restricted in any way, but they still are included in your byte count**

# Final restriction

Your program must contain Unicode **ONLY** in the range of `0x20` (space) to `0x7e` (~), as well as `0x0a` (LF newline) and `0x09` (tab). This is to exclude code golfing languages and give traditional languages a change or at least level the playing field.

# Notes:

* This is , the shortest answer in bytes wins!
* Input can be from STDIN, a function parameter, command-line parameter, etc. but **not a variable**.
* Output can be to STDOUT, a function return value, or even an error/exception. Can include a trailing newline.
* Traditional languages are encouraged to compete because this challenge bans a lot of golfing languages by excluding high Unicode characters. C might even have a chance of winning!
* Any questions? Comment below!

# If it's too hard…

You can ignore the character sets in your answer, but it then becomes non-competitive.

# NOTE: You can now use up to 4 character sets. You're welcome.

You can use this snippet to check if your code is valid:

```
let f = code => {
  let sets = Array(6).fill(false);
  code = code.replace(/\s/g, "");
  code = code.replace(/\d/g, _ => (sets[0] = true, ""));
  code = code.replace(/[pzcm]/gi, _ => (sets[1] = true, ""));
  code = code.replace(/[hten]/gi, _ => (sets[2] = true, ""));
  code = code.replace(/[qwryuioasdfgjklxvb]/g, _ => (sets[3] = true, ""));
  code = code.replace(/[QWRYUIOASDFGJKLXVB]/g, _ => (sets[4] = true, ""));
  if (code) sets[5] = true;
  return sets.reduce((a, b) => a + b, 0);
}
```

```
<textarea oninput="var x=f(value);O.innerHTML='You\'re using '+x+' charset'+(x===1?'':'s')+(x>4?', which is too many.':'. Nice job!')"></textarea><br>
<p id=O></p>
```

# Answer
> 4 votes
# CJam, ~~50~~ ~~49~~ 48 bytes

```
q"Plz send teh codez!"#)"- flag comment""+"?(T)@

```

Doesn't use digits or the capital letters set.

Try it online!

**Explanation**

```
q                       e# Push the input
"Plz send teh codez!"#  e# Find index of "Plz send teh codez!" in the input (-1 if not found)
)                       e# Increment the index
                        e# Check the truthiness of the index:
 "- flag comment"       e#   If truthy (i.e. it appeared in the input), push this string
 "+"                    e#   If falsy (it wasn't in the input), push this string
?                       e#
(                       e# Uncons from left, removes the first character of the string and
                        e#  pushes it on the stack
T)                      e# Push 0, and increment it to 1
@                       e# Bring third-from-top stack element to the top
                        e# Implicit output of stack contents

```

# Answer
> 11 votes
## JavaScript (ES6), 60 bytes

```
x=>/Plz send teh codez!/.test(x)?~x+' flag comment':'+'+-~[]

```

Everything was straightforward, except avoiding using `1` anywhere. I use `~x` to get `-1` (since if `x` contains `Plz send teh codez!`, it's not a valid number and therefore `~x` will give `-1`), and `-~[]` to get `1` (since if `x` is e.g. `'7'`, `-~x` will be `8`, so we can't rely on `x`).

### Test snippet

```
let f =
x=>/Plz send teh codez!/.test(x)?~x+' flag comment':'+'+-~[];

console.log(f("Hello, Plz send teh codez!"))
console.log(f("Hello, Plz send teh codez?"))
```

# Answer
> 8 votes
# JS (JSFuck), 37959 bytes

Here's a gist, since PPCG hates long codes.

Only uses special characters. :P

Heres the original code:

```
alert(prompt().includes("Plz send teh codez!")?"-1 flag comment":"+1")

```

# Answer
> 3 votes
# C, 102 bytes

```
i;f(char*s){i=strstr(s,"Plz send teh codez!");printf("%+d%s",i?'a'-'b':'b'-'a',i?" flag comment":"");}

```

Doesn't use any digit or any of `QWERTYUIOASDFGHJKLXVBN`. Try it online!

# Answer
> 3 votes
## Retina, 56 bytes

```
(?!.*Plz send teh codez).+

.+
-$#+ flag comment
^$
+$#+

```

Try it online!

Uses special characters, the two case insensitive letter sets and other lower-case letters.

First we remove the entire input if it doesn't contain `Plz send teh codez`. If there is any input left we replace it with `-1 flag comment`, avoiding the digit with `$#+`. `$+` refers to the last capturing group which is `$0` (the entire match) sind there are no capturing groups. `$#+` then gives the number of captures, which is always `1`.

Finally, if the string is still empty (i.e. we cleared it in the first stage), we replace it with `+1` (again using `$#+` for the `1`).

# Answer
> 2 votes
# Python 2, ~~95~~ ~~94~~ 87 Bytes

Uses special characters and all lowercase lowers (plus three char sets and except for "p", which is case insensitive) for a total of **four characters sets used**.

```
b=ord('b')-ord('a')
print["+"+`b`,`-b`+" flag comment"][input()=="Plz send teh codez!"]

```

Try it online! Thanks to @math\_junkie for saving 8 bytes! Thanks to @officialaimm for saving two bytes!

---

```
a=ord

```

Let `a` be the `ord()` built-in function.

```
b=str(a('b')-a('a'))

```

This is really `b=1`.

```
print["+"+b, "-"+b+" flag comment"][input()=="Plz send teh codez!"]

```

If the statement in the second pair of brackets is true, print the second string in the first pair of brackets. Otherwise, print the first one.

# Answer
> 2 votes
# Python 2/3, ~~81~~ ~~76~~ 68 bytes

```
lambda x:["+%s","-%s flag comment"]["Plz send teh codez!"in x]%+True

```

Uses:

* All special characters (anything not a space, newline (0x0a), case-insensitive alphabet, or digit)
* Any of `pzcm` (case-insensitive)
* Any of `hten` (case-insensitive)
* Any of `qwryuioasdfgjklxvb`

Doesn't use:

* Any of `QWRYUIOASDFGJKLXVB`
* Any digit (0-9)

*-8 bytes thanks to math\_junkie*

# Answer
> 1 votes
# C#, 77 bytes

```
x=>x.Contains("Plz send teh codes!")?$"{'x'-'y'} flag comment":$"+{'x'/'x'}";

```

Not being able to use digits is such a pain.

# Answer
> 1 votes
# Groovy, 78 bytes

```
{a="a".length();it.contains("Plz send teh codez!")?-a+" flag comment":"+"+a}

```

Doesn't use the numbers or the uppercase sets.

Just a straightforward use of the ternary operator. `"a".length()` is a workaround to get 1

# Answer
> 1 votes
# Python 3, 115 bytes

```
if"p".upper()+"lz send teh codez!"in input():print("-"+str(len('a'))+" flag comment")
else:print("+"+str(len('a')))

```

It doesn't use numbers or upper case letters.

**Try it online**

# Answer
> 1 votes
## Pip, 48 bytes

```
s.a@?"Plz send teh codez!"?v." flag comment"'+.o

```

Tied with CJam.

I am very mad that I was unable to get this under 48 bytes.

The program uses Pip's predefined variables to get around the number sequence, and it doesn't have any characters from the Capitals sequence.

Try it online!

# Answer
> 0 votes
# Python 3.5 (137 102 98 87 85 94 Bytes)

### Uses small-case letters(3 charsets) + special characters(1 charset) = 4 charsets

### i was almost planning to avoid whitespaces as well but the indentation in python forced me to keep one newline so i left the whitespaces as they were.

```
i=str(ord('b')-ord('a'))
print(['+'+i,'-'+i+' flag comment']['Plz send teh codez!'in input()])

```

Try it online!

* saved 35 bytes!!!!: apparently i had forgotten the existence of upper() function before(silly me!!)
* saved 4 bytes: reduced i=input() to just input()
* saved 11 bytes!!!: Thanks to Anthony-Pham (used 'P' since it is valid in charset)
* saved 2 bytes: (removed a=ord; learnt that shortening a function is not always a good idea! :D)
* added 9 bytes: Thanks to math-junkie for pointing out that I was not displaying +1 for strings with no 'Plz send teh codez!' before.

# Answer
> 0 votes
# Common Lisp, 81 bytes

Special + lower case + 2 mixed-case = 4 charsets

```
(format t"~:[+~s~;-~s flag comment~]"(search"Plz send teh codez!"(read-line))(*))

```

Ungolfed

```
(format t "~:[+~s~;-~s flag comment~]"
        (search "Plz send teh codez!" (read-line))
        (*))

```

Explanation

`(read-line)`

Accepts a line of input from `*standard-input*` (STDIN, by default).

`(search "Plz send teh codez!" ...)`

Scans through the second argument (the read in line) for the index where the first argument starts. Returns either this index or `nil` (false) if it could not be found.

`(*)`

Multiplication in lisp is defined to take an arbitrary number of arguments, including none- in that case it always returns 1.

`(format t "~:[+~s~;-~s flag comment~]" ...)`

`#'format` is similar to `fprintf` or `sprintf` in C. It's first argument, `t`, designates the output as `*standard-output*` (STDOUT, by default). The next argument is the format string. "~" is used like "%" in `printf`\- the character(s) following it designate a formatting operation.

`"~:[<a>~;<b>~]"` is the conditional formatting operation. It takes an argument and continues with `<a>` if the argument was `nil` (false). Any other value, like `t` (true) or a number (for example), has it continue with `<b>`. The third argument to format (the first, after `t` and the format string) is the search, so `<a>` will be chosen if the search fails (and `<b>` otherwise).

In this case, the `<a>` (`nil`/false) branch prints "+~s". "~s" converts a format argument to a string and prints out its characters. The fourth argument to format (the second, after `t` and the format string) is `(*)` or 1, so we get "+1" printed.

The `<b>` branch is similar: "-~s flag comment". It also uses the fourth (second) argument to fill in its "~s", so it prints out "-1 flag comment".

# Answer
> 0 votes
# sh + sed, 72 bytes

Uses character sets: 1, 3, 4, 5.

```
let ""
sed "s/.*Plz send teh codez!.*/-$? flag comment/
tz
s/.*/+$?/
:z"

```

At first, I wanted to go with pure sed, but I had no idea how to avoid using digits. So I used sh just for that. `let ""` has an exit status of `1`, since it can't be evaluated as an arithmetic expression.

`z` is just a label and can be replaced with any other character.

# Answer
> 0 votes
## Mathematica, 265 bytes

This was hard.

```
t[s_,n_]:=ToString@s~StringTake~{n};If[StringFreeQ[#,t[Head[a^b],i=-I I]<>"l"<>(s=t[RSolve[f[a+i]==f@a-i/Sqrt@a,f@a,a],(i+i+i+i)^(e=i+i+i)+i+e])<>" send teh "<>(k=t[i/Sin@x,e])<>"ode"<>s<>"!"],"+"<>t[i,i],"-"<>t[i,i]<>" flag "<>k<>"o"<>(n=Head[a b]~t~e)<>n<>"ent"]&

```

Readable version:

```
t[s_, n_] := ToString@s~StringTake~{n};
If[StringFreeQ[#,
   t[Head[a^b], i = -I I] <>
    "l" <> (s =
      t[RSolve[f[a + i] == f@a - i/Sqrt@a, f@a,
        a], (i + i + i + i)^(e = i + i + i) + i + e]) <>
    " send teh " <> (k = t[i/Sin@x, e]) <> "ode" <> s <> "!"],
  "+" <> t[i, i],
  "-" <> t[i, i] <> " flag " <> k <> "o" <> (n = Head[a b]~t~e) <> n <>
    "ent"] &

```

Uses special characters, `hten`, `qwryuioasdfgjklxvb` and `QWRYUIOASDFGJKLXVB`. Mathematica without special characters would be basically impossible, and almost all string-related functions include `String` in their name, so that really limits the choice here…

To get the other character sets, we need a few tricks. Firstly, to get `1` we take the negative of the square of the imaginary number `I`: `i = -I I`. Later we also define `3` by `e = i+i+i`.

The letter `P` was fairly straightforward: Mathematica treats `a^b` internally as `Power[a,b]`, so all we need to do is take the head of this (`Power`), turn it into a string, and take the first (aka `i`th) letter. (We'll be turning things into strings and taking the *n*th letter a lot, so we define `t[s_,n_]:=ToString@s~StringTake~{n}`.) The letter `m` is similar: take the head of `a b`, which is `Times`, and get the third (aka `e`th) letter.

The letter `c` is slightly harder: we use the trigonometric identity `1/Sin[x] == Csc[x]` (or rather `i/Sin[x]` since we can't use `1`), and take the third letter of `Csc[x]`.

The really hard part is the `z`. To make a `z`, we use the `HurwitzZeta` function (yes, really). We get that by solving the recurrence relation `RSolve[f[a + i] == f@a - i/Sqrt@a, f@a, a]`, which yields the string

```
"                             1            1
 {{f[a] -> C[1] + HurwitzZeta[-, a] - Zeta[-]}}
                              2            2"

```

of which the 68th character is `z`. We get the number 68 as `4^3 + 4`.

This could probably be golfed further: the Hurwitz zeta stuff is pretty much copied from the Mathematica documentation, and there's probably a shorter way of getting 68 — or we could use another method entirely for the `z`. Any suggestions?

# Answer
> 0 votes
# Swift (non-competitive) - 64 bytes

```
print(x.contains("Plz send teh codez!") ?"-1 flag comment":"+1")

```

Unfortunately used 5 charsets, couldn't make it without them... Suggestions are welcome!

---
Tags: code-golf, string, restricted-source
---


title: Make me a blanket!

text:
# Question
Title: Make me a blanket!
I want a blanket that looks like this. Each strip goes over, under, over, under. Can you print it?

```
\\\\////\\\\////\\\\////\\\\////\\\\////\\\\////
 \\////  \\////  \\////  \\////  \\////  \\////
  ////    ////    ////    ////    ////    ////
 ////\\  ////\\  ////\\  ////\\  ////\\  ////\\
////\\\\////\\\\////\\\\////\\\\////\\\\////\\\\
\//  \\\\//  \\\\//  \\\\//  \\\\//  \\\\//  \\\
\\    \\\\    \\\\    \\\\    \\\\    \\\\    \\
\\\  //\\\\  //\\\\  //\\\\  //\\\\  //\\\\  //\
\\\\////\\\\////\\\\////\\\\////\\\\////\\\\////
 \\////  \\////  \\////  \\////  \\////  \\////
  ////    ////    ////    ////    ////    ////
 ////\\  ////\\  ////\\  ////\\  ////\\  ////\\
////\\\\////\\\\////\\\\////\\\\////\\\\////\\\\
\//  \\\\//  \\\\//  \\\\//  \\\\//  \\\\//  \\\
\\    \\\\    \\\\    \\\\    \\\\    \\\\    \\
\\\  //\\\\  //\\\\  //\\\\  //\\\\  //\\\\  //\
\\\\////\\\\////\\\\////\\\\////\\\\////\\\\////
 \\////  \\////  \\////  \\////  \\////  \\////
  ////    ////    ////    ////    ////    ////
 ////\\  ////\\  ////\\  ////\\  ////\\  ////\\
////\\\\////\\\\////\\\\////\\\\////\\\\////\\\\
\//  \\\\//  \\\\//  \\\\//  \\\\//  \\\\//  \\\
\\    \\\\    \\\\    \\\\    \\\\    \\\\    \\
\\\  //\\\\  //\\\\  //\\\\  //\\\\  //\\\\  //\

```

Trailing spaces at the end of each line and trailing newlines are acceptable.

Remember, this is , so the code with the fewest bytes wins.

## Leaderboards

Here is a Stack Snippet to generate both a regular leaderboard and an overview of winners by language.

To make sure that your answer shows up, please start your answer with a headline, using the following Markdown template:

```
# Language Name, N bytes

```

where `N` is the size of your submission. If you improve your score, you *can* keep old scores in the headline, by striking them through. For instance:

```
# Ruby, <s>104</s> <s>101</s> 96 bytes

```

If there you want to include multiple numbers in your header (e.g. because your score is the sum of two files or you want to list interpreter flag penalties separately), make sure that the actual score is the *last* number in the header:

```
# Perl, 43 + 2 (-p flag) = 45 bytes

```

You can also make the language name a link which will then show up in the leaderboard snippet:

```
# [><>](http://esolangs.org/wiki/Fish), 121 bytes

```

```
var QUESTION_ID=99023,OVERRIDE_USER=12537;function answersUrl(e){return"https://api.stackexchange.com/2.2/questions/"+QUESTION_ID+"/answers?page="+e+"&pagesize=100&order=desc&sort=creation&site=codegolf&filter="+ANSWER_FILTER}function commentUrl(e,s){return"https://api.stackexchange.com/2.2/answers/"+s.join(";")+"/comments?page="+e+"&pagesize=100&order=desc&sort=creation&site=codegolf&filter="+COMMENT_FILTER}function getAnswers(){jQuery.ajax({url:answersUrl(answer_page++),method:"get",dataType:"jsonp",crossDomain:!0,success:function(e){answers.push.apply(answers,e.items),answers_hash=[],answer_ids=[],e.items.forEach(function(e){e.comments=[];var s=+e.share_link.match(/\d+/);answer_ids.push(s),answers_hash[s]=e}),e.has_more||(more_answers=!1),comment_page=1,getComments()}})}function getComments(){jQuery.ajax({url:commentUrl(comment_page++,answer_ids),method:"get",dataType:"jsonp",crossDomain:!0,success:function(e){e.items.forEach(function(e){e.owner.user_id===OVERRIDE_USER&&answers_hash[e.post_id].comments.push(e)}),e.has_more?getComments():more_answers?getAnswers():process()}})}function getAuthorName(e){return e.owner.display_name}function process(){var e=[];answers.forEach(function(s){var r=s.body;s.comments.forEach(function(e){OVERRIDE_REG.test(e.body)&&(r="<h1>"+e.body.replace(OVERRIDE_REG,"")+"</h1>")});var a=r.match(SCORE_REG);a&&e.push({user:getAuthorName(s),size:+a[2],language:a[1],link:s.share_link})}),e.sort(function(e,s){var r=e.size,a=s.size;return r-a});var s={},r=1,a=null,n=1;e.forEach(function(e){e.size!=a&&(n=r),a=e.size,++r;var t=jQuery("#answer-template").html();t=t.replace("{{PLACE}}",n+".").replace("{{NAME}}",e.user).replace("{{LANGUAGE}}",e.language).replace("{{SIZE}}",e.size).replace("{{LINK}}",e.link),t=jQuery(t),jQuery("#answers").append(t);var o=e.language;/<a/.test(o)&&(o=jQuery(o).text()),s[o]=s[o]||{lang:e.language,user:e.user,size:e.size,link:e.link}});var t=[];for(var o in s)s.hasOwnProperty(o)&&t.push(s[o]);t.sort(function(e,s){return e.lang>s.lang?1:e.lang<s.lang?-1:0});for(var c=0;c<t.length;++c){var i=jQuery("#language-template").html(),o=t[c];i=i.replace("{{LANGUAGE}}",o.lang).replace("{{NAME}}",o.user).replace("{{SIZE}}",o.size).replace("{{LINK}}",o.link),i=jQuery(i),jQuery("#languages").append(i)}}var ANSWER_FILTER="!t)IWYnsLAZle2tQ3KqrVveCRJfxcRLe",COMMENT_FILTER="!)Q2B_A2kjfAiU78X(md6BoYk",answers=[],answers_hash,answer_ids,answer_page=1,more_answers=!0,comment_page;getAnswers();var SCORE_REG=/<h\d>\s*([^\n,]*[^\s,]),.*?(\d+)(?=[^\n\d<>]*(?:<(?:s>[^\n<>]*<\/s>|[^\n<>]+>)[^\n\d<>]*)*<\/h\d>)/,OVERRIDE_REG=/^Override\s*header:\s*/i;
```

```
body{text-align:left!important}#answer-list,#language-list{padding:10px;width:290px;float:left}table thead{font-weight:700}table td{padding:5px}
```

```
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <link rel="stylesheet" type="text/css" href="//cdn.sstatic.net/codegolf/all.css?v=83c949450c8b"> <div id="answer-list"> <h2>Leaderboard</h2> <table class="answer-list"> <thead> <tr><td></td><td>Author</td><td>Language</td><td>Size</td></tr></thead> <tbody id="answers"> </tbody> </table> </div><div id="language-list"> <h2>Winners by Language</h2> <table class="language-list"> <thead> <tr><td>Language</td><td>User</td><td>Score</td></tr></thead> <tbody id="languages"> </tbody> </table> </div><table style="display: none"> <tbody id="answer-template"> <tr><td>{{PLACE}}</td><td>{{NAME}}</td><td>{{LANGUAGE}}</td><td>{{SIZE}}</td><td><a href="{{LINK}}">Link</a></td></tr></tbody> </table> <table style="display: none"> <tbody id="language-template"> <tr><td>{{LANGUAGE}}</td><td>{{NAME}}</td><td>{{SIZE}}</td><td><a href="{{LINK}}">Link</a></td></tr></tbody> </table>
```

# Answer
> 11 votes
## Python 2, 84 bytes

```
R=range(24)
for i in R:print''.join(" \// \/\\"[i+~j>>2&1^i+j>>1&2^i&4]for j in R*2)

```

Thanks to Sp3000 for 6 bytes from turning the arithmetic operations into bitwise ones.

# Answer
> 7 votes
# Pyth, 36 bytes

```
V24sm@" \// \/\\"im<3%k8++BNdt-NdT48

```

Try it online: Demonstration

### Explanation:

We can determine the symbol by checking 3 conditions:

```
A := row % 8 > 3
B := (row + column) % 8 > 3
C := (row - column - 1) % 8 > 3

```

If we interpret `[A,B,C]` as a binary number, we get the following mapping:

```
01234567
 \// \/\

```

We can also interpret `[A,B,C]` as decimal number and perform a modular indexed lookup in the string. This doesn't make a difference because `10 mod 8 = 2`.

Now to the code:

`V24` iterates `N` (row-idx) over `[0, 1, ..., 23]`.

`sm...48` maps the numbers `d` (column-idx) in `[0, 1, ..., 47]` to chars and print the combined string.

`++BNd` generates the list `[N, N+d]`, `+...t-Nd` appends `N-d-1`. So we have get the list `[N, N+d, N-d-1]`. `m<3%k8` checks for each computed number `k`, if `3 < k % 8`, so this gives the list with the conditions `[A, B, C]`.

`i...T` convents this to a decimal number and then `@" \// \/\\"` does the lookup in the string.

More or less the same code in Python2: **98 bytes**:

```
R=range(8)
for r in R*3:print''.join(" \// \/\\"[4*(r>3)+2*((r+c)%8>3)+((r-c-1)%8>3)]for c in R*6)

```

# Answer
> 4 votes
# Python 3, ~~174~~ ~~172~~ 138 bytes

```
print("\n".join(o*6for o in("bbbb////"," bb//// ","  ////  "," ////bb ","////bbbb","b//  bbb","bb    bb","bbb  //b")*3).replace("b","\\"))

```

Found the smallest pattern I could find in the blanket (the "under" and "over" pattern), stuck it in a list and added some list comprehension and string manipulation to unpack it all. Substituted all escaped backslashes by "b" and replaced them back later to save a few bytes.

Thanks to Oliver for golfing off 2 bytes!

Took 34 bytes off by changing the pattern - the whole pattern for the blanket is now in a single list, so only one for loop is needed to unwrap the pattern.

# Answer
> 4 votes
# Python 2, ~~171~~ ~~170~~ 168 bytes

```
a,b,c=r"\\","/"*4," "
f,g=c*2,c+a+b+c
d=(a*2+b)*6,g*6,(f+b+f)*6,g[::-1]*6,(b+a*2)*6,('\\//'+f+a+"\\")*6,(a+f*2+a)*6,(a+"\\"+f+'//\\')*6
for e in 0,1,2:print'\n'.join(d)

```

Not pretty and not clever. Just sets variables for the most often used groups of strings then combines them and prints the result 3 times. May try and golf it more later if I don't find a better approach.

1 byte saved by using raw input on the a assignment. Thanks @nedla2004

-2 by assigning a couple of variables but still not a serious competitor

# Answer
> 4 votes
# Brainfuck, 301 bytes

```
-[>+<-----]-[>>+<<---]>---->+++++++>>++++[<++++++++>-]>+++>++++++++++<[-<++++++[-<<....<....>>>]>>.<<++++++[-<.<..<....>>.>]>>.<<++++++[-<..<<....>>..>]>>.<<++++++[-<.<<....>..>.>]>>.<<++++++[-<<<....>....>>]>>.<<++++++[-<<.<..>>..<...>>]>>.<<++++++[-<<..>....<..>>]>>.<<++++++[-<<...>..<<..>.>>]>>.<]

```

Try it online!

# Answer
> 3 votes
# Perl, 209 + 17 = 226 bytes

Run with `-mList::Util=max -M5.010` (the second flag is free). It's not winning any byte count competitions, but here's my solution.

```
for(0..7){@b=(1)x8;@b[$_+3..$_+7]=(3)x4;@b[7-$_..10-$_]=(2)x4;for$c(0..2){$b[$c+8]=max$b[$c+8],$b[$c];$b[5-$c]=max$b[5-$c],$b[13-$c];}push@a,sprintf("%-8s",join("",@b[3..10])=~tr[123][ /\\]r)x6;}say for@a,@a,@a

```

Readable:

```
for(0..7){
    @b=(1)x8;
    @b[$_+3..$_+7]=(3)x4;
    @b[7-$_..10-$_]=(2)x4;
    for$c(0..2){
        $b[$c+8]=max$b[$c+8],$b[$c];
        $b[5-$c]=max$b[5-$c],$b[13-$c];
    }
    push@a,sprintf("%-8s",join("",@b[3..10])=~tr[123][ /\\]r)x6
}
say for@a,@a,@a

```

Procedurally generates each segment, then repeats the pattern 6 times, then outputs the total result 3 times.

# Answer
> 3 votes
# 05AB1E, 37 bytes

Uses CP-1252 encoding.

```
24FNU48FXXN+XN-<)8%3›J" \// \/\"è?}¶?

```

Try it online!

**Explanation**

Uses the mod-8 trick expertly explained in Jakube's pyth answer.

```
24F                                    # for N in [0 ... 23] do:
   NU                                  # save N in X
     48F                               # for N in [0 ... 48] do:
        XXN+XN-<)                      # push [X,X+N,X-N-1]
                 8%                    # mod each by 8
                   3›                  # compare with 3
                     J                 # join
                      " \// \/\"è?     # index into string and print
                                  }    # end inner loop
                                   ¶?  # print newline

```

# Answer
> 2 votes
# PHP 157 126 bytes

Taking the changes @Titus lists in the comments... I'm annoyed I missed point 1 which I should have caught, but I didn't know strtr() existed which is where most of the savings come - nice work Titus!

NEW:

```
while($i<32)echo$b=strtr([3322,' 322 ','0220',' 223 ',2233,12013,3003,13021][$i++%8],['  ','\\','//','\\\\']),"$b$b$b$b$b\n";

```

OLD:

```
<?$a=[zzyy,' zyy ',syys,' yyz ',yyzz,xysxz,zssz,xzsyx];while($i<32){$b=$a[$i++%8];$b=str_replace([z,x,y,s],['\\\\','\\','//','  '],$b);echo"$b$b$b$b$b$b
";}

```

Because all the backslashes need escaping it saves quite a bit of space to pack them up as different character and replace them for output, and then once I'm calling str\_replace() it makes sense to use it as often as possible.

# Answer
> 2 votes
# SOML, 106 bytes

```
3{"\\\\////”6*p" \\//// ”6*p"  ////  ”6*p" ////\\ ”6*p"////\\\\”6*p"\//  \\\”6*p"\\    \\”6*p"\\\  //\”6*p

```

a non-competing version using a function that I've only recently added: (~~83~~ ~~67~~ 66 bytes)

explanation:

```
  →$\\→#////→@”6*p"→~3{"##@~ #@ ~$@$~ @# ~@##~\//$#\~#$$#~#\$//\~”
  →$                                                                in the further code replace "$" with "  "
    \\→#                                                            replace "#" with "\\"
        ////→@                                                      replace "@" with "////"
              ”6*p"→~3{"##@~ #@ ~$@$~ @# ~@##~\//$#\~#$$#~#\$//\~” the code to exchange stuff in

so that results in:
”6*p"→~3{"\\\\////~ \\//// ~  ////  ~ ////\\ ~////\\\\~\//  \\\~\\    \\~\\\  //\~”
”6*p"→~3{"A~B~C~D~E~F~G~H~”  modified version of the program (removing "/","\" and " " and replaced with A,B,C,ect.)
”6*p"→~                      replace in the further program "~" with ”6*p" which is:
”                            end string
 6*                          repeat the last thing in stack 6 times
   p                         output the result
    "                        start a string
resulting program:
3{"A”6*p"B”6*p"C”6*p"D”6*p"E”6*p"F”6*p"G”6*p"H”6*p"”
shortened example:
3{"A”6*p"B”6*p"H”6*p"”
3{                      repeat 3 times
  "A”                   push "A" (original: "\\\\////")
     6*p                output it multiplied by 6
        "B”             push "B" (original: " \\//// ")
           6*p          output it multiplied by 6
              "H”       push "H" (original: "\\\  //\")
                 6*p    output it multiplied by 6
                    "”  push an empty string (shorter to do ~” than ”6*p)

```

# Answer
> 2 votes
# Perl, ~~132~~ ~~131~~ 113 bytes

```
@a=((0)x4,1..4);map{say+(map$a[7-$_]?$a[$_]*$r?'/':'\\':$a[$_]?'/':$",0..7)x6;push@a,shift@a;$_%4||($r=!$r)}0..23

```

Ungolfed:

```
use strict;
use warnings;
use feature 'say';

my @a = ((1) x 4, (0) x 4);  # print '\' if true
my @b = ((0) x 4, (1) x 4);  # print '/' if true
my $r = 0;                   # print '\' over '/' if true

for (0 .. 23) {
    say((map { $a[$_] ? ($b[$_] * $r ? '/' : '\\') : ($b[$_] ? '/' : ' ') } 0 .. 7) x 6);
    unshift(@a, pop(@a));    # circular shift to left
    push(@b, shift(@b));     # circular shift to right
    $r = !$r if !($_ % 4);   # change print priority
}

```

# Answer
> 2 votes
# Python, ~~245~~ ~~236~~ ~~234~~ ~~233~~ ~~230~~ ~~216~~ ~~212~~ ~~198~~ 195 bytes

OK, longer than my last (and any other) answer but would be interested in feedback on the approach.

```
for a in(40,4496,6200,5456,3240,1188,720,228)*3:print((`a%6561/2178`+`a%2178/729`+`a%729/243`+`a%243/81`+`a%81/27`+`a%27/9`+`a%9/3`+`a%3/1`)*6).replace('0','\\').replace('1','/').replace('2',' ')

```

**Edit**

-9 due to @nedla2004 being more on the ball than me

-2 by taking the lambda outside of the loop and so losing 2 indent spaces

-1 by using `in' '*3` instead of `in 0,1,2` since I don't use `h` anyway. it's just a counter.

-3 Why, why, why did I leave a newline and 2 indents between the second for and the print??? It's late. Will revisit tomorrow.

-14 Can actually lose the lambda completely and just include the base 3 decoder directly after the print statement. Looks messy but after all, this is code golf :)

-4 No point setting a variable for the integer list. Just use it directly in the second for loop.

-14 and no point using the outer loop. Just multiply the integer tuple by 3 (shamelessly stolen from @nedla2004 to get under 200 :))

-3 Saved 3 by making \\=0, /=1 and space=2. This makes the integer list shorter as three of the base 3 numbers now have leading 0's

**How it works (and it does)**

Since only 3 characters are used:

1. l is a list of the 8 repeating patterns as integer equivalents of their base 3 representation assuming that " "=0, "\\"=1 and "/"=2
2. ~~The lambda~~ The first code after the print statement is a lightweight converter from integer to a base 3 string
3. The first loop loops 3 times and the second prints each line with the base 3 characters multiplied by 6 and replaced with /,\ or space.

I'm sure I could use a regex instead of the nested replace() but I'm too tired to try right now. This was just an experiment and longer than my previous Python effort but have posted just for any comments on the approach (and also because I have never worked in base 3 before and I quite enjoyed working out the converter).

# Answer
> 2 votes
# Ruby, 75 bytes

```
1152.times{|i|$><<"\\/ /\\\\ /"[(i+j=i/48)/4&1|(i-j)/2&2|j&4]+$/*(i%48/47)}

```

Better golfed, using a single 8-byte string lookup indexed by j&4 in addition to the other parameters, rather than a modifiable 4-byte string.

# Ruby, 81 bytes

```
1152.times{|i|j=i/48%8;$><<"\\#{'/\\'[j/4]} /"[(i+j)/4&1|(i-j)/2&2]+$/*(i%48/47)}

```

Prints the diagonal stripes character by character. The correct character is selected from a string of 4 characters depending on the presence / absence of each strand. The overlap character is varied depending on which strand is on top.

**Commented**

```
1152.times{|i|j=i/48%8;        #Iterate through all printable chars. j is line number.
  $><<"\\#{'/\\'[j/4]} /"[     #Print a char from "\/ /" if j/4 even or "\\ /" if odd. character changes depending which strand on top.
   (i+j)/4&1|(i-j)/2&2]+       #Print \ if (i+j)/4==0, / if (i-j)/2&2 >0, space if both false. As above if both true.
   $/*(i%48/47)                #If on column 47, print a newline.
}

```

# Answer
> 2 votes
# Haskell, 96 bytes

```
f n=n`mod`8`div`4
putStr$unlines[["\\ //\\ \\/"!!(f(x-y)+2*f(x+y)+4*f y)|x<-[0..47]]|y<-[0..23]]

```

# Answer
> 2 votes
## Ruby, 135 bytes

`puts [3320,1212,720,2172,6520,4144,2920,3184].map{|e|(e.to_s(3).rjust(8,"0").gsub("0"," ").gsub("1","\\").gsub("2","/"))*6+"\n"}.join*3`

The number array corresponds to each component of each line, translated to base 3:  = 0, `\` = 1, `/`= 2, then converted to decimal. The gsub() calls are too big, though.

And, just now, I saw @ElPedro's answer. :-( Just coincidence.

# Answer
> 2 votes
# APL (Dyalog Unicode), <sup>~~36~~</sup> 34 bytes

```
'\/ /\\ /'[(2⊥3<8|⊣,-⍨,+)/¨⍳24 48]

```

Try it online!

Because I can't tolerate an APL answer doing so badly.

This is almost a port of Angs' Haskell answer. Uses `⎕IO←0`.

### How it works

```
'\/ /\\ /'[(2⊥0⌷2 4⊤⊣,-⍨,+)/¨⍳24 48]
⍳24 48   ⍝ Construct a matrix containing pairs of (0..23),(0..47)
(...)/¨  ⍝ Map over each pair...
⊣,-⍨,+   ⍝   Given two numbers x and y, construct [x,y-x,x+y]
2 4⊤     ⍝   Convert the three numbers to mixed base;
         ⍝   equivalent to n → [n%8/4,n%4] in Python 2
0⌷       ⍝   Extract first row (n%8/4)
2⊥       ⍝   Convert base 2 to integer
'\/ /\\ /'[...]  ⍝ Convert each number in the entire matrix with
                 ⍝ the character at that index

```

# Answer
> 1 votes
# Python 2, ~~169~~ ~~161~~ ~~165~~ ~~160~~ ~~155~~ ~~154~~ 152

Based on @ElPedro's answer, with small improvements. To see the explanation, see their answer. This is Python 2, even though there seems to be parenthesis near the `print`.

~~Saved 8 bytes by using a variable for `replace`.~~ That works only for strings, and using a function for it would be longer.

Saved 4 bytes by seeing that @ElPedro realized that they did not need l, and I did not either.

Saved 5 bytes by not flipping the `range(8)`, and instead of using `+=` to append to r, adding r to the end of the new digit. Try it using repl.it

Saved 5 bytes by stealing @ElPedro's new list of values.

Saved 1 byte by removing the space between the `in` and `(`.

Saved 2 bytes by removing the variable a.

```
for x in(40,4496,6200,5456,3240,1188,720,228)*3:
 r=''
 for i in range(8):r=`x/3**i%3`+r
 print(r*6).replace('0','\\').replace('1','/').replace('2',' ')

```

# Answer
> 1 votes
# PHP, 184 bytes

```
<?$p=['1111////',' 11//// ','  ////  ',' ////11 ','////1111','1//  111','11    11','111  //1'];for($j=0;$j<3;$j++)for($i=0;$i<8;$i++)echo str_replace(1,'\\',str_repeat($p[$i],6))."\n";

```

**Output:**

```
C:\PHP>php make-me-a-blanket.php
\\\\////\\\\////\\\\////\\\\////\\\\////\\\\////
 \\////  \\////  \\////  \\////  \\////  \\////
  ////    ////    ////    ////    ////    ////
 ////\\  ////\\  ////\\  ////\\  ////\\  ////\\
////\\\\////\\\\////\\\\////\\\\////\\\\////\\\\
\//  \\\\//  \\\\//  \\\\//  \\\\//  \\\\//  \\\
\\    \\\\    \\\\    \\\\    \\\\    \\\\    \\
\\\  //\\\\  //\\\\  //\\\\  //\\\\  //\\\\  //\
\\\\////\\\\////\\\\////\\\\////\\\\////\\\\////
 \\////  \\////  \\////  \\////  \\////  \\////
  ////    ////    ////    ////    ////    ////
 ////\\  ////\\  ////\\  ////\\  ////\\  ////\\
////\\\\////\\\\////\\\\////\\\\////\\\\////\\\\
\//  \\\\//  \\\\//  \\\\//  \\\\//  \\\\//  \\\
\\    \\\\    \\\\    \\\\    \\\\    \\\\    \\
\\\  //\\\\  //\\\\  //\\\\  //\\\\  //\\\\  //\
\\\\////\\\\////\\\\////\\\\////\\\\////\\\\////
 \\////  \\////  \\////  \\////  \\////  \\////
  ////    ////    ////    ////    ////    ////
 ////\\  ////\\  ////\\  ////\\  ////\\  ////\\
////\\\\////\\\\////\\\\////\\\\////\\\\////\\\\
\//  \\\\//  \\\\//  \\\\//  \\\\//  \\\\//  \\\
\\    \\\\    \\\\    \\\\    \\\\    \\\\    \\
\\\  //\\\\  //\\\\  //\\\\  //\\\\  //\\\\  //\

```

# Answer
> 1 votes
# PowerShell, 89 bytes

```
0..23|%{$y=$_
-join(48..94|%{('\/'[$y%8-lt4]+'\/ ')[(($_+$y)%8-lt4)+2*(($_-$y)%8-ge4)]})}

```

Try it online!

# Answer
> 1 votes
# 05AB1E, 29 bytes

```
•M;(Ð§0—øθε;û…•…/\ Åв8ôJ6×3и»

```

Try it online!

# Answer
> 1 votes
# Underload, 130 bytes

```
((\\\\////)( \\//// )(  ////  )( ////\\ )(////\\\\)(\//  \\\)(\\    \\)(\\\  //\)()(::**:*S(
)S)(:(~*a(a)~*^*)~a*^):*:*:*^!^)::**^

```

Try it online!

# Answer
> 0 votes
## Batch, 152 bytes

```
@call:l
@call:l
:l
@for %%s in (\\\\//// " \\//// " "  ////  " " ////\\ " ////\\\\ "\//  \\\" "\\    \\" "\\\  //\")do @echo %%~s%%~s%%~s%%~s%%~s%%~s

```

String processing in Batch sucks, so this is probably the best approach. The call-and-fall-through is very slightly shorter than a nested `for` loop. At least I don't have to quote my backslashes!

# Answer
> 0 votes
# APL, 110 bytes

I'm new to APL, so this is a simplistic solution.

```
A←48⍴'\\\\////'⋄B←48⍴' \\//// '⋄C←48⍴'  ////  '⋄F←48⍴'\//  \\\'⋄G←48⍴'\\    \\'⋄24 48⍴A,B,C,(⊖B),(⊖A),F,G,⊖F

```

Here's my approach: note that after the first 8 lines of the blanket, the pattern repeats itself. Therefore I only need to define the first 8 lines, and then I can repeat them 3 times. Also note that each line repeats itself after the first 8 characters. Therefore to define a single line I only need to define the first 8 characters and then repeat them 8 times.

Here's an ungolfed solution:

```
A←48⍴'\\\\////'⋄ ⍝ set A to a 48 element vector (48⍴) of repeated '\\\\////'s
B←48⍴' \\//// '⋄ ⍝ set B to a 48 element vector (48⍴) of repeated ' \\//// 's
C←48⍴'  ////  '⋄ ⍝ ...
D←48⍴' ////\\ '⋄ ⍝ Note that this is actually the reverse of vector B
E←48⍴'////\\\\'⋄ ⍝ Note that this is actually the reverse of vector A
F←48⍴'\//  \\\'⋄
G←48⍴'\\    \\'⋄
H←48⍴'\\\  //\'⋄ ⍝ Note that this is actually the reverse of vector F

24 48 ⍴ A,B,C,D,E,F,G,H ⍝ Make a 24 by 48 character matrix (24 48⍴) by concatenating A,B...H
                        ⍝ and repeating the string until the matrix is full

```

I noted above that D is the reverse of B, E is the revers of A, and H is the reverse of F. In my actual code, I take advantage of this by not defining D,F, or H and using the reverse function :

`24 48⍴A,B,C,(⊖B),(⊖A),F,G,⊖F`

# Answer
> 0 votes
## Ruby, 132 bytes

```
puts Zlib.inflate Base64.decode64 "eJzt0bENADAMAsGeKdggC/3+cyQRC+A2ipuT3RgJgHWGUjm6VXb2Vjn/3KpJ/qtIPlp1v+XSKZKPVk3y/x5+D6/3sAEUXQ+Q"

```

very simple answer.

# Answer
> 0 votes
# Perl 5 \+ `-M5.10.0`, 97 bytes

```
say s/\d(.)/$1x$&/ger x6for('4\4/| 2\4/ |  4/  | 4/2\ |4/4\|\//  3\|2\4 2\|3\  //\\'=~/[^|]+/g)x3

```

Try it online!

---
Tags: code-golf, ascii-art, kolmogorov-complexity
---


title: On the Subject of Wire Sequences

text:
# Question
Title: On the Subject of Wire Sequences
This challenge is from a game, Keep Talking And Nobody Explodes.

*It's hard to say how this mechanism works. The engineering is pretty impressive, but there must have been an easier way to manage nine wires.* — from the manual

# Input

Exactly 9 "wires", each which is labeled 'A', 'B', or 'C', and is colored red, blue, or black.

Input format and type doesn't matter, as long as they uniquely identify the wires. In particular, the alphabets can be encoded arbitrarily, so can the colors.

# Objective and Output

Output the indices of the wires that needs to be cut. The output format and type doesn't matter either, as long as they uniquely identify the wires to be cut.

# Which wire to cut?

If the wire has color \\$X\\$ and it's the \\$N\\$th wire of that color that you have seen so far, look at the entry of color \\$X\\$ on row \\$N\\$ of the table. If and only if the wire's label is listed on that entry, it is to be cut.

$$ \begin{array}{c|ccc} & \text{Red} & \text{Blue} & \text{Black} \\ \hline \text{1st} & \text{C} & \text{B} & \text{A, B, or C} \\ \text{2nd} & \text{B} & \text{A or C} & \text{A or C} \\ \text{3rd} & \text{A} & \text{B} & \text{B} \\ \text{4th} & \text{A or C} & \text{A} & \text{A or C} \\ \text{5th} & \text{B} & \text{B} & \text{B} \\ \text{6th} & \text{A or C} & \text{B or C} & \text{B or C} \\ \text{7th} & \text{A, B, or C} & \text{C} & \text{A or B} \\ \text{8th} & \text{A or B} & \text{A or C} & \text{C} \\ \text{9th} & \text{B} & \text{A} & \text{C} \end{array} $$

# Example

Assuming the wires are 1-indexed, and given the following input:

```
Blue  C
Blue  C
Black C
Black B
Black A
Red   C
Blue  C
Black A
Black A

```

The 1st wire is the 1st blue wire, which is not connected to B, so leave it.
The 2nd wire is the 2nd blue wire, which is connected to A *or* C, so cut it.
The 3rd wire is the 1st black wire, so cut it.
The 4th wire is the 2nd black wire, which is not connected to A nor C, so leave it.
The 5th wire is the 3rd black wire, which is not connected to B, so leave it.
The 6th wire is the 1st red wire, which is connected to C, so cut it.
The 7th wire is the 3rd blue wire, which is not connected to B, so leave it.
The 8th wire is the 4th black wire, which is connected to A *or* C, so cut it.
The 9th wire is the 5th black wire, which in not connected to B, so leave it.

So the output is `[2,3,6,8]`.

# Answer
> 3 votes
# Jelly,  ~~27~~  25 bytes

```
ċṪ$Ƥżḅ3Ʋị“µỵƓṢ⁴ż]¶:ɼ’ḃ7¤&

```

A dyadic Link accepting a list of the wire colours on the left and a list of the wire labels on the right which yields a list of indicators of whether to cut each wire.

Inputs:

```
  Red : 1        A : 1
 Blue : 2        B : 2
Black : 3        C : 4

```

Outputs:

```
      Cut : non-zero (truthy)
Don't cut : zero (falsey)

```

**Try it online!**

Here is an easier to use version accepting the colours, `RBK` (red, blue, black), on the first line and the labels, `ABC` on the second line, which yields a list of wire numbers to cut.

### How?

```
ċṪ$Ƥżḅ3Ʋị“...’ḃ7¤& - Link: colours, labels
       Ʋ           - last four links as a monad - f(colours):
   Ƥ               -   for prefixes:
  $                -     last two links as a monad - f(prefix):
 Ṫ                 -       tail -> current wire's colour
ċ                  -       count -> number of such wires seen before
    ż              -     zip with (colours)
      3            -     three
     ḅ             -     convert (zip result items) from base (3)
                             X = the indexes to check in the flattened table
                ¤  - nilad followed by link(s) as a nilad:
         “...’     -   41650313607423351764917
               7   -   seven
              ḃ    -   bijective-base -> [4,2,7,2,5,5,1,2,2,5,1,5,2,2,2,5,6,6,7,4,3,3,5,4,2,1,4]
                             Y = the flattened table as bitmasks of labels to cut
        ị          - (each of X) index into (Y)
                 & - (that) bitwise AND with (labels) (vectorises)

```

# Answer
> 5 votes
# JavaScript (ES6),  ~~75 74~~  67 bytes

Expects a list of `[color, label]` pairs, using `0-2` for both. Returns a binary array describing which wires must be cut.

```
a=>a.map(([c,w])=>(m[c]/=8)>>w&1,m=[334844576,228136272,611931512])

```

Try it online!

### 63 bytes

We can save a few bytes by taking `A=1, B=2, C=4` and returning a list of zero / non-zero values.

```
a=>a.map(([c,w])=>w&=m[c]/=8,m=[334844576,228136272,611931512])

```

Try it online!

### How?

Each color is encoded as a bit mask describing the wire labels for the 1st to the 9th appearance.

```
 #     |  9   8   7   6   5   4   3   2   1  (0)
 Label | CBA CBA CBA CBA CBA CBA CBA CBA CBA ---
-------+-----------------------------------------
 Red   | 010 011 111 101 010 101 001 010 100 000 -> 334844576
 Blue  | 001 101 100 110 010 001 010 101 010 000 -> 228136272
 Black | 100 100 011 110 010 101 010 101 111 000 -> 611931512

```

Whenever a color appears, we right-shift the corresponding bit mask by 3 positions (by dividing it by 8) and we test the bit 0, 1 or 2 according to the label.

# Answer
> 3 votes
# Retina 0.8.2, 119 bytes

```
s`(\d)(?<=(\1.*?)+)
$1$#2
%`(23|4|26|19)A|(22|1[136]|03|5|06|29)B|(2[148]|04|6|17|09)C|(07|28)[AB]|([10]2|18)[AC]|01|27

```

Try it online! Takes input as list of digit + letter pairs where the digit is `2` for Red, `1` for Blue and `0` for Black. Output is a list of whether each wire should be cut. Explanation:

```
s`(\d)(?<=(\1.*?)+)
$1$#2

```

After each digit insert its cumulative appearance count.

```
%`(23|4|26|19)A|(22|1[136]|03|5|06|29)B|(2[148]|04|6|17|09)C|(07|28)[AB]|([10]2|18)[AC]|01|27

```

For each wire check whether it needs to be cut.

# Answer
> 3 votes
# Rust, 89 bytes

```
|w|w.scan([0;3],|a,&(c,l)|{a[c]+=1;Some(b"TGjEQBMERBuFgCkDJD"[2*a[c]-2+c/2]>>c%2*3+l&1)})

```

Try it online!

## Explanation:

Both colors and labels are encoded as numbers from 0-2. The output is a number for every wire: 1 if it should be cut, 0 otherwise. The `b"TG...D"` string contains a binary encoding of the above table. The labels to be cut in every cell is transformed into a 3-bit mask. Three of these masks can be packed into two bytes (Red and Blue in the first byte and Black in the second byte). The 6-th bit (which is unused) is also set, to make all the characters ASCII printable (to not need escape sequences or raw strings).

# Answer
> 2 votes
# , 61 bytes

Takes in values as `Red Blue Black -> 0 1 2`, `A B C -> 0 1 2` transposed, so color stands above letter in the matrix. Returns a bit-mask of wires to be cut.

```
(9 3 3$-.#:2005405163341131167346014x){::~(1#.{:=}:)\@{.|:@,]

```

Try it online!

### How it works

The table is encoded in `(9 3 3$-.#:2005405163341131167346014x)`. Convert the long number to base 2, negate it, and reshape to `9 3 3`. With a index like `4 1 1` (5th blue B) we get a 1, corresponding to cut. I use the negated form so we have a leading 1. Fun fact: the table razed to a list in base 2 `412446475888127182066337` is prime!

```
t{::~(1#.{:=}:)\@{.|:@,]
                 {.      the first row (colors)
               \@        for each prefix (1, 1 1, 1 1 2, …)
         {:=}:           compare last element to all other
      1#.                and count the occurrences
                      ,] prepend this to the original list
                   |:@   and transpose it
t{::~                    get the corresponding bit of the table

```

# Answer
> 2 votes
# Charcoal, 33 bytes

```
⭆θ§”)∧∨⦃↧dＧ↓◨h↓WK”⍘⁺№Ｅ…θκ§λ⁰§ι⁰ι³

```

Try it online! Link is to verbose version of code. Takes input as list of digit + letter pairs where the digit is `2` for Red, `1` for Blue and `0` for Black. Output is a binary string of whether each wire should be cut. Explanation:

```
 θ                      Input list
⭆                       Map over elements and join
   ”...”                Compressed binary lookup table
  §                     Cyclically indexed by
          №             Count of
                  § ⁰   First character of
                   ι    Current entry in
            … κ         Prefix of
             θ          Input list
           Ｅ            Map over entries
               § ⁰      First character of
                λ       Inner entry
         ⁺              Concatenated with
                     ι  Current entry
        ⍘             ³ Interpreted as base 3
                        Implicitly print

```

As an example, the last wire from the example, `0A`, is the fifth black wire, therefore there are four wires in the prefix, resulting in a string `40A`. This converts as `4 * 9 + 0 * 3 + A`, where the letters are decoded using `a=10, ... z=35, A=36, ... Z=61`, resulting in a final total of 72. The use of uppercase letters here just requires the entire lookup table to be rotated by 36 bits, so it's not necessary to encode the letters.

# Answer
> 2 votes
### Python 3, 92 bytes

```
def f(w):
 m,i=[41855572,28517034,76491439],1
 for c,t in w:t&m[c]and print(i);i+=1;m[c]>>=3

```

Takes input as a list of (color, wire) tuples. Color is coded red=0, blue=1, and black=2. Wires are coded A=1, B=2, and C=4. So the example is

```
[(1, 4), (1, 4), (2, 4), (2, 2), (2, 1), (0, 4), (1, 4), (2, 1), (2, 1)]

```

`m` is the encoded table. The 1st row is encoded in the least significant bits. In binary:

```
table = [
    #   9   8   7   6   5   4   3   2   1   <- table row
    #  CBA CBA CBA CBA CBA CBA CBA CBA CBA
    0b_010_011_111_101_010_101_001_010_100,
    0b_001_101_100_110_010_001_010_101_010,
    0b_100_100_011_110_010_101_010_101_111
]

```

After checking a color/label combination, the table column is shifted by 3 bits so that it doesn't need to keep track of the 1st red wire, 2nd red wire, etc.

# Answer
> 1 votes
# 05AB1E, 32 bytes

```
ε•1ä)eι()2×rK•b3ô3ô¯yн©¢è®èyθè®ˆ

```

Input as a pair of `[color, wire]`, where the colors are `red=2, blue=1, black=0` and wires are `A=0, B=1, C=2`. Outputs a list of 0s and 1s, where the 1s are the position of the wires we should cut.

Try it online.

**Explanation:**

```
ε                   # Map over each pair `y` of the (implicit) input:
 •1ä)eι()2×rK•      #  Push compressed integer 2199241953913589502631010
  b                 #  Convert it to binary: 111010001101101010010010100101100101010010010011011101110001111001101110001100010
   3ô               #  Split it into parts of size 3: ["111","010","001","101","101","010","010","010","100","101","100","101","010","010","010","011","011","101","110","001","111","001","101","110","001","100","010"]
     3ô             #  Split that list into parts of size 3 again: [["111","010","001"],["101","101","010"],["010","010","100"],["101","100","101"],["010","010","010"],["011","011","101"],["110","001","111"],["001","101","110"],["001","100","010"]]
       ¯            #  Push the global array
        yн          #  Get the first item of the pair
          ©         #  Store it in variable `®` (without popping)
           ¢        #  Count the amount of times it occurs in the global array
            è       #  Use that to index into the list of triplets
             ®      #  Push the first item of variable `®` again
              è     #  Use that to index into the triplet
               yθ   #  Push the last item of the pair
                 è  #  Use that to index into the binary-string
          ®ˆ        #  Add the first item of variable `®` to the global array
                    # (after which the resulting list is output implicitly)

```

See this 05AB1E tip of mine (section *How to compress large integers?*) to understand why `•1ä)eι()2×rK•` is `2199241953913589502631010`.

# Answer
> 1 votes
# C (gcc), 107 bytes

```
_,O;P(int*T){for(int R[3]={O=0};9>O++;"T+R&%*{9+*"[_/7]>>_%7&1&&printf("%d ",O))_=*T+R[*T++/3]++*9+*T++;}

```

Try it online!

Takes an array of { color 1, label 1, color 2, label 2, ...

Each entry of table is encoded in three triplets of bits , one for each color, where each bit represent a label

```
    r b bla        RedBluBla
                   abcabcabc
1st c b abc     -> 001010111
2   b ac ac     -> 010101101
3   a b b       -> 100010010
4   ac a ac     -> 101100101
5   b b b       -> 010010010
6   ac bc bc    -> 101011011
7   abc c ab    -> 111001110
8   ab ac c     -> 110101001
9   b a c       -> 010100001

```

Then all bits are joined, spilt by 7 , reversed and converted to a string `T+R&%*{9+*`.

To get the the target bit position we multiply by 9 the table line we need and we add color value and label value.

Then we divide by 7 to get the character we need in the encoded string and we shift back by modulo 7

---
Tags: code-golf
---