+1 (315) 557-6473 

Program To Build a Crossword and Logarithmic Program Solution Assignment Solution.


Instructions

Objective
Write a Python assignment program to build a crossword and logarithmic program solution.

Requirements and Specifications

Crossword and logarithmic program solution in python solution

Source Code

TASK 1

import numpy as np

limit = 100000

count = 0

for _ in range(limit):

    deck = [value for value in range(1,14) for _ in range(4)]

    deck = np.array(deck)

    positions = np.random.choice(range(52), replace = False, size = 5)

    hand = deck[positions]

    if len(set(hand)) == 4:

        count += 1

        # print("This is one pair.", hand)

print("Calculated one pair probability: ", str(float(count)/limit))

print("One pair probability from Wikipedia: 0.422569")

TASK 2

import numpy as np

limit = 100000

count = 0

for _ in range(limit):

    row = 0

    length = 0

    while row < 5:

        length += 1

        if np.random.randint(2) == 1:

            row += 1

        else:

            row = 0

    count += length

print("Average waiting time: ", str(float(count)/limit))

TASK 3

import matplotlib.pyplot as plt

import numpy as np

f = open('crossword.txt')

result = []

for word in f.readlines():

    d = set()

    for w in word:

        if w.isalpha():

            d.add(w)

    result.append(len(d))

a = np.array(result)

plt.hist(a, bins=np.max(a))

plt.title("histogram")

print('Minimum number of distinct letters: ', str(np.min(a)))

print('Number of words with minimum number of distinct letters: ', str(np.count_nonzero(a == np.min(a))))

plt.show()

TASK 4

def attack(p, a, pubA):

    curr = a

    for i in range(1, p):

        if curr == pubA:

            return i

        curr = (curr * a) % p

    return -1

p = 619

a = 2

A = 521

print("Alice's private key: ", str(attack(p, a, A)))

B = 190

print("Bob's private key: ", str(attack(p, a, B)))

C = 622542

p = 1000003

g = 1997

print("Your private key: ", str(atta