Showing posts with label euler. Show all posts
Showing posts with label euler. Show all posts

Sunday, November 4, 2012

Bitwise operators in C, JavaScript, Lua and Killa

So I thought that porting a Game Boy Advance (GBA) console emulator written in JavaScript to Killa would be fun, boy I was wrong... All because I wanted to play with this:


Thursday, November 1, 2012

Dynamic programming

Dynamic Programming (DP) problems are fun, but they can be also difficult to solve. For a better definition than I could give you here I'll redirect you to the Wikipedia article, and there are some nice tutorials and sample problems in TopCoder and CodeChef. In this post I'm just going to add commentaries to the DP problem I solved previously without giving much explanation. This problem comes from the Project Euler site:

An n×n grid of squares contains n^2 ants, one ant per square.
All ants decide to move simultaneously to an adjacent square
(usually 4 possibilities, except for ants on the edge of the grid or at the corners). 
We define f(n) to be the number of ways this can happen without any ants ending on 
the same square and without any two ants crossing the same edge between two squares.
You are given that f(4) = 88. Find f(10).

Sunday, September 16, 2012

Combinatorial explosion and Project Euler 393

Last week I found a nice video about algorithmic combinatorial explosion. It was very interesting but it's a bit sad to see the big sister throwing away her life in order to teach her little students the perils of trying to compute combinatorial problems that grow very fast. The problem they studied didn't seem to be hard, just enumerate all the ways you can go from one corner to the opposite corner in a rectangular grid without passing the same node twice. Deceptively simple, for a 1x1 grid there are only 2 ways, for a 2x2 grid there are 12 ways:

Friday, July 3, 2009

Particiones enteras

Celebrando el hecho de que ya termino con mi primer ciclo de la maestría, y que ademas he conseguido el titulo de experto en ProjectEuler haré un post acerca de un problema que me parece interesante. El enunciado es bien simple:

Dado un numero entero "n" ¿De cuantas maneras diferentes se puede descomponer "n" en números enteros positivos?.

La solución aunque simple no es evidente.
Por ejemplo, sea n = 4.
4 puede descomponerse en: ( 1 + 1 + 1 + 1 ), ( 1 + 2 + 1 ), ( 3 + 1 ), ( 2 + 2 ) y ( 4 ). Cada una de estas sumas es una partición entera de 4. Como buscamos solo particiones diferentes hay algunas que no se consideran, por ejemplo, no se esta considerando ( 2 + 1 + 1 ) porque es lo mismo que ( 1 + 1 + 2 ) si ignoramos el orden.
Es fácil entender de donde viene el nombre de partición entera, lo que estamos haciendo es "partir" el numero 4 en agrupaciones diferentes:
Vemos que el numero de formas diferentes en que se puede descomponer 4 es 5.