Things were moved. Go find it.
Also, things were fixed so check that out too.
Saturday, November 29, 2014
Sunday, October 19, 2014
Code Hunt Solutions 8
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();
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();
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";}}
Sunday, August 24, 2014
Code Hunt Solutions 6
6.01- return false;
6.02 - string r = "";
for(int i = 0; i < s.Length ;i++){
if (i % 2 == 0){
r += s.Substring(i, 1).ToUpper();
}
else
r += s.Substring(i, 1);
}
return r;
6.03 - string r = "";
for(int i = 0, j = 1; i < s.Length; i++, j++){
if(i == s.Length - 1 || s[j] == ' ' ){
r += Char. ToUpper(s[i]);
}
else{
r += s[i];
}
}
return r;
6.04 - return s[x];
6.05 - return two + one;
6.06 - return s.Substring(s.Length/2);
6.07 - string r = "";
r = s.Substring((s.Length/2)+1).ToUpper();
r += s.Substring((s.Length /2));
return r;
6.08 - return Math.Max(b.Length, a.Length);
updated
6.09 - if(a.Length > b.Length){
return a;
}
if(b.Length > a.Length){
return b;
}
return a + b;
6.10 - return s.Length /3;
6.11- return s.Substring(i,s.Length-i-1) + s.Substring(s.Length-2,1);
Thanks to Araz
6.12 -string w = "";
char [] charArray = s.ToCharArray();
Array.Reverse( charArray );
w = new string( charArray );
return s+w;
6.02 - string r = "";
for(int i = 0; i < s.Length ;i++){
if (i % 2 == 0){
r += s.Substring(i, 1).ToUpper();
}
else
r += s.Substring(i, 1);
}
return r;
6.03 - string r = "";
for(int i = 0, j = 1; i < s.Length; i++, j++){
if(i == s.Length - 1 || s[j] == ' ' ){
r += Char. ToUpper(s[i]);
}
else{
r += s[i];
}
}
return r;
6.04 - return s[x];
6.05 - return two + one;
6.06 - return s.Substring(s.Length/2);
6.07 - string r = "";
r = s.Substring((s.Length/2)+1).ToUpper();
r += s.Substring((s.Length /2));
return r;
6.08 - return Math.Max(b.Length, a.Length);
updated
6.09 - if(a.Length > b.Length){
return a;
}
if(b.Length > a.Length){
return b;
}
return a + b;
6.10 - return s.Length /3;
6.11- return s.Substring(i,s.Length-i-1) + s.Substring(s.Length-2,1);
Thanks to Araz
6.12 -string w = "";
char [] charArray = s.ToCharArray();
Array.Reverse( charArray );
w = new string( charArray );
return s+w;
Code Hunt Solutions 5
5.01 - if (s.Length <= 3){
return "short";
}
if (s.Length >= 4 && s.Length <= 7){
return "average";
}
if(s.Length >= 8 && s.Length <= 14){
return "long";
}
return "super long";
5.02 - thx
if (i % 1111 == 0) return "fancy year";
return "not a fancy year";
5.04 - if (y > 0 && x < 0){
return (x-y) - 2*(x-y);
}
if (x > 0 && y < 0){
return (x-y);
}
if ((x+y) < 0){
return (x+y) - 2*(x+y);
}
return x + y;
5.05 - return (j == i*i)
return "short";
}
if (s.Length >= 4 && s.Length <= 7){
return "average";
}
if(s.Length >= 8 && s.Length <= 14){
return "long";
}
return "super long";
5.02 - thx
if (i % 1111 == 0) return "fancy year";
return "not a fancy year";
5.04 - if (y > 0 && x < 0){
return (x-y) - 2*(x-y);
}
if (x > 0 && y < 0){
return (x-y);
}
if ((x+y) < 0){
return (x+y) - 2*(x+y);
}
return x + y;
5.05 - return (j == i*i)
Code Hunt Solutions 4
4.01 - if (x == true || y == true){
return true;
}
return false;
4.02 - if(x == false || y == false){
return false;
}
return true;
4.03 - if (x < 50){
return true;
}
return false;
4.04 - if(x >= y){
return false;
}
return true;
4.05 - if(i < 0){
return -1;
}
if(i > 0){
return 1;
}
return 0;
4.06 - if(i == j){
return true;
}
return false;
4.07 - if(i > 99){
return 3;
}
return 2;
4.08 - if(i % 2 == 0){
return "even";
}
return "odd";
4.09 - if(i % 5 == 0){
return "multiple of 5";
}
return "not a multiple of 5";
4.10 - if(i % x == 0){
return "multiple of " + x;
}
return "not a multiple of " + x;
4.11 - if(i==(2*j) && j==(2*k))
return "yes!";
else
return "no";
4.12 - int output = 21;
if(i <= 7){
return 0;
}
if(i > 7 && i <= 14){
return 7;
}
return output;
return true;
}
return false;
4.02 - if(x == false || y == false){
return false;
}
return true;
4.03 - if (x < 50){
return true;
}
return false;
4.04 - if(x >= y){
return false;
}
return true;
4.05 - if(i < 0){
return -1;
}
if(i > 0){
return 1;
}
return 0;
4.06 - if(i == j){
return true;
}
return false;
4.07 - if(i > 99){
return 3;
}
return 2;
4.08 - if(i % 2 == 0){
return "even";
}
return "odd";
4.09 - if(i % 5 == 0){
return "multiple of 5";
}
return "not a multiple of 5";
4.10 - if(i % x == 0){
return "multiple of " + x;
}
return "not a multiple of " + x;
4.11 - if(i==(2*j) && j==(2*k))
return "yes!";
else
return "no";
4.12 - int output = 21;
if(i <= 7){
return 0;
}
if(i > 7 && i <= 14){
return 7;
}
return output;
Code Hunt Solutions 3
3.01 - int r = 1;
for(int i = 0; i < power; i++){
r = r *number;
}
return r;
3.02 - int r = 1;
for(int a = i; a > 0 ;a-- ){
r = r * a;
}
return r;
3.03 - int r = 1;
for(int i = lowerBound; i <= upperBound; i++){
r = r*i;
}
return r;
3.04 - if (n < 3){
return 0;
}
int r = 0;
for(int i = 0; (i*2) < n; i++){
r = r + (i*2);
}
return r;
3.05 - int r = 0;
for(int i = 0; i <= upperBound; i++){
for(int a = 0; a < i; a++){
r += a;
}
r += i;
}
return r;
3.06 - string r = "";
for(int i = 0; i < word.Length; i++){
if (i == word.Length - 1)
r = r + "_";
else
r = r + "_ ";
}
return r;
3.07 - int m = 5;
char[] c = new char[s.Length];
for(int i = 0; i < s.Length; i++)
c[i] = (char)((s[i] + m - (int)'a') % 26 + (int)'a');
return new String(c);
3.08 - string r = "";
r = x.ToString(r);
return r.Length;
for(int i = 0; i < power; i++){
r = r *number;
}
return r;
3.02 - int r = 1;
for(int a = i; a > 0 ;a-- ){
r = r * a;
}
return r;
3.03 - int r = 1;
for(int i = lowerBound; i <= upperBound; i++){
r = r*i;
}
return r;
3.04 - if (n < 3){
return 0;
}
int r = 0;
for(int i = 0; (i*2) < n; i++){
r = r + (i*2);
}
return r;
3.05 - int r = 0;
for(int i = 0; i <= upperBound; i++){
for(int a = 0; a < i; a++){
r += a;
}
r += i;
}
return r;
3.06 - string r = "";
for(int i = 0; i < word.Length; i++){
if (i == word.Length - 1)
r = r + "_";
else
r = r + "_ ";
}
return r;
3.07 - int m = 5;
char[] c = new char[s.Length];
for(int i = 0; i < s.Length; i++)
c[i] = (char)((s[i] + m - (int)'a') % 26 + (int)'a');
return new String(c);
3.08 - string r = "";
r = x.ToString(r);
return r.Length;
Code Hunt Solutions 2
2.01 - int [] a = new int [n];
for(int i = 0; i < n; i++){
a [i] = i;
}
return a;
2.02 - int [] a = new int [n];
for(int i = 0; i < n; i++){
a [i] = i*n;
}
return a;
2.03 - int [] a = new int [n];
for(int i = 0; i < n; i++){
a [i] = i*i;
}
return a;
2.04 - int result = 0;
foreach(var i in v){
result += i;
}
return result;
2.05 - int r = 0;
for(int i = 0; i < n; i++)
r += (i*i);
return r;
2.06 - int count = 0;
foreach(char c in s){
if (c == 'a'){
count++;
}
}
return count;
2.07 - int r = 0;
foreach(char x in string s){
r++;
}
return r;
for(int i = 0; i < n; i++){
a [i] = i;
}
return a;
2.02 - int [] a = new int [n];
for(int i = 0; i < n; i++){
a [i] = i*n;
}
return a;
2.03 - int [] a = new int [n];
for(int i = 0; i < n; i++){
a [i] = i*i;
}
return a;
2.04 - int result = 0;
foreach(var i in v){
result += i;
}
return result;
2.05 - int r = 0;
for(int i = 0; i < n; i++)
r += (i*i);
return r;
2.06 - int count = 0;
foreach(char c in s){
if (c == 'a'){
count++;
}
}
return count;
2.07 - int r = 0;
foreach(char x in string s){
r++;
}
return r;
Code Hunt Solutions 1
1.01 - -x
1.02 - x-2
1.03 - x*x
1.04 - x*3
1.05 - x/3
1.06 - 8 / (x*2)
1.07 - x-y
1.08 - y*2 + x
1.09 - x*y
1.10 - (y/3) + x
1.11 - x/y
1.12 - x%3
1.13 - x%3 + 1
1.14 - 10%x
1.15 - (x+y+z) /3
1.02 - x-2
1.03 - x*x
1.04 - x*3
1.05 - x/3
1.06 - 8 / (x*2)
1.07 - x-y
1.08 - y*2 + x
1.09 - x*y
1.10 - (y/3) + x
1.11 - x/y
1.12 - x%3
1.13 - x%3 + 1
1.14 - 10%x
1.15 - (x+y+z) /3
Subscribe to:
Posts (Atom)