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 python | |
# coding: utf8 | |
""" | |
generate wrong counter-examples of Fermat's theorem | |
see http://www.drgoulu.com/2016/03/25/contre-exemples-au-theoreme-de-fermat-wiles/ | |
""" | |
from __future__ import print_function, division | |
import itertools | |
__author__ = "Philippe Guglielmetti" |
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
/* | |
Google Spreadsheet custom functions for Benford Law statistics | |
author : Philippe Guglielmetti aka Dr. Goulu | |
contact: drgoulu@gmailcom | |
license: LGPL | |
*/ | |
function sum(a, b) { return a + b; } // not predefined ? |
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
from threading import Timer | |
from multiprocessing import TimeoutError | |
def itimeout(iterable,timeout): | |
"""timeout for loops | |
:param iterable: any iterable | |
:param timeout: float max running time in seconds | |
:yield: items in iterator until timeout occurs | |
:raise: multiprocessing.TimeoutError if timeout occured | |
""" |
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
SCP[i_, n_] := Sum [Prime[j], {j, i, i + n - 1}] | |
PSP[n_, i_] := {m = i; While[p = SCP[m, n]; Not[PrimeQ[p]], m++]; p, m} | |
PSP[n_] := PSP[n, 1] | |
CPSP[list_] := {p = Map[PSP, list]; p1 = {}; | |
While[p != p1, p1 = p; Print[p]; | |
For[i = 2, i <= Length[list], i++, | |
While[p[[i, 1]] < p[[1, 1]], | |
p = ReplacePart[p, i -> PSP[list[[i]], p[[i, 2]] + 1]]]; | |
While[p[[1, 1]] < p[[i, 1]], | |
p = ReplacePart[p, 1 -> PSP[list[[1]], p[[1, 2]] + 1]]]; |
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
def points_on_sphere(N): | |
""" Generate N evenly distributed points on the unit sphere centered at | |
the origin. Uses the 'Golden Spiral'. | |
Code by Chris Colbert from the numpy-discussion list. | |
""" | |
import numpy as np | |
phi = (1 + np.sqrt(5)) / 2 # the golden ratio | |
long_incr = 2*np.pi / phi # how much to increment the longitude | |
dz = 2.0 / float(N) # a unit sphere has diameter 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
from PIL import Image | |
im = Image.open("img2htmltable.png") | |
mat=im.load() | |
width, height = im.size | |
file=open('img2htmltable.htm','w') | |
file.write('<table width="%d"px height="%d"px cellpadding=0 cellspacing=0 style="border-collapse: collapse;">'%(width,height)) | |
for line in range(height): |
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
def proportional(nseats,votes): | |
"""assign n seats proportionaly to votes using the https://en.wikipedia.org/wiki/Hagenbach-Bischoff_quota method | |
:param nseats: int number of seats to assign | |
:param votes: iterable of int or float weighting each party | |
:result: list of ints seats allocated to each party | |
""" | |
quota=sum(votes)/(1.+nseats) #force float | |
frac=[vote/quota for vote in votes] | |
res=[int(f) for f in frac] | |
n=nseats-sum(res) #number of seats remaining to allocate |
NewerOlder