Deutsch English Français Italiano |
<vitvta$24sm3$1@dont-email.me> View for Bookmarking (what is this?) Look up another Usenet article |
Path: ...!weretis.net!feeder9.news.weretis.net!news.quux.org!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail From: porkchop@invalid.foo (Mike Sanders) Newsgroups: comp.lang.awk Subject: Re: 100 Random Single Variable Linear Equations Date: Fri, 6 Dec 2024 04:51:54 -0000 (UTC) Organization: A noiseless patient Spider Lines: 41 Sender: Mike Sanders <busybox@sdf.org> Message-ID: <vitvta$24sm3$1@dont-email.me> References: <vits2o$240vr$1@dont-email.me> Injection-Date: Fri, 06 Dec 2024 05:51:55 +0100 (CET) Injection-Info: dont-email.me; posting-host="b091e410931247565241b7435975ad23"; logging-data="2257603"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1947PH45G1PZWw2bJly72t7" User-Agent: tin/2.6.2-20221225 ("Pittyvaich") (NetBSD/9.3 (amd64)) Cancel-Lock: sha1:1iTYizyZOdgw0Nj6cE5RP5GP5UM= Bytes: 2146 Mike Sanders <porkchop@invalid.foo> wrote: > # algebra.awk: 2024 - Michael Sanders > # > # usage: awk -f algebra.awk > solve.txt > > [...] # subtle tweak: every equation unique (no duplicates)... BEGIN { srand() # seed the random number generator # keep generating until we have exactly 100 unique equations while (u < 100) { a = int(rand() * 20) + 1 # random value for 'a' (1 to 20) b = int(rand() * 20) + 1 # random value for 'b' (1 to 20) c = int(rand() * 50) + 1 # random value for 'c' (1 to 50) opc = (rand() < 0.5 ? "*" : "/") # random operator lhs = sprintf("%dx %s %d", a, opc, b) # left-hand side rhs = c # right-hand side equ = lhs " = " rhs # full equation # store equation in array if it doesn't already exist if (!(equ in equations)) { equations[equ] = 1 # mark element as 'reserved'... u++ # increment u for each unique equation } } # print equations for (e in equations) printf("%03d. %s\n\n\n\n\n\n\n\n\n", ++q, e) } # eof -- :wq Mike Sanders