Skip to main content
Commonmark migration
Source Link

##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 base 2
  • 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]s ToInt32 from base 2, which is finally stored that into $c
  • If $c is greater than 31, or equal to 10, 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

##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: Takes 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 base 2
  • 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]s ToInt32 from base 2, which is finally stored that into $c
  • If $c is greater than 31, or equal to 10, 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

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:

Takes 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 base 2
  • 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]s ToInt32 from base 2, which is finally stored that into $c
  • If $c is greater than 31, or equal to 10, 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
replaced http://codegolf.stackexchange.com/ with https://codegolf.stackexchange.com/
Source Link

##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: Takes 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 base 2
  • 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 stringinverting a binary string and recast the result as a string with "$(..)"
  • We feed that string into a different .NET call that [convert]s ToInt32 from base 2, which is finally stored that into $c
  • If $c is greater than 31, or equal to 10, 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

##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: Takes 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 base 2
  • 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]s ToInt32 from base 2, which is finally stored that into $c
  • If $c is greater than 31, or equal to 10, 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

##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: Takes 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 base 2
  • 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]s ToInt32 from base 2, which is finally stored that into $c
  • If $c is greater than 31, or equal to 10, 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
Changed how int cast to save a couple bytes
Source Link
AdmBorkBork
  • 43.5k
  • 5
  • 103
  • 284

##PowerShell, (199-15%)=169.15 175 (175171 -15% 15%)=148=145.7535

param([char[]]$a)($a|%{$b=[convert]::ToString([int]$_+$_,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: Takes 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 [int]$_+$_ and [convert]ed to base 2
  • 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]s ToInt32 from base 2, which is finally stored that into $c
  • If $c is greater than 31, or equal to 10, 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

##PowerShell, (199-15%)=169.15 (175-15%)=148.75

param([char[]]$a)($a|%{$b=[convert]::ToString([int]$_,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: Takes 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 [int]$_ [convert]ed to base 2
  • 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]s ToInt32 from base 2, which is finally stored that into $c
  • If $c is greater than 31, or equal to 10, 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

##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: Takes 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 base 2
  • 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]s ToInt32 from base 2, which is finally stored that into $c
  • If $c is greater than 31, or equal to 10, 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
Saved 24 bytes by changing how $b gets reversed
Source Link
AdmBorkBork
  • 43.5k
  • 5
  • 103
  • 284
Loading
Source Link
AdmBorkBork
  • 43.5k
  • 5
  • 103
  • 284
Loading