Since I started playing around with Lisp (Scheme dialect initially) I have been trying to find the simplest way possible to run my programs directly from the command line. MIT-Scheme allows you to load files with Scheme code, but you need to run it from inside the program, so not very practical. I also tried […]
A reader asked if I could help him with the Square Subsequences problem on HackerRank. Basically you need to generate all subsequences of a given string (i.e., a powerset of the set of chars), count the number of subsequences that are square, and return this count. In the past I have already coded a powerset […]
Below you’ll find the code of a simple server-client program in C using UDP sockets for the transmission. Basically the client sends a message to the server, the server converts the message to uppercase and returns it to the client. If you want to see a simpler program first check this client-server program that only […]
Below you’ll find an example of a client-server application that uses sockets programming in C. Basically the server listens for connection requests, and whatever message the client sends the server converts it to uppercase and sends it back. You could see this as the server providing a service of converting strings to uppercase. The server […]
Below you’ll find an example of a very simple client-server program in C. Basically the client connects to the server, the server sends the message “Hello World”, and the client prints the received message. Keep in mind that I am configuring the settings manually. If you want your code to be IPV4-IPV6 agnostic, IP agnostic […]
I am playing around with Lisp (Scheme dialect in this case), 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 […]
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 […]