9 replaced http://stackoverflow.com/ with https://stackoverflow.com/
source | link

Perl 5 + GD: 225 - 25 = 200

Edit: Found the reasonthe reason for the incorrect pixel reading in indexed PNGs and applied a workaround. For some reason with the GD library the green pixel values are read as (4,254,4). I am not sure if this is specific to the PNG files included in the question. Line breaks can be removed in the code below.

use GD;$k=newFromPng GD::Image'-',1;
sub v{/ /;10-int((($'-@x/2)**2+($`-@x/2)**2)**.5/@x*20)}
map{v>0?($r+=v):$%++,fill$k @c,0if 65280==getPixel$k @c=split
}sort{v($_=$b)- v$_=$a}map{//;map"$_ $'",@x}@x=0..width$k-1;
print"$r $%"

Takes a PNG image on the input and prints 2 values: Number of points and misses. For example:

perl arch.pl <arch52.png
52 1

Last minute change:

In true color mode that I needed anyway the color indexes used by getPixel and fill are simply integer encoded RGB values, so no need to use rgb and colorAllocate to convert to and from those indexes.

Explanation:

  • Generate list of all pixel coordinates (as space separated pairs of integers).
  • Sort by potential score (using sub v which takes parameter through $_ instead of standard parameters as it is shorter).
  • For each pixel starting from the highest scoring ones if it is green add to the result and flood fill its location black.

Perl 5 + GD: 225 - 25 = 200

Edit: Found the reason for the incorrect pixel reading in indexed PNGs and applied a workaround. For some reason with the GD library the green pixel values are read as (4,254,4). I am not sure if this is specific to the PNG files included in the question. Line breaks can be removed in the code below.

use GD;$k=newFromPng GD::Image'-',1;
sub v{/ /;10-int((($'-@x/2)**2+($`-@x/2)**2)**.5/@x*20)}
map{v>0?($r+=v):$%++,fill$k @c,0if 65280==getPixel$k @c=split
}sort{v($_=$b)- v$_=$a}map{//;map"$_ $'",@x}@x=0..width$k-1;
print"$r $%"

Takes a PNG image on the input and prints 2 values: Number of points and misses. For example:

perl arch.pl <arch52.png
52 1

Last minute change:

In true color mode that I needed anyway the color indexes used by getPixel and fill are simply integer encoded RGB values, so no need to use rgb and colorAllocate to convert to and from those indexes.

Explanation:

  • Generate list of all pixel coordinates (as space separated pairs of integers).
  • Sort by potential score (using sub v which takes parameter through $_ instead of standard parameters as it is shorter).
  • For each pixel starting from the highest scoring ones if it is green add to the result and flood fill its location black.

Perl 5 + GD: 225 - 25 = 200

Edit: Found the reason for the incorrect pixel reading in indexed PNGs and applied a workaround. For some reason with the GD library the green pixel values are read as (4,254,4). I am not sure if this is specific to the PNG files included in the question. Line breaks can be removed in the code below.

use GD;$k=newFromPng GD::Image'-',1;
sub v{/ /;10-int((($'-@x/2)**2+($`-@x/2)**2)**.5/@x*20)}
map{v>0?($r+=v):$%++,fill$k @c,0if 65280==getPixel$k @c=split
}sort{v($_=$b)- v$_=$a}map{//;map"$_ $'",@x}@x=0..width$k-1;
print"$r $%"

Takes a PNG image on the input and prints 2 values: Number of points and misses. For example:

perl arch.pl <arch52.png
52 1

Last minute change:

In true color mode that I needed anyway the color indexes used by getPixel and fill are simply integer encoded RGB values, so no need to use rgb and colorAllocate to convert to and from those indexes.

Explanation:

  • Generate list of all pixel coordinates (as space separated pairs of integers).
  • Sort by potential score (using sub v which takes parameter through $_ instead of standard parameters as it is shorter).
  • For each pixel starting from the highest scoring ones if it is green add to the result and flood fill its location black.
8 added 558 characters in body
source | link

Perl 5 + GD: 262225 - 25 = 238200

Edit: Found the reason for the incorrect pixel reading in indexed PNGs and applied a workaround. For some reason with the GD library the green pixel values are read as (4,254,4). I am not sure if this is specific to the PNG files included in the question. Line breaks can be removed in the code below.

use GD;$k=newFromPng GD::Image'-',1;
sub v{/ /;10-int((($'-@x/2)**2+($`-@x/2)**2)**.5/@x*20)}
map{@y=rgb$k getPixel$k @c=split;
v>0?($r+=v):$%++,fill$k @c,colorAllocate$k(0)x3if"@y"eq"00if 25565280==getPixel$k 0"@c=split
}sort{v($_=$b)- v$_=$a}map{//;map"$_ $'",@x}@x=0..width$k-1;
print"$r $%"

Takes a PNG image on the input and prints 2 values: Number of points and misses. For example:

perl arch.pl <arch52.png
52 1

Last minute change:

In true color mode that I needed anyway the color indexes used by getPixel and fill are simply integer encoded RGB values, so no need to use rgb and colorAllocate to convert to and from those indexes.

Explanation:

  • Generate list of all pixel coordinates (as space separated pairs of integers).
  • Sort by potential score (using sub v which takes parameter through $_ instead of standard parameters as it is shorter).
  • For each pixel starting from the highest scoring ones if it is green add to the result and flood fill its location black.

Perl 5 + GD: 262 - 25 = 238

Edit: Found the reason for the incorrect pixel reading in indexed PNGs and applied a workaround. For some reason with the GD library the green pixel values are read as (4,254,4). I am not sure if this is specific to the PNG files included in the question. Line breaks can be removed in the code below.

use GD;$k=newFromPng GD::Image'-',1;
sub v{/ /;10-int((($'-@x/2)**2+($`-@x/2)**2)**.5/@x*20)}
map{@y=rgb$k getPixel$k @c=split;
v>0?($r+=v):$%++,fill$k @c,colorAllocate$k(0)x3if"@y"eq"0 255 0"
}sort{v($_=$b)- v$_=$a}map{//;map"$_ $'",@x}@x=0..width$k-1;
print"$r $%"

Takes a PNG image on the input and prints 2 values: Number of points and misses. For example:

perl arch.pl <arch52.png
52 1

Perl 5 + GD: 225 - 25 = 200

Edit: Found the reason for the incorrect pixel reading in indexed PNGs and applied a workaround. For some reason with the GD library the green pixel values are read as (4,254,4). I am not sure if this is specific to the PNG files included in the question. Line breaks can be removed in the code below.

use GD;$k=newFromPng GD::Image'-',1;
sub v{/ /;10-int((($'-@x/2)**2+($`-@x/2)**2)**.5/@x*20)}
map{v>0?($r+=v):$%++,fill$k @c,0if 65280==getPixel$k @c=split
}sort{v($_=$b)- v$_=$a}map{//;map"$_ $'",@x}@x=0..width$k-1;
print"$r $%"

Takes a PNG image on the input and prints 2 values: Number of points and misses. For example:

perl arch.pl <arch52.png
52 1

Last minute change:

In true color mode that I needed anyway the color indexes used by getPixel and fill are simply integer encoded RGB values, so no need to use rgb and colorAllocate to convert to and from those indexes.

Explanation:

  • Generate list of all pixel coordinates (as space separated pairs of integers).
  • Sort by potential score (using sub v which takes parameter through $_ instead of standard parameters as it is shorter).
  • For each pixel starting from the highest scoring ones if it is green add to the result and flood fill its location black.
    Bounty Ended with 100 reputation awarded by globby
7 added 210 characters in body
source | link

Perl 5 + GD: 278262 - 25 = 253238

For some reason with the GD library the green pixel values are read asEdit: Found (4,254,4). I am not sure if this is specific tothe reason for the PNG files includedincorrect pixel reading in the questionindexed PNGs and applied a workaround. For some reason with the GD library the green pixel values are read as (4,254,4). I am not sure if this is specific to the PNG files included in the question. Line breaks can be removed in the code below.

use GD;$k=newFromPng GD::Image('Image'-');$b=colorAllocate$k(0,0,0);1;
sub v{/ /;10-int((($'-$s@x/2)**2+($`-$s@x/2)**2)**.5/$s*20@x*20)}
map{@y=rgb$k( getPixel$k(@c=split)); @c=split;
v>0?($r+=v):$%++,fill$k( @c,$bcolorAllocate$k(0)if"@y"eq"4x3if"@y"eq"0 254255 4"0"
}sort{v($_=$b)<=>v$_=$a- v$_=$a}map{//;map"$_ $'",@x}@x=0..($s=width$k)width$k-1;
print"$r $%"

Takes a PNG image on the input and prints 2 values: Number of points and misses. For example:

perl arch.pl <arch52.png
52 1

Perl 5 + GD: 278 - 25 = 253

For some reason with the GD library the green pixel values are read as (4,254,4). I am not sure if this is specific to the PNG files included in the question. Line breaks can be removed in the code below.

use GD;$k=newFromPng GD::Image('-');$b=colorAllocate$k(0,0,0);
sub v{/ /;10-int((($'-$s/2)**2+($`-$s/2)**2)**.5/$s*20)}
map{@y=rgb$k(getPixel$k(@c=split));
v>0?($r+=v):$%++,fill$k(@c,$b)if"@y"eq"4 254 4"
}sort{v($_=$b)<=>v$_=$a}map{//;map"$_ $'",@x}@x=0..($s=width$k)-1;
print"$r $%"

Takes a PNG image on the input and prints 2 values: Number of points and misses. For example:

perl arch.pl <arch52.png
52 1

Perl 5 + GD: 262 - 25 = 238

Edit: Found the reason for the incorrect pixel reading in indexed PNGs and applied a workaround. For some reason with the GD library the green pixel values are read as (4,254,4). I am not sure if this is specific to the PNG files included in the question. Line breaks can be removed in the code below.

use GD;$k=newFromPng GD::Image'-',1;
sub v{/ /;10-int((($'-@x/2)**2+($`-@x/2)**2)**.5/@x*20)}
map{@y=rgb$k getPixel$k @c=split;
v>0?($r+=v):$%++,fill$k @c,colorAllocate$k(0)x3if"@y"eq"0 255 0"
}sort{v($_=$b)- v$_=$a}map{//;map"$_ $'",@x}@x=0..width$k-1;
print"$r $%"

Takes a PNG image on the input and prints 2 values: Number of points and misses. For example:

perl arch.pl <arch52.png
52 1
6 deleted 5 characters in body
source | link
5 deleted 9 characters in body
source | link
4 deleted 7 characters in body
source | link
3 deleted 20 characters in body
source | link
2 deleted 20 characters in body
source | link
1
source | link