I’m looking for a new job, and one of the companies that interviewed with asked me to do a test on a certification site. I took their certification test, and it took me a bit more than required, but I nailed that. However, I was in my comfort zone, using Perl.
I took the test for the second problem I kind of failed. The problem was to write a function that will calculate the smallest symmetric binary root of a integer within O(sqrt(N)) complexity and O(1) space complexity.
The symmetric binary root of a of a given positive integer N is a positive integer A such that
N = A * bit-rev(A).
bit-rev(A) is an integer obtained by reversing the bits of A.
My initial thinking was that I iterate from 1 to the sqrt(N) and try each solution. Seeing that it fails for some examples, I just iterated to N, to cover all cases, so at least the solution would be complete, never mind the complexity.
Here is what I summited:
1 def bit_rev(N): 2 return int('0b' + bin(N)[:1:-1],2) 3 def symmetric_binary_root_count ( N ): 4 for i in range(N): 5 if (i * bit_rev(i) == N): 6 return i 7 return -1
I did make the most common mistake in a programmers life : offset error. In python range(2) returns [0,1]. But the symmetric binary root of 2 is 2.
The fact that I had to look up how to reverse the bits of a integer in python and the solution involves a string is equally
What’s fun about modern interpreted languages is that you can experiment very easy. Just fire up a console and trow in a few lines and voila you did it ;)read more
I’ve been planing to add a relevant posts list in my sidebar for a while now. But while walking the web, I found up that related links on various sites do not seem to be really relevant.
At first, I was thinking of using the links in the post to extract some of the posts that are relevant, but that would mean that:
So, I decided to go with the most common path that seems to be used, to use tags. However that would present a problem: I have many posts that are tagged with a specific language, and really common tags like programming, basics, etc. so the links would not be really relevant
I decided to posts that are share tags in the order of the least used tag. We will see how it will work ;)read more
Who would want to use it, I don’t know. Especially with the cryptic messages that the compiler gives.
According to Wikipedia ADA was designed by the DOD to replace a large number of languages that were used across many projects. ADA has strong built-in support for concurrent programming.
Have you seen the Carlos Mencia mocking a Asian that says I looove tests. That’s me when I think about programming and programming languages in general. I’ve stumbled upon a site named CodeChef , who posts programming problems and accepts answers in may languages. I decided to solve a few of the questions in all possible ways, maybe I will learn something new.Challenge accepted!
I’m going to start with assembler, I’ve written a series of mini programs for dos, a lot of code for 8051 and 8080/Z80, but I didn’t had a chance to do in Linux. I’ve chosen the most popular problem on CodeChef, Life, the Universe, and Everything .read more
I plan on having tags that are common for most of my posts, and a few tags that will keep togeder a few related articles. Also, I hope I will have a lot to share, so a lot of posts, and a lot of tags that have huge count.
This basicaly means that, common tags will have a huge advantage over uncomon tags.
It ocured to me that a logarithmic scale will solve that issue, rare tags will be bigger, common tags will still be bigger than the small ones, but not by much.
It seems that I wasn’t the only one with that idea, I found this article on Wikipedia while researching for this one.
I decided on a arbitray number of 5 tag sizes. All I needed was a function that will map the tag count to one of the sizes.
I ended up with the following function:
note that this will fail if the max tag count is 1, so the actual formula I used is:
I strongly believe in code readability. I would go so far to recommend that code should not be commented. But that’s another story. I think that code should be in such a way written that even a profane person should be able to understand what is going on.
A while back I had to write a myriad of test cases to test a telecommunication product. Most of the test cases had the same structure with minor differences in the setup.
These differences are hard to spot if you look at a classical bash function that has a few parameters (most of them were creating database entries). On top of that, most of the values were irrelevant for test case, and most of the default values would have been safe.
I had my resume online for quite a while, but never have I spent more than a few minutes to think about how it was formated, just used some “simple” html tables in a static page.
The trouble with tables is that the “simple” stuff is actually sufficiently complicated to write or update. As a result, my resume was most of the time outdated. I decided to solve this, so instead of having a static table to edit, I decided to separate the HTML from the content, and store the content in a YAML file, and use ruby and ERB to generate the updated version of the resume, each time something changed.
Why YAML ? Because it’s pretty easy to maintain and understand, it doesn’t have much overhead so you can easily spell check it (you don’t need to skip over lot’s of keywords).read more
There is a old joke about programmers, real programmers use “copy con program.com” to write programs. Yes, it’s possible see this video.
I don’t really think of it as a joke, for me that’s a reminder that a programmer should always respect the resources he has at his disposal, and implement things with minimum cost.
That’s why this blog is a collection of static files instead of dynamically generated pages by PHP/Python/Perl/Ruby. If you think about it, it makes sense, a blog is a collection of articles. The only truly dynamic part is the comments system, the rest can be easily implemented as static pages. The editing posts/pages is not really necessary for a IT specialist, there is no web application that will mach a good text editor.read more
A while a go I had to run some load tests for a few days in a row. I had to run billions of transactions against a system, and keeping all the transaction parameters stored somewhere wasn’t really a option. Plus, I wanted to be able to see what the current average was while the test was running.read more