Module: AtCoderFriends::Parser::ConstraintsParser
- Defined in:
- lib/at_coder_friends/parser/constraints_parser.rb
Overview
parses constraints
Class Method Summary collapse
Class Method Details
.parse(desc) ⇒ Object
13 14 15 16 17 18 19 20 21 22 23 |
# File 'lib/at_coder_friends/parser/constraints_parser.rb', line 13 def parse(desc) desc .gsub(/[,\\(){}|]/, '') .gsub(/(≤|leq?)/i, '≦') .scan(/([\da-z_]+)\s*≦\s*(\d+)(?:\^(\d+))?/i) .map do |v, sz, k| sz = sz.to_i sz **= k.to_i if k Constraint.new(v, :max, sz) end end |
.process(pbm) ⇒ Object
9 10 11 |
# File 'lib/at_coder_friends/parser/constraints_parser.rb', line 9 def process(pbm) pbm.constraints = parse(pbm.desc) end |