Square Root Algorithms in Lisp/Scheme

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 […]

Solution to Problem 32 on ProjectEuler

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 […]

Factorial Algorithm in Lisp/Scheme

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 […]

CodeChef Problem: Feedback

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 […]

How to Find the Real URL Behind a Redirect in Java

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 […]

How to Search and Find Files on Linux

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 […]