Hackvent_2018/Day 7/code.pl

86 lines
2.0 KiB
Perl
Raw Permalink Normal View History

2018-12-07 13:52:13 +01:00
use Term::ReadKey;
sub k {
ReadKey(-1) # Perform a non-blocked read
}
ReadMode 3; # Echo off, unbuffered, signals enabled, Xon/Xoff
# possibly enabled, and 8-bit mode possibly enabled.
sub rk {
$Q = '';
$Q .= $QQ while ( $QQ = k() ); $Q
}
$| = 1;
print "\ec\e[0;0r\e[4242;1H\e[6n\e[1;1H";
# ???
( $p .= $c ) until ( ( $c = k() ) eq 'R' );
$x = 75;
$dx = 3;
# idk?
( ($yy) = ( $p =~ /(\d+);/ ) ) && ( $yy -= 10 );
# Border
print( ( "\r\n\e[40m\e[37m#" . ( ' ' x 78 ) . "#" ) x 100 );
# and what is this?
$r = (
sub {
$M = shift;
sub {
$M = ( ( $M * 0x41C64E6D ) + 12345 ) & 0x7FFFFFFF;
$M % shift;
}
}
)->(42);
# What is this?
$s = (
sub {
select( $HV18, $faLL, $D33p, shift );
}
);
# Does nothing?
$INT0 ? $H3ll : $PERL;
# Nowhere used?
# hex string -> ascii -> decimal
# ascii: b'st\x0c\x128vRHq\x05WSFb\x0elUe^\x1bKkoT\x1ak-ru'
# dec: [115, 116, 12, 18, 56, 118, 82, 72, 113, 5, 87, 83, 70, 98, 14, 108, 85, 101, 94, 27, 75, 107, 111, 84, 26, 107, 45, 114, 117]
# Length: 29
@HASH = unpack( "C*", pack( "H*", '73740c12387652487105575346620e6c55655e1b4b6b6f541a6b2d7275' ));
for $i ( 0 .. 666 ) {
$s->(0.1);
print("\e[40;91m\e[${yy};${x}H.");
$dx += int( rk() =~ / /g ) * 2 - 1;
$dx = ( $dx > 3 ? 3 : ( $dx < -3 ? -3 : $dx ) );
$x += $dx;
# ( $x > 1 && $x < 80 ) || last;
( ( $i % 23 ) && print( "\e[4242;1H\n\e[40m\e[37m#" . ( ' ' x 78 ) . "#" ) )
|| (
( $h = 20 + $r->(42) )
&& (
print(
"\e[4242;1H\n\e[40m\e[37m#"
. ( ( chr( $HASH[ $i / 23 ] ^ $h ) ) x ( $h - 5 ) )
. ( " " x 10 )
. ( ( chr( $HASH[ $i / 23 ] ^ $h ) ) x ( 73 - $h ) ) . "#"
)
)
);
# ( ( $i + 13 ) % 23 ) ? 42 : ( ( abs( $x - $h ) < 6 ) || last );
print("\e[${yy};${x}H\e[41m\e[37m@");
}
# Reset Read Mode
ReadMode 1;
###################-EOF-flappy.pl###############