Tag Info

New answers tagged

1

Here I figured out a rough, primitive solution to get the work done, still looking forward a smarter solution. labels = {"00", "01", "11", "10"}; lab = {"0", "1"}; Clear[a, b, c, x, y, A, B]; elem = {{! a && ! b && ! c, ! a && ! b && c}, {! a && b && ! c, ! a && b && c}, {a && b ...


4

Another option, sort of like pattern matching on training wheels. First apply criteria for individual houses. ClearAll@"Global`*"; colors = {red, blue, yellow, ivory, green}; nations = {norway, ukraine, england, spain, japan}; drinks = {water, tea, milk, oj, coffee}; smokes = {kools, chesterfields, golds, luckys, parliaments}; pets = {fox, horse, snails, ...


8

I wrote an unification-based program as used in Prolog language. First, I setup a simple unification functions: Clear[unify]; unify[var1_Symbol, var2_Symbol] := If[var1 === var2, {}, {var1 -> var2}]; unify[const1_?StringQ, const2_?StringQ] := If[const1 == const2, {}, $Failed]; unify[var_Symbol, const_?StringQ] := {var -> const}; ...


6

EDIT This edit (I hope corrects the problem identified by Mr. Wizard: (i) there was a typographical error "Kools", should have been "Kool", and the styling of desired targets has now been left to the end). I post this not as elegant but I spent some time and particularly like "unlikely"'s answer. The puzzle: Setting up: housenumber = Range[5]; ...


16

You can use LinearProgramming or more simply Minimize to solve this problem. The idea is to minimize an objective function of some decision variables subject to some constraints. The objective function doesn't matter, can be a constant function, the only relevant thing is the constraint satisfaction. First, setup the parameters, sets and clues (in an ...


0

Here's a bitwise approach, using a two-argument definition like @m_goldberg: xor[str1_String, str2_String] := IntegerString[ BitXor[FromDigits[str1, 2], FromDigits[str2, 2]], 2, StringLength[str1]]; The other functions could be implemented with bitwise operators, too.


1

Perhaps xor[ab : {a_String /; StringFreeQ[a, Except["0" | "1"]], b_String /; StringFreeQ[b, Except["0" | "1"]]}] := StringJoin[ MapThread[Xor, Characters[ab] /. {"0" -> False, "1" -> True}] /. {False -> "0", True -> "1"}] Since xor is limited to two strings in the list it will be convenient to support this form: ...


0

I think it would be simpler to implement the logic directly, with fewer transformations: str2={"11000000","10000001","11111111"}; do[f_]:=StringJoin[ToString/@Boole@MapThread[f,StringSplit[#,""]]]&; not=StringReplace[#,{"1"->"0","0"->"1"}]&; not@str2[[1]] "00111111" or=do[!FreeQ[{##},"1"]&]; or@str2 "11111111" ...



Top 50 recent answers are included