Daniel Guerrero Thoughts

Sunday, June 05, 2005

Those days..

Today was the birthday of Ragnarok, it was really funny and we joke and talk for about six hours =S.

I was testing colorize in the gimp and I will release some manipulated images in deviantart.com, the images I have released are:


I also found a new radio station, really cool, except it repeats much of his music =( Virgin Radio UK, yesterday I was listening 'Late Show with Leona' which started about 10 pm... in England, 3 pm in Mexico =P.

Checking my mail I found a Top Coder problem about 'masive numbers', which was really simple, my solution (trying to be more legible than the original answer, which I found later) is:

------
MassiveNumbers.java
------

public class MassiveNumbers
{
public static String getLargest(String numberA, String numberB)
{
String m, n;
double a, b;
double c, d;
double result;

int index_m, index_n;

m = numberA.trim();
n = numberB.trim();

index_m = m.indexOf("^");
index_n = n.indexOf("^");

if (index_m == -1 || index_n == -1)
return null;

try
{
a = (new Double(m.substring(0, index_m))).doubleValue();
c = (new Double(n.substring(0, index_n))).doubleValue();

b = (new Double(m.substring(index_m + 1))).doubleValue();
d = (new Double(n.substring(index_n + 1))).doubleValue();
}
catch(Exception e)
{
return null;
}

result = (d * Math.log(c)) - (b * Math.log(a));

if (result > 0) //c^d > a^b ie n > m
return numberB;
else
return numberA;
}
}



---------
test.java
---------

public class test
{
public static void main(String[] args)
{
String greatest;

if (args.length != 2)
{
System.out.println("Uso: test numeroA numberB");
System.exit(1);
}

greatest = MassiveNumbers.getLargest(args[0], args[1]);

System.out.println("El numero mayor es: " + greatest);
}
}


Listening: R.E.M. - Losing My Religion

0 Comments:

Post a Comment

<< Home