[2016][ruby][7.1]

profile
Alpha Chen 8 years ago
parent b443ba5312
commit e695938abf

@ -3,12 +3,22 @@ def abba?(s)
end
def tls?(s)
hypernets, s = s.split(/\[|\]/).inject([[],[]]) {|n,x| n[0] << x; [n[1], n[0]]}
s.any? {|x| abba?(x) } && hypernets.none? {|x| abba?(x) }
hypernets, supernets = s.split(/\[|\]/).inject([[],[]]) {|n,x| n[0] << x; [n[1], n[0]]}
supernets.any? {|x| abba?(x) } && hypernets.none? {|x| abba?(x) }
end
def abas(s)
s.chars.each_cons(3).select {|a,b,c| (a != b) && (a == c) }
end
def ssl?(s)
hypernets, supernets = s.split(/\[|\]/).inject([[],[]]) {|n,x| n[0] << x; [n[1], n[0]]}
abas = supernets.flat_map {|supernet| abas(supernet)}
hypernets.any? {|hypernet| abas.any? {|a,b,_| hypernet.include?("#{b}#{a}#{b}") }}
end
if __FILE__ == $0
p DATA.each_line.count {|line| tls?(line) }
p DATA.each_line.count {|line| ssl?(line) }
end
require 'minitest'

Loading…
Cancel
Save