function calculate_multiples ($limit){ $t= [Math]::floor($limit/3) $f= [Math]::floor($limit/5) $tf=[Math]::floor($limit/15) return (($t/2)*($t+1)*3)+(($f/2)*($f+1)*5)-(($tf/2)*($tf+1)*15) }
function calculate_multiples {- function calculate_multiples ($limit){
$SUM = 01..999 | ForEach-Object {if (!( $_ % 3) -OR !($_ % 5)) {$Sum += $_}}return $Sum- $t= [Math]::floor($limit/3)
- $f= [Math]::floor($limit/5)
- $tf=[Math]::floor($limit/15)
- return (($t/2)*($t+1)*3)+(($f/2)*($f+1)*5)-(($tf/2)*($tf+1)*15)
- }
# You can test with Pester (https://github.com/pester/Pester) # TODO: replace with your own tests (TDD), these are just here to demonstrate usage. $Results = calculate_multiples 9 Describe 'My Solution 9' { It 'Should return 23' { $Results | Should be 23 } } $Results = calculate_multiples 999 Describe 'My Solution 999' { It 'Should return 233168' { $Results | Should be 233168 } }
- # You can test with Pester (https://github.com/pester/Pester)
- # TODO: replace with your own tests (TDD), these are just here to demonstrate usage.
$Results = calculate_multiples- $Results = calculate_multiples 9
Describe 'My Solution' {- Describe 'My Solution 9' {
- It 'Should return 23' {
- $Results | Should be 23
- }
- }
- $Results = calculate_multiples 999
- Describe 'My Solution 999' {
- It 'Should return 233168' {
- $Results | Should be 233168
- }
- }