Posts

Another challenging problem

Image
Code Jam round 3 seems to be quite more challenging than previous rounds. I was not able to complete Polygonovich's professor problem in two hours. I was quite happy with the use of java.awt.Polygon object, mostly because it includes a contains method that seemed quite useful for this problem. However solving the problem took longer than expected too, as I wanted a method that worked nicely for both the small and large problems. In the mean time I constructed the whole set of graphs for the small dataset. You may find it interesting. Vacation time is over though, so I'll be back to work soon I still I have some problems pending.

Keeping me entertained

I thought the Crop Triangles Code Jam problem will be gone in no time. It looked simple the morning I started with it and I was expecting to have it all done by lunch time. The basic idea is that you have an integer coordinate system (or grid) and in certain points of the grid there are some trees located. If you use those trees as vertices to make triangles ... how many different triangles can be created? Well, the answer to that is actually quite simple using combinatoric numbers, but they added a restriction: the center of a valid triangle has to be located on a grid coordinate, if not do not count that triangle. A triangle with vertices (x1,y1) (x2,y2) and (x3,y3) has a center at coordinate ((x1+x2+x3)/3,(y1+y2+y3)/3) My first solution was to simulate the system. Given all the available trees, I will go though all the different combinations and after checking each one a counter will give me the valid answer. That idea worked nicely for the small dataset (once I realized that Case #...

CVT vs MT vs AT vs AMT

Image
I've always owned manual transmission (MT) cars, but while living in USA I drove automatic transmission (AT) cars most of the time (manual transmission is not very popular over there). When I recently bought a car I was offered a continuously variable transmission (CVT) that, instead of gears, uses an steel belt and two variable-diameter pulleys. The system works nicely and it may even offer a set of "simulated" fixed transmission rates. While the fuel economy is not as good as MT it gets quite close. For many years AT cars exhibited worse fuel economy than their MT counterparts. I've always found weird that, but I am not a mechanical engineer 8but wikipedia tells me it's because of torque converter mostly). Now it seems some manufacturers, probably feeling the pressure from regulators due to the high cost of petrol, are delivering a new technology (maybe not so new) dubbed as automatic manual transmission (AMT). The good thing about AMT is that its fuel e...

Solving Triangle Areas

Vacation time is a good moment to ... keep on trying things at the computer. At least this is what I am doing now, as have been having a look at the Code Jam Round 2 problems. Again interesting problems that I have not been able to solve in two hour time. Amazingly, some guys did it with flying colors and using a bit more than one hour! I have already done the Star Wars problem , though I would complain that there is not such a thing as "receiver power" (even on a spaceship) but "receiver sensitivity". However the problem was challenging and fun (I did a minimum search in 3D space and it worked). I'm dealing now with the Triangle Areas problem, that though manageable in complexity it is a bit of a challenge to get right. A few ideas can help, the first one is how to know the triangle area out of set of vertices coordinates . The second observation is that if we keep one vertex at (0,0) then the area of the triangle is just 0.5*(x2*y3-x3*y2). With this idea in mi...

Defeated by Ugly Numbers

Now I am out of Code Jam 2008. Though I did the Text Messaging Outrage quite easily I've bet my solution to the use of the 'bc' command as a helper in Ugly Numbers for computing strings like "12123+324234+232342-234234". For these numbers it does not seem to be any need, but to be able to solve the large data set of the same problem arbitrary (or at least 40 digits) precision was a requirement. 'bc' can work with these, but unfortunately the computing speed I've got was not up to the task. I was piping each line to 'bc' and reading the proper answer. Unfortunately it took more than half an hour on my laptop to finish calculation. I run out of time and I failed both small and large datasets. Later on, once the contest was over and the problems were in practice mode I uploaded my solution file for the small problem and it was Correct! (too late). Still my routing for checking ugly numbers was only dealing with Java longs (n Now I've changed...

My laptop's Gutsy meets vodafone

Sunday morning I'd like to be able to join CodeJam round 1. But I'm attending a wedding out of town. I asked for some help and I've borrowed a Huawi e220 UTMS modem from my university. Just pluging it in did not do the trick though. Ubuntu showed a CD-ROM-like icon on my desktop that contained the device's Windows drivers. I was told to do some dark magic that did the trick for Spanish Vodafone prepaid service: umount /dev/sr0 rmmod usb-storage rmmod usbserial modprobe usbserial vendor=0x12d1 product=0x1003 #now disconnect the modem and reconnect it again #wait a few seconds ls -la /dev/ttyUSB* # three devices should show up # now fire wvdial I've created this wvdial.conf file: [Dialer Defaults] Init2 = ATZ Init3 = ATQ0 V1 E1 S0=0 &C1 &D2 +FCLASS=0 Stupid Mode = 1 Modem Type = Analog Modem ISDN = 0 Phone = *99***1# Modem = /dev/ttyUSB0 Username = user Dial Command = ATDT Password = pass Baud = 460800 Init4 = AT+CGDCONT=1,"IP","ac.vodafone.es...

CodeJam Qualification Round

It took place yesterday. It was made of three interesting problems. Not too difficult I would say, but 24h were not long enough for me to finish on time. I did the first too problems: Saving the world and Train Timetable, but I failed the third one: Fly Swatter (I chose Montecarlo approach and I did not get accurate enough results). I think being familiar with the contest site helped and every time the site was responsive. Being behind of several thousands of more talented guys is good to keep you humble. I loved the mental exercise and it felt great every time you get a Correct! answer. Still this morning I've been discussing with my colleagues how to get the Fly Swatter right and I have an idea to test, that hopefully will work: Calculate the area of the openings but modifying the value of g so now g is min(0,g-f) . One minus the quotient of this area and the circle area should be the answer to the problem (or so I think till I test it).

Arduino talk

Image
I am giving a talk at an Arduino workshop next Saturday 17:00. There is no attendance fee and people will be able to try their own code on the available Arduinos. Contact was made through the Arduino Forum and Vicent Ferrer proved to be quite an entrepreneurial person. Presentation will be held in Spanish and hopefully it will include a lot of Q&A and user experimentation. If you bring your own laptop you will be sure you'll get the development environment installed.

Photoshop degrees

We have some international programs at our university. Besides European students, many students from Spanish-speaking countries from South America are attending too. I am sure there is a good amount of paperwork (yes, in the paperless era it is when paper usage is skyrocketing) to go through the admission process. The twist is that now some people are thinking this international programs can be used as an excuse to get a visa to enter the country. Some doctored documents are sent in the hope they will go undetected, but while the Photoshop work is good, the background checks on the side of the fraudsters are not: They have created fake titles of real world universities, but they have selected degrees that have never been taught at those universities. You know that the Euro currency is now used in many (but not all) European countries (Denmark, Sweden and Norway come to my mind now) but if you are handed over an Euro from, let's say, Brazil, you are sure it is forged note. Fraudster...

New tricks to an old dog

Image
Some time ago I developed a small project that put together a few software pieces to create a monitoring system. I've used for development a great graphics library built in PHP called JpGraph . It did the work but I realized that the software license required payment of $600 for each website that use it commercially. As my system was like an Internet appliance and each customer had a different unit (and address) it seemed that I would need to add $600 to the price tag of the system to be compliant with JpGraph license. It was time to look for an alternative, as there was no way the product price could support that extra cost. So I found libchart library that worked nicely with PHP5 (provided you already have GD support built-in). The end result looks ok too, though libchart lacks many of the features of JpGraph, it is still good enough for my application. Libchart author licenses the software with GPL3 and while the software is free, he's accepting donations.

Shopping list problem

Image
Definitely this has been the most challenging problem I've found on the Code Jam practice site. It asks you to determine the optimal selection of what to buy where. With a couple of twists: the cost of going from one place to another is factored in; plus a rule that forces you to drive back home whenever you're buying perishable goods. The approach that worked for me was to first consider the different combinations of articles from different shops, just to obtain the list of shops to visit for each instance. Each one of list of shops to visit is a traveling salesman problem (perishable rule just changes the cost of some of the links). Combine both costs, the article's prices at selected shops and the transportation costs to determine how much each realization will amount. The minimum case is the answer you're looking for. The main problem I faced with the large set is that unless the code is quite efficient (and mine was not) it will take a long long time to finish the...

Google Code Jam '08

Image
I've just got a notice about the new edition of Google Code Jam . I guess if you like challenges it is a place to go. I've spent part of the evening solving the "Alien Numbers" problem just to discover how rusted I am. It was fun though, and it was satisfying to make it right (though not very fast I would say).

Single data packet TCP

Image
For Ethernet enabled devices I've used in the past (and I was happy with) the cores from Rabbit Semiconductor. They offer a lot of data and program memory and a royalty-free TCP/IP stack. Not in the same league but still surprisingly useful is the Ethernet shield I've bought from Nuelectronics (a UK-based company). The shield plugs-in nicely on an Arduino board and it can easily allow you to create a simple network appliance. In the picture I have my sample system that using a DS18B20 digital temperature sensor offers the temperature reading as a web page. All the code used is the sample code and TCP/IP library provided by Nuelectronics. I had some minor trouble with my setup as I am using the so-called parasitic power on the temperature sensor and a few lines of code where added to the original code to make it work. The symptom of the problem is that I was getting +85.00 C no matter what the temperature was. The cause was that the sensor did not get enough power from the 1...

Kudos to Canon

Image
I dumped my old Epson color printer, an Epson Stylus Photo Color 830, after playing any trick to get a decent printing performance for quite a while (I failed). As we needed a new printer at home I searched and browsed around and I settled with Canon's IP4300 that also had good Linux support. Unfortunately that model was no longer available (I learned this at the computer shop) so it was not an option. I guessed the next model, Canon's IP4500 won't be that different. It was cool as it could do duplex printing automatically. I was wrong: While the printer worked like a charm ("New" is the best printer brand!) I was disappointed to discover there was not Linux driver. And when I tried the IP4300's driver it did not work at all. Time to go to the Ubuntu forums: There I was referred to a Canon's portal . In there I downloaded and install a couple of .deb files and next I restarted cups. I connected the printer's USB cable to my computer and it was automagi...

Another format for arduino

Image
I've just bought another arduino board for a project. My main complaint with arduino standard board is that it is not prototype board friendly. I am afraid this was a 'feature' and not an error: This way people would have to buy special prototype boards for arduino. This was a design error that later on has survived to maintain compatibility with existing shields (thanks for shedding some light on this, David) There are other solutions like Modern Device BBB, but the new iDuino does include the USB adapter that may power and interface to a PC your project. And iDuino kit costs less than $18 so it seems quite cost effective. The main con is that the kit includes a resonator instead of crystal. I haven't used it yet but it seems another development to have a look at. If you plan to buy one I think you better use Fundamental Logic website instead of eBay.

Dead router

Image
Yesterday night my router died on me. Apparently it is no longer coming up after powering it up. Minutes later it seemed that a hardware reset had brought it back to life: It was not true, while DHCP and router lights were working, only a firmware reload web page was available. After downloading several versions of firmware it became apparent that the damage to the router was beyond the original firmware. Time to buy a new one (or to check with SMC whether a lifetime warranty was included). However, hours later I came across this news . I know it may sound a bit paranoid on my side but timing was just perfect. While I wait the new unit to be delivered, I've borrowed an ASUS WL-500G from the lab. I've been told this unit has a lot of potential once you reflash it with new firmware. A couple of cool projects are possible: OpenWRT or DD-WRT .

Awesome web service

I was browsing this photography blog when I learned about a cool and very useful service . The image below describes better than I would do it what it is about. In the past I featured a similar service but I've found this new service better. Assignment #4 - Get more documents Please note I throw at it the first document I've found on my desktop. It seems to handle many different type of popular office files. I think I'll be using this system for my students in the future. In order not to change my site CSS code I've shrunk the width of the embedded object a bit too much :-( You may use the link on the left bottom side of the image to go to the home page of the document where it will be shown full width.

More on RGB LEDs

I was thinking about controlling multiple color LEDs to make an elaborate panel with different light areas that can be contolled remotely from a laptop. As each LED needs three PWM outputs and many microcontrollers have just a few of them (I mean PWM outputs) the use of a microcontroller per LED makes sense. It did for this project . I've just changed the LED type for a Superflux RGB LED to get what you can see in the video. The next step is to make a version that can be addressed (also available from the same site) so as each LED can be commanded to show a certain color. (One PIC 12F675 plus a Superflux LED cost less than $2!). I'll be using an Arduino board with an XBee wireless module to control a bunch of leds. Alternatively I could use a Wi-port to control the panel via wifi.

Adobe's Lightroom

Image
A friend of mine brought to my attention this great software tool from Adobe. There is a new version 2 on development and I've tried both 1.3 and 2.0 beta. One of the reasons I've bought a Digital SLR camera was to be able to shot in RAW mode. Doing so gives you more choice in terms of development options than shooting JPEG. Lightroom software allows you to give a similar treatment to your photos, no matter your shoot RAW or JPEG. The software main aim is to help you make your good photos great. You may wonder why don't you just use Photoshop or GIMP instead. These other tools are just not designed to help you do that easily. However Lightroom has a simple but yet very powerful interface with an astonishing fast calculation that make it very pleasant to use. You can always easily compare the "Before" and "After" pictures. You can get a trial version from Adobe website so you may try by yourself.

Running circles with Ipod Touch

Image
I've recently bought one iPod Touch 16GB for my wife. A few days later I bought another one for my youngest kid (a clear case of iPod envy). I was quite dissapointed when I've learned that the Touch did not support enterprise WPA nor it does include a VPN client. This renders it useless for any serious network use (so I'm not buying one for me till this is corrected). After the initial excitement my kid was kind of bored with the lack of new applications for his iPod Touch so he asked me to do something about it. I was not eager to get into that fight, but I was told that Ziphone was a safe bet to install an application installer on the iPod Touch so new applications can be installed. They even claimed on their website that even a caveman can do it with Ziphone. So I decided to give it a go.  I dowloaded the application to our iMac and selected Jailbreak. A few messages indicated that files were copied to the Touch and a message told me to wait 1'10''. Nothing ...