Editing
Flow-Diagrams
(section)
Jump to navigation
Jump to search
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
== 3. Prime Generation β Sieve Loop == '''Program:''' <code>primesgen.cbl</code> (r80-series paragraphs) + <code>primes.cbl</code> (r81, r83)<br /> '''What it shows:''' The trial-division sieve β how each candidate is tested, how composites are skipped, and how confirmed primes are persisted. '''Algorithm in words:''' 1. Start at candidate = 3. Load first divisor (prime at ident 1 = prime 2, assumed pre-seeded). 2. Divide candidate by current divisor. 3. If remainder = 0 β composite. Add 2, reset divisor to first prime. 4. If divisor > βcandidate β prime confirmed. Write to DB and print buffer. Add 2, reset divisor. 5. Otherwise β try next divisor (fetch next prime from DB by ident). <pre class="mermaid">flowchart TD A([r91-start-primes-generation]) --> B[CALL primes 'connect'] B --> C{dal-method-ok?} C -->|No| FAIL([session-result = 1\nEXIT]) C -->|Yes| D[test-divider = 2\nold-ident = 1\ntest-number = 3\ntest-number-sqr = SQRT 3] D --> LOG1[LOG 'Database initialisation succeeded.'] LOG1 --> LOOP{test-number\n= 999999999?} LOOP -->|Yes| CLOSE([r99-close-primes\nEXIT PROGRAM]) LOOP -->|No| DIV[r80-test-number\nDIVIDE test-number BY test-divider\nGIVING test-quot REMAINDER test-rest] DIV --> EVAL{EVALUATE TRUE} EVAL -->|test-rest = 0\ncomposite| NEXT[r82-next-test-number] EVAL -->|test-divider > test-number-sqr\nprime confirmed| WRITE[r85-write-prime\nCALL primes 'write'\nINSERT INTO primes prime\nCALL primesui 'write'\nadd to print buffer] EVAL -->|otherwise\ntry next divisor| GETDIV[r89-get-next-divider\nCALL primes 'next-divider'\nSELECT prime WHERE ident = old-ident+1] WRITE --> NEXT GETDIV --> LOOP NEXT --> NA[ADD 2 TO test-number\nCOMPUTE test-number-sqr = test-number ** 0.5\nMOVE 1 TO old-ident\nr89-get-next-divider\nload first divisor] NA --> LOOP</pre> '''Data flow through the sieve:''' <pre>test-number (candidate) βββ DIVIDE βββ test-rest test-divider (from DB) βββ DIVIDE βββ test-quot test-number-sqr (SQRT) βββ compare to test-divider old-ident (DB row pointer) βββ SELECT prime WHERE ident = old-ident+1 βββ test-divider prime-number (confirmed) βββ INSERT INTO primes (prime) βββ database βββ u-number / u-sequence βββ primesui print buffer</pre> ----- <span id="prime-report-cursor-loop"></span>
Summary:
Please note that all contributions to Webhuis wiki are considered to be released under the GNU Free Documentation License 1.3 or later (see
Project:Copyrights
for details). If you do not want your writing to be edited mercilessly and redistributed at will, then do not submit it here.
You are also promising us that you wrote this yourself, or copied it from a public domain or similar free resource.
Do not submit copyrighted work without permission!
Cancel
Editing help
(opens in new window)
Navigation menu
Personal tools
Not logged in
Talk
Contributions
Create account
Log in
Namespaces
Page
Discussion
English
Views
Read
Edit
View history
More
Search
Navigation
Voorpagina
Cobol and PostgreSQL
PostgreSQL
CFEngine
Proxmox
Webhuis Kennisbank
Basale infra
Webhuis bouwstenen
Webhuis configuratie
Webhuis Infra
Webhuis Support
Webhuis Raspberry
Opzet Applicaties
Business Applicaties
Community portal
Current events
Recent changes
Random page
Help
sitesupport
Tools
What links here
Related changes
Special pages
Page information