Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #61430
| Path | csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!news.mixmin.net!rt.uk.eu.org!newsfeed.xs4all.nl!newsfeed4.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail |
|---|---|
| Return-Path | <rosuav@gmail.com> |
| X-Original-To | python-list@python.org |
| Delivered-To | python-list@mail.python.org |
| X-Spam-Status | OK 0.005 |
| X-Spam-Evidence | '*H*': 0.99; '*S*': 0.00; 'output': 0.05; 'definitions': 0.07; 'elegant': 0.07; 'cc:addr:python-list': 0.11; 'python': 0.11; 'posted': 0.15; 'chris,': 0.16; 'devise': 0.16; 'evaluates': 0.16; 'from:addr:rosuav': 0.16; 'from:name:chris angelico': 0.16; 'inputs': 0.16; 'solver.': 0.16; 'subject:Programming': 0.16; 'subsequently': 0.16; 'tweak': 0.16; 'zero,': 0.16; 'all.': 0.16; 'wrote:': 0.18; '(not': 0.18; 'solution.': 0.20; 'cc:addr:python.org': 0.22; 'fairly': 0.24; 'cc:2**0': 0.24; 'posts': 0.26; 'post': 0.26; 'values': 0.27; 'header:In-Reply-To:1': 0.27; 'dec': 0.30; 'message- id:@mail.gmail.com': 0.30; 'asked': 0.31; 'code': 0.31; 'piece': 0.31; 'class': 0.32; 'figure': 0.32; 'maybe': 0.34; 'subject:with': 0.35; 'classes': 0.35; 'but': 0.35; 'received:google.com': 0.35; 'version': 0.36; 'skip:~ 10': 0.36; 'yours,': 0.36; 'possible': 0.36; 'two': 0.37; 'pm,': 0.38; 'bad': 0.39; "couldn't": 0.39; 'either': 0.39; 'how': 0.40; 'most': 0.60; 'ago,': 0.61; 'grab': 0.64; 'hours': 0.66; 'pleasure.': 0.84; 'joel': 0.91; 'to:none': 0.92; '2013': 0.98 |
| DKIM-Signature | v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:cc :content-type; bh=joO6nUHPlQH8LS8dZ3YleYsc0aDPUcC1624K+XFwdFM=; b=IFtWLfRb4cEDHMeRWdraaTOKoFtm0RdELwoUW6o9iRmvdwrH42ne3K5PjUlVdsSAoJ hzbQzUsCGuXrCvnfCXLzFApQnFJ71cYcD+Szq/V2oIyLW/GVqwXHVFWSb/U+54H9ZZPg 2uH6k/zh9T2wmdE376gz0csD1d0s/WcOhdSNseZBEAb3/d+MhfJbbrjIOzZo2vptuioF d5OzHXJu1zjW8f70n2G4xtSQyCky/gPfR2q0vkkKRvTSf1aR9A68IKy1Z/iEiYkjeawx AyJBySZ5QIbc6ocz5LQoBex9kj1lve/PKlUCI+SbFM58l3SFkJDLnimzDnmAR52OcHhd bC2g== |
| MIME-Version | 1.0 |
| X-Received | by 10.66.118.71 with SMTP id kk7mr24637536pab.14.1386642106391; Mon, 09 Dec 2013 18:21:46 -0800 (PST) |
| In-Reply-To | <CAPM-O+yssdgztsRZjZOWE8k8OaB_2sg3nnd1zQM=osZ0ggE0ow@mail.gmail.com> |
| References | <l84aor$3mj$1@news.albasani.net> <CAPM-O+z4vuhoyKuEVdoYxJe42qhXT89GQTyQEHGjvm+c8yV3NQ@mail.gmail.com> <CAPM-O+yssdgztsRZjZOWE8k8OaB_2sg3nnd1zQM=osZ0ggE0ow@mail.gmail.com> |
| Date | Tue, 10 Dec 2013 13:21:46 +1100 |
| Subject | Re: Programming puzzle with boolean circuits |
| From | Chris Angelico <rosuav@gmail.com> |
| Cc | "python-list@python.org" <python-list@python.org> |
| Content-Type | text/plain; charset=UTF-8 |
| X-BeenThere | python-list@python.org |
| X-Mailman-Version | 2.1.15 |
| Precedence | list |
| List-Id | General discussion list for the Python programming language <python-list.python.org> |
| List-Unsubscribe | <https://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe> |
| List-Archive | <http://mail.python.org/pipermail/python-list/> |
| List-Post | <mailto:python-list@python.org> |
| List-Help | <mailto:python-list-request@python.org?subject=help> |
| List-Subscribe | <https://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe> |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.3807.1386642111.18130.python-list@python.org> (permalink) |
| Lines | 66 |
| NNTP-Posting-Host | 2001:888:2000:d::a6 |
| X-Trace | 1386642111 news.xs4all.nl 2837 [2001:888:2000:d::a6]:57261 |
| X-Complaints-To | abuse@xs4all.nl |
| Xref | csiph.com comp.lang.python:61430 |
Show key headers only | View raw
On Tue, Dec 10, 2013 at 1:03 PM, Joel Goldstick <joel.goldstick@gmail.com> wrote: > Chris, and all.. Since you posted yours, I post this for your pleasure. I > couldn't figure out what you were doing. > [chomp Python implementation of a fairly elegant solution] That's a fairly nice piece of code that comes from a deliberate solution. What the OP asked was how to devise a brute-force solver. Grab the four class definitions from my code a few posts ago, and then tweak your code to use them: a = Schrodinger(1) b = Schrodinger(2) c = Schrodinger(4) all_ones = a & b & c two_or_three = (a & b) | (a & c) | (b & c) zero_or_one = ~two_or_three one_one = zero_or_one & (a | b | c) zero_or_two = ~(all_ones | one_one) zero_ones = zero_or_one & zero_or_two two_ones = zero_or_two & two_or_three # the output is true if all the inputs are zero, | if one of the inputs is zero & it is either b | c # | two inputs are zero & they are b & c # ditto f| other two inputs x = zero_ones | (one_one & (b | c)) | (two_ones & (b & c)) y = zero_ones | (one_one & (a | c)) | (two_ones & (a & c)) z = zero_ones | (one_one & (b | a)) | (two_ones & (b & a)) if x == ~a: print(x) if y == ~b: print(y) if z == ~c: print(z) Output: (I tweaked my __repr__ functions to parenthesize for clarity) (((not ((($1 and $2) or ($1 and $4)) or ($2 and $4)) and not ((($1 and $2) and $4) or (not ((($1 and $2) or ($1 and $4)) or ($2 and $4)) and (($1 or $2) or $4)))) or ((not ((($1 and $2) or ($1 and $4)) or ($2 and $4)) and (($1 or $2) or $4)) and ($2 or $4))) or ((not ((($1 and $2) and $4) or (not ((($1 and $2) or ($1 and $4)) or ($2 and $4)) and (($1 or $2) or $4))) and ((($1 and $2) or ($1 and $4)) or ($2 and $4))) and ($2 and $4))) (((not ((($1 and $2) or ($1 and $4)) or ($2 and $4)) and not ((($1 and $2) and $4) or (not ((($1 and $2) or ($1 and $4)) or ($2 and $4)) and (($1 or $2) or $4)))) or ((not ((($1 and $2) or ($1 and $4)) or ($2 and $4)) and (($1 or $2) or $4)) and ($1 or $4))) or ((not ((($1 and $2) and $4) or (not ((($1 and $2) or ($1 and $4)) or ($2 and $4)) and (($1 or $2) or $4))) and ((($1 and $2) or ($1 and $4)) or ($2 and $4))) and ($1 and $4))) (((not ((($1 and $2) or ($1 and $4)) or ($2 and $4)) and not ((($1 and $2) and $4) or (not ((($1 and $2) or ($1 and $4)) or ($2 and $4)) and (($1 or $2) or $4)))) or ((not ((($1 and $2) or ($1 and $4)) or ($2 and $4)) and (($1 or $2) or $4)) and ($2 or $1))) or ((not ((($1 and $2) and $4) or (not ((($1 and $2) or ($1 and $4)) or ($2 and $4)) and (($1 or $2) or $4))) and ((($1 and $2) or ($1 and $4)) or ($2 and $4))) and ($2 and $1))) Okay, so maybe the brute-force-discovered version isn't so bad after all. :) The classes allow "a and b == c" to be evaluated for all possible values of a, b, and c, so the brute-forcing actually accumulates data and only subsequently evaluates it. It's far from the most efficient solution (took hours on an i5 CPU), but it's fun :) ChrisA
Back to comp.lang.python | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
Programming puzzle with boolean circuits Johannes Bauer <dfnsonfsduifb@gmx.de> - 2013-12-09 12:49 +0100
Re: Programming puzzle with boolean circuits Chris Angelico <rosuav@gmail.com> - 2013-12-10 00:25 +1100
Re: Programming puzzle with boolean circuits Johannes Bauer <dfnsonfsduifb@gmx.de> - 2013-12-11 14:52 +0100
Re: Programming puzzle with boolean circuits Joel Goldstick <joel.goldstick@gmail.com> - 2013-12-09 15:19 -0500
Spoiler alert? (Re: Programming puzzle with boolean circuits) John Ladasky <john_ladasky@sbcglobal.net> - 2013-12-09 12:39 -0800
Re: Spoiler alert? (Re: Programming puzzle with boolean circuits) Joel Goldstick <joel.goldstick@gmail.com> - 2013-12-09 15:45 -0500
Re: Programming puzzle with boolean circuits Chris Angelico <rosuav@gmail.com> - 2013-12-10 12:41 +1100
Fwd: Programming puzzle with boolean circuits Joel Goldstick <joel.goldstick@gmail.com> - 2013-12-09 21:03 -0500
Re: Programming puzzle with boolean circuits Chris Angelico <rosuav@gmail.com> - 2013-12-10 13:21 +1100
Re: Programming puzzle with boolean circuits Chris Angelico <rosuav@gmail.com> - 2013-12-10 19:50 +1100
Re: Programming puzzle with boolean circuits Antoon Pardon <antoon.pardon@rece.vub.ac.be> - 2013-12-10 15:25 +0100
csiph-web