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 find_perfect_squares(number): | |
| perfect_squares = {i * i for i in range(sqrt(n)} | |
| for other_i in sqrt(n): | |
| if n - other_i * other_i in perfect_squares: | |
| return True | |
| return False |
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 | |
| class ConversionNotPossible(Exception): | |
| def __init__(self, from_unit, to_unit): | |
| super(Exception).__init__() | |
| self.from_unit = from_unit | |
| self.to_unit = to_unit | |
| def __repr__(self) -> str: |
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 functools import lru_cache | |
| def minCut(s: str) -> int: | |
| def is_palindrome(start, end): | |
| while start < end: | |
| if s[start] != s[end]: | |
| return False | |
| start += 1 |
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 threading | |
| import time | |
| def do_something_random_until_stopped(event): | |
| counter = 0 | |
| elapsed = time.time() | |
| while not event.isSet(): | |
| print(f"I am at {counter}") | |
| counter += 1 |
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
| <!DOCTYPE html> | |
| <html> | |
| <head> | |
| <meta name="viewport" content="width=device-width" /> | |
| <title>ngErrorRedirect</title> | |
| </head> | |
| <body> | |
| <div> | |
| Error | |
| </div> |
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
| npost = nrow(filter(df, Impact==1)) | |
| mm = mean(filter(df, Impact==1)$AbundanceRate) | |
| ll = mm - qnorm(1 - alpha/2) * sd(filter(df, Impact==1)$AbundanceRate)/sqrt(npost) | |
| uu = mm + qnorm(1 - alpha/2) * sd(filter(df, Impact==1)$AbundanceRate)/sqrt(npost) | |
| print(paste("lower", round(ll, 2))) | |
| print(paste("upper", round(uu, 2))) |
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
| sequence=""" | |
| SRSRRSSRSRSSRSSRRSSRSSSSSRSSRSSRSRSSRSSRSSSSSSSSRSSRSSSSSRSSRSSRRSSRSSSSSRSSRSSRSSSSSSSSSSSSSSSSSRSSRSSRS | |
| """ | |
| from fractions import Fraction | |
| def decode(seq): | |
| x = 0 | |
| for nr in seq: | |
| if nr == 'S': |
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
| CURRENT_AGE = 27 | |
| BLOOMBERG_MULTIPLICATION_RATE = 2 | |
| ESTIMATED_INFLATION_RATE = 0.03 | |
| TAX_FREE_AMOUNT = 0.25 | |
| ESTIMATED_TAX_VALUE = 0.35 | |
| ANUAL_INVESTMENT = 10000 | |
| def years_until_retirement(): | |
| return 55 - CURRENT_AGE |
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 heapq import heappop, heappush | |
| class Solution: | |
| def handle_end(self, h, res, item): | |
| end, height = item | |
| while len(h) != 0 and h[0][1] <= end: | |
| heappop(h) | |
| if res[-1][1] == 0 or (len(h) != 0 and abs(h[0][0]) >= height): | |
| return |
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
| ''' | |
| given a function and a value y, find the bext x for which |f(x) - y| is minimal | |
| ''' | |
| def get_boundaries(func, y): | |
| # x * x > max_value #overflow | |
| # sqrt(max_value) < x # next x will be overflow | |
| # in python this is not an issue but it could be in some other languages | |
NewerOlder