Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
68 changes: 68 additions & 0 deletions JavaScript/Generating-sequences.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
# Generating-sequences

Mathematical sequences occur so frequently in nature very often this transfers into computer programming problems. For example, the
cicadas who appear periodically but only emerge after a prime number of years. Or sunflowers which have either 34, 55 or 89 petals
on their face, depending upon the size of the sunflower. Additionally, lilies and irises have three petals, buttercups and wild roses
have five, delphiniums have eight petals, all related to the Fibonacci sequence. Or simply triangular numbers in bowling!
We are surrounded by sequences which are regularly analysed within computer programming.

Being equipped to generate such sequences is vital. This is dedicated to exploring the possibleways these sequences can be produced
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • add a noun after the word 'This' e.g. 'This article is dedicated to...'
  • add space between 'possible' and 'ways'

within a computer program using javascript:

Prime Numbers
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perhaps make this heading bold/bigger to improve readability


A prime number is a natural number that has exactly two distinct natural number divisors: 1 and itself. There are several prime number
sieves in circulation, however, Sieve of Eratosthenes is a simple ancient algorithm.

By iterating through an array of numbers starting at the beginning and removing all subsequent numbers that are a factor of the prime.
The multiples of a given prime are generated as a sequence of numbers starting from that prime, with constant difference between
them that is equal to that prime. This is the sieve's key distinction from using trial division to sequentially test each
candidate number for divisibility by each prime:

function primes(num) {
var x = [];
for( var i =0; i<= num; i++) {
x[i] = true;
}
x[0]= false;
x[1]= false;
x[2]= true;
for ( var j = 2; j< num; j++) {
for (var k = 2; j*k <= num; k++) {
x[j*k] = false;
}
}

primeValues = [];

for (var i = 0; i< num; i ++) {
if (x[i] == true) {
primeValues.push(i);
}
}
return primeValues;
}

primes(20);
[2, 3, 5, 7, 11, 13, 17, 19]

Fibonnaci Sequence
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perhaps make this heading bold/bigger to improve readability


In mathematical terms, the sequence Fn of Fibonacci numbers is defined by the recurrence relation Fn = Fn-1 + Fn-2 with seed values.

function fibonacci(nums) {

var fibSequence = [];

fibSequence[0] = 0;
fibSequence[1] = 1;

for (var i = 2; i < nums; i ++) {
fibSequence[i] = fibSequence[i-1] + fibSequence[i-2];
}

return fibSequence;
}

fibonacci(8);
[ 0, 1, 1, 2, 3, 5, 8, 13 ]
1 change: 1 addition & 0 deletions READMEs
Submodule READMEs added at 305717