génération de séries de chiffres

T'a très bien compris, les 2 scripts que tu m'a fait me sont d'une grande utilité. :up:

Ma demande evolue au fur et a mesure de mes besoins.
 
@zeltron54

Le générateur de TRIOS est vraiment nickel.

Actuellement ca me donne une liste sous cette forme :
-- liste actuelle --
8 34 58
9 1 46
10 66 70
11 19 7
12 68 39
13 29 36
14 21 18



Serait-il possible d'avoir les N° par ordre croissant (car parfois ils sont dans le désordre) ?
-- trie par ordre croissant souhaité --
8 34 58
1 9 46
10 66 70
7 11 19
12 39 68
13 29 36
14 18 21


Merci :)
 
Nouveau script avec tri croissant des trinomes .
Tiens moi au courant si OK.
Bloc de code:
repeat
    set chemindef to ((path to desktop folder as text) & "liste 70.txt") as text
    set bigList to {}
    set bigListRef to a reference to bigList
    set numItems to 70
    repeat with n from 1 to numItems -- rempli la liste avec numero de 1 à 70
        copy n to the end of bigListRef
    end repeat
    set laliste to {}
    set impossible to 0
    repeat with i from 1 to 70
        tell application "Finder"
            repeat
                set place to random number from 1 to (count of bigListRef) as integer
                set choix to item place of bigListRef as string
                if choix - i > 2 then exit repeat
                if i - choix > 2 then exit repeat
                if i > 67 then
                    set impossible to 1
                    exit repeat
                end if
            end repeat
            if place = 1 then
                set bigListRef to rest of bigListRef
            else
                if place = (count of bigListRef) then
                    set bigListRef to items 1 thru -2 of bigListRef
                else
                    set bigListRef to items 1 thru (place - 1) of bigListRef & items (place + 1) thru -1 of bigListRef --efface le numero choisi de la liste
                end if
            end if
            set end of laliste to choix
        end tell
    end repeat
    repeat with j from 1 to 70
        set control to item j of laliste
        set le2 to j as string
        set le3 to item control of laliste as string
        if le3 = le2 then
            set impossible to 1
            exit repeat
        end if
    end repeat
    if impossible = 0 then
        exit repeat
    end if
end repeat
repeat
    set bigList to {}
    set bigListRef to a reference to bigList
    set numItems to 70
    repeat with n from 1 to numItems
        copy n to the end of bigListRef
    end repeat
    set laliste2 to {}
    set impossible to 0
    repeat with i from 1 to 70
        tell application "Finder"
            repeat
                set ecart to 0
                set place to random number from 1 to (count of bigListRef) as integer
                set choix to item place of bigListRef as string
                set test to choix - i
                if test < 0 then set test to test * -1
                if test < 3 then set ecart to 1
                if ecart = 1 then
                    if i > 67 then
                        set impossible to 1
                        set ecart to 0
                    end if
                end if
                set letest to item i of laliste
                set test to choix - letest
                if test < 0 then set test to test * -1
                if test < 3 then set ecart to 1
                if ecart = 1 then
                    if i > 67 then
                        set impossible to 1
                        set ecart to 0
                    end if
                end if
                set lenum to i as string
                if ecart = 0 then exit repeat
            end repeat
            if place = 1 then
                set bigListRef to rest of bigListRef
            else
                if place = (count of bigListRef) then
                    set bigListRef to items 1 thru -2 of bigListRef
                else
                    set bigListRef to items 1 thru (place - 1) of bigListRef & items (place + 1) thru -1 of bigListRef
                end if
            end if
            set end of laliste2 to choix
        end tell
    end repeat
    repeat with j from 1 to 70
        set control to item j of laliste
        set control2 to item j of laliste2
        set le2 to j as string
        set le3 to item control of laliste as string
        set le4 to item control2 of laliste2 as string
        if le3 = le2 then
            set impossible to 1
            exit repeat
        end if
        if le4 = le2 then
            set impossible to 1
            exit repeat
        end if
    end repeat
    if impossible = 0 then
        exit repeat
    end if
end repeat
repeat with i from 1 to 70
    set l1 to i as integer
    set l2 to item i of laliste as integer
    set l3 to item i of laliste2 as integer
    repeat with tri from 1 to 3
        if l1 > l2 then
            set tmp to l2
            set l2 to l1
            set l1 to tmp
        end if
        if l2 > l3 then
            set tmp to l3
            set l3 to l2
            set l2 to tmp
        end if
    end repeat
    set le1 to l1 as string
    set le2 to l2 as string
    set le3 to l3 as string
    set lefichier to open for access chemindef with write permission
    write le1 & (ASCII character 9) & le2 & (ASCII character 9) & le3 & return to lefichier starting at eof
    close access lefichier
end repeat
tell application "Finder"
    (display dialog ("waouou ... Ca y est c'est fait !") buttons {"Salut !"})
end tell
 
Je viens de tester. C'est parfait.

Avant il fallait que je génère la liste, puis je faisais le tri avec EXcel. Maintenant c'est tout en un :)

Merci :coucou::up:
 
Salut Zeltron54

Dans le script que tu as fait plus haut (dont je suis troujours tres satisfait) .
Serait il possible que les N° 1,2,3,4,5,6,7,8,9, apparaissent comme 01,02,03,04,05,06,07,08,09 dans le fichier sauvegardé ?

par exemple
1 27 devient 01 27

merci
 
Salut symbol
Pas de problème il suffit de formater l'affichage , donc remplacer les 3 lignes en bas du script:

Bloc de code:
set le1 to l1 as string
set le2 to l2 as string
set le3 to l3 as string

par :

Bloc de code:
set le1 to items -2 thru -1 of ("0" & l1) as string
set le2 to items -2 thru -1 of ("0" & l2) as string
set le3 to items -2 thru -1 of ("0" & l3) as string

Dis moi si c'est bon !

Bonne journée.
 
Merci Zeltron54 :)

J'essai de suite. Je reviens te dire.

MAJ : c'est bizarre le script que j ai est different de celui posté au dessus, du coup je trouve pas les lignes que tu m'indique.

ou alors tu m'avais envoyé un script en message privé ?. je me souviens plus, en tout cas c'est toi qui a fait le code c'est sur.

je me rappelle avoir changé une valeur pour l'ecart entre nombre genérés soit 4 si j'ai bonne mémoire, mais c'est tout.



Bloc de code:
repeat -- au cas ou a la fin il ne reste que 1,2,3 ou 4 nombres impossibles
 
    set chemindef to ((path to desktop folder as text) & "liste KENO 70.txt") as text -- defini le chemin pour creer fichier texte
    set bigList to {} --ceer une liste
    set bigListRef to a reference to bigList
    set numItems to 70
    repeat with n from 1 to numItems -- rempli la liste avec numero de 1 à 70
        copy n to the end of bigListRef
    end repeat
 
    set laliste to {}
    set impossible to 0 -- pour test fin
    repeat with i from 1 to 70
        tell application "Finder"
            repeat
                set place to random number from 1 to (count of bigListRef) as integer -- un nombre au hasard entre 1 et x contenu dans la liste
          
                set choix to item place of bigListRef as string --recupere le numero situé a la position du choix
                if choix - i > 3 then exit repeat -- si superieur a 4 OK
                if i - choix > 3 then exit repeat -- Si inferieur a 4 OK
                if i > 66 then -- si reste impossible
                    set impossible to 1
                    exit repeat
                end if
            end repeat
      
            -- routine pour effacer de la liste le nombre choisi
            if place = 1 then
                set bigListRef to rest of bigListRef
            else
                if place = (count of bigListRef) then
                    set bigListRef to items 1 thru -2 of bigListRef
                else
                    set bigListRef to items 1 thru (place - 1) of bigListRef & items (place + 1) thru -1 of bigListRef --efface le numero choisi de la liste
                end if
            end if
      
            set end of laliste to choix
            my ecriture(i, choix, chemindef) -- appelle la routine ecriture dans le fichier texte
        end tell
    end repeat
 
    -- test si paire double si mettre impossible à 1
    repeat with j from 1 to 70
        set control to item j of laliste
        set le2 to j as string
        set le3 to item control of laliste as string
        if le3 = le2 then
            set impossible to 1
            exit repeat
        end if
    end repeat
 
 
    if impossible = 0 then -- si fini
        exit repeat
    end if
 
    do shell script "rm " & quoted form of POSIX path of chemindef -- impossible efface le fichier et recommence
end repeat


-- routine ecriture dans fichier texte
on ecriture(i, lenum, chemindef)
    set num to i as string
    set lefichier to open for access chemindef with write permission
    write num & (ASCII character 9) & lenum & return to lefichier starting at eof
    close access lefichier
end ecriture

tell application "Finder"
    (display dialog ("waouou ... Ca y est c'est fait !") buttons {"Salut !"})
end tell
 
Dernière édition:
Coucou,
Le script du message #23 construit une liste de 3 nombres
Le script que tu mets en #27 construit une liste de 2 nombres

Sur lequel veux-tu faire la modif ?
 
Allez !
Voilà ton 2 ieme script modifié !
Dis moi si c'est bon !

Bloc de code:
repeat -- au cas ou a la fin il ne reste que 1,2,3 ou 4 nombres impossibles
   
    set chemindef to ((path to desktop folder as text) & "liste KENO 70.txt") as text -- defini le chemin pour creer fichier texte
    set bigList to {} --ceer une liste
    set bigListRef to a reference to bigList
    set numItems to 70
    repeat with n from 1 to numItems -- rempli la liste avec numero de 1 à 70
        copy n to the end of bigListRef
    end repeat
   
    set laliste to {}
    set impossible to 0 -- pour test fin
    repeat with i from 1 to 70
        tell application "Finder"
            repeat
                set place to random number from 1 to (count of bigListRef) as integer -- un nombre au hasard entre 1 et x contenu dans la liste
               
                set choix to item place of bigListRef as string --recupere le numero situé a la position du choix
                if choix - i > 3 then exit repeat -- si superieur a 4 OK
                if i - choix > 3 then exit repeat -- Si inferieur a 4 OK
                if i > 66 then -- si reste impossible
                    set impossible to 1
                    exit repeat
                end if
            end repeat
           
            -- routine pour effacer de la liste le nombre choisi
            if place = 1 then
                set bigListRef to rest of bigListRef
            else
                if place = (count of bigListRef) then
                    set bigListRef to items 1 thru -2 of bigListRef
                else
                    set bigListRef to items 1 thru (place - 1) of bigListRef & items (place + 1) thru -1 of bigListRef --efface le numero choisi de la liste
                end if
            end if
           
            set end of laliste to choix
            my ecriture(i, choix, chemindef) -- appelle la routine ecriture dans le fichier texte
        end tell
    end repeat
   
    -- test si paire double si mettre impossible à 1
    repeat with j from 1 to 70
        set control to item j of laliste
        set le2 to j as string
        set le3 to item control of laliste as string
        if le3 = le2 then
            set impossible to 1
            exit repeat
        end if
    end repeat
   
   
    if impossible = 0 then -- si fini
        exit repeat
    end if
   
    do shell script "rm " & quoted form of POSIX path of chemindef -- impossible efface le fichier et recommence
end repeat


-- routine ecriture dans fichier texte
on ecriture(i, lenum, chemindef)
    set num to i as string
    set num to items -2 thru -1 of ("0" & num) as string
    set lenum to items -2 thru -1 of ("0" & lenum) as string
   
    set lefichier to open for access chemindef with write permission
    write num & (ASCII character 9) & lenum & return to lefichier starting at eof
    close access lefichier
    --display dialog num & " " & lenum
   
end ecriture

tell application "Finder"
    (display dialog ("waouou ... Ca y est c'est fait !") buttons {"Salut !"})
end tell
 
  • J’aime
Réactions: symbol