swap-candidates #26

Open
bustikiller wants to merge 7 commits from swap-candidates into main
2 changed files with 10 additions and 13 deletions
Showing only changes of commit 1d28cfc527 - Show all commits

View File

@ -17,9 +17,7 @@ module Tables
end
def discomfort
@tables.map do |table|
local_discomfort(table)
end.sum
@tables.map(&:discomfort).sum
end
def inspect
@ -28,7 +26,7 @@ module Tables
def pretty_print
@tables.map.with_index do |table, i|
"Table #{i + 1} (#{table.count} ppl): (#{local_discomfort(table)}) #{table.map(&:full_name).join(', ')}"
"Table #{i + 1} (#{table.count} ppl): (#{table.discomfort}) #{table.map(&:full_name).join(', ')}"
end.join("\n")
end
@ -55,11 +53,5 @@ module Tables
arrangement.update!(discomfort:)
end
end
private
def local_discomfort(table)
table.discomfort ||= DiscomfortCalculator.new(table).calculate
end
end
end

View File

@ -1,15 +1,20 @@
module Tables
class Table < Array
attr_accessor :discomfort
attr_writer :discomfort
def initialize(*args)
super
reset
end
def reset
original_discomfort = discomfort
original_discomfort = @discomfort
@discomfort = nil
original_discomfort
end
def discomfort
@discomfort ||= DiscomfortCalculator.new(self).calculate
end
end
end
end