Skip to content

Instantly share code, notes, and snippets.

@dabeaz
dabeaz / lala.py
Last active August 20, 2024 07:20
Some lambdas
# Author: David Beazley (https://www.dabeaz.com)
# Twitter: @dabeaz
from functools import reduce
run = lambda s: reduce(lambda *_:..., iter(lambda s=[s]:
(_:=s.pop()(),s.append(_))[0], None))
const = lambda v,c : lambda: c(v)
add = lambda x,y,c : lambda: c(x+y)
mul = lambda x,y,c : lambda: c(x*y)
@barrysmyth
barrysmyth / oeis.py
Last active June 4, 2023 13:59
Two functions to programmatically search for matching sequences on the OEIS and to lookup a given sequence (by id) on the OEIS.
import requests
from lxml import html
def search(seq, n=10, m=10):
"""Search the OEIS for sequences matching seq and return a list of results.
Args:
seq: list of integers
n: number of results to return.
m: number of terms to return per result.