-
-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
e979689
commit 57167cc
Showing
8 changed files
with
135 additions
and
0 deletions.
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
23 changes: 23 additions & 0 deletions
23
exercises/practice/pythagorean-triplet/.docs/instructions.md
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,23 @@ | ||
# Description | ||
|
||
A Pythagorean triplet is a set of three natural numbers, {a, b, c}, for which, | ||
|
||
```text | ||
a² + b² = c² | ||
``` | ||
|
||
and such that, | ||
|
||
```text | ||
a < b < c | ||
``` | ||
|
||
For example, | ||
|
||
```text | ||
3² + 4² = 5². | ||
``` | ||
|
||
Given an input integer N, find all Pythagorean triplets for which `a + b + c = N`. | ||
|
||
For example, with N = 1000, there is exactly one Pythagorean triplet for which `a + b + c = 1000`: `{200, 375, 425}`. |
19 changes: 19 additions & 0 deletions
19
exercises/practice/pythagorean-triplet/.docs/introduction.md
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 @@ | ||
# Introduction | ||
|
||
You are an accomplished problem-solver, known for your ability to tackle the most challenging mathematical puzzles. | ||
One evening, you receive an urgent letter from an inventor called the Triangle Tinkerer, who is working on a groundbreaking new project. | ||
The letter reads: | ||
|
||
> Dear Mathematician, | ||
> | ||
> I need your help. | ||
> I am designing a device that relies on the unique properties of Pythagorean triplets — sets of three integers that satisfy the equation a² + b² = c². | ||
> This device will revolutionize navigation, but for it to work, I must program it with every possible triplet where the sum of a, b, and c equals a specific number, N. | ||
> Calculating these triplets by hand would take me years, but I hear you are more than up to the task. | ||
> | ||
> Time is of the essence. | ||
> The future of my invention — and perhaps even the future of mathematical innovation — rests on your ability to solve this problem. | ||
Motivated by the importance of the task, you set out to find all Pythagorean triplets that satisfy the condition. | ||
Your work could have far-reaching implications, unlocking new possibilities in science and engineering. | ||
Can you rise to the challenge and make history? |
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": [ | ||
"pythagorean-triplet.ua" | ||
], | ||
"test": [ | ||
"tests.ua" | ||
], | ||
"example": [ | ||
".meta/example.ua" | ||
] | ||
}, | ||
"blurb": "Given an integer N, find all Pythagorean triplets for which a + b + c = N.", | ||
"source": "A variation of Problem 9 from Project Euler", | ||
"source_url": "https://projecteuler.net/problem=9" | ||
} |
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,10 @@ | ||
As ← +1⇡-1÷3 | ||
Bs ← ⍜-⇡ ⊃(+1|+1⌊÷2-) | ||
C ← -+ | ||
Valid ← =⊙+⊓⊓ⁿ₂ⁿ₂ⁿ₂ | ||
Triplet ← ⊂⊂ | ||
|
||
∵(∵(⨬(⊂⊙⋅∘|⋅⋅∘) ⊃(Valid|Triplet)◡C)Bs,,) As. 12 ↯3 | ||
3[] | ||
|
||
TripletsWithSum ← |1 ⊙(⍤"Please implement TripletsWithSum" 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,31 @@ | ||
# 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. | ||
|
||
[a19de65d-35b8-4480-b1af-371d9541e706] | ||
description = "triplets whose sum is 12" | ||
|
||
[48b21332-0a3d-43b2-9a52-90b2a6e5c9f5] | ||
description = "triplets whose sum is 108" | ||
|
||
[dffc1266-418e-4daa-81af-54c3e95c3bb5] | ||
description = "triplets whose sum is 1000" | ||
|
||
[5f86a2d4-6383-4cce-93a5-e4489e79b186] | ||
description = "no matching triplets for 1001" | ||
|
||
[bf17ba80-1596-409a-bb13-343bdb3b2904] | ||
description = "returns all matching triplets" | ||
|
||
[9d8fb5d5-6c6f-42df-9f95-d3165963ac57] | ||
description = "several matching triplets" | ||
|
||
[f5be5734-8aa0-4bd1-99a2-02adcc4402b4] | ||
description = "triplets for large number" |
3 changes: 3 additions & 0 deletions
3
exercises/practice/pythagorean-triplet/pythagorean-triplet.ua
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 @@ | ||
# Find the Pythagorean triplet for a given sum | ||
# Triplets ? Sum | ||
TripletsWithSum ← |1 ⊙(⍤"Please implement TripletsWithSum" 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,22 @@ | ||
~ "pythagorean-triplet.ua" ~ TripletsWithSum | ||
|
||
# Triplets whose sum is 12 | ||
⍤⤙≍ [3_4_5] TripletsWithSum 12 | ||
|
||
# Triplets whose sum is 108 | ||
⍤⤙≍ [27_36_45] TripletsWithSum 108 | ||
|
||
# Triplets whose sum is 1000 | ||
⍤⤙≍ [200_375_425] TripletsWithSum 1000 | ||
|
||
# No matching triplets for 1001 | ||
⍤⤙≍ [] TripletsWithSum 1001 | ||
|
||
# Returns all matching triplets | ||
⍤⤙≍ [9_40_41 15_36_39] TripletsWithSum 90 | ||
|
||
# Several matching triplets | ||
⍤⤙≍ [40_399_401 56_390_394 105_360_375 120_350_370 140_336_364 168_315_357 210_280_350 240_252_348] TripletsWithSum 840 | ||
|
||
# Triplets for large number | ||
⍤⤙≍ [1200_14375_14425 1875_14000_14125 5000_12000_13000 6000_11250_12750 7500_10000_12500] TripletsWithSum 30000 |