-
Notifications
You must be signed in to change notification settings - Fork 30
Generating Sequences #239
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
MicahWoldu
wants to merge
3
commits into
master
Choose a base branch
from
generating_sequences
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Generating Sequences #239
Changes from 1 commit
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 | ||
| within a computer program using javascript: | ||
|
|
||
| Prime Numbers | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 ] | ||
Submodule READMEs
added at
305717
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.