Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #61452
| Path | csiph.com!usenet.pasdenom.info!weretis.net!feeder4.news.weretis.net!rt.uk.eu.org!newsfeed.xs4all.nl!newsfeed4.news.xs4all.nl!xs4all!news.tele.dk!news.tele.dk!small.news.tele.dk!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.064 |
| X-Spam-Evidence | '*H*': 0.87; '*S*': 0.00; 'sys': 0.07; 'similar,': 0.09; 'cc:addr:python-list': 0.11; 'from:addr:rosuav': 0.16; 'from:name:chris angelico': 0.16; 'ha!': 0.16; 'simplified': 0.16; 'subject:Programming': 0.16; 'all.': 0.16; 'wrote:': 0.18; '(not': 0.18; 'bit': 0.19; 'solution.': 0.20; 'seems': 0.21; 'cc:addr:python.org': 0.22; 'fairly': 0.24; 'looks': 0.24; 'cc:2**0': 0.24; 'header:In-Reply-To:1': 0.27; 'chris': 0.29; 'change,': 0.30; 'dec': 0.30; 'message-id:@mail.gmail.com': 0.30; 'maybe': 0.34; 'could': 0.34; 'subject:with': 0.35; 'problem.': 0.35; 'something': 0.35; 'received:google.com': 0.35; 'version': 0.36; 'shorter': 0.36; 'pm,': 0.38; 'bad': 0.39; 'though,': 0.39; 'even': 0.60; 'most': 0.60; 'full': 0.61; 'simple': 0.61; 'real': 0.63; 'hours': 0.66; 'six': 0.68; 'applying': 0.72; 'notable': 0.91; 'step.': 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=UgNpsk31NFaTW4VoZcEgE4kaAcHfABv/BKmtJCo0cmY=; b=HwaO5gX/I/rT2xviokD2Pxo0Q/EAyuwo9pXxtDtSdY9F/wdsf9tvKVrksx1y7ucLgD PKtbqQylPmjYUXCQCbVkLGxJ9HWrotPN0A15SrmT/AjgfQRg5IAZA9wLm9/yksJmWPOM 2t5ibPyFj0RQXeYIYQRE386ecx2bXJGui7P+LXXexBP9KG4nwkOdsskrIajxXTpLyMSY mxnPiV28Rs3SrD2frS8xvo5K10uHlkgxY6gDU+v20FOprKN+hIE+JuZFoUhRcmauzhDl hw55w6KbA7WPgGCuKNOIjMzeV5t5Ybq/jHpYQZj69s2QuCiipxvjh6tiLfdXeRFTKLSw cTqw== |
| MIME-Version | 1.0 |
| X-Received | by 10.66.164.136 with SMTP id yq8mr26742132pab.67.1386665440958; Tue, 10 Dec 2013 00:50:40 -0800 (PST) |
| In-Reply-To | <CAPTjJmoz1A2ASai3sZFXdJ9jaYDV-BGPgfdgGGTz-b4e3uuqKQ@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> <CAPTjJmoz1A2ASai3sZFXdJ9jaYDV-BGPgfdgGGTz-b4e3uuqKQ@mail.gmail.com> |
| Date | Tue, 10 Dec 2013 19:50:40 +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.3815.1386665450.18130.python-list@python.org> (permalink) |
| Lines | 78 |
| NNTP-Posting-Host | 2001:888:2000:d::a6 |
| X-Trace | 1386665450 news.xs4all.nl 2952 [2001:888:2000:d::a6]:52987 |
| X-Complaints-To | abuse@xs4all.nl |
| Xref | csiph.com comp.lang.python:61452 |
Show key headers only | View raw
On Tue, Dec 10, 2013 at 1:21 PM, Chris Angelico <rosuav@gmail.com> wrote: > 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. :) I added the same parenthesizing to the brute force searcher and reran it through 'time'. ~$1 = (($4 or not (($1 and $2) or ($4 and ($1 or $2)))) and (($4 and not (($1 and $2) or ($4 and ($1 or $2)))) or (($2 or not (($1 and $2) or ($4 and ($1 or $2)))) and (($2 and not (($1 and $2) or ($4 and ($1 or $2)))) or not (($2 or ($1 or $4)) and (($2 and ($1 and $4)) or not (($1 and $2) or ($4 and ($1 or $2))))))))) ~$2 = (($4 or not (($1 and $2) or ($4 and ($1 or $2)))) and (($4 and not (($1 and $2) or ($4 and ($1 or $2)))) or (($1 or not (($1 and $2) or ($4 and ($1 or $2)))) and (($1 and not (($1 and $2) or ($4 and ($1 or $2)))) or not (($2 or ($1 or $4)) and (($2 and ($1 and $4)) or not (($1 and $2) or ($4 and ($1 or $2))))))))) ~$4 = (($2 or not (($1 and $2) or ($4 and ($1 or $2)))) and (($2 and not (($1 and $2) or ($4 and ($1 or $2)))) or (($1 or not (($1 and $2) or ($4 and ($1 or $2)))) and (($1 and not (($1 and $2) or ($4 and ($1 or $2)))) or not (($2 or ($1 or $4)) and (($2 and ($1 and $4)) or not (($1 and $2) or ($4 and ($1 or $2))))))))) real 362m12.261s user 362m7.186s sys 0m0.064s Yes, that is indeed six full hours of CPU time for a simple problem. Ha! It seems to have come up with something fairly similar, actually. A bit shorter than the algebraic solution. brute: (($4 or not (($1 and $2) or ($4 and ($1 or $2)))) and (($4 and not (($1 and $2) or ($4 and ($1 or $2)))) or (($2 or not (($1 and $2) or ($4 and ($1 or $2)))) and (($2 and not (($1 and $2) or ($4 and ($1 or $2)))) or not (($2 or ($1 or $4)) and (($2 and ($1 and $4)) or not (($1 and $2) or ($4 and ($1 or $2))))))))) algebra: (((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))) Here's the most notable difference: two_or_three = (a & b) | (a & c) | (b & c) can be simplified to: two_or_three = (a & b) | (c & (a | b)) That's one less gate in an early step. Even applying that change, though, the brute-forced solution is still a bit shorter. Looks like the algebraic solution could have a bit of optimization done! 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