Tag Archives: challenge

Small programming challenge No. 6 – nblocks

I came up with this challenge when I had to write a function to divide a sequence to percentiles. I needed this to calculate some statistics over trips for plnnr.com. “This sounds trivial” I thought, and reached for my simple … Continue reading

Posted in Challenges, Programming, Python, Statistics | Tagged , , , , | 21 Comments

Small Programming Challenge no. 5 – Generating a Permutation

I thought of this one quite a long time ago, and I believe that the idea behind it is pretty nice mathematically. I got the idea for it from Knuth’s “The Art of Computer Programming”. The challenge is simple: write … Continue reading

Posted in Challenges, computer science, Programming | Tagged , | 15 Comments

My solution to the counting sets challenge

A few days ago, I wrote up a challenge – to count the number of sets a given set is contained in. In the comments, I touched briefly on the original problem from which the challenge was created, and I’ll … Continue reading

Posted in Challenges, computer science, Python | Tagged , , , | 5 Comments

Small Python Challenge No. 4 – Counting Sets

This is a problem that I encountered a short while ago. It seems like it could be easily solved very efficiently, but it’s not as easy as it looks. Let’s say that we are given N (finite) sets of integers … Continue reading

Posted in Challenges, computer science | Tagged , , | 17 Comments

Some Assembly Required No. 1

I’ve been working on some of the instruction tests in vial, and I wanted to test the implementation of LOOP variants. My objective was to make sure the vial version is identical to the real CPU version (as discussed here). … Continue reading

Posted in Assembly, Challenges, Programming, Testing | Tagged , , , | 2 Comments

Solution for the Random Selection Challenge

A few days ago, I wrote up two small Python Challenges. Several people have presented solutions for the first challenge, and I also posted my solution in the comments there. However, the second challenge remained unsolved, and I will present … Continue reading

Posted in computer science, Math, Programming, Python, Statistics, Utility Functions | Tagged , , , , , , , , | Leave a comment

Small Python Challenge No. 3 – Random Selection

This time I’ll give two related problems, both not too hard. Lets warm up with the first: You have a mapping between items and probabilities. You need to choose each item with its probability. For example, consider the items [‘good’, … Continue reading

Posted in Challenges, Math, Programming, Python | Tagged , , , , , | 12 Comments

Small Python Challenge No. 2 – LRU Cache

Caching is easy. Consider the cache I used to optimize the recursive spring: class _NotInDict(object): pass _NotInDict = _NotInDict() def cached(func): cache = {} def wrapper_func(*args): prev_result = cache.get(args, _NotInDict) if prev_result is _NotInDict: result = func(*args) cache[args] = result … Continue reading

Posted in Algorithms, Challenges, computer science, Programming, Python, Utility Functions | Tagged , , | 2 Comments

A classic programming challenge, in Python

It has become a tradition for computer scientists to create various self referential ‘strange loops’. Traditions such as writing a compiler in the language it compiles are actually quite useful – and also very interesting. This tradition also branched to … Continue reading

Posted in Challenges, computer science, Programming Philosophy, Python | Tagged , , | 6 Comments

Small Python Challenge No. 1

I bet I already wrote that sometime earlier, but I found myself today writing the following function: def blocks(seq, block_len): “”"blocks(range(5),2) -> [[0, 1], [2, 3], [4]]”"” seq_len = len(seq) if seq_len%block_len == 0: num_blocks = seq_len/block_len else: num_blocks = … Continue reading

Posted in Challenges, Programming, Python | Tagged , | 13 Comments