-
-
Notifications
You must be signed in to change notification settings - Fork 7
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
Add prime-factors
exercise
#80
Merged
Merged
Changes from all commits
Commits
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 |
---|---|---|
@@ -0,0 +1,36 @@ | ||
# Instructions | ||
|
||
Compute the prime factors of a given natural number. | ||
|
||
A prime number is only evenly divisible by itself and 1. | ||
|
||
Note that 1 is not a prime number. | ||
|
||
## Example | ||
|
||
What are the prime factors of 60? | ||
|
||
- Our first divisor is 2. | ||
2 goes into 60, leaving 30. | ||
- 2 goes into 30, leaving 15. | ||
- 2 doesn't go cleanly into 15. | ||
So let's move on to our next divisor, 3. | ||
- 3 goes cleanly into 15, leaving 5. | ||
- 3 does not go cleanly into 5. | ||
The next possible factor is 4. | ||
- 4 does not go cleanly into 5. | ||
The next possible factor is 5. | ||
- 5 does go cleanly into 5. | ||
- We're left only with 1, so now, we're done. | ||
|
||
Our successful divisors in that computation represent the list of prime factors of 60: 2, 2, 3, and 5. | ||
|
||
You can check this yourself: | ||
|
||
```text | ||
2 * 2 * 3 * 5 | ||
= 4 * 15 | ||
= 60 | ||
``` | ||
|
||
Success! |
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 |
---|---|---|
@@ -0,0 +1,19 @@ | ||
{ | ||
"authors": [ | ||
"erikschierboom" | ||
], | ||
"files": { | ||
"solution": [ | ||
"prime-factors.ua" | ||
], | ||
"test": [ | ||
"tests.ua" | ||
], | ||
"example": [ | ||
".meta/example.ua" | ||
] | ||
}, | ||
"blurb": "Compute the prime factors of a given natural number.", | ||
"source": "The Prime Factors Kata by Uncle Bob", | ||
"source_url": "https://web.archive.org/web/20221026171801/http://butunclebob.com/ArticleS.UncleBob.ThePrimeFactorsKata" | ||
} |
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 |
---|---|---|
@@ -0,0 +1 @@ | ||
Factors ← °/× | ||
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. What! No way. 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. Yeah, it's built-in :) |
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 |
---|---|---|
@@ -0,0 +1,46 @@ | ||
# This is an auto-generated file. | ||
# | ||
# Regenerating this file via `configlet sync` will: | ||
# - Recreate every `description` key/value pair | ||
# - Recreate every `reimplements` key/value pair, where they exist in problem-specifications | ||
# - Remove any `include = true` key/value pair (an omitted `include` key implies inclusion) | ||
# - Preserve any other key/value pair | ||
# | ||
# As user-added comments (using the # character) will be removed when this file | ||
# is regenerated, comments can be added via a `comment` key. | ||
|
||
[924fc966-a8f5-4288-82f2-6b9224819ccd] | ||
description = "no factors" | ||
|
||
[17e30670-b105-4305-af53-ddde182cb6ad] | ||
description = "prime number" | ||
|
||
[238d57c8-4c12-42ef-af34-ae4929f94789] | ||
description = "another prime number" | ||
|
||
[f59b8350-a180-495a-8fb1-1712fbee1158] | ||
description = "square of a prime" | ||
|
||
[756949d3-3158-4e3d-91f2-c4f9f043ee70] | ||
description = "product of first prime" | ||
|
||
[bc8c113f-9580-4516-8669-c5fc29512ceb] | ||
description = "cube of a prime" | ||
|
||
[7d6a3300-a4cb-4065-bd33-0ced1de6cb44] | ||
description = "product of second prime" | ||
|
||
[073ac0b2-c915-4362-929d-fc45f7b9a9e4] | ||
description = "product of third prime" | ||
|
||
[6e0e4912-7fb6-47f3-a9ad-dbcd79340c75] | ||
description = "product of first and second prime" | ||
|
||
[00485cd3-a3fe-4fbe-a64a-a4308fc1f870] | ||
description = "product of primes and non-primes" | ||
|
||
[02251d54-3ca1-4a9b-85e1-b38f4b0ccb91] | ||
description = "product of primes" | ||
|
||
[070cf8dc-e202-4285-aa37-8d775c9cd473] | ||
description = "factors include a large prime" |
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 |
---|---|---|
@@ -0,0 +1,3 @@ | ||
# Get a number's prime factors | ||
# Factors | Number | ||
Factors ← |1 ⊙(⍤ "Please implement Factors" 0) |
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 |
---|---|---|
@@ -0,0 +1,37 @@ | ||
~ "prime-factors.ua" ~ Factors | ||
|
||
# No factors | ||
⍤⤙≍ [] Factors 1 | ||
|
||
# Prime number | ||
⍤⤙≍ [2] Factors 2 | ||
|
||
# Another prime number | ||
⍤⤙≍ [3] Factors 3 | ||
|
||
# Square of a prime | ||
⍤⤙≍ [3 3] Factors 9 | ||
|
||
# Product of first prime | ||
⍤⤙≍ [2 2] Factors 4 | ||
|
||
# Cube of a prime | ||
⍤⤙≍ [2 2 2] Factors 8 | ||
|
||
# Product of second prime | ||
⍤⤙≍ [3 3 3] Factors 27 | ||
|
||
# Product of third prime | ||
⍤⤙≍ [5 5 5 5] Factors 625 | ||
|
||
# Product of first and second prime | ||
⍤⤙≍ [2 3] Factors 6 | ||
|
||
# Product of primes and non-primes | ||
⍤⤙≍ [2 2 3] Factors 12 | ||
|
||
# Product of primes | ||
⍤⤙≍ [5 17 23 461] Factors 901255 | ||
|
||
# Factors include a large prime | ||
⍤⤙≍ [11 9539 894119] Factors 93819012551 |
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.
This is something I found, I didn't actually come up with this
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.
It's ingenious. And totally reasonable.