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:

October 9, 2013

SSH and Sudoers

After I had set up the server to connect to my internet source, the next step to cover was a way to communicate to it without using the User Interface. As there are many solutions, one of the most common, safe and secure is the SSH protocol (Secure SHell).



In order to archive this in the Ubuntu Server, I followed this tutorial:

 # sudo apt-get install openssh-client openssh-server 

August 4, 2013

DNSCrypt on Ubuntu


After setting up a shared wireless connection, I started to be worried about the "plainness" of the transmissions, that everything which would go through the air and the router could be simply read by another received and use that information to another purpose. Of course, there is the always reliable TOR network, but due to a quite high latency already increased, then I decided to skip it. Nonetheless, I still wanted something running on every request and that would increase a little the privacy, then I found DNSCryopt. In other words:
DNSCrypt encrypts all DNS traffic between your computer and the OpenDNS servers (so you'll be using OpenDNS) and can protect you from man-in-the-middle attacks, spying, resolver impersonation, can prevent Internet service providers from blocking various websites and more.

July 16, 2013

Configure an Ubuntu "Gateway"

The original title was going to be:

Configure an Ubuntu "Gateway" using two wireless devices and one server

But it was going to be long and boring. Ok, everything started because I have moved to a new location and I was not going to have internet in a long time nor willing to get a two year contract with a company again. So, connection from my supporting neighbor was provided, the only thing I had to do is to create an extension to his wireless AP. Easily enough I could had bought a WiFi extender, but no fun was going to be out of there and of course, if he would like to sniff what was going trough, well you know the history.

Fortunately I have this hardware ready to be set up:

VIA ARTiGO Pico-ITX Builder Kit A1000
Alfa AWUS036NH
WiDrive DX325

I could explain the network, but better seen graphically:

April 10, 2013

Scalability and consistency in Server Based Network Gaming


While I was doing the MSc in Newcastle, we needed to create an academic paper for the Game Networking module. So, now I am doing it public so other people, and specially researchers, can see that I have strong academic background and I am able to write papers. Of course, I am open to comments and always learning new ways to do it better ;)

This paper describes the capabilities of a Server based communication between two or many PS3 consoles as a way to efficiently transfer data using the TCP/IP protocols with the hardware embedded (Ethernet Cable and Wireless 802.11G). Also, it coves the common problems arising with the inclusion of more systems in the same network in order to keep communication consistency as well as some performance efficacy under different scenarios where low and high data transfer is required in between systems, whilst just one active server socket is kept open. When low demand applications are running and as highly bandwidth consuming case both are presented, in order to estimate how many consoles could be brought into the same network without a hit on game accomplishment.

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 2, 2013

Voxel Render Engine for PS3 SDK

Hello Everyone!!

Long time I have not been here, not even to check if someone is trying to spam comments all around. Well, the good news it is that today I wanted to release my Master Thesis, which was about a way to display voxelized models using the PS3 SDK.

I did not do it before because I was "under NDA", an agreement between Newcastle University and SCE Europe. however I think by this time, they do not care anymore about releasing key points and ideas about what my document is about.