I am playing around with Lisp, so I decided to write some square root algorithms. Here’s the first naive version I wrote. As you can see it only works with perfect squares (the first argument should always be 1, as it starts looking with it; the second argument is the number you want to find […]
I am reading the SICP (Structure and Interpretation of Computer Programs) book right now, and I am impressed with the elegance and clarity in which the authors explain most concepts.
I found this picture on Reddit. What’s the right answer? What if instead of 60% choice C was 0%?
The problem: We shall say that an n-digit number is pandigital if it makes use of all the digits 1 to n exactly once; for example, the 5-digit number, 15234, is 1 through 5 pandigital. The product 7254 is unusual, as the identity, 39 × 186 = 7254, containing multiplicand, multiplier, and product is 1 […]
Below you’ll find a recursive and an iterative version of the Factorial algorithm in Lisp/Scheme, based on the book Structure and Interpretation of Computer Programs (SICP). Recursive (define (factorial n) (if (= n 1) 1 (* n (factorial (- n 1) )) )) (display (factorial 7)) Iterative (define (factorial n) (define (iter product counter) (if […]
Lots of geeky customers visit our chef’s restaurant everyday. So, when asked to fill the feedback form, these customers represent the feedback using a binary string (i.e a string that contains only characters ’0′ and ’1′. Now since chef is not that great in deciphering binary strings, he has decided the following criteria to classify […]
The problem: In England the currency is made up of pound, £, and pence, p, and there are eight coins in general circulation: 1p, 2p, 5p, 10p, 20p, 50p, £1 (100p) and £2 (200p). It is possible to make £2 in the following way: 1×£1 + 1×50p + 2×20p + 1×5p + 1×2p + 3×1p […]
Say you have a URL that redirects to another (e.g., bit.ly). How do you find the real URL behind the redirect? You can do this in Java using the HttpURLConnection class. Like this: String url = "http://bit.ly/23414"; HttpURLConnection con = (HttpURLConnection) new URL(url).openConnection(); con.setInstanceFollowRedirects(false); con.connect(); String realURL = con.getHeaderField(3).toString(); You basically create a connection, disable […]
If you use an IDE like Eclipse to develop your Java programs then using external libraries is pretty straight forward. You just need to add the JAR file to your project and then right click on it and add it to the build path, and the IDE will do the rest of the work for […]
As a Linux user you’ll inevitable need to search around for a specific file once in a while, be it a configuration file you need to edit or a version of a document you somehow lost. There are three basic ways to search for files using the command line: 1. locate The locate command is […]