Take the 2-minute tour ×
Programming Puzzles & Code Golf Stack Exchange is a question and answer site for programming puzzle enthusiasts and code golfers. It's 100% free, no registration required.

Golf a Venn Diagram generator

enter image description here

In order to properly celebrate John Venn's 180th birthday, today your task will be creating a program that outputs a Venn Diagram!

Input:

A positive integer N that will define the range of numbers appearing in the diagram (From zero to N) and three sets of positive integers.

Output:

A 3 set Venn diagram showing all integers from 0 to N and the relationships of the sets by displaying them in the proper regions of the diagram, similar to this one.

Notes

  1. Use stdin (or whatever your language's equivalent is) to get the values.
  2. You can define the input format for the sets and for N (Separated by comma, slash or whatever works best for you).
  3. Numbers that do not appear in any of the sets but are within the specified range must appear on the diagram, just not inside any region.
  4. The sets don't need to be named.
  5. The output can be a drawing or ascii-art.
  6. The diagram can have any shape as long as the boundaries are unambiguously distinguishable (if you chose ASCII art, using + (or similar) for crossing boundaries is essential, for example).
  7. The regions may but don't have to be shaded.
  8. Any built-in functions or third party libraries that generate Venn Diagrams are disallowed.
  9. Standard loopholes apply.

This is , so the shortest code, in bytes, wins.

share|improve this question
    
It looks like you should have added a note that solutions have to scale for arbitrary input sizes. Currently only a few of them do that (as far as I can tell only the ASCII ones). I don't like changing rules after the contest has started, but without this requirement, someone could probably really abuse it with a simple layout that only works for one character in each set (if I did that I'd probably cut the code size to a third or so). –  Martin Büttner Aug 5 at 9:24
    
@MartinBüttner Yeah, some of them scale pretty bad. But adding a note now that there are 7 answers seems like a bad idea. Should add the note and them comment on everyone's post to let them know that the diagram should scale well up to X? –  William Barbosa Aug 5 at 10:54
    
Setting a limit will still allow just hard-coding that limit. I think that proper scaling is actually the most difficult part of the challenge. So either leave it as it is, or change it to say that it must deal with arbitrary set sizes (which technically isn't even a change, since you didn't limit the input sizes I think arbirtrary input sizes should be assumed anyway). –  Martin Büttner Aug 5 at 10:58
    
@Ryan Note that I state "by displaying them in the proper regions of the diagram" in the output section. Some answers (yours included) don't display the innermost section correctly if said section has more than 5 elements, so I think it's invalid –  William Barbosa Aug 5 at 11:35

10 Answers 10

up vote 7 down vote accepted

Mathematica 343 264

UnGolfed

m=Input[]; data=Input[];


(* The circles to represent set boundaries *)
{R1,R2,R3}=Circle[#,5]&/@{{-2,8.5},{2,8.5},{0,5}};

(*converts  {1,0,1} to base 10, ie, the number 5.
bool[x_]:=FromDigits[Boole[x],2]

(* determines the region in which each number from 0 to `m` resides *)
encode[num_]:=bool[Table[MemberQ[data[[k]],num],{k,3}]]

(*Centroid of each region; the first is a location for numbers in none of the three sets *)
points={{7,4},{0,2},{4,10},{3,6},{-4,10},{-3,6},{0,11},{0,7}}

(* Plots the venn diagram with numbers in regions *)
Graphics[{
Text@@@({#[[1]],points[[#[[2]]+1]]}&/@({#[[All,1]],#[[1,2]]}&/@GatherBy[{#,encode[#]}&/@Range[0,m],Last])),
Opacity[.1],R1,R2,R3
}]

Assuming 10 was input for m and {{1,2,3,4,5,9},{1,2,3,6,8},{7,2,9}} was input for d,

new venn diagram


Golfed 264

I was surprised that all of the computation could be carried out within the Graphics function itself. With the exception of the inputs, it is a one-liner.

m=Input[];d=Input[]
Graphics@{Text@@@({#[[1]],{{7,4},{0,2},{4,10},{3,6},{-4,10},{-3,6},{0,11},{0,7}}[[#[[2]]+1]]}&/@({#[[All,1]],#[[1,2]]}&/@GatherBy[{#,FromDigits[Boole[Table[d[[k]]~MemberQ~#,{k,3}]],2]}&/@Range[0,m],Last])),Circle[#,5]&/@{{-2,8.5},{2,8.5},{0,5}}}
share|improve this answer
    
+1 for the appearance of the circles. I'm surprised they look so good in grey. The scattering of the numbers is weird though. You're using RandomSample to pick the location? –  steveverrill Aug 5 at 9:46
    
Gray works because the opacity is 10%. RandomSample was used to pick the location. Once a location has been chosen, it is removed from the set of candidates for additional picks. I played around with other methods (e.g. employing the centroid of a sub-region, but didn't like the results). BTW, I like your approach to fitting labels. –  David Carraher Aug 5 at 9:58
    
To save characters, I switched to Circles, so the gray disks are gone. Most of the savings comes from the fact that all members of a region are plotted at the center of that region. –  David Carraher Aug 5 at 22:46

Ruby, 654 590 566 542 505 bytes

This was fun. I used ASCII. I wasn't able to test every possible combination yet, so if you find a glitchy test case, please let me know.

require'set'
u=(0..gets.to_i).to_set
a,b,c=eval(gets).map &:to_set
i=' '
m,M,n,N,o,O,p,P,q,Q,r,R,s,S=[a-b-c,b-a-c,c-a-b,a&b-c,b&c-a,a&c-b,a&b&c].map{|u|[t=u.to_a*i,t.size]}.flatten
H,V,X=?─,?│,?┼
puts'┌'+H*(A=[1+M+[P,S].max,1+R].max)+?┐+(u-a-b-c).to_a*i,V+i*M+?┌+(b=H*(T=-M+U=A-1)+X+H*(B=[N,Q].max))+?┐,V+m+V+p+i*(T-P)+V+n+i*(B-N)+V,'│┌'+H*(K=M-1)+X+b+X+H*(C=[O-B-1,0].max)+?┐,(v=V*2+i*K)+V+s+i*(T-S)+V+q+i*(B-Q)+V+i*C+V,v+?└+b+?┘+i*C+V,V*2+r+i*(U-R)+V+o+i*(-O+D=B+C+1)+V,'└┼'+H*U+?┘+i*D+V,' └'+H*(A+D)+?┘

It expects the input on STDIN in the following format

10
[[1,2,3,4,5,9],[1,2,3,6,8],[7,2,9]]

And will then reward you with this beauty

┌───────┐0 10
│   ┌───┼───┐
│4 5│1 3│6 8│
│┌──┼───┼───┼┐
││  │2  │   ││
││  └───┼───┘│
││9     │7   │
└┼──────┘    │
 └───────────┘

I don't think I can be bothered to add an ungolfed version. Please have a look at the original version in the edit history for a somewhat more readable version.

This could certainly be golfed further by making the set boundaries less tight or even keeping them fixed like some of the graphical ones do, but I prefer that it looks nice and is done "properly" despite being golfed.

share|improve this answer
    
If you hadn't reach today's cap you'd reach the 10K club today with this answer, what a pity –  William Barbosa Aug 4 at 20:58
    
@WilliamBarbosa Maybe it'll give me the necessary upvotes tomorrow. ;) –  Martin Büttner Aug 4 at 20:58
    
That's a nice looking Venn diagram. I'm guessing the appearance of the diagram is the main reason for all you upvotes. What happens for larger sets? I'm guessing it stays the same height and just gets wider and wider? –  steveverrill Aug 4 at 23:03
    
@steveverrill yes exactly. each of the 8 subsets is just printed as a space delimited list in the right position. the boundaries are always the same shape, and each section's width is determined to be the minimum possible to fit everything inside. of course, it might look nicer if I computed line break to keep each subset roughly square, but then again this is code-golf after all ;). also it looks even better without the additional spacing between lines –  Martin Büttner Aug 4 at 23:10
1  
Saw the little angle characters and did a double-take, thinking it was APL or something. :) –  hoosierEE Aug 5 at 23:53

BBC BASIC, 243 ASCII characters (tokenised file size 211 bytes)

Download emulator at http://www.bbcbasic.co.uk/bbcwin/bbcwin.html

Golfed

  INPUT"N",n
  DIMs(n+1)
  FORi=0TO2PRINT"S";i
  REPEATINPUTx:s(x)=s(x)+2^i:UNTILx>n
  NEXTMODE4r=360CIRCLE460,r,r
  CIRCLE640,664,r
  CIRCLE820,r,r
  FORi=0TO7FORx=0TOn:IFs(x)=i PRINT;x
  NEXTREADa
  VDU28,a+1792;a+5;
  NEXT
  DATA19,4873,2572,4893,2586,5907,3091,34

BBC Basic is very arbitrary about which newlines/whitespace you can eliminate. Apart from stripping out unnecessary newlines there's another trick here that's not in the ungolfed version: I assign the viewport (see explanation below in ungolfed comments) at the END of the plotting loop, not at the beginning. This means that the elements outside the set are plotted the top left, and the cursor is trapped in a viewport at top right at the end of the program. The reason for this is to eliminate the VDU26.

Ungolfed

Each set of numbers is terminated by the user entering the number N+1 (a slightly unusual choice, this is to avoid errors caused by trying to write outside the range of an array.) Then it changes from a text mode to a graphics mode and plots the Venn diagram.

The input data is stored in an array, one cell for each value to be displayed. The data is stored as a 3-bit value: 1 for Set0 + 2 for Set1 + 4 for Set2 giving a number in the range 0 to 7. BBC basic has no shift operator, so the power operator is used instead: 2^i instead of 1<<i in C for example.

After plotting the circles, an outer loops goes through each of the eight regions, moving to the required coordinates (as per a data table.) An inner loop prints all the numbers in that region (those with the corresponding 3-bit value in the array.)

  INPUT"N",n                                 :REM create an array called s() with range 0..n+1
  DIMs(n+1)
  FORi=0TO2
    PRINT"S";i                               :REM prompt the user for data for set 0, set 1 and set 2.
    REPEATINPUTx:s(x)=s(x)+2^i:UNTILx>n      :REM input numbers and store as a bit table. Repeat until user enters n+1.
  NEXT
  MODE4                                      :REM change to graphics mode.
  r=360
  CIRCLE460,r,r                              :REM plot a circle at x,y,r.
  CIRCLE640,664,r                            :REM for the bottom two circles y=r.
  CIRCLE820,r,r
  FORi=0TO7                                  :REM for each region of the venn diagram
    READa                                    :REM read a 2 byte value for the  coordinates of the top left corner of a text viewport from the DATA statement: x+256y
    VDU28,a+1792;a+5;                        :REM create a 5x7 viewport (limits each region to 7 numbers.) 1792=7*256
    FORx=0TOn:IFs(x)=i PRINT;x               :REM print all numbers in the array belonging to that region
    NEXT
  NEXT
  VDU26                                      :REM Restore the viewport to the whole screen, to ensure the command prompt does not mess up the display at the end of the program.
  DATA34,19,4873,2572,4893,2586,5907,3091

Montage of typical input and output (ungolfed version)

In the golfed version, the position of the numbers outside the sets is exchanged with the command prompt >.

enter image description here

share|improve this answer
    
Does this work for arbitrarily large inputs? –  Martin Büttner Aug 4 at 22:35
    
@MartinBüttner in principle yes the algorithm can do it, but the display lets it down (as is likely to be the problem with other solutions.) I hint in the program comments that each region is limited to 7 numbers before it begins to scroll (the numbers are in a vertical column as I thought wrapping would look horrible.) The emulator I am using can handle much higher screen resolutions, but I have gone for one of the "authentic" BBC micro screen modes which is quite limiting. If someone ports this to Java, the only practical limit will be the human ability to read the diagram. –  steveverrill Aug 4 at 22:48
    
Ah yeah, I was just wondering whether the circles would adapt to the input size... of course my solution will also be unreadable for large inputs if your terminal wraps the lines, but as long as it's displayed with scrollbars it can handle any input size. –  Martin Büttner Aug 4 at 22:53
2  
even if this was ported to java you'd have to add code to make the circles bigger for more text –  Sparr Aug 5 at 1:05

Javascript 1235

http://jsfiddle.net/44a4L/7/

Tested in google chrome v36.

Input is taken in the variables upper, set1, set2 and set3.

Update: Now automatically scales depending on the size of input.

function t(e,t){z.getElementById(e).innerHTML+=" "+t}z=document;s=200+upper*20;z.body.innerHTML+="<style>#m{width:"+s+"px;height:"+s+"px;}div{position:absolute;text-align:center;border-radius:50%;}#s1{left:calc(15% + 15px);top:30px;bottom:30%;right:calc(15% + 15px);background-color:rgba(255,0,0,0.4);padding:10%;}#s2{left:30px;bottom:30px;top:30%;right:30%;background-color:rgba(0,255,0,0.4);padding-right:40%;padding-top:30%;}#s3{right:30px;bottom:30px;top:30%;left:30%;background-color:rgba(0,0,255,0.4);padding-left:40%;padding-top:30%;}#s123{left:40%;top:40%;right:40%;bottom:40%;}#s12{left:20%;top:35%;right:65%;bottom:50%;}#s13{right:20%;top:35%;left:65%;bottom:50%;}#s23{left:40%;right:40%;bottom:15%;top:70%;}</style><div id=m><div id=s1 class=s></div><div id=s2 class=s></div><div id=s3 class=s></div><div id=s123 class=v></div><div id=s12 class=v></div><div id=s13 class=v></div><div id=s23 class=v></div></div>";for(i=0;i<=upper;i++){i1=i2=i3=false;if(set1.indexOf(i)!=-1)i1=true;if(set2.indexOf(i)!=-1)i2=true;if(set3.indexOf(i)!=-1)i3=true;if(i1&&i2&&i3)t("s123",i);else if(i1&&i2)t("s12",i);else if(i1&&i3)t("s13",i);else if(i2&&i3)t("s23",i);else if(i1)t("s1",i);else if(i2)t("s2",i);else if(i3)t("s3",i);else t("m",i)}

Sample output:

Venn

share|improve this answer
    
Pretty nice! I was able to squeeze it a bit tighter, see jsfiddle.net/44a4L/2 - look at the "t" function, CSS and body.innerHTML. Same logic though. I'm sure it could still be squeezed. –  Nenotlep Aug 5 at 5:35
    
This is the most beautiful one so far, it's a pity it doesn't scale well. Three elements inside the innermost area makes it break. Do you plan on making it scale somehow? –  William Barbosa Aug 5 at 11:08
    
@WilliamBarbosa scaling is implemented now –  Ryan Aug 5 at 21:40
2  
Gorgeous! Stunning! Spectacular! (Had to use more than one superlative because SE hates brevity.) –  Scott Leadley Aug 6 at 15:13

Python - 603

import re
n,a,b,c=eval(input())
h=set(range(n+1))-a-b-c
g=a&b&c
d,e,f=a&b-g,b&c-g,a&c-g
l,m=set(a),set(b)
a-=b|c
b-=l|c
c-=l|m
for t in'abcdefgh':exec("%s=' '.join(map(str,%s))"%(2*(t,)))
l=len
x,y,z=max(l(a),l(f)+2,3),l(max(d,g)),max(l(b),l(e)+2,l(c)-l(f+g)-2,3)
j=[0]*4
for t in'abcdefg':exec("%s=%s.ljust([x,z,x+y+z-2,y,z-2,x-2,y][ord('%s')-97])+'|'"%(3*(t,)))
s='\d| '
w=re.sub
for r in (1,3):q=r//2;j[r]=['','| '][q]+'|'+[a+d+b,f+g+e][q]+['',' |'][q];j[r-1]=w('\|','+',w(s,'-',j[r]))
j[0]+=h
o=j[2]
j[2]='| +'+j[2][3:-3]+'+ |'
p='  |'+c
q='  '+w('\|','+',w(s,'-',p))[2:]
for l in j+[o,p,q]:print(l)

Input is N followed by the three sets, seperated by commas (e.g. 8, {1,2,4}, {2,3,4,5}, {4,6,8}). It outputs a set in ACSII art like the following:

+---+-+---+0 7
|1  | |3 5|
| +-+-+-+ |
| |2|4| | |
+-+-+-+-+-+
  |6 8  |
  +-----+
share|improve this answer
    
Haha, two nearly identical solutions within 5 minutes. (3 hours after the challenge was posted...) –  Martin Büttner Aug 4 at 20:30
1  
Please refer to note number 6. Your edges and crossing boundaries need to be a different character, such as "+". –  William Barbosa Aug 4 at 20:36

HTML + JavaScript (E6) 752 761

Input format: max set1 set2 set3 (each set is a comma separated list of numbers)

Example: 10 1,2,3,4,5,9 1,2,3,6,8 7,2,9

Screenshot

Example 2: 30 2,4,6,8,10,12,14,16,18,30 3,6,9,12,15,18,21,30 5,10,15,20,25,30

Chrome Screenshot

All the sections auto size thanks to html rendering.

<html><body><script>
i=prompt().split(' ');
r=",,,,,,,, class=',></i>".split(c=',')
for (j=-1;j++<i[0];r[h]+=j+' ')for(h=k=0;++k<4;)if((c+i[k]+c).search(c+j+c)+1)h+=k+(k>2);
document.write(
"<style>div{1row}p{position:relative;text-align:center;padding:7;1cell}i{position:absolute;top:0;3:0;4:0;left:0}.a{2top-left5b{2top-45c{23-left5d{23-45x{6880,9.y{680,89.z{60,889</style>"
.replace(/\d/g,x=>'09display:table-9border-9bottom9right9-radius:60px}.9background:rgba(930px9255,9.3)}'.split(9)[x])
+"<div><p8x a'/><p8x'>1</p><p><i8y a'9<i8x b'93</p><p8y'>2</p><p8y b'/></div><div><p8x c'/><p8z a'><i8x'95</p><p8z'><i8x d'9<i8y c'97</p><p8z b'><i8y'96</p><p8y d'/></div><div><p/><p8z c'/><p8z'>4</p><p8z d'/></div>0"
.replace(/\d/g,x=>r[x]))
</script></body></html>

Javascript E5 version Works in Chrome and MSIE 10 (maybe 9)

<html><body><script>
i=prompt().split(' ');
r=",,,,,,,, class=',></i>".split(c=',')
for (j=-1;j++<i[0];r[h]+=j+' ')for(h=k=0;++k<4;)if((c+i[k]+c).search(c+j+c)+1)h+=k+(k>2);
document.write(
"<style>div{1row}p{position:relative;text-align:center;padding:7;1cell}i{position:absolute;top:0;3:0;4:0;left:0}.a{2top-left5b{2top-45c{23-left5d{23-45x{6880,9.y{680,89.z{60,889</style>"
.replace(/\d/g,function(x){return '09display:table-9border-9bottom9right9-radius:60px}.9background:rgba(930px9255,9.3)}'.split(9)[x]})
+"<div><p8x a'/><p8x'>1</p><p><i8y a'9<i8x b'93</p><p8y'>2</p><p8y b'/></div><div><p8x c'/><p8z a'><i8x'95</p><p8z'><i8x d'9<i8y c'97</p><p8z b'><i8y'96</p><p8y d'/></div><div><p/><p8z c'/><p8z'>4</p><p8z d'/></div>0"
.replace(/\d/g,function(x){return r[x]}))
</script></body></html>

Not (so) golfed

<html>
<style>
div {   display:table-row; }
p {
    position: relative;
    text-align: center;
    padding: 30px;
    display: table-cell;
}
i {
    position: absolute;
    top:0;bottom:0;right:0;left:0;
}
.a { border-top-left-radius: 60px; }
.b { border-top-right-radius: 60px; }
.c { border-bottom-left-radius: 60px; }
.d { border-bottom-right-radius: 60px; }
.x { background: rgba(255,255,0,.3) }
.y { background: rgba(255,0,255,.3) }
.z { background: rgba(0,255,255,.3) }
</style>
<body>
<div>
<p class='x a'/><p class='x'><b id='b1'></b></p><p><i class='y a'></i><i class='x b'></i><b id='b3'></b></p><p class='y'><b id='b2'></b></p><p class='y b'/>
</div>    
<div>
<p class='x c'/><p class='z a'><i class='x'></i><b id='b5'></b></p><p class='z'><i class='x d'></i><i class='y c'></i><b id='b7'></b></p><p class='z b'><i class='y'></i><b id='b6'></b></p><p class='y d'/>
</div>        
<div>
<p/><p class='z c'/><p class='z'><b id='b4'></b></p><p class='z d'/>
</div>    
<b id='b0'></b>    
<script>
i=prompt().split(' ')
r=',,,,,,,'.split(c=',')
for (j=-1; j++<i[0];)
{
    for(h = k = 0; ++k < 4;)
    {
    if( (c+i[k]+c).search(c+j+c) >= 0)
      h += k + (k>2); // bit mask 1 or 2 or 4
  }
  r[h] += j + ' ';
}        
for (j = 0; j < 8; j++)
    document.getElementById('b'+j).innerHTML=r[j]
</script>
</html>
share|improve this answer

Python 3 - 353

# 353 bytes, input format like: 6 1,2,3 2,3,4 1,3,4
import sys
from turtle import*
_,n,*q=sys.argv
n=set(range(int(n)))
a,b,c=map(set,map(eval,q))
for x,y in(0,0),(-115,-185),(115,-185):goto(x,y),pd(),circle(200),up()
for x,y,s in(200,331,n-a-b-c),(-101,278,a-b-c),(-254,-49,b-a-c),(95,-49,c-a-b),(-172,164,a&b-c),(58,164,a&c-b),(-49,-39,b&c-a),(-49,52,a&b&c):goto(x,y),write(s or'',font=None)
ht()
done()

Did anybody else play with Logo as a kid?

Sample: python3 turtletest.py 15 1,2,3,4,5,9,10,12 1,3,4,6,7,9 1,2,7,8,9

enter image description here

share|improve this answer
    
will the font/circles scale for arbitrarily large input? –  Sparr Aug 5 at 5:37
    
No, still thinking about that one. –  Jason S Aug 5 at 5:39

perl 388b 346b 488b

This has output similar to another entry:

@a=split($",<>);
$n=pop @a;
@a=map[split(',')],@a;
for$i(0..2){$b{$_}+=1<<$i foreach@{$a[$i]}}
push@{$c[$b{$_}]},$_ for(0..$n);
$l|=length($d[$_]=join($",@{$c[$_]}))for(0..$n);
print$h=(("+-"."-"x$l)x3)."+
";
sub j{sprintf"% ".(sprintf"%ds",$l+($_[0]<4)+($_[0]==7)),$d[$_[0]]}
sub r{join('|',map{j($_)}@_)}
$h=~s/\+-/|+/;
$h=~s/-\+$/+|/;
print "|".r(1,3,2)."|
".$h;
$h=~s/[|+]{2}/++/g;
print "||".r(5,7,6)."||
".$h;
$h=~s/\+\+/ +/;
$h=~s/\+\+/+ /;
$h=~s/-\+-/---/g;
$l=$l*3+3;print " |".j(4)."|
",$h,$d[0]

Test run and output:

# echo "1,2,3,7,13 2,3,8,11,13,6,9 3,4,5,11,12,13,14 15" | perl venn.pl ;echo
+----------------+----------------+----------------+
|             1 7|               2|           6 8 9|
|+---------------+----------------+---------------+|
||               |            3 13|             11||
++---------------+----------------+---------------++
 |                                       4 5 12 14|
 +------------------------------------------------+ 
share|improve this answer
    
Hm, I'm not sure the layout is really unambiguous if you haven't seen the input. –  Martin Büttner Aug 5 at 9:22
    
You're right, this isn't venn-y enough –  William Barbosa Aug 5 at 11:09
    
@WilliamBarbosa ok, I made it look like faubiguy's entry –  Sparr Aug 5 at 13:50

T-SQL 2095

Assumes @N is an int containing N. Assumes @A, @B, and @C are tables containing the three sets of numbers. Didn't try to golf it too much.

DECLARE @D INT=@N,@E INT=0,@F CHAR='/',@G CHAR='\',@H CHAR='-',@I CHAR='|',@J CHAR='+'DECLARE @ TABLE(Z INT,Y INT,X INT,W INT,V INT,U INT,T INT,S INT)INSERT INTO @(Z)SELECT A.P FROM @A A JOIN @B B ON A.P=B.P JOIN @C C ON A.P=C.P INSERT INTO @(Y)SELECT A.P FROM @A A JOIN @B B ON A.P=B.P LEFT JOIN @C C ON A.P=C.P WHERE C.P IS NULL INSERT INTO @(X)SELECT C.P FROM @C C JOIN @A A ON C.P=A.P LEFT JOIN @B B ON C.P=B.P WHERE B.P IS NULL INSERT INTO @(W)SELECT B.P FROM @B B JOIN @C C ON B.P=C.P LEFT JOIN @A A ON B.P=A.P WHERE A.P IS NULL INSERT INTO @(V)SELECT A.P FROM @A A LEFT JOIN @B B ON A.P=B.P LEFT JOIN @C C ON A.P=C.P WHERE C.P IS NULL AND B.P IS NULL INSERT INTO @(U)SELECT C.P FROM @C C LEFT JOIN @A A ON C.P=A.P LEFT JOIN @B B ON C.P=B.P WHERE B.P IS NULL AND A.P IS NULL INSERT INTO @(T)SELECT B.P FROM @B B LEFT JOIN @C C ON B.P=C.P LEFT JOIN @A A ON B.P=A.P WHERE A.P IS NULL AND C.P IS NULL WHILE @N>=0BEGIN INSERT INTO @(S)SELECT @N WHERE @N NOT IN(SELECT*FROM @A UNION SELECT*FROM @B UNION SELECT*FROM @C)SET @N-=1 END DECLARE @Z TABLE(A CHAR(5),B CHAR(5),C CHAR(5),D CHAR(5),E CHAR(5),F CHAR(5),G CHAR(5),H CHAR(5))INSERT INTO @Z SELECT @F,@H,@F,@H,@G,@H,@G,''WHILE @E<=@D BEGIN INSERT INTO @Z SELECT @I,ISNULL((SELECT CONVERT(CHAR,@E,5) WHERE @E IN(SELECT V FROM @)),''),@I,ISNULL((SELECT CONVERT(CHAR,@E,5) WHERE @E IN(SELECT X FROM @)),''),@I,ISNULL((SELECT CONVERT(CHAR,@E,5) WHERE @E IN(SELECT U FROM @)),''),@I,ISNULL((SELECT CONVERT(CHAR,@E,5) WHERE @E IN(SELECT S FROM @)),'')SET @E+=1 END INSERT INTO @Z SELECT @F,@H,@J,@H,@G,'',@I,''SET @E=0WHILE @E<=@D BEGIN INSERT INTO @Z SELECT @I,ISNULL((SELECT CONVERT(CHAR,@E,5) WHERE @E IN(SELECT Y FROM @)),''),@I,ISNULL((SELECT CONVERT(CHAR,@E,5) WHERE @E IN(SELECT Z FROM @)),''),@I,'',@I,''SET @E+=1 END INSERT INTO @Z SELECT @G,@H,@J,@H,@F,'',@I,''SET @E=0WHILE @E<=@D BEGIN INSERT INTO @Z SELECT @I,ISNULL((SELECT CONVERT(CHAR,@E,5) WHERE @E IN(SELECT T FROM @)),''),@I,ISNULL((SELECT CONVERT(CHAR,@E,5) WHERE @E IN(SELECT W FROM @)),''),@I,'',@I,''SET @E+=1 END INSERT INTO @Z SELECT @G,@H,@G,@H,@F,@H,@F,''SELECT*FROM @Z

Less golfed version:

--finding the sets
DECLARE @D INT=@N,@E INT=0,@F CHAR='/',@G CHAR='\',@H CHAR='-',@I CHAR='|',@J CHAR='+'
DECLARE @ TABLE(Z INT,Y INT,X INT,W INT,V INT,U INT,T INT,S INT)
INSERT INTO @(Z)
SELECT A.P FROM @A A JOIN @B B ON A.P=B.P JOIN @C C ON A.P=C.P 
INSERT INTO @(Y)
SELECT A.P FROM @A A JOIN @B B ON A.P=B.P LEFT JOIN @C C ON A.P=C.P WHERE C.P IS NULL 
INSERT INTO @(X)
SELECT C.P FROM @C C JOIN @A A ON C.P=A.P LEFT JOIN @B B ON C.P=B.P WHERE B.P IS NULL 
INSERT INTO @(W)
SELECT B.P FROM @B B JOIN @C C ON B.P=C.P LEFT JOIN @A A ON B.P=A.P WHERE A.P IS NULL 
INSERT INTO @(V)
SELECT A.P FROM @A A LEFT JOIN @B B ON A.P=B.P LEFT JOIN @C C ON A.P=C.P WHERE C.P IS NULL AND B.P IS NULL 
INSERT INTO @(U)
SELECT C.P FROM @C C LEFT JOIN @A A ON C.P=A.P LEFT JOIN @B B ON C.P=B.P WHERE B.P IS NULL AND A.P IS NULL 
INSERT INTO @(T)
SELECT B.P FROM @B B LEFT JOIN @C C ON B.P=C.P LEFT JOIN @A A ON B.P=A.P WHERE A.P IS NULL AND C.P IS NULL 
WHILE @N>=0
BEGIN 
    INSERT INTO @(S)
    SELECT @N WHERE @N NOT IN(SELECT*FROM @A UNION SELECT*FROM @B UNION SELECT*FROM @C)
    SET @N-=1 
END

--displaying the venn diagram
DECLARE @Z TABLE(A CHAR(5),B CHAR(5),C CHAR(5),D CHAR(5),E CHAR(5),F CHAR(5),G CHAR(5),H CHAR(5))
INSERT INTO @Z 
SELECT @F,@H,@F,@H,@G,@H,@G,''
WHILE @E<=@D 
BEGIN 
    INSERT INTO @Z 
    SELECT @I,ISNULL((SELECT CONVERT(CHAR,@E,5) WHERE @E IN(SELECT V FROM @)),''),@I,ISNULL((SELECT CONVERT(CHAR,@E,5) WHERE @E IN(SELECT X FROM @)),''),@I,ISNULL((SELECT CONVERT(CHAR,@E,5) WHERE @E IN(SELECT U FROM @)),''),@I,ISNULL((SELECT CONVERT(CHAR,@E,5) WHERE @E IN(SELECT S FROM @)),'')
    SET @E+=1 
END 
INSERT INTO @Z 
SELECT @F,@H,@J,@H,@G,'',@I,''
SET @E=0
WHILE @E<=@D 
BEGIN 
    INSERT INTO @Z 
    SELECT @I,ISNULL((SELECT CONVERT(CHAR,@E,5) WHERE @E IN(SELECT Y FROM @)),''),@I,ISNULL((SELECT CONVERT(CHAR,@E,5) WHERE @E IN(SELECT Z FROM @)),''),@I,'',@I,''
    SET @E+=1 
END 
INSERT INTO @Z 
SELECT @G,@H,@J,@H,@F,'',@I,''
SET @E=0
WHILE @E<=@D 
BEGIN 
    INSERT INTO @Z 
    SELECT @I,ISNULL((SELECT CONVERT(CHAR,@E,5) WHERE @E IN(SELECT T FROM @)),''),@I,ISNULL((SELECT CONVERT(CHAR,@E,5) WHERE @E IN(SELECT W FROM @)),''),@I,'',@I,''
    SET @E+=1 
END 
INSERT INTO @Z 
SELECT @G,@H,@G,@H,@F,@H,@F,''
SELECT*FROM @Z
share|improve this answer

C++

enter image description here

I wrote my own PPM drawing library in c++, then did a small program to do the number sorting. If you go much beyond 30 numbers it will start to overlap. Had to link to my PPMDraw files because when I put the code in the answer box I was told I was about twice over the 30,000 character limit.

EDIT: This new version takes the N and three sets from the user correctly. For debugging I kept using the divisible by 2, 3, and 5 sets. But I also added scalability, so the image will automatically change size to accommodate larger sets.

Have added a "golfed" version of my graphics library. As you can see, even this minimal version is big.

PPMDraw Files

Highest score wins right?

main.cpp

#include "PPMDraw.h"
#include <iostream>
#include <sstream>
#include <cmath>
#include <set>
#include <algorithm>

//GLOBAL VARIABLES BECAUSE REASONS
std::set<int> input_a = std::set<int>();
std::set<int> input_b = std::set<int>();
std::set<int> input_c = std::set<int>();

std::set<int> A    = std::set<int>();
std::set<int> B    = std::set<int>();
std::set<int> C    = std::set<int>();
std::set<int> AB   = std::set<int>();
std::set<int> AC   = std::set<int>();
std::set<int> BC   = std::set<int>();
std::set<int> ABC  = std::set<int>();
std::set<int> NONE = std::set<int>();

std::string A_STRING;
std::string B_STRING;
std::string C_STRING;
std::string AB_STRING;
std::string AC_STRING;
std::string BC_STRING;
std::string ABC_STRING;
std::string NONE_STRING;


// create a string for printing to image
std::string set_to_string(std::set<int> s){
    std::string return_me;
    for(std::set<int>::iterator it = s.begin(); it != s.end(); it++){
        return_me += std::to_string(*it) + " ";
    }
    return return_me;
}

// calculate size of text boxes, which sets scale of whole diagram
int get_box_width(){
    int widths[8];
    widths[0] = sqrt(   A_STRING.size()) * 8;
    widths[1] = sqrt(   B_STRING.size()) * 8;
    widths[2] = sqrt(   C_STRING.size()) * 8;
    widths[3] = sqrt(  AB_STRING.size()) * 8;
    widths[4] = sqrt(  AC_STRING.size()) * 8;
    widths[5] = sqrt(  BC_STRING.size()) * 8;
    widths[6] = sqrt( ABC_STRING.size()) * 8;
    widths[7] = sqrt(NONE_STRING.size()) * 8;
    int max_value = widths[0];
    for(int i = 1; i < 8; i++){
        if(widths[i] > max_value){
            max_value = widths[i];
        }
    }
    return max_value;
}

// remove any items from set a that appear in set b
void filter_set(std::set<int> & set_a, std::set<int> & set_b){
    std::set<int>::iterator a_value;
    for(std::set<int>::iterator it = set_b.begin(); it != set_b.end(); it++){
        a_value = std::find(set_a.begin(), set_a.end(), *it);
        if(a_value != set_a.end()){
            set_a.erase(a_value);
        }
    }
}

// generate the set of items that aren't in A, B, or C
void generate_NONE_set(int N){
    for(int i = 1; i <= N; i++){
        NONE.insert(i);
    }
    filter_set(NONE, input_a);
    filter_set(NONE, input_b);
    filter_set(NONE, input_c);
}

// print contents of a set for debugging
void print_set(std::set<int> s){
    for(std::set<int>::iterator it = s.begin(); it != s.end(); it++){
        std::cout << *it << " ";
    }
  std::cout << std::endl;
}

// draw the venn diagram to venn.ppm
void draw_image(int box_width){
    // radius of the three circles
    int rad = 2*box_width;
    int image_height = 3.0*rad;
    int image_width = 4.0*rad;
    int center_x = 0.125*box_width + image_height / 2;
    int center_y = image_height / 2;
    // determine where to put the centers of the 3 circles
    int A_center_x = center_x + cos(1.57)*0.433*rad;
    int A_center_y = center_y - sin(1.57)*0.433*rad;
    int B_center_x = A_center_x - cos(1.047)*1.00*rad;
    int B_center_y = A_center_y + sin(1.047)*1.00*rad;
    int C_center_x = A_center_x + cos(1.047)*1.00*rad;
    int C_center_y = A_center_y + sin(1.047)*1.00*rad;
    // determine positions of boxes to hold text
    int ABC_box_origin_x = center_x - cos(0.72)*0.33*rad;
    int ABC_box_origin_y = center_y - sin(0.72)*0.33*rad;
    int AB_box_origin_x = center_x - cos(0.436)*rad;
    int AB_box_origin_y = center_y - sin(0.436)*rad;
    int AC_box_origin_x = center_x + cos(0.846)*0.60*rad;
    int AC_box_origin_y = center_y - sin(0.846)*0.60*rad;
    int BC_box_origin_x = center_x - cos(1.176)*0.65*rad;
    int BC_box_origin_y = center_y + sin(1.176)*0.65*rad;
    int A_box_origin_x = center_x - cos(1.382)*1.33*rad;
    int A_box_origin_y = center_y - sin(1.382)*1.33*rad;
    int B_box_origin_x = center_x - cos(0.148)*1.42*rad;
    int B_box_origin_y = center_y + sin(0.148)*1.42*rad;
    int C_box_origin_x = center_x + cos(0.228)*0.88*rad;
    int C_box_origin_y = center_y + sin(0.228)*0.88*rad;
    int NONE_box_origin_x = center_x + cos(0.682)*2.14*rad;
    int NONE_box_origin_y = center_y - sin(0.682)*2.14*rad;

    PPMDraw image = PPMDraw(image_width, image_height);
    image.fill(0, 0, 0);
    //draw the circles
    image.set_color(255, 0, 0);
    image.draw_circle(A_center_x, A_center_y, rad);
    image.set_color(0, 255, 0);
    image.draw_circle(B_center_x, B_center_y, rad);
    image.set_color(0, 0, 255);
    image.draw_circle(C_center_x, C_center_y, rad);

    // DRAW TEXT HERE
    image.set_color(255, 255, 255);
    image.draw_text_box(A_box_origin_x, A_box_origin_y, box_width, A_STRING);
    image.draw_text_box(B_box_origin_x, B_box_origin_y, box_width, B_STRING);
    image.draw_text_box(C_box_origin_x, C_box_origin_y, box_width, C_STRING);
    image.draw_text_box(AB_box_origin_x, AB_box_origin_y, box_width, AB_STRING);
    image.draw_text_box(AC_box_origin_x, AC_box_origin_y, box_width, AC_STRING);
    image.draw_text_box(BC_box_origin_x, BC_box_origin_y, box_width, BC_STRING);
    image.draw_text_box(ABC_box_origin_x, ABC_box_origin_y, box_width, ABC_STRING);
    image.draw_text_box(NONE_box_origin_x, NONE_box_origin_y, box_width, NONE_STRING);

    image.save("venn.ppm");
}

int main(){
    // ask for input
    int N;
    std::string A_str;
    std::string B_str;
    std::string C_str;
    std::cout << "ENTER ONLY NUMBERS AND SPACES TO SEPERATE NUMBERS" << std::endl;
    std::cout << "How many numbers?" << std::endl;
    std::cin >> N;
    std::cout << "Enter set A" << std::endl;
    getline(std::cin, A_str);
    getline(std::cin, A_str);
    std::cout << "Enter set B" << std::endl;
    getline(std::cin, B_str);
    std::cout << "Enter set C" << std::endl;
    getline(std::cin, C_str);

    // put the values from the strings into sets A, B, C
    std::istringstream stream;
    stream.str(A_str);
    int temp;
    while(!stream.eof()){
        stream >> temp;
        input_a.insert(temp);
    }
    stream.str(B_str);
    stream.clear();
    while(!stream.eof()){
        stream >> temp;
        input_b.insert(temp);
    }
    stream.str(C_str);
    stream.clear();
    while(!stream.eof()){
        stream >> temp;
        input_c.insert(temp);
    }

    // sort out the sets
    std::set<int> temp_set = std::set<int>();
    std::set_intersection(input_a.begin(), input_a.end(), input_b.begin(), input_b.end(), std::inserter(AB, AB.begin()));
    std::set_intersection(input_a.begin(), input_a.end(), input_c.begin(), input_c.end(), std::inserter(AC,AC.begin()));
    std::set_intersection(input_b.begin(), input_b.end(), input_c.begin(), input_c.end(), std::inserter(BC, BC.begin()));
    std::set_intersection(     AB.begin(),      AB.end(),      AC.begin(),      AC.end(), std::inserter(ABC, ABC.begin()));

    std::set_difference( input_a.begin(),  input_a.end(), AB.begin(), AB.end(), std::inserter(temp_set, temp_set.begin()));
    std::set_difference(temp_set.begin(), temp_set.end(), AC.begin(), AC.end(), std::inserter(       A,        A.begin()));
    temp_set.clear();

    std::set_difference( input_b.begin(),  input_b.end(), AB.begin(), AB.end(), std::inserter(temp_set, temp_set.begin()));
    std::set_difference(temp_set.begin(), temp_set.end(), BC.begin(), BC.end(), std::inserter(       B,        B.begin()));
    temp_set.clear();

    std::set_difference( input_c.begin(),  input_c.end(), AC.begin(), AC.end(), std::inserter(temp_set, temp_set.begin()));
    std::set_difference(temp_set.begin(), temp_set.end(), BC.begin(), BC.end(), std::inserter(       C,        C.begin()));
    temp_set.clear();

    filter_set(AB, ABC);
    filter_set(AC, ABC);
    filter_set(BC, ABC);

    generate_NONE_set(N);

    A_STRING    = set_to_string(A);
    B_STRING    = set_to_string(B);
    C_STRING    = set_to_string(C);
    AB_STRING   = set_to_string(AB);
    AC_STRING   = set_to_string(AC);
    BC_STRING   = set_to_string(BC);
    ABC_STRING  = set_to_string(ABC);
    NONE_STRING = set_to_string(NONE);

    draw_image(get_box_width());
}

Makefile

CC = g++
CFLAGS = -Wall -c -std=c++11
LFLAGS = -Wall
OBJS = main.o PPMDraw.o

list: $(OBJS)
    $(CC) $(LFLAGS) $(OBJS) -o venn

main.o: PPMDraw.h
    $(CC) $(CFLAGS) main.cpp

PPMDraw.o: PPMDraw.h
    $(CC) $(CFLAGS) PPMDraw.cpp

clean:
    rm *.o main

Golfed PPMDraw.h

#ifndef PPMDRAW_H
#define PPMDRAW_H

#include <fstream>
#include <sstream>
#include <map>
#include <bitset>
#include <vector>

struct pixel{
    unsigned char r;
    unsigned char g;
    unsigned char b;

    bool equals(pixel p){
        return (r == p.r && g == p.g && b == p.b);
    }
};

class PPMDraw
{
    public:
        PPMDraw(int w, int h);

        virtual ~PPMDraw();

        void fill(unsigned char r, unsigned char g, unsigned char b);

        void set_color(unsigned char r, unsigned char g, unsigned char b);

        void draw_point(int x, int y);

        void draw_circle(int xC, int yC, int rad);

        void draw_char(int x, int y, char c);
        void draw_string(int x, int y, std::string text);
        void draw_text_box(int x, int y, int w, std::string text);

        bool save(std::string file);
        bool load(std::string file);

        float const PI = 3.14159265;

    protected:
    private:

        int width;
        int height;

        pixel * image;

        std::vector<bool> checked;

        unsigned char red;
        unsigned char green;
        unsigned char blue;


        void init_alpha();
        std::map<char, std::bitset<48> > font;

};

#endif // PPMDRAW_H

Golfed PPMDraw.cpp

#include "PPMDraw.h"
#include <fstream>
#include <iostream>
#include <sstream>
#include <cstdlib>
#include <cmath>
#include <map>
#include <bitset>
#include <vector>

// standard constructor
PPMDraw::PPMDraw(int w, int h){
    width = w;
    height = h;

    // make an array to hold all the pixels, r, g, b for each
    image = new pixel[width * height];

    // a bitset to use for functions that have to check which pixels have been worked on
    checked = std::vector<bool>();
    for(int i = 0; i < width * height; i++){
        checked.push_back(false);
    }

    init_alpha();
}


PPMDraw::~PPMDraw(){
    if(image != nullptr){
        delete[] image;
    }
}



void PPMDraw::fill(unsigned char r, unsigned char g, unsigned char b){
    for(int i = 0; i < width * height; i++){
        image[i + 0] = pixel{r, g, b};
    }
}

void PPMDraw::set_color(unsigned char r, unsigned char g, unsigned char b){
    red = r;
    green = g;
    blue = b;
}

void PPMDraw::draw_point(int x, int y){
    if(x >= 0 && x < width && y >= 0 && y < height){
        image[y * width + x] = pixel{red, green, blue};
    }
}

void PPMDraw::draw_circle(int xC, int yC, int rad){
    int x = -rad;
    int y = 0;
    int err = 2-2*rad;
    do{
        draw_point(xC - x, yC + y);
        draw_point(xC - y, yC - x);
        draw_point(xC + x, yC - y);
        draw_point(xC + y, yC + x);
        rad = err;
        if(rad <= y){ err += ++y*2+1;}
        if(rad > x || err > y){ err += ++x*2+1;}
    }while(x < 0);
}


void PPMDraw::draw_char(int x, int y, char c){
    std::bitset<48> letter = font[c];
    int n = 47;
    for(int i = 0; i < 6; i++){
        for(int j = 0; j < 8; j++){
            if(letter[n]){
                draw_point(x + i, y + j);
            }
            n--;
        }
    }
}
void PPMDraw::draw_string(int x, int y, std::string text){
        for(unsigned int i = 0; i < text.length(); i++){
            draw_char(x + 6 * i, y, text[i]);
        }

}
void PPMDraw::draw_text_box(int x, int y, int w, std::string text){
    // keep track of where to draw the next line
    int line_x = x;
    int line_y = y + 8;

    // determine the number of characters that fit on 1 line
    unsigned int char_limit = w / 6;

    std::string line = "";

    while(char_limit < text.length()){

        // get a substring from current char to char limit

        int i = text.find_last_of(' ', char_limit);
        int j = text.find('\n');
        if( j != -1 && j < i){
            line = text.substr(0, j);
            text = text.substr(j+1);
        }else{
            line = text.substr(0, i);
            text = text.substr(i+1);
        }

        // draw the line and update the y position
        draw_string(line_x, line_y, line);
        line_y += 8;
    }
    // draw rest of text
    draw_string(line_x, line_y, text);



}



bool PPMDraw::save(std::string file){
    std::ofstream save(file.c_str(), std::ios_base::out | std::ios_base::binary);
    if(save.is_open()){
        save << "P6" << std::endl;
        save << width << " " << height << std::endl;
        save << "255" << std::endl;
        unsigned char * temp = new unsigned char[height * width * 3];
        for(int i  = 0; i < height * width; i++){
            temp[i * 3 + 0] = image[i].r;
            temp[i * 3 + 1] = image[i].g;
            temp[i * 3 + 2] = image[i].b;
        }
        save.write(reinterpret_cast<const char *> (temp), height*width*3*sizeof(unsigned char));
        delete temp;
        save.close();
        return true;
    }else{
        return false;
    }


}

void PPMDraw::init_alpha(){
    // Define a simple font for drawing text
    font[' '] = std::bitset<48>  (std::string("000000000000000000000000000000000000000000000000"));
    font['!'] = std::bitset<48>  (std::string("000000000000000011110110000000000000000000000000"));
    font['"'] = std::bitset<48>  (std::string("000000001100000000000000110000000000000000000000"));
    font['#'] = std::bitset<48>  (std::string("001010001111111000101000111111100010100000000000"));
    font['$'] = std::bitset<48>  (std::string("001001000101010011111110010101000100100000000000"));
    font['%'] = std::bitset<48>  (std::string("000000100100110000010000011000001000010000000000"));
    font['&'] = std::bitset<48>  (std::string("000111001110001010110010110011000000001000000000"));
    font['\\'] = std::bitset<48>  (std::string("100000000110000000010000000011000000001000000000"));
    font['('] = std::bitset<48>  (std::string("000000000000000001111100100000100000000000000000"));
    font[')'] = std::bitset<48>  (std::string("000000001000001001111100000000000000000000000000"));
    font['*'] = std::bitset<48>  (std::string("010010000011000011100000001100000100100000000000"));
    font['+'] = std::bitset<48>  (std::string("000100000001000001111100000100000001000000000000"));
    font[','] = std::bitset<48>  (std::string("000000000000000000000110000000000000000000000000"));
    font['-'] = std::bitset<48>  (std::string("000100000001000000010000000100000001000000000000"));
    font['.'] = std::bitset<48>  (std::string("000000000000000000000100000000000000000000000000"));
    font['/'] = std::bitset<48>  (std::string("000000100000110000010000011000001000000000000000"));
    font['0'] = std::bitset<48>  (std::string("011111001000001010000010100000100111110000000000"));
    font['1'] = std::bitset<48>  (std::string("000000001000001011111110000000100000000000000000"));
    font['2'] = std::bitset<48>  (std::string("010011101001001010010010100100100111001000000000"));
    font['3'] = std::bitset<48>  (std::string("010001001000001010000010100100100110110000000000"));
    font['4'] = std::bitset<48>  (std::string("111100000001000000010000000100001111111000000000"));
    font['5'] = std::bitset<48>  (std::string("111001001001001010010010100100101001110000000000"));
    font['6'] = std::bitset<48>  (std::string("011111001001001010010010100100101000110000000000"));
    font['7'] = std::bitset<48>  (std::string("100000001000000010000110100110001110000000000000"));
    font['8'] = std::bitset<48>  (std::string("011011001001001010010010100100100110110000000000"));
    font['9'] = std::bitset<48>  (std::string("011000001001000010010000100100000111111000000000"));
    font[':'] = std::bitset<48>  (std::string("000000000000000001000100000000000000000000000000"));
    font[';'] = std::bitset<48>  (std::string("000000000000000001000110000000000000000000000000"));
    font['<'] = std::bitset<48>  (std::string("000000000001000000101000010001000000000000000000"));
    font['='] = std::bitset<48>  (std::string("001010000010100000101000001010000000000000000000"));
    font['>'] = std::bitset<48>  (std::string("000000000100010000101000000100000000000000000000"));
    font['?'] = std::bitset<48>  (std::string("010000001000000010001010100100000110000000000000"));
    font['@'] = std::bitset<48>  (std::string("011111001000001010111010101010100111001000000000"));
    font['A'] = std::bitset<48>  (std::string("011111101001000010010000100100000111111000000000"));
    font['B'] = std::bitset<48>  (std::string("111111101001001010010010100100100110110000000000"));
    font['C'] = std::bitset<48>  (std::string("011111001000001010000010100000100100010000000000"));
    font['D'] = std::bitset<48>  (std::string("111111101000001010000010100000100111110000000000"));
    font['E'] = std::bitset<48>  (std::string("111111101001001010010010100100101000001000000000"));
    font['F'] = std::bitset<48>  (std::string("111111101001000010010000100100001000000000000000"));
    font['G'] = std::bitset<48>  (std::string("011111001000001010000010100010100100110000000000"));
    font['H'] = std::bitset<48>  (std::string("111111100001000000010000000100001111111000000000"));
    font['I'] = std::bitset<48>  (std::string("100000101000001011111110100000101000001000000000"));
    font['J'] = std::bitset<48>  (std::string("000011000000001000000010000000101111110000000000"));
    font['K'] = std::bitset<48>  (std::string("111111100001000000010000001010001100011000000000"));
    font['L'] = std::bitset<48>  (std::string("111111100000001000000010000000100000001000000000"));
    font['M'] = std::bitset<48>  (std::string("111111101000000001100000100000001111111000000000"));
    font['N'] = std::bitset<48>  (std::string("111111100100000000100000000100001111111000000000"));
    font['O'] = std::bitset<48>  (std::string("011111001000001010000010100000100111110000000000"));
    font['P'] = std::bitset<48>  (std::string("111111101001000010010000100100001111000000000000"));
    font['Q'] = std::bitset<48>  (std::string("011111001000001010001010100001000111101000000000"));
    font['R'] = std::bitset<48>  (std::string("111111101001000010010000100110001111011000000000"));
    font['S'] = std::bitset<48>  (std::string("011000101001001010010010100100101000110000000000"));
    font['T'] = std::bitset<48>  (std::string("100000001000000011111110100000001000000000000000"));
    font['U'] = std::bitset<48>  (std::string("111111000000001000000010000000101111110000000000"));
    font['V'] = std::bitset<48>  (std::string("111110000000010000000010000001001111100000000000"));
    font['W'] = std::bitset<48>  (std::string("111111100000001000001100000000101111111000000000"));
    font['X'] = std::bitset<48>  (std::string("110001100010100000010000001010001100011000000000"));
    font['Y'] = std::bitset<48>  (std::string("110000000010000000011110001000001100000000000000"));
    font['Z'] = std::bitset<48>  (std::string("100001101000101010010010101000101100001000000000"));
    font['['] = std::bitset<48>  (std::string("000000001111111010000010100000100000000000000000"));
    font['\''] = std::bitset<48>  (std::string("100000000110000000010000000011000000001000000000"));
    font[']'] = std::bitset<48>  (std::string("000000001000001010000010111111100000000000000000"));
    font['^'] = std::bitset<48>  (std::string("001000000100000010000000010000000010000000000000"));
    font['_'] = std::bitset<48>  (std::string("000000100000001000000010000000100000001000000000"));
    font['`'] = std::bitset<48>  (std::string("000000001000000001000000000000000000000000000000"));
    font['a'] = std::bitset<48>  (std::string("000001000010101000101010001010100001111000000000"));
    font['b'] = std::bitset<48>  (std::string("111111100001001000010010000100100000110000000000"));
    font['c'] = std::bitset<48>  (std::string("000111000010001000100010001000100001010000000000"));
    font['d'] = std::bitset<48>  (std::string("000011000001001000010010000100101111111000000000"));
    font['e'] = std::bitset<48>  (std::string("000111000010101000101010001010100001101000000000"));
    font['f'] = std::bitset<48>  (std::string("000100000111111010010000100100000000000000000000"));
    font['g'] = std::bitset<48>  (std::string("001100100100100101001001010010010011111000000000"));
    font['h'] = std::bitset<48>  (std::string("111111100001000000010000000100000000111000000000"));
    font['i'] = std::bitset<48>  (std::string("000000000000000001011110000000000000000000000000"));
    font['j'] = std::bitset<48>  (std::string("000000100000000100000001010111100000000000000000"));
    font['k'] = std::bitset<48>  (std::string("111111100000100000010100001000100000000000000000"));
    font['l'] = std::bitset<48>  (std::string("000000000000000011111110000000000000000000000000"));
    font['m'] = std::bitset<48>  (std::string("000111100001000000001000000100000001111000000000"));
    font['n'] = std::bitset<48>  (std::string("001111100001000000010000000100000001111000000000"));
    font['o'] = std::bitset<48>  (std::string("000111000010001000100010001000100001110000000000"));
    font['p'] = std::bitset<48>  (std::string("001111110010010000100100001001000001100000000000"));
    font['q'] = std::bitset<48>  (std::string("000110000010010000100100001001000011111100000000"));
    font['r'] = std::bitset<48>  (std::string("000000000011111000010000000100000000000000000000"));
    font['s'] = std::bitset<48>  (std::string("000000000001001000101010001010100010010000000000"));
    font['t'] = std::bitset<48>  (std::string("000000000010000011111110001000000000000000000000"));
    font['u'] = std::bitset<48>  (std::string("000111000000001000000010000000100001110000000000"));
    font['v'] = std::bitset<48>  (std::string("000110000000010000000010000001000001100000000000"));
    font['w'] = std::bitset<48>  (std::string("000111100000001000000100000000100001111000000000"));
    font['x'] = std::bitset<48>  (std::string("001000100001010000001000000101000010001000000000"));
    font['y'] = std::bitset<48>  (std::string("001100000000100000000111000010000011000000000000"));
    font['z'] = std::bitset<48>  (std::string("010001100100101001010010011000100000000000000000"));
    font['{'] = std::bitset<48>  (std::string("000000000000000001101100100100100000000000000000"));
    font['|'] = std::bitset<48>  (std::string("000000000000000011111110000000000000000000000000"));
    font['}'] = std::bitset<48>  (std::string("000000000000000010010010011011000000000000000000"));
    font['~'] = std::bitset<48>  (std::string("000100000010000000010000000010000001000000000000"));
}
share|improve this answer
    
This is awesome, but you should've at least have allowed user input for N and the sets like the challenge asked... –  William Barbosa Aug 7 at 0:42
    
User can input N, in main.cpp it asks for the number to sort with std::cin. And I didn't see any specific sets in the challenge description, did I miss something? –  user137 Aug 7 at 0:49
    
Input: A positive integer N that will define the range of numbers appearing in the diagram (From zero to N) and three sets of positive integers.. You did include N, but the sets are limited to divisibility of the numbers when they should be inputed by the user. –  William Barbosa Aug 7 at 0:52
1  
so the user inputs three separate sets of numbers? I need to get back to work. –  user137 Aug 7 at 0:53
    
Cool, it'd be nice to see this as a valid submission –  William Barbosa Aug 7 at 10:44

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.