Results 1 to 6 of 6

Thread: Python 3 --> Ackermann Function

  1. #1
    thinBasic MVPs danbaron's Avatar
    Join Date
    Jan 2010
    Location
    California
    Posts
    1,378
    Rep Power
    152

    Python 3 --> Ackermann Function

    [font=courier new][size=8pt]Here is a program that does exactly the same thing as the thinBasic script, here:

    http://community.thinbasic.com/index.php?topic=3403.0

    Only, this one is written in Python 3.

    (Python 3.x is not necessarily backwardly compatible with Python 2.x.)


    Dan :P

    [code=python]#------------------------------------------------------

    def ack1(m, n):
    if (m < 0) or (n < 0):
    return -1
    if m == 0:
    return n + 1
    if n == 0:
    return ack1(m - 1, 1)
    return ack1(m - 1, ack1(m, n - 1))

    #------------------------------------------------------

    def ack2(m, n):
    s = &#91;]

    if (m < 0) or (n < 0):
    return -1

    while 1:

    if m == 0:
    if len(s) == 0:
    return n + 1
    else:
    m = s.pop(0)
    n += 1
    continue

    if n == 0:
    m -= 1
    n = 1
    continue

    s.insert(0, m - 1)
    n -= 1

    #------------------------------------------------------

    print(" ack1 ack2")
    print()
    for i in range(0, 4):
    for j in range(0, :
    print('ack(%1d, %1d) = %04d %04d' % (i, j, ack1(i, j), ack2(i, j)))
    print('ack(%1d, %1d) = %04d %04d' % (4, 0, ack1(4, 0), ack2(4, 0)))

    print()
    print("Done.")
    print("Press a key.")
    input()

    #------------------------------------------------------
    [/code]
    "You can't cheat an honest man. Never give a sucker an even break, or smarten up a chump." - W.C.Fields

  2. #2
    thinBasic MVPs kryton9's Avatar
    Join Date
    Nov 2006
    Location
    Naples, Florida & Duluth, Georgia
    Age
    67
    Posts
    3,869
    Rep Power
    404

    Re: Python 3 --> Ackermann Function

    Please tell me they got rid of using underscores and double underscores. That is why I never really got into python, I see that in the code listings and it pushes me away.
    Acer Notebook: Win 10 Home 64 Bit, Core i7-4702MQ @ 2.2Ghz, 12 GB RAM, nVidia GTX 760M and Intel HD 4600
    Raspberry Pi 3: Raspbian OS use for Home Samba Server and Test HTTP Server

  3. #3
    thinBasic MVPs danbaron's Avatar
    Join Date
    Jan 2010
    Location
    California
    Posts
    1,378
    Rep Power
    152

    Re: Python 3 --> Ackermann Function

    [font=courier new][size=8pt]I'd like to be able to tell you that, Kent, but I don't think I can.

    I don't like any kind of underscores.

    For instance, I don't like the identifier, "long_black_train".

    One thing I like about Lisp, is that you can have dashes ("-") in names. And, the language uses them for its library functions. So, you could have the identifier, "long-black-train".

    For my own identifiers, I never make one that requires me to use the shift key. And, I don't know how to type, either. I use only one finger from each hand. And, normally, I never indent any code (Python forces you to, but, I got the Wingware Personal Python IDE ($35), and it does it for you).

    I do remember that Python uses built-in identifiers, like, "__self__", (4 underscores). I agree, they test your patience.

    Some languages force you to use mixed case, like, "openWindow" (Java). That is almost beyond my capacity.

    Here are the changes in Python 3.0.

    http://docs.python.org/py3k/whatsnew/3.0.html

    "You can't cheat an honest man. Never give a sucker an even break, or smarten up a chump." - W.C.Fields

  4. #4
    thinBasic MVPs kryton9's Avatar
    Join Date
    Nov 2006
    Location
    Naples, Florida & Duluth, Georgia
    Age
    67
    Posts
    3,869
    Rep Power
    404

    Re: Python 3 --> Ackermann Function

    Looks like they removed some underscores and put them back in other places, too bad.

    Acer Notebook: Win 10 Home 64 Bit, Core i7-4702MQ @ 2.2Ghz, 12 GB RAM, nVidia GTX 760M and Intel HD 4600
    Raspberry Pi 3: Raspbian OS use for Home Samba Server and Test HTTP Server

  5. #5

    Re: Python 3 --> Ackermann Function


    _I_ use a few of these scruffy beasts in Oxygen for system variables and labels. Normally you will never see them. The underscores are there to prevent conflicts with user defined names.

    __Charles

  6. #6
    thinBasic MVPs kryton9's Avatar
    Join Date
    Nov 2006
    Location
    Naples, Florida & Duluth, Georgia
    Age
    67
    Posts
    3,869
    Rep Power
    404

    Re: Python 3 --> Ackermann Function

    I know Charles, that is what Python does too to some extent. I would rather see something like sysName instead of _Name_ or resName for reserved or even them spelled out systemName or reservedName a lot easier on the eyes if you ask me. Look at this code from python, yikes!
    [code=python]>>> class MyClass():
    ... def __init__(self):
    ... self.__superprivate = "Hello"
    ... self._semiprivate = ", world!"
    ...
    >>> mc = MyClass()
    >>> print mc.__superprivate
    Traceback (most recent call last):
    File "<stdin>", line 1, in <module>
    AttributeError: myClass instance has no attribute '__superprivate'
    >>> print mc._semiprivate
    , world!
    >>> print mc.__dict__
    {'_myClass__superprivate': 'Hello', '_semiprivate': ', world!'}[/code]
    Acer Notebook: Win 10 Home 64 Bit, Core i7-4702MQ @ 2.2Ghz, 12 GB RAM, nVidia GTX 760M and Intel HD 4600
    Raspberry Pi 3: Raspbian OS use for Home Samba Server and Test HTTP Server

Similar Threads

  1. Ackermann function
    By danbaron in forum Sources, Templates, Code Snippets, Tips and Tricks, Do you know ...
    Replies: 0
    Last Post: 21-05-2010, 04:30

Members who have read this thread: 0

There are no members to list at the moment.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •