Created
May 4, 2019 08:04
-
-
Save yoggy/73d108c9888c0ad46e832b60f0b258bb to your computer and use it in GitHub Desktop.
solver for 零は? https://qiita.com/shiracamus/items/3d3ec5d95c8384ccf424
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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