##PowerShell, 199 175 (171 - 15%)=145.35
PowerShell, 199 175 (171 - 15%)=145.35
param([char[]]$a)($a|%{$b=[convert]::ToString(+$_,2);$c=[convert]::ToInt32("$((-join$b[$b.Length..0])-split0-replace1,0-join1)",2);if($c-gt31-or$c-eq10){[char]$c}})-join''
Uses an unfortunate amount of some .NET calls/built-ins, which significantly bloats the code.
Explained:
###Explained:
TakesTakes the input param(..)
and casts it as a char[]
so we can work through it appropriately.
The next bit (..)-join''
collects and joins our output together.
Inside those parens, we iterate with $a|%{..}
as a foreach loop.
Inside the loop:
- We create a new string
$b
, which is our input letter cast as an int+$_
and[convert]
ed to base2
- This next bit, setting
$c
, is tricky, so let's start inside and work our way out - We reverse the string
$b
with(-join$b[$b.length..0])
- We leverage my previous code for inverting a binary string and recast the result as a string with
"$(..)"
- We feed that string into a different .NET call that
[convert]
sToInt32
from base2
, which is finally stored that into$c
- If
$c
is greater than31
, or equal to10
, we cast it as a char and that value is left on the pipeline for output (which is what gets collected and-join''
ed together, above), else nothing gets left on this particular iteration
Phew.
Qualifies for the -15% bonus, as well.
Example
PS C:\Tools\Scripts\golfing> .\reverse-and-invert-a-string.ps1 "Hello, World!"
v,dd2>
Xdl