Skip to content

Instantly share code, notes, and snippets.

@megastary
Created June 28, 2021 15:10
Show Gist options
  • Save megastary/3d4da66fe957cb245f25d58a7701725a to your computer and use it in GitHub Desktop.
Save megastary/3d4da66fe957cb245f25d58a7701725a to your computer and use it in GitHub Desktop.
The ABACABA sequence
# 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
}
}
# 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
}
}
@megastary
Copy link
Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment