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
def asterisk_arrow(size): | |
spaces = range(size) | |
for i in [*spaces, *spaces[-2::-1]]: | |
print(f'{" " * i}*') |
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
def inits(lst): return [lst[:i] for i in range(len(lst)+1)] |
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 move_zeroes(arr: &mut Vec<i32>) -> Vec<i32> { | |
arr.sort_by_key(|n: &i32| n == &0); | |
arr.to_vec() | |
} | |
// How to use it: | |
fn main() { | |
let mut xs: Vec<i32> = vec![1, 0, 0, 5, 3, 0]; | |
move_zeroes(&mut xs); | |
println!("{:?}", xs); |
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
def digits_list_to_int(digits): | |
return int("".join([str(i) for i in digits])) | |
def max_num(n, m, k): | |
return digits_list_to_int( | |
sorted(n + m)[::-1][:k] | |
) | |
def max_num_uniq(n, m, k): | |
return digits_list_to_int( |
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
const express = require('express') | |
var cors = require('cors') | |
const PORT = process.env.PORT || 5000 | |
const viewLog = [] | |
express() | |
.use(cors()) | |
.get('/ping', (req, res) => { |
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 math import ceil | |
def surface_area(l, w, h): | |
return 2 * (w*l+h*l+h*w) | |
# only four walls and roof, we don't paint floor | |
def room_surface(l, w, h): | |
return surface_area(l, w, h) - (2 * l * w) | |
def number_of_cans(room, can_coverage): |
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
ash@ly:~$ python3 | |
Python 3.8.5 (default, Jul 28 2020, 12:59:40) | |
[GCC 9.3.0] on linux | |
Type "help", "copyright", "credits" or "license" for more information. | |
>>> from time import perf_counter | |
>>> lst = range(10_000) | |
>>> before = perf_counter(); _=[i for i in lst if i % 2]; perf_counter() - before | |
0.0010968240001147933 | |
## compare to JS |
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
int every_other(char *str) { | |
// Empty string edge case | |
if (!(*str)) return 0; | |
char current = *str; | |
int counter = 0; | |
str++; | |
while (*str) { |
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
def make_sentence(string, words, current=[], final=[]): | |
# Base case | |
if string == '': | |
final.append(current) | |
for word in words: | |
if string[:len(word)] == word: | |
make_sentence( | |
string[len(word):], | |
words, |
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 math | |
class ProductList: | |
def __init__(self): | |
self.numbers = [] | |
def add(self, number): | |
self.numbers.append(number) | |
def product(self, m): |
NewerOlder