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 Question

Tweeted twitter.com/StackCodeGolf/status/708044422521491456
Fixed test case
Source Link
Zgarb
  • 43.2k
  • 4
  • 84
  • 265
" " -> " "
" ." -> ". "
". " -> "' "
"' " -> " '"
" '" -> " ."
": " -> "''"
"''" -> " :"
":." -> ":'"
":.'" -> ":'."
"..." -> ":. "
": :" -> "':."
"':." -> ".:'"
".:'" -> ": :"
" " -> " "
"::::" -> "::::"
":..:'." -> "::. :'"
" : .:'" -> ". '.. :"
": ''. :" -> "'' :'.."
"........" -> ":...... "
":::: " -> ":::'' "
" ::::" -> " ..:::"
" : : : : " -> ". : : : '"
".'.'.'.'.'" -> "'.'.'.'.'."
".. :: '.' :." -> ": ..'' .' :.'"
".' '.:: :.'. . ::.' '. . .::' :.'." -> "' ' .:.''..'.'. ..:' ' .'. ...:'''''..'.'"
" " -> " "
" ." -> ". "
". " -> "' "
"' " -> " '"
" '" -> " ."
": " -> "''"
"''" -> " :"
":." -> ":'"
":.'" -> ":'."
"..." -> ":. "
": :" -> "':."
"':." -> ".:'"
".:'" -> ": :"
" " -> " "
"::::" -> "::::"
":..:'." -> "::. :'"
" : .:'" -> ". '.. :"
": ''. :" -> "'' :'.."
"........" -> ":...... "
":::: " -> ":::'' "
" ::::" -> " ..:::"
" : : : : " -> ". : : : '"
".'.'.'.'.'" -> "'.'.'.'.'."
".. :: '.' :." -> ": ..'' .' :.'"
".' '.:: :.'. . ::.' '. . .::' :.'." -> "' ' .:.''..'.'. ..:' ' .'. ...:''..'.'"
" " -> " "
" ." -> ". "
". " -> "' "
"' " -> " '"
" '" -> " ."
": " -> "''"
"''" -> " :"
":." -> ":'"
":.'" -> ":'."
"..." -> ":. "
": :" -> "':."
"':." -> ".:'"
".:'" -> ": :"
" " -> " "
"::::" -> "::::"
":..:'." -> "::. :'"
" : .:'" -> ". '.. :"
": ''. :" -> "'' :'.."
"........" -> ":...... "
":::: " -> ":::'' "
" ::::" -> " ..:::"
" : : : : " -> ". : : : '"
".'.'.'.'.'" -> "'.'.'.'.'."
".. :: '.' :." -> ": ..'' .' :.'"
".' '.:: :.'. . ::.' '. . .::' :.'." -> "' ' .:.''..'.'. ..:' ' .'. ...'''..'.'"
Source Link
Zgarb
  • 43.2k
  • 4
  • 84
  • 265

Rotate the dots

Introductions

A ×ばつn Boolean matrix can be represented as a string of the four characters . ':. The string has an "upper row" and a "lower row", with dots representing 1s and empty spaces representing 0s. For example, the ×ばつ6 matrix

1 0 1 0 0 1
0 0 0 1 0 1

can be represented as ' '. :. Your task is to take a matrix in this "compressed form", and rotate its entries one step clockwise, like a conveyor belt.

Input

Your input is a single string over the characters . ':. Its length is guaranteed to be at least 2.

Output

Your output shall be the input string, but with every dot rotated one step in the clockwise direction. More explicitly, the dots on the upper row more one place to the right, except the rightmost one, which moves down. The dots on the lower row move one step to the left, except the leftmost one, which moves up. In particular, the output string must have the same length as the original, and whitespace is significant.

Example

Consider the input string :..:'., which corresponds to the ×ばつ6 matrix

1 0 0 1 1 0
1 1 1 1 0 1

The rotated version of this matrix is

1 1 0 0 1 1
1 1 1 0 1 0

which corresponds to the string ::. :'.

Rules and scoring

You can write a full program or a function. The lowest byte count wins, and standard loopholes are disallowed. You can decide whether the input and output are enclosed in quotes, and one trailing newline is also acceptable in both.

Test cases

These test cases are enclosed in double quotes.

" " -> " "
" ." -> ". "
". " -> "' "
"' " -> " '"
" '" -> " ."
": " -> "''"
"''" -> " :"
":." -> ":'"
":.'" -> ":'."
"..." -> ":. "
": :" -> "':."
"':." -> ".:'"
".:'" -> ": :"
" " -> " "
"::::" -> "::::"
":..:'." -> "::. :'"
" : .:'" -> ". '.. :"
": ''. :" -> "'' :'.."
"........" -> ":...... "
":::: " -> ":::'' "
" ::::" -> " ..:::"
" : : : : " -> ". : : : '"
".'.'.'.'.'" -> "'.'.'.'.'."
".. :: '.' :." -> ": ..'' .' :.'"
".' '.:: :.'. . ::.' '. . .::' :.'." -> "' ' .:.''..'.'. ..:' ' .'. ...:''..'.'"

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