title: Print the Oscars Best Picture Winner

text:
# Question
Title: Print the Oscars Best Picture Winner
This challenge is in tribute to the winner of Best Picture at the Oscars 2017, ~~La La Land~~ Moonlight!

---

Your challenge is to print the text

```
La La Land
```
pause one second, then change the text to show
```
~~La La Land~~ Moonlight
```
The original text (La La Land) **must have a strikethrough**. This can be achieved either by clearing the screen, drawing on top of the original text, or by any other clever solutions.

This is a so lowest bytes wins. Standard code-golf rules apply.

# Answer
# Python (137 Bytes)

```
from turtle import *;import time;write("La La Land");time.sleep(1);clearscreen();write("\u0336".join("La La Land ")+" Moonlight");done()

```
> 0 votes

# Answer
# Vim, 37 bytes

```
3iLa <esc>snd<esc>gs:s/./&<C-v>u336/g
A Moonlight

```

A fairly straightforward solution.

Here is an animation of it running:
> 26 votes

# Answer
# HTML, ~~153~~ 148 bytes

Using CSS animation. Tested on Firefox and Chrome only.

```
<s>La La Land</s> <b>Moonlight<style>@keyframes l{0%{text-decoration:none}}@keyframes m{0%{opacity:0}}b,s{animation:m 0s 1s both}s{animation-name:l}
```
> 25 votes

# Answer
# HTML + JavaScript, 18 + 59 = 77 bytes

```
setTimeout('O.innerHTML="<s>La La Land</s> Moonlight"',1e3)
```

```
<p id=O>La La Land
```

Sadly, there doesn't seem to be an efficient way to reuse `O.innerHTML`...
> 19 votes

# Answer
# Octave, ~~81~~ 66 bytes

*15 bytes saved thanks to @Stewie*

```
text(0,.5,'La La Land');pause(1);text(0,.5,'---------- Moonlight')

```

Online Demo Here.

While the demo shows two separate plots, when run in the desktop version of MATLAB, it shows the first plot, waits 1 second, and then adds the second string to the same plot.

Since Octave doesn't have support for strike through text, I have instead opted to display the text within an `axes` object in a figure and display a "strikethrough" by displaying `'--------'` on top of the initial text (initial idea by @Stewie). Previously, I had actually plotted a `line` object to strike through `'La La Land'`
> 19 votes

# Answer
# Jelly, 31 bytes

```
“XSøjĠḌ⁻Ça»Œts⁵µṀȮ⁸œS“Æɓ9m“ɓm”ż

```

Tested with xterm and `LANG=en_US`. Doesn't work on TIO for several reasons.

### Hexdump

```
00000000: 58 53 1d 6a c4 ad 8b 0e 61 fb 13 74 73 85 09 c8  XS.j....a..ts...
00000010: ca 88 1e 53 fe 0d 9b 39 6d fe 9b 6d ff f9        ...S...9m..m..

```

### Verification

### Background

This answer makes use of control characters and ANSI escape sequences.

* `0d` (`<CR>`) is used to return to the beginning of the liner after printing **La La Land**.
* `9b 39 6d` (`<CSI> 9 m`) is used to activate strike-through text before printing **La La Land** for the second time.
* `9b 6d` (`<CSI> m`) is used to reset foreground and background to default mode, thus deactivating strike-through, before printing **Moonlight**.

### How it works

```
“XSøjĠḌ⁻Ça»Œts⁵µṀȮ⁸œS“Æɓ9m“ɓm”ż Main link. No arguments.

“XSøjĠḌ⁻Ça»                     Index into Jelly's inbuilt dictionary to yield
                                "LA LA Land moonlight".
           Œt                   Convert to title case, yielding the string
                                "La La Land Moonlight".
             s⁵                 Split into chunks of length 10, yielding
                                A =: ["La La Land", " Moonlight"].
               µ                Begin a new chain with argument A.
                Ṁ               Take the maximum, yielding "La La Land".
                 Ȯ              Output; print "La La Land".
                  ⁸œS           Sleep for bool("La La Land") seconds and yield A.
                     “Æɓ9m“ɓm”ż Zip ["\r\x9b9m", "\x9bm"] with A, yielding
                                [["\r\x9b9m","La La Land"],["\x9bm"," Moonlight"]].
                                (implicit) Flatten and print.

```
> 13 votes

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

-4 pts thanks to Riley

`echo La La Land;sleep 1;echo -e "\r\e[9mLa La Land\e[0m Moonlight"`

Credits to Sylvain Pineau's answer on AskUbuntu for the strikethrough
> 10 votes

# Answer
## QBasic, 61 bytes

```
SCREEN 9
?"La La Land";
SLEEP 1
LINE(0,7)-(80,7)
?" Moonlight

```

Using graphics mode, draw an actual line through the text. Here's what it looks like in QB64:

The code should be pretty self-explanatory, but here's an ungolfed version:

```
SCREEN 9             ' One of several graphics modes
PRINT "La La Land";  ' The semicolon suppresses the trailing newline
SLEEP 1
LINE (0,7)-(80,7)
PRINT " Moonlight"

```
> 9 votes

# Answer
# MATL, 46 bytes

```
'La La Land'tDlY.ttv45HY(`t@Y)' Moonlight'hXxDT

```

Since MATL doesn't have support for control codes or text formatting, this solution simply alternates between `'La La Land'` and `'-----------'` as fast as possible to simulate strikethrough text.

**Explanation**

```
'La La Land'   % Push the string literal to the stack
tD             % Duplicate this string and display
tv             % Stack a version of this string on top of another
45HY(          % Replace the second one with '----------'
`              % Do...while loop
  t            % Duplicate the 2D character array
  @Y)          % Grab the row corresponding to the loop index (modular indexing)
  ' Moonlight' % Push the string literal to the stack
  h            % Horizontally concatenate the two
  Xx           % Clear the display
  D            % Display the string
  T            % Push a literal TRUE to the stack to make it an infinite loop

```
> 8 votes

# Answer
# Bash \+ pv, 50 bytes

```
printf ♪La\ La\ Land›%b 9m\\0 m\ Moonlight|pv -0L1

```

This builds on @DigitalTrauma's Bash answer.

represents a carriage return (**0x0d**),  a CSI byte (**0x9b**).

### Hexdump

```
0000000: 70 72 69 6e 74 66 20 0d 4c 61 5c 20 4c 61 5c 20  printf .La\ La\
0000010: 4c 61 6e 64 9b 25 62 20 39 6d 5c 5c 30 20 6d 5c  Land.%b 9m\\0 m\
0000020: 20 4d 6f 6f 6e 6c 69 67 68 74 7c 70 76 20 2d 30   Moonlight|pv -0
0000030: 4c 31                                            L1

```

### Verification

### How it works

*printf* repeats its format string as many times as needed to exhaust its other arguments. Since there is one occurrence of `%b` and two arguments (`9m\\0` and `m\ Moonlight`), it will produce the following byte stream.

```
\rLa La Land\x9b9m\0\rLa La Land\x9bm Moonlight

```

This does the following.

* `\r` brings the cursor to the start of the line.
* `La La Land` is printed verbatim.
* `\x9b9m` activates strike-through text.
* `\0` sets an end-of-line marker for `pv -0`.
* `\rLa La Land` does the same as before.
* `\x9bm` reset foreground and background to default mode, deactivating strike-through.
* `Moonlight` is printed verbatim.

Finally, `pv -0L1` prints one null-terminated line per second, introducing the desired delay.
> 6 votes

# Answer
# Pyth - 47 bytes

Does the strikethrough thing now.

```

K"La La Land".d_1"\033c"+j"\u0336"K" Moonlight

```
> 3 votes

# Answer
## C ~~87~~ 86 bytes

```
f(){char*s="La La Land";puts(s);printf("\e[9m%s\e[0m",s);sleep(1);puts(" Moonlight");}

```

Ungolfed version:

```
void f()
{
  char *s="La La Land";
  puts(s);
  printf("\e[9m%s\e[0m",s);
  sleep(1);
  puts(" Moonlight");

}

```
> 3 votes

# Answer
## GNU sed \+ sleep, ~~63~~ 58 bytes

*Edit:* saved 5 bytes, based on Digital Trauma's comments

Waiting between two print statements can't be done using sed alone, and as such I call `sleep 1`. It is possible to do a system call from sed, using the `e` command, which is a GNU extension.

```
s:$:La La Land:p
esleep 1
s:.:&̶:g
s:.*:\c[[A& Moonlight:

```

To create strike-through text (line 3), a "combining long stroke overlay", U+0336, is appended to each character. After that, I move the cursor up 1 line, effectively replacing the old text when printing something new, using the so called ANSI Escape Sequences. These are interpreted by the terminal as special formatting commands. You can find more information about them here.

**Explanation:**

```
s:$:La La Land:p         # add "La La Land" to pattern space and print it
esleep 1                 # run system command 'sleep 1'
s:.:&̶:g                  # append U+0336 after each character (strike-through)
s:.*:\c[[A& Moonlight:   # '\c[[A' is '(escape)[A', ANSI code to move the cursor
                         #up 1 line. Then append ' Moonlight' and print on exit.

```
> 3 votes

# Answer
# PHP (86 75 69 Bytes)

```
La La Land<?=sleep(1)?:"\rL̶a̶ ̶L̶a̶ ̶L̶a̶n̶d̶ Moonlight";

```

Uses UTF-8 character U+0336 for the strikethrough.

Edit: Saved 17 bytes with the suggestions @Titus commented
> 3 votes

# Answer
# Java 7, ~~207~~ ~~206~~ ~~171~~ 139 bytes

```
void c()throws Exception{System.out.print("La La Land");Thread.sleep(1000);System.out.print("\rL̶a̶ ̶L̶a̶ ̶L̶a̶n̶d̶ Moonlight");}

```

I'm kinda cheating with this first answer, because I use strike-through unicode.

**Explanation:**

```
void c() throws Exception{         // Method (throws is necessary due to Thread.sleep)
  System.out.print("La La Land");  //  Show initial text
  Thread.sleep(1000);              //  Wait 1 second
  System.out.print("\r             //  Move 'cursor' to the start of the line so we can overwrite the current text
    L̶a̶ ̶L̶a̶ ̶L̶a̶n̶d̶ Moonlight");        //  and print new text
}                                  // End of method

```

---

# Java 7 (with AWT), ~~444~~ ~~429~~ 341 bytes

Crossed out 444 is still regular 444 ;(

```
import java.awt.*;import java.text.*;void m(){new Frame(){public void paint(Graphics g){g.drawString("La La Land",9,50);try{Thread.sleep(1000);}catch(Exception e){}AttributedString s=new AttributedString("La La Land Moonlight");s.addAttribute(java.awt.font.TextAttribute.STRIKETHROUGH,1>0,0,10);g.drawString(s.getIterator(),9,50);}}.show();}

```

Since Java console doesn't have any markup like strike-through, you'll have to use Java AWT. And well, if you thought Java Console was already verbose, then this is even worse (I know, I know, most of you couldn't even imagined Java 7 being any worse..)

**Explanation:**

```
import java.awt.*;                                         // import used for Frame and Graphics
import java.text.*;                                        // Import used for all AttributedStrings
void m(){                                                  // method
  new Frame(){                                             //  Frame
    public void paint(Graphics g){                         //   Overridden paint method
      g.drawString("La La Land", 9, 50);                   //    Show the initial text
      try{
        Thread.sleep(1000);                                //    Wait 1 second
      }catch(Exception e){}                                //    Thread.sleep requires a try-catch..
      AttributedString s
          = new AttributedString("La La Land Moonlight");  //    Object to add markup to text
      s.addAttribute(
        java.awt.font.TextAttribute.STRIKETHROUGH,         //    Strike-through attribute
        1>0,//true                                         //    Mandatory parameter before we can specify the length
        0, 10);                                            //    From length 0 to 10 (length of "La La Land")
      g.drawString(s.getIterator(), 9, 50);                //    Show this new text with strike-through part
    }                                                      //   End of paint method
  }.show();                                                //  Show Frame
}                                                          // End of method

```

**Output gif:**
> 3 votes

# Answer
# HTML + JavaScript, 10 + 63 = 73 bytes

```
setTimeout("document.write('<s>La La Land</s> Moonlight')",1e3)
```

```
La La Land
```
> 3 votes

# Answer
# HTML + JavaScript, 100 bytes

```
La La Land<script>setTimeout(function(){document.write("<s>La La Land</s> Moonlight")},1e3)</script>

```

```
setTimeout(function(){document.write("<s>La La Land</s> Moonlight")},1e3);
```

```
La La Land
```
> 3 votes

# Answer
# Python 3, 90 bytes

Use Unicode (U+0336) to strike-through, because the macOS terminal doesn't support that `\e[9m` command.

```
import time
s='La La Land '
print(s,end='\r')
time.sleep(1)
print('̶'.join(s),'Moonlight')

```
> 2 votes

# Answer
# Python3, 99 bytes

```
import time
l='La La Land'
s='\u0336'
print(l,end="\r")
time.sleep(1)
print(s.join(l)+' Moonlight')

```
> 2 votes

# Answer
# Arduino, ~~332~~ 331 bytes

Not competing, just for the fun.

```
#include<LiquidCrystal.h>
LiquidCrystal lcd(7,8,9,10,11,12);String a="La La Land";String b="-- -- ----";void setup(){lcd.begin(16,2);}void loop(){lcd.home();lcd.print(a);delay(1000);lcd.clear();lcd.print(b);lcd.setCursor(0,2);lcd.print("Moonlight");while(1){delay(150);lcd.home();lcd.print(a);delay(150);lcd.home();lcd.print(b);}}

```

Bill of Materials:

* 1 x Arduino Uno
* 1 x LCD 16 x 2
* 1 x 10K Potentiometer
* 1 x 180 ohm Resistor
> 2 votes

# Answer
# Bash + pv, 62

```
l="La La Land"
printf "$l\0\r\e[9m$l\e[0m Moonlight"|pv -0qlL1

```
> 1 votes

# Answer
# SmileBASIC, 45 bytes

**One less byte thanks to 12Me21's magic period trick.**

As far as I'm aware SB doesn't have strikethrough characters, so I used `GLINE` instead. Obviously assumes a clear display, use `ACLS` if you need to.

```
?"La La Land
WAIT 60GLINE.,4,79,4?" Moonlight

```
> 1 votes

# Answer
# AHK, 102 bytes

```
s=La La Land
Send,%s%
Sleep,1000
Send,^a{Del}
Loop,Parse,s
Send,%A_LoopField%{U+0336}
Send,` Moonlight

```

I cheated a bit to get strikethrough text by using the combining long stroke overlay unicode character. This may create an odd appearance depending on your setup. Notepad gives a good appearance.

---

AutoHotkey is clearly not the most efficient language for this but it was a fun challenge. Be careful where you run it because it doesn't create it's own display and wipes all the text of whatever window is active.
> 1 votes

# Answer
# Swift, 392 bytes

Swift+UIKit is really not ideal for golfing! Run this in a XCode playground and the result will be shown in the preview pane.

```
import UIKit
import PlaygroundSupport
let l=UILabel(frame:CGRect(x:0,y:0,width:200,height:20))
l.textColor=UIColor.red
let m="La La Land"
let n=" Moonlight"
l.text=m
DispatchQueue.main.asyncAfter(deadline:.now()+1){
let a=NSMutableAttributedString(string:m+n)
a.addAttribute("NSStrikethrough",value:1,range:NSRange(location:0,length:10))
l.attributedText=a
}
PlaygroundPage.current.liveView=l

```
> 1 votes

# Answer
# Jelly, 41 bytes

```
“ñ[“m‘Ọj
“¡ṭḊßȥṡoẋ»¹13Ọ;9Ç¤;;0Ç¤;“"dE»œS1

```

Doesn't work on online interpreter.
> 0 votes

# Answer
# TI-BASIC, ~~57~~ 53 bytes

```
:" LA
:Text(3,4,Ans+Ans+Ans+"ND
:Pause "",1
:Line(-9,8,-2,8
:Text(3,41,"MOONLIGHT

```

Note that this uses the TI-84+ CE ability with the newest OS to pause for 1 second. This will return a synthax error on the TI-84+. For testing, you can omit the 1 second pause by removing that line. Also remember to press Zoom, 6 first so that you are on default window settings, otherwise the line command won't work.
> 0 votes

# Answer
# SpecBAS - 58 bytes

```
1  ?"La La Land ";
2 WAIT 1e3
3 DRAW 0,4;80,0
4  ?"Moonlight"

```

Each character is 8x8 pixels, so draws a line from 0,4 to the relative position 80,4 (80 added to first coordinate and 0 to second so it stays on same line).
> 0 votes

# Answer
# OIL, 76 bytes

```
↩⎋[9m
La La Land
⎋[0m Moonlight
4
1
10
20
4
14
10
9
20
6
5
4
0
4
1
4
2
89999

```

Replace the  with an escape character and `↩` with a carriage return. OIL lacks any kind of sleep command, so I emulate it using a loop that counts down from 89999 to 1. It takes about one second on my computer, but it may not on yours.

The first 3 lines are ignored by the interpreter, it then prints (`4`) the second line (line 1; "La La Land"). The following structure is the loop that decrements the large number at the end until it's equal to 1. In the end, I just print the first 3 lines.
> 0 votes

# Answer
# PHP, not competing (64 bytes)

```
<?=$s="\rLa La Land",sleep(1)?:wordwrap($s,1,--,1)," Moonlight";

```

uses UTF-8: `--` stands for `U+0336` \- but I am pretty certain that it does not work standing alone.

If it does not, try `~"1I"` or `~I1` instead of `--` (+3 or +1 bytes).

No time to store it to a file or figure out how to set my console to UTF-8; so I couldn´t test either of these; but whoever can: please let me know wether this is complete BS or not.
> 0 votes

# Answer
# Powershell, 63 bytes

Works only in PowerShell ISE. Non-competing, since strikethrough is shifted by one char and I can't fix it.

```
'La La Land',('̶'*10+' Moonlight')|%{sleep 1;Write-Host $_ -N}

```
> 0 votes

# Answer
# Haskell ~~170~~ ~~158~~ ~~153~~ 149 bytes

```
import System.Posix.Unistd
import System.IO
l="La La Land"
p=putStr
main=p l>>hFlush stdout>>usleep(10^6)>>p(('\b'<$l)++(l>>=(:"\822"))++"moonlight")

```

Lots of imports required for the flush and the delay. There's probably other golfing techniques I could implement. Works by appending \822 (the strikethrough modifier) to each character in `l`, then printing this followed by `"moonlight"`.

Wow my first use of `<$`.
> 0 votes

# Answer
## HTML + JS 6 + jQuery, 153 bytes

Longer than this answer due to the script tag but I anyway wanted to do it.

```
setTimeout('$("*").html`<s>La La Land</s> Moonlight`',1e3)
```

```
<script src=http://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js></script>La La Land
```
> 0 votes

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


title: Spirograph Time!

text:
# Question
Title: Spirograph Time!
A Spirograph is a toy that draws hypotrochoids and epitrochoids. For this challenge, we'll just focus on the hypotrochoids.

From Wikipedia:

> A hypotrochoid is a roulette traced by a point attached to a circle of radius **r** rolling around the inside of a fixed circle of radius **R**, where the point is a distance **d** from the center of the interior circle.

The parametric equations for them can be defined as:

Where *θ* is the angle formed by the horizontal and the center of the rolling circle.

---

Your task is to write a program that will draw the path traced by the point defined above. As input, you'll be given **R**, **r**, and **d**, all integers between 1 and 200 inclusive.

You can receive this input from stdin, arguments, or user input, but it cannot be hardcoded into the program. You can accept it in whatever form is most convenient for you; as strings, integers, etc.

Assume:

* Input units are given in pixels.
* **R** \>= **r**

---

Output should be a graphical representation of the hypotrochoid defined by the input. No ASCII- or other text-based output is allowed. This image can be saved to a file or displayed on screen. Include a screenshot or image of the output for an input of your choosing.

You can choose any colors you like for the path/background, subject to a contrast restriction. The two colors must have HSV 'Value' component at least half the scale apart. For instance, if you're measuring HSV from `[0...1]`, there should be at least `0.5` difference. Between `[0...255]` there should be a minimum `128` difference.

---

This is a code golf, minimum size of source code in bytes wins.

# Answer
## Mathematica, 120 bytes

```
f[R_,r_,d_]:=ParametricPlot[p#@t+#[-p*t/r]d&/@{Cos,Sin},{t,0,2r/GCD[p=R-r,r]Pi},PlotRange->400,ImageSize->800,Axes->0>1]

```

Ungolfed code and example output:

If I may include the axes in the plot, I can save another 9 characters.
> 9 votes

# Answer
# JavaScript (ECMAScript 6) - ~~312~~ 314 Characters

```
document.body.appendChild(e=document.createElement("canvas"))
v=e.getContext("2d")
n=(e.width=e.height=800)/2
M=Math
P=2*M.PI
t=0
p=prompt
r=p('r')
R=p('R')-r
d=p('d')
X=x=>n+R*M.cos(t)+d*M.cos(R/r*t)
Y=x=>n+R*M.sin(t)-d*M.sin(R/r*t)
v.beginPath()
v.moveTo(X(),Y())
for(;t<R*P;v.lineTo(X(),Y()))t+=P/2e4
v.stroke()

```

JSFIDDLE

**Example Output**

r=1,R=200,d=30
> 5 votes

# Answer
# Python: 579

## Summary

This is not competitive at all given the Mathematica answer, but I decided to post it anyway because the pictures are pretty and it may inspire someone or be useful to someone. Because it is so much bigger, I left it basically ungolfed. The program expects command-line input of R,r,d.

## Screenshot

Here are two examples, one for (5,3,5) and one for (10,1,7)

## Code

```
import math
import matplotlib.pyplot as P
from matplotlib.path import Path as H
import matplotlib.patches as S
import sys
a=sys.argv
(R,r,d)=int(a[1]),int(a[2]),int(a[3])
v=[]
c=[]
c.append(H.MOVETO)
t=0
while(len(v)<3 or v.count(v[-1])+v.count(v[-2])<3):
 p=t*math.pi/1000
 t+=1
 z=(R-r)*p/r
 v.append((round((R-r)*math.cos(p)+d*math.cos(z),3),round((R-r)*math.sin(p)-d*math.sin(z),3)))
 c.append(H.LINETO)
c.pop()
v.append((0,0))
c.append(H.CLOSEPOLY)
f=P.figure()
x=f.add_subplot(111)
x.add_patch(S.PathPatch(H(v,c)))
l=R+d-r
x.set_xlim(-l-1,l+1)
x.set_ylim(-l-1,l+1)
P.show()

```
> 3 votes

# Answer
## Perl/Tk - 239 227

```
use Tk;($R,$r,$d)=@ARGV;$R-=$r;$s=$R+$d;$c=tkinit->Canvas(-width=>2*$s,-height=>2*$s)->pack;map{$a=$x;$b=$y;$x=$s+$R*cos($_/=100)+$d*cos$_*$R/$r;$y=$s+$R*sin($_)-$d*sin$_*$R/$r;$c->createLine($a,$b,$x,$y)if$a}0..628*$s;MainLoop

```

**R=120, r=20, d=40:**

**R=128, r=90, d=128:**

**R=179, r=86, d=98:**
> 3 votes

# Answer
## GeoGebra, 87

**That is, if you consider GeoGebra a valid language.**

```
R=2
r=1
d=1
D=R-r
Curve[D*cos(t)+d*cos(D*t/r),D*sin(t)-d*sin(D*t/r),t,0,2π*r/GCD[D,r]]

```

Accepts input from the GeoGebra input bar, in the format `<variable>=<value>`, e.g. `R=1000`.

Note that you may need to manually change the zoom size to view the whole image.

*(The thing at the bottom of the window is the input bar that I was talking about)*

Try it online here.
> 2 votes

# Answer
# R, 80 bytes

```
f=function(R,r,d){a=0:1e5/1e2;D=R-r;z=D*exp(1i*a)+d*exp(-1i*D/r*a);plot(z,,'l')}

```

However, if one wants 'clean' figures (no axes, no labels etc), then the code will have to be slightly longer (88 characters):

```
f=function(R,r,d)plot((D=R-r)*exp(1i*(a=0:1e5/1e2))+d*exp(-1i*D/r*a),,'l',,,,,,'','',,F)

```

One code example using the longer version of f:

```
f(R<-179,r<-86,d<-98);title(paste("R=",R,", r=",r," d=",d,sep=""))

```

Some example outputs:
> 2 votes

# Answer
# HTML + Javascript 256  ~~286 303~~

**Edit** Removed 1st call to moveTo, it works anyway. Could save more cutting beginPath, but then it works only the first time

**Edit2** 30 bytes saved thx @ӍѲꝆΛҐӍΛПҒЦꝆ

```
<canvas id=c></canvas>R,r,d:<input oninput="n=400;c.width=c.height=t=n+n;v=c.getContext('2d');s=this.value.split(',');r=s[1],d=s[2],R=s[0]-r;v.beginPath();for(C=Math.cos,S=Math.sin;t>0;v.lineTo(n+R*C(t)+d*C(R/r*t),n+R*S(t)-d*S(R/r*t)),t-=.02);v.stroke()">

```

**Test**

Put input in the text box (comma separated) then press tab

```
R,r,d:<input onchange="n=400;c.width=c.height=t=n+n;v=c.getContext('2d');s=this.value.split(',');r=s[1],d=s[2],R=s[0]-r;v.beginPath();for(C=Math.cos,S=Math.sin;t>0;v.lineTo(n+R*C(t)+d*C(R/r*t),n+R*S(t)-d*S(R/r*t)),t-=.02);v.stroke()"><canvas id=c></canvas>
```
> 2 votes

# Answer
# Processing, 270

```
import java.util.Scanner;
void setup(){size(500, 500);}
Scanner s=new Scanner(System.in);
int R=s.nextInt(),r=s.nextInt(),d=s.nextInt();
void draw(){
  int t=width/2,q=(R-r);
  for(float i=0;i<R*PI;i+=PI/2e4)
    point(q*sin(i)-d*sin(i*q/r)+t,q*cos(i)+d*cos(i*q/r)+t);
}

```

The input is entered via console, one number per line.

Screenshot for R=65, r=15, d=24:
> 2 votes

# Answer
# shell script + gnuplot (153)

Most of the effort is to remove the axes and tics, set the size and range, and increase the precision. Thankfully, gnuplot is natural for golfing, so most of the commands can be abbreviated. To save characters, the output must be redirected to an image file manually.

```
gnuplot<<E
se t pngc si 800,800
se pa
se sa 1e4
uns bor
uns tic
a=$1-$2
b=400
p[0:2*pi][-b:b][-b:b]a*cos($2*t)+$3*cos(a*t),a*sin($2*t)-$3*sin(a*t) not
E

```

Calling the script with `spiro.sh 175 35 25>i.png` gives
> 2 votes

# Answer
## C# 813, was 999

Needs some work to reduce byte count. I managed to reduce it a little. It accepts three space separated integers from the Console.

```
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Windows.Forms;
class P:Form
{
int R,r,d;
P(int x,int y,int z) {R=x;r=y;d=z;}
protected override void OnPaint(PaintEventArgs e)
{
if(r==0)return;
Graphics g=e.Graphics;
g.Clear(Color.Black);
int w=(int)this.Width/2;
int h=(int)this.Height/2;
List<PointF> z= new List<PointF>();
PointF pt;
double t,x,y;
double pi=Math.PI;
for (t=0;t<2*pi;t+=0.001F)
{
x=w+(R-r)*Math.Cos(t)+d*Math.Cos(((R-r)/r)*t);
y=h+(R-r)*Math.Sin(t)-d*Math.Sin(((R-r)/r)*t);
pt=new PointF((float)x,(float)y);
z.Add(pt);
}
g.DrawPolygon(Pens.Yellow,z.ToArray());
}
static void Main()
{
char[] d={' '};
string[] e = Console.ReadLine().Split(d);
Application.Run(new P(Int32.Parse(e[0]),Int32.Parse(e[1]),Int32.Parse(e[2])));
}
}

```

Output sample:
> 1 votes

# Answer
## R, 169 characters

```
f=function(R,r,d){png(w=2*R,h=2*R);par(mar=rep(0,4));t=seq(0,R*pi,.01);a=R-r;x=a*cos(t)+d*cos(t*a/r);y=a*sin(t)-d*sin(t*a/r);plot(x,y,t="l",xaxs="i",yaxs="i");dev.off()}

```

Indented:

```
f=function(R,r,d){
    png(w=2*R,h=2*R) #Creates a png device of 2*R pixels by 2*R pixels
    par(mar=rep(0,4)) #Get rid of default blank margin
    t=seq(0,R*pi,.01) #theta
    a=R-r
    x=a*cos(t)+d*cos(t*a/r)
    y=a*sin(t)-d*sin(t*a/r)
    plot(x,y,t="l",xaxs="i",yaxs="i") #Plot spirograph is a plot that fits tightly to it (i. e. 2*R by 2*R)
    dev.off() #Close the png device.
}

```

Examples:

```
> f(65,15,24)

```

```
> f(120,20,40)

```

```
> f(175,35,25)

```
> 1 votes

# Answer
# SmileBASIC, 96 bytes

```
INPUT R,Q,D
M=R+MAX(Q,D)
S=R-Q@L
GPSET M+S*COS(I)+D*COS(S/Q*I),M+S*SIN(I)-D*SIN(S/Q*I)I=I+1GOTO@L

```

### Input: 50,30,50:
> 1 votes

# Answer
# Befunge-98, 113 bytes

```
&&:00p-10p&20p"PXIF"4(10g'd:*:I10v>H40gF1+:"}`"3**`>jvI@
1(4"TURT"p04/d'*g02I/g00*p03/d'*g<^-\0/g00*g01:Fg03H:<0P

```

This code relies on the Fixed Point Maths (FIXP) fingerprint for some trigonometric calculations, and the Turtle Graphics (TURT) fingerprint for drawing the path of the spirograph.

The Turtle Graphics in Befunge are very similar in behaviour to the graphics in the Logo programming language. You draw with a 'turtle' (serving as your pen), which you steer around the output surface. This entails orienting the turtle in a particular direction, and then instructing it to move forward a certain distance.

In order to work with this system, I needed to adjust the original spirograph equations into something a little more turtle friendly. I'm not sure if this is the best approach, but the algorithm I came up with works something like this:

```
ratio = (R-r)/r
distance1 = sin(1°) * (R-r)
distance2 = sin(1° * ratio) * d
foreach angle in 0° .. 36000°:
  heading(angle)
  forward(distance1)
  heading(-ratio*angle)
  forward(distance2)

```

Note that this actually draws the path with a kind of zig-zag pattern, but you don't really notice unless you zoom in closely on the image.

Here's an example using the parameters R = 73, r = 51, d = 45.

I've tested the code with CCBI and cfunge, both of which produce output in the form of an SVG image. Since this is a scalable vector format, the resulting image doesn't have a pixel size as such - it just scales to fit the screen size (at least when viewed in a browser). The example above is a screen capture that has been manually cropped and scaled.

In theory the code could also work on Rc/Funge, but in that case you'd need to be running on a system with XWindows, since it'll try to render the output in a window.
> 1 votes

# Answer
## wxMaxima: 110

```
f(R,r,d):=plot2d([parametric,(p:R-r)*cos(t)+d*cos(t*(p)/r),(p)*sin(t)-d*sin(t*(p)/r),[t,0,2*%pi*r/gcd(p,r)]]);

```

This is called in the interactive session via `f(#,#,#)`. As a sample, consider `f(3,2,1)`:
> 0 votes

# Answer
## Racket

```
#lang racket/gui
(require 2htdp/image)

(define frame (new frame%
                   [label "Spirograph"]
                   [width 300]
                   [height 300]))

(define-values (R r d) (values 50 30 10)) ; these values can be adjusted;

(new canvas% [parent frame]
     [paint-callback
      (lambda (canvas dc)
        (send dc set-scale 3 3)
        (for ((t (in-range 0 (* 10(* R pi)) 1)))
          (define tr (degrees->radians t))
          (define a (- R r))
          (define x (+ (* a (cos tr))
                       (* d (cos (* tr (/ a r))))))
          (define y (- (* a (sin tr))
                       (* d (sin (* tr (/ a r))))))
          (send dc draw-ellipse (+ x 50) (+ y 50) 1 1)))])

(send frame show #t)

```

Output:
> 0 votes

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


title: Quadrants passed through by a line

text:
# Question
Title: Quadrants passed through by a line
## Task

Given a representation of a line, output the number of quadrants that that line passes through.

## Valid Representations of a Line

You can represent a line as

* Three signed integers `A`, `B`, and `C` which share no common factor and where `A` and `B` are not both zero, representing the line `Ax + By = C`,
* Four signed integers `X<sub>1</sub>`, `Y<sub>1</sub>`, `X<sub>2</sub>`, and `Y<sub>2</sub>`, representing the line passing through the points `(X<sub>1</sub>, Y<sub>1</sub>)` and `(X<sub>2</sub>, Y<sub>2</sub>)`, or
* A data type that describes a line, if your language has one (it must support vertical lines).

You may *not* take input in any format that does not allow for a vertical line (e.g. slope-intercept form). If you choose to take integers as input, you can assume that they lie in the inclusive range `[-127, 128]`.

## Specifications

* The output will always be 0, 2, or 3 (a line can never pass through all four quadrants, nor can it pass through only a single one).
* A line on an axis is considered not to pass through any quadrants. A line through the origin is considered to only pass through 2 quadrants.
* You do not have to return which quadrants are being passed through (though the test cases include them for clarity).
* This is , so the shortest valid answer (measured in bytes) wins.

## Test Cases

You will have to convert these to a suitable format before using them.

```
1x + 1y = 1   ->  3  (quadrants I, II, and IV)
-2x + 3y = 1  ->  3  (quadrants I, II, and III)
2x + -3y = 0  ->  2  (quadrants III and I)
1x + 1y = 0   ->  2  (quadrants II and IV)
3x + 0y = 6   ->  2  (quadrants I and IV)
-3x + 0y = 5  ->  2  (quadrants II and III)
0x + -8y = 4  ->  2  (quadrants III and IV)
0x + 1y = 0   ->  0  (lies on the x-axis)
1x + 0y = 0   ->  0  (lies on the y-axis)

```

# Answer
> 22 votes
# Python 3, 24 bytes

```
lambda a:3<<a.count(0)&3

```

Try it online!

# Answer
> 3 votes
# Jelly, 5 bytes

```
TL’ȧ$

```

Try it online!

* -1 byte thanks to Challenger5
* -1 byte thanks to Leaky Nun
* -2 bytes thanks to H.PWiz

No longer based off Leaky's answer!

# Answer
> 3 votes
# Javascript (ES6), ~~30~~ ~~24~~ 22 bytes

This is my first time trying to golf in Javascript. ~~There's gotta be a better way to count zeros...~~

```
(a,b,c)=>3<<!a+!b+!c&3

```

-6 bytes thanks to Herman Lauenstein, -2 bytes to remembering operator precedences.

Alternate 24-bytes solution to return a string instead:

```
(a,b,c)=>"320"[!a+!b+!c]

```

# Answer
> 2 votes
# 05AB1E, 6 bytes

```
ƵÜ¹0¢è

```

Try it online!

Based on Leaky Nun's answer.

# Answer
> 2 votes
# SOGL V0.12, 8 bytes

```
0233{.‽X

```

Try it Here!

Based off Leaky Nun's answer.

# Answer
> 2 votes
# Retina, 13 bytes

```
M`\b0
T`d`320

```

**Try it online**

Also based on Leaky Nun's answer.

# Answer
> 2 votes
# GolfScript, ~~16~~ 14 bytes

```
~{!!}%{+}*.1>*

```

Try it online!

* @Challenger5 -2 bytes

This program takes an array of 3 integers representing the coefficients in the equation `Ax + By = C`

**Example Input/Output**

```
[1 1 1]   -> 3
[-2 3 1]  -> 3

```

**How it Works**

```
~                       - Eval string (input)
  {  }%                 - Map to array
   !!                   - Double not (equivalent to != 0)
        {+}*            - total array (fold addition)
            .           - Duplicate top of stack
             1>         - Greater than 1?
               *        - Multiply

```

This was a little tricky at first for me to figure out a mathematical way to calculate this. However there are only 8 possible configurations such that `a != 0 & b != 0 & c != 0`

```
0 0 0 = 0
a 0 0 = 0
0 b 0 = 0
0 0 c = 0
a 0 c = 2
0 b c = 2
a b 0 = 2
a b c = 3

```

I eventually came to the following function.

```
F(a,b,c) {
    var r = sign(a)+sign(b)+sign(c);
    if(r > 1)
        r;
    else
        return 0;
}

```

and the whole thing can be condensed to a single math problem

```
F(a,b,c) {
    return (sign(a)+sign(b)+sign(c)) * (sign(a)+sign(b)+sign(c) > 1);
}

```

# Answer
> 1 votes
# APL (Dyalog Unicode), ~~14~~ 11 bytes

```
0⌈3-×⍨+/0=⎕

```

Try it online!

`⎕IO` is `0`. Thanks to @Adám for -3 bytes!

# Answer
> 1 votes
# JavaScript, 25 bytes

```
_=>3<<!_[0]+!_[1]+!_[2]&3

```

Based off Leaky Nun's answer.

# Answer
> 1 votes
# Haskell, 22 bytes

```
f l="320"!!sum[1|0<-l]

```

Try it online!

## Point-free solution, 27 bytes

```
("320"!!).(\l->sum[1|0<-l])

```

Try it online!

# Answer
> 1 votes
## Perl 6, 18 bytes

```
{3+<@_.grep(0)+&3}

```

# Answer
> 1 votes
# ABCR, 30 bytes

Input is in the form `A,B,C` where the commas can be replaced by any non-numeric, non-`-` character.

```
BBi7baxci7baxci7bax@7)A7(xxo

```

No online interpreter yet, but here's an explanation:

```
BB                                Add two values to the B queue. (Values are unimportant)
  i7 ax                           Read in a number.  If it's non-zero...
    b                             Dequeue one item from the B queue.
       c                          Read in the delimiter...
        i                         ... And promptly overwrite it with the next number.
         7baxci7bax               Repeat the whole "if 0, dequeue from B" for the
                                     other two input numbers.
                   @              Get the current length of the B queue. [2, 1, or 0]
                    7             If the length isn't 0...
                     )            ... Increment it to our required [3,2,0]
                      A           ... And enqueue it to A.
                                  (We don't need to add to A otherwise, because it defaults
                                    to 0 already if there's no value in it.
                                    I used that to exit the queue with 7_ax earlier.)
                       7(xx       Set the register to 0 to exit from loop.
                           o      Peek A and print as a number.

```

# Answer
> 0 votes
# Deorst, 12 bytes

```
l0EN))A:k?Z+

```

Try it online!

Somewhat based off Leaky's answer; uses the same premise, but a different mapping method.

## How it works

Deorst has a count occurrences builtin, but doesn't (for some reason) have an indexing command, so I had to create the following mapping, where the left is `a.count(0)` and the right is the wanted result

```
0 -> 3
1 -> 2
2 -> 0

```

The program itself works like this (example input of `[1,1,1]`)

```
l0           - Push 0;     STACK = [[1 1 1] 0]
  EN         - Count;      STACK = [0]
    ))       - Subtract 2; STACK = [-2]
      A      - Absolute;   STACK = [2]
       :     - Duplicate;  STACK = [2 2]
        k?Z  - Positive?;  STACK = [2 1]
           + - Sum;        STACK = [3]

```

# Answer
> 0 votes
# Add++, 23 bytes

```
D,f,@@@,!$!@!s2$_|d0$>+

```

Try it online!

Based off both my Deorst answer and Leaky's Python answer

## How it works

```
D,f,@@@,  - Create a triadic function.
            Example arguments;   [1 1 1]
        ! - Logical NOT; STACK = [1 1 0]
        $ - Swap;        STACK = [1 0 1]
        ! - Logical NOT; STACK = [1 0 0]
        @ - Reverse;     STACK = [0 0 1]
        ! - Logical NOT; STACK = [0 0 0]
        s - Sum;         STACK = [0]
        2 - Push 2;      STACK = [0 2]
        $ - Swap;        STACK = [2 0]
        _ - Subtract;    STACK = [-2]
        | - Absolute;    STACK = [2]
        d - Duplicate;   STACK = [2 2]
        0 - Push 0;      STACK = [2 2 0]
        $ - Swap;        STACK = [2 0 2]
        > - Greater to;  STACK = [2 1]
        + - Sum;         STACK = [3]

```

However, I think I've been using functions too much in Add++, rather than the main code body. So I attempted to do this using both functions, and the code body, and resulted in a much nicer 50 byte piece (yes, that is the longest answer here):

```
# Example input: 1 1 1;
# x and y are the accumulators

D,f,@@@,!$!@!s # Count the 0s
$f>?>?>?       # Call f with the input.
-2   # Subtract 2;    x: -2;  y: 0
^2   # Square;        x: 4;   y: 0
S    # Square root;   x: 2.0; y: 0
\1   # To integer;    x: 2;   y: 0
y:x  # Assign x to y; x: 2;   y: 2
}    # Switch to y;   x: 2;   y: 2
>0   # Is positive?;  x: 2;   y: 1
}    # Switch to x;   x: 2;   y: 1
+y   # Add y to x;    x: 3;   y: 1
O    # Print x

```

Try it online!

---
Tags: code-golf, number, geometry
---


title: The thousand character classic

text:
# Question
Title: The thousand character classic
# Background

The Thousand Character Classic is a chinese poem written around the 4th Century CE in China, and memorized by large populations since then. The name comes from not only its length, but its number of characters: each character occurs only once in the text. It is commonly used to teach children chinese characters, and also, because of its commonness, as a means of enumerating the 1000 characters in the text.

# The challenge

Here is a copy of the Thousand Character Classic, gotten from Wikipedia.

The Thousand Character Classic

Reproduce the entirety of the Thousand Character Classic in either UTF-8 or UTF-16, including punctuation, newlines, and heading numbers. Punctuation can be halfwidth or fullwidth, and the trailing newline is optional.

For those that want to analyze the unicode text for patterns, I've provided hexdumps of both encodings.

utf-8

utf-16

# Rules

Because of the size of the text to reproduce, you may optionally supply a file for your submission to use as input. If this is done, add the byte length of the input file to the byte length of your code.

Otherwise, this is a standard issue code golf challenge, so standard loopholes apply, and shortest submission wins.

# Answer
> 3 votes
# Bubblegum, 2526 bytes

```
00000000: 2dd4 47c2 82cc 9680 e1f9 b78a de42 e7ed  -.G..........B..
00000010: 898a 808a 3921 28e6 0ca8 1830 e162 9a13  ....9!(....0.b..
00000020: 6ad4 5bb8 50fe e3e7 bc86 4aff fe07 8b2d  j.[.P.....J....-
00000030: 3847 aa15 c5ab f0ff ef2a f81a f816 5e76  8G.......*....^v
00000040: 6cb6 fe2f 97ff b73f ec2f d1d1 c9d6 7190  l../...?./....q.
00000050: 39c7 47f0 bfa0 f7e1 7d95 0e41 2b89 4b38  9.G.....}..A+.K8
00000060: 6c42 9c4b 9dd6 15ec dca0 74e0 7e5d bae8  lB.K......t.~]..
00000070: d5c5 6280 7a03 bd73 ea10 57a0 99e7 dd57  ..b.z..s..W....W
00000080: 589f 9fdb 67b1 39b2 7611 f626 75e1 9ce9  X...g.9.v..&u...
00000090: daa0 fc53 38ce cfb5 2675 5cf1 ece3 f192  ...S8...&u\.....
000000a0: 3ad5 0cd0 9e70 69c2 792a 1dca 265b 2edc  :....pi.y*..&[..
000000b0: 37a2 dfcd bc3e a1cd 0916 0ea8 8674 1c3b  7....>.......t.;
000000c0: 5437 7154 43f7 983a d71d a199 5c5e c2da  T7qTC..:....\^..
000000d0: f9f9 f50e ad08 cf21 dea7 a98b 531f 3f36  .......!....S.?6
000000e0: c51f fa76 a4ff c79f 884d 88f6 a4ec 211a  ...v.....M....!.
000000f0: 6513 e112 fc41 f27c d250 9313 b0ae 807e  e....A.|.P.....~
00000100: c39e 065e 3ff5 e451 40c7 e4e9 9ce7 a174  ...^?..Q@......t
00000110: ac6d 928f c97e 1b9c 4aea e818 6c8d 8575  .m...~..J...l..u
00000120: 834e 433a bc3b 786c 26ef 067d 76a9 4373  .NC:.;xl&..}v.Cs
00000130: 43d6 1bfd 3b3e 829f 8f1a e88c a05b 174a  C...;>.......[.J
00000140: 3bf3 711e 2b27 7884 b49f 48c7 a2cd f9b3  ;.q.+'x...H.....
00000150: 78d5 c4aa 973a 6bf3 e45d 47bd 4671 55ba  x....:k..]G.FqU.
00000160: 501a 22af 2551 4eec 3b72 0535 0edb e845  P.".%QN.;r.5...E
00000170: 54ab fc3c bc88 3004 6743 fb47 e6d6 47ac  T..<..0.gC.G..G.
00000180: 5b62 eec2 e422 1daa 3d9e edd9 34d0 d9a4  [b..."..=...4...
00000190: cee1 05ea 656e 1cb0 f790 fe9f 7fdc aea0  ....en..........
000001a0: b7e0 e75e ecfd 7402 6c1b 16eb e4d9 8128  ...^..t.l......(
000001b0: 9213 a878 5870 c578 2216 e5d4 f9a4 6377  ...xXp.x".....cw
000001c0: 8641 0ef2 77e9 b00c 51ed f279 4c57 2775  .A..w...Q..yLW'u
000001d0: eadc b1ab a361 b211 4827 7729 941a 7c55  .....a..H'w)..|U
000001e0: ec3c e419 ea73 e1c3 b53d 7c07 3fff 7478  .<...s...=|.?.tx
000001f0: afc1 e74d ae97 ba18 4d51 29c0 fd24 ba77  ...M....MQ)..$.w
00000200: e9c9 779a 7cbe 500f 7855 ca7a 6b83 87b3  ..w.|.P.xU.zk...
00000210: b0e7 42ab 4b87 d906 f367 ba9e d16d a7ce  ..B.K....g...m..
00000220: db2d fb43 8a3b 1497 a5a3 15f0 b44a 378f  .-.C.;.......J7.
00000230: c359 d6ab 15f8 5e93 8fc3 4a4f 3ac4 7778  .Y....^...JO:.wx
00000240: 3da1 61d2 be92 f967 46fb b4d8 a037 974e  =.a....gF....7.N
00000250: db27 1fef 900f 5939 a7ce 960d 933c 7d5b  .'....Y9.....<}[
00000260: ac7c 7ebe 32c1 9e60 614a 5b33 755a d5e9  .|~.2..`aJ[3uZ..
00000270: 3e87 5e11 d59b 7438 3ea9 b516 a331 04b7  >.^...t8>....1..
00000280: d421 8884 75c4 4140 fb9f 73a8 917e 4b9e  .!..u.A@..s..~K.
00000290: 1568 d8a9 a37d 84e1 8575 0dbb 07e9 e08d  .h...}...u......
000002a0: a87b a3bd 07e5 cce1 3b01 4323 7b0a cd8f  .{......;.C#{...
000002b0: 74d6 3678 3fc1 69c9 bd62 e60b 8b75 1d9f  t.6x?.i..b...u..
000002c0: 7bd0 cad2 93f7 9b07 1ef6 02b1 da64 beca  {............d..
000002d0: e328 4e1e 15b2 6de9 701f e155 4922 1395  .(N...m.p..UI"..
000002e0: 2075 bc5f 312e 42bd 8783 c9cf fd07 7a33   u._1.B.......z3
000002f0: ae2c 3137 4a9d 3739 8e3d f00d f087 d229  .,17J.79.=.....)
00000300: 5880 3ee2 dd84 e25a d6ab 35ba e6c1 7792  X.>....Z..5...w.
00000310: d742 3aae 7c5c 7a68 e4c0 7d66 7ddf a0ce  .B:.|\zh..}f}...
00000320: 908a 53da bbd2 c18b a0b8 23eb 95bc ba59  ..S.......#....Y
00000330: df19 b172 8778 8c9d ef3f 3e48 5e4b ea0c  ...r.x...?>H^K..
00000340: 703e 491d 6a2f ce55 c92e f376 221d 3779  p>I.j/.U...v".7y
00000350: f4cb 7cbe 70b8 90eb ef83 be84 6319 cca6  ..|.p.......c...
00000360: f424 2a43 ab9a 4415 1aad e4fa eca1 7382  .$*C..D.......s.
00000370: ed4a 0c37 d261 d183 7a1f f22a 6fda 99ab  .J.7.a..z..*o...
00000380: 4b58 1a18 9850 cc49 e77d 04eb 66f2 0ea0  KX...P.I.}..f...
00000390: 2e6f 60f5 065e 0383 0ea8 2de9 e075 50bb  .o`..^....-..uP.
000003a0: 835a 84b7 9bf5 8d2a 1ee7 2237 c7c9 437a  .Z.....*.."7..Cz
000003b0: f25c 40bd 82e5 2ee8 a5cc 758d e61b f22f  .\@.......u..../
000003c0: bcaa fffc a5a0 aa8b e109 0baf d445 6e82  .............En.
000003d0: 8729 bcfb c29e 49a7 2047 f116 5e86 c8e5  .)....I. G..^...
000003e0: 329f da78 b6a1 ba63 6b2d 1d73 6b31 72b0  2..x...ck-.sk1r.
000003f0: a08a 5c24 cf47 012a 5d5a 8ea9 7796 0ebe  ..\$.G.*]Z..w...
00000400: 4e8e 0bdf 3ebe bef2 f31b 646c b158 a7f5  N...>.....dl.X..
00000410: ebe7 1315 ab8a b055 6c9b 59bf fc90 7e65  .......Ul.Y...~e
00000420: 6d47 d1cf ffeb 4f14 3e22 dfe4 7a00 8b7a  mG....O.>"..z..z
00000430: b643 a313 2fbf c9b3 9a3c 7f27 940b 5591  .C../....<.'..U.
00000440: b7c4 6886 173b f3ab 8f91 87ed 21de 34e9  ..h..;......!.4.
00000450: e0fb e87f c95e 8882 92f9 a6cd eb9c 98db  .....^..........
00000460: 623b fcb9 d383 604f ab0f 9951 ead4 ddc3  b;....`O...Q....
00000470: 679b bcd2 4fd4 a527 91c5 ba09 7913 ba6e  g...O..'....y..n
00000480: e69d 3344 211c 4d5c 3ea4 73be 44de 9537  ..3D!.M\>.s.D..7
00000490: 1e44 f205 79b7 a9e9 42e3 4107 4b3a 989a  .D..y...B.A.K:..
000004a0: 18d6 e862 0a4b dea0 b7c2 1f83 7a4d 1cb8  ...b.K......zM..
000004b0: 3faf 8722 3784 d71c d475 e6f7 9550 3a68  ?.."7....u...P:h
000004c0: 7c71 5093 8efd 99b0 4b30 0b41 8d52 4f9e  |qP.....K0.A.RO.
000004d0: 2b56 8614 2fb8 72fa f9c8 a1cd 5798 b118  +V../.r.....W...
000004e0: 668e ef12 da11 cc15 bab5 a5c3 d3a1 5885  f.............X.
000004f0: a346 76e6 7c0f 92ef 04d7 0d30 bfd2 51bf  .Fv.|......0..Q.
00000500: c151 0175 4fd1 3c75 f06f 745d 8159 00f5  .Q.uO.<u.ot].Y..
00000510: 2a5d ec07 509a 086b c7ef 55ea 62ab f227  *]..P..k..U.b..'
00000520: 8fd5 809e 6de9 49d4 a374 4362 1d82 6aea  ....m.I..tCb..j.
00000530: fc2a 8b75 97f3 4b7e 77a5 93d7 83b2 cbd5  .*.u..K~w.......
00000540: 3c04 590f 9516 cd9a a0bf 4479 f0f3 f90b  <.Y.......Dy....
00000550: 9fbb e45d 86e3 23f5 e4d3 402b 2f06 5f9e  ...]..#...@+/._.
00000560: 4ea5 c3b2 08be 8af6 590c 9cac 8f7d ecaf  N.......Y....}..
00000570: c03b 92e6 4ac7 691b d403 54a7 d0d0 53c7  .;..J.i...T...S.
00000580: af0b ef13 1a37 c8c7 d2e9 f604 7b8c ef19  .....7......{...
00000590: 1626 a9f3 6e87 4517 bd55 1229 d293 6f39  .&..n.E..U.)..o9
000005a0: 79e4 2128 41e5 2b6f e810 e67b 083a 10ac  y.!(A.+o...{.:..
000005b0: a5a3 65e0 7288 f645 3872 fd6e 96f0 ea60  ..e.r..E8r.n...`
000005c0: 1f71 bb97 0e8a 2672 1d7c a96c cd32 8f1a  .q....&r.|.l.2..
000005d0: e0b8 e814 c876 a527 9fae 50ae 7429 62d8  .....v.'..P.t)b.
000005e0: 4d5d b86d 7897 49dd 82de 94ce d73b 7d57  M].mx.I......;}W
000005f0: 62d2 2763 2dcf d786 5f26 3a39 3ac7 d2c1  b.'c-..._&:9:...
00000600: 9fc3 46c1 b385 ef49 d6af 42f6 3e49 f410  ..F....I..B.>I..
00000610: a396 f4e4 3182 fb98 560f be4f b3de 8a45  ....1...V..O...E
00000620: 614a eb15 3c6e d2e1 1c82 dfc7 f008 e753  aJ..<n.........S
00000630: e6ab 5d12 bd92 6733 797a d285 ad88 5e8e  ..]...g3yz....^.
00000640: 2e7b 988e 5317 f698 3a47 be2e c0ad 49c7  .{..S...:G....I.
00000650: 4109 4f13 9acd c90d 3337 54a1 d5f0 3286  A.O.....37T...2.
00000660: 7f7a b427 4299 d0ed 2bf2 7aea 70de c279  .z.'B...+.z.p..y
00000670: 8fa3 104a 4be9 fffd 87e7 173a 07ec bd39  ...JK......:...9
00000680: 3ecb 1360 71f5 4c9b 376d a7ff ecc0 8ddf  >..`q.L.7m......
00000690: 0698 7dea 8e52 47bd c9fd 9178 99b4 b94b  ..}..RG....x...K
000006a0: a78d 4a25 97cf 33ec 1d65 1f71 3816 2f47  ..J%..3..e.q8./G
000006b0: 58ae 74f0 5c7e bdb0 bba2 cb24 f3fa 5978  X.t.\~.....$..Yx
000006c0: 435a 1b64 5f7e febc c123 4e22 0f9e 91ec  CZ.d_~...#N"....
000006d0: c77c b0f8 f0c0 6e57 3a2b 25e1 8610 b8d4  .|....nW:+%.....
000006e0: 28a5 2e9a 2d3e 5739 deb0 71fe f9f9 03b5  (...->W9..q.....
000006f0: 250c 0caa de65 6f80 7aa3 651f 17a6 7472  %....eo.z.e...tr
00000700: 147e 1ed8 abf3 6e9a 7970 85d9 18cb 7d5c  .~....n.yp....}\
00000710: 5ea5 a35f e2f8 c4df 262a cbd4 71dc a761  ^.._....&*..q..a
00000720: 051e 1198 a174 50b7 d4ab f3aa 825b 3775  .....tP......[7u
00000730: 5ecf e95a e4dd 51e4 ded2 e932 8393 2a7a  ^..Z..Q....2..*z
00000740: 2db6 ba59 7f36 c46b 0041 1e82 a574 3ce5  -..Y.6.k.A...t<.
00000750: a1be 8063 85f7 bdcc bb73 547d 9133 8562  ...c.....sT}.3.b
00000760: fdfc 3087 659d 2e81 50e6 99ab 6f3e 8cd0  ..0.e...P...o>..
00000770: 9b62 c5fe 7934 61f3 4ec3 227a f2ff 392d  .b..y4a.N."z..9-
00000780: ae7d b0fc c1d9 e8e7 630d 4777 b486 f49d  .}......c.Gw....
00000790: 64fd 6c8d d306 0f17 a055 a40b 2bc4 c903  d.l......U..+...
000007a0: d61d fa86 a973 e3c3 4d43 cc8b d8e8 49c7  .....s..MC....I.
000007b0: 2812 d798 cc8d 502a a983 56c5 e696 aea1  (.....P*..V.....
000007c0: 708a d2ff e78f 731f f673 54db 4294 972b  p.....s..sT.B..+
000007d0: d826 db07 bb4c fee9 9f33 d8e6 f70d 3b11  .&...L...3....;.
000007e0: 75eb 999f 0e9c 0b61 3c27 a324 1dd4 3b97  u......a<'.$..;.
000007f0: 42b1 6888 7990 ba50 b650 9f83 aab2 1a49  B.h.y..P.P.....I
00000800: 17f3 8f98 efa9 f000 ff98 f97c 0635 8f42  ...........|.5.B
00000810: 97c2 8974 5eed 501f 6257 65bd 9c3a e714  ...t^.P.bWe..:..
00000820: 3836 a97b a470 2d1d 5631 c453 8a62 bac8  86.{.p-.V1.S.b..
00000830: 1d8e 55b8 c710 dd51 ff4a a78b 8e86 064e  ..U....Q.J.....N
00000840: 1b3f 9dd4 4539 479a 476a 8bd4 aa74 b446  .?..E9G.Gj...t.F
00000850: e44c 60d1 85a0 913a f74d f24c 3e4d e159  .L`....:.M.L>M.Y
00000860: 960e ef15 7a55 a1b6 c0bf a48e b525 8e02  ....zU.......%..
00000870: d60d 5e5f a493 1ba0 5111 9336 dfc2 ccf3  ..^_....Q..6....
00000880: 2a9f f649 d481 e75d 3aec a710 57a1 3fa7  *..I...]:...W.?.
00000890: 6735 755a 7ab4 cc51 6104 83be 74da 7cc4  g5uZz..Qa...t.|.
000008a0: d482 9289 1547 f643 d4de a834 b070 fbb9  .....G.C...4.p..
000008b0: 5f21 a345 c729 af94 d4c5 744d 5e07 822d  _!.E.)....tM^..-
000008c0: 6f43 e962 17c1 7886 8510 af97 d4c1 bd53  oC.b..x........S
000008d0: e924 a603 bcbd 7fbe 9d89 4d4c e519 198f  .$........ML....
000008e0: ac5f 7bfc 34f9 a68a ed42 3aef 54ec 1d38  ._{.4....B:.T..8
000008f0: 2c93 2dbf dfec 9279 86ba 9d3c a7d2 fff7  ,.-....y...<....
00000900: 0fa2 021c 8b50 1826 91bc a357 8d1a 1731  .....P.&...W...1
00000910: f061 10a4 137f a81c c82b 416e 4f17 2b65  .a.......+AnO.+e
00000920: a18f e1be 4e5e 2fa1 cd33 165a 852e 36e8  ....N^/..3.Z..6.
00000930: dbe4 db4f 99f6 231a 9692 4f08 2b4b d681  ...O..#...O.+K..
00000940: 8dbd 0fde 9bb0 964f fc7d 29a6 4758 9974  .......O.}).GX.t
00000950: 6866 0c8f 0bb9 330c ea90 3fa4 8cf6 0a87  hf....3...?.....
00000960: 063a 7db4 9d8c a9f5 a5d6 1cb5 087b d38c  .:}..........{..
00000970: ad95 f08a d43a 92ba ce18 ab1a f776 c9d7  .....:.......v..
00000980: a7a5 93f1 31a2 5b1d 1a06 943d 59bb 5bf4  ....1.[....=Y.[.
00000990: 96f0 ee8a c920 e5e4 1b24 af23 bcca f072  ..... ...$.#...r
000009a0: 653d 7221 ba91 ebc0 b328 4fd6 00e2 328d  e=r!.....(O...2.
000009b0: 5fe4 3c33 066f 21ac 0a04 5356 c629 6371  _.<3.o!...SV.)cq
000009c0: c82d 8b3c 8377 c38c f990 e7dd 18ca 5bce  .-.<.w........[.
000009d0: a929 53d1 80b6 913c 6ac9 c34d f95f       .)S....<j..M._

```

Try it online!

# Answer
> 3 votes
# C, 50 + 3008 = 3058 bytes

I've tried out several simple compression methods, and found that outputting the UTF-16 input (trailing newline removed) directly is the best way. Input from stdin.

```
int b[999];main(){read(0,b,3008);write(1,b,3008);}

```

# Python 3, 62 + 2145 = 2207 bytes

Evil built-in. Input filename is `A`, which is an xz-compressed file of UTF-16 version.

```
import lzma
print(lzma.open('A','rt',encoding='utf16').read())

```

Compressor code:

```
import lzma
open('A','wb').write(lzma.compress(open('utf16_file.txt','rb').read(),lzma.FORMAT_ALONE))

```

# Answer
> 1 votes
# Java 8, 3640 (127 + 3513) bytes

```
import java.nio.file.*;v->{Files.lines(Paths.get("a")).map(x->x.length()>1?x+"。":x).forEach(System.out::println);}

```

The total byte-length of the original file is `4003` bytes. When we remove all trailing spaces and the trailing new-line, this becomes `3888` bytes. All the lines in the file except for the single digits end with , so removing all those and using `.map(x->x.length()>1?x+"。":x)` will save an additional `390` bytes.

Can definitely be golfed by just using an encoding/decoding compressed strategy, but whatever..

**Explanation:**

```
import java.nio.file.*;        // Required import for Files and Paths

v->{                           // Method with empty unused parameter and no return-type
  Files.lines(Paths.get("a"))  //  Read the file as a String-Stream
       .map(x->                //  Map over the lines:
         x.length()>1?         //   If the length of a line is larger than 1:
          x+"。"               //    Use the line + literal "。"
         :                     //   Else:
          x)                   //    Use the line as is
       .forEach(System.out::println);
                               //  And print each of those mapped lines
}                              // End of method

```

# Answer
> 1 votes
# 05AB1E, 2605 bytes

```
•!…мOÂ6м’ZÖ₁-Pr@½õθ₃žв∊}`?(Ć·Ò[Íš2мö$qjõaF“;<!S¤mC†&ζΓ{ãˆFiUM’^Nm…M¾g¹Ć"ú¥/ÐòvÂqŒ4©Ù
1£v4ÒÀÌçтΛ˜þ∍ãÛ[£FàΔт÷¾ÜʒÕā“q¾^|°7δ«à÷³þ§I₁˜ýΣŽê¾мΘà¹œb₅γ*Üã“öÚŸEà/‚µá¢—₃;œýLº₅fK“ÎIF‹{Æ~3âтü!ï^:¢Σιв¾¢ißŠk¥´∍Õ'ÀºζE×*ÆAÄj`î¦ûKλL&н"ĀÛĀ™ú¥ÖµвrÁD²āh—ζŒ%ÇxÃ²©¼Á¹Ù½Θ¾~‹¡¨FÞFg≠¨É÷ƒá_:§£Ãìć˜ùÍ´zεΘoиXhδ'úEÐÂÖ&Ô!¨ú¹Òó²˜OOäê₃\å`q[í ₆ΣuÍ¯¬ª₆-éßkEšxX¸ï.c‰ó€‡Kð"P[áìαλ€!f¨в≠ΣYí-ʒ{€0à51QÃè…Wöù·t8ÁÏ=U—–TòΩá¨y2˜z)@¥¹#lLP¬ÔO2ýÀòŒÍä∞Δk¿cÅŒã’[ºнe¬7¢UÙÈδ´'§ÀbMÞи@Q)Vα#*yÚì°®Š₂ªl@ƶÅ∞è‡¾V@ÁçĀoµ¯ˆåÀÓ£öWg1^Kåα³¿ζ™¯í¥‰®6ê¥AïƶTCR´"zêÛ^Äª;¥n₁*ŠäδÓ₂¡Ž²Áü,|tWR¨cd¢ú×λ>B¯ÃÈÒĆâŸÎŠ˜`ΛαPиĆ₂è9×)≠ç÷ºÀ‰ÆÒ—\|<RõéÅΛ₆¢µV¿ǝâÀë7q{Σ₄Ib éZrγ)αI¸Ñ-,E½Ó´¢å7Ö8-»CʒEā%eo
³tX1s–O∞d‚÷θT3†&ïÕ)Z¯н¾½røδ¦ÎÉη~ΩSëÞÓ¿w ∍Ð¿´6тв₂M~šÜKž×Ä¦ãÅšÓ3Ýàlá|å₃м_mCs©¥¾²Á[6À3{MÍO<‡
∍9¹eΩ(ǝPΔнÅZp“=1GÂbÏΛηñzÒ²ûζœÉ‹ön®œ¦ΛÞ0®ζï₄Þ>c¬ˆ~Θ*¤_é¨ÉBÔÕð₅€xÁIz‚æ(»'JRúÓd±^pÜ±λLα½‹FΔò(ΔÆrð6±/^н₅yì}ž6îEy…´θ2s25þÔô[>Å£и¬?Òd Ñ?`Ÿ∊Xlêx`:ŠòΘBŠ':´KM^нΓæ±s»∍vǝλà"‘ív32É»‚}@ÎÈé₃I¨zA³ÚÅb≠†ËØΘÙ¹Ý²ćÛ^fǝäÚ_™§Ô©₆Θeñ¼-иx(„àR—ÑWú/”.”OKéŽÎ‘™þÊð
N/8sØ§«ÀMÂηjIĆ2*bηǝ±m¨¬¾ΔtÃ_∍ÿþΩ¼∊÷γ½.,ÙC¯¤àÊhŠ[ˆñтúΓiƒ¯[~ηΛ₆¿–©µΩJ‹»\≠:°ù…нYĀì—!Ûl1™Ö¤°´A3-мćÞôîΣFÊ)Oƶ€lª®mĀ!%½ŽZdUºĆåùÛCp±?99äƒ\ñ£ÕH´¹0f±Q2Íö’Ćв₂ǝÔ§üñ&ÔÎèçÆw¦â«×ý'Ë₃ʒвƵ
nAä„ÐĆs<F×¿4dxç©ù‹ʒóTË)¡≠{ùO5₅ʒ@
Ö…U²&¨®lŽuu“≠¹ÍÒWZâÃ¶_Ûyt‰ΛuItÃλfŒ3Ž¨Ƶ}+â©¨ƶ—*Ê1и≠ž]ˆÛ$?ʒu¾2z>ôÿÚ¤ÄŸE₁Uò!Ƶf1A1ζ‹Öj:¸Zc2Ã^d_¾₂Í%l"jÊ˜ð„.tþì∊Γ*WÛÓ™§ÜÁŒÁòz‘Σ·kçŽ>Ï~ÕÃn\β8δ₄XMe¹Ú‰.$ƒ=ÏÕ…¡˜bH5¼pñвÆÉ×¬~ßιÀP$WÆñ;Uðè‰#uú‡Ï²т?¢þ»ÂÈÑÛ@Úć‰f0Èö₅Í°¼0₆õòÿ∍ª¢ÈUTà’æÊöü₆ÉIмΛú:Σ£…Ç×ÜBÂµãÓq₃¡н¸‰4œÞª(∊ΓÍ[εS_?ì…KнâOùFr½³ê∍*θ§€‘PÄ¾õÔ ªÃΔ”Duï¿Ćub¨Λé3ìCð6µK=Çθ>wjñ‰yP¦
gr¸N(Ô½G>“aóÀo»³{Î§_øā(¢*´ΓyĀí´R§æÀ0$MÔˆζÜÊàx¸Û₁¨и"+ƶÑǝtJ”É‹Mçò‘tývÓ^:¡Ü‘≠OË!θÃw₂î(∍‘Pœ²ižraïΓ]E∞zo5θè@[žĀS4€jU≠ÃZD*Ðùв†ù·Λ{’₃≠„αûΣT3Ì×¯OS¤T–Œþ&ÞVKV.∍2§Gú₃₁~ª¼)(ø><q₂¤S»þìAMв+ U’Íy†p×E0‚QÛ£Ü–½7=nyÚ˜qú6;Δ“Ì¹YĀ—p₅!Ω"a–|á&†ª“ëkBQöã}3
s××ĀΓ¶ü¸†¹è¹zÒć†@+2ΓRαÃðû∊$º–„Ÿã>\>|d£Ýõõdʒhû#“IƒvJýi{Ùʒ₃-±¥)—ÝÅн{Š\e∞‡Δ-8¹ûÌâ₃±
«ãÜ‹›tdÂ«W"Ô£&₄;åL à¿мÂλÌм£«н₆¹NóüQH„w¦ºÔòcΔ¡HáÕ¢δĆShΔÈÔBX`Â´0₃iè«®°—fS$×ǝ&Ë3nH]wÂß0µ∍±ò+ÚΓqQ]õºćuH~°ÄÜÉ’=øƶË₄¹\ï≠7ðDg›½ÑšƵ÷é3µÿη–|Øìä₄CĀ²‹₅So–saÆ₃¦õÌÉr—=0ć₆?ŸÛÏƶ‡[õ¸β%H<-çмlÞ„‹59°C>#ÓΛh₂µJôü…ι¥mΩ«ÎP`§т·¥Òž©Ó¤½θVC!’вxjí<:∍{ÇS&PsÆÅË†:₄Ì¡ˆΛð∍ó«:ièîðÕ{ôт%F¨2uÞ∍ù)/θÙ-αŒj)7·BÿJ€Ãδñ«[éÒm‡ìõиà₁AVw₆ÇÇÂk“Ÿkˆ£}TžŽ¹©¤âò+gZεê}ñÖàΔ÷ǝ³U;°:ûhmÑòÏÜ₄[ÛÁçû$µ“"Xz€‚zλ1
¯0ï3ƶTн=íõ99ƒñβÌõöæ¶E˜ƵÝÑŒà·ƒFÊVùûèÏWŒþā4αº+ŒÔFàŽrÆ#'€î²d¸xLmAĀ÷«vV°©!¯āÌØ≠в'ÕxêÃÄmWβªŸíê¢6}2ú…åô%gÿEXÙr6íËÛ€¶Ý₄·®₄¬ºó«'(Ë—ûá—ÔË½*e‚*Õ›Ø/"‘¡oαΛñ†4~¸qCyî>òšqu"₆Æ¡áë“¤š_¦¦!т<gÙ×¼'oθp²n¶'^±‚X!½ƶΔ>{is¢λ"oAÁjв₄z‹ø₆)5HˆCÍ‘˜Þðêβƶÿùc¼λoM₄ªÞΛ≠H&ÚþýoÒÝ¥@a³Y[áæ°$¢}ćĆ¹±»₂¥˜³²™Lm9GΘΣΛ«2‚O»‘ηhĀÛˆ\¥ηÕÞ ‘6Rm‹ð≠~r–[+“Å7Àx/т÷âIι”Õ¾õ'3K[]=€Q}Ô,XÖè₁3µ /ÖZ₄X
≠è₁÷
≠Rèxž×hÉÑ’₁óqÊÒ:<eÀÙØãÚžNg‹Ā~Gη«ø¶`rΣÖ)Ä«Ω.Ç<Æ;´(…;±+§AP™wQÉι×¶т+_Ωj-Ê°ƒ§¡çóùÿ‡αØAh—“ζì(Adß¾y‚2ÿÄyFìεíøíagúÐ₂¥¼MsÀïê;EAŠ+³ìΘEwC–Hç•5ôçTô»

```

Try it online!

---

*Shrugs in 05AB1E: I'm astonished how direct base conversion almost ties BG...*

---
Tags: code-golf, kolmogorov-complexity, unicode
---


title: Ain't no thang! ...or is it?

text:
# Question
Title: Ain't no thang! ...or is it?
# Introduction

Street talk can be really difficult to understand, in particular to programmers, who aren't known to be very streetwise.

It is your job to create an interpreter to help us all survive in the urban environment.

# Challenge

Given an English sentence as input, create a program or a function that determines whether the outcome of the sentence is positive or negative.

The sentence will contain `0` to `2` negative words. As any programmer knows, a double negative results in a positive. Therefore, your code must output or return a truthy/falsey value according to the following rule:

```
No negative words  -> truthy
One negative word  -> falsey
Two negative words -> truthy

```

The list of negative words:

* `no`, `not`, `none`
* Anything ending in `n't`
* `never`, `neither`, `nor`
* `nobody`, `nothing`, `nowhere`

There is one edge case. Whenever a sentence begins with `No,`, that word isn't treated as a negative word when determining the result (it does count towards the number of negative words so there can be just one more).

The sentence will follow basic grammar rules (capitalization, punctuation) and will only contain words that can be found from a dictionary (luckily, this doesn't invalidate the question title). The sentence won't contain any proper nouns (sorry, Dr. No, you're out).

# Test cases

**Truthy:**

```
Yes.
It's noon.
Hello, World!
What is this?
Ain't no thang!
Never say never.
No, it's noon now.
Neither me nor you.
I didn't do nothing!
No, I am your father.
A non-alcoholic drink.
I can't get no satisfaction.
All your base are belong to us.

```

**Falsey:**

```
No.
No, no!
Not today.
Neither am I.
Don't do that!
That's no moon!
And none survived.
Is this not my car?
No man is an island.
Nosebleeds are no fun.
Nothing compares to you.
That's a no, I'm afraid.
No, I am not your mother.

```

The irony here, of course, is that some of these *should* be interpreted differently. But hey, you can't fault the speaker for not conforming to our logic.

# Rules

Standard loopholes are forbidden. This is , so be concise!

# Answer
## Retina, 63 bytes

```
No,

Mi`\bn(e(ith|v)er|o(|body|ne|r|t|thing|where))\b|n't\b
0|2

```

Try it online!

### Explanation

```
No,

```

Remove `No,` from the input. Due to the capitalisation rules, this can only appear at the beginning of the input, so we don't need an explicit `^`.

```
Mi`\bn(e(ith|v)er|o(|body|ne|r|t|thing|where))\b|n't\b

```

Count the number of matches of the case-insensitive regex after the ```. It just matches all the relevant words, where I've extracted common prefixes/suffixes with the alternatives.

```
0|2

```

Count `0` or `2`s, so we turn even counts into `1` and odd counts into `0`.
> 10 votes

# Answer
# Bash, ~~115~~ ~~107~~ ~~99~~ ~~98~~ ~~97~~ ~~95~~ 85 bytes

Uses packages Core Utilities (for `wc`) and `grep`. Assume the sentence is given via Standard Input. **History expansion is disabled by `set +o histexpand`.**

```
((~`grep -Pio "(?!^no,)\b(no(|t|r|ne|body|thing|where)|ne(v|ith)er|.*n't)\b"|wc -l`%2))

```

Check the result: In Bash 0 is for true, 1 is for false

### How does it work?

```
((                       )) # Logical evaluation: non-zero to TRUE, zero to FALSE
  ~                    %2   # C-style arithmetic: Bit-Negate and Modulus 2
   $(                 )     # Output of the program chain
     grep -Pio "regex"      # PCRE match, ignore case, output matching part one-per-line
     | wc -l                # Pipe to `wc` and count number of lines

```

---

18 bytes (115 to 99) saved by inspiration from *Qwertiy*'s answer and *Martin Ender*'s answer. 1 byte thanks to *Nahuel Fouilleul*.
> 8 votes

# Answer
# Javascript ES6, ~~89~~ ~~87~~ 86 chars

```
s=>s.match(/(?!^no,)\bn(o(|t|r|ne|body|thing|where)|e(v|ith)er)\b|n't\b|$/ig).length&1

```

## Test:

```
f=s=>s.match(/(?!^no,)\bn(o(|t|r|ne|body|thing|where)|e(v|ith)er)\b|n't\b|$/ig).length&1

console.log(`Yes.
It's noon.
Hello, World!
Never say never.
Ain't no thang!
No, it's noon now.
Neither me nor you.
I didn't do nothing!
No, I am your father.
A non-alcoholic drink.
I can't get no satisfaction.
All your base are belong to us.`.split`
`.every(f))

console.log(`No.
No, no!
Not today.
Neither am I.
Don't do that!
That's no moon!
And none survived.
No man is an island.
Nosebleeds are no fun.
Nothing compares to you.
That's a no, I'm afraid.
No, I am not your mother.`.split`
`.every(s=>!f(s)))
```
> 5 votes

# Answer
## Perl 5, 74 bytes

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

```
s/No,//;$_=!(s/(\bn(o(r|t|ne|body|thing|where)?|e(v|ith)er)|n't)\b//gi%2)

```

Try it online!
> 2 votes

---
Tags: code-golf, string, decision-problem, natural-language
---


# Question
Title: Translate Morse code based on tone duration
# Goal

Morse code is often represented as sound. Given a stream of bits that represent whether sound is on or off, translate the stream into letters and numbers and spaces.

# Specifics

* The bit stream is analysed based on the length of repeating ON/OFF bits.
    + 1 ON bit is a dot
    + 3 ON bits are a dash
    + 1 OFF bit delimits dots and dashes
    + 3 OFF bits delimits characters
    + 7 OFF bits delimits words (space)
* The input may be a string or array. Only two unique characters/values of your choice are allowed in the input. (eg. 0/1, true/false, comma/space)
* The output returns a string or is printed to the standard output.

# Example

```
Input:    101010100010001011101010001011101010001110111011100000001011101110001110111011100010111010001011101010001110101
Analysis: \--H--/   E   \---L---/   \---L---/   \----O----/\-- --/\---W---/   \----O----/   \--R--/   \---L---/   \--D--/
Output:   HELLO WORLD

```

# Assumptions

* The stream always starts and ends with an ON bit.
* There is no leading or trailing whitespace.
* The input is always valid.
* All letters (case-insensitive) and digits are supported.

# Test Cases

```
101010100010001011101010001011101010001110111011100000001011101110001110111011100010111010001011101010001110101
HELLO WORLD

10100000001011100011101110000000101110000000101011101000101000101010001010101
I AM A FISH

1010111011101110001110111011101110111000101110111011101110001110111010101
2017

101010001110111011100010101
SOS

```

# Scoring

This is code golf. The lowest byte-count code by this time next week wins.

# Answer
> 9 votes
# APL (Dyalog), ~~65~~ ~~62~~ ~~60~~ 57 bytes

-3 thanks to ngn.

Tacit prefix function.

```
⎕CY'dfns'
morse'/|[-.]+'⎕S'&'∘(⊃∘'/. -'¨6|'1+|(00)+'⎕S 1)

```

Try it online! Header, `f←`, and Footer are just to allow calling the function from Input while retaining TIO's byte count. In a normal APL session (corresponding to TIO's Input field), it would not be needed.

`⎕CY'dfns'`**c**op**y** the *dfns* workspace (library)

`(``)` apply this tacit function:
`'1+|(00)+'⎕S 1` PCRE **S**earch 1-runs and even-length 0-runs and return matches' lengths
`6|` division remainder when divided by 6
`⊃∘'/. -'¨` for each match length, pick the corresponding character from this string
`'/|[-.]+'⎕S'&'∘` PCRE **S**earch slashes and dash/dot-runs and return those
`morse` translate from Morse code to regular text

# Answer
> 8 votes
# Python 2, ~~142~~ 135 bytes

```
lambda s:''.join(' E-T----Z-Q---RSWU--2FH-V980NIMA--1CBYX-6--GDOK534PLJ-7'[int('0'+l.replace('111','3'),16)%57]for l in s.split('000'))

```

Try it online!

**Explanation:**

Splits the string into letters on `000` (`0` thus means space)

Replaces each `111` with `3`, and converts into base 16.

Then each number is modded by `57`, which gives a range of `0..54`, which is the index of the current character.

---

Previous version that converted to base 3:

# Python 2, ~~273~~ ~~252~~ 247 bytes

```
lambda s:''.join(chr(dict(zip([0,242,161,134,125,122,121,202,229,238,241]+[2]*7+[5,67,70,22,1,43,25,40,4,53,23,49,8,7,26,52,77,16,13,2,14,41,17,68,71,76],[32]+range(48,91)))[int('0'+l.replace('111','2').replace('0',''),3)])for l in s.split('000'))

```

Try it online!

Previous version that converted to binary:

# Python 2, ~~282~~ ~~261~~ 256 bytes

```
lambda s:''.join(chr(dict(zip([0,489335,96119,22391,5495,1367,341,1877,7637,30581,122333]+[2]*7+[23,469,1885,117,1,349,477,85,5,6007,471,373,119,29,1911,1501,7639,93,21,7,87,343,375,1879,7543,1909],[32]+range(48,91)))[int('0'+l,2)])for l in s.split('000'))

```

Try it online!

# Answer
> 5 votes
# Ruby, 123 bytes

```
->s{s.split(/0000?/).map{|r|r[0]?"YE9_0IZTO_BHKU58V_GR_SFA__1_4NP_60X_____C__D_ML7WQ3__2__J"[r.to_i(2)%253%132%74]:" "}*""}

```

Try it online!

Split the input string on character limit. Use 3 or 4 OFF bits so that spaces are converted to empty strings. Take the base 2 value of every character, and bring into a reasonable range (less than 60 possible values) using modulo on 3 successive divisions.

# Answer
> 4 votes
# Python, ~~175~~ 168 bytes

```
s=lambda t,f=''.join:f('; TEMNAIOGKDWRUS;;QZYCXBJP;L;FVH09;8;;;7;;;;;;;61;;;;;;;2;;;3;45'[int('1'+f('0'if j[1:]else j for j in i.split('0')),2)]for i in t.split('000'))

```

First convert the string into list of 0(dash)/1(dot) string, add a prefix `1` (to prevent leading zeroes and deal with whitespaces), then convert to binary.

Since every code have length no more than 5, the result ranges from 0 to 63 and can be listed in a string.

# Answer
> 3 votes
# Jelly, ~~67~~ 62 bytes

```
ṣ0L€«2ḅ2“>.&" þ/7;=¥çı¿¢×ÆÐ¤æ€Œ©¦Çß÷µ¬£®Ñ½ðȷñ‘iịØB;⁶¤
œṣ0ẋ3¤Ç€

```

Try it online!

# Answer
> 3 votes
# Visual Basic .NET (.NET Core), 252 bytes

*-7 bytes thanks to @recursive*

```
Function A(i)
For Each w In i.Split({"0000000"},0)
For Each l In w.Split({"000"},0)
Dim c=0
For Each p In l.Split("0")
c=c*2+1+p.Length\2
Next
A &="!ETIANMSURWDKGOHVF!L!PJBXCYZQ!!54!3!!!2!!!!!!!16!!!!!!!7!!!8!90"(c)
Next
A+=" "
Next
End Function

```

A function that takes a string of `1`s and `0`s, and returns a string. (Actually, only the `0` for the `OFF` is a hard requirement. Anything not `OFF` is assumed to be `ON`).

The string literal is Morse code setup as a binary heap in array form. VB.NET lets you index strings as arrays of characters. The `\` is integer division, taking the left sub heap for `1` or the right sub heap for `111`.

I used `!` as a blank for when there isn't a value in that heap spot. It's only necessary to properly pad out the indices.

VB.NET lets you return by assigning a value to the function name (in this case, `A`). I just iteratively do string concatenations (`&`) to build up the output string. The very first time I need to use `&` because using `+` leaves a leading null char, but any other time I can use `+`, which behaves the same as `&` for strings.

Try it online!

# Answer
> 3 votes
# JavaScript (ES6), ~~170~~ 131 bytes

```
s=>s.split`000`.map(e=>'  ETIANMSURWDKGOHVF L PJBXCYZQ'[c=+`0b${1+e.replace(/0?(111|1)/g,d=>+(d>1))}`]||'473168290 5'[c%11]).join``

```

---

**How it works:**

If you change the dots to 0s and the dashes to 1s, and prefix with a 1, you get binary numbers, which when converted to decimal gives you:

1. Letters: 2 - 18, 20, and 22 - 29.
These can be converted to the correct letters by indexing into `' ETIANMSURWDKGOHVF L PJBXCYZQ'`.
2. Numbers: 32, 33, 35, 39, 47, 48, 56, 60, 62, and 63.
If we take these numbers modulus 11, we get the numbers 0 - 8 and 10, which can be converted to the correct numbers by indexing into `'473168290 5'`.

The program splits on characters, then converts each character into dots and dashes, which are converted into the appropriate output based on the above rules.

---

**Test Cases:**

```
let f=

s=>s.split`000`.map(e=>'  ETIANMSURWDKGOHVF L PJBXCYZQ'[c=+`0b${1+e.replace(/0?(111|1)/g,d=>+(d>1))}`]||'473168290 5'[c%11]).join``

console.log(f('101010100010001011101010001011101010001110111011100000001011101110001110111011100010111010001011101010001110101'))
console.log(f('10100000001011100011101110000000101110000000101011101000101000101010001010101'));
console.log(f('1010111011101110001110111011101110111000101110111011101110001110111010101'));
console.log(f('101010001110111011100010101'));
```

# Answer
> 3 votes
# Python 2, 127 bytes

```
lambda s:''.join("IVMB  T  K 9LZF 1HWO3 GUS4 8 7A  E QR 26   NJX    Y0P 5D  C"[(int('0'+l)^2162146)%59]for l in s.split('000'))

```

Try it online!

Building off of **TFeld**'s solution by removing *replace* and by working in base 10, at the cost of a bitwise xor and a longer reference string.

# Answer
> 2 votes
# PHP, ~~321~~ 284 bytes

*Saved 37 bytes thanks to @ovs*

```
$a=array_flip([242,161,134,125,122,121,202,229,238,241,5,67,70,22,1,43,25,40,4,53,23,49,8,7,26,52,77,16,13,2,14,41,17,68,71,76]);foreach(split('0000000',$argv[1])as$w){foreach(split('000',$w)as$m){echo($v=$a[base_convert(str_replace([111,0],[2,],$m),3,10)])>9?chr($v+55):$v;}echo' ';}

```

Previous version (321 bytes)

```
$a=array_flip([22222,12222,11222,11122,11112,11111,21111,22111,22211,22221,12,2111,2121,211,1,1121,221,1111,11,1222,212,1211,22,21,222,1221,2212,121,111,2,112,1112,122,2112,2122,2211]);foreach(split('0000000',$argv[1])as$w){foreach(split('000',$w)as$m){echo($v=$a[str_replace([111,0],[2,],$m)])>9?chr($v+55):$v;}echo' ';}

```

Try it online!

Ungolfed version :

```
$a=array_flip(
// Building an array $a with every Morse letter representation (1=dot, 2=dash) and flip it
               [22222,12222,11222,11122,11112,
                // 01234
                11111,21111,22111,22211,22221,
                // 56789
                12,2111,2121,211,1,1121,221,
                // ABCDEFG
                1111,11,1222,212,1211,22,
                // HIJKLM
                21,222,1221,2212,121,111,2,
                // NOPQRST
                112,1112,122,2112,2122,2211]);
                // UVWXYZ
foreach (split('0000000', $argv[1]) as $w){
// for each word (separate with 7 consecutive zeroes)
    foreach (split('000',$w) as $m){
    // for each letter (separate with 3 consecutive zeroes)
        echo ($v = $a[str_replace([111,0],[2,],$m)]) > 9
        // Replace '111' with '2' and '0' with nothing and find $v, the corresponding entry in the array $a
            ? chr($v+55)
            // If > 9th element, then letter => echo the ASCII code equal to $v+55
            : $v;
            // Else echo $v
    }
    echo ' ';
    // Echo a space
}

```

# Answer
> 2 votes
# Java (JDK), 355 bytes

```
s->{var r="";for(var t:s.split("0000000")){for(var u:t.split("000"))for(int x[]={1,7,5,21,29,23,87,93,119,85,117,341,375,343,373,471,477,349,469,1877,1367,1909,1879,1501,1911,1885,7637,5495,7543,7639,6007,30581,22391,122333,96119,489335},i=36;i-->0;)if(u.equals(Long.toString(x[i],2)))r+="ETISNAURMHD5WVLKGFB64ZXPOC73YQJ82910".charAt(i);r+=" ";}return r;}

```

Try it online!

## Credits

* -3 bytes saved thanks to @Jeutnarg.
* -6 bytes thanks to @ceilingcat

# Answer
> 2 votes
# GNU sed, 261 + 1 = 262 bytes

+1 byte for `-r` flag.

```
s/000/;/g
s/111/_/g
s/0//g
s/$/;:51111141111_3111__211___i1____6_11117__1118___119____10_____H1111V111_F11_1L1_11P1__1J1___B_111X_11_C_1_1Y_1__Z__11Q__1_S111U11_R1_1W1__D_11K_1_N__1G__1O___I11A1_M__E1T_/
:
s/([1_]+);(.*([^1_])\1)/\3\2/
t
y/i/1/
s/;/ /g
s/:.*//g

```

Try it online!

## Explanation

This is a very basic lookup table solution.

The first three lines transform the input so dashes are `_`s and dots are `1`s. First, `000`s are replaced with `;`, so characters are separated by `;` and words by `;;0`. Then `111`s are replaced by `_` and all remaining `0`s are discarded, leaving `1`s for dots.

```
s/000/;/g
s/111/_/g
s/0//g

```

The next line appends the lookup table. It takes the form `cmcmcm...` where `c` is a character and `m` is the sequence of `_`s and `1`s representing it. `i` is substituted for `1` in the table for disambiguation. Since regular expressions in sed are always greedy, the table is sorted from longest to shortest code (so e.g. `1_` matches `A1_` instead of `i1____`).

```
s/$/;:51111141111_3111__211___i1____6_11117__1118___119____10_____H1111V111_F11_1L1_11P1__1J1___B_111X_11_C_1_1Y_1__Z__11Q__1_S111U11_R1_1W1__D_11K_1_N__1G__1O___I11A1_M__E1T_/

```

Next, in a loop, each sequence of `_`s and `1`s (and the subsequent `;`) is replaced by the corresponding character:

```
:
s/([1_]+);(.*([^1_])\1)/\3\2/
t

```

Finally, cleanup: `i`s are replaced with `1`s, remaining `;`s are spaces, and the lookup table is deleted:

```
y/i/1/
s/;/ /g
s/:.*//g

```

# Answer
> 1 votes
# Jelly, 67 bytes

```
ŒrḌṣ7ṣ€3ṣ€€1’H_4F€€ḅ3i@€€“ṗƙ⁶}zyȮẓŀȯ¦CFæ¢+ı(¥5ç1®¬ȷ4MÑÆ£Ç)×DGL‘ịØBK

```

Try it online!

# Answer
> 1 votes
# Retina, ~~144~~ ~~138~~ ~~130~~ 103 bytes

```
T`d`@#
^|@@@

 @?#
E
{T`L#@`R6_BI_Z5S1C_GD8__\L\HNF3P__7_`\w@#
T`589B-INPRSZ#@`490XYKT2\OVAMJWUQ_`\w##

```

Try it online! Link includes test cases. Explanation:

```
T`d`@#

```

Change the binary digits to other characters because 0 and 1 are valid outputs.

```
^|@@@

```

Insert a space before every character and two spaces between words.

```
 @?#
E

```

Assume that all characters are Es.

```
{T`L#@`R6_BI_Z5S1C_GD8__\L\HNF3P__7_`\w@#

```

Translate all letters assuming that they will be followed by a dot. For instance, if we have an E, and we see a second dot (we consumed the first when we inserted the E) then it translates to an I. For letters that can only be legally followed by a dash, they are translated with that assumption, and then the dash is consumed by the next stage. Other letters are deleted (keeping `L` costs a byte).

```
T`589B-INPRSZ#@`490XYKT2\OVAMJWUQ_`\w##

```

If it transpires that they were in fact followed by a dash, then fix up the mistranslations. This also consumes the dash when it was assumed by the previous stage. Both translations are repeated until all of the dots and dashes are consumed.

# Answer
> 1 votes
# JavaScript (ES6), ~~104~~ ~~102~~ ~~101~~ 99 bytes

```
s=>s.split`000`.map(n=>" _T__9VEFO0K7MX_CGS__LU1RYIJ845__Z_B_D6QP_3__AHNW2"[n*1741%8360%51]).join``

```

### Test cases

```
let f =

s=>s.split`000`.map(n=>" _T__9VEFO0K7MX_CGS__LU1RYIJ845__Z_B_D6QP_3__AHNW2"[n*1741%8360%51]).join``

console.log(f("101010100010001011101010001011101010001110111011100000001011101110001110111011100010111010001011101010001110101"))
console.log(f("10100000001011100011101110000000101110000000101011101000101000101010001010101"))
console.log(f("1010111011101110001110111011101110111000101110111011101110001110111010101"))
console.log(f("101010001110111011100010101"))
```

### How?

Because converting from binary to decimal costs bytes, we use a hash function which works directly on binary blocks interpreted in base 10.

**Example**

```
dot dash dot dot = 101110101
101110101 * 1741 = 176032685841
176032685841 % 8360 = 3081
3081 % 51 = 21

--> The 21st character in the lookup table is 'L' (0-indexed).

```

# Answer
> 0 votes
# Perl 5, 241 + 1 (`-p`) = 242 bytes

```
%k=map{(23,469,1885,117,1,349,477,85,5,6007,471,373,119,29,1911,1501,7639,93,21,7,87,343,375,1879,7543,1909,489335,96119,22391,5495,1367,341,1877,7637,30581,122333)[$i++]=>$_}A..Z,0..9;map{$\.=$k{oct"0b$_"}for split/000/;$\.=$"}split/0{7}/}{

```

Try it online!

# Answer
> 0 votes
# PHP, 181+1 bytes

```
foreach(explode(_,strtr($argn. 0,[1110=>1,10=>0,"0000"=>_A,"00"=>_]))as$t)echo$t<A?~$t[-5]?(10+substr_count($t,0)*(1-2*$t[-5]))%10:__ETIANMSURWDKGOHVF_L_PJBXCYZQ[bindec("1$t")]:" ";

```

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

# Answer
> 0 votes
## ES6, 268 bytes

Uses ASCII encoding after mapping from a base36 representation of the morse to an index position. Not my best golf day, but it only took around 15 mins.

```
s=>s.split('00000').map(w=>String.fromCharCode.apply({},w.split('000').map(c=>"ahkn,225z,h9z,48n,11z,9h,1g5,5w5,nlh,2me5,,,,,,,,n,d1,1gd,39,1,9p,d9,2d,5,4mv,d3,ad,3b,t,1h3,15p,5w7,2l,l,7,2f,9j,af,1g7,1h1".split(',').indexOf(parseInt(c,2).toString(36))+48))).join(' ')
```

Easier to read (kinda):

```
s=>
s
.split('00000')
.map(w=>
 String.fromCharCode.apply({},
  w.split('000')
   .map(c=>
    "ahkn,225z,h9z,48n,11z,9h,1g5,5w5,nlh,2me5,,,,,,,,n,d1,1gd,39,1,9p,d9,2d,5,4mv,d3,ad,3b,t,1h3,15p,5w7,2l,l,7,2f,9j,af,1g7,1h1"
    .split(',')
    .indexOf(
     parseInt(c,2).toString(36)
    )+48)
   )
 ).join(' ')
```

# Answer
> 0 votes
# Wolfram Language (Mathematica), 288 bytes

Thought about reading in the data as binary from a file but that gets hard to explain. Base 36 seemed like a good compromise way to store the data efficiently lexically.

Takes a string of 0's and 1's as input. Does a series of replacements, starting with the runs of 7 zeros, then the runs of 3, then the longest binary letters down to the shortest. Order of replacement is important.

```
StringReplace[#,Thread@Rule[Join[{"0000000","000"},#~FromDigits~36~IntegerString~2&/@StringSplit@"ahkn 2me5 225z nlh h9z 5w7 5w5 5tj 4mv 48n 1h3 1h1 1gd 1g7 1g5 15p 11z d9 d3 d1 af ad 9p 9j 9h 3b 39 2l 2f 2d t n l 7 5 1"],Insert[Characters@" 09182Q7YJ3OZCX6P4GKBWLFV5MDRUHNASTIE","",2]]]&

```

Try it online!

# Answer
> 0 votes
## Perl 5, 195 bytes

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

```
%h=map{$_,(A..Z,0..9)[$i++]}unpack"S26I2S7I","\xd5]u]\xddUw\xd7uww\xdd\xd7]WWwWwuwwwwwWwWUU\xd5uw\xdd\xdd";s/0{7}/ /g;s/(\d+?)(000|\b)/$h{oct"0b$1"}/ge

```

I couldn't get this working with just a standard packed binary string, I had to escape the higher-byte chars otherwise I'd be on 171, if anyone knows what I've missed, or why it's breaking that'd be great!

Try it online!

### Explanation

The binary string is a `pack`ed list of the numbers that relate to the morse characters (`101011101` \- `349` for `F` etc) and this is zipped with the ranges `A..Z,0..9` and used as a lookup. The `s///` expressions replace all runs of seven `0`s with space and then all runs of digits, separated with three `0`s or word boundaries `\b`, with their corresponding key from the `%h` hash.

---
Tags: code-golf, morse
---


# Question
Title: Iterative Alliterative Additive Array Antics
I honestly don't know what the point of this sort of calculation would be, but it should make fun golfing. Shortest code wins.

## Input (in no particular order)

* An array of integers, `a` (All elements will be integers less than the length of the array.)
* An index therein, `i`
* An iteration count, `n`

## Processing

* Store a number `x` with initial value of `0`.
* Do the following steps `n` times:
    1. Add the current value of `i` to `x`.
    2. Decrement `a[i]`.
    3. If `a[i]` is negative, increment it by the length of `a`.
    4. Set `i` to `a[i]`.
* After the iterations, add the final value of `i` to `x`.

## Output

After doing the above process, your program should output the final value of `x`.

## Example (n=5)

```
a                     i   x
2,0,0,5,5,6,7,5,8,5   0   0
1,0,0,5,5,6,7,5,8,5   1   0
1,9,0,5,5,6,7,5,8,5   9   1
1,9,0,5,5,6,7,5,8,4   4   10
1,9,0,5,4,6,7,5,8,4   4   14
1,9,0,5,3,6,7,5,8,4   3   18

```

The program outputs `21`.

## Test Case Generator

```
function newTestCase() {
    var a = Array(Math.floor(Math.random() * 50) + 25).fill(0);
    a = a.map(Math.random).map(e => e * a.length).map(Math.floor);
    var i = Math.floor(Math.random() * a.length);
    for (var x = 0, n = 0, aa = [...a], ii = i; Math.random() * a.length >= .5;) {
        n++;
        x += ii;
        aa[ii]--;
        if (aa[ii] < 0) aa[ii] += a.length;
        ii = aa[ii];
    }
    return {a, i, n, shouldOutput: x + ii};
}
```

```
<button type="button" onclick="console.log(newTestCase());">Generate</button>
```

# Answer
> 5 votes
# Ruby, ~~54~~ 53 bytes

```
->a,i,n{i+(1..n).map{i=a[i]+=a[i]<1?a.size-1:-1}.sum}

```

Try it online!

# Answer
> 5 votes
# Python 2, 71 bytes

```
def f(a,i,n):x=0;exec"x+=i;a[i]+=len(a)*(a[i]<1)-1;i=a[i];"*n;print x+i

```

Try it online!

# Answer
> 3 votes
# Kotlin, ~~86~~ 82 bytes

```
{a,i,n->var x=0;var y=i;(0..n).map{x+=y;a[y]+=if(a[y]<1)a.size-1 else-1;y=a[y]};x}

```

Try it online!

---

## Ungolfed

```
{a, i, n ->
    var x=0
    var y=i
    (0..n).map{
        x+=y
        a[y]+=if(a[y]<1) a.size -1 else -1
        y=a[y]
    }
    x
}

```

# Answer
> 3 votes
# , ~~95~~ 83 bytes

```
function(a,i,n){for(j in 1:n){F=i+F-1
i=(a[i]=a[i]-1+(a[i]-1<0)*sum(a|1))+1}
F+i-1}

```

Try it online!

Takes `i` as a 1-based index, so it requires some adjustment to account for that.

# Answer
> 3 votes
# JavaScript (ES6), ~~57~~ ~~56~~ 55 bytes

*Saved one byte thanks to @Lynn.*

```
a=>n=>g=(i,x=0)=>n--?g(a[i]-=a[i]?1:1-a.length,x+i):x+i

```

Takes input in currying syntax in the format `f(a)(n)(i)`.

## Test Cases

```
f=
a=>n=>g=(i,x=0)=>n--?g(a[i]-=a[i]?1:1-a.length,x+i):x+i
;
console.log( /*21*/ f([2,0,0,5,5,6,7,5,8,5])(5)(0) )
console.log( /*2066*/ f([18,26,9,26,58,53,35,28,0,47,44,6,24,11,66,48,63,64,3,19,67,55,59,35,37,22,41,8,51,44,3,58,58,9,31,29,20,63,43,19,53,28,40,70,20,46,3,69,34,63,49,29,42,69,26,49,37,26,41,62,7,3,66,55,27,59,9,2,36,24,61,6,7])(63)(26) )
console.log( /*1182*/ f([58,3,43,19,8,8,50,24,31,10,8,17,23,2,8,19,19,45,9,46,7,4,6,31,33,19,8,18,37,11,57,28,35,20,22,35,42,38,7,2,48,28,5,17,54,35,5,35,29,9,22,39,27,49,62,40,0,48,52,42,40,24,26])(46)(39) )
```

# Answer
> 1 votes
# C, ~~66~~ 63 bytes

The first argument is the length of the array.

*Thanks to Justin Mariner for saving 3 bytes.*

```
f(l,a,i,n,x)int*a;{for(x=i;n--;x+=i=a[i]+=l*!a[i]-1);return x;}

```

Getting negative after decrement means it is zero before that.

Try it online!

# Answer
> 1 votes
# Python 2, 59 bytes

```
def f(a,i,n):x=i;exec"a[i]=i=~-a[i]%len(a);x+=i;"*n;print x

```

Try it online!

Similar to XCoder's, but makes use of simultaneous assignment, and python's delightful negative modulus, plus re-ordering some instructions to eliminate the extra addition.

# Answer
> 0 votes
# Java, 87 bytes

I went with a recursive method for this

```
int r(int[]a,int i,int n){return n>0?(i=a[i]>0?--a[i]:(a[i]=a.length-1))+r(a,i,--n):0;}

```

see IDEone here

---
Tags: code-golf, array
---


# Question
Title: The answer to life, the universe, and ASCII-art
Simple challenge: try to output the following text in as few bytes as you can:

```
       the        answer
      toli      fetheuniv
     ersea     nde     ver
    ything     the     ans
   wer tol     ife     the
  uni  ver           sean
 dev   ery         thin
gth    ean       swer
tolifetheuni    ver
seandeveryth   ing
       the     ans      wer
       tol     ifetheuniver
       sea     ndeverything

```

The original drawing contains 332 characters.

### Rules

* No input or an unused input.
* Output can be in any reasonable format (string, list of strings, matrix of chars and so on).
* You can use uppercase instead of lowercase for the drawing if your prefer so.
* Trailing whitespaces and newlines allowed.
* This is , so may the shortest program/function for each language win!

### Notes

* This has been identified as a possible duplicate of We're no strangers to code golf, you know the rules, and so do I. That question was about searching and replacing text. Here you have to draw a shape using a given text, and at least two of the current answers demonstrate that golfing languages can beat plain compression algorithms in this case.

# Answer
# Python 3, ~~224 220 219 215 211~~ 194 bytes

* Thanks to @TFeld for ~~1~~ 5 bytes: `if(j%27<1)*j` instead of `if j*(j%27<1)` and simplified print statement.
* Thanks to @Leaky Nun for 4 bytes:Inverting 0 and 1, did not require the padding by zeros `7*'0'`
* **@Leaky nun saved 17 bytes with his awesome golfing skills(Thanks a lot!!!!): awesome use of modular indexing**

```
i=j=0
k=int("OHZE5WCKDTW6JYMO1JNROAAJQVAN6F8KEO0SMKJM86XIBMCEH5FXXONZGBAVCN3689DS",36)
while k:j+=1;print(k%2*'theanswertolifetheuniverseandeverything'[i%39]or' ',end='\n'*(j%27<1));i+=k%2;k//=2

```

Try it online!

## Explanation:

Uses base-36 compression to compress this binary number(new-line excluded)

```
111111100011111111000000111
111111000011111100000000011
111110000011111000111110001
111100000011111000111110001
111000100011111000111110001
110001100011111111111000011
100011100011111111100001111
000111100011111110000111111
000000000000111100011111111
000000000000111000111111111
111111100011111000111111000
111111100011111000000000000
111111100011111000000000000

```

We basically have two counters `i` and `j`. On encountering a `1` we print a space; Else if `0` is encountered we print next letter from the string and increase `i`. `j` increases for each `0 or 1`. We also print new-lines whenever necessary i.e. when `j%27<1` becomes true.
> 21 votes

# Answer
# Python 2, ~~235~~ ~~218~~ 213 bytes

```
x=bin(int('OC5POO6MZYQNBWY0RP6BKBZCOZL13MIAB6I8YZ5N7LXSZBVKX7GC57AW5631YCJ6XCLC',36))[2:].replace('1',' ')
for c in'theanswertolifetheuniverseandeverything'*4:x=x.replace('0',c,1)
while x:y,x=x[:27],x[27:];print y

```

Try it online!

Switched to a base 36 encoded int of the positions of letters as hinted in thew question.

Replaces each character one at a time.

```
       111        111111                              the        answer
      1111      111111111                            toli      fetheuniv
     11111     111     111                          ersea     nde     ver
    111111     111     111                         ything     the     ans
   111 111     111     111                        wer tol     ife     the
  111  111           1111                        uni  ver           sean
 111   111         1111             --->        dev   ery         thin
111    111       1111                          gth    ean       swer
111111111111    111                            tolifetheuni    ver
111111111111   111                             seandeveryth   ing
       111     111      111                           the     ans      wer
       111     111111111111                           tol     ifetheuniver
       111     111111111111                           sea     ndeverything

```

Edit: It seems officialaimm used base 36 before me.
> 8 votes

# Answer
# Bubblegum, 125 bytes

```
0000000: 45 8f c5 01 03 31 0c 04 ff ae 62 4b 0b 99 02 c7  E....1....bK....
0000010: d8 7d 84 e7 f9 59 30 5e 41 59 4a 84 71 ef e6 3d  .}...Y0^AYJ.q..=
0000020: 4e c1 ea fd b7 42 48 91 66 d6 ae 6e da 89 d3 1c  N....BH.f..n....
0000030: ef 60 ba 97 ae 6e b6 74 2e a5 76 d9 ad ae e4 16  .`...n.t..v.....
0000040: 69 59 08 a6 a6 e8 23 d4 22 af 08 d0 20 7d 17 f0  iY....#."... }..
0000050: 8a 9b 7c 76 c2 61 7b c8 4b 01 41 23 50 24 32 87  ..|v.a{.K.A#P$2.
0000060: f5 98 9e 88 35 24 21 83 ac 50 b2 e0 a2 16 0e 42  ....5$!..P.....B
0000070: bb ba a5 bc ae 6e bd 76 b7 69 d9 f9 07           .....n.v.i...

```

Try it online!
> 7 votes

# Answer
# Python 2, 220 213 212 bytes

*-1 byte by switching `()*4` for `%39` from* **@officialaimm**

```
s=""
w=l=i=0
for g in`int("352G7FS4XC8J2Q2M2HNK7IZI65Z9TVUMHOZ6MR3HY46RQBLWY4PR",36)`[:-1]:
	for j in g*int(g):l+=1;s+=[' ',"theanswertolifetheuniverseandeverything"[w%39]][i%2]+"\n"*(l%27<1);w+=i%2
	i+=1
print s

```

Try it online!

This is a different approach from the other Python answers. I use a hex **base-36** (saved 7 bytes) encoding of a PNG-style  RLE-style encoding of the image (a string of digits indicating the number of consecutive repeated pixels).

**The string of digits is**:

```
73869469755353565353431353533323902433339443437469034389033390735363735903735903
```

Then I iterate through those digits and alternately print that number of ' 's or characters from the palette ('theanswer...'). When more than 9 of a character is repeated, I'd simply add a 0 and then the remainder.
> 6 votes

# Answer
# 05AB1E, ~~83~~ ~~79~~ 74 bytes

-4 bytes thanks to Erik the Outgolfer

Outputs a list of strings to save a byte.

```
•2ÖH₆Ôn₅Ò\ÊÑĆ¸Ý¾*£„ÔûC∞qΘœ™‚¹µ—₃₄fm•vNÈy×vyiðë¾¼’€€Ž»to‚ì€€ªÜ€ƒ‰Ö’è}}}J27ô

```

Try it online!

### Explanation

`2ÖH₆Ôn₅Ò\ÊÑĆ¸Ý¾*£„ÔûC∞qΘœ™‚¹µ—₃₄fm` is the base 255 representation of the decimal number:

```
73869469755353565353431353533323902433339443437469034389033390735363735903735903

```

Which encodes runs of `1`s and `0`s respectively, even indices being the `1`s and uneven indeices the `0`s. This evaluates to the binary number:

```
111111100011111111000000111
111111000011111100000000011
111110000011111000111110001
111100000011111000111110001
111000100011111000111110001
110001100011111111111000011
100011100011111111100001111
000111100011111110000111111
000000000000111100011111111
000000000000111000111111111
111111100011111000111111000
111111100011111000000000000
111111100011111000000000000

```

### Code

```
•...•                                         Convert from base 255 to decimal
     v                                }       For each digit, do:
      NÈy×                                       is_even(index) repeated that many times
          v                          }           For each digit, do:
           yi                       }               If digit is truthy, then:
             ð                                         Push space
              ë                                     Else:
               ¾¼                                      Get and increment counter, starts at 0
                 ’€€Ž»to‚ì€€ªÜ€ƒ‰Ö’                    Push "theanswertolifetheuniverseandeverything"
                                   è                   Get the character at that index
                                       J      Join whole stack
                                        27ô   Split into parts of 27

```
> 6 votes

# Answer
# SOGL V0.12, 74 bytes

```
"ō⅓׀?@C⁶¬IΧΖO‘@øŗč"βΘ⅔Μv∙KΩqψ3╥W≡A;2ļm½±iq╗∆Δ⁶Πqīσ‽ε⁰5τΩ⅜δσΞoΤi┘‽N¹\Λ:‘'    n

```

Try it Here!

```
"...‘              push "the answer to life the universe and everything". because of a bug-not-really-bug, the starting quote is required
     @øŗ           remove spaces
        č          chop it into characters
         "...‘     push a string of spaces and ŗ where ŗ gets replaced with each next characters of the character array
              ' n  split into an array of line length 27

```
> 5 votes

# Answer
Allow me to answer my own question...

# Charcoal, 140 126 112 bytes

```
Ａ⟦⟧βＦ⁶⁸Ｆ⁻℅§”c#*U[“⎆Ｖl¶·δ‴ü"Ｉp8ξＺ{e/⪫¦σMＭ⪫¢Ｑ⁸UＬê←⪫W?—υ⁻$⌀)”ι³⁴«¿﹪ι²§”m⌊0Ｙ℅¿№”XＪ-⁵η}Z¿8_*<o%!±Ÿ”Ｌ⊞Ｏβω ¿¬﹪Ｌ⊞Ｏυω²⁷⸿

```

Try it online!

You have here a link to the closest verbose version.

Explanation (see verbose version for details):

* The `)%*(+&(+)''%'%'('%'%&%#%'%'%%%$%-&%%%%+&&%&%)&(.&%*.%%2%'%(%)%'.)%'.` string (68 bytes, 48 bytes compressed) is a representation of the RLE-encoding of the drawing. Every char code minus 34 is the number of spaces (even positions) or the number of text characters (odd positions) to print consecutively.
* The algorithm just decompress the RLE-encoded string and writes the next char of the `gtheanswertolifetheuniverseandeverythin` string (39 bytes, 27 bytes compressed) every time a non-whitespace character is needed to be written. As I check the length of a list to get the next character and that list starts with one element, the last character of the string is written in the first position.
* Every 27 characters written I insert a new line.

### Acknowledgments

* Many thanks to Neil and his amazing tips for allowing me to save 28 bytes and finally be able to beat Bubblegum. :-)
> 5 votes

# Answer
## JavaScript (ES6), ~~207~~ ~~205~~ 203 bytes

Returns an array of strings with some trailing spaces.

```
let f =

_=>[16515968,33489856,k=58950624,k+16,k-40,31458204,7865230,1966983,462847,233471,117670784,k=134185856,k].map(n=>'heanswertolifetheuniverseandeverythingt '.replace(/./g,(_,i,s)=>s[n>>i&i<27?k++%39:39]))

console.log(f().join('\n'));
```
> 5 votes

# Answer
# Retina, 183 bytes

```

7386¶6469¶555353¶465353¶33135353¶23239024¶133394¶034374¶090343¶090333¶735363¶735903¶735903¶theanswertolifetheuniverseandeverything
.*$
$&$&$&$&
(\d)(.)
$1$* $2$*
+s`1([ 1¶]+)(.)
$2$1

```

Try it online! Explanation: The first stage adds the RLE encoding of the cell bitmap and the text, which the second stage then duplicates to the correct length, while the third stage decodes the RLE encoding. The fourth stage then moves the text into the cells.
> 4 votes

# Answer
# Jelly, 83 bytes

```
“¡eu⁾ṃṣƬİḂṃ½)ṣṾṘƇ@^AṀẆṫ+¢ṗɲ⁾ṭḋZ`⁺×Ṗj½Ṇ-Þḣ2żṿƤc’BCẋ"`“ÆZ⁺ƙ{Æß¥ŀŒ1gỤ3Ḍṭṁ ṃjɓ»ṁȯ€⁶s27Y

```

Try it online!

## How it works

```
“XX’BCẋ"`“YY»ṁȯ€⁶s27Y
“XX’                   a large number
    B                  binary
     C                 complement
      ẋ"`              1 becomes [1] and 0 becomes []
             ṁ         reshape
         “YY»             "theanswertolifetheuniverseandeverything"
              ȯ€⁶      replace [] with " "
                 s27   split into chunks of length 27
                    Y  join with newline

```
> 4 votes

# Answer
# Add++, 1398 bytes

```
+32
&
&
&
&
&
&
&
+84
&
-12
&
-3
&
-69
&
&
&
&
&
&
&
&
+65
&
+13
&
+5
&
+4
&
-18
&
+13
&
-104
&
+22
&
&
&
&
&
&
+84
&
-5
&
-3
&
-3
&
-73
&
&
&
&
&
&
+70
&
-1
&
+15
&
-12
&
-3
&
+16
&
-7
&
-5
&
+13
&
-108
&
+22
&
&
&
&
&
+69
&
+13
&
+1
&
-14
&
-4
&
-65
&
&
&
&
&
+78
&
-10
&
+1
&
-69
&
&
&
&
&
+86
&
-17
&
+13
&
-104
&
+22
&
&
&
&
+89
&
-5
&
-12
&
+1
&
+5
&
-7
&
-71
&
&
&
&
&
+84
&
-12
&
-3
&
-69
&
&
&
&
&
+65
&
+13
&
+5
&
-105
&
+22
&
&
&
+87
&
-18
&
+13
&
-82
&
+84
&
-5
&
-3
&
-76
&
&
&
&
&
+73
&
-3
&
-1
&
-69
&
&
&
&
&
+84
&
-12
&
-3
&
-91
&
+22
&
&
+85
&
-7
&
-5
&
-73
&
&
+86
&
-17
&
+13
&
-82
&
&
&
&
&
&
&
&
&
&
&
+83
&
-14
&
-4
&
+13
&
-100
&
+22
&
+68
&
+1
&
+17
&
-86
&
&
&
+69
&
+13
&
+7
&
-89
&
&
&
&
&
&
&
&
&
+84
&
-12
&
+1
&
+5
&
-100
&
+93
&
+13
&
-12
&
-72
&
&
&
&
+69
&
-4
&
+13
&
-78
&
&
&
&
&
&
&
+83
&
+4
&
-18
&
+13
&
-104
&
+106
&
-5
&
-3
&
-3
&
-3
&
-1
&
+15
&
-12
&
-3
&
+16
&
-7
&
-5
&
-73
&
&
&
&
+86
&
-17
&
+13
&
-104
&
+105
&
-14
&
-4
&
+13
&
-10
&
+1
&
+17
&
-17
&
+13
&
+7
&
-5
&
-12
&
-72
&
&
&
+73
&
+5
&
-7
&
-93
&
+22
&
&
&
&
&
&
&
+84
&
-12
&
-3
&
-69
&
&
&
&
&
+65
&
+13
&
+5
&
-83
&
&
&
&
&
&
+87
&
-18
&
+13
&
-104
&
+22
&
&
&
&
&
&
&
+84
&
-5
&
-3
&
-76
&
&
&
&
&
+73
&
-3
&
-1
&
+15
&
-12
&
-3
&
+16
&
-7
&
-5
&
+13
&
-17
&
+13
&
-104
&
+22
&
&
&
&
&
&
&
+83
&
-14
&
-4
&
-65
&
&
&
&
&
+78
&
-10
&
+1
&
+17
&
-17
&
+13
&
+7
&
-5
&
-12
&
+1
&
+5
&
-7
&
P

```

Try it online!

It looks like hardcoding it is the shortest way (at least in Add++)
> 3 votes

# Answer
## Vim, 239 keystrokes

```
:h4<CR>3hy5bZZitheanswerto<Esc>p:%s/ \|,//g<CR>ye3P
lqqi<CR><Esc>qqw3li <Esc>lq3@wbhr<CR>16l@q@w3-@w6l@ql@w9l@qll3@whr<CR>3l9@w4l@q 2@w4l@q2@w4l@q9l2@wlr<CR>9l@w4klr<CR>4whr<CR>jj
el<C-v>3k"aD0jji <Esc>qqdiwukPi <Esc>q5@qwy04j$"ap6+<C-v>GPp3kw3i <Esc>2@q4kbXj2@qywh<C-v>4jp2je<C-v>jj4A <Esc>8j5i <Esc>b<C-v>jj2I <Esc>

```

Linebreaks added for "readability"

### Explanation

The first line yanks `life, the universe and everything` from a help page, which is one byte shorter than simply typing it out. It then turns that into this:

```
theanswertolifetheuniverseandeverythingtheanswertolifetheuniverseandeverythingtheanswertolifetheuniverseandeverythingtheanswertolifetheuniverseandeverything

```

The second line breaks the string up into:

```
the answer
toli fetheuniv
ersea nde ver
ything the ans
wer tol ife the
uni ver sean
dev ery thin
gth ean swer
tolifetheuni ver
seandeveryth ing
the ans wer
tol ifetheuniver
sea ndeverything

```

And then the final line indents it to make:

```
       the        answer
      toli      fetheuniv
     ersea     nde     ver
    ything     the     ans
   wer tol     ife     the
  uni  ver           sean
 dev   ery         thin
gth    ean       swer
tolifetheuni    ver
seandeveryth   ing
       the     ans      wer
       tol     ifetheuniver
       sea     ndeverything

```
> 3 votes

# Answer
# Jelly, 76 bytes

```
“¡¢ʋỵṆ⁻kỴ⁷ṁḤæ ƊVṛĠ¥¡¢tṢ}ȧƘ=ẒṆ_`-p1ḷṠ’ḃ⁴ĖŒṙḂ¬R“£:(ḥB⁼Ṇ#¥Ṡ1ɗĠðȮ $¿⁹½ɓ»ṁȯ€⁶s27Y

```

Try it online!
> 3 votes

# Answer
# Retina, 185 bytes

```

7!8&sw'6Bi6fe!Av¶5#sea5nde5v'4y%g5!5&s¶3w#1B5ife5!¶2A2v#92se&¶1dev3#y9%¶gth4e&7sw'Bife!A4v'se&dev#yth3ing¶7!5&s6w'7B5ife!Av'7sea5ndev#y%g
'
#¶
&
an
%
thin
#
er
!
the
A
uni
B
tol
\d
$*

```

Try it online!
> 2 votes

# Answer
# JavaScript, 215 bytes

solution based on guest44851

```
$=>'a21xb0k9qf30155yiv016ewp3018lkhz0ohfdb077or302cl5b0mgzr0b8hz028ghs7028gi67028gi67'.split(p=0).map(x=>parseInt(x,36).toString(2).slice(1).replace(/./g,x=>" theanswertolifetheuniverseandeverything"[+x&&1+p++%39]))

```
> 2 votes

# Answer
# Ruby, 216 bytes

```
o=i=1
puts"6iffnqxq0opdbco5e3f1zk5d7eezo2j6zwly9z5yykqsc1hl5svaof".to_i(36).to_s(17).chars.map{|c|
o=!o
c.to_i(17).times.map{o ? (i+=1)&&"ngtheanswertolifetheuniverseandeverythi"[i%39]:" "}.join
}.join.scan /.{1,27}/

```

Try it online!

**Explanation** Similar to the Python solutions but I used Run Length Encoding before converting to base 36. So the data string is only 54 characters instead of 68.

But it still ended up longer over all, hopefully it can be golfed further.
> 2 votes

# Answer
A port of my Charcoal answer:

# C# (.NET Core), 229 bytes

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

```

Try it online!
> 2 votes

# Answer
# C (gcc), ~~220~~ ~~219~~ ~~217~~ ~~213~~ 210 bytes

-1 byte thanks to ceilingcat

-3 bytes thanks to Jerry Jeremiah

```
q,i,j,t;main(c){for(;c="HDIG@GEGJ@FFFDFD@EGFDFD@DDBDFDFD@CDCDLE@BDDDJE@ADEDHE@AMED@AMDD@HDFDGD@HDFM@HDFM"[t++];)for(c%=64,j=c?q=!q,c:2;--j;)putchar(c?q?32:"theanswertolifetheuniverseandeverything"[i++%39]:10);}

```

Try it online!
> 2 votes

# Answer
# JavaScript, ~~265~~ ~~237~~ 219 bytes

```
(i=0)=>'jwq80,13ntvk,26p62g,25g7w8,239k3c,zg4xc,7rpbk,1e9dc,b8mw,5mbc,4f9reg,4f9r0g,4f9r0g'.split`,`.map(b=>parseInt(b,36).toString(2).slice(1).replace(/./g,c=>'  theanswertolifetheuniverseandeverything'[+c||2+i++%39]))

```

Few bytes off thanks to @tsh.

# JSFiddle
> 1 votes

# Answer
# Pyth, 121 bytes

This contained too many bytes that I couldn't get to show up in TIO, so here's a hexdump:

```
00000000: 7558 6848 477c 2a64 6548 622c 5658 434d  uXhHG|*deHb,VXCM
00000010: 2290 8d8d 817e 7e7b 7875 7572 6663 5753  "....~~{xuurfcWS
00000020: 504d 4946 4343 3f3c 3939 3633 302d 2d2a  PMIFCC?<99630--*
00000030: 2721 211e 1b16 160d 0909 0300 225d 545d  '!!........."]T]
00000040: 3133 6a43 2202 1232 a464 b09d 7303 4244  13jC"..2.d..s.BD
00000050: 9386 74d2 e954 b89e e722 3132 2a34 2e22  ..t..T..."12*4."
00000060: 6179 1aa6 55ad c176 932b 6088 d5c5 556c  ay..U..v.+`...Ul
00000070: e4f4 5575 12a0 e7fb 1f                   ..Uu.....

```

Try it online!

You can add a call to `wc` or `xxd` in the bash script to see the byte length or the hexdump I produced above.

Interestingly, this program demonstrates a minor bug (?) in Pyth. Any carriage return bytes (0x0d) are read as newline bytes (0x0a) when in string literals. This forces me to add 6 bytes: `X ... ]T]13` to replace the incorrect ten with a thirteen.

Otherwise the idea behind this code was fairly simple: record each position where a run of whitespace occurs. Then, pair each of those indices with the number of spaces in that run. Then, reconstruct the original string by repeating the phrase four times, then inserting in the correct locations. If the number of spaces recorded was zero, instead a newline is inserted.
> 1 votes

# Answer
# Java (OpenJDK 8), ~~258~~ ~~252~~ 251 bytes

```
z->{int i=0,x,j,N[]={16515968,33489856,x=58950624,x+16,x-40,31458204,7865230,1966983,462847,233471,117670784,x=134185856,x};for(int n:N)for(j=32;j-->0;n/=2)System.out.print(n%2<1?j<1?"\n":" ":"theanswertolifetheuniverseandeverything".charAt(i++%39));}

```

Try it online!

It's a rather naive implementation. First a mask, for the printed characters, then a roll over the text until done.

* 6 bytes saved thanks to Carlos Alejo!
> 1 votes

# Answer
# Javascript, approximate drawing. 319 bytes

```
s=32
t="theanswertolifetheuniverseandeverything"
j=0
o=""
b=document.createElement('canvas'),c=b.getContext('2d')
b.width=b.height=s
c.font="25px Verdana"
c.fillText('42',0,20)
m=c.getImageData(0,0,s,s)
i=0
while(i<m.data.length) {
 d=m.data[i+3]
 o+=d?t[j%t.length]:" "
 if(d)j++
 i+=4
}
o.match(/.{1,32}/g).join("\n")

```

^ for what it's worth, not much really, but before I delete the failed code.
> 0 votes

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