#!/usr/bin/env tclsh proc seat {s} { set fb [string range $s 0 6] set lr [string range $s 7 9] set min 0; set max 127 foreach c [split $fb {}] { switch -- $c { F { # Keep the lower half. set width [expr {$max - $min + 1}] set max [expr {$min + $width/2}] } B { # Keep the upper half. set width [expr {$max - $min + 1}] set min [expr {$min + $width/2}] } } } set fb $min set min 0; set max 7 foreach c [split $lr {}] { switch -- $c { L { # Keep the lower half. set width [expr {$max - $min + 1}] set max [expr {$min + $width/2}] } R { # Keep the upper half. set width [expr {$max - $min + 1}] set min [expr {$min + $width/2}] } } } set lr $min expr {$lr + $fb * 8} } while {[gets stdin line] >= 0} { if {$line eq ""} continue set seats([seat $line]) 1 } for {set i 0} {$i < 1024} {incr i} { if {! [info exists seats($i)]} {puts $i} }