Skip to main content
better scoring version, using "binary data trick"
Source Link
neocpp
  • 631
  • 5
  • 10

Perl, 5955.96878124 5149.56218378

Looking at the "unprintable gibberish" approach, I decided I could try that in Perl as well. Again, I don't really know Perl so I'm sure this can be improved (actually, the most obvious improvement, reduction to 7 bytes per ellipse by omitting the alpha channel, has already been implemented for the next version, but I'm still working on other parts of that code; I'm also thinking the whole pop/push business can be golfed more).

I don't think this will actually work on Windows machines (I can't test), since I couldn't figure out an easy way to open the DATA section in binary mode -- however it has worked on my linux machines.

I was able to basically keep using my same GA code to create:

use GD;
$X=GD::Image->new(386,320,1);
@r=do{$/=\8;<DATA>;};
foreach $r(@r){@x=unpack"CCCCI",$r;$c=pop@x;map{$_*=2}@x;push@x,$c;$X->filledEllipse(@x)}
open $h,">","p.png" or die "$!";
binmode $h;
print $h $X->png;
close($h);
__END__
<<unprintable gibberish>>

Where the xxd output is:

0000000: 7573 6520 4744 3b0a 2458 3d47 443a 3a49  use GD;.$X=GD::I
0000010: 6d61 6765 2d3e 6e65 7728 3338 362c 3332  mage->new(386,32
0000020: 302c 3129 3b0a 4072 3d64 6f7b 242f 3d5c  0,1);.@r=do{$/=\
0000030: 383b 3c44 4154 413e 3b7d 3b0a 666f 7265  8;<DATA>;};.fore
0000040: 6163 6820 2472 2840 7229 7b40 783d 756e  ach $r(@r){@x=un
0000050: 7061 636b 2243 4343 4349 222c 2472 3b24  pack"CCCCI",$r;$
0000060: 633d 706f 7040 783b 6d61 707b 245f 2a3d  c=pop@x;map{$_*=
0000070: 327d 4078 3b70 7573 6840 782c 2463 3b24  2}@x;push@x,$c;$
0000080: 582d 3e66 696c 6c65 6445 6c6c 6970 7365  X->filledEllipse
0000090: 2840 7829 7d0a 6f70 656e 2024 682c 223e  (@x)}.open $h,">
00000a0: 222c 2270 2e70 6e67 2220 6f72 2064 6965  ","p.png" or die
00000b0: 2022 2421 223b 0a62 696e 6d6f 6465 2024   "$!";.binmode $
00000c0: 683b 0a70 7269 6e74 2024 6820 2458 2d3e  h;.print $h $X->
00000d0: 706e 673b 0a63 6c6f 7365 2824 6829 3b0a  png;.close($h);.
00000e0: 5f5f 454e 445f 5f0a b252 8e38 3a27 2400  __END__..R.8:'$.
00000f0: 6a48 8c5d 888b 7a00 328e 7684 6c3b 2b00  jH.]..z.2.v.l;+.
0000100: 6063 8e3d 5635 2a00 a996 bf59 8650 3b00  `c.=V5*....Y.P;.
0000110: b26c 1f0f 9b6b 5500 ae19 297e 855d 4a00  .l...kU...)~.]J.
0000120: ae92 af3e 665d 4b00 be8c 480c 3a2c 2500  ...>f]K...H.:,%.
0000130: b465 5d06 432a 2400 b29a 202d 4332 2b00  .e].C*$... -C2+.
0000140: c178 1517 5e58 4c00 5d3e 907a 704b 3900  .x..^XL.]>.zpK9.
0000150: 7754 b903 2921 2000 9148 621e 99a7 a500  wT..)! ..Hb.....
0000160: aa41 6421 9ba3 9600 124d b44f 8e6f 5400  .Ad!.....M.O.oT.
0000170: 7f88 1f53 512e 2400 5c33 6c97 5b33 2800  ...SQ.$.\3l.[3(.
0000180: 2a4e 8a3e 918b 7400 a231 3c51 9489 7000  *N.>..t..1<Q..p.
0000190: 7a0c 9f11 8f8e 7700 817f 4c20 644d 3b00  z.....w...L dM;.
00001a0: 9742 5229 9eab 9d00 0884 a218 4435 2b00  .BR)........D5+.
00001b0: 749f 834a 4937 2e00 6b2a 8d5d a07b 5b00  t..JI7..k*.].{[.
00001c0: 8626 3b6b 9165 4900 aa20 3b2f 88ab 9c00  .&;k.eI.. ;/....
00001d0: 8c36 6920 9f76 5500 573e 8359 9979 6000  .6i .vU.W>.Y.y`.
00001e0: 2f1d c08d 8d76 6100 2a9a b216 313d 3400  /....va.*...1=4.
00001f0: 034d 1d18 8b63 4400 b69f 181a 3839 3200  .M...cD.....892.
0000200: 1412 302d 854b 3600 080a 931a 6b3a 2c00  ..0-.K6.....k:,.
0000210: 6400 902b 8b65 5000 003f 321b a088 6e00  d..+.eP..?2...n.
0000220: 1c4d 1f0b 779e 8f00 8127 1f0d 8897 8900  .M..w....'......
0000230: 5d96 6c16 6057 5100 7537 4c1b 9064 4900  ].l.`WQ.u7L..dI.
0000240: 2da0 6403 6482 8600 3a45 6e07 866b 5000  -.d.d...:En..kP.
0000250: 453f 5c5b 3a37 3100 3659 610f 865a 3f00  E?\[:71.6Ya..Z?.
0000260: bb24 361b 8dac 9b00 b01d 161d 58ae b700  .$6.........X...
0000270: 3c65 5031 785f 4800 330c 5b6f 834b 3700  <eP1x_H.3.[o.K7.
0000280: 4e23 539b 8961 4a00 5926 2c19 9c8c 7c00  N#S..aJ.Y&,...|.
0000290: 3031 980d 9479 6200 2708 431c 8184 7300  01...yb.'.C...s.
00002a0: a89d 1e02 2f26 2300 205f 0d74 2727 1e00  ..../&#. _.t''..
00002b0: bf33 210f 997b 5c00 1d60 0670 9476 5f00  .3!..{\..`.p.v_.
00002c0: 1f71 107c 292c 2700 5113 940e 7f47 3500  .q.|),'.Q....G5.
00002d0: 7140 4906 9881 6b00 3614 0e3e 8648 3400  [email protected]..>.H4.
00002e0: 940a 0f68 9979 5d00 3471 1229 2223 2200  ...h.y].4q.)"#".
00002f0: 3060 031c 614b 3600 5908 830b 7c73 6200  0`..aK6.Y...|sb.
0000300: 2706 1239 5488 8700 468a 683d 2226 2400  '..9T...F.h="&$.
0000310: 4774 1715 6949 3400 5d9c 4a37 3c3f 4000  Gt..iI4.].J7<?@.
0000320: 5f51 3438 8c6b 5000 4c4e 3d48 8771 5800  _Q48.kP.LN=H.qX.
0000330: 2488 1385 1e22 1e00 5979 3417 5134 2700  $...."..Yy4.Q4'.
0000340: 5030 5622 937d 6700 6c23 1c1c 9672 5c00  P0V".}g.l#...r\.
0000350: 2543 0126 2224 1f00 8c8d 7a01 9171 6600  %C.&"$....z..qf.
0000360: 4932 1012 6341 2d00 3341 1515 7a54 3a00  I2..cA-.3A..zT:.
0000370: 3893 2849 1f22 1f00 798f 7f11 4b3f 3500  8.(I."..y...K?5.
0000380: 6890 4e1d 3530 2b00 6d7b 2b21 6347 3700  h.N.50+.m{+!cG7.
0000390: 4e54 3222 9ca5 9a00 2705 2224 7243 3500  NT2"....'."$rC5.
00003a0: 7705 4c31 7d49 3900 915c 2d0b 9697 8100  w.L1}I9..\-.....
00003b0: 4e3d 221e 9874 5a00 748e 1118 3831 2d00  N="..tZ.t...81-.
00003c0: bf68 340d 9666 5000 9529 0848 9a68 4c00  .h4..fP..).H.hL.
00003d0: 2003 0466 3c2d 2900 5a49 1c4c 916e 5400   ..f<-).ZI.L.nT.
00003e0: 6c60 6008 8e8b 7500 4696 2219 1c20 1d00  l``...u.F.".. ..
00003f0: 7906 1165 8052 3f00 740e 1412 7c7d 6c00  y..e.R?.t...|}l.

Which generates the image:

enter image description here

It's interesting that even though it scores better, the image looks somewhat worse to me -- there's too much going on with all the extra ellipses, somehow the simpler image is easier to deal with visually.

Perl, 5955.96878124Old Results

Perl, 5955.96878124

Perl, 5955.96878124 5149.56218378

Looking at the "unprintable gibberish" approach, I decided I could try that in Perl as well. Again, I don't really know Perl so I'm sure this can be improved (actually, the most obvious improvement, reduction to 7 bytes per ellipse by omitting the alpha channel, has already been implemented for the next version, but I'm still working on other parts of that code; I'm also thinking the whole pop/push business can be golfed more).

I don't think this will actually work on Windows machines (I can't test), since I couldn't figure out an easy way to open the DATA section in binary mode -- however it has worked on my linux machines.

I was able to basically keep using my same GA code to create:

use GD;
$X=GD::Image->new(386,320,1);
@r=do{$/=\8;<DATA>;};
foreach $r(@r){@x=unpack"CCCCI",$r;$c=pop@x;map{$_*=2}@x;push@x,$c;$X->filledEllipse(@x)}
open $h,">","p.png" or die "$!";
binmode $h;
print $h $X->png;
close($h);
__END__
<<unprintable gibberish>>

Where the xxd output is:

0000000: 7573 6520 4744 3b0a 2458 3d47 443a 3a49  use GD;.$X=GD::I
0000010: 6d61 6765 2d3e 6e65 7728 3338 362c 3332  mage->new(386,32
0000020: 302c 3129 3b0a 4072 3d64 6f7b 242f 3d5c  0,1);.@r=do{$/=\
0000030: 383b 3c44 4154 413e 3b7d 3b0a 666f 7265  8;<DATA>;};.fore
0000040: 6163 6820 2472 2840 7229 7b40 783d 756e  ach $r(@r){@x=un
0000050: 7061 636b 2243 4343 4349 222c 2472 3b24  pack"CCCCI",$r;$
0000060: 633d 706f 7040 783b 6d61 707b 245f 2a3d  c=pop@x;map{$_*=
0000070: 327d 4078 3b70 7573 6840 782c 2463 3b24  2}@x;push@x,$c;$
0000080: 582d 3e66 696c 6c65 6445 6c6c 6970 7365  X->filledEllipse
0000090: 2840 7829 7d0a 6f70 656e 2024 682c 223e  (@x)}.open $h,">
00000a0: 222c 2270 2e70 6e67 2220 6f72 2064 6965  ","p.png" or die
00000b0: 2022 2421 223b 0a62 696e 6d6f 6465 2024   "$!";.binmode $
00000c0: 683b 0a70 7269 6e74 2024 6820 2458 2d3e  h;.print $h $X->
00000d0: 706e 673b 0a63 6c6f 7365 2824 6829 3b0a  png;.close($h);.
00000e0: 5f5f 454e 445f 5f0a b252 8e38 3a27 2400  __END__..R.8:'$.
00000f0: 6a48 8c5d 888b 7a00 328e 7684 6c3b 2b00  jH.]..z.2.v.l;+.
0000100: 6063 8e3d 5635 2a00 a996 bf59 8650 3b00  `c.=V5*....Y.P;.
0000110: b26c 1f0f 9b6b 5500 ae19 297e 855d 4a00  .l...kU...)~.]J.
0000120: ae92 af3e 665d 4b00 be8c 480c 3a2c 2500  ...>f]K...H.:,%.
0000130: b465 5d06 432a 2400 b29a 202d 4332 2b00  .e].C*$... -C2+.
0000140: c178 1517 5e58 4c00 5d3e 907a 704b 3900  .x..^XL.]>.zpK9.
0000150: 7754 b903 2921 2000 9148 621e 99a7 a500  wT..)! ..Hb.....
0000160: aa41 6421 9ba3 9600 124d b44f 8e6f 5400  .Ad!.....M.O.oT.
0000170: 7f88 1f53 512e 2400 5c33 6c97 5b33 2800  ...SQ.$.\3l.[3(.
0000180: 2a4e 8a3e 918b 7400 a231 3c51 9489 7000  *N.>..t..1<Q..p.
0000190: 7a0c 9f11 8f8e 7700 817f 4c20 644d 3b00  z.....w...L dM;.
00001a0: 9742 5229 9eab 9d00 0884 a218 4435 2b00  .BR)........D5+.
00001b0: 749f 834a 4937 2e00 6b2a 8d5d a07b 5b00  t..JI7..k*.].{[.
00001c0: 8626 3b6b 9165 4900 aa20 3b2f 88ab 9c00  .&;k.eI.. ;/....
00001d0: 8c36 6920 9f76 5500 573e 8359 9979 6000  .6i .vU.W>.Y.y`.
00001e0: 2f1d c08d 8d76 6100 2a9a b216 313d 3400  /....va.*...1=4.
00001f0: 034d 1d18 8b63 4400 b69f 181a 3839 3200  .M...cD.....892.
0000200: 1412 302d 854b 3600 080a 931a 6b3a 2c00  ..0-.K6.....k:,.
0000210: 6400 902b 8b65 5000 003f 321b a088 6e00  d..+.eP..?2...n.
0000220: 1c4d 1f0b 779e 8f00 8127 1f0d 8897 8900  .M..w....'......
0000230: 5d96 6c16 6057 5100 7537 4c1b 9064 4900  ].l.`WQ.u7L..dI.
0000240: 2da0 6403 6482 8600 3a45 6e07 866b 5000  -.d.d...:En..kP.
0000250: 453f 5c5b 3a37 3100 3659 610f 865a 3f00  E?\[:71.6Ya..Z?.
0000260: bb24 361b 8dac 9b00 b01d 161d 58ae b700  .$6.........X...
0000270: 3c65 5031 785f 4800 330c 5b6f 834b 3700  <eP1x_H.3.[o.K7.
0000280: 4e23 539b 8961 4a00 5926 2c19 9c8c 7c00  N#S..aJ.Y&,...|.
0000290: 3031 980d 9479 6200 2708 431c 8184 7300  01...yb.'.C...s.
00002a0: a89d 1e02 2f26 2300 205f 0d74 2727 1e00  ..../&#. _.t''..
00002b0: bf33 210f 997b 5c00 1d60 0670 9476 5f00  .3!..{\..`.p.v_.
00002c0: 1f71 107c 292c 2700 5113 940e 7f47 3500  .q.|),'.Q....G5.
00002d0: 7140 4906 9881 6b00 3614 0e3e 8648 3400  [email protected]..>.H4.
00002e0: 940a 0f68 9979 5d00 3471 1229 2223 2200  ...h.y].4q.)"#".
00002f0: 3060 031c 614b 3600 5908 830b 7c73 6200  0`..aK6.Y...|sb.
0000300: 2706 1239 5488 8700 468a 683d 2226 2400  '..9T...F.h="&$.
0000310: 4774 1715 6949 3400 5d9c 4a37 3c3f 4000  Gt..iI4.].J7<?@.
0000320: 5f51 3438 8c6b 5000 4c4e 3d48 8771 5800  _Q48.kP.LN=H.qX.
0000330: 2488 1385 1e22 1e00 5979 3417 5134 2700  $...."..Yy4.Q4'.
0000340: 5030 5622 937d 6700 6c23 1c1c 9672 5c00  P0V".}g.l#...r\.
0000350: 2543 0126 2224 1f00 8c8d 7a01 9171 6600  %C.&"$....z..qf.
0000360: 4932 1012 6341 2d00 3341 1515 7a54 3a00  I2..cA-.3A..zT:.
0000370: 3893 2849 1f22 1f00 798f 7f11 4b3f 3500  8.(I."..y...K?5.
0000380: 6890 4e1d 3530 2b00 6d7b 2b21 6347 3700  h.N.50+.m{+!cG7.
0000390: 4e54 3222 9ca5 9a00 2705 2224 7243 3500  NT2"....'."$rC5.
00003a0: 7705 4c31 7d49 3900 915c 2d0b 9697 8100  w.L1}I9..\-.....
00003b0: 4e3d 221e 9874 5a00 748e 1118 3831 2d00  N="..tZ.t...81-.
00003c0: bf68 340d 9666 5000 9529 0848 9a68 4c00  .h4..fP..).H.hL.
00003d0: 2003 0466 3c2d 2900 5a49 1c4c 916e 5400   ..f<-).ZI.L.nT.
00003e0: 6c60 6008 8e8b 7500 4696 2219 1c20 1d00  l``...u.F.".. ..
00003f0: 7906 1165 8052 3f00 740e 1412 7c7d 6c00  y..e.R?.t...|}l.

Which generates the image:

enter image description here

It's interesting that even though it scores better, the image looks somewhat worse to me -- there's too much going on with all the extra ellipses, somehow the simpler image is easier to deal with visually.

Old Results

Source Link
neocpp
  • 631
  • 5
  • 10

Perl, 5955.96878124

use GD;
$X=GD::Image->new(386,320);
sub c{$X->colorAllocate(@_);};
sub e{$X->filledEllipse(@_);};
e(0,7,9,4,c(98,122,142));
e(352,168,130,61,c(38,41,57));
e(313,296,319,213,c(44,56,92));
e(281,71,240,257,c(99,127,149));
e(55,266,372,67,c(41,55,96));
e(39,15,281,130,c(55,73,128));
e(235,149,226,90,c(136,156,152));
e(81,55,29,29,c(129,133,89));
e(183,139,285,65,c(58,79,108));
e(368,261,177,130,c(75,97,145));
e(283,270,386,88,c(70,86,99));
e(271,11,322,58,c(86,104,129));
e(254,78,185,200,c(90,116,151));
e(29,16,34,35,c(119,135,130));
e(195,311,297,189,c(51,69,98));
e(234,19,150,89,c(58,75,126));
e(286,313,286,108,c(49,56,68));
e(232,30,40,31,c(114,130,122));
e(375,145,106,32,c(159,172,160));
e(59,16,21,141,c(43,53,90));
e(66,135,21,108,c(39,45,43));
e(353,53,84,80,c(167,172,117));
e(196,122,150,137,c(86,110,145));
e(101,320,284,185,c(48,55,59));
e(79,193,73,114,c(36,42,42));
e(106,310,126,191,c(31,35,33));
e(119,169,70,56,c(128,144,150));
open $h,">","p.png" or die "$!";
binmode $h;
print $h $X->png;
close($h);

enter image description here

After seeing jamieguinan's answer, I used ellipses as a drawing primitive since in Perl I have access to the GD library for drawing. I am not a Perl expert at all, so any suggestions would be useful. I used a genetic algorithm which was modified from my C++ answer.

It seems to work okay, but honestly I am a bit disappointed in the score. I could probably let it run a little longer since you can easily see that a few ellipses are not in optimal positions. However, even now it looks nicer to my eyes compared to the rectangle-based solution.