Skip to content

Instantly share code, notes, and snippets.

@yoggy
Created May 4, 2019 08:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save yoggy/73d108c9888c0ad46e832b60f0b258bb to your computer and use it in GitHub Desktop.
Save yoggy/73d108c9888c0ad46e832b60f0b258bb to your computer and use it in GitHub Desktop.
#!/usr/bin/ruby
#
# reiwa.rb - solver for 零は? https://qiita.com/shiracamus/items/3d3ec5d95c8384ccf424
#
require 'socket'
require 'pp'
s = TCPSocket.new("zerois-o-reiwa.seccon.jp", 23615)
count = 0
loop do
line = ""
loop do
c = s.read(1)
break if c == "\n"
line << c
end
pp line
if line[0] == "0"
count += 1
if line.include?("?*0")
s.puts "0"
elsif count == 99 or count == 100
s.puts "0"
else
line = line.gsub(/\?/, "x")
e = "bash -c 'echo \"solve([#{line}], [x]);\" | maxima'"
rv =`#{e}`
rv.each_line do |l|
if l.include?("[")
l.chomp!
ans = l.gsub(/\[(.+)\]/, "\\1").split(" ")
pp ans
a = ans[4]
pp a
s.puts(a)
#s.write("\n")
break
end
end
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment