|
|
@ -3,12 +3,22 @@ def abba?(s)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
def tls?(s)
|
|
|
|
def tls?(s)
|
|
|
|
hypernets, s = s.split(/\[|\]/).inject([[],[]]) {|n,x| n[0] << x; [n[1], n[0]]}
|
|
|
|
hypernets, supernets = s.split(/\[|\]/).inject([[],[]]) {|n,x| n[0] << x; [n[1], n[0]]}
|
|
|
|
s.any? {|x| abba?(x) } && hypernets.none? {|x| abba?(x) }
|
|
|
|
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
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
if __FILE__ == $0
|
|
|
|
if __FILE__ == $0
|
|
|
|
p DATA.each_line.count {|line| tls?(line) }
|
|
|
|
p DATA.each_line.count {|line| ssl?(line) }
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
require 'minitest'
|
|
|
|
require 'minitest'
|
|
|
|