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
end_scripts = {"quit", "end", "q"} | |
help_scripts = {"help", "h"} | |
help_doc = """ | |
A reverse polish or postfix calculator evaluates two numbers by the next opertion. | |
For example, the sum of 4 and 5 can be found by entering: 5 4 + | |
Available operations include | |
+ addition |
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
# This will only work on MacOS | |
CIRCUITPY_PWD = "/Volumes/CIRCUITPY" | |
ORIGIN = "code.py" | |
TARGET = CIRCUITPY_PWD + "/code.py" | |
with open(ORIGIN, "r") as origin_file: | |
origin_code = origin_file.read() | |
with open(TARGET, "w") as target_file: |
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
# == Add Python Aliases and Paths ========================================================== | |
# Python 3.6 | |
alias py36="/Library/Frameworks/Python.framework/Versions/3.6/bin/Python3.6" | |
PATH="/Library/Frameworks/Python.framework/Versions/3.6/bin:${PATH}" | |
export PATH | |
# Python 3.7 | |
alias py37="/Library/Frameworks/Python.framework/Versions/3.7/bin/Python3.7" | |
PATH="/Library/Frameworks/Python.framework/Versions/3.7/bin:${PATH}" | |
export PATH | |
# Python 3.8 |
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
fn main() { | |
let mut array = [0, 2, 0, 3, 8]; | |
println!("{:?}", array); // [0, 2, 0, 3, 8] | |
move_zeroes(&mut array); | |
println!("{:?}", array); // [2, 3, 8, 0, 0] | |
} | |
/// `move_zeroes` function | |
/// | |
/// Shifts all elements with a value of zero in the `array` to the end of the `array`. |
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
/// # Rotate Brackets | |
/// | |
/// Given a string of brackets, return a rotation of those brackets that is balanced. | |
/// The numbers of opening and closing brackets will always be equal. | |
/// | |
/// Example | |
/// ``` | |
/// rotate_brackets("]][][["); | |
/// "[[]][]" // First rotation yields "[]][][". Second one yields "[[]][]" | |
/// ``` |
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
""" | |
Given a positive or negative real number, round it to the next whole integer | |
closer to zero. This means if it’s positive, round down, and if it’s negative, | |
round up. Try to do this in as few characters possible! | |
""" | |
def round(number: float) -> int: | |
return int(str(number).split(".")[0]) | |
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
""" | |
Given an integer n, return true if n^3 and n have the same set of digits. | |
""" | |
def same_digits(n: int) -> bool: | |
return set(str(n)) == set(str(n**3)) | |
def print_and_assert(expected, actual): | |
print("expected = " + str(expected)) | |
print("actual = " + str(actual) + "\n") |
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 typing import Iterable | |
def inits(items: Iterable) -> list[Iterable]: | |
"""Given an iterable, returns all of its prefixes in ascending order of length | |
Arguments: | |
items: Iterable items whose prefixes will be returned | |
Returns: | |
list[Iterable] prefixes of the iterable |
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
package main | |
import ( | |
"fmt" | |
"strings" | |
) | |
/* Redistribute Characters to Make All Strings Equal | |
LeetCode 1897: https://leetcode.com/contest/weekly-contest-245/problems/redistribute-characters-to-make-all-strings-equal/ |
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
package longest | |
func longestPrefix(words []string) string { | |
if len(words) == 0 { | |
return "" | |
} | |
common := make([]rune, 0, len(words[0])) | |
for i, letter := range words[0] { | |
for _, word := range words[0:] { |
OlderNewer