<jupyter_start><jupyter_text>**Lab 01**Labs in general are for you to solve short programming challenges in class. In contrast, homework assignments will involve more challenging and lengthy problems.Feel free to ask the TAs for help if there is anything you do not understand. The TAs will go through suggested solutions in the last 15 minutes of the lab - typically by solving them in a live demo. **Your midterm exams will be like this, so it is highly beneficial for you to attend these labs**.The first lab is to gain basic familiarity with Python. - Any library needed has been imported for you- You are not to use any 3rd party library such as `numpy` for the first lab- Do this lab without using the web to search for solutions<jupyter_code>import random
import math

random.seed(123)<jupyter_output><empty_output><jupyter_text>**1**. Write Bayes theorem in $\LaTeX$ using a Markdown cell. $$\Pr(A \mid B) = \frac{\Pr(B \mid A) \Pr(A)}{\Pr(B)}$$ **2**. Create two lists of 100 random integers in the range`[0, 1000]`.  Find all numbers that are shared by the two lists.Note: `randint` includes *both* endpoints<jupyter_code>xs = [random.randint(0, 1000) for i in range(100)]
ys = [random.randint(0, 1000) for i in range(100)]
set(xs).intersection(set(ys))<jupyter_output><empty_output><jupyter_text>**3**. A Pythagorean triplet is a tuple of integers $(a, b, c)$ such that $a^2 + b^2 = c^2$. Find all unique Pythagorean triplets for which $a$ and $b$ are less than 25. For example, $(3,4,5)$ is a Pythagorean triplet.<jupyter_code>import math
triplets = []
for a in range(1, 25):
    for b in range(a, 25):
        c = math.sqrt(a**2 + b**2)
        if c.is_integer():
            triplets.append((a, b, int(c)))
triplets<jupyter_output><empty_output><jupyter_text>**4**. Implement a bubble sort function in Python. Use it to sort the list `[9,1,9,6,6,8,2,4,5,9]`.<jupyter_code>def bubblesort(xs):
    """Bubble sort."""
    
    n = len(xs)
    for i in range(n):
        for j in range(i+1, n):
            if xs[i] > xs[j]:
                xs[i], xs[j] = xs[j], xs[i]
    return xs
xs = [9,1,9,6,6,8,2,4,5,9]
bubblesort(xs)<jupyter_output><empty_output><jupyter_text>**5**. The "Fizz-Buzz test" is an interview question designed to help filter out the 99.5% of programming job candidates who can't seem to program their way out of a wet paper bag. The text of the programming assignment is as follows:```Write a program that prints the numbers from 1 to 100. But for multiples of three print “Fizz” instead of the number and for the multiples of five print “Buzz”. For numbers which are multiples of both three and five print “FizzBuzz”.```Source: "Using FizzBuzz to Find Developers who Grok Coding" http://tickletux.wordpress.com/2007/01/24/using-fizzbuzz-to-find-developers-who-grok-coding/Write the Fizz-Buzz program in Python. Print the 100 encoded numbers in a single line.<jupyter_code>for i in range (1, 101):
    if i % 15 == 0:
        print('FizzBuzz', end=', ')
    elif i % 3 == 0:
        print('Fizz', end=', ')
    elif i % 5 == 0:
        print('Buzz', end=', ')
    else:
        print(i, end=',')<jupyter_output><empty_output><jupyter_text>**6**.Write a function that returns the specified output for the given input.```Input: ['Tokyo', 'London', 'Rome', 'Donlon', 'Kyoto', 'Paris']// YOUR ALGORITHMOutput: [['Tokyo', 'Kyoto'], ['London', 'Donlon'], ['Rome'], ['Paris']]```<jupyter_code>def find_paired(cities):
    """Organize ciites in some way."""

    n = len(cities)
    paired = set([])
    for i in range(n):
        for j in range(i+1, n):
            c1 = cities[i]
            c2 = cities[j]
            if sorted(c1.lower()) == sorted(c2.lower()):
                paired.add((c1, c2))
    paired_ = [x for xs in paired for x in xs]
    unpaired = [[city] for city in cities if not city in paired_]
    return list(map(list, paired)) + unpaired
cities = ['Tokyo', 'London', 'Rome', 'Donlon', 'Kyoto', 'Paris']
find_paired(cities)<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.1345672836418209, 'fraction_numerical': 0.02751375687843922, 'mean_word_length': 3.8064903846153846, 'pattern_counts': {'":': 0, '<': 25, '<?xml version=': 0, '>': 26, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 1, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '6', 'dir': 'jupyter-structured-clean-dedup', 'id': '616014', 'license': 'MIT', 'n_tokens_mistral': 1422, 'n_tokens_neox': 1309, 'n_words': 499, 'path': 'labs/Lab01_Solutions.ipynb', 'repo_name': 'cliburn/sta-662-2020', 'size': '3998'}