Skip to content

Instantly share code, notes, and snippets.

View antimon2's full-sized avatar

GOTOH Shunsuke antimon2

View GitHub Profile
@antimon2
antimon2 / gist:960956
Created May 7, 2011 23:26 — forked from maehrm/gist:960807
rw3sat.rb
#!/usr/bin/env ruby
# -*- coding: utf-8 -*-
def random_walk_3_sat(f, n, rr) # W1: R を rr に変更
ff = f.split(/\s*and\s*/)
rr.times do
x = Array.new(n) { [true, false].sample } # W4: a を x に変更
(3*n).times do
return "充足可能である" if ff.all? { |c| eval(c) } # W7,8,9
c = ff.find { |cc| !eval(cc) } # W10