title: Cyclic prime number program generator

text:
# Question
Title: Cyclic prime number program generator
# Challenge

Your submission should consist of 2 or more programs each written in distinct languages. They can be arbitrarily numbered from 1 to `k`.

Each program `p`, given a natural number `n` should print the *next* `n` prime numbers (initially, the *next* prime is the 0-th prime, 2) on a single line, followed by a single blank newline, followed by a program fragment, which, when appended to the `p+1 mod k`th program, produces the program which does precisely the same thing, but with the *next* prime being the `n+1`th prime number.

# Details

* Your programs may accept its input as a function argument, or from standard input, or the closest equivalent in your languages.
* Your programs may not read data from any external source other than to read `n` from standard input. If this data is required by your program, it must be included in the source code fragment generated by the previous program.
* Your programs may not compute *any* prime numbers less than the *next* prime number.
* The prime numbers may be separated by any delimiter other than a newline.
* You may not use any language primitives or libraries for prime number generation - you must write the algorithm yourself.
* You *may* use standard libraries for things other than prime generation.
* Two languages which differ only in their versions are *not* said to be distinct languages.
* Two languages whose semantics largely overlap (for example, C and C++) are *not* said to be distinct.
* Your programs may do whatever they like for undefined inputs.
* Your programs are required to support generating prime numbers up to 2^32-1. You may assume whatever you need about the runtime environment to ensure this is the case (i.e. you can assume your C program will be run on a machine where `int` has at least 32 bits). If this assumptions is non-trivial it should be stated explicitly.
* If running your program involves a non-trivial compilation step it should be stated how to do it, so others can reproduce it.

# Input/Output

```
next    in    out
0       10    2,3,5,7,11,13,17,19,23,29
25      13    101,103,107,109,113,127,131,137,139,149,151,157,163
7       4     19,23,29,31

```

# Scoring

Because disk space is very expensive, your programs should be as small as possible. Because more is obviously better, your submission should consist of as many programs as possible. The score of your submission is the average byte count of your programs divided by the number of distinct languages used. Lowest score wins.

# Answer
# Java + Python 2, Score = (302 + 218) / 2 / 2 = 130

Here is a brief explanation on how this works:

* **Choose** a program and pick a positive integer, `n`; for Java, pass `n` as a command line argument; for Python, pass `n` through stdin.
    + The program will then print a list of `n` primes followed by 2 newlines and then a snippet.
* **Append** this to a fresh copy of the program which was not chosen.
* **Choose** a new `n` and pass it to this modified program
    + The program will then print a list of `n` primes followed by 2 newlines and then a snippet.
* **Append** this to a fresh copy of the program which was originally chosen.
* **Rinse, repeat**.

---

## Golfed

### Java, 302 bytes

Netbeans is able to compile this even with the `A` class missing, I haven't been able to figure out how. But once I do, I will add the flags to the byte count.

```
public class P{static int i=2;public static void main(String[]a){int l=2,n=Integer.parseInt(a[0]),x;String s="";try{new A().a();}catch(Exception e){}while(n>0){if(i>1){boolean b=false;for(x=2;x<i;x++){if(i%x==0 && i!=2)b=true;}if(!b){s+=s==""?i:","+i;l=i;n--;}i++;}}System.out.print(s+"\n\n+"+(l-1));}}

```

### Python 2, 218 bytes

```
n=int(input())
s=[]
i=-1
while n:
 if i>1:
  for x in range(2,i):
   if i%x==0and i!=2:break
  else:s+=[i];n-=1
  i+=1
 if n==0:print",".join(str(y)for y in s)+"\n\nclass A{void a(){P.i="+str(s[-1]+1)+";}}"
 if i<0:i=2

```

---

## Un-Golfed

### Java

```
public class PPCG {

   public static int i = 2;

   public static void main(String[] args){
       int n = Integer.parseInt(args[0]);
       int last = 2;
       String s = "";
       try{
           new A().a();
       }catch(Exception e){}
       while(n>0){
           if(i>1){
               boolean broken=false;
               for(int x=2;x<i;x++){
                   if(i%x==0 && i!=2){
                       broken=true;
                   }
               }
               if(!broken){
                   s += s==""?i:","+i;
                   last = i;
                   n-=1;
               }
               i+=1;
           }
       }
       System.out.println(s+"\n\n+"+(last-1));
   }
}

```

### Python 2

```
n=int(input())
s=[]
i=-1
while n:
  if i>1:
    for x in range(2,i):
      if i%x==0 and i!=2:
        break
    else:
      s+=[i]
      n -= 1
    i+=1
  if n==0:
    print ",".join(str(y) for y in s)+"\n\nclass A{public static void a(){PPCG.i="+str(s[-1]-1)+";}}"
  if i<0:
    i = 2

```

**Update**

* **-17** \[16-12-13\] Misc golfing
> 1 votes

---
Tags: code-golf, primes
---


title: Lined up circle, n points

text:
# Question
Title: Lined up circle, n points
Draw lines between every pair of distinct points for `n` points arranged in a circle, producing something like the below result. Shortest code (in bytes) wins! Your lines don't have to be transparent, but it looks better that way. The output must be a vector graphic, or be an image at least 600 pixels by 600 pixels (either saved to a file or displayed on the screen). To complete the challenge you must draw at least 20.

# Answer
> 26 votes
**Mathematica, 13 bytes**

```
CompleteGraph

```

Looks like this only fails to give a circular embedding for `n=4`, but the question states `n>=20`

# Answer
> 13 votes
# MATL, ~~16~~ 14 bytes

As I'm not terribly fluent with MATL I expect that this is somewhat more golfable. (Would be nice to at least beat Mathematica :-) I.e. the the flip `w` is not optimal, it could probably be avoided...

```
:G/4*Jw^2Z^!XG

```

Test it Online! (Thanks @Suever for this service, thanks @DrMcMoylex for -2 bytes.)

Explanation (for `N=3`):

```
  :               Generate Range 1:input:       [1,2,3]
   G/             Divide By the first input     [0.333,0.666,1]
     4*           Multiply by 4                 [1.33,2.66,4.0]
       Jw^        i ^ (the result so far)       [-0.49+ 0.86i,-.5-0.86i,1.00]
                  (This results in a list of the n-th roots of unity)
          2Z^     Take the cartesian product with itself (i.e. generate all 2-tuples of those points)
             !XG  Transpose and plot

```

It is worth noting that for generating the N-th roots of unity you can use the formula `exp(2*pi*i*k/N)` for `k=1,2,3,...,N`. But since `exp(pi*i/2) = i` you could also write `i^(4*k/N)` for `k=1,2,3,...,N` which is what I'm doing here.

# Answer
> 13 votes
## PICO-8, 131 bytes

I wasn't really sure if I'd be breaking any rules, but I did it anyway!

**Golfed**

```
p={}for i=0,19 do add(p,{64+64*cos(i/20),64+64*sin(i/20)})end for x in all(p)do for y in all(p)do line(x[1],x[2],y[1],y[2])end end

```

**Ungolfed**

```
points={}

for i=0,19 do
  x=64+64*cos(i/20)
  y=64+64*sin(i/20)
  add(points,{x,y})
end

for x in all(points) do
  for y in all(points) do
    line(x[1],x[2],y[1],y[2])
  end
end

```

PICO-8 is a Lua based fantasy console with a native resolution of **128x128.** I made the circle as big as I could...

# Answer
> 9 votes
# Mathematica, 42 bytes

Creates a set of 37 points arranged in a circle, and then draws lines between all possible subsets of two points. Someone posted a shorter answer that takes advantage of CompleteGraph, but I believe this is the shortest one aside from those relying on CompleteGraph.

```
Graphics@Line@Subsets[CirclePoints@37,{2}]

```

# Answer
> 9 votes
# HTML + JS (ES6), 34 + ~~177~~ ~~164~~ 162 = 196 bytes

Using the HTML5 Canvas API.

See it on CodePen.

```
f=n=>{with(Math)with(c.getContext`2d`)for(translate(S=300,S),O=n;O--;)for(rotate(a=PI*2/n),N=n;N--;)beginPath(stroke()),lineTo(0,S),lineTo(sin(a*N)*S,cos(a*N)*S)}

/* Demo */
f(20)
```

```
<canvas id=c width=600 height=600>
```

*-13 bytes*: Removed `closePath()`, moved `stroke()` inside `beginPath()`

*-2 bytes*: Defined variable `a` inside `rotate()`

# Answer
> 8 votes
# Java, ~~346~~ ~~338~~ ~~322~~ 301 Bytes

This solution works for all `n>1`, even though the original post didn't require that, it does.

My favorite is `n=5`, don't ask why, also, if you want a cooler GUI, use:

`int a=Math.min(this.getHeight(),this.getWidth())/2;`

In place of the hard-coded 300, it'll use the width or height of the frame as the diameter.

*Saved 8 bytes thanks to Shooqie.* *Saved 21 bytes thanks to Geobits.*

```
import java.awt.*;void m(final int n){new Frame(){public void paint(Graphics g){Point[]p=new Point[n];int a=300;for(int i=1;i<n+1;i++){p[i-1]=new Point(a+(int)(a*Math.cos(i*2*Math.PI/n)),a+(int)(a*Math.sin(i*2*Math.PI/n)));for(int j=0;j<i;j++){g.drawLine(p[i-1].x,p[i-1].y,p[j].x,p[j].y);}}}}.show();}

```

Output for `n=37`:

# Answer
> 7 votes
## Python 2, ~~258~~ ~~235~~ 229 Bytes

```
import itertools as T,math as M
from PIL import Image as I,ImageDraw as D
s=300
n=input()
t=2*M.pi/n
o=I.new('RGB',(s*2,)*2)
for x in T.combinations([(s*M.cos(t*i)+s,s*M.sin(t*i)+s)for i in range(n)],2):D.Draw(o).line(x)
o.show()

```

Output for `n=37`

# Answer
> 6 votes
# Octave, ~~88~~ 69 bytes

```
N=input('');t=0:2*pi/N:N;k=nchoosek(1:N,2)';line(cos(t)(k),sin(t)(k))

```

Output for `N=37`:

Output for `N=19`:

# Answer
> 6 votes
## Perl, 229 bytes

It uses the same formula as most languages that don't have convenient builtin for this challenge (even if I didn't look at them to find it, but that's a fairly easy to find formula). So not very interesting, but there are usually not a lot of Perl answers to this kind of challenges, so I just wanted to propose one.

```
$i=new Imager xsize=>700,ysize=>700;for$x(1..$_){for$y(1..$_){$i->line(color=>red,x1=>350+300*cos($a=2*pi*$x/$_),x2=>350+300*cos($b=2*pi*$y/$_),y1=>350+300*sin$a,y2=>350+300*sin$b)}}$i->write(file=>"t.png")

```

And you'll need `-MImager` (9 bytes), `-MMath::Trig` (providing `pi`, 13 bytes), and `-n` (1 byte) ==\> + 23 bytes.

To run it :

```
perl -MImager -MMath::Trig -ne '$i=new Imager xsize=>700,ysize=>700;for$x(1..$_){for$y(1..$_){$i->line(color=>red,x1=>350+300*cos($a=2*pi*$x/$_),x2=>350+300*cos($b=2*pi*$y/$_),y1=>350+300*sin$a,y2=>350+300*sin$b)}}$i->write(file=>"t.png")' <<< 27

```

It will create a file named `t.png` which contains the image.

You'll need to install `Imager` though, but no worries, it's quite easy :

```
(echo y;echo) | perl -MCPAN -e 'install Imager'

```

(The `echo`s will configure you cpan if you've never used it before. (actually that will only work if your perl is recent enough, I think for most of you it will be, and I'm sorry for the others!)).

And the more readable version (yes, it's fairly readable for a Perl script!) :

```
#!/usr/bin/perl -n
use Imager;
use Math::Trig;
$i=Imager->new(xsize=>700,ysize=>700);
for $x (1..$_){
    for $y (1..$_){
    $i->line(color=>red,x1=>350+300*cos($a=2*pi*$x/$_), x2=>350+300*cos($b=2*pi*$y/$_),
         y1=>350+300*sin($a), y2=>350+300*sin($b));
    }
}
$i->write(file=>"t.png");

```

*-1 byte thanks to Titus.*

# Answer
> 5 votes
# GeoGebra, 92 bytes

```
a=polygon((0,0),(1,0),20)
sequence(sequence(segment(vertex(a,i),vertex(a,j)),j,1,20),i,1,20)

```

Each line is separately entered into the input bar. Here is a gif showing the execution:

**How it works**

The `polygon` command creates a 20-sided polygon, with the vertices of the baseline at `(0,0)` and `(1,0)`. The next command then iterates over each vertex of the polygon with index `i`, using the `sequence` and `vertex` commands, and for each vertex with index `i`, draws a line segment to every other vertex with index `j` using the `segment` command.

# Answer
> 4 votes
# PHP, ~~186~~ ~~184~~ 196 bytes

```
imagecolorallocate($i=imagecreate(601,601),~0,~0,~0);for(;$a<$p=2*M_PI;)for($b=$a+=$p/=$argv[1];$b>0;)imageline($i,(1+cos($a))*$r=300,$r+$r*sin($a),$r+$r*cos($b-=$p),$r+$r*sin($b),1);imagepng($i);

```

writes the image to STDOUT

**breakdown**

```
// create image with white background
imagecolorallocate($i=imagecreate(601,601),~0,~0,~0);

// loop angle A from 0 to 2*PI
for(;$a<$p=2*M_PI;)
    // loop angle B from A down to 0
    for($b=$a+=$p/=$argv[1];$b;)    // ($a pre-increment)
        // draw black line from A to B
        imageline($i,                           // draw line
            (1+cos($a))*$r=300,$r+$r*sin($a),   // from A
            $r+$r*cos($b-=$p),$r+$r*sin($b),    // to B ($b pre-decrement)
            1                                   // undefined color=black
        );
// output
imagepng($i);

```

**-12 bytes for fixed `n=20`**

Replace `$p=2*M_PI` with `6` (-8), `/=$argv[1]` with `=M_PI/10` (-2), and `$b>0` with `$b` (-2)

Using exact PI/10 doesn´t hurt. With `.3142`, the rounding errors from the parametrized version remained, but with `M_PI/10` they vanished and I can check `$b`(\<\>0) instead of `$b>0`. I could have saved two bytes with `.314`, but that would have off-set the points.

The limit `$a<6` is sufficiently exact for 20 points.

**174 bytes for fixed `n=314`**

```
imagecolorallocate($i=imagecreate(601,601),~0,~0,~0);for(;$a<314;)for($b=$a++;$b--;)imageline($i,(1+cos($a))*$r=300,$r+$r*sin($a),$r+$r*cos($b),$r+$r*sin($b),1);imagepng($i);

```

Using 314 points results in a filled circle in that resolution (as do 136,140, every even number above that, and everything above 317).

# Answer
> 4 votes
## R, ~~127~~ 123 bytes

```
plot((e=cbind(sin(t<-seq(0,2*pi,l=(n=21)))*2,cos(t)*2)));for(i in 2:n)for(j in 1:i)lines(c(e[i,1],e[j,1]),c(e[i,2],e[j,2]))

```

**Produces :**

Nice axis' labels uh ?

*-4 bytes* thanks to @Titus !

# Answer
> 4 votes
## NetLogo \- 44 bytes

```
cro 20[create-links-to other turtles fd 20]

```

# Answer
> 3 votes
# Octave, ~~50 48 46~~ 45 bytes

```
@(N)gplot((k=0:2*pi/N:N)+k',[cos(k);sin(k)]')

```

This is an anyonmous function that plots the graph we're looking for.

Explanation:

`(k=0:2*pi/N:N)+k'` Makes a full `N+1 x N+1` adjecency matrix and simultaneously defines the vector `k` of angles, which we we use then for `[cos(k);sin(k)]'`, a matrix of coordinates where each graph node is positioned. `gplot` just plots the graph that we want.

For `N = 29` we get:

# Answer
> 3 votes
# BBC BASIC, 98 ascii characters

Tokenised filesize 86 bytes

```
r=600V.5142;29,r;r;:I.n:t=2*PI/n:F.i=1TOn*n:a=i DIVn*t:b=i MODn*t:L.r*SINa,r*COSa,r*SINb,r*COSb:N.

```

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

There's nothing wrong with drawing every line twice, the appearance is identical :-P

**Ungolfed**

```
  r=600                              :REM Radius 600 units. 2 units per pixel, so 300 pixels
  VDU5142;29,r;r;                    :REM Set mode 20 (600 pixels high) and move origin away from screen corner
  INPUTn                             :REM Take input.
  t=2*PI/n                           :REM Step size in radians.
  FORi=1TOn*n                        :REM Iterate through all combinations.
    a=i DIVn*t                       :REM Get two angles a and b
    b=i MODn*t                       :REM by integer division and modlo
    LINEr*SINa,r*COSa,r*SINb,r*COSb  :REM calculate cartesian coordinates and draw line
  NEXT

```

**Output n=21**

This looks much better in the original rendering than in the browser.

# Answer
> 2 votes
# MATLAB, 36 bytes

```
@(n)plot(graph(ones(n),'Om'),'La','c')

```

This is an anoymous function that creates the plot.

```
@(n)                                     Define an anonymous fuction of
               ones(n)                   Create an × matrix of ones
         graph(       ,'Om')             Create a graph object with that adjacency
                                         matrix, omitting self-loops
    plot(                   ,'La','c')   Plot the graph with a circular layout

```

Example:

# Answer
> 2 votes
## JavaScript (ES5)/SVG (HTML5), 181 bytes

```
document.write('<svg viewBox=-1e3,-1e3,2e3,2e3><path stroke=#000 fill=none d=M1e3,0')
with(Math)for(i=37;--i;)for(j=37;j--;)document.write('L'+1e3*cos(a=i*j*PI*2/37)+','+1e3*sin(a))
```

Only works for prime numbers, such as the original suggestion of 37. You can halve (rounded up) the initial value of `i` to obtain a fainter image. You can also consistently adjust the `1e3,2e3` to other values to taste (I started with `300,600` but decided that it was too coarse).

# Answer
> 1 votes
## QBasic 4.5, ~~398~~ 271 bytes

```
CLS:SCREEN 11:DEFSTR M-Z:DEFDBL A-L
INPUT"N",A:I=(360/A)*.0175:J=230
Q=",":FOR E=0 TO A
FOR F=E TO A
M=x$(COS(I*E)*J+J):N=x$(SIN(I*E)*J+J):O=x$(COS(I*F)*J+J):P=x$(SIN(I*F)*J+J):DRAW "BM"+M+Q+N+"M"+O+Q+P
NEXT:NEXT
FUNCTION x$(d):x$=LTRIM$(STR$(CINT(d))):END FUNCTION

```

The screen in QBasic can onl be 640x480, so the circle has a radius of only 230 px, unfortunately. Also, there's some artifacting because of float-to-int precision loss. Looks like this for `N=36`:

EDIT: I didn't need the storage, the type declaration and all the looping. Calculating all Carthesians from Polars in place is 50% cheaper in byte count...

# Answer
> 1 votes
## QBIC, ~~98~~ 94 bytes

```
$SCREEN 11|:i=6.3/a j=230[0,a|[b,a|line(cos(b*i)*j+j,sin(b*i)*j+j)-(cos(c*i)*j+j,sin(c*o)*j+j)

```

I've converted ~~my original QBasic answer~~ @LevelRiverSt 's answer to QBIC. I thought this would rely too heavily on functions that are not built into QBIC to be feasible, but as it turns out, it saves another 90 bytes. Substituting the `DRAW` for `LINE` saves another 80 bytes. I knew I was forgetting something simple...

When run with a command line parameter of 36, it looks like this:

# Answer
> 1 votes
# Processing, 274 bytes (239 + `size` call and function call)

```
void d(int s){float a=2*PI/s,x=0,y=-400,m,n;float[][]p=new float[2][s];translate(400,400);for(int i=0;i<s;i++){m=x*cos(a)-y*sin(a);n=x*sin(a)+y*cos(a);x=m;y=n;p[0][i]=x;p[1][i]=y;for(int j=0;j<i;j++)line(p[0][j],p[1][j],p[0][i],p[1][i]);}}
void setup(){size(800,800);d(50);}

```

I honestly don't know why, but `setup` had to be on the second line. I used https://en.wikipedia.org/wiki/Rotation\_matrix to help me calculate the maths for rotation. This program calculates the points and pushes them to an array, with which we are using to draw lines.

Here is a picture of a polygon with 50 edges (the 100 edges one was almost completely black)

You can add `stroke(0,alpha);` to have transparent edges, where `alpha` is the opacity of the line. Here's the same polygon with `alpha` of `20`.

# Answer
> 1 votes
# Bash + Jelly + GraphViz, 52 characters, 52 or 63 bytes

Given that the programs in question disagree on which character encoding to use, the program is full of control characters. Here's what it looks like under `xxd`, in Latin-1 encoding (which represents each character in one byte):

```
00000000: 6a65 6c6c 7920 6520 2793 5213 636a 0c8e  jelly e '.R.cj..
00000010: 2d2d 59fe 9a3f 1d15 dc65 34d3 8442 7f05  --Y..?...e4..B..
00000020: 1172 80cf fb3b ff7d 277c 6369 7263 6f20  .r...;.}'|circo
00000030: 2d54 7073                                -Tps

```

I couldn't actually get the program to run, though, without converting the input into UTF-8 for some reason (which would make it 63 bytes long). Logically it *should* work as Latin-1 – none of the characters are outside the range 0 to 255 – but I keep getting "string index out of range" errors no matter how I configure the character encoding environment variables. So this will have to be counted as 63 bytes unless someone can figure out a way to run it without re-encoding it.

The program might be slightly more readable if we interpret it in Jelly's encoding:

```
jelly e 'ƓRŒcj€⁾--Y“Ȥ?øßṇe4ạ⁴B¶¦×r°Ẇ»;”}'|circo -Tps

```

The program takes the number of points on standard input and outputs a PostScript image on standard output. (It can trivially be adapted to output in any format GraphViz supports by changing the `-Tps` at the end; it's just that PostScript has the shortest name. Arguably, you can save five characters by removing the `-Tps`, but then you get output in GraphViz's internal image format that nothing else supports, which probably doesn't count for the purposes of the question.)

Fundamentally, this is just a Jelly program that calls into GraphViz to do the drawing; however, Jelly doesn't seem to have any capabilities for running external programs, so I had to use bash to link them together. (This also means that it's cheaper to make Jelly request input from stdin manually; normally it takes input from the command line, but that would mean extra bytes in the bash wrapper.) `circo` will automatically arrange all the points it's asked to draw in a circle, so the Jelly code just has to ask it to draw a list of points, all of which are connected to each other. Here's how it works:

```
ƓRŒcj€⁾--Y“Ȥ?øßṇe4ạ⁴B¶¦×r°Ẇ»;”}
Ɠ                               read number from stdin
 R                              produce range from 1 to that number
                                (here used to produce a list with
                                that many distinct elements)
  Œc                            select all unordered pairs from that
      ⁾--                       a string consisting of two hyphens
    j€                          join each pair via the string
         Y                      join on newlines
                            ;   prepend (in this context)
          “Ȥ?øßṇe4ạ⁴B¶¦×r°Ẇ»    "graph{node[shape=point]"
                             ”} follow output with a "}" character

```

The use of Jelly lets us slightly compress the string that configures the GraphViz output via its built-in dictionary. The dictionary has `graph`, `node`, and `point`. Annoyingly, it doesn't have `shape` (it has `SHAPE`, but GraphViz is case-sensitive), so we have to encode that character-by-character.

Here's the output for input 21 (with a slight modification to the program to make it output in a format that can be uploaded to Stack Exchange):

# Answer
> 0 votes
# PHP + HTML SVG, ~~316~~ 263 bytes

**Golfed version with hardcoded `n` points and no input `n` parameter:**

```
<svg height="610" width="610"><?for($i=1;$i<33;$i++){$x[]=300*sin(2*M_PI/32*$i)+305;$y[]=300*cos(2*M_PI/32)+305;}foreach($x as$j=>$w){foreach($y as$k=>$z){echo'<line x1="'.$x[$j].'" y1="'.$y[$j].'" x2="'.$x[$k].'" y2="'.$y[$k].'" style="stroke:red;"/>';}}?></svg>

```

**Previous golfed version with input parameter for `n` points, 316 bytes:**

```
<svg height="610" width="610"><?$n=$_GET[n];$d=2*M_PI/$n;$r=300;$o=305;for($i=1;$i<=$n;$i++){$x[]=$r*sin($d*$i)+$o;$y[]=$r*cos($d*$i)+$o;}foreach($x as$j=>$w){foreach($y as$k=>$z){echo'<line x1="'.$x[$j].'" y1="'.$y[$j].'" x2="'.$x[$k].'" y2="'.$y[$k].'" style="stroke:rgba(0,0,0,.15);stroke-width:1;" />';}}?></svg>

```

Usage: save in a file and call from the browser:

```
http://localhost/codegolf/circle.php?n=32

```

Ungolfed version with input parameter for `n` points and CSS:

```
<style>
line {
    stroke: rgba(0,0,0,.15);
    stroke-width:1;
}
</style>
<svg height="610" width="610">
<?php
$n=$_GET[n]; // number of points
$d=2*M_PI/$n; // circle parts
$r=300; // circle radius
$o=305; // offset x,y
for ($i=1;$i<=$n;$i++){
    $x[]=$r*sin($d*$i)+$o; // store x,y coordinates in array
    $y[]=$r*cos($d*$i)+$o;
}
foreach($x as $j => $w){ // iterate all x,y points and connect to each other
    foreach($y as $k => $z) {
        echo '<line x1="'.$x[$j].'" y1="'.$y[$j].'" x2="'.$x[$k].'" y2="'.$y[$k].'" />'."\n";
    }
}
?>
</svg>

```

Couldn't attach a 32 points fully functional snippet because of the 30k characters limit for a single post. Here is a screenshot:

The attached snippet is limited to 18 points because of the 30k single post limit.

```
line {
stroke: rgba(0,0,0,.15);
stroke-width:1;
}
```

```
<svg height="610" width="610">
<line x1="407.6060429977" y1="586.90778623577" x2="407.6060429977" y2="586.90778623577" />
<line x1="407.6060429977" y1="586.90778623577" x2="497.83628290596" y2="534.81333293569" />
<line x1="407.6060429977" y1="586.90778623577" x2="564.80762113533" y2="455" />
<line x1="407.6060429977" y1="586.90778623577" x2="600.44232590366" y2="357.09445330008" />
<line x1="407.6060429977" y1="586.90778623577" x2="600.44232590366" y2="252.90554669992" />
<line x1="407.6060429977" y1="586.90778623577" x2="564.80762113533" y2="155" />
<line x1="407.6060429977" y1="586.90778623577" x2="497.83628290596" y2="75.186667064307" />
<line x1="407.6060429977" y1="586.90778623577" x2="407.6060429977" y2="23.092213764227" />
<line x1="407.6060429977" y1="586.90778623577" x2="305" y2="5" />
<line x1="407.6060429977" y1="586.90778623577" x2="202.3939570023" y2="23.092213764227" />
<line x1="407.6060429977" y1="586.90778623577" x2="112.16371709404" y2="75.186667064307" />
<line x1="407.6060429977" y1="586.90778623577" x2="45.192378864669" y2="155" />
<line x1="407.6060429977" y1="586.90778623577" x2="9.5576740963376" y2="252.90554669992" />
<line x1="407.6060429977" y1="586.90778623577" x2="9.5576740963376" y2="357.09445330008" />
<line x1="407.6060429977" y1="586.90778623577" x2="45.192378864668" y2="455" />
<line x1="407.6060429977" y1="586.90778623577" x2="112.16371709404" y2="534.81333293569" />
<line x1="407.6060429977" y1="586.90778623577" x2="202.3939570023" y2="586.90778623577" />
<line x1="407.6060429977" y1="586.90778623577" x2="305" y2="605" />
<line x1="497.83628290596" y1="534.81333293569" x2="407.6060429977" y2="586.90778623577" />
<line x1="497.83628290596" y1="534.81333293569" x2="497.83628290596" y2="534.81333293569" />
<line x1="497.83628290596" y1="534.81333293569" x2="564.80762113533" y2="455" />
<line x1="497.83628290596" y1="534.81333293569" x2="600.44232590366" y2="357.09445330008" />
<line x1="497.83628290596" y1="534.81333293569" x2="600.44232590366" y2="252.90554669992" />
<line x1="497.83628290596" y1="534.81333293569" x2="564.80762113533" y2="155" />
<line x1="497.83628290596" y1="534.81333293569" x2="497.83628290596" y2="75.186667064307" />
<line x1="497.83628290596" y1="534.81333293569" x2="407.6060429977" y2="23.092213764227" />
<line x1="497.83628290596" y1="534.81333293569" x2="305" y2="5" />
<line x1="497.83628290596" y1="534.81333293569" x2="202.3939570023" y2="23.092213764227" />
<line x1="497.83628290596" y1="534.81333293569" x2="112.16371709404" y2="75.186667064307" />
<line x1="497.83628290596" y1="534.81333293569" x2="45.192378864669" y2="155" />
<line x1="497.83628290596" y1="534.81333293569" x2="9.5576740963376" y2="252.90554669992" />
<line x1="497.83628290596" y1="534.81333293569" x2="9.5576740963376" y2="357.09445330008" />
<line x1="497.83628290596" y1="534.81333293569" x2="45.192378864668" y2="455" />
<line x1="497.83628290596" y1="534.81333293569" x2="112.16371709404" y2="534.81333293569" />
<line x1="497.83628290596" y1="534.81333293569" x2="202.3939570023" y2="586.90778623577" />
<line x1="497.83628290596" y1="534.81333293569" x2="305" y2="605" />
<line x1="564.80762113533" y1="455" x2="407.6060429977" y2="586.90778623577" />
<line x1="564.80762113533" y1="455" x2="497.83628290596" y2="534.81333293569" />
<line x1="564.80762113533" y1="455" x2="564.80762113533" y2="455" />
<line x1="564.80762113533" y1="455" x2="600.44232590366" y2="357.09445330008" />
<line x1="564.80762113533" y1="455" x2="600.44232590366" y2="252.90554669992" />
<line x1="564.80762113533" y1="455" x2="564.80762113533" y2="155" />
<line x1="564.80762113533" y1="455" x2="497.83628290596" y2="75.186667064307" />
<line x1="564.80762113533" y1="455" x2="407.6060429977" y2="23.092213764227" />
<line x1="564.80762113533" y1="455" x2="305" y2="5" />
<line x1="564.80762113533" y1="455" x2="202.3939570023" y2="23.092213764227" />
<line x1="564.80762113533" y1="455" x2="112.16371709404" y2="75.186667064307" />
<line x1="564.80762113533" y1="455" x2="45.192378864669" y2="155" />
<line x1="564.80762113533" y1="455" x2="9.5576740963376" y2="252.90554669992" />
<line x1="564.80762113533" y1="455" x2="9.5576740963376" y2="357.09445330008" />
<line x1="564.80762113533" y1="455" x2="45.192378864668" y2="455" />
<line x1="564.80762113533" y1="455" x2="112.16371709404" y2="534.81333293569" />
<line x1="564.80762113533" y1="455" x2="202.3939570023" y2="586.90778623577" />
<line x1="564.80762113533" y1="455" x2="305" y2="605" />
<line x1="600.44232590366" y1="357.09445330008" x2="407.6060429977" y2="586.90778623577" />
<line x1="600.44232590366" y1="357.09445330008" x2="497.83628290596" y2="534.81333293569" />
<line x1="600.44232590366" y1="357.09445330008" x2="564.80762113533" y2="455" />
<line x1="600.44232590366" y1="357.09445330008" x2="600.44232590366" y2="357.09445330008" />
<line x1="600.44232590366" y1="357.09445330008" x2="600.44232590366" y2="252.90554669992" />
<line x1="600.44232590366" y1="357.09445330008" x2="564.80762113533" y2="155" />
<line x1="600.44232590366" y1="357.09445330008" x2="497.83628290596" y2="75.186667064307" />
<line x1="600.44232590366" y1="357.09445330008" x2="407.6060429977" y2="23.092213764227" />
<line x1="600.44232590366" y1="357.09445330008" x2="305" y2="5" />
<line x1="600.44232590366" y1="357.09445330008" x2="202.3939570023" y2="23.092213764227" />
<line x1="600.44232590366" y1="357.09445330008" x2="112.16371709404" y2="75.186667064307" />
<line x1="600.44232590366" y1="357.09445330008" x2="45.192378864669" y2="155" />
<line x1="600.44232590366" y1="357.09445330008" x2="9.5576740963376" y2="252.90554669992" />
<line x1="600.44232590366" y1="357.09445330008" x2="9.5576740963376" y2="357.09445330008" />
<line x1="600.44232590366" y1="357.09445330008" x2="45.192378864668" y2="455" />
<line x1="600.44232590366" y1="357.09445330008" x2="112.16371709404" y2="534.81333293569" />
<line x1="600.44232590366" y1="357.09445330008" x2="202.3939570023" y2="586.90778623577" />
<line x1="600.44232590366" y1="357.09445330008" x2="305" y2="605" />
<line x1="600.44232590366" y1="252.90554669992" x2="407.6060429977" y2="586.90778623577" />
<line x1="600.44232590366" y1="252.90554669992" x2="497.83628290596" y2="534.81333293569" />
<line x1="600.44232590366" y1="252.90554669992" x2="564.80762113533" y2="455" />
<line x1="600.44232590366" y1="252.90554669992" x2="600.44232590366" y2="357.09445330008" />
<line x1="600.44232590366" y1="252.90554669992" x2="600.44232590366" y2="252.90554669992" />
<line x1="600.44232590366" y1="252.90554669992" x2="564.80762113533" y2="155" />
<line x1="600.44232590366" y1="252.90554669992" x2="497.83628290596" y2="75.186667064307" />
<line x1="600.44232590366" y1="252.90554669992" x2="407.6060429977" y2="23.092213764227" />
<line x1="600.44232590366" y1="252.90554669992" x2="305" y2="5" />
<line x1="600.44232590366" y1="252.90554669992" x2="202.3939570023" y2="23.092213764227" />
<line x1="600.44232590366" y1="252.90554669992" x2="112.16371709404" y2="75.186667064307" />
<line x1="600.44232590366" y1="252.90554669992" x2="45.192378864669" y2="155" />
<line x1="600.44232590366" y1="252.90554669992" x2="9.5576740963376" y2="252.90554669992" />
<line x1="600.44232590366" y1="252.90554669992" x2="9.5576740963376" y2="357.09445330008" />
<line x1="600.44232590366" y1="252.90554669992" x2="45.192378864668" y2="455" />
<line x1="600.44232590366" y1="252.90554669992" x2="112.16371709404" y2="534.81333293569" />
<line x1="600.44232590366" y1="252.90554669992" x2="202.3939570023" y2="586.90778623577" />
<line x1="600.44232590366" y1="252.90554669992" x2="305" y2="605" />
<line x1="564.80762113533" y1="155" x2="407.6060429977" y2="586.90778623577" />
<line x1="564.80762113533" y1="155" x2="497.83628290596" y2="534.81333293569" />
<line x1="564.80762113533" y1="155" x2="564.80762113533" y2="455" />
<line x1="564.80762113533" y1="155" x2="600.44232590366" y2="357.09445330008" />
<line x1="564.80762113533" y1="155" x2="600.44232590366" y2="252.90554669992" />
<line x1="564.80762113533" y1="155" x2="564.80762113533" y2="155" />
<line x1="564.80762113533" y1="155" x2="497.83628290596" y2="75.186667064307" />
<line x1="564.80762113533" y1="155" x2="407.6060429977" y2="23.092213764227" />
<line x1="564.80762113533" y1="155" x2="305" y2="5" />
<line x1="564.80762113533" y1="155" x2="202.3939570023" y2="23.092213764227" />
<line x1="564.80762113533" y1="155" x2="112.16371709404" y2="75.186667064307" />
<line x1="564.80762113533" y1="155" x2="45.192378864669" y2="155" />
<line x1="564.80762113533" y1="155" x2="9.5576740963376" y2="252.90554669992" />
<line x1="564.80762113533" y1="155" x2="9.5576740963376" y2="357.09445330008" />
<line x1="564.80762113533" y1="155" x2="45.192378864668" y2="455" />
<line x1="564.80762113533" y1="155" x2="112.16371709404" y2="534.81333293569" />
<line x1="564.80762113533" y1="155" x2="202.3939570023" y2="586.90778623577" />
<line x1="564.80762113533" y1="155" x2="305" y2="605" />
<line x1="497.83628290596" y1="75.186667064307" x2="407.6060429977" y2="586.90778623577" />
<line x1="497.83628290596" y1="75.186667064307" x2="497.83628290596" y2="534.81333293569" />
<line x1="497.83628290596" y1="75.186667064307" x2="564.80762113533" y2="455" />
<line x1="497.83628290596" y1="75.186667064307" x2="600.44232590366" y2="357.09445330008" />
<line x1="497.83628290596" y1="75.186667064307" x2="600.44232590366" y2="252.90554669992" />
<line x1="497.83628290596" y1="75.186667064307" x2="564.80762113533" y2="155" />
<line x1="497.83628290596" y1="75.186667064307" x2="497.83628290596" y2="75.186667064307" />
<line x1="497.83628290596" y1="75.186667064307" x2="407.6060429977" y2="23.092213764227" />
<line x1="497.83628290596" y1="75.186667064307" x2="305" y2="5" />
<line x1="497.83628290596" y1="75.186667064307" x2="202.3939570023" y2="23.092213764227" />
<line x1="497.83628290596" y1="75.186667064307" x2="112.16371709404" y2="75.186667064307" />
<line x1="497.83628290596" y1="75.186667064307" x2="45.192378864669" y2="155" />
<line x1="497.83628290596" y1="75.186667064307" x2="9.5576740963376" y2="252.90554669992" />
<line x1="497.83628290596" y1="75.186667064307" x2="9.5576740963376" y2="357.09445330008" />
<line x1="497.83628290596" y1="75.186667064307" x2="45.192378864668" y2="455" />
<line x1="497.83628290596" y1="75.186667064307" x2="112.16371709404" y2="534.81333293569" />
<line x1="497.83628290596" y1="75.186667064307" x2="202.3939570023" y2="586.90778623577" />
<line x1="497.83628290596" y1="75.186667064307" x2="305" y2="605" />
<line x1="407.6060429977" y1="23.092213764227" x2="407.6060429977" y2="586.90778623577" />
<line x1="407.6060429977" y1="23.092213764227" x2="497.83628290596" y2="534.81333293569" />
<line x1="407.6060429977" y1="23.092213764227" x2="564.80762113533" y2="455" />
<line x1="407.6060429977" y1="23.092213764227" x2="600.44232590366" y2="357.09445330008" />
<line x1="407.6060429977" y1="23.092213764227" x2="600.44232590366" y2="252.90554669992" />
<line x1="407.6060429977" y1="23.092213764227" x2="564.80762113533" y2="155" />
<line x1="407.6060429977" y1="23.092213764227" x2="497.83628290596" y2="75.186667064307" />
<line x1="407.6060429977" y1="23.092213764227" x2="407.6060429977" y2="23.092213764227" />
<line x1="407.6060429977" y1="23.092213764227" x2="305" y2="5" />
<line x1="407.6060429977" y1="23.092213764227" x2="202.3939570023" y2="23.092213764227" />
<line x1="407.6060429977" y1="23.092213764227" x2="112.16371709404" y2="75.186667064307" />
<line x1="407.6060429977" y1="23.092213764227" x2="45.192378864669" y2="155" />
<line x1="407.6060429977" y1="23.092213764227" x2="9.5576740963376" y2="252.90554669992" />
<line x1="407.6060429977" y1="23.092213764227" x2="9.5576740963376" y2="357.09445330008" />
<line x1="407.6060429977" y1="23.092213764227" x2="45.192378864668" y2="455" />
<line x1="407.6060429977" y1="23.092213764227" x2="112.16371709404" y2="534.81333293569" />
<line x1="407.6060429977" y1="23.092213764227" x2="202.3939570023" y2="586.90778623577" />
<line x1="407.6060429977" y1="23.092213764227" x2="305" y2="605" />
<line x1="305" y1="5" x2="407.6060429977" y2="586.90778623577" />
<line x1="305" y1="5" x2="497.83628290596" y2="534.81333293569" />
<line x1="305" y1="5" x2="564.80762113533" y2="455" />
<line x1="305" y1="5" x2="600.44232590366" y2="357.09445330008" />
<line x1="305" y1="5" x2="600.44232590366" y2="252.90554669992" />
<line x1="305" y1="5" x2="564.80762113533" y2="155" />
<line x1="305" y1="5" x2="497.83628290596" y2="75.186667064307" />
<line x1="305" y1="5" x2="407.6060429977" y2="23.092213764227" />
<line x1="305" y1="5" x2="305" y2="5" />
<line x1="305" y1="5" x2="202.3939570023" y2="23.092213764227" />
<line x1="305" y1="5" x2="112.16371709404" y2="75.186667064307" />
<line x1="305" y1="5" x2="45.192378864669" y2="155" />
<line x1="305" y1="5" x2="9.5576740963376" y2="252.90554669992" />
<line x1="305" y1="5" x2="9.5576740963376" y2="357.09445330008" />
<line x1="305" y1="5" x2="45.192378864668" y2="455" />
<line x1="305" y1="5" x2="112.16371709404" y2="534.81333293569" />
<line x1="305" y1="5" x2="202.3939570023" y2="586.90778623577" />
<line x1="305" y1="5" x2="305" y2="605" />
<line x1="202.3939570023" y1="23.092213764227" x2="407.6060429977" y2="586.90778623577" />
<line x1="202.3939570023" y1="23.092213764227" x2="497.83628290596" y2="534.81333293569" />
<line x1="202.3939570023" y1="23.092213764227" x2="564.80762113533" y2="455" />
<line x1="202.3939570023" y1="23.092213764227" x2="600.44232590366" y2="357.09445330008" />
<line x1="202.3939570023" y1="23.092213764227" x2="600.44232590366" y2="252.90554669992" />
<line x1="202.3939570023" y1="23.092213764227" x2="564.80762113533" y2="155" />
<line x1="202.3939570023" y1="23.092213764227" x2="497.83628290596" y2="75.186667064307" />
<line x1="202.3939570023" y1="23.092213764227" x2="407.6060429977" y2="23.092213764227" />
<line x1="202.3939570023" y1="23.092213764227" x2="305" y2="5" />
<line x1="202.3939570023" y1="23.092213764227" x2="202.3939570023" y2="23.092213764227" />
<line x1="202.3939570023" y1="23.092213764227" x2="112.16371709404" y2="75.186667064307" />
<line x1="202.3939570023" y1="23.092213764227" x2="45.192378864669" y2="155" />
<line x1="202.3939570023" y1="23.092213764227" x2="9.5576740963376" y2="252.90554669992" />
<line x1="202.3939570023" y1="23.092213764227" x2="9.5576740963376" y2="357.09445330008" />
<line x1="202.3939570023" y1="23.092213764227" x2="45.192378864668" y2="455" />
<line x1="202.3939570023" y1="23.092213764227" x2="112.16371709404" y2="534.81333293569" />
<line x1="202.3939570023" y1="23.092213764227" x2="202.3939570023" y2="586.90778623577" />
<line x1="202.3939570023" y1="23.092213764227" x2="305" y2="605" />
<line x1="112.16371709404" y1="75.186667064307" x2="407.6060429977" y2="586.90778623577" />
<line x1="112.16371709404" y1="75.186667064307" x2="497.83628290596" y2="534.81333293569" />
<line x1="112.16371709404" y1="75.186667064307" x2="564.80762113533" y2="455" />
<line x1="112.16371709404" y1="75.186667064307" x2="600.44232590366" y2="357.09445330008" />
<line x1="112.16371709404" y1="75.186667064307" x2="600.44232590366" y2="252.90554669992" />
<line x1="112.16371709404" y1="75.186667064307" x2="564.80762113533" y2="155" />
<line x1="112.16371709404" y1="75.186667064307" x2="497.83628290596" y2="75.186667064307" />
<line x1="112.16371709404" y1="75.186667064307" x2="407.6060429977" y2="23.092213764227" />
<line x1="112.16371709404" y1="75.186667064307" x2="305" y2="5" />
<line x1="112.16371709404" y1="75.186667064307" x2="202.3939570023" y2="23.092213764227" />
<line x1="112.16371709404" y1="75.186667064307" x2="112.16371709404" y2="75.186667064307" />
<line x1="112.16371709404" y1="75.186667064307" x2="45.192378864669" y2="155" />
<line x1="112.16371709404" y1="75.186667064307" x2="9.5576740963376" y2="252.90554669992" />
<line x1="112.16371709404" y1="75.186667064307" x2="9.5576740963376" y2="357.09445330008" />
<line x1="112.16371709404" y1="75.186667064307" x2="45.192378864668" y2="455" />
<line x1="112.16371709404" y1="75.186667064307" x2="112.16371709404" y2="534.81333293569" />
<line x1="112.16371709404" y1="75.186667064307" x2="202.3939570023" y2="586.90778623577" />
<line x1="112.16371709404" y1="75.186667064307" x2="305" y2="605" />
<line x1="45.192378864669" y1="155" x2="407.6060429977" y2="586.90778623577" />
<line x1="45.192378864669" y1="155" x2="497.83628290596" y2="534.81333293569" />
<line x1="45.192378864669" y1="155" x2="564.80762113533" y2="455" />
<line x1="45.192378864669" y1="155" x2="600.44232590366" y2="357.09445330008" />
<line x1="45.192378864669" y1="155" x2="600.44232590366" y2="252.90554669992" />
<line x1="45.192378864669" y1="155" x2="564.80762113533" y2="155" />
<line x1="45.192378864669" y1="155" x2="497.83628290596" y2="75.186667064307" />
<line x1="45.192378864669" y1="155" x2="407.6060429977" y2="23.092213764227" />
<line x1="45.192378864669" y1="155" x2="305" y2="5" />
<line x1="45.192378864669" y1="155" x2="202.3939570023" y2="23.092213764227" />
<line x1="45.192378864669" y1="155" x2="112.16371709404" y2="75.186667064307" />
<line x1="45.192378864669" y1="155" x2="45.192378864669" y2="155" />
<line x1="45.192378864669" y1="155" x2="9.5576740963376" y2="252.90554669992" />
<line x1="45.192378864669" y1="155" x2="9.5576740963376" y2="357.09445330008" />
<line x1="45.192378864669" y1="155" x2="45.192378864668" y2="455" />
<line x1="45.192378864669" y1="155" x2="112.16371709404" y2="534.81333293569" />
<line x1="45.192378864669" y1="155" x2="202.3939570023" y2="586.90778623577" />
<line x1="45.192378864669" y1="155" x2="305" y2="605" />
<line x1="9.5576740963376" y1="252.90554669992" x2="407.6060429977" y2="586.90778623577" />
<line x1="9.5576740963376" y1="252.90554669992" x2="497.83628290596" y2="534.81333293569" />
<line x1="9.5576740963376" y1="252.90554669992" x2="564.80762113533" y2="455" />
<line x1="9.5576740963376" y1="252.90554669992" x2="600.44232590366" y2="357.09445330008" />
<line x1="9.5576740963376" y1="252.90554669992" x2="600.44232590366" y2="252.90554669992" />
<line x1="9.5576740963376" y1="252.90554669992" x2="564.80762113533" y2="155" />
<line x1="9.5576740963376" y1="252.90554669992" x2="497.83628290596" y2="75.186667064307" />
<line x1="9.5576740963376" y1="252.90554669992" x2="407.6060429977" y2="23.092213764227" />
<line x1="9.5576740963376" y1="252.90554669992" x2="305" y2="5" />
<line x1="9.5576740963376" y1="252.90554669992" x2="202.3939570023" y2="23.092213764227" />
<line x1="9.5576740963376" y1="252.90554669992" x2="112.16371709404" y2="75.186667064307" />
<line x1="9.5576740963376" y1="252.90554669992" x2="45.192378864669" y2="155" />
<line x1="9.5576740963376" y1="252.90554669992" x2="9.5576740963376" y2="252.90554669992" />
<line x1="9.5576740963376" y1="252.90554669992" x2="9.5576740963376" y2="357.09445330008" />
<line x1="9.5576740963376" y1="252.90554669992" x2="45.192378864668" y2="455" />
<line x1="9.5576740963376" y1="252.90554669992" x2="112.16371709404" y2="534.81333293569" />
<line x1="9.5576740963376" y1="252.90554669992" x2="202.3939570023" y2="586.90778623577" />
<line x1="9.5576740963376" y1="252.90554669992" x2="305" y2="605" />
<line x1="9.5576740963376" y1="357.09445330008" x2="407.6060429977" y2="586.90778623577" />
<line x1="9.5576740963376" y1="357.09445330008" x2="497.83628290596" y2="534.81333293569" />
<line x1="9.5576740963376" y1="357.09445330008" x2="564.80762113533" y2="455" />
<line x1="9.5576740963376" y1="357.09445330008" x2="600.44232590366" y2="357.09445330008" />
<line x1="9.5576740963376" y1="357.09445330008" x2="600.44232590366" y2="252.90554669992" />
<line x1="9.5576740963376" y1="357.09445330008" x2="564.80762113533" y2="155" />
<line x1="9.5576740963376" y1="357.09445330008" x2="497.83628290596" y2="75.186667064307" />
<line x1="9.5576740963376" y1="357.09445330008" x2="407.6060429977" y2="23.092213764227" />
<line x1="9.5576740963376" y1="357.09445330008" x2="305" y2="5" />
<line x1="9.5576740963376" y1="357.09445330008" x2="202.3939570023" y2="23.092213764227" />
<line x1="9.5576740963376" y1="357.09445330008" x2="112.16371709404" y2="75.186667064307" />
<line x1="9.5576740963376" y1="357.09445330008" x2="45.192378864669" y2="155" />
<line x1="9.5576740963376" y1="357.09445330008" x2="9.5576740963376" y2="252.90554669992" />
<line x1="9.5576740963376" y1="357.09445330008" x2="9.5576740963376" y2="357.09445330008" />
<line x1="9.5576740963376" y1="357.09445330008" x2="45.192378864668" y2="455" />
<line x1="9.5576740963376" y1="357.09445330008" x2="112.16371709404" y2="534.81333293569" />
<line x1="9.5576740963376" y1="357.09445330008" x2="202.3939570023" y2="586.90778623577" />
<line x1="9.5576740963376" y1="357.09445330008" x2="305" y2="605" />
<line x1="45.192378864668" y1="455" x2="407.6060429977" y2="586.90778623577" />
<line x1="45.192378864668" y1="455" x2="497.83628290596" y2="534.81333293569" />
<line x1="45.192378864668" y1="455" x2="564.80762113533" y2="455" />
<line x1="45.192378864668" y1="455" x2="600.44232590366" y2="357.09445330008" />
<line x1="45.192378864668" y1="455" x2="600.44232590366" y2="252.90554669992" />
<line x1="45.192378864668" y1="455" x2="564.80762113533" y2="155" />
<line x1="45.192378864668" y1="455" x2="497.83628290596" y2="75.186667064307" />
<line x1="45.192378864668" y1="455" x2="407.6060429977" y2="23.092213764227" />
<line x1="45.192378864668" y1="455" x2="305" y2="5" />
<line x1="45.192378864668" y1="455" x2="202.3939570023" y2="23.092213764227" />
<line x1="45.192378864668" y1="455" x2="112.16371709404" y2="75.186667064307" />
<line x1="45.192378864668" y1="455" x2="45.192378864669" y2="155" />
<line x1="45.192378864668" y1="455" x2="9.5576740963376" y2="252.90554669992" />
<line x1="45.192378864668" y1="455" x2="9.5576740963376" y2="357.09445330008" />
<line x1="45.192378864668" y1="455" x2="45.192378864668" y2="455" />
<line x1="45.192378864668" y1="455" x2="112.16371709404" y2="534.81333293569" />
<line x1="45.192378864668" y1="455" x2="202.3939570023" y2="586.90778623577" />
<line x1="45.192378864668" y1="455" x2="305" y2="605" />
<line x1="112.16371709404" y1="534.81333293569" x2="407.6060429977" y2="586.90778623577" />
<line x1="112.16371709404" y1="534.81333293569" x2="497.83628290596" y2="534.81333293569" />
<line x1="112.16371709404" y1="534.81333293569" x2="564.80762113533" y2="455" />
<line x1="112.16371709404" y1="534.81333293569" x2="600.44232590366" y2="357.09445330008" />
<line x1="112.16371709404" y1="534.81333293569" x2="600.44232590366" y2="252.90554669992" />
<line x1="112.16371709404" y1="534.81333293569" x2="564.80762113533" y2="155" />
<line x1="112.16371709404" y1="534.81333293569" x2="497.83628290596" y2="75.186667064307" />
<line x1="112.16371709404" y1="534.81333293569" x2="407.6060429977" y2="23.092213764227" />
<line x1="112.16371709404" y1="534.81333293569" x2="305" y2="5" />
<line x1="112.16371709404" y1="534.81333293569" x2="202.3939570023" y2="23.092213764227" />
<line x1="112.16371709404" y1="534.81333293569" x2="112.16371709404" y2="75.186667064307" />
<line x1="112.16371709404" y1="534.81333293569" x2="45.192378864669" y2="155" />
<line x1="112.16371709404" y1="534.81333293569" x2="9.5576740963376" y2="252.90554669992" />
<line x1="112.16371709404" y1="534.81333293569" x2="9.5576740963376" y2="357.09445330008" />
<line x1="112.16371709404" y1="534.81333293569" x2="45.192378864668" y2="455" />
<line x1="112.16371709404" y1="534.81333293569" x2="112.16371709404" y2="534.81333293569" />
<line x1="112.16371709404" y1="534.81333293569" x2="202.3939570023" y2="586.90778623577" />
<line x1="112.16371709404" y1="534.81333293569" x2="305" y2="605" />
<line x1="202.3939570023" y1="586.90778623577" x2="407.6060429977" y2="586.90778623577" />
<line x1="202.3939570023" y1="586.90778623577" x2="497.83628290596" y2="534.81333293569" />
<line x1="202.3939570023" y1="586.90778623577" x2="564.80762113533" y2="455" />
<line x1="202.3939570023" y1="586.90778623577" x2="600.44232590366" y2="357.09445330008" />
<line x1="202.3939570023" y1="586.90778623577" x2="600.44232590366" y2="252.90554669992" />
<line x1="202.3939570023" y1="586.90778623577" x2="564.80762113533" y2="155" />
<line x1="202.3939570023" y1="586.90778623577" x2="497.83628290596" y2="75.186667064307" />
<line x1="202.3939570023" y1="586.90778623577" x2="407.6060429977" y2="23.092213764227" />
<line x1="202.3939570023" y1="586.90778623577" x2="305" y2="5" />
<line x1="202.3939570023" y1="586.90778623577" x2="202.3939570023" y2="23.092213764227" />
<line x1="202.3939570023" y1="586.90778623577" x2="112.16371709404" y2="75.186667064307" />
<line x1="202.3939570023" y1="586.90778623577" x2="45.192378864669" y2="155" />
<line x1="202.3939570023" y1="586.90778623577" x2="9.5576740963376" y2="252.90554669992" />
<line x1="202.3939570023" y1="586.90778623577" x2="9.5576740963376" y2="357.09445330008" />
<line x1="202.3939570023" y1="586.90778623577" x2="45.192378864668" y2="455" />
<line x1="202.3939570023" y1="586.90778623577" x2="112.16371709404" y2="534.81333293569" />
<line x1="202.3939570023" y1="586.90778623577" x2="202.3939570023" y2="586.90778623577" />
<line x1="202.3939570023" y1="586.90778623577" x2="305" y2="605" />
<line x1="305" y1="605" x2="407.6060429977" y2="586.90778623577" />
<line x1="305" y1="605" x2="497.83628290596" y2="534.81333293569" />
<line x1="305" y1="605" x2="564.80762113533" y2="455" />
<line x1="305" y1="605" x2="600.44232590366" y2="357.09445330008" />
<line x1="305" y1="605" x2="600.44232590366" y2="252.90554669992" />
<line x1="305" y1="605" x2="564.80762113533" y2="155" />
<line x1="305" y1="605" x2="497.83628290596" y2="75.186667064307" />
<line x1="305" y1="605" x2="407.6060429977" y2="23.092213764227" />
<line x1="305" y1="605" x2="305" y2="5" />
<line x1="305" y1="605" x2="202.3939570023" y2="23.092213764227" />
<line x1="305" y1="605" x2="112.16371709404" y2="75.186667064307" />
<line x1="305" y1="605" x2="45.192378864669" y2="155" />
<line x1="305" y1="605" x2="9.5576740963376" y2="252.90554669992" />
<line x1="305" y1="605" x2="9.5576740963376" y2="357.09445330008" />
<line x1="305" y1="605" x2="45.192378864668" y2="455" />
<line x1="305" y1="605" x2="112.16371709404" y2="534.81333293569" />
<line x1="305" y1="605" x2="202.3939570023" y2="586.90778623577" />
<line x1="305" y1="605" x2="305" y2="605" />
</svg>
```

# Answer
> 0 votes
# R, 108 bytes

```
plot(x<-cos(t<-seq(0,2*pi,l=21)),y<-sin(t),as=1);apply(expand.grid(1:21,1:21),1,function(e)lines(x[e],y[e]))

```

Could shave 5 bytes off if I got rid of argument `,as=1` which forces an aspect ratio of 1. Uses `expand.grid` to create a matrix with all possible pair of points, and uses `apply` to loop through it.

# R + igraph, 87 bytes

Another solution using package `igraph`.

```
library(igraph);plot(make_full_graph(21),layout=cbind(cos(t<-seq(0,2*pi,l=21)),sin(t)))

```

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


# Question
Title: Transform number into 7-segment display pattern
Given two arbitrary numbers A,B. Print number B as a Digital LED Pattern where A is the scale.

input:

```
1 2320451640799518

```

ouput:

```
 _  _  _  _     _     _     _  _  _  _  _     _
 _| _| _|| ||_||_   ||_ |_|| |  ||_||_||_   ||_|
|_  _||_ |_|  | _|  ||_|  ||_|  |  |  | _|  ||_|

```

input:

```
2 23

```

ouput:

```
 __  __
   |   |
 __| __|
|      |
|__  __|

```

**Rules:**

* Use **STDIN/STDOUT** for **input/output**
* Code with most up-votes wins. In case of Tie, shortest code will be accepted
* Most up voted Answer will be accepted at 01/02/2014 (Accepted this answer with highest 12 votes)

# Answer
# Commodore 64 BASIC

PETSCII art rules :)

Output:
> 20 votes

# Answer
# Python 3, ~~286 282~~ 280

Yeah I golfed this one. Nice challenge!

```
n,x=input().split()
n=int(n)
l=lambda s:"".join(s)+"\n"
h=lambda s:s.replace(*"! ")*~-n+s.replace(*"!_")
print(l(" "+"_ "[c in"14"]*n+" "for c in x)+h(l("| "[c in"1237"]+n*"! "[c in"017"]+"| "[c in"56"]for c in x))+h(l(" |"[c in"0268"]+n*"! "[c in"1479"]+"| "[c=="2"]for c in x)))

```

---

Also, here's a Python 2 version weighing in at only 273 bytes!

Not updating this one any more with further golfed original source. This was created when the original source was 282 bytes (Python 3 version).

```
exec'eJxdzE0OgjAQhuE9pxhn1VIlFhHUpCdRQlAx1NShAYwsOLzgD4irSd758tC8UWX6SDTZe824V1mju+uQ0lQz4o5RJr0dzylUO0TvWmhiFRd4IHTy8VV5ZWZNesqYizNA7jJaSC4mOUHu2LJjwTAEFJgA7k+gCWWAsUuii5eihD5Bw0XOul07bPxVhLGgl/9OS9mXcbIOMf4BPgK037kfbv4EGUTbgVAK/SnwBAs+TpU='.decode('base64').decode('zip')

```

This may be cheating, so I'm adding it separately. Let me know whether this is considered valid or not.
> 13 votes

# Answer
## Haskell (389 chars)

The solution uses 7 arrays, one for each segment of the array, using the names from this image:

. The value `a !! 4` will be the character that should be displayed at that a position for the number 4.

The values are multiplied by the scale where appropriate (using `r` and `rp` for replication), and finally printed out.

### The code

```
a="_ __ _____"
b="|||||  |||"
c="|| |||||||"
d="_ __ __ _ "
e="| |   | | "
f="|   ||| ||"
g="  _____ __"
r=replicate
cm=concatMap
s=(' ':).(++" ")
dd w n=[[t n],rp$m f b n,[o g f b n],rp$m e c n,[o d e c n]] where
 rp=r$w-1
 t=cm(s.r w.(a!!))
 q f s x y=cm(\n->x!!n:r w(f s n)++[y!!n])
 o=q(!!)
 m=q const ' '
go a=unlines$concat$dd(read$a!!0)$map(read.(:[]))$a!!1
main=interact$go.words

```

## Example usage

```
echo '1 2320451640799518' | runhaskell ./digit_led.hs
 _  _  _  _     _     _     _  _  _  _  _     _
 _| _| _|| ||_||_   ||_ |_|| |  ||_||_||_   ||_|
|_  _||_ |_|  | _|  ||_|  ||_|  |  |  | _|  ||_|

```
> 6 votes

# Answer
# C, 249 226 chars

Golfed solution in C:

```
int x,y,g,s,q;main(){char*c,i[99];for(scanf("%d %98s",&s,i);y<2*s+1;++y,puts(""))for(c=i;*c;++c)for(x=0;x<s+2;++x)q=(y+s-1)/s*3+(x+s-1)/s,g=(x%(s+1))*(y%s)?7:q<3?~q%2*7:q-2,putchar("_|_||_| "["zG<lMfvH~N"[*c-48]+1>>g&1?g:7]);}

```

With added whitespace:

```
int x, y, g, s, q;

main() {
  char *c, i[99];
  for (scanf("%d %98s", &s, i); y < 2 * s + 1; ++y, puts(""))
    for (c = i; *c; ++c)
      for (x = 0; x < s + 2; ++x)
        q = (y + s - 1) / s * 3 + (x + s - 1) / s,
        g = (x % (s + 1)) * (y % s)
          ? 7
          : q < 3
            ? ~q % 2 * 7
            : q - 2,
        putchar("_|_||_| "["zG<lMfvH~N"[*c - 48] + 1 >> g & 1 ? g : 7]);
}

```

Notes:

* At most 99 digits are printed
* Behavior is undefined if the input is not well formed (e.g. contains non-digits, or scale is \< 1)
* Should be legal C89 code

I will provide an explanation of how it works, should anyone care.
> 6 votes

# Answer
# Ruby 2.0

Quick and (not so) naive ruby implementation.

```
V,H = ' |',' _'
l = gets.split
s = l[0].to_i
o = Array.new 1+s*2, ''
l[1].each_char {|c|
  m = "{H=mNgwI\x7FO"[c.to_i].ord
  o[0] += " #{H[m[0]]*s} "
  o[s] += "#{V[m[1]]}#{H[m[2]]*s}#{V[m[3]]}"
  o[s*2] += "#{V[m[4]]}#{H[m[5]]*s}#{V[m[6]]}"
}
(s-1).times { |i|
  o[i+1] = o[s].gsub '_', ' '
  o[s+i+1] = o[s*2].gsub '_', ' '
}
o.each {|r| puts r}

```

Quick explanation:

I first declare the strings representing on and off digits for horizontal and vertical bars.
Then I read scale and the digits.
I then declare an array of the necessary size to store enough lines for the given scale. The weird string is actually a mapping of 7-bits values representing which LEDs to switch on for each digit.
Next, for each digit, I fill the output array from top to bottom, taking into account horizontal scaling.
The final loop is to fill the rows that only have vertical bars, which can just be generated from the middle and bottom rows by removing horizontal bars.
Finally, I print the output array !
> 5 votes

# Answer
Python 2.6 with no imports. I'd say that the attractiveness of this solution is the use of templates. Unfortunately I think that's why I had such a hard time compacting it.

```
def numbers(scale, number):

    def single(yay, wall, digit):
        walls = ('1110111', '0010010', '1011101', '1011011',
                 '0111010', '1101011', '1101111',
                 '1010010', '1111111',
                 '1111010')
        return yay if int(walls[digit][wall]) else ' '

    def expand_one(char, digit):
        characters = '_||_||_'
        translated = single(characters[char], char, digit)
        if char % 3:
            return translated
        return translated * scale

    def expand_template(template, digit):
        out = ''
        for c in template:
            if c == '.':
                out += ' ' * scale
            elif c == ' ':
                out += c
            else:
                out += expand_one(int(c), digit)
        return out

    def repeated_expand_template(template, n):
        print ''.join(expand_template(template, int(d)) for d in n)

    repeated_expand_template(' 0 ', number)
    for _ in range(scale - 1):
        repeated_expand_template('1.2', number)
    repeated_expand_template('132', number)
    for _ in range(scale - 1):
        repeated_expand_template('4.5', number)
    repeated_expand_template('465', number)

scale, number = raw_input().split()
numbers(int(scale), number)

```

And a bit shorter (308 characters):

```
s,n=raw_input().split();s=int(s)
for e in('0 0 ','11.2','0132','14.5','0465'):print '\n'.join(''.join(''.join(([' ','_||_||_'[int(c)]][int(bin(1098931065668123279354)[7*int(d)+int(c)+2])]*(s,1,1)[int(c)%3])if ord(c)>46 else c for c in e[1:].replace('.',' '*s))for d in n) for _ in range((1,s-1)[int(e[0])]))

```
> 5 votes

# Answer
(Edit: This solution is now invalid because the semantics of the  instruction has changed. I didn’t realise that I’d already made use of the instruction when I changed it. You can, however, fix ths program by simply changing it to the newer instruction .)

# ~~Sclipting — 85 characters~~

~~```
겠合글坼銻標⓷가殲갰復묽땸민뫝뜵깉걈밂⓶各가⓵겐上⓷감嚙긇밌⓶掘⓶감嚙눖밂⓶掘⓷合⓶감嚙긇밌⓶掘⓷合⓸⓸替❶終⓶丟終❶눠替눐終①貶復⓶⓷終丟併눐替글①復終눠替뇰①復終⓶丟

```

---

Input:
```
1 1024856359701

```
Output:
```
    _  _     _  _  _  _  _  _  _  _
  || | _||_||_||_ |_  _||_ |_|  || |  |
  ||_||_   ||_| _||_| _| _|  |  ||_|  |

```

---

Input:
```
2 47474747

```
Output:
```
     __      __      __      __
|  |   ||  |   ||  |   ||  |   |
|__|   ||__|   ||__|   ||__|   |
   |   |   |   |   |   |   |   |
   |   |   |   |   |   |   |   |

```~~
> 5 votes

# Answer
# C# (480 443 chars)

```
namespace System{using z=String;using w=Console;class P{static void Main(){var t=w.ReadLine().Split(' ');var s=int.Parse(t[0]);z b="17",d=b+23,e=b+3459,f="56",g=e+2680;Action<z,z,z,int>q=(l,m,r,n)=>{for(int i=1;i<n;i++){foreach(var c in t[1]){h(c,l);for(int j=0;j<s;j++)h(c,m,"_");h(c,r);}w.Write("\n");}};q(g,"14",g,2);q(d,g,f,s);q(d,b+0,f,2);q(e,g,"2",s);q(e,b+49,"2",2);}static void h(char x,z m,z y="|"){w.Write(m.Contains(""+x)?" ":y);}}}

```

Extended version:

```
using System;
using System.Linq;

namespace Segments
{
    internal class Program
    {
        static void Main()
        {
            var scale = int.Parse(Console.ReadLine());
            var input = Console.ReadLine();

            PrintLine(input, "", "14", "", 2);
            PrintLine(input,"1237", "", "56", scale);
            PrintLine(input,"1237", "170", "56", 2);
            PrintLine(input,"134579", "", "2", scale);
            PrintLine(input,"134579", "147", "2", 2);
        }

        static void PrintLine(string input, string leftMatch, string middleMatch, string rightMatch, int scale)
        {
            for (int i = 1; i < scale; i++)
            {
                foreach (var c in input)
                {
                    PrintDigitLine(c, leftMatch, '|', 1);
                    PrintDigitLine(c, middleMatch, "_", scale);
                    PrintDigitLine(c, rightMatch, '|', 1);
                }
                Console.Write("\n");
            }
        }

        private static void PrintDigitLine(char digit, string match, char charToPrint, int)
        {
            for (int i = 0; i < n; i++) Console.Write(match.Contains(digit) || match == "" ? ' ' : charToPrint);
        }
    }
}

```

My idea was to split the task up into 5 horizontal lines, which in turn are split up in a left, right and middle part for each character.
> 4 votes

# Answer
I guess there are very shorter solutions, but since this is not code-golf I'm quite satisfied!

This PHP script will take two numbers `a`, `b` from STDIN and echo `b` in LED format, at `a` size.

```
fscanf(STDIN, "%d %d", $a, $b); //Didn't test this line, but it should be ok.
$space=str_repeat(" ", $a);

$top = $topLeft = $topRight = $mid = $botLeft = $botRight = $bot = array();
for ($i=0; $i<count($b); $i++) {
    $top[$i] = $topLeft[$i] = $topRight[$i] = $mid[$i] = $botLeft[$i] = $botRight[$i] = $bot[$i] = true;
switch ($b[$i]) {
    case 0:
        $mid[$i] = false;
    break;
    case 1:
        $top[$i] = $topLeft[$i] = $mid[$i] = $botLeft[$i] = $bot[$i] = false;
        break;
    case 2:
        $topLeft[$i] = $botRight[$i] = false;
        break;
    case 3:
        $topLeft[$i] = $botLeft[$i] = false;
        break;
    case 4:
        $top[$i] = $botLeft[$i] = $bot[$i] = false;
        break;
    case 5:
        $topRight[$i] = $botLeft[$i] = false;
        break;
    case 6:
        $topRight[$i] = false;
        break;
    case 7:
        $topLeft[$i] = $mid[$i] = $botLeft[$i] = $bot[$i] = false;
        break;
    case 9:
        $botLeft[$i] = false;
        break;
    }
}

horizontal($top);
vertical($topLeft, $topRight);
horizontal($mid);
vertical($botLeft, $botRight);
horizontal($bot);

function horizontal($position) {
    global $a, $b, $space;
    for ($i=0;$i<count($b);$i++) {
        if ($position[$i])
            echo " ".str_repeat("-", $a)." ";
        else
            echo " ".$space." ";
    }
    echo "<br />";
}

function vertical($positionLeft, $positionRight) {
    global $a, $b, $space;
    for ($j=0;$j<$a;$j++) {
        for ($i=0;$i<count($b);$i++) {
            if ($positionLeft[$i]) {
                echo "|".$space;
                if ($positionRight[$i])
                    echo "|;";
                else
                    echo " ";
            }
            else {
                echo " ".$space;
                if ($positionRight[$i])
                    echo "|";
                else
                    echo " ";
            }
        }
        echo "<br />";
    }
}

```

**EDIT:** Looking at the previous output example, I wrongly supposed that space between digits should be as large as the `a` size. This has been fixed with the OP's declaration that no space is needed.
> 3 votes

# Answer
## C#, 435 359 473 bytes

**EDITS:**

* Removed redundant code. Reduced byte size of comparisons.
* Converted to a stand-alone application using standard in for input.

Here's the golfed code (with added line breaks and whitespace):

```
using C=System.Console;
class P{
    static void Main(){
        var a=C.ReadLine().Split(' ');
        D(int.Parse(a[0]),a[1]);
    }
    static void D(int r,string n){
        int i,j;
        string s="",v="|",w=" ",x=new string('_',r),y=new string(' ',r),z="\n";
        foreach(var c in n)s+=w+(F(0,c)?x:y)+w+w;
        for(j=1;j<6;j+=3)
            for(i=r;i-->0;){
                s+=z;
                foreach(var c in n)s+=(F(j,c)?v:w)+(i<1&&F(j+1,c)?x:y)+(F(j+2,c)?v:w)+w;
            }
        C.Write(s+z);
    }
    static bool F(int i,char c){
        return(new[]{1005,881,892,927,325,365,1019}[i]&1<<(int)c-48)>0;
    }
}

```
> 2 votes

# Answer
## C (~~561~~ 492 bytes)

Author is frmar. He sent me his answer last week (he has not yet created his account).

### 492 bytes but a bit more obfuscated:

```
#include<stdio.h>
#include<ctype.h>
#include<stdlib.h>
#define C(x) ((_[*n-'0'])>>s)&m&x
#define P putchar
unsigned _[]={476,144,372,436,184,428,492,148,508,188};
void p(int a,char*n,unsigned m,int s)
{for(;isdigit(*n);++n){P(C(1)?'|':' ');
for(int i=0;i<a;++i)P(C(4)?'_':' ');
P(C(2)?'|':' ');}
P('\n');}
void l(int a,char*b){p(a,b,7,0);int i=1;
for(;i<a;++i)p(a,b,3,3);p(a,b,7,3);i=1;
for(;i<a;++i)p(a,b,3,6);p(a,b,7,6);}
int main(int c,char**v){l(c>1?atoi(v[1]):1,c>2?v[2]:"0123456789");}

```

### Previous version using 561 bytes:

```
#include<stdio.h>
#include<ctype.h>
#define C(x) ((((*n-'0')[_])>>s)&m&x)
const unsigned _[]={476,144,372,436,184,428,492,148,508,188};
void p(int a,const char*n,unsigned m,int s)
{
 for(;isdigit(*n);++n) {
  putchar(C(1)?'|':' ');
  const char c=C(4)?'_':' ';
  for(int i=0;i<a;++i) putchar(c);
  putchar(C(2)?'|':' ');
 }
 putchar('\n');
}
void l(int a,const char*b)
{
 p(a,b,7,0);
 for(int i=1;i<a;++i)p(a,b,3,3);p(a,b,7,3);
 for(int i=1;i<a;++i)p(a,b,3,6);p(a,b,7,6);
}
#include<stdlib.h>
int main(int c,char**v){l(c>1?atoi(v[1]):1,c>2?v[2]:"0123456789");}

```

### Original version from frmar (623 bytes):

```
#include<stdio.h>
#include<ctype.h>
const unsigned int _[]={476,144,372,436,184,428,492,148,508,188};
void p(int a,const char*n,unsigned int m,int s)
{
  for(;isdigit(*n);++n) {
#define C(x) ((((*n-'0')[_])>>s)&m&x)
    putchar(C(1)?'|':' ');
    const char c=C(4)?'_':' ';
    for(int i=0;i<a;++i) putchar(c);
    putchar(C(2)?'|':' ');
  }
  putchar('\n');
}
void print_as_led(int a,const char*b)
{
  p(a,b,7,0);
  for(int i=1;i<a;++i)p(a,b,3,3);p(a,b,7,3);
  for(int i=1;i<a;++i)p(a,b,3,6);p(a,b,7,6);
}
#include<stdlib.h>
int main(int argc,char**argv){print_as_led(argc>1?atoi(argv[1]):1,argc>2?argv[2]:"0123456789");}

```

### Compilation:

```
$ gcc -std=c99 -Wall print_as_led.c

```

### Examples using default `0123456789` number but different sizes:

```
$ ./a.out
 _     _  _     _  _  _  _  _
| |  | _| _||_||_ |_   ||_||_|
|_|  ||_  _|  | _||_|  ||_|  |

$ ./a.out 2
 __      __  __      __  __  __  __  __
|  |   |   |   ||  ||   |      ||  ||  |
|  |   | __| __||__||__ |__    ||__||__|
|  |   ||      |   |   ||  |   ||  |   |
|__|   ||__  __|   | __||__|   ||__|   |

$ ./a.out 3
 ___       ___  ___       ___  ___  ___  ___  ___
|   |    |    |    ||   ||    |        ||   ||   |
|   |    |    |    ||   ||    |        ||   ||   |
|   |    | ___| ___||___||___ |___     ||___||___|
|   |    ||        |    |    ||   |    ||   |    |
|   |    ||        |    |    ||   |    ||   |    |
|___|    ||___  ___|    | ___||___|    ||___|    |

```

### Other examples:

```
$ ./a.out 1 42
    _
|_| _|
  ||_

$ ./a.out 2 42
     __
|  |   |
|__| __|
   ||
   ||__

$ ./a.out 3 42
      ___
|   |    |
|   |    |
|___| ___|
    ||
    ||
    ||___

```

### Larger sizes:

```
$ ./a.out 4 42
       ____
|    |     |
|    |     |
|    |     |
|____| ____|
     ||
     ||
     ||
     ||____
$ ./a.out 5 42
        _____
|     |      |
|     |      |
|     |      |
|     |      |
|_____| _____|
      ||
      ||
      ||
      ||
      ||_____

```
> 2 votes

# Answer
# Perl + FIGlet + BRA*: 54 characters

```
while(<>){($n,$x)=split;print(`figlet -f 7seg$n $x`);}

```

I figured this would be quite easy to do with FIGlet, but there didn't appear to be any suitable fonts for this purpose. So I made some :-)

Here's how it looks on the terminal:

```
$ perl ./led.pl
1 234
 _  _
 _| _||_|
|_  _|  |
2 345
 __      __
   ||  ||
 __||__||__
   |   |   |
 __|   | __|
3 456
      ___  ___
|   ||    |
|   ||    |
|___||___ |___
    |    ||   |
    |    ||   |
    | ___||___|

```

\*BRA: blatant rule abuse
> 1 votes

# Answer
# PERL,  261 244 187  166 chars

Little bit of bitwise encoding philosophy rulez :-)

```
($n,$a)=split/ /;sub c{$_=$a;y/0-9/Gl+%<UWm7=/;s/./(substr"   _ _|_| |_  |",2*ord($&)>>$_[0]&$_[1],3)=~s|.\K.|$&x$n|er/ge;print y/_/ /r x($n-1).$_}c 0,2;c 4,14;c 1,14

```

Code with whitespace added:

```
($n,$a)=split/ /;

sub c{
$_=$a;
y/0-9/Gl+%<UWm7=/;
s/./(substr"   _ _|_| |_  |",2*ord($&)>>$_[0]&$_[1],3)=~s|.\K.|$&x$n|er/ge;
print y/_/ /r x($n-1).$_
}

c 0,2;
c 4,14;
c 1,14

```

Perl has to be invoked with `-n`:

```
$ perl -n digitize.zoom.pl
1 12304597
     _   _   _       _   _   _
  |  _|  _| | | |_| |_  |_|   |
  | |_   _| |_|   |  _|   |   |
2 0784
 __   __   __
|  |    | |  | |  |
|  |    | |__| |__|
|  |    | |  |    |
|__|    | |__|    |
3 789
 ___   ___   ___
    | |   | |   |
    | |   | |   |
    | |___| |___|
    | |   |     |
    | |   |     |
    | |___|     |

```

Notes:

* Everything about how digits are displayed is encoded in the string `Gl+%<UWm7=` :-) One character corresponds to one digit, encoded are 3 positions of 3 consecutive characters within the `" _ _|_| |_ |"` string.
* Numbers are constructed in 3 lines, line by line. Each of the 3 lines corresponds to one call to sub-routine `c`, which also accomplishes vertical zooming for second and third line.
* Horizontal zooming is done at the end of sub-routine `c`.

---

My `sed` program cannot zoom, but it looks a lot nicer, doesn't it? :-)

```
s/./\0 /g
h
s/[14]/   /g
s/[2305-9]/ _ /g
p
g
s/[17]/  |/g
s/[23]/ _|/g
s/[489]/|_|/g
s/[56]/|_ /g
s/0/| |/g
p
g
s/[147]/  |/g
s/2/|_ /g
s/[359]/ _|/g
s/[680]/|_|/g

```

Pretty much the idea my PERL script uses, but in PERL it's a lot uglier. Note that for my sed program I prefered to use `9` which has the underscore in the last line, to be like reversed 6.
> 1 votes

# Answer
## C#, 386 382 364 chars / 374 bytes (UTF-8) and (lots? of) room for improvement...

```
using System.Linq;using C=System.Console;class P{static void Main(string[] args){var s=C.ReadLine();for(int l=0;l<5;l++){for(int j=0;j<s.Length;j++)C.Write(string.Join("",Enumerable.Range(0,3).Select(i=>{var x=l*3+i;return((x&1)>0?((((System.Text.Encoding.Unicode.GetBytes("⑷浝欮╻潿")[(byte)s[j]-48]>>x/2)&1)==1)?(x-1%3>0?"|":"-"):" "):" ");}))+" ");C.WriteLine();}}}

```

**EDIT** Crap... I missed the "scale" part

I'll give it another shot if I get around to it..
> 0 votes

# Answer
# J - 147 95 characters

Added required scaling:

```
1!:2&2,./(([1 s 0 s=:1 :(':';'y#"(2-m)~(m{$y)$1,x'))"2(3 :'(y{(5 3$&,0&,.)"1@#:l)}d')@"."0@":)/".]1!:1]1[l=:>:a.i.'v#\Z9jnQ~z'[d=:' ',:5 3$' - | |'

```

Annotated version:

```
NB. Digit array (2 x 5 x 3) first is blank, second is filled.
d=:' ',:5 3$' - | |'
NB. Bits to selector (taking into account that all "usefull" bits are separated with 0 bits, looking at the 5 x 3 grid)
bts =: 5 3 $&, (0&,.)
NB. list of character bits.
l=: 119 36 93 91 58 107 111 82 127 123
NB. golfing using ascii range
l=: >:a.i.'v#\Z9jnQ~z'

NB. scaling function
NB. scaling in 1 direction involves inserting copies of the middle segments:
NB. from y, copy the middle segments, 1 x 1 x 1 for rank 2 and 1 x 1 for rank 1
NB. Usage: scale (rank s) segment
s=: 1 : (':';'y#"(2-m)~(m{$y)$1,x')
NB. scale first along columns, then along rows, apply only to rank 2 (planes)
b=:([1 s 0 s)"2

NB. Get one number by using amend with a selection array (0 is blank, 1 is filled)
NB. get the y'th plane from the array of 10 x 5 x 3 selector bits, use those to index d with.
g=: 3 : '(y { (bts"1 #: l)) } d'
NB. from right to left: read stdin, convert number string to numbers,
NB. use the left for scaling, and split the right in digits,then apply g,
NB. then paste them together so the numbers appear next to each other.
NB. Put this result on stdout
1!:2&2,./(b g@"."0@":)/".]1!:1]

```

Example:

```
1 0123456789
 -     -  -     -  -  -  -  -
| ||    |  || ||  |    || || |
       -  -  -  -  -     -  -
| ||  |    |  |  || |  || |  |
 -     -  -     -  -     -  -

2 123
     --  --
|      |   |
|      |   |
     --  --
|   |      |
|   |      |
     --  --

```
> 0 votes

# Answer
# Ruby,126 ASCII characters

```
->n,x{(n*2).downto(0){|i|x.bytes{|c|z='u"ik:[]b}{'[c-48].ord+2>>i/n*3&7
print' |'[z/2%2],(z%2>i%n ??_:' ')*n,' |'[z/4]}
puts}}

```

Each digit is encoded as a bitmap in thirds thus, with each third represented by an octal digit.

```
|_| 8^2 (left and right never used! only the 1's bit used!)
|_| 8^1 (4*right+2*left+1*bottom)
|_| 8^0 (4*right+2*left+1*bottom)

```

As all digits have either the 64's bit or 32's bit set, the range is 044 octal to 177 octal. Unfortunately 177 is the nonprintable DEL character, so the magic string contains the numbers 2 below the required bitmap code, and we have to add 2 back on in the function.

**Ungolfed in test program**

```
f=->n,x{
  (n*2).downto(0){|i|                               #1 top line, n middle lines, n bottom lines
    x.bytes{|c|                                     #iterate through bytes
      z='u"ik:[]b}{'[c-48].ord+2>>i/n*3&7           #find octal code for current 1/3 digit
      print' |'[z/2%2],(z%2>i%n ??_:' ')*n,' |'[z/4]#print left,right and bottom
    }                                               #z%2>i%n only true on bottom row of 3rd where i%n=0 (print _'s) and octal code has 1's bit set
    puts                                            #print a newline to finish line
  }
}

n=gets.to_i  #size
x=gets.chop  #number taken in string form
f[n,x]

```

**Output**

```
C:\Users\steve>ruby 7seg.txt
4
0123456789
 ____        ____  ____        ____  ____  ____  ____  ____
|    |     |     |     ||    ||     |          ||    ||    |
|    |     |     |     ||    ||     |          ||    ||    |
|    |     |     |     ||    ||     |          ||    ||    |
|    |     | ____| ____||____||____ |____      ||____||____|
|    |     ||          |     |     ||    |     ||    |     |
|    |     ||          |     |     ||    |     ||    |     |
|    |     ||          |     |     ||    |     ||    |     |
|____|     ||____  ____|     | ____||____|     ||____| ____|

```
> 0 votes

# Answer
## Perl 6, ~~284~~ ~~241~~ 237

```
my (\a,\n)=split " ",slurp.trim;my @p=n.comb;sub g(\b,\c){for @p {my $h=:36(b);$h+>=3*$_;for ^3 {my \e=$_==1;print " |_".substr($h%2&&(c+!e)&&1+e,1)x a**e;$h+>=1}};say ""};for <52N98I 0 HMTVAD 1 AZRXEV 1> ->\s,\q{g(s,0)for 2..a*q;g(s,1)}

```

Previous solutions:

```
my (\a,\n)=slurp.trim.split: " ";my @p=n.comb;sub g(\b,\c){for @p {my $h=b;$h+>=3*$_;for ^3 {my \e=$_==1;print " |_".substr($h%2&&(c+!e)&&1+e,1)x a**e;$h+>=1}};say ""};for 306775170,0,1066270117,1,664751335,1 ->\s,\q{g(s,0)for 2..a*q;g(s,1)}
my (\a,\n)=slurp.trim.split: " ";my @p=n.comb;my &f={print $^b.substr(3*$_,1)~($^c??$b.substr(3*$_+1,1)!!" ")x a~$b.substr(3*$_+2,1)for @p;say ""};for (" _     _  _    "~" _ "x 5,0,"| |  | _| _||_||_ |_   ||_||_|",1,"|_|  ||_  _|  | _||_|  ||_|  |",1) ->\s,\q{f(s,0)for 2..a*q;f(s,1)}

```
> 0 votes

---
Tags: ascii-art, popularity-contest
---


title: Verify my lasagne

text:
# Question
Title: Verify my lasagne
## Scenario

I often cook lasagne, but I also have a few mistakes. Since I repeat these faults so often, I thought I maybe could do a program that checks if I did everything right.

## Valid lasagne

A valid lasagne is

* At least 5 columns wide
* At least 4 layers high
    + Excluding extra cheese
* The top layer is cheese (represented by `,`)
* The second layer is sauce (represented by either `@` or `#`)
* After that the layers alternate (1 layer sauce, 1 layer noodles (represented by either `~` or `-`))
* Each column can have either one or two layers of cheese

## The program

Should

* take a lasagne string as input
    + multiline string
    + string array
    + the string only contains the chars `,@#~-`
    + Rectangular
    + Padded with spaces if necessary
* Output whether it's a valid lasagne
    + Any thing that's thruthy in your language if valid
    + Nothing or anything that's falsy in your language
* be either
    + a full program
    + a function
    + that only uses functionality that was implemented before the 14.12.2016

## Test cases

```
,, ,
,,,,,,
@@@###
~~~~~-
@##@@#

--> truthy

@@@#
----
@@##
----
@###

--> falsy (cause of cheese and width (You don't have to print the stuff in the brackets))

,,,,,
-----
@####
-----
@@@@@

--> falsy (have the sauce as last layer)

```

## Winning criteria

The

submission wins.

# Answer
> 11 votes
## Retina, ~~38~~ 34 bytes

*Thanks to Grimy for saving 4 bytes.*

Have a regex with your lasagne.

Byte count assumes ISO 8859-1 encoding.

```
^([, ]+¶)?,{5,}(¶[@#]+¶[-~]*){2,}$

```

Assumes that the input ends with a trailing linefeed. Prints `1` (match) for valid lasagnes and `0` (no match) for invalid ones.

Try it online!

### Explanation

This is just a standard .NET regex matched against the input, except that Retina provides the alias  for linefeeds or `\n`.

Since the input is guaranteed to be rectangular, we only need to check the width of the lasagne on one of the rows.

```
^           # Anchor the regex to the beginning of the input.
([, ]+¶)?   # Match an optional first line of only commas an spaces.
,{5,}       # Match at least 5 commas.
(           # Match this at least twice to ensure at least two layers of sauce.
  ¶[@#]+    #   Match a line of sauce.
  ¶[-~]*    #   Match a line of pasta. This line may be empty (which would
            #   indicate the end of the input.
){2,}
$           # Make sure we've indeed reached the end. Note that `$` can
            # match either at the very end of the input, or in front of
            # the trailing linefeed.

```

# Answer
> 5 votes
## Grime, 43 bytes

```
e`[ \,]+/?/(\,/[#@]^/[\-~]/+/[#@]/?)+{5-,4-

```

Try it online! Prints `1` for match and `0` for no match.

## Explanation

Grime is designed for matching two-dimensional patterns, which are constructed piece by piece from smaller patterns. I define the optional top layer first, then the other layers by repeating a vertical stripe.

```
e`                                           Match entire input against pattern:
        /?                                   Optionally
  [ \,]+                                     a row of spaces and commas,
          /                                  below that
           (                       )         this pattern
                                    +        repeated horizontally
                                     {5-,4-  having size at least 5x4.
                                             The brace is closed implicitly.
                                             "This pattern" is a vertical stripe containing
            \,                               a comma,
              /                              below that
               [#@]^/[\-~]                   a sauce character on top of a noodle character
                                             (the ^/ is like / but with higher precedence)
                          /+                 repeated vertically,
                            /                below that
                                 /?          optionally
                             [#@]            a sauce character.

```

---
Tags: code-golf, ascii-art, decision-problem
---