FICO : Hips Don’t Lie

The video speaks for itself. It was a night when we had lots of fun with our juniors at FICO. I wish a few of them join the cultural team and we continue planning fun activities.

Popularity: 2% [?]

Chelsea Songs

A few Chelsea songs that I liked:

Carefree:

Carefree
Where-ever you may be
We are the famous CFC
And we don’t give a fuck
Who-ever you may be
Cause we are the famous CFC

Blue Is The Colour:

Blue is the colour, football is the game
We’re all together, and winning is our aim
So cheer us on through the sun and rain
’cause Chelsea, Chelsea is our name
Here at the Bridge whether rain or fine
We can shine all the time
Home or away, come and see us play
You’re welcome any day
Blue is the colour, football is the game
We’re all together, and winning is our aim
So cheer us on through the sun and rain
’cause Chelsea, Chelsea is our name

Come to the Shed and we’ll welcome you
Wear your blue and see us through
Sing loud and clear until the game is done
Sing Chelsea everyone.

Blue is the colour, football is the game
We’re all together, and winning is our aim
So cheer us on through the sun and rain
’cause Chelsea, Chelsea is our name
Here at the Bridge whether rain or fine
We can shine all the time
Home or away, come and see us play
You’re welcome any day
Blue is the colour, football is the game
We’re all together, and winning is our aim
So cheer us on through the sun and rain
’cause Chelsea, Chelsea is our name

Popularity: 3% [?]

Ted Talks : How Youtube Thinks About Copyright

Margaret Gould Stewart in this video explains the copyright violation of new videos that are uploaded to youtube. She says that when a video is uploaded, its heatmap is checked for a match with all the existing videos. Each point is tried for a match with each other point so that if the uploaded video is a clip of the original, or has audio/video slightly slowed or fast forwarded, even then the two would get matched.

Unless, the user of original video has mentioned strict no copy policy, in which case a new upload gets immediately rejected, when an uploaded video is found to match with an existing copyright video, the user owning the copyright is given an option to deal with the video .  The user might want to allow the upload if he sees a potential for advertisement/propagation.

She mentions an example wherein a video song released by Sony went off the charts in just a few weeks. Months later, a wedding video was uploaded featuring the same song. Now since Sony had the copyright to the song, they were given the option to either reject the upload or let it be. They allowed the upload, and put up advertisements and links to this upload from their page. Within weeks the video went ballistic and was watched by millions of people all across the world. The song was back in reckoning and it made to the 4th spot in the weekly charts!

Thinking about it, I do feel a bit of leniency can do good promotion of a video and should be the encouraged option.

Popularity: 6% [?]

Intelligent Tutor System

I spent a couple of days reading about the Intelligent Tutor Systems and gave a presentation to our team at FICO. The presentation was a brief overview on the cognitive aspect of building up a tutor.

Popularity: 7% [?]

A Few Monologues I Liked

Not at all an exhaustive list. Mentioning only 4 that come to my mind now.

Jack Nicholson, A Few Good Men (1992)

You can’t handle the truth! Son, we live in a world that has walls, and those walls have to be guarded by men with guns. Who’s gonna do it? You? You, lieutenant Weinberg? I have a greater responsibility than you can possibly fathom. You weep for Santiago, and you curse the Marines. You have that luxury. You have the luxury of not knowing what I know – that Santiago’s death, while tragic, probably saved lives. And my existence, while grotesque and incomprehensible to you, saves lives.

Samuel L Jackson, Pulp Fiction (1994)

The path of the righteous man is beset on all sides by the inequities of the selfish and the tyranny of evil men. Blessed is he who, in the name of charity and good will, shepherds the weak through the valley of darkness, for he is truly his brother’s keeper and the finder of lost children. And I will strike down upon thee with great vengeance and furious anger those who attempt to poison and destroy my brothers. And you will know my name is the Lord when I lay my vengeance upon you.

Mel Gibson, Braveheart (1995)

You have come to fight as free men, and free men you are. What will you do with that freedom? Will you fight? Aye, fight and you may die, run and you’ll live. At least a while. And dying in your beds many years from now, would you be willing to trade all the days from this day to that for one chance. Just one chance to come back here and tell our enemies that they may take our lives, but they’ll never take our freedom!

Robert Duvall, Apocalypse Now (1979)

You smell that? Do you smell that? Napalm, son. Nothing else in the world smells like that. I love the smell of napalm in the morning. You know, one time we had a hill bombed, for twelve hours. When it was all over I walked up. We didn’t find one of ‘em, not one stinkin’ dink body. The smell, you know that gasoline smell, the whole hill. Smelled like… victory. Someday this war’s gonna end…

Popularity: 3% [?]

2010 WC Finals : Germany vs Australia – Beautiful

It was a wonderful game yesterday. I was amazed at the fluency with which the young German midfielders passed the ball around. At every chance they spurt forwards creating a goal scoring opportunity. 4-0 is a scoreline any team would be excited with, but I think the Germans could have won by a bigger margin.

With the likes of Ballack and Frings missing, I was skeptical of this young and relatively unknown group of players. To add to that, Podolski and Klose were coming after a difficult season with their respective clubs. But the two have a knack of lifting their game when they put on the white jersey of the national team. And they did that again tonight. You could see the brilliance of Podolski feeding crosses for Klose from the left wing. Klose though failed to grab them, and you could see his agony and the frustration.

The movements of Ozil and Khedira were troubling the Australians already.  Muller made it worse with his forward runs. It was simply amazing to watch them take control and dictate the pace of the game. And then Podolski scored!!! A powerful shot into the nets, even the palm of the Australian goalkeeper could not keep it away. But when Klose headed the ball home I had tears in my eyes. He sliced himself between the keeper and a defender to win the ball and head it right into the nets. This might be his last world cup finals, and I really want that guy to net another 5 goals this summer.

What excited me the most was the youthful energy of this team. They were ready to press ahead. As a fan commented:

Germany has evolved ever since Klinasmann took the helm. The days of slow build up play followed by a cross/header attempt are over. Although the Germans dont have 1 world class striker they have proven several players can slice through defences like a shark in water and put the ball in the back of the net. Now lovely through balls and tic-tac-toe passes are the heart of the german offence. However the Defence and Keepers have yet to prove themselves for this German side as I belive they are the weaklink.

The real test of this young side will be in the knockout stages when they run into the likes of Spain and England. It is then that the youth vs. experience will be tested, and we shall know if the 20-somethings of this starting 11 have it in them to cope up with the pressure. I have faith in the youthful energy of this reinvigorated German team, and even if they fail to reach the final, I am sure they will provide an entertaining and spectacular game of football.

Popularity: 8% [?]

FICO : Icebreaking Session – Lessons Learnt

Well, being a part of a group who had to think up something for the ice-breaking, I have learnt a new lesson today.

People on their first day are just too nervous to really play a game even if you ask them to.

My idea was pretty simple. I believe that creating systematic chaos is the best way to make people gel together. So we had come up with this idea of having a simple ball game. The instructions were to move around the room and throw the ball at a person who you want to play the game of truth-or-dare with.

I had imagined a room full of people enthusiastic about joining their first job. But it turned out to be otherwise. When we asked a guy to sing, all he could muster his courage and blurt out was that he was too nervous to do anything right then. Also, those fools were rooted to their places. They weren’t moving at all! :( … My ideas of systematic chaos just did not lift up.

Thinking retrospectively about the whole thing, I guess it was asking too much.

The other activity that we made them do was more fun. It involved the bollywood theme, so people enjoyed it.

Popularity: 6% [?]

Project Euler : Pascal Triangle To Find nCr

Problem 53 required one to find all the generated numbers of nCr, 1 <= n <= 100, which are greater than a million. And the solution was all too simple – Pascal Triangle.

Each row of the Pascal Triangle is a series of nCr. So all that was needed to be done was to generate a triangle to a depth of 100, and find all the large numbers.

One small modification that I could have done is – not all numbers needed to be calculated. Once a number greater than a million is found, all successive number in that series till the halfway mark will be greater than million. Remembering just the smallest number greater than a million should have sufficed.

public class Problem_53 {
	public static int solve() {
		int count = 0;

		Map<Settings, Object> settings = new HashMap<Settings, Object>();
		settings.put(Settings.ONLY_RIGHT_HALF_GENERATION, true);

		PascalTriangle pascalTriangle = new PascalTriangle(settings);
		for (int i = 1; i <= 100; i++) {
			int sum = 0;
			for (double num : pascalTriangle.constructNextLevel()) {
				if (num < 1000000)
					break;
				sum++;
			}
			count += sum > 0 ? (i % 2 == 0 ? 2 * sum - 1 : 2 * sum) : 0;
		}

		return count;
	}

	public static void main(String[] args) {
		System.out.println(Problem_53.solve());
	}
}

The Pascal Triangle Generator

public class PascalTriangle {
	private List<List<Double>> m_triangle;
	private int m_currentLevel;
	private boolean m_onlyRightHalfGeneration;

	public PascalTriangle(Map<Settings, Object> settings) {
		m_currentLevel = 0;
		initTree();
		m_onlyRightHalfGeneration = isOnlyRightHandGenerationEnabled(settings);
	}

	/**
	 * Create a new tree and initialize the Level 0
	 */
	private void initTree() {
		m_triangle = new ArrayList<List<Double>>();
		List<Double> levelZero = new ArrayList<Double>();
		levelZero.add(new Double(1));
		m_triangle.add(levelZero);
	}

	/**
	 * Check if the property ONLY_RIGHT_HALF_GENERATION is enabled by the user
	 *
	 * @param settings The settings provided by the user
	 * @return true if the ONLY_RIGHT_HALF_GENERATION is set to true
	 */
	private boolean isOnlyRightHandGenerationEnabled(Map<Settings, Object> settings) {
		return !settings.containsKey(Settings.ONLY_RIGHT_HALF_GENERATION) ? false : (Boolean) settings
		        .get(Settings.ONLY_RIGHT_HALF_GENERATION);
	}

	/**
	 * Construct the next level of the Pascal Triangle.
	 *
	 * @return the new level added to the Pascal Triangle
	 */
	public List<Double> constructNextLevel() {
		return m_onlyRightHalfGeneration ? constructRightHaflTreeNextLevel() : constructLeftHaflTreeNextLevel();
	}

	/**
	 * Construct the left half of the tree
	 */
	private List<Double> constructLeftHaflTreeNextLevel() {
		List<Double> nextLevel = new ArrayList<Double>();
		Double prevNum = new Double(0);
		for (Double num : m_triangle.get(m_currentLevel)) {
			nextLevel.add(prevNum + num);
			prevNum = num;
		}
		if (m_currentLevel % 2 != 0)
			nextLevel.add(2 * prevNum);

		m_triangle.add(nextLevel);
		m_currentLevel++;

		return nextLevel;
	}

	/**
	 * Construct the right half of the tree
	 */
	private List<Double> constructRightHaflTreeNextLevel() {
		List<Double> prevLevel = m_triangle.get(m_currentLevel);
		List<Double> nextLevel = new ArrayList<Double>();

		Double prevNum = prevLevel.get(0);
		if (m_currentLevel % 2 != 0)
			nextLevel.add(2 * prevNum);

		for (int i = 1; i < prevLevel.size(); i++) {
			Double num = prevLevel.get(i);
			nextLevel.add(prevNum + num);
			prevNum = num;
		}
		nextLevel.add(new Double(1));

		m_triangle.add(nextLevel);
		m_currentLevel++;

		return nextLevel;
	}

	/**
	 * Settings for the Pascal Triangle Generator
	 *
	 * @author AnuvratSingh
	 */
	public enum Settings {
		ONLY_RIGHT_HALF_GENERATION
	}
}

Popularity: 7% [?]

Project Euler : Problem 32 – All Round Pandigital

The problem requires one to find a product of two numbers such that the multiplicand/multiplier/product can be written as a 1 through 9 pandigital.

An example would be: 39 * 186 = 7254

Working with paper and a pencil, one can discover that the two form of solution are:

a * bbbb = cccc

aa * bbb = cccc

So all that was required to be done was generate all 9 digit permutations of 1-9 and then check if the arrangement satisfies any of the two cases mentioned above.

public class Problem_32<I extends Integer> {
	public static void main(String[] args) {
		System.out.println(new Problem_32<Integer>().computeSum());
	}

	public int computeSum() {
		int sum = 1;
		Set<Integer> products = new HashSet<Integer>();

		Iterator<CombinatoricsVector<I>> permutationIterator = getPermutationGenerator();
		while (!permutationIterator.isDone()) {
			permutationIterator.next();
			CombinatoricsVector<I> permutation = permutationIterator.getCurrentItem();
			products.add(checkCaseA(permutation));
			products.add(checkCaseB(permutation));
		}

		for (Integer i : products)
			sum += i;

		return sum;
	}

	/**
	 * Case A :: a x bbbb = cccc
	 *
	 * @return cccc if above equality holds, -1 otherwise
	 */
	private int checkCaseA(CombinatoricsVector<I> permutation) {
		int a = permutation.getValue(0);
		int b = get4Number(permutation, 1);
		int c = get4Number(permutation, 5);

		return a * b == c ? c : -1;
	}

	/**
	 * Case B :: aa x bbb = cccc
	 *
	 * @return cccc if above equality holds, -1 otherwise
	 */
	private int checkCaseB(CombinatoricsVector<I> permutation) {
		int a = get2Number(permutation, 0);
		int b = get3Number(permutation, 2);
		int c = get4Number(permutation, 5);

		return a * b == c ? c : -1;
	}

	private int get2Number(CombinatoricsVector<I> permutation, int startIdx) {
		return permutation.getValue(startIdx) * 10 + permutation.getValue(startIdx + 1);
	}

	private int get3Number(CombinatoricsVector<I> permutation, int startIdx) {
		return permutation.getValue(startIdx) * 100 + permutation.getValue(startIdx + 1) * 10
		        + permutation.getValue(startIdx + 2);
	}

	private int get4Number(CombinatoricsVector<I> permutation, int startIdx) {
		return permutation.getValue(startIdx) * 1000 + permutation.getValue(startIdx + 1) * 100
		        + permutation.getValue(startIdx + 2) * 10 + permutation.getValue(startIdx + 3);
	}

	private Iterator<CombinatoricsVector<I>> getPermutationGenerator() {
		ArrayList<I> array = new ArrayList<I>();
		for (int i = 1; i < 10; i++)
			array.add((I) new Integer(i));

		Iterator<CombinatoricsVector<I>> permutationIterator = new PermutationGenerator<I>(new CombinatoricsVector<I>(
		        array)).createIterator();
		permutationIterator.first();

		return permutationIterator;
	}
}

Popularity: 16% [?]

Project Euler : Largest N Digit Pandigital Prime Number

Well, I did a brute force for problem 41 for Project Euler. There’s a smarter way of course, but I still haven’t implemented a Permutation Generator. That later.

I already have a good enough prime number generator. So all I did was to generate all the prime number till 7 digits long. Why did I not go any further?

8 digit pandigital numbers will sum up to 36, and the 9 digit numbers will sum up to 45. So all the pandigital 8 and 9 digit numbers will be non-prime. So we need to check till atmost the 7 digit prime numbers.

Now apart from a prime generator, I also have a prime number iterator, which can iterate forwards as well as backwards. So all I had to do was to ask my iterator to iterate backwards and check if the prime number is pandigital or not.

Obviously, my prime number iterator internally calls my sieve of Eratosthenes to generate prime numbers using java.util.BitSet.

Surprisingly, the code runs in just a few seconds! I was expecting it to take atleast a minute.

Here is my prime number iterator:


public class PrimeNumbersIterator implements Iterator<Integer> {
	private PrimeNumbers m_pNumber;
	private int m_currentIndex;
	private boolean m_reverse;

	public PrimeNumbersIterator(int upperLimit) {
		m_pNumber = new PrimeNumbers(upperLimit);
		m_reverse = false;
	}

	public boolean hasNext() {
		if (!m_reverse)
			return m_currentIndex < m_pNumber.getNumberOfPrimes() ? true : false;
		else
			return m_currentIndex >= 0 ? true : false;
	}

	public Integer next() {
		Integer prime = hasNext() ? m_pNumber.getPrime(m_currentIndex) : null;
		if (m_reverse)
			m_currentIndex--;
		else
			m_currentIndex++;

		return prime;
	}

	public void remove() {
		throw new UnsupportedOperationException();
	}

	public void reverseOrder() {
		m_reverse = !m_reverse;
		m_currentIndex = m_pNumber.getNumberOfPrimes() - 1;
	}
}

And here is a small unoptimized method to check if the number is pandigital or not:


	public static boolean isNPandigital(int number) {
		int numberOfDigits = NumberUtil.numberOfDigits(number);
		int[] digits = new int[numberOfDigits];
		Arrays.fill(digits, 0);

		while (number > 0) {
			int digit = number % 10;
			if (digit == 0 || digit > numberOfDigits || digits[digit - 1]++ == 1)
				return false;
			number /= 10;
		}

		return true;
	}

Popularity: 32% [?]