ICAI Code (Python 3)

The following code was written in Python 3.7 in a Linux environment. To download the .py file directly, click here.

""" icai_oeis.py

AUTHOR:
    Nicholas P. Taliceo
    EMAIL:                      WEB:
    ntaliceo@gmail.com          www.NicholasTaliceo.com

DATE:
    Date Created:   09-08-2019
    Date Modified:

VERSION HISTORY:
    v-01:   Initialization
"""


# Construction definitions for p, e, and M(n) first
def pCalc(n):
    """
    :param n: the number of tiles in a polyplet
    :return p: a variable used to calculate M(n)
    """
    global p
    p = 1        # Default value of p
    p_list = []  # List of qualifying p - take the largest

    while n >= 7*(p**2) - (10*p) + 4:
        p_list.append(p)
        p += 1

    p = max(p_list)
    return(p)


def eCalc(n, p):
    """
    :param n: the number of tiles in a polyplet
    :param p: a variable used to calculate M(n); calculated in pCalc(n)
    :return e: a variable used to calculate M(n)
    """
    global e

    if n == 7*(p**2) - 10*p + 4:
        e = 0
    elif 7*(p**2) - 10*p + 4 < n <= 7*(p**2) - 9*p + 3:
        e = 1
    elif 7*(p**2) - 9*p + 3 < n <= 7*(p**2) - 8*p + 2:
        e = 2
    elif 7*(p**2) - 8*p + 2 < n <= 7*(p**2) - 7*p + 2:
        e = 3
    elif 7*(p**2) - 7*p + 2 < n <= 7*(p**2) - 6*p + 1:
        e = 4
    elif 7*(p**2) - 6*p + 1 < n <= 7*(p**2) - 5*p + 1:
        e = 5
    elif 7*(p**2) - 5*p + 1 < n <= 7*(p**2) - 4*p + 1:
        e = 6
    elif 7*(p**2) - 4*p + 1 < n <= 7*(p**2) - 3*p:
        e = 7
    elif 7*(p**2) - 3*p < n <= 7*(p**2) - 2*p:
        e = 8
    elif 7*(p**2) - 2*p < n <= 7*(p**2) - p:
        e = 9
    elif 7*(p**2) - p < n <= 7*(p**2):
        e = 10
    elif 7*(p**2) < n <= 7*(p**2) + p:
        e = 11
    elif 7*(p**2) + p < n <= 7*(p**2) +2*p:
        e = 12
    elif 7*(p**2) +2*p < n <= 7*(p**2) + 3*p:
        e = 13
    elif n > 7*(p**2) + 3*p:
        e = 14

    return(e)


def calcM(n, p, e):
    """
    Calculates M(n) - the number of intercardinal adjacencies in a polyplet with n tiles
    Calculated using the formula M(n) = 4n - 14p + 10 - e
    """
    global M
    M = 4*n - 14*p + 10 - e

    print("M(%d) = %d" % (n, M))
    return M


"""
Choose one of the code blocks below. See comments for implementation usage.
"""

# For interactive n/M(n) user query, use this code:
new_value = True
while new_value == True:
    while True:
        try:
            n = int(input("What is the value of n? "))
            calcM(n, pCalc(n), eCalc(n, p))
            break
        except ValueError:
            print("n must be an integer!")

    # Ask the user to input another value for n
    rerun = input("Input another n-value (Y/N): ")
    if rerun.lower() == "y" or rerun.lower() == "yes":
        new_value == True
    else:
        new_value == False
        input("The script is finished. Press any key to continue. ")
        break


# Returns a list of M(n) from a predefined range of n
# for n in range(1, 101):
#     # Prints results to terminal
#     calcM(n, pCalc(n), eCalc(n,p))

# Returns a list of M(n) for a specific list of n
# for n in [50, 100, 250, 500, 750, 1000]:
#     # Prints results to terminal
#     calcM(n, pCalc(n), eCalc(n,p))
css.php