title: Tribute to Stan Lee

text:
# Question
Title: Tribute to Stan Lee
Unfortunately one of the greatest comic book writers passed away yesterday afternoon. Lots of Hollywood stars, musicians, actors, and many other people are paying tribute to this awesome writer, so we must do something as well.

**Challenge**

Print The Avengers Logo

Note: You may use any other character in place of # other than a space character; while you must use a space character for the space

In ASCII-art

```
              ######
      ###############
    #####    ##########
  ####       ####### ####
 ###        #### ###   ###
###         #### ###    ###
###        ####  ###    ###
###        ####  ###    ###
###       ####   ###    ###
###       ####   ###    ###
###      ###########    ###
###      ###########    ###
###     ####     ###    ###
###     ###      ###    ###
 ####  ####           ####
  ########         ######
      #################
      ###

```

**Optional**

Who was (in your opinion) his greatest hero and villain in the entire marvel universe?

---

Standard rules apply

# Answer
> 26 votes
# Jelly, ~~62~~ ~~59~~ 58 bytes

```
“ḢE{ɠs{Ƒ0Ṇṁỵ8ỊṢṂƊeLṫfIWẈḞ'ʠJ£ṗɱ\çoȧ?ƒnØẆƥṂ⁷ɱ’b12ĖŒṙḂa⁶s27Y

```

*Thanks to @JonathanAllan for golfing off 1 byte!*

Try it online!

### How it works

```
“ḢE{ɠs{Ƒ0Ṇṁỵ8ỊṢṂƊeLṫfIWẈḞ'ʠJ£ṗɱ\çoȧ?ƒnØẆƥṂ⁷ɱ’

```

is a bijective base-250 integer literal, which uses the characters in Jelly's code page as digits.

The literal encodes the integer \\$\scriptsize 10250938842396786963034911279002199266186481794751691439873548591280332406943905758890346943197901909163\\$, which `b12` converts to duodecimal, yielding \\$\scriptsize 30b620b40ba54a64771433841333139413468423468423467433467433466b466b465453465363431424b43896860ba3\_{12}\\$.

There are some zeroes, because 14 spaces (e.g.) are encoded as 3 spaces, 0 hashes, and 11 spaces. This maintains the base small (the largest run consists of 17 hashes), without adding any additional logic to the decoder.

`Ė` (enumerate) prefixes every base-12 digit by its 1-based index, then `Œṙ` performs run-length decoding.

Now, for each integer in the resulting array,  extracts the least significant bit, then `a⁶` (AND space) replaces ones with spaces, while leaving zeroes unchanged.

Finally, `s27` splits the unformatted character array into chunks of length 27, which `Y` separates by linefeeds.

# Answer
> 18 votes
# , ~~198~~, ~~173~~, ~~163~~, ~~157~~, ~~144~~, 142 bytes

```
write(rep(rep(c(' ',4),44),utf8ToInt("NFMOJEDJFDGGADCCHDACCCACIDACDFHDBCDFHDBCDFGDCCDFGDCCDFFKDFFKDFEDECDFECFCDCADBDKDCHIFHQJC")-64),1,27,,'')

```

Try it online!

Also `R` honors to the great Stan.

**Notes :**

* instead of the character `#` we've used the character `4` because saves 2 bytes and :
    + it's a reference to the Fantastic Four and/or the next Avengers 4 movie
    + it's like we're repeating the logo inside the logo (since `4` seems a mini "slanted" `A`)
* -15 bytes thanks to @Giuseppe

**Explanation** :

Applying a Run Length Encoding (`rle` function) on the characters of the string (excluding `'\n'`) returns 88 repetitions of the alternating `<space>,<hash>,<space>,<hash>,<space>,<hash>...`.

The 88 repetitions are all values in the range `[1,17]` hence, summing `64` we get the code points of the letters `[A...Q]` obtaining the string : `"NFMOJEDJFDGGADCCHDACCCACIDACDFHDBCDFHDBCDFGDCCDFGDCCDFFKDFFKDFEDECDFECFCDCADBDKDCHIFHQJC"`

Hence the code basically does the opposite operations :

```
v <- utf8ToInt("NFMOJEDJFDGGADC...")-64  # convert the string back to [1...17] vector

e <- rep(rep(c(' ',4),44),v)             # perform the inverse of rle function obtaining an
                                         # expanded vector of <space>'s and <four>'s

write(e,1,27,,'')                        # write the vector to stdout arranging it
                                         # in rows of maximum 27 characters

```

# Answer
> 13 votes
# Bubblegum, ~~71~~ ~~66~~ ~~65~~ 64 bytes

```
0000000: 95 91 21 12 00 20 08 c0 3a af 90 ff 7f 52 4e 58  ..!.. ..:....RNX
0000010: 58 93 25 d8 8a 27 47 e4 23 66 01 2c ce b1 3c 12  X.%..'G.#f.,..<.
0000020: 5f 5b 17 7c 81 ed 31 28 4e 6e a4 6d 23 ad 5b c2  _[.|..1(Nn.m#.[.
0000030: ae 25 83 9a 94 1a 2f 6f 05 fc e5 f0 73 13 f9 0b  .%..../o....s...

```

*Thanks to @ovs for golfing off 1 byte!*

Try it online!

# Answer
> 12 votes
# C (gcc), ~~244~~ ~~243~~ 242 bytes

```
#define z <<10|117441415
x[]={8064,2097088,8142832,31473596,58751886,30 z,60 z,60 z,120 z,120 z,255 z,255 z,480 z,448 z,63897630,33423612,2097136,1835008};b(_,i){i&&b(_/2,i-1),putchar(32+_%2*3);}main(_){_<19&&b(x[_-1],27)&puts("")&main(_+1);}

```

Try it online!

-1 Thanks to Peter Cordes

-1 Thanks to ceilingcat

Uses bit compression.

### Explanation:

The goal is to print a set of numbers in binary using space and # as digits which represent the logo. A bit of bash magic converts the logo to binary masks:

```
echo "ibase=2;$(<code which echoes the logo [see my bash solution for example]> | tr ' #' 01)" | bc

```

This results in the binary 'numbers' being:

```
8064,2097088,8142832,31473596,58751886,117472135,117502855,117502855,117564295,117564295,117702535,117702535,117932935,117900167,63897630,33423612,2097136,1835008

```

There is an obvious pattern in the middle where every line contains `### ### ###`

We can save some space by compressing that middle section based on saving that pattern and OR-ing against it. In addition, all of those lines merely add some stuff to the left of the middle section, so we make the `z` macro which takes `??????????????` and converts it into `###??????????????### ###`. This involves bitshifting left by 10 and OR-ing with the binary of that pattern, which is 117441415.

Now we can more easily understand the code:

```
#define z <<10|117441415 // Define z to be the compression defined above
x[]={                    // Define x to be an array storing each line's number
8064,2097088,8142832,    // The first 5 lines are uncompressed
31473596,58751886,
30 z,60 z,60 z,120 z,    // The middle 9 lines are z-compressed
120 z,255 z,255 z,480 z,
448 z,
63897630,33423612,       // The last 4 lines are uncompressed
2097136,1835008};
b(_,i){                  // we also need a function to print n-bit binary numbers
i&&                      // i is the bit counter, we recurse until its zero
b(_/2,i-1),              // each recursive call halves the input and decrements i
putchar(" #"[_%2]);}     // this just prints the correct character
main(_){                 // this is the main function, called as ./? will have 1 in _ (argc)
_<19?                    // if _ is less than 19 then...
  b(x[_-1],27),          // print the binary expansion of x[_-1]
  puts(""),              // print a new line
  main(_+1)              // recurse with _++
:0;}

```

# Answer
> 12 votes
# Python 2, 129 bytes

```
00000000: 2363 6f64 696e 673a 4c31 0a70 7269 6e74  #coding:L1.print
00000010: 2778 da95 9141 0e5c 3021 0803 ef7d 4593  'x...A.\0!...}E.
00000020: feff 8f9b 5d14 5c6e f1b0 f622 7422 2890  ....].\n..."t"(.
00000030: 2e7d 5a09 dc4b 19cb bc53 84d1 4a6a 5960  .}Z..K...S..JjY`
00000040: 116e 3f42 c290 b3f7 c0bc 76cf 549d 6ed8  .n?B......v.T.n.
00000050: f8fa 5f26 0b0e 8c93 d5cb 35f6 b1e7 a939  .._&......5....9
00000060: 9e98 e769 47b9 87d6 cdf5 5c30 3030 32c0  ...iG.....\0002.
00000070: 4029 272e 6465 636f 6465 2827 7a69 7027  @)'.decode('zip'
00000080: 29                                       )

```

Try it online!

# Answer
> 12 votes
# Charcoal, ~~71~~ ~~68~~ 67 bytes

```
←⁸↙Ｐ⁵↘←⁴↓Ｐ³↙Ｆ⁹⟦³⟧→Ｐ⁴↘Ｐ⁶↘‖ＯＭ←←¹⁷↘Ｆ⁹«Ｐ⁺³›ι³↑Ｐ⁴↗¿⁼ι²Ｂ⁸±²»↘→ＵＯ³¦¹⁴ＵＭＫＡ#

```

Try it online! Link is to verbose version of code. Explanation:

```
←⁸↙Ｐ⁵↘←⁴↓Ｐ³↙Ｆ⁹⟦³⟧→Ｐ⁴↘Ｐ⁶

```

Output half of the circle.

```
↘‖ＯＭ←←¹⁷↘

```

Reflect it and draw in the bottom.

```
Ｆ⁹«Ｐ⁺³›ι³↑Ｐ⁴↗¿⁼ι²Ｂ⁸±²»

```

Draw the left arm and crossbar of the A.

```
↘→ＵＯ³¦¹⁴

```

Draw the right arm of the A.

```
ＵＭＫＡ#

```

Change all the characters to `#`s.

# Answer
> 11 votes
# T-SQL, ~~341~~ 338 bytes

```
DECLARE @ CHAR(2000)=REPLACE(REPLACE(REPLACE(
'PRINT SPACE(14*6&$6*15&$4*5$4*10&$2*4$7*7$1*4&$1*3$8*4$1*3$3*3&*3$9*4$1*3$4
 *3&*3$8*4$2*3$4*3&*3$8*4$2*3$4*3&*3$7*4$3*3$4*3&*3$7*4$3*3$4*3&*3$6*11$4*3&
 *3$6*11$4*3&*3$5*4$5*3$4*3&*3$5*3$6*3$4*3&$1*4$2*4$11*4&$2*8$9*6&$6*17&$6*3)'
,'*',')+REPLICATE(''#'','),'$',')+SPACE('),'&',')+(''
''')EXEC(@)

```

The first 4 line breaks are for readability only, the final line break is part of a string literal.

Similar to my Adam West tribute, I've manually encoded a long string, and made the following replacements:

* `*7` gets replaced by `+REPLICATE('#',7)`
* `$4` gets replaced by `+SPACE(4)`
* `&` gets replaced by a line break inside quotes

This results in a *massive* SQL command string:

```
PRINT SPACE(14)+REPLICATE('#',6)+('
')+SPACE(6)+REPLICATE('#',15)+('
')+SPACE(4)+REPLICATE('#',5)+SPACE(4)+REPLICATE('#',10)+('
')+SPACE(2)+REPLICATE('#',4)+SPACE(7)+REPLICATE('#',7)+SPACE(1)+REPLICATE('#',4)+('
')+SPACE(1)+REPLICATE('#',3)+SPACE(8)+REPLICATE('#',4)+SPACE(1)+REPLICATE('#',3)+SPACE(3)+REPLICATE('#',3)+('
')+REPLICATE('#',3)+SPACE(9)+REPLICATE('#',4)+SPACE(1)+REPLICATE('#',3)+SPACE(4)+REPLICATE('#',3)+('
')+REPLICATE('#',3)+SPACE(8)+REPLICATE('#',4)+SPACE(2)+REPLICATE('#',3)+SPACE(4)+REPLICATE('#',3)+('
')+REPLICATE('#',3)+SPACE(8)+REPLICATE('#',4)+SPACE(2)+REPLICATE('#',3)+SPACE(4)+REPLICATE('#',3)+('
')+REPLICATE('#',3)+SPACE(7)+REPLICATE('#',4)+SPACE(3)+REPLICATE('#',3)+SPACE(4)+REPLICATE('#',3)+('
')+REPLICATE('#',3)+SPACE(7)+REPLICATE('#',4)+SPACE(3)+REPLICATE('#',3)+SPACE(4)+REPLICATE('#',3)+('
')+REPLICATE('#',3)+SPACE(6)+REPLICATE('#',11)+SPACE(4)+REPLICATE('#',3)+('
')+REPLICATE('#',3)+SPACE(6)+REPLICATE('#',11)+SPACE(4)+REPLICATE('#',3)+('
')+REPLICATE('#',3)+SPACE(5)+REPLICATE('#',4)+SPACE(5)+REPLICATE('#',3)+SPACE(4)+REPLICATE('#',3)+('
')+REPLICATE('#',3)+SPACE(5)+REPLICATE('#',3)+SPACE(6)+REPLICATE('#',3)+SPACE(4)+REPLICATE('#',3)+('
')+SPACE(1)+REPLICATE('#',4)+SPACE(2)+REPLICATE('#',4)+SPACE(11)+REPLICATE('#',4)+('
')+SPACE(2)+REPLICATE('#',8)+SPACE(9)+REPLICATE('#',6)+('
')+SPACE(6)+REPLICATE('#',17)+('
')+SPACE(6)+REPLICATE('#',3)

```

Which, when run, produces the necessary output.

Long, but still better than my best set-based solution (**463 bytes**):

```
SELECT SPACE(a)+REPLICATE('#',b)+SPACE(c)+REPLICATE('#',d)
      +SPACE(e)+REPLICATE('#',f)+SPACE(g)+REPLICATE('#',h)
FROM(VALUES(7,0,7,6,0,0,0,0),(6,8,0,7,0,0,0,0),(4,5,4,5,0,5,0,0),(2,4,7,7,1,4,0,0),
           (1,3,8,4,1,3,3,3),(0,3,9,4,1,3,4,3),(0,3,8,4,2,3,4,3),(0,3,8,4,2,3,4,3),
           (0,3,7,4,3,3,4,3),(0,3,7,4,3,3,4,3),(0,3,6,6,0,5,4,3),(0,3,6,6,0,5,4,3),
           (0,3,5,4,5,3,4,3),(0,3,5,3,6,3,4,3),(1,4,2,4,5,0,6,4),(2,8,9,6,0,0,0,0),
           (6,9,0,8,0,0,0,0),(6,3,0,0,0,0,0,0))t(a,b,c,d,e,f,g,h)

```

# Answer
> 10 votes
# JavaScript (ES6), ~~173~~ 170 bytes

```
_=>`tc
du
9a9k
58fe38
36h83676
6j83!h85!h85!f87!f87!dm96
6dm96
6b8b!b6d696
3858n8
5gjc
dy
d6`.split`!`.join`696
6`.replace(/./g,c=>'# '[(k=parseInt(c,36))&1].repeat(k/2))

```

Try it online!

---

# Node.js, 163 bytes

Provided that an array of strings is a valid output:

```
_=>Buffer(`.&-/*%$*&$''!$##($!###!#)$!#$&($"#$&($"#$&'$##$&'$##$&&+$&&+$&%$%#$&%#&#$#!$"$+$#()&(1*#2`).map(c=>s+='# '[x^=1].repeat(c-32),s=x='')&&s.match(/.{27}/g)

```

Try it online!

# Answer
> 10 votes
# Canvas, ~~74~~ ~~73~~ 71 bytes

```
ｑｃ２－Ａｚ↓n⁴╫ｍ┬ｆｆ╷＼_↘Tｔ)%⁵6＞Ｙy7pＱ∔Ｉ％SIŗ＋T＾≤?↔↖¶８^`O‾+Ｏ│≤n≡j↶82„２┬｛ #＠］∑‾＋ｎ

```

Try it here!

# Answer
> 10 votes
# C (gcc), ~~174~~ ~~168~~ ~~164~~ 160 bytes

-6 bytes thanks to Dennis.

```
i,j;main(l){while(i="NFMOJEDJFDGGADCCHDACCCACIDACDFHDBCDFHDBCDFGDCCDFGDCCDFFKDFFKDFEDECDFECFCDCADBDKDCHIFHQJC"[j++]&63)for(;i;)putchar(l++%28?--i,35-j%2*3:10);}

```

Try it online!

# Answer
> 10 votes
# 05AB1E, ~~101~~ ~~88~~ 64 bytes

```
„# •∍ΔÎë,½=bOÅ.âαUΔ'òõƶαÔγλ#xÆ]~”FbćÁ˜Ð”wнQ_wā©•12вεN>yи}˜èJ27ô»

```

-24 bytes by creating a port of *@Dennis♦*' Jelly answer.

Try it online.

**Explanation:**

```
„#                     # Push string "# "
   •∍ΔÎë,½=bOÅ.âαUΔ'òõƶαÔγλ#xÆ]~”FbćÁ˜Ð”wнQ_wā©•
                      '# Push compressed integer 10250938842396786963034911279002199266186481794751691439873548591280332406943905758890346943197901909163
     12в               # Convert to Base-12 as list: [3,0,11,6,2,0,11,4,0,11,10,5,4,10,6,4,7,7,1,4,3,3,8,4,1,3,3,3,1,3,9,4,1,3,4,6,8,4,2,3,4,6,8,4,2,3,4,6,7,4,3,3,4,6,7,4,3,3,4,6,6,11,4,6,6,11,4,6,5,4,5,3,4,6,5,3,6,3,4,3,1,4,2,4,11,4,3,8,9,6,8,6,0,11,10,3]
        ε    }         # Map each `y` to:
         N>            #  The index+1
           yи          #  Repeated `y` amount of times
              ˜        # Flatten the list
               è       # Index each in the string "# " (with automatic wraparound)
                J      # Join everything together
                 27ô   # Split into parts of length 27
                    »  # And join by newlines

```

See this 05AB1E tip of mine (sections *How to compress large integers?* and *How to compress integer lists?*) to understand how the compression of the integer and list works.

# Answer
> 8 votes
# ///, 170 bytes

```
/+/\/\///*/  +)/'$# +(/"$!+'/" +&/!#+%/"!
!+$/*!+"/**+!/###/""('*
(!!!'
"&#"!!&"
$#'$& &*
 !""& ! $
!"'& !%""&$%""&$%)$%)$%(&#%(&#%'&'!%'!"$"!
 &$#")
$&#"'!!*
(!!&#"
"$

```

Try it online!

# Answer
> 8 votes
# Bash, ~~192~~ 176 bytes

```
dc<<<"16i2o81C0000 81FFFF0 9FE00FC BCF001E F070387 F078387 F03FF87 F03FF87 F01E387 F01E387 F00F387 F00F387 F007B87 B807B8E 9E03FBC 87C3FF0 81FFFC0 8001F80f"|tr 01 ' #'|cut -c2-

```

Try it online!

-16 thanks to manatwork

This is similar to my C answer, except it just uses a raw base-16 compression and passes it through bc, then uses tr to convert 1 to # and 0 to space. Each row has 1 appended to it and stripped off of it to maintain alignment.

Unfortunately `dc` is shorter than `bc`.

# Answer
> 6 votes
# Perl 6, ~~136~~ 112 bytes

```
:128['?@~p<?x?aB~<|xpqpac`?@~x>q|<!Ca`||?x'.ords].base(2)~~TR/1/ /.comb(27)>>.say

```

Try it online!

Parses a base 128 number from the ordinal values of the compressed string, converts to base 2 and replaces the `1`s with spaces. This uses zeroes as the main character. The string has like 9 null bytes, which was a bitch to type up in TIO. I would have used base 127 for the same amount of bytes, but no nulls, but that has a carriage return, which seems to be impossible to distinguish from a newline `:(`

### Explanation:

```
:128['...'.ords]   # Convert the bytes of the string to base 128
.base(2)           # Convert to base 2
~~TR/1/ /          # Translate 1s to spaces
                   # Alternatively, this could be .split(1)
.comb(27)          # Split to strings of length 27
>>.say             # Print each on a newline

```

# Answer
> 6 votes
## Haskell, ~~170~~ 163 bytes

Edit: -7 bytes thanks to @Ørjan Johansen

```
m=<<"Mc Ul WeWg YdTgZa ZcSdZcX cRdZcW cSdYcW cSdYcW cTdXcW cTdXcW cUkW cUkW cVdVcW cVcUcW ZdYdPa YhRc Un U "
m ' '="###\n"
m c=(' '<$['Z','Y'..c])++('#'<$['a'..c])

```

Try it online!

Spaces are encoded as uppercase characters (length: `Z` down to char), hash signs as lowercase characters (length: `a` to char) and the last three `#` of each line plus newline as a space. Function `m` decodes it.

# Answer
> 5 votes
# , 130 128 bytes

```
echo' #'{~18 27$;(_243{.2#.inv 92x#._32+a.i.])&>'!TYPW.ajz i8hIhXl''3lOH8GvV.C2Z{r/=,G';'"a*2ZDxRplkh2tzRakz.?ZwVmeOT6L^lFB^eyT'

```

Try it online!

## Initial solution

# , 164 bytes

```
echo' #'{~18 27$,#:849239965469633263905532594449192007713271791872263657753301928240007 12380965417202148347902847903517734495157419855048834759608223758433386496x

```

Try it online!

# Answer
> 5 votes
# PHP, ~~286~~ ~~212~~ ~~209~~ 208 bytes

```
<?php foreach(str_split('000680018y4g04uj1s0iql6k0yz98u1xxu2v1xyhs71xyhs71xzt6v1xzt6v1y2ruv1y2ruv1y7pmv1y70cn121jq60jwdto018y5s13bwg',6)as $i)echo str_replace(0,' ',str_pad(base_convert($i,36,2),27,0,0))."
";

```

Try it online!

# Answer
> 4 votes
# Perl 5, 181 bytes

```
say+(sprintf"%28b",oct"0x$_")=~y/10/# /r for"0003f0003fff800f87fe03c07f78700f71ce00f70ee01e70ee01e70ee03c70ee03c70ee07ff0ee07ff0ee0f070ee0e070e79e003c3fc01f803fffe00380000"=~/.{7}/g

```

Try it online!

# Answer
> 4 votes
**MATLAB** **: 144 Bytes**

```
reshape(repelem([repmat(' #',1,44),' '],'NFMOJEDJFDGGADCCHDACCCACIDACDFHDBCDFHDBCDFGDCCDFGDCCDFFKDFFKDFEDECDFECFCDCADBDKDCHIFHQJCR'-64),27,[])'

```

Try it online! (Technically in Octave)

**Explanation:**

This uses the same strategy as digEmAll in R, just with MATLAB syntax. The main difference is that MATLAB has automatic conversion from characters to integers.

# Answer
> 3 votes
# C# (.NET Core), 199 bytes

```
_=>{var r="";for(int i=0,j,k=0;i<88;i++)for(j=0;j++<"0(/1,'&,(&))#&%%*&#%%%#%+&#%&(*&$%&(*&$%&()&%%&()&%%&((-&((-&('&'%&('%(%&%#&$&-&%*+(*3,%"[i]-34;){r+=i%2<1?' ':'#';if(++k%27<1)r+='\n';}return r;}

```

Try it online!

Uses the same approach as my solution to the tribute to Adam West.

# Answer
> 3 votes
# Deadfish~, 726 723 bytes

*-3 bytes thanks to @squid*

```
{iii}ii{c}cccciccccccddd{dd}c{ii}iicccccci{c}cccccddd{dd}c{ii}iiccccicccccdcccci{c}ddd{dd}c{ii}iicciccccdcccccccicccccccdciccccddd{dd}c{ii}iicicccdcccccccciccccdcicccdcccicccddd{dd}c{ii}iiicccdccccccccciccccdcicccdccccicccddd{dd}c{ii}iiicccdcccccccciccccdccicccdccccicccddd{dd}c{ii}iiicccdcccccccciccccdccicccdccccicccddd{dd}c{ii}iiicccdccccccciccccdcccicccdccccicccddd{dd}c{ii}iiicccdccccccciccccdcccicccdccccicccddd{dd}c{ii}iiicccdcccccci{c}cdccccicccddd{dd}c{ii}iiicccdcccccci{c}cdccccicccddd{dd}c{ii}iiicccdccccciccccdcccccicccdccccicccddd{dd}c{ii}iiicccdcccccicccdccccccicccdccccicccddd{dd}c{ii}iiciccccdcciccccd{c}ciccccddd{dd}c{ii}iicciccccccccdccccccccciccccccddd{dd}c{ii}iicccccci{c}cccccccddd{dd}c{ii}iicccccciccc

```

Try it online!

---

Having never seen/read anything Marvel and only relying on spoilers, it seems that Thanos is the best.

# Answer
> 2 votes
## Turing Machine But Way Worse \- 16913 bytes

```
0 0 0 1 1 0 0
0 1 0 1 2 0 0
0 2 1 0 3 1 0
0 3 0 1 0 1 0
1 0 1 1 4 1 0
0 4 0 1 5 1 0
0 5 0 0 6 1 0
0 6 0 1 7 1 0
0 7 0 0 8 1 0
0 8 0 1 9 1 0
0 9 0 0 10 1 0
0 10 0 1 11 1 0
0 11 0 0 12 1 0
0 12 0 1 13 1 0
0 13 0 0 14 1 0
0 14 0 1 15 1 0
0 15 0 1 16 0 0
0 16 0 1 17 0 0
0 17 1 1 18 0 0
0 18 1 0 1 1 0
1 1 1 0 19 1 0
0 19 0 0 20 1 0
0 20 0 0 21 1 0
0 21 0 1 22 1 0
0 22 0 0 23 1 0
0 23 0 0 2 0 0
1 2 0 0 24 0 0
0 24 0 1 25 0 0
0 25 0 1 26 0 0
0 26 0 1 27 0 0
0 27 1 1 28 0 0
0 28 0 1 3 0 0
1 3 1 1 4 0 0
1 4 0 0 5 1 0
1 5 0 0 29 0 0
0 29 0 0 6 0 0
1 6 0 0 30 0 0
0 30 0 0 31 0 0
0 31 1 0 32 1 0
0 32 0 1 7 1 0
1 7 1 1 33 1 0
0 33 0 1 34 1 0
0 34 0 0 35 1 0
0 35 0 1 36 1 0
0 36 0 1 37 0 0
0 37 0 1 38 0 0
0 38 1 1 39 0 0
0 39 1 0 8 1 0
1 8 1 0 40 1 0
0 40 0 0 41 1 0
0 41 0 0 42 1 0
0 42 0 1 43 1 0
0 43 0 0 44 1 0
0 44 0 1 45 1 0
0 45 0 0 46 1 0
0 46 0 1 47 1 0
0 47 0 0 48 1 0
0 48 0 1 49 1 0
0 49 0 0 50 1 0
0 50 0 1 51 1 0
0 51 0 0 52 1 0
0 52 0 1 53 1 0
0 53 1 1 54 0 0
0 54 0 1 9 0 0
1 9 1 1 10 0 0
1 10 0 0 11 0 0
1 11 1 0 55 0 0
0 55 0 0 12 0 0
1 12 1 0 56 0 0
0 56 0 0 13 0 0
1 13 0 0 57 1 0
0 57 0 1 58 0 0
0 58 1 0 59 0 0
0 59 0 1 14 0 0
1 14 1 1 60 0 0
0 60 0 1 15 0 0
1 15 0 1 61 0 0
0 61 0 1 16 0 0
1 16 0 0 62 1 0
0 62 0 0 63 1 0
0 63 0 0 64 1 0
0 64 0 1 65 1 0
0 65 0 1 66 0 0
0 66 0 1 67 0 0
0 67 1 1 68 0 0
0 68 1 0 17 1 0
1 17 1 0 69 1 0
0 69 0 0 70 1 0
0 70 0 0 71 1 0
0 71 0 1 72 1 0
0 72 0 1 73 0 0
0 73 0 1 18 0 0
1 18 0 1 19 0 0
1 19 0 0 74 1 0
0 74 0 0 75 1 0
0 75 0 0 76 1 0
0 76 0 0 77 1 0
0 77 0 1 78 0 0
0 78 0 1 79 0 0
0 79 0 1 80 0 0
0 80 1 1 81 0 0
0 81 1 0 20 1 0
1 20 1 0 82 1 0
0 82 0 0 83 1 0
0 83 0 0 84 1 0
0 84 0 1 85 1 0
0 85 0 0 86 1 0
0 86 0 1 87 1 0
0 87 0 0 88 1 0
0 88 0 1 89 1 0
0 89 0 0 90 1 0
0 90 0 0 21 0 0
1 21 0 0 91 0 0
0 91 0 1 92 0 0
0 92 0 1 93 0 0
0 93 0 1 94 0 0
0 94 1 1 95 0 0
0 95 0 1 22 0 0
1 22 1 1 23 0 0
1 23 0 0 24 1 0
1 24 0 0 96 0 0
0 96 0 0 25 0 0
1 25 0 0 97 0 0
0 97 0 0 98 0 0
0 98 1 0 99 1 0
0 99 0 1 26 1 0
1 26 1 1 100 0 0
0 100 0 1 101 0 0
0 101 0 1 102 0 0
0 102 0 1 103 0 0
0 103 1 1 104 0 0
0 104 1 0 27 1 0
1 27 1 0 105 1 0
0 105 0 0 106 1 0
0 106 0 0 107 1 0
0 107 0 1 108 0 0
0 108 0 1 109 0 0
0 109 0 1 28 0 0
1 28 0 1 29 0 0
1 29 0 0 110 1 0
0 110 0 0 111 1 0
0 111 0 0 112 1 0
0 112 0 0 113 1 0
0 113 0 1 114 1 0
0 114 0 0 115 1 0
0 115 0 1 116 1 0
0 116 0 1 117 0 0
0 117 0 1 118 0 0
0 118 1 1 119 0 0
0 119 1 0 30 1 0
1 30 1 0 120 1 0
0 120 0 0 121 1 0
0 121 0 0 122 1 0
0 122 0 1 123 1 0
0 123 0 0 124 1 0
0 124 0 1 125 1 0
0 125 0 1 126 0 0
0 126 0 1 31 0 0
1 31 0 1 32 0 0
1 32 0 0 127 1 0
0 127 1 1 128 0 0
0 128 1 0 33 1 0
1 33 1 0 129 1 0
0 129 0 0 130 1 0
0 130 0 0 131 1 0
0 131 0 0 34 0 0
1 34 0 0 132 0 0
0 132 0 1 133 0 0
0 133 0 1 134 0 0
0 134 0 1 135 0 0
0 135 1 1 136 0 0
0 136 0 1 35 0 0
1 35 1 1 36 0 0
1 36 0 0 37 1 0
1 37 0 0 137 0 0
0 137 0 0 38 0 0
1 38 0 0 138 0 0
0 138 0 0 139 0 0
0 139 1 0 140 1 0
0 140 0 1 39 0 0
1 39 1 1 141 0 0
0 141 0 1 142 0 0
0 142 0 1 143 0 0
0 143 0 1 144 0 0
0 144 1 1 145 0 0
0 145 1 0 40 1 0
1 40 1 0 146 1 0
0 146 0 0 147 1 0
0 147 0 1 148 0 0
0 148 0 1 41 0 0
1 41 0 1 42 0 0
1 42 0 0 149 1 0
0 149 0 0 150 1 0
0 150 0 0 151 1 0
0 151 0 0 152 1 0
0 152 0 1 153 1 0
0 153 0 0 154 1 0
0 154 0 1 155 1 0
0 155 0 0 156 1 0
0 156 0 1 157 0 0
0 157 0 1 158 0 0
0 158 0 1 159 0 0
0 159 1 1 160 0 0
0 160 1 0 43 1 0
1 43 1 0 161 1 0
0 161 0 0 162 1 0
0 162 0 0 163 1 0
0 163 0 1 164 0 0
0 164 0 1 165 0 0
0 165 0 1 44 0 0
1 44 0 1 45 0 0
1 45 0 0 166 1 0
0 166 1 1 167 0 0
0 167 1 0 46 1 0
1 46 1 0 168 1 0
0 168 0 0 169 1 0
0 169 0 1 170 0 0
0 170 0 1 47 0 0
1 47 0 1 48 0 0
1 48 0 0 171 1 0
0 171 0 0 172 1 0
0 172 0 0 173 1 0
0 173 0 1 174 0 0
0 174 0 1 175 0 0
0 175 1 1 176 0 0
0 176 1 0 49 1 0
1 49 1 0 177 1 0
0 177 0 0 178 1 0
0 178 1 1 179 0 0
0 179 0 1 50 0 0
1 50 1 1 51 0 0
1 51 0 0 52 0 0
1 52 1 0 180 0 0
0 180 0 0 53 0 0
1 53 1 0 181 0 0
0 181 0 0 54 0 0
1 54 0 0 182 1 0
0 182 0 1 183 0 0
0 183 1 0 184 0 0
0 184 0 1 55 0 0
1 55 1 1 185 0 0
0 185 0 1 56 0 0
1 56 0 1 186 0 0
0 186 0 1 57 0 0
1 57 1 1 187 0 0
0 187 1 0 58 1 0
1 58 1 0 188 1 0
0 188 0 0 189 1 0
0 189 0 1 190 0 0
0 190 0 1 59 0 0
1 59 0 1 60 0 0
1 60 0 0 191 1 0
0 191 0 0 192 1 0
0 192 0 0 193 1 0
0 193 0 0 194 1 0
0 194 0 1 195 1 0
0 195 0 0 196 1 0
0 196 0 1 197 1 0
0 197 0 0 198 1 0
0 198 0 1 199 1 0
0 199 0 1 200 0 0
0 200 0 1 201 0 0
0 201 1 1 202 0 0
0 202 1 0 61 1 0
1 61 1 0 203 1 0
0 203 0 0 204 1 0
0 204 0 0 205 1 0
0 205 0 1 206 0 0
0 206 0 1 207 0 0
0 207 0 1 62 0 0
1 62 0 1 63 0 0
1 63 0 0 208 1 0
0 208 1 1 209 0 0
0 209 1 0 64 1 0
1 64 1 0 210 1 0
0 210 0 0 211 1 0
0 211 0 1 212 0 0
0 212 0 1 65 0 0
1 65 0 1 66 0 0
1 66 0 0 213 1 0
0 213 0 0 214 1 0
0 214 0 0 215 1 0
0 215 0 0 216 1 0
0 216 0 1 217 0 0
0 217 0 1 218 0 0
0 218 0 1 219 0 0
0 219 1 1 220 0 0
0 220 1 0 67 1 0
1 67 1 0 221 1 0
0 221 0 0 222 1 0
0 222 1 1 223 0 0
0 223 0 1 68 0 0
1 68 1 1 69 0 0
1 69 0 0 70 0 0
1 70 1 0 224 0 0
0 224 0 0 71 0 0
1 71 1 0 225 0 0
0 225 0 0 72 0 0
1 72 0 0 226 1 0
0 226 0 1 227 0 0
0 227 1 0 228 0 0
0 228 0 1 73 0 0
1 73 1 1 229 0 0
0 229 0 1 74 0 0
1 74 0 1 230 0 0
0 230 0 1 75 0 0
1 75 1 1 231 0 0
0 231 1 0 76 1 0
1 76 1 0 232 1 0
0 232 0 0 233 1 0
0 233 0 1 234 0 0
0 234 0 1 77 0 0
1 77 0 1 78 0 0
1 78 0 0 235 1 0
0 235 0 0 236 1 0
0 236 0 0 237 1 0
0 237 0 0 238 1 0
0 238 0 1 239 1 0
0 239 0 0 240 1 0
0 240 0 1 241 1 0
0 241 0 0 242 1 0
0 242 0 1 243 0 0
0 243 0 1 244 0 0
0 244 0 1 245 0 0
0 245 1 1 246 0 0
0 246 1 0 79 1 0
1 79 1 0 247 1 0
0 247 0 0 248 1 0
0 248 0 0 249 1 0
0 249 0 1 250 0 0
0 250 0 1 251 0 0
0 251 0 1 80 0 0
1 80 0 1 81 0 0
1 81 0 0 252 1 0
0 252 0 0 253 1 0
0 253 0 1 254 0 0
0 254 1 1 255 0 0
0 255 1 0 82 1 0
1 82 1 0 256 1 0
0 256 0 0 257 1 0
0 257 0 1 258 0 0
0 258 0 1 83 0 0
1 83 0 1 84 0 0
1 84 0 0 259 1 0
0 259 0 0 260 1 0
0 260 0 0 261 1 0
0 261 0 0 262 1 0
0 262 0 1 263 0 0
0 263 0 1 264 0 0
0 264 0 1 265 0 0
0 265 1 1 266 0 0
0 266 1 0 85 1 0
1 85 1 0 267 1 0
0 267 0 0 268 1 0
0 268 1 1 269 0 0
0 269 0 1 86 0 0
1 86 1 1 87 0 0
1 87 0 0 88 0 0
1 88 1 0 270 0 0
0 270 0 0 89 0 0
1 89 1 0 271 0 0
0 271 0 0 90 0 0
1 90 0 0 272 1 0
0 272 0 1 273 0 0
0 273 1 0 274 0 0
0 274 0 1 91 0 0
1 91 1 1 275 0 0
0 275 0 1 92 0 0
1 92 0 1 276 0 0
0 276 0 1 93 0 0
1 93 1 1 277 0 0
0 277 1 0 94 1 0
1 94 1 0 278 1 0
0 278 0 0 279 1 0
0 279 0 1 280 0 0
0 280 0 1 95 0 0
1 95 0 1 96 0 0
1 96 0 0 281 1 0
0 281 0 0 282 1 0
0 282 0 0 283 1 0
0 283 0 0 284 1 0
0 284 0 1 285 1 0
0 285 0 0 286 1 0
0 286 0 1 287 1 0
0 287 0 0 288 1 0
0 288 0 1 289 0 0
0 289 0 1 290 0 0
0 290 0 1 291 0 0
0 291 1 1 292 0 0
0 292 1 0 97 1 0
1 97 1 0 293 1 0
0 293 0 0 294 1 0
0 294 0 0 295 1 0
0 295 0 1 296 0 0
0 296 0 1 297 0 0
0 297 0 1 98 0 0
1 98 0 1 99 0 0
1 99 0 0 298 1 0
0 298 0 0 299 1 0
0 299 0 1 300 0 0
0 300 1 1 301 0 0
0 301 1 0 100 1 0
1 100 1 0 302 1 0
0 302 0 0 303 1 0
0 303 0 1 304 0 0
0 304 0 1 101 0 0
1 101 0 1 102 0 0
1 102 0 0 305 1 0
0 305 0 0 306 1 0
0 306 0 0 307 1 0
0 307 0 0 308 1 0
0 308 0 1 309 0 0
0 309 0 1 310 0 0
0 310 0 1 311 0 0
0 311 1 1 312 0 0
0 312 1 0 103 1 0
1 103 1 0 313 1 0
0 313 0 0 314 1 0
0 314 1 1 315 0 0
0 315 0 1 104 0 0
1 104 1 1 105 0 0
1 105 0 0 106 0 0
1 106 1 0 316 0 0
0 316 0 0 107 0 0
1 107 1 0 317 0 0
0 317 0 0 108 0 0
1 108 0 0 318 1 0
0 318 0 1 319 0 0
0 319 1 0 320 0 0
0 320 0 1 109 0 0
1 109 1 1 321 0 0
0 321 0 1 110 0 0
1 110 0 1 322 0 0
0 322 0 1 111 0 0
1 111 1 1 323 0 0
0 323 1 0 112 1 0
1 112 1 0 324 1 0
0 324 0 0 325 1 0
0 325 0 1 326 0 0
0 326 0 1 113 0 0
1 113 0 1 114 0 0
1 114 0 0 327 1 0
0 327 0 0 328 1 0
0 328 0 0 329 1 0
0 329 0 0 330 1 0
0 330 0 1 331 1 0
0 331 0 0 332 1 0
0 332 0 1 333 1 0
0 333 0 1 334 0 0
0 334 0 1 335 0 0
0 335 1 1 336 0 0
0 336 1 0 115 1 0
1 115 1 0 337 1 0
0 337 0 0 338 1 0
0 338 0 0 339 1 0
0 339 0 1 340 0 0
0 340 0 1 341 0 0
0 341 0 1 116 0 0
1 116 0 1 117 0 0
1 117 0 0 342 1 0
0 342 0 0 343 1 0
0 343 0 0 344 1 0
0 344 0 1 345 0 0
0 345 0 1 346 0 0
0 346 1 1 347 0 0
0 347 1 0 118 1 0
1 118 1 0 348 1 0
0 348 0 0 349 1 0
0 349 0 1 350 0 0
0 350 0 1 119 0 0
1 119 0 1 120 0 0
1 120 0 0 351 1 0
0 351 0 0 352 1 0
0 352 0 0 353 1 0
0 353 0 0 354 1 0
0 354 0 1 355 0 0
0 355 0 1 356 0 0
0 356 0 1 357 0 0
0 357 1 1 358 0 0
0 358 1 0 121 1 0
1 121 1 0 359 1 0
0 359 0 0 360 1 0
0 360 1 1 361 0 0
0 361 0 1 122 0 0
1 122 1 1 123 0 0
1 123 0 0 124 0 0
1 124 1 0 362 0 0
0 362 0 0 125 0 0
1 125 1 0 363 0 0
0 363 0 0 126 0 0
1 126 0 0 364 1 0
0 364 0 1 365 0 0
0 365 1 0 366 0 0
0 366 0 1 127 0 0
1 127 1 1 367 0 0
0 367 0 1 128 0 0
1 128 0 1 368 0 0
0 368 0 1 129 0 0
1 129 1 1 369 0 0
0 369 1 0 130 1 0
1 130 1 0 370 1 0
0 370 0 0 371 1 0
0 371 0 1 372 0 0
0 372 0 1 131 0 0
1 131 0 1 132 0 0
1 132 0 0 373 1 0
0 373 0 0 374 1 0
0 374 0 0 375 1 0
0 375 0 0 376 1 0
0 376 0 1 377 1 0
0 377 0 0 378 1 0
0 378 0 1 379 1 0
0 379 0 1 380 0 0
0 380 0 1 381 0 0
0 381 1 1 382 0 0
0 382 1 0 133 1 0
1 133 1 0 383 1 0
0 383 0 0 384 1 0
0 384 0 0 385 1 0
0 385 0 1 386 0 0
0 386 0 1 387 0 0
0 387 0 1 134 0 0
1 134 0 1 135 0 0
1 135 0 0 388 1 0
0 388 0 0 389 1 0
0 389 0 0 390 1 0
0 390 0 1 391 0 0
0 391 0 1 392 0 0
0 392 1 1 393 0 0
0 393 1 0 136 1 0
1 136 1 0 394 1 0
0 394 0 0 395 1 0
0 395 0 1 396 0 0
0 396 0 1 137 0 0
1 137 0 1 138 0 0
1 138 0 0 397 1 0
0 397 0 0 398 1 0
0 398 0 0 399 1 0
0 399 0 0 400 1 0
0 400 0 1 401 0 0
0 401 0 1 402 0 0
0 402 0 1 403 0 0
0 403 1 1 404 0 0
0 404 1 0 139 1 0
1 139 1 0 405 1 0
0 405 0 0 406 1 0
0 406 1 1 407 0 0
0 407 0 1 140 0 0
1 140 1 1 141 0 0
1 141 0 0 142 0 0
1 142 1 0 408 0 0
0 408 0 0 143 0 0
1 143 1 0 409 0 0
0 409 0 0 144 0 0
1 144 0 0 410 1 0
0 410 0 1 411 0 0
0 411 1 0 412 0 0
0 412 0 1 145 0 0
1 145 1 1 413 0 0
0 413 0 1 146 0 0
1 146 0 1 414 0 0
0 414 0 1 147 0 0
1 147 1 1 415 0 0
0 415 1 0 148 1 0
1 148 1 0 416 1 0
0 416 0 0 417 1 0
0 417 0 1 418 0 0
0 418 0 1 149 0 0
1 149 0 1 150 0 0
1 150 0 0 419 1 0
0 419 0 0 420 1 0
0 420 0 0 421 1 0
0 421 0 0 422 1 0
0 422 0 1 423 1 0
0 423 0 0 424 1 0
0 424 0 1 425 0 0
0 425 0 1 426 0 0
0 426 0 1 427 0 0
0 427 1 1 428 0 0
0 428 1 0 151 1 0
1 151 1 0 429 1 0
0 429 0 0 430 1 0
0 430 0 0 431 1 0
0 431 0 1 432 1 0
0 432 0 0 433 1 0
0 433 0 1 434 1 0
0 434 0 0 435 1 0
0 435 0 1 436 1 0
0 436 0 0 437 1 0
0 437 0 1 438 1 0
0 438 0 1 439 0 0
0 439 0 1 152 0 0
1 152 0 1 153 0 0
1 153 0 0 440 1 0
0 440 0 0 441 1 0
0 441 0 0 442 1 0
0 442 0 0 443 1 0
0 443 0 1 444 0 0
0 444 0 1 445 0 0
0 445 0 1 446 0 0
0 446 1 1 447 0 0
0 447 1 0 154 1 0
1 154 1 0 448 1 0
0 448 0 0 449 1 0
0 449 1 1 450 0 0
0 450 0 1 155 0 0
1 155 1 1 156 0 0
1 156 0 0 157 0 0
1 157 1 0 451 0 0
0 451 0 0 158 0 0
1 158 1 0 452 0 0
0 452 0 0 159 0 0
1 159 0 0 453 1 0
0 453 0 1 454 0 0
0 454 1 0 455 0 0
0 455 0 1 160 0 0
1 160 1 1 456 0 0
0 456 0 1 161 0 0
1 161 0 1 457 0 0
0 457 0 1 162 0 0
1 162 1 1 458 0 0
0 458 1 0 163 1 0
1 163 1 0 459 1 0
0 459 0 0 460 1 0
0 460 0 1 461 0 0
0 461 0 1 164 0 0
1 164 0 1 165 0 0
1 165 0 0 462 1 0
0 462 0 0 463 1 0
0 463 0 0 464 1 0
0 464 0 0 465 1 0
0 465 0 1 466 1 0
0 466 0 0 467 1 0
0 467 0 1 468 0 0
0 468 0 1 469 0 0
0 469 0 1 470 0 0
0 470 1 1 471 0 0
0 471 1 0 166 1 0
1 166 1 0 472 1 0
0 472 0 0 473 1 0
0 473 0 0 474 1 0
0 474 0 1 475 1 0
0 475 0 0 476 1 0
0 476 0 1 477 1 0
0 477 0 0 478 1 0
0 478 0 1 479 1 0
0 479 0 0 480 1 0
0 480 0 1 481 1 0
0 481 0 1 482 0 0
0 482 0 1 167 0 0
1 167 0 1 168 0 0
1 168 0 0 483 1 0
0 483 0 0 484 1 0
0 484 0 0 485 1 0
0 485 0 0 486 1 0
0 486 0 1 487 0 0
0 487 0 1 488 0 0
0 488 0 1 489 0 0
0 489 1 1 490 0 0
0 490 1 0 169 1 0
1 169 1 0 491 1 0
0 491 0 0 492 1 0
0 492 1 1 493 0 0
0 493 0 1 170 0 0
1 170 1 1 171 0 0
1 171 0 0 172 0 0
1 172 1 0 494 0 0
0 494 0 0 173 0 0
1 173 1 0 495 0 0
0 495 0 0 174 0 0
1 174 0 0 496 1 0
0 496 0 1 497 0 0
0 497 1 0 498 0 0
0 498 0 1 175 0 0
1 175 1 1 499 0 0
0 499 0 1 176 0 0
1 176 0 1 500 0 0
0 500 0 1 177 0 0
1 177 1 1 501 0 0
0 501 1 0 178 1 0
1 178 1 0 502 1 0
0 502 0 0 503 1 0
0 503 0 1 504 0 0
0 504 0 1 179 0 0
1 179 0 1 180 0 0
1 180 0 0 505 1 0
0 505 0 0 506 1 0
0 506 0 0 507 1 0
0 507 0 0 508 1 0
0 508 0 1 509 1 0
0 509 0 1 510 0 0
0 510 0 1 511 0 0
0 511 1 1 512 0 0
0 512 1 0 181 1 0
1 181 1 0 513 1 0
0 513 0 0 514 1 0
0 514 0 0 515 1 0
0 515 0 1 516 0 0
0 516 0 1 517 0 0
0 517 0 1 182 0 0
1 182 0 1 183 0 0
1 183 0 0 518 1 0
0 518 0 0 519 1 0
0 519 0 0 520 1 0
0 520 0 0 521 1 0
0 521 0 1 522 1 0
0 522 0 1 523 0 0
0 523 0 1 524 0 0
0 524 1 1 525 0 0
0 525 1 0 184 1 0
1 184 1 0 526 1 0
0 526 0 0 527 1 0
0 527 0 1 528 0 0
0 528 0 1 185 0 0
1 185 0 1 186 0 0
1 186 0 0 529 1 0
0 529 0 0 530 1 0
0 530 0 0 531 1 0
0 531 0 0 532 1 0
0 532 0 1 533 0 0
0 533 0 1 534 0 0
0 534 0 1 535 0 0
0 535 1 1 536 0 0
0 536 1 0 187 1 0
1 187 1 0 537 1 0
0 537 0 0 538 1 0
0 538 1 1 539 0 0
0 539 0 1 188 0 0
1 188 1 1 189 0 0
1 189 0 0 190 0 0
1 190 1 0 540 0 0
0 540 0 0 191 0 0
1 191 1 0 541 0 0
0 541 0 0 192 0 0
1 192 0 0 542 1 0
0 542 0 1 543 0 0
0 543 1 0 544 0 0
0 544 0 1 193 0 0
1 193 1 1 545 0 0
0 545 0 1 194 0 0
1 194 0 1 546 0 0
0 546 0 1 195 0 0
1 195 1 1 547 0 0
0 547 1 0 196 1 0
1 196 1 0 548 1 0
0 548 0 0 549 1 0
0 549 0 1 550 0 0
0 550 0 1 197 0 0
1 197 0 1 198 0 0
1 198 0 0 551 1 0
0 551 0 0 552 1 0
0 552 0 0 553 1 0
0 553 0 0 554 1 0
0 554 0 1 555 1 0
0 555 0 1 556 0 0
0 556 0 1 557 0 0
0 557 1 1 558 0 0
0 558 1 0 199 1 0
1 199 1 0 559 1 0
0 559 0 0 560 1 0
0 560 0 1 561 0 0
0 561 0 1 200 0 0
1 200 0 1 201 0 0
1 201 0 0 562 1 0
0 562 0 0 563 1 0
0 563 0 0 564 1 0
0 564 0 0 565 1 0
0 565 0 1 566 1 0
0 566 0 0 567 1 0
0 567 0 1 568 0 0
0 568 0 1 569 0 0
0 569 0 1 570 0 0
0 570 1 1 571 0 0
0 571 1 0 202 1 0
1 202 1 0 572 1 0
0 572 0 0 573 1 0
0 573 0 1 574 0 0
0 574 0 1 203 0 0
1 203 0 1 204 0 0
1 204 0 0 575 1 0
0 575 0 0 576 1 0
0 576 0 0 577 1 0
0 577 0 0 578 1 0
0 578 0 1 579 0 0
0 579 0 1 580 0 0
0 580 0 1 581 0 0
0 581 1 1 582 0 0
0 582 1 0 205 1 0
1 205 1 0 583 1 0
0 583 0 0 584 1 0
0 584 1 1 585 0 0
0 585 0 1 206 0 0
1 206 1 1 207 0 0
1 207 0 0 208 0 0
1 208 1 0 586 0 0
0 586 0 0 209 0 0
1 209 1 0 587 0 0
0 587 0 0 210 0 0
1 210 0 0 588 1 0
0 588 0 1 589 0 0
0 589 1 0 590 0 0
0 590 0 1 211 0 0
1 211 1 1 591 0 0
0 591 0 1 212 0 0
1 212 0 1 592 0 0
0 592 0 1 213 0 0
1 213 0 0 593 1 0
0 593 0 1 594 0 0
0 594 1 1 595 0 0
0 595 1 0 214 1 0
1 214 1 0 596 1 0
0 596 0 0 597 1 0
0 597 0 0 598 1 0
0 598 0 1 599 0 0
0 599 0 1 600 0 0
0 600 0 1 215 0 0
1 215 0 1 216 0 0
1 216 0 0 601 1 0
0 601 0 0 602 1 0
0 602 0 1 603 0 0
0 603 1 1 604 0 0
0 604 1 0 217 1 0
1 217 1 0 605 1 0
0 605 0 0 606 1 0
0 606 0 0 607 1 0
0 607 0 1 608 0 0
0 608 0 1 609 0 0
0 609 0 1 218 0 0
1 218 0 1 219 0 0
1 219 0 0 610 1 0
0 610 0 0 611 1 0
0 611 0 0 612 1 0
0 612 0 0 613 1 0
0 613 0 1 614 1 0
0 614 0 0 615 1 0
0 615 0 1 616 1 0
0 616 0 0 617 1 0
0 617 0 1 618 1 0
0 618 0 0 619 1 0
0 619 0 1 620 1 0
0 620 0 1 621 0 0
0 621 0 1 622 0 0
0 622 1 1 623 0 0
0 623 1 0 220 1 0
1 220 1 0 624 1 0
0 624 0 0 625 1 0
0 625 0 0 626 1 0
0 626 0 0 221 0 0
1 221 0 0 627 0 0
0 627 0 1 628 0 0
0 628 0 1 629 0 0
0 629 0 1 630 0 0
0 630 1 1 631 0 0
0 631 0 1 222 0 0
1 222 1 1 223 0 0
1 223 0 0 224 1 0
1 224 0 0 632 0 0
0 632 0 0 225 0 0
1 225 0 0 633 0 0
0 633 0 0 634 0 0
0 634 1 0 635 1 0
0 635 0 1 226 1 0
1 226 1 1 636 0 0
0 636 0 1 637 0 0
0 637 0 1 638 0 0
0 638 0 1 639 0 0
0 639 1 1 640 0 0
0 640 1 0 227 1 0
1 227 1 0 641 1 0
0 641 0 0 642 1 0
0 642 0 0 643 1 0
0 643 0 1 644 1 0
0 644 0 0 645 1 0
0 645 0 1 646 1 0
0 646 0 0 647 1 0
0 647 0 1 648 0 0
0 648 0 1 649 0 0
0 649 0 1 228 0 0
1 228 0 1 229 0 0
1 229 0 0 650 1 0
0 650 0 0 651 1 0
0 651 0 0 652 1 0
0 652 0 0 653 1 0
0 653 0 1 654 1 0
0 654 0 0 655 1 0
0 655 0 1 656 1 0
0 656 0 0 657 1 0
0 657 0 1 658 1 0
0 658 0 1 659 0 0
0 659 0 1 660 0 0
0 660 1 1 661 0 0
0 661 1 0 230 1 0
1 230 1 0 662 1 0
0 662 0 0 663 1 0
0 663 0 0 664 1 0
0 664 0 1 665 1 0
0 665 0 0 666 1 0
0 666 0 0 231 0 0
1 231 0 0 667 0 0
0 667 0 1 668 0 0
0 668 0 1 669 0 0
0 669 0 1 670 0 0
0 670 1 1 671 0 0
0 671 0 1 232 0 0
1 232 1 1 233 0 0
1 233 0 0 234 1 0
1 234 0 0 672 0 0
0 672 0 0 235 0 0
1 235 0 0 673 0 0
0 673 0 0 674 0 0
0 674 1 0 675 1 0
0 675 0 1 236 1 0
1 236 1 1 676 1 0
0 676 0 1 677 1 0
0 677 0 0 678 1 0
0 678 0 1 679 1 0
0 679 0 1 680 0 0
0 680 0 1 681 0 0
0 681 1 1 682 0 0
0 682 1 0 237 1 0
1 237 1 0 683 1 0
0 683 0 0 684 1 0
0 684 0 0 685 1 0
0 685 0 1 686 1 0
0 686 0 0 687 1 0
0 687 0 1 688 1 0
0 688 0 0 689 1 0
0 689 0 1 690 1 0
0 690 0 0 691 1 0
0 691 0 1 692 1 0
0 692 0 0 693 1 0
0 693 0 1 694 1 0
0 694 0 0 695 1 0
0 695 0 1 696 1 0
0 696 0 0 697 1 0
0 697 0 1 698 1 0
0 698 1 1 699 0 0
0 699 0 1 238 0 0
1 238 1 1 239 0 0
1 239 0 0 240 0 0
1 240 1 0 700 0 0
0 700 0 0 241 0 0
1 241 1 0 701 0 0
0 701 0 0 242 0 0
1 242 0 0 702 1 0
0 702 0 1 703 0 0
0 703 1 0 704 0 0
0 704 0 1 243 0 0
1 243 1 1 705 0 0
0 705 0 1 244 0 0
1 244 0 1 706 0 0
0 706 0 1 245 0 0
1 245 0 0 707 1 0
0 707 0 0 708 1 0
0 708 0 0 709 1 0
0 709 0 1 710 1 0
0 710 0 0 711 1 0
0 711 0 1 712 1 0
0 712 0 1 713 0 0
0 713 0 1 714 0 0
0 714 1 1 715 0 0
0 715 1 0 246 1 0
1 246 1 0 716 1 0
0 716 0 0 717 1 1

```

Made with ASCII\_only's program generator

# Answer
> 1 votes
# deflate, 79 bytes

eJyVkcsJADAIQ++ZIpD9dyxUqrGUgjlpHvglXdqCJymk1yEiaRXEIOXzuBHCiKObReUxUzYaMdt2wmTBg/FmNXndgLRbNvL7ifsLfMw6iQ==

# Answer
> 1 votes
# Brainf\***, ~~656~~ ~~652~~ 605 bytes

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

```

The loop at the start initiates the tape to

```
... 032  [035]  010 ...

```

Then the rest of the code outputs those characters.

(-47 bytes thanks to orthoplex)

# Answer
> 0 votes
# T-SQL, 244 bytes

**Golfed:**

```
DECLARE @ varchar(max)='MfFoDEDjBDGGAcACHDACCc@CIDACDc@CHDBCDc@CHDBCDc@CGDCCDc@CGDCCDc@CFKDc@CFKDc@CEDECDc@CECFCDcADBDKdBHIfFqFC 'WHILE'!'<@
SET @=stuff(@,1,1,'')+replicate(char(35-charindex(' ',@)%2*3),ascii(@)%32)+left('
',ascii(@)/97)PRINT @

```

**Ungolfed:**

```
DECLARE
 @ varchar(max)='MfFoDEDjBDGGAcACHDACCc@CIDACDc@CHDBCDc@CHDBCDc@CGDCCDc@CGDCCDc@CFKDc@CFKDc@CEDECDc@CECFCDcADBDKdBHIfFqFC '

WHILE'!'<@
  SET
    @=stuff(@,1,1,'')+
    replicate(char(35-charindex(' ',@)%2*3),ascii(@)%32)+
    left('
',ascii(@)/97)
PRINT @

```

**Try it online** ungolfed version

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


title: Tips for golfing in TeX/LaTeX

text:
# Question
Title: Tips for golfing in TeX/LaTeX
What tips do people have for golfing in TeX/LaTeX? Please post one tip per answer, each at least somewhat specific to TeX/LaTeX.

---

Context: I noticed this answer and that there is no tips question for TeX/LaTeX, so I'm creating this one. There's some overlap with the narrower question tips for golfing in TikZ (as TikZ is a specific macro package on top of TeX/LaTeX): answers to this question will probably also apply there, but not the other way around.

# Answer
**Consider internal LaTeX macros rather than the documented ones**

For example, `\roman` is a documented LaTeX macro that works on LaTeX counters. To turn `42` into `XLIV` you'd have to use something like

```
\newcounter{z}
\setcounter{z}{42}
\roman{z}

```

Instead, by looking up how `\roman` is implemented (use `\show\roman` to get this interactively, instead of reading the source files), one can see that it's implemented in terms of a useful macro called `\@roman`, and instead use that directly:

```
\catcode`@11
\@roman{42}

```

`\catcode`@11` is the golfy way of writing `\makeatletter` (clean way in LaTeX) or `\catcode`\@=11` (clean way in plain TeX). It's needed only once at the beginning, after this you can use macro names containing `@`.
> 16 votes

# Answer
**`~` can be used as a macro** (as can other active characters)

**Example**

Before:

```
\def\a{...some definition...} ... use \a...

```

After:

```
\def~{...some definition...} ... use ~...

```

**Explanation**: Generally macros in TeX are “control sequences”: you can define `\something` or `\a`. But you can go even shorter, by using an active character. The only active character that is present by default (in plain TeX / LaTeX) is `~` (used for “ties”, i.e. defined as `\penalty \@M \` in plain TeX (a penalty of 10000 followed by a space), and as `\nobreakspace {}` in LaTeX). But nothing stops you from redefining it for whatever purpose you need.

**Further**: you can do the same with any other character by setting its catcode to `\active` (13). For example, making `Z` an active character has a "cost" of 12 bytes: `\catcode`Z13`. Then you can use simply `Z` everywhere instead of a macro like `\z`. For some characters that start out with a special meaning, the direct backtick approach doesn't work and you need one more character: `\catcode`\Z13` or `\catcode90=13`.
> 13 votes

# Answer
**`\def` can match fixed patterns**

Let's say you had `\def\a #1 #2 {...some definition here...}`. Then when you call it on a string like `\a Act42, Scene26`, inside the macro the arguments may be assigned like #1 \<- `Act42,`, #2 \<- `Scene26` and then you'd have to do some further work to extract out the relevant parts. Instead, one could directly write

```
\def\a Act#1, Scene#2 {...some definition here...}

```

and then calling it as `\a Act42, Scene26` would directly set #1 \<- `42` and #2 \<- `26`.

(This is basically the definition of `\def`, but it's easy to forget as one doesn't typically do this in LaTeX, preferring to pass arguments into `{}` as if they were function calls.)
> 10 votes

# Answer
**Choosing between plain TeX and LaTeX**

A lot can be said about this, but in short, compare a typical plain TeX document that prints "Hello" with a typical LaTeX document for the same:

```
Hello
\bye

```

versus

```
\documentclass{article}
\begin{document}
Hello
\end{document}

```

The "cost" of LaTeX (wrt code golf) is obvious; the "benefit" of course is that LaTeX comes with a library of many pre-written macros and packages, some of which may be useful for the task at hand.
> 10 votes

# Answer
### `\input ...` is shorter than `\usepackage{...}`

For example, you can write

```
\input color

```

instead of

```
\usepackage{color}

```

which is 6 less bytes.
> 10 votes

# Answer
**If using LaTeX, use a short `documentclass`** (idea by Chris H)

Instead of starting with the typical

```
\documentclass{article}

```

one can choose shorter document classes like `book` or even

```
\documentclass{ecv}

```

or

```
\documentclass{tui}

```
> 8 votes

# Answer
Creating an environment called `myenvironment` generates the commands `\myenvironment` and `\endmyenvironment`. These are used internally to begin and end the environment. In some cases they can be used as shortcuts. For example, instead of

```
\begin{itemize}
\item abc
\end{itemize}

```

one can do

```
\itemize
\item abc
\enditemize

```

Not supported, not reliable, doesn't work in all cases, use at your own peril, etc. etc.
> 8 votes

# Answer
Run lines together. Line breaks are rarely needed in LaTeX/TeX, as compared to many long-form languages.
> 5 votes

# Answer
`\usepackage{packagea,packageb,packagec}` works, so long as you're not passing options to the packages.
> 5 votes

# Answer
**Use local `{` ... `}` groups wisely**

As pointed out in this answer, active characters like `~` can be used as a macro name. Unfortunately, `~` is the only active character by default, and changing the catcode for another character is expensive: `\catcode`!13` takes 12 bytes. If the new macro definition is only needed in a small region of your code, local groups can be a solution.

When TeX enters a new local group opened by `{`, it creates a new grouping level on the internal save stack. This means that all current macros and registers are saved. Any modifications to them (unless explicitly marked as `\global`) are now only being active until the group is closed by `}`. This means that `~` can be redefined within a group, used there with the new definition, and the old defintion will automatically be restored after the group has finished.

Here's an example:

```
\def~{abc}
~ -- {\def~{123}~} -- ~

```

This outputs

> abc - 123 - abc

An interesting side effect of this grouping mechanism is that the old values are still available inside the group until they are changed there. To illustrate that, imagine we want to print a number of characters based on the value of a counter, pad them with spaces up to a fixed length, and go on with the original counter value. This could be achieved by the following:

```
\newcount\x
\x=3
Print a char \the\x\ times,
{\x=-\x \advance\x 10 pad with \the\x\ spaces,}
and go on with x=\the\x.

```

which outputs

> Print a char 3 times, pad with 7 spaces, and go on with x=3.

This grouping behaviour is especially important if you want to use TeX's standard macros for looping `\loop ... \repeat` nested. These macros define internal commands and use them for determining how to proceed. Nesting them without putting the inner loop into braces will confuse the internal commands and lead to unexpected behaviour.
> 5 votes

# Answer
Some macros that you might expect to need braces round their arguments actually don't, especially when used inside another macro with `#1`-style arguments.

Most macros only need braces if there's more than one token (character or control sequence) in the argument.

```
\mymacro1          % equivalent to \mymacro{1}
\mymacro{12}       % equivalent to \mymacro{12}
\mymacro a         % equivalent to \mymacro{a}
\mymacro{ab}       % equivalent to \mymacro{ab}
\mymacro\foo       % equivalent to \mymacro{\foo}
\mymacro{\foo x}   % equivalent to \mymacro{\foo x}

```
> 3 votes

# Answer
If you need to use the same macro with a long name several times, you can use `\let` to define a shorter alias.

```
\let\a\mymacrowithalongname
\a{foo}\a{bar}\a{qux}

```

This saves two bytes on `\def\a{\mymacrowithalongname}`, if you don't need multiple tokens in the definition.

Instead of a macro name, you can have an active character to save on backslashes.

Note that `\let` doesn't only work with macro names but also with built-in primitives. For example, if you use a lot of `\ifnum ... \fi` constructs in your code, defining `\let\i\ifnum` and instead using `\i ... \fi` could save you a few bytes. This even works for `\let` itself: `\let\l\let`.
> 3 votes

# Answer
The advancement of counters, such as

```
\advance\u by 1
\multiply\u by 3
\divide\u by 2

```

also work as

```
\advance\u1        % \u = \u + 1
\advance\u-1       % \u = \u - 1
\multiply\u3       % \u = \u * 3
\multiply\u\u      % \u = \u * \u
\divide\u2         % \u = \u / 2

```

The same principle also works for initialisation:

```
\newcount\u\u1

```

sets the counter \u to 1.

Do note that these do need a whitespace character (linebreak or space) after them (or a `\relax`, but whitespace does the same) so the next command won't be ignored. For example,

```
\u1\the\u

```

does NOT print \u, but ignores the `\the` command.
> 2 votes

# Answer
`\enddocument` instead of `\end{document}` saves two characters
> 2 votes

---
Tags: code-golf, tips
---


title: The Clock Hands of Doom

text:
# Question
Title: The Clock Hands of Doom
You are chained to a chair. Underneath you is a huge volcano. A 12-hour clock next to you ticks ominously, and you see that it has wires leading from the back up to a chain, which will drop you into the center of the earth. Taped to the clock is a note:

> Each clock hand has an electrode. When both clock hands are in the same position, the power flows and you die. That is, unless you can tell me the exact time that this will occur, to the nearest minute.

You have a computer that knows every programming language. You need to create the shortest (this is , and standard loopholes are prohibited) program you can, and tell the evil scientist what the time will be. Your program should take input (in any method), consisting of the hour and minute. It should return the next hour and minute (in any method) that this occurs.

According to the OEIS page, the eleven overlap times are:

```
00:00:00 plus 0/11 s, 01:05:27 plus 3/11 s,
02:10:54 plus 6/11 s, 03:16:21 plus 9/11 s,
04:21:49 plus 1/11 s, 05:27:16 plus 4/11 s,
06:32:43 plus 7/11 s, 07:38:10 plus 10/11 s,
08:43:38 plus 2/11 s, 09:49:05 plus 5/11 s,
10:54:32 plus 8/11 s.

```

The next time would be 12:00:00. The seconds and their fractional parts are not needed for this challenge. Simply round to the nearest minute.

**Test cases:**

```
0:00 (Or 12:00) > 1:05
1:00 > 1:05
11:56 > 12:00 (Or 0:00)
6:45 > 7:38
5:00 > 5:27
6:30 > 6:33 (round up)

```

The program can be a function, or full program. I do not care if you choose `0:00` or `12:00`, and both are acceptable. Good luck!

# Answer
> 6 votes
# JavaScript (Node.js), ~~54~~ 47 bytes (round to the nearest)

*-7 bytes. Thanks @user202729*

```
a=>b=>[(a+=b>5.46*a)+a/11|0,a%12*65.46%60+.5|0]

```

Try it online!

---

# JavaScript (Node.js), ~~40~~ ~~33~~ 44 bytes (rounds towards 0)

*-3 bytes thanks to @Arnauld*

*-4 bytes thanks to @Kevin Cruijssen*

```
a=>b=>[(a+=b>5.46*a)+a/11|0,a%12*65.46%60|0]

```

**Explanation**

```
a=>b=>[(a+=b>5.46*a)+a/11|0,a%12*65.46%60|0]    Full Code
a                                               Hours
   b                                            Minutes
    =>[                    ,               ]    return array with
       (a+=        )                            add to the current hour
           b>5.46*a                             1 if the minute's clock hand has
                                                passed the hour's clock hand. Here we use
                                                equation 60*a/11 which is the same as 5.46*a
                    +a/11                       and add 1 when hour is 11
                         |0                     floor the result

                            a%12*65.46%60|0     Here we do equation ((720/11)*a) (mod 60)
                            a%12                In case of hour 12 we take 0
                                *65.46          multiply hour by 720/11 which can be shortened to
                                                65.46 to save 1 byte.
                                      %60       mod 60
                                         |0     floor the result

```

***Side note:*** *I'm pretty sure this can be golf down by someone with more knowledge at math. I barely know how to sum and multiply*

Try it online!

# Answer
> 5 votes
# , 31 bytes

```
0.5<.@+>:@<.&.(11r720*12 60&#.)

```

Try it online!

The way to round a number in J is to add `0.5` and take the floor (`<.`). Takes too many bytes...

---

# Explanation

`12 60&#.` (mixed base conversion) converts from an array of \[hour, minute\] to the minute passed since 0:00.

Note that starting from 0:00, every 12/11 hours (that is, 720/11 minutes), the two hands overlap once.

Therefore, given the minute value, just round it up to the nearest multiple of 720/11 (different from itself). This can be achieved by `*` it by 11/720 (J has rational number literal `11r720`), take the floor `<.`, increment `>:`, then multiply it by 720/11.

Note that "multiply by 11/720" and "multiply by 720/11" are 2 reverse action, as well as "convert from \[hour, minute\] to number of minute passed" and vice versa. Fortunately J has built-in `&.` (under), which reverses some action after applying a transformation.

After that just do the rounding: `0.5` `+` then `<.`.

# Answer
> 5 votes
# , 68 bytes

```
a=round(1:30*720/11);a[a>sum(scan()*c(60,1))][1]%/%c(60,1)%%c(12,60)

```

Try it online!

* -2 bytes thanks to Giuseppe
* +7 bytes due to missing rounding :(

Exploiting the equation :

```
same_position_minutes = 720/11 * index

```

where `index` is 0 for the first overlapping position (00:00), 1 for the 2nd and so on...

# Answer
> 4 votes
# , 88 bytes

```
i=scan();d=1+60*i[1]+i[2];while(abs(60*(h=d%/%60%%12)-11*(m=d%%60))>5){d=d+1};paste(h,m)

```

Try it online!

Increase time by one minute. Checks the angle. If not close enough, loops until a solution is found.

# Answer
> 3 votes
# Python 3, ~~80~~ 78 bytes

This is my first submission, so constructive criticism is welcome :)

*-2 bytes thanks to @Jo King*

```
def f(h,m):n=65.45;r=round(((60*h+m)//n%11+1)*n);print('%i:%02i'%(r//60,r%60))

```

Try it online! (78) ~~Try it online! (80)~~

# Answer
> 2 votes
# Java 8, ~~89~~ 82 bytes

```
(h,m)->(m=m<(m=(int)(h%12*720d/11%60))?m:(int)(++h%12*720d/11%60))*0+h%12%11+" "+m

```

Fixed. Will see if I can golf it later (probably by porting another answer)..

Try it online.

**Explanation:**

*TODO*

# Answer
> 2 votes
# C# (.NET Core), 70 bytes

```
(h,m)=>{h%=12;int n=(5*h+h/2)%60;return (m>n||h>10)?f(h+1,0):h+":"+n;}

```

Try it online!

I think it passes all test cases. Although the h=11 case is kind of ugly

**Explanation:**

```
(h,m)=>{ // Lambda receiving 2 integers
    h%=12; // Just to get rid of the 0/12 case
    int n=(5*h+h/2)%60; // get the minute at which the hands overlap
                        //for current hour.
    return
    (m>n||h>10)? // if current minute > n or h=11
        f(h+1,0) // it will happen next hour
    :
        h+":"+n; // return result
}

```

# Answer
> 2 votes
# Apl (Dyalog Unicode), 28 bytes

```
((⍳11),⍪0,+\∊5/⊂5 6)(⍸⌷1⊖⊣)⎕

```

Try it online!

---

# Explanation

`((⍳11),⍪0,+\∊5/⊂5 6)` is a matrix of times where the hands overlap (printed at the end of the tio link)
`(⍸⌷1⊖⊣)⎕` finds the interval in which the input is in the matrix and indexes below it wrapping around.

# Answer
> 1 votes
# JavaScript, 41 bytes

```
p=>q=>(p+=q>=(5.5*p|0),p%=11,[p,5.5*p|0])

```

```
f =
p=>q=>(p+=q>=(5.5*p|0),p%=11,[p,5.5*p|0])
```

```
<div oninput="o.value = f(+h.value)(+m.value).join(':')">
Input: <input type=number min=0 max=11 id=h style=width:40px value=0 autofocus>:<input type=number min=0 max=59 id=m style=width:40px value=0><br />
Output: <output id=o></output>
</div>
```

# Answer
> 1 votes
# Jelly, 25 bytes

```
‘2¦ɓ;W}Ṣi¹ịḷø5,6ẋ5ÄĖØ0W¤;

```

Try it online!

A monadic link that takes the time as a two-integer list and returns a two-integer list corresponding to the next time the hands are due to touch.

# Answer
> 0 votes
# Perl 6, 43 bytes

```
(* *60+*+33).round(65.45).round.polymod(60)

```

Try it online!

An anonymous Whatever lambda that takes two integers representing hours and minutes and returns the hours and minutes in reverse order. Right now it isn't consistent when you input an aligned time, whether it outputs the next aligned time or stays on the same one. I'm waiting on OP to respond on that matter, but right now I'm treating it as undefined.

### Explanation

```
(* *60+*+33)   # Converts the two inputs to number of minutes
            .round(65.45)   # Round to the nearest multiple of 65.45
                         .round  # Round to the nearest integer
                               .polymod(60) # Repeatedly modulo by 60 and return the list of results

```

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


title: More is less and less is more

text:
# Question
Title: More is less and less is more
Anybody can make the output of a program bigger by adding characters, so let's do the exact opposite.

Write a full program, an *inner* function or a snippet for a REPL environment in a language of your choice that satisfies the following criteria:

1. Your code must be at least 1 character long.
2. Running the original code produces **x** characters of output to STDOUT (or closest alternative), where **0 ≤ x \< +∞**.
3. Removing *any arbitrary single character* from the original code results again in valid code, which produces at least **x + 1** characters of output to STDOUT.
4. Neither the original code nor the modifications may produce any error output, be to STDOUT, STDERR, syslog or elsewhere. The only exceptions to this rule are compiler warnings.

Your program may not require any flags or settings to suppress the error output.

Your program may not contain any fatal errors, even if they don't produce any output.
5. Both the original code and the modifications must be deterministic and finish eventually (no infinite loops).
6. Neither the original code nor the modifications may require input of any kind.
7. Functions or snippets may not maintain any state between executions.

Considering that this task is trivial is some languages and downright impossible in others, this is a .

When voting, please take the "relative shortness" of the code into account, i.e., a shorter answer should be considered more creative than a longer answer *in the same language*.

# Answer
# Any REPL with caret XOR operation, 5 bytes

```
11^11

```

`11^11` is of course 0. The only other possibilities are `1^11` or `11^1` which are 10, or `1111` which produces itself.
> 99 votes

# Answer
# TI-BASIC, ~~3~~ 1

```
"

```

When the last line of a program is an expression, the calculator will display that expression. Otherwise, the calculator displays `Done` when the program finishes. The expression here is the empty string, but it could also work with any one-digit number.

### 2 bytes:

```
isClockOn

```

Same as the above but with a 2-byte token.

### 3 bytes:

```
ππ⁻¹

```

Prints `1` due to implied multiplication. Can be extended indefinitely by adding pairs of `⁻¹`'s. The below also work.

```
√(25
e^(πi
⁻ii
ii³
2ππ
cos(2π

```

### Longer solutions:

```
11/77►Frac
ᴇ⁻⁻44
cos(208341   //numerator of a convergent to pi; prints "-1"

```

There are probably also multi-line solutions but I can't find any.
> 57 votes

# Answer
# CJam, JavaScript, Python, etc, 18 bytes

```
8.8888888888888888

```

The outputs in CJam are:

```
8.8888888888888888 -> 8.88888888888889
8.888888888888888  -> 8.888888888888888
88888888888888888  -> 88888888888888888
.8888888888888888  -> 0.8888888888888888

```

JavaScript and Python work in similar ways. It isn't competitive in JavaScript and Python, but it's not easy to find a shorter one in CJam.
> 50 votes

# Answer
# Octave, 5 bytes

```
10:10

```

(x : y) gives the array of numbers between x and y in increments of 1, so between 10 and 10 the only element is 10:

```
> 10:10
ans = 10

```

When the second argument is less than the first, octave prints the empty matrix and its dimensions:

```
> 10:1
ans = [](1x0)

> 10:0
ans = [](1x0)

```

When a character is removed from the first number, there are more elements in the array:

```
> 1:10
ans = 1 2 3 4 5 6 7 8 9 10

> 0:10
ans = 0 1 2 3 4 5 6 7 8 9 10

```

When the colon is removed, the number returns itself:

```
> 1010
ans = 1010

```
> 31 votes

# Answer
# Microscript, 1 byte

```
h

```

This produces no ouput, as `h` suppresses the language's implicit printing. Removing the sole character produces a program whose output is `0\n`.

~~I'll try to come up with a better answer later.~~

**EDIT ON NOVEMBER 17:**

This also works in Microscript II, with the exception that, instead of yielding `0\n`, the empty program yields `null`.
> 30 votes

# Answer
# Pyth, 3 bytes

```
cGG

```

`G` is preinitialized with the lowercase letters in the alphabet. `c` is the split-function.

`cGG` splits the alphabet by occurrences of the alphabet, which ends in `['', '']` (8 bytes).

When the second parameter is missing, `c` splits the string by whitespaces, tabs or newlines. Since none of them appear in `G`, the output for `cG` is `['abcdefghijklmnopqrstuvwxyz']` (30 bytes).

And `GG` simply prints twice the alphabet on two seperate lines: `abcdefghijklmnopqrstuvwxyz\nabcdefghijklmnopqrstuvwxyz` (53 bytes).

Try it online: Demonstration
> 22 votes

# Answer
# Python REPL, 6 bytes

Not the shortest, but here's another floating point abuse answer:

```
>>> 1e308
1e+308
>>> 11308
11308
>>> 11e08
1100000000.0
>>> 11e38
1.1e+39
>>> 11e30
1.1e+31

```

But...

```
>>> 11e308
inf

```
> 17 votes

# Answer
**JavaScript (and a lot more), 5byte**

`44/44` or

```
44/44 -> 1
44/4  -> 11
4444  -> 4444
4/44  -> 0.09090909090909091

```
> 14 votes

# Answer
# CJam, 5

```
''''=

```

Try it online

```
''''=   compares two apostrophes and prints 1
'''=    prints '=
''''    prints ''

```
> 12 votes

# Answer
# Lenguage, 5 bytes

```
00000

```

The length of the program is 5 which corresponds to the brainf\*** program `,` reading an end of input character and terminating without output.

Removing any char results in the code `0000` which has a length of 4 corresponding to the brainf\*** program `.` printing out one character (codepoint `0`) and terminating.

The Unary equivalent would be `0000000000000` (13 zeros) because you have to prepend a leading `1` to the binary length of the code so `101` becomes `1101`.
> 12 votes

# Answer
# PHP, 6 bytes

I have been watching this group for a couple of weeks and am amazed of your programming techniques. Now I had to sign in, there is something I can do, sorry :-) However, this might be my last post here...

```
<?php

```

(note the space after second `p`)

This outputs empty string. Removing any character outputs the text without the character. Note it can produce HTML errors (content not rendered by browsers for eg. `<?ph`).

I also tried with the `echo` tag. ie. eg.:

```
<?= __LINE__;;

```

This one outputs `1`. If `=` is omitted, `<? __LINE__;;` is the output. However, removing any of the magic constant character will result in *E\_NOTICE*: Notice: Use of undefined constant **LNE** \- assumed '**LNE**' in...

If *notices* are not considered *errors* (point 4 of rules), this also applies :-)
> 10 votes

# Answer
# Python, 10 8 bytes

```
256**.25

```

Works in Python and friends. Thanks to Jakube for showing how to make it 2 bytes smaller.

From IDLE:

```
>>> 256**.25
4.0
>>> 26**.25
2.2581008643532257
>>> 56**.25
2.7355647997347607
>>> 25**.25
2.23606797749979
>>> 256*.25
64.0
>>> 256*.25
64.0
>>> 256**25
1606938044258990275541962092341162602522202993782792835301376L
>>> 256**.5
16.0
>>> 256**.2
3.0314331330207964

```

originally I had this (10 bytes):

```
14641**.25

```

From IDLE:

```
>>> 14641**.25
11.0
>>> 4641**.25
8.253780062553423
>>> 1641**.25
6.364688382085818
>>> 1441**.25
6.161209766937384
>>> 1461**.25
6.18247763499657
>>> 1464**.25
6.185648950548194
>>> 14641*.25
3660.25
>>> 14641*.25
3660.25
>>> 14641**25
137806123398222701841183371720896367762643312000384664331464775521549852095523076769401159497458526446001L
>>> 14641**.5
121.0
>>> 14641**.2
6.809483127522302

```

and on the same note:

```
121**.25*121**.25

```

works identically due to nice rounding by Python, in 17 bytes.

```
>>> 121**.25*121**.25
11.0
>>> 21**.25*121**.25
7.099882579628641
>>> 11**.25*121**.25
6.0401053545372365
>>> 12**.25*121**.25
6.172934291446435
>>> 121*.25*121**.25
100.32789990825084
>>> 121*.25*121**.25
100.32789990825084
>>> 121**25*121**.25
3.8934141282176105e+52
>>> 121**.5*121**.25
36.4828726939094
>>> 121**.2*121**.25
8.654727864164496
>>> 121**.25121**.25
29.821567222277217
>>> 121**.25*21**.25
7.099882579628641
>>> 121**.25*11**.25
6.0401053545372365
>>> 121**.25*12**.25
6.172934291446435
>>> 121**.25*121*.25
100.32789990825084
>>> 121**.25*121*.25
100.32789990825084
>>> 121**.25*121**25
3.8934141282176105e+52
>>> 121**.25*121**.5
36.4828726939094
>>> 121**.25*121**.2
8.654727864164496

```
> 10 votes

# Answer
# SWI-Prolog interpreter

```
__A=__A.

```

**Note: You cannot remove the final `.`**. Prolog interpreters will always look for a final period to run your query, so if we stick strictly to the rules of this contest and allow ourselves to remove the period it won't run, it will jump a line and wait for additional commands until one is ended by a period.

The original query `__A=__A.` outputs `true.`.

The query `_A=__A.` outputs `_A = '$VAR'('__A')`. Similar modifications (i.e. removing one `_` or one of the two `A`) will result in similar outputs.

Finally, the query `__A__A.` outputs in SWI-Prolog:

```
% ... 1,000,000 ............ 10,000,000 years later
%
%       >> 42 << (last release gives the question)

```
> 7 votes

# Answer
# K, 3 bytes

```
2!2

```

Outputs `0` in the REPL. Removing the first 2 outputs `0 1`, removing the exclamation results in `22`, and removing the last 2 results in a string that varies between K implementations but is always at least 2 characters (in oK, it's `(2!)`; according to @Dennis, Kona outputs `2!`).
> 5 votes

# Answer
# Sed, 1 byte

```
d

```

As `sed` requires an input stream, I'll propose a convention that the program itself should be supplied as input.

```
$ sed -e 'd' <<<'d' | wc -c
0
$ sed -e '' <<<'d' | wc -c
2

```

An alternative program is `x`, but that only changes from `1` to `2` bytes of output when deleted.
> 5 votes

# Answer
# MATLAB, ~~9~~ 7 bytes

It's 2 bytes longer than the other MATLAB/Octave answer, but I like it nonetheless, as it's a bit more complex.

Matlab's `'` operator is the complex conjugated transpose. Using this on a scalar imaginary number, you get `i' = -i`. As imaginary numbers can be written simply as `2i` one can do:

```
2i--2i'
ans =
     0

```

Removing any one of the characters will result in one of the below:

```
ans =
   0.0000 - 1.0000i
   2.0000 - 2.0000i
   0.0000 + 4.0000i
   0.0000 + 4.0000i
   0.0000 + 1.0000i
   2.0000 + 2.0000i
   0.0000 + 4.0000i

```
> 5 votes

# Answer
# GolfScript, 2 bytes

This answer is non-competing, but since it is the piece of code that inspired this challenge, I wanted to share it anyway.

```
:n

```

By default, all GolfScript programs print the entire stack, followed by a linefeed, by executing `puts` on the entire stack. The function `puts` itself is implemented as `{print n print}` in the interpreter, where `print` is an actual built-in and `n` is a variable that holds the string `"\n"` by default.

Now, a GolfScript program always pushes the input from STDIN on the stack. In this case, since there isn't any input, an empty string is pushed. The variable assignment `:n` saves that empty string in `n`, suppressing the implicit linefeed and making the output completely empty.

By eliminating `n`, you're left with the incomplete variable assignment `:` (you'd think that's a syntax error, but nope), so the implicit linefeed is printed as usual.

By eliminating `:`, you're left with `n`, which pushes a linefeed on the stack, so the program prints two linefeeds.
> 4 votes

# Answer
# J, 5 bytes

```
|5j12

```

Magnitude of the complex number `5 + 12i` in REPL.

```
   |5j12 NB. original, magnitude of the complex number `5 + 12i`
13
   5j12  NB. the complex number `5 + 12i`
5j12
   |j12  NB. magnitude of the undefined function j12
| j12
   |512  NB. magnitude of 512
512
   |5j2  NB. magnitude of 5 + 2i
5.38516
   |5j1  NB. magnitude of 5 + 1i
5.09902

```

.

# J, 9 bytes

```
%0.333333

```

Based on floating point precision, reciprocal and matrix inverse.

```
   %0.333333 NB. original, reciprocal of 0.333333
3
   0.333333  NB. 0.333333
0.333333
   %.333333  NB. matrix inverse of 333333
3e_6
   %0333333  NB. reciprocal of 333333
3e_6
   %0.33333  NB. reciprocal of 0.33333
3.00003

```

Try it online here.
> 4 votes

# Answer
# APL, J and possibly other variants, 3 bytes

```
--1

```

It outputs `1` in APL. `-1` outputs `¯1`, and `--` outputs the following in TryAPL:

```
┌┴┐
- -

```
> 4 votes

# Answer
# Mathematica, 3 bytes

```
4!0

```

---

```
4!0  ->  0    the factorial of 4, times 0
4!   ->  24   the factorial of 4
40   ->  40
!0   ->  !0   the logical not of 0, but 0 is not a boolean value

```
> 4 votes

# Answer
# Dyalog APL, 2 bytes

`⍴0` returns an empty string (length 0)

returns  (length 1)

`0` returns `0` (length 1)
> 3 votes

# Answer
# Swift (and a lot more), 8 bytes

```
93^99<84

```

output (4 chars):

```
true

```

When removing the nth character the output is:

```
n -> out
----------
0 -> false
1 -> false
2 -> false
3 -> false
4 -> false
5 -> 10077
6 -> false
7 -> false

```

There are 78 possible solutions like this in the format of `a^b<c`.

I think the goal of this challenge should be as many bytes as possible, because the more bytes, the more possible bytes to remove and therefore more difficult.
> 2 votes

# Answer
# MathGolf, 2 bytes

```
♂(

```

Try it online!

## Explanation

```
♂   Push 10
 (  Decrement TOS by 1

```

## Why does this work?

The regular output is `9`. If the `(` is removed, the output is 10. If the  is removed, the program implicitly pops a 0 from the stack to feed the `(` operator, which outputs `-1`.
> 2 votes

# Answer
# 05AB1E (legacy), 1 byte

Any single byte in 05AB1E (legacy) would work, except for `[` (infinite loop).

See here all possible outputs for all possible single-byte 05AB1E programs.

Removing that single byte so an empty program remains will output the content of info.txt to STDOUT instead by default.

Try it online.

---

# 05AB1E, 1 byte

```
?

```

Try it online.

Unfortunately an empty program in the new version of 05AB1E only outputs a 1-byte newline by default (Try it online), so almost none of the 1-byte characters are possible since they'll have to output nothing. The only possible program that outputs nothing (so also not the implicit newline) is `?` as far as I know.
> 2 votes

# Answer
# Clojure, 11 bytes

```
(defn x[]1)

```

At first I thought to just post a single character answer in the REPL like the other languages, e.g.

```
user=> 1
1

```

But the problem is that if you remove that character, the REPL doesn't do anything upon the enter keypress. So instead it had to be wrapped with a function as permitted by the question's rules. When you call this function, it returns 1. If you remove the only character in the function,

```
(defn x[])

```

the function returns `nil` which prints an additional two bytes.

```
user=> (defn x[]1)
#'user/x
user=> (x)
1
user=> (defn y[])
#'user/y
user=> (y)
nil

```
> 1 votes

# Answer
# Japt, 2 bytes

Try it online!

`A` is pre-initialized to 10, `É` subtracts 1, and the result is 1 byte: `9`.

Removing É results in the program `A`, which outputs A's value, `10`, so the result is 2 bytes.

Similarly, removing A results in just `É` which is interpreted as -1 and output as `-1`, so the result is 2 bytes.
> 0 votes

# Answer
# Runic Enchantments, 6 (modifiable) bytes

```
11-{{B\
/B~~@/
\00<
R"Error"@

```

Try it online!

Runic does not have a REPL environment and writing a full program to satisfy the constraints is not readily feasible (leading to either invalid programs or no output). So the portion of the code `11-{{B` is acting as an *inner function* and only this portion can be modified. The `B` instruction is close enough to a function pointer and return statement that this classification should be acceptable (as it jumps the IP to a position in the code as well as pushing a return location to the stack which may be accessed by a subsequent `B` or discarded).

* Standard output: `0`
* Removing either of the `1`s: `05`
* Removing the `-`: `11`
* Removing either `{`: `Error051`
* Removing the `B`: `120`

The final `\` on the end of the first line provides an external boundary around the inner function in the event that the return instruction is removed so that the IP doesn't go meandering all over everywhere willy nilly (and print no output).

Note that `Error051` is just an arbitrary string, I could put anything I wanted into that portion of the code and "Error" was an amusing result for having code that feks up the return coordinates and the IP teleports to an arbitrary location.
> 0 votes

---
Tags: popularity-contest, radiation-hardening
---


title: Divide Two Numbers Using Long Division

text:
# Question
Title: Divide Two Numbers Using Long Division
Your challenge is to divide two numbers using long division. The method we used to use in old days of school to divide two numbers.

Example here
You should **NOT** use `/` or any other division operator in your code.

Also, this is not

**Example:**

```
Input  : 4 2 (4 divided by 2)

Output : 2 0 (here 2 is quotient and 0 is remainder)

```

Another example

```
Input  : 7182 15 (7182 divided by 15)

Output : 478 12 (7170 is quotient and 12 is remainder)

```

The answer with most up-votes after 24 hours wins because this is a popularity contest.

# Answer
## C

Not exactly a long division - this answer uses the method used in the *real* old days.

```
#include <stdio.h>
#include <stdlib.h>
int main() {
    int a,b;
    scanf("%d %d", &a, &b);
    int *p=calloc(b, sizeof(int));
    int *q=p;
    while(a--) {
        (*p)++;
        if(p-q<b-1) p++;
        else p-=b-1;
    }
    p=q;
    int r=0, i;
    for(i=0; i<b; i++) r+=p[i]-p[b-1];
    printf("%d %d\n", p[b-1], r);
    return 0;
}

```

Explanation:

Suppose you are given `a` number of sheep and you need to split them up into `b` number of groups. The method used here is to assign each sheep into a different group until the total number of groups reaches `b`, then start from the first group again. This repeats until there are no more sheep. Then, the quotient will be the number of sheep in the last group, and the remainder will be the sum of the differences between each group and the last group.

An illustration for `8/3`:

```
       |Group 1 | Group 2 | Group 3
-------------------------------------
       | 1      | 2       | 3        // first sheep in group 1, second sheep in group 2, etc
       | 4      | 5       | 6
       | 7      | 8       |
-------------------------------------
total: | 3      | 3       | 2

```

So the quotient is 2 and the remainder is (3-2)+(3-2)=2.
> 13 votes

# Answer
# Bash + coreutils

Forget what you learned in school. Nobody uses long division. Its always important to chose the right tool for the job. `dd` is known by some as the swiss army knife of the command-line tools, so it really is the right tool for every job!:

```
#!/bin/bash

q=$(dd if=/dev/zero of=/dev/null ibs=$1 count=1 obs=$2 2>&1 | grep out | cut -d+ -f1)
r=$(( $1 - $(dd if=/dev/zero of=/dev/null bs=$q count=$2 2>&1 | grep bytes | cut -d' ' -f1) ))
echo $q $r

```

Output:

```
$ ./divide.sh 4 2
2 0
$ ./divide.sh 7182 15
478 12
$

```

---

Sorry, I know this is a subversive, trolly answer, but I just couldn't resist. Cue the downvotes...
> 9 votes

# Answer
# C

Long division! At least how a standard computer algorithm might do it, one binary digit (bit) at a time. Handles negatives, too.

```
#include <stdio.h>

#define INT_BITS (sizeof(int)*8)

typedef struct div_result div_result;
struct div_result {
    int quotient;
    int remainder;
};

div_result divide(int dividend, int divisor) {
    int negative = (dividend < 0) ^ (divisor < 0);

    if (divisor == 0) {
        result.quotient = dividend < 0 ? INT_MIN : INT_MAX;
        result.remainder = 0;
        return result;
    }

    if ((dividend == INT_MIN) && (divisor == -1)) {
        result.quotient = INT_MAX;
        result.remainder = 0;
        return result;
    }

    if (dividend < 0) {
        dividend = -dividend;
    }
    if (divisor < 0) {
        divisor = -divisor;
    }

    int quotient = 0, remainder = 0;

    for (int i = 0; i < sizeof(int)*8; i++) {
        quotient <<= 1;

        remainder <<= 1;
        remainder += (dividend >> (INT_BITS - 1)) & 1;
        dividend <<= 1;

        if (remainder >= divisor) {
            remainder -= divisor;
            quotient++;
        }
    }

    div_result result;
    if (negative) {
        result.quotient = -quotient;
        result.remainder = -remainder;
    } else {
        result.quotient = quotient;
        result.remainder = remainder;
    }
    return result;
}

int main() {
    int dividend, divisor;
    scanf("%i%i", &dividend, &divisor);

    div_result result = divide(dividend, divisor);
    printf("%i %i\r\n", result.quotient, result.remainder);
}

```

It can be seen in action here. I chose to handle negative results to be symmetrical to positive results, but with both the quotient and remainder negative.

Handling of edge cases is done with best effort. Division by zero returns the integer of highest magnitude with the same sign as the dividend (that's `INT_MIN` or `INT_MAX`), and `INT_MIN / -1` returns `INT_MAX`.
> 7 votes

# Answer
## Julia

Here is an entry that not only is free from division but doesn't employ any multiplication either. It does the long division quite literally by using more string manipulation than arithmetic. It also prints out an ASCII version of what the long-division would look like on a sheet of paper (at least the way I learned it)

```
function divide(x,y)
    if y > x
        return 0, x
    end

    x = "$x"
    q = ""
    r = ""

    workings = ""

    for i = 1:length(x)
        r = "$(r)0"
        num = int(r) + int(x[i:i])
        sum = 0
        m = 0
        while sum+y <= num
            m += 1
            sum += y
        end
        r = string(num-sum)
        q = "$q$m"
        ls = length(string(sum))
        workings *= repeat(" ", i-ls) * "-$sum\n"
        workings *= repeat(" ", i+1-ls) * repeat("-", ls) * "\n"
        workings *= repeat(" ", i+1-length(r)) * r * (i >= length(x) ? "" : x[i+1:i+1]) * "\n"
    end

    workings *= repeat(" ", length(x)-length(r)+1) * repeat("=", length(r)) * "\n"

    print(" $x : $y = $(int(q)) R $r\n$workings")
    int(q), int(r)
end

```

Results (the `(q,r)` line at the end is just Julia printing the result of the function call):

```
> divide(5,3)         > divide(4138,17)           > divide(7182,15)

 5 : 3 = 1 R 2         4138 : 17 = 243 R 7         7182 : 15 = 478 R 12
-3                    -0                          -0
 -                     -                           -
 2                     41                          71
 =                    -34                         -60
                       --                          --
(1,2)                   73                         118
                       -68                        -105
                        --                         ---
                         58                         132
                        -51                        -120
                         --                         ---
                          7                          12
                          =                          ==

                      (243,7)                     (478,12)

```

I suppose I could get rid of the remaining arithmetic by using a unary number system, `repeat` and `length` but that feels more like multiplying than not using arithmetic.

Don't even try dividing by zero! (Seriously, who would do long division for that?) Also don't try negative numbers.
> 6 votes

# Answer
## Python

```
def divide(a, b):
    q = 0
    while a >= b:
       a -= b
       q += 1
    return (q, a)

```
> 4 votes

# Answer
# C#

Not exactly golfing, but IMO it's pretty easy to follow. It only uses the `/` operator after it has broken the dividend down into smaller sections. It performs division in the "old" way. For example, for `1907 / 12`, it takes `19` and divides it by `12`, then carries the remainder `7` over, divides `70` (from `707`) by `12`, etc.

```
string divisor = "12";
string dividend = "1907";
string output = "";
do
{
    double dd = Convert.ToDouble(dividend.Substring(0, divisor.Length));
    double dr = Convert.ToDouble(divisor);
    if (dd >= dr)
    {
        string s = (dd / dr).ToString();
        output += s.Substring(0, s.Contains(".") ? s.IndexOf(".") : s.Length);
        dividend = dd % dr + dividend.Substring(divisor.Length);
    }
    else
    {
        double d2 = Convert.ToDouble(dividend.Substring(0, divisor.Length + 1));
        string s = (d2 / dr).ToString();
        output += s.Substring(0, s.Contains(".") ? s.IndexOf(".") : s.Length);
        dividend = d2 % dr + dividend.Substring(divisor.Length + 1);
     }
 } while (Convert.ToDouble(dividend) >= Convert.ToDouble(divisor))
 for (int i = 0; i < dividend.Length - 1; i++ )
     if (dividend[i].ToString() == "0") output += "0";
 dividend = Convert.ToInt32(dividend).ToString();
 Console.WriteLine("result: " + output + " r." + dividend);

```
> 3 votes

# Answer
## D

Horribly roundabout method that has more steps than is probably necessary to divide a number, but there you are.

```
import std.stdio;
import std.traits : isIntegral, isUnsigned;
import std.conv   : to;

TNum divide( TNum )( TNum dividend, TNum divisor, out TNum remainder ) if( isIntegral!TNum )
{
    TNum quot = 0,
         rem  = dividend,
         prod = divisor,
         t    = 1,
         max  = ( ( TNum.sizeof * 8 ) - 1 ) ^^ 2;

    while( t < max  && prod < rem )
    {
        prod = prod * 2;
        t    = t    * 2;
    }

    while( t >= 1 )
    {
        if( prod <= rem )
        {
            quot = quot + t;
            rem  = rem - prod;
        }

        static if( isUnsigned!TNum )
        {
            prod >>>= 1;
            t    >>>= 1;
        }
        else
        {
            prod >>= 1;
            t    >>= 1;
        }
    }

    remainder = rem;
    return quot;
}

void main( string[] args )
{
    if( args.length < 3 )
        return;

    long dividend  = args[1].to!long;
    long divisor   = args[2].to!long;
    long remainder = 0;
    long result    = divide( dividend, divisor, remainder );

    if( remainder == 0 )
        "%s / %s = %s".writefln( dividend, divisor, result );
    else
        "%s / %s = %s (r %s)".writefln( dividend, divisor, result, remainder );
}

```

Obviously `/` appears in the code, but it's in a string and is just for output. There's no string interpolation in D, so it's not diving anything.
> 2 votes

# Answer
# 64 characters in Ruby

```
def d a,b;x=0;while((x+1)*b<=a);x+=1;end;puts"#{x} #{a-x*b}";end

```

Example:

```
pry(main)> d 31,6
5 1
=> nil

```
> 2 votes

# Answer
**C 371 with whitespaces**

Includes cases for div by zero and divisor\<0. Uses subtraction loop.

```
#include <stdio.h>
int a, b, n, r;
void e(int i, int j){ printf("Output: %d %d\n", i, j); }
void g()
{
    if (scanf_s("%d %d", &a, &b))
    {
        r = 1;
        if (b < 0){ r = -1; b = r*b; }
        if (!b) e(0, 0);
        else{
            if (b>a){
                n = 0;
            }
            else{
                n = 1;
                while ((a -= b) >= b){
                    n++;
                }

            }
            e(r*n, a);
        }
    }
}

int main(){ g();}

```
> 2 votes

# Answer
## Brainfuck

*works only for numbers between 1 and 9*

Do not fit the rules, so I don't expect to win but answers in brainfuck are always awesome.

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

```

Based on `divmod` method

Test it here (and try to change input) : http://ideone.com/9L2yYf

Some tests :

> 74 returns 13
> 82 returns 40
> 92 returns 41
> 2 votes

# Answer
# C

Sorry for the bulky code, I am still a noob. The idea is to grab the first piece of bits from n such that k \< bits, then extract each bit of n from that point on and update remainder and quotient along the way.

```
#include <stdio.h>

unsigned int rightMostBit(unsigned int n){
   unsigned int bitmask=0x1 << 31;
   int position=31;
   while((bitmask & n)==0 && position>=0){
        position-=1;
        bitmask = bitmask>>1;
   }
   return position;
}

unsigned int extractBits(unsigned int n, unsigned int start, unsigned int end){
    unsigned int unitMask=0x1;
    unsigned int mask=unitMask << start;
    for(int i=start;i<end;i++){
        mask= (mask | (mask << 1));
    }
    return  ((mask &  n) >> start);
}

void longDivision(unsigned int n, unsigned int k)
{
      unsigned int q=0;
      unsigned int head=rightMostBit(n);
      int tail=head;
      unsigned int r=extractBits(n,tail,head);
      while(k>r && tail>=0){
            tail-=1;
            r=extractBits(n,tail,head);
      }

      unsigned int pointMask= 0x1 << tail;

      while(pointMask>0) //scan all bits of n
      {
           if(k<= r){ //If k less than r, we can do division
              r-= k ; //subtraction
              q=q << 1; //make space
              q = q | 0x1;  //add a 1 to quotient
           }else{
                q=q << 1; //make space
                q= q | 0x0; //k > r, so add 0 to quotient
           }
           pointMask=pointMask >> 1;
           if(pointMask!=0){
                if((pointMask & n)){
                     r=((r << 1) | 1);
                }else{
                     r=((r << 1) | 0);
                }
           }
      }
  printf("quotient: %d, remainder: %d \n",q,r);
}

```
> 2 votes

# Answer
**Edited:170 with Excel VBA:**

```
Sub Long_Div(n As Integer, d As Integer)
j = 1
If d <> 0 Then
If (n * d) < 0 Then
j = -1
End If
Do While (Abs(n) >= Abs(d))
n = Abs(n) - Abs(d)
i = i + 1
Loop

MsgBox i * j & " " & n
Else:
MsgBox "can't divide by zero"
End If
End Sub

```
> 2 votes

# Answer
# Python

# Advantages:

* Go as Precise as you want or can handle
* Find out the repetitiveness from the quotient
* Fast

Late to the party but here you go:

```
def ManualDivision(Dividend, Divisor, acQPrecision, BreakOnRepetitive):

    Repetitive = False
    RepetitiveIndex = 0
    bcQComplete = False
    acQComplete = False
    bcQ = ''   #before comma Quotient
    acQ = ''   #after comma Quotient
    history = []
    a = 0
    b = 0

    while (not bcQComplete or not acQComplete):
        if not bcQComplete:
            for digit in map(int, str(Dividend)):
                a = int(str(a) + str(digit))
                if a in history:
                    if not Repetitive:
                        Repetitive = True
                        RepetitiveIndex = len(history) - len(bcQ)
                    if BreakOnRepetitive:
                        break
                else:
                    history.append(a)
                if a < Divisor:
                    b = 0
                    bcQ += '0'
                else:
                    pQ = 0
                    result = a - Divisor
                    while result >= 1:
                        pQ += 1
                        result -= Divisor
                    b = pQ * Divisor
                    bcQ += str(pQ)
                a -= b
            bcQComplete = True

        if not acQComplete:
            acQPrecision -= 1
            if acQPrecision <= 0:
                acQComplete = True
            a = int(str(a) + str('0'))
            if a in history:
                if not Repetitive:
                    Repetitive = True
                    RepetitiveIndex = len(history) - len(bcQ)
                if BreakOnRepetitive:
                    break
            else:
                history.append(a)
            if a < Divisor:
                b = 0
                acQ += '0'
            else:
                pQ = 0
                result = a - Divisor
                while result >= 1:
                    pQ += 1
                    result -= Divisor
                b = pQ * Divisor
                acQ += str(pQ)
            a-=b
       return '{0}.{1} \nRepetitive: {2} from position {3} acQ \nHistory:{4}'.format(bcQ, acQ, Repetitive, RepetitiveIndex, history)

```

# Result

```
Quotient = ManualDivision(91,256,100,False) #Dividend = 91, Divisor = 256, precision= 100, breakonrepetitive=False
print(Quotient)

```

> 00.3554687499999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999
>
> Repetitive: True from position 9 acQ
>
> History:\[9, 91, 910, 1420, 1400, 1200, 1760, 2240, 1920, 1280, 2560\]
> 2 votes

# Answer
## Python

Using recursion

```
def divide(a, b, q=0):
    if a < b:
        return (q, a)
    return divide(a - b, b, q+1)

```
> 1 votes

---
Tags: popularity-contest, math, division
---