This file contains hidden or 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 | |
| c = [(r, s) for s in ["♠️", "♦️", "♣️", "❤️"] for r in ["A", *list(range(2, 11)), "J", "Q", "K"]] | |
| random.shuffle(c) | |
| print("\n".join([f"{str(r).rjust(2, ' ')} {s}" for r, s in c])) |
This file contains hidden or 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
| def coins_can_make_value(coin_dictionary: dict[int, int], value: float) -> bool: | |
| if value == 0: | |
| return True | |
| for coin_value, coin_count in coin_dictionary.items(): | |
| for _ in range(coin_count): | |
| if value >= coin_value: | |
| value -= coin_value | |
| if value == 0: |
This file contains hidden or 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
| with open("./meta_print.py", "r") as file: | |
| for line in file: | |
| print(line, end="") |
This file contains hidden or 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
| use std::io::{self, Write}; | |
| #[derive(Debug, PartialEq)] | |
| enum Weapon { | |
| Rock, | |
| Paper, | |
| Scissors, | |
| } | |
| impl std::fmt::Display for Weapon { |
This file contains hidden or 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 collections import Counter | |
| from random import randint | |
| def visualize(numbers): | |
| counter = Counter(numbers) | |
| max_number_length = len(str(max(numbers))) | |
| for number, count in counter.most_common(): | |
| padded_number = str(number).rjust(max_number_length, "0") | |
| count_visualization = "*" * count |
This file contains hidden or 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
| fn main() { | |
| let items: [Result<i32, &str>; 4] = [Ok(1), Ok(2), Err("Missing Value"), Ok(3)]; | |
| // 1 | |
| let items_result: Result<Vec<_>, _> = items.into_iter().collect(); | |
| match items_result { | |
| Ok(items) => { | |
| for item in items { | |
| println!("{}", item); |
This file contains hidden or 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 shuffle_word(word): | |
| shufflable_characters = [character for character in word if character.isalnum()] | |
| random.shuffle(shufflable_characters) | |
| word = [shufflable_characters.pop(0) if character.isalnum() else character for character in word] | |
| word = "".join(word) | |
| # Sanity check to ensure we've used the exact same number of letters as we initially collected | |
| assert len(shufflable_characters) == 0 |
This file contains hidden or 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
| class IterInt(int): | |
| def __init__(self, integer): | |
| self.integer = integer | |
| def __iter__(self): | |
| return iter(int(character) for character in str(self.integer)) | |
| number = IterInt(4_999_135) | |
| for digit in number: |
This file contains hidden or 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 collections import defaultdict | |
| import random | |
| def get_shrink_rank(word): | |
| if " " in word: | |
| print(word) | |
| raise Exception("Word must be a single word") | |
| if not word.isalpha(): | |
| print(word) |
This file contains hidden or 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
| use counter::Counter; | |
| use defaultmap::DefaultHashMap; | |
| fn counter_example() { | |
| let counter = "Hello, world!".chars().collect::<Counter<_>>(); | |
| for (item, count) in counter.most_common() { | |
| println!("{}: {}", item, count); | |
| } | |
| } |