On Monday, 8 April 2019 03:07:00 UTC+5:30, Ronan Burke  wrote:
> My solution for this one was to just do the opposite of the route the other 
> person took. If you did something other than, I imagine things could get 
> quite messy and it would be easy to make a mistake.
> 
> Their route: "SSEESE" then I would do "EESSES"

HI ,

This is my code. I followed the logic like, if the given path starts at "E" and 
ends with "S" , then the resultant path should start at "S" and ends with "E" , 
for that just start with "S" and proceed till the bottom and then proceed with 
"E" and proceed till the end point. The same reverse for the case where path 
starts with "S" and ends with "E".  In the case where path starts with "E" and 
ends with "E"  (or) starts with "S" and ends with "S" , we need to handle it 
different.  
For case where path starts at "E" and Ends at "E" , just start with "S" and 
whenever there are two continuous "S" in the given path. , at that particular 
point just proceed to the right most of the maze with the required "E" s and 
then proceed to the end point with "S". The same reverse for the case where 
path starts with "S" and ends with "S". 

This is my code written in JS.


var readline = require('readline')

var rl = readline.createInterface({
    input: process.stdin,
    output: process.stdout
  })
  var  caseId= 0
  var totalCaseNO = 0;
  var mazeDimension = null;
  rl.on('line',  function(n)
  {
        if(totalCaseNO == 0 )
        {
            totalCaseNO = parseInt(n);
        }
        else if(!mazeDimension)
        {
            mazeDimension = parseInt(n);
        }
        else{
            caseId++;
            test(caseId,mazeDimension,n);
            mazeDimension = null;
        }
        if(caseId == totalCaseNO)
        {
            process.exit(0)
        }
  })

function test(caseId,mazeDimension,path)
{
    var matrixDim = mazeDimension -1;
    var pathLength = matrixDim * 2;
    var isEastStart = path[0] == "E" ? true : false;
    var isEastEnd = path[pathLength-1] == "E" ? true : false;
    var ourPath = "";
    var ourStart = isEastStart ? "S" : "E";
    var solved = false;
    var ourStart,ourEnd;
    if((isEastStart && !isEastEnd) || (!isEastStart && isEastEnd))
    {
        ourStart = isEastStart ? "S" : "E";
        ourEnd = isEastEnd ? "S" : "E";
        ourPath = ourStart.repeat(matrixDim);
        ourPath += ourEnd.repeat(matrixDim);
        solved = true;
    }
    else{
        ourStart = ourEnd = isEastStart ? "S" : "E";
        var ourMid = isEastStart ? "E"  : "S";
        var index = path.match(ourStart.repeat(2)).index;
        var subPath = path.substring(0,index);
        var count = (subPath.match(ourStart) || []).length + 1;
        ourPath = ourStart.repeat(count);
        ourPath += ourMid.repeat(matrixDim);
        ourPath += ourEnd.repeat(matrixDim-count);
    }
    console.log("Case #"+caseId+": "+ourPath);
}

I didn't see any case, which may fail with this logic, but i got response like 
"Wrong Answer". If there are some cases, where it will fail, please let me know

Thanks,
Gokul

On Monday, 8 April 2019 03:07:00 UTC+5:30, Ronan Burke  wrote:
> My solution for this one was to just do the opposite of the route the other 
> person took. If you did something other than, I imagine things could get 
> quite messy and it would be easy to make a mistake.
> 
> Their route: "SSEESE" then I would do "EESSES"



On Monday, 8 April 2019 03:07:00 UTC+5:30, Ronan Burke  wrote:
> My solution for this one was to just do the opposite of the route the other 
> person took. If you did something other than, I imagine things could get 
> quite messy and it would be easy to make a mistake.
> 
> Their route: "SSEESE" then I would do "EESSES"



On Monday, 8 April 2019 03:07:00 UTC+5:30, Ronan Burke  wrote:
> My solution for this one was to just do the opposite of the route the other 
> person took. If you did something other than, I imagine things could get 
> quite messy and it would be easy to make a mistake.
> 
> Their route: "SSEESE" then I would do "EESSES"



On Monday, 8 April 2019 03:07:00 UTC+5:30, Ronan Burke  wrote:
> My solution for this one was to just do the opposite of the route the other 
> person took. If you did something other than, I imagine things could get 
> quite messy and it would be easy to make a mistake.
> 
> Their route: "SSEESE" then I would do "EESSES"



On Monday, 8 April 2019 03:07:00 UTC+5:30, Ronan Burke  wrote:
> My solution for this one was to just do the opposite of the route the other 
> person took. If you did something other than, I imagine things could get 
> quite messy and it would be easy to make a mistake.
> 
> Their route: "SSEESE" then I would do "EESSES"



On Monday, 8 April 2019 03:07:00 UTC+5:30, Ronan Burke  wrote:
> My solution for this one was to just do the opposite of the route the other 
> person took. If you did something other than, I imagine things could get 
> quite messy and it would be easy to make a mistake.
> 
> Their route: "SSEESE" then I would do "EESSES"



On Monday, 8 April 2019 03:07:00 UTC+5:30, Ronan Burke  wrote:
> My solution for this one was to just do the opposite of the route the other 
> person took. If you did something other than, I imagine things could get 
> quite messy and it would be easy to make a mistake.
> 
> Their route: "SSEESE" then I would do "EESSES"



On Monday, 8 April 2019 03:07:00 UTC+5:30, Ronan Burke  wrote:
> My solution for this one was to just do the opposite of the route the other 
> person took. If you did something other than, I imagine things could get 
> quite messy and it would be easy to make a mistake.
> 
> Their route: "SSEESE" then I would do "EESSES"



On Monday, 8 April 2019 03:07:00 UTC+5:30, Ronan Burke  wrote:
> My solution for this one was to just do the opposite of the route the other 
> person took. If you did something other than, I imagine things could get 
> quite messy and it would be easy to make a mistake.
> 
> Their route: "SSEESE" then I would do "EESSES"



On Monday, 8 April 2019 03:07:00 UTC+5:30, Ronan Burke  wrote:
> My solution for this one was to just do the opposite of the route the other 
> person took. If you did something other than, I imagine things could get 
> quite messy and it would be easy to make a mistake.
> 
> Their route: "SSEESE" then I would do "EESSES"



On Monday, 8 April 2019 03:07:00 UTC+5:30, Ronan Burke  wrote:
> My solution for this one was to just do the opposite of the route the other 
> person took. If you did something other than, I imagine things could get 
> quite messy and it would be easy to make a mistake.
> 
> Their route: "SSEESE" then I would do "EESSES"

-- 
You received this message because you are subscribed to the Google Groups 
"Google Code Jam" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/google-code/c48dd51a-6991-4c97-a9c6-ca364724cbc8%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to