## Posts

Showing posts from August, 2015

### Finding similar images

In this post we're going to implement a simple algorithm which finds images that look similar to each other. # Overview In order to find images that look similar, we first need to normalize them to a simpler form and compute a fingerprint for each image. The fingerprint is a binary sequence of ones and zeros and it's created from the average color of the image and the average color of each pixel. In order to make the process faster and more flexible (and also to have fingerprints of the same length) the image is first resized to a fixed resolution, which defaults to 64x64. # Algorithm This is the algorithm which creates the fingerprint of an image: averages = [ ] for y in range ( height ) { for x in range ( width ) { rgb = img . get_pixel ( x , y ) averages . append ( sum ( rgb ) / len ( rgb ) ) } } avg = sum ( averages ) / len ( averages ) fingerprint = averages . map { | v | v < avg ? 1 : 0 } It

### Creating a programming language

In this post we're going to look over the main things required in designing and implementing a programming language. # Overview Before writing any code and before designing any language construct, we need to think about the core of the language that we want to create. The core of the language is the most important part which defines the language itself. We also have to choose a  programming paradigm  for our language from the following list: imperative declarative functional object-oriented procedural logic symbolic A language can have more than one paradigm. For example, it can be imperative and object-oriented at the same time. These are called multi-paradigm languages. After these two criteria are met, we can start thinking about a syntax for our language and begin carefully to design language constructs and implement them. In order to implement our programming language, we need to write a parser which creates an abstract syntax tree (AST) from our s