Created
June 28, 2021 15:10
-
-
Save megastary/3d4da66fe957cb245f25d58a7701725a to your computer and use it in GitHub Desktop.
The ABACABA sequence
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
# Author: Jakub Šindelář megastary@houby-studio.eu | |
# Date: 2021-06-28 | |
# Solution definition | |
function abacaba { | |
[CmdletBinding()] | |
param ( | |
[Parameter()] | |
[String] | |
$CurrentSequence = '', | |
[Parameter()] | |
[Int32] | |
$CurrentLoopIndex = 0 | |
) | |
$CurrentLetter = [char](65 + $CurrentLoopIndex) | |
$CurrentSequence = $CurrentSequence + $CurrentLetter + $CurrentSequence | |
$CurrentLoopIndex++ | |
if ($CurrentLoopIndex -eq 26) { | |
$CurrentSequence | |
} | |
else { | |
abacaba -CurrentSequence $CurrentSequence -CurrentLoopIndex $CurrentLoopIndex | |
} | |
} |
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
# Test result with Pester | |
# Install with: Install-Module Pester -MinimumVersion 4.0.0 -Force -SkipPublisherCheck | |
# Import tested script | |
BeforeAll { | |
. $PSCommandPath.Replace('.Tests.ps1', '.ps1') | |
$File = "$([IO.Path]::GetTempPath())/$([Guid]::NewGuid())abacaba.txt" | |
New-Item -Path $File | |
} | |
Describe 'abacaba' { | |
Context 'no parameters' { | |
It 'resulting length is 67,108,863 characters' { | |
$abacaba = abacaba | |
$abacaba.Length | Should -Be 67108863 | |
} | |
It 'resulting file size is 64MB' { | |
abacaba | Out-File -FilePath $File | |
[Int32]((Get-Item -Path $File).Length / 1MB) | Should -Be 64 | |
} | |
} | |
} | |
AfterAll { | |
if (Test-Path $File) { | |
Remove-Item -Path $File | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This gist is my PowerShell solution to challenge https://old.reddit.com/r/dailyprogrammer/comments/njxq95/20210524_challenge_391_easy_the_abacaba_sequence/