=begin https :// ideone.com/OJiVYh の続き 入力オプションは "a1 b1 a2 b2 a3 b3 a4 b4 z"。 ex. "X Y X c1 Y c1 c2 c3 c4" 配線は手抜き # NAND の SVG のオリジナルは https :// ja.wikipedia.org/wiki/NAND%E3%82%B2%E3%83%BC%E3%83%88 https :// ja.wikipedia.org/wiki/NAND%E3%82%B2%E3%83%BC%E3%83%88#/media/%E3%83%95%E3%82%A1%E3%82%A4%E3%83%AB:NAND_ANSI_Labelled.svg =end ab = gets.split exit if ab.size != 9 Logic = Struct.new( :a, :b, :q, :stg, :x, :y, :no ) logics = [] lHash = { 'x'=>0,'y'=>1, 'c1'=>2,'c2'=>3,'c3'=>4,'c4'=>5 } lName = %W{ X Y c1 c2 c3 c4 } 4.times{|n| logics << Logic.new( lHash[ ab[2*n].downcase ],lHash[ ab[2*n+1].downcase ],false, false, -1,-1, n ) } logics[ lHash[ ab[8].downcase ]-2 ].q = true # ステージ調査 begin lg = [] logics.each{|s| lg[2*s.no] = true if s.a <= 1 lg[2*s.no+1] = true if s.b <= 1 } 3.times{|st| sq = [] 4.times{|i| next if logics[i].stg next unless lg[2*i] && lg[2*i+1] logics[i].stg = st sq << "c#{i+1}" } sq.each{|q| ab.each_with_index{|s,i| lg[i] = true if s == q } } } end # 座標決定 begin max_stg = [] logics.each{|s| max_stg[s.stg] = (max_stg[s.stg] || 0) + 1 } max_stg.size.times{|j| si = 0 logics.each_with_index{|s,i| next unless j == s.stg s.x = s.stg * 120 * 2 + 20 s.y = si * 100 + 20 si += 1 } } (max_stg.max-1).times{|n| max_stg.each_with_index{|s,i| next unless s == n + 1 logics.each{|x| next unless x.stg == i x.y += 50 * (s-n) } } } end # SVG出力 # File.open( save_path, 'w:UTF-8' ){|fh| print <<_EOT_ _EOT_ logics.each{|s| puts %Q{\t} } puts %Q{ } logics.each{|s| puts %Q{\ta#{s.no+1}} puts %Q{\tb#{s.no+1}} puts %Q{\tc#{s.no+1}} } puts " " puts %Q{ } logics.each{|s| puts %Q{\t#{lName[s.a]}} if s.a < 2 puts %Q{\t#{lName[s.b]}} if s.b < 2 if s.q puts %Q{\t} puts %Q{\tZ} else sno = s.no + 2 corner = s.no * 10 logics.each{|s2| if s2.a == sno puts %Q{\t} end if s2.b == sno puts %Q{\t} end } end } puts " " print <<_EOT_ _EOT_