Path: csiph.com!usenet.pasdenom.info!weretis.net!feeder4.news.weretis.net!rt.uk.eu.org!newsfeed.xs4all.nl!newsfeed2.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.004 X-Spam-Evidence: '*H*': 0.99; '*S*': 0.00; 'python.': 0.02; 'received:134': 0.05; 'binary': 0.07; 'suppose': 0.07; 'solution,': 0.09; 'tackle': 0.09; 'type,': 0.09; 'boolean': 0.16; 'digits.': 0.16; 'i1,': 0.16; 'i2,': 0.16; 'subject:Programming': 0.16; 'thought.': 0.16; 'values:': 0.16; 'bit': 0.19; 'input': 0.22; 'coding': 0.22; 'python?': 0.22; 'header:User-Agent:1': 0.23; 'guys': 0.24; 'question': 0.24; 'appreciated': 0.26; 'header :In-Reply-To:1': 0.27; "i'm": 0.30; 'code': 0.31; 'maybe': 0.34; 'problem': 0.35; 'subject:with': 0.35; 'advice': 0.35; 'but': 0.35; 'possible': 0.36; 'should': 0.36; 'two': 0.37; 'to:addr :python-list': 0.38; 'to:addr:python.org': 0.39; 'how': 0.40; 'even': 0.60; 'easy': 0.60; 'most': 0.60; 'new': 0.61; 'kind': 0.63; 'group,': 0.63; 'combining': 0.68; 'circuit': 0.84; 'pardon': 0.84 X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: AogFAOApp1KGuA9G/2dsb2JhbABZs3uGLoMGgTODGgEFeBELIRYPCQMCAQIBRRMIAheHZ7sEhhAXjwwWhB4EmBSGLotlgyo Date: Tue, 10 Dec 2013 15:25:42 +0100 From: Antoon Pardon User-Agent: Mozilla/5.0 (X11; Linux i686; rv:17.0) Gecko/20131005 Icedove/17.0.9 MIME-Version: 1.0 To: python-list@python.org Subject: Re: Programming puzzle with boolean circuits References: In-Reply-To: Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: Lines: 37 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1386687123 news.xs4all.nl 2932 [2001:888:2000:d::a6]:41117 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:61471 Op 09-12-13 12:49, Johannes Bauer schreef: > Hi group, > > it's somewhat OT here, but I have a puzzle to which I would like a > solution -- but I'm unsure how I should tackle the problem with Python. > But it's a fun puzzle, so maybe it'll be appreciated here. > > The question is: How do you design a boolean circuit that contains at > most 2 NOT gates, but may contain as many AND or OR gates that inverts > three inputs? IOW: Build three inverters by using only two inverters > (and an infinite amount of AND/OR). > > Surprisingly, this is possible (and I even know the solution, but won't > give it away just yet). > > I found this puzzle again and was thinking about: How would I code a > brute-force approach to this problem in Python? And to my surprise, it > isn't as easy as I thought. So I'm looking for some advice from you guys > (never huts to improve ones coding skills). Well I would make some kind of connecter type, that would have a binary vector associated with it. How do we calculate bit n of a connector? Take the three input signals, i0, i1, i2, these can be seen as a binary digits. So suppose we have input 0, 1, 0 then bit 2 of the connector would be the value of that connector with these input signals. The original three connectors would have the following values: 01010101, 00110011, 00001111. What you can do now is make new connectors by combining them with an or, and or not port and search for those whose value is 10101010, 11001100 and 11110000. -- Antoon Pardon