Skip to main content
Commonmark migration
Source Link

#Powershell

Powershell

((1..9)|%{
    $_ = ($_%18-5)
5 - @($_,-$_)[$_ -lt -$_]
})-join ' '

1 variable, no if, no functions (unless you were to count -join which is just for displaying the data...

Explanation: Loops from 1 to 9, then for each value calculates the reminder of the current value by 18, then subtracts 5 and assigns it to the currently used $_ variable. After that it evaluates $_ < -$_ (this is to handle negative values), and uses the result (False/True) to get the value from the array @($_,-$_), therefore making sure we always get a positive number in this case, after that it subtracts this number to 5 and finally joins the results with space.

#Powershell

((1..9)|%{
    $_ = ($_%18-5)
5 - @($_,-$_)[$_ -lt -$_]
})-join ' '

1 variable, no if, no functions (unless you were to count -join which is just for displaying the data...

Explanation: Loops from 1 to 9, then for each value calculates the reminder of the current value by 18, then subtracts 5 and assigns it to the currently used $_ variable. After that it evaluates $_ < -$_ (this is to handle negative values), and uses the result (False/True) to get the value from the array @($_,-$_), therefore making sure we always get a positive number in this case, after that it subtracts this number to 5 and finally joins the results with space.

Powershell

((1..9)|%{
    $_ = ($_%18-5)
5 - @($_,-$_)[$_ -lt -$_]
})-join ' '

1 variable, no if, no functions (unless you were to count -join which is just for displaying the data...

Explanation: Loops from 1 to 9, then for each value calculates the reminder of the current value by 18, then subtracts 5 and assigns it to the currently used $_ variable. After that it evaluates $_ < -$_ (this is to handle negative values), and uses the result (False/True) to get the value from the array @($_,-$_), therefore making sure we always get a positive number in this case, after that it subtracts this number to 5 and finally joins the results with space.

Source Link
DarkAjax
  • 669
  • 3
  • 8

#Powershell

((1..9)|%{
    $_ = ($_%18-5)
5 - @($_,-$_)[$_ -lt -$_]
})-join ' '

1 variable, no if, no functions (unless you were to count -join which is just for displaying the data...

Explanation: Loops from 1 to 9, then for each value calculates the reminder of the current value by 18, then subtracts 5 and assigns it to the currently used $_ variable. After that it evaluates $_ < -$_ (this is to handle negative values), and uses the result (False/True) to get the value from the array @($_,-$_), therefore making sure we always get a positive number in this case, after that it subtracts this number to 5 and finally joins the results with space.