• [^] # Re: marrant, ton truc

    Posté par (site web personnel) . En réponse au message Algo de recherche arborescente en largeur. Évalué à 4.

    Bon, ça m'a titillé ton truc. J'ai codé mon algo en scilab.
    Ca a l'air de marcher.

    function [e,t]=ecriture(x)
    if (x>0) then
    p=1;
    while (p<x), p=2*p, end
    if (x==p) then
    e=[p];
    t=1;
    else
    [f,u]=ecriture(p-x);
    [g,v]=ecriture(x-p/2);
    if (u<v) then e=[p -f], t=u+1
    else e=[p/2 g], t=v+1, end

    end
    else
    e=[];
    t=0;
    end
    endfunction

    Par exemple, pour 121:
    [e,s]=ecriture(121)
    s= 3
    e=[ 128 -8 1]