Line tracer

Draw a line of hashes based on simple directions.
each instruction is a letter ('U', 'D', 'L' or 'R' for up, down, left or right) followed by a number and then a space.

move in the right direction by the right number of steps.

Start at top left. Fill unvisited squares with '_' (underscore)
Squares can be visited twice.

IN

D3 R4 U1

OUT

#____
#____
#___#
#####

IN

R9 D6 L9 U4 R7 D2 L5

OUT

##########
_________#
########_#
#______#_#
#_######_#
#________#
##########

IN

R13 D5 U2 L3

OUT

##############
_____________#
_____________#
__________####
_____________#
_____________#

IN

D2 R2 U1 D2 U1 R2

OUT

#____
#_#__
#####
__#__
Login to submit solution


64 symbols pyth
Thu Nov 3 18:35:24 2016 Sait2000
.vCim-id64^964 2cCM"ඔ揇拂䂁ẏ涆蔅㘚욪슱鉙藊䥡僬팵辎篑劥뀖咮⽔冏듗彔驡⃙☒纵㦕"3 71825
71 symbols pyth
Thu Nov 3 18:32:33 2016 Sait2000
jmsm@"_#"},kdThheSThheS_M=TuaG,=s+Yt/Jx" LDUR"H2=+Zt%J3rm,vtdhdcw)9],ZZ
73 symbols pyth
Wed Oct 19 08:09:03 2016 Sait2000
 aY,KZZVrm,vtdhdcz)9 aY,=+Kt/Jx" LDUR"N2=+Zt%J3)VhheS_MYsm@"_#"},dNYhheSY
223 symbols perl
Wed Oct 1 19:52:44 2014 vakorol
#!/usr/bin/perl -pa
%h=(L,0,U,1,R,2,D,3);for(@F){/./;$l=$';$d=$&;@c=(0,0);$a[$y+$c[1]][$x+$c[0]]='#',$c[$p=$h{$d}%2]+=$h{$d}-2+!$p for 1..$l;$x+=$c[0];$y+=$c[1];$a[$y][$x]='#';$m=$x if$x>$m}for$r(@a){$s.=$$r[$_]||'_'for 0..$m;$s.="\n"}$_=$s
287 symbols php
Mon Jun 23 08:58:15 2014 KoukiMino
<?php $a=explode(' ',fgets(STDIN));$w=$y=$x=0;$m[0][0]=1;foreach($a as$v){$f=$v[0];$r=substr($v,1);while($r-->0){$y+=($f=='D')*-1+($f=='U');$x+=($f=='R')+($f=='L')*-1;$w=$x>$w?$x:$w;$m[$y][$x]=1;}};foreach($m as$k=>$v){$s='';for($x=0;$x<=$w;){$s.=$m[$k][$x++]==1?'#':'_';};echo$s,"
";}?>
298 symbols php
Sat Jun 21 15:29:28 2014 KoukiMino
<?php $a=explode(' ',fgets(STDIN));$w=$y=$x=0;foreach($a as$v){$f=$v[0];$r=substr($v,1);$m[$y][$x]=0;while($r-->0){$y+=($f=='D')*-1+($f=='U')*1;$x+=($f=='R')*1+($f=='L')*-1;$w=$x>$w?$x:$w;$m[$y][$x]=0;}};foreach($m as$k=>$v){$s='';for($x=0;$x<=$w;){$s.=isset($m[$k][$x++])?'#':'_';};echo$s,"\n";}?>
301 symbols perl
Sat Jun 14 02:51:38 2014 danieljabailey
#!/usr/bin/perl -na
for(@F){/^(.)(.*)/;$u=$x+($1 eq'R'?$2:$1 eq'L'?-$2:0);$v=$y+($1 eq'D'?$2:$1 eq'U'?-$2:0);for($x..$u){$o[$_][$y]=1;}for($u..$x){$o[$_][$y]=1;}for($y..$v){$o[$x][$_]=1;}for($v..$y){$o[$x][$_]=1;}$x=$u;$y=$v;$a=$a<$x?$x:$a;$b=$b<$y?$y:$b;}for(0..$b){for$s(0..$a){print($o[$s][$_]==1?'#':'_');}print$/}
438 symbols haskell
Sat Mar 14 17:44:13 2015 YoshikuniJujo
import Data.List
b=map
main=interact$unlines.d.s(b(b snd).groupBy(n(==)fst).nub.sort).t 0(0,0).b(\(q:n)->(q,read n)).words
s f(x,y)=(x,f y)
n v w x y=w x`v`w y
t m i[]=(m+1,[i])
t m i((o,0):q)=t m i q
t m i((o,n):q)=(i:)`s`t(max m x)r((o,n-1):q)where r@(_,x)=a o i
a 'U'(y,x)=(y-1,x)
a 'D'(y,x)=(y+1,x)
a 'L'(y,x)=(y,x-1)
a 'R'(y,x)=(y,x+1)
d(m,p)=b(l m)p
l m[]=replicate m '_'
l m(0:xs)='#':l(m-1)(b pred xs)
l m xs='_':l(m-1)(b pred xs)

View all solutions