Showing posts with label Programming. Show all posts
Showing posts with label Programming. Show all posts

November 22, 2013

Word capitalization with Haskell


We have this problem, given a string of words, capitalize just the first letter, but the main trouble here is the lack of a common pattern to distinguish between one and another, for example:

"helloanyonethere" -> "HelloAnyoneThere"
"himartin" -> "HiMartin"
"hellorange" -> "HelloRange"
"thereach" -> "TheReach"

Well, the trouble can be addressed using Haskell, list and the always opportune recursion. The input information would be a dictionary that contains all possible words and the string to analyze; the output should be an string with the capitalized letters.

November 20, 2013

Pentagonal Numbers in Haskell


As part of my refresh on algorithms, data structures and programming, I found this interesting mathematic problem:

Pentagonal numbers are generated by the formula, Pn=n(3n−1)/2. The first ten pentagonal numbers are:
1, 5, 12, 22, 35, 51, 70, 92, 117, 145, ...
It can be seen that P4 + P7 = 22 + 70 = 92 = P8. However, their difference, 70 − 22 = 48, is not pentagonal.
Find the pair of pentagonal numbers, Pj and Pk, for which their sum and difference are pentagonal and D = |Pk − Pj| is minimised; what is the value of D?

Then, I decided to elaborate a program in Haskell that would find the number D. Of course, you can find the code in Github.

November 8, 2013

Unbalanced Balances...


Once again, I found a challenge in a very common webpage that said the following:

You have a room-full of balances and weights. Each balance weighs ten pounds and is considered perfectly balanced when the sum of weights on its left and right sides are exactly the same. You have placed some weights on some of the balances, and you have placed some of the balances on other balances. Given a description of how the balances are arranged and how much additional weight is on each balance, determine how to add weight to the balances so that they are all perfectly balanced.

There may be more than one way to balance everything, but always choose the way that places additional weight on the lowest balances.

The input file will begin with a single integer, N, specifying how many balances there are.
Balance 0 is specified by lines 1 and 2, balance 1 is specified by lines 3 and 4, etc...
Each pair of lines is formatted as follows:

WL &lt balances &gt
WR &lt balances &gt

WL and WR indicate the weight added to the left and right sides, respectively. &lt balances &gt is a space-delimited list of the other balance that are on that side of this balance. &lt balances &gt may contain zero or more elements.

November 2, 2013

First Haskell Published Program: Arithmetic Progression


I find Haskell a challenging language, one that let you express yourself in different ways as procedural or object oriented programming allows you to do it. I knew about it quite a few months ago, but I have never had the time to concentrate to develop any example using it. As I found in the Facebook challenge example, I considered was a good opportunity to create a program with the current knowledge of Haskell (minimal) and still learn a lot using what I take for granted in other languages (C++ or Objective C).

At first, it is really a change of paradigm to start thinking about functions instead of variables that you declare at the beginning and use them as the program executes. Here those do not exist in the same way, as it does for loops (while or for) and the list are fundamental for data manipulation, you will notice my tries to force the language to behave as a procedural language, which I am aware it is not the best practice, but for the first steps I consider it is ok.

The statement of the test is the following:

October 29, 2013

Deferred Lighting: The backdoor, Part 2


In the first part of this article, we covered the a little theory of what this technique means as well as we set the foundations of code that started its execution on main. Now, the functional parts that are needed to create magic are going to be explained as follows.

When the Renderer class is allocated, also the constructor method is called, and here many preparations take place; in the following order: load each necessary CG shader, initialize the sphere lights (8) and place them across the heightmap, create the projection matrix and the root scene node to render objects, load the splash screen as a mesh, and set some configuration of the GCM. It is important to have considered the mesh "Sphere", this object will be the one in charge of draw into the scene the values of each light, in other words, the light will affect only on the area this sphere is colliding with, nothing else, process that differs from a ray tracing procedure. The code for what was explained before is here:

October 25, 2013

Deferred Lighting: The backdoor, Part 1


Today, I was asked about the theory behind the Deferred Lighting procedure, of which, to be honest, I was starting to forget (too much Functional programming lately); but what is well learned, is never forgotten.

The main idea behind this technique is to delay as much as possible the calculations of light over the objects on the scene, only those that deserve to be rendered will be performed, otherwise will be discarded. This also relies on "several" passes, which also means, the first time an scene is going to be rendered as normal: vertex positions, its normals and the material for each surface and instead of sending it to the screen it is transformed into a "texture" with information of the depth, normals and specular. This last texture becomes the input for the next step, where lighting takes place using the information from the variables from the previous phase. And then one "last" pass calculates all objects in the scene once again but this time it combines the color from the texture with the emissive and ambient light. The image below shows graphically how they are all added:

March 17, 2013

Constraint Functional Programming using Heterogenous Architectures

What a fancy name for just do this:

Have a Constraint Satisfaction Problem, then program it using Haskell and exploit multicore capabilities, what I mean with this, that user should not worry if they have 1, 10 or 1000 processing units, he/she would see an automatic performance increase just by running on a platform where more resources are available.


March 23, 2012

Deferred Lighting on PS3


After almost 4 weeks trying to work out Deferred lighting on the PS3, we did it!! Thanks to the help and knowledge of almighty Richard, we were able to render to multiple phases and output the results on a PS3, something quite similar to what is shown on the initial image.

But less words, more action:

March 19, 2012

MSc in Computer Game Engineering @ NCL



Hello Everyone!!

I know I've been far away from blogging in a long time, more precisely since September 9 2011, when today it's March 19, 2012. Before you get angrier with me, let me explain why I've been so faraway lately:

In late September I started master degree program in the United Kingdom, at the Newcastle University, then right now I'm studying MSc in Computer Game Engineering, where I've learnt so much about programming in C++, OpenGL, Maths for Graphics, Memory Management, even how to program for the PS3 using the Sony Official SDK, isn't it so exciting??

That's my main reason for being so distant from my blog, another was the overhear that was moving from México City to Newcastle Upon Tyne: baggages, computers, clothes and almost my entire life, however I forgot my tennis shoes back home.

April 18, 2011

Let's dance with Sorting Algoritms

Have you ever cracked your mind trying to understand sorting algoritms like the one of bubble, insert, shell or some others?? Ok, this is your lucky day to at least have fun watching some videos.

Sapientia University, in Romany, is responsible for this idea and production. The sort methods that are shown list the Bubble Sort (by Hungarian folk dance "Csángó"), the Shell Sort (by Hungarian folk dance "Székely), the Insert Sort (Hungarian dance only) and the Select Sort (by gypsy dance unspecified).

December 10, 2010

More Cocoa Tips and Tricks


I been working on improving and adding functionality to Mittratter so that it will be available through the Mac App Store. Of course, in my path to developing it, I found more tutorial that could help others programmers out there:

November 27, 2010

Cocoa App Life Cicle

Every process has a beginning and an end, that's how we are able to describe the procedural steps involved to reach an objective. And of course, computational apps, are related to a certain steps necessary to execute a block of code. Most common example is the operative system, this is once we push the button every circuit runs a piece of compiled source so that after 10 - 40 seconds we are using it.

After this boring introduction, let's go to the matter of this post: How Cocoa Apps runs in MacOS X:

October 28, 2010

Objective C Valuable Links

Right now that I have been developing Suertudo for the iPhone/iPod, many doubts and circumstances have been solved with just little search over the greatest Google, however others have not, anyway I found many useful links that could help many others programmers:

October 25, 2010

FastPost: iOS User Interface Dimensions

iOS management bars for normal resolution devices has this constants:

- Status bar: 20 pixels
- Nav bar: 44 pixels
- Tab bar: 49 pixels
- Toolbar: 44 pixels


WebOS for Android with Itching Thumb


Such applications are always interesting, because one of the things people most want is to customize their mobile. In addition to testing things that belong to an OS, running in another.

WebOS multitasking interface is based on "cards" system. Inside the application, the user makes a gesture in the "gestures area" of the phone to bring the "cards" (apps) to front, enabling the move along left and right of the screen. Applications are closed by releasing the app of the screen. Something similar is what Itching Thumb tries to emulate, multitasking management view like for Android.

September 20, 2010

Mittratter - Source Code


Ok, the Compilated App has been released here: Mittratter and its post related: http://mittrasw.blogspot.com/2010/09/mittratter-twitter-client-for-osx.html. What would help to other programmers trying to implement oAuth into their developments will be the source code used by Mittratter to sign into Twitter's Servers. Also I will give a brief explanation of how does this thing work.

As I explained here and here, now Twitter uses the oAuth Procedure, well the code behind is quite tricky and might confuse at first sight. Mittratter is an application developed in Objective-C, so the code is going to display here helps to implement those functions into iPhone/iPod Touch/iPad developments as well. Don't forget to do a quick review of the Twitter API where few libraries and implementations could be found. Well, let's get started.

Mittratter - Twitter Client for OSX


Yesterday, I was writing about the Twitter oAuth Authentication Method, well today I will release Mittratter, it is a simple Twitter Client developed with Objective-C and XCode. It took me few hours of development to understand the way oAuth works, Twitter and available documentation about it.

With the App running, I will give an example how exactly this works:

September 5, 2010

Prog: Accelerometer on iPhone/iPod Touch

In this post, I am going to talk about the accelerometer on the iPhone/iPod Touch and how to use it via SDK. The Wikipedia says that

An accelerometer is a device that measures proper acceleration, the acceleration experienced relative to freefall.

Well the accelerometer inside the device help us to detect the relative position in relation with the gravity, measuring the answer of the 3 movement axis: x, y and z, so this allow the device to detect its orientation (portrait, landscape, face up or down), a shake or the relative values in specific moment in time.


And accelerometer sensor is not only used on Phone devices, also many high end cameras uses for the image stabilization; the cars to detect the vehicle acceleration; watches for runners that include footpods; the Nintendo Wii with the accessory Wii Motion Plus or the six axis control of the PS3 includes one. Well let's talk about how to get the values of this sensor in side the iPhone/iPod.