diff --git a/powershell/leap/.exercism/config.json b/powershell/leap/.exercism/config.json new file mode 100644 index 0000000..084d7c2 --- /dev/null +++ b/powershell/leap/.exercism/config.json @@ -0,0 +1,23 @@ +{ + "blurb": "Given a year, report if it is a leap year.", + "authors": [ + "spuder" + ], + "contributors": [ + "gyssels", + "kchenery" + ], + "files": { + "solution": [ + "LeapYear.ps1" + ], + "test": [ + "LeapYear.tests.ps1" + ], + "example": [ + ".meta/LeapYear.example.ps1" + ] + }, + "source": "JavaRanch Cattle Drive, exercise 3", + "source_url": "http://www.javaranch.com/leap.jsp" +} diff --git a/powershell/leap/.exercism/metadata.json b/powershell/leap/.exercism/metadata.json new file mode 100644 index 0000000..f8b368c --- /dev/null +++ b/powershell/leap/.exercism/metadata.json @@ -0,0 +1 @@ +{"track":"powershell","exercise":"leap","id":"0a3fd49cec7f4abab206a09b5accdf20","url":"https://exercism.org/tracks/powershell/exercises/leap","handle":"Xevion","is_requester":true,"auto_approve":false} \ No newline at end of file diff --git a/powershell/leap/.version b/powershell/leap/.version new file mode 100644 index 0000000..d00491f --- /dev/null +++ b/powershell/leap/.version @@ -0,0 +1 @@ +1 diff --git a/powershell/leap/HELP.md b/powershell/leap/HELP.md new file mode 100644 index 0000000..c4683b9 --- /dev/null +++ b/powershell/leap/HELP.md @@ -0,0 +1,33 @@ +# Help + +## Running the tests + +To run the tests run the command `Invoke-Pester` from within the exercise directory. + +## Submitting your solution + +You can submit your solution using the `exercism submit LeapYear.ps1` command. +This command will upload your solution to the Exercism website and print the solution page's URL. + +It's possible to submit an incomplete solution which allows you to: + +- See how others have completed the exercise +- Request help from a mentor + +## Need to get help? + +If you'd like help solving the exercise, check the following pages: + +- The [PowerShell track's documentation](https://exercism.org/docs/tracks/powershell) +- [Exercism's support channel on gitter](https://gitter.im/exercism/support) +- The [Frequently Asked Questions](https://exercism.org/docs/using/faqs) + +Should those resources not suffice, you could submit your (incomplete) solution to request mentoring. + +To get help if you are having trouble, you can use one of the following resources: + +- [Powershell Documentation][powershell docs] + +[Add more resources]: TODO + +[powershell docs]: https://docs.microsoft.com/en-us/powershell/ \ No newline at end of file diff --git a/powershell/leap/LeapYear.ps1 b/powershell/leap/LeapYear.ps1 new file mode 100644 index 0000000..3dfa4af --- /dev/null +++ b/powershell/leap/LeapYear.ps1 @@ -0,0 +1,9 @@ +function Test-LeapYear { + param( [int]$year ) + + if ((($year % 4 -eq 0) -and !($year % 100 -eq 0)) -or ($year % 400 -eq 0)) { + return $true + } + + return $false +} diff --git a/powershell/leap/LeapYear.tests.ps1 b/powershell/leap/LeapYear.tests.ps1 new file mode 100644 index 0000000..05dd388 --- /dev/null +++ b/powershell/leap/LeapYear.tests.ps1 @@ -0,0 +1,21 @@ +BeforeAll { + . ".\LeapYear.ps1" +} + +Describe "LeapYear Tests" { + It "Year not divisible by 4: common year" { + Test-LeapYear(2015) | Should -Be $false + } + + It "Year divisible by 4, not divisible by 100: leap year" { + Test-LeapYear(1996) | Should -Be $true + } + + It "Year divisible by 100, not divisible by 400: common year" { + Test-LeapYear(2100) | Should -Be $false + } + + It "Year divisible by 400: leap year" { + Test-LeapYear(2000) | Should -Be $true + } +} diff --git a/powershell/leap/README.md b/powershell/leap/README.md new file mode 100644 index 0000000..f707d6b --- /dev/null +++ b/powershell/leap/README.md @@ -0,0 +1,44 @@ +# Leap + +Welcome to Leap on Exercism's PowerShell Track. +If you need help running the tests or submitting your code, check out `HELP.md`. + +## Instructions + +Given a year, report if it is a leap year. + +The tricky thing here is that a leap year in the Gregorian calendar occurs: + +```text +on every year that is evenly divisible by 4 + except every year that is evenly divisible by 100 + unless the year is also evenly divisible by 400 +``` + +For example, 1997 is not a leap year, but 1996 is. 1900 is not a leap +year, but 2000 is. + +## Notes + +Though our exercise adopts some very simple rules, there is more to +learn! + +For a delightful, four minute explanation of the whole leap year +phenomenon, go watch [this youtube video][video]. + +[video]: http://www.youtube.com/watch?v=xX96xng7sAE + +## Source + +### Created by + +- @spuder + +### Contributed to by + +- @gyssels +- @kchenery + +### Based on + +JavaRanch Cattle Drive, exercise 3 - http://www.javaranch.com/leap.jsp \ No newline at end of file diff --git a/powershell/raindrops/.exercism/config.json b/powershell/raindrops/.exercism/config.json new file mode 100644 index 0000000..bd7c812 --- /dev/null +++ b/powershell/raindrops/.exercism/config.json @@ -0,0 +1,22 @@ +{ + "blurb": "Convert a number to a string, the content of which depends on the number's factors.", + "authors": [ + "gyssels" + ], + "contributors": [ + "kchenery" + ], + "files": { + "solution": [ + "Raindrops.ps1" + ], + "test": [ + "Raindrops.tests.ps1" + ], + "example": [ + ".meta/Raindrops.example.ps1" + ] + }, + "source": "A variation on FizzBuzz, a famous technical interview question that is intended to weed out potential candidates. That question is itself derived from Fizz Buzz, a popular children's game for teaching division.", + "source_url": "https://en.wikipedia.org/wiki/Fizz_buzz" +} diff --git a/powershell/raindrops/.exercism/metadata.json b/powershell/raindrops/.exercism/metadata.json new file mode 100644 index 0000000..41e4e40 --- /dev/null +++ b/powershell/raindrops/.exercism/metadata.json @@ -0,0 +1 @@ +{"track":"powershell","exercise":"raindrops","id":"5b35a1ecc3b94181bc46ed1119958c44","url":"https://exercism.org/tracks/powershell/exercises/raindrops","handle":"Xevion","is_requester":true,"auto_approve":false} \ No newline at end of file diff --git a/powershell/raindrops/.version b/powershell/raindrops/.version new file mode 100644 index 0000000..c227083 --- /dev/null +++ b/powershell/raindrops/.version @@ -0,0 +1 @@ +0 \ No newline at end of file diff --git a/powershell/raindrops/0 b/powershell/raindrops/0 new file mode 100644 index 0000000..573541a --- /dev/null +++ b/powershell/raindrops/0 @@ -0,0 +1 @@ +0 diff --git a/powershell/raindrops/HELP.md b/powershell/raindrops/HELP.md new file mode 100644 index 0000000..d47097f --- /dev/null +++ b/powershell/raindrops/HELP.md @@ -0,0 +1,33 @@ +# Help + +## Running the tests + +To run the tests run the command `Invoke-Pester` from within the exercise directory. + +## Submitting your solution + +You can submit your solution using the `exercism submit Raindrops.ps1` command. +This command will upload your solution to the Exercism website and print the solution page's URL. + +It's possible to submit an incomplete solution which allows you to: + +- See how others have completed the exercise +- Request help from a mentor + +## Need to get help? + +If you'd like help solving the exercise, check the following pages: + +- The [PowerShell track's documentation](https://exercism.org/docs/tracks/powershell) +- [Exercism's support channel on gitter](https://gitter.im/exercism/support) +- The [Frequently Asked Questions](https://exercism.org/docs/using/faqs) + +Should those resources not suffice, you could submit your (incomplete) solution to request mentoring. + +To get help if you are having trouble, you can use one of the following resources: + +- [Powershell Documentation][powershell docs] + +[Add more resources]: TODO + +[powershell docs]: https://docs.microsoft.com/en-us/powershell/ \ No newline at end of file diff --git a/powershell/raindrops/README.md b/powershell/raindrops/README.md new file mode 100644 index 0000000..1643fc3 --- /dev/null +++ b/powershell/raindrops/README.md @@ -0,0 +1,35 @@ +# Raindrops + +Welcome to Raindrops on Exercism's PowerShell Track. +If you need help running the tests or submitting your code, check out `HELP.md`. + +## Instructions + +Your task is to convert a number into a string that contains raindrop sounds corresponding to certain potential factors. A factor is a number that evenly divides into another number, leaving no remainder. The simplest way to test if a one number is a factor of another is to use the [modulo operation](https://en.wikipedia.org/wiki/Modulo_operation). + +The rules of `raindrops` are that if a given number: + +- has 3 as a factor, add 'Pling' to the result. +- has 5 as a factor, add 'Plang' to the result. +- has 7 as a factor, add 'Plong' to the result. +- _does not_ have any of 3, 5, or 7 as a factor, the result should be the digits of the number. + +## Examples + +- 28 has 7 as a factor, but not 3 or 5, so the result would be "Plong". +- 30 has both 3 and 5 as factors, but not 7, so the result would be "PlingPlang". +- 34 is not factored by 3, 5, or 7, so the result would be "34". + +## Source + +### Created by + +- @gyssels + +### Contributed to by + +- @kchenery + +### Based on + +A variation on FizzBuzz, a famous technical interview question that is intended to weed out potential candidates. That question is itself derived from Fizz Buzz, a popular children's game for teaching division. - https://en.wikipedia.org/wiki/Fizz_buzz \ No newline at end of file diff --git a/powershell/raindrops/Raindrops.ps1 b/powershell/raindrops/Raindrops.ps1 new file mode 100644 index 0000000..b97d06b --- /dev/null +++ b/powershell/raindrops/Raindrops.ps1 @@ -0,0 +1,40 @@ +Function Get-Raindrops() { + <# + .SYNOPSIS + Given a number convert it to Pling, Plang, Plong if it has factors of 3, 5 or 7. + + .DESCRIPTION + Convert a number to a string, the contents of which depend on the number's factors. + + - If the number has 3 as a factor, output 'Pling'. + - If the number has 5 as a factor, output 'Plang'. + - If the number has 7 as a factor, output 'Plong'. + - If the number does not have 3, 5, or 7 as a factor, just pass the number's digits straight through. + + .PARAMETER Rain + The number to evaluate + + .EXAMPLE + Get-Raindrops -Rain 35 + + This will return PlangPlong as it has factors of 5 and 7 + + .EXAMPLE + Get-Raindrops -Rain 12121 + + This will return 12121 as it does not contain factors of 3, 5 or 7 so the value is passed through. + #> + [CmdletBinding()] + Param( + [int]$Rain + ) + + + [String] $result = "" + if ($Rain % 3 -eq 0) { $result += "Pling" } + if ($Rain % 5 -eq 0) { $result += "Plang" } + if ($Rain % 7 -eq 0) { $result += "Plong" } + + if ($result.Length -gt 0) { return $result } + return $Rain.ToString() +} \ No newline at end of file diff --git a/powershell/raindrops/Raindrops.tests.ps1 b/powershell/raindrops/Raindrops.tests.ps1 new file mode 100644 index 0000000..6a50712 --- /dev/null +++ b/powershell/raindrops/Raindrops.tests.ps1 @@ -0,0 +1,34 @@ +BeforeAll { + . ".\Raindrops.ps1" +} + +Describe "Test Get-Raindrops" { + + It "Given the number it should output " -TestCases @( + @{ Number = 1; Result = "1" }, + @{ Number = 3; Result = "Pling" }, + @{ Number = 5; Result = "Plang" }, + @{ Number = 7; Result = "Plong" }, + @{ Number = 6; Result = "Pling" }, + @{ Number = 9; Result = "Pling" }, + @{ Number = 10; Result = "Plang" }, + @{ Number = 14; Result = "Plong" }, + @{ Number = 15; Result = "PlingPlang" }, + @{ Number = 21; Result = "PlingPlong" }, + @{ Number = 25; Result = "Plang" }, + @{ Number = 27; Result = "Pling" }, + @{ Number = 35; Result = "PlangPlong" }, + @{ Number = 49; Result = "Plong" }, + @{ Number = 52; Result = "52" }, + @{ Number = 105; Result = "PlingPlangPlong" }, + @{ Number = 3125; Result = "Plang" }, + @{ Number = 12121; Result = "12121" } + ) { + Param( + [int]$Number, + [string]$Result + ) + + Get-Raindrops -Rain $Number | Should -BeExactly $Result + } +} \ No newline at end of file diff --git a/powershell/reverse-string/.exercism/config.json b/powershell/reverse-string/.exercism/config.json new file mode 100644 index 0000000..66bc657 --- /dev/null +++ b/powershell/reverse-string/.exercism/config.json @@ -0,0 +1,22 @@ +{ + "blurb": "Reverse a string", + "authors": [ + "gyssels" + ], + "contributors": [ + "kchenery" + ], + "files": { + "solution": [ + "ReverseString.ps1" + ], + "test": [ + "ReverseString.tests.ps1" + ], + "example": [ + ".meta/ReverseString.example.ps1" + ] + }, + "source": "Introductory challenge to reverse an input string", + "source_url": "https://medium.freecodecamp.org/how-to-reverse-a-string-in-javascript-in-3-different-ways-75e4763c68cb" +} diff --git a/powershell/reverse-string/.exercism/metadata.json b/powershell/reverse-string/.exercism/metadata.json new file mode 100644 index 0000000..064c1ec --- /dev/null +++ b/powershell/reverse-string/.exercism/metadata.json @@ -0,0 +1 @@ +{"track":"powershell","exercise":"reverse-string","id":"675925dac0bc4ca59b00bd1f0515381e","url":"https://exercism.org/tracks/powershell/exercises/reverse-string","handle":"Xevion","is_requester":true,"auto_approve":false} \ No newline at end of file diff --git a/powershell/reverse-string/.version b/powershell/reverse-string/.version new file mode 100644 index 0000000..d00491f --- /dev/null +++ b/powershell/reverse-string/.version @@ -0,0 +1 @@ +1 diff --git a/powershell/reverse-string/HELP.md b/powershell/reverse-string/HELP.md new file mode 100644 index 0000000..2e82548 --- /dev/null +++ b/powershell/reverse-string/HELP.md @@ -0,0 +1,33 @@ +# Help + +## Running the tests + +To run the tests run the command `Invoke-Pester` from within the exercise directory. + +## Submitting your solution + +You can submit your solution using the `exercism submit ReverseString.ps1` command. +This command will upload your solution to the Exercism website and print the solution page's URL. + +It's possible to submit an incomplete solution which allows you to: + +- See how others have completed the exercise +- Request help from a mentor + +## Need to get help? + +If you'd like help solving the exercise, check the following pages: + +- The [PowerShell track's documentation](https://exercism.org/docs/tracks/powershell) +- [Exercism's support channel on gitter](https://gitter.im/exercism/support) +- The [Frequently Asked Questions](https://exercism.org/docs/using/faqs) + +Should those resources not suffice, you could submit your (incomplete) solution to request mentoring. + +To get help if you are having trouble, you can use one of the following resources: + +- [Powershell Documentation][powershell docs] + +[Add more resources]: TODO + +[powershell docs]: https://docs.microsoft.com/en-us/powershell/ \ No newline at end of file diff --git a/powershell/reverse-string/README.md b/powershell/reverse-string/README.md new file mode 100644 index 0000000..8c42145 --- /dev/null +++ b/powershell/reverse-string/README.md @@ -0,0 +1,26 @@ +# Reverse String + +Welcome to Reverse String on Exercism's PowerShell Track. +If you need help running the tests or submitting your code, check out `HELP.md`. + +## Instructions + +Reverse a string + +For example: +input: "cool" +output: "looc" + +## Source + +### Created by + +- @gyssels + +### Contributed to by + +- @kchenery + +### Based on + +Introductory challenge to reverse an input string - https://medium.freecodecamp.org/how-to-reverse-a-string-in-javascript-in-3-different-ways-75e4763c68cb \ No newline at end of file diff --git a/powershell/reverse-string/ReverseString.ps1 b/powershell/reverse-string/ReverseString.ps1 new file mode 100644 index 0000000..bbb3da7 --- /dev/null +++ b/powershell/reverse-string/ReverseString.ps1 @@ -0,0 +1,11 @@ +Function Get-ReverseString { + [CmdletBinding()] + Param( + [Parameter(Position=1, ValueFromPipeline=$true)] + [string]$Forward + ) + + $x = $Forward.ToCharArray() + [array]::Reverse($x) + return -join $x +} diff --git a/powershell/reverse-string/ReverseString.tests.ps1 b/powershell/reverse-string/ReverseString.tests.ps1 new file mode 100644 index 0000000..a9ab1c7 --- /dev/null +++ b/powershell/reverse-string/ReverseString.tests.ps1 @@ -0,0 +1,21 @@ +BeforeAll { + . ".\ReverseString.ps1" +} + +Describe "Get-ReverseString Tests" { + It "Given it outputs " -TestCases @( + @{ Forward = ""; Reverse = "" }, + @{ Forward = "PowerShell"; Reverse = "llehSrewoP" }, + @{ Forward = "robot"; Reverse = "tobor" }, + @{ Forward = "Ramen"; Reverse = "nemaR" }, + @{ Forward = "I'm hungry!"; Reverse = "!yrgnuh m'I" }, + @{ Forward = "racecar"; Reverse = "racecar" } + ) { + Param( + [string]$Forward, + [string]$Reverse + ) + + Get-ReverseString -Forward $Forward | Should -BeExactly $Reverse + } +} diff --git a/powershell/two-fer/.exercism/config.json b/powershell/two-fer/.exercism/config.json new file mode 100644 index 0000000..8a5364e --- /dev/null +++ b/powershell/two-fer/.exercism/config.json @@ -0,0 +1,23 @@ +{ + "blurb": "Create a sentence of the form \"One for X, one for me.\"", + "authors": [ + "gyssels" + ], + "contributors": [ + "cmccandless", + "kchenery", + "sjwarner" + ], + "files": { + "solution": [ + "TwoFer.ps1" + ], + "test": [ + "TwoFer.tests.ps1" + ], + "example": [ + ".meta/TwoFer.example.ps1" + ] + }, + "source_url": "https://github.com/exercism/problem-specifications/issues/757" +} diff --git a/powershell/two-fer/.exercism/metadata.json b/powershell/two-fer/.exercism/metadata.json new file mode 100644 index 0000000..b4494cb --- /dev/null +++ b/powershell/two-fer/.exercism/metadata.json @@ -0,0 +1 @@ +{"track":"powershell","exercise":"two-fer","id":"ee6acfe67bf6423e8ceab007e73d57ac","url":"https://exercism.org/tracks/powershell/exercises/two-fer","handle":"Xevion","is_requester":true,"auto_approve":false} \ No newline at end of file diff --git a/powershell/two-fer/.version b/powershell/two-fer/.version new file mode 100644 index 0000000..d00491f --- /dev/null +++ b/powershell/two-fer/.version @@ -0,0 +1 @@ +1 diff --git a/powershell/two-fer/HELP.md b/powershell/two-fer/HELP.md new file mode 100644 index 0000000..275f6e3 --- /dev/null +++ b/powershell/two-fer/HELP.md @@ -0,0 +1,33 @@ +# Help + +## Running the tests + +To run the tests run the command `Invoke-Pester` from within the exercise directory. + +## Submitting your solution + +You can submit your solution using the `exercism submit TwoFer.ps1` command. +This command will upload your solution to the Exercism website and print the solution page's URL. + +It's possible to submit an incomplete solution which allows you to: + +- See how others have completed the exercise +- Request help from a mentor + +## Need to get help? + +If you'd like help solving the exercise, check the following pages: + +- The [PowerShell track's documentation](https://exercism.org/docs/tracks/powershell) +- [Exercism's support channel on gitter](https://gitter.im/exercism/support) +- The [Frequently Asked Questions](https://exercism.org/docs/using/faqs) + +Should those resources not suffice, you could submit your (incomplete) solution to request mentoring. + +To get help if you are having trouble, you can use one of the following resources: + +- [Powershell Documentation][powershell docs] + +[Add more resources]: TODO + +[powershell docs]: https://docs.microsoft.com/en-us/powershell/ \ No newline at end of file diff --git a/powershell/two-fer/README.md b/powershell/two-fer/README.md new file mode 100644 index 0000000..a6bac85 --- /dev/null +++ b/powershell/two-fer/README.md @@ -0,0 +1,47 @@ +# Two Fer + +Welcome to Two Fer on Exercism's PowerShell Track. +If you need help running the tests or submitting your code, check out `HELP.md`. + +## Instructions + +`Two-fer` or `2-fer` is short for two for one. One for you and one for me. + +Given a name, return a string with the message: + +```text +One for name, one for me. +``` + +Where "name" is the given name. + +However, if the name is missing, return the string: + +```text +One for you, one for me. +``` + +Here are some examples: + +|Name |String to return +|:-------|:------------------ +|Alice |One for Alice, one for me. +|Bob |One for Bob, one for me. +| |One for you, one for me. +|Zaphod |One for Zaphod, one for me. + +## Source + +### Created by + +- @gyssels + +### Contributed to by + +- @cmccandless +- @kchenery +- @sjwarner + +### Based on + +https://github.com/exercism/problem-specifications/issues/757 \ No newline at end of file diff --git a/powershell/two-fer/TwoFer.ps1 b/powershell/two-fer/TwoFer.ps1 new file mode 100644 index 0000000..90e0917 --- /dev/null +++ b/powershell/two-fer/TwoFer.ps1 @@ -0,0 +1,32 @@ +Function Get-TwoFer(){ + <# + .SYNOPSIS + "Two-fer" is short for two for one. One for you and one for me. + + .DESCRIPTION + If the given name is "Alice", the result should be "One for Alice, one for me." + If no name is given, the result should be "One for you, one for me." + + .PARAMETER Name + The name to use. + + .EXAMPLE + Get-TwoFer + + Will return: One for you, one for me + + .EXAMPLE + Get-TwoFer -Name Alice + + Will return: One for Alice, one for me + #> + [CmdletBinding()] + Param( + [Parameter(Mandatory=$false, Position=0)] + [string]$Name + ) + + # if ($Name -eq $null -or $Name.Length -eq 0) { $Name = 'you'} + if ([string]::IsNullOrEmpty($Name)) { $Name = 'you' } + return "One for $($Name), one for me" +} \ No newline at end of file diff --git a/powershell/two-fer/TwoFer.tests.ps1 b/powershell/two-fer/TwoFer.tests.ps1 new file mode 100644 index 0000000..5e143df --- /dev/null +++ b/powershell/two-fer/TwoFer.tests.ps1 @@ -0,0 +1,18 @@ +BeforeAll { + . ".\TwoFer.ps1" +} + +Describe "Get-TwoFer Tests" { + + It "Given expects " -TestCases @( + @{ Name = $null; Expected = "One for you, one for me" }, + @{ Name = ""; Expected = "One for you, one for me" }, + @{ Name = "Alice"; Expected = "One for Alice, one for me" } + ) { + Param( + $Name, $Expected + ) + + Get-TwoFer -Name $Name | Should -Be $Expected + } +} \ No newline at end of file