jilljenn / tryalgo.org Goto Github PK
View Code? Open in Web Editor NEWLes 128 algorithmes qu'il faut avoir codés et compris dans sa vie en Python.
Home Page: https://tryalgo.org
License: Other
Les 128 algorithmes qu'il faut avoir codés et compris dans sa vie en Python.
Home Page: https://tryalgo.org
License: Other
Moi je tenterais bien le premier ci-dessous pour avoir un peu de couleur pour changer :
Bonjour Jill-Jênn, Clémence, Louis, et les autres,
deux choses décoratives.
J'aimerais changer le pied de nos pages pour ne pas mettre en avant seulement Jill-Jênn Vie, moi-même et ENS Paris-Saclay. Est-ce qu'on pourrait juste y écrire un petit slogan ou "raise CornerCaseException" par exemple pour faire écho à "try algo" ? Ça vous irait?
Je vois que son mon smartphone (oui vous avez bien lu), dans nos pages les codes sont tronqués. Est-ce qu'il y a quelque chose qu'on puisse faire ou est-ce que important déjà? Ce n'est peut-être pas un site qu'on lit sur un tel appareil.
Je vais recommencer à être plus actif, maintenant que SWERC'2017 est terminé.
xtof
Hi,
On a 1366-pixel large screen (and smaller) the sidebar is not displayed entirely with the default zoom level (100%).
Could you try to either make the theme more adaptive, or simply reduce the font of the sidebar, or reduce the zoom level of the whole website?
Bonjour
Vous proposez dans votre livre l'algorithme classique de Floyd-Warshall pour ASSP. Pas de souci concernant l'algo, mais curieusement les performances ne sont pas du tout safisfaisantes. Voici votre code (j'ai retiré la docstring et n'ai gardé que le calcul de la matrice des distances) :
def tryalgo(weight):
V = range(len(weight))
for k in V:
for u in V:
for v in V:
weight[u][v] = min(weight[u][v], weight[u][k] + weight[k][v])
Ce code en C++ est très efficace mais pas en Python. Il y a selon moi deux problèmes, provenant de la dernière ligne :
[]
est couteux (__getitem__
), or il est appliqué de nombreuses fois, tant à gauche qu'à droiteweight[u][v] = weight[u][v]
.Donc, je pense qu'il faut ré-écrire le code pour :
min
(et donc limiter l'évaluation du membre de droite),__getitem__
pour éviter les recalculs.En faisant cela, le temps d'exécution est divisé par un facteur allant de 3 à 4 sur ma machine (oui, oui, je n'y croyais pas) ! Voici quelques benchmarks:
from time import perf_counter
import networkx as nx
from copy import deepcopy
def random_edges(n, density, max_weight=100):
from random import randrange
M = n * (n - 1) // 2
m = int(density * M)
edges = set()
wedges = []
while len(edges) < m:
L = (randrange(n), randrange(n))
if L[0] != L[1] and L not in edges:
w = float(randrange(max_weight))
wedges.append(L + (w, ))
edges.add(L)
return wedges
def wedges2matrix(wedges, n, loop=True):
M = [[float('inf')] * n for _ in range(n)]
for a, b, w in wedges:
M[a][b] = w
if loop:
for a in range(n):
M[a][a] = 0
return M
def tryalgo(weight):
V = range(len(weight))
for k in V:
for u in V:
for v in V:
weight[u][v] = min(weight[u][v], weight[u][k] + weight[k][v])
def po(M):
n = len(M)
for k in range(n):
rowk = M[k]
colk = [M[i][k] for i in range(n)]
for i in range(n):
a = colk[i]
Mi = M[i]
for j in range(n):
if a + rowk[j] < Mi[j]:
Mi[j] = a + rowk[j]
def test(n=800, density=0.15):
wedges = random_edges(n, density)
print("%-10s%d" % ("Vertices:", n))
print("%-10s%d" % ("Edges:", len(wedges)))
print("%-10s%.2f" % ("Density:", density))
print("--------------------")
return wedges2matrix(wedges, n)
M = test(100)
MM = deepcopy(M)
start = perf_counter()
tryalgo(M)
tryalgo_time = perf_counter() - start
print("Tryalgo ASSP \t: %.2f" % tryalgo_time)
start = perf_counter()
po(MM)
po_time = perf_counter() - start
print("PO ASSP \t: %.2f" % po_time)
print("--------------------")
print("Checking:", M == MM)
print("Ratio: %.2f" % (tryalgo_time / po_time))
qui affiche
Vertices: 100
Edges: 742
Density: 0.15
--------------------
Tryalgo ASSP : 0.20
PO ASSP : 0.05
--------------------
Checking: True
Ratio: 3.74
Voilà, sinon, j'aime beaucoup votre livre et je fais confiance à vos algos qui me servent de références pour mes propres implémentations !
Cordialement
PO
C'est moins joli ici https://tryalgo.org/liste_algos_fr/
Either lunr.js or FlexSearch!
Hard to read
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.