This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python3 | |
from enum import auto, Enum, unique | |
def fib_recursive(n, calculated_results=None): | |
if calculated_results is not None and n in calculated_results: | |
result = calculated_results[n] | |
else: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from django.contrib.auth.models import AbstractUser | |
from django.db import models | |
from django.db.models.fields.related import ForeignKey | |
from django.utils.translation import ugettext | |
class ArchitectureSupport(models.Model): | |
THIRTY_TWO_BIT_VALUE = 32 | |
SIXTY_FOUR_BIT_VALUE = 64 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import threading | |
import time | |
lock = threading.Lock() | |
def make_cookies(cake_number): | |
"""Instructions for the robot on how to create cookies""" | |
with lock: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import random | |
from datetime import datetime, timedelta | |
def convert_integer_to_date(day_number_offset): | |
beginning_of_year = datetime(year=2021, month=1, day=1) | |
date = beginning_of_year + timedelta(days=day_number_offset) | |
date_string = date.strftime("%B %d") | |
return date_string |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import random | |
from typing import Optional | |
def main() -> None: | |
run_number: int = 0 | |
run_amount: int = 10_000 | |
count_total: int = 0 | |
while run_number < run_amount: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import random | |
cards = [] | |
for suit in ["♠️", "♦️", "♣️", "❤️"]: | |
for rank in ["A", *list(range(2, 11)), "J", "Q", "K"]: | |
cards.append((rank, suit)) | |
random.shuffle(cards) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import random | |
def main(): | |
runs = 100_000 | |
successes = 0 | |
cards = list(range(13)) * 4 | |
for _ in range(runs): | |
random.shuffle(cards) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from timeit import timeit | |
all_are_equal_functions = [ | |
lambda numbers: all(a == b for a, b in zip(numbers, numbers[1:])), | |
lambda numbers: all(number == numbers[0] for number in numbers), | |
lambda numbers: len([number for number in numbers if number != numbers[0]]) == 0, | |
lambda numbers: len(set(numbers)) <= 1, | |
lambda numbers: not numbers or numbers.sort() or numbers[0] == numbers[-1], | |
lambda numbers: not numbers or numbers == ([numbers[0]] * len(numbers)), | |
lambda numbers: not numbers or numbers.count(numbers[0]) == len(numbers), |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import math | |
import random | |
import time | |
SIGNAL_CHAIN = [ | |
lambda sample: sample + 1, | |
lambda sample: sample / 2, | |
lambda sample: math.tan(sample), | |
lambda sample: abs(sample), |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import random | |
class Card: | |
def __init__(self, card_value): | |
self.card_value = card_value | |
def __str__(self): | |
rank_string = self.get_rank_string() | |
rank_string_justified = rank_string.rjust(2, " ") |