Skip to content

Instantly share code, notes, and snippets.

@alexgreenbank
Created December 5, 2020 10:52
Show Gist options
  • Save alexgreenbank/8f9f60abcd4fa6a140cb076264112f7e to your computer and use it in GitHub Desktop.
Save alexgreenbank/8f9f60abcd4fa6a140cb076264112f7e to your computer and use it in GitHub Desktop.
my $max_seat = undef;
my $min_seat = undef;
my %exist=();
while( my $line = <STDIN> ) {
chomp( $line );
$line =~ tr/BRFL/1100/;
my $ans = oct( "0b".$line );
$exist{$ans}=1;
$min_seat=$ans if( !defined( $min_seat ) || $ans < $min_seat );
$max_seat=$ans if( !defined( $max_seat ) || $ans > $max_seat );
}
print "Max: $max_seat\n";
my $ct=$min_seat+1;
while( $ct < $max_seat ) {
if( exists( $exist{$ct-1} ) && !exists( $exist{$ct} ) && exists( $exist{$ct+1} ) ) {
print "SEAT: $ct\n";
}
$ct++;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment