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 ics import Calendar, Event | |
import datetime | |
from lunarcalendar import Converter, Solar, Lunar, DateNotExist | |
c = Calendar() | |
for i in range(2020, 2100): | |
lunar = Lunar(i, 7, 7) | |
d = Converter.Lunar2Solar(lunar) | |
str_d = d.to_date().strftime('%Y-%m-%d 00:00:00') | |
e = Event() |
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 os | |
import time | |
import shutil | |
import signal | |
import sys | |
############# Fill this Box ################### | |
# source_directory: folder which containers files to grab from | |
# target_directory: folder where to store files |
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
# So, you want to learn MinHeap. Here's an example of min heap. | |
# Sometimes you panic when you see so many lines of code, but trust me it is worth to read. | |
# Because there are only three operations: get peek, add item, and poll item. | |
# The functions are well divided in small functions, very simple, easy to understand. | |
class MinHeap(): | |
def __init__(self): | |
self.arr = [] | |
def peek(self): | |
if self._is_empty(): |
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
#include <stdlib.h> | |
#include <stdio.h> | |
#include <string.h> | |
#include <stdint.h> | |
#include <stdbool.h> | |
#define MAX_NAME 256 | |
#define TABLE_SIZE 10 | |
typedef struct { |
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
BANK_ACCOUNT = "steven" | |
PASSWORD = "123456" | |
failed_attempts = 0 | |
balance = 1000 | |
def welcome(): | |
print("Welcome to my ATM machine!") | |
def get_bank_account(): |
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 os | |
GAME_BOARD = [[' '] * 3 for _ in range(3)] | |
COL = ROW = 3 | |
def print_game_board(): | |
count_row = 0 | |
for row in GAME_BOARD: | |
a_row = "" | |
for col in row: |
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
# 加载 math 库,这个库有很多有用的模块可以用。你可以在本次作业中使用 | |
# math.isclose(a, b, rel_tol=1e-10) 来比较 a 和 b。并且只比较到小数点后10位。 | |
# 例如 math.isclose(5.0, 4.99998, rel_tol=1e-10) 会返回 True, 意思是 5.0 跟 4.99998 足够相似了。 | |
# 如果你认为你不需要这个函数,可以忽略它。 | |
import math | |
# 在此处定义你的 `expected_value` 函数 | |
# def .... | |
# ..... |
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
class Solution: | |
def solveNQueens(self, n: int) -> List[List[str]]: | |
leftright = [0] * (2 * n - 1) | |
rightleft = [0] * (2 * n - 1) | |
row = [0] * n | |
col = [0] * n | |
def valid(board, x, y): | |
return not ( | |
row[x] or col[y] |
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
class Solution: | |
def countOfAtoms(self, formula: str) -> str: | |
i = 0 | |
ans = "" | |
def _countOfAtoms(formula): | |
nonlocal i | |
counts = defaultdict(int) | |
while i < len(formula): | |
if formula[i] == "(": |