title: Draw the ☣ (Biohazard Symbol)

text:
# Question
Title: Draw the ☣ (Biohazard Symbol)
Draw the Biohazard symbol in an arbitrary colour on a distinctly coloured background. The specific proportions were published in the June 27th 1974 issue of the Federal Register of the US Government.

### Details

* As output, writing to a file (raster and vector formats are permitted) or displaying on the screen are both allowed.
* You can draw just the border or the filled shape.
* If you use raster images, you should take a parameter (or two) as input that lets you adjust the resolution of the output (e.g. width/height).
* The background must at least have the size of the bounding box of the symbol but may be larger.
* Outputting the unicode symbol ☣ is not sufficient.
* The exact ratios of the used distances are given in following diagram (which was originally from here):

I also tried to make an additional diagram with the same measurements that is hopefully a little bit easier to read:

(Inspired by a post on 99%invisible)

# Answer
> 105 votes
# T-SQL, ~~442 441 426 355 349~~ 344 bytes

```
DECLARE @ VARCHAR(MAX)=REPLACE(REPLACE(REPLACE('DECLARE @a5MULTIPOINT((0 31),(19 -2),(-19 -2))'',@b5MULTIPOINT((0 39),(26 -6),(-26 -6))'',@5POINT(0 9)'',@d5LINESTRING(0 9,0 99,90 -43,0 9,-90 -43)''SELECT @a830%b821)%86)%d81)%d84%819))).STUnion(@827%820)).STIntersection(@b819)))'
,8,'.STBuffer('),5,' GEOMETRY='''),'%',').STDifference(@')EXEC(@)

```

Saved 70+ bytes by using `REPLACE()` for long keywords and executing as dynamic SQL. See the post-replacement code in the screenshot below.

I doubled the coordinate values from the sample illustration and moved up 9 units, to reduce the number of decimals displayed.

This was done in SQL 2017, using geo-spatial features introduced in SQL 2008. Lots of useful built-in geometry functions, including `STBuffer`, which gives me a simple way to define circles of different sizes around a point.

Visual of output, with annotated code:

For more T-SQL drawing, see my Easter Bunny.

For more *practical* applications of this tech in SQL, read this article or watch this video. SE even has a related site, gis.stackexchange.com.

**Edits:**

1. Saved 1 byte by changing a coordinate from 104 to 99.
2. Saved 15 bytes by taking the `STDifference` of a `STUnion` of objects, instead of each individually.
3. Saved 71 bytes by using `REPLACE()` on repeated keywords, then executing as dynamic SQL. Reverted Edit 2, to leave more replacements of `STDifference`.
4. Saved 4 bytes by moving the center up 9 units, which changed a few coordinates to single (negative) digits. This also freed up the numeral `5` to use as a replacement character instead of `'#'`, saving 2 more bytes on the quotes.
5. Saved 5 bytes by moving `)` into the `STDifference` replacement string; thanks, @Nicholas!

# Answer
> 37 votes
# Tex + Tikz, 232 bytes

*43 bytes saved by switching to tex. Thanks to Phelype Oleinik*

*Some bytes saved thanks to Skillmon*

```
\input tikz \tikz[x=1,y=1,white]{\def\f{\foreach\1in{90:,210:,330:}}\def\u{\draw[line width=}\def~{circle(}\f\fill[red](\122)~30);\f{\u2](0,)--(\111);\u8](\130)--(\160);\fill(\130)~21);}\fill~6);\u7,red]~23.5);\f\u2](\130)~20);}\bye

```

With line breaks and without `\def`:

```
\input tikz
\tikz[x=1,y=1,white]{
\foreach\1in{90,210,330}\fill[red](\1:22)circle(30);
\foreach\1in{90,210,330}{
\draw[line width=2](0,0)--(\1:11);
\fill(\1:30)circle(21);
\draw[line width=8](\1:30)--(\1:60);
}
\fill(0,0)circle(6);
\draw[line width=7,red](0,0)circle(23.5);
\foreach\1in{90,210,330}\draw[line width=2](\1:30)circle(20);
}
\bye

```

## Explanation

*This is a little outdated I will fix it when I can figure out how to make the images not enourmous*

Here I am going to explain how the uncompressed answer solves the problem. I may at some point explain how the compression works. First we draw the big black circles:

```
\foreach\x in{90,210,330}\fill(\x:21)circle(30);

```

Then we draw some white lines:

```
\foreach\x in{90,210,330}\draw[white,line width=2cm](0,0)--(\x:11);

```

Then we draw white circles:

```
\foreach\x in{90,210,330}\fill[white](\x:30)circle(21);

```

Then we add a central white circle:

```
\fill[white](0,0)circle(6);

```

Then we add a black annulus:

```
\draw[line width=7cm](0,0)circle(25.5);

```

Then we remove parts of the black annulus

```
\foreach\x in{90,210,330}\draw[white,line width=2cm](\x:30)circle(20);

```

# Answer
> 18 votes
# C, 8010 bytes

Way back, before SVG or EMF, you had to deal with raster, and if you wanted something to load right away, say before the O/S was ready, like a Windows startup screen, you had to use RLE, or run-length-encoding. This monster outputs a PBM file using RLE as the data. Build like usual and run like this `./biohazard > biohazard.pbm`.

If you were to include all the frameworks required to generate, e.g. the SVG engine in HTML, the Java libraries, etc. this would likely be the smallest *self-contained solution*, because `puts` is the only external function, and it's typically one of the smallest `stdio.h` functions.

Regarding this detail:

> If you use raster images, you should take a parameter (or two) as input that lets you adjust the resolution of the output (e.g. width/height).

I interpreted "should" as different from "must", e.g. as in RFC 2119, so I didn't include scaling, because for this code it would only be feasible to do multiples of the original, e.g. `./biohazard 2` and that would introduce `atoi`, `printf` and other complications which would detract from the main focus of the submission.

```
int o,i,x[]=
{4946,3,33,2,389,8,33,8,378,13,33,13,369,17,33,16,363,20,33,20,356,19,41,19,350,18,49,18,344,18,55,18,339,17,61,17,334,
17,66,17,330,17,71,17,325,17,75,17,321,17,79,17,317,17,83,17,313,17,87,16,311,16,90,17,307,17,93,17,303,17,97,17,300,
17,99,17,297,17,102,18,293,18,105,17,291,18,107,18,288,17,110,18,285,18,113,17,283,18,115,18,280,18,117,18,277,19,119,
18,275,19,121,19,272,19,123,19,270,19,125,19,268,19,127,19,266,19,129,19,263,20,131,19,261,20,133,19,259,20,134,20,257,
20,136,20,255,21,137,20,253,21,139,20,251,21,141,20,249,21,142,21,248,21,143,21,246,21,145,21,244,21,146,22,242,22,147,
22,240,22,149,22,238,22,150,22,238,22,151,22,236,22,152,23,234,23,153,23,232,23,155,22,232,23,155,23,230,23,157,23,228,
24,157,24,226,24,159,23,226,24,159,24,224,24,160,25,222,25,161,24,222,24,162,25,220,25,163,25,219,25,163,25,218,25,164,
26,216,26,165,25,216,26,165,26,214,26,166,26,214,26,167,26,212,27,167,26,212,26,168,27,210,27,169,27,209,27,169,27,208,
27,170,28,207,27,170,28,206,28,171,27,206,28,171,28,204,29,171,28,204,28,172,29,202,29,172,29,202,29,173,29,201,29,173,
29,200,30,173,29,200,30,173,30,198,31,173,30,198,30,174,31,197,30,174,31,196,31,174,31,196,31,175,31,195,31,175,31,194,
32,175,31,194,32,175,32,193,32,175,32,193,32,175,32,192,33,175,32,192,33,175,33,191,33,175,33,190,34,175,33,190,34,175,
33,190,34,175,34,189,34,174,35,189,34,174,35,188,35,174,35,188,35,174,36,187,36,173,36,187,36,173,36,187,36,173,36,186,
37,74,25,74,36,186,37,67,39,67,36,186,37,62,49,61,38,185,37,58,57,57,38,185,38,53,64,54,38,185,38,50,71,50,38,185,38,
47,76,48,38,185,38,45,81,44,39,184,40,41,87,41,39,184,40,39,91,39,39,184,40,37,95,37,39,184,40,35,99,34,41,183,41,32,
103,32,41,183,41,30,107,30,41,183,41,28,111,27,42,183,42,25,115,25,42,183,42,24,117,24,42,183,42,22,121,21,43,183,43,
19,124,20,43,183,43,18,127,18,43,183,43,17,129,16,44,183,44,14,133,14,44,183,44,13,135,12,45,183,45,11,137,11,45,183,
45,10,139,9,46,183,46,9,138,10,46,183,46,10,137,9,47,183,47,9,136,10,47,183,47,10,135,9,48,183,48,10,56,20,57,10,48,
183,49,9,50,33,49,10,48,184,49,10,45,41,45,10,48,184,50,10,40,49,40,10,49,184,50,10,37,55,36,10,50,185,50,10,33,60,34,
10,50,185,51,10,30,65,30,10,51,185,51,11,27,69,27,10,52,185,52,10,25,73,24,11,52,185,53,10,22,77,21,11,53,185,53,11,19,
81,19,10,53,186,54,11,16,85,16,10,54,185,56,11,13,88,14,11,56,181,59,11,11,91,11,11,59,176,63,11,8,94,9,11,63,171,66,
11,6,97,6,11,66,167,68,12,4,99,4,11,69,163,71,12,1,102,2,11,72,159,74,126,75,155,77,124,78,151,80,123,79,149,82,120,83,
145,85,118,86,141,88,116,88,139,90,114,91,135,93,112,93,133,96,109,96,130,98,107,98,127,101,104,102,124,104,101,104,
122,106,99,106,119,110,95,109,117,112,93,112,114,115,89,115,112,118,85,118,110,120,82,121,107,124,78,124,105,127,74,
127,103,131,69,130,101,134,65,133,99,137,60,137,97,141,54,141,95,146,47,145,93,151,39,150,91,157,29,156,89,166,13,165,
88,168,9,168,86,169,9,169,84,170,9,170,82,171,9,171,80,172,9,171,79,173,9,172,78,173,9,173,76,174,9,174,74,175,9,175,
72,176,9,175,72,176,9,176,70,177,9,177,68,64,20,93,10,94,20,63,68,57,34,83,17,83,33,58,66,54,42,77,21,76,43,54,64,51,
50,71,25,71,49,51,64,48,57,65,29,65,56,49,62,46,63,61,31,61,62,47,60,45,67,58,33,58,67,44,60,43,71,55,35,54,72,43,58,
41,36,8,32,52,37,51,33,8,35,41,58,40,36,17,26,49,39,48,27,16,37,40,56,39,38,22,23,46,41,45,24,21,39,39,55,37,40,26,21,
43,42,44,21,26,40,37,54,36,42,29,20,41,43,41,20,29,42,36,53,35,43,29,21,39,44,39,22,29,43,35,52,34,45,29,23,37,45,37,
23,29,45,34,51,33,46,29,24,35,46,35,25,29,46,33,50,32,48,29,26,33,47,33,26,29,47,33,49,31,49,29,27,32,47,32,27,29,49,
31,48,31,49,30,28,30,48,30,29,29,50,31,47,29,51,30,30,28,49,28,30,29,51,30,46,29,52,29,32,27,49,27,31,29,53,28,46,28,
53,29,33,26,49,26,32,29,54,28,44,28,54,29,34,25,49,25,33,29,55,27,44,27,55,29,35,24,49,23,35,29,56,27,43,26,56,29,36,
22,50,22,36,29,57,26,42,26,57,29,37,21,50,21,37,29,58,26,41,25,58,29,38,21,49,20,38,29,59,25,40,25,59,29,39,20,49,19,
39,29,60,24,40,24,60,29,40,19,49,19,39,29,61,24,39,23,61,29,41,18,49,18,40,29,62,23,38,23,62,30,41,17,49,17,41,29,63,
22,38,22,63,30,42,16,48,17,42,29,63,23,37,21,65,29,43,16,47,16,43,29,64,22,36,22,65,29,43,16,47,15,44,29,65,21,36,21,
66,29,44,13,50,14,44,29,66,21,35,20,67,29,45,11,53,11,45,29,67,20,34,20,68,29,46,8,57,8,46,29,67,20,34,20,68,29,46,6,
61,5,46,30,68,19,34,19,69,29,47,4,63,4,46,30,69,19,33,18,70,30,47,1,67,1,47,29,70,19,32,19,70,30,163,29,71,18,32,18,71,
30,61,2,37,2,61,29,72,18,31,17,73,29,59,5,35,5,58,30,72,18,31,17,73,29,58,7,33,7,57,30,73,17,30,17,74,30,55,10,31,10,
55,30,73,17,30,17,74,30,53,13,28,14,53,30,74,16,30,16,75,30,51,17,25,16,52,29,75,17,29,16,76,29,50,20,21,19,50,30,76,
16,29,15,77,30,50,21,16,22,50,30,77,15,29,15,77,30,50,26,7,25,51,30,77,15,28,15,78,30,51,57,50,30,78,15,28,15,78,31,50,
56,51,30,79,15,27,14,80,30,51,55,51,30,79,15,27,14,80,30,51,55,50,31,80,14,27,13,81,31,51,53,51,30,81,14,27,13,82,30,
51,53,51,30,82,13,27,13,82,31,50,52,51,31,82,13,26,13,83,31,51,51,51,31,82,13,26,13,83,31,51,51,50,31,84,12,26,13,84,
31,50,50,51,31,84,12,26,12,85,31,51,49,50,32,84,13,25,12,85,32,50,49,50,31,86,12,25,12,86,31,50,48,50,32,86,12,25,11,
87,32,50,47,50,32,86,12,25,11,87,32,50,47,49,32,88,11,25,11,88,32,49,47,49,32,88,11,25,11,88,32,49,46,49,32,89,11,25,
10,90,32,49,45,49,32,89,11,25,10,90,33,48,45,48,33,90,10,25,10,91,32,48,45,47,33,91,10,25,10,91,33,47,44,48,33,91,10,
25,10,91,34,46,44,47,33,92,10,25,9,93,33,47,43,46,34,92,10,25,9,93,34,46,43,46,33,93,10,25,9,94,34,45,43,45,34,94,9,25,
9,94,35,44,43,44,34,95,9,25,9,95,34,44,42,44,35,95,9,25,9,95,35,43,42,44,34,96,9,25,9,96,35,42,42,43,35,96,9,25,8,97,
36,42,41,42,35,97,9,25,8,98,36,41,41,41,36,97,9,25,8,99,36,40,41,40,36,98,8,26,8,99,37,39,41,39,36,99,8,26,8,100,37,38,
41,38,37,99,8,27,7,100,38,37,41,37,37,101,7,27,7,101,38,36,41,36,38,101,7,27,7,102,38,35,41,35,38,102,7,27,7,102,39,34,
41,34,38,103,7,27,7,103,39,33,41,33,39,103,7,27,7,104,39,32,41,32,39,104,7,27,7,104,41,30,41,30,40,104,7,29,6,105,41,
29,41,29,40,105,7,29,6,106,41,28,41,28,41,105,7,29,6,107,42,26,41,26,42,106,7,29,6,108,42,25,41,25,42,107,7,29,7,107,
44,22,42,23,43,108,6,30,7,108,44,21,42,21,45,108,6,31,6,109,45,19,42,20,45,109,6,31,6,110,46,17,43,17,46,110,6,31,6,
111,47,15,43,15,47,111,6,31,6,112,48,13,43,13,48,112,5,33,5,113,49,11,43,10,50,112,6,33,5,114,50,9,43,9,50,113,6,33,6,
113,50,8,44,9,49,114,6,33,6,114,48,9,45,8,48,115,5,35,5,115,47,9,45,8,47,116,5,35,5,117,45,8,46,9,45,116,6,35,6,117,44,
8,46,9,44,117,5,37,5,118,42,9,47,8,43,118,5,37,5,119,41,9,47,9,41,119,5,37,5,120,40,8,48,9,40,119,5,39,5,120,39,8,48,9,
38,121,5,39,5,121,37,9,49,8,37,122,5,39,5,123,35,9,49,9,35,123,4,41,5,123,34,8,50,9,34,123,5,41,5,124,32,9,51,9,31,125,
5,42,3,127,30,9,51,9,30,127,3,43,1,130,28,9,52,9,29,130,1,176,26,9,53,9,26,310,24,9,54,9,24,314,22,9,55,9,22,317,20,9,
55,9,20,320,18,9,56,10,17,324,15,10,57,9,16,327,13,9,58,10,13,331,10,10,59,9,11,335,8,9,60,10,8,339,5,10,61,9,6,344,2,
9,62,10,2,358,63,368,65,367,65,366,67,365,67,364,69,362,70,362,71,360,73,358,75,356,76,356,77,354,79,352,81,350,82,349,
84,215,2,130,86,130,3,79,5,129,87,128,6,77,6,127,89,126,6,79,6,125,91,124,7,80,6,123,93,122,7,82,6,121,95,120,7,84,6,
119,97,118,7,86,7,115,100,116,7,87,8,113,102,114,7,89,8,111,105,111,7,91,8,109,107,109,7,93,8,107,109,106,9,94,9,103,
112,104,9,96,9,101,115,101,9,98,10,97,118,98,10,100,10,95,121,95,10,102,11,91,124,92,11,104,11,89,127,88,11,107,12,85,
131,85,11,110,12,81,135,81,12,112,13,77,138,78,13,114,14,73,143,73,14,116,15,69,72,2,73,69,15,118,17,63,74,5,73,64,16,
122,17,59,75,7,75,58,18,124,19,53,77,9,77,53,19,126,22,45,79,13,78,46,21,130,24,37,82,15,81,38,24,132,28,27,85,18,86,
27,28,135,37,5,95,21,95,5,37,138,134,24,135,141,131,27,131,144,128,31,127,148,124,34,125,151,121,37,121,155,117,41,117,
159,113,45,113,163,109,49,109,167,105,53,105,171,101,57,101,175,96,62,96,181,91,67,91,185,86,72,86,191,80,78,81,196,74,
84,74,204,67,91,67,211,59,99,59,219,51,107,51,228,40,119,39,242,25,133,25,5311,0};
main(){for(puts("P1\n432 408");x[i];++i,o=!o)while(x[i]--)puts(o?"0":"1");}

```

# Answer
> 17 votes
# TeX + Ti*k*Z, ~~234~~ ~~230~~ ~~226~~ 224 bytes

Originally 5 bytes longer than Sriotchilism O'Zaic's answer, but this one should be correct. It is similar to his answer but saves a few bytes more here and there, it needs one `\draw[line width=8]` more (in the code below this is done by `\28](~30)to(~55);`, that's 17 bytes added only for this) to get the tips of the symbol right, hence the 5 bytes more overall code length.

* thanks to Sriotchilism O'Zaic I reread some specifications of the question and realized I can change the colour to red, so that saves a few bytes again.
* another two bytes were stripped thanks to Joe85AC's comment

```
\input tikz\let~\def~\1{circle(}~\2{~\draw[line width=}~~{\foreach~in{90:,210:,330:}}\tikz[x=1,y=1,white]{~\fill[red](~22)\130);~\fill(~30)\121);\28](~30)to(~55);\22](~0)to(~10);\fill\16);\27,red]\123.5);\22](~30)\120);}\bye

```

# TeX-g + Ti*k*Z, 195 Bytes

Just if someone cares, the following uses a TeX-based code golf dialect that I'm working on (don't consider the code stable). The byte count includes EOL characters and the EOF character, as those are semantically used (EOL delimits arguments of loops). The dialect is pretty small up until now and only features shorthands for definitions and a for-loop syntax, however it is not specifically written for this answer, so it shouldn't break the rules of code golfing. Repository for the `-g.tex`-package/file: https://github.com/Skillmon/TeX-g

```
\input-g <tikz>~"{\:~{90:,210:,330:}}~'{circle(}~_{\draw[line width=}!f\fill\tikz[x=1,y=1,white]{"f[red](~22)'30);
"f(~30)'21);_8](~30)to(~55);_2](~0)to(~10);
f'6);_7,red]'23.5);"_2](~30)'20);
}

```

Output of both code snippets looks identical:

(*too lazy to update the image, just imagine it being red*)

# Answer
> 16 votes
## SVG(HTML5), ~~434~~ ~~410~~ ~~321~~ 306 bytes

```
<svg viewbox=-60,-60,120,120><circle r=23.5 stroke-width=7 fill=#fff stroke=#000 /><use href=#g transform=scale(-1,1) /><g id=g><use href=#p transform=rotate(120) /><use href=#p transform=rotate(240) /><path id=p stroke=#fff stroke-width=2 d=M5,0A5,5,0,0,0,0,-5V-10A20,20,0,0,0,2,-50V-53A31,31,0,0,1,31,-17
```

Now based on @LevelRiverSt's SVG. Edit: Saved 12 bytes thanks to @G0BLiN.

# Answer
> 13 votes
# Processing, ~~371~~ 368 bytes

```
translate(width/2,width/2);scale(width/99);int i=0,b=204;float t=TAU/3;noStroke();for(;i<3;i++){fill(0);ellipse(0,-22,60,60);rotate(t);}for(;i<6;i++){fill(b);rect(-4,-60,8,16);ellipse(0,-30,42,42);rotate(t);}ellipse(0,0,12,12);stroke(0);strokeWeight(7);noFill();ellipse(0,0,47,47);for(;i<9;i++){strokeWeight(2);stroke(b);ellipse(0,-30,40,40);line(0,0,0,-9);rotate(t);}

```

I wasn't sure if Processing should count as rasterized or not for the purpose of this challenge. If it counts as rasterized, the `translate` and `scale` is necessary to make the symbol legible and on-screen for a given window size. But, because all of the drawing commands are vectorized, it works at any given scale; so if we assume drawing at the relative origin to be about 200 units wide is fine, the first 43 bytes can be dropped.

This assumes the background color is `204, 204, 204`, which is the default background color in processing. It also assumes a `rectMode` of `CORNER` and an `ellipseMode` of `CENTER` (the defaults)

With an initial `size(640, 640)`, the resulting sketch looks like this:

By doubling the scale, I saved 3 bytes, because `.5`s are eliminated (though several numbers do flow from 1 digit to 2 digit).

The construction is similar to the TeX solution, drawing black and then gray on top to "erase" the gaps between the shape.

Explanation:

```
translate(width/2,width/2); // Move to the middle of the canvas
scale(width/99);            // Scale up to fill the canvas

int i=0,b=204;              // Initialize i, and `b` to the background color
float t=TAU/3;              // Save a rotation of one third, in radians

noStroke();
for(;i<3;i++){ // Draw the three big black circles
  fill(0);
  ellipse(0,-22,60,60);
  rotate(t);
}
for(;i<6;i++){
  fill(b);
  rect(-4,-60,8,16);     // "Blunt" the corners on the sharp outer rings
  ellipse(0,-30,42,42); // Cut out the middle of the big circles
  rotate(t);
}
ellipse(0,0,12,12); // Cut out the small circle in the middle
stroke(0);
strokeWeight(7);
noFill();
ellipse(0,0,47,47); // Draw the thick band that goes through all three big circles
for(;i<9;i++){
  strokeWeight(2);
  stroke(b);
  ellipse(0,-30,40,40); // Cut the "gap" between the three big rings
                        //and the band passing through them
  line(0,0,0,-16);      // Cut the lines coming out of the small middle circle
  rotate(t);
}

```

# Answer
> 12 votes
# Java 10, ~~860~~ 841 bytes

```
import java.awt.*;v->new Frame(){Color C;public void paint(Graphics g){var G=(Graphics2D)g;int t=300;G.fillOval(150,40,t,t);G.fillOval(55,205,t,t);G.fillOval(245,205,t,t);G.setColor(C.WHITE);G.fillOval(195,45,t=210,t);G.fillOval(65,270,t,t);G.fillOval(325,270,t,t);G.fillOval(270,270,60,60);G.fillRect(295,240,10,60);G.fillPolygon(new int[]{246,251,303,298},new int[]{326,334,304,296},4);G.fillPolygon(new int[]{298,349,354,303},new int[]{304,334,326,296},4);G.fillRect(280,0,40,80);G.fillPolygon(new int[]{30,50,119,99},new int[]{433,467,427,393},4);G.fillPolygon(new int[]{550,570,501,481},new int[]{467,433,393,427},4);G.setColor(C.BLACK);G.setStroke(new BasicStroke(35));G.drawOval(183,183,235,235);G.setColor(C.WHITE);G.setStroke(new BasicStroke(10));G.drawOval(200,50,t=205,t);G.drawOval(70,275,t,t);G.drawOval(330,275,t,t);}{show();}}

```

**Output:**

And here with each part colored differently to see what is actually being drawn:

## Explanation:

Unlike all other answers, rotating and drawing would be even longer in Java, so instead I'm using default draw methods. This unfortunately came with one big disadvantage: I need to know the \\$x,y\\$-coordinate of the top-left corner of the square surrounding the circle, and its width/height. As well as some more \\$x,y\\$-coordinates for rotated rectangles. This took A LOT of calculations to finally finish with this code and output.

The sizes are based on a center point at coordinate \\$\[300,300\]\\$, with 10 times the units mentioned in the picture of the challenge description as sizes for all shapes. Why 10 times as large? All the Java AWT methods require integers as pixel-coordinates, so using the default small units would become way to inaccurate when rounding to integers. By using a 10 times as large value it's still easy to calculate with, and the rounding errors are minimal (although still slightly noticeable to the naked eye - note: all decimals are rounded 'half up').

**Code explanation:**

```
// Import for Frame, Panel, Graphics, Graphics2D, Color, and BasicStroke:
import java.awt.*;
// Method with empty unused parameter and Frame return-type
v->
  // Create a Frame (window for graphical output)
  new Frame(){
    // Color null-object on class-level to use for static calls and save bytes
    Color C;
    // Override its default paint method
    public void paint(Graphics g){
      // Cast the Graphics to a Graphics2D-object, for the setStroke() method
      var G=(Graphics2D)g;
      // Temp integer to save bytes
      int t=300;
      // Draw the three large black circles (default color is black)
      G.fillOval(150,40,t,t);
      G.fillOval(55,205,t,t);
      G.fillOval(245,205,t,t);
      // Then change the color to white
      G.setColor(C.WHITE);
      // Draw the two smaller inner circles
      G.fillOval(195,45,t=210,t);
      G.fillOval(65,270,t,t);
      G.fillOval(325,270,t,t);
      // As well as the small circle at the center of the bio-hazard symbol
      G.fillOval(270,270,60,60);
      // Draw the three openings next to the middle circle
      G.fillRect(295,240,10,60);
      G.fillPolygon(new int[]{246,251,303,298},new int[]{326,334,304,296},4);
      G.fillPolygon(new int[]{298,349,354,303},new int[]{304,334,326,296},4);
      // Create the three openings for the outer circles
      G.fillRect(280,0,40,80);
      G.fillPolygon(new int[]{30,50,119,99},new int[]{433,467,427,393},4);
      G.fillPolygon(new int[]{550,570,501,481},new int[]{467,433,393,427},4);
      // Change the color back to black
      G.setColor(C.BLACK);
      // Set the line thickness to 35 pixels
      G.setStroke(new BasicStroke(35));
      // Draw the circle that would form the arcs in the bio-hazard symbol
      G.drawOval(183,183,235,235);
      // Change the color to white again
      G.setColor(C.WHITE);
      // Set the line thickness to 10 pixels
      G.setStroke(new BasicStroke(10));
      // And draw the three rings alongside the earlier inner circles we drew,
      // to create gaps in the ring to form the arcs
      G.drawOval(200,50,t=200,t);
      G.drawOval(70,275,t,t);
      G.drawOval(330,275,t,t);}
    // Start an initialized block for this Frame
    {
     // And finally show the Frame
     show();}}

```

**Calculations:**

And now comes the long part: how are all these magic numbers in the code calculated?

As I mentioned earlier, I've used 10 times the units of the picture in the challenge description, so those sizes are: \\$A=10, B=35, C=40, D=60, E=110, F=150, G=210, H=300\\$. I've also assumed the very center is at coordinate \\$\[300,300\]\\$. Using just this information, I had to calculate all the magic numbers you see in the code, which I will go over down below:

*1a) Top black circle:*

Width/height: this is mentioned in the diagram: \\$H=300\\$.
\\$x,y\\$-coordinate top-left square corner: line \\$E\\$ goes from the center of the bio-hazard symbol (\\$\[300,300\]\\$) to the center of the black circle. So the coordinate at the center of this circle is therefore \\$\[300, 300-E\]\\$. From there, we can subtract halve the width/height from both the \\$x\\$ and \\$y\\$ coordinate of this center to get the coordinate of the top-left corner of the square surrounding the circle: \\$\[300-\frac{H}{2}, 300-E-\frac{H}{2}\] → \[150, 40\]\\$.

*1b) Bottom-left black circle:*

Width/height: again \\$H=300\\$.
\\$x,y\\$-coordinate top-left square corner: we again know the length of line \\$E\\$. We also know that the angle is at 330°. If we draw a triangle with \\$E\\$ as long side, and with the three corners as angles \\$90,60,30\\$, we can calculate the other two sides:

Here \\$a=\frac{E}{2}\\$ and \\$c=\frac{E}{2}\sqrt{3}\\$. So the center coordinates of this black circle is therefore \\$\[300-\frac{E}{2}\sqrt{3}, 300+\frac{E}{2}\]\\$. From there, we can again subtract halve the width/height from both to get the coordinate of the top-left corner of the square surrounding the circle: \\$\[300-\frac{E}{2}\sqrt{3}-\frac{H}{2}, 300+\frac{E}{2}-\frac{H}{2}\] → \[54.737, 205\]\\$

*1c) Bottom-right black circle:*

Width/height: again \\$H=300\\$.
\\$x,y\\$-coordinate top-left square corner: we do something similar as above, but in the other direction: \\$\[300+\frac{E}{2}\sqrt{3}-\frac{H}{2}, 300+\frac{E}{2}-\frac{H}{2}\] → \[245.262, 205\]\\$

*2a) Top inner white circle:*

Width/height: this is mentioned in the diagram: \\$G=210\\$.
\\$x,y\\$-coordinate top-left square corner: line \\$F\\$ goes from the center of the bio-hazard symbol (\\$\[300,300\]\\$) to the center of the inner white circle. So the coordinate at the center of this circle is therefore \\$\[300, 300-F\]\\$. From there, we can subtract halve the width/height from both the \\$x\\$ and \\$y\\$ coordinate of this center to get the coordinate of the top-left corner of the square surrounding the circle: \\$\[300-\frac{G}{2}, 300-F-\frac{G}{2}\] → \[195, 45\]\\$.

*2b) Bottom-left inner white circle:*

Width/height: again \\$G=210\\$.
\\$x,y\\$-coordinate top-left square corner: similar as what we did in step 1b: \\$\[300-\frac{F}{2}\sqrt{3}-\frac{G}{2}, 300+\frac{F}{2}-\frac{G}{2}\] → \[65.096, 270\]\\$

*2c) Bottom-right inner white circle:*

Width/height: again \\$G=210\\$.
\\$x,y\\$-coordinate top-left square corner: similar as what we did in step 1c: \\$\[300+\frac{F}{2}\sqrt{3}-\frac{G}{2}, 300+\frac{F}{2}-\frac{G}{2}\] → \[324.903, 270\]\\$

*3) Center white circle:*

Width/height: this is mentioned in the diagram: \\$D=60\\$.
\\$x,y\\$-coordinate top-left square corner: subtracting halve this width/height from the center coordinate is enough: \\$\[300-\frac{D}{2}, 300-\frac{D}{2}\] → \[270, 270\]\\$

*4a) Top white rectangle gap at the center of the bio-hazard symbol:*

Width: this is mentioned in the diagram: \\$A=10\\$.
Height: Not too irrelevant, as long as it's large enough to create the gap, and not too large to go over other thing that should remain black. So I've just used \\$D=60\\$ here.
\\$x,y\\$-coordinate top-left corner: \\$\[300-\frac{A}{2}, 300-D\] → \[295, 240\]\\$

*4b) Bottom-left rectangle gap at the center of the bio-hazard symbol:*

Single the rectangle is angled, the Java method `fillPolygon(int[] xPoints, int[] yPoint, int amountOfPoints)` doesn't need the width/height, but instead needs the four individual coordinates of the corners of this rectangle. By again creating multiple triangles with corner-angles at 90, 60, and 30 degrees with the long side known, we can calculate the other sides. The calculations of the four points in the order I've used them in the Java method are:
\\$\[300-\frac{D}{2}\sqrt{3}-\frac{A}{4}, 300+\frac{D}{2}-\frac{A}{4}\sqrt(3)\] → \[245.528, 325.669\]\\$
\\$\[300-\frac{D}{2}\sqrt{3}+\frac{A}{4}, 300+\frac{D}{2}+\frac{A}{4}\sqrt(3)\] → \[250.538, 334.330\]\\$
\\$\[300+\frac{A}{4}, 300+\frac{A}{4}\sqrt{3}\] → \[302.5, 304.330\]\\$
\\$\[300-\frac{A}{4}, 300-\frac{A}{4}\sqrt{3}\] → \[297.5, 295.669\]\\$

*4c) Bottom-right rectangle gap at the center of the bio-hazard symbol:*

Likewise as step 4b:
\\$\[300-\frac{A}{4}, 300+\frac{A}{4}\sqrt{3}\] → \[297.5, 304.220\]\\$
\\$\[300+\frac{D}{2}\sqrt{3}-\frac{A}{4}, 300+\frac{D}{2}+\frac{A}{4}\sqrt{3}\] → \[349.461, 334.330\]\\$
\\$\[300+\frac{D}{2}\sqrt{3}+\frac{A}{4}, 300+\frac{D}{2}-\frac{A}{4}\sqrt{3}\] → \[354.461, 325.669\]\\$
\\$\[300+\frac{A}{4}, 300-\frac{A}{4}\sqrt{3}\] → \[302.5, 295.669\]\\$

*5a) Top big white gap:*

Width: this is mentioned in the diagram: \\$C=40\\$.
Height: Not too irrelevant, as long as it's large enough to create the gap, and not too large to go over other thing that should remain black. So I've just used \\$2\times\text{1a.}y=80\\$ here.
\\$x,y\\$-coordinate top-left corner: \\$\[300-\frac{C}{2}, 0\] → \[280, 0\]\\$ The \\$0\\$ isn't calculated, it was just easier to use (as mentioned earlier, the height is mostly irrelevant).

*5b) Bottom-left big rectangle gap:*

Similar as step 4b for the first two points:
\\$\[300-\frac{H}{2}\sqrt{3}-\frac{C}{4}, 300+\frac{H}{2}-\frac{C}{4}\sqrt{3}\] → \[30.192, 432.679\]\\$
\\$\[300-\frac{H}{2}\sqrt{3}+\frac{C}{4}, 300+\frac{H}{2}+\frac{C}{4}\sqrt{3}\] → \[50.192, 467.320\]\\$

For the other two we can't base it on the center of the screen like we did in step 4b, but instead we'll calculate it based on the two points we've just calculated:

\\$\[300-\frac{H}{2}\sqrt{3}+\frac{C}{4}+\frac{80}{2}\sqrt{3}, 300+\frac{H}{2}+\frac{C}{4}\sqrt{3}-\frac{80}{2}\] → \[119.474, 427.320\]\\$ \\$\[300-\frac{H}{2}\sqrt{3}-\frac{C}{4}+\frac{80}{2}\sqrt{3}, 300+\frac{H}{2}-\frac{C}{4}\sqrt{3}-\frac{80}{2}\] → \[99.474, 392.679\]\\$
(where the \\$80\\$ is the \\$2\times\text{1a.}y\\$ mentioned in step 5a)

*5c) Bottom-right big rectangle gap:*

Likewise as step 5b:
\\$\[300+\frac{H}{2}\sqrt{3}-\frac{C}{4}, 300+\frac{H}{2}+\frac{C}{4}\sqrt{3}\] → \[549.807, 467.320\]\\$
\\$\[300+\frac{H}{2}\sqrt{3}+\frac{C}{4}, 300+\frac{H}{2}-\frac{C}{4}\sqrt{3}\] → \[569.807, 432,679\]\\$
\\$\[300+\frac{H}{2}\sqrt{3}+\frac{C}{4}-\frac{80}{2}\sqrt{3}, 300+\frac{H}{2}-\frac{C}{4}\sqrt{3}-\frac{80}{2}\] → \[500.525, 392.679\]\\$
\\$\[300+\frac{H}{2}\sqrt{3}-\frac{C}{4}-\frac{80}{2}\sqrt{3}, 300+\frac{H}{2}+\frac{C}{4}\sqrt{3}-\frac{80}{2}\] → \[480.525, 427.320\]\\$

*6) Black ring that will form the arcs:*

Thickness: this is mentioned in the diagram: \\$B=35\\$.
Width/height: this can be calculated with the units in the diagram: \\$2(E-A+B) → 270\\$, after which we'll remove the thickness: \\$2(E-A+B)-B → 235\\$ (halve the thickness at both sides)
\\$x,y\\$-coordinate top-left corner: we simply subtract halve the width/height from the center coordinate: \\$\[300-\frac{2(E-A+B)-B}{2}, 300-\frac{2(E-A+B)-B}{2}\] → \[182.5, 182.5\]\\$

*7) White ring inside the inner circles to form the arcs:*

Thickness: this is mentioned in the diagram: \\$A=10\\$.
Width/height: this is the same as step 2a: \\$G=210\\$, but with this thickness removed: \\$G-A → 200\\$
\\$x,y\\$-coordinate top-left corner: these are the same calculations as in step 2a, but with the adjusted width/height \\$G-A\\$ instead of \\$G\\$:
\\$\[300-\frac{G-A}{2}, 300-F-\frac{G-A}{2}\] → \[200, 50\]\\$
\\$\[300-\frac{F}{2}\sqrt{3}-\frac{G-A}{2}, 300+\frac{F}{2}-\frac{G-A}{2}\] → \[65.096, 270\] → \[70.096, 275\]\\$
\\$\[300+\frac{F}{2}\sqrt{3}-\frac{G-A}{2}, 300+\frac{F}{2}-\frac{G-A}{2}\] → \[324.903, 270\] → \[329.903, 275\]\\$

And rounding all those values we've calculated to integers we get the code and output above.

# Answer
> 12 votes
# GLSL, ~~700~~ ~~629~~ ~~564~~ ~~545~~ 499 bytes

```
#define v vec2
#define j(x,r)length(x-g)<r
#define k(x,r,q)j(x,q)!=j(x,r)
#define l(b)length(g-b)<1.&&length(g-dot(g,b)*b)<(length(g)<S?A*S:A/S)
float C=.86,S=.5,F=.3,E=.22,A=.02,G=.21;void mainImage(out vec4 o,in v p){v r=iResolution.xy;v g=(p/S-r)/r.y;o.g=(k(v(0,F),G,G-A)||k(v(F*C,-F*S),G,G-A)||k(v(-F*C,-F*S),G,G-A))?o.g=0.:k(v(0),F,G)?C:l(v(0,1))||l(v(C,-S))||l(v(-C,-S))||j(v(0),.06)||j(v(0,F),G)||j(v(F*C,-F*S),G)||j(v(-F*C,-F*S),G)?0.:j(v(0,E),F)||j(v(E*C,-E*S),F)||j(v(-E*C,-E*S),F)?C:0.;}

```

I was playing around with Shadertoy, so I tried the GLSL shading language. The code just rasterizes circles and lines by testing each fragment, and assigns them a value of one or zero. The size was cut down from \>1000 bytes by heavy use of macros.

Shadertoy program

# Answer
> 12 votes
# PostScript, ~~367~~ ~~359~~ ~~328~~ 271 bytes

Code (compressed version):

```
5 5 scale 36 24 translate <</c{0 360 arc closepath}/r{120 rotate}/R{repeat}/L{setlinewidth}/g{setgray}/F{fill}>>begin 3{0 11 15 c F r}R 1 g 3{0 15 10.5 c F r}R 0 0 3 c F 3{[-.5 2 1 3 -2 25 4 3]rectfill r}R 0 g 4 L 0 0 11.5 c stroke 1 g 1 L 3{0 15 10 c stroke r}R showpage

```

Code (uncompressed version):

```
5 5 scale                  % over-all scale
36 24 translate            % over-all shift

% define some short-named procedures for later use
<<
  /c { 0 360 arc closepath }  % append circle (x, y, radius are taken from stack)
  /r { 120 rotate }           % rotate by 120°
  /R { repeat }
  /L { setlinewidth }
  /g { setgray }
  /F { fill }
>> begin

3 {
    0 11 15 c F       % black circle
    r                 % rotate by 120°
} R
1 g                   % set white color
3 {
    0 15 10.5 c F     % white circle
    r                 % rotate by 120°
} R
0 0 3 c F             % small white circle
3 {
    [ -.5 2 1 3       % white gap near center
      -2 25 4 3       % white gap on edge
    ] rectfill
    r                 % rotate by 120°
} R
0 g                   % set black color
4 L                   % set linewidth 4
0 0 11.5 c stroke     % black ring
1 g                   % set white color
1 L                   % set linewidth 1
3 {
    0 15 10 c stroke  % white ring
    r                 % rotate by 120°
} R
showpage

```

Result (as animation to see how it is drawn):

# Answer
> 10 votes
# GLSL, ~~319~~ 310 bytes

```
#define F float
#define H(y)sqrt(x*x+(y)*(y))
void mainImage(out vec4 D,in vec2 u){vec2 U=u*.003-.5;F x=abs(U.x),y=U.y;if(y<.577*x){F t=.5*x+.866*y;y=.866*x-.5*y;x=abs(t);}F c=F(H(y-.11)<.15);F R=H(y);F S=H(y-.15);if(S<.105)c=0.;if(R<.03)c=0.;if(x<(R<.1?.005:.02))c=0.;if(R>.10&&R<.135&&S<.095)c=1.;D=vec4(c);}

```

This can be rendered on Shadertoy.

You can use the symmetry in the image to draw it with a smaller amount of separate shapes.

Here is a somewhat inflated version:

```
#define F float
#define H(y) sqrt(x*x+(y)*(y))

void mainImage(out vec4 D,in vec2 u)
{
    // normalized UV
    vec2 U = u*.003 - .5;

    // fold the 6 identical sections to the same UV coordinates
    F x = abs(U.x), y = U.y;
    if (y < .577*x)
    {
        F t = .5*x + .866*y;
        y = .866*x - .5*y;
        x = abs(t);
    }

    // circles and lines
    F c = F(H(y-.11) < .15);
    F R = H(y);
    F S = H(y-.15);
    if (S < .105) c = 0.;
    if (R < .03) c = 0.;
    if (x < (R < .1 ? .005 : .02)) c = 0.;
    if (R > .10 && R < .135 && S < .095) c = 1.;

    // output
    D = vec4(c);
}

```

---

(thanks to @Kevin Cruijssen for removing some unnecessary whitespace)

# Answer
> 10 votes
# Haskell, ~~530~~ ~~491~~ ~~436~~ ~~435~~ ~~430~~ 420 bytes

```
f=fromIntegral
c(a,b)r(x,y)=(x-a)^2+(y-b)^2<r^2
(m#w)t(x,y)|c<-cos(-t),s<-sin(-t)=x*c-y*s>m&&abs(x*s+y*c)<w/2
u a p=any($p)a
i a p=all($p)a
v=(*(pi/6))<$>[9,5,1]
o=c(0,0)
h?r=[c(h*cos a,h*sin a)r|a<-v]
(h%y)x|u[i[u$11?15,(not.)$u$o 3:map(0#1)v++map(9#4)v++15?10.5],i[o 13.5,not.(o 10),u$15?9.5]](60*f x/h-30,60*f y/h-30)="0 "|0<1="1 "
g h|s<-show h,n<-[0..h-1]=writeFile"a.pbm"$unlines$"P1":(s++' ':s):[n>>=(f h%)y|y<-n]

```

Outputs a PBM file.

This was a lot of fun!

(I had to convert this to PNG to upload to imgur)

Basically we create our own vector graphics functions which render onto an image pixel by pixel by detecting whether the pixel is part of the shape. The shape is constructed as a bunch of circles and lines (radiating from the origin) held together with basic set operations: union, intersection, and not. The circles are composed of their center and a radius, and the lines have a minimum radius, a width, and an angle in that order. Detecting membership in a circle is easy: I just subtract the center coords and compare the magnitude to the radius. The line is slightly more complicated: I rotate the point by the opposite of the angle to bring it (to nullify the rotation) then I just check whether the x and y coordinates fall within the expected range. The minimum radius is to ensure the larger gap at the far ends of the large circles does not overrule the small gaps near the center. After that it's a simple matter of boolean logic to do set math.

EDIT: Thanks a lot to @flawr for taking off 39 bytes!

EDIT2: Thanks a lot to @Christian Sievers for taking off 55 bytes! Good idea making them into functions

EDIT3: Thanks again to @Christian Sievers for shaving off another byte!

EDIT4: Took off 7 bytes thanks to @H.PWiz and @Angs!

EDIT5: Just noticed a bug! I was rendering the lines twice as thick as they were supposed to be! Cost me 2 bytes to fix it (had to divide width by 2; could've adjusted the constant values but changing 1 to 0.5 would also cost 2).

EDIT6: Thanks @Angs for taking off another 10 bytes!

# Answer
> 8 votes
# HTML / JS,  ~~448 435 433~~  387 bytes

*Saved many bytes by using @Neil's pre-minimized version of the SVG*
*Saved 2 bytes thanks to @Shaggy*

A compressed version of this SVG file from Wikimedia Commons.

```
<body onload="_=`<svg~12y~24y><path id=p d=m28.8117,27.046a3,3}0qb3117q4.004v-1w539|1wq20.7959v-w583a1jxb7975x7.3228xj,8.6032x9.7443l-.4835q.2792|-18.7598q9.0989zm3.4148q8.871a10x0}0q1b453,c9w,9w{-kx3wx3w}1x6.8042,0x0x0{k>~><use href=#p transform=rotate(},cc|a10wx0w}c{}1qb1756,yc26,26) /x,1w.5q,-kb7417j5x5}1c0,b2.`;for(i of`bcjkqwxy{|}~`)with(_.split(i))_=b.innerHTML=join(pop())"id=b>

```

Try it online! (just outputs the decompressed string)

### Demo snippet

```
setTimeout(_ => document.getElementsByTagName('svg')[0].setAttribute("viewBox", "0 0 100 100"), 0)
```

```
<body onload="_=`<svg~12y~24y><path id=p d=m28.8117,27.046a3,3}0qb3117q4.004v-1w539|1wq20.7959v-w583a1jxb7975x7.3228xj,8.6032x9.7443l-.4835q.2792|-18.7598q9.0989zm3.4148q8.871a10x0}0q1b453,c9w,9w{-kx3wx3w}1x6.8042,0x0x0{k>~><use href=#p transform=rotate(},cc|a10wx0w}c{}1qb1756,yc26,26) /x,1w.5q,-kb7417j5x5}1c0,b2.`;for(i of`bcjkqwxy{|}~`)with(_.split(i))_=b.innerHTML=join(pop())"id=b>
```

# Answer
> 6 votes
# Ruby, 278 bytes

```
puts"<svg viewBox='-60-60 120 120'><circle cx='0'cy='0'r='23.5'stroke-width='7'fill='white'stroke='red'/>",(-3..5).map{|i|"<path fill='red'stroke='white'stroke-width='2'd='M5 0A5 5 0 0 1 0 5v5A20 20 0 0 1 2 50v3A31 31 0 0 0 31 17'transform='scale(#{i/3},-1)rotate(#{i*120})'/>"}

```

Try it online!

Generates the SVG code below, with the symbol being at 200% of the scale in the OP.

It consists of a circle at the back, and the prongs in the foreground. The prong is scaled `-1,0,1` in the `X` axis and rotated through multiples of 120 degrees. The cases where the `X` scaling is zero produce no output, while the `-1` and `+1`. provide the two sides of each pair of prongs.

Use is made of a 2-unit wide white border around the prong to cut the back circle, using the `stroke` and `stroke-width` attributes. In order for the internal shape to be per the OP, the coordinates are moved by 1 unit (half the width of the border.) Note that the path is deliberately not closed, to suppress the drawing of the final line of the border. This ensures the two halves of each pair of prongs join together.

90 degrees of the inner circle are drawn rather than the expected 60, for golfing reasons. This means there is some overlap between the bases of each pair of prongs, but this does not affect the appearance of the output shape.

```
<svg viewBox='-60-60 120 120'><circle cx='0'cy='0'r='23.5'stroke-width='7'fill='white'stroke='red'/>
<path fill='red'stroke='white'stroke-width='2'd='M5 0A5 5 0 0 1 0 5v5A20 20 0 0 1 2 50v3A31 31 0 0 0 31 17'transform='scale(-1,-1)rotate(-360)'/>
<path fill='red'stroke='white'stroke-width='2'd='M5 0A5 5 0 0 1 0 5v5A20 20 0 0 1 2 50v3A31 31 0 0 0 31 17'transform='scale(-1,-1)rotate(-240)'/>
<path fill='red'stroke='white'stroke-width='2'd='M5 0A5 5 0 0 1 0 5v5A20 20 0 0 1 2 50v3A31 31 0 0 0 31 17'transform='scale(-1,-1)rotate(-120)'/>
<path fill='red'stroke='white'stroke-width='2'd='M5 0A5 5 0 0 1 0 5v5A20 20 0 0 1 2 50v3A31 31 0 0 0 31 17'transform='scale(0,-1)rotate(0)'/>
<path fill='red'stroke='white'stroke-width='2'd='M5 0A5 5 0 0 1 0 5v5A20 20 0 0 1 2 50v3A31 31 0 0 0 31 17'transform='scale(0,-1)rotate(120)'/>
<path fill='red'stroke='white'stroke-width='2'd='M5 0A5 5 0 0 1 0 5v5A20 20 0 0 1 2 50v3A31 31 0 0 0 31 17'transform='scale(0,-1)rotate(240)'/>
<path fill='red'stroke='white'stroke-width='2'd='M5 0A5 5 0 0 1 0 5v5A20 20 0 0 1 2 50v3A31 31 0 0 0 31 17'transform='scale(1,-1)rotate(360)'/>
<path fill='red'stroke='white'stroke-width='2'd='M5 0A5 5 0 0 1 0 5v5A20 20 0 0 1 2 50v3A31 31 0 0 0 31 17'transform='scale(1,-1)rotate(480)'/>
<path fill='red'stroke='white'stroke-width='2'd='M5 0A5 5 0 0 1 0 5v5A20 20 0 0 1 2 50v3A31 31 0 0 0 31 17'transform='scale(1,-1)rotate(600)'/>
```

# Answer
> 6 votes
# Desmos, ~~126~~ 125 bytes

```
s=\sqrt3x
Y=max(2y,s-y,-s-y)/2
S=xx+yy

S-6Y+6.39<\{4<S<7.29\}

0>(S-6Y+4.59)(S-.36)(S-4.4Y-4.16)\{Y<2,S-YY>.16\}\{S-YY>.01\}

```

The empty lines are included to paste in piecewises properly.

Try it on Desmos!

*-1 byte thanks to @KevinCruijssen (inline `S-YY`)*

This translates nicely to the following 159-byte one-liner:

```

[\{xx+yy-6Y+6.39<\{4<xx+yy<7.29\},(xx+yy-6Y+4.59)(.36-xx-yy)(xx+yy-4.4Y-4.16)\{Y<2,xx+yy-YY>.16\}\{xx+yy-YY>.01\}\}\for Y=[\max(2y,\sqrt3x-y,-\sqrt3x-y)/2]]>0

```

Try it on Desmos!

# Answer
> 5 votes
# Wolfram Language (Mathematica), ~~211~~ ~~209~~ ~~191~~ ~~182~~ ~~175~~ ~~168~~ ~~166~~ ~~164~~ ~~163~~ 162 bytes

```
{a,b}=AbsArg[I*x-y];z=Exp[Mod[b,2Pi/3]I-Pi/3I]a-22;u=Abs@Im@z;n=Abs[z-8];RegionPlot[20<a<27&&n<19||a>6&&Abs[z]<30&&n>21&&u>1&&(u>4||Re@z<-2),{x,s=52,-s},{y,-s,s}]

```

Here exported with the additional option `PlotPoints -> 100` to make it look more accurate:

### how it works:

* `a = Sqrt[x^2+y^2]` is the distance from the center.
* `z+22 = I*x-y` is the complex representation of the point (x,y) but mapped into the first 120° wedge, so that its complex argument is always in the range \[-π/3,+π/3\] and we only need to deal with one third of the symbol
* `u = Abs[Im[z]]` is the magnitude of the x-coordinate in the first 120° wedge
* The `RegionPlot` plots for each point in the x-y plane whether or not it satisfies a given condition. This condition is satisfied for points that belong to the symbol, magnified by a factor of 2 to avoid fractions.
* `n` is the distance to the point (0,30), which is the center of the outward-going arcs (2F=30)
* `20 < a < 27 && n < 19` is the ring around the center: 2(E-A) \< a \< 2(E-A+B) and n \< G-2A
* `a > 6 && Abs[z] < 30 && n > 21 && u > 1 && (u > 4 || Re@z < -2)` is the main structure of the symbol:
    + a \> D clears out the central hole
    + Abs\[z+22 - 2E\] \< H clears out anything beyond the outer edge of the arcs
    + n \> G clears out the holes surrounded by the arcs
    + u \> A clears the gaps in the symbol around the central hole
    + u \> C || Re\[z+22\] \< 20 cuts a gap into the tips of the arcs

# Answer
> 4 votes
# Python 3 with pygame, ~~327 314 287~~ 278 bytes

(Applied various nasty hacks to save 13 bytes; most notably no longer storing the color but calculating it on the fly with `-(r>25)`)
(Refactored to function, losing `sys`; hacked out `math` in favour of coordinate constants; small tweaks; saved 27 bytes)
(Rewrote coordinate constants to complex math tricks to get (co)sine, saving 9 bytes)

Function that takes a single integer argument representing half the width/height of the resulting image. E.g. `f(500)` will create a 1000x1000 pixel window, and draw a biohazard symbol in there.

```
from pygame import*;D=display
def f(S):
 u=D.set_mode([S*2]*2);b=S>>6
 for p,r,w in(22,30,0),(30,20,0),(0,27,7),(30,21,2),(0,6,0),(51,4,0):
  for l in 0,4/3,8/3:Z=1j**l*p*b;q=S+int(Z.imag),S-int(Z.real);draw.circle(u,-(r>25),q,r*b,w*b);r-20or draw.line(u,0,(S,S),q,b*2);D.flip()

```

Unshortened version:

```
import pygame
import math
import sys

size = int(sys.argv[1])
basic = size // 55

screen = pygame.display.set_mode((size * 2, size * 2))

circles = [
    (22, 30, 0, -1),  # basic shape
    (30, 20, 0, 0),   # large cutouts
    (0, 27, 7, -1),   # "background circle"
    (30, 21, 2, 0),   # "background circle" clearance
    (0, 6, 0, 0),     # center disc
    (51, 4, 0, 0),    # blunt the points
]

for pos, radius, width, color in circles:
    for lobe in [0, math.pi * 2 / 3, math.pi * 4 / 3]:
        x = int(math.sin(lobe) * pos * basic) + size
        y = size - int(pos * basic * math.cos(lobe))
        pygame.draw.circle(screen, color, (x, y), radius * basic, width * basic)
        # Hack to draw the small slots in the center
        if radius == 20:
            pygame.draw.line(screen, 0, (size, size), (x, y), basic * 2)

pygame.display.flip()

```

The key to this program is mostly exploiting the 3-way point symmetry of the symbol, and expressing the drawing operations as sparsely as possible. The heart of it all is `circles`, which is a list of circle definitions, consisting just of:

* `position`: how far outwards from the origin in half basic units
* `radius`: the radius of the circle in half basic units
* `width`: the border width of the circle (inwards from the outer circle, 0 = fill)
* `color`: exploiting the fact that pygame interprets `0` as black and `-1` as white

Every drawing operation is repeated three times, rotated 120°. The blunting of the "claws" is done with another circle. The inside "line cuts" are special-cased because I couldn't think of a more efficient way to get them in there. The "basic unit" defined in the specification is doubled here so I didn't have to use `.5` in `circles` and `int()` all over the place to satisfy pygame.

Result for `python3 -c 'from biohazard import *; f(500)'`:

# Answer
> 3 votes
# C (gcc) (MinGW), ~~557~~ ~~530~~ ~~524~~ 522 bytes

-27 -6 bytes thanks to ceilingcat

Added compiler option `-lm` on TiO strictly to be able to show how it runs. Under MinGW this is not necessary.

Takes width of image as a command line argument. Outputs a 3-shade greyscale PGM file to STDOUT. The circle drawing function is slightly longer than it could be, to avoid dreadful runtime on even moderately sized images, the positioning/scaling of the symbol is not perfect, and I suspect shuffling the draw order somewhat might squeeze some more out of this, so there is room for improvement for sure.

Everything is drawn as circles. The rectangular cutouts are painted using the circle drawing function as a moving brush.

```
char*I;q,j=5,r,c;N(n){n="F=**(..*(C/)F<<*>FF)"[j*4+n]-40;}float d,b,m,x,y,V=2.0944;C(x,y,R,t,z)float x,y,R,t;{for(r=y<R?0:y-R;r<=y+R;r++)for(c=x-R;c<=x+R;c++)d=hypot(c-x,r-y),d<R&d>=R-t?I[r*q+c]=z:0;}main(i,v)int**v;{q=atoi(v[1]);b=q/104.;m=q/2.;for(I=memset(calloc(q,q+1),2,q*q);i=j--;)for(x=0;x<7;x+=V)C(m+cos(x)-N(0)*b*sin(x),m-N(0)*b*cos(x)+sin(x),N(1)*b,N(2)*b,N(3));for(;i<3;i++)for(j=m;j--;C(m-x,m-y,d,d=d>4*b&d<10*b?b:d>50*b?b*4:0,2))d=hypot(x=j*sin(x)-cos(x),y=j*cos(x=i*V)-sin(x));printf("P5 %d %d 2 %s",q,q,I);}

```

Try it online!

# Answer
> 2 votes
# Tcl/Tk - 557 bytes

```
set F #000
set B #F50
pack [canvas .c -bg $B]
rename expr e
rename foreach f
rename proc p
p R r {list [e $r*cos($::a)] [e $r*sin($::a)]}
p D {d r} {lassign [R $d] x y;list [e $x-$r] [e $y-$r] [e $x+$r] [e $y+$r]}
p C {d r c} {.c cr o {*}[D $d $r] -f $c -outline $c}
p L {p q w} {.c cr l {*}[R $p] {*}[R $q] -w [e $w] -f $::B}
p A {d r w c} {.c cr a {*}[D $d $r] -w [e $w] -star 0 -ex 359.9 -sty arc -outline $c}
f x {{C 11 15 $F} {C 15 10.5 $B} {L 0 5 1} {L 20 40 4} {C 0 3 $B} {A 0 11.75 3.5 $F} {A 15 10 1 $B}} {f a {2.62 4.72 6.81} $x}
.c move all 99 99

```

That version, however, is boring, since you get the same small-sized image no matter what. It does satisfy the OP conditions for displaying on-screen, however. Here is the uncompressed version with commentary and the ability to specify a size added in:

```
# Input: command line argument is the pixel width (same as the height) of the window to create
# For example:
#   wish a.tcl 500
set window_size $argv

set foreground_color #000
set background_color #F50
pack [canvas .c -bg $background_color -width $window_size -height $window_size]

# Helper procs to generate x,y coordinates
proc radius->x,y r {
  list [expr {$r*cos($::angle)}] [expr {$r*sin($::angle)}]
}

proc center_offset,radius->rectangle {offset r} {
  lassign [radius->x,y $offset] x y
  list [expr {$x-$r}] [expr {$y-$r}] [expr {$x+$r}] [expr {$y+$r}]
}

# Tk's canvas does not scale line widths, so we have to do that manually
# The $scale is a global variable for compressing the code text above
set scale [expr {$window_size*.016}]

# These three procs draw items in the canvas
proc circle {offset r color} {
  .c create oval {*}[center_offset,radius->rectangle $offset $r] -fill $color -outline $color
}
proc line {p q w} {
  .c create line {*}[radius->x,y $p] {*}[radius->x,y $q] -width [expr {$::scale*$w}] -fill $::background_color
}
proc annulus {offset r w color} {
  .c create arc {*}[center_offset,radius->rectangle $offset $r] -width [expr {$::scale*$w}] -start 0 -extent 359.9 -style arc -outline $color
}

# Our list of shapes to draw
#  circle  center_offset, radius,                   color
#  line    end_offset_1,  end_offset_2, line_width
#  annulus center_offset, radius,       line_width, color
foreach command {
  {circle  11 15        $foreground_color}
  {circle  15 10.5      $background_color}
  {line     0  5    1}
  {line    20 40    4}
  {circle   0  3        $background_color}
  {annulus  0 11.75 3.5 $foreground_color}
  {annulus 15 10    1   $background_color}
} {
  # Each command gets applied thrice, rotated $angle radians each time
  foreach angle {2.62 4.72 6.81} $command
}

.c scale all 0 0 $scale $scale
.c move all [expr {$window_size/2}] [expr {$window_size/2}]

# Some random convenience stuff for playing with it
bind . <Escape> exit
after 500 {focus -force .}

```

Sorry, no pictures (working off my phone today). Produces a black symbol on a biohazard orange background.

# Answer
> 2 votes
# Scratch, 423 bytes

Try it online!

Surprisingly, Scratch beats more than 0 other langauges! Alternatively, 46 blocks.

```
define T(o
turn cw(o)degrees
define P(s
set pen size to(s
define (d)(r)(t)(c
set pen color to(c
P(1
repeat(3
move(d)steps
repeat(360
move(r)steps
pen down
move(t)steps
pen up
move(()-((r)+(t)))steps
T(1
end
move(()-(d))steps
T(120
when gf clicked
repeat(2
point in direction(0
erase all
(22)()(30)(
(30)()(19)(#fff
repeat(3
P(2
pen down
move(52)steps
P(8
pen down
pen up
go to x()y(
T(120
()(20)(7)(
()()(6)(#fff
(30)(19)(2)(#fff

```

# Explanation

## Definitions

```
define T(o                Obligatory hat block
turn cw(o)degrees         Rotate clockwise a specified amount of degrees

define P(s                Obligatory hat block
set pen size to(s         Sets pen size to a specified amount

define (d)(r)(t)(c        d=distance, r=radius, t=thickness (of ring), c=color
set pen color to(c        Sets pen to a specified color
P(1                       Sets pen size to be 1 pixel in diameter
repeat(3                  Loops code for each circle
move(d)steps              Moves a specified distance away from the center
repeat(360                Loops code for each ray being drawn in a circle
move(r)steps              Moves to the inner edge of the ring, without applying pen
pen down                  Begins to apply pen
move(t)steps              Applies pen for the specified thickness of the ring
pen up                    Stops applying the pen
move(()-((r)+(t)))steps   Moves back to the center of the circle being drawn
T(1                       Rotates 1 degree clockwise
end                       Ends code to be  looped
go to x()y(               Moves to the center
T(120                     Rotates in preparation of next circle

```

## Construction

```
when gf clicked        Initiates code
repeat(2               Loops code twice, skipping the need to move to the origin.
point in direction(0   Resets angle
erase all              Clears stage
(22)()(30)(            Draws 3 black circles 22 pixels from the center, with a radius of 30
(30)()(19)(#fff        Draws 3 white circles 30 pixels from the center, with a radius of 19
repeat(3               Loops code for each break to be made
P(2                    Sets pen size to 2 pixels in diameter
pen down               Applies pen
move(52)steps          Draws a white line from the center
P(8                    Sets pen size to 8 pixels in diameter
pen down               Applies pen, creating the gap in the outer rings
pen up                 Removes pen
go to x()y(            Moves to the origin
T(120                  Rotates 120 degrees clockwise
()(20)(7)(             Draws a black ring 7 pixels thick with an internal radius of 20 pixels
()()(6)(#fff           Draws a white circle with a 6 pixel radius
(30)(19)(2)(#fff       Draws 3 white rings 30 pixels from the center, 2 pixels thick, and an internal radius of 29 pixels

```

# Answer
> 1 votes
# C (GCC), 319 bytes

```
#define q(i)x*x+(y-i)*(y-i)main(k,w,i,j,z){scanf("%d",&k);i=w=65*k;float x,y,s;for(printf("P5\n%d %d\n1\n",2*w,2*w);i-->-w;)for(j=-w;j++<w;putchar((q(22)>900|q(30)<441|q(0)<36|(s=labs(x))<1|s<4&y>30)&(q(0)<400|q(0)>729)|q(30)<441&q(30)>400))s=sqrt(3),z=i<0|abs(j)>s*i,s/=j>0?2:-2,x=(z?i*s+j/2.:j)/k,y=(z?j*s-i/2.:i)/k;}
```

Attempt This Online!

Takes the scale factor (a positive integer) from `stdin`, and outputs on `stdout` a binary (black and white) PGM image.

Formatted version:

```
// q(i) == x^2 + (y-i)^2
// used to draw circles of center (x,y-i)
#define q(i)x*x+(y-i)*(y-i)

main(k,w,i,j,z){
    scanf("%d",&k);
    i=w=65*k;
    float x,y,s;

    // PPM header
    printf("P5\n%d %d\n1\n",2*w,2*w);

    for(;i-->-w;)
        for(j=-w;j++<w;)

            // rotates the points of the bottom part by +120 or -120 degrees
            s=sqrt(3),
            z=i<0|abs(j)>s*i,
            s/=j>0?2:-2,
            x=(z?i*s+j/2.:j)/k,
            y=(z?j*s-i/2.:i)/k,

            putchar((q(22)>900|q(30)<441|q(0)<36|(s=labs(x))<1|s<4&y>30)&(q(0)<400|q(0)>729)|q(30)<441&q(30)>400);
}

```

# Answer
> 1 votes
## PostScript, ~~198~~ 106 bytes

```
00000000: 3520 3592 8b88 3c36 3092 ad32 7b33 7b39  5 5...<60..2{3{9
00000010: 7b30 7d92 8333 3088 1532 3735 2e35 884f  {0}..30..275.5.O
00000020: 9205 3232 881e 3832 2e33 8754 0192 0636  ..22..82.3.T...6
00000030: 8800 3730 2e35 9205 9242 924e 3330 8813  ..70.5...B.N30..
00000040: 3088 ff92 0592 1492 6f88 1b30 885a 9205  0.......o..0.Z..
00000050: 3230 885a 3092 0692 4292 4d88 7892 887d  20.Z0...B.M.x..}
00000060: 9283 88ff 3192 8b7d 9283                 ....1..}..

```

Before tokenization:

```
5 5 scale 60 60 translate
2{3{9{0}repeat 30 21 275.5 79 arc 22 30 82.3 340 arcn
6 0 70.5 arc fill gsave 30 19 0 -1 arc clip newpath
27 0 90 arc 20 90 0 arcn fill
grestore 120 rotate}repeat -1 1 scale}repeat

```

This draws 1/6 of the shape at a time:

Final output:

# Answer
> 0 votes
# JavaScript, ~~193~~ ~~189~~ 183 bytes

```
(x,y,t=(r,c=0)=>(R=(u,v=y-c/2)=>u*u+v*v<r*r)(x,y+c)|R(x+(X=c*.75**.5))|R(x-X))=>t(15,11)&!(t(10.5,15)|t(3)|((y<0?4*x*x:((x*x)**.5-y*3**.5)**2)<(y*y>36?16:1)))|t(13.5)&!t(10)&t(9.5,15)

```

A pixel shader taking `x` and `y` centred around `[0, 0]` to the scale of the spec. Outputs truthy or falsey depending on whether to draw the pixel.

Ungolfed and explained:

```
(x, y, // the current pixel
  t = ( // define a func 't' to check if pixel is in any of 3 circles around centre
      r,    // radius of circle
      c = 0 // distance from centre
    ) => ( // define a func 'R' to check if pixel inside a circle
        R = (u, v = y - c / 2) => u ** 2 + v ** 2 < r ** 2
    )(x, y + c) | // call 'R' on each circle centre
    R(x + (X = c * Math.sqrt(3) / 2)) | // use default y
    R(x - X) // use default y
) =>
  t(15, 11) & // 3 largest circles
  !(
    t(10.5, 15) | // large circle cutouts
    t(3) |        // tiny centre circle
    ((y < 0 ? // remove gaps
      4 * x ** 2 : // top half
      (Math.abs(x) - y * Math.sqrt(3)) ** 2) < // bottom half
    (y ** 2 > 36 ? 16 : 1))) | // a bit of pythagoras
  t(13.5) &  // pixel inside ring
  !t(10) &   // (ring inner)
  t(9.5, 15) // (ring cut-away)

```

```
shader =
  (x,y,t=(r,c=0)=>(R=(u,v=y-c/2)=>u*u+v*v<r*r)(x,y+c)|R(x+(X=c*.75**.5))|R(x-X))=>t(15,11)&!(t(10.5,15)|t(3)|((y<0?4*x*x:((x*x)**.5-y*3**.5)**2)<(y*y>36?16:1)))|t(13.5)&!t(10)&t(9.5,15)

const size = 400;
const scale = 60;
const ratio = scale / size;

const canvas = document.getElementById('canvas');
canvas.width = canvas.height = size;
const ctx = canvas.getContext('2d');

let x, y;
for (x = 0; x < size; x++) for (y = 0; y < size; y++) {
  ctx.fillStyle = shader((x - size / 2) * ratio, (y - size / 2) * ratio) ? 'black' : 'orangered';
  ctx.fillRect(x, y, 1, 1);
}
```

```
<canvas id="canvas"/>
```

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


title: I Need Moore(less) Chips

text:
# Question
Title: I Need Moore(less) Chips
If you wanted to compute a very large long problem, that on a machine that you could buy today for an inflation adjusted price, will take some amount of years/decades. The issue is, if you only have that budget, and so can only purchase one machine. So if you purchase the machine now, it may actually take longer to compute than if you purchase one later, for the same inflation adjusted price, because of Moore's Law.

Moore's law states that machines will double in everything every two years, so, theoretically, a problem that takes m years to compute now, will only take m/2 years 2 years from now. The question is, how long should I wait to buy the machine, if I need to compute a problem that takes m years to compute, to get the optimal time of computation, which is inclusive of the time waited to buy the machine, and how much time does it take?

It is assumed both that I gain no money, and make just enough interest on my money to beat inflation, but no more, and also that Moore's Law continues ad infinitum.

some examples:

| years | time-to-wait | time-it-takes |
| --- | --- | --- |
| 0 years | 0 seconds, buy now! | 0 years |
| 1 year | 0 seconds, buy now! | 1 year |
| 2 years | 0 seconds, buy now! | 2 years |
| 3 years | 0.1124 years | 2.998 years |
| 4 years | 0.9425 years | 3.828 years |
| 5 years | 1.5863 years | 4.472 years |
| 7 years | 2.557 years | 5.443 years |
| 8 years | 2.942 years | 5.828 years |
| 10 years | 3.586 years | 6.472 years |
| 20 years | 5.586 years | 8.472 years |
| 100 years | 10.23 years | 13.12 years |
| 1000000 years | 38.81 years | takes 39.70 years |

Code-golf, so shortest answer wins.

Desmos example text:

`f\left(t\right)=N\cdot\left(\frac{1}{2}^{\frac{t}{2}}\right)+t`

# Answer
## JavaScript (ES7), 52 bytes

```
f=eval(`
with(Math)a=>[b=max(0,log2(a*LN2)*2-2),b+a/2**(b/2)]
`)
```

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

Edit: Saved 2 bytes thanks to @Samathingamajig.
> 3 votes

# Answer
# Wolfram Language (Mathematica), ~~29~~ 28 bytes

```
{y+#/√2^y,y>0}~Minimize~y&

```

Try it online!

Returns `{*time-it-takes*, {y->*time-to-wait*}}`.

There's a built-in. All is well.
> 3 votes

# Answer
# C (GCC), ~~79~~ 77 bytes

*-2 bytes thanks to @Neil*

```
f(x,r)double*r,x;{r[1]=(*r=fmaxl(0,2*log(x*log(2)/2)/log(2)))+x/pow(2,*r/2);}
```

Attempt This Online!
> 2 votes

# Answer
# Jelly, 16 bytes

```
2Æl2÷«ɓ÷l2Ḥ»0,+¥

```

A monadic Link that accepts a positive number, `m` years, and yields a list of two numbers, `[wait, total]` in years.

Note: Input is strictly positive - inputting `0` will yield `[nan, nan]` which is *technically* true as one cannot do anything in zero time.

**Try it online!**

### How?

```
2Æl2÷«ɓ÷l2Ḥ»0,+¥ - Link: number, M
2                - two
 Æl              - natural logarithm
   2÷            - two divided by that
     «           - minimum with M
      ɓ          - start a new dyadic chain - f(M, CalculationTime=that)
       ÷         - M divided by CalculationTime
        l2       - log-base-two
          Ḥ      - halved
           »0    - maximum with zero
               ¥ - last two links as a dyad - f(WaitTime=that, CalculationTime)
              +  -   WaitTime add CalculationTime = TotalTime
             ,   -   WaitTime paired with that -> [WaitTime, TotalTime]

```
> 1 votes

# Answer
# Wolfram Language (Mathematica), 35 bytes

*\- a lot from ATT*

```
2{a=Ramp@Log2[Log@2#/2],a+#/2^a/2}&

```

Try it online!

---

Explanation:

`2` Take twice

`{a=Ramp@` zero or

`Log2,` the base-2 logarithm

`Log@2` of the natural logarithm of 2

`#` times the input

`/2]` divided by two.

`, a` Then, output this

`+#/` plus the input divided by

`2^a` two to the power of the variable,

`/2}&` all divided by two.
> 1 votes

# Answer
# JavaScript (V8), 87 bytes

```
s=(n,x=3,i=999,l=Math.LN2)=>i?s(n,x+2/l-2**(x/2+2)/n/l/l,i-1):[x=x>0?x:0,n*.5**(x/2)+x]

```

Try it online!

Returns both `time-to-wait` and `time-it-takes`. You could remove 1 byte to make it less precise at higher values, as 86 fits all test cases, but the problem does not tell a range you have to be precise to.

This uses Newton's Method on the first derivative of the function given to find the minimum.

Pre-golfed code: (derivatives found with WolframAlpha)

```
const f=(x,n)=>n*.5**(x/2)+x; // f(t)
const g=(x,n)=>1-n*2**(-x/2-1)*Math.LN2; // f'(t)
const h=(x,n)=>2**(-2-x/2)*n*Math.LN2**2; // f''(t)

const solution = n => {
  let x = 3; // arbitrary number that seems to work
  for (let i = 0; i < 999; i++) {
    // console.log(x);
    x = x - g(x,n)/h(x,n);
  }
  x = Math.max(0,x);
  return [x, f(x,n)];
}

```
> 0 votes

# Answer
# x86 64-bit machine code, 30 bytes

```
D9 EA D8 C0 D9 E8 DB 2F DB F2 72 0D D8 F2 D9 F1 D8 C0 D9 C9 D8 C1 DB 3F C3 DE D9 D8 E0 C3

```

This takes in RDI a pointer to a double-extended-precision floating-point number, used both for the input \\$m\\$ and for the output of total time taken, and returns the waiting time on the FPU register stack.

Try it online!

Letting \\$x\\$ be the running time in years, the total time is \\$ 2\log\_2(m/x) + x \\$. The derivative of that is \\$ \frac{2}{\ln(2)} \frac xm \frac{-m}{x^2} + 1 = \frac{-2}{\ln(2)x} + 1 \\$, which is zero when \\$ x = \frac{2}{\ln(2)} = 2\log\_2(e)\\$. Therefore, that is the optimal value if it is valid – if \\$m\\$ is at least that value.

In assembly:

```
f:  fldl2e                  # Push log_2(e) onto the FPU register stack.
    fadd st(0), st(0)       # Double it by adding it to itself.
    fld1                    # Push 1 onto the FPU register stack.
    fld TBYTE PTR [rdi]     # Push m onto the FPU register stack.
    fcomi st(0), st(2)      # Compare m and 2*log_2(e).
    jb low                  # Jump if m < 2*log_2(e).
    fdiv st(0), st(2)       # Divide m by 2*log_2(e).
    fyl2x                   # Taking the top two values (m/(2*log_2(e)), 1) as (x, y),
                            # replace them with y*log_2(x).
    fadd st(0), st(0)       # Double the result, getting the waiting time.
    fxch st(1)              # Exchange values, moving 2*log_2(e) to the top.
    fadd st(0), st(1)       # Add the waiting time to 2*log_2(e) for the total time.
    fstp TBYTE PTR [rdi]    # Store that at the address and pop it off the stack.
    ret                     # Return.
low:
    fcompp                  # Compare the two values on top of the stack and pop both.
    fsub st(0), st(0)       # Subtract the remaining value from itself, producing 0.
    ret                     # Return. (The value at the address is unchanged.)

```
> 0 votes

# Answer
# 05AB1E (legacy), 20 bytes

```
žr.²/.²·Í¾‚àÐ;oIs/+‚

```

Port of *@Neil*'s JavaScript answer.

Uses the legacy version of 05AB1E, because apparently `o` (\\$2^a\\$ builtin) doesn't work for zero as float (`0.0`)..

Try it online or verify all test cases.

**Explanation:**

```
žr                   # Push builtin e
  .²                 # Take the base-2 logarithm of it
    /                # Divide the (implicit) input-integer by this
     .²              # Get the base-2 logarithm of that again
       ·             # Double it
        Í            # Decrease it by 2
         ¾‚          # Pair it with 0
           à         # Get the maximum of this pair
            Ð        # Triplicate this maximum
             ;       # Halve the top copy
              o      # Push 2 to the power this
               Is/   # Push the input, and divide it by this value
                  +  # Add it to the other maximum-copy
                   ‚ # Pair it with the remaining maximum
                     # (after which this pair is output implicitly as result)

```
> 0 votes

# Answer
# Python 3.8 (pre-release), ~~73~~ 70 bytes

```
from math import*
lambda a:[b:=log2(max(a*log(2),2))*2-2,b+a/2**(b/2)]

```

Try it online!

* -3 Thanks to att, since
> 0 votes

---
Tags: code-golf
---


# Question
Title: Best performance on x/(y+z) + y/(x+z) + z/(x+y) = N
Consider the equation $$\frac x {y+z} + \frac y {x+z} + \frac z {x+y} = n$$ for positive integers \\$x, y, z\\$ and \\$n \ge 4\\$. Your code will receive \\$n\\$ as an input, and output three integers \\$x, y\\$ and \\$z\\$ such that the equation holds. You may assume that a solution always exists.

## Background

This equation is a little bit of a meme equation; it's famously difficult to solve, and even the lowest case of \\$n = 4\\$ took hundreds of years to do so. In this paper, the authors present maximum sizes (in digit lengths) for various different \\$n\\$s, all of which are crazy large. It's pretty clear that a standard brute force approach of iterating through all triples is never going to find the smallest solution for any \\$n\\$.

However, some pretty clever approaches using elliptic curves (a curve in the form \\$y^2 = x^3 + ax + b\\$ for constants \\$a, b\\$) managed to find a solution for \\$n = 4\\$:

$$\begin{align\*} x & = 36875131794129999827197811565225474825492979968971970996283137471637224634055579 \\ y & = 154476802108746166441951315019919837485664325669565431700026634898253202035277999 \\ z & = 4373612677928697257861252602371390152816537558161613618621437993378423467772036 \end{align\*}$$

Your task is to find these solutions.

## Challenge

Given some positive integer \\$n \ge 4\\$, you should output three positive integers \\$x, y, z\\$ such that

$$\frac x {y+z} + \frac y {x+z} + \frac z {x+y} = n$$

You may output any one solution, in any reasonable format and manner, but you must output exactly *one* solution. You may assume that you will only receive inputs where a solution exists.

Additionally, your answer may not fail due to floating point issues.

## Scoring

This is a challenge, so you should aim for speed over conciseness. I will time each submission on my computer, so:

* You must use a freely available language (that's free as in beer)
* Please provide testing instructions
* If the language is obscure, or requires additional packages/modules, please provide a link to a page where I can download the interpreter

My computer specifications are: MacBook Pro (16-inch, 2019). Processor: 2.3 GHz 8-Core Intel Core i9. Memory: 16 GB 2667 MHz DDR4. Graphics: AMD Radeon Pro 5500M 4 GB. Retina Display: 16-inch (3072 × 1920). Storage: 208 GB available.

Please test your submission on \\$n = 4\\$ before submitting, and include a preliminary time (which I will replace with an official score in due time).

### !! The only valid inputs for \\$n ≤ 10\\$ are supposedly `4`, `6`, and `10`.

# Answer
# PARI/GP, 0.02s for n=4 on ATO

```
fromellpoint(n, x, y) = [ 8 * (n + 3) - x + y, 8 * (n + 3) - x - y, -8 * (n + 3) - 2 * (n + 2)* x]

{ findellpoint(e, n) =
    my(s, h);
    h = 1;
    until(#s > 0,
        h *= 10;
        s = [ p | p <- ellratpoints(e, h), ellmul(e, p, 6) ]);
    s[1]
}

{ f(n) =
    my(e, x, y, a, b, c);
    e = ellinit([0, 4 * n^2 + 12 * n - 3, 0, 32 * (n + 3), 0]);
    [x, y] = g = findellpoint(e, n);
    while([a, b, c] = fromellpoint(n, x, y);
        a <= 0 || b <= 0 || c <= 0,
        [x, y] = elladd(e, g, [x, y]));
    [a, b, c] * denominator([a, b, c])
}

print(f(input))
```

Attempt This Online!

Not really optimized. PARI/GP has some built-in functions for elliptic curves, so I just use them.

You can download PARI/GP here.

When you test the code, just save the code into a file, e.g., `a.gp`, and run `echo 4 | gp -fq a.gp` (replace `4` with your input `n`).
> 2 votes

---
Tags: math, number-theory, fastest-code, rational-numbers
---


# Question
Title: Write two programs that compress and decompress data
**Challenge:**

Create a program that compresses a semi-random string, and another program that decompresses it. The question is indeed quite similar to this one from 2012, but the answers will most likely be very different, and I would therefore claim that this is not a duplicate.

The functions should be tested on 3 control strings that are provided at the bottom.

**The following rules are for both programs:**

The input strings can be taken as function argument, or as user input. The compressed string should either be printed or stored in an *accessible* variable. Accessible means that at the end of the program, it can be printed / displayed using `disp(str)`, `echo(str)`, or the equivalent in your language.

If it's not printed automatically, a command that prints the result should be added at the end of the program, but it will not be included in the byte count. It's OK to print more than the result, as long as it's obvious what the result is. So, for instance in MATLAB, simply omitting the `;` at the end is OK.

Compressing a string of maximum length should take no more than 2 minutes on any modern laptop. The same goes with decompression.

The programs may be in different languages if, for some reason, someone wants to do that.

**The strings:**

In order to help you create an algorithm, an explanation of how the strings are made up follows:

First, a few definitions. All lists and vectors are zero-indexed using brackets `[]`. Parentheses `(n)` are used to construct a string/vector with `n` elements.

```
c(1) = 1 random printable ascii-character (from 32-126, Space - Tilde)
c(n) = n random printable ascii-characters in a string (array of chars ++)
a*c(1) = 1 random printable ascii-character repeated a times
r(1) = 1 random integer
r(n) = n random integers (vector, string, list, whatever...)
c(1) + 2*c(1) + c(3) = 1 random character followed by a random character repeated 2
                       times followed by 3 random characters

```

The string will be made up as follows:

```
 N = 4       // Random integer (4 in the following example)
 a = r(N)    // N random integers, in this example N = 4
 string = a[0]*c(1) + c(a[1]) + a[2]*c(1) + c(a[3])

```

Note: repeated calls to `c(1)` will give different values each time.

As an example:

```
N = 4
a = (5,  3,  7,  4)
string: ttttti(vAAAAAAA=ycf

```

5 times `t` (random character), followed by `i(v` (3 random characters), followed by 7 times `A` (random character) followed by `=ycf` (4 random characters).

For the purpose of this challenge, you may assume that `N > 10` and `N < 50`, every second random number in `A` is larger than `50` and less than `500`, while the other random numbers can be from `1` to `200`. As an example:

```
N = 14
a = (67, 48, 151, 2, 51, 144, 290, 23, 394, 88, 132, 53, 77, 31)

```

The score will be the combined length (bytes) of the two programs, multiplied be the compression rate squared.

The compression rate is the size of the compressed data divided by the size of the original data. The average rate for all three strings is used.

```
score = (Bytes in program 1 + Bytes in program 2)*(Compression rate)^2

```

The winner will be the one with the lowest score two weeks from today.

**Test strings:**

String 1 (5022 chars):

```
TTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTX_w}yo7}vWL$Y@qNR*Xxqt|oqmwr4+32ejdnaKdEf1<a?<iEKswv)HcNyF/pGc).SPpCF-j$& 1**(NNZ.>Zy0e-`a)i$1Z,X[hcR5JX18wG|`9:H;Qi&nluCKC:b! Q+)i77B28/j/4ZYT1=FN!>DR7'yyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyeDW,FmJh.%AgO&<CIO|Z>gSmszi/I?nL3P8)se$cbNit%['G<X9VW/)+Xg%$Y}E98\X o;y<Jf8(,8=i`v\e B\7\?<\!Pht(U7FFg\!\L_&bh=G*IJLPLpKGc@ 3j9E%{z^+'3bFmM3q"|c2Gt#ed%-U+y?<bB'/[I]o}bmyE=Y$h!oo/H,9$&^*7Rbzd.L;KGN-Wllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllgk4D:*\(Kt);&^0:RL.KB)IqS79Xj)c8qhf5+S=Up%y0xj%1lA=C<.^F*!UuE2u4wbZ[1#?Q)wz*E;;_5 w\{VUBqH}0(tE& HV(4eZ}S@7xi_s]nzwtP2$8_v`)BDFEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEzgGFo9b8`U':3H<;;K)D'B4:L'}7x;3d]^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^*'wt#^or$m_F{@D"`[n?x1Ow3H1bh$5Z@yzRJ4=my&%X+bc6Or/Bw`Zx,VO{Ss10}[fKFLX}Rh9W?_k7)\&j\`Z.BABUy'q8\VP5D_n-f|v3Y$cLe;;7r{5lD@uc?r/c+&O=0{Hr!5&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&9<OIozM4dNlw9N-MUW<kwD/E]XB^1/(?)?C4x)%p,K)p#<cG&PMV"10"&+vN-/oKw9FsubG=*&c'A)a Tu)uZD,S{c|<QO}w+[Pdc=$}3f(!73W?Ko!z:gPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPP(!B"n}ydQP W^]2!$,0,ym! cVy4U>hmsNbdU}b-T`n'B^:L#Z}pI5l+46(1LCS>:BAp8+?[ ?}}1mtpo3\[{I]!7T33333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333FzE klH&6Cj[VPd: HB\e9FvH_./lxP*Z\LD-,Y``IegX+=1T_:B>VJ{Ikq>'_>k5>rrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrr"EI5K,%OB??_{"fNG>Ql6"jJ4m[S{I_/`P000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000=K#Gc-0ai'N"zDO[roJAJOPPY!%C#+J7"xd0V^teUZX$QW!<\s 3kuuXS'W`F mUvkzr7R ET"(2Y9c}M-a&shkT9j>*x+KDprC'9WFXl(`I{AfsCffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffvKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKK#v>boc"..................................................................................................................................................................................................a#,uAOemp[b5CPOzI85g:a[|:]<Ss=`JuIB]+Sg$b'>PJ=%:zM#I$,YM1eX)Ja=P5x^WhuVt1?$ZU5qoM68P?n;T]R-RZ0PMH^pS%W*so-v!=2Z=9J^p,j$4)"'mXvWFF]IQN^MqG:^Lr&V?is6A%N${wNjCXpJE+F^wBG4@c`c^/CU-}8TIYJHu$|KGq=\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\l7G7DK9Nq+'{=>.^a"I<ytX0(HsP'x:I4enw5'^kjQ{ZQta\FL|zOC2C[d4y\z8'z<OgHw3+XZ_nSq@B9m)Yu"|JkOTP*L3T"t\<'sh,y*{0%*NBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBl,OuBGl;X(Yxx._o0Jv8a_]`]j=u6-W^Ve%&meh`]PmR}c>3CCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCP+GZ-jP@U#$K.}zTy^J(@9"LZ<,Dm}LkKn'>>ZBn:fn?o_o>LT1{2{t0r4$M-GnV;?/M^P-#uzJ=PnBhYo<,uyXNJ#yiZ;R29ta5 >.D0_$\BWWO%3=|#W:c8^VVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVV%'r`CdgOv(WZ_y2*/sW|$Mmut0CX>Mw+109!Ky$;o`eKqd1D2Kh9x=y8{;(p)xpuIVT+9JS<T>/UIWB< T5$hs|V.$(>$J6j}@\WtWM3\>dvc{O!<(mzw@<xeRkhCIE7L;z7_OFx|nbxfIxu|hhBiN!d"`5;vxnpk3juf;J2})#r!]AFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF<7#0%Uj,b<WrAK?I%kPx![bJBF}RE'j>`f>U]*f%gDY?aa]O3>sL.V\.3#u/%O;xHIl<A4#6zO}umALe*B5P'*`kkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkINNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNIv%x1QT@:A`TeVc"AVnFzfPGN%^</a=G=#P/G/oAS^ZPI-8yhu0T8>V5kF80Gh;QU=SC>ymTH{Onh/)[kN+:y .iRj[yK!V HDFW<<fU&zmm2.OY-H^Gf)yH{R%>5DNI]'AX7-kpEJr`+IM-cUn S{co^]ir%J,(P/[q1 h},R",d\Kg%(*HpGDEq`=ubhTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTgeQ_!6|Qj$L77777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777>JV8&V]xq4k#U)5e^8VTJPRzD)HeT6STV:WgqwBbF61R/{_x=diD{<5jKf/Yds7.;Eu}[bYDyA1wRA{-S:1l[%5dHHVOgWMQBy">VO^fJ4yn>oN.,1LEzxT.)>cHk!PbB|$#."Jg^;8}\% D>*8e))=OnSNhRQ

```

String 2 (2299 chars):

```
VVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVV`]e!oO{=i&}\o8^('MDPC`VCI`(@3AFa"A3Dhc<h2Rhc99F^$<LpAOdzC6Y%dTm:!iHH@&&OCV?y)Vv [`wq=?0-YjXSPx1t3k&=>(6^EW?%pH3y6Rb8="2tG%$Jo6A<X^nS4K\v@nZ(Bi1jCW4?p]aIv}<26gXQ%'GKa*<$aPOnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnn.$$}.HK{It43ltY"H&:VcTkq+C3.g2VB`Ui-P=8I^%9\TN5=[&@;YOR0`[sssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssZz_qnx9wqa'caEfvlp,;c0't70I8'>|W=SHQx\{#ed9)WFM!:l[24.qU,UV^0gARZYW4}n<.6HJdK:{]8,QOO]KbZ'Tugd9{9>X1q.-[adNHmMP*+"<]XIIf>7>Rp/,sQ0QHTO$jduG3O>AV/,GY++$AOBDepNz9qIPzr\G$.NtKLD=j8?8ia*@y34GgmtM%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%]"0'-roq!u`Aw/EYlk< R>-AsSmJ3D w}Pp;Rpi`r755VI,Ao(uVA%)v0]WC/XW{-v7k+37y5QQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQ`9q;^dn#byX+NvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvaY#. xKADce75y7E]`(m'cAg.$N5j{,u!v%Pc(6D?"axU*VQ,n^bWomxD.`LA:I1nvX=^VGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGtOnQL:PKI':C}q.:6|aHiYII*C7{kGa,9aSE8D}h#S%[^:P&e^:kazo,"W]e--\bW=],xD44\@,Z;Q7$RPKA0b6yO_7&h}b/c4@nE.CvI}0.-ySF2zWy_3gwpmcqWZZ'Y))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))X']&p]icj|RFj'ci2*1jXg%* Eu&9QZEWwGpen1Pa,Gti_?FUL)&=r<YL-Th"]f%jV<Kx);@L^)mw'g S(nry%kbZp pGD]R@j3{idSHH<!X{%(/T,ow]$259a P-6_AX*o?4g^>(n<v^:/U@cmh9nOG|ot=8Rw5FfvU/'IGD(gm++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++K#&U4RN$dR*rv1p5t`<n7XpvpVz#uncF647sssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssYl?CCkw#e?#be5,c0GttH}N j:$5AHa Xz[<z-=CdX)@}fHmk7L-k&hZHOP5o9^yU%%:g|TD1b=7G !HKGMN|}/l:}2Ia^fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff56&4i{38sY*]<DTT#:5>RJm*\c&|kM+K\s^"055%FL5Fl&X|{q+4N6t^(<\gt@;v?z}xly?Bi_!mSA+8r/6n4)Kdh4)P8'|oK&-7tFNO:]mr$nl6L1jr):uC(vh`Ei)19MfumB<VtL]"Vc

```

String 3 (10179 chars):

<pre><code>"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""":=P,W$WS.vBP9d89L65VeuKY27|*-Ih1x/nY}p09Sq$PQ%4z!l*)@wmbP3b;C3E8#*?2-T`W"0&::+kA:`.OrjmD-u(oDpE:{x0 ttb13yO"q6U:1N@/[R2g}#y}d,7)_STJ^0hb]4]hSd9%L#]Bimmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmm+HuOde&d,uX?B??|AJ)h.}D<HouV7NXUP0!.,HmhBaar7(c.)A#%8aPc{g8iE.hw0H)P5B^zQT('wG7Vu(|M>lo.5EM3Z/o&[Pfd}A{Vsi,+lAlam*K}69zlNWJv)|u0<e#+:l![((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((G#zx B)=N\[hRY8Dm`x@SPG=3ZRJ^SkywE:U/[\Z?q[fjY9gxO.]TiH)xKw}%*Tb[JhlD]2D4:(CE:#Zre/}9:z2*G)u)O,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,It)UnqhJ_XIzXNlT%C*Mq%R6KNTg=Q(4G)}=Q2Fp.A>Tuz?y4,wvh%,qQS5gb`6E>^6M]1FV/*4s%LDf%bwEr!oH.G/////////////////////////////////////////////////////////////////////////////////////////////////////JfITfs\Bp{8uJmAE@qW>QT!"R\q\q}2Rwo3333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333q Kxp"zbN(am%qRC"bc#]zzD,sr]=H)yMS"0X&_/|yqs!kZ)`MY[C%3j`6$D!(Qk4x."e,m]                                                                                ;B|S)E{BQT:%eSr0j7Gqx0&u7c7.lT]P?.&&mV2ZT^.k^"0)4K*#E4d!z/$#[-?zi8a(S?iIU9|q?lfy3T"}fh)oWfO5^{sAXu`CB*LStW5(KCe3I]-|oE^>!VL<#Pd$PLDBqZfQ)QPCWja7&7HtM7uM9*..................................................................................................................................................................v/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////\sh*_l7Tk`b7KQueol'sWCC,5|\=H>v0I4c\PPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPP4q.r!#H?yY/-t2:iDRwn,TwSR6 v@lBv\jjO!Kz+1NT>ksfbl=hq)/y1q<}3"kYHLJ&&m'NS'lhqaPYJW3}3Qjh)|ZnAQvb^v=6TIw%Ry{!M,aBIzd9QLhB%cjXOoc*C\S0!(f :NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNv(9%9@j.1yF&fw@L9edFP3#7tuHlxpCk8]hD.ky{V6bS#?rEz5PERx_"V:\TN {2_"pE/T:X<#&<\V%IQISzo6w5vO%lvPx)|wO!"+>\t-SzP\wWXFQrmXp`JGJ/sIoVyns2u=yU`26&A1]vrpEXHD/K1HjnN4-t";S*****************************************************************************************************************************************************************a&.z "aV6]K"JhyO;/`UOpAkb}zP53=$AD:Io3lkjdUMjw1w!rL2Za3Dk:,`]AsG!L[3e^ECxxqx[I_{|qe)z;zZ#V&HZ:J4g+2U>}y!Oazq`qY_]'n=egXV9*IaFbtRZGVQG!ojmkTkStrbzFnd|7Keu [7$2f7Npb]ne=wuAg\9*4Rd/cqcDApSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSS[OTjad;#l+*>m&fFSS{rc|xb?MTV$Z2I>)l8QfAUB"wNHhMNpvaz_TnvM:2Ck>*2=jWS2)a/$dP\,"pB9#L^1lSir+m%oG@YA/G#M3T10gF+xdJDqe"8888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888":6Y<zLVYm@aQ-.\-u\M_.7<}L`(w!+7lm@<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<aJHBA#?>9cSxN5HZ:$Z{Kr15x>cZ?!NACujxBVAu;->*BxS)wu dA:2#Sq:FaGgr5,mKLv&_ms"s1:NXEVVX)`y#ekL4H$;%{xrU$ai&9J5C8eqyQE(E|;+3tf^csoENQJG#}X81VE2m1xY 2SI d[*Eozzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz7/+M6f *n*GBp_/+rpBX@]%OpIgfkF":Cc"xzIGYw5H{LVBWFKg\1j{S duWiWB[-%'z7)NGE)QR >"t4#N1{(EntG)$u^o/J(*IaBAB<D\iE?gWj)ccWk-[OToXKjQZTWIji%^] ,Z#:_5Rsk e`s-bxrLW|(,c!>mmin\w5lcLO`````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````+b"0@z2a@N^IO}K{uefxE%pgz'!7GoJ2mLaOZh3#I$tSEZ/=x9S6]Y0[5T@qRftKeXuBFr_ \)-?-2">0r*=MB'hhf4x"%g8Y\[kmPx><6ejGL; s:yp@5af+rg=/`W(xm,{OKLzj dY/3PC)Ea]LLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLcqGx?cJ"y,>w5jkIbja_qUNv#-r_G 86[090^^F@x|4(8@dWy`"MnL5<+Mf{IsyVO32xy@ZKS4.o2T`G$gNJbCddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddd:>WH*?#n+7oFZQ\gLEzvR8LS6u&0^pR[;n`x&D9m"YFf````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````G=Z^o74rpXU<`',;JPl|}/>8f<ir3M6;&O)Y4rV5T2^+AJ>QvlE([bozzb,ifw=BG7+P((lS$g{c!N*&_K<);rx,2&9@7QJi6Q*(.qFQys>EB['1a4(`?htRwJ"a+<j6*>.Lm}F)`:M3;=^n+Bp&\HZI[sv1FGI93\6VVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVV O}h4W!dP?}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}Z'lC(E *d#-Ub?y". r:D{n--gCk&=IpmT{\I-;2vQ18xtU'2u1<qAN<IF!YEwx)ZKvY_)D%CU;l1bC%$>u|W.(2=dC!{_e?bc32]DYC?m}<{vdZKnZ <.VhO?EYwINo7lS36Ir1p4Q%cG*7RX#)iVIu..............................................................................NuF1uxKoCH5[cn,,7uj "6aoUK_7hV|lb;u8Piim!{f4 dASS'mtQ&L_-jZ=a?=YwO%Q?y240o".T*]k",5]S*f(P?Rp?T1=V7[^T=w8_h>(:O%f?iZuaJ=3d`f[dI;8S@'Gz]zn%{_OAw7&T%-44444444444444444444444444444444444444444444444444444444444444444444uSz;a(-U)o.xYDgr0,Kyo+jsMrB^oQJ=V}U`nEB>Eqo}S]sUil-sAurUOxxU.+S#f.lvO>Q_SN71{(3"eXt.%$z2Y%Gk8WFTCBz;\`2-eis.*pQ"q^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^vbAbVM q5#3gqC[FPb%7[jHR(o!jK[B)-!FD+.6Pu-(-ccyOsQPKug;]M8R5c'IK>O4EuxI8nr#Ab\EXRK+fP'KHb@-J=51g?/?<H\-BWq1s-Rb:5TuB5kb;eG3Sp/]h5Y{E+T\#i\.&+Q#%*G&O1o-sRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRR'%*P|wj/I!ThsIYvh&#$W3\.]4[RTuwFOF#8y+TA7%B@u1T)l!:VFW;i.-{w6Gebq3JaMn7X9cwj3eg8Kf!HaME[<f2*w',ji0t0sDj>n+,=WN *k#[a3XKg!"0Mg$`vP\Fvjup*@8TV@ly{k{4Z2[@a:N)SWQ?Lxxv}dJ?WUmFYPBcG>Z;r_[6Kw$n2\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\'ja3@b''Ol'{i3K`wB5(kIOVg9'/R`I6=la;cV=ajQbf1+o3J&B{>(hUQE+g.YMv#q3&i5s/2mB|U^h2.A3U;(rxB{6DQb)`_/Sx/:!URO&49eSAm'B\GP8)9RdPO9FrqGI\^1j*'7Rgfpi&zgX52GU%%h<)h1)KG/Uu:un{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{W02fvj%BMP=H:dSNif}w[lZ@gF,O]w3O R"+g3G[7i*8y,n>1]u 5G!)nulS^S064#?y=/E1_QBDM`i`M5kzH0au24xQNB^u4;4ipll}IP1%V3yEC+2Oq83Y$iezSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSqQd$I49 o;w_%&90L/ckdHY8TeRWLFZNvi3aGwN3&HRuU$Vgt9(_R\FmT9}Aj#VQp"oUoXW=s*vS6SKP ]x<[IA2M2I`2Vy=a3&Jc,n:}qTboygX6pp,L?\ff{zE#9D-?-jgPrKwd6V{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{jB8OKx6j]=oPzb;pL(<A8`%g7+<O6*)W1m8(SiC+4n(775\g8$[?I\`Cffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff)/.%\4TZ1%Eq!chTOC|#Tbx(m}"@u>Bw&L*hz=Px4?yM}`4s>uGL,U0x@-JPIc.Kq-tx/h:Qr7r*t:6>#q 6O+doZQvl#kr:]VM `z%(&<`yhME|B;2Tjm$^N^,0\h)rVEVT\rp@T>>0U:KoFAsZ'_rZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZaI}`I/T;Qk/dyY_96VxX6=EGn%{'uzDF}.k!\}O^NG1p7PI<_C'/3%d70'@;\6n)wydLj}bZfWP9 zei[;J:^;BRwKcBFdFld3IRrRY9oBJ<#ZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZ/e{hh'&wP3jknjfma}v:*__SLUIg\@*_`m:fcbfj((6:1)..?,Xx6<%bi.9Z>)xC`Jbwv#mo_[O0z8>@Exm^>b.&2)[Eyg\Y{UZA9:+SuwhG(<w***********************************************************************************************************************************************************************s4NBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBJ_ h\ xgC46py]Wh'|,LnG2dgl1\*ZG2HWA0Z%26_zB(Y{:;2zxS?>5NJrX8j^*9bt$UQ\PD95El;e'EU6K.[:a&zn]$]`g^Wl;Q(o9oWI3HwTj}NR_:OAdJ@!M8#twm6+tN!*%ldWyOZpnGBeOyz\CiH9w>FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFVRA"MafX,*ZvJvhH{]BrDX">v}pMz2ze.q#$U1c_ XA207Zof^cE,(R`LgHdYY&etOFaShx`F])18.O#\go/-Q#!%6%O0)W`v$fX)7VSTUYau9TC|%a_'bI&i1i7Z3,om_'9(2m-ihn jCh5VrJPD9gm@EoAP*[.!5e{5BJ_>_ut^Hu\:^kJS0IOn+ 555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555gp_;VbIVS>7)S?V.!Qgx7T/Ik33tV.M>/[l/8HiS1L1tX<P_2,rR(R&+-#^rl=b8GgJP^y:!/`+-:_sWyzD56jqu0/N-)].j`*q9$csBoIl CyC]3j+^DT-Ra|LN*TesCL*-Z;OdO^m#{rp8rAaFB.N-''n:\p?O5bPgT{eD9^3[S7&E,n%/VFiz>K(VXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXEFm-T"2Ny{`4Jt7kv2fTpcsn=U.XCpppppppppppppppppppppppppppppppppppppppppppppppppppHr5aL@FX.UBLt$Um68vRs;Fw)Ymm>=^;++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++JczE.=iK'CWH`]_Xf3G*Nb*ExFAKl;|ssZsBC 2s4jz=GR9y>`X8(M;2/BI3h75[[Yfr]txi5}i{np "p}H*.&3o(e>6I)`/;]`[7Oq{=Y4_2jUl}M)jWn&aX&h'dOUrZ),5>Rr2J<UF&{.vJNB?v{Hyp8sK`\J+;%_WTm__________________________________________________________________________________________________________________________3|+lq,Eb6.3HKu}g;La3'x$%?4tgQhIsR'9 c@i<5(LW'$[)YBE rA}BcWFWswnk_h(Z_ a`tQ)IorJ(!>0=c)/-t.n8rL|Php0!tjtI^r=GMN)GU4k?E oQc4|x#y;AU2hW
</code></pre>

Note that the strings can be much longer than this, but there's a character limit (30000) on posts, so I had to restrict it. The functions should work for codes up to the maximum size.

# Answer
# CJam, 40 bytes + 13 bytes, rate 0.48697, score 12.5682

Just a baseline solution which compresses the long runs.

Compression (Test it here with length calculation):

```
qe`{(S*\_{0=K>}#)_{(/(e~\L*}:F&N\}h;;_,F

```

Decompression (Test it here):

```
r{~l1>(@*\r}h

```

The lengths of the three test strings compressed are 2296, 1208 and 4917 respectively. This score could probably be vastly improved by making use of base encoding.
> 2 votes

# Answer
# Awk, 74.9 = (199 + 115) * 0.48853^2

The compression replaces the characters repeated over 4 times, by character & total, enclosed by tabs. For example: `&&&&&` becomes `\t&5\t`. While `dddd` remains `dddd`.

The decompression script uses the tabs as the record separator and restores the repeated characters.

### Compression

```
{split($0,s,"");for(i=1;i<=length($0);i++){c=s[i];f=s[i+1];if(c==p||c==f){n++}else{printf("%s",c)}if(n>1&&c!=s[i+1]){if(n>4){printf("\t%s%d\t",c,n)}else{for(j=0;j<n;j++){printf("%s",c)}};n=0}p=s[i]}}

```

### Decompression

```
BEGIN{RS="\t"}{if($0~/^.[0-9]+$/){for(i=0;i<int(substr($0,2));i++)printf("%s",substr($0,1,1))}else printf("%s",$0)}

```

(note that this script would be more efficient if the substring calculations are first put in variables. But codegolfing often trades efficiency for bytes.)

### Test

```
$ for s in string1 string2 string3; do cat $s.txt|awk -f compress.awk >$s.compressed.txt; done
$ for s in string1 string2 string3; do cat $s.compressed.txt |awk -f uncompress.awk >$s.uncompressed.txt; done

$ wc -c string[1-3].txt string[1-3].uncompressed.txt string[1-3].compressed.txt
 5022 string1.txt
 2299 string2.txt
10179 string3.txt
 5022 string1.uncompressed.txt
 2299 string2.uncompressed.txt
10179 string3.uncompressed.txt
 2296 string1.compressed.txt
 1208 string2.compressed.txt
 4916 string3.compressed.txt
43420 totaal

$ md5sum string[1-3].[ut]*xt
ea7076dd2f24545e2b1d1a680b33e054 *string1.txt
ea7076dd2f24545e2b1d1a680b33e054 *string1.uncompressed.txt
dd69a92cb06fa5e1d49b371efb425e12 *string2.txt
dd69a92cb06fa5e1d49b371efb425e12 *string2.uncompressed.txt
9e6eaf10867da7d0a8d220d429cc579c *string3.txt
9e6eaf10867da7d0a8d220d429cc579c *string3.uncompressed.txt

```
> 2 votes

# Answer
# Perl, 113 bytes + 80 bytes, rate 0.497325, score 47.735

This is my first golf ever, and a first draft. For now all it does is count the length of repeated sequences and replace the repetitions with an integer representing the number of repetitions. E.g. "aaaaa" → "a{{5}}"

Compression:

```
$d=<>;push@d,$1while$d=~/((.)\2*)/g;map{$l=length;($o)=/(.)*/;$_="$o\{\{$l\}\}"if$l>4;}@d;print length(join'',@d);

```

Decompression:

```
map{($o)=/^(.)/;$_="$o"x$lif($l)=/\{\{([0-9]+)\}\}/;}@d;print length(join'',@d);

```

Double curlies ({{ }}) are probably redundant, but I want to be on the safe side. Compressed lengths are 2340, 1230 and 4998 respectively.
> 1 votes

# Answer
# Mathematica, 9 bytes + 11 bytes, rate: 0.565899. Score: 6.40483

Mathematica, of course, has builtins for this. This makes this answer a bit of a cheat, but I thought I should include it anyway.

```
Compress@

```

and

```
Uncompress@

```
> 1 votes

# Answer
# PowerShell 5 (invalid), 37 bytes + 35 bytes, rate 0.43121, score 13.3878

<sub>This entry is currently invalid and theoretical only, as I don't have access to a machine equipped with PowerShell 5 to verify, and/or I'm not sure if this counts as "using an external source." More of a theoretical "what-if" scenario than actual submission.</sub>

.

Compression (the `Get-Content` displays the results and doesn't add to the byte count)

```
$args|sc .\t;compress-archive .\t .\c
Get-Content .\c -Raw

```

Gets command-line input, uses `Set-Content` to store that as a file `.\t`, then uses `Compress-Archive` to zip it to .\c

Decompression (again `Get-Content` doesn't count)

```
$args|sc .\c;expand-archive .\c .\t
Get-Content .\t -Raw

```

PowerShell 5, introduced with Windows 10, includes a new feature that lets you use the built-in-to-Windows zip/unzip functionality. Previously, you would need to create a new shell and explicitly execute a zip.exe command with appropriate command-line arguments - yuck. Now, it's just a simple command away.

Note that this is likely *also* not valid if you're expecting to copy-paste the string output from the compression algorithm into the decompression algorithm, as the PowerShell console doesn't handle non-ASCII characters very well ... Piping from one to the other should work OK, though.
> -1 votes

---
Tags: code-challenge, compression
---


title: Connecting Dots

text:
# Question
Title: Connecting Dots
# Connecting Dots

## We define a type of question on the test, connecting the dots

### Question parameters

There are two parameters. Suppose they are `5` and `4`. The second one **must be less than or equal to the first one**.

Thus, the question will look like this:

```
*
         *
*
         *
*
         *
*
         *
*

```

### Possible answers

An answer is termed `logically possible` if and only if:

* Each dot on the left corresponds to one and only one dot on the right
* Each dot on the right corresponds to at least one dot on the left (there is no maximum)

### We describe an answer using a `matrix`, or `list of lists`.

For instance, `[[0,0],[1,0],[2,1]]` will link the dot indexed 0 on the left to the dot indexed 0 on the right, et cetera. You may choose to use 0-indexed or 1-indexed.

### We define an answer's `complexity`...

...as the number of intersections there are. For instance, the complexity of the answer `[[0,2],[1,1],[2,0]]` to be `1` as they intersect at the same point (assuming they are **evenly spaced out**).

# Purpose

* Calculate the complexity of a given solution

# Grading

This is **`code golf`**.

# Answer
> 6 votes
# Wolfram Language (Mathematica), 17 bytes

```
#2!StirlingS2@##&

```

Try it online!

This is OEIS A019538.

# Answer
> 5 votes
# C (gcc), 42 bytes

```
f(a,b){return a--?b*(f(a,b)+f(a,b-1)):!b;}

```

Try it online!

This uses a recurrence relation. Let \\$f(a,b)\\$ be the number of answers for \\$a\\$ left dots and \\$b\\$ right dots.

Consider the first left dot; it is joined to one right dot, with \\$b\\$ possibilities.

* If that right dot is joined to at least one other left dot, then the remaining \\$a-1\\$ left dots cover the \\$b\\$ right dots at least once each, for \\$f(a-1,b)\\$ possibilities.
* If that right dot is not joined to any other left dot, then the remaining \\$a-1\\$ left dots cover the \\$b-1\\$ other right dots at least once each, for \\$f(a-1,b-1)\\$ possibilities.

Therefore, \\$ f(a,b) = b \times (f(a-1,b) + f(a-1,b-1)) \\$.

The base case is \\$ f(0,0) = 1\\$ and \\$ f(0,b) = 0\\$ for \\$ b \> 0 \\$.

# Answer
> 3 votes
# 05AB1E, 10 bytes

```
LIãεÙg¹Q}O

```

Two loose inputs in reversed order.

Port of *@MatteoC.*'s Python answer, so make sure to upvote him as well!

Try it online or verify all test cases below 6.

**Explanation:**

```
          #  E.g. inputs: b=2,a=3
L         # Push a list in the range [1, first (implicit) input `b`]
          #  → [1,2]
 Iã       # Create all possible `a`-sized combinations from this list, using the
          # cartesian product
          #  → [[1,1,1],[1,1,2],[1,2,1],[1,2,2],[2,1,1],[2,1,2],[2,2,1],[2,2,2]]
   ε      # Map over each inner list:
    Ù     #  Uniquify it
          #   → [[1],[1,2],[1,2],[1,2],[2,1],[2,1],[2,1],[2]]
     g    #  Pop and push the length to get the amount of unique values
          #   → [1,2,2,2,2,2,2,1]
      ¹Q  #  Check if its equal to the first input `b`
          #   → [0,1,1,1,1,1,1,0]
   }O     # After the map: check how many were truthy by taking the sum
          #  → 6
          # (which is output implicitly as result)

```

# Answer
> 2 votes
# Python, ~~97~~ ~~95~~ ~~88~~ 84 bytes

*-2 bytes thanks to @Number Basher*

*-4 bytes thanks to @Kevin Cruijssen*

```
from itertools import*
f=lambda a,b:sum(b==len({*x})for x in product(*[range(b)]*a))
```

Attempt This Online!

# Answer
> 2 votes
# Vyxal `s`, 7 bytes

```
ɾ↔vUvL=

```

Try it Online! or Run all the test cases below 6

## How?

```
ɾ↔vUvL=
ɾ       # List in the range [1, (implicit) first input `b`]
 ↔      # Get all possible combinations of this list of size (implicit) second input `a`
  vU    # For each item, uniquify
    vL  # For each item, get the length
      = # Is each item equal to the (implicit) first input `b`?
        # `s` flag sums the top of the stack

```

Other 7-byters:

```
ɾ↔ƛUL;=
ɾ↔ƛUL¹=

```

### Flagless:

# Vyxal, 8 bytes

```
ɾ↔vUvL=∑

```

Try it Online!

# Answer
> 1 votes
# Charcoal, 23 bytes

```
Ｆ⊕η⊞υ¬ιＦＮＵＭυ×λ⁺κ§υ⊖λＩ⊟υ

```

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

```
Ｆ⊕η⊞υ¬ι

```

Create a list of one `1` and `k` `0`s corresponding to a 0-indexed first row of the table in OEIS linked by @alephalpha.

```
ＦＮ

```

Repeat `n` times:

```
ＵＭυ×λ⁺κ§υ⊖λ

```

Update the row using the recurrence relation given in OEIS but also @m90's answer.

```
Ｉ⊟υ

```

Output the last value calculated.

---
Tags: code-golf
---