Finding all possible combinations of numbers to reach a given sum

This problem can be solved with a recursive combinations of all possible sums filtering out those that reach the target. Here is the algorithm in Python: This type of algorithms are very well explained in the following Stanford’s Abstract Programming lecture – this video is very recommendable to understand how recursion works to generate permutations of solutions. … Read more

What is the best regular expression to check if a string is a valid URL?

I wrote my URL (actually IRI, internationalized) pattern to comply with RFC 3987 (http://www.faqs.org/rfcs/rfc3987.html). These are in PCRE syntax. For absolute IRIs (internationalized): To also allow relative IRIs: How they were compiled (in PHP): Edit 7 March 2011: Because of the way PHP handles backslashes in quoted strings, these are unusable by default. You’ll need … Read more

Create your own MD5 collisions

These following two different 128 byte sequences hash to the same: MD5 Hash: 79054025255fb1a26e4bc422aef54eb4 The differences below are highlighted (bold). Sorry it’s kind of hard to see. d131dd02c5e6eec4693d9a0698aff95c 2fcab58712467eab4004583eb8fb7f89 55ad340609f4b30283e488832571415a 085125e8f7cdc99fd91dbdf280373c5b d8823e3156348f5bae6dacd436c919c6 dd53e2b487da03fd02396306d248cda0 e99f33420f577ee8ce54b67080a80d1e c69821bcb6a8839396f9652b6ff72a70 and d131dd02c5e6eec4693d9a0698aff95c 2fcab50712467eab4004583eb8fb7f89 55ad340609f4b30283e4888325f1415a 085125e8f7cdc99fd91dbd7280373c5b d8823e3156348f5bae6dacd436c919c6 dd53e23487da03fd02396306d248cda0 e99f33420f577ee8ce54b67080280d1e c69821bcb6a8839396f965ab6ff72a70 The visualization of the collision/block1 (Source: Links.Org) The visualization of the … Read more

What is a coroutine?

Coroutines and concurrency are largely orthogonal. Coroutines are a general control structure whereby flow control is cooperatively passed between two different routines without returning. The ‘yield’ statement in Python is a good example. It creates a coroutine. When the ‘yield ‘ is encountered the current state of the function is saved and control is returned … Read more