Proposed OEIS adapter for searching integer sequences
- Dominant language
- Python
- Stars
- 41.7k
- Forks
- 1.9k
- PR merge metrics
- No merged PRs in 30d
Description
## Todo
* [x] define query format
* [x] implement query format using an external adapter
* [x] fix syntax highlighting
* [x] add oeis cheat sheet with query format description and examples
- [x] Occasional formatting mishaps [BAD](http://cheat.sh/oeis/9/mathematica/) instead of [GOOD](http://cheat.sh/oeis/a9/mathematica/)
- [x] Bibliography sources should be names (ignore and consolidate different dates with same name)
- [x] When stress testing: ```curl cheat.sh/oeis/$RANDOM/mathematica``` continually ended up with misplaced error messages (seemingly from ```grep```)
Adapter:
* [X] Remove pygmentize calls
* [x] Add language selection for code samples
* [x] Limit number of terms shown for sequence sample (implemented?)
cheat.sheets:
* [X] add OEIS languages names
## Details
[The On-Line Encyclopedia of Integer Sequences](https://oeis.org/) is a great resource for programmers. It'd be cool to browse sequences from the command line and potentially get code samples to copy and paste. I have a working prototype of the script [here](https://github.com/ErezBinyamin/Scripts/blob/master/tools/oeis.sh). Currently it can either take one argument or many. If many are supplied, a list of potential sequence matches is returned, of one argument is supplied, then the sequence with that ID and a colorized code segment are returned.
# Example usage finding a sequence by pattern
```bash
curl cht.sh/oeis/1+1+2+1+1+3+3+1
```
> A007318: Pascal's triangle read by rows: C(n,k) = binomial(n,k) = n!/(k!*(n-k)!), 0 <= k <= n.
> 1, 1, 1, 1, 2, 1, 1, 3, 3, 1, 1, 4, 6, 4, 1, 1, 5, 10, 10, 5, 1, 1, 6, 15, 20, 15, 6, 1, 1, 7, 21, 35, 35, 21, 7, 1, 1, 8, 28, 56, 70, 56, 28, 8, 1, 1, 9, 36, 84, 126, 126, 84, 36, 9, 1, 1, 10, 45, 120, 210, 252, 210, 120, 45, 10, 1, 1, 11, 55, 165, 330, 462, 462, 330, 165, 55, 11, 1
>
> A061554: Square table read by antidiagonals: a(n,k) = binomial(n+k, floor(k/2)).
> 1, 1, 1, 2, 1, 1, 3, 3, 1, 1, 6, 4, 4, 1, 1, 10, 10, 5, 5, 1, 1, 20, 15, 15, 6, 6, 1, 1, 35, 35, 21, 21, 7, 7, 1, 1, 70, 56, 56, 28, 28, 8, 8, 1, 1, 126, 126, 84, 84, 36, 36, 9, 9, 1, 1, 252, 210, 210, 120, 120, 45, 45, 10, 10, 1, 1, 462, 462, 330, 330, 165, 165, 55, 55, 11, 11, 1, 1
# Example usage looking up a particular sequence by ID
```bash
curl cht.sh/oeis/A007318
```
> ID: A007318
> Pascal's triangle read by rows: C(n,k) = binomial(n,k) = n!/(k!*(n-k)!), 0 <= k <= n.
>
> 1, 1, 1, 1, 2, 1, 1, 3, 3, 1, 1, 4, 6, 4, 1, 1, 5, 10, 10, 5, 1, 1, 6, 15, 20, 15, 6, 1, 1, 7, 21, 35, 35, 21, 7, 1, 1, 8, 28, 56, 70, 56, 28, 8, 1, 1, 9, 36, 84, 126, 126, 84, 36, 9, 1, 1, 10, 45, 120, 210, 252, 210, 120, 45, 10, 1, 1, 11, 55, 165, 330, 462, 462, 330, 165, 55, 11, 1
>
> (AXIOM)
> )set expose add constructor OutputForm
> pascal(0, n) == 1
> pascal(n, n) == 1
> pascal(i, j | 0 < i and i < j) == pascal(i-1, j-1) + pascal(i, j-1)
> pascalRow(n) == [pascal(i, n) for i in 0..n]
> displayRow(n) == output center blankSeparate pascalRow(n)
> for i in 0..20 repeat displayRow i
> (PARI) C(n, k)=binomial(n, k)
> (Python)
> def C(n, k):
> if k < 0 or k > n:
> return 0
> res = 1
> for i in range(k):
> res *= (n - i)
> return res
> def C(n, k): from numpy import prod; return prod([(n-j)/(j+1) for j in range(k)])
> def C(n, k): from functools import reduce; return reduce(lambda x, y: x*(n-y)
> (Haskell)
> a007318 n k = a007318_tabl !! n !! k
> a007318_row n = a007318_tabl !! n
> a007318_list = concat a007318_tabl
> a007318_tabl = iterate (
> (Maxima) create_list(binomial(n, k), n, 0, 12, k, 0, n);
> (Sage) def C(n, k): return Subsets(range(n), k).cardinality()
> (MAGMA)
> (GAP) Flat(List([0..12], n->List([0..n], k->Binomial(n, k))));
Contributor guide
Assessment
This issue has not been assessed yet.