Code Monkey home page Code Monkey logo

tryalgo.org's Introduction

TryAlgo.org

This is the code that powers the website tryalgo.org.

Run locally

bundle install
bundle exec jekyll serve --incremental  # Faster

How to contribute

If you want to add a post, feel free to create a pull request! It should be in fr/_posts if French, in en/_posts if English.

tryalgo.org's People

Contributors

cbeausei avatar clreda avatar espitau avatar gaubian avatar jilljenn avatar kuredatan avatar louisabraham avatar naereen avatar shloub avatar xtof-durr avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

tryalgo.org's Issues

Changer le thème

  • Fix nav
  • Fix TOC
  • Fix pagination
  • Fix MathJax
  • Meilleur style code
  • Faster Jekyll?
  • Depreciation links

Suggestions

Moi je tenterais bien le premier ci-dessous pour avoir un peu de couleur pour changer :

Plus durs à trouver (démo lien mort)

Just for fun

Performance de l'implémentation de Floyd-Warshall

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 :

  • en Python, l'opérateur [] est couteux (__getitem__), or il est appliqué de nombreuses fois, tant à gauche qu'à droite
  • le minimum est calculé à chaque tour de boucle, et va souvent faire une affectation équivalente à weight[u][v] = weight[u][v].

Donc, je pense qu'il faut ré-écrire le code pour :

  • ne pas calculer le minimum avec min (et donc limiter l'évaluation du membre de droite),
  • factoriser le plus possible les appels à __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

page footer

Bonjour Jill-Jênn, Clémence, Louis, et les autres,

deux choses décoratives.

  1. 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?

  2. 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

Reduce size of the sidebar / make the theme more adaptive

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?

Here are two examples, first at 100%:
tryalgo2

Then at 80%:
tryalgo1

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.