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 itertools | |
from typing import Iterator | |
def sift(ns: Iterator[int]) -> Iterator[int]: | |
p = next(ns) | |
yield p | |
yield from sift(filter(lambda n: n%p != 0, ns)) | |
def primes(): | |
yield from sift(itertools.count(2)) |
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
BIG = 1_000_000.0 | |
SMALL = 1e-12 | |
COUNT = 1_000_000 | |
def big_first(): | |
yield BIG | |
for _ in range(COUNT): | |
yield SMALL |
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
node_modules/ | |
main.js | |
package-lock.json |
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
words = ['peace','piece','geese','tease','spoon'] | |
def ham_dis(word1, word2): | |
return sum(c1 != c2 for c1, c2 in zip(word1, word2)) | |
output = [ | |
[ 'Ham-Dis', *words ], | |
*( | |
[ w1, *(ham_dis(w1, w2) for w2 in words) ] | |
for w1 in 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
' ** PYTHON CODE CHALLENGE - SCHOOL ADMISSIONS ** ' | |
# write code to handle admissions for a school - print results | |
# rules: pass test and interview. If applicant is legacy | |
# passing either test or interview is enough to be admitted | |
# your output should be sorted | |
# output = 'Accepted students: An, Bo, Mo, My, Xi' | |
appl =['Jay','Sam','Vi','Li','My','Xi','On','Mo','An','Bo'] | |
test_ok =['xi','my','sam','an','mo','on'] |
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 <stdio.h> | |
typedef int square; | |
typedef int row; | |
typedef int col; | |
int is_valid_row(row n) | |
{ | |
return ( | |
n == 0b0011 || |
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
t :: Integer -> Float | |
t 0 = 0 | |
t n = sqrt(2 + t(n-1)) | |
p :: Integer -> Float | |
p n = 2**(n+1) * sqrt(2 - t(n)) |
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
interface Thenable<a> { | |
then<b>(cont: (_: a) => Thenable<b>): Thenable<b>; | |
} | |
/* | |
run_slow_task.then((result) => { | |
do_something(result).then((new_result) => { | |
do_something_else(new_result) | |
}) | |
}) |
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 itertools | |
def primes(): | |
def sieve(numbers): | |
try: | |
n = next(numbers) | |
yield n | |
yield from sieve(filter(lambda m: m%n!=0, numbers)) | |
except StopIteration: |
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
#!/usr/bin/env python3 | |
import sys | |
import fileinput | |
import re | |
if sys.argv[2] == "merge": | |
with fileinput.input(sys.argv[1], inplace=True) as f: | |
for line in f: | |
if line.startswith("Merge branch"): |
NewerOlder