Monthly Archive for August, 2010

EPL 2010/11 : Wigan Athletic vs. Chelsea 0 – 6

Chelsea continued their goal scoring into the second match day without even going into the second gear. It was all too easy in the end. Sadly though, Drogba couldn’t create history by becoming the first person to score 3 consecutive hat-tricks.


wig vs chel
Uploaded by TotalFootball2010. – More professional, college and classic sports videos.

Popularity: 2% [?]

Paagal Google

Paagal Google

Paagal Google

Popularity: 2% [?]

EPL 2010/11 : Chelsea vs. West Bromwich Albion 6 – 0

A better start couldn’t have been possible. Drogba nets hat-trick. Malouda gets a couple and even Lampard puts one in! :)


chel vs wba 6-0
Uploaded by TotalFootball2010. – More professional, college and classic sports videos.

Popularity: 2% [?]

What Chelsea Needs

With the transfer window just a couple of weeks from closing, Chelsea has only Benayoun as the confirmed signing for season ’10-11. Having let players like Joe Cole, Michael Ballack, Deco, Beletti and Caravalho leave, much was expected in terms of getting star players. Also the world cup added to the hype. Now I am no soccer pundit. I just want to put down how I expected Chelsea to operate in the summer transfer window.

Chelsea were not want for goals last season having scored a team and epl record number of goals. Drogba and Lampard got their career best number of goals to contribute. But therein lies the problem. They are both in their 30′s and its foolish to expect them to repeat the feat again and again. You would expect them to do well again, but it’ll be tough to reach the benchmark set in the last season. Apart from Drogba, Kalou and Anelka are not that good. Actually, I have no respect for Anelka. I do not understand what Chelsea saw in him that they renewed his contract. Kalou has not shone either. Sturridge is good, but we do need another good signing in that department. I would not really favor Torres as he is already 26. Drogba can carry the team for another couple of years. We need a youngster who comes in as Drogba’s understudy and picks off from where Drogba leaves. Chelsea need to find their Chicharito.

In the mid field, I see no real need to spend money. Lampard plays almost every match. Essien is back to fitness. Mikel is also good. We have bought the experience of Benayoun this summer. Malouda came of age last season. Kakuta has had a wonderful outing with France. I would certainly like to see Kakuta play in the first team.So getting Oezil or any other world cup star doesn’t make sense if the Ramires deal is almost done.

The one area that really concerns me is the defence. Terry has gotten slow with age. Caravalho has left. So we are dependent on Alex and Ivanovic. Ashley Cole has a cover in Zirkhov, but RB is weak. Jefferey Bruma and Mancienne are almost sure to be listed in the squad as well. But that isn’t reassuring. We need a good world class defender.

The goal keeping department is the Achilles heel. Turnbull and Hilario are just not good enough to take over from Cech in case of injury. Chelsea suffered because of Cech’s injury in the last season and this summer pre-season games.

On the whole, I would like Chelsea to sign a good young forward (say maximum age of 22-23), a good defender. It would be a dream come true if Chelsea can get Sergio Ramos or Philip Lahm. But I know it’s just too good to be possible. Our squad is good enough to defend the titles. And if we get a few good signings, we’ll have a great chance in Champions League as well.

Popularity: 1% [?]

Project Euler : Fractions With Unorthodox Cancelling Method

Problem 33 in Project Euler says there are 4 non-trivial curious fractions which satisfy the following properties:

\frac{ax}{xb} = \frac{a}{b}

where a, b and x are all single digit numbers and a < b

The solution was pretty simple.

\frac{ax}{xb} = \frac{a}{b}

\Rightarrow b [10a + x] = a [10x + b]

\Rightarrow x = \frac{9ab}{10a - b}

Similarly solving for the other form \frac{xa}{bx} = \frac{a}{b} gives the answer x = \frac{9ab}{10b - a}.

Implementing this solution in java:

public class Problem_33 {
	/**
	 * @return All the proper non-trivial curious fractions having numerator, denominator < 100
	 */
	public static List<Fraction> getCuriousFractions() {
		List<Fraction> curiousFractions = new ArrayList<Fraction>();

		for (int a = 1; a < 10; a++)
			for (int b = a + 1; b < 10; b++)
				if (Problem_33.checkCondition(a, b))
					curiousFractions.add(new Fraction(a, b));

		return curiousFractions;
	}

	/**
	 * Checks if the number is of the form xa/bx = a/b or ax/xb = a/b
	 *
	 * @param a The numerator of the fraction
	 * @param b The denominator of the fraction
	 * @return true if it can be formed into a curious fraction, false otherwise
	 */
	private static boolean checkCondition(int a, int b) {
		int numerator = 9 * a * b;
		int denominatorA = 10 * b - a;
		int denominatorB = 10 * a - b;
		return numerator % denominatorA == 0 && numerator / denominatorA < 10 || numerator % denominatorB == 0
		        && numerator / denominatorB < 10 ? true : false;
	}
}

Popularity: 11% [?]

Project Euler : Find Hexagonal Pentagonal Number

Problem 45 of Project Euler required one to find numbers which are triangular, pentagonal and hexagonal together. Checking for triangularity is redundancy as all hexagonal numbers are also triangular. So it boils down to solving the equation:

n(3n – 1) / 2 = m(2m – 1)

Using the Diophantine Equation solver at http://www.alpertron.com.ar/QUAD.HTM, we get the solution as

n_{i+1} = 97 \times n_i + 112 \times m_i - 44

m_{i+1} = 84 \times n_i + 97 \times m_i - 38

The solution comes very easily from here.

public class Problem_45 {
	/**
	 * Find a number which is Pentagonal and also Hexagonal
	 *
	 * @param index The nth number which is required
	 * @return The nth number which is both Pentagonal and Hexagonal
	 */
	public static int findPentaHexaNumber(int index) {
		int p = 1;
		int h = 1;
		do {
			// This is the solution to the Diophantine Equation
			// p(3p-1)/2 = h(2h-1)
			int p2 = 97 * p + 112 * h - 44;
			h = 84 * p + 97 * h - 38;
			p = p2;
			index--;
		} while (index != 0);

		return h * (2 * h - 1);
	}
}

Popularity: 9% [?]

Project Euler : Quadratic Producing Longest Prime Sequence

Problem 27 done! Ah well, nothing spectacular as such, but solved none the less. It’s a happy feeling.

The problem required one to find a quadratic of the form x^2 + a \times x + b, with the condition |a| < 1000, |b| < 1000 which produces the longest sequence of primes starting with x = 0.

Let us call f(x) = x^2 + a \times x + b

The first thing you notice is that the values of b must belong to the set of primes and they must always be positive.

f(0) = b, and hence b has to be a prime

The next thing to notice is that the values of a are influenced by that of b.

f(1) = 1 + a + b is a prime \Rightarrow a = [prime] – (1+b)

So all I did was to generate primes. Set b as one of the primes. Let a iterate over the other primes and form a polynomial function for each combination. This polynomial function was evaluated for ascending values of x and the longest sequence of primes recorded in each case. I used the commons-math-2.1 library by Apache commons to evaluate the quadratic function.

I did one additional thing. The problem mentions that the quadratic function n^2 + n + 41 generates a sequence of 40 primes. You must have noted that these polynomials cannot produce a sequence longer than the value of the constant term, which is b in our case (to see this, evaluate the expression with x = b). So for 0 < b < 41 the above is the best quadratic there is. Thus we need to begin at 41.

Below is my solution which runs in 1600ms on my laptop. Not good enough though :( .

public class Problem_27 {
	public static UnivariateRealFunction getPrimeNumberFunction() throws FunctionEvaluationException {
		PrimeNumbers primeGenerator = new PrimeNumbers(100000);
		List<Integer> primes = primeGenerator.getPrimeNumbers();
		int upperLimit = primeGenerator.getPrimeIndex(997);
		int lowerLimit = primeGenerator.getPrimeIndex(41);

		double[] coefficients = new double[3];
		coefficients[2] = 1;
		MaxObject<UnivariateRealFunction> maxLength = MaxObject.init();

		Stopwatch sw = new Stopwatch();
		sw.start();
		for (int i = upperLimit; i >= lowerLimit; i--) {
			coefficients[0] = primes.get(i);
			for (int j = 0; j < upperLimit; j++) {
				coefficients[1] = primes.get(j) - coefficients[0] - 1;
				UnivariateRealFunction quadratic = new PolynomialFunction(coefficients);
				maxLength.compare(quadratic, Problem_27.getSeriesLength(quadratic, primes));
			}
		}
		sw.stop();
		System.out.println(sw);

		return maxLength.getMaxObject();
	}

	private static int getSeriesLength(UnivariateRealFunction function, List<Integer> primes)
	        throws FunctionEvaluationException {
		for (int i = 0; true; i++) {
			int value = (int) function.value(i);
			if (value < 0 || !primes.contains(value))
				return i;
		}
	}
}

Popularity: 9% [?]

Project Euler : Sundays Falling On First Day Of Month In Twentieth Century

To solve the Project Euler Problem 19, I did initially search around a bit and found the wiki article which explains how to determine the day for any given date by consulting tables of centuries and months. Also I found a list of corresponding months for normal and leap years. By corresponding, I mean that two dates in these months will fall on the same day.

But when I started implementing this, I realized that the sun already provides us the GregorianCalendar class which has methods to do all this built in itself. And then the task was very simple:

public class Problem_19 {
	/**
	 * @return The number of times a Sunday appears as the first day of the month for the interval January 1901 -
	 *         December 2000
	 */
	public static int countNumberOfSundays() {
		int numberOfSundays = 0;

		Calendar cal = new GregorianCalendar();

		// We have been told that 1st of January, 1900 was a Monday
		cal.set(1900, Calendar.JANUARY, 1);
		int sundayValue = cal.get(Calendar.DAY_OF_WEEK) - 1;

		for (int year = 1901; year < 2001; year++)
			for (int month = Calendar.JANUARY; month <= Calendar.DECEMBER; month++) {
				cal.set(year, month, 1);
				if (cal.get(Calendar.DAY_OF_WEEK) == sundayValue)
					numberOfSundays++;
			}

		return numberOfSundays;
	}
}

Popularity: 6% [?]

Project Euler : d For Which 1/d Has Longest Recurring Cycle

Problem 26 in Project Euler is a very simple question. There are two options – check the periodicity of numbers in quotient, or check the periodicity of remainders. Yup! The periodicity of remainders implies periodicity in quotient.

Here is my Java solution. It runs in 125ms on my Latitude D630 laptop.

public class Problem_26 {
	/**
	 * @return The number which has the highest recurring decimal periodicity
	 */
	public int getLargestPeriodicityNumber() {
		PrimeNumbersIterator primes = new PrimeNumbersIterator(1000);
		primes.reverseOrder();
		MaxObject<Integer> maxNumber = MaxObject.init();

		Stopwatch sw = new Stopwatch();
		sw.start();
		while (primes.hasNext()) {
			int i = primes.next();
			maxNumber.compare(i, getPeriodicity(i));
		}
		sw.stop();
		System.out.println(sw);

		return maxNumber.getMaxObject();
	}

	/**
	 * Get the periodicity of recurring decimals by checking the remainders
	 *
	 * @param number The number for which the periodicity is required
	 * @return The periodicity of recurring decimal
	 */
	private int getPeriodicity(int number) {
		List<Integer> remainders = new ArrayList<Integer>();

		int remainder = 10;
		remainders.add(remainder);
		while (true) {
			remainder = remainder % number * 10;
			if (remainders.contains(remainder))
				return remainders.size() - remainders.indexOf(remainder);
			remainders.add(remainder);
		}
	}

	public static void main(String[] args) {
		System.out.println(new Problem_26().getLargestPeriodicityNumber());
	}
}

Popularity: 9% [?]

What Does Evenly Divisible Mean?

I thought it meant the quotient should be even!!

But no! It means dividing a group of objects into subgroups of even size, i.e; same size.  Simply put, A is evenly divisible by B if it leaves no remainder.

Popularity: 6% [?]