title: Generate a Stack Exchange Favicon

text:
# Question
Title: Generate a Stack Exchange Favicon
Do you recognize the PPCG logo? it looks like this, when you do an ascii art of it.

```
+---+
|PCG|
+---+
   v

```

Now, In this Code Golf, You will make a code, that makes logos for other sites, similar to the PPCG logo.

# What You should do

The "Shortened" string will be the string, with all upper case letters and numbers in the input string.(Which would be `PPCG` when the input string is `Programming Puzzles & Code Golf`)

The "Box" (

```
+---+
|   |
+---+
   v

```

) should fit the Shortened string perfectly.(No bigger or smaller)

Also the `v` part should be exactly 1 down and 1 left to the down right `+`.

Then output the box which has the shortened string in it.

# Example

`Stack Overflow`:

```
+--+
|SO|
+--+
  v

```

`Area 51`:

```
+---+
|A51|
+---+
   v

```

# Rules

You may assume that the input contains at least one digit or upper case letter.

Standard rules apply.

# Answer
# Vim, 42 strokes

```
:s/[^A-Z0-9]//g
YPVr-i+<DOWN><LEFT>|<ESC><C-V>ky$pYjppVr $xrv

```

Replace `<DOWN>` with , `<LEFT>` with , `<ESC>` with `esc` and `<C-V>` with `CTRL`+`V`.

Here's an animation of this script running (old version which uses a `V` instead of a `v`):

Explanation of the script:

```
:s/[^A-Z0-9]//g                               # Remove all the characters that are not uppercase or numbers using a Regex.
YPVr-                                         # Duplicate the current, and replace all the characters of the upper one with dashes.
     i+<DOWN><LEFT>|<ESC>                     # Insert a + on the upper line, and a | on the second line.
                         <C-V>ky$p            # Copy the + and | to the end of both lines.
                                  Yjpp        # Copy the upper line to the bottom two times.
                                      Vr $    # Replace the bottom most line with spaces and put the cursor on the last character.
                                          xrv # Remove the last character and replace the second last character with a v.

```
> 24 votes

# Answer
# 34 bytes

```
Ó[^A-Z0-9]
ys$|ÄVr-r+$.YLppVr x$rv

```

Note that this worked in an older version, but doesn't work in the current version on try it online. I changed `Ä` to `YP` which is functionally equivalent.

Try it online!

Explanation:

```
Ó[^A-Z0-9]

```

Remove everything except for digits and uppercase characters.

```
ys$|              "Surround this line with '|' characters.
    Ä             "Duplicate this line
     Vr-          "Replace this whole duplicated line with '-' characters
        r+        "replace the first character with '+'
          $       "Move to the end of the line, and
           .      "Repeat our last command. This is the same as 'r+'
            Y     "Yank the current line
              pp  "and paste it twice
             L    "At the end of our text

```

Now, the buffer looks like this:

```
+---+
|A51|
+---+
+---+

```

And our cursor is at the first column of the last line.

```
Vr                 "Change the whole last line to spaces
   x               "Delete a character
    $rv            "And change the last character to a 'v'

```

Non-competing version: (31 bytes)
> 10 votes

# Answer
# 16-bit x86 machine code, 72 bytes

In hex:

```
565789F731C9FCAC84C074143C5A77F73C4173083C3977EF3C3072EBAA41EBE75F5EE81500B07CAA51F3A4AB59E80A00B020F3AAB076AA91AAC351B02BAAB02DF3AAB82B10AB59C3

```

Parameters: `SI` = input string, `DI` \- output buffer.

Outputs a NULL-terminated string with lines delimited by newline. Uses input string as a temporary buffer.

```
56           push   si
57           push   di
89 f7        mov    di,si    ;Using source string as a buffer
31 c9        xor    cx,cx    ;Counter
fc           cld
_loop:
ac           lodsb
84 c0        test   al,al    ;Test for NULL
74 14        jz     _draw    ;Break
3c 5a        cmp    al,'z'   ;\
77 f7        ja     _loop    ; |
3c 41        cmp    al,'a'    ; \
73 08        jae    _stor    ;  >[A-Z0-9]?
3c 39        cmp    al,'9'   ; /
77 ef        ja     _loop    ; |
3c 30        cmp    al,'0'   ;/
72 eb        jb     _loop
_stor:
aa           stosb           ;Store char in the source buffer
41           inc    cx
eb e7        jmp    _loop
_draw:
5f           pop    di
5e           pop    si
e8 15 00     call   _line    ;Output the first line
b0 7c        mov    al,'|'   ;This proc upon return leaves '\n' in AH
aa           stosb           ;First char of the second line
51           push   cx
f3 a4        rep    movsb    ;Copy CX logo characters from the source buffer
ab           stosw           ;Outputs "|\n", which is still in AX
59           pop    cx
e8 0a 00     call   _line    ;Output the third line
b0 20        mov    al,0x20  ;Space
f3 aa        rep    stosb    ;Output it CX times
b0 76        mov    al,'v'
aa           stosb           ;Output the final 'v'
91           xchg   cx,ax    ;CX == 0
aa           stosb           ;NULL-terminate the string
c3           retn            ;Return to caller
_line:
51           push   cx
b0 2b        mov    al,'+'
aa           stosb
b0 2d        mov    al,'-'
f3 aa        rep    stosb     ;'-'*CX
b8 2b 10     mov    ax,0x102b ;"+\n"
ab           stosw
59           pop    cx
c3           retn

```
> 7 votes

# Answer
## Lua, ~~145~~ 99 Bytes

Not much to say, manipulating strings is always wordy in lua :). Takes a command-line argument and output via STDOUT

**Thanks to @LeakyNun for saving me 45 Bytes !**

```
n=(...):gsub("[^%u%d]","")s="+"..("-"):rep(#n).."+\n"return s.."|"..n.."|\n"..s..(" "):rep(#n).."V"

```

**100 Bytes proposed by @LeakyNun**

```
n=(...):gsub("[^A-Z%d]","")s="+"..("-"):rep(#n).."+\n"return s.."|"..n.."|\n"..s..(" "):rep(#n).."V"

```

**OLD 145 Bytes**

```
g="|"..(...):gsub("%a+",function(w)return w:sub(1,1)end):gsub("%s",'').."|"S="+"..g.rep("-",#g-2).."+"p=print
p(S)p(g)p(S)p(g.rep(" ",#g-2).."v")

```

### Ungolfed

```
g="|"                            -- g is the second, and starts with a |
  ..(...):gsub("%a+",            -- append the string resulting of the iteration on each word
    function(w)                  -- in the input, applying an anonymous function
      return w:sub(1,1)          -- that return the first character of the word
    end):gsub("%s",'')           -- then remove all spaces
  .."|"                          -- and append a |
S="+"..g.rep("-",#g-2).."+"      -- construct the top and bot of the box
p=print                          -- alias for print
p(S)p(g)p(S)                     -- output the box
p(g.rep(" ",#g-2).."v")          -- output #g-2 spaces (size of the shortened name), then v

```
> 4 votes

# Answer
# Retina, 43 bytes

```
[^A-Z\d]

.+
+$.&$*-+¶|$&|¶+$.&$*-+¶$.&$* V

```

Try it online!

This is the perfect challenge to demonstrate Retina, Martin Ender's golfing language.

This solution is divided into two steps (what we call stages), both stages being a replacement stage.

The first stage:

```
[^A-Z\d]

```

This matches the substrings which match `[^A-Z\d]`, which is the characters that are not uppercase and not digits, and then substitute them by nothing, meaning deleting them.

The second stage:

```
.+
+$.&$*-+¶|$&|¶+$.&$*-+¶$.&$* V

```

The `.+` matches the whole result, and then substitutes it with the second line.

In the second line:

* `$&` refers to the whole match
* `$.&` refers to the length of the whole match
* `$*` means take the previous integer, repeat the next character that many times. Here `$.&$*-` means to repeat `-` however long the match is.
* refers to a new-line.
> 4 votes

# Answer
# Excel VBA, ~~375~~ ~~359~~ 358 bytes:

It works, I give up on trying to make it shorter...

Edit: Switched to case statement from if statements, -16 bytes

Edit2: Got rid of u and replaced with Len(b), -1 byte

```
Function b(x)
For i = 1 To Len(x)
a = Mid(x, i, 1)
e = Asc(a)
If e > 64 And e < 91 Or e > 47 And e < 58 Then b = b & a
Next i
For Z = 1 To 4
y = ""
Select Case Z
Case 2
y = "|" & b & "|"
Case 4
For i = 1 To Len(b)
y = y & " "
Next i
y = y & "v"
Case Else
y = "+"
For i = 1 To Len(b)
y = y & "-"
Next i
y = y & "+"
End Select
Debug.Print y
Next Z
End Function

```
> 4 votes

# Answer
## C#, 183 177 165 bytes

```
string h(string s){s=string.Concat(s.Where(n=>n>47&n<58|n>64 &n<91));int m=s.Length;var x=new string('-',m);return$"+{x}+\n|{s}|\n+{x}+\n{new string(' ', m + 1)}v";}

```

multiplying chars is terrible in C#. suggestions appreciated

thanks alot to aloisdg for -18 bytes
> 4 votes

# Answer
# 2sable, ~~36~~ ~~34~~ ~~33~~ ~~32~~ 31 bytes

Presenting **2sable** :). Although it has a lot in common with 05AB1E, this one actually auto joins the stack rather than outputting the top of the stack. Code:

```
žKA-Ã©g'-×'+DŠJDU„
|Â®sX¶®gð×'v

```

Uses the **CP-1252** encoding.
> 3 votes

# Answer
## JavaScript (ES6), 99 bytes

```
(s,t=s.replace(/[^0-9A-Z]/g,``),g=c=>t.replace(/./g,c))=>`${s=`+${g(`-`)}+
`}|${t}|
${s}${g(` `))v`

```
> 3 votes

# Answer
# Haskell, 107 Bytes

This answer is heavily based on the answer by *Zylviij* and the comments by *nimi*. I would have added more comments to that answer, but alas, I don't have enough rep.

```
o n=t++'|':f++"|\n"++t++(f>>" ")++"v"where f=[c|c<-n,any(==c)$['0'..'9']++['A'..'Z']];t='+':(f>>"-")++"+\n"

```

Additional tricks used:

* Replaced `intersect` by its implementation so the import can be dropped. (Side note: the implementation is nearly verbatim the library one, I couldn't find a shorter version.)
* Moved the helper functions into the `where` clause so functions can use the `n` parameter internally.
* After that, `(#)` was short enough to be inlined.
* Put everything on one line to limit extra whitespace.
> 3 votes

# Answer
# Python 3.5, ~~114~~ ~~93~~ 112 bytes:

```
import re;Y=re.findall('[A-Z0-9]',input());I='+'+'-'*len(Y)+'+\n|';print(I+''.join(Y)+I[::-1]+'\n'+' '*len(Y)+'v')

```

A full program. Basically uses a regular expression to match all occurrences of uppercase letters and numbers, then creates the box of the exact size based on the length of the list of matches, and finally puts the joined list of matches "inside" it.

Try It Online! (Ideone)
> 2 votes

# Answer
# Python 3, ~~121~~ 124 bytes

Fixed stupid mistake

```
s=''
for i in input():_=ord(i);s+=("",i)[91>_>64or 47<_<58]
x=len(s)
c='+'+"-"*x+'+'
print(c+"\n|"+s+"|\n"+c+"\n"+" "*x+"v")

```

does not import libraries like other python answer.
> 2 votes

# Answer
# Java 8, 149 bytes

```
s->{s=s.replaceAll("[^A-Z0-9]","");String t="+",r;int l=s.length(),i=l;for(;i-->0;t+="-");for(r=(t+="+\n")+"|"+s+"|\n"+t;++i<l;r+=" ");return r+"v";}

```

Try it online.

**Explanation:**

```
s->{                     // Method with String as both parameter and return-type
  s=s.replaceAll("[^A-Z0-9]","");
                         //  Leave only the uppercase letters and digits
  String t="+",          //  Temp-String, starting at "+"
         r;              //  Result-String
  int l=s.length(),      //  Amount of uppercase letters and digits `l`
  i=l;for(;i-->0;t+="-");//  Loop and append `l` amount of "-" to the temp-String
  for(r=(t+="+\n")       //  Append "+" and a new-line to the temp-String
        +"|"+s+"|\n"+t;  //  Set the result to `t`, "|", modified input, "|", new-line, `t`
                         //  all appended to each other
      ++i<l;r+=" ");     //  Loop and append `l` amount of spaces to the result
  return r+"v";}         //  Return the result-String with appended "v"

```
> 2 votes

# Answer
## Perl, 57 bytes

**56 bytes code + 1 for `-p`.**

```
y/a-z //d;$d="-"x y///c;$_="+$d+
|$_|
+$d+
".$"x y///c.v

```

I originally tried to make this only using regexes, but it was much larger than I'd hoped, so I've used some string repetition instead.

Try it online!
> 1 votes

# Answer
## Pyke, 39 bytes

```
cFDh~u{!Ih(sil\-*\+R\+sj\|i\|++jild*\v+

```

Try it here!

12 bytes of mini-string creation, 20 bytes of formatting. Joy!
> 1 votes

# Answer
# Pyth, ~~38~~ 37 bytes

```

Jj*\-lK@jrG1UTz"++"jK"||"JtXJ"-+"" v
```

Try it online.

Note the newline in the start.
> 1 votes

# Answer
## Python 2, 113 bytes

```
def f(n):c=filter(lambda x:x.isupper()^x.isdigit(),n);L=len(c);h='+'+L*'-'+'+\n';return h+'|'+c+'|\n'+h+' '*L+'v'

```
> 1 votes

# Answer
# Jolf, 35 bytes

```
Ά+,Alγ/x"[^A-Z0-9]"1'+'-'|γS*lγ" 'v

```

I need a shorter way to remove all but caps & numbers...
> 1 votes

# Answer
# C, ~~171~~ 163

Function `f()` modifies its input and prints out the result.

```
l;f(char*n){char*p=n,*s=n,c[99];for(;*n;++n)isupper(*n)+isdigit(*n)?*p++=*n:0;*p=0;memset(c,45,l=strlen(s));c[l]=0;printf("+%s+\n|%s|\n+%s+\n%*.cv\n",c,s,c,l,32);}

```

## Test Program

Requires one parameter, the string to use in the favicon:

```
#include <stdlib.h>
#include <stdio.h>
#include <string.h>

int main(int argc, const char **argv)
{
    char *input=malloc(strlen(argv[1])+1);
    strcpy(input,argv[1]);
    f(input);
    free(input);
    return 0;
}

```
> 1 votes

# Answer
# Haskell, 161

```
import Data.List
r=replicate
l=length
f n=intersect n$['0'..'9']++['A'..'Z']
t n='+':(r(l$f n)'-')++"+\n"
o n=(t n)++"|"++(f n)++"|\n"++(t n)++(r(l$f n)' ')++"V"

```

### Usage

```
o"Stack Overflow"
+--+
|SO|
+--+
  V

o"Area 51"
+---+
|A51|
+---+
   V

```
> 1 votes

# Answer
# Bash, ~~99~~ 74 bytes

```
s=$(sed s/[^A-Z0-9]//g);a=${s//?/-};echo -e "+$a+\n|$s|\n+$a+\n${s//?/ }v"

```

Usage: Run the above command, type the site name, press enter and then `Ctrl` \+ `D` (send 'end of file').
> 1 votes

# Answer
# MATL, 34 bytes

```
t1Y24Y2hm)T45&Ya'+|+'!wy&h10M~'v'h

```

**Try it online!**

```
t        % Implicit input. Duplicate
1Y2      % Uppercase letters
4Y2      % Digit characters
h        % Concatenate horizontally: string with uppercase letters and digits
m        % True for input chars that are uppercase letters or digits
)        % Keep only those
T45&Ya   % Pad up and down with character 45, which is '-'. Gives three-row char array
'+|+'!   % Push this string and transpose into a column vector
wy       % Swap, duplicate the second array from the top. This places one copy of the
         % column vector below and one above the three-row char array
&h       % Contatenate all stack arrays horizontally. This gives the box with the text
10M      % Retrieve the string with selected letters
~        % Logical negate. Gives zeros, which will be displayes as spaces
'v'      % Push this character
h        % Concatenate horizontally with the zeros.
         % Implicitly display the box with the text followed by the string containing
         % the zero character repeated and the 'v'

```
> 1 votes

# Answer
# R, 108 bytes

```
cat(x<-gsub("(.*)","+\\1+\n",gsub(".","-",y<-gsub("[^A-Z0-9]","",s))),"|",y,"|\n",x,gsub("."," ",y),"v",sep="")

```

## Explanation

Going from the inside out (because who doesn't love assigning global variables from inside a regex), assuming `s` is our input string:

`y<-gsub("[^A-Z0-9]","",s)` keeps capitals and numbers, assigns the resulting value to y.

`gsub(".","-",y<-...)` replaces all characters with hyphens in the above.

`x<-gsub("(.*)","+\\1+\n",gsub(...))` chucks a `+` on either end of the row of hyphens, and a newline, and we store that as x.

The rest is pretty straightforward, output in the appropriate order, and use the fact that the number of spaces before the `v` will be the same as the length of y.
> 1 votes

# Answer
# CJam, 41

```
"||"q_'[,65>A,s+--*__"+-"er_@\_,((S*]N*'v

```

Try it online
> 1 votes

# Answer
## APL, 52 49 bytes

```
{x⍪2⌽'v'↑⍨≢⍉x←⍉z⍪⍨(z←'+|+')⍪'-','-',⍨⍪⍵/⍨⍵∊⎕D,⎕A}

```

(down to 49 thanks to the comment).
> 1 votes

# Answer
# Brachylog, 61 bytes

Linked to the repository at Jul 7 to ensure backward compatibility.

```
lybL:{,."-"}ac:"+"c:"+"rcAw@NNw"|"Bw?wBwNwAwNwL:{," "w}a,"v"w

```

### Non-competing, 53 bytes

```
lL:"-"rjb:"+"c:"+"rcAw@NNw"|"Bw?wBwNwAwNw" ":Ljbw"v"w

```

Try it online!
> 1 votes

# Answer
## JavaScript (ES6), 119 bytes

```
h=a=>"+"+"-".repeat(a.length)+"+\n";j=a=>(a=a.replace(/[^A-Z0-9]/g,""),h(a)+"|"+a+"|\n"+h(a)+" ".repeat(a.length)+"v");

```
> 1 votes

# Answer
# , 52 bytes

```
'v'(<3 _2)}4{.1":]<@#~2|'/9@Z'&I.[9!:7@'+++++++++|-'

```

Try it online!

```
   [9!:7@'+++++++++|-'            Set the box drawing characters.
        '/9@Z'&I.                 Interval index, 1 for numbers, 3 for
                                  uppercase letters.
          ]  #~2|                 Mod 2, and filter
                                  the characters that correspond to 1s.
           <@                     Put them in a box.
           1":                    Convert to a character matrix, so we can do stuff to it.
           4{.                    Add a 4th line filled with spaces
       'v'(<3 _2)}                Insert a “v” at 3,−2

```
> 1 votes

# Answer
# Ruby, 81 bytes (78 + `-p` flag)

```
gsub(/[^A-Z\d]/,'')
gsub(/.+/){"+#{k=?-*s=$&.size}+
|#{$&}|
+#{k}+
#{' '*s}v"}

```
> 0 votes

# Answer
# PHP, 112 bytes

```
<?$s=str_replace('-',' ',$m=ereg_replace('.','-',$n=ereg_replace('[^A-Z0-9]','',$x)));echo"+$m+
|$n|
+$m+
$s",v;

```
* PHP\<5.4 with `register_globals=1`, call `php-cgi -f <filename> x="<name>";echo""`
* add `<pre>` after `echo"` for call in web browser `<scriptpath>?x=<name>`;
* for PHP\>=5.4: replace `$x` with `$_GET[x]` (+6)
or with `$argv[1]` to call `php <filename> "<name>";echo""` (+6)
* you may want to add `-d error_reporting=0` to cli options

There are times when I love that PHP accepts newlines in constant strings.

* `str_repeat` looked like a buddy here, but costs 3 bytes
* `<?=(<assignments>)?"<output>".v:0` costs 1 byte
* `<?=(<assignments>),"
<output>",v;` does neither cost nor save, but adds a leading blank line to the output
> 0 votes

# Answer
## Common Lisp (Lispworks), 159 bytes bytes

```
(defun f(s)(labels((p(c l)(dotimes(i l)(format t"~A"c))))(let((l(length s)))#1=(p"+"1)#2=(p"-"l)#3=(format t"+~%")(format t"|~A|~%"s)#1##2##3#(p" "l)(p"v"1))))

```

ungolfed:

```
(defun f (s)
  (labels ((p (c l)
             (dotimes (i l)
               (format t "~A" c))))
    (let ((l (length s)))
      #1=(p "+" 1)
      #2=(p "-" l)
      #3=(format t "+~%")
      (format t "|~A|~%" s)
      #1#
      #2#
      #3#
      (p " " l)
      (p "v" 1))))

```

Usage:

```
CL-USER 2 > (f "so")
+--+
|so|
+--+
  v
NIL

CL-USER 3 > (f "pcg")
+---+
|pcg|
+---+
   v
NIL

```
> 0 votes

# Answer
# Japt 2.0 `-R`, ~~37~~ 36 bytes

*Saved 1 byte thanks to Shaggy*

```
r/\W|\a/
'+²¬qUÊî-
[V'|+U+'|V'viUÊî]

```

Run it online
> 0 votes

# Answer
# SmileBASIC 3, 131 bytes

```
INPUT N$WHILE""<N$C$=SHIFT(N$)IF@0<C$&&"[">C$||"/"<C$&&":">C$THEN W$=W$+C$
WEND
L=LEN(W$)H$="+"+"-"*L+"+
?H$?"|"+W$+"|
?H$?" "*L+"v

```
> 0 votes

# Answer
# Kotlin, ~~129~~ 126 bytes

```
{s:String->val x=s.filter{it in('A'..'Z')+('0'..'9')}
val h="-".repeat(x.length)
"+$h+\n|$x|\n+$h+\n${" ".repeat(x.length)}v"}

```

Try it online!
> 0 votes

# Answer
# C# (Visual C# Interactive Compiler), 128 bytes

```
x=>{x=Replace(x,"[^A-Z0-9]","");Write("{0}{1}\n{0}{2}","+"+"+\n".PadLeft(x.Length+2,'-'),$"|{x}|","v".PadLeft(x.Length+1,' '));}

```

Try it online!
> 0 votes

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


title: Hexadecimal and the Alphabet

text:
# Question
Title: Hexadecimal and the Alphabet
In this challenge, you will receive an input, convert it to hexadecimal, make a couple changes, and output the result.

Because they are only 16 characters in hexadecimal, your code will need to be as short as possible.

---

## Examples

Examples are separated by a blank line. First line is input, second line shows the steps, third shows the output

```
234589
234589 -> 3945D -> 39454 -> 9A1E -> 9115 -> 239B -> 2392 -> 958
958

435234
435234 -> 6A422 -> 61422 -> EFEE -> 5655 -> 1617
1617

153
153 -> 99 -> 99 -> 63
1617

```

## Steps

The input will always be a positive integer

---

In order to generate the output you will follow the following steps:

1. Convert the input to hexadecimal
2. Replace any letters with their index in the alphabet (e.g. `a -> 1, b -> 2`)
3. Convert the result back to hexadecimal
4. If the result contains any letters, go to step 2. If not, output the result

---

This is so shortest code in bytes wins!

# Answer
> 13 votes
# Jelly, 18 bytes

```
b⁴µ:⁵©+¹%⁵ḅ⁵ß¹®S¤?

```

Try it online!

The binary, 18 byte version of the source code has the xxd dump

```
0000000: 62 b6 8c 3a b7 85 2b 8e 25 b7 a3 b7 95 8e 88 53 83 3f b..:..+.%......S.?

```

and works with this version of the Jelly interpreter.

### How it works

```
b⁴µ:⁵©+¹%⁵ḅ⁵ß¹®S¤?  Define the main link -- Left input: a (number)

b⁴                  Convert from integer to base 16.
  µ                 Start a new, monadic link.
   :⁵               Divide all base 16 digits by 10.
     ©              Save the result in a register.
      +¹            Add the quotients to the base 16 digits.
        %⁵          Take all resulting sums modulo 10.
          ḅ⁵        Convert from base 10 to integer.
              ®S¤   Take the sum of the quotients from the list in the register.
                 ?  If the result is non-zero:
            ß         Recursively call the main link.
             ¹        Else, apply the identity function.

```

(decimal-to-integer) should have worked as a shorthand for `ḅ⁵`, but the latest version of Jelly at the time of this post had a bug that prevented me from using it.

# Answer
> 8 votes
# JavaScript ES6, ~~98~~ ~~92~~ ~~67~~ 64 bytes

*Saved 3 bytes thanks to @Downgoat, 3 more thanks to @user81655*

Found a much, much shorter version, ditching the loop for recursion:

```
h=x=>(y=x.toString(16))>(r=y.replace(/\D/g,z=>'0x'+z-9))?h(+r):r

```

Probably the most interesting part of this program is the `replace` function:

```
z=>     // Implicit: z = one of "a", "b", "c", "d", "e", "f"
'0x'+z  // Add '0x' to the beginning of z.
        // If z == "a", this results in "0xa".
-9      // Subtract 9. JavaScript automatically coerces the string to a number,
        // and because the prefix "0x" means "convert from hexadecimal",
        // the "a" is converted to 10, which then becomes 1 because of the subtraction.

```

### Test snippet

*(taken from here)*

```
h=x=>(y=x.toString(16))>(r=y.replace(/\D/g,z=>'0x'+z-9))?h(+r):r
```

```
<!--                               Try the test suite below!                              --><strong id="bytecount" style="display:inline; font-size:32px; font-family:Helvetica"></strong><strong id="bytediff" style="display:inline; margin-left:10px; font-size:32px; font-family:Helvetica; color:lightgray"></strong><br><br><pre style="margin:0">Code:</pre><textarea id="textbox" style="margin-top:5px; margin-bottom:5px"></textarea><br><pre style="margin:0">Input:</pre><textarea id="inputbox" style="margin-top:5px; margin-bottom:5px"></textarea><br><button id="testbtn">Test!</button><button id="resetbtn">Reset</button><br><p><strong id="origheader" style="font-family:Helvetica; display:none">Original Code Output:</strong><p><div id="origoutput" style="margin-left:15px"></div><p><strong id="newheader" style="font-family:Helvetica; display:none">New Code Output:</strong><p><div id="newoutput" style="margin-left:15px"></div><script type="text/javascript" id="golfsnippet">var bytecount=document.getElementById("bytecount");var bytediff=document.getElementById("bytediff");var textbox=document.getElementById("textbox");var inputbox=document.getElementById("inputbox");var testbtn=document.getElementById("testbtn");var resetbtn=document.getElementById("resetbtn");var origheader=document.getElementById("origheader");var newheader=document.getElementById("newheader");var origoutput=document.getElementById("origoutput");var newoutput=document.getElementById("newoutput");inputbox.value="234589";textbox.style.width=inputbox.style.width=window.innerWidth-50+"px";var _originalCode=null;function getOriginalCode(){if(_originalCode!=null)return _originalCode;var allScripts=document.getElementsByTagName("script");for(var i=0;i<allScripts.length;i++){var script=allScripts[i];if(script.id!="golfsnippet"){originalCode=script.textContent.trim();return originalCode}}}function getNewCode(){return textbox.value.trim()}function getInput(){try{var inputText=inputbox.value.trim();var input=eval("["+inputText+"]");return input}catch(e){return null}}function setTextbox(s){textbox.value=s;onTextboxChange()}function setOutput(output,s){output.innerHTML=s}function addOutput(output,data){output.innerHTML+='<pre style="background-color:'+(data.type=="err"?"lightcoral":"lightgray")+'">'+escape(data.content)+"</pre>"}function getByteCount(s){return(new Blob([s],{encoding:"UTF-8",type:"text/plain;charset=UTF-8"})).size}function onTextboxChange(){var newLength=getByteCount(getNewCode());var oldLength=getByteCount(getOriginalCode());bytecount.innerHTML=newLength+" bytes";var diff=newLength-oldLength;if(diff>0){bytediff.innerHTML="(+"+diff+")";bytediff.style.color="lightcoral"}else if(diff<0){bytediff.innerHTML="("+diff+")";bytediff.style.color="lightgreen"}else{bytediff.innerHTML="("+diff+")";bytediff.style.color="lightgray"}}function onTestBtn(evt){origheader.style.display="inline";newheader.style.display="inline";setOutput(newoutput,"");setOutput(origoutput,"");var input=getInput();if(input===null){addOutput(origoutput,{type:"err",content:"Input is malformed. Using no input."});addOutput(newoutput,{type:"err",content:"Input is malformed. Using no input."});input=[]}doInterpret(getNewCode(),input,function(data){addOutput(newoutput,data)});doInterpret(getOriginalCode(),input,function(data){addOutput(origoutput,data)});evt.stopPropagation();return false}function onResetBtn(evt){setTextbox(getOriginalCode());origheader.style.display="none";newheader.style.display="none";setOutput(origoutput,"");setOutput(newoutput,"")}function escape(s){return s.toString().replace(/&/g,"&").replace(/</g,"<").replace(/>/g,">")}window.alert=function(){};window.prompt=function(){};function doInterpret(code,input,cb){var workerCode=interpret.toString()+";function stdout(s){ self.postMessage( {'type': 'out', 'content': s} ); }"+" function stderr(s){ self.postMessage( {'type': 'err', 'content': s} ); }"+" function kill(){ self.close(); }"+" self.addEventListener('message', function(msg){ interpret(msg.data.code, msg.data.input); });";var interpreter=new Worker(URL.createObjectURL(new Blob([workerCode])));interpreter.addEventListener("message",function(msg){cb(msg.data)});interpreter.postMessage({"code":code,"input":input});setTimeout(function(){interpreter.terminate()},1E4)}setTimeout(function(){getOriginalCode();textbox.addEventListener("input",onTextboxChange);testbtn.addEventListener("click",onTestBtn);resetbtn.addEventListener("click",onResetBtn);setTextbox(getOriginalCode())},100);function interpret(code,input){window={};alert=function(s){stdout(s)};window.alert=alert;console.log=alert;prompt=function(s){if(input.length<1)stderr("not enough input");else{var nextInput=input[0];input=input.slice(1);return nextInput.toString()}};window.prompt=prompt;(function(){try{var evalResult=eval(code);if(typeof evalResult=="function"){var callResult=evalResult.apply(this,input);if(typeof callResult!="undefined")stdout(callResult)}}catch(e){stderr(e.message)}})()};</script>
```

# Answer
> 6 votes
## CJam, ~~21~~ 19 bytes

```
r{siGb_{(9%)}%_@#}g

```

Test it here.

### Explanation

A *very* rare case of negative modulo results being helpful. :)

```
r       e# Read input.
{       e# While the condition on top of the stack is truthy...
  s     e#   Convert to string. This is a no-op in the first iteration, but necessary
        e#   on subsequent iterations.
  i     e#   Convert to integer.
  Gb    e#   Get base-16 digits.
  _{    e#   Copy and map over the copy...
    (   e#   Decrement.
    9%  e#   Modulo 9. If the digit was originally in the range 0 to 9, it will remain
        e#   unchanged because -1 % 9 == -1. If the digit was in 10 to 15, it will become
        e#   0 to 5, respectively.
    )   e#   Increment. Undoes the decrement for unchanged digits and fixes the letter
        e#   digits because A corresponds to 1, not 0.
  }%
  _     e#   Duplicate result.
  @#    e#   Pull up original digits and try to find them in the array. This will be zero,
        e#   i.e. falsy, if they are equal and -1, i.e. truthy, if they are not.
}g

```

# Answer
> 4 votes
# Ruby, 35 + 1 = 36

With command-line flag `p`, run

```
$_='%x'%$_
redo if$_.tr!'a-f','1-6'

```

Explanation:

The -p flag creates a loop, storing the input and eventual output in the variable `$_`. `'%x'` does the hex conversion, and `tr!` does the digit substitution and returns a falsey value if there wasn't anything to change. redo starts over with the new `$_`.

# Answer
> 4 votes
# MATL, 23 ~~25~~ bytes

### Disclaimer

*While writing this answer I noticed a bug in MATL's `dec2base` function, corrected it, and released a new version with the correction (as well as a couple other accumulated, unrelated changes)*.

*Since I am using a version which is later than this challenge, according to consensus on Meta this answer is not eligible for winning*.

### Code

```
i`0:15YAt9X\t10ZQbb=~a]

```

### Example

```
>> matl i`0:15YAt9X\t10ZQbb=~a]
> 234589
958

```

### Explanation

```
i             % input number
`             % do...while
  0:15YA      % convert number to representation with base defined by symbols 0,...,15
  t9X\        % duplicate vector. Modulus 9 with 0 replaced by 9
  t10ZQ       % duplicate vector and convert to number using base 10
  bb=~a       % are second- and third-top stack elements different? (If so, next iteration)
]             % end

```

# Answer
> 4 votes
# Julia, ~~78~~ 74 bytes

```
f(x)=(h=hex(x);isdigit(h)?h:f(parse(replace(h,r"[a-z]",c->Int(c[1])-96))))

```

This is a recursive function that accepts an integer and returns a string.

Ungolfed:

```
function f(x::Integer)
    # Get the hexadecimal representation of x as a string
    h = hex(x)

    # Check whether all characters are digits
    if isdigit(h)
        # Return the hexadecimal representation of the input
        h
    else
        # Replace each letter with its position in the alphabet,
        # parse as an integer, and call f on the result
        f(parse(replace(h, r"[a-z]", c -> Int(c[1]) - 96)))
    end
end

```

# Answer
> 3 votes
# Dyalog APL, 37 36 33 bytes

```
{∧/9≥X←16⊥⍣¯1⊢⍵:10⊥X⋄∇10(⊣⊥|+≤)X}

```

Thanks to Adám and ngn for suggestions. I'm keeping `16⊥⍣¯1⊢⍵` instead of `⍵⊤⍨⍴⍨16` \- it's an extra byte, but allows us to operate on numbers of arbitrary size rather than 64-bit.

# Answer
> 2 votes
# Python, ~~118~~ 105 bytes

```
def f(n):h=hex(n)[2:];return h if h.isdigit()else f(int(''.join(map(lambda x:chr((ord(x)-47)%48+47),h))))

```

# Answer
> 2 votes
# PHP, ~~140~~ ~~126~~ ~~122~~ ~~114~~ ~~112~~ 87 or 84 bytes (including `-r`)

Not entirely sure about how the rules around this as this is my first codegolf attempt, but the code can be run with `php -r` without needing `<?` and `?>`

### Code

```
$b=readline();while($c!=$b)$b=preg_replace('/\D/e','ord($0)-96',$c=dechex($b));echo$c

```

### Formatted

```
$b=readline();
while($c!=$b){
  $b=preg_replace('/\D/e','ord($0)-96',$c=dechex($b));
}
echo "$b\n";

```

### Alternate Code (using argv instead of stdin)

```
for($b=$argv[1];$c!=$b;)$b=preg_replace('/\D/e','ord($0)-96',$c=dechex($b));echo$b

```

### Formatted

```
for($b=$argv[1];$c!=$b;) {
  $b=preg_replace('/\D/e','ord($0)-96',$c=dechex($b));
}
echo $b;

```

### Notes

Edit 1: I cut out a call to `intval()` to save 14 characters as PHP will happily treat numerical strings as numbers.
Edit 2: I removed `\n` from the output that I forgot to remove after testing, and removed quote marks from the final echo to save a total of 4 characters.
Edit 3: Removed the last call to `intval()`
Edit 4: Saved 2 bytes by removing quote marks from the regex line
Edit 5: Changed `[a-f]` to `\D` to save 3 characters, removed `strval` call from `preg_replace` for 8 more; added version that uses `argv[]` instead of STDIN, moved the loop terminator into the while statement(oops!) saving 11 more characters, and moved the dechex call into the `subject` part of `preg_replace` for another 3, making a total of 25; also added a non-stdin version as an alternate version that uses 3 less characters. Thanks for the help, @Blackhole

# Answer
> 2 votes
# , ~~106~~ ~~103~~ 102 bytes

-3 bytes by using `if` instead of `while`

-1 byte thanks to Giuseppe using `as.double` instead of `as.integer`

```
a=function(y){x=as.hexmode(as.double(y))
if(grepl("[a-f]",x)){x=chartr("a-f","1-6",x);return(a(x))};x}

```

Try it online!

Just add `a(your_integer_here)` to the TIO to see the result.

```
> a(234589)
[1] "958"
> a(435234)
[1] "1617"
> a(99999)
[1] "4908"

```

I used recursion to reapply the function to each successive iteration, on the condition that it doesn't find any of the letters 'abcdef' within the string, when this condition is False, it outputs the result as a string. The best part was my discovery of the `chartr` function, which allows me to swap elements with corresponding elements in a string. This string comes from the function coercing the hexadecimal into a string format.

Edit: I tried to use `sprint("%x",y)` instead of `as.hexmode(as.double(y))`, but I am still required to use `as.double` somewhere in the code, which was ~~2~~ 1 byte longer.

# Answer
> 2 votes
# 05AB1E, 12 bytes

```
h[Au₂L‡hÐþQ#

```

Try it online or verify all test cases.

**Explanation:**

```
h              # Convert the (implicit) integer-input to a hexadecimal string
               #  i.e. 234589 → "3945D"
 [             # Start an infinite loop:
  Au           #  Push the uppercase alphabet "ABC...XYZ"
    ₂L         #  Push a list in the range [1,26]
      ‡        #  Transliterate: replace all letters with the integers at the same index
               #   i.e. "3945D" → "39454"
               #   i.e. "239B" → "2392"
       h       #  Convert the integer to a hexadecimal string again
               #   i.e. "39454" → "9A1E"
               #   i.e. "2392" → "958"
        Ð      #  Triplicate it
         þ     #  Leave only the digits of the last copy
               #   i.e. "9A1E" → "91"
               #   i.e. "958" → "958"
          Q    #  Check if these digits and the hexadecimal string are equal
               #   i.e. "9A1E" and "91" → 0 (falsey)
               #   i.e. "958" and "958" → 1 (truthy)
           #   #  And if they are: stop the infinite loop
               # (and output the remaining copy from the triplicate implicitly as result)

```

`ÐþQ` could alternatively be `D.ï` (`D`: Duplicate; : is\_int?) for the same byte-count.

# Answer
> 2 votes
# C# (Visual C# Interactive Compiler), 92 bytes

```
n=>{var s=$"{n:x}";for(;(s=$"{s.Aggregate(0,(a,c)=>10*a+c%48):x}").Any(c=>c>57););return s;}

```

Try it online!

Less golfed code:

```
// anonymous function with
// input integer n
// output is a string
n=>{
  // 1) Convert the input to hexadecimal
  var s=$"{n:x}";
  for(;
    (s=$"{
      // 2) replace letters with their index in the alphabet
      s.Aggregate(0,(a,c)=>10*a+c%48)
      // 3) Convert the result back to hexadecimal
      :x}"
    // 4) If the result contains any letters, go to step 2
    ).Any(c=>c>57););
  // If not, output the result
  return s;
}

```

# Answer
> 1 votes
## Mathematica, 107 bytes

```
(b=FromDigits)@NestWhile[b[#/.Thread[10~Range~15->Range@6]]~a~16&,#~(a=IntegerDigits)~16,MemberQ[a_/;a>9]]&

```

Can't think of any more ways to golf this...

# Answer
> 1 votes
# Java, 201 bytes

```
String f(int a){String s=Long.toString(a,16);while(s.matches(".*[a-z].*")){char[]b=s.toCharArray();for(int i=0;i<b.length;i++)if(b[i]>96)b[i]-=48;s=Long.toString(new Long("".valueOf(b)),16);}return s;}

```

# Answer
> 1 votes
## Mathematica, 80 bytes

```
i=IntegerDigits;f=FromDigits;f[#~i~16//.l_/;Max@l>9:>f[If[#>9,#-9,#]&/@l]~i~16]&

```

This uses a neat trick for while-loops I learned from alephalpha. The `//.` is "apply this substitution rule as often as possible". Then we use a pattern, `l_/;Max@l>9` which only matches if the hexadecimal digit list still contains digits greater than 9.

# Answer
> 1 votes
# Japt, ~~45~~ 40 bytes

Based on my JS answer:

```
I=_nG -9}H=_=ZsG)f/\D/ ?H$($ÂZr"\\D"I):Z

```

Pretty pathetic for a golfing language, huh? There seems to be a lot of folks realizing during this challenge that their interpreters have bugs, and I am now included among them. This *should* be able to be done in 30 bytes or less, but a bug makes this impossible.

This creates a function `H` that can be called like so:

```
I=_nG -9}H=_=ZsG)f/\D/ ?H$($ÂZr"\\D"I):Z}
$H(234589)$

```

Alternatively, here is a full program, taking input from STDIN:

```
I=_nG -9}H=_=ZsG)f/\D/ ?H$($ÂZr"\\D"I):Z}H$(U

```

Try it online!

# Answer
> 1 votes
# GNU Sed (with eval extension), 44

```
:
y/ABCDEF/123456/
s/^/printf %X /e
/[A-F]/b

```

I wish `sed` would allow `y/A-F/1-6/`. But it doesn't.

# Answer
> 1 votes
# Python 3, ~~101~~ 89 bytes

Overall, this is quite similar to Boomerang's solution, but it takes a few different approaches to various aspects.

```
def d(n):n=hex(int(n))[2:];return n.isdigit()and n or d(str([ord(c)%12for c in n])[1::3])

```

This is the expanded version of my original code:

```
def d(n):
    n = int(n)                        # Interpret input as a decimal integer.
    n = hex(n)[2:]                    # Convert it to hex, stripping the '0x'.
    if n.isdigit():                   # If every character is a digit...
        return n                      # ...we're done.
    else:                             # Otherwise...
        n = ''.join(c if c < ':' else # ...don't change digits (':' is after
                    chr(ord(c - 48))  # '9'), but do change letters ('1' is 48
                    for c in n)       # characters before 'a').
        return d(n)                   # Then follow the process again.

```

11 bytes were shed thanks to @pacholik (replacing the innards of the `join` with a single operation that worked for both digits and letters). Another byte was trimmed by replacing the `join` with a string-slicing trick that hit me in a lightbulb moment (but which already exists in the Python golfing tips, albeit under a heading that specifies Python 2).

# Answer
> 1 votes
# Japt, 21 bytes

```
ìG
®+zA
eV ?U:ßVmuA ì

```

Try it online!

A significant improvement over the existing Japt answer. It doesn't handle the `153 -> 63` case proposed in a comment, but none of the other answers seem to either so I'll leave it unless the OP clarifies.

Output as a list of decimal digits, could be changed to outputting a decimal number for 1 byte

Explanation:

```
ìG               #Get a list of base-16 digits, each as a base-10 number
                    e.g. 234589 -> [3,9,4,5,13]

®+zA             #Increment the numbers greater than 10
                    e.g. [3,9,4,5,13] -> [3,9,4,5,14]

eV ?             #If the second step didn't change any digit:
    U            # Output the digits from step 1
     :           #Otherwise
      ß          # Repeat the program with new input:
       V         #  The result of step 2
        muA      #  With each digit modulo 10
            ì    #  Treated as a base-10 number

```

# Answer
> 1 votes
# APL(NARS) 104 chars, 208 bytes

```
f←{k←10⊥{⍵≤9:⍵⋄1+10∣⍵}¨q←{(16⍴⍨⌊1+16⍟⍵)⊤⍵}⍵⋄9≥⌈/q:k,0⋄k,1}
t←{⍵≤0:0⋄0=2⊃v←f⍵:↑f↑v⋄{k←f⍵⋄0=2⊃k:↑k⋄∇↑k}⍵}

```

test:

```
  t 153
63
  t 0
0
  t 234589
958
  t 435234
1617
  t ¯123
0

```

I don't know if it is ok... Possible it is not enough for the standard quality answer...

# Answer
> 0 votes
## Seriously, 42 bytes

```
1╤╝4ª╗,$1WX╛@¿╜@¡;`╜@¿;)╛;(\(+%$`Mεj;)=YWX

```

Hex Dump:

```
31d1bc34a6bb2c24315758be40a8bd40ad3b60bd40
a83b29be3b285c282b2524604dee6a3b293d595758

```

Try it online

There has to be a shorter way than this, but this is what I got... (This is where I find myself wishing `W` actually popped, since it's shorter to put a `;` right before the last one when you DON'T want it to than to put an `X` after EACH `W`. Here, having `W` pop instead of peek would save three bytes.)

# Answer
> 0 votes
# Japt, 18 bytes

```
Æ=ìG ®%9ª9Ãì)sGÃæÑ

```

Try it

# Answer
> 0 votes
# PHP, 71 bytes

```
while($n++<2|$b-$a=&$argn)$a=strtr($b=dechex($a),abcdef,123456);echo$a;

```

Run as pipe with `-nR` or try it online.

Yields a warning for some inputs in PHP 7.1 and later; replace `-` with `!=` to fix.
Yields another warning in PHP 7.2; put `abcdef` in quotes to fix.

---
Tags: code-golf, math, number, base-conversion, hexadecimal
---


title: i love yOu i lOve you i love yOu!

text:
# Question
Title: i love yOu i lOve you i love yOu!
XKCD #99, with the title "Binary Heart" shows a simple image of ones and zeros, with some digits colored red.

The red heart is visible to the naked eye, but the message hidden in the binary sequence is not. If you remove all the spaces and newlines and interpret the binary sequence as 8 bit ASCII-code, you'll end up with the message:

```
iloveyOuilOveyouiloveyOuilOveyOuiloveyouilOveyouilOveyOuilOv

```

**Cute right?**

Pssst... The string isn't a pure string repetition.

---

Your challenge is to create this binary image with 21 digits across, and 23 digits down. **There should be exactly one space between each digit in each row, and one newline for each new row.** Note that the last bits are only the beginning of the letter `e`, since `21*23` isn't divisible by 8. You need those bits correct too.

The function or program should not take any input. Leading and trailing spaces and newlines are accepted.

The result of your code should look like this:

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

```

This is code golf, so the shortest answer (in bytes) wins.

---

## Leaderboard

```
var QUESTION_ID=94699,OVERRIDE_USER=31516;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
# Jelly, ~~36~~ ~~33~~ 32 bytes

```
“ḅUɗaṚPXṙ’Bṁ484¬“½:J⁺ȤṾ‘Ḥ¤¦Ḋs21G

```

*Thanks to @JonathanAllan for golfing off 3 bytes!*

Try it online!

### How it works

The main link

```
“ḅUɗaṚPXṙ’Bṁ484¬“½:J⁺ȤṾ‘Ḥ¤¦Ḋs21G

```

is executed niladically (i.e., without any arguments) when the program is run. Its return value will be printed implicitly.

```
“ḅUɗaṚPXṙ’

```

find the indices of the quoted characters in Jelly's code page and interprets them as digits of a bijective base 250 number. This yields the integer **13021639057551959994**.

```
          B

```

converts the generated integer to binary. This yields the bit array **1011010010110110001001111011101100110010101111001010011110111010** which corresponds to the UTF-8 encoding of the string **ilOveyOu**, shifted one bit to the left.

Shifting is necessary because `B` cannot return a bit array with a leading **0**. Other options include negating the binary digits or computing the square in reverse, but this approach saves one byte.

```
            ṁ484

```

molds the generated array like the range from **1** to **484**, i.e., it repeats the contents of the array as many times as necessary to achieve a length of **484**.

This is one more bit than we need, to account for the shift. We could remove the first bit now, but doing so later means that all bits that have to get swapped lie at even indices, which allows us to save the aforementioned byte.

```
                 “½:J⁺ȤṾ‘Ḥ¤

```

takes the code points of the characters between  and  (**\[10, 58, 74, 138, 154, 186\]**), then "unhalves" them, i.e., multiples them by **2** (**\[20, 116, 148, 276, 308, 372\]**).

```
                ¬           ¦

```

conditionally negates the bits at those indices. This corresponds to the **O/o** variations in the original pattern.

Finally,

```
                             Ḋs21G

```

dequeues the bit array (removing the first bit), splits the remaining array into rows of **21** elements and prints the resulting matrix as a grid.
> 21 votes

# Answer
# Jelly, ~~41 40 35~~ 33 bytes

Thanks to @Dennis for making the end `ṖṖCG`! (complement `C` = `1-x` in place of logical not `¬` )

```
“ƝƓỊ⁹Ȥ⁶Ị⁺‘ẋ8_“¤ÐŒ#'/‘¦32BFs21ṖṖCG

```

**TryItOnline**

### How?

```
“ƝƓỊ⁹Ȥ⁶Ị⁺‘ẋ8_“¤ÐŒ#'/‘¦32BFs21ṖṖCG - Main link: no arguments
“ƝƓỊ⁹Ȥ⁶Ị⁺‘                        - code page indexes [150,147,176,137,154,134,176,138]
                                        (bitwise negated values of ordinals of "ilOveyOu")
          ẋ8                      - repeat eight times
            _                     - subtract
                     ¦            - apply to indexes
             “¤ÐŒ#'/‘             - code page indexes [3,15,19,35,39,47]
                                        (the indexes of the lowercase Os)
                      32          - literal 32 (subtracting 32 from the bitwise negated
                                                'O's makes them bitwise negated 'o's)
                        B         - binary (all are 8 bits, hence the negation)
                         F        - flatten list
                          s21     - split into slices of length 21
                             ṖṖ   - pop (remove the last two slices)
                               C  - complement (transform the bits to what they should be)
                                G - format as a grid
                                        (inserts both the spaces and line feeds)

```

---

### "Colour" version, 77 bytes

```
“¤Ɓ¥J¬ ¥ƲėNėR½5ðḃḍCṬ’b19‘“Y^‘jĖŒṙḂ
“ƝƓỊ⁹Ȥ⁶Ị⁺‘ẋ8_“¤ÐŒ#'/‘¦32BFż¢Ḅị“¹0°1”s21ṖṖG

```

**TryItOnline**

Jelly has no colour output, but this is much easier for me to see anyway (I am colour blind)...

```
° ¹ ¹ ° ¹ ° ° ¹ ° ¹ ¹ ° ¹ ¹ ° ° ° ¹ ¹ ° ¹
¹ ¹ ¹ ° ¹ ¹ ¹ ° ¹ ¹ ° ° ¹ ¹ ° ° ¹ ° ¹ ° ¹
¹ ¹ ¹ ° ° ¹ ° ¹ ° ° ¹ ¹ ¹ ¹ ° ¹ ¹ ¹ ° ¹ °
¹ ° ¹ ¹ ° ¹ ° ° ¹ ° ¹ ¹ ° ¹ ¹ ° ° ° ¹ ° °
¹ ¹ ¹ ¹ ° 1 1 1 ° ¹ ¹ ° ° 1 1 0 ° ¹ ° ¹ °
¹ ¹ ¹ 1 0 0 1 0 1 1 ° 1 1 1 1 0 1 1 ¹ ° ¹
° ¹ ° 1 1 0 1 0 0 1 ° 1 1 0 1 1 0 0 ° ¹ ¹
° ¹ ¹ 1 1 0 1 1 1 0 1 1 0 0 1 1 0 0 1 ° ¹
° ¹ 1 1 1 0 0 1 0 1 0 0 1 1 1 1 0 1 1 ¹ °
¹ ° 1 0 1 1 0 1 0 0 1 0 1 1 0 1 1 0 0 ° ¹
° ° ¹ 1 1 1 0 1 1 1 0 1 1 0 0 1 1 0 0 ¹ °
¹ ° ¹ 1 1 1 0 0 1 0 1 0 0 1 1 1 1 0 ¹ ¹ ¹
° ¹ ° ¹ 0 1 1 0 1 0 0 1 0 1 1 0 ¹ ¹ ° ° °
¹ ¹ ° ¹ ¹ 1 1 0 1 1 1 0 1 1 0 0 ¹ ¹ ° ° ¹
° ¹ ° ¹ ¹ ¹ 1 0 0 1 0 1 1 0 1 ¹ ¹ ¹ ° ¹ ¹
¹ ° ¹ ° ¹ ° ¹ 1 0 1 0 0 1 0 ¹ ¹ ° ¹ ¹ ° °
° ¹ ° ° ¹ ¹ ¹ ¹ 0 1 1 1 0 ¹ ¹ ° ° ¹ ¹ ° °
¹ ° ¹ ° ¹ ¹ ¹ ¹ ° 0 1 0 ¹ ¹ ° ¹ ¹ ¹ ¹ ° ¹
¹ ¹ ° ¹ ° ¹ ° ¹ ¹ ° 1 ° ° ¹ ° ¹ ¹ ° ¹ ¹ °
° ° ¹ ° ° ¹ ¹ ¹ ¹ ° ¹ ¹ ¹ ° ¹ ¹ ° ° ¹ ¹ °
° ¹ ° ¹ ° ¹ ¹ ¹ ¹ ° ° ¹ ° ¹ ° ° ¹ ¹ ¹ ¹ °
¹ ¹ ¹ ° ¹ ° ¹ ° ¹ ¹ ° ¹ ° ° ¹ ° ¹ ¹ ° ¹ ¹
° ° ° ¹ ° ° ¹ ¹ ¹ ¹ ° ¹ ¹ ¹ ° ¹ ¹ ° ° ¹ ¹

```

### How?

```
“¤Ɓ¥J¬ ¥ƲėNėR½5ðḃḍCṬ’b19‘“Y^‘jĖŒṙḂ - Link 1: no arguments
“¤Ɓ¥J¬ ¥ƲėNėR½5ðḃḍCṬ’              - base 250 of a big number
                     b19           - convert to base 19, yields a list of integers
                        ‘          - increment those numbers
                         “Y^‘      - get code page indexes [89,94]
                             j     - join: [89,3,5,3,8, ... ,3,19,1,94]
                                         - {left-right, top-bottom} runs of colours
                              Ė    - enumerate [[1,89],[2,3],[3,5],[4,3],[5,8], ...]
                               Œṙ  - run-length decode [89 1s, 3 2s, 5 3s, 3 4s, 8 5s, ...]
                                 Ḃ - mod 2

“ƝƓỊ⁹Ȥ⁶Ị⁺‘ẋ8_“¤ÐŒ#'/‘¦32BFż¢Ḅị“¹0°1”s21ṖṖG - Main link: no arguments
“ƝƓỊ⁹Ȥ⁶Ị⁺‘ẋ8_“¤ÐŒ#'/‘¦32BF                 - same as the original to get 1s and 0s
                          ż                - zip with
                           ¢               - last link (1) as a nilad
                            Ḅ              - binary to integer (vectorises)
                             ị             - index into
                              “¹0°1”       - string "¹0°1"
                                    s21    - split into length 21 slices
                                       ṖṖ  - pop last two unused slices
                                         G - format as a grid

```
> 42 votes

# Answer
## Actually, 58 bytes

```
73*8╙:13542├`≈"÷≥"E`M"«%s₧ªn%s6û"7*%"♠n≥6û"+¿├`' +`M╪♂Σ♂Ri

```

Try it online!

### Explanation

There are three main parts here, so I'm going to break it down accordingly.

**Part 1: Constructing the base-256 string**

We're actually going to construct the binary string reversed, to take advantage of Actually's stack-based (LIFO) structure and to avoid complications with leading zeros in the binary string. Thus, the target binary string is `110011011101111001000110110100101101010111011110010100111101010011001101110111100100011011010010110101011101111011010011110101001100110111011110010001101101001011010101110111101101001111010100110011011101111011000110110100101101010111011110010100111101010011001101110111100100011011010010110101011101111001010011110101001100110111011110110001101101001011010101110111101101001111010100110011011101111001000110110100101101010111011110010100111101010011001101110111101100011011010010110`, which is equivalent to `20083405242288679348048842451418880256193335738939042905519679590571514414673488599852759703515507690399267425671627412178904636115120346432419478` in decimal. In base-256 (using the CP437 character table for conversion), the corresponding string is `♠n≥6û«≥₧ªn≥6û«÷₧ªn≥6û«÷₧ªn÷6û«≥₧ªn≥6û«≥₧ªn÷6û«÷₧ªn≥6û«≥₧ªn÷6û`. To construct the original binary string, we construct the base-256 string (taking advantage of the pattern in it), and perform base conversions to decimal and binary.

The base-256 string has the following format (spaces and newlines added for clarity):

```
♠n≥6û
« (either ≥ or ÷) ₧ªn (either ≥ or ÷) 6û
  (7 times)

```

Thus, each of the 7 middle sections can be formed by using the scaffold `«%s₧ªn%s6û` and replacing the `%s` parts with either  or `÷`.

The specific sequence of s and `÷`s we need is `≥≥÷≥÷÷≥≥≥÷÷≥≥÷`. Since we need this as a list of length-1 strings, the naïve way of representing this would be `"≥≥÷≥÷÷≥≥≥÷÷≥≥÷"#` (push the string, make it into a list). However, we can do slightly better. By interpreting that string as a binary number (where  represents `1` and `÷` represents `0`), we get `13542` in decimal. By converting this back to binary (using the traditional `1`s and `0`s), and indexing into a length-2 string, we can get the list using one less byte than the naïve method.

```
:13542├`≈"÷≥"E`M"«%s₧ªn%s6û"7*%"♠n≥6û"+
:13542├                                  push 13542, convert to binary
       `≈"÷≥"E`M                         for each bit:
        ≈                                  convert to integer (from string)
         "÷≥"E                             index into "÷≥"
                "«%s₧ªn%s6û"7*           push the scaffold for the middle section
                              %          old-style Python string formatting to fill in the scaffold
                               "♠n≥6û"+  prepend the beginning piece

```

**Part 2: Converting to binary**

This part is much more straightforward. If Actually had the capability to directly convert base-256 to binary, we'd use that. Unfortunately, it doesn't, so we'll have to use decimal as an intermediary format.

The `,` in the following code represents the code from Part 1 - for explanatory purposes, I've replaced the Part 1 code with `,` to read the output from Part 1 from STDIN. It is not part of the actual final code.

```
8╙,¿├
  ,    Part 1 result
8╙ ¿   convert from base-256 to decimal
    ├  convert to binary

```

**Part 3: Formatting**

If the challenge was to merely output the binary string as-is, we'd be done. However, we still have some formatting to do to get the binary string into a 21 x 23 rectangle.

As in Part 2, the `,` represents the output from the previous part, and is not part of the actual code.

```
73*,`' +`M╪♂Σ♂Ri
   ,              output from Part 2
    `' o`M        insert a space after every character
73*       ╪       chunk into 21 pieces
           ♂Σ     concatenate each piece
             ♂R   reverse each piece
               i  flatten
                  (implicitly print)

```

---

For those keeping track at home, this is the equivalent Python 3 code (481 bytes):

```
print('\n'.join([''.join(' '+c for c in bin(sum('\x00☺☻♥♦♣♠•◘○◙♂♀♪♫☼►◄↕‼¶§▬↨↑↓→←∟↔▲▼ !"#$%&\'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz{|}~⌂ÇüéâäàåçêëèïîìÄÅÉæÆôöòûùÿÖÜ¢£¥₧ƒáíóúñÑªº¿⌐¬½¼¡«»░▒▓│┤╡╢╖╕╣║╗╝╜╛┐└┴┬├─┼╞╟╚╔╩╦╠═╬╧╨╤╥╙╘╒╓╫╪┘┌█▄▌▐▀αßΓπΣσµτΦΘΩδ∞φε∩≡±≥≤⌠⌡÷≈°∙·√ⁿ²■\xa0'.index(c)*256**i for i,c in enumerate(("♠n≥6û"+("«%s₧ªn%s6û"*7)%tuple("÷≥"[int(b)]for b in bin(13542)[2:]))[::-1])))[2:])[i*42:-~i*42][::-1]for i in range(23)][::-1]))

```
> 41 votes

# Answer
## JavaScript (ES6), ~~169~~ ... ~~136~~ 135 bytes

```
let f =

_=>"0213021203131214".replace(x=/./g,v=>0+[a=1768714102,a-8192,a-=66265089,a+8192,3][v].toString(2)).replace(x,(c,i)=>`
`[+!(i%21)]+c)

console.log(f());
```

*Saved 2 bytes thanks to Andrakis*
*Saved 4 bytes thanks to Hedi*
*Saved ~~3~~ 5 bytes thanks to Neil*

## Colored version, 249 bytes (237 bytes of JS + 12 bytes of CSS)

The JS code outputs the ASCII art with bold tags for the heart. 12 bytes of CSS are required to colorize in red. (Is that byte count fair?)

```
let f =

_=>"0213021203131214".replace(x=/./g,v=>0+[a=1768714102,a-8192,a-=66265089,a+8192,3][v].toString(2)).replace(x,(c,i)=>`
`[+!(y=i/21|0,x=i%21)]+([57568,a=261112,a,b=524280,b+4,b+4,b,a+1024,65520][y-4]&1<<x|y>12&x>y-9&x<29-y?c.bold():c))

document.getElementById("o").innerHTML = f();
```

```
b{color:red}
```

```
<pre id="o"></pre>
```
> 22 votes

# Answer
# 05AB1E, ~~77~~ ~~54~~ ~~53~~ ~~44~~ ~~43~~ 41 bytes

Uses CP-1252 encoding.

```
’i„Î€î’8×•1žä¿*•S·£™J¦'iìÇb0ìJ011JSðý42ô»

```

**Explanation**

```
’i„Î€î’   # the string "iloveyou"
8×        # repeated 8 times
•1žä¿*•   # the number 3262264221 encoded in base 214
S·        # split to list and multiplied by 2, gives [6, 4, 12, 4, 4, 12, 8, 4, 4, 2]
£         # split the "iloveyou..." string into chunks of these lengths
™J        # title-case the chunks and join, giving the string with capitalized O's
¦'iì      # replace the faulty capitalized "I" in the beginning with a lower case "i"
Ç         # convert to list of ascii values
b0ì       # convert each to binary and prepend a 0 to each binary string
J011J     # join the strings and append "011"
Sðý       # add a space between each digit
42ô       # split in pieces of 42 (21 digits, 21 spaces)
»         # merge on newline

```

Try it online!
> 20 votes

# Answer
## CJam, 48 bytes

```
19560Yb"Oo"f="uilvey"8*3/.\s:i2fb0a*7>21/W<Sf*N*

```

Collaboration with @MartinEnder, who took off a tricky 3 bytes with the `"uilvey"3/` string. Online interpreter.

```
19560Yb        Convert 19560 to base 2
"Oo"f=         Index each bit into the string "Oo" to give "ooooOOooOOOooOoOOO"
"uilvey"8*3/   Repeat the string "uilvey" 8 times then split into chunks of 3
.\s            Vectorised swap (insert the Os into the right places) then stringify
:i2fb          Convert each char to int then take base 2
0a*            Join with 0s
7>             Remove the first 7 bits
21/            Split into chunks of length 21
W<             Drop the last row
Sf*            Join each row with spaces
N*             Join the rows with newlines

```
> 15 votes

# Answer
# Javascript ES6 REPL, ~~124~~ ~~121~~ ~~119~~ 113 bytes

Saved 6 bytes thanks to *@ETHproductions*

This is a full program which can be pasted in the REPL/console to produce the correct result.

```
for(i=r='';i<483;)r+=(`il${"Oo"[21>>i/64&1]}vey${"oO"[77>>i/64&1]}u`.charCodeAt(i/8%8)>>7-i%8&1)+(++i%21?` `:`
`)

```

```
f=

_=>{for(i=0,r='';i<483;)r+=(`il${"Oo"[21>>(a=i/64)&1]}vey${"oO"[77>>a&1]}u`.charCodeAt(i/8%8)>>7-i%8&1)+(++i%21==0?`
`:` `);return r}

a.innerHTML = f()
```

```
<pre id=a>
```

More verbose

```
for (i=0, r='';                         // r == the result
     i < 483;)                          // 483 == 21 * 23
r+= (                                   // construct "iloveyou"
        `il${                           // il
            "Oo"[21 >> (a = i/64) & 1]  // position in the loop defines the o or O
         }vey${                         // vey
            "oO"[77 >> a & 1]           // position in the loop defines the o or O
         }u`                            // u
        .charCodeAt(                    // "i" == 105 == 01101001
            i / 8 % 8                   // find the correct bit to append
        ) >> 7-i%8 & 1                  // shift it to select 1 or 0
    )
+                                       // add a space or newline
    (
        ++i%21 == 0 ? `
` : ` `                                 // every 21 characters add a new line,
                                           otherwise a space
    )
;                                       // Javascript implicitly returns the last value
                                           edited in a for loop

```

# Coloured JavaScript only heart, 281 bytes

```
for(i=z=r='',h=[],g=[90,...[...'353871767176G4H4H5G5F7CABB9D7F5H3J1'].map(n=>parseInt(n,20)),-1];i<483;)r+=`%c`+(`il${"Oo"[21>>i/64&1]}vey${"oO"[77>>i/64&1]}u`.charCodeAt(i/8%8,--g[+z]||z++,h[i]=z%2)>>7-i%8&1)+(++i%21?` `:`
`);console.log(r,...h.map(H=>`color:${H?'red':'black'}`))

```

This works by switching colours every *n* bits and makes use of the console.log ability to log colours

# Coloured CSS Heart, 229+12 bytes

If using css is allowed, the coloured heart can be reduced even further to 229 bytes of JavaScript code and 12 bytes of CSS

```
for(i=z=r='',g=[90,...[...'353871767176G4H4H5G5F7CABB9D7F5H3J1'].map(n=>parseInt(n,20)),-1];C=`il${"Oo"[21>>i/64&1]}vey${"oO"[77>>i/64&1]}u`.charCodeAt(i/8%8,--g[+z]||z++)>>7-i%8&1,i++<483;)r+=(z%2?(''+C).bold():C)+(i%21?` `:`
`)

```

```
let f =

    _=>{for(i=z=r='',g=[90,...[...'353871767176G4H4H5G5F7CABB9D7F5H3J1'].map(n=>parseInt(n,20)),-1];C=`il${"Oo"[21>>i/64&1]}vey${"oO"[77>>i/64&1]}u`.charCodeAt(i/8%8,--g[+z]||z++)>>7-i%8&1,i++<483;)r+=(z%2?(''+C).bold():C)+(i%21?` `:`
`);return r}

document.getElementById("b").innerHTML = f();
```

```
b{color:red}
```

```
<pre id="b">
```
> 12 votes

# Answer
# MATL, ~~56~~ 55 bytes

```
'!?u<TgGU*lB7SE1q3s.?Su(q6)iM'F'eilovyOu'Za8&B!FTTv21e!

```

**Try it Online**

**Explanation**

```
'!?u<TgGU*lB7SE1q3s.?Su(q6)iM'      % Previously compressed version of the string
F'eilovyOu'Za                       % Decompress this string
8&B                                 % Convert each char to 8-bit binary number
!                                   % Transpose the result
FTTv                                % Append [0 1 1] to the end to take care of
                                    % the partial "e" bits
21e!                                % Reshape it into the appropriate shape
                                    % Implicitly display the result

```
> 9 votes

# Answer
## PowerShell v2+, (UTF-16) 300 bytes

*Corrected erroneous byte count thanks to @Mego*

```
'ږƍ໬ƕ๓ƺ֥˄ϝӊ༭ǝ֥ţϝɥޔǮ૒ƱϝĲ˲ӷʴ˘ͻ֙ץŻ઴Ŭɻˌʼֽ͖ҶɻŦʼʞݖɛĽƳ'-split'(..)'-ne''|%{(-join($_[0,1]|%{[convert]::ToString(+$_,2)})).PadLeft(21,'0')-replace'(.)','$1 '}

```

Not the shortest, but a different approach. I manually took each line and sliced them into pairs each (roughly) 9-11 significant bits in length. Converted each of those binary values to a `char` (Note: PowerShell uses UTF-16 by default, not UTF-8), and mushed that into a string. That's the `'...'` at the beginning.

We then `-split` that into strings of length 2, and loop through each pair. Those pairs are split into a `char`-array via `$_[0,1]`, and each of those are cast as an int `+$_`, and `[convert]`ed into a binary (`,2`) `String`. That's `-join`ed together into a single string, then `PadLeft`'d to get the proper length, then each element is `-replace`d with itself and a space `'$1 '`.

Those strings are all left on the pipeline, and output is implicit, with the default `Write-Output` sticking a newline between elements.

```
PS C:\Tools\Scripts\golfing> 'ږƍ໬ƕ๓ƺ֥˄ϝӊ༭ǝ֥ţϝɥޔǮ૒ƱϝĲ˲ӷʴ˘ͻ֙ץŻ઴Ŭɻˌʼֽ͖ҶɻŦʼʞݖɛĽƳ'-split'(..)'-ne''|%{(-join($_[0,1]|%{[convert]::ToString(+$_,2)})).PadLeft(21,'0')-replace'(.)','$1 '}
0 1 1 0 1 0 0 1 0 1 1 0 1 1 0 0 0 1 1 0 1
1 1 1 0 1 1 1 0 1 1 0 0 1 1 0 0 1 0 1 0 1
1 1 1 0 0 1 0 1 0 0 1 1 1 1 0 1 1 1 0 1 0
1 0 1 1 0 1 0 0 1 0 1 1 0 1 1 0 0 0 1 0 0
1 1 1 1 0 1 1 1 0 1 1 0 0 1 1 0 0 1 0 1 0
1 1 1 1 0 0 1 0 1 1 0 1 1 1 1 0 1 1 1 0 1
0 1 0 1 1 0 1 0 0 1 0 1 1 0 1 1 0 0 0 1 1
0 1 1 1 1 0 1 1 1 0 1 1 0 0 1 1 0 0 1 0 1
0 1 1 1 1 0 0 1 0 1 0 0 1 1 1 1 0 1 1 1 0
1 0 1 0 1 1 0 1 0 0 1 0 1 1 0 1 1 0 0 0 1
0 0 1 1 1 1 0 1 1 1 0 1 1 0 0 1 1 0 0 1 0
1 0 1 1 1 1 0 0 1 0 1 0 0 1 1 1 1 0 1 1 1
0 1 0 1 0 1 1 0 1 0 0 1 0 1 1 0 1 1 0 0 0
1 1 0 1 1 1 1 0 1 1 1 0 1 1 0 0 1 1 0 0 1
0 1 0 1 1 1 1 0 0 1 0 1 1 0 1 1 1 1 0 1 1
1 0 1 0 1 0 1 1 0 1 0 0 1 0 1 1 0 1 1 0 0
0 1 0 0 1 1 1 1 0 1 1 1 0 1 1 0 0 1 1 0 0
1 0 1 0 1 1 1 1 0 0 1 0 1 1 0 1 1 1 1 0 1
1 1 0 1 0 1 0 1 1 0 1 0 0 1 0 1 1 0 1 1 0
0 0 1 0 0 1 1 1 1 0 1 1 1 0 1 1 0 0 1 1 0
0 1 0 1 0 1 1 1 1 0 0 1 0 1 0 0 1 1 1 1 0
1 1 1 0 1 0 1 0 1 1 0 1 0 0 1 0 1 1 0 1 1
0 0 0 1 0 0 1 1 1 1 0 1 1 1 0 1 1 0 0 1 1

```
> 9 votes

# Answer
# ///, 237 bytes

```
/2/\/\///3/0 24/1 25/0
26/1
27/4428/3329/772A/432B/A732C/937A782D/B48B72E/8A4892F/98B93/373A3A737837367A7A7878AA674E37A45D83A5C78A45F7A63D83463C78A639E3745AD8368C7845A9E3763AD8573C7863AF46AAD35348C735AAF673AD5848C753AA9E57AAB48B468348C41

```

Try it online!
> 6 votes

# Answer
# Python 3, ~~147~~ 144 bytes

```
lambda i=0:exec("print(' '.join(''.join('0'+bin(ord(chr(j+30)in' ,0@DL'and'o'or c))[2:]for j,c in enumerate('ilOveyOu'*8))[i:i+21]));i+=21;"*23)

```

Test it at **ideone**

Initialises `i` to `0` in the function declaration, then repeats this 23 times:
makes the whole binary string without spaces (see below);
slices a row from within using `[i:i+21]`;
inserts the spaces with `' '.join(...)`;
prints; and
increments `i` by 21 with `i+=21`

To make the whole binary string:
it repeats `"ilOveyOu"` eight times;
replaces `O` with `o` where necessary (at indexes `[2,14,18,34,38,46]`);
\- - - this is achieved with `chr(j+30)in' ,0@DL'` to save 3 bytes
converts each char to it's ordinal;
casts each ordinal to a binary string (`'0bxxxxxxx'`);
removes the leading `'0b'` from each using `[2:]`;
prepends each with a `'0'`; and
joins the whole thing up with `''.join(...)`
> 4 votes

# Answer
# Powershell, 110 bytes

```
'uil','vey'*8|%{$s+=$_+'oOOooOOOooOoOOO'[$i++]}
-join(8..490|%{(+$s[$_-shr3]-shr(7-$_%8))%2
'
'[!(++$j%21)]})

```

Explanation:

The first line of the script takes the substrings and inserts a letter `O` between them. The result is the string `uiloveyOuilOveyouiloveyOuilOveyOuiloveyouilOveyouilOveyOuilOvey`. Note that the first and last characters are redundant.

The loop outputs all the necessary `(8..490)` bits from the characters of the string, as well as a space or a line feed.

## The riddle of the recipient of the valentine letter

It can be seen that small and large symbol `O` themselves make up the bit encoding. There are 15 symbols (bits). There is only one partition on the bits to get ASCII characters: `oOOooOOO`+`ooOoOOO[o]`. We had to add a small `o` instead of `0` at the end. This ASCII symbols are: `g.`

Who is this mysterious `g.`?
> 4 votes

# Answer
# PHP+HTML+CSS, 173 Bytes Colored 367 Bytes

CLI only PHP 173 Bytes

```
$o=2841;for($i=0;$i<16;)$t.=il.Oo[$o>>$i++&1].vey.Oo[$o>>$i++&1].u;foreach(str_split($t)as$c)$x.="0".decbin(ord($c));for($i=0;$i<504;$i++){$i%21?:print"\n";echo$x[$i]." ";}}

```

conform to the bounty spec content type text/html

```
<?=gzinflate(base64_decode("jVNbDoIwELwKJ9Ctn9hwF9HGmFQwiB+GeHcRd7ezvDQEAmWmMzuT+nv7jKG4dddDc75UOW124foqu0OM+aO6h3Z/rGPd5E04vfz2C/a3gjLXXzTcxG/pSem7xzr4hxhn2BZLZvfpDjRg/3FBjBWuL78fflsWAOVl0uWk8rmG3yDCMNnMLMsshHpq0jLVQLKj6RrIbHBCYoq6WclPHHJ+PNdqjEZlpLNgbaTy2xoTHAQ3kBasKZyg3/XUDAVV5urVcDE5mQXsGWugIJqikibVmcZTJIrL0Bq3NKdgjxhak2q5ukmpWuXS+QJPEBVi52vE025VJy7Yw18u3g==");

```

`b{all:unset;color:red}` instead of `b{all:unset;color:#911;background:red}` in the first version

PHP+HTML+CSS, 392 Bytes

heart red +black which looks more pretty

Maybe call the color number in the CSS Part

```
<?=gzinflate(base64_decode("jVTLDoIwELyb+A8m3nXrzdrwL7xijAgG8GAI/67WdpktD00DoWWmMztLMU37LPLo3t3i+nwpNe0O+a1Purgo9KNs8vaUVkVV6+1RqVMSp9dzXT3KTNd51pv9l7xemXtEG/UeZC9yT8OdhrlFK3iLKCX4IZqEwngPcuh/vBCjPd8k34nZJxGA3TLxMip9hgWAkAP67cTyUBOhJluVXDYxWIKsBWgyRE9jEntayNL75CxdfYuRBkqB1ozBkdJvg46iRIiWNmOQCSQ6vpygIEmlqYZz1LAN1AQmhUFQUfBBhjVzbWE1SFIbNOi6NqUSHkI06JvtmjlqMzR37gSCMxEboicbG/wVpPbICzv5y8sL"));

```

add this before it looks nicer

```
<style>*{word-spacing:1em;}</style>

```

## Output first version it is the ugliest HTML Code in my live

red-black heart

```
<style>*{word-spacing:1em;}</style><style>p{margin:0.2em}b{all:unset;color:#911;background:red}</style>
<p>0 1 1 0 1 0 0 1 0 1 1 0 1 1 0 0 0 1 1 0 1
<p>1 1 1 0 1 1 1 0 1 1 0 0 1 1 0 0 1 0 1 0 1
<p>1 1 1 0 0 1 0 1 0 0 1 1 1 1 0 1 1 1 0 1 0
<p>1 0 1 1 0 1 0 0 1 0 1 1 0 1 1 0 0 0 1 0 0
<p>1 1 1 1 0 <b>1 1 1</b> 0 1 1 0 0 <b>1 1 0</b> 0 1 0 1 0
<p>1 1 1 <b>1 0 0 1 0 1 1</b> 0 <b>1 1 1 1 0 1 1</b> 1 0 1
<p>0 1 0 <b>1 1 0 1 0 0 1</b> 0 <b>1 1 0 1 1 0 0</b> 0 1 1
<p>0 1 1 <b>1 1 0 1 1 1 0 1 1 0 0 1 1 0 0 1</b> 0 1
<p>0 1 <b>1 1 1 0 0 1 0 1 0 0 1 1 1 1 0 1 1</b> 1 0
<p>1 0 <b>1 0 1 1 0 1 0 0 1 0 1 1 0 1 1 0 0</b> 0 1
<p>0 0 1 <b>1 1 1 0 1 1 1 0 1 1 0 0 1 1 0 0</b> 1 0
<p>1 0 1 <b>1 1 1 0 0 1 0 1 0 0 1 1 1 1 0</b> 1 1 1
<p>0 1 0 1 <b>0 1 1 0 1 0 0 1 0 1 1 0</b> 1 1 0 0 0
<p>1 1 0 1 1 <b>1 1 0 1 1 1 0 1 1 0 0</b> 1 1 0 0 1
<p>0 1 0 1 1 1 <b>1 0 0 1 0 1 1 0 1</b> 1 1 1 0 1 1
<p>1 0 1 0 1 0 1 <b>1 0 1 0 0 1 0</b> 1 1 0 1 1 0 0
<p>0 1 0 0 1 1 1 1 <b>0 1 1 1 0</b> 1 1 0 0 1 1 0 0
<p>1 0 1 0 1 1 1 1 0 <b>0 1 0</b> 1 1 0 1 1 1 1 0 1
<p>1 1 0 1 0 1 0 1 1 0 <b>1</b> 0 0 1 0 1 1 0 1 1 0
<p>0 0 1 0 0 1 1 1 1 0 1 1 1 0 1 1 0 0 1 1 0
<p>0 1 0 1 0 1 1 1 1 0 0 1 0 1 0 0 1 1 1 1 0
<p>1 1 1 0 1 0 1 0 1 1 0 1 0 0 1 0 1 1 0 1 1
<p>0 0 0 1 0 0 1 1 1 1 0 1 1 1 0 1 1 0 0 1 1

```

```
    <style>p{margin:0.2em}b{all:unset;color:red}</style>
    <p>0 1 1 0 1 0 0 1 0 1 1 0 1 1 0 0 0 1 1 0 1
    <p>1 1 1 0 1 1 1 0 1 1 0 0 1 1 0 0 1 0 1 0 1
    <p>1 1 1 0 0 1 0 1 0 0 1 1 1 1 0 1 1 1 0 1 0
    <p>1 0 1 1 0 1 0 0 1 0 1 1 0 1 1 0 0 0 1 0 0
    <p>1 1 1 1 0 <b>1 1 1</b> 0 1 1 0 0 <b>1 1 0</b> 0 1 0 1 0
    <p>1 1 1 <b>1 0 0 1 0 1 1</b> 0 <b>1 1 1 1 0 1 1</b> 1 0 1
    <p>0 1 0 <b>1 1 0 1 0 0 1</b> 0 <b>1 1 0 1 1 0 0</b> 0 1 1
    <p>0 1 1 <b>1 1 0 1 1 1 0 1 1 0 0 1 1 0 0 1</b> 0 1
    <p>0 1 <b>1 1 1 0 0 1 0 1 0 0 1 1 1 1 0 1 1</b> 1 0
    <p>1 0 <b>1 0 1 1 0 1 0 0 1 0 1 1 0 1 1 0 0</b> 0 1
    <p>0 0 1 <b>1 1 1 0 1 1 1 0 1 1 0 0 1 1 0 0</b> 1 0
    <p>1 0 1 <b>1 1 1 0 0 1 0 1 0 0 1 1 1 1 0</b> 1 1 1
    <p>0 1 0 1 <b>0 1 1 0 1 0 0 1 0 1 1 0</b> 1 1 0 0 0
    <p>1 1 0 1 1 <b>1 1 0 1 1 1 0 1 1 0 0</b> 1 1 0 0 1
    <p>0 1 0 1 1 1 <b>1 0 0 1 0 1 1 0 1</b> 1 1 1 0 1 1
    <p>1 0 1 0 1 0 1 <b>1 0 1 0 0 1 0</b> 1 1 0 1 1 0 0
    <p>0 1 0 0 1 1 1 1 <b>0 1 1 1 0</b> 1 1 0 0 1 1 0 0
    <p>1 0 1 0 1 1 1 1 0 <b>0 1 0</b> 1 1 0 1 1 1 1 0 1
    <p>1 1 0 1 0 1 0 1 1 0 <b>1</b> 0 0 1 0 1 1 0 1 1 0
    <p>0 0 1 0 0 1 1 1 1 0 1 1 1 0 1 1 0 0 1 1 0
    <p>0 1 0 1 0 1 1 1 1 0 0 1 0 1 0 0 1 1 1 1 0
    <p>1 1 1 0 1 0 1 0 1 1 0 1 0 0 1 0 1 1 0 1 1
    <p>0 0 0 1 0 0 1 1 1 1 0 1 1 1 0 1 1 0 0 1 1
```

375 Bytes for create the HTML Page with PHP directly

```
<?$o=2841;for(;$i<16;)$t.=il.Oo[$o>>$i++&1].vey.Oo[$o>>$i++&1].u;foreach(str_split($t)as$c)$x.="0".decbin(ord($c));$a=[1,9,20,28,41,49,62,82,103,125,146,168,190,212,234,256,278,300];$z=[3,11,26,34,47,55,77,98,119,140,160,179,200,220,240,260,280,300];for($i=0;$i<483;$i++)echo $i%21?"":"<p>",in_array($i-88,$a)?"<b style=color:red>":"",$x[$i],in_array($i-88,$z)?"</b>":""," ";

```
> 3 votes

# Answer
# q/kdb+, ~~107~~ ~~93~~ ~~85~~ ~~55~~ 53 bytes

**Solution:**

```
23 21#0 1(,/)0b vs'@[61#"ilOveyOu";0x020e1222262e;_:]

```

**Example:**

```
q)23 21#0 1(,/)0b vs'@[61#"ilOveyOu";0x020e1222262e;_:]
0 1 1 0 1 0 0 1 0 1 1 0 1 1 0 0 0 1 1 0 1
1 1 1 0 1 1 1 0 1 1 0 0 1 1 0 0 1 0 1 0 1
1 1 1 0 0 1 0 1 0 0 1 1 1 1 0 1 1 1 0 1 0
1 0 1 1 0 1 0 0 1 0 1 1 0 1 1 0 0 0 1 0 0
1 1 1 1 0 1 1 1 0 1 1 0 0 1 1 0 0 1 0 1 0
1 1 1 1 0 0 1 0 1 1 0 1 1 1 1 0 1 1 1 0 1
0 1 0 1 1 0 1 0 0 1 0 1 1 0 1 1 0 0 0 1 1
0 1 1 1 1 0 1 1 1 0 1 1 0 0 1 1 0 0 1 0 1
0 1 1 1 1 0 0 1 0 1 0 0 1 1 1 1 0 1 1 1 0
1 0 1 0 1 1 0 1 0 0 1 0 1 1 0 1 1 0 0 0 1
0 0 1 1 1 1 0 1 1 1 0 1 1 0 0 1 1 0 0 1 0
1 0 1 1 1 1 0 0 1 0 1 0 0 1 1 1 1 0 1 1 1
0 1 0 1 0 1 1 0 1 0 0 1 0 1 1 0 1 1 0 0 0
1 1 0 1 1 1 1 0 1 1 1 0 1 1 0 0 1 1 0 0 1
0 1 0 1 1 1 1 0 0 1 0 1 1 0 1 1 1 1 0 1 1
1 0 1 0 1 0 1 1 0 1 0 0 1 0 1 1 0 1 1 0 0
0 1 0 0 1 1 1 1 0 1 1 1 0 1 1 0 0 1 1 0 0
1 0 1 0 1 1 1 1 0 0 1 0 1 1 0 1 1 1 1 0 1
1 1 0 1 0 1 0 1 1 0 1 0 0 1 0 1 1 0 1 1 0
0 0 1 0 0 1 1 1 1 0 1 1 1 0 1 1 0 0 1 1 0
0 1 0 1 0 1 1 1 1 0 0 1 0 1 0 0 1 1 1 1 0
1 1 1 0 1 0 1 0 1 1 0 1 0 0 1 0 1 1 0 1 1
0 0 0 1 0 0 1 1 1 1 0 1 1 1 0 1 1 0 0 1 1

```

**Explanation:**

```
23 21#0 1(,/)0b vs'@[61#"ilOveyOu";0x020e1222262e;_:] / the solution
                   @[             ;              ;  ] / apply[input;indices;function]
                                                  _:  / lowercase
                                   0x020e1222262e     / 2 14 18 34 38 46 represented in hex
                    61#"ilOveyOu"                     / 61 take "ilOveyOu" (wraps around)
             0b vs'                                   / convert into 8-bit representation
         (,/)                                         / flatten
      0 1                                             / index into 0 / 1 (convert from booleans)
23 21#                                                / reshape

```

**Notes:**

* -2 bytes thanks to ngn!
> 3 votes

# Answer
# C (gcc), 102 bytes

```
f(i){for(i=0;i<483;)printf("\n%2d"+!!(i++%21),(i/8%4^2|35609>>i/32&1?"iloveyou"[i/8%8]:79)>>7-i%8&1);}

```

# Rundown

```
f(i){
for(i=0;i<483;)         Loop through bits.
printf("\n%2d"
+!!(i++%21),            Decide if newline in format string should be skipped.
(i/8%4^2|               Are we at a non-'o' letter?
                        (They occur every 4th letter, starting at index 2.)
35609>>i/32&1?          Check with magic number if the 'o' should be capital.
"iloveyou"[i/8%8]:      If not-'o' or not capital, use current letter.
79)                     Otherwise, use the letter 'O'.
>>7-i%8&1               Extract bit to write.
);}

```

Try it online!
> 3 votes

# Answer
# PHP, 121 bytes

```
for($n=5682;$i++<60;)for($b=8;$b;)$p.=(1&ord(~$i&3||($n/=2)&1?uiloveyo[$i%8]:O)>>--$b)." ";echo wordwrap($p."0 1 1",42);

```

**breakdown**

```
$n=2*bindec("000101100011001"); // where to NOT replace o with O
for($i=1;$i<61;$i++)            // loop $i from 1 to 60
{
    $c=
        ~$i&3                       // $i%4!=3
        ||
        ($n/=2)&1                   // or (1. shift $n, 2. test bit 0)
        ? "uiloveyo"[$i%8]          // yes: character from string
        : "O"                       // no: uppercase "O"
    ;
    for($b=8;$b--;)                 // run from bit 7 to bit 0
        $p.=(1 & ord($c)>>$b). " ";     // append 1 or 0 plus space
}
$p.="0 1 1";                    // append the missing three bits
echo wordwrap($p,42);           // wrap at column 42 (actually 41; 42 is space -> gets cut)

```
> 2 votes

# Answer
# K (oK), ~~50~~ 48 bytes

**Solution:**

```
23 21#,/(8#2)\'@[61#"ilOveyOu";0x020e1222262e;_]

```

Try it online!

**Explanation:**

Port of my Q/KDB+ solution.

**Notes:**

* -2 bytes thanks to ngn!
> 2 votes

# Answer
# Python 3, 199 Bytes:

```
z='01111011101'
a='011010010110110001'
b=z+'10011001010111100101'
[print(' '.join(''.join([a+i[0]+b+i[1]+z+'01'for i in'10 01 10 00 11 01 00'.split()])+a+'0'+b[:16])[i:i+41])for i in range(0,966,42)]

```
> 1 votes

# Answer
# Python 3, 170 bytes

```
from textwrap import*
print('\n'.join(' '.join(list(i))for i in wrap(''.join(bin(ord(i)+256)[3:]for i in (7*"il%svey%su")%(tuple("oOOooOOOooOoOO"))+"ilOv"),21))+" 0 1 1")

```

makes a string repetition of "Il%svey%su", repeats it the required number of times, then uses a tuple to sub all the o's in. it then converts it to binary, uses the textwrap module, converts each item of the new list to list, joins with space, then appends 0 1 1 because that seems to be a stub or something
> 1 votes

# Answer
# Mathematica, 123 bytes (275 with color)

I'm not sure if using `Grid` instead of outputting a string is OK (if not then this is a non-competing entry).

### B/W

```
Grid@Partition[ReplacePart[PadLeft[{},483,IntegerDigits[36^^nz4sp78k5qyb,2,64]],
Thread[51+32{0,1,4,5,6,9,11,12,13}->0]],21]

```

### Color

```
Grid[Partition[ReplacePart[PadLeft[{},483,IntegerDigits[36^^nz4sp78k5qyb,2,64]],
Thread[51+32{0,1,4,5,6,9,11,12,13}->0]],21],ItemStyle->{{},{},Thread[Join@@MapIndexed[
Thread@{Range@@#,2+First@#2}&,Thread[Partition[IntegerDigits[36^^k32b741shmsoiwed4vnakt],
17]+{0,10}]]->Red]}]

```
> 1 votes

# Answer
# Ruby 142 Bytes

```
(('iloveyOuilOveyouiloveyOuilOveyOuiloveyouilOveyouilOveyOuilOv'.unpack('B*')[0]+'011').split(/(.{21})/)-['']).map{|i|puts(i.chars.join(' '))}

```

(Slightly more) legibly:

```
(('iloveyOuilOveyouiloveyOuilOveyOuiloveyouilOveyouilOveyOuilOv'.unpack('B*')[0]+'011')
  # unpack turns it into a binary string, [0] takes the first element, and then we add on the trailing 011
.split(/(.{21})/) -[''])
  # split it every group of 21 characters and remove the empty strings that are also included
.map { |i| puts(i.chars.join(' ')) }
  # take each string of 21 characters, get its chars and join them with an empty string for formatting (puts takes care of the newlines)

```

I have not yet found a way to condense the original text into a more succinct form in Ruby - it has some great String manipulation functions, but all of the ways I've tried use more characters than the string itself. Any pointers appreciated, this is my first Code Golf on StackOverflow!
> 1 votes

# Answer
# Rust, 195 bytes

```
||for(c,i)in"iloveyOuilOveyouiloveyOuilOveyOuiloveyouilOveyouilOveyOuilOve".bytes().fold(String::new(),|a,c|format!("{}0{:b}",a,c)).chars().zip(1..484){print!("{}{}",c,if i%21!=0{' '}else{'\n'})}

```

Ungolfed:

```
fn main(){
    // convert bytes of the string to binary numerals.
    let s = "iloveyOuilOveyouiloveyOuilOveyOuiloveyouilOveyouilOveyOuilOve"
        .bytes()
        .fold(String::new(),|a,c|format!("{}0{:b}",a,c));

    // print them over the range with newlines/spaces as appropriate
    for(c,i) in s.chars().zip(1..484) {
        print!("{}{}",c,if i%21!=0{' '}else{'\n'})
    }
}

```
> 1 votes

# Answer
# Pyth, 47 bytes

```
jPcjdsm+0.BCdtPs.i*8c"uil vey"dmr\o!djC\䱨2 42

```

Try it online here.

```
jPcjdsm+0.BCdtPs.i*8c"uil vey"dmr\o!djC\䱨2 42   Implicit: d=" "
                    c"uil vey"d                  Chop "uil vey" on spaces, to yield ["uil" "vey"]
                  *8                             Repeat the above 8 times - {1}
                                      C\䱨       Character code of 䱨, yields 19560
                                     j    2      Convert the above to base 2
                               m                 Map the digits of the above, as d, using:
                                r\o!d            If d is 0, yield "O", otherwise "o" - {2}
                .i                               Interleave {1} with {2}
               s                                 Concatenate into a string
                                                   This yields "uiloveyOuilOveyouiloveyOuilOveyOuiloveyouilOveyouilOveyOuilOvey"
             tP                                  Remove first and last characters of the above
      m                                          Map each character, as d, using:
           Cd                                      Get character code
         .B                                        Convert to binary string
       +0                                          Prepend 0 (all binary strings will be length 7, so this pads to length 8)
     s                                           Flatten the result of the map
   jd                                            Join on spaces
  c                                        42    Chop into strings of length 42
 P                                               Discard the last, partial, string
j                                                Join on newlines, implicit print

```
> 1 votes

# Answer
# ///, 220 bytes

```
/H/2E//G/CBDCC//F/ABC2C//E/AC//D/2B//C/A2//A/33//B/32//2/0 //3/1 /2G22C3
ABFDB3
ABDBHABB
BG2D2
EFDB
EDCEAB3
DG22A
HFD3
HDBHAB
BBG223
2HFD
BEDBHA3
DBG22
CEF23
DEDCEA
BBBG2
DHF2
BBEDCE3
CBBG
2DHF
DBEDBH
ABBBCBDCA
22DHABC2A

```

Try it online!
> 0 votes

# Answer
### C++11, Non-competing, ~~726~~ ~~687~~ 636 bytes (\*NIX or W10 threshold 2 required)

```
#include <iostream>
#include <string>
#ifdef  _WIN32
#include <Windows.h>
#endif
using namespace std;int main() {
#ifdef  _WIN32
HANDLE h=GetStdHandle(-11);DWORD m;GetConsoleMode(h,&m);SetConsoleMode(h,m|0x04);
#endif
cout<<"\033[47m\033[30m";string d("4fup8y8hihjyl9g1ifh9wpc4f52l5a8giosim2isj80xff814db9wmf958x4zlbl58x4zlbl6zxgjt9whbcz4mu91r0j5c4kfq48uxw53w1zvpdshv6ylrnl3t38qyiteyw0lphs3kx59vf4ezay145thrt7lkb80w83nz10ih27f77p0820wzr9");for(int s=0;s!=184;s+=8){unsigned long long n=stoull(d.substr(s,8),NULL,36),i=3;for(int p=40;p!=-2;p-=2){int r=(n&(i<<p))>>p;printf(r>1?"\033[31m %d\033[30m":" %d",r>1?r-2:r);}puts("");}return 0;}

```

I know this can be golfed way better. I want to see a short c++ answer damnit!

I also probably made a few mistakes when I was encoding the heart section.

Output (colors fixed):
> 0 votes

# Answer
# Python, 473 bytes

### Colored!

```
r=str.replace;print r(r(r(r(r(r(r(r("""
jh0k1k1k0jk1
ikik1kjk0h1
ik0hjikih
k1h0k1k1k00k0
i1ksi1ejk0s1ke0h
i1sk0kie0si1kiek1
0ks1hje0s1k1k0ej1
j1s1kik1kjkjej
jsik0hjikiek
ksk1h0k1k1k0ej
0jsikik1kjk0ek
k1sik0hjikei1
0k1sjh0k1ke1k00
1kis1kik1k0e1kj
0ki1sk0k1k1eiki
hk1sh0ke1k1k0
0kji1sj1ke1kjk0
hi1ks0ke1ki1k1
1hk1ks1e00k1k1k
00kjikik1kjk
0hi1k0hjik
ihk1h0k1ki
000kjikik1kj1
""",'h','1010'),'i','11'),'j','01'),'k','10'),'1','1 '),'0','0 '),'s','\x1b[0;40;31m'),'e','\x1b[0m')

```
> 0 votes

# Answer
## FEU, 360 bytes

```
m/a/0 1 /b/1 0 /c/1 1 /d/0 0 /e/0 /f/1 /g
__DATA__
afaeaafabeab1
cfacababaae1
cbaaeacfaca0
fafaeaafabeae0
ccacababaa0
cfbaafacfafb1
aafaeaafabea1
acfacababae1
acbaaeacfac0
faafaeaafabd1
eacfacababa0
facbaaeacfaf1
aaafaeaafabe0
cacfacababe1
aacbaafacfa1
faaafaeaafab0
aeacfacabab0
faacbaafacb1
caaafaeaafaf0
eaeacfacabaf0
aaacbaaeacf0
cfaaafaeaafa1
daeacfacaba1

```

Just stupid compression
> 0 votes

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


title: Determine the "Luck" of a string

text:
# Question
Title: Determine the "Luck" of a string
Given a string, return that string's "luck".

A string's luck, as I completely just made up for the purpose of this challenge, is an integer, determined as so:

* The base luck for a string is 1.
* For each consecutive letter it shares with the word "lucky" (case insensitive), multiply the luck by 2. For instance, if your string was "**lu**mberjack" or "sma**ck**" you'd multiply by 4. (More specifically, 2^number of consecutive characters shared.)
    + The shared letters have to be in the same consecutive order it appears in "lucky" but can start anywhere in the word for the same value ("luc" has the same 8\* multiplier as "cky").
    + If the word has multiple occurrences where it shares consecutive characters with lucky, use the longest consecutive string of the characters.
* For ANY letter it shares with the word "omen" subtract 2 from the luck.
    + It can match a character any amount of times, in any order. For instance the string "nnnnnomemenn" loses 24 luck (12 matching letters)

Example:

```
luck("lucky")
>>32

```

2^5 (5 consecutive letters) = 32

```
luck("firetruck")
>>6

```

2^3 - 2 (3 consecutive letters from *uck*, *e* shared with omen)

```
luck("memes")
>>-7

```

1 - 8 (base amount, 4 shared with "omen")

This is code golf, so the answer with the fewest bytes wins.

You can input and output any way you'd like - write a function, use standard input, etc.

For functions, assume whatever data type would make sense for that language. (For example, in JavaScript, you'd be passed a `String` and return a `Number`)

Edit: You can assume any input is lowercase.

# Answer
> 7 votes
## 05AB1E, ~~36~~ ~~32~~ ~~28~~ 26 bytes

```
Œv'¸éyåiyˆ}}¯é¤go¹'ƒÖ¦Ãg·-

```

**Explanation**

```
Œv         }                  # for each substring of input
  '¸éyåi  }                   # if substring is part of "lucky"
        yˆ                    # add it to global array
            ¯é¤               # get the longest such substring
               go             # raise 2 to its length
                 ¹'ƒÖ¦Ã       # remove all chars from input that isn't in "omen"
                       g·     # get length and multiply by 2
                         -    # subtract
                              # implicitly display

```

Try it online

Saved 2 bytes thanks to Adnan

# Answer
> 7 votes
## JavaScript (ES7), ~~123~~ ~~112~~ 107 bytes

```
s=>2**[5,4,3,2,1,0].find((i,_,a)=>a.some(j=>s.includes("luckyL".substr(j,i))))-2*~-s.split(/[omen]/).length

```

Edit: Saved 11 bytes thanks to @Titus by assuming that the letter `L` does not appear in the input. Saved 5 bytes thanks to @Oriol. ES6 version for ~~125~~ ~~114~~ 109 bytes:

```
f=
s=>(1<<[5,4,3,2,1,0].find((i,_,a)=>a.some(j=>s.includes("luckyL".substr(j,i)))))-2*~-s.split(/[omen]/).length
;
```

```
<input oninput=o.textContent=f(this.value)><pre id=o></pre>
```

# Answer
> 6 votes
# Ruby, ~~91~~ 87 bytes

`String#count`'s finnicky usage strikes again! (When passed a String, it counts all occurrences of each letter in the function argument instead of all occurrences of the entire string.)

Try it online

```
->s{2**(z=0..5).max_by{|j|z.map{|i|s[b="lucky"[i,j]]?b.size: 0}.max}-2*s.count("omen")}

```

A version that takes in lines from STDIN and prints them: 89 bytes (86 +3 from the `-n` flag)

```
p 2**(z=0..5).max_by{|j|z.map{|i|$_[b="lucky"[i,j]]?b.size: 0}.max}-2*$_.count("omen")

```

# Answer
> 6 votes
# Pyth, ~~27~~ ~~26~~ 28 bytes

```
-^2le+k}#"lucky".:Q)yl@"omen

```

1 byte saved thanks to OP :-)

Explanation:

```
                                 Implicit Q as input
                .:Q              Find all substrings of input
     +k}#"lucky"                 Filter for substring of "lucky", prepend "" in case of []
    e                            Take last element, which is longest
   l                             Get its length
 ^2                              Raise two to that
                      @"omen"Q   Filter Q for characters in "omen"
                     l           Get length; counts how many characters in "omen" there are
                    y            Double that
-                                Find the difference

```

Test it here.

# Answer
> 4 votes
## Ruby: 100 bytes

```
->s{2**(m=0;4.times{|j|1.upto(5){|i|m=[i,m].max if s.match"lucky"[j,i]}};m)-s.scan(/[omen]/).size*2}

```

# Answer
> 3 votes
# Javascript - 206 Bytes

```
r=>{var a="lucky";r:for(var e=5;e>0;e--)for(var n=0;6>n+e;n++){var o=a.substring(n,e+n);if(r.includes(o))break r}for(var t=0,e=0;e<r.length;e++)('omen'.indexOf(r[e])+1)&&t++;return Math.pow(2,o.length)-2*t}

```

# Answer
> 3 votes
# Haskell, 99

Another approach... I just learned about function aliasing

```
import Data.List
s=subsequences
i=intersect
l=length
f n=2^(l$last$i(s"lucky")$s n)-2*l(i n$"omen")

```

### Usage

```
f"lucky"
32

f"firetruck"
6

f"memes"
-7

```

# Answer
> 3 votes
# Ruby, 57 bytes

```
b=gets.count'omen'
$.+=1while/[lucky]{#$.}/
p 2**$./2-2*b

```

`gets` sets `$.` to 1 as a side effect, then we increment it until the regular expression matching `$.` consecutive lucky characters no longer matches.

# Answer
> 2 votes
# Mathematica, 86 bytes

Code:

```
2^StringLength@LongestCommonSubsequence[#,"lucky"]-2StringCount[#,{"o","m","e","n"}]&

```

Explanation:

`LongestCommonSubsequence` returns the longest contiguous substring common to the input and `"lucky"`. `StringLength` gives its length. `StringCount` counts the number of occurrences of the characters of `"omen"` in the input.

# Answer
> 2 votes
## Python (139 Bytes)

```
import itertools as t
s=input()
print 2**max([j-i for i,j in t.combinations(range(6),2)if'lucky'[i:j]in s]+[0])-2*sum(_ in'omen'for _ in s)

```

# Answer
> 1 votes
# Python 3, ~~168~~ ~~157~~ ~~152~~ ~~139~~ ~~144~~ 136 bytes

EDIT: Really obvious things I should have seen easier have been changed, and some slightly less obvious.

Edit 2: stoopid (˚n˚). The program threw errors. I fixed it up. not actually 153 :(

Thanks to Leaky Nun for saving 5 bytes, and to jmilloy for saving ~~13~~ 8 bytes.

```
s=input()
p=q=k=len(s)
m=0
while-~p:
 while-~q:m=(m,q-p)[(s[p:q]in"lucky")*q-p>m];q-=1
 p-=1;q=k
print(2**m-2*sum(i in"omen"for i in s))

```

The program runs through all possibly possible substrings in input (possibly possible, because it computes impossible substrings as well, 8 to 7, for example), checks if the substring is in "lucky", then sets the exponent of 2 to the length of the substring should it be greater than the current value. Possibly could be improved by using only one while loop. Could possibly use some improvement; I'm still getting the hang of this.

# Answer
> 1 votes
# TSQL, 233 bytes

**Golfed:**

```
DECLARE @t varchar(99)='oluck'

,@z INT=0,@a INT=0,@ INT=1,@c INT=0WHILE @a<LEN(@t)SELECT
@a+=IIF(@=1,1,0),@z=IIF('LUCKY'LIKE'%'+x+'%'and @>@z,@,@z),@c+=IIF(x
IN('O','M','E','N'),2,0),@=IIF(@+@a-1=LEN(@t),1,@+1)FROM(SELECT
SUBSTRING(@t,@a,@)x)x PRINT POWER(2,@z)-@c

```

**Ungolfed:**

```
DECLARE @t varchar(99)='oluck'

,@z INT=0
,@a INT=0
,@  INT=1
,@c INT=0
WHILE @a<LEN(@t)
  SELECT
    @a+=IIF(@=1,1,0),
    @z=IIF('LUCKY'LIKE'%'+x+'%'and @>@z,@,@z),
    @c+=IIF(x IN('O','M','E','N'),2,0),
    @=IIF(@+@a-1=LEN(@t),1,@+1)
    FROM(SELECT SUBSTRING(@t,@a,@)x)x
PRINT POWER(2,@z)-@c

```

Try it online

# Answer
> 1 votes
# PHP program, ~~139~~ 135 ~~108~~ bytes

quantum leap fails for multiple substrings where the first occurence is shorter. :(

actually I could save another 7 bytes in PHP\<5.4 with register\_globals on

```
<?for($s=$argv[1];$i<5;$i++)for($j=6;--$j;)$r=max($r,strstr($s,substr('lucky*',$i,$j))?2**$j:1);echo$r-2*preg_match_all('/[omen]/',$s);

```

usage: `php -d error_reporting=0 <filename> <string>`

+5 for a function:

```
function f($s){for(;$i<5;$i++)for($j=6;--$j;)$r=max($r,strstr($s,substr('lucky*',$i,$j))?2**$j:1);return$r-2*preg_match_all('/[omen]/',$s);}

```

**tests** (on the function)

```
echo '<table border=1><tr><th>input</th><th>output</th><th>expected</th><th>ok?</th></tr>';
foreach([
    'lumberjack'=>0,        'smack'=>2,
    'nnnnnomemenn'=>-23,    'lucky'=>32,
    'omen'=>-7,             'firetruck'=>6,
    'memes'=>-7,            'determine the “luck” of a string'=>0,
    'amazing'=>-3,          'wicked'=>2,
    'chucky'=>16,           'uckyuke'=>14,
    'ugly'=>2,              'lucy'=>8,
    'lukelucky'=>30
] as $x=>$e){
    $y=f($x);
    echo"$h<tr><td>",$x,'</td><td>',$y,'</td><td>',$e,'</td><td>',$e==$y?'Y':'N',"</td></tr>";
}echo '</table>';

```

# Answer
> 1 votes
# Haskell (134 132 Bytes)

```
import Data.List
c[]=[]
c s@(_:x)=inits s++c x
l=length
g q=2^(maximum$map(\z->l q-l(q\\z))$c"lucky")-2*(l$intersect q"omen")

```

Not a code golfer nor a Haskell programmer, so would love some tips on this one.

(Example: `g "firetruck"`)

# Answer
> 1 votes
# Scala, 155 bytes

```
def f(w:String)=(1::List.fill((for(a<-1 to 5;s<-"lucky".sliding(a))yield if(w.contains(s)) a else 0).max){2}).product-2*w.filter("omen".contains(_)).length

```

# Answer
> 1 votes
# C# (Visual C# Interactive Compiler) with flag `/u:System.Text.RegularExpressions.Regex`, 99 bytes

```
n=>(1<<Matches(n,"l?u?c?k?y?").OrderBy(x=>x.Value).Last().Length)-n.Count(x=>"omen".Any(c=>c==x))*2

```

Try it online!

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


title: Blunt the Images

text:
# Question
Title: Blunt the Images
## Introduction

Sharp edges are, frankly, just plain dangerous so, given a PNG as input, blur the image using the method described below and blunt those damned sharp edges.

## Method

To get the RGB value of each pixel, use the following three equations:

$$R = \sqrt{\frac{1.5\times\sum^n\_{a=1}R^2\_a}{n}}$$ $$G = \sqrt{\frac{1.5\times\sum^n\_{a=1}G^2\_a}{n}}$$ $$B = \sqrt{\frac{1.5\times\sum^n\_{a=1}B^2\_a}{n}}$$

Where \\$\sum^n\_{a=1}R^2\_a\\$ is the sum of the red values of each of the adjacent pixels squared. The value of \\$n\\$ is the number of adjacent pixels (e.g., a corner pixel will have an \\$n\\$ value of 3, whilst a pixel around the center of the image will have an \\$n\\$ value of 8).

An adjacent pixel is a pixel which is 1 pixel away from the original pixel in all directions (left, right, up, down and on all of the diagonals).

For example, in the following 3 x 1 image:

The blurred RGB value of the middle pixel will be:

$$R = \sqrt{\frac{1.5\*(0^2+0^2)}{2}} = 0$$ $$G = \sqrt{\frac{1.5\*(0^2+255^2)}{2}} = 220.836 = 221$$ $$B = \sqrt{\frac{1.5\*(255^2+0^2)}{2}} = 220.836 = 221$$

where any decimal outputs are rounded to the nearest unit. You should not simply floor the result.

Therefore, the middle pixel will be the colour (0, 221, 221), or:

Resulting in the image:

You should repeat this process for every pixel in the image. (Note that you do this with the original pixels and not the modified pixels. Basically, **you shouldn't overwrite the original image, and should keep it completely separate from the new, blurred image**).

If you calculate any values to be greater than 255, assume that its value is 255 (I.e., a value of 374 would be set to 255).

The resulting output should be a separate PNG image (you may name this whatever you wish).

## Examples

### Super Mario

**Original:**

**Blurred:**

### Checkerboard

**Original:**

**Blurred:**

### Crisps

**Original**

**Blurred**

Not so crisp anymore

### American Gothic

**Original:**

**Blurred:**

To see the blur on larger images, it's best to run the program again on the blurred image:

## Challenge

The shortest code to blur a given PNG image wins.

You can use image processing libraries (such as PIL) but you must not use built-in blurring functions (Mathematica, I'm looking at you).

## Note

As @orlp says below:

> For the record, (to my knowledge) this is not a standard blurring method. This challenge is not an educational resource.

# Answer
# Python, ~~354~~ 313 bytes

Not the best, but hey...

Using Space for 1st level indentation, Tab for 2nd level, then Tab+Space and Tab+Tab

```
import Image as I
A=I.open(raw_input())
w,h=A.size
B=I.new('RGB',(w,h))
s=[-1,1,0]
r=range
for x in r(w):
 for y in r(h):
    P=[]
    for d in s:
     for e in s:
        try:P+=[A.load()[x+e,y+d]]
        except:0
    P.pop()
    B.load()[x,y]=tuple(min(int(.5+(1.5*sum([v*v for v in t])/len(P))**.5),255)for t in zip(*P))
B.save("b.jpg")

```
* Edit1: replacing `math.sqrt()` with `()**.5` thanks to beta decay
* Edit2: using `min` for clamping (saving a lot!) and `0` for `pass` thanks to Loovjo
* Edit3: `+=[]` for `.append()` saving 5 bytes
* Edit4: using the variable `s` for the stencil
> 5 votes

# Answer
# MATLAB, 130 bytes

Takes an image as an input and saves the output as `b.png`.

```
i=double(input(''));m=ones(3);m(5)=0;k=@(x)imfilter(x,m);imwrite(uint8(round((1.5*k(double(i.^2))./k(i(:,:,1)*0+1)).^.5)),'b.png')

```
> 0 votes

---
Tags: code-golf, image-processing
---