School themes from USSR and EurAsia - Printable Version +- QB64 Phoenix Edition (https://staging.qb64phoenix.com) +-- Forum: QB64 Rising (https://staging.qb64phoenix.com/forumdisplay.php?fid=1) +--- Forum: Code and Stuff (https://staging.qb64phoenix.com/forumdisplay.php?fid=3) +---- Forum: Programs (https://staging.qb64phoenix.com/forumdisplay.php?fid=7) +---- Thread: School themes from USSR and EurAsia (/showthread.php?tid=310) |
School themes from USSR and EurAsia - DANILIN - 05-02-2022 School themes from USSR and EurAsia Some topics have been preserved for eternity web.archive.org/save/ plus I saved 5500 pages of previous forum qb64 School themes from USSR Relief 3d multivariate parametric https://qb64forum.alephc.xyz/index.php?topic=4398 Russian Circle Diagram https://qb64forum.alephc.xyz/index.php?topic=4367 Shuffling Letters https://qb64forum.alephc.xyz/index.php?topic=3982 Guess Number https://qb64forum.alephc.xyz/index.php?topic=3999 Integral of letters: all combinations of letters of all words https://qb64forum.alephc.xyz/index.php?topic=3106 Rebus of Letters https://qb64forum.alephc.xyz/index.php?topic=2961 Running strings https://qb64forum.alephc.xyz/index.php?topic=1724 Russian Sorting Halves Danilin https://qb64forum.alephc.xyz/index.php?topic=702 Nobel Prize will not receive itself Nobelevskaya premiya sama sebya ne poluchit Нобелевская премия сама себя не получит Le prix Nobel ne se recevra pas Nobelpreis wird sich nicht erhalten Il Premio Nobel non ricevera se stesso RE: School themes from USSR and EurAsia - DANILIN - 05-02-2022 I am currently a PeaceMaker I applied to Ministries of RF and to deputies and received answers and notifications But I don't write about political topics anywhere so that my appeals to authorities are not discussed And I recommend 2020 movie: TeNeT Flagimation: 137 kB RE: School themes from USSR and EurAsia - bplus - 05-02-2022 Hey @Danilin you found your way here! You win... ? A welcome from me at least Let the fun continue! RE: School themes from USSR and EurAsia - DANILIN - 05-08-2022 "we win"? all we won in 1945 and in 2022 we won covid what is happening shows: government has best calculations for example waves of virus were clear before 1st wave of covid Together: Flag of USA 1945 now in RU: deposits for 16% have started against inflation and against deficit and I have invested family savings main novelties of RU: own plastic cards MIR = Peace and own social networks and pension savings for themselves this new forum was found again thanks to IDE qb64 https://boxgm.itch.io/qbjs and thanks to topics about qbjs: https://staging.qb64phoenix.com/showthread.php?tid=34 https://qb64forum.alephc.xyz/index.php?topic=4670.0 plus I recommend quick documents indexing and search within a few seconds since 2005 Archivarius 3000 likasoft.com/document-search/index-en.shtml further: algorithms against falsification of randomness are specially designed for a minimum of pictures even small ones RE: School themes from USSR and EurAsia - DANILIN - 06-06-2022 10001th prime Find and show: 10001st prime number rosettacode.org/wiki/10001th_prime qbasic Code: (Select All) max = 10001: n=0: s=1 ' PRIMES.bas Python Code: (Select All) import time; max=10001; n=1; p=1; # PRIMES russian DANILIN C# Code: (Select All) using System; using System.Text; // PRIMEQ.cs qb64 Code: (Select All) max=10001: n=1: p=0: t=Timer ' PRIMES.bas Your Answers ?! ?! RE: School themes from USSR and EurAsia - bplus - 06-07-2022 6 Wheel Sieve 78498 primes from first million integers in .046 secs Code: (Select All) _Title "6 Wheel Sieve" RE: School themes from USSR and EurAsia - JRace - 06-07-2022 (06-06-2022, 03:15 PM)DANILIN Wrote: 10001th prime That's pretty much the way I would do it, so no major changes, but.... What stands out to me is that the value of p does not change within the inner loop, therefore repeating the exponential operation "p ^ 0.5" within the inner loop is slowing the program down. Moving "p ^ 0.5" to the outer loop doubles the speed of the program: Code: (Select All) 'JRace's results: I'm sure the other versions of the program will also give much better times if you make similar changes to their inner loops. RE: School themes from USSR and EurAsia - JRace - 06-07-2022 (06-06-2022, 03:15 PM)DANILIN Wrote: 10001th prime Okay, you made me think. I dusted off an old Sieve of Eratosthenes program I had lying around. Problem is: the original version of the program has no quick-and-easy way to stop when prime 10001 is found. SO, I tweaked the buffer size so that ONLY 10001 primes will fit. (Edit: OK, NOW there is a way to catch and print the nth prime: set the "target" constant to be your chosen target. This ALSO means you can go hog wild and increase the size of the prime flag buffer to any size you want, if the compiler is OK with it, by changing the "size" constant.) This thing runs so fast that my run times keep coming out at 0.0 seconds, to I've set this version to run the Sieve loop 100 times to give a meaningful run time. Is it cheating to use a sieve to improve speed? The RosettaCode rules say nothing about it. Of course the rules say nothing about speed requirements, either. Code: (Select All) Rem DMDScript demo. Prime 10001 is: 104759 Time for 100 iterations: 0.38477 Time per iteration: 0.00385 (Edited to add: Doh! I didn't actually show the 10001st prime with this one. Fixed.) RE: School themes from USSR and EurAsia - bplus - 06-08-2022 @JRACE This was a nice catch on Danilin's code: If j >= p ^ 0.5 Then f = 2 'original line moved outside inner loop But as far as speed goes, sieving is way faster than testing so many times for divisibility with MOD. But you need an array to save results. Maybe the RC challenge was looking to do it without arrays? BUT who really needs to know the 10001th dang prime number? or any nth prime number. Most applications use primes info for factoring so you need to collect prime info in an array for vast range of factors and sieving is fastest for that to do something more practical than this RC challenge. Sieving with wheels is even faster! The example I showed was sieving with a wheel of 6 the samllest, which takes out all multiples of 2 and 3 for prime candidates even before you start sieving. That's 1/2 of all numbers plus 1/3 of 1/2 = 1/6 of the remaining prime candidates. Sieving with a 210 wheel; takes out 2, 3, 5, 7 multiples (2*3*5*7 = 210) before sieving with remaining prime candidates another speed improvement. The wheel size eventually get unwieldy but it depends on the number of integers your prime info (what I call array or first factors) needs to cover. RE: School themes from USSR and EurAsia - JRace - 06-08-2022 (06-08-2022, 02:49 PM)bplus Wrote: @JRACE Re the catch: I started programming in the days of 8-bit, 64K max CPUs, when RAM was at a premium and even integer multiplies and divides were expensive, cycle-wise, so my eye is trained to spot little inefficiencies. The RCode (I hesitate to use the initials RC on this site) page has no rules yet. It's not even a challenge at this point: Quote:10001th prime is a draft programming task. It is not yet considered ready to be promoted as a complete task, for reasons that should be found in its talk page. The sieve I posted leaves out multiples of 2 by design, but I've never (yet) experimented with wheels. I had thought about preemptively marking off the lower primes, but wasn't sure about the benefit and never even bothered. You introduced me to the term "wheels" in this usage. The prog I posted was one of MANY translations I made of an example program from the Digital Mars website. After checking out DMDScript's speed (it may do well against older JavaScript engines, but it can't hold a candle to SpiderMonkey or V8), I went on a speed testing binge of several different compilers & interpreters. Granted, a sieve is not a well-rounded benchmark, but it was an amusing diversion (especially during slow times at work) until I got bored with it. I've been programming mainly in C for many years and am weary of doing all the little things that one must do, over and over again, to craft a robust C program. I wanted a simpler way of creating small utilities and such on the fly. Anyway, my experiments led me to learn and use GAWK for a while, but I eventually came back home to Basic. |