How to resolve the algorithm Stern-Brocot sequence step by step in the MAD programming language

Published on 12 May 2024 09:40 PM

How to resolve the algorithm Stern-Brocot sequence step by step in the MAD programming language

Table of Contents

Problem Statement

For this task, the Stern-Brocot sequence is to be generated by an algorithm similar to that employed in generating the Fibonacci sequence.

Show your output on this page.

Let's start with the solution:

Step by Step solution about How to resolve the algorithm Stern-Brocot sequence step by step in the MAD programming language

Source code in the mad programming language

            NORMAL MODE IS INTEGER
            VECTOR VALUES FRST15 = $20HFIRST 15 NUMBERS ARE*$
            VECTOR VALUES FRSTAT = $6HFIRST ,I3,S1,11HAPPEARS AT ,I4*$
            VECTOR VALUES NUMBER = $I4*$
            
            DIMENSION STERN(1200)
            STERN(1) = 1
            STERN(2) = 1
          
          R GENERATE FIRST 1200 MEMBERS OF THE STERN-BROCOT SEQUENCE
            THROUGH GENSEQ, FOR I = 1, 1, I .GE. 600
            STERN(I*2-1) = STERN(I) + STERN(I-1)
GENSEQ      STERN(I*2) = STERN(I)

          R PRINT FIRST 15 VALUES OF STERN-BROCOT SEQUENCE
            PRINT FORMAT FRST15
            THROUGH P15, FOR I = 1, 1, I .G. 15
P15         PRINT ON LINE FORMAT NUMBER, STERN(I)
            
          R PRINT FIRST OCCURRENCE OF 1..10
            THROUGH FRST10, FOR I = 1, 1, I .G. 10
FRST10      PRINT FORMAT FRSTAT, I, FIRST.(I)
            PRINT FORMAT FRSTAT, 100, FIRST.(100)
            
          R SEARCH FOR FIRST OCCURRENCE OF N IN SEQUENCE  
            INTERNAL FUNCTION(N)
            ENTRY TO FIRST.
            THROUGH SCAN, FOR K = 1, 1, I .G. 1200
SCAN        WHENEVER N .E. STERN(K), FUNCTION RETURN K
            END OF FUNCTION
            END OF PROGRAM

  

You may also check:How to resolve the algorithm Hello world/Standard error step by step in the Octave programming language
You may also check:How to resolve the algorithm Faulhaber's triangle step by step in the Java programming language
You may also check:How to resolve the algorithm Digital root step by step in the Modula-3 programming language
You may also check:How to resolve the algorithm GUI enabling/disabling of controls step by step in the Nim programming language
You may also check:How to resolve the algorithm Count in octal step by step in the PowerShell programming language