génération de séries de chiffres

symbol

Membre actif
13 Octobre 2004
536
25
Bonjour

Toujours dans mon projet "KENO", j'aimerais un petit script.

- J'ai de 2 listes de N° de 1 a 70

je souhaite qu'en face de chaque N° corresponde un autre N°.
L'autre N° doit avoir au moins un ecart de 3.

Chaque N° doit être utilisé 1 seule fois

(les N° doivent être attribues aléatoirement, en respectant la règle d'écart de 3 entre le N° de départ et sa correspondance).

J'ai besoin d'un script qui genere cela en un simple clique


exemple :

01 02 03 04 05 06 07 08 09 10 11 12 13 14 ...... 70
05 50 17 23 18 32 37 01 22 25 03 41 45 56 etc....

merci
 
Bonjour,

Peut être un applescript qui te générerait ça dans un fichier texte sur le bureau.
Pas simple car arrivé à vers la fin il risque de ne rester à affecter que des nombres avec un écart trop faible ...

Je te joint un applescript qui fait celà (mais c'est lourd) . Il doit certainement y avoir plus simple dans un autre langage.
Le principe: créer une liste des 70 nombres, tirer une valeur au hasard, récupérer le nombre dans la liste à la position de la valeur (hasard), effacer ce nombre de la liste et recommencer...

Bloc de code:
repeat -- au cas ou a la fin il ne reste que 1,2 ou 3 nombres impossibles
  
    set chemindef to ((path to desktop folder as text) & "liste 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 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 > 2 then exit repeat -- si superieur a 3 OK
                if i - choix > 2 then exit repeat -- Si inferieur a 3 OK
                if i > 67 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
          
            my ecriture(i, choix, chemindef) -- appelle la routine ecriture dans le fichier texte
        end tell
    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 & "   " & 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:
Merci, j'essai et reviens te rendre compte.



MAJ

J'ai testé -> parfait :)

C'est d'autant plus utile que je dois générer ce type de liste plusieurs fois.

Encore merci. :up:
 
OK content pour toi.
J'ai commenté pour faire d'éventuelles modifications si nécessaire.

Edit: Une chose à laquelle je viens de penser, si tu dois récupérer les valeurs à l'aide d'un script, il serait peut-être utile que ces valeurs soit séparées par une tabulation au lieu d'espaces. si c'est la cas il faut remplacer dans la routine écriture les espaces par une tabulation, ce qui donne: je te remet le script complet

Bloc de code:
repeat -- au cas ou a la fin il ne reste que 1,2 ou 3 nombres impossibles
   
    set chemindef to ((path to desktop folder as text) & "liste 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 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 > 2 then exit repeat -- si superieur a 3 OK
                if i - choix > 2 then exit repeat -- Si inferieur a 3 OK
                if i > 67 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
           
            my ecriture(i, choix, chemindef) -- appelle la routine ecriture dans le fichier texte
        end tell
    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 ("waouo
 
Dernière édition:
Merci de ta modification.

Y'aurais juste un léger inconvenient (que je règle a la main si le vois), c'est que le script peut parfois produire une liste avec 2 fois les mêmes DUOS mais inversés.
exemple :

12 47
47 12

Je ne sais si il est possible d'éviter ca ?

Merci
 
Voila un nouveau script auquel j'ai ajouté le contrôle de paire.
Dis -moi si cela te convient.

Bloc de code:
repeat -- au cas ou a la fin il ne reste que 1,2 ou 3 nombres impossibles
   
    set chemindef to ((path to desktop folder as text) & "liste 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 > 2 then exit repeat -- si superieur a 3 OK
                if i - choix > 2 then exit repeat -- Si inferieur a 3 OK
                if i > 67 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
 
OK content pour toi !:coucou:
 
Zeltron54

Serait il possible de modifier le script pour qu'il me donne des séries de 3 N° (au lieu de 2), selon les memes règles ?

Merci
 
Bonsoir symbol,

J'ai du mal à comprendre ce que tu veux dire par 3 chiffres ?

si tu génères 2 listes les 2 seront conformes à tes règles par rapport à la liste initiale qui est la suite de 1 à 70.

Par contre si tu veux que la deuxième liste créées respecte les règles à la fois par rapport à la première et à la liste initiale en même temps, celà va restreinte de beaucoup les possibilités du hasard, et là il faut entièrement réécrite le script.

Essai de me préciser exactement ce que tu veux obtenir et j'essaierais de le réaliser ...
 
Je suis parti sur le fait que tu veux la liste avec le 3 nombres, et je t'ai préparé ce script.
Dis- moi si cela te convient.
Obligé de supprimer les commentaires du code (dépasse 5000 caractères)
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
        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
                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 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
                set test to item i of laliste
                set test to test as string
                if choix - test > 2 then exit repeat
                if test - 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 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
set lefichier to open for access chemindef with write permission
repeat with i from 1 to 70
    set num to i as string
    set chif1 to item i of laliste as string
    set chif2 to item i of laliste2 as string
    write num & (ASCII character 9) & chif1 & (ASCII character 9) & chif2 & return to lefichier starting at eof
end repeat
close access lefichier
tell application "Finder"
    (display dialog ("waouou ... Ca y est c'est fait !") buttons {"Salut !"})
end tell
 
J'ai repris mes essais ce matin,
le script ne contrôle pas si l'écart est supérieur à 3 entre la première liste générée et la deuxième.
Je cherche ça des que je peux, et je remettrais le script modifié.
 
Ok teste cette version, et dis moi si ça te convient.

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
set lefichier to open for access chemindef with write permission
repeat with i from 1 to 70
    set num to i as string
    set chif1 to item i of laliste as string
    set chif2 to item i of laliste2 as string
    write num & (ASCII character 9) & chif1 & (ASCII character 9) & chif2 & return to lefichier starting at eof
end repeat
close access lefichier
tell application "Finder"
    (display dialog ("waouou ... Ca y est c'est fait !") buttons {"Salut !"})
end tell
 
Je viens de tester la dernière version du script. Ca m'a l'air parfait :)

Je demande si il est possible de générer la meme meme chose mais en ayant aucun doublon.
C'est a dire que l'integralité des trinomes générés ne doit utilisé qu'une fois les 70 N° ( -> sans limite d'ecart entre les N°, pour simplifier la chose).

En tout cas, merci pour ton travail.

Cordialement , :coucou:
 
Je demande si il est possible de générer la meme meme chose mais en ayant aucun doublon.
C'est a dire que l'integralité des trinomes générés ne doit utilisé qu'une fois les 70 N°

La je comprend pas ce que tu veux dire !
Il n'y a pas de doublons.... et chaque liste n'utilise qu'une fois les 70 N°...

Je m'explique: verticalement tu as 3 listes de 70 N° allant de 1 à 70 sans doublon les 70 N° étant utilisés. Et horizontalement tu as 70 trinomes, chaque trinome à 3 nombres espacés de 3 minimum. il ne peut donc pas y avoir de doublon et les 70 N° sont utilisés à chaque fois.

Essai d'être un peux plus clair .... je comprend vite si on m'explique longtemps :p
 
Dernière édition:
Je me suis mal expliqué, je m'en excuse.


Avec le script qui génère des séries de 3 N°, si on utilise chaque N°,seulement 1 fois, il ne devrait y voir que 23,33333 séries de 3 N° possibles (70 N° / 3 = 23,3333), mais en réalité j'en ai 70.

Ce qui indique que certains N° sont utilisés plusieurs fois, dans plusieurs combinaisons (mais jamais dans la MEME combinaison)

Quand je lance le script , je lis le fichiers "liste 70.txt", et je vois par exemple que le 53 est utilisé dans "1-53-4" et dans "30-42-53"


;)

MAJ :
J'ai trouvé un service online qui peux générer ce genre liste.
25 33 2
8 36 56
5 68 64
10 31 32
14 29 65
6 61 22
20 1 59
15 7 27
49 52 57
35 70 23
62 16 69
48 67 55
21 44 38
47 4 28
42 9 24
54 63 11
51 17 60
39 41 53
43 46 66
3 40 13
34 12 37
50 45 58
18 30 26
19

Encore merci de ton aide. :up::up:
 
Effectivement chaque N° est utilisé 3 fois (1 fois en 1ere position, 1 fois en deuxième position, et une fois en troisième) sur l'ensemble des 70 trinomes.
Si chaque N° ne doit être utilisé qu'une seule fois on ne pourra sortir que 23 trinomes différents !

Edit nos messages ce sont croisés.
 
effectivement , seulement 23 trinomes a la fois.

J'ai besoin d'avoir 10 fois 23 trinomes.

Du coup, on peut avoir 10 X 23 trinomes différents :)
 
Ça revient simplement à faire un tirage style loto parmi 70 N°.
Ça n'a rien à voir avec ta demande initiale. Ou alors j'avais mal compris :(
Ce genre de script est encore plus simple que le précédent o_O

Cordialement :coucou: