8.01- public static int Factorial(int x) {
if (x == 1)
return 1;
return x*Factorial(x-1);
}
  public static int Puzzle(int i, int j) {
int sum = 0;
for (int s=i; s<=j; s++)
sum += Factorial(s);
return sum;
}
8.02-  string output = "";
        for(int i = 1; i <= n; i++){
            output += new string('#', i) + " ";
        }
        return output;
8.03- string output = "";
  for(int i = n; i >= 0; i--){
   
           for(int a = 0; a <= n - i; a++){
   output += a;
  }
   output += new string('_', i ) + " ";
        }
        return output;
8.04- string r = "";
  for (int i = 0; i < n; i++){
   
   
   for (int a = 0; a < n; a++){
   if (i == a){
    r += "-";
   } else {
   
    r += b;
   }
  }
   r += " ";
  }
  return r.Trim();
8.05-  string r = "";
  for (int i = 0; i < a.Length; i++){
   
   
   for (int b = 0; b < a.Length; b++){
   if (i == b){
    r += "_";
   } else {
   
    r += a[b];
   }
  }
   r += " ";
  }
  return r.Trim();
8.06-string r = "";
  for (int i = 0; i < size; i++){
   
   
   for (int b = 0; b < size; b++){
   if ((i == 0 || i == size -1 ) || (b == 0 || b == size -1) ){
    r += "$";
   } else   {
    
   
    r += "_";
   }
  }
   r += " ";
  }
  return r.Trim();
8.07- string output = "";
  string next = "x";
        for(int i = 0; i < height; i++){
   
   if (i % 2 == 0){
    next = "x";
   } else {
    next = "o";
   }
   
            for(int b = 0; b < width; b++){
    
    
    output += next;
    if (next == "x")
     next = "o";
    else
     next = "x";
    if ((b +1) % width == 0)
     output += " ";
   }
   
        }
        return output.Trim();
8.08-    string output = "";
  
        for(int i=1; i<=number; i++){
                output += new string(i.ToString()[0], i)   + " ";
        }
  for(int i=number -1 ; i>0; i--){
                output += new string(i.ToString()[0], i)   + " ";
        }
        return output.Trim();
Sunday, October 19, 2014
Code Hunt Solutions 7
7.01 - return two+three+one+one+three+two;
7.02 - return s.Substring(0, s.Length/2);
7.03 - return a.Replace(b,c);
7.04 - string w = "";
char[] charArray = s.ToCharArray();
Array.Reverse( charArray );
w = new string ( charArray );
return w;
7.05 - string r = "";
for(int i = 0; i < a.Length ;i++){
if (i % 2 == 0){
r += b.Substring(i, 1);
}
else
r += a.Substring(i, 1);
   
}
  
return r;
7.06 - return s.Replace(" ", "");
7.07 - return s.Replace("a", "").Replace("e", "").Replace("i", "").Replace("o", "").Replace("u", "");
7.08 - string r = "";
r = input.Replace(a, "").Replace(b, "").Replace(c, "");
if (r == "" && input.Contains(a) && input.Contains(b) && input.Contains(c)){
return true;
}
return false;
7.09 - string r = "";
for(int id = 0; id<i-1; id++){
r += s + " ";
}
return r + s;
7.10 -(thanks to RainVision for this one)
using System;
using System.Linq;
public class Program {public static string Puzzle(int t) {return String.Join(" ", Enumerable.Repeat("a b c d e f g h i j k l m n o p q r s t u v w x y z", t)).Substring(0, 52*t-t*2) + "z";}}
7.02 - return s.Substring(0, s.Length/2);
7.03 - return a.Replace(b,c);
7.04 - string w = "";
char[] charArray = s.ToCharArray();
Array.Reverse( charArray );
w = new string ( charArray );
return w;
7.05 - string r = "";
for(int i = 0; i < a.Length ;i++){
if (i % 2 == 0){
r += b.Substring(i, 1);
}
else
r += a.Substring(i, 1);
}
return r;
7.06 - return s.Replace(" ", "");
7.07 - return s.Replace("a", "").Replace("e", "").Replace("i", "").Replace("o", "").Replace("u", "");
7.08 - string r = "";
r = input.Replace(a, "").Replace(b, "").Replace(c, "");
if (r == "" && input.Contains(a) && input.Contains(b) && input.Contains(c)){
return true;
}
return false;
7.09 - string r = "";
for(int id = 0; id<i-1; id++){
r += s + " ";
}
return r + s;
7.10 -(thanks to RainVision for this one)
using System;
using System.Linq;
public class Program {public static string Puzzle(int t) {return String.Join(" ", Enumerable.Repeat("a b c d e f g h i j k l m n o p q r s t u v w x y z", t)).Substring(0, 52*t-t*2) + "z";}}
Subscribe to:
Comments (Atom)
