Sumedh Meshram

.Net Technical Blog

TECHGIG : Code Contest HomeThe Great Indian Programming League 2013 - May Edition - Visit a Colony

Problem Statement :

In a colony all houses are in a single line. We call a house either in a good condition or in a bad condition. If a house is good its score is 1 otherwise 0. We decided to perform the scoring of houses in a different way. 

We not only consider that particular house but also the 2 neighboring house.
 
New scoring strategy- The Score of a house if affected by three house, that house and its two neighbors
 
Score-1 : If any of the three houses is in good condition 
Score-2 : if any of the two houses is in good condition 
Score-3 : if all the three houses are in good condition 
 
Now Josheph has the score list of all the houses ( according to new strategy ) and he wants to know what is the condition ( good or bad) of his house just seeing the score of the houses. He assumes that first house is in good condition.

MyResult

Successfully compiledSuccessfully compiled
: 9: 90
 
Solution :
using System;
public class CandidateCode
{
public static int house_condition(int[] input1,int input2)
{
int[] score = new int[input1.Length];	
for(int i=0;i<input1.Length;i++)
{
if(i == 0)
{
score[i] = 1; //first house in good condition

if(i+1<input1.Length)
{
score[i+1] = input1[i]- score[i];	
}
}
else
{
if(i+1<input1.Length)
{	
score[i+1] = input1[i] - (score[i-1] + score[i]);
}
}
}
return score[input2-1];	
}
}
Cheap MLB Jerseys maillot de foot pas cher www.fotballdrakter.org