Skip to content
6 changes: 6 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -157,3 +157,9 @@ indent_size = 0
trim_trailing_whitespace = false
insert_final_newline = false
end_of_line = lf


# PowerShell
[*.ps1]
indent_style = space
indent_size = 4
4 changes: 4 additions & 0 deletions book.json
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,10 @@
{
"lang": "ss",
"name": "Scheme"
},
{
"lang": "ps1",
"name": "PowerShell"
}
]
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
function Sub-Euclid($a, $b) {
$a = [Math]::Abs($a)
$b = [Math]::Abs($b)

while ($a -ne $b) {
if ($a -gt $b) {
$a = $a - $b
} else {
$b = $b - $a
}
}

return $a
}

function Mod-Euclid($a, $b) {
$a = [Math]::Abs($a)
$b = [Math]::Abs($b)

while ($b -ne 0) {
$tmp = $b
$b = $a % $b
$a = $tmp
}

return $a
}

Write-Host "Subtraction-based euclidean algorithm result: $(Mod-Euclid $(64 * 67) $(64 * 81))"
Write-Host "Modulus-based euclidean algorithm result: $(Sub-Euclid $(128 * 12) $(128 * 77))"
12 changes: 12 additions & 0 deletions contents/euclidean_algorithm/euclidean_algorithm.md
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,10 @@ The algorithm is a simple way to find the *greatest common divisor* (GCD) of two
<p>
<img class="center" src="code/scratch/euclid_sub.svg" width="200" />
</p>
# leave one line empty:

{% sample lang="ps1" %}
[import:1-14, lang="powershell"](code/powershell/euclidean_algorithm.ps1)

{% endmethod %}

Expand Down Expand Up @@ -157,6 +161,10 @@ Modern implementations, though, often use the modulus operator (%) like so
<p>
<img class="center" src="code/scratch/euclid_mod.svg" width="200" />
</p>
# leave one line empty:

{% sample lang="ps1" %}
[import:16-27, lang="powershell"](code/powershell/euclidean_algorithm.ps1)

{% endmethod %}

Expand Down Expand Up @@ -264,6 +272,10 @@ The code snippets were taken from this [Scratch project](https://scratch.mit.edu
<p>
<img class="center" src="code/scratch/main.svg" width="200" />
</p>
# leave one line empty:

{% sample lang="ps1" %}
[import, lang="powershell"](code/powershell/euclidean_algorithm.ps1)

{% endmethod %}

Expand Down