Re: 100 Random Single Variable Linear Equations

Liste des GroupesRevenir à cl awk 
Sujet : Re: 100 Random Single Variable Linear Equations
De : porkchop (at) *nospam* invalid.foo (Mike Sanders)
Groupes : comp.lang.awk
Date : 06. Dec 2024, 23:04:16
Autres entêtes
Organisation : A noiseless patient Spider
Message-ID : <vivsd0$2jij8$1@dont-email.me>
References : 1 2 3 4
User-Agent : tin/2.6.2-20221225 ("Pittyvaich") (NetBSD/9.3 (amd64))
Mike Sanders <porkchop@invalid.foo> wrote:

Yes, certainly, let me study & consider your code & see if I can weave
it into the project. Sounds interesting.

ok, a start, but still need to rework loop, hopefully this weekend.

also added global SEED allowing for re-use...

awk -f algebra.awk -v SEED=$RANDOM

BEGIN {

    SEED = SEED ? SEED : 1

    srand(SEED) # seed random number generator

    # keep generating until we have exactly 100 unique equations
    while (u < 100) {
        a = rnd(1, 20) # random value 1 to 20
        b = rnd(1, 20) # random value 1 to 20
        c = rnd(1, 50) # random value 1 to 50
        z = (rnd(1, 2) == 1) ? "+" : "-"          # safe/janis: random operator
      # z = substr("*-/+", (++q % 4) + 1, 1)      # wild/mike: cycle operators
        e = sprintf("%dx %s %d = %d", a, z, b, c) # formatted equation

        # store equation in array if it doesn't already exist
        if (!(e in equ)) {
            equ[e] = 1 # mark element as reserved
            u++        # increment u for each unique equation
        }
    }

    # print equations
    printf("SEED: %d\n\n", SEED)
    for (j in equ) printf("%03d. %s\n\n\n\n\n\n\n", ++n, j)
}

function rnd(min, max) { return int(rand() * (max - min + 1)) + min }

# eof

--
:wq
Mike Sanders

Date Sujet#  Auteur
6 Dec 24 * 100 Random Single Variable Linear Equations23Mike Sanders
6 Dec 24 +* Re: 100 Random Single Variable Linear Equations19Mike Sanders
6 Dec 24 i`* Re: 100 Random Single Variable Linear Equations18Janis Papanagnou
6 Dec 24 i +* Re: 100 Random Single Variable Linear Equations3Janis Papanagnou
7 Dec 24 i i+- Re: 100 Random Single Variable Linear Equations1Mike Sanders
7 Dec 24 i i`- Re: 100 Random Single Variable Linear Equations1Mike Sanders
6 Dec 24 i `* Re: 100 Random Single Variable Linear Equations14Mike Sanders
6 Dec 24 i  +* Re: 100 Random Single Variable Linear Equations3Janis Papanagnou
7 Dec 24 i  i`* Re: 100 Random Single Variable Linear Equations2Christian Weisgerber
7 Dec 24 i  i `- Re: 100 Random Single Variable Linear Equations1Mike Sanders
6 Dec 24 i  +* Re: 100 Random Single Variable Linear Equations3Keith Thompson
7 Dec 24 i  i`* Re: 100 Random Single Variable Linear Equations2Mike Sanders
7 Dec 24 i  i `- Re: 100 Random Single Variable Linear Equations1Mike Sanders
7 Dec 24 i  `* Re: 100 Random Single Variable Linear Equations7Mike Sanders
7 Dec 24 i   `* Re: 100 Random Single Variable Linear Equations6Mike Sanders
7 Dec 24 i    `* Re: 100 Random Single Variable Linear Equations5Janis Papanagnou
8 Dec 24 i     `* Re: 100 Random Single Variable Linear Equations4Mike Sanders
8 Dec 24 i      `* Re: 100 Random Single Variable Linear Equations3Janis Papanagnou
9 Dec 24 i       `* Re: 100 Random Single Variable Linear Equations2Mike Sanders
9 Dec 24 i        `- Re: 100 Random Single Variable Linear Equations1Janis Papanagnou
8 Dec 24 +* Re: 100 Random Single Variable Linear Equations2Mike Sanders
8 Dec 24 i`- Re: 100 Random Single Variable Linear Equations1Mike Sanders
8 Dec 24 `- Re: 100 Random Single Variable Linear Equations1Mike Sanders

Haut de la page

Les messages affichés proviennent d'usenet.

NewsPortal