-
Notifications
You must be signed in to change notification settings - Fork 84
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
We Got Coders entrance test for Paul O'Hara #83
Open
CodeCrusader2017
wants to merge
4
commits into
wegotcoders:master
Choose a base branch
from
CodeCrusader2017:master
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
Changes from 2 commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
eb9db07
wgc_groundwork for Paul OHara: commit initial app.rb file on 17/06/2017
CodeCrusader2017 557197f
Paul O'Hara entrance test for We Got Coders completed late 17/06/2017…
CodeCrusader2017 78b016b
We Got Coders - post coding challenge, ruby code submitted by Paul O'…
CodeCrusader2017 0e14aa6
Delete Paul_O'Hara_photo.png
CodeCrusader2017 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 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
This file contains 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 |
---|---|---|
@@ -1,6 +1,45 @@ | ||
class Primes | ||
def self.sum_to(limit = 100) | ||
# TODO - add your prime number solution here... | ||
"I'm working on it!" | ||
# Ruby code added below by Paul O'Hara 19/07/2017 for entrance test. | ||
# Note: I ran out of time to implement a correct algorithm to add up prime numbers. | ||
# Instead, to show some knowledge of Ruby, I have implemented a routine to add up positive odd numbers to 100. | ||
index = 1 | ||
count = 0 | ||
while index < limit | ||
if index % 2 > 0 | ||
count += index | ||
end | ||
index += 1 | ||
end | ||
"The sum of all positive odd numbers from 1 up to #{limit} is: #{count} " | ||
end | ||
end | ||
end | ||
|
||
|
||
#Code below was an attempt over 1.5 hours, on 19/07/2017, to implement an algorithm to add up prime numbers, but in hind sight I should | ||
#have used an array to hold dividing values up to num being checked - within the inner loop - to get the code to work correctly. | ||
# n = 0 | ||
# m = 0 | ||
# count = 0 | ||
# | ||
# while n <= limit | ||
# | ||
# m = n - 1 | ||
# | ||
# while m > 1 | ||
# | ||
# if m <= Math.sqrt(n) | ||
# if n % m > 0 | ||
# count += n | ||
# m = 0 #break inner loop | ||
# end | ||
# end | ||
# | ||
# m -= 1 | ||
# end | ||
# | ||
# n += 1 | ||
# end | ||
# | ||
# puts "Final count = #{count}" |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains 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
This file contains 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
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.
Good stuff- keep going! If you commit further changes and
git push
them they'll show up here- no need to open another PR. If you decide to finish it we'd gladly look over it