First it reads in the input, and makes it nice and rectangular, with a " " border so we don't have to do any bounds checking on the horizontal (cheaper to do the checking on the vertical than to put in the extra line). Then it looks back through the rectangle, so it always hits a right-bottom corner. When it hits one of these, it directs itself up, following any +s it meets, and clearing them as it goes (with a space). It stops following when it meets a space. Tested on the five given examples.
First it reads in the input, and makes it nice and rectangular, with a " " border so we don't have to do any bounds checking. Then it looks back through the rectangle, so it always hits a right-bottom corner. When it hits one of these, it directs itself up, following any +s it meets, and clearing them as it goes (with a space). It stops following when it meets a space. Tested on the five given examples.
First it reads in the input, and makes it nice and rectangular, with a " " border so we don't have to do any bounds checking on the horizontal (cheaper to do the checking on the vertical than to put in the extra line). Then it looks back through the rectangle, so it always hits a right-bottom corner. When it hits one of these, it directs itself up, following any +s it meets, and clearing them as it goes (with a space). It stops following when it meets a space. Tested on the five given examples.
C# - 388338 388 433 bytes
Quick job making good useSaved a bunch of LINQbytes by changing to a 1-dimensional array.
using C=System.Console;using System.Linq;class P{static void Main(){var D=("\n"+CD=C.In.ReadToEnd()).Split('\n');int i=D.Length,I,J,kz,M=Dw=D.Max(m=>m.Length)+1,d,c=0;var E=D.SelectSelectMany(l=>l.PadRight(M+1).ToCharArray(w)).ToList();for(;i-->0;)for(J=M;Jz=E.Count;z-->0;>1;)if(E[I=i][J]==43E[z-1]==43)for(d=0d=1,c++;(k=E[I+=(dc++;E[z+=d%2<1?w*d-2)%2][J+=(w:d-1)%2])>32;2]>32;)if(k<44E[z]<44){E[I][J]='E[z]=' ';d=d%2<1';d=d%2>0?E[Iz<w||E[z-1][J]<99w]<99?32:10:E[I][J+1]E[z+1]!=45?01:2;3;}C.WriteLine(c);}} using C=System.Console; using System.Linq; class P { // this is far too LINQy static void Main() { // 43 + 00101011 // 45 - 00101101 // 124 | 01111100 // read in var D=("\n"+CD=C.In.ReadToEnd()).Split('\n'); // say no to verticle bounds checking int z, // z is position intin i=D.Length,I,J,k,E M=Dw=D.Max(m=>m.Length)+1, // Mw is max length of a linewidth d, // d is direction of travel (1 == verticalhorizontal?, 2 == down/right?) c=0; // c is loop count // maxmake all the lines the same length var E=D.SelectSelectMany(l=>l.PadRight(M+1).ToCharArray(w)).ToList(); // say no to horizontal bounds checking // consume +s for(;i-->0;) // for each line (bottom to top) for(J=M;Jz=E.Count;z-->0;) // for each char (right to left>1;) if(E[I=i][J]==43E[z-1]==43) // right-most lower-most + for(d=0d=1,c++; // go upleft, increment counter (k=E[I+=(dE[z+=d%2<1?w*d-2)%2][J+=(w:d-1)%2])>322]>32 // move I and Jz, then check we havn't hit a space (when we do, z is basiclly z - 1) ;) ;) if(k<44E[z]<44) // + { E[I][J]='E[z]=' '; // toodles d= d%2<1d%2>0? // currently horizontal, must go vertical E[Iz<w||E[z-1][J]<99w]<99?32 // can't go up, must go down :10 // can go up, go up : // currently verticlevertical, must go horizontal E[I][J+1]E[z+1]!=45?01 // can't go right, must go left :23 // can go right, go right ; } // output result C.WriteLine(c); } } C# - 388 433 bytes
Quick job making good use of LINQ.
using C=System.Console;using System.Linq;class P{static void Main(){var D=("\n"+C.In.ReadToEnd()).Split('\n');int i=D.Length,I,J,k,M=D.Max(m=>m.Length),d,c=0;var E=D.Select(l=>l.PadRight(M+1).ToCharArray()).ToList();for(;i-->0;)for(J=M;J-->0;)if(E[I=i][J]==43)for(d=0,c++;(k=E[I+=(d-2)%2][J+=(d-1)%2])>32;)if(k<44){E[I][J]=' ';d=d%2<1?E[I-1][J]<99?3:1:E[I][J+1]!=45?0:2;}C.WriteLine(c);}} using C=System.Console; using System.Linq; class P { // this is far too LINQy static void Main() { // 43 + 00101011 // 45 - 00101101 // 124 | 01111100 // read in var D=("\n"+C.In.ReadToEnd()).Split('\n'); // say no to verticle bounds checking int i=D.Length,I,J,k, M=D.Max(m=>m.Length), // M is max length of a line d, // d is direction of travel (1 == vertical?, 2 == down/right?) c=0; // c is loop count // max all the lines the same length var E=D.Select(l=>l.PadRight(M+1).ToCharArray()).ToList(); // say no to horizontal bounds checking // consume +s for(;i-->0;) // for each line (bottom to top) for(J=M;J-->0;) // for each char (right to left) if(E[I=i][J]==43) // right-most lower-most + for(d=0,c++; // go up, increment counter (k=E[I+=(d-2)%2][J+=(d-1)%2])>32 // move I and J, then check we havn't hit a space ;) if(k<44) // + { E[I][J]=' '; // toodles d= d%2<1? // currently horizontal, must go vertical E[I-1][J]<99?3 // can't go up, must go down :1 // can go up, go up : // currently verticle, must go horizontal E[I][J+1]!=45?0 // can't go right, must go left :2 // can go right, go right ; } // output result C.WriteLine(c); } } C# - 338 388 433 bytes
Saved a bunch of bytes by changing to a 1-dimensional array.
using C=System.Console;using System.Linq;class P{static void Main(){var D=C.In.ReadToEnd().Split('\n');int z,w=D.Max(m=>m.Length)+1,d,c=0;var E=D.SelectMany(l=>l.PadRight(w)).ToList();for(z=E.Count;z-->1;)if(E[z-1]==43)for(d=1,c++;E[z+=d%2<1?w*d-w:d-2]>32;)if(E[z]<44){E[z]=' ';d=d%2>0?z<w||E[z-w]<99?2:0:E[z+1]!=45?1:3;}C.WriteLine(c);}} using C=System.Console; using System.Linq; class P { static void Main() { // read in var D=C.In.ReadToEnd().Split('\n'); int z, // z is position in E w=D.Max(m=>m.Length)+1, // w is width d, // d is direction of travel (1 == horizontal?, 2 == down/right?) c=0; // c is loop count // make all the lines the same length var E=D.SelectMany(l=>l.PadRight(w)).ToList(); // say no to horizontal bounds checking // consume +s for(z=E.Count;z-->1;) if(E[z-1]==43) // right-most lower-most + for(d=1,c++; // go left, increment counter E[z+=d%2<1?w*d-w:d-2]>32 // move z, then check we havn't hit a space (when we do, z is basiclly z - 1) ;) if(E[z]<44) // + { E[z]=' '; // toodles d= d%2>0? // currently horizontal, must go vertical z<w||E[z-w]<99?2 // can't go up, must go down :0 // can go up, go up : // currently vertical, must go horizontal E[z+1]!=45?1 // can't go right, must go left :3 // can go right, go right ; } // output result C.WriteLine(c); } } C# 433- 388 433 bytes
Quick job hopefully making good use of LINQ.
using C=System.Console;using System.Linq;class P{static void Main(){var D=("\n"+C.In.ReadToEnd()+"\n").Split('\n');var E=D.Select(l=>(";int "+li=D.PadRight(DLength,I,J,k,M=D.Max(m=>m.Length+1)Length),d,c=0;var E=D.Select(l=>l.PadRight(M+1).ToCharArray()).ToArrayToList();int L=E.Length,i=L,j,I,J,k,d,c=0;for;for(;i-->0;)for(j=E[i].Length;jJ=M;J-->0;)if(E[I=i][J=j]==43E[I=i][J]==43){d=0;forfor(d=0,c++;(k=E[I+=((d&2)d-1)*(d&12)][J+=(%2][J+=(d&2)d-1)*(~d&1)]%2])>32;)if(k<44){E[I][J]=' ';d=d%2<1?E[I-1][J]<99?3:1:E[I][J-1]E[I][J+1]!=45?20:0;}2;}C.WriteLine(c);}} using C=System.Console; using System.Linq; class P { // this is far too LINQy static void Main() { // 43 + 00101011 // 45 - 00101101 // 124 | 01111100 // read in var D=("\n"+C.In.ReadToEnd()+"\n").Split('\n'); // say no to verticle bounds checking // max all the lines the same length int i=D.Length,I,J,k, var E=D.Select(l=>(" "+l.PadRight(DM=D.Max(m=>m.Length+1))).ToCharArray()).ToArray(Length); // say no to horizontal bounds checking , // consume +s M is max length of inta L=E.Length,i=L,j,I,J,k,line d, // d is direction of travel (1 == vertical?, 2 == down/right?) c=0; // c is loop count for(;i-->0;) for(j=E[i].Length;j-->0;) // max all the lines the same length var ifE=D.Select(E[I=i][J=j]==43l=>l.PadRight(M+1).ToCharArray()).ToList(); // right-most lower-most + say no to horizontal bounds checking { // consume +s for(;i-->0;) // usefor Ieach andline J(bottom into heretop) for(J=M;J-->0;) // for each d=0;char //(right goto upleft) if(E[I=i][J]==43) // right-most lower-most + for(d=0,c++; // go up, increment counter (k=E[I+=((d&2)d-1)*(d&12)][J+=(%2][J+=(d&2)d-1)*(~d&1)]%2])>32 // move I and J, then check we havn't hit a space ;) if(k<44) // + { E[I][J]=' '; // toodles d= d%2<1? // currently horizontal, must go vertical E[I-1][J]<99?3 // can't go up, must go down :1 // can go up, go up : // currently verticle, must go horizontal E[I][J-1]E[I][J+1]!=45?20 // can't go leftright, must go rightleft :02 // can go leftright, go leftright ; } } // output result C.WriteLine(c); } } C# 433
Quick job hopefully making good use of LINQ
using C=System.Console;using System.Linq;class P{static void Main(){var D=("\n"+C.In.ReadToEnd()+"\n").Split('\n');var E=D.Select(l=>(" "+l.PadRight(D.Max(m=>m.Length+1))).ToCharArray()).ToArray();int L=E.Length,i=L,j,I,J,k,d,c=0;for(;i-->0;)for(j=E[i].Length;j-->0;)if(E[I=i][J=j]==43){d=0;for(c++;(k=E[I+=((d&2)-1)*(d&1)][J+=((d&2)-1)*(~d&1)])>32;)if(k<44){E[I][J]=' ';d=d%2<1?E[I-1][J]<99?3:1:E[I][J-1]!=45?2:0;}}C.WriteLine(c);}} using C=System.Console; using System.Linq; class P { // this is far too LINQy static void Main() { // 43 + 00101011 // 45 - 00101101 // 124 | 01111100 // read in var D=("\n"+C.In.ReadToEnd()+"\n").Split('\n'); // say no to verticle bounds checking // max all the lines the same length var E=D.Select(l=>(" "+l.PadRight(D.Max(m=>m.Length+1))).ToCharArray()).ToArray(); // say no to horizontal bounds checking // consume +s int L=E.Length,i=L,j,I,J,k, d, // d is direction of travel (1 == vertical?, 2 == down/right?) c=0; // c is loop count for(;i-->0;) for(j=E[i].Length;j-->0;) if(E[I=i][J=j]==43) // right-most lower-most + { // use I and J in here d=0; // go up for(c++; // increment counter (k=E[I+=((d&2)-1)*(d&1)][J+=((d&2)-1)*(~d&1)])>32 // move I and J, then check we havn't hit a space ;) if(k<44) // + { E[I][J]=' '; // toodles d= d%2<1? // currently horizontal, must go vertical E[I-1][J]<99?3 // can't go up, must go down :1 // can go up, go up : // currently verticle, must go horizontal E[I][J-1]!=45?2 // can't go left, must go right :0 // can go left, go left ; } } // output result C.WriteLine(c); } } C# - 388 433 bytes
Quick job making good use of LINQ.
using C=System.Console;using System.Linq;class P{static void Main(){var D=("\n"+C.In.ReadToEnd()).Split('\n');int i=D.Length,I,J,k,M=D.Max(m=>m.Length),d,c=0;var E=D.Select(l=>l.PadRight(M+1).ToCharArray()).ToList();for(;i-->0;)for(J=M;J-->0;)if(E[I=i][J]==43)for(d=0,c++;(k=E[I+=(d-2)%2][J+=(d-1)%2])>32;)if(k<44){E[I][J]=' ';d=d%2<1?E[I-1][J]<99?3:1:E[I][J+1]!=45?0:2;}C.WriteLine(c);}} using C=System.Console; using System.Linq; class P { // this is far too LINQy static void Main() { // 43 + 00101011 // 45 - 00101101 // 124 | 01111100 // read in var D=("\n"+C.In.ReadToEnd()).Split('\n'); // say no to verticle bounds checking int i=D.Length,I,J,k, M=D.Max(m=>m.Length), // M is max length of a line d, // d is direction of travel (1 == vertical?, 2 == down/right?) c=0; // c is loop count // max all the lines the same length var E=D.Select(l=>l.PadRight(M+1).ToCharArray()).ToList(); // say no to horizontal bounds checking // consume +s for(;i-->0;) // for each line (bottom to top) for(J=M;J-->0;) // for each char (right to left) if(E[I=i][J]==43) // right-most lower-most + for(d=0,c++; // go up, increment counter (k=E[I+=(d-2)%2][J+=(d-1)%2])>32 // move I and J, then check we havn't hit a space ;) if(k<44) // + { E[I][J]=' '; // toodles d= d%2<1? // currently horizontal, must go vertical E[I-1][J]<99?3 // can't go up, must go down :1 // can go up, go up : // currently verticle, must go horizontal E[I][J+1]!=45?0 // can't go right, must go left :2 // can go right, go right ; } // output result C.WriteLine(c); } }