How to resolve the algorithm Jacobsthal numbers step by step in the Quackery programming language

Published on 12 May 2024 09:40 PM

How to resolve the algorithm Jacobsthal numbers step by step in the Quackery programming language

Table of Contents

Problem Statement

Jacobsthal numbers are an integer sequence related to Fibonacci numbers. Similar to Fibonacci, where each term is the sum of the previous two terms, each term is the sum of the previous, plus twice the one before that. Traditionally the sequence starts with the given terms 0, 1. Terms may be calculated directly using one of several possible formulas:

Jacobsthal-Lucas numbers are very similar. They have the same recurrence relationship, the only difference is an initial starting value J0 = 2 rather than J0 = 0. Terms may be calculated directly using one of several possible formulas: Jacobsthal oblong numbers is the sequence obtained from multiplying each Jacobsthal number Jn by its direct successor Jn+1.

Jacobsthal primes are Jacobsthal numbers that are prime.

Let's start with the solution:

Step by Step solution about How to resolve the algorithm Jacobsthal numbers step by step in the Quackery programming language

Source code in the quackery programming language

  [ 2 over ** -1 rot ** - 3 / ] is j  ( n --> n )

  [ 2 over ** -1 rot ** + ]     is jl ( n --> n )

  [ dup 1+ j swap j * ]         is jo ( n --> n )

  say "First 30 Jacobsthal numbers:"
  cr
  30 times [ i^ j echo sp ]
  cr cr
  say "First 30 Jacobsthal-Lucas numbers:"
  cr
  30 times [ i^ jl echo sp ]
  cr cr
  say "First 20 Jacobsthal oblong numbers:"
  cr
  20 times [ i^ jo echo sp ]
  cr cr
  say "First 10 Jacobsthal primes:"
  cr
  [] 0
  [ dup j dup isprime iff
      [ swap dip join ]
    else drop
    1+
    over size 10 = until ]
   drop
   witheach [ echo sp ]

  

You may also check:How to resolve the algorithm Dutch national flag problem step by step in the BASIC programming language
You may also check:How to resolve the algorithm Reduced row echelon form step by step in the AutoIt programming language
You may also check:How to resolve the algorithm Polymorphism step by step in the R programming language
You may also check:How to resolve the algorithm Solve a Hopido puzzle step by step in the REXX programming language
You may also check:How to resolve the algorithm Exceptions step by step in the Pascal programming language