Skip to content

Instantly share code, notes, and snippets.

@Lapin0t
Last active September 22, 2016 18:34
Show Gist options
  • Save Lapin0t/a4be31f01c380a4afbc8584be5761b82 to your computer and use it in GitHub Desktop.
Save Lapin0t/a4be31f01c380a4afbc8584be5761b82 to your computer and use it in GitHub Desktop.
from math import ceil as ceil_, floor as floor_, log
from matplotlib import pyplot as plt
import numpy as np
ceil = lambda n: int(ceil_(n))
floor = lambda n: int(floor_(n))
immeuble = lambda i: lambda j: j >= i
def etage_fatal(k, n, fatal):
d = max(2, ceil(n**(1/k))) # max just in case n = 1
k_min = min(k_ for k_ in range(1, k+1) if ceil(n**(1/k_)) == d)
u = n**(1/k_min)
a, b = -1, n
# l'étage fatal est dans ]a;b]
while b - a > 1:
c_ = a
for i in range(1, d):
c = a + floor((b - a) * i / u)
if fatal(c):
print('étage %i: fatal' % c)
a, b = c_, c
break
print('étage %i: ok' % c)
c_ = c
else:
a = c
return b
comp_high = lambda k, n: ceil(log(n, 2))
comp_low = lambda k, n: min(k_ for k_ in range(1, k+1) if ceil(n**(1/k_)) == ceil(n**(1/k)))*(ceil(n**(1/k)) - 1)
comp = lambda k, n: comp_low(k, n) if k < ceil(log(n, 2)) else comp_high(k, n)
def plot_2Df(f, xs, ys):
zs = [[f(x, y) for x in xs] for y in ys]
plt.contourf(xs, ys, zs, 72)
c = plt.contour(xs, ys, zs, 10, colors='k')
plt.clabel(c, colors='k')
plt.show()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment