Skip to main content
We’ve updated our Terms of Service. A new AI Addendum clarifies how Stack Overflow utilizes AI interactions.
Code Golf

Return to Answer

added 241 characters in body
Source Link
mazzy
  • 7.2k
  • 2
  • 13
  • 23

Powershell, 18(削除) 18 (削除ここまで) 12 bytes

$args|% t*y|%{' '}

-6 bytes thanks @Julian

$args|%{' '}

The expression % t*ysplits input strings into chars. This solution has same length as solution in the Matt's comment : " "*"$args".length.Try it online!

Testscript (use LF only mode in your editor):

$f = {
$args|% t*y|%{' '}
}
@(
,(13, "Hello, World!")
,(2, "Hi")
,(45, " Don't
Forget about
Existing
Whitespace! ")
,(0, "")
,(13, " ")
,(1,"
")
) | % {
 $len,$source=$_
 $r = &$f $source
 $l=$r.length
 "$($l-eq$len): $l"
}
$f = {
$args|% t*y|%{' '}
}
@(
,(13, "Hello, World!")
,(2, "Hi")
,(45, " Don't
Forget about
Existing
Whitespace! ")
,(0, "")
,(13, " ")
,(1,"
")
) | % {
 $len,$source=$_
 $r = &$f $source
 $l=$r.length
 "$($l-eq$len): $l"
}

Output:

True: 13
True: 2
True: 45
True: 0
True: 13
True: 1
True: 13
True: 2
True: 45
True: 0
True: 13
True: 1

Powershell + Regex, 20 bytes

$args-replace'.',' '
$args-replace'.',' '

Powershell, 18 bytes

$args|% t*y|%{' '}

The expression % t*ysplits input strings into chars. This solution has same length as solution in the Matt's comment : " "*"$args".length.

Testscript (use LF only mode in your editor):

$f = {
$args|% t*y|%{' '}
}
@(
,(13, "Hello, World!")
,(2, "Hi")
,(45, " Don't
Forget about
Existing
Whitespace! ")
,(0, "")
,(13, " ")
,(1,"
")
) | % {
 $len,$source=$_
 $r = &$f $source
 $l=$r.length
 "$($l-eq$len): $l"
}

Output:

True: 13
True: 2
True: 45
True: 0
True: 13
True: 1

Powershell + Regex, 20 bytes

$args-replace'.',' '

Powershell, (削除) 18 (削除ここまで) 12 bytes

-6 bytes thanks @Julian

$args|%{' '}

Try it online!

Testscript (use LF only mode in your editor):

$f = {
$args|% t*y|%{' '}
}
@(
,(13, "Hello, World!")
,(2, "Hi")
,(45, " Don't
Forget about
Existing
Whitespace! ")
,(0, "")
,(13, " ")
,(1,"
")
) | % {
 $len,$source=$_
 $r = &$f $source
 $l=$r.length
 "$($l-eq$len): $l"
}

Output:

True: 13
True: 2
True: 45
True: 0
True: 13
True: 1

Powershell + Regex, 20 bytes

$args-replace'.',' '
One more solution :)
Source Link
mazzy
  • 7.2k
  • 2
  • 13
  • 23

Powershell, 18 bytes

$args|% t*y|%{' '}

The expression % t*y splits input strings into chars. This solution has same length as solution in the Matt's comment: " "*"$args".length.

Testscript (use LF only mode in your editor):

$f = {
$args|% t*y|%{' '}
}
@(
,(13, "Hello, World!")
,(2, "Hi")
,(45, " Don't
Forget about
Existing
Whitespace! ")
,(0, "")
,(13, " ")
,(1,"
")
) | % {
 $len,$source=$_
 $r = &$f $source
 $l=$r.length
 "$($l-eq$len): $l"
}

Output:

True: 13
True: 2
True: 45
True: 0
True: 13
True: 1

Powershell + Regex, 20 bytes

$args-replace'.',' '

Powershell, 18 bytes

$args|% t*y|%{' '}

The expression % t*y splits input strings into chars. This solution has same length as solution in the Matt's comment: " "*"$args".length.

Testscript (use LF only mode in your editor):

$f = {
$args|% t*y|%{' '}
}
@(
,(13, "Hello, World!")
,(2, "Hi")
,(45, " Don't
Forget about
Existing
Whitespace! ")
,(0, "")
,(13, " ")
,(1,"
")
) | % {
 $len,$source=$_
 $r = &$f $source
 $l=$r.length
 "$($l-eq$len): $l"
}

Output:

True: 13
True: 2
True: 45
True: 0
True: 13
True: 1

Powershell, 18 bytes

$args|% t*y|%{' '}

The expression % t*y splits input strings into chars. This solution has same length as solution in the Matt's comment: " "*"$args".length.

Testscript (use LF only mode in your editor):

$f = {
$args|% t*y|%{' '}
}
@(
,(13, "Hello, World!")
,(2, "Hi")
,(45, " Don't
Forget about
Existing
Whitespace! ")
,(0, "")
,(13, " ")
,(1,"
")
) | % {
 $len,$source=$_
 $r = &$f $source
 $l=$r.length
 "$($l-eq$len): $l"
}

Output:

True: 13
True: 2
True: 45
True: 0
True: 13
True: 1

Powershell + Regex, 20 bytes

$args-replace'.',' '
Source Link
mazzy
  • 7.2k
  • 2
  • 13
  • 23

Powershell, 18 bytes

$args|% t*y|%{' '}

The expression % t*y splits input strings into chars. This solution has same length as solution in the Matt's comment: " "*"$args".length.

Testscript (use LF only mode in your editor):

$f = {
$args|% t*y|%{' '}
}
@(
,(13, "Hello, World!")
,(2, "Hi")
,(45, " Don't
Forget about
Existing
Whitespace! ")
,(0, "")
,(13, " ")
,(1,"
")
) | % {
 $len,$source=$_
 $r = &$f $source
 $l=$r.length
 "$($l-eq$len): $l"
}

Output:

True: 13
True: 2
True: 45
True: 0
True: 13
True: 1

AltStyle によって変換されたページ (->オリジナル) /