blob: 462a7a9f332da07de1aed91b4b7e4d00f55de1ba (
plain) (
tree)
|
|
#!/bin/env tclsh
source lib.tcl
setup 1
puts {Part 1: Find the sum of distances between pairs of numbers with the same ordinal in each list.}
while {[gets $input line] != -1} {
lassign [regexp -inline -all {\d+} $line] ln rn
lappend left_nums $ln
lappend right_nums $rn
dict incr right_num_counts $rn
}
close $input
set left_nums [lsort -integer $left_nums]
set right_nums [lsort -integer $right_nums]
foreach ln $left_nums rn $right_nums {
incr total1 [expr {abs($ln - $rn)}]
if [dict exists $right_num_counts $ln] {
incr total2 [expr {$ln * [dict get $right_num_counts $ln]}]
}
}
puts "Sum of distances: $total1"
puts ""
puts {Part 2: Find the "Similarity Score" of the lists.}
puts "Similarity Score: $total2"
|