Skip to content

Commit

Permalink
convert img html to md images and add gist
Browse files Browse the repository at this point in the history
  • Loading branch information
alexmic committed Oct 6, 2013
1 parent cfe019f commit 6ae953c
Show file tree
Hide file tree
Showing 4 changed files with 61 additions and 10 deletions.
2 changes: 2 additions & 0 deletions Gemfile
@@ -0,0 +1,2 @@
source 'https://rubygems.org'
gem 'github-pages'
49 changes: 49 additions & 0 deletions Gemfile.lock
@@ -0,0 +1,49 @@
GEM
remote: https://rubygems.org/
specs:
RedCloth (4.2.9)
classifier (1.3.3)
fast-stemmer (>= 1.0.0)
colorator (0.1)
commander (4.1.5)
highline (~> 1.6.11)
directory_watcher (1.4.1)
fast-stemmer (1.0.2)
github-pages (6)
RedCloth (= 4.2.9)
jekyll (= 1.2.1)
kramdown (= 1.0.2)
liquid (= 2.5.2)
maruku (= 0.6.1)
rdiscount (= 1.6.8)
redcarpet (= 2.3.0)
highline (1.6.19)
jekyll (1.2.1)
classifier (~> 1.3)
colorator (~> 0.1)
commander (~> 4.1.3)
directory_watcher (~> 1.4.1)
liquid (~> 2.5.2)
maruku (~> 0.5)
pygments.rb (~> 0.5.0)
redcarpet (~> 2.3.0)
safe_yaml (~> 0.7.0)
kramdown (1.0.2)
liquid (2.5.2)
maruku (0.6.1)
syntax (>= 1.0.0)
posix-spawn (0.3.6)
pygments.rb (0.5.2)
posix-spawn (~> 0.3.6)
yajl-ruby (~> 1.1.0)
rdiscount (1.6.8)
redcarpet (2.3.0)
safe_yaml (0.7.1)
syntax (1.0.0)
yajl-ruby (1.1.0)

PLATFORMS
ruby

DEPENDENCIES
github-pages
8 changes: 4 additions & 4 deletions _config.yml
@@ -1,4 +1,4 @@
server: true
auto: true
permalink: /:title/
pygments: true
safe: true
lsi: false
pygments: true
permalink: /:title/
12 changes: 6 additions & 6 deletions _posts/2013-11-05-password-derivation-project-euler.md
Expand Up @@ -5,15 +5,15 @@ tldr: "A solution to problem #79 using simple graph theory and breath-first sear
published: true
---

<a href="http://projecteuler.net/problem=79">Problem 79</a> is an interesting problem which actually uncovers how easy it is for someone to recover the passcode of a user using a keylogger.
[Problem 79](http://projecteuler.net/problem=79) is an interesting problem which actually uncovers how easy it is for someone to recover the passcode of a user using a keylogger.

The problem is phrased as follows:

> A common security method used for online banking is to ask the user for three
> random characters from a passcode. For example, if the passcode was 531278,
> they may ask for the 2nd, 3rd, and 5th characters; the expected reply would be: 317.
>
> The text file, <a href="http://projecteuler.net/project/keylog.txt">keylog.txt</a>, contains fifty successful login attempts.
> The text file, [keylog.txt](http://projecteuler.net/project/keylog.txt), contains fifty successful login attempts.
>
> Given that the three characters are always asked for in order, analyse the
> file so as to determine the shortest possible secret passcode of unknown > length.
Expand Down Expand Up @@ -66,9 +66,9 @@ The last bit of the puzzle is to traverse this graph and find the shortest path

### Breadth-first searching

Breadth-first search is a method of traversing a graph by visiting the nodes in "breadth" than in "depth". That means, the algorithm traverses all the nodes of level N and then moves to the nodes of level N + 1. Typical implementations use a FIFO queue. Below is an animated image of the algorithm traversing a tree (source: <a href="http://en.wikipedia.org/wiki/Breadth-first_search">Wikipedia</a>).
Breadth-first search is a method of traversing a graph by visiting the nodes in "breadth" than in "depth". That means, the algorithm traverses all the nodes of level N and then moves to the nodes of level N + 1. Typical implementations use a FIFO queue. Below is an animated image from [Wikipedia](http://en.wikipedia.org/wiki/Breadth-first_search) showing the algorithm traversing a tree.

<img class="centered" src="http://upload.wikimedia.org/wikipedia/commons/4/46/Animated_BFS.gif"/>
![BFS](http://upload.wikimedia.org/wikipedia/commons/4/46/Animated_BFS.gif)

Our implementation follows a similar pattern and stops at the first match i.e returns the first path where the set difference with the number universe is empty:

Expand All @@ -87,7 +87,7 @@ def find_smallest_code(start, graph, number_universe):
{% endraw %}
{% endhighlight %}

We now need to put everything together. Since we don't know a-priori which letter the passcode starts with, we need to run a search from each vertex and collect the results in a candidate list. The shortest code in that list is the answer:
We now need to put everything together. Since we don't know a priori which letter the passcode starts with, we need to run a search from each vertex and collect the results in a candidate list. The shortest code in that list is the answer:

{% highlight python linenos=table %}
{% raw %}
Expand All @@ -102,4 +102,4 @@ def solve(keylog):
{% endraw %}
{% endhighlight %}

Running the code on keylog.txt returns **73162890** which succesfully solves the problem on Project Euler.
Running the code on keylog.txt returns **73162890** which succesfully solves the problem on Project Euler. You can find the full code in this <a href="https://gist.github.com/alexmic/6846774">gist.</a>

0 comments on commit 6ae953c

Please sign in to comment.