Bit manipulation

Given two list of bit patterns and two bit strings, extract bits from the first string with the first pattern and place them in the second string with the second pattern. Draw a diagram above each value with numbers indicating the order of extraction and insertion (see tests for details). It should also work for text, not just binary digits. (see test 7)

IN

From: 010011010
Bits: 1:0, 6:4, 8
To:   000000000
Bits: 7:2

OUT

From:
3 2    1
^ /-\  /\
010011010

=100010

To:
 1
 /----\
010001000

IN

From: 0000011111
Bits: 9, 0, 8, 1, 7, 2, 6, 3, 5:4
To:   11111111110000000000
Bits: 14:5

OUT

From:
13579 8642
^^^^/\^^^^
0000011111

=0101010101

To:
     1
     /--------\
11111010101010100000

IN

From: 010011010
Bits: 6:4, 1:0, 8
To:   000000000
Bits: 7:2

OUT

From:
3 1    2
^ /-\  /\
010011010

=001100

To:
 1
 /----\
000110000

IN

From: 100100010000100000
Bits: 5:0, 10:6, 14:11, 17:15
To:   000000000000000000
Bits: 17:15, 14:11, 10:6, 5:0

OUT

From:
4  3   2    1
/-\/--\/---\/----\
100100010000100000

=100000100001000100

To:
1  2   3    4
/-\/--\/---\/----\
100000100001000100

IN

From: 100100010000100000
Bits: 5:0, 10:6, 14:11, 17:15
To:   000000000000000000
Bits: 17:12, 11:7, 6:3, 2:0

OUT

From:
4  3   2    1
/-\/--\/---\/----\
100100010000100000

=100000100001000100

To:
1     2    3   4
/----\/---\/--\/-\
100000100001000100

IN

From: 0011010010101100100101
Bits: 0, 2, 5, 9:8, 11, 13, 16, 19:18
To:   000000000000
Bits: 11, 8:0

OUT

From:
  8  7  6 5 4   3  2 1
  /\ ^  ^ ^ /\  ^  ^ ^
0011010010101100100101

=1111111111

To:
1  2
^  /-------\
100111111111

IN

From: saint
Bits: 4, 0, 3:1
To:   _____
Bits: 4, 2, 3, 1:0

OUT

From:
13  2
^/-\^
saint

=stain

To:
1324
^^^/\
satin
Login to submit solution


126 symbols pyth
Thu Nov 3 11:27:54 2016 Sait2000
.v.ZCim-id64^964 2cCM"ა꾁璏肈㿂ꅦ⭫練⩂孲㵦쪱๱脄㧓埁툙芄뙷췷ᡊ筄걂娿㝄饿醌ꎐᮁᯟᇄ䨯䎨仦䤤民陗꟏즷蹉䭋ﻨ굦砽蒀耼墼촻蜮㑕놔愑촷㖲쫴▆㪎ꪒᏭ끏浲茠笎챸틼椇췃猺鉝㯃첎俙㪳賋觱쒸ꌓ퐶ᓓ༭欻爾갖泝⛟饘"3 64218
135 symbols pyth
Mon Oct 31 14:32:15 2016 Sait2000
 .v.ZCim-i%Vd[16=Y64Y)Y=Y6485cCM"᧒ⵗ숈⧍㾶汫쿷ᷗ籑㉝떻碉䇗啼潰췸㌩歂펻爿뺿恰㌛찠훑睖⎘薈皲ᴠ‿쨹▒壵楙峌濔⦃粺⼊䓈啃ꂷ㯱⚍큸⺙蠔餤ⳣ⳯⑏졎怦鄨㊾ꋌỐ䆦㬣㖅껍认䍽콰ⳙꅛ窖珪ꞁꏓ䴱ꊮᰩ닻쀶깗돕삻䊧⮂꘾鲂茵ꛋ짡㕝"3*Y9
200 symbols pyth
Mon Oct 31 14:02:48 2016 Sait2000
J>R6.z=Ts.b<>hJNYhAmm,-tlhdKv@k1.xh-Kvek1:ed"(\d+)(:(\d+))?"4cJ2)Ljkm|hxhCbd;hheSbMu:G+@GhHX1"()?"*dteH?teH++\/*tteH\-*2\\\^HG"From:"g
yGGhJkp\=Tk"To:"g
yHHhu,j<eGeHt:hGX2X3"(^)"*eH\.*hH\.3>eGeHH,@J2T
204 symbols pyth
Mon Oct 31 13:42:50 2016 Sait2000
J>R6.z=Ts.b<>hJNYhAmm,-tlhdKv@k1.xh-Kvek1:ed"(\d+)(:(\d+))?"4cJ2)Ljkm|hxhCbd;hheSbMu:G+@GhHX1"()?"*dteH?teH++\/*tteH\-*2\\\^HG"From:"jbgByGGhJkp\=Tk"To:"jbgByHHhu,j<eGeHt:hGX2X3"(^)"*eH\.*hH\.3>eGeHH,@J2T
205 symbols pyth
Mon Oct 31 13:34:08 2016 Sait2000
J>R6.z=Ts.b<>hJNYhAmm,-tlhdKv@k1.xh-Kvek1:ed"(\d+)(:(\d+))?"4cJ2)Ljkm|hxhCbd;hheSbMu:G+@GhHX1"()?"*dteH?teH++\/*tteH\-*2\\\^HG"From:"jbgByGGhJkp\=Tk"To:"jbgByHHhu[j<eGeHt:hGX2X3"(^)"*eH\.*hH\.3>eGeH)H,@J2T
215 symbols pyth
Mon Oct 31 13:57:10 2016 Sait2000
J>R6.z=Ts.b<>hJNYhAmm,-tlhdKv@k1.xh-Kvek1:ed"(\d+)(:(\d+))?"4cJ2)Mu:G+@GhHX1"()?"*dteH?teH++\/*tteH\-*2\\\^HG"From:"jbgBjkm|hxhCGd;hheSGGhJkp\=Tk"To:"jbgBjkm|hxhCHd;hheSHHhu,j<eGeHt:hGX2X3"(^)"*eH\.*hH\.3>eGeHH,@J2T
258 symbols pyth
Mon Oct 31 14:25:23 2016 Sait2000
 [J>R6.z=Ts.b<>hJNYhAmm,-tlhdKv@k1.xh-Kvek1:ed"(\d+)(:(\d+))?"4cJ2)
"From:"
u:G+@GhHX1"()?"*dteH?teH++\/*tteH\-*2\\\^G
jkm|hxhCGd;hheSG
hJ
kp\=
T
k
"To:"
u:G+@GhHX1"()?"*dteH?teH++\/*tteH\-*2\\\^H
jkm|hxhCHd;hheSH
hu,j<eGeHt:hGX2X3"(^)"*eH\.*hH\.3>eGeHH,@J2T
291 symbols pyth
Mon Oct 31 14:04:33 2016 Sait2000
J>R6.z=Ts.b<>hJNYhAmm,-tlhdKv@k1.xh-Kvek1:ed"(\d+)(:(\d+))?"4cJ2)Mu:G+@GhHX1"()?"*dteH?teH++\/*tteH\-*2\\\^HG"From:"u:G+@GhHX1"()?"*dteH?teH++\/*tteH\-*2\\\^G
jkm|hxhCGd;hheSGhJkp\=Tk"To:"u:G+@GhHX1"()?"*dteH?teH++\/*tteH\-*2\\\^H
jkm|hxhCHd;hheSHhu,j<eGeHt:hGX2X3"(^)"*eH\.*hH\.3>eGeHH,@J2T
300 symbols pyth
Mon Oct 31 14:29:51 2016 Sait2000
 .v"[J>R6.z=Ts.b<>hJNYhAmm,-tlhdKv@k1.xh-Kvek1:ed\"(\\d+)(:(\\d+))?\"4cJ2)\n\"From:\"\nu:G+@GhHX1\"()?\"*dteH?teH++\\/*tteH\\-*2\\\\\\^G\njkm|hxhCGd;hheSG\nhJ\nkp\\=\nT\nk\n\"To:\"\nu:G+@GhHX1\"()?\"*dteH?teH++\\/*tteH\\-*2\\\\\\^H\njkm|hxhCHd;hheSH\nhu,j<eGeHt:hGX2X3\"(^)\"*eH\\.*hH\\.3>eGeHH,@J2T"
348 symbols python3
Fri Jan 5 04:30:46 2018 Sait2000
def F(t,x):
 w,[*r]=S(I());a=len(r);*p,=o=[' ']*a;n=1
 for s in S(I()[6:],", "):
  e,b,*_=map(int,S(s,":")*2);d=b-e;p[~e:a-b]=-~d*'^'or"/%s\\"%("-"*~d);o[~e]=str(n);n+=1
  if x:t+=r[~e:a-b]
  else:r[~e:a-b],t=t[:1-d],t[1-d:]
 return[''.join(q).rstrip()for q in[w,o,p,r]+[t]*x]
I=input
S=str.split
*h,z=F([],1)
print(*h,"","="+z,"",*F(z,0),sep='\n')
350 symbols python3
Fri Jan 5 04:43:58 2018 Sait2000
def F(t):
 w,r=S(I());a=len(r);*p,=o=[' ']*a;n=1
 for s in S(I()[6:],", "):
  e,b,*_=map(int,S(s,":")*2);d=b-e;p[~e:a-b]=-~d*'^'or"/%s\\"%("-"*~d);o[~e]=str(n);n+=1;t+=r[~e:a-b]*x
  if~-x:r,t=r[:~e]+t[:1-d]+r[a-b:],t[1-d:]
 return[''.join(q).rstrip()for q in[w,o,p,r]+[t]*x]
I=input
S=str.split
x=1
*h,z=F('')
x=0
print(*h,"","="+z,"",*F(z),sep='\n')
357 symbols python3
Thu Jan 4 02:28:33 2018 Sait2000
def F(t,x):
 w,[*r]=S(I());a=len(r);*p,=o=[' ']*a;n=1
 for s in S(S(I(),": ",1)[1],", "):
  e,b,*_=map(int,S(s,":")*2);d=b-e;p[~e:a-b]=-~d*'^'or"/%s\\"%("-"*~d);o[~e]=str(n);n+=1
  if x:t+=r[~e:a-b]
  else:r[~e:a-b],t=t[:1-d],t[1-d:]
 return[''.join(q).rstrip()for q in[w,o,p,r]+[t]*x]
I=input
S=str.split
*o,r=F([],1)
print(*o,"","="+r,"",*F(r,0),sep='\n')
359 symbols python3
Thu Jan 4 02:24:15 2018 Sait2000
def F(t,x):
 w,[*r]=S(I());a=len(r);*p,=o=[' ']*a;n=1
 for s in S(S(I(),": ",1)[1],", "):
  e,b,*_=map(int,S(s,":")*2);d=b-e;p[~e:a-b]=d<0and"/%s\\"%("-"*~d)or"^";o[~e]=str(n);n+=1
  if x:t+=r[~e:a-b]
  else:r[~e:a-b],t=t[:1-d],t[1-d:]
 return[''.join(q).rstrip()for q in[w,o,p,r]+[t]*x]
I=input
S=str.split
*o,r=F([],1)
print(*o,"","="+r,"",*F(r,0),sep='\n')
360 symbols python3
Wed Jan 3 18:29:14 2018 Sait2000
def F(t,x):
 w,[*r]=S(I());a=len(r);*p,=o=[' ']*a;n=1
 for s in S(S(I(),": ",1)[1],", "):
  e,b,*_=map(int,S(s,":")*2);d=e-b;p[~e:a-b]=d>0and"/%s\\"%("-"*~-d)or"^";o[~e]=str(n);n+=1
  if x:t+=r[~e:a-b]
  else:r[~e:a-b],t=t[:d+1],t[d+1:]
 return[''.join(q).rstrip()for q in[w,o,p,r]+[t]*x]
I=input
S=str.split
*o,r=F([],1)
print(*o,"","="+r,"",*F(r,0),sep='\n')
362 symbols python3
Wed Jan 3 17:59:49 2018 Sait2000
def F(t,x):
 w,[*r]=S(I());*p,=o=[' ']*len(r);n=1
 for s in S(S(I(),": ",1)[1],", "):
  e,b,*_=map(int,S(s,":")*2);s=slice(~e,len(r)-b);d=e-b;p[s]=d>0and"/%s\\"%("-"*~-d)or"^";o[~e]=str(n);n+=1
  if x:t+=r[s]
  else:r[s],t=t[:d+1],t[d+1:]
 return[''.join(q).rstrip()for q in[w,o,p,r]+[t]*x]
I=input
S=str.split
*o,r=F([],1)
print(*o,"","="+r,"",*F(r,0),sep='\n')
363 symbols python3
Wed Jan 3 17:49:42 2018 Sait2000
def F(t,x):
 w,[*r]=S(I());*p,=o=[' ']*len(r);n=1
 for s in S(S(I(),": ",1)[1],", "):
  e,b,*_=map(int,S(s,":")*2);s=slice(~e,-b or 99);d=e-b+1;p[s]=e>b and"/%s\\"%("-"*(d-2))or"^";o[~e]=str(n);n+=1
  if x:t+=r[s]
  else:r[s],t=t[:d],t[d:]
 return[''.join(q).rstrip()for q in[w,o,p,r]+[t]*x]
I=input
S=str.split
*o,r=F([],1)
print(*o,"","="+r,"",*F(r,0),sep='\n')
385 symbols python3
Wed Jan 3 17:40:53 2018 Sait2000
def F(r,t,x):
 *p,=o=[' ']*len(r);n=1
 for s in S(S(I(),": ",1)[1],", "):
  e,b,*_=map(int,S(s,":")*2);s=slice(~e,-b or 99);d=e-b+1;p[s]=e>b and"/%s\\"%("-"*(d-2))or"^";o[~e]=str(n);n+=1
  if x:t+=r[s]
  else:r[s],t=t[:d],t[d:]
 return[''.join(q).rstrip()for q in(o,p,x*t or r)]
I=input
S=str.split
f,g=S(I())
*o,r=F(g,[],1)
t,u=S(I())
print(f,*o,g,"","="+r,"",t,*F([*u],r,0),sep='\n')
390 symbols python3
Wed Jan 3 16:23:25 2018 Sait2000
def F(r,t,x):
 *p,=o=[' ']*max(len(t),len(r));n=1
 for s in S(S(I(),": ",1)[1],", "):
  e,b,*_=map(int,S(s,":")*2);s=slice(~e,-b or 99);d=e-b+1;p[s]=e>b and"/%s\\"%("-"*(d-2))or"^";o[~e]=str(n);n+=1
  if x:t+=r[s]
  else:t[s],r=r[:d],r[d:]
 return[''.join(x).rstrip()for x in(o,p,t)]
I=input
S=str.split
f,g=S(I())
*o,r=F(g,[],1)
t,u=S(I())
print(f,*o,g,"","="+r,"",t,*F(r,[*u],0),sep='\n')
403 symbols python3
Wed Jan 3 16:15:12 2018 Sait2000
def F(r,y,x=1):
 *t,=y;*p,=o=[' ']*max(len(t),len(r));n=1
 for s in I().split(": ",1)[1].split(", "):
  e,b,*_=map(int,s.split(":")*2);s=slice(~e,-b or 99);d=e-b+1;p[s]=e>b and"/%s\\"%("-"*(d-2))or"^";o[~e]=str(n);n+=1
  if x:t+=r[s]
  else:t[s],r=r[:d],r[d:]
 return[''.join(x).rstrip()for x in(o,p,t)]
I=input
f,g=I().split()
*o,r=F(g,"")
t,u=I().split()
print(f,*o,g,"","="+r,"",t,*F(r,u,0),sep='\n')
414 symbols perl
Tue May 3 03:06:10 2016 megahallon
#!/usr/bin/perl
@i=map{chomp;substr$_,6}<>;sub s{length$&}sub z{$n=0;while($i[$w*2+1]=~/(\d+)(:(\d+))?/g){$p=-$1-1;$l=-($3//$1)-$p;substr$f[$w],$p,$l,++$n x$l;$w?(substr($i[2],$p,$l,substr$r,$q,$l),$q+=$l):($r.=substr$i[0],$p,$l)}$w++}@f=map{' 'x length$_}@i[0,2];z;z;($p,$w)=map{s/(\d)\1*/$1.' 'x(&s-1)/ger}@f;($g,$h)=map{s#(\d)\1*#&s-1?'/'.'-'x(&s-2).'\\':'^'#ger}@f;$_="From:!$p!$g!$i[0]!!=$r!!To:!$w!$h!$i[2]";s/ *!/\n/g;print

View all solutions