-
-
Save DemianD/4bbeb392671d2ef8ecc0b57a8391d4df to your computer and use it in GitHub Desktop.
16.pl
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@ARGV_COPY = @ARGV; | |
$/ = undef; | |
$file = <>; | |
# filtering lines | |
$file =~ s/.* w$//ms; | |
$file =~ s/endstream.*//ms; | |
$_ = $file; | |
while (/(\d+)(?:\.\d+)? (\d+)(?:\.\d+)? m.(\d+)(?:\.\d+)? (\d+)(?:\.\d+)? l/gsm) { | |
$x1 = $1; | |
$y1 = $2; | |
$x2 = $3; | |
$y2 = $4; | |
$X{$x1} = undef; | |
$X{$x2} = undef; | |
$Y{$y1} = undef; | |
$Y{$y2} = undef; | |
} | |
$z = 1; | |
foreach (sort { $a <=> $b } keys %X) { | |
$X{$_} = $z; | |
$maxX = $_; | |
$z++; | |
} | |
$z = 1; | |
foreach (sort { $a <=> $b } keys %Y) { | |
$Y{$_} = $z; | |
$maxY = $_; | |
$z++; | |
} | |
foreach (keys %X) { | |
printf "%s: %s\n", $_, $X{$_}; | |
} | |
foreach (keys %Y) { | |
printf "%s: %s\n", $_, $Y{$_}; | |
} | |
@ARGV = @ARGV_COPY; | |
$/ = undef; | |
$file = <>; | |
# filtering lines | |
$file =~ s/.* w$//ms; | |
$file =~ s/endstream.*//ms; | |
$_ = $file; | |
@matrix = (); | |
while (/(\d+)(?:\.\d+)? (\d+)(?:\.\d+)? m.(\d+)(?:\.\d+)? (\d+)(?:\.\d+)? l/gsm) { | |
$x1 = $1; | |
$y1 = $2; | |
$x2 = $3; | |
$y2 = $4; | |
# verticale lijn | |
if ($x1 == $x2) { | |
if ($y2 > $y1) { | |
$min = $Y{$y1}; | |
$max = $Y{$y2}; | |
} else { | |
$min = $Y{$y2}; | |
$max = $Y{$y1}; | |
} | |
for ($i = $min; $i<= $max; $i++) { | |
$matrix[$i][$X{$x1}] = "|"; | |
} | |
} | |
if ($y1 == $y2) { | |
if ($x2 > $x1) { | |
$min = $X{$x1}; | |
$max = $X{$x2}; | |
} else { | |
$min = $X{$x2}; | |
$max = $X{$x1}; | |
} | |
for ($i = $min; $i<= $max; $i++) { | |
$matrix[$Y{$y1}][$i] = "-"; | |
} | |
} | |
} | |
print "\n\n"; | |
foreach $row (reverse @matrix) { | |
foreach $element (@$row) { | |
if ($element eq "|" || $element eq "-" || $element eq "+") { | |
print $element; | |
} else { | |
print " "; | |
} | |
} | |
print "\n"; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment