Thoughts on architecture components and software stability. In this article we also discuss one approach to evaluating architecture quality. Software Architecture is about drawing boxes and arrows. – Some architect Architecture Quality Challenge Evaluating software architecture is difficult. Unlike performance or test coverage, architecture lacks clear, objective metrics. Most assessments rely on…
Emacs is great for editing text, IntelliJ IDEA is great for navigation. Let’s take best from both worlds into one editor. Rationale If you can configure it, you will configure it - Anonymous, about Linux Emacs is keyboard-driven editor, meaning all actions you can do without mouse or touchpad. It is a good part. The bad part is it lacks rich navigation capabilities, integration with external…
Evolville is an imaginary computer world, inhabited by creatures. They live, move, eat, communicate and evolve. In previous post we’ve seen the origins of the World. It looks pretty simple: white space inhabited by some creatures. All those creatures just moving in random directions causing world look like boiling soup. Even it seems that some creatures exist, there is no life yet. God of Setup…
Evolville is an imaginary computer world, inhabited by creatures. They live, move, eat, communicate and evolve. This is going to be series of posts for simulation, starting from scratch and test various evolution strategies. Our world will evolve, our creatures will evolve, our code will evolve. Welcome to Evolville! The Beginning At the beginning there was nothing. No big boom, no hydrogen, no…
Implementing Depth-First Search for the Binary Tree without stack and recursion. Binary Tree Array This is binary tree. 0 is a root node. 0 has two children: left 1 and right: 2 . Each of its children have their children and so on. The nodes without children are leaf nodes ( 3 , 4 , 5 , 6 ). The number of edges between root and leaf nodes define tree height . The tree above has the height 2 .…
Find the value of d < 1000 for which 1/d contains the longest recurring cycle in its decimal fraction part. Permalink: https://projecteuler.net/problem=26 1/2 = 0.5 1/3 = 0.(3) 1/4 = 0.25 1/5 = 0.2 1/6 = 0.1(6) 1/7 = 0.(142857) 1/8 = 0.125 1/9 = 0.(1) 1/10 = 0.1 As you see for d from 2 to 10 , the longest cycle length is 6 , for d=7 . Let’s start with a function, which finds the cycle length for…
Let’s celebrate geeky New Year by drawing New Year Tree using Clojure! Problem Write a program which prints New Year Tree to console. Source code should take as small number of characters as possible. I came up with the following tree rules: Star. There is should be a star on top of the tree. Triangles. Tree body is a set of triangle levels. Let the number of levels will be an input argument to…
Quick overview of the classic Design Patterns in Clojure Disclaimer: Most patterns are easy to implement because we use dynamic typing, functional programming and, of course, Clojure. Some of them look wrong and ugly. It’s okay. All characters are fake, coincidences are accidental. Index Intro Episode 1. Command Episode 2. Strategy Episode 3. State Episode 4. Visitor Episode 5. Template Method…
Cook, little pot, cook! – The Magic Porridge Pot, Brothers Grimm I’ve just released littlepot , tiny library devoted to transform batched request into single element request. The Problem Imagine you develop a service which return one random image and some witty text below. As an image provider, you have chosen some http://image.provider.com , because they have a free limited API. Their endpoint…
Apache Spark is a fast and general engine for large-scale data processing. 100 times faster than Hadoop. Everyone knows SQL. But traditional databases are not good in hadling big amount of data . Nevertheless, SQL is a good DSL for data processing and it is much easier to understand Spark if you have similar query implemented in SQL. This article shows how common SQL queries implemented in Spark.…
Emacs org-mode use cases, for non-programmers. org-mode Org-mode is what makes emacs popular among non-programmers community. It could replace your Notes, TODO, Calendar, Agenda, Project Management, Time Tracking, Spreadsheets and other apps. But seems like most of org-mode tutorials are dedicated to hardcore emacs users, these tutorials are hard to follow as they are exposing all-the-power of…
Let’s celebrate Pi day in clojure! Tweet Exactly 140 characters to print 9 digits of $\pi$ ( 3.141592654 ) ( let [ r reduce N ( rest ( range )) t take ]( clojure.pprint/cl-format nil "~11f" ( r + ' -2 ( map # ( / ( r * ' 2 ( t % N ))( r * ' ( t % ( take-nth 2 N ))))( t 99 N ))) 9 )) “Sugared” version There are two parts of a problem: Calculate rational for $\pi$ using arctangent approximation…
Pouring a bit light on SecurityManager and its use cases. Intro You can do a terrible things in java using sun.misc.Unsafe class. Some really creepy examples were discussed in Java Magic. Part 5: sun.misc.Unsafe SecurityManager is a guard, which could help to prevent some sensitive actions (io, net, reflection, access etc.) SecurityManager manager = System . getSecurityManager (); if ( manager !=…
Clojure Cup 2014 has finished and we’ve build clojure app in two days! We are proud to announce funstructor ( pre-alpha ) Funstructor Funstructor is a turn-based multiplayer card game for clojurists. Your goal is to make some clojure code snippet, function or expression, but instead of typing characters you must use cards. Every card has unique behaviour and I suggest actually play game, instead…
What is the first term in the Fibonacci sequence to contain 1000 digits? Permalink: https://projecteuler.net/problem=25 We’ve introduced Fibonacci sequence at Clojure Euler: Problem 002 Lazy sequence generates fibonacci numbers is dead simple: ( defn fibonacci [] ( ->> [ 0 1 ] ( iterate ( fn [[ a b ]] [ b ( + ' a b )])) ( map first ))) We also can count the length of number in digits. No decimal…
A permutation is an ordered arrangement of objects. For example, 3124 is one possible permutation of the digits 1, 2, 3 and 4. If all of the permutations are listed numerically or alphabetically, we call it lexicographic order. The lexicographic permutations of 0, 1 and 2 are: 012 021 102 120 201 210 What is the millionth lexicographic permutation of the digits 0, 1, 2, 3, 4, 5, 6, 7, 8 and 9?…
Recently, I’ve re-read awesome java book Effective Java by Joshua Bloch. The book contains 78 independent items, discussing various aspects of programming in java. Something like mini-design patterns with emphasis on their pros and cons. Few notes from each item as a refresher. Item 1: Consider static factory methods instead of constructors Static factory methods have more informative names than…
Programming Sucks. 1. Programming Sucks …many of the programs you depend on are written by dicks and idiots Funny ranting about crazy programming life. Every programmer occasionally, when nobody’s home, turns off the lights, pours a glass of scotch, puts on some light German electronica, and opens up a file on their computer…This file is Good Code. 2. Functional Programming For The Rest Of Us…
Clojure is a great language, and as every language, it has some unobvious and strange things, which seem confusing. Some of such things are gathered here. Most of them encountered by stupidity, docs misunderstanding, clojure specifics and procrastination. 1. Anybody home? ( contains? [ 10 20 30 ] 20 ) => false Surprised? The issue here is contains? function checks if key (not a value!) is present…
Find the sum of all the positive integers which cannot be written as the sum of two abundant numbers. Permalink: http://projecteuler.net/problem=23 To define abundant number let’s revisit sum-of-proper-divisors from the Clojure Euler: Problem 021 ( defn sum-of-proper-divisors [ n ] ( let [ base ( filter # ( zero? ( mod n % )) ( range 2 ( Math/sqrt n )))] ( reduce + 1 ( concat ( map # ( / n % )…
Numberto has new features! In previous post I wrote about simple clojure library numberto for experiments with numbers. New version of numberto has a bunch of new features. Expressions Expressions package provides two functions: eval-infix to evaluate infix expression and infix->prefix to build prefix lisp-style expression from mathematical notation. Let’s give it alias for simplicity ( def e…
How to live in the Kingdom of Nouns, why mathematicians cry, filling gaps in algorithms, portion of clojure, STM, HTTP and more. 1. Execution in the Kingdom of Nouns Another great Steve Yegge’s post. Not a post, a tale about Javaland , a place where all verbs are owned by nouns. Accept it like an analogy between OOP and FP. Verbs in Javaland are responsible for all the work, but as they are held…
Using names.txt a 46K text file containing over five-thousand first names, begin by sorting it into alphabetical order. Then working out the alphabetical value for each name, multiply this value by its alphabetical position in the list to obtain a name score. For example, when the list is sorted into alphabetical order, COLIN, which is worth 3 + 15 + 12 + 9 + 14 = 53, is the 938th name in the…
Evaluate the sum of all the amicable numbers under 10000. Permalink: http://projecteuler.net/problem=21 Let d(n) be defined as the sum of proper divisors of n (numbers less than n which divide evenly into n). If d(a) = b and d(b) = a, where a != b, then a and b are an amicable pair and each of a and b are called amicable numbers. For example, the proper divisors of 220 are 1, 2, 4, 5, 10, 11, 20,…
All you need to play with numbers! numberto simple clojure library with a bunch of functions operating on numbers. I created this project for two reasons: Solving problems on Project Euler , 4Clojure and just playground with numbers needed common functions. I just extracted them to separate util library. Practice to develop clojure project with unit tests, continuos integration, documentation and…
Brainfuck Interpreter in two tweets. Previous article Code Golf: Game of Life raised some interest, and I decided to proceed. Today’s problem is a Brainfuck Interpreter. Brainfuck is an esoteric programming language, famous because of its small command set. It is based on array of cells (Turing Tape) and pointer to this array. There are only 8 commands: > move to the next cell < move to the…
Why your software sucks and what is the “Secret Weapon”. Also, algorithm complexities refresher, functional programming, including Scala and Clojure, concurrency and lot of humor. 1. Big Ball of Mud What does your programming day look like? The article describes problems in software design and explains why almost every system nowadays look like “Big Ball of Mud”. There are seven real patterns in…
Find the sum of the digits in the number 100! Permalink: http://projecteuler.net/problem=20 First of all we need to calculate factorial. Without integer overflows, stack overflows and other caveats. Previous article Fast Factorial has working solution that we might use. (defn ! [n] (reduce *' (range 1 (inc n)))) Now, calculate the sum of digits, the same function that we used in Clojure Euler:…
How many Sundays fell on the first of the month during the twentieth century (1 Jan 1901 to 31 Dec 2000)? Permalink: http://projecteuler.net/problem=19 Project Euler also gives following information: 1 Jan 1900 was a Monday. A poem Thirty days has September, April, June and November. All the rest have thirty-one, Saving February alone, Which has twenty-eight, rain or shine. And on leap years,…
randomorg-0.1 released! If you use random numbers in your software you might be interested in better numbers distribution than Random.nextInt() . Someone solves this problem with hardware generators, few entropy sources and even books . By the way, there is great service random.org which allows to generate random numbers via atmospheric noise. randomorg is a small java library for random.org API.…
Factorial function is simple enough. But there is still some fun about it. In Stirling’s Approximation article we’ve seen how to calculate good factorial approximation faster than exact value. By the way, there is an algorithm to calculate exact value of factorial faster than “by definition”. Factorials Most of programming languages tutorials shows the following approach to calculate factorial (…
By starting at the top of the triangle below and moving to adjacent numbers on the row below, the maximum total from top to bottom is 23. 3 7 4 2 4 6 8 5 9 3 That is, 3 + 7 + 4 + 9 = 23. Find the maximum total from top to bottom of the triangle below: [Check out big triangle in original link] NOTE: As there are only 16384 routes, it is possible to solve this problem by trying every route. However,…
Why math is needed for developers, what is REST, how to become experienced developer…in 10 years, “coding it’s just writing” and some practice: Naive Bayes Classifier, functional programming and Java 8. 1. Math For Programmers Another great post by Steve Yegge about math. Math for developers. As everyone might to retort, knowing math is not mandatory for software engineering field, but you know:…
If the numbers 1 to 5 are written out in words: one, two, three, four, five, then there are 3 + 3 + 5 + 4 + 4 = 19 letters used in total. If all the numbers from 1 to 1000 (one thousand) inclusive were written out in words, how many letters would be used? Permalink: http://projecteuler.net/problem=17 To solve this problem we need some sort of mapping that defines association between number and its…
Conway’s Game of Life in a tweet. Recently, my friend pointed out me an article Life in a tweet where Game of Life was implemented in one tweet ( less than 140 characters ) in Ruby and F#. I took this challenge. Tweet Here is the final version in 137 characters of Clojure: ( fn [ g r ]( reduce ( fn [ i j ]( update-in i j ( fn [ v ]( get [ v 1 ] ( - ( apply + ( map # ( get-in g% 0 )( for [ a [ -1 0…
2^15 = 32768 and the sum of its digits is 3 + 2 + 7 + 6 + 8 = 26. What is the sum of the digits of the number 2^1000 ? Permalink: http://projecteuler.net/problem=16 Are you kidding me? Find 1000th power of two Sum its digits In Clojure Euler: Problem 008 we learned how to sum digits in the number. Just gentle reminder: ( defn sum-of-digits [ n ] ( reduce + ( map # ( - ( int % ) 48 ) ( seq ( str n…
Java is a safe programming language and prevents programmer from doing a lot of stupid mistakes, most of which based on memory management. But, there is a way to do such mistakes intentionally, using Unsafe class. This article is a quick overview of sun.misc.Unsafe public API and few interesting cases of its usage. Unsafe instantiation Before usage, we need to create instance of Unsafe object.…
Have you heard about Elephant-Oriented Programming? 1. Read very clever book with an elephant on cover. 2. I bet you didn’t understand anything, so choose easy programming language with an elephant . 3. What is IDE? We already have elephant text editor . 4. For real life programming tasks we need storage. PostgreSQL database is good. Because of elephant . 5. And finally, fancy word Big Data . Did…
Do you like factorials? Probably, you do. If no, whatever, read this post to know how get rid of factorials. TL;DR \[ln(n!) = n \cdot ln(n) - n + 1\] It is Stirling’s approximation or just Stirling’s formula. It allows to replace factorials with their approximation. If you not interested in math, skip to formula usage Proof Replace factorial with its definition: \[ln(n!) = ln(1 \cdot 2 \cdot 3…
It is so obvious, so I decided to write about it. Heisenberg principle came from quantum mechanics and means that you can’t know exactly both coordinates and speed of particle. If you improve accuracy of detecting position, you lose accuracy in detecting speed and vice versa. Uncertain stuff. In human-readable form it sounds like Either one or the other The same in every field, even in software…
Starting in the top left corner of a 2 x 2 grid, there are 6 routes (without backtracking) to the bottom right corner. How many routes are there through a 20 x 20 grid? Permalink: http://projecteuler.net/problem=15 Picture is always a huge help to find correct the solution. Let’s see the pattern here, with another picture Warning: If you don’t understand art, don’t look at that picture. It’s a…
Last weekend I was hacking Standard ML a bit. Coursera There are excellent course on coursera called Programming Languages Currently, the first half is available, that explains basic and advanced functional programming constructions with Standard ML as primary language. Later some idioms will be presented using Racket and Ruby ( maybe, I will finally understand ruby ) so you can treat this course…
Which starting number, under one million, produces the longest Collatz chain? Permalink: http://projecteuler.net/problem=14 The following iterative sequence is defined for the set of positive integers: n → n/2 (n is even) n → 3n + 1 (n is odd) Using the rule above and starting with 13, we generate the following sequence: 13 → 40 → 20 → 10 → 5 → 16 → 8 → 4 → 2 → 1 It can be seen that this sequence…
How to get job at Google, estimate complexity of your algorithm, what is Structural Immutability , why PHP is awful and Java is awesome, best programming jokes and lot more. 1. Get that job at Google …it’s highly likely that someone on the loop will be unimpressed with you, even if you are Alan Turing. Especially if you’re Alan Turing, in fact, since it means you obviously don’t know C++ The quote…
Recently, I come up with idea to share my favorite articles I found on the internet and give basic description for them. I do not plan this digest as periodical thing, so the first pattern I found appropriate is to publish this as soon as I have ten articles marked as favorite somewhere. That’s the rule: each post - 10 articles . Favorite means really favorite , so I do not crosspost every article…
What programming language is most used? To answer this question we use results from the qualification round of Facebook Hacker Cup 2013 If you only interested in statistics, skip! 0. Intro As you may know, Facebook Hacker Cup is a programming contest. You have programming problem and you need to solve it, in most cases in efficient way. You get input file and you need to submit the output file in…
Work out the first ten digits of the sum of the following one-hundred 50-digit numbers. Permalink: http://projecteuler.net/problem=13 Assume, here is a huge amount of digits. In any case, you can always find them in permalink. What is the problem to sum one-hundred numbers? ( reduce + numbers ) Done. Are you kidding me? Not so fast. The question is what type of number you must choose to sum all…
What is the value of the first triangle number to have over five hundred divisors? Permalink: http://projecteuler.net/problem=12 The sequence of triangle numbers is generated by adding the natural numbers. So the 7th triangle number would be 1 + 2 + 3 + 4 + 5 + 6 + 7 = 28. The first ten terms would be: 1, 3, 6, 10, 15, 21, 28, 36, 45, 55, … Let us list the factors of the first seven triangle…
Little journey through the history of most critical software bugs with some code examples. Do not try to reproduce any of these! Intro Every last bug is the last but one. Bugs are bad. Some of them cause uncomfortable work, more actions than expected, inconsistency, layout issues, etc. Some of them “ not a bug ” at all. Bad bugs much worse. They cause data corruption, invalid data representation,…
What is the greatest product of four adjacent numbers in the same direction (up, down, left, right, or diagonally) in the 20 x 20 grid? Permalink: http://projecteuler.net/problem=11 In the 20 x 20 grid below, four numbers along a diagonal line have been enclosed into square brackets 08 02 22 97 38 15 00 40 00 75 04 05 07 78 52 12 50 77 91 08 49 49 99 40 17 81 18 57 60 87 17 40 98 43 69 48 04 56 62…