Skip to content

Instantly share code, notes, and snippets.

View ashleighbasil's full-sized avatar

Ashleigh ashleighbasil

View GitHub Profile
@ashleighbasil
ashleighbasil / dequeue_stocks.py
Created February 2, 2021 07:30
Solution to cassidoo newsletter problem
def stockQueue(snapshot):
dequeued_snapshot = {
stock['sym']:stock['cost'] for stock in snapshot
}
return [
{
'sym':stock,
'cost': cost
} for stock, cost in dequeued_snapshot.items()
@ashleighbasil
ashleighbasil / productlist.py
Created February 8, 2021 08:06
ProductList solution to cassidoo puzzle
import math
class ProductList:
def __init__(self):
self.numbers = []
def add(self, number):
self.numbers.append(number)
def product(self, m):
@ashleighbasil
ashleighbasil / make_sentence.py
Created February 15, 2021 07:38
Solution to Cassidoo make sentence puzzle :D :D :D
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,
@ashleighbasil
ashleighbasil / every_other.h
Created February 23, 2021 02:32
Cassidoo newsletter every other toy problem
int every_other(char *str) {
// Empty string edge case
if (!(*str)) return 0;
char current = *str;
int counter = 0;
str++;
while (*str) {
@ashleighbasil
ashleighbasil / list_comprehension_vs_js_methods.sh
Created February 24, 2021 17:14
Prove aziz wrong on Twitter about comprehension speed
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
@ashleighbasil
ashleighbasil / paint.py
Created March 2, 2021 06:56
cassidoo newsletter paint problem
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):
const express = require('express')
var cors = require('cors')
const PORT = process.env.PORT || 5000
const viewLog = []
express()
.use(cors())
.get('/ping', (req, res) => {
@ashleighbasil
ashleighbasil / max_num.py
Created March 22, 2021 06:38
Cassido broken solution!
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(
@ashleighbasil
ashleighbasil / move_zeroes.rs
Created April 19, 2021 03:52
Cassidoo move zeroes solution :3
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);
@ashleighbasil
ashleighbasil / one_liner.py
Created May 31, 2021 17:57
Python version of Haskell's inits function (for cassidoo newsletter puzzle)
def inits(lst): return [lst[:i] for i in range(len(lst)+1)]