McCulloch's second machine
McCulloch's second machine
def mcculloch(digits):
Esoteric
tongue-in-cheek manner how some deceptively simple
wielder the powers of universal computation. Introduced by Raymond Smullyan in one of his clandestine brain teasers on logic and computability, McCulloch's second machine is a string
rewriting system that receives a string of digits between one and nine. The rewrite rule applied to the rest of the digits (denoted below by X) depends on the first digit. Notice how rule for the leading digit 2 is applied to X itself, whereas rules for the leading digits 3 to 5 are applied to
Y=mcculloch(X). This function should return None whenever X or Y is None.
![Form of
Formula for the expected result (computational operation)
digits
2x
quoting
3X
Y + '2' + Y
concatenation with separator mark
4X
Y[::-1]
reversal
Y + Y
concatenation
anything else
None
N/A
digits
Expected result
'329'
'929'
'53231'
'3123131231'
4524938'
'83948394'
'343424859355'
'4859355248593552485935524859355'
'433342717866'
'71786627178662717866271786627178662717866271
78662717866'](/v2/_next/image?url=https%3A%2F%2Fcontent.bartleby.com%2Fqna-images%2Fquestion%2Fb9ec6203-7441-453e-8993-3e6380986f00%2Fa08412f9-b062-4507-ba20-360cfec22a94%2Fc7um3hm_processed.png&w=3840&q=75)
![](/static/compass_v2/shared-icons/check-mark.png)
Trending now
This is a popular solution!
Step by step
Solved in 4 steps
![Blurred answer](/static/compass_v2/solution-images/blurred-answer.jpg)
![Database System Concepts](https://www.bartleby.com/isbn_cover_images/9780078022159/9780078022159_smallCoverImage.jpg)
![Starting Out with Python (4th Edition)](https://www.bartleby.com/isbn_cover_images/9780134444321/9780134444321_smallCoverImage.gif)
![Digital Fundamentals (11th Edition)](https://www.bartleby.com/isbn_cover_images/9780132737968/9780132737968_smallCoverImage.gif)
![Database System Concepts](https://www.bartleby.com/isbn_cover_images/9780078022159/9780078022159_smallCoverImage.jpg)
![Starting Out with Python (4th Edition)](https://www.bartleby.com/isbn_cover_images/9780134444321/9780134444321_smallCoverImage.gif)
![Digital Fundamentals (11th Edition)](https://www.bartleby.com/isbn_cover_images/9780132737968/9780132737968_smallCoverImage.gif)
![C How to Program (8th Edition)](https://www.bartleby.com/isbn_cover_images/9780133976892/9780133976892_smallCoverImage.gif)
![Database Systems: Design, Implementation, & Manag…](https://www.bartleby.com/isbn_cover_images/9781337627900/9781337627900_smallCoverImage.gif)
![Programmable Logic Controllers](https://www.bartleby.com/isbn_cover_images/9780073373843/9780073373843_smallCoverImage.gif)