<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Lyndon Armitage on Medium]]></title>
        <description><![CDATA[Stories by Lyndon Armitage on Medium]]></description>
        <link>https://medium.com/@lyndon.armitage?source=rss-34873860e551------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*iH15aBDB2-TsKxzXq_xb9w.jpeg</url>
            <title>Stories by Lyndon Armitage on Medium</title>
            <link>https://medium.com/@lyndon.armitage?source=rss-34873860e551------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Tue, 24 Nov 2026 22:42:18 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@lyndon.armitage/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Scala Word wheel solver]]></title>
            <link>https://medium.com/@lyndon.armitage/scala-word-wheel-solver-460744d7b9ab?source=rss-34873860e551------2</link>
            <guid isPermaLink="false">https://medium.com/p/460744d7b9ab</guid>
            <category><![CDATA[scala]]></category>
            <category><![CDATA[word-wheel]]></category>
            <category><![CDATA[puzzle]]></category>
            <category><![CDATA[programming]]></category>
            <dc:creator><![CDATA[Lyndon Armitage]]></dc:creator>
            <pubDate>Thu, 28 Jul 2016 19:22:49 GMT</pubDate>
            <atom:updated>2016-07-28T19:24:53.182Z</atom:updated>
            <content:encoded><![CDATA[<p>A few years ago I created a <a href="http://lyndonarmitage.com/word-wheel-solverhelper/">Word Wheel solver</a> in Java and Android, earlier this year (January) I again decided to create a Word wheel solver but this time in Scala. I tweeted out the result, a program less than 100 lines long, a lot shorter compared to my Java version (it also runs a lot faster) but I thought I’d revisit it in a blog post.</p><h4>Scala</h4><p>First and foremost for those unfamiliar with it; <a href="http://www.scala-lang.org/">Scala</a> is a functional programming language that runs on the Java Virtual Machine.<br> It is incredibly feature rich and allows you to solve some problems much more elegantly than more Object Orientated languages like Java or C++.</p><p>Like Python; Scala features a powerful interpreter that allows you to evaluate code on the fly:</p><pre>Welcome to Scala 2.11.8 (OpenJDK 64-Bit Server VM, Java 1.8.0_92).<br>Type in expressions for evaluation. Or try :help.<br><br>scala&gt; 1 + 1<br>res0: Int = 2<br><br>scala&gt;</pre><p>Which can prove invaluable when testing or exploring data.</p><p>For those interested in Scala I highly recommend the <a href="http://www.scala-lang.org/">Scala language website</a> and for those who are familiar with Java, the <a href="https://www.amazon.co.uk/Learn-Scala-Java-Developers-Weston/dp/1508734178/ref=sr_1_1?ie=UTF8&amp;qid=1469726665&amp;sr=8-1&amp;keywords=scala+for+java">Scala for Java Programmers book</a>.</p><h4>Word Wheel</h4><p>A Word Wheel is a simple puzzle where you try to create as many words as you can from a set of letters, with one (or more) letters having to be in all your words.</p><figure><img alt="A Word Wheel" src="https://cdn-images-1.medium.com/max/327/0*CvvigRXTrwi9qztv.jpg" /><figcaption>This is an example Word Wheel with the required letter of D and optional letters of N,G,A,R,S,E,O, and U</figcaption></figure><p>Normally there is also a word that uses all the letters in the Word Wheel, can you see what it is in the given example?</p><h4>Word Wheel Solver</h4><p>Now that is out-of-the-way onto my Word Wheel Solver.</p><p>The Word Wheel solver has 3 required arguments:</p><ol><li>Required Letter — The letter required to be within any made words</li><li>Optional Letters — The letters surrounding the required letter</li><li>Path to a word list — A file with a word per line</li></ol><p>And a 4th optional argument; the minimum length words can be, by default this is set to 3.</p><p>The first 2 arguments are straight forward when you look at Word Wheel, however for the word list you can use the <a href="https://en.wikipedia.org/wiki/Words_(Unix)">Unix words file</a>, generate your own from text, or download an existing words list.</p><h4>Generating a Word List</h4><p>I normally download an existing word list but generating a word list is relatively easy so I will show how to do that using text files (books) provided by <a href="https://www.gutenberg.org/">Project Gutenberg</a>.</p><p>For this example I have chosen the following books:</p><ul><li><a href="https://www.gutenberg.org/ebooks/1342">Pride and Prejudice</a></li><li><a href="https://www.gutenberg.org/ebooks/98">A Tale of Two Cities</a></li><li><a href="https://www.gutenberg.org/ebooks/1661">The Adventures of Sherlock Holmes</a></li><li><a href="https://www.gutenberg.org/ebooks/76">The Adventures of Huckleberry Finn</a></li><li><a href="https://www.gutenberg.org/ebooks/174">The Picture of Dorian Gray</a></li></ul><p>I downloaded the UTF-8 text versions of these files and placed them in a folder.</p><p>To turn these books into a list of words I wrote the following Scala program (explanation of what it does is below):</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/cc4abfbf2ab8c6d4d868c973c24f43f5/href">https://medium.com/media/cc4abfbf2ab8c6d4d868c973c24f43f5/href</a></iframe><ol><li>This program takes a 1 or more paths to text files as arguments.</li><li>It creates a mutable set to store all words in</li><li>Then it iterates over each file and opens them</li><li>For each line in the file it sanitizes the input: making sure to replace all special characters with a space, and makes everything lower case</li><li>Then for each of these lines it splits the line on spaces and tabs and creates a set of the resulting words</li><li>This words set is then added to the main words set</li><li>Then it opens a file called wordlist.txt and populates it with all the words in the word set</li></ol><p>This produces me a file with almost 20,000 ‘words’. Some of these aren’t really words but I have ignored those for now.</p><h4>The Solver Code</h4><p>Now I have a word list I can run my Word Wheel solver on the example Word Wheel given above using the it.</p><p>Below is the source to the Word Wheel solver:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/527fdf7aa078403f670c0b39ea41879f/href">https://medium.com/media/527fdf7aa078403f670c0b39ea41879f/href</a></iframe><p>The bulk of the work is done within the solve and createWordMap methods.</p><h4>createWordMap Method</h4><p>This method takes the words from the word list and creates a map of letters to corresponding words. For example:</p><p>Imagine our word list consisted of the 2 words: <strong>cat</strong> and <strong>act</strong>.<br> This method would:</p><ol><li>Takes the word <strong>cat</strong></li><li>Orders the letters alphabetically (act)</li><li>Finds the entry in the map for those letters (act), if it fails to find the entry it create a new one mapping the letters (act) to a list of words containing the word <strong>cat</strong></li><li>Next it takes the word <strong>act</strong></li><li>Order the letters alphabetically (act)</li><li>Finds the entry in the map for those letters (act) and adds the word <strong>act</strong> to the list already present</li></ol><p>This data structure allows you to find anagrams of words which will prove useful in the main solve method.</p><h4>solve Method</h4><p>The next line after creating the word map in the solve method does the bulk of the computation in the solve method.<br> It basically generates all possible combinations of the optional letters and required letter.</p><p>The last bit of code in this method than uses the map generated earlier and attempts to match up the generated combinations with the its entries.<br> Any matches are flattened down to a sequence that is then printed to the console in the main method.</p><h4>The Results</h4><p>When run against the example Word Wheel using the generated word list I get the following results:</p><pre>dangerous<br>dangers<br>gardens<br>groaned<br>aground<br>grounds<br>undergo<br>asunder<br>resound<br>aroused<br>ranged<br>garden<br>gander<br>grande<br>danger<br>dragon<br>ground<br>snared<br>around<br>rondes<br>snored<br>nursed<br>rounds<br>guards<br>argued<br>gourds<br>adores<br>soared<br>roused<br>soured<br>grand<br>daren<br>arden<br>doran<br>adorn<br>under<br>round<br>nosed<br>doesn<br>ondes<br>sound<br>drags<br>guard<br>dregs<br>drugs<br>urged<br>gourd<br>reads<br>dares<br>roads<br>adore<br>doers<br>dang<br>dasn<br>sand<br>dane<br>doan<br>dern<br>rend<br>ends<br>dens<br>send<br>nods<br>done<br>undo<br>drag<br>egad<br>aged<br>drug<br>dogs<br>gods<br>doge<br>ards<br>dear<br>read<br>dare<br>road<br>soda<br>rods<br>rode<br>rude<br>does<br>dose<br>used<br>sued<br>dues<br>and<br>dan<br>den<br>ned<br>end<br>nod<br>don<br>dun<br>und<br>god<br>dog<br>dug<br>dar<br>sad<br>ado<br>red<br>rod<br>des<br>ode<br>due</pre><p>Some of these don’t look like real words; this is because the contents of the words list I generated contains some misspellings, slang words and badly formatted text.</p><p>It does however contain the long word using all the letters: “dangerous” along with many other real words that can be found in the word wheel.</p><p>And that concludes this post, feel free to leave any comments on the code provided here.</p><p><em>Originally published at </em><a href="http://lyndonarmitage.com/scala-word-wheel-solver/"><em>Lyndon Armitage</em></a><em>.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=460744d7b9ab" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Programmatically Generating Image Collages]]></title>
            <link>https://medium.com/@lyndon.armitage/programmatically-generating-image-collages-aa23ecb270ae?source=rss-34873860e551------2</link>
            <guid isPermaLink="false">https://medium.com/p/aa23ecb270ae</guid>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[collage]]></category>
            <category><![CDATA[java]]></category>
            <dc:creator><![CDATA[Lyndon Armitage]]></dc:creator>
            <pubDate>Mon, 18 Apr 2016 19:13:18 GMT</pubDate>
            <atom:updated>2016-04-20T21:54:59.522Z</atom:updated>
            <content:encoded><![CDATA[<p><em>Note: Because of how Medium handles links to gists all mentioned data examples are at the bottom of this post.</em></p><p>I created this project over the course of a few days.</p><p>The general idea was to automate the creation of picture collages.</p><h4>The Inspiration</h4><p>Previously a work colleague had created a similar project to show off the power of distributed computing and Hadoop to some curious customers. Unfortunately the colleague has since left and I was not able to have a look at the source to their project so had to start from scratch.</p><p>The actual code I have written, in its current form, doesn’t actually run using Hadoop or any other piece of big data technology as the images and scales I was testing at just about fit within the memory on a single machine.<br> I do however have plans on seeing how hard it is to get this project working with Apache Spark or another big data technology.</p><h4>The Algorithms</h4><p>Creating a collage automatically can be separated into a few distinct tasks:</p><ol><li>Dividing the target image into sections</li><li>Categorizing source images</li><li>Matching the target image sections to source images</li></ol><p>Obviously the last one relies on the first 2 being completed, but both of those steps can be done independently of each other.</p><h4>1. Dividing the target image into sections</h4><p>This is relatively simple.<br> Given a source image like this:</p><figure><img alt="The source image" src="https://cdn-images-1.medium.com/proxy/0*WQ43nnSvWOixHFzp.jpg" /><figcaption>This is a screenshot from the game Metal Gear Solid V: The Phantom Pain. This and many other screenshots from the game will be used as examples.</figcaption></figure><ul><li>Split it up into sections based on the size and aspect ratio of the image.</li><li>Then sample the average colour of this section. This is what we then use for<br> scoring the source images in the 3rd step.</li></ul><p>Visualized this might look something like this:</p><figure><img alt="A visualization of the image" src="https://cdn-images-1.medium.com/proxy/0*CUvSJLhcD5nGtCfX.png" /><figcaption>Note how this is almost the equivalent of blurring or down scaling the image</figcaption></figure><h4>2. Categorizing source images</h4><p>This step is similar to the last one, but instead of taking an image and splitting into sections and getting their average colours it takes whole images and gets their average colours.</p><p>Doing this to many images creates what is essentially a palette to use in the collage.<br> More images are obviously better, and keeping them a consistent size or aspect ratio makes sure they will not be distorted when scaled. For this example I used a set of approximately 800 pictures.</p><p>This step can take quite a while depending on the amount of images being categorized and their dimensions and would be an excellent candidate for parallelizing with something like Spark or a MapReduce job.</p><p>At the bottom of this post are some examples of images turned into their average colours (the full output file is 128KB and about 4000 lines long). The data output by my code also contains some additional parameters such as their dimensions and locations on disk. This allows me to run this step once and reuse the results in step 3 over and over again without having to parse all the source images again.</p><h4>3. Matching the target image sections to source images</h4><p>With steps 1 and 2 done all you have to do is marry their 2 resulting pieces of data together and output an image to disk.</p><p>In this step you take each of the sections of the target image and find the closest matching average colour from the source images.</p><p>Then you decide on how big you want each of the collage images to be, in the example below I set them to be 160px by 90px, this worked well as all the pictures had the same aspect ratio.</p><p>Something to be aware of in this step is how big the resulting collage will be both in terms of dimensions and file size. A really large output may crash the JVM as it will run out memory. To rectify this you can split the output into multiple images that can then be stitched together in another step using an native tool or graphics program like Adobe Photoshop or GIMP.</p><p>In my code I added in the ability to write the output of this step to file so if needed the rendering to an actual image could be done at a later date or by several different machines at once. A snippet of the example data can be seen below (the actual output JSON is about 2.5MB), each section of the image is given an x,y coordinate that maps to the previously shown data format.</p><p>The results of this step end up looking something like this (shrunk to 1920px by 1080px):</p><figure><img alt="The result" src="https://cdn-images-1.medium.com/proxy/0*w9JzuP-YT7zGX0LT.png" /><figcaption>Click the image for a bigger version. But be warned it is about 80MB big and has been run through pngquant. There may also be spoilers in some of the composite images</figcaption></figure><h4>Potential Additions</h4><ul><li>Potentially you could also overlay a transparent copy of the original image on top of the collage to restore some of the lost details</li><li>You could try using different colour models instead of just RGB for matching the colours of the image. <a href="https://en.wikipedia.org/wiki/CMYK_color_model">CMYK</a> for instance</li><li>You could take more information than just a single average colour from the image section. Algorithms for line and shape detection could help produce a match closer to the original section of the image.</li><li>You could come up with a mechanic to reduce the repetition of images, something as naive as removing them from the pool of potential images to use could work although could potentially require a lot more images to use as a palette. Alternatively creating a stack (or ringbuffer) for each image with an average colour close to the search colour.</li><li>Using a video as the source of images instead of still screenshots. This could be achieved through clever use of something like ffmpeg.</li></ul><h4>Source code</h4><p>If desired I can make the source code to the project available online. Currently it is sat in a private BitBucket git repository.<br> Be warned however, as previously mentioned it was hacked together of the course of a few days!</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/24cb7b5aa0af40e03a1cb7171df8be10/href">https://medium.com/media/24cb7b5aa0af40e03a1cb7171df8be10/href</a></iframe><p><em>Originally published at </em><a href="http://lyndonarmitage.com/programmatically-generating-image-collages/"><em>Lyndon Armitage</em></a><em>.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=aa23ecb270ae" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>