This file contains hidden or 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
# Finding roots of polynomials in p-adic integers using Hensel's lemma | |
from padic import * | |
from poly import * | |
def roots(p, poly): | |
'Yield all roots of polynomial in the given p-adic integers.' | |
for root in xrange(p): | |
try: | |
yield PAdicPoly(p, poly, root) |
This file contains hidden or 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
/* | |
* Search for integer a in sorted array arr[n] similarly to Newton's method | |
*/ | |
int newtonsearch(int *arr, int n, int a) | |
{ | |
int i = 0; | |
while (i >= 0 && i < n) { | |
if (arr[i] == a) | |
return i; | |
i -= (arr[i] - a) / (arr[i + 1] - arr[i]); // TODO check for boundary conditions, zero denominator, rounding errors |
This file contains hidden or 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
/* | |
* Verifies the Collatz conjecture up to N positive integers. | |
* The program searches backwards starting from 1 to form a tree, where each integer n has children 2n and (n-1)/3 if odd, | |
* and then searching this tree breadth-first without forming it. | |
*/ | |
#include <stdio.h> | |
#include <stdlib.h> | |
#define N 1000 |
This file contains hidden or 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
// Tries are implemented as objects containing values and maps of letters to a value or subtrie. | |
// Construct trie from given list of strings (optional, defaults to 0) | |
function Trie(strings) { | |
this.value = null; | |
this.nodes = {}; | |
if (strings !== undefined) | |
for (var str in strings) | |
this.addString(str); |
This file contains hidden or 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
/* | |
* The following is an implementation of the finite field GF(2^8) as bit vectors of length 8, where the nth bit represents the | |
* coefficient of the nth power of the generator in each element, and the generator satisfies the minimal polynomial | |
* x^8 + x^4 + x ^3 + x^2 + 1 in the prime field Z_2, in which addition is equivalent to XOR and multiplication to AND. | |
* The elements of GF(2^8) thus represent polynomials of degree < 8 in the generator x. Addition in this field is simply | |
* bitwise XOR, but multiplication requires the elimination of powers of x <= 8. | |
*/ | |
#include <stdio.h> | |
#include <stdint.h> |
This file contains hidden or 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
curl --silent "http://wxdata.weather.com/wxdata/weather/local/TUXX0002?cc=*&unit=m&dayf=1" | \ | |
grep -A2 '<tmp>' | tr '\n' ' ' | sed -E 's|.*<tmp>(.*)</tmp>.*<t>(.*)</t>.*|\2, \1°|' |
This file contains hidden or 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/python | |
from datetime import datetime | |
numwrds = ["one", "two", "three", "four", "five", "six", "seven", "eight", "nine", "ten", | |
"eleven", "twelve", "thirteen", "fourteen", "quarter", "sixteen", "seventeen", | |
"eighteen", "nineteen", "twenty", "twenty-one", "twenty-two", "twenty-three", | |
"twenty-four", "twenty-five", "twenty-six", "twenty-seven", "twenty-eight", | |
"twenty-nine", "half"] | |
now = datetime.now() |