57
\$\begingroup\$

Introductions

A 2×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 2×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 2×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.

" " -> " "
" ." -> ". "
". " -> "' "
"' " -> " '"
" '" -> " ."
": " -> "''"
"''" -> " :"
":." -> ":'"
":.'" -> ":'."
"..." -> ":. "
": :" -> "':."
"':." -> ".:'"
".:'" -> ": :"
" " -> " "
"::::" -> "::::"
":..:'." -> "::. :'"
" : .:'" -> ". '.. :"
": ''. :" -> "'' :'.."
"........" -> ":...... "
":::: " -> ":::'' "
" ::::" -> " ..:::"
" : : : : " -> ". : : : '"
".'.'.'.'.'" -> "'.'.'.'.'."
".. :: '.' :." -> ": ..'' .' :.'"
".' '.:: :.'. . ::.' '. . .::' :.'." -> "' ' .:.''..'.'. ..:' ' .'. ...'''..'.'"
asked Mar 10, 2016 at 18:34
\$\endgroup\$
0

26 Answers 26

13
\$\begingroup\$

JavaScript (ES6), (削除) 100 (削除ここまで) (削除) 97 (削除ここまで) 93 bytes

Saved 4 bytes thanks to @edc65

s=>s.replace(/./g,(c,i)=>" '.:"[(i?q>' '&q!=".":c>"'")+(q=c,s[++i]?s[i]>"'":c>' '&c!=".")*2])

How it works

This decides on the character we need to insert by performing some calculations on the chars before and after the current one. We sum:

  • If it's the first char, and it has a dot on the bottom, 2;
  • Otherwise, if the one before it has a dot on top, 2.
  • If it's the last char, and it has a dot on top, 1;
  • Otherwise, if the one after it has a dot on the bottom, 1.

This sums nicely to 0 for a space, 1 for ', 2 for ., and 3 for :.

Test snippet

f=s=>s.replace(/./g,(c,i)=>" '.:"[(i?q>' '&q!=".":c>"'")+(q=c,s[++i]?s[i]>"'":c>' '&c!=".")*2])
Try it out:
<input id=A type="text" value=".' '.:: :.'. . ::.' '. . .::' :.'.">
<button onclick="B.innerHTML=f(A.value)">Run</button>
<pre id=B></pre>

answered Mar 10, 2016 at 20:08
\$\endgroup\$
2
  • \$\begingroup\$ Well done. Save 4: s=>s.replace(/./g,(c,i)=>" '.:"[(i?q>' '&q!=".":c>"'")+(q=c,s[++i]?s[i]>"'":c>' '&c!=".")*2]) (flip 2 parts so I can increase i, less regexp and more simple test, save prev c in q) \$\endgroup\$ Commented Mar 10, 2016 at 22:55
  • \$\begingroup\$ @edc65 Thanks for the tip! \$\endgroup\$ Commented Mar 11, 2016 at 1:15
10
\$\begingroup\$

Jelly, (削除) 32 (削除ここまで) (削除) 30 (削除ここまで) 29 bytes

,Ṛe€""':".:"μṪ€;"ṚU1¦ZḄị"'.: 

Note the trailing space. Try it online! or verify all test cases.

Background

We begin by considering the input string (e.g., :..:'.) and its reverse.

:..:'.
.':..:

For each character in the top row, we check if it belongs to ':, and for each character of the bottom row if it belongs to .:. This gives the 2D array of Booleans

100110
101111

which is the matrix from the question, with reversed bottom row.

We remove the last Boolean of each row, reverse the order of the rows, prepend the Booleans in their original order, and finally reverse the top row.

100110 10011 10111 010111 111010
101111 10111 10011 110011 110011

This yields the rotated matrix from the question.

Finally, we consider each column of Booleans a binary number and index into '.: to obtain the appropriate characters.

332031 ::. :'

How it works

,Ṛe€""':".:"μṪ€;"ṚU1¦ZḄ‘ị"'.: Main link. Argument: S (string)
 Ṛ Reverse S.
, Form a pair of S and S reversed.
 "':".:" Yield ["':" ".:"].
 e€" For each character in S / S reversed, check if it
 is an element of "':" / ".:".
 Yield the corresponding 2D array of Booleans.
 μ Begin a new, monadic chain.
 Argument: A (2D array of Booleans)
 Ṫ€ Pop the last Boolean of each list.
 Ṛ Yield the reversed array of popped list.
 ;" Prepend the popped items to the popped lists.
 U1¦ Reverse the first list.
 Z Zip to turn top and bottom rows into pairs.
 Ḅ Convert each pair from base 2 to integer.
 "'.: Yield "'.: ".
 ị Retrieve the characters at the corr. indices.
Makonede
6,79921 silver badges49 bronze badges
answered Mar 10, 2016 at 21:39
\$\endgroup\$
9
\$\begingroup\$

Retina, 66

  • 2 bytes saved thanks to @daavko
  • 4 bytes saved thanks to @randomra
:
1e
\.
1f
'
0e
 
0f
T`h`Rh`^.|.$
(.)(\d)
2ドル1ドル
e1
:
e0
'
f0
 
f1
.

Explanation

Starting with input:

: ''. :

The first 4 stages construct the matrix, using 1/e for true and 0/f for false for the top/bottom rows, respectively. Top and bottom rows are interlaced together. This would yield a string like:

e1f0e0e0f1f0e1

However, these 4 stages also effectively move the lower row 1 to the left, simply by reversing the order of the letters and digits:

1e0f0e0e1f0f1e

The Transliteration stage reverses hex digits for the first and last characters only, i.e. replaces 0-9a-f with f-a9-0. This has the effect of moving the bottom-left character up to the top row and the top-right character down to the bottom row:

ee0f0e0e1f0f11

The next stage then swaps every letter-digit pair, thereby moving the upper row 1 to the right. Previously this was (\D)(\d), but it turns out that (.)(\d) is sufficient because the substitutions always happen left-to-right and so the final two digits won't be erroneously matched by this, because penultimate character will have been already substituted. The matrix has now been fully rotated as required:

e0e0f0e1e0f1f1

The final 4 stages then translate back to the original format:

'' :'..

Try it online.

All testcases, one per line, m added to T line to allow separate treatment of each input line.

answered Mar 10, 2016 at 19:43
\$\endgroup\$
0
9
\$\begingroup\$

Perl, (削除) 70 (削除ここまで) (削除) 69 (削除ここまで) (削除) 64 (削除ここまで) (削除) 63 (削除ここまで) (削除) 61 (削除ここまで) 60 bytes

Includes +2 for -lp

Run with the input string on STDIN, e.g.

perl -lp rotatedots.pl <<< ":..:'."

rotatedots.pl:

y/'.:/02/r=~/./;y/.':/01/;$_=$'.2*chop|$&/2 .$_;y;0-3; '.:

Explanation

y/'.:/02/r Construct bottom row but
 with 2's instead of 1's
 Return constructed value
 (for now assume space
 becomes 0 too)
 =~/./ Match first digit on bottom
 row into $&. $' contains
 the rest of the bottom row
 y/.':/01/ Convert $_ to top row
 (again assume space
 becomes 0 too)
 $'.2*chop Remove last digit from
 the top row, multiply by 2
 and append to bottom row
 $&/2 .$_ Divide removed digit by
 2 and prepend it to the
 top row
 $_= | "or" the top and bottom
 row together. The ASCII
 values of 0,1,2,3 have
 00,01,10,11 as their last
 two bits.
y;0-3; '.: Convert the smashed together top and bottom rows
 to the corresponding representation characters.
 Drop the final ; since it is provided by -p
 (after a newline which doesn't matter here)

Space is not converted in the above code. For the calculations /2 and *2 it will behave like and become 0. In the other positions it will be part of the "or", but the 1 bits of space are a subset of the one bits of 0 and will have the same effect as 0 if or-ed with any of the digits. Only if the character it is or-ed with is a space will it remain a space instead of becoming a 0. But that's ok since 0 would have been converted back to space anyways.

answered Mar 11, 2016 at 12:57
\$\endgroup\$
6
\$\begingroup\$

Python 3, (削除) 145 (削除ここまで) (削除) 141 (削除ここまで) 130 bytes

def f(s):a=[i in"':"for i in s]+[i in".:"for i in s][::-1];return''.join(" '.:"[i+2*j]for i,j in zip([a[-1]]+a,a[-2:len(s)-2:-1]))

Explanation

The golfed solution use the following property of zip : zip('ABCD', 'xy') --> Ax By so zip(a[:l],a[l:]) can be replace by zip(a,a[l:]) and that allow to remove the definition of l

def f(s):
 l=len(s)-1
 # ┌───── unfold input string : 123 -> 123456
 # │ 654
 # ──────────────┴──────────────────────────────
 a=[i in"':"for i in s]+[i in".:"for i in s][::-1]
 # ─────────┬───────── ────────────┬───────────
 # │ └──── generate the second row and reverse it
 # └─────────── generate the first row 
 return''.join(" '.:"[i+2*j]for i,j in zip([a[-1]]+a[:l],a[l:-1][::-1]))
 # ──────┬────── ─┬ ────────────┬───────────
 # │ │ └──── rotate and create first/second new row : 123456 -> 612345 -> 612
 # │ │ 543
 # │ └ group pair of the first and second row : 612 -> (6,5),(1,4),(2,3)
 # │ 543
 # └─────────── replace pair by symbol 

Results

>>> f(".' '.:: :.'. . ::.' '. . .::' :.'.")
"' ' .:.''..'.'. ..:' ' .'. ...'''..'.'"
>>> f(".....''''''")
":... '''':"
answered Mar 11, 2016 at 13:54
\$\endgroup\$
1
  • \$\begingroup\$ You can save a few bytes by putting the last three lines on one line, separated by semicolons. \$\endgroup\$ Commented Mar 11, 2016 at 21:00
5
\$\begingroup\$

Pyth, 66 bytes

KlQJ.nCm@[,1Z,Z1,ZZ,1 1)%Cd5Qjkm@" .':"id2Ccs[:JKhK<JtK>JhK:JtKK)K

Try it here!

Explanation

This can be broken down in 3 parts:

  • Convert the input into a flat array of ones and zeros.
  • Do the rotation.
  • Convert it back into ASCII.

Convert input

This is fairly trivial. Each character is mapped in the following way:

 -> (0,0)
. -> (0,1)
' -> (1,0)
: -> (1,0)

First one is a whitespace.
We get a list of 2-tuples which we transpose to get the 2 rows of the matrix which then gets flattened.

Code

KlQJ.nCm@[,1Z,Z1,ZZ,1 1)%Cd5Q # Q = input
KlQ # save the width of the matrix in K (gets used later)
 m Q # map each character d
 %Cd5 # ASCII-code of d modulo 5
 @[,1Z,Z1,ZZ,1 1) # use this as index into a lookup list
 J.nC # transpose, flatten and assign to J
 

Rotate

We have the matrix as flat array in J and the width of the matrix in K. The rotation can be described as:

J[K] + J[:K-1] + J[K+1:] + J[K-1]

Code

s[:JKhKJhK:JtKK) # J = flat array, K = width of matrix
s[ ) # Concat all results in this list
 :JKhK # J[K]
 JhK # J[K+1:]
 :JtKK # J[K-1]

Convert it back

jkm@" .':"id2Cc[)K # [) = resulting list of the step above
 c[)K # chop into 2 rows
 C # transpose to get the 2-tuples back
 m # map each 2-tuple d
 id2 # interpret d as binary and convert to decimal
 @" .':" # use that as index into a lookup string to get the correct char
jk # join into one string
answered Mar 10, 2016 at 19:27
\$\endgroup\$
0
5
\$\begingroup\$

Pyth, (削除) 38 (削除ここまで) 36

L,hb_ebsXCyc2.>syCXzJ" .':"K.DR2T1KJ

2 bytes thanks to Jakube!

Try it here or run the Test Suite.

Explanation:

L,hb_eb ## Redefine the function y to take two lists
 ## and return them but with the second one reversed
 ## Uses W to apply a function only if it's first argument is truthy
XzJ" .':"K.DR2T ## Does a translation from the string " .':" to
 ## .DR2T which is [0,1,2,3...,9] mapped to divmod by 2
 ## (which is [0,0],[0,1],[1,0],[1,1], then some extra, unused values)
 ## we also store the string and the list for later use in J and K
.>syC ... 1 ## zip the lists to get the bits on top and below as two separate lists
 ## apply the function y from before, flatten and rotate right by 1
Cyc2 ## split the list into 2 equal parts again, then apply y and zip again
sX ... KJ ## apply the list to string transformation from above but in reverse
 ## then flatten into a string
answered Mar 10, 2016 at 19:45
\$\endgroup\$
3
  • \$\begingroup\$ Seems like I did it way too complicated ^^ Would you mind adding an explanation? \$\endgroup\$ Commented Mar 10, 2016 at 19:53
  • 1
    \$\begingroup\$ @DenkerAffe Was in the middle of adding one :) Added! \$\endgroup\$ Commented Mar 10, 2016 at 19:56
  • \$\begingroup\$ Did the same approach as you. Two things I've noticed: this lambda L,hb_eb is one byte shorter, and .DR2T creates also the Cartesian product and a few more pairs, but doesn't and in a digit and helps saving a space. \$\endgroup\$ Commented Mar 11, 2016 at 16:57
4
\$\begingroup\$

Python 3, (削除) 166 (削除ここまで) (削除) 154 (削除ここまで) (削除) 153 (削除ここまで) (削除) 150 (削除ここまで) (削除) 146 (削除ここまで) (削除) 138 (削除ここまで) (削除) 137 (削除ここまで) (削除) 135 (削除ここまで) (削除) 132 (削除ここまで) 127 bytes

Edit: I've borrowed the use of zip from Erwan's Python answer at the end of the function. (削除) and their idea to use [::-1] reversals, though I put in my own twist. (削除ここまで) As it turns out, reversals were not a good idea for my function. I have changed my use of format for further golfing. Moved a and b directly into zip for further golfing (ungolfing remains unchanged because the separation of a and b there is useful for in avoiding clutter in my explanation)

Edit: Borrowed (some number)>>(n)&(2**something-1) from this answer by xnor on the Music Interval Solver challenge. The clutter that is zip(*[divmod(et cetera, 2) for i in input()]) can probably be golfed better, though I do like the expediency it grants from using two tuples t and v.

t,v=zip(*[divmod(708>>2*(ord(i)%5)&3,2)for i in input()])
print("".join(" '.:"[i+j*2]for i,j in zip((v[0],*t),(*v[1:],t[-1]))))

Ungolfed:

def rotate_dots(s):
 # dots to 2 by len(s) matrix of 0s and 1s (but transposed)
 t = []
 v = []
 for i in s:
 m = divmod(708 >> 2*(ord(i)%5) & 3, 2)
 # ord(i)%5 of each char in . :' is in range(1,5)
 # so 708>>2 * ord & 3 puts all length-2 01-strings as a number in range(0,4)
 # e.g. ord(":") % 5 == 58 % 5 == 3
 # 708 >> 2*3 & 3 == 0b1011000100 >> 6 & 3 == 0b1011 == 11
 # divmod(11 & 3, 2) == divmod(3, 2) == (1, 1)
 # so, ":" -> (1, 1)
 t.append(m[0])
 v.append(m[1])
 # transposing the matrix and doing the rotations
 a = (v[0], *t) # a tuple of the first char of the second row 
 # and every char of the first row except the last char
 b = (v[1:], t[-1]) # and a tuple of every char of the second row except the first
 # and the last char of the first row
 # matrix to dots
 z = ""
 for i, j in zip(a, b):
 z += " '.:"[i + j*2] # since the dots are binary
 # we take " '.:"[their binary value]
 return z
answered Mar 10, 2016 at 20:46
\$\endgroup\$
3
\$\begingroup\$

Ruby, (削除) 166 (削除ここまで) 163 bytes

->s{a=s.tr(f=" .':",t='0-3').chars.map{|x|sprintf('%02b',x).chars}.transpose;a[1]+=[a[0].pop];a[0]=[a[1].shift]+a[0];a.transpose.map{|x|x.join.to_i 2}.join.tr t,f}

Yuck... transpose is too long.

Tricks used here:

  • sprintf('%02b',x) to convert "0", "1", "2", "3" into "00", "01", "10", and "11" respectively. Surprisingly, the second argument does not have to be converted into an integer first.

  • The rotation is done via a[1].push a[0].pop;a[0].unshift a[1].shift;, which I thought was at least a little clever (if not excessively verbose in Ruby). The symmetry is aesthetically nice, anyway :P

answered Mar 10, 2016 at 19:56
\$\endgroup\$
2
  • \$\begingroup\$ May I suggest to golf it a little? ->s{a=s.tr(f=" .':",'001').chars;b=s.tr(f,'0101').chars;b<<a.pop;([b.shift]+a).zip(b).map{|x|x.join.to_i 2}.join.tr'0-3',f} \$\endgroup\$ Commented Mar 11, 2016 at 7:54
  • \$\begingroup\$ Finally the ☕ made its effect. Was looking for this all morning: .map{|x|x.join.to_i 2}.join.tr'0-3',f.map{|x|f[x.join.to_i 2]}*'' \$\endgroup\$ Commented Mar 11, 2016 at 9:44
3
\$\begingroup\$

Javascript ES6 125 bytes

q=>(n=[...q].map(a=>(S=` .':`).indexOf(a))).map((a,i)=>(i?n[i-1]&2:n[0]&1&&2)|((I=n[i+1])>-1?I&1:n[i]&2&&1)).map(a=>S[a]).join``

I map each character to a two digit binary equivalent

 : becomes 3 11
 ' becomes 2 10
 . becomes 1 01
 becomes 0 00

and I'm thinking of them as being one on top of the other

3212021 becomes
1101010
1010001

I save that to n

For each character (0-3) of n, I check it's neighbors, adding the highest order bit of the left neighbor to the lowest order bit of the right neighbor. if i==0 (first character) I use it's own lower order bit instead of the left neighbor's higher order bit.

if n[i+1]>-1 it means we got 0,1,2,3 so when that's false we hit the last element.

When that happens I use the character's own highest order bit instead of the right neighbor's lower bit

map that back to .': land and join that array back together

answered Mar 10, 2016 at 20:34
\$\endgroup\$
3
\$\begingroup\$

MATL, (削除) 40 (削除ここまで) 39 bytes

' ''.:'tjw4#mqBGnXKq:QKEh1Kq:K+hv!)XBQ)

Try it online! The linked version has v repaced by &v, because of changes in the language after this answer was posted.

' ''.:' % pattern string. Will indexed into, twice: first for reading 
 % the input and then for generating the ouput
t % duplicate this string
j % input string
w % swap
4#m % index of ocurrences of input chars in the pattern string
qB % subtract 1 and convert to binay. Gives 2-row logical array
GnXKq:QKEh1Kq:K+hv! % (painfully) build two-column index for rotation
) % index into logical array to perform the rotation
XBQ % transform each row into 1, 2, 3 or 4
) % index into patter string. Implicitly display
answered Mar 10, 2016 at 20:53
\$\endgroup\$
3
\$\begingroup\$

Uiua, 19 bytes

⍜(♭⍜⊣⇌⍉⋯⨂" '.:")°↻1

try it!

Perhaps the only task on this site where Uiua can out-golf Jelly by (削除) ten (削除ここまで) seven bytes. This task is extremely well suited to Uiua because the entire operation can be expressed with a single ⍜ under. For those out of the loop, under takes two functions and applies the first one to some value, then applies the second one, and finally applies an inverse transformation of the first. Here, the first function does the following:

♭⍜⊣⇌⍉⋯⨂" '.:"
 ⨂" '.:" # zero-indexed position of each in this string
 ⋯ # each converted to binary (little-endian)
 ⍉ # transpose (giving our 2xN array)
 ⍜⊣⇌ # reverse the last row
♭ # flatten the array

From here, all that has to be done is °↻1 to cycle this flattened form one to the right, and the above transformation is undone, resulting in the desired string.

This is possible because Uiua's implementation of under allows very advanced use-cases like this because each operation stores context which it can use to undo itself in the end. For example, when the array is flattened, Uiua keeps track of the original shape of the array and molds it back while inverting.

answered Sep 29 at 11:02
\$\endgroup\$
2
\$\begingroup\$

Perl, (削除) 144 (削除ここまで) (削除) 142 (削除ここまで) (削除) 137 (削除ここまで) 131 bytes

y/.':/1-3/;s/./sprintf'%02b ',$&/ge;@a=/\b\d/g;@b=(/\d\b/g,pop@a);@a=(shift@b,@a);say map{substr" .':",oct"0b$a[$_]$b[$_]",1}0..@a

Byte added for the -n flag.

Pretty much the same algorithm as my Ruby answer, just shorter, because... Perl.

y/.':/1-3/; # transliterate [ .':] to [0123]
s/./sprintf'%02b ',$&/ge; # convert each digit to 2-digit binary
@a=/\b\d/g; # grab the 1st digit of each pair
@b=(/\d\b/g, # 2nd digit of each pair
pop@a); # push the last element of a to b
@a=(shift@b,@a); # unshift the first element of b to a
say # output...
map{ # map over indices of a/b
substr" .':",oct"0b$a[$_]$b[$_]",1 # convert back from binary, find right char
}0..@a # @a is length of a

Obnoxiously, @a=(shift@b,@a) is shorter than unshift@a,shift@b.

Alas, these are the same length:

y/ .':/0-3/;s/./sprintf'%02b ',$&/ge;
s/./sprintf'%02b ',index" .':",$&/ge;

Thanks to Ton Hospel for 5 bytes and msh210 for a byte!

answered Mar 10, 2016 at 20:14
\$\endgroup\$
4
  • \$\begingroup\$ Can you use ..@a instead of ..$#a? (Perhaps oct dies or returns 0 or something. I haven't tried it.) \$\endgroup\$ Commented Mar 10, 2016 at 23:08
  • \$\begingroup\$ No need to convert space to 0. It will evaluate as 0 for the sprintf anyways. Also get rid of the parenthesis in the regex. If there is no capture the whole match is returned for a //g \$\endgroup\$ Commented Mar 11, 2016 at 13:30
  • \$\begingroup\$ @TonHospel Thanks, incorporated those into the answer (although obviously yours still completely blows mine out of the water). \$\endgroup\$ Commented Mar 11, 2016 at 23:06
  • \$\begingroup\$ That sprintf is soooo long. map$_%2,/./g and map$_/2|0,//g almost has to be shorter (untested) \$\endgroup\$ Commented Mar 12, 2016 at 0:22
2
\$\begingroup\$

Common Lisp, (削除) 253 (削除ここまで) 247 bytes

(defun R(i &aux(n(length i))(u #1=(make-list n))(b #1#))(dotimes(k n)(setf(elt u k)(find #2=(elt i k)"':")(elt b k)(find #2#".:")))(map'string(lambda(u b)(cond((and u b)#\:)(u #\')(b #\.)(t #\ )))`(,(car b),@(butlast u))`(,@(cdr b),(nth(1- n)u))))

Try it online!

Tests included in TIO.

(defun R (i &aux (n (length i)) ; take the length of input
 (u #1=(make-list n)) ; create the top (up) list
 (b #1#)) ; create the bottom list
 (dotimes (k.. n)
 (setf (elt u k) (find #2=(elt i k) "':") 
; set the k'th element of the top list to a non-falsey value if k'th element of input is #\' or #\:
 (elt b k) (find #2# ".:")
; set the k'th element of the bottom list to a non-falsey value if k'th element of input is #\. or #\:
(map 'string ; collect the results into a string
 (lambda (u b) ; for each element of the rotated up and bottom lists
 (cond
 ((and u b) #\:) ; if both top and bottom are non-falsey add #\:
 (u #\') ; if only top is non-falsey add #\'
 (b #\.) ; if only bottom is non-falsey add #\.
 (t #\ ))) ; if both are falsey add '#\ ' (#\Space)
 `(,(car b),@(butlast u)) ; first element of the bottom and the all but last element of the top
 `(,(cdr b),(nth(1- n)u)))) ; all but first element of the bottom and the last element of the top

Saved 6 bytes using #= notation for (make-list n) and (elt i k)

answered Jul 3, 2021 at 13:28
\$\endgroup\$
2
\$\begingroup\$

Python 3, (削除) 105 (削除ここまで) 104 bytes

s=" .':"
a=[*map(s.find,input())]
b=a[0]*2,*a,a[-1]//2
print(*map(lambda x,y:s[x&2|y&1],b,b[2:]),sep='')

Try it online!

answered Jul 5, 2021 at 2:11
\$\endgroup\$
2
\$\begingroup\$

Dyalog APL, 53 bytes

{' ''.:'⌷⍨⊂1+2⊥⊖⌽@2⊢2(≢⍵)⍴ ̄1⌽,⌽@2⊖2 2⊤⌊7÷⍨32-⍨⎕UCS⍵}­⁡​‎⁠⁠⁠‎⁡⁠⁣⁤⁣‏⁠‎⁡⁠⁣⁤⁤‏⁠‎⁡⁠⁤⁡⁡‏⁠‎⁡⁠⁤⁡⁢‏⁠‎⁡⁠⁤⁡⁣‏⁠‏​⁡⁠⁡‌⁢​‎‎⁡⁠⁣⁣⁣‏⁠‎⁡⁠⁣⁣⁤‏⁠‎⁡⁠⁣⁤⁡‏⁠‎⁡⁠⁣⁤⁢‏⁠‏​⁡⁠⁡‌⁣​‎‎⁡⁠⁣⁢⁣‏⁠‎⁡⁠⁣⁢⁤‏⁠‎⁡⁠⁣⁣⁡‏⁠‎⁡⁠⁣⁣⁢‏⁠‏​⁡⁠⁡‌⁤​‎‎⁡⁠⁣⁡⁣‏⁠‎⁡⁠⁣⁡⁤‏⁠‎⁡⁠⁣⁢⁡‏⁠‎⁡⁠⁣⁢⁢‏⁠‏​⁡⁠⁡‌⁢⁡​‎‎⁡⁠⁣⁡⁢‏⁠‏​⁡⁠⁡‌⁢⁢​‎‎⁡⁠⁢⁤⁣‏⁠‎⁡⁠⁢⁤⁤‏⁠‎⁡⁠⁣⁡⁡‏‏​⁡⁠⁡‌⁢⁣​‎‎⁡⁠⁢⁣⁣‏⁠‎⁡⁠⁢⁣⁤‏⁠‎⁡⁠⁢⁤⁡‏⁠‎⁡⁠⁢⁤⁢‏‏​⁡⁠⁡‌⁢⁤​‎‎⁡⁠⁢⁢⁡‏⁠‎⁡⁠⁢⁢⁢‏⁠‎⁡⁠⁢⁢⁣‏⁠‎⁡⁠⁢⁢⁤‏⁠‎⁡⁠⁢⁣⁡‏⁠‎⁡⁠⁢⁣⁢‏‏​⁡⁠⁡‌⁣⁡​‎‎⁡⁠⁢⁡⁡‏⁠‎⁡⁠⁢⁡⁢‏⁠‎⁡⁠⁢⁡⁣‏⁠‎⁡⁠⁢⁡⁤‏⁠‏​⁡⁠⁡‌⁣⁢​‎‎⁡⁠⁤⁤‏‏​⁡⁠⁡‌⁣⁣​‎‎⁡⁠⁤⁢‏⁠‎⁡⁠⁤⁣‏‏​⁡⁠⁡‌⁣⁤​‎‎⁡⁠⁣⁤‏⁠‎⁡⁠⁤⁡‏‏​⁡⁠⁡‌⁤⁡​‎‎⁡⁠⁢‏⁠‎⁡⁠⁣‏⁠‎⁡⁠⁤‏⁠‎⁡⁠⁢⁡‏⁠‎⁡⁠⁢⁢‏⁠‎⁡⁠⁢⁣‏⁠‎⁡⁠⁢⁤‏⁠‎⁡⁠⁣⁡‏⁠‎⁡⁠⁣⁢‏⁠‎⁡⁠⁣⁣‏‏​⁡⁠⁡‌­
 ⎕UCS⍵ # ‎⁡Get codepoint
 32-⍨ # ‎⁢subtact 32 (space (32) being the smallest of the 4 chars)
 ⌊7÷⍨ # ‎⁣divide by 7 and floor
 2 2⊤ # ‎⁤Encode each of those as binary (2 digits)
 ⊖ # ‎⁢⁡Flip it over
 ⌽@2 # ‎⁢⁢Replace 2nd row with itself reversed
 ̄1⌽, # ‎⁢⁣Ravel and shift to the right
 # ‎⁢⁣This gives the conveyor belt shift
 2(≢⍵)⍴ # ‎⁢⁤Reshape that to 2xN (the original input length)
 ⌽@2⊢ # ‎⁣⁡Re-reverse 2nd row again
 ⊖ # ‎⁣⁢And flip back over
 2⊥ # ‎⁣⁣Decode the binary number
 1+ # ‎⁣⁤Add 1 for indexing's sake
 ' ''.:'⌷⍨⊂ # ‎⁤⁡And finally select from magic string
💎

Created with the help of Luminespire.

answered Sep 29 at 5:06
\$\endgroup\$
2
\$\begingroup\$

Jelly, 26 bytes

".': "ðṖiⱮd2j@/ṙ1ŒHUż\/Ḅịḷ

Try it online!

Granted that is 2016 jelly

Newer answers could be shorter

-- lyxal

Just barely! Jelly changed a lot between 2016 and 2019, but the main byte saver here over Dennis' solution is just not having two separate string constants. There might be a shorter way to perform the core logic as well, but this kind of thing isn't really Jelly's forte--either rearranging multi-dimensional arrays or computing things under some transformation.

 iⱮ Find the 1-index of every character in
".': " Ṗ the string ".': " without the trailing space.
 d2 Divmod the indices by 2.
 / Reduce the list of [div, mod] pairs by
 j@ sticking the accumulator between the div and mod.
".': " ṖiⱮd2j@/ The result is the 's backwards followed by the .s.
 ṙ1 Rotate that 1 to the left,
 ŒH split it in half,
 ż / pair the elements of the halves
 U \ with the first half (un-)reversed,
 Ḅ convert each pair from binary,
".': "ð ịḷ and index into ".': ".
answered Sep 29 at 13:55
\$\endgroup\$
1
  • 1
    \$\begingroup\$ Hey, at least it isn't a 10 byte difference any more :p \$\endgroup\$ Commented Sep 29 at 13:56
1
\$\begingroup\$

JavaScript, 311 bytes

Can probably be improved alot:

a=(s=prompt()).length-1;o=s[0]==":"||s[0]=="."?s[1]==":"||s[1]=="."?":":"'":s[1]==":"||s[1]=="."?".":" ";for(i=1;i<a;i++)o+=s[i-1]=="'"||s[i-1]==":"?s[i+1]=="."||s[i+1]==":"?":":"'":s[i+1]=="."||s[i+1]==":"?".":" ";alert(o+=s[a]==":"||s[a]=="'"?s[a-1]==":"||s[a-1]=="'"?":":"'":s[a-1]==":"||s[a-1]=="'"?".":" ")
answered Mar 10, 2016 at 19:20
\$\endgroup\$
4
  • \$\begingroup\$ Maybe set something to s[i-1]? That could save some bytes. \$\endgroup\$ Commented Mar 10, 2016 at 20:08
  • \$\begingroup\$ Same with s[i+1]. \$\endgroup\$ Commented Mar 10, 2016 at 20:13
  • 1
    \$\begingroup\$ Try using ES6 arrow functions and a lookup, also using < instead of == might save you quite a few bytes. You may also want to checkout Tips for Golfing in JS and Tips for golfing in ES6 \$\endgroup\$ Commented Mar 10, 2016 at 20:39
  • 1
    \$\begingroup\$ @Downgoat How can you use < instead of == \$\endgroup\$ Commented Mar 10, 2016 at 20:42
1
\$\begingroup\$

JavaScript (ES6), (削除) 237 (削除ここまで) (削除) 210 (削除ここまで) (削除) 204 (削除ここまで) (削除) 188 (削除ここまで) (削除) 182 (削除ここまで) 178 bytes

Credit to @Downgoat for saving 16 bytes in the 188-byte revision

Update: I had a brainwave and reduced the first operation on s to a single map call instead of two separate ones

s=>(r=" .':",a=[],s=[...s].map(c=>(t=('00'+r.indexOf(c).toString(2)).slice(-2),a.push(t[0]),t[1])),a.splice(0,0,s.shift()),s.push(a.pop()),a.map((v,i)=>r[+('0b'+v+s[i])]).join``)

Pretty Print & Explanation

s => (
 r = " .':", // Map of characters to their (numerical) binary representations (e.g. r[0b10] = "'")
 a = [], // extra array needed
 // Spread `s` into an array
 s = [...s].map(c => (
 // Map each character to a `0`-padded string representation of a binary number, storing in `t`
 t = ('00' + r.indexOf(c).toString(2)).slice(-2)),
 // Put the first character of `t` into `a`
 a.push(t[0]),
 // Keep the second character for `s`
 t[1]
 )),
 // Put the first character of `s` in the first index of `a`
 a.splice(0,0,s.shift()),
 // Append the last character of `a` to `s`
 s.push(a.pop(),
 // Rejoin the characters, alternating from `a` to `s`, representing the rotated matrix, and map them back to their string representation
 // Use implicit conversion of a binary number string using +'0b<num>'
 a.map((v,i) => r[+('0b' + v + s[i])]).join``
)
\$\endgroup\$
3
  • 1
    \$\begingroup\$ does: s=>(r=" .':",a=[],s=[...s].map(c=>('00'+r.indexOf(c).toString(2)).slice(-2)).map(n=>(a.push(n[0]),n[1]),a.splice(0,0,s.shift()),s.push(a.pop()),a.map((v,i)=>r[parseInt(v+s[i],2)]).join``) work? \$\endgroup\$ Commented Mar 10, 2016 at 23:28
  • \$\begingroup\$ Sorry for not replying to this earlier, didn't see the notification - my developer tools are giving me an "illegal character" exception \$\endgroup\$ Commented Mar 11, 2016 at 13:25
  • \$\begingroup\$ Got it to work as you put it - apparently when I copied it there were some extra invisible characters in it that didn't show up in the browser developer tools. \$\endgroup\$ Commented Mar 11, 2016 at 13:40
1
\$\begingroup\$

Vyxal, 44 bytes

f`:'. `f+↑b2ẇL·2ẇÞT÷ḣ„ṫ$„p‟JWÞT+↑b2ẇ`:'. `fL·∑

Try it Online!

Yuck.

answered Jul 2, 2021 at 10:10
\$\endgroup\$
1
\$\begingroup\$

Python 3, 124 bytes

def f(a,s=" .':",j="".join):q=j(bin(4+s.find(i))for i in a);return j(s[int(j(x),2)]for x in zip(q[4]+q[3::5],q[9::5]+q[-2]))

Try it online!

How it works :

  • q="".join(bin(4+s.find(i))for i in a) store an unpacked version of our starting string a by using binary conversion

If a is equal to

ABCD
EFGH

then q is equal to ---ae---bf---cg---dh with a to h equal to "1" if there is a dot in the corresponding emplacement and "0" otherwise (and --- equal to 0b1)

  • zip(q[4]+q[3::5],q[9::5]+q[-2]) reshapes q to have : (eabcd),(fghd) (the last d in the first part is ignored since the second part is shorter)

  • s[int("".join(x),2)] reverse the process converting back the binary number into their dot version. Result :

EABC
FGHD
answered Jul 2, 2021 at 13:17
\$\endgroup\$
1
\$\begingroup\$

05AB1E, 41 bytes

Â)εS„':„.:‚Nès夈 ̈}R ̄øí ̃2äćR ̧ìζJC" '.:"sè

Try it online! Outputs as a list of characters. Link includes a footer to format the output.

Â)εS„':„.:‚Nès夈 ̈}R ̄øí ̃2äćR ̧ìζJC"..."sè # trimmed program
 è # push character...
 # (implicit) s...
 è # in...
 "..."s # literal...
 è # at...
 s # (implicit) indices in...
 ζ # list of elements with same indices in each element of...
 ̧ # list of...
 ć # first element of...
 ) # list of...
 # implicit input...
 ) # and...
 # implicit input...
 # reversed...
 ε # with each element replaced by...
 å¤ # is...
 s # (implicit) each element of...
 S # list of characters of...
 # (implicit) current element in map...
 å # in...
 ès # element in...
 ‚ # list of...
 „': # literal...
 ‚ # and...
 „.: # literal...
 è # at index...
 N # current index in map...
 ̈ # excluding the last element...
 ˆ # and append...
 ¤ # last element of...
 å¤ # is...
 s # (implicit) each element of...
 S # list of characters of...
 # (implicit) current element in map...
 å # in...
 ès # element in...
 ‚ # list of...
 „': # literal...
 ‚ # and...
 „.: # literal...
 è # at index...
 N # current index in map...
 ˆ # to global array...
 R # reversed...
 í # with...
 ̄ # global array...
 ø # with each element paired with corresponding element in...
 ̄ # global array...
 í # prepended...
 ̃ # flattened...
 ä # split into...
 2 # literal...
 ä # equal pieces...
 R # reversed...
 ì # with...
 ) # list of...
 # implicit input...
 ) # and...
 # implicit input...
 # reversed...
 ε # with each element replaced by...
 å¤ # is...
 s # (implicit) each element of...
 S # list of characters of...
 # (implicit) current element in map...
 å # in...
 ès # element in...
 ‚ # list of...
 „': # literal...
 ‚ # and...
 „.: # literal...
 è # at index...
 N # current index in map...
 ̈ # excluding the last element...
 ˆ # and append...
 ¤ # last element of...
 å¤ # is...
 s # (implicit) each element of...
 S # list of characters of...
 # (implicit) current element in map...
 å # in...
 ès # element in...
 ‚ # list of...
 „': # literal...
 ‚ # and...
 „.: # literal...
 è # at index...
 N # current index in map...
 ˆ # to global array...
 R # reversed...
 í # with...
 ̄ # global array...
 ø # with each element paired with corresponding element in...
 ̄ # global array...
 í # prepended...
 ̃ # flattened...
 ä # split into...
 2 # literal...
 ä # equal pieces...
 ć # excluding the first element...
 ì # prepended...
 # (implicit) with each element...
 J # joined...
 # (implicit) with each element...
 C # converted from binary to decimal
answered Jul 3, 2021 at 14:00
\$\endgroup\$
1
\$\begingroup\$

Excel, 139 bytes

=LET(e,LEN(A1),q,SEQUENCE(e),x,CODE(MID(A1,q,1))-32,l,x>7,u,x>l*14,CONCAT(MID(" '.:",IF(q=1,l,INDEX(u,q-1))+IF(q=e,u,INDEX(l,q+1))*2+1,1)))

Link to Spreadsheet

How it works

=LET(
*Assignments*
e,LEN(A1), 'e = length of A1
q,SEQUENCE(e), 'q = (1 .. e)
x,CODE(MID(A1,q,1))-32, 'x = list of ASCII codes of each character - 32
l,x>7, 'l = array of lower numbers = 1 if x>7 (.:)
u,x>l*14, 'u = array of upper numbers = 1 if x>l*14 (':)
*Result*
IF(q=1,l,INDEX(u,q-1)) + 'String indices = if q = 1 then l[1] else u[q-1] 
IF(q=e,u,INDEX(l,q+1))*2+1 ' + (if q=e then u[e] else l[q+1]) * 2 + 1
CONCAT(MID(" '.:",~,1))) 'Concatenate all the results
answered Jul 3, 2021 at 14:11
\$\endgroup\$
1
\$\begingroup\$

J, 55 bytes

' .'':'&([{~([:g@($$_1|.,)g=.|.@{:1}_2{.])&.(|:@#:)@i.)

Try it online!

answered Jul 3, 2021 at 21:46
\$\endgroup\$
0
\$\begingroup\$

Python 3, (削除) 294 (削除ここまで) (削除) 287 (削除ここまで) 283 bytes

Waaayyyyyy too long, but I will try to golf of some bytes:

z=input()
x=len(z)
M=[0,1,2,3]
for Q in M:z=z.replace(":'. "[Q],"11100100"[Q*2:Q*2+2])
a=[]
b=[]
for X in range(x):a+=[z[X*2]];b+=[z[X*2+1]]
b=b[1:]+[a.pop()]
c=[b[0]]+a
z=""
for X in range(len(c)):
 y=c[X]+b[X]
 for Q in M:y=y.replace("11100100"[Q*2:Q*2+2],":'. "[Q])
 z+=y
print(z)
answered Mar 10, 2016 at 19:56
\$\endgroup\$
0
\$\begingroup\$

Lua, 139 bytes

print(((...):gsub(".",{[" "]="NN@",["."]="YN@",["'"]="NY@",[":"]="YY@"}):gsub("(.)@(.?)","%2%1"):gsub("..",{NN=" ",NY=".",YN="'",YY=":"})))

Usage:

$ lua conveyor.lua ".' '.:: :.'. . ::.' '. . .::' :.'."
' ' .:.''..'.'. ..:' ' .'. ...'''..'.'
answered Mar 11, 2016 at 19:04
\$\endgroup\$

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.