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
| async def scrap_exchanges(): | |
| coins = pd.DataFrame.from_csv('crypto/data/coins.csv') | |
| data = defaultdict(lambda:[]) | |
| chunks = [coins[i: i + 5] for i in range(0, len(coins), 5)] | |
| for chunk in chunks[0:10]: | |
| with concurrent.futures.ThreadPoolExecutor(max_workers=10) as executor: | |
| futures = [loop.run_in_executor(executor, get_exchanges_for_coin, coin.split(":")[0]) for coin in chunk["Coins"]] |
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 shortest_substring(words, text): | |
| total, start, mstart, mend = 0, 0, 0, 0 | |
| min_value = len(text) | |
| counts = defaultdict(int) | |
| for i in range(len(text)): | |
| if text[i] in words: | |
| counts[text[i]] = counts[text[i]] + 1 | |
| if counts[text[i]] == 1: | |
| total = total + 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
| ''' | |
| given a final score in a certain sport, get all the possible scores during | |
| the game. the scoring points are given ahead | |
| ''' | |
| from copy import copy | |
| def get_scores(points, result): | |
| dp = [0 for _ in range(result + 1)] | |
| dp[0] = 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
| ''' | |
| compute the minimum number of removals in order to make the string palindrome | |
| ''' | |
| def palindromic_substring(word): | |
| dp = [[-1 for _ in range(len(word) + 1)] for _ in range(len(word)+1)] | |
| def count_nr_chars(word, i, j, count): | |
| if dp[i][j] != -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
| def keyboard_path(word): | |
| path = [] | |
| current = 'a' | |
| for letter in word: | |
| x,y = get_position(current) | |
| nx, ny = get_position(letter) | |
| path += math.abs(nx - x) * ['down' if nx > x else 'up'] | |
| path += math.abs(ny - y) * ['right' if ny > y else 'left'] |
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 | |
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
| 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
| 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
| 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))) |
OlderNewer