Sha256: 32cd5f244d4683a39063abcf1328c3f7669dba517303f8d668b004879b406805

Contents?: true

Size: 548 Bytes

Versions: 4

Compression:

Stored size: 548 Bytes

Contents

#
# https://adventofcode.com/2018/day/5 Part 2
#
# Does not use any cem functions \o/ but did you know:
#
#  - String#swapcase turns a Hello into hELLO?
#  - Regex support 'i' for insensitive matches?
# 

File.readlines("inputs/day5_input.txt").each { |line|

  puts [*'a'..'z'].map { |delete|
            
    out = []
    
    line.gsub(/#{delete}/i, '').each_char { |c|    
      if out.empty? || out.last != c.swapcase
        out << c
      else
        out.pop
      end
    }
    
    out.join.size
  }.min
}


Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
cem-0.1.7 examples/aoc2018/day5_part2.rb
cem-0.1.6 examples/aoc2018/day5_part2.rb
cem-0.1.5 examples/aoc2018/day5_part2.rb
cem-0.1.4 examples/aoc2018/day5_part2.rb