<?xml version='1.0' encoding='UTF-8'?><rss xmlns:atom="http://www.w3.org/2005/Atom" xmlns:openSearch="http://a9.com/-/spec/opensearchrss/1.0/" xmlns:blogger="http://schemas.google.com/blogger/2008" xmlns:georss="http://www.georss.org/georss" xmlns:gd="http://schemas.google.com/g/2005" xmlns:thr="http://purl.org/syndication/thread/1.0" version="2.0"><channel><atom:id>tag:blogger.com,1999:blog-6893032696317132921</atom:id><lastBuildDate>Sat, 14 Mar 2026 00:33:10 +0000</lastBuildDate><category>Scala</category><category>code</category><category>functional programming</category><category>programming</category><category>software engineering</category><category>process</category><category>J2EE</category><category>Java</category><category>OO</category><category>JSF</category><category>frameworks</category><category>project management</category><category>RUP</category><category>architecture</category><category>quotes</category><category>refactoring</category><category>OOAD</category><category>certifications</category><category>risk</category><category>ruby</category><category>DDD</category><category>DSL</category><category>Haskell</category><category>IASA</category><category>SCEA</category><category>exercises</category><category>humor</category><category>optimization</category><category>pathfinding</category><category>FluentInterfaces</category><category>ICFP</category><category>JavaScript</category><category>Microsoft</category><category>OOPSLA</category><category>Types</category><category>UI</category><category>UML</category><category>adictions</category><category>coffee</category><category>creativity</category><category>currying</category><category>lego</category><category>patterns</category><category>podcasts</category><category>scala haskell functor monads</category><category>scala haskell functor monads java</category><category>security</category><title>Gabriel&#39;s software development blog</title><description>Software surgery, programming, architecture, process, development, design, and more...</description><link>http://gabrielsw.blogspot.com/</link><managingEditor>noreply@blogger.com (Anonymous)</managingEditor><generator>Blogger</generator><openSearch:totalResults>52</openSearch:totalResults><openSearch:startIndex>1</openSearch:startIndex><openSearch:itemsPerPage>20</openSearch:itemsPerPage><item><guid isPermaLink="false">tag:blogger.com,1999:blog-6893032696317132921.post-2743624591467418380</guid><pubDate>Sun, 09 Sep 2012 03:15:00 +0000</pubDate><atom:updated>2012-09-11T11:21:53.954-04:00</atom:updated><category domain="http://www.blogger.com/atom/ns#">Java</category><category domain="http://www.blogger.com/atom/ns#">Scala</category><category domain="http://www.blogger.com/atom/ns#">Types</category><title>Phantom types in Java</title><description>&lt;span style=&quot;font-size: large;&quot;&gt;Introduction&lt;/span&gt;&lt;br /&gt;
One of the things that I like about types in programming languages is that they&#39;re there to help you (although sometimes feels the opposite). The more things you can check at compile time, the less you need to do during tests (if you need to do it at all!).&lt;br /&gt;
&lt;div&gt;
One of those techniques are Phantom Types, and although well known in advanced languages (Haskell, Scala, OCaml, etc.) it seems to be relativelly unknown in Java despite the fact it can be perfectly used&lt;review&gt;.&lt;/review&gt;&lt;br /&gt;
&lt;br /&gt;
Since Java 1.5, we have&amp;nbsp;parametric types (generics).&amp;nbsp;Once you have that, you can add types parameters to other types...&lt;br /&gt;
&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;public class MyTpye &amp;lt;TypeParameter&amp;gt; { ....&amp;nbsp;&lt;/span&gt;&lt;/div&gt;
&lt;br /&gt;
you can have methods with generic parameters&lt;br /&gt;
&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;public&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;&amp;lt;T&amp;gt;&amp;nbsp;&lt;/span&gt;&lt;t style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;Result doSomething( MyType&lt;/t&gt;&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;&amp;lt;T&amp;gt;&amp;nbsp;p){&amp;nbsp;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;.... do something with p ...&amp;nbsp;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;}&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
or require specific type parameters on your methods (called a &lt;i&gt;generic type invocation&lt;/i&gt; ). &lt;br /&gt;
&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;public Result doSomethingStringy( MyType&amp;lt;String&amp;gt;&amp;nbsp;&amp;nbsp;p){&amp;nbsp;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;.... do something with p ...&amp;nbsp;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;}&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;span style=&quot;font-size: large;&quot;&gt;A ghost in the (type) machine
&lt;/span&gt;&lt;br /&gt;
So, what are phantom types?.&amp;nbsp;Now, normally when you require a specific type in the parameter you use it in the method body (say, when you have&amp;nbsp;&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;sum(&lt;/span&gt;&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;List&amp;lt;Integer&amp;gt; xs)&amp;nbsp;&lt;/span&gt;you&#39;ll use the fact that you have a list of Integers to sum them)&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp;&lt;/span&gt;, but what happen if you don&#39;t? Now you have a parameter type that never appears in the body, although is there, requiring that specific parameter in the type and preventing compilation if doesn&#39;t match. That&#39;s a phantom type :)&lt;br /&gt;
&lt;br /&gt;
&lt;span style=&quot;font-size: large;&quot;&gt;A simple example&lt;/span&gt;&lt;br /&gt;
Here an example: let&#39;s model a plane that can be either flying or landed and a takeOff and land methods that can only be applied to landed and flying planes respectively.&lt;br /&gt;
First, let&#39;s define the different flight status as marker interfaces:&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;script src=&quot;https://gist.github.com/2919649.js?file=FlightStatus.java&quot;&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;public interface FlightStatus {&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;}&lt;/span&gt;
&lt;/script&gt;

&lt;br /&gt;
&lt;script src=&quot;https://gist.github.com/2919649.js?file=Flying.java&quot;&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;public interface Flying extends FlightStatus{&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;}&lt;/span&gt;
&lt;/script&gt;

&lt;br /&gt;
&lt;script src=&quot;https://gist.github.com/2919649.js?file=Landed.java&quot;&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;public interface Landed extends FlightStatus {&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;}&lt;/span&gt;
&lt;/script&gt;

Now, our plane class parametrized by the flight status:&lt;br /&gt;
&lt;script src=&quot;https://gist.github.com/2919649.js?file=Plane.java&quot;&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;public class Plane&lt;status extends FlightStatus&gt; {&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; private Plane(){&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; // blah blah blah&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; }&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; public Plane(Plane&lt;? extends FlightStatus &gt; p){&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; //copy whatever info we need&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; }&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; public static Plane&lt;landed&gt; plane(){&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; return new Plane&lt;landed&gt;();&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; }&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; public static Plane&lt;landed&gt; land(Plane&lt;flying&gt; p) {&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; return new Plane&lt;landed&gt;(p);&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; }&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; public static Plane&lt;flying&gt; takeOff(Plane&lt;landed&gt; p) {&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; return new Plane&lt;flying&gt;(p);&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; }&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; }&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;}&lt;/span&gt;
&lt;/script&gt;

&lt;br /&gt;
And finally, our flight controller class with the takeOff and land methods:&lt;br /&gt;
&lt;script src=&quot;https://gist.github.com/2919649.js?file=AirTrafficController.java&quot;&gt;
&lt;div&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;public class AirTrafficController {&lt;/span&gt;&lt;/div&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; public static void main(String[] args){&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; Plane&lt;landed&gt; p=Plane.newPlane();&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; Plane&lt;flying&gt; fly=takeOff(p);&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; Plane&lt;landed&gt; land=land(fly);&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; //doesn&#39;t compile:&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; //Plane&lt;landed&gt; reallyLanded=land(land);&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; //Plane&lt;flying&gt; reallyFlying=takeOff(fly);&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;}&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;
&lt;/script&gt;

&lt;br /&gt;
&lt;div&gt;
The interesting part is in the land and takeOff methods. For example, in the land method, we require a Plane&amp;lt;Flying&amp;gt; but we just return a landing plane, (without using the Flying interface in the body). That&#39;s how we enforce that a plane must be flying to be able to land.&lt;br /&gt;
What I wanted to show with this is pretty silly example is how you can use phantom types to enforce some rules.&lt;br /&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;span style=&quot;font-size: large;&quot;&gt;What are they good for?&lt;/span&gt;&lt;br /&gt;
Ok, now you have a way to require at compile type certain parameter on a type, what can you use it for?&lt;br /&gt;
Turns out it you can use to enforce many constraints:&lt;br /&gt;
Enforce a particular state: in the previous example, we used phantom types to require a specific state in a method (flying/landing in this case). In the same way we can require a connection to be open when we do a query or close it:&lt;br /&gt;
&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;public ResultSet execute( Connection&amp;lt;Open&amp;gt; c, Query q) ....&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;public void close( Connection&amp;lt;Open&amp;gt; c) ....
&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
(but is not safe, will work a better example)&lt;br /&gt;
&lt;br /&gt;
You can also use it for safer Ids:&lt;br /&gt;
Usually Ids are Int or Strings, and is very easy to mix them up, e.g. in buy(String productId, String customerId) you can swap the Ids by mistake and you can get subtle bugs (the productId might match a customerId). With phantom types you can define an Id class parametrized by the entity and you get&amp;nbsp;buy(Id&amp;lt;Product&amp;gt; productId,&amp;nbsp;
Id&amp;lt;Customer&amp;gt; &amp;nbsp;customerId) and you&#39;ll get a compiler error if you pass a product id where you expect a customer id.&lt;br /&gt;
The full example &amp;nbsp;(in Scala):&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;script src=&quot;https://gist.github.com/3682353.js?file=Ids.scala&quot;&gt;
&lt;pre style=&quot;white-space: pre-wrap; word-wrap: break-word;&quot;&gt;trait Entity
trait User extends Entity
trait Product extends Entity

case class Id[T&lt;:entity buy=&quot;buy&quot; def=&quot;def&quot; for=&quot;for&quot; format=&quot;format&quot; id:string=&quot;id:string&quot; id=&quot;id&quot; ought=&quot;ought&quot; pid.id=&quot;pid.id&quot; pid:id=&quot;pid:id&quot; pid=&quot;new&quot; product=&quot;product&quot; roduct=&quot;roduct&quot; s=&quot;s&quot; scala=&quot;scala&quot; ser=&quot;ser&quot; uid.id=&quot;uid.id&quot; uid:id=&quot;uid:id&quot; uid=&quot;new&quot; user=&quot;user&quot; val=&quot;val&quot;&gt; buy(pId,uId)
res2: String = Bought product 1 for user 2

scala&gt; buy(uId,pId)
&lt;console&gt;:16: error: type mismatch;
 found   : Id[User]
 required: Id[Product]
              buy(uId,pId)
                  ^
*/&lt;/console&gt;&lt;/:entity&gt;&lt;/pre&gt;
&lt;/script&gt;

&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;span style=&quot;font-size: large;&quot;&gt;Go ahead and Type!&lt;/span&gt;&lt;br /&gt;
As you see, phantom types are pretty straightforward and gives you more expressive power (in particular, will allow you to get more mileage from Java&#39;s type system). I hope they get more use in Java...&lt;br /&gt;
&lt;br /&gt;
&lt;div&gt;
&lt;span style=&quot;font-size: large;&quot;&gt;Some useful links:&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;background-color: white; color: #202020; font-family: inherit; line-height: 18px;&quot;&gt;&lt;a href=&quot;https://michid.wordpress.com/2008/08/13/type-safe-builder-pattern-in-java/&quot;&gt;https://michid.wordpress.com/2008/08/13/type-safe-builder-pattern-in-java/&lt;/a&gt;&lt;/span&gt;&lt;br /&gt;
&lt;a href=&quot;http://maniagnosis.crsr.net/2010/06/phantom-types-in-java.html&quot;&gt;&lt;span style=&quot;font-family: inherit;&quot;&gt;http://maniagnosis.crsr.net/2010/06/phantom-types-in-java.html&lt;/span&gt;&lt;/a&gt;&lt;br /&gt;
&lt;a href=&quot;http://www.haskell.org/haskellwiki/Phantom_type&quot;&gt;&lt;span style=&quot;font-family: inherit;&quot;&gt;http://www.haskell.org/haskellwiki/Phantom_type&lt;/span&gt;&lt;/a&gt;&lt;br /&gt;
&lt;a href=&quot;http://en.wikipedia.org/wiki/Phantom_types&quot;&gt;&lt;span style=&quot;font-family: inherit;&quot;&gt;http://en.wikipedia.org/wiki/Phantom_types&lt;/span&gt;&lt;/a&gt;&lt;br /&gt;
&lt;a href=&quot;https://ocaml.janestreet.com/?q=node/11&quot;&gt;&lt;span style=&quot;font-family: inherit;&quot;&gt;https://ocaml.janestreet.com/?q=node/11&lt;/span&gt;&lt;/a&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: inherit;&quot;&gt;&lt;a href=&quot;http://stackoverflow.com/questions/5881301/implementing-phantom-types-in-c-sharp&quot;&gt;http://stackoverflow.com/questions/5881301/implementing-phantom-types-in-c-sharp&lt;/a&gt;&lt;/span&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;span style=&quot;font-size: large;&quot;&gt;Edit:&lt;/span&gt;&lt;br /&gt;
There&#39;s an interesting discussion in &lt;a href=&quot;http://www.reddit.com/r/programming/comments/zm7f9/phantom_types_in_java/&quot;&gt;reddit&lt;/a&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;span style=&quot;font-size: large;&quot;&gt;Note:&lt;/span&gt;&lt;br /&gt;
The connection example is a misleading, as you&#39;ll still can hold a reference to the open connection and attempt stuff, I will work a better example.&lt;/div&gt;
</description><link>http://gabrielsw.blogspot.com/2012/09/phantom-types-in-java.html</link><author>noreply@blogger.com (Anonymous)</author><thr:total>60</thr:total></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-6893032696317132921.post-8573774368095381897</guid><pubDate>Fri, 06 Apr 2012 08:17:00 +0000</pubDate><atom:updated>2012-04-08T02:56:44.526-04:00</atom:updated><category domain="http://www.blogger.com/atom/ns#">functional programming</category><category domain="http://www.blogger.com/atom/ns#">Scala</category><title>A (purely functional) Turing Machine simulator in Scala</title><description>&lt;h3&gt;








Why?&lt;/h3&gt;
While preparing for the exam for a Language Theory course I took, I have many exercises requiring to draw turing machines. Having to verify them manually is pretty cumbersome, so just for fun I set out to write one in Scala and stay in a pure functional style.&lt;br /&gt;
&lt;br /&gt;
If you want a definition of a turing machine you can always go to &lt;a href=&quot;http://en.wikipedia.org/wiki/Turing_machine&quot;&gt;wikipedia&lt;/a&gt;&amp;nbsp;, but simplifying (a lot), you can see it as a finite state machine with a read/write head over an infinite tape.&lt;br /&gt;
&lt;br /&gt;
&lt;h3&gt;








The implementation&lt;/h3&gt;
First we need to model the tape. We just need four operations: move left, move right, read, and write. Your typical functional immutable list is not the best for that, as there&#39;s no way to go back (left) and moving ahead (right) is O(n). Doing it with an array or double linked list is trivial but they&#39;re mutable, we&#39;re stuck!&lt;br /&gt;
&lt;br /&gt;
If you think about it, we need to go step by step forward and change the head, for that the normal immutable list is perfect, but how we go back step by step?&lt;br /&gt;
Any idea?&lt;br /&gt;
What if we keep another list with the elements we&#39;ll find if we go backwards? Then, advancing thought the list is just a matter of taking the head of the forward list and adding as head of the backward list and vice-versa.&amp;nbsp;As a plus, to add/update/remove we just change the head of the &amp;nbsp;forward list.&lt;br /&gt;
Does it make sense?&amp;nbsp;Congratulations, we just reinvented/discovered the &lt;a href=&quot;http://en.wikipedia.org/wiki/Zipper_(data_structure)&quot;&gt;List Zipper&lt;/a&gt;&amp;nbsp;!&amp;nbsp;(as usual, there&#39;s a nice explanation in &quot;&lt;a href=&quot;http://learnyouahaskell.com/zippers#focusing-on-lists&quot;&gt;Learn you a Haskell...&lt;/a&gt;&quot; )&lt;br /&gt;
&lt;br /&gt;
&lt;h3&gt;





A Zipper&lt;/h3&gt;
Simple zipper implementation in Scala will look like:&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;script src=&quot;https://gist.github.com/1670610.js?file=ListZipper.scala&quot;&gt;
&lt;pre style=&quot;font-family: &#39;Bitstream Vera Sans Mono&#39;, &#39;Courier New&#39;, monospace; font-size: 12px; line-height: 1.4em; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; text-align: left;&quot;&gt;&lt;div class=&quot;line&quot; id=&quot;LC1&quot; style=&quot;line-height: 1.4em; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 1em; padding-right: 0px; padding-top: 0px;&quot;&gt;



&lt;span class=&quot;k&quot; style=&quot;font-weight: bold; line-height: 1.4em; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;&quot;&gt;case&lt;/span&gt; &lt;span class=&quot;k&quot; style=&quot;font-weight: bold; line-height: 1.4em; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;&quot;&gt;class&lt;/span&gt; &lt;span class=&quot;nc&quot; style=&quot;color: #445588; font-weight: bold; line-height: 1.4em; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;&quot;&gt;ListZipper&lt;/span&gt;&lt;span class=&quot;o&quot; style=&quot;font-weight: bold; line-height: 1.4em; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;kt&quot; style=&quot;color: #445588; font-weight: bold; line-height: 1.4em; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;&quot;&gt;T&lt;/span&gt;&lt;span class=&quot;o&quot; style=&quot;font-weight: bold; line-height: 1.4em; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;&quot;&gt;](&lt;/span&gt;&lt;span class=&quot;n&quot; style=&quot;line-height: 1.4em; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;&quot;&gt;rev&lt;/span&gt;&lt;span class=&quot;k&quot; style=&quot;font-weight: bold; line-height: 1.4em; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;kt&quot; style=&quot;color: #445588; font-weight: bold; line-height: 1.4em; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;&quot;&gt;List&lt;/span&gt;&lt;span class=&quot;o&quot; style=&quot;font-weight: bold; line-height: 1.4em; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;kt&quot; style=&quot;color: #445588; font-weight: bold; line-height: 1.4em; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;&quot;&gt;T&lt;/span&gt;&lt;span class=&quot;o&quot; style=&quot;font-weight: bold; line-height: 1.4em; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;&quot;&gt;],&lt;/span&gt; &lt;span class=&quot;n&quot; style=&quot;line-height: 1.4em; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;&quot;&gt;fwd&lt;/span&gt;&lt;span class=&quot;k&quot; style=&quot;font-weight: bold; line-height: 1.4em; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;kt&quot; style=&quot;color: #445588; font-weight: bold; line-height: 1.4em; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;&quot;&gt;List&lt;/span&gt;&lt;span class=&quot;o&quot; style=&quot;font-weight: bold; line-height: 1.4em; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;kt&quot; style=&quot;color: #445588; font-weight: bold; line-height: 1.4em; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;&quot;&gt;T&lt;/span&gt;&lt;span class=&quot;o&quot; style=&quot;font-weight: bold; line-height: 1.4em; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;&quot;&gt;]){&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;line&quot; id=&quot;LC2&quot; style=&quot;line-height: 1.4em; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 1em; padding-right: 0px; padding-top: 0px;&quot;&gt;



&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span class=&quot;k&quot; style=&quot;font-weight: bold; line-height: 1.4em; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;&quot;&gt;override&lt;/span&gt; &lt;span class=&quot;k&quot; style=&quot;font-weight: bold; line-height: 1.4em; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;&quot;&gt;def&lt;/span&gt; &lt;span class=&quot;n&quot; style=&quot;line-height: 1.4em; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;&quot;&gt;toString&lt;/span&gt; &lt;span class=&quot;k&quot; style=&quot;font-weight: bold; line-height: 1.4em; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot; style=&quot;line-height: 1.4em; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;&quot;&gt;rev&lt;/span&gt;&lt;span class=&quot;o&quot; style=&quot;font-weight: bold; line-height: 1.4em; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot; style=&quot;line-height: 1.4em; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;&quot;&gt;reverse&lt;/span&gt;&lt;span class=&quot;o&quot; style=&quot;font-weight: bold; line-height: 1.4em; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot; style=&quot;line-height: 1.4em; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;&quot;&gt;toString&lt;/span&gt; &lt;span class=&quot;o&quot; style=&quot;font-weight: bold; line-height: 1.4em; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;&quot;&gt;++&lt;/span&gt;&lt;span class=&quot;s&quot; style=&quot;color: #dd1144; line-height: 1.4em; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;&quot;&gt;&quot; &quot;&lt;/span&gt; &lt;span class=&quot;o&quot; style=&quot;font-weight: bold; line-height: 1.4em; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;&quot;&gt;++&lt;/span&gt; &lt;span class=&quot;n&quot; style=&quot;line-height: 1.4em; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;&quot;&gt;fwd&lt;/span&gt;&lt;span class=&quot;o&quot; style=&quot;font-weight: bold; line-height: 1.4em; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot; style=&quot;line-height: 1.4em; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;&quot;&gt;toString&lt;/span&gt;  &lt;span style=&quot;line-height: 1.4em;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;line-height: 1.4em;&quot;&gt;
&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;line&quot; id=&quot;LC4&quot; style=&quot;line-height: 1.4em; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 1em; padding-right: 0px; padding-top: 0px;&quot;&gt;



&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span class=&quot;k&quot; style=&quot;font-weight: bold; line-height: 1.4em; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;&quot;&gt;def&lt;/span&gt; &lt;span class=&quot;n&quot; style=&quot;line-height: 1.4em; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;&quot;&gt;read&lt;/span&gt;&lt;span class=&quot;k&quot; style=&quot;font-weight: bold; line-height: 1.4em; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;kt&quot; style=&quot;color: #445588; font-weight: bold; line-height: 1.4em; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;&quot;&gt;T&lt;/span&gt;&lt;span class=&quot;o&quot; style=&quot;font-weight: bold; line-height: 1.4em; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot; style=&quot;line-height: 1.4em; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;&quot;&gt;fwd&lt;/span&gt;&lt;span class=&quot;o&quot; style=&quot;font-weight: bold; line-height: 1.4em; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot; style=&quot;line-height: 1.4em; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;&quot;&gt;head&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;line&quot; id=&quot;LC5&quot; style=&quot;line-height: 1.4em; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 1em; padding-right: 0px; padding-top: 0px;&quot;&gt;



&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span class=&quot;k&quot; style=&quot;font-weight: bold; line-height: 1.4em; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;&quot;&gt;def&lt;/span&gt; &lt;span class=&quot;n&quot; style=&quot;line-height: 1.4em; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;&quot;&gt;add&lt;/span&gt;&lt;span class=&quot;o&quot; style=&quot;font-weight: bold; line-height: 1.4em; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot; style=&quot;line-height: 1.4em; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;&quot;&gt;c&lt;/span&gt;&lt;span class=&quot;k&quot; style=&quot;font-weight: bold; line-height: 1.4em; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;kt&quot; style=&quot;color: #445588; font-weight: bold; line-height: 1.4em; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;&quot;&gt;T&lt;/span&gt;&lt;span class=&quot;o&quot; style=&quot;font-weight: bold; line-height: 1.4em; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;k&quot; style=&quot;font-weight: bold; line-height: 1.4em; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;nc&quot; style=&quot;color: #445588; font-weight: bold; line-height: 1.4em; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;&quot;&gt;ListZipper&lt;/span&gt;&lt;span class=&quot;o&quot; style=&quot;font-weight: bold; line-height: 1.4em; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot; style=&quot;line-height: 1.4em; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;&quot;&gt;rev&lt;/span&gt;&lt;span class=&quot;o&quot; style=&quot;font-weight: bold; line-height: 1.4em; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;n&quot; style=&quot;line-height: 1.4em; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;&quot;&gt;c&lt;/span&gt;&lt;span class=&quot;o&quot; style=&quot;font-weight: bold; line-height: 1.4em; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;n&quot; style=&quot;line-height: 1.4em; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;&quot;&gt;fwd&lt;/span&gt;&lt;span class=&quot;o&quot; style=&quot;font-weight: bold; line-height: 1.4em; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;&quot;&gt;)&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;line&quot; id=&quot;LC6&quot; style=&quot;line-height: 1.4em; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 1em; padding-right: 0px; padding-top: 0px;&quot;&gt;



&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span class=&quot;k&quot; style=&quot;font-weight: bold; line-height: 1.4em; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;&quot;&gt;def&lt;/span&gt; &lt;span class=&quot;n&quot; style=&quot;line-height: 1.4em; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;&quot;&gt;update&lt;/span&gt;&lt;span class=&quot;o&quot; style=&quot;font-weight: bold; line-height: 1.4em; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot; style=&quot;line-height: 1.4em; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;&quot;&gt;c&lt;/span&gt;&lt;span class=&quot;k&quot; style=&quot;font-weight: bold; line-height: 1.4em; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;kt&quot; style=&quot;color: #445588; font-weight: bold; line-height: 1.4em; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;&quot;&gt;T&lt;/span&gt;&lt;span class=&quot;o&quot; style=&quot;font-weight: bold; line-height: 1.4em; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;k&quot; style=&quot;font-weight: bold; line-height: 1.4em; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;nc&quot; style=&quot;color: #445588; font-weight: bold; line-height: 1.4em; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;&quot;&gt;ListZipper&lt;/span&gt;&lt;span class=&quot;o&quot; style=&quot;font-weight: bold; line-height: 1.4em; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot; style=&quot;line-height: 1.4em; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;&quot;&gt;rev&lt;/span&gt;&lt;span class=&quot;o&quot; style=&quot;font-weight: bold; line-height: 1.4em; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;n&quot; style=&quot;line-height: 1.4em; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;&quot;&gt;c&lt;/span&gt;&lt;span class=&quot;o&quot; style=&quot;font-weight: bold; line-height: 1.4em; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;n&quot; style=&quot;line-height: 1.4em; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;&quot;&gt;fwd&lt;/span&gt;&lt;span class=&quot;o&quot; style=&quot;font-weight: bold; line-height: 1.4em; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot; style=&quot;line-height: 1.4em; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;&quot;&gt;tail&lt;/span&gt;&lt;span class=&quot;o&quot; style=&quot;font-weight: bold; line-height: 1.4em; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;&quot;&gt;)&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;line&quot; id=&quot;LC7&quot; style=&quot;line-height: 1.4em; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 1em; padding-right: 0px; padding-top: 0px;&quot;&gt;



&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span class=&quot;k&quot; style=&quot;font-weight: bold; line-height: 1.4em; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;&quot;&gt;def&lt;/span&gt; &lt;span class=&quot;n&quot; style=&quot;line-height: 1.4em; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;&quot;&gt;remove&lt;/span&gt;&lt;span class=&quot;o&quot; style=&quot;font-weight: bold; line-height: 1.4em; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;&quot;&gt;()&lt;/span&gt;&lt;span class=&quot;k&quot; style=&quot;font-weight: bold; line-height: 1.4em; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;nc&quot; style=&quot;color: #445588; font-weight: bold; line-height: 1.4em; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;&quot;&gt;ListZipper&lt;/span&gt;&lt;span class=&quot;o&quot; style=&quot;font-weight: bold; line-height: 1.4em; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot; style=&quot;line-height: 1.4em; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;&quot;&gt;rev&lt;/span&gt;&lt;span class=&quot;o&quot; style=&quot;font-weight: bold; line-height: 1.4em; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;n&quot; style=&quot;line-height: 1.4em; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;&quot;&gt;fwd&lt;/span&gt;&lt;span class=&quot;o&quot; style=&quot;font-weight: bold; line-height: 1.4em; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot; style=&quot;line-height: 1.4em; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;&quot;&gt;tail&lt;/span&gt;&lt;span class=&quot;o&quot; style=&quot;font-weight: bold; line-height: 1.4em; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;&quot;&gt;)&lt;/span&gt;  &lt;/div&gt;
&lt;div class=&quot;line&quot; id=&quot;LC8&quot; style=&quot;line-height: 1.4em; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 1em; padding-right: 0px; padding-top: 0px;&quot;&gt;



&lt;/div&gt;
&lt;div class=&quot;line&quot; id=&quot;LC9&quot; style=&quot;line-height: 1.4em; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 1em; padding-right: 0px; padding-top: 0px;&quot;&gt;



&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span class=&quot;k&quot; style=&quot;font-weight: bold; line-height: 1.4em; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;&quot;&gt;def&lt;/span&gt; &lt;span class=&quot;n&quot; style=&quot;line-height: 1.4em; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;&quot;&gt;back&lt;/span&gt;&lt;span class=&quot;k&quot; style=&quot;font-weight: bold; line-height: 1.4em; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;nc&quot; style=&quot;color: #445588; font-weight: bold; line-height: 1.4em; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;&quot;&gt;ListZipper&lt;/span&gt;&lt;span class=&quot;o&quot; style=&quot;font-weight: bold; line-height: 1.4em; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot; style=&quot;line-height: 1.4em; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;&quot;&gt;rev&lt;/span&gt;&lt;span class=&quot;o&quot; style=&quot;font-weight: bold; line-height: 1.4em; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot; style=&quot;line-height: 1.4em; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;&quot;&gt;tail&lt;/span&gt;&lt;span class=&quot;o&quot; style=&quot;font-weight: bold; line-height: 1.4em; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;n&quot; style=&quot;line-height: 1.4em; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;&quot;&gt;rev&lt;/span&gt;&lt;span class=&quot;o&quot; style=&quot;font-weight: bold; line-height: 1.4em; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot; style=&quot;line-height: 1.4em; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;&quot;&gt;head&lt;/span&gt;&lt;span class=&quot;o&quot; style=&quot;font-weight: bold; line-height: 1.4em; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;n&quot; style=&quot;line-height: 1.4em; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;&quot;&gt;fwd&lt;/span&gt;&lt;span class=&quot;o&quot; style=&quot;font-weight: bold; line-height: 1.4em; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;&quot;&gt;)&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;line&quot; id=&quot;LC10&quot; style=&quot;line-height: 1.4em; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 1em; padding-right: 0px; padding-top: 0px;&quot;&gt;



&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span class=&quot;k&quot; style=&quot;font-weight: bold; line-height: 1.4em; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;&quot;&gt;def&lt;/span&gt; &lt;span class=&quot;n&quot; style=&quot;line-height: 1.4em; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;&quot;&gt;forward&lt;/span&gt;&lt;span class=&quot;k&quot; style=&quot;font-weight: bold; line-height: 1.4em; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;nc&quot; style=&quot;color: #445588; font-weight: bold; line-height: 1.4em; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;&quot;&gt;ListZipper&lt;/span&gt;&lt;span class=&quot;o&quot; style=&quot;font-weight: bold; line-height: 1.4em; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot; style=&quot;line-height: 1.4em; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;&quot;&gt;fwd&lt;/span&gt;&lt;span class=&quot;o&quot; style=&quot;font-weight: bold; line-height: 1.4em; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot; style=&quot;line-height: 1.4em; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;&quot;&gt;head&lt;/span&gt;&lt;span class=&quot;o&quot; style=&quot;font-weight: bold; line-height: 1.4em; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;n&quot; style=&quot;line-height: 1.4em; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;&quot;&gt;rev&lt;/span&gt;&lt;span class=&quot;o&quot; style=&quot;font-weight: bold; line-height: 1.4em; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;n&quot; style=&quot;line-height: 1.4em; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;&quot;&gt;fwd&lt;/span&gt;&lt;span class=&quot;o&quot; style=&quot;font-weight: bold; line-height: 1.4em; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot; style=&quot;line-height: 1.4em; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;&quot;&gt;tail&lt;/span&gt;&lt;span class=&quot;o&quot; style=&quot;font-weight: bold; line-height: 1.4em; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;&quot;&gt;)&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;line&quot; id=&quot;LC11&quot; style=&quot;line-height: 1.4em; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 1em; padding-right: 0px; padding-top: 0px;&quot;&gt;



&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/div&gt;
&lt;div class=&quot;line&quot; id=&quot;LC12&quot; style=&quot;line-height: 1.4em; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 1em; padding-right: 0px; padding-top: 0px;&quot;&gt;



&lt;span class=&quot;o&quot; style=&quot;font-weight: bold; line-height: 1.4em; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;&quot;&gt;}&lt;/span&gt;&lt;/div&gt;
&lt;/pre&gt;
&lt;/script&gt;
&lt;br /&gt;
&lt;h3&gt;





The Tape&lt;/h3&gt;
We&#39;re going to adapt the idea to model our tape with a couple of tweaks: first to better represent the concept of the read/write head in the tape, we&#39;re going to keep the element under focus separated form the list (actually is the same as working with the head of the list in the zipper, but when I started with the implementation I thought it could be easier to understand this way ). The important tweak is that the previous list zipper implementation works on a finite list, but our turing machine operates on an infinite list, so we need to adapt the left/right (or forward/back) operations to check when the list is empty and add a new blank element, so we never &quot;fall off&quot;. So, our tape will look like:&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;script src=&quot;https://gist.github.com/1258371.js?file=Tape.scala&quot;&gt;
&lt;pre style=&quot;font-family: &#39;Bitstream Vera Sans Mono&#39;, &#39;Courier New&#39;, monospace; font-size: 12px; line-height: 1.4em; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; text-align: left;&quot;&gt;&lt;div class=&quot;line&quot; id=&quot;LC4&quot; style=&quot;line-height: 1.4em; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 1em; padding-right: 0px; padding-top: 0px;&quot;&gt;



&lt;span class=&quot;k&quot; style=&quot;font-weight: bold; line-height: 1.4em; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;&quot;&gt;  type&lt;/span&gt; &lt;span class=&quot;kt&quot; style=&quot;color: #445588; font-weight: bold; line-height: 1.4em; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;&quot;&gt;Symb&lt;/span&gt;&lt;span class=&quot;o&quot; style=&quot;font-weight: bold; line-height: 1.4em; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;nc&quot; style=&quot;color: #445588; font-weight: bold; line-height: 1.4em; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;&quot;&gt;Char&lt;/span&gt; &lt;/div&gt;
&lt;div class=&quot;line&quot; id=&quot;LC5&quot; style=&quot;line-height: 1.4em; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 1em; padding-right: 0px; padding-top: 0px;&quot;&gt;



&amp;nbsp;&amp;nbsp;&lt;span class=&quot;k&quot; style=&quot;font-weight: bold; line-height: 1.4em; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;&quot;&gt;val&lt;/span&gt; &lt;span class=&quot;n&quot; style=&quot;line-height: 1.4em; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;&quot;&gt;b&lt;/span&gt;&lt;span class=&quot;o&quot; style=&quot;font-weight: bold; line-height: 1.4em; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;sc&quot; style=&quot;color: #dd1144; line-height: 1.4em; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;&quot;&gt;&#39; &#39;&lt;/span&gt;&lt;span class=&quot;o&quot; style=&quot;font-weight: bold; line-height: 1.4em; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;&quot;&gt;;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;line&quot; id=&quot;LC7&quot; style=&quot;line-height: 1.4em; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 1em; padding-right: 0px; padding-top: 0px;&quot;&gt;



&amp;nbsp;&amp;nbsp;&lt;span class=&quot;k&quot; style=&quot;font-weight: bold; line-height: 1.4em; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;&quot;&gt;case&lt;/span&gt; &lt;span class=&quot;k&quot; style=&quot;font-weight: bold; line-height: 1.4em; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;&quot;&gt;class&lt;/span&gt; &lt;span class=&quot;nc&quot; style=&quot;color: #445588; font-weight: bold; line-height: 1.4em; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;&quot;&gt;Tape&lt;/span&gt;&lt;span class=&quot;o&quot; style=&quot;font-weight: bold; line-height: 1.4em; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot; style=&quot;line-height: 1.4em; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;&quot;&gt;l&lt;/span&gt;&lt;span class=&quot;k&quot; style=&quot;font-weight: bold; line-height: 1.4em; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;kt&quot; style=&quot;color: #445588; font-weight: bold; line-height: 1.4em; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;&quot;&gt;List&lt;/span&gt;&lt;span class=&quot;o&quot; style=&quot;font-weight: bold; line-height: 1.4em; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;kt&quot; style=&quot;color: #445588; font-weight: bold; line-height: 1.4em; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;&quot;&gt;Symb&lt;/span&gt;&lt;span class=&quot;o&quot; style=&quot;font-weight: bold; line-height: 1.4em; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;&quot;&gt;],&lt;/span&gt;&lt;span class=&quot;n&quot; style=&quot;line-height: 1.4em; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;&quot;&gt;head&lt;/span&gt;&lt;span class=&quot;k&quot; style=&quot;font-weight: bold; line-height: 1.4em; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;kt&quot; style=&quot;color: #445588; font-weight: bold; line-height: 1.4em; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;&quot;&gt;Symb&lt;/span&gt;&lt;span class=&quot;o&quot; style=&quot;font-weight: bold; line-height: 1.4em; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot; style=&quot;line-height: 1.4em; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;&quot;&gt;r&lt;/span&gt;&lt;span class=&quot;k&quot; style=&quot;font-weight: bold; line-height: 1.4em; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;kt&quot; style=&quot;color: #445588; font-weight: bold; line-height: 1.4em; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;&quot;&gt;List&lt;/span&gt;&lt;span class=&quot;o&quot; style=&quot;font-weight: bold; line-height: 1.4em; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;kt&quot; style=&quot;color: #445588; font-weight: bold; line-height: 1.4em; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;&quot;&gt;Symb&lt;/span&gt;&lt;span class=&quot;o&quot; style=&quot;font-weight: bold; line-height: 1.4em; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;&quot;&gt;]){&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;line&quot; id=&quot;LC8&quot; style=&quot;line-height: 1.4em; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 1em; padding-right: 0px; padding-top: 0px;&quot;&gt;



&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span class=&quot;k&quot; style=&quot;font-weight: bold; line-height: 1.4em; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;&quot;&gt;override&lt;/span&gt; &lt;span class=&quot;k&quot; style=&quot;font-weight: bold; line-height: 1.4em; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;&quot;&gt;def&lt;/span&gt; &lt;span class=&quot;n&quot; style=&quot;line-height: 1.4em; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;&quot;&gt;toString&lt;/span&gt; &lt;span class=&quot;k&quot; style=&quot;font-weight: bold; line-height: 1.4em; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;o&quot; style=&quot;font-weight: bold; line-height: 1.4em; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;&quot;&gt;(&lt;/span&gt; &lt;span class=&quot;n&quot; style=&quot;line-height: 1.4em; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;&quot;&gt;l&lt;/span&gt;&lt;span class=&quot;o&quot; style=&quot;font-weight: bold; line-height: 1.4em; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot; style=&quot;line-height: 1.4em; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;&quot;&gt;reverse&lt;/span&gt; &lt;span class=&quot;o&quot; style=&quot;font-weight: bold; line-height: 1.4em; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;&quot;&gt;++&lt;/span&gt; &lt;span class=&quot;o&quot; style=&quot;font-weight: bold; line-height: 1.4em; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot; style=&quot;line-height: 1.4em; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;&quot;&gt;head&lt;/span&gt;&lt;span class=&quot;o&quot; style=&quot;font-weight: bold; line-height: 1.4em; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;n&quot; style=&quot;line-height: 1.4em; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;&quot;&gt;r&lt;/span&gt;&lt;span class=&quot;o&quot; style=&quot;font-weight: bold; line-height: 1.4em; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;&quot;&gt;)&lt;/span&gt;  &lt;span class=&quot;o&quot; style=&quot;font-weight: bold; line-height: 1.4em; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;&quot;&gt;).&lt;/span&gt;&lt;span class=&quot;n&quot; style=&quot;line-height: 1.4em; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;&quot;&gt;mkString&lt;/span&gt;&lt;span class=&quot;o&quot; style=&quot;font-weight: bold; line-height: 1.4em; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot; style=&quot;line-height: 1.4em; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;&quot;&gt;trim&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;line&quot; id=&quot;LC9&quot; style=&quot;line-height: 1.4em; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 1em; padding-right: 0px; padding-top: 0px;&quot;&gt;



&amp;nbsp;&amp;nbsp;&lt;span class=&quot;o&quot; style=&quot;font-weight: bold; line-height: 1.4em; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;&quot;&gt;}&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;line&quot; id=&quot;LC10&quot; style=&quot;line-height: 1.4em; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 1em; padding-right: 0px; padding-top: 0px;&quot;&gt;



&lt;/div&gt;
&lt;div class=&quot;line&quot; id=&quot;LC11&quot; style=&quot;line-height: 1.4em; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 1em; padding-right: 0px; padding-top: 0px;&quot;&gt;



&amp;nbsp;&lt;span class=&quot;c1&quot; style=&quot;color: #999988; font-style: italic; line-height: 1.4em; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;&quot;&gt;// less painful tape builder from a string, setting the head at the start char of the list&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;line&quot; id=&quot;LC12&quot; style=&quot;line-height: 1.4em; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 1em; padding-right: 0px; padding-top: 0px;&quot;&gt;



&amp;nbsp;&amp;nbsp;&lt;span class=&quot;k&quot; style=&quot;font-weight: bold; line-height: 1.4em; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;&quot;&gt;def&lt;/span&gt; &lt;span class=&quot;n&quot; style=&quot;line-height: 1.4em; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;&quot;&gt;tape&lt;/span&gt;&lt;span class=&quot;o&quot; style=&quot;font-weight: bold; line-height: 1.4em; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot; style=&quot;line-height: 1.4em; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;&quot;&gt;s&lt;/span&gt;&lt;span class=&quot;k&quot; style=&quot;font-weight: bold; line-height: 1.4em; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;kt&quot; style=&quot;color: #445588; font-weight: bold; line-height: 1.4em; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;&quot;&gt;String&lt;/span&gt;&lt;span class=&quot;o&quot; style=&quot;font-weight: bold; line-height: 1.4em; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;k&quot; style=&quot;font-weight: bold; line-height: 1.4em; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot; style=&quot;line-height: 1.4em; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;&quot;&gt;right&lt;/span&gt; &lt;span class=&quot;o&quot; style=&quot;font-weight: bold; line-height: 1.4em; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nc&quot; style=&quot;color: #445588; font-weight: bold; line-height: 1.4em; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;&quot;&gt;Tape&lt;/span&gt;&lt;span class=&quot;o&quot; style=&quot;font-weight: bold; line-height: 1.4em; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nc&quot; style=&quot;color: #445588; font-weight: bold; line-height: 1.4em; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;&quot;&gt;Nil&lt;/span&gt;&lt;span class=&quot;o&quot; style=&quot;font-weight: bold; line-height: 1.4em; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;n&quot; style=&quot;line-height: 1.4em; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;&quot;&gt;b&lt;/span&gt;&lt;span class=&quot;o&quot; style=&quot;font-weight: bold; line-height: 1.4em; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;n&quot; style=&quot;line-height: 1.4em; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;&quot;&gt;s&lt;/span&gt;&lt;span class=&quot;o&quot; style=&quot;font-weight: bold; line-height: 1.4em; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot; style=&quot;line-height: 1.4em; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;&quot;&gt;toList&lt;/span&gt; &lt;span class=&quot;o&quot; style=&quot;font-weight: bold; line-height: 1.4em; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;&quot;&gt;))&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;line&quot; id=&quot;LC14&quot; style=&quot;line-height: 1.4em; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 1em; padding-right: 0px; padding-top: 0px;&quot;&gt;



&amp;nbsp;&amp;nbsp;&lt;span class=&quot;k&quot; style=&quot;font-weight: bold; line-height: 1.4em; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;&quot;&gt;def&lt;/span&gt; &lt;span class=&quot;n&quot; style=&quot;line-height: 1.4em; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;&quot;&gt;write&lt;/span&gt;&lt;span class=&quot;o&quot; style=&quot;font-weight: bold; line-height: 1.4em; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot; style=&quot;line-height: 1.4em; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;&quot;&gt;c&lt;/span&gt;&lt;span class=&quot;k&quot; style=&quot;font-weight: bold; line-height: 1.4em; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;kt&quot; style=&quot;color: #445588; font-weight: bold; line-height: 1.4em; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;&quot;&gt;Symb&lt;/span&gt;&lt;span class=&quot;o&quot; style=&quot;font-weight: bold; line-height: 1.4em; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot; style=&quot;line-height: 1.4em; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;&quot;&gt;t&lt;/span&gt;&lt;span class=&quot;k&quot; style=&quot;font-weight: bold; line-height: 1.4em; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;kt&quot; style=&quot;color: #445588; font-weight: bold; line-height: 1.4em; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;&quot;&gt;Tape&lt;/span&gt;&lt;span class=&quot;o&quot; style=&quot;font-weight: bold; line-height: 1.4em; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;&quot;&gt;)=&lt;/span&gt;&lt;span class=&quot;nc&quot; style=&quot;color: #445588; font-weight: bold; line-height: 1.4em; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;&quot;&gt;Tape&lt;/span&gt;&lt;span class=&quot;o&quot; style=&quot;font-weight: bold; line-height: 1.4em; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot; style=&quot;line-height: 1.4em; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;&quot;&gt;t&lt;/span&gt;&lt;span class=&quot;o&quot; style=&quot;font-weight: bold; line-height: 1.4em; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot; style=&quot;line-height: 1.4em; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;&quot;&gt;l&lt;/span&gt;&lt;span class=&quot;o&quot; style=&quot;font-weight: bold; line-height: 1.4em; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;n&quot; style=&quot;line-height: 1.4em; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;&quot;&gt;c&lt;/span&gt;&lt;span class=&quot;o&quot; style=&quot;font-weight: bold; line-height: 1.4em; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;n&quot; style=&quot;line-height: 1.4em; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;&quot;&gt;t&lt;/span&gt;&lt;span class=&quot;o&quot; style=&quot;font-weight: bold; line-height: 1.4em; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot; style=&quot;line-height: 1.4em; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;&quot;&gt;r&lt;/span&gt;&lt;span class=&quot;o&quot; style=&quot;font-weight: bold; line-height: 1.4em; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;&quot;&gt;)&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;line&quot; id=&quot;LC15&quot; style=&quot;line-height: 1.4em; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 1em; padding-right: 0px; padding-top: 0px;&quot;&gt;



&amp;nbsp;&amp;nbsp;&lt;span class=&quot;k&quot; style=&quot;font-weight: bold; line-height: 1.4em; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;&quot;&gt;def&lt;/span&gt; &lt;span class=&quot;n&quot; style=&quot;line-height: 1.4em; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;&quot;&gt;read&lt;/span&gt;&lt;span class=&quot;o&quot; style=&quot;font-weight: bold; line-height: 1.4em; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot; style=&quot;line-height: 1.4em; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;&quot;&gt;t&lt;/span&gt;&lt;span class=&quot;k&quot; style=&quot;font-weight: bold; line-height: 1.4em; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;kt&quot; style=&quot;color: #445588; font-weight: bold; line-height: 1.4em; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;&quot;&gt;Tape&lt;/span&gt;&lt;span class=&quot;o&quot; style=&quot;font-weight: bold; line-height: 1.4em; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;k&quot; style=&quot;font-weight: bold; line-height: 1.4em; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot; style=&quot;line-height: 1.4em; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;&quot;&gt;t&lt;/span&gt;&lt;span class=&quot;o&quot; style=&quot;font-weight: bold; line-height: 1.4em; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot; style=&quot;line-height: 1.4em; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;&quot;&gt;head&lt;/span&gt;&lt;span style=&quot;line-height: 1.4em;&quot;&gt;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;line&quot; id=&quot;LC17&quot; style=&quot;line-height: 1.4em; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 1em; padding-right: 0px; padding-top: 0px;&quot;&gt;



&amp;nbsp;&amp;nbsp;&lt;span class=&quot;c1&quot; style=&quot;color: #999988; font-style: italic; line-height: 1.4em; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;&quot;&gt;//infinite tape: it grows with blanks when any end is reached &lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;line&quot; id=&quot;LC18&quot; style=&quot;line-height: 1.4em; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 1em; padding-right: 0px; padding-top: 0px;&quot;&gt;



&amp;nbsp;&amp;nbsp;&lt;span class=&quot;k&quot; style=&quot;font-weight: bold; line-height: 1.4em; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;&quot;&gt;def&lt;/span&gt; &lt;span class=&quot;n&quot; style=&quot;line-height: 1.4em; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;&quot;&gt;left&lt;/span&gt;&lt;span class=&quot;o&quot; style=&quot;font-weight: bold; line-height: 1.4em; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot; style=&quot;line-height: 1.4em; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;&quot;&gt;t&lt;/span&gt;&lt;span class=&quot;k&quot; style=&quot;font-weight: bold; line-height: 1.4em; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;kt&quot; style=&quot;color: #445588; font-weight: bold; line-height: 1.4em; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;&quot;&gt;Tape&lt;/span&gt;&lt;span class=&quot;o&quot; style=&quot;font-weight: bold; line-height: 1.4em; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;&quot;&gt;)=&lt;/span&gt;&lt;span class=&quot;n&quot; style=&quot;line-height: 1.4em; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;&quot;&gt;t&lt;/span&gt; &lt;span class=&quot;k&quot; style=&quot;font-weight: bold; line-height: 1.4em; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;&quot;&gt;match&lt;/span&gt; &lt;span class=&quot;o&quot; style=&quot;font-weight: bold; line-height: 1.4em; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;&quot;&gt;{&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;line&quot; id=&quot;LC19&quot; style=&quot;line-height: 1.4em; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 1em; padding-right: 0px; padding-top: 0px;&quot;&gt;



&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span class=&quot;k&quot; style=&quot;font-weight: bold; line-height: 1.4em; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;&quot;&gt;case&lt;/span&gt; &lt;span class=&quot;nc&quot; style=&quot;color: #445588; font-weight: bold; line-height: 1.4em; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;&quot;&gt;Tape&lt;/span&gt;&lt;span class=&quot;o&quot; style=&quot;font-weight: bold; line-height: 1.4em; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nc&quot; style=&quot;color: #445588; font-weight: bold; line-height: 1.4em; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;&quot;&gt;Nil&lt;/span&gt;&lt;span class=&quot;o&quot; style=&quot;font-weight: bold; line-height: 1.4em; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;n&quot; style=&quot;line-height: 1.4em; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;&quot;&gt;head&lt;/span&gt;&lt;span class=&quot;o&quot; style=&quot;font-weight: bold; line-height: 1.4em; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;n&quot; style=&quot;line-height: 1.4em; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;&quot;&gt;right&lt;/span&gt;&lt;span class=&quot;o&quot; style=&quot;font-weight: bold; line-height: 1.4em; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;o&quot; style=&quot;font-weight: bold; line-height: 1.4em; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;&quot;&gt;=&gt;&lt;/span&gt;&lt;span class=&quot;nc&quot; style=&quot;color: #445588; font-weight: bold; line-height: 1.4em; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;&quot;&gt;Tape&lt;/span&gt;&lt;span class=&quot;o&quot; style=&quot;font-weight: bold; line-height: 1.4em; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nc&quot; style=&quot;color: #445588; font-weight: bold; line-height: 1.4em; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;&quot;&gt;Nil&lt;/span&gt;&lt;span class=&quot;o&quot; style=&quot;font-weight: bold; line-height: 1.4em; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;n&quot; style=&quot;line-height: 1.4em; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;&quot;&gt;b&lt;/span&gt;&lt;span class=&quot;o&quot; style=&quot;font-weight: bold; line-height: 1.4em; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;n&quot; style=&quot;line-height: 1.4em; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;&quot;&gt;head&lt;/span&gt;&lt;span class=&quot;o&quot; style=&quot;font-weight: bold; line-height: 1.4em; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;n&quot; style=&quot;line-height: 1.4em; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;&quot;&gt;right&lt;/span&gt;&lt;span class=&quot;o&quot; style=&quot;font-weight: bold; line-height: 1.4em; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;&quot;&gt;)&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;line&quot; id=&quot;LC20&quot; style=&quot;line-height: 1.4em; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 1em; padding-right: 0px; padding-top: 0px;&quot;&gt;



&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span class=&quot;k&quot; style=&quot;font-weight: bold; line-height: 1.4em; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;&quot;&gt;case&lt;/span&gt; &lt;span class=&quot;nc&quot; style=&quot;color: #445588; font-weight: bold; line-height: 1.4em; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;&quot;&gt;Tape&lt;/span&gt;&lt;span class=&quot;o&quot; style=&quot;font-weight: bold; line-height: 1.4em; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot; style=&quot;line-height: 1.4em; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;&quot;&gt;left&lt;/span&gt;&lt;span class=&quot;o&quot; style=&quot;font-weight: bold; line-height: 1.4em; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;n&quot; style=&quot;line-height: 1.4em; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;&quot;&gt;head&lt;/span&gt;&lt;span class=&quot;o&quot; style=&quot;font-weight: bold; line-height: 1.4em; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;n&quot; style=&quot;line-height: 1.4em; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;&quot;&gt;right&lt;/span&gt;&lt;span class=&quot;o&quot; style=&quot;font-weight: bold; line-height: 1.4em; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;o&quot; style=&quot;font-weight: bold; line-height: 1.4em; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;&quot;&gt;=&gt;&lt;/span&gt;&lt;span class=&quot;nc&quot; style=&quot;color: #445588; font-weight: bold; line-height: 1.4em; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;&quot;&gt;Tape&lt;/span&gt;&lt;span class=&quot;o&quot; style=&quot;font-weight: bold; line-height: 1.4em; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot; style=&quot;line-height: 1.4em; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;&quot;&gt;left&lt;/span&gt;&lt;span class=&quot;o&quot; style=&quot;font-weight: bold; line-height: 1.4em; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot; style=&quot;line-height: 1.4em; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;&quot;&gt;tail&lt;/span&gt;&lt;span class=&quot;o&quot; style=&quot;font-weight: bold; line-height: 1.4em; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;n&quot; style=&quot;line-height: 1.4em; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;&quot;&gt;left&lt;/span&gt;&lt;span class=&quot;o&quot; style=&quot;font-weight: bold; line-height: 1.4em; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot; style=&quot;line-height: 1.4em; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;&quot;&gt;head&lt;/span&gt;&lt;span class=&quot;o&quot; style=&quot;font-weight: bold; line-height: 1.4em; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;n&quot; style=&quot;line-height: 1.4em; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;&quot;&gt;head&lt;/span&gt;&lt;span class=&quot;o&quot; style=&quot;font-weight: bold; line-height: 1.4em; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;n&quot; style=&quot;line-height: 1.4em; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;&quot;&gt;right&lt;/span&gt;&lt;span class=&quot;o&quot; style=&quot;font-weight: bold; line-height: 1.4em; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;&quot;&gt;)&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;line&quot; id=&quot;LC21&quot; style=&quot;line-height: 1.4em; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 1em; padding-right: 0px; padding-top: 0px;&quot;&gt;



&amp;nbsp;&amp;nbsp;&lt;span class=&quot;o&quot; style=&quot;font-weight: bold; line-height: 1.4em; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;&quot;&gt;}&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;line&quot; id=&quot;LC22&quot; style=&quot;line-height: 1.4em; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 1em; padding-right: 0px; padding-top: 0px;&quot;&gt;



&amp;nbsp;&amp;nbsp;&lt;span class=&quot;k&quot; style=&quot;font-weight: bold; line-height: 1.4em; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;&quot;&gt;def&lt;/span&gt; &lt;span class=&quot;n&quot; style=&quot;line-height: 1.4em; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;&quot;&gt;right&lt;/span&gt;&lt;span class=&quot;o&quot; style=&quot;font-weight: bold; line-height: 1.4em; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot; style=&quot;line-height: 1.4em; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;&quot;&gt;t&lt;/span&gt;&lt;span class=&quot;k&quot; style=&quot;font-weight: bold; line-height: 1.4em; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;kt&quot; style=&quot;color: #445588; font-weight: bold; line-height: 1.4em; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;&quot;&gt;Tape&lt;/span&gt;&lt;span class=&quot;o&quot; style=&quot;font-weight: bold; line-height: 1.4em; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;&quot;&gt;)=&lt;/span&gt;&lt;span class=&quot;n&quot; style=&quot;line-height: 1.4em; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;&quot;&gt;t&lt;/span&gt; &lt;span class=&quot;k&quot; style=&quot;font-weight: bold; line-height: 1.4em; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;&quot;&gt;match&lt;/span&gt; &lt;span class=&quot;o&quot; style=&quot;font-weight: bold; line-height: 1.4em; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;&quot;&gt;{&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;line&quot; id=&quot;LC23&quot; style=&quot;line-height: 1.4em; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 1em; padding-right: 0px; padding-top: 0px;&quot;&gt;



&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span class=&quot;k&quot; style=&quot;font-weight: bold; line-height: 1.4em; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;&quot;&gt;case&lt;/span&gt; &lt;span class=&quot;nc&quot; style=&quot;color: #445588; font-weight: bold; line-height: 1.4em; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;&quot;&gt;Tape&lt;/span&gt;&lt;span class=&quot;o&quot; style=&quot;font-weight: bold; line-height: 1.4em; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot; style=&quot;line-height: 1.4em; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;&quot;&gt;left&lt;/span&gt;&lt;span class=&quot;o&quot; style=&quot;font-weight: bold; line-height: 1.4em; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;n&quot; style=&quot;line-height: 1.4em; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;&quot;&gt;head&lt;/span&gt;&lt;span class=&quot;o&quot; style=&quot;font-weight: bold; line-height: 1.4em; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;nc&quot; style=&quot;color: #445588; font-weight: bold; line-height: 1.4em; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;&quot;&gt;Nil&lt;/span&gt;&lt;span class=&quot;o&quot; style=&quot;font-weight: bold; line-height: 1.4em; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;o&quot; style=&quot;font-weight: bold; line-height: 1.4em; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;&quot;&gt;=&gt;&lt;/span&gt;&lt;span class=&quot;nc&quot; style=&quot;color: #445588; font-weight: bold; line-height: 1.4em; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;&quot;&gt;Tape&lt;/span&gt;&lt;span class=&quot;o&quot; style=&quot;font-weight: bold; line-height: 1.4em; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot; style=&quot;line-height: 1.4em; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;&quot;&gt;head&lt;/span&gt;&lt;span class=&quot;o&quot; style=&quot;font-weight: bold; line-height: 1.4em; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;n&quot; style=&quot;line-height: 1.4em; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;&quot;&gt;left&lt;/span&gt;&lt;span class=&quot;o&quot; style=&quot;font-weight: bold; line-height: 1.4em; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;n&quot; style=&quot;line-height: 1.4em; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;&quot;&gt;b&lt;/span&gt;&lt;span class=&quot;o&quot; style=&quot;font-weight: bold; line-height: 1.4em; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;nc&quot; style=&quot;color: #445588; font-weight: bold; line-height: 1.4em; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;&quot;&gt;Nil&lt;/span&gt;&lt;span class=&quot;o&quot; style=&quot;font-weight: bold; line-height: 1.4em; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;&quot;&gt;)&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;line&quot; id=&quot;LC24&quot; style=&quot;line-height: 1.4em; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 1em; padding-right: 0px; padding-top: 0px;&quot;&gt;



&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span class=&quot;k&quot; style=&quot;font-weight: bold; line-height: 1.4em; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;&quot;&gt;case&lt;/span&gt; &lt;span class=&quot;nc&quot; style=&quot;color: #445588; font-weight: bold; line-height: 1.4em; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;&quot;&gt;Tape&lt;/span&gt;&lt;span class=&quot;o&quot; style=&quot;font-weight: bold; line-height: 1.4em; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot; style=&quot;line-height: 1.4em; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;&quot;&gt;left&lt;/span&gt;&lt;span class=&quot;o&quot; style=&quot;font-weight: bold; line-height: 1.4em; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;n&quot; style=&quot;line-height: 1.4em; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;&quot;&gt;head&lt;/span&gt;&lt;span class=&quot;o&quot; style=&quot;font-weight: bold; line-height: 1.4em; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;n&quot; style=&quot;line-height: 1.4em; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;&quot;&gt;right&lt;/span&gt;&lt;span class=&quot;o&quot; style=&quot;font-weight: bold; line-height: 1.4em; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;o&quot; style=&quot;font-weight: bold; line-height: 1.4em; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;&quot;&gt;=&gt;&lt;/span&gt;&lt;span class=&quot;nc&quot; style=&quot;color: #445588; font-weight: bold; line-height: 1.4em; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;&quot;&gt;Tape&lt;/span&gt;&lt;span class=&quot;o&quot; style=&quot;font-weight: bold; line-height: 1.4em; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot; style=&quot;line-height: 1.4em; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;&quot;&gt;head&lt;/span&gt;&lt;span class=&quot;o&quot; style=&quot;font-weight: bold; line-height: 1.4em; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;n&quot; style=&quot;line-height: 1.4em; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;&quot;&gt;left&lt;/span&gt;&lt;span class=&quot;o&quot; style=&quot;font-weight: bold; line-height: 1.4em; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;n&quot; style=&quot;line-height: 1.4em; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;&quot;&gt;right&lt;/span&gt;&lt;span class=&quot;o&quot; style=&quot;font-weight: bold; line-height: 1.4em; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot; style=&quot;line-height: 1.4em; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;&quot;&gt;head&lt;/span&gt;&lt;span class=&quot;o&quot; style=&quot;font-weight: bold; line-height: 1.4em; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;n&quot; style=&quot;line-height: 1.4em; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;&quot;&gt;right&lt;/span&gt;&lt;span class=&quot;o&quot; style=&quot;font-weight: bold; line-height: 1.4em; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot; style=&quot;line-height: 1.4em; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;&quot;&gt;tail&lt;/span&gt;&lt;span class=&quot;o&quot; style=&quot;font-weight: bold; line-height: 1.4em; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;&quot;&gt;)&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;line&quot; id=&quot;LC25&quot; style=&quot;line-height: 1.4em; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 1em; padding-right: 0px; padding-top: 0px;&quot;&gt;



&amp;nbsp;&amp;nbsp;&lt;span class=&quot;o&quot; style=&quot;font-weight: bold; line-height: 1.4em; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;&quot;&gt;}&lt;/span&gt;&lt;/div&gt;
&lt;/pre&gt;
&lt;/script&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;tape code=&quot;&quot;&gt;&lt;/tape&gt;&lt;br /&gt;
To make things easier on notation, we can also define two vals holding the right and left functions:&lt;br /&gt;
&lt;br /&gt;
&lt;script src=&quot;https://gist.github.com/1258371.js?file=IDfunctions.scala&quot;&gt;
&lt;pre style=&quot;font-family: &#39;Bitstream Vera Sans Mono&#39;, &#39;Courier New&#39;, monospace; font-size: 12px; line-height: 1.4em; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; text-align: left;&quot;&gt;&lt;div class=&quot;line&quot; id=&quot;LC27&quot; style=&quot;line-height: 1.4em; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 1em; padding-right: 0px; padding-top: 0px;&quot;&gt;



&amp;nbsp;&amp;nbsp;&lt;span class=&quot;k&quot; style=&quot;font-weight: bold; line-height: 1.4em; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;&quot;&gt;val&lt;/span&gt; &lt;span class=&quot;n&quot; style=&quot;line-height: 1.4em; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;&quot;&gt;I&lt;/span&gt;&lt;span class=&quot;k&quot; style=&quot;font-weight: bold; line-height: 1.4em; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot; style=&quot;line-height: 1.4em; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;&quot;&gt;left&lt;/span&gt; &lt;span class=&quot;k&quot; style=&quot;font-weight: bold; line-height: 1.4em; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;&quot;&gt;_&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;line&quot; id=&quot;LC28&quot; style=&quot;line-height: 1.4em; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 1em; padding-right: 0px; padding-top: 0px;&quot;&gt;



&amp;nbsp;&amp;nbsp;&lt;span class=&quot;k&quot; style=&quot;font-weight: bold; line-height: 1.4em; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;&quot;&gt;val&lt;/span&gt; &lt;span class=&quot;n&quot; style=&quot;line-height: 1.4em; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;&quot;&gt;D&lt;/span&gt;&lt;span class=&quot;k&quot; style=&quot;font-weight: bold; line-height: 1.4em; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot; style=&quot;line-height: 1.4em; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;&quot;&gt;right&lt;/span&gt; &lt;span class=&quot;k&quot; style=&quot;font-weight: bold; line-height: 1.4em; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;&quot;&gt;_&lt;/span&gt;&lt;/div&gt;
&lt;/pre&gt;
&lt;/script&gt;
&lt;br /&gt;
&lt;h3&gt;





The interpreter&lt;/h3&gt;
Once the infinite tape is in place, the rest of the turing machine is easy: we need a state machine that based on the current symbol under the head and the current machine state, decides whether to write, move the head right or left and what&#39;s the next state. Using maps for those transitions is very straightforward:&amp;nbsp;We use a map from the current state to a map from the current symbol &lt;br /&gt;
&lt;br /&gt;
You can think of the transition as a function T: State x Symbol =&amp;gt; (State, Symbol,Move)&lt;br /&gt;
&lt;map and=&quot;&quot; move=&quot;&quot; signature=&quot;&quot;&gt;&lt;/map&gt;&lt;br /&gt;
Or in types:&lt;br /&gt;
&lt;br /&gt;
&lt;script src=&quot;https://gist.github.com/1258371.js?file=TrnsMtrx.scala&quot;&gt;
&lt;pre style=&quot;font-family: &#39;Bitstream Vera Sans Mono&#39;, &#39;Courier New&#39;, monospace; font-size: 12px; line-height: 1.4em; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; text-align: left;&quot;&gt;&lt;div class=&quot;line&quot; id=&quot;LC30&quot; style=&quot;line-height: 1.4em; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 1em; padding-right: 0px; padding-top: 0px;&quot;&gt;



&lt;span class=&quot;c1&quot; style=&quot;color: #999988; font-style: italic; line-height: 1.4em; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;&quot;&gt;  //transition matrix&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;line&quot; id=&quot;LC31&quot; style=&quot;line-height: 1.4em; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 1em; padding-right: 0px; padding-top: 0px;&quot;&gt;



&amp;nbsp;&amp;nbsp;&lt;span class=&quot;k&quot; style=&quot;font-weight: bold; line-height: 1.4em; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;&quot;&gt;type&lt;/span&gt; &lt;span class=&quot;kt&quot; style=&quot;color: #445588; font-weight: bold; line-height: 1.4em; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;&quot;&gt;Move&lt;/span&gt;&lt;span class=&quot;o&quot; style=&quot;font-weight: bold; line-height: 1.4em; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;nc&quot; style=&quot;color: #445588; font-weight: bold; line-height: 1.4em; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;&quot;&gt;Tape&lt;/span&gt;&lt;span class=&quot;o&quot; style=&quot;font-weight: bold; line-height: 1.4em; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;&quot;&gt;=&gt;&lt;/span&gt;&lt;span class=&quot;nc&quot; style=&quot;color: #445588; font-weight: bold; line-height: 1.4em; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;&quot;&gt;Tape&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;line&quot; id=&quot;LC32&quot; style=&quot;line-height: 1.4em; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 1em; padding-right: 0px; padding-top: 0px;&quot;&gt;



&amp;nbsp;&amp;nbsp;&lt;span class=&quot;k&quot; style=&quot;font-weight: bold; line-height: 1.4em; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;&quot;&gt;type&lt;/span&gt; &lt;span class=&quot;kt&quot; style=&quot;color: #445588; font-weight: bold; line-height: 1.4em; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;&quot;&gt;TrnsMtrx&lt;/span&gt;&lt;span class=&quot;o&quot; style=&quot;font-weight: bold; line-height: 1.4em; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;nc&quot; style=&quot;color: #445588; font-weight: bold; line-height: 1.4em; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;&quot;&gt;Map&lt;/span&gt;&lt;span class=&quot;o&quot; style=&quot;font-weight: bold; line-height: 1.4em; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;kt&quot; style=&quot;color: #445588; font-weight: bold; line-height: 1.4em; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;&quot;&gt;State&lt;/span&gt;, &lt;span class=&quot;kt&quot; style=&quot;color: #445588; font-weight: bold; line-height: 1.4em; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;&quot;&gt;Map&lt;/span&gt;&lt;span class=&quot;o&quot; style=&quot;font-weight: bold; line-height: 1.4em; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;kt&quot; style=&quot;color: #445588; font-weight: bold; line-height: 1.4em; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;&quot;&gt;Symb&lt;/span&gt;,&lt;span class=&quot;o&quot; style=&quot;font-weight: bold; line-height: 1.4em; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;kt&quot; style=&quot;color: #445588; font-weight: bold; line-height: 1.4em; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;&quot;&gt;State&lt;/span&gt;,&lt;span class=&quot;kt&quot; style=&quot;color: #445588; font-weight: bold; line-height: 1.4em; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;&quot;&gt;Symb&lt;/span&gt;,&lt;span class=&quot;kt&quot; style=&quot;color: #445588; font-weight: bold; line-height: 1.4em; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;&quot;&gt;Move&lt;/span&gt;&lt;span class=&quot;o&quot; style=&quot;font-weight: bold; line-height: 1.4em; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;&quot;&gt;)]]&lt;/span&gt;&lt;/div&gt;
&lt;/pre&gt;
&lt;/script&gt;
&lt;br /&gt;
With that, the core of our Turing Machine (the interpreter), is pretty simple:&lt;br /&gt;
&lt;br /&gt;
&lt;script src=&quot;https://gist.github.com/1258371.js?file=TMInterpreter.scala&quot;&gt;
&lt;pre style=&quot;font-family: &#39;Bitstream Vera Sans Mono&#39;, &#39;Courier New&#39;, monospace; font-size: 12px; line-height: 1.4em; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; text-align: left;&quot;&gt;&lt;div class=&quot;line&quot; id=&quot;LC34&quot; style=&quot;line-height: 1.4em; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 1em; padding-right: 0px; padding-top: 0px;&quot;&gt;



&lt;span class=&quot;nd&quot; style=&quot;line-height: 1.4em; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;&quot;&gt;    @tailrec&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;line&quot; id=&quot;LC35&quot; style=&quot;line-height: 1.4em; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 1em; padding-right: 0px; padding-top: 0px;&quot;&gt;



&amp;nbsp;&amp;nbsp;  &lt;span class=&quot;k&quot; style=&quot;font-weight: bold; line-height: 1.4em; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;&quot;&gt;final&lt;/span&gt; &lt;span class=&quot;k&quot; style=&quot;font-weight: bold; line-height: 1.4em; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;&quot;&gt;def&lt;/span&gt; &lt;span class=&quot;n&quot; style=&quot;line-height: 1.4em; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;&quot;&gt;step&lt;/span&gt;&lt;span class=&quot;o&quot; style=&quot;font-weight: bold; line-height: 1.4em; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot; style=&quot;line-height: 1.4em; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;&quot;&gt;q&lt;/span&gt;&lt;span class=&quot;k&quot; style=&quot;font-weight: bold; line-height: 1.4em; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;kt&quot; style=&quot;color: #445588; font-weight: bold; line-height: 1.4em; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;&quot;&gt;State&lt;/span&gt;&lt;span class=&quot;o&quot; style=&quot;font-weight: bold; line-height: 1.4em; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot; style=&quot;line-height: 1.4em; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;&quot;&gt;t&lt;/span&gt;&lt;span class=&quot;k&quot; style=&quot;font-weight: bold; line-height: 1.4em; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;kt&quot; style=&quot;color: #445588; font-weight: bold; line-height: 1.4em; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;&quot;&gt;Tape&lt;/span&gt;&lt;span class=&quot;o&quot; style=&quot;font-weight: bold; line-height: 1.4em; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;n&quot; style=&quot;line-height: 1.4em; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;&quot;&gt;tm&lt;/span&gt;&lt;span class=&quot;k&quot; style=&quot;font-weight: bold; line-height: 1.4em; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;kt&quot; style=&quot;color: #445588; font-weight: bold; line-height: 1.4em; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;&quot;&gt;TrnsMtrx&lt;/span&gt;&lt;span class=&quot;o&quot; style=&quot;font-weight: bold; line-height: 1.4em; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot; style=&quot;line-height: 1.4em; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;&quot;&gt;qf&lt;/span&gt;&lt;span class=&quot;k&quot; style=&quot;font-weight: bold; line-height: 1.4em; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;kt&quot; style=&quot;color: #445588; font-weight: bold; line-height: 1.4em; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;&quot;&gt;State&lt;/span&gt;&lt;span class=&quot;o&quot; style=&quot;font-weight: bold; line-height: 1.4em; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;k&quot; style=&quot;font-weight: bold; line-height: 1.4em; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;kt&quot; style=&quot;color: #445588; font-weight: bold; line-height: 1.4em; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;&quot;&gt;Tape&lt;/span&gt; &lt;span class=&quot;o&quot; style=&quot;font-weight: bold; line-height: 1.4em; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;&quot;&gt;=&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;line&quot; id=&quot;LC36&quot; style=&quot;line-height: 1.4em; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 1em; padding-right: 0px; padding-top: 0px;&quot;&gt;



&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;  &lt;span class=&quot;k&quot; style=&quot;font-weight: bold; line-height: 1.4em; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;o&quot; style=&quot;font-weight: bold; line-height: 1.4em; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot; style=&quot;line-height: 1.4em; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;&quot;&gt;q&lt;/span&gt; &lt;span class=&quot;o&quot; style=&quot;font-weight: bold; line-height: 1.4em; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;&quot;&gt;==&lt;/span&gt; &lt;span class=&quot;n&quot; style=&quot;line-height: 1.4em; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;&quot;&gt;qf&lt;/span&gt; &lt;span class=&quot;o&quot; style=&quot;font-weight: bold; line-height: 1.4em; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;n&quot; style=&quot;line-height: 1.4em; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;&quot;&gt;t&lt;/span&gt; &lt;span class=&quot;k&quot; style=&quot;font-weight: bold; line-height: 1.4em; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;&quot;&gt;else&lt;/span&gt; &lt;span class=&quot;o&quot; style=&quot;font-weight: bold; line-height: 1.4em; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;&quot;&gt;{&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;line&quot; id=&quot;LC37&quot; style=&quot;line-height: 1.4em; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 1em; padding-right: 0px; padding-top: 0px;&quot;&gt;



&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span class=&quot;k&quot; style=&quot;font-weight: bold; line-height: 1.4em; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;&quot;&gt;val&lt;/span&gt; &lt;span class=&quot;o&quot; style=&quot;font-weight: bold; line-height: 1.4em; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot; style=&quot;line-height: 1.4em; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;&quot;&gt;qnew&lt;/span&gt;&lt;span class=&quot;o&quot; style=&quot;font-weight: bold; line-height: 1.4em; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;n&quot; style=&quot;line-height: 1.4em; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;&quot;&gt;c&lt;/span&gt;&lt;span class=&quot;o&quot; style=&quot;font-weight: bold; line-height: 1.4em; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;n&quot; style=&quot;line-height: 1.4em; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;&quot;&gt;move&lt;/span&gt;&lt;span class=&quot;o&quot; style=&quot;font-weight: bold; line-height: 1.4em; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;&quot;&gt;)=&lt;/span&gt;&lt;span class=&quot;n&quot; style=&quot;line-height: 1.4em; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;&quot;&gt;tm&lt;/span&gt; &lt;span class=&quot;o&quot; style=&quot;font-weight: bold; line-height: 1.4em; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot; style=&quot;line-height: 1.4em; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;&quot;&gt;q&lt;/span&gt;&lt;span class=&quot;o&quot; style=&quot;font-weight: bold; line-height: 1.4em; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;&quot;&gt;)(&lt;/span&gt;&lt;span class=&quot;n&quot; style=&quot;line-height: 1.4em; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;&quot;&gt;t&lt;/span&gt;&lt;span class=&quot;o&quot; style=&quot;font-weight: bold; line-height: 1.4em; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot; style=&quot;line-height: 1.4em; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;&quot;&gt;head&lt;/span&gt;&lt;span class=&quot;o&quot; style=&quot;font-weight: bold; line-height: 1.4em; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;&quot;&gt;);&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;line&quot; id=&quot;LC38&quot; style=&quot;line-height: 1.4em; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 1em; padding-right: 0px; padding-top: 0px;&quot;&gt;



&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span class=&quot;n&quot; style=&quot;line-height: 1.4em; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;&quot;&gt;step&lt;/span&gt;&lt;span class=&quot;o&quot; style=&quot;font-weight: bold; line-height: 1.4em; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot; style=&quot;line-height: 1.4em; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;&quot;&gt;qnew&lt;/span&gt;&lt;span class=&quot;o&quot; style=&quot;font-weight: bold; line-height: 1.4em; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;n&quot; style=&quot;line-height: 1.4em; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;&quot;&gt;move&lt;/span&gt;&lt;span class=&quot;o&quot; style=&quot;font-weight: bold; line-height: 1.4em; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot; style=&quot;line-height: 1.4em; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;&quot;&gt;write&lt;/span&gt;&lt;span class=&quot;o&quot; style=&quot;font-weight: bold; line-height: 1.4em; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot; style=&quot;line-height: 1.4em; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;&quot;&gt;c&lt;/span&gt;&lt;span class=&quot;o&quot; style=&quot;font-weight: bold; line-height: 1.4em; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;n&quot; style=&quot;line-height: 1.4em; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;&quot;&gt;t&lt;/span&gt;&lt;span class=&quot;o&quot; style=&quot;font-weight: bold; line-height: 1.4em; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;&quot;&gt;)),&lt;/span&gt;&lt;span class=&quot;n&quot; style=&quot;line-height: 1.4em; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;&quot;&gt;tm&lt;/span&gt;&lt;span class=&quot;o&quot; style=&quot;font-weight: bold; line-height: 1.4em; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;n&quot; style=&quot;line-height: 1.4em; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;&quot;&gt;qf&lt;/span&gt;&lt;span class=&quot;o&quot; style=&quot;font-weight: bold; line-height: 1.4em; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;&quot;&gt;)&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;line&quot; id=&quot;LC39&quot; style=&quot;line-height: 1.4em; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 1em; padding-right: 0px; padding-top: 0px;&quot;&gt;



&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span class=&quot;o&quot; style=&quot;font-weight: bold; line-height: 1.4em; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;&quot;&gt;}&lt;/span&gt;&lt;/div&gt;
&lt;/pre&gt;
&lt;/script&gt;
&lt;br /&gt;
We have q: the current state, t:the tape (and head), tm is the transition matrix and qf is the final state, because we need to know when to stop. If we&#39;re in the final state, we return the tape, if not, we&amp;nbsp;look-up&amp;nbsp;the state, symbol and move for &amp;nbsp;the current state and symbol on the head of the tape and recursively call step again with the new state, the result of writing the new symbol on the tape and the same transition matrix and final state. Because the call to step is the last function we call, we can optimize the recursive call with @tailrec.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;h3&gt;





An example&lt;/h3&gt;
&lt;div&gt;
Here is an example, the turing machine I wanted to test is the following:&lt;/div&gt;
Given an imput string in the form b&lt;span style=&quot;font-size: xx-small;&quot;&gt;n&lt;/span&gt;#1^k , where&amp;nbsp;b&lt;span style=&quot;font-size: xx-small;&quot;&gt;n &lt;/span&gt;is&lt;span style=&quot;font-size: xx-small;&quot;&gt;&amp;nbsp;&lt;/span&gt;a binary representation of number&amp;nbsp;n and&amp;nbsp;1^k are &#39;1&#39; repeated k times, we want to calculate the binary number&amp;nbsp;b&lt;span style=&quot;font-size: xx-small;&quot;&gt;n+k &lt;/span&gt;. ( i.e. incrementing&amp;nbsp;b&lt;span style=&quot;font-size: xx-small;&quot;&gt;n &lt;/span&gt;by k&lt;span style=&quot;font-size: xx-small;&quot;&gt;)&lt;/span&gt;&lt;br /&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
&lt;script src=&quot;https://gist.github.com/1258371.js?file=TMsample.scala&quot;&gt;
&lt;pre style=&quot;font-family: &#39;Bitstream Vera Sans Mono&#39;, &#39;Courier New&#39;, monospace; font-size: 12px; line-height: 1.4em; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; text-align: left;&quot;&gt;&lt;div class=&quot;line&quot; id=&quot;LC43&quot; style=&quot;line-height: 1.4em; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 1em; padding-right: 0px; padding-top: 0px;&quot;&gt;



&lt;span class=&quot;k&quot; style=&quot;font-weight: bold; line-height: 1.4em; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;&quot;&gt;object&lt;/span&gt; &lt;span class=&quot;nc&quot; style=&quot;color: #445588; font-weight: bold; line-height: 1.4em; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;&quot;&gt;TMsample&lt;/span&gt; &lt;span class=&quot;k&quot; style=&quot;font-weight: bold; line-height: 1.4em; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;&quot;&gt;extends&lt;/span&gt; &lt;span class=&quot;nc&quot; style=&quot;color: #445588; font-weight: bold; line-height: 1.4em; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;&quot;&gt;App&lt;/span&gt; &lt;span class=&quot;o&quot; style=&quot;font-weight: bold; line-height: 1.4em; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;&quot;&gt;{&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;line&quot; id=&quot;LC44&quot; style=&quot;line-height: 1.4em; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 1em; padding-right: 0px; padding-top: 0px;&quot;&gt;



&lt;/div&gt;
&lt;div class=&quot;line&quot; id=&quot;LC45&quot; style=&quot;line-height: 1.4em; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 1em; padding-right: 0px; padding-top: 0px;&quot;&gt;



&amp;nbsp;&amp;nbsp;&lt;span class=&quot;k&quot; style=&quot;font-weight: bold; line-height: 1.4em; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;&quot;&gt;val&lt;/span&gt; &lt;span class=&quot;n&quot; style=&quot;line-height: 1.4em; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;&quot;&gt;machine&lt;/span&gt;&lt;span class=&quot;o&quot; style=&quot;font-weight: bold; line-height: 1.4em; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;k&quot; style=&quot;font-weight: bold; line-height: 1.4em; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;&quot;&gt;new&lt;/span&gt; &lt;span class=&quot;nc&quot; style=&quot;color: #445588; font-weight: bold; line-height: 1.4em; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;&quot;&gt;TuringMachine&lt;/span&gt;&lt;span class=&quot;o&quot; style=&quot;font-weight: bold; line-height: 1.4em; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;kt&quot; style=&quot;color: #445588; font-weight: bold; line-height: 1.4em; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;&quot;&gt;Symbol&lt;/span&gt;&lt;span class=&quot;o&quot; style=&quot;font-weight: bold; line-height: 1.4em; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;&quot;&gt;]()&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;line&quot; id=&quot;LC46&quot; style=&quot;line-height: 1.4em; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 1em; padding-right: 0px; padding-top: 0px;&quot;&gt;



&amp;nbsp;&amp;nbsp;&lt;span class=&quot;k&quot; style=&quot;font-weight: bold; line-height: 1.4em; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;&quot;&gt;import&lt;/span&gt; &lt;span class=&quot;nn&quot; style=&quot;color: #555555; line-height: 1.4em; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;&quot;&gt;machine._&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;line&quot; id=&quot;LC48&quot; style=&quot;line-height: 1.4em; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 1em; padding-right: 0px; padding-top: 0px;&quot;&gt;



&amp;nbsp;&amp;nbsp;&lt;span class=&quot;c1&quot; style=&quot;color: #999988; font-style: italic; line-height: 1.4em; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;&quot;&gt;// map current state -&gt; symbol -&gt; (new state, symbol to write, direction ) &lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;line&quot; id=&quot;LC49&quot; style=&quot;line-height: 1.4em; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 1em; padding-right: 0px; padding-top: 0px;&quot;&gt;



&amp;nbsp;&amp;nbsp;&lt;span class=&quot;k&quot; style=&quot;font-weight: bold; line-height: 1.4em; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;&quot;&gt;val&lt;/span&gt; &lt;span class=&quot;n&quot; style=&quot;line-height: 1.4em; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;&quot;&gt;tm&lt;/span&gt;&lt;span class=&quot;k&quot; style=&quot;font-weight: bold; line-height: 1.4em; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;kt&quot; style=&quot;color: #445588; font-weight: bold; line-height: 1.4em; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;&quot;&gt;TrnsMtrx&lt;/span&gt; &lt;span class=&quot;o&quot; style=&quot;font-weight: bold; line-height: 1.4em; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;nc&quot; style=&quot;color: #445588; font-weight: bold; line-height: 1.4em; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;&quot;&gt;Map&lt;/span&gt;&lt;span class=&quot;o&quot; style=&quot;font-weight: bold; line-height: 1.4em; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;&quot;&gt;(&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;line&quot; id=&quot;LC50&quot; style=&quot;line-height: 1.4em; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 1em; padding-right: 0px; padding-top: 0px;&quot;&gt;



&lt;span class=&quot;-Symbol&quot; style=&quot;line-height: 1.4em; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;&quot;&gt;&#39;q1&lt;/span&gt;&lt;span class=&quot;o&quot; style=&quot;font-weight: bold; line-height: 1.4em; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;&quot;&gt;-&gt;&lt;/span&gt;&lt;span class=&quot;nc&quot; style=&quot;color: #445588; font-weight: bold; line-height: 1.4em; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;&quot;&gt;Map&lt;/span&gt;&lt;span class=&quot;o&quot; style=&quot;font-weight: bold; line-height: 1.4em; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;sc&quot; style=&quot;color: #dd1144; line-height: 1.4em; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;&quot;&gt;&#39;1&#39;&lt;/span&gt;&lt;span class=&quot;o&quot; style=&quot;font-weight: bold; line-height: 1.4em; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;&quot;&gt;-&gt;(&lt;/span&gt;&lt;span class=&quot;-Symbol&quot; style=&quot;line-height: 1.4em; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;&quot;&gt;&#39;q1&lt;/span&gt;&lt;span class=&quot;o&quot; style=&quot;font-weight: bold; line-height: 1.4em; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;sc&quot; style=&quot;color: #dd1144; line-height: 1.4em; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;&quot;&gt;&#39;1&#39;&lt;/span&gt;&lt;span class=&quot;o&quot; style=&quot;font-weight: bold; line-height: 1.4em; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;n&quot; style=&quot;line-height: 1.4em; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;&quot;&gt;D&lt;/span&gt;&lt;span class=&quot;o&quot; style=&quot;font-weight: bold; line-height: 1.4em; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;&quot;&gt;),&lt;/span&gt; &lt;span class=&quot;sc&quot; style=&quot;color: #dd1144; line-height: 1.4em; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;&quot;&gt;&#39;0&#39;&lt;/span&gt;&lt;span class=&quot;o&quot; style=&quot;font-weight: bold; line-height: 1.4em; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;&quot;&gt;-&gt;(&lt;/span&gt;&lt;span class=&quot;-Symbol&quot; style=&quot;line-height: 1.4em; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;&quot;&gt;&#39;q1&lt;/span&gt;&lt;span class=&quot;o&quot; style=&quot;font-weight: bold; line-height: 1.4em; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;sc&quot; style=&quot;color: #dd1144; line-height: 1.4em; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;&quot;&gt;&#39;0&#39;&lt;/span&gt;&lt;span class=&quot;o&quot; style=&quot;font-weight: bold; line-height: 1.4em; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;n&quot; style=&quot;line-height: 1.4em; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;&quot;&gt;D&lt;/span&gt;&lt;span class=&quot;o&quot; style=&quot;font-weight: bold; line-height: 1.4em; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;&quot;&gt;),&lt;/span&gt; &lt;span class=&quot;sc&quot; style=&quot;color: #dd1144; line-height: 1.4em; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;&quot;&gt;&#39;#&#39;&lt;/span&gt;&lt;span class=&quot;o&quot; style=&quot;font-weight: bold; line-height: 1.4em; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;&quot;&gt;-&gt;(&lt;/span&gt;&lt;span class=&quot;-Symbol&quot; style=&quot;line-height: 1.4em; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;&quot;&gt;&#39;q1&lt;/span&gt;&lt;span class=&quot;o&quot; style=&quot;font-weight: bold; line-height: 1.4em; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;sc&quot; style=&quot;color: #dd1144; line-height: 1.4em; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;&quot;&gt;&#39;#&#39;&lt;/span&gt;&lt;span class=&quot;o&quot; style=&quot;font-weight: bold; line-height: 1.4em; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;n&quot; style=&quot;line-height: 1.4em; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;&quot;&gt;D&lt;/span&gt;&lt;span class=&quot;o&quot; style=&quot;font-weight: bold; line-height: 1.4em; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;&quot;&gt;),&lt;/span&gt; &lt;span class=&quot;n&quot; style=&quot;line-height: 1.4em; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;&quot;&gt;b&lt;/span&gt;&lt;span class=&quot;o&quot; style=&quot;font-weight: bold; line-height: 1.4em; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;&quot;&gt;-&gt;(&lt;/span&gt;&lt;span class=&quot;-Symbol&quot; style=&quot;line-height: 1.4em; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;&quot;&gt;&#39;q2&lt;/span&gt;&lt;span class=&quot;o&quot; style=&quot;font-weight: bold; line-height: 1.4em; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;n&quot; style=&quot;line-height: 1.4em; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;&quot;&gt;b&lt;/span&gt;&lt;span class=&quot;o&quot; style=&quot;font-weight: bold; line-height: 1.4em; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;n&quot; style=&quot;line-height: 1.4em; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;&quot;&gt;I&lt;/span&gt;&lt;span class=&quot;o&quot; style=&quot;font-weight: bold; line-height: 1.4em; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;&quot;&gt;)),&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;line&quot; id=&quot;LC51&quot; style=&quot;line-height: 1.4em; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 1em; padding-right: 0px; padding-top: 0px;&quot;&gt;



&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span class=&quot;-Symbol&quot; style=&quot;line-height: 1.4em; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;&quot;&gt;&#39;q2&lt;/span&gt;&lt;span class=&quot;o&quot; style=&quot;font-weight: bold; line-height: 1.4em; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;&quot;&gt;-&gt;&lt;/span&gt;&lt;span class=&quot;nc&quot; style=&quot;color: #445588; font-weight: bold; line-height: 1.4em; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;&quot;&gt;Map&lt;/span&gt;&lt;span class=&quot;o&quot; style=&quot;font-weight: bold; line-height: 1.4em; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;sc&quot; style=&quot;color: #dd1144; line-height: 1.4em; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;&quot;&gt;&#39;1&#39;&lt;/span&gt;&lt;span class=&quot;o&quot; style=&quot;font-weight: bold; line-height: 1.4em; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;&quot;&gt;-&gt;(&lt;/span&gt;&lt;span class=&quot;-Symbol&quot; style=&quot;line-height: 1.4em; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;&quot;&gt;&#39;q3&lt;/span&gt;&lt;span class=&quot;o&quot; style=&quot;font-weight: bold; line-height: 1.4em; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;n&quot; style=&quot;line-height: 1.4em; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;&quot;&gt;b&lt;/span&gt;&lt;span class=&quot;o&quot; style=&quot;font-weight: bold; line-height: 1.4em; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;n&quot; style=&quot;line-height: 1.4em; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;&quot;&gt;I&lt;/span&gt;&lt;span class=&quot;o&quot; style=&quot;font-weight: bold; line-height: 1.4em; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;&quot;&gt;),&lt;/span&gt; &lt;span class=&quot;sc&quot; style=&quot;color: #dd1144; line-height: 1.4em; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;&quot;&gt;&#39;#&#39;&lt;/span&gt;&lt;span class=&quot;o&quot; style=&quot;font-weight: bold; line-height: 1.4em; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;&quot;&gt;-&gt;(&lt;/span&gt;&lt;span class=&quot;-Symbol&quot; style=&quot;line-height: 1.4em; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;&quot;&gt;&#39;qf&lt;/span&gt;&lt;span class=&quot;o&quot; style=&quot;font-weight: bold; line-height: 1.4em; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;n&quot; style=&quot;line-height: 1.4em; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;&quot;&gt;b&lt;/span&gt;&lt;span class=&quot;o&quot; style=&quot;font-weight: bold; line-height: 1.4em; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;n&quot; style=&quot;line-height: 1.4em; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;&quot;&gt;I&lt;/span&gt;&lt;span class=&quot;o&quot; style=&quot;font-weight: bold; line-height: 1.4em; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;&quot;&gt;)),&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;line&quot; id=&quot;LC52&quot; style=&quot;line-height: 1.4em; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 1em; padding-right: 0px; padding-top: 0px;&quot;&gt;



&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span class=&quot;-Symbol&quot; style=&quot;line-height: 1.4em; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;&quot;&gt;&#39;q3&lt;/span&gt;&lt;span class=&quot;o&quot; style=&quot;font-weight: bold; line-height: 1.4em; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;&quot;&gt;-&gt;&lt;/span&gt;&lt;span class=&quot;nc&quot; style=&quot;color: #445588; font-weight: bold; line-height: 1.4em; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;&quot;&gt;Map&lt;/span&gt;&lt;span class=&quot;o&quot; style=&quot;font-weight: bold; line-height: 1.4em; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;sc&quot; style=&quot;color: #dd1144; line-height: 1.4em; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;&quot;&gt;&#39;1&#39;&lt;/span&gt;&lt;span class=&quot;o&quot; style=&quot;font-weight: bold; line-height: 1.4em; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;&quot;&gt;-&gt;(&lt;/span&gt;&lt;span class=&quot;-Symbol&quot; style=&quot;line-height: 1.4em; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;&quot;&gt;&#39;q3&lt;/span&gt;&lt;span class=&quot;o&quot; style=&quot;font-weight: bold; line-height: 1.4em; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;sc&quot; style=&quot;color: #dd1144; line-height: 1.4em; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;&quot;&gt;&#39;1&#39;&lt;/span&gt;&lt;span class=&quot;o&quot; style=&quot;font-weight: bold; line-height: 1.4em; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;n&quot; style=&quot;line-height: 1.4em; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;&quot;&gt;I&lt;/span&gt;&lt;span class=&quot;o&quot; style=&quot;font-weight: bold; line-height: 1.4em; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;&quot;&gt;),&lt;/span&gt;&lt;span class=&quot;sc&quot; style=&quot;color: #dd1144; line-height: 1.4em; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;&quot;&gt;&#39;#&#39;&lt;/span&gt;&lt;span class=&quot;o&quot; style=&quot;font-weight: bold; line-height: 1.4em; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;&quot;&gt;-&gt;(&lt;/span&gt;&lt;span class=&quot;-Symbol&quot; style=&quot;line-height: 1.4em; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;&quot;&gt;&#39;q4&lt;/span&gt;&lt;span class=&quot;o&quot; style=&quot;font-weight: bold; line-height: 1.4em; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;sc&quot; style=&quot;color: #dd1144; line-height: 1.4em; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;&quot;&gt;&#39;#&#39;&lt;/span&gt;&lt;span class=&quot;o&quot; style=&quot;font-weight: bold; line-height: 1.4em; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;n&quot; style=&quot;line-height: 1.4em; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;&quot;&gt;I&lt;/span&gt;&lt;span class=&quot;o&quot; style=&quot;font-weight: bold; line-height: 1.4em; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;&quot;&gt;)),&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;line&quot; id=&quot;LC53&quot; style=&quot;line-height: 1.4em; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 1em; padding-right: 0px; padding-top: 0px;&quot;&gt;



&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span class=&quot;-Symbol&quot; style=&quot;line-height: 1.4em; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;&quot;&gt;&#39;q4&lt;/span&gt;&lt;span class=&quot;o&quot; style=&quot;font-weight: bold; line-height: 1.4em; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;&quot;&gt;-&gt;&lt;/span&gt;&lt;span class=&quot;nc&quot; style=&quot;color: #445588; font-weight: bold; line-height: 1.4em; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;&quot;&gt;Map&lt;/span&gt;&lt;span class=&quot;o&quot; style=&quot;font-weight: bold; line-height: 1.4em; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;sc&quot; style=&quot;color: #dd1144; line-height: 1.4em; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;&quot;&gt;&#39;1&#39;&lt;/span&gt;&lt;span class=&quot;o&quot; style=&quot;font-weight: bold; line-height: 1.4em; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;&quot;&gt;-&gt;(&lt;/span&gt;&lt;span class=&quot;-Symbol&quot; style=&quot;line-height: 1.4em; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;&quot;&gt;&#39;q4&lt;/span&gt;&lt;span class=&quot;o&quot; style=&quot;font-weight: bold; line-height: 1.4em; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;sc&quot; style=&quot;color: #dd1144; line-height: 1.4em; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;&quot;&gt;&#39;0&#39;&lt;/span&gt;&lt;span class=&quot;o&quot; style=&quot;font-weight: bold; line-height: 1.4em; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;n&quot; style=&quot;line-height: 1.4em; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;&quot;&gt;I&lt;/span&gt;&lt;span class=&quot;o&quot; style=&quot;font-weight: bold; line-height: 1.4em; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;&quot;&gt;),&lt;/span&gt;&lt;span class=&quot;sc&quot; style=&quot;color: #dd1144; line-height: 1.4em; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;&quot;&gt;&#39;0&#39;&lt;/span&gt;&lt;span class=&quot;o&quot; style=&quot;font-weight: bold; line-height: 1.4em; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;&quot;&gt;-&gt;(&lt;/span&gt;&lt;span class=&quot;-Symbol&quot; style=&quot;line-height: 1.4em; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;&quot;&gt;&#39;q1&lt;/span&gt;&lt;span class=&quot;o&quot; style=&quot;font-weight: bold; line-height: 1.4em; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;sc&quot; style=&quot;color: #dd1144; line-height: 1.4em; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;&quot;&gt;&#39;1&#39;&lt;/span&gt;&lt;span class=&quot;o&quot; style=&quot;font-weight: bold; line-height: 1.4em; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;n&quot; style=&quot;line-height: 1.4em; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;&quot;&gt;D&lt;/span&gt;&lt;span class=&quot;o&quot; style=&quot;font-weight: bold; line-height: 1.4em; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;&quot;&gt;),&lt;/span&gt;&lt;span class=&quot;n&quot; style=&quot;line-height: 1.4em; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;&quot;&gt;b&lt;/span&gt;&lt;span class=&quot;o&quot; style=&quot;font-weight: bold; line-height: 1.4em; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;&quot;&gt;-&gt;(&lt;/span&gt;&lt;span class=&quot;-Symbol&quot; style=&quot;line-height: 1.4em; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;&quot;&gt;&#39;q1&lt;/span&gt;&lt;span class=&quot;o&quot; style=&quot;font-weight: bold; line-height: 1.4em; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;sc&quot; style=&quot;color: #dd1144; line-height: 1.4em; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;&quot;&gt;&#39;1&#39;&lt;/span&gt;&lt;span class=&quot;o&quot; style=&quot;font-weight: bold; line-height: 1.4em; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;n&quot; style=&quot;line-height: 1.4em; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;&quot;&gt;D&lt;/span&gt;&lt;span class=&quot;o&quot; style=&quot;font-weight: bold; line-height: 1.4em; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;&quot;&gt;))&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;line&quot; id=&quot;LC54&quot; style=&quot;line-height: 1.4em; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 1em; padding-right: 0px; padding-top: 0px;&quot;&gt;



&amp;nbsp;&amp;nbsp;&lt;span class=&quot;o&quot; style=&quot;font-weight: bold; line-height: 1.4em; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;&quot;&gt;)&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;line&quot; id=&quot;LC55&quot; style=&quot;line-height: 1.4em; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 1em; padding-right: 0px; padding-top: 0px;&quot;&gt;



&amp;nbsp;&amp;nbsp;&lt;/div&gt;
&lt;div class=&quot;line&quot; id=&quot;LC56&quot; style=&quot;line-height: 1.4em; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 1em; padding-right: 0px; padding-top: 0px;&quot;&gt;



&amp;nbsp;&amp;nbsp;&lt;span class=&quot;n&quot; style=&quot;line-height: 1.4em; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;&quot;&gt;println&lt;/span&gt; &lt;span class=&quot;o&quot; style=&quot;font-weight: bold; line-height: 1.4em; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;&quot;&gt;(&lt;/span&gt; &lt;span class=&quot;n&quot; style=&quot;line-height: 1.4em; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;&quot;&gt;step&lt;/span&gt; &lt;span class=&quot;o&quot; style=&quot;font-weight: bold; line-height: 1.4em; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;-Symbol&quot; style=&quot;line-height: 1.4em; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;&quot;&gt;&#39;q1&lt;/span&gt;&lt;span class=&quot;o&quot; style=&quot;font-weight: bold; line-height: 1.4em; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot; style=&quot;line-height: 1.4em; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;&quot;&gt;tape&lt;/span&gt;&lt;span class=&quot;o&quot; style=&quot;font-weight: bold; line-height: 1.4em; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot; style=&quot;color: #dd1144; line-height: 1.4em; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;&quot;&gt;&quot;0#11&quot;&lt;/span&gt;&lt;span class=&quot;o&quot; style=&quot;font-weight: bold; line-height: 1.4em; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;&quot;&gt;),&lt;/span&gt; &lt;span class=&quot;n&quot; style=&quot;line-height: 1.4em; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;&quot;&gt;tm&lt;/span&gt;&lt;span class=&quot;o&quot; style=&quot;font-weight: bold; line-height: 1.4em; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;-Symbol&quot; style=&quot;line-height: 1.4em; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;&quot;&gt;&#39;qf&lt;/span&gt;&lt;span class=&quot;o&quot; style=&quot;font-weight: bold; line-height: 1.4em; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;&quot;&gt;))&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;line&quot; id=&quot;LC57&quot; style=&quot;line-height: 1.4em; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 1em; padding-right: 0px; padding-top: 0px;&quot;&gt;



&amp;nbsp;&amp;nbsp;&lt;span class=&quot;n&quot; style=&quot;line-height: 1.4em; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;&quot;&gt;println&lt;/span&gt; &lt;span class=&quot;o&quot; style=&quot;font-weight: bold; line-height: 1.4em; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;&quot;&gt;(&lt;/span&gt; &lt;span class=&quot;n&quot; style=&quot;line-height: 1.4em; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;&quot;&gt;step&lt;/span&gt; &lt;span class=&quot;o&quot; style=&quot;font-weight: bold; line-height: 1.4em; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;-Symbol&quot; style=&quot;line-height: 1.4em; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;&quot;&gt;&#39;q1&lt;/span&gt;&lt;span class=&quot;o&quot; style=&quot;font-weight: bold; line-height: 1.4em; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot; style=&quot;line-height: 1.4em; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;&quot;&gt;tape&lt;/span&gt;&lt;span class=&quot;o&quot; style=&quot;font-weight: bold; line-height: 1.4em; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot; style=&quot;color: #dd1144; line-height: 1.4em; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;&quot;&gt;&quot;100#&quot;&lt;/span&gt; &lt;span class=&quot;o&quot; style=&quot;font-weight: bold; line-height: 1.4em; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;&quot;&gt;),&lt;/span&gt; &lt;span class=&quot;n&quot; style=&quot;line-height: 1.4em; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;&quot;&gt;tm&lt;/span&gt;&lt;span class=&quot;o&quot; style=&quot;font-weight: bold; line-height: 1.4em; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;-Symbol&quot; style=&quot;line-height: 1.4em; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;&quot;&gt;&#39;qf&lt;/span&gt;&lt;span class=&quot;o&quot; style=&quot;font-weight: bold; line-height: 1.4em; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;&quot;&gt;))&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;line&quot; id=&quot;LC58&quot; style=&quot;line-height: 1.4em; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 1em; padding-right: 0px; padding-top: 0px;&quot;&gt;



&amp;nbsp;&amp;nbsp;&lt;span class=&quot;n&quot; style=&quot;line-height: 1.4em; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;&quot;&gt;println&lt;/span&gt; &lt;span class=&quot;o&quot; style=&quot;font-weight: bold; line-height: 1.4em; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;&quot;&gt;(&lt;/span&gt; &lt;span class=&quot;n&quot; style=&quot;line-height: 1.4em; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;&quot;&gt;step&lt;/span&gt; &lt;span class=&quot;o&quot; style=&quot;font-weight: bold; line-height: 1.4em; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;-Symbol&quot; style=&quot;line-height: 1.4em; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;&quot;&gt;&#39;q1&lt;/span&gt;&lt;span class=&quot;o&quot; style=&quot;font-weight: bold; line-height: 1.4em; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot; style=&quot;line-height: 1.4em; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;&quot;&gt;tape&lt;/span&gt;&lt;span class=&quot;o&quot; style=&quot;font-weight: bold; line-height: 1.4em; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot; style=&quot;color: #dd1144; line-height: 1.4em; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;&quot;&gt;&quot;1000#11&quot;&lt;/span&gt; &lt;span class=&quot;o&quot; style=&quot;font-weight: bold; line-height: 1.4em; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;&quot;&gt;),&lt;/span&gt; &lt;span class=&quot;n&quot; style=&quot;line-height: 1.4em; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;&quot;&gt;tm&lt;/span&gt;&lt;span class=&quot;o&quot; style=&quot;font-weight: bold; line-height: 1.4em; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;-Symbol&quot; style=&quot;line-height: 1.4em; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;&quot;&gt;&#39;qf&lt;/span&gt;&lt;span class=&quot;o&quot; style=&quot;font-weight: bold; line-height: 1.4em; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;&quot;&gt;))&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;line&quot; id=&quot;LC59&quot; style=&quot;line-height: 1.4em; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 1em; padding-right: 0px; padding-top: 0px;&quot;&gt;



&amp;nbsp;&amp;nbsp;&lt;span class=&quot;n&quot; style=&quot;line-height: 1.4em; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;&quot;&gt;println&lt;/span&gt; &lt;span class=&quot;o&quot; style=&quot;font-weight: bold; line-height: 1.4em; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;&quot;&gt;(&lt;/span&gt; &lt;span class=&quot;n&quot; style=&quot;line-height: 1.4em; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;&quot;&gt;step&lt;/span&gt; &lt;span class=&quot;o&quot; style=&quot;font-weight: bold; line-height: 1.4em; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;-Symbol&quot; style=&quot;line-height: 1.4em; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;&quot;&gt;&#39;q1&lt;/span&gt;&lt;span class=&quot;o&quot; style=&quot;font-weight: bold; line-height: 1.4em; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot; style=&quot;line-height: 1.4em; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;&quot;&gt;tape&lt;/span&gt;&lt;span class=&quot;o&quot; style=&quot;font-weight: bold; line-height: 1.4em; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot; style=&quot;color: #dd1144; line-height: 1.4em; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;&quot;&gt;&quot;1111#1&quot;&lt;/span&gt; &lt;span class=&quot;o&quot; style=&quot;font-weight: bold; line-height: 1.4em; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;&quot;&gt;),&lt;/span&gt; &lt;span class=&quot;n&quot; style=&quot;line-height: 1.4em; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;&quot;&gt;tm&lt;/span&gt;&lt;span class=&quot;o&quot; style=&quot;font-weight: bold; line-height: 1.4em; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;-Symbol&quot; style=&quot;line-height: 1.4em; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;&quot;&gt;&#39;qf&lt;/span&gt;&lt;span class=&quot;o&quot; style=&quot;font-weight: bold; line-height: 1.4em; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;&quot;&gt;))&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;line&quot; id=&quot;LC60&quot; style=&quot;line-height: 1.4em; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 1em; padding-right: 0px; padding-top: 0px;&quot;&gt;



&amp;nbsp;&amp;nbsp;&lt;span class=&quot;n&quot; style=&quot;line-height: 1.4em; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;&quot;&gt;println&lt;/span&gt; &lt;span class=&quot;o&quot; style=&quot;font-weight: bold; line-height: 1.4em; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;&quot;&gt;(&lt;/span&gt; &lt;span class=&quot;n&quot; style=&quot;line-height: 1.4em; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;&quot;&gt;step&lt;/span&gt; &lt;span class=&quot;o&quot; style=&quot;font-weight: bold; line-height: 1.4em; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;-Symbol&quot; style=&quot;line-height: 1.4em; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;&quot;&gt;&#39;q1&lt;/span&gt;&lt;span class=&quot;o&quot; style=&quot;font-weight: bold; line-height: 1.4em; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot; style=&quot;line-height: 1.4em; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;&quot;&gt;tape&lt;/span&gt;&lt;span class=&quot;o&quot; style=&quot;font-weight: bold; line-height: 1.4em; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot; style=&quot;color: #dd1144; line-height: 1.4em; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;&quot;&gt;&quot;1#11&quot;&lt;/span&gt; &lt;span class=&quot;o&quot; style=&quot;font-weight: bold; line-height: 1.4em; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;&quot;&gt;),&lt;/span&gt; &lt;span class=&quot;n&quot; style=&quot;line-height: 1.4em; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;&quot;&gt;tm&lt;/span&gt;&lt;span class=&quot;o&quot; style=&quot;font-weight: bold; line-height: 1.4em; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;-Symbol&quot; style=&quot;line-height: 1.4em; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;&quot;&gt;&#39;qf&lt;/span&gt;&lt;span class=&quot;o&quot; style=&quot;font-weight: bold; line-height: 1.4em; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;&quot;&gt;))&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;line&quot; id=&quot;LC61&quot; style=&quot;line-height: 1.4em; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 1em; padding-right: 0px; padding-top: 0px;&quot;&gt;



&amp;nbsp;&amp;nbsp;&lt;span class=&quot;n&quot; style=&quot;line-height: 1.4em; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;&quot;&gt;println&lt;/span&gt; &lt;span class=&quot;o&quot; style=&quot;font-weight: bold; line-height: 1.4em; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;&quot;&gt;(&lt;/span&gt; &lt;span class=&quot;n&quot; style=&quot;line-height: 1.4em; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;&quot;&gt;step&lt;/span&gt; &lt;span class=&quot;o&quot; style=&quot;font-weight: bold; line-height: 1.4em; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;-Symbol&quot; style=&quot;line-height: 1.4em; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;&quot;&gt;&#39;q1&lt;/span&gt;&lt;span class=&quot;o&quot; style=&quot;font-weight: bold; line-height: 1.4em; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot; style=&quot;line-height: 1.4em; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;&quot;&gt;tape&lt;/span&gt;&lt;span class=&quot;o&quot; style=&quot;font-weight: bold; line-height: 1.4em; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot; style=&quot;color: #dd1144; line-height: 1.4em; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;&quot;&gt;&quot;1#111&quot;&lt;/span&gt; &lt;span class=&quot;o&quot; style=&quot;font-weight: bold; line-height: 1.4em; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;&quot;&gt;),&lt;/span&gt; &lt;span class=&quot;n&quot; style=&quot;line-height: 1.4em; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;&quot;&gt;tm&lt;/span&gt;&lt;span class=&quot;o&quot; style=&quot;font-weight: bold; line-height: 1.4em; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;-Symbol&quot; style=&quot;line-height: 1.4em; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;&quot;&gt;&#39;qf&lt;/span&gt;&lt;span class=&quot;o&quot; style=&quot;font-weight: bold; line-height: 1.4em; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;&quot;&gt;))&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;line&quot; id=&quot;LC62&quot; style=&quot;line-height: 1.4em; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 1em; padding-right: 0px; padding-top: 0px;&quot;&gt;



&lt;/div&gt;
&lt;div class=&quot;line&quot; id=&quot;LC63&quot; style=&quot;line-height: 1.4em; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 1em; padding-right: 0px; padding-top: 0px;&quot;&gt;



&lt;span class=&quot;o&quot; style=&quot;font-weight: bold; line-height: 1.4em; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;&quot;&gt;}&lt;/span&gt;&lt;/div&gt;
&lt;/pre&gt;
&lt;/script&gt;
&lt;/div&gt;
&lt;br /&gt;
If we run the program, you&#39;ll see the expected results:&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;10&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;100&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;1010&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;10000&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;11&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;100&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
You can check the full code in github:&amp;nbsp;&lt;a href=&quot;https://gist.github.com/1258371&quot;&gt;https://gist.github.com/1258371&lt;/a&gt;&lt;br /&gt;
&lt;br /&gt;
Well, that&#39;s all :)&lt;br /&gt;
&lt;br /&gt;
&lt;h3&gt;


Conclusion&lt;/h3&gt;
&lt;div&gt;
There&#39;s an important conclusion to this: we implemented a Turing Machine in a purely functional way.&lt;/div&gt;
&lt;div&gt;
If we encode the &lt;a href=&quot;http://en.wikipedia.org/wiki/Universal_Turing_machine&quot;&gt;Universal Turing machine&lt;/a&gt;&amp;nbsp;in the transition table, we can feed the program itself on the tape.&amp;nbsp;Because is purely functional, we can directly translate our program to&lt;a href=&quot;http://en.wikipedia.org/wiki/Lambda_calculus&quot;&gt; lambda calculus&lt;/a&gt;, thus proving* that the lambda calculus is as powerful as a turning machine. If we come up with a lambda calculus implementation in a turing machine, you have the equivalence of the turing machine/lambda calculus models. Hint: implementing the lambda calculus interpreter in a turing machine is not far from what the Scala compiler and the JVM are doing in this case (or a Haskell interpreter for what is worth)&amp;nbsp;&lt;/div&gt;
&lt;div&gt;
*some handwaving required (or a lot), we&#39;re just fleas standing in the shoulder of &lt;a href=&quot;http://en.wikipedia.org/wiki/Church-Turing_Thesis&quot;&gt;gigants&lt;/a&gt;&lt;/div&gt;</description><link>http://gabrielsw.blogspot.com/2012/04/purely-functional-turing-machine.html</link><author>noreply@blogger.com (Anonymous)</author><thr:total>66</thr:total></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-6893032696317132921.post-7174828179182643716</guid><pubDate>Sat, 08 Oct 2011 04:26:00 +0000</pubDate><atom:updated>2011-10-12T10:37:19.979-04:00</atom:updated><category domain="http://www.blogger.com/atom/ns#">scala haskell functor monads java</category><title>Yes, Virginia, Scala can save you from Null Pointer Exceptions.</title><description>First,&amp;nbsp;Virginia, let me tell you that I don&#39;t know why everybody in the Scala community is&amp;nbsp;writing&amp;nbsp;to to you, I guess is because you&#39;re curious and want to learn about it, or maybe you know where to find the &amp;nbsp;mythical &quot;average programmer&quot;. But I digress...&lt;br /&gt;
&lt;br /&gt;
Let&#39;s focus on the subject of this post: how you can prevent null pointer exceptions with Scala. Suppose you have your&amp;nbsp;tidy Scala code in functional flavor with all the fixes, and you need to do a series of calls to a Java library, where each value depends on the previous value:&amp;nbsp;let&#39;s say you want to call functions A,B,and C.&lt;br /&gt;
&amp;nbsp; val x=A(in)&lt;br /&gt;
&amp;nbsp; val y=B(x)&lt;br /&gt;
&amp;nbsp; val z=C(y)&lt;br /&gt;
&lt;br /&gt;
(or C(B(A(in))) if you like )&lt;br /&gt;
&lt;br /&gt;
Now, is common in Java to return null when no value can be returned or even throw an exception if something goes wrong. How we prevent that? The naive approach will be to chain the ifs:&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp;&amp;nbsp; val x=A(in)&lt;br /&gt;
&amp;nbsp;&amp;nbsp; if (x != null){&lt;br /&gt;
&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; val y=B(x)&lt;br /&gt;
&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;if (x != null){&lt;br /&gt;
&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; val z=C(y)&lt;br /&gt;
&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; }&lt;br /&gt;
&amp;nbsp;&amp;nbsp; }&lt;br /&gt;
&lt;br /&gt;
I don&#39;t know you, but for me that style doesn&#39;t cut it anymore, is too verbose! And now our flow is littered with null checks, obscuring the purpose.&lt;br /&gt;
So, what we can do? I know! Let&#39;s use Scala&#39;s &lt;a href=&quot;http://www.scala-lang.org/api/rc/scala/Option.html&quot;&gt;Option&lt;/a&gt;&amp;nbsp;and write a small function that returns &quot;Some&quot; value or &quot;None&quot; if we got null or something wrong happened:&lt;br /&gt;
&lt;br /&gt;
&lt;script src=&quot;https://gist.github.com/1271271.js?file=unsafe.scala&quot;&gt;
&amp;nbsp;&amp;nbsp;def unsafeCall[T](x: =&gt;T):Option[T]=  try {
&amp;nbsp;&amp;nbsp;Option(x) 
&amp;nbsp;&amp;nbsp;} catch { 
&amp;nbsp;&amp;nbsp;case _ =&gt; None 
&amp;nbsp;&amp;nbsp;}
&lt;/script&gt;&lt;br /&gt;
&lt;br /&gt;
Nothing fancy here, Option(x) will evaluate x and return Some(x) if it has a value or None if is null. The only noteworthy thing here is in the signature: it defined as &quot; x:=&amp;gt; T &quot; that roughly means &quot;any function that returns something of type T&quot;, so x will be evaluated when we actually use it and not when we call the function, otherwise we risk getting the exception before entering the try block.&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp;Ok, so now we wrap every function call with our unsafeCall function, but now we have a problem, the types don&#39;t match! We can&#39;t just chain the calls, we need to extract the value from the Option first!&lt;br /&gt;
We can try with pattern matching:&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp; A(x) match {t&lt;br /&gt;
&amp;nbsp; &amp;nbsp; case None =&amp;gt; _&lt;br /&gt;
&amp;nbsp; &amp;nbsp; case &amp;nbsp;Some(y) =&amp;gt; B(y) match {&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; case None =&amp;gt; _&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; case &amp;nbsp;Some(z) =&amp;gt; C(z)&lt;br /&gt;
&amp;nbsp; &amp;nbsp; }&lt;br /&gt;
&amp;nbsp; }&lt;br /&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
But it looks clumsy and we don&#39;t gain much compared to the &quot;if not null&quot; version, what we can do?&lt;br /&gt;
Let&#39;s take a step back and look at the types: we want to chain a series of function with T=&amp;gt;Option[T] ... does it ring a bell? What if we write as T=&amp;gt;M[T] ? &lt;a href=&quot;http://gabrielsw.blogspot.com/2011/08/functors-applicative-functors-and.html&quot;&gt;If you&#39;ve said the M-word,&lt;/a&gt; bingo!&lt;br /&gt;
Some[_] is a monad, and that means we can use Scala&#39;s &quot;for&quot; notation.&lt;br /&gt;
Let&#39;s tie everything together in one example:&lt;br /&gt;
&lt;br /&gt;
&lt;script src=&quot;https://gist.github.com/1147238.js?file=SafeUnsafe.scala&quot;&gt;
package demo

class SafeUnsafe {

  def unsafe[T](x: =&gt;T):Option[T]=  try {
    Option(x) 
  } catch { 
    case _ =&gt; None 
  }


  def A(x:Int) = x+10
  def B(x:Int) = x.toString
  def C(s:String)=s+&quot;!&quot;
  def D(s:String)=&quot;Hell yeah, &quot;+s

  def KaPow(s:String):String= throw new Exception(&quot;KaPow!&quot;)

  def result(i:Int)=for (
    a&lt;- unsafe(A(i));
    b&lt;- unsafe(B(a));
    c&lt;- unsafe(C(b))
  ) yield D(c)


  def noResult(i:Int)= for (
    a&lt;- unsafe(A(i));
    b&lt;- unsafe(B(a));
    k&lt;- unsafe(KaPow(b));
    c&lt;- unsafe(C(k))
  ) yield D(c)

//scala&gt; result(1)
//res10: Option[java.lang.String] = Some(Hell yeah, 11!)

//scala&gt; noResult(1)
//res11: Option[java.lang.String] = None

}
&lt;/script&gt;&lt;/div&gt;
ADENDUM:
This is a toy example for illustrative purposes. I guess I should have left out the exceptions, otherwise is almost the same result as surrounding everything with a try/catch. Also, is an exception happens, we want to know what happens, for that Either is more suitable than Option (I&#39;ll leave that for another blog post).  
Still, when you need to chain a series of functions that return Some/None, for comprehensions gives you a nice sugar ;)</description><link>http://gabrielsw.blogspot.com/2011/10/yes-virginia-scala-can-save-you-from.html</link><author>noreply@blogger.com (Anonymous)</author><thr:total>10</thr:total></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-6893032696317132921.post-1510706158988336260</guid><pubDate>Thu, 18 Aug 2011 05:38:00 +0000</pubDate><atom:updated>2011-10-08T22:29:10.037-04:00</atom:updated><category domain="http://www.blogger.com/atom/ns#">scala haskell functor monads</category><title>Functors, Applicative Functors, and Monads aren&#39;t that scary</title><description>I&#39;m currently reading &quot;&lt;a href=&quot;http://learnyouahaskell.com/&quot;&gt;Learn You a Haskell for Great Good&lt;/a&gt;&quot; (really great book, if you want to learn Haskell, you can read it online or better, buy it now! ) and it has a very good explanation of Functors, Applicative Functors, and Monads. I refuse to write another Monad tutorial (I&#39;m not knowledgeable enough) but I&#39;ll write about what I&#39;ve understood so far. (Be kind enough to correct me)&lt;br /&gt;
&lt;br /&gt;
Here is all you need to know about functors, applicative functors, and monads (Haskell code):&lt;br /&gt;
&lt;br /&gt;
&lt;script src=&quot;https://gist.github.com/1140324.js?file=functors.hs&quot;&gt;
-- from &quot;Learn you a Haskell for great good&quot;

class Functor f where  
    fmap :: (a -&gt; b) -&gt; f a -&gt; f b  

class (Functor f) =&gt; Applicative f where  
    pure :: a -&gt; f a  
    (&lt;*&gt;) :: f (a -&gt; b) -&gt; f a -&gt; f b  

class (Applicative m) = &gt; Monad m where 
    (&gt;&gt;=) :: m a -&gt; (a -&gt; m b) -&gt; m b
&lt;/script&gt;&lt;br /&gt;
&lt;br /&gt;
Or it&#39;s equivalent Scala code:&lt;br /&gt;
&lt;script src=&quot;https://gist.github.com/1140324.js?file=Functor.scala&quot;&gt;
trait Functor[T[_]]{
  def fmap[A,B](f:A=&gt;B)(ta:T[A]):T[B]
}

trait Applicative[T[_]] extends Functor[T]{
  def pure[A](a:A):T[A]
  def &lt;*&gt;[A,B](tf:T[A=&gt;B])(ta:T[A]):T[B]
}

trait Monad[M[_]] extends Applicative[M]{
  def &gt;&gt;=[A,B](ma:M[A])(f:A=&gt;M[B]):M[B]
}
&lt;/script&gt;&lt;br /&gt;
&lt;br /&gt;
Crystal clear, isn&#39;t it? Just kidding. &lt;br /&gt;
IMPORTANT NOTE:THIS ARE ONLY THE THE TYPE SIGNATURES, ANY IMPLEMENTATION HAVE TO COMPLY WITH THE FUNCTOR/MONAD LAWS (see ADENDUM at the bottom)&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;&lt;span style=&quot;font-size: large;&quot;&gt;The TL;DR version&lt;/span&gt;&lt;/b&gt;&lt;br /&gt;
Want to apply a function to things in some &quot;context&quot;? Use a functor.&lt;br /&gt;
The functions are already in some &quot;context&quot;? Use applicative functor.&lt;br /&gt;
What if your function put things in the &quot;context&quot;? Use a Monad (... and flatMap that shit!)&lt;br /&gt;
That&#39;s all you need to know. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;&lt;span style=&quot;font-size: large;&quot;&gt;Functor&lt;/span&gt;&lt;/b&gt;&lt;br /&gt;
Let&#39;s start with the functor. &lt;br /&gt;
First, the trait has a type parameter, T[_]  (it&#39;s a polymorphic type constructor or higher kinded type, but you aren&#39;t the type that get scared easily, right?)&lt;br /&gt;
For now, you can consider it as a &quot;context&quot;: it can be a data structure, like a list, or something else that holds the parameter type inside plus whatever you want to add.&lt;br /&gt;
Let&#39;s look now at the method signature:&lt;br /&gt;
&amp;nbsp;&amp;nbsp;def fmap[A,B](f:A=&amp;gt;B)(ta:T[A]):T[B]&lt;br /&gt;
You take a function f from A to B, and ta context of A and returns a context of B.&lt;br /&gt;
In Scala collections is the map function. It transforms T[A] into T[B] by applying f to the elements wrapped &quot;inside&quot; T[A].&lt;br /&gt;
That&#39;s all you need for a functor! It doesn&#39;t look that scary...&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;&lt;span style=&quot;font-size: large;&quot;&gt;Applicative Functor&lt;/span&gt;&lt;/b&gt;&lt;br /&gt;
Now let&#39;s look at the applicative functor. For starters, the applicative functor is also a functor (I guess the &quot;functor&quot; in the name is a big hint) so we have the map function available. &lt;br /&gt;
With map, you can apply functions to things already in some context, but what if what you have in the context are functions? you need more than fmap to apply them.&lt;br /&gt;
Enter the applicative functor.&lt;br /&gt;
The applicative functor defines two methods pure and &amp;lt;*&amp;gt;:&lt;br /&gt;
&amp;nbsp;&amp;nbsp;def pure[A](a:A):T[A]&lt;br /&gt;
Pure is for putting things in the context, it takes an element of A and returns that element in the minimal context that makes sense (e.g. for lists, would be a list with a single element a).&lt;br /&gt;
The next function, &quot;apply&quot; or &amp;lt;*&amp;gt; (you can call it advanced TIE fighter or clenched angle arse if you want) takes functions already in the context and applies them to values in the context, yielding the results also in the context. The way it combines the functions with the values depends on the implementation of the applicative functor itself (e.g. for lists, it applies every function in the list of functions to every value in the list of values).&lt;br /&gt;
You can see &lt;a href=&quot;https://groups.google.com/d/msg/scala-user/uh5w6N2eAHY/3Shf1295VpYJ&quot;&gt;Tony&#39;s message to the Scala mailing list&lt;/a&gt; for an amazing example of why the applicative functor is useful.&lt;br /&gt;
&lt;br /&gt;
&lt;span style=&quot;font-size: large;&quot;&gt;&lt;b&gt;Monad&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;
And now, the famous Monad !. Monads are applicative functors, but with another method &quot;&amp;gt;&amp;gt;=&quot; (in Scala, you know it as flatMap ). We saw that applicative functors are like functors but the &amp;lt;*&amp;gt; allows you to apply functions already in a context unlike fmap wich needs the functions directly.  But what if you have a function that takes a value of A (outside a context) and returns a value of b &lt;i&gt;in &lt;/i&gt;the context? (they&#39;re pretty common: think of a function that may fail, returning Option[A] ). To apply those kind of functions to things already in the context is why we have &amp;gt;&amp;gt;= function: is pretty similar to the applicative functor&#39;s &quot;apply&quot; but instead of a function already in context, it takes a function from A to a context of B.&lt;br /&gt;
&lt;br /&gt;
For my next post, I want to show that using Option as a monad in Scala &lt;i&gt;CAN &lt;/i&gt;save you from NullPointerExceptions...&lt;br /&gt;
&lt;br /&gt;
Notes:&lt;br /&gt;
&lt;ul&gt;
&lt;li&gt;Eric explained most of this way better than me in&amp;nbsp; &lt;a href=&quot;http://etorreborre.blogspot.com/2011/06/essence-of-iterator-pattern.html&quot;&gt;&quot;The essence of the iterator pattern&quot;&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;The traits above are just for illustrative purposes, for the real thing use &lt;a href=&quot;http://code.google.com/p/scalaz/&quot;&gt;Scalaz&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;I&#39;m no authority, take all I&#39;ve said with a grain of salt, I just hope it helps in your explorations. For me, applicative functor was the missing piece in my understanding of monads. &lt;/li&gt;
&lt;/ul&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
ADENDUM:

There&#39;s a great (and WAY better than mine) explanation of all of this in Haskell&#39;s &lt;a href=&quot;http://www.haskell.org/wikiupload/e/e9/Typeclassopedia.pdf&quot;&gt;Typeclassopedia&lt;/a&gt;.

I don&#39;t know why nobody called me on it, but to actually have an instance of Functor/Applicative/Monad the implementation has to obey the following laws:&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: Arial, Helvetica, sans-serif;&quot;&gt;&lt;b&gt;Functor laws&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;fmap id = id&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;fmap (g . h) = fmap g . fmap&amp;nbsp;&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: Arial, Helvetica, sans-serif;&quot;&gt;&lt;b&gt;Applicative Functor laws&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;pure id &amp;lt;*&amp;gt; v = v &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;-- Identity&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;pure (.) &amp;lt;*&amp;gt; u &amp;lt;*&amp;gt; v &amp;lt;*&amp;gt; w = u &amp;lt;*&amp;gt; (v &amp;lt;*&amp;gt; w) -- Composition&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;pure f &amp;lt;*&amp;gt; pure x = pure (f x) &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; -- Homomorphism&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;u &amp;lt;*&amp;gt; pure y = pure ($ y) &amp;lt;*&amp;gt; u &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;-- Interchange&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: Arial, Helvetica, sans-serif;&quot;&gt;&lt;b&gt;Monad laws&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;m &amp;gt;&amp;gt;= return &amp;nbsp; &amp;nbsp; = &amp;nbsp;m &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;-- right unit&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;return x &amp;gt;&amp;gt;= f &amp;nbsp; = &amp;nbsp;f x &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;-- left unit&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;(m &amp;gt;&amp;gt;= f) &amp;gt;&amp;gt;= g &amp;nbsp;= &amp;nbsp;m &amp;gt;&amp;gt;= (\x -&amp;gt; f x &amp;gt;&amp;gt;= g) &amp;nbsp;-- associativity&lt;/span&gt;&lt;br /&gt;
</description><link>http://gabrielsw.blogspot.com/2011/08/functors-applicative-functors-and.html</link><author>noreply@blogger.com (Anonymous)</author><thr:total>4</thr:total></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-6893032696317132921.post-1699194274749545595</guid><pubDate>Fri, 16 Jul 2010 02:40:00 +0000</pubDate><atom:updated>2010-08-07T19:44:38.534-04:00</atom:updated><title>Short break for a long hiatus</title><description>&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiZFivP9S7bzXk7G2WXTy2pMjJx3Q_oEshVv35YVhGCIBg29mmtj0Cp7wBUh-4Bk9GKK0yd3Qkl0zgqyPX2no6LxNCfxxYrguu5_hrxmgY21XZYZOoTVISZQLpQlCVutUsFx-LXYk5fQT0/s1600/IMG_2825_6.JPG&quot; imageanchor=&quot;1&quot; style=&quot;clear: right; float: right; margin-bottom: 1em; margin-left: 1em;&quot;&gt;&lt;img border=&quot;0&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiZFivP9S7bzXk7G2WXTy2pMjJx3Q_oEshVv35YVhGCIBg29mmtj0Cp7wBUh-4Bk9GKK0yd3Qkl0zgqyPX2no6LxNCfxxYrguu5_hrxmgY21XZYZOoTVISZQLpQlCVutUsFx-LXYk5fQT0/s320/IMG_2825_6.JPG&quot; /&gt;&lt;/a&gt;&lt;/div&gt;Hi! Anybody out there?&lt;br /&gt;
I guess twitter totally killed whatever energy I had for blogging :)&lt;br /&gt;
For lazy people like me, the fact that instead of inaccurately express your idea in a couple of paragraph you&#39;re able to slap one phrase and that&#39;s enough is fantastic... it doesn&#39;t even need to be coherent!&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Noteworthy things that happen in between (in no particular order whatsoever):&lt;br /&gt;
&lt;ul&gt;&lt;li&gt;I&#39;m learning Scheme by the AWESOME book &quot;The Little Schemer&quot; (Amazon link: &lt;a href=&quot;http://www.amazon.com/gp/product/0262560992?ie=UTF8&amp;amp;tag=gabrielssoftw-20&amp;amp;linkCode=as2&amp;amp;camp=1789&amp;amp;creative=390957&amp;amp;creativeASIN=0262560992&quot;&gt;The Little Schemer - 4th Edition&lt;/a&gt;&lt;img alt=&quot;&quot; border=&quot;0&quot; height=&quot;1&quot; src=&quot;http://www.assoc-amazon.com/e/ir?t=gabrielssoftw-20&amp;amp;l=as2&amp;amp;o=1&amp;amp;a=0262560992&quot; style=&quot;border: medium none ! important; margin: 0px ! important;&quot; width=&quot;1&quot; /&gt;) and using &lt;a href=&quot;http://www.racket-lang.org/&quot;&gt;PLT Scheme / Racket&lt;/a&gt;. I&#39;m getting over to my aversion to prefix notation and now I can somehow understand Lisp code and I&#39;m getting ready to learn Clojure&amp;nbsp;&lt;/li&gt;
&lt;li&gt;I&#39;m back in my home country, Uruguay (go team! we made it to the semifinals!!)&lt;/li&gt;
&lt;li&gt; I badly broke my ankle, had two surgeries and I still limp after a couple of months&lt;/li&gt;
&lt;li&gt;I&#39;m expecting another baby!&lt;/li&gt;
&lt;li&gt;Scala 2.8 is out!!!!!!! Go get it while still hot&lt;/li&gt;
&lt;li&gt;I need to learn Haskell&lt;/li&gt;
&lt;li&gt;I went to the east coast Scala lift-off and meet awesome people&lt;/li&gt;
&lt;li&gt;Don&#39;t be afraid of powerful languages, believe it or not, they make your life easier&lt;/li&gt;
&lt;li&gt;I bought more Star wars legos than I needed &lt;/li&gt;
&lt;li&gt;I have a couple of unfinished blog posts that someday I&#39;ll finish :)&lt;/li&gt;
&lt;/ul&gt;Thanks for stopping by, I&#39;ll promise more useful posts in the future.&lt;br /&gt;
(I&#39;m adding a totally unrelated picture of a alien spider I found lying on a wall)</description><link>http://gabrielsw.blogspot.com/2010/07/short-break-for-long-hiatus.html</link><author>noreply@blogger.com (Anonymous)</author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiZFivP9S7bzXk7G2WXTy2pMjJx3Q_oEshVv35YVhGCIBg29mmtj0Cp7wBUh-4Bk9GKK0yd3Qkl0zgqyPX2no6LxNCfxxYrguu5_hrxmgY21XZYZOoTVISZQLpQlCVutUsFx-LXYk5fQT0/s72-c/IMG_2825_6.JPG" height="72" width="72"/><thr:total>3</thr:total></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-6893032696317132921.post-4312877071354991392</guid><pubDate>Tue, 02 Jun 2009 23:17:00 +0000</pubDate><atom:updated>2010-12-13T09:00:59.104-05:00</atom:updated><category domain="http://www.blogger.com/atom/ns#">DSL</category><category domain="http://www.blogger.com/atom/ns#">Scala</category><title>Boolean Algebra Internal DSL in Scala (aka fun with Unicode names )</title><description>In Scala, operator names can be characters from the unicode set of mathematical symbols (Sm) or other symbols (So). That can lead to interesting possibilities:&lt;br /&gt;
&lt;br /&gt;
&lt;p class=&quot;codebkg&quot; &gt;&lt;code class=&quot;prettyprint&quot;&gt;&lt;br /&gt;
val Π = Math.Pi&lt;br /&gt;
def √(x:Double)=Math.sqrt(x)&lt;br /&gt;
val x= √(9*Π)&lt;br /&gt;
&lt;/code&gt;&lt;br /&gt;
&lt;/p&gt;&lt;br /&gt;
Here, &quot;Π&quot; is just another constant and &quot;√&quot; is a function like &quot;q&quot;.&lt;br /&gt;
(To use  unicode in eclipse, you have to go to Preferences-&amp;gt;General-&amp;gt;Workspace, and change the text encoding to UTF-16)&lt;br /&gt;
&lt;br /&gt;
Another example: with the ∑ and ∏ you can have define summation and the product of a sequence as follows:&lt;br /&gt;
&lt;p class=&quot;codebkg&quot; &gt;&lt;code class=&quot;prettyprint&quot;&gt;&lt;br /&gt;
def ∑(r:Range)(f:Int =&amp;gt;Int)=r.reduceLeft(_+ f(_))&lt;br /&gt;
def ∏(r:Range)(f:Int =&amp;gt;Int)=r.reduceLeft(_* f(_))&lt;br /&gt;
&lt;/code&gt;&lt;br /&gt;
&lt;/p&gt;&lt;br /&gt;
And now we can write:&lt;br /&gt;
&lt;p class=&quot;codebkg&quot; &gt;&lt;code class=&quot;prettyprint&quot;&gt;&lt;br /&gt;
val s= ∑(1 to 100)(x=&amp;gt;x^2)&lt;br /&gt;
val p= ∑(1 to 100 by 2)(x=&amp;gt;x^2)&lt;br /&gt;
val y= ∏(1 to 30 by 3)(_)&lt;br /&gt;
&lt;/code&gt;&lt;br /&gt;
&lt;/p&gt;&lt;br /&gt;
Of course, I&#39;m not advocating using Scala as a substitute of a specific mathematical tool, besides, &lt;a href=&quot;http://en.wikipedia.org/wiki/APL_%28programming_language%29&quot;&gt;there&#39;s already a &quot;language with symbols&quot;&lt;/a&gt; (btw, I wonder if one can make a Scala &quot;skin&quot; that looks like APL). I&#39;m not sure how other languages can do this (except APL maybe?), but this goes to show the power of Scala for &quot;internal DSL&quot;.&lt;br /&gt;
&lt;br /&gt;
For a slightly more complex example, let&#39;s define an internal DSL for boolean logic, with the appropriate symbols: ¬,V,Λ,and →.&lt;br /&gt;
&lt;br /&gt;
&lt;p class=&quot;codebkg&quot; &gt;&lt;code class=&quot;prettyprint&quot;&gt;&lt;br /&gt;
class LogicBoolean(val value:Boolean) {&lt;br /&gt;
import LogicBoolean.¬&lt;br /&gt;
override def toString=value.toString&lt;br /&gt;
&lt;br /&gt;
def V(b:LogicBoolean)=new LogicBoolean(this.value || b.value)&lt;br /&gt;
def Λ(b:LogicBoolean)=new LogicBoolean(this.value &amp;amp;&amp;amp; b.value)&lt;br /&gt;
def →(b:LogicBoolean)=(¬(this)) V (this Λ b)&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
object LogicBoolean {&lt;br /&gt;
def ¬(a:LogicBoolean)=new LogicBoolean(!a.value)&lt;br /&gt;
implicit def boolToLogicBool(x:Boolean)=new LogicBoolean(x)&lt;br /&gt;
}&lt;br /&gt;
&lt;/code&gt;&lt;br /&gt;
&lt;/p&gt;&lt;br /&gt;
The only prefix operators that can be defined in Scala are ‘+’, ‘’, ‘!’ or ‘~’, so no luck for ¬. But we if we define it as a function, we can import it and use it (almost) like a prefix op. As we want an implicit conversion from boolean to our LogicBoolean class, a companion object is the ideal place to put both. By importing all the methods in the companion, we bring the ¬ operator and the implicit conversion into scope:&lt;br /&gt;
&lt;p class=&quot;codebkg&quot; &gt;&lt;code class=&quot;prettyprint&quot;&gt;&lt;br /&gt;
import LogicBoolean._&lt;br /&gt;
&lt;br /&gt;
val A=true&lt;br /&gt;
val B=false&lt;br /&gt;
&lt;br /&gt;
println(&quot;¬A :&quot;+ ¬(A))&lt;br /&gt;
println(&quot;¬B :&quot;+ ¬(B))&lt;br /&gt;
println(&quot;A Λ B :&quot;+ (A Λ B))&lt;br /&gt;
println(&quot;A V B :&quot;+ (A V B))&lt;br /&gt;
println(&quot;A → B :&quot; + (A → B))&lt;br /&gt;
println(&quot;B → A :&quot; + (B → A))&lt;br /&gt;
&lt;/code&gt;&lt;br /&gt;
&lt;/p&gt;&lt;br /&gt;
With everything in place, with a for comprehension is very easy to print the truth tables of any complex formula (just be careful with the precedence, use parenthesis):&lt;br /&gt;
&lt;p class=&quot;codebkg&quot; &gt;&lt;code class=&quot;prettyprint&quot;&gt;&lt;br /&gt;
import LogicBoolean._&lt;br /&gt;
&lt;br /&gt;
val r=List(true,false)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
def expr(a:Boolean,b:Boolean,c:Boolean,d:Boolean)=&lt;br /&gt;
( (a Λ b) V ¬(a Λ c) ) Λ ((c V d) Λ ¬(b) )&lt;br /&gt;
&lt;br /&gt;
//let&#39;s print the truth table&lt;br /&gt;
println (&quot;\na\tb\tc\td\t(a Λ b) V ¬(a Λ c) ) Λ ((c V d) Λ ¬(b)&quot;)&lt;br /&gt;
for (&lt;br /&gt;
a &amp;lt;- r; b &amp;lt;- r; c &amp;lt;- r; d &amp;lt;- r ) println (a+&quot;\t&quot;+b+&quot;\t&quot;+c+&quot;\t&quot;+d+&quot;\t&quot;+expr(a,b,c,d)) &lt;/code&gt;&lt;br /&gt;
&lt;/p&gt;If you run the examples you get:&lt;br /&gt;
&lt;p class=&quot;codebkg&quot; &gt;&lt;code class=&quot;prettyprint&quot;&gt;&lt;br /&gt;
¬A :false&lt;br /&gt;
¬B :true&lt;br /&gt;
A Λ B :false&lt;br /&gt;
A V B :true&lt;br /&gt;
A → B :false&lt;br /&gt;
B → A :true&lt;br /&gt;
&lt;br /&gt;
a b c d (a Λ b) V ¬(a Λ c) ) Λ ((c V d) Λ ¬(b)&lt;br /&gt;
true true true true false&lt;br /&gt;
true true true false false&lt;br /&gt;
true true false true false&lt;br /&gt;
true true false false false&lt;br /&gt;
true false true true false&lt;br /&gt;
true false true false false&lt;br /&gt;
true false false true true&lt;br /&gt;
true false false false false&lt;br /&gt;
false true true true false&lt;br /&gt;
false true true false false&lt;br /&gt;
false true false true false&lt;br /&gt;
false true false false false&lt;br /&gt;
false false true true true&lt;br /&gt;
false false true false true&lt;br /&gt;
false false false true true&lt;br /&gt;
false false false false false&lt;br /&gt;
&lt;/code&gt;&lt;br /&gt;
&lt;/p&gt;The ability to easily adapt the language to looks like the domain is one of the main selling features of languages like Lisp. Though Scala is no way like Lisp, it can go very far in the &quot;internal DSL&quot; direction and provides many features to make that easy.&lt;br /&gt;
&lt;br /&gt;
EDIT: &lt;a href=&quot;http://www.oreillynet.com/ruby/blog/2007/10/fun_with_unicode_1.html&quot;&gt;Something very similar in Ruby&lt;/a&gt;</description><link>http://gabrielsw.blogspot.com/2009/06/boolean-algebra-internal-dsl-in-scala.html</link><author>noreply@blogger.com (Anonymous)</author><thr:total>14</thr:total></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-6893032696317132921.post-3818876624216334321</guid><pubDate>Fri, 22 May 2009 00:07:00 +0000</pubDate><atom:updated>2011-08-19T10:19:30.287-04:00</atom:updated><category domain="http://www.blogger.com/atom/ns#">code</category><category domain="http://www.blogger.com/atom/ns#">exercises</category><category domain="http://www.blogger.com/atom/ns#">programming</category><category domain="http://www.blogger.com/atom/ns#">Scala</category><title>My take on 99 problems in Scala (23 to 26)</title><description>I have lot of things going on, but a quick post. Here are 5 more problems solved in Scala.&lt;br /&gt;
Note: in all this and the &lt;a href=&quot;http://gabrielsw.blogspot.com/2009/04/my-take-on-99-problems-in-scala-first.html&quot;&gt;previous solutions&lt;/a&gt;, I&#39;ve left out (most of the time) boundary conditions checks, to keep the code simple and as elegant as possible.&lt;br /&gt;
&lt;br /&gt;
P23: Random select. We reuse P20 (removeAt) and remove a random element of the list recursively.&lt;br /&gt;
&lt;div class=&quot;codebkg&quot;&gt;&lt;code class=&quot;prettyprint&quot;&gt;&lt;br /&gt;
//P23&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Times New Roman&#39;;&quot;&gt;&lt;/span&gt;&lt;/code&gt;&lt;br /&gt;
&lt;pre style=&quot;white-space: pre-wrap; word-wrap: break-word;&quot;&gt;&lt;code class=&quot;prettyprint&quot;&gt;  def randomSelect[A](n: Int, xs: List[A]): List[A] = (n, xs) match {
    case (_, Nil) =&amp;gt; Nil
    case (0, _) =&amp;gt; Nil
    case (_, _) =&amp;gt; {
      val x = removeAt(new Random().nextInt(xs.size), xs)
      x._2 :: randomSelect(n - 1, x._1)
    }
  }&lt;/code&gt;&lt;/pre&gt;&lt;code class=&quot;prettyprint&quot;&gt; &lt;/code&gt;&lt;/div&gt;&lt;br /&gt;
P24: lotto. we create a list (well, actually is a range converted to a list) of the numbers and use P23 to select a random draw.&lt;br /&gt;
&lt;div class=&quot;codebkg&quot;&gt;&lt;code class=&quot;prettyprint&quot;&gt;&lt;br /&gt;
//P24&lt;br /&gt;
def lotto(n:Int,max:Int):List[Int] =randomSelect(n,(1 to max).toList)&lt;br /&gt;
&lt;/code&gt;&lt;/div&gt;&lt;br /&gt;
P25: random permute. That&#39;s easy: we use P23 to do a randomSelect on the whole list&lt;br /&gt;
&lt;div class=&quot;codebkg&quot;&gt;&lt;code class=&quot;prettyprint&quot;&gt;&lt;br /&gt;
//P25&lt;br /&gt;
def randomPermute[A](xs:List[A]):List[A] =randomSelect(xs.size,xs)&lt;br /&gt;
&lt;/code&gt; &lt;/div&gt;&lt;br /&gt;
P26: combinations. That one wasn&#39;t straightforward, I actually had to think! :)&lt;br /&gt;
But the solution can be defined recursively:&lt;br /&gt;
to get the combinations of size n, take one element of the set and append it to all the combinations of sets of size n-1 of the remaining elements, union the combinations of size n of the remaining elements.&lt;br /&gt;
I had to create an auxiliary function that &quot;lift&quot; a list into a list of lists, (kind of the opposite of flatten).&lt;br /&gt;
&lt;div class=&quot;codebkg&quot;&gt;&lt;code class=&quot;prettyprint&quot;&gt;&lt;br /&gt;
//P26&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Times New Roman&#39;;&quot;&gt;&lt;/span&gt;&lt;/code&gt;&lt;br /&gt;
&lt;pre style=&quot;white-space: pre-wrap; word-wrap: break-word;&quot;&gt;&lt;code class=&quot;prettyprint&quot;&gt;  def combinations[A](n: Int, xs: List[A]): List[List[A]] = {
    def lift[A](xs: List[A]): List[List[A]] = xs.foldLeft(List[List[A]]())((ys, y) =&amp;gt; (List(y) :: ys))

    (n, xs) match {
      case (1, ys) =&amp;gt; lift(ys)
      case (i, xs) if (i == xs.size) =&amp;gt; xs :: Nil
      case (i, ys) =&amp;gt; combinations(i - 1, ys.tail).map(zs =&amp;gt; ys.head :: zs) ::: combinations(i, ys.tail)
    }
  }&lt;/code&gt;&lt;/pre&gt;&lt;code class=&quot;prettyprint&quot;&gt; &lt;/code&gt;&lt;/div&gt;</description><link>http://gabrielsw.blogspot.com/2009/05/my-take-on-99-problems-in-scala-23-to.html</link><author>noreply@blogger.com (Anonymous)</author><thr:total>5</thr:total></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-6893032696317132921.post-1100643377463536493</guid><pubDate>Tue, 28 Apr 2009 04:24:00 +0000</pubDate><atom:updated>2011-08-19T10:17:43.605-04:00</atom:updated><category domain="http://www.blogger.com/atom/ns#">code</category><category domain="http://www.blogger.com/atom/ns#">exercises</category><category domain="http://www.blogger.com/atom/ns#">programming</category><category domain="http://www.blogger.com/atom/ns#">Scala</category><title>My take on 99 problems in Scala (first 22)</title><description>A while ago I saw &lt;a href=&quot;https://prof.ti.bfh.ch/hew1/informatik3/prolog/p-99/&quot;&gt;99 problems in Prolog&lt;/a&gt; they looked really good and I started trying to solve them in Scala. Now, thanks to &lt;a href=&quot;http://blog.tmorris.net/22-of-99/&quot;&gt;Tony Morris&lt;/a&gt; I found that there&#39;s a &lt;a href=&quot;http://aperiodic.net/phil/scala/s-99/&quot;&gt;Scala version&lt;/a&gt;!&lt;br /&gt;
Nice stuff to get your skills up to shape. It helped me to improve my understanding of folds, maps, flatMaps, zips, etc. Also I learned new pattern matching techniques (tuples and guards).&lt;br /&gt;
You must really give the exercises a shot!&lt;br /&gt;
Here are my solutions:&lt;br /&gt;
&lt;br /&gt;
&lt;div class=&quot;codebkg&quot;&gt;&lt;code class=&quot;prettyprint&quot;&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Times New Roman&#39;;&quot;&gt;&lt;/span&gt;&lt;/code&gt;&lt;br /&gt;
&lt;pre style=&quot;white-space: pre-wrap; word-wrap: break-word;&quot;&gt;&lt;code class=&quot;prettyprint&quot;&gt;package exercises

object NinetyNine {
  //P01
  def last[A](xs: List[A]): A = xs match {
    case x :: Nil =&amp;gt; x
    case x :: xs =&amp;gt; last(xs)
    case Nil =&amp;gt; throw new NoSuchElementException
  }

  //P02
  def penultimate[A](xs: List[A]): A = xs match {
    case x :: y :: Nil =&amp;gt; x
    case x :: xs =&amp;gt; penultimate(xs)
    case _ =&amp;gt; throw new NoSuchElementException
  }

  //P03
  def nth[A](i: Int, xs: List[A]): A = xs match {
    case x :: xs =&amp;gt; if (i == 0) x else nth(i - 1, xs)
    case _ =&amp;gt; throw new NoSuchElementException
  }

  def nth2[A](i: Int, xs: List[A]): A = xs match {
    case x :: xs if (i == 0) =&amp;gt; x
    case x :: xs if (i &amp;gt; 0) =&amp;gt; nth(i - 1, xs)
    case _ =&amp;gt; throw new NoSuchElementException
  }

  //P04
  def length[A](xs: List[A]): Int = xs match {
    case x :: xs =&amp;gt; 1 + length(xs)
    case Nil =&amp;gt; 0
  }

  //Although straight recursion is fun, using folds is more effective
  // folds are abstractions for recursion over data structures

  //P04
  def length1[A](xs: List[A]): Int = xs.foldLeft(0)((a, b) =&amp;gt; a + 1)

  //P05
  def reverse[A](xs: List[A]): List[A] = xs.foldLeft(Nil: List[A])((a, b) =&amp;gt; b :: a)

  //P06
  def isPalindrome[A](xs: List[A]): Boolean = reverse(xs) == xs

  //P07
  def flatten[A](xs: List[List[A]]): List[A] = xs.foldRight(Nil: List[A])(
    (xs, acc) =&amp;gt; xs match {
      case ys: List[A] =&amp;gt; ys ::: acc
      case y: A =&amp;gt; y :: acc
    })

  //P08
  def compress[A](xs: List[A]): List[A] =
    xs.foldRight(List[A]())((y, ys) =&amp;gt;
      if (ys != Nil &amp;amp;&amp;amp; ys.head == y) ys else y :: ys)

  //P09
  def pack[A](xs: List[A]): List[List[A]] = xs match {
    case Nil =&amp;gt; Nil
    case _ =&amp;gt; xs.takeWhile(_ == xs.head) :: pack(xs.dropWhile(_ == xs.head)) //can use span too, see P13
  }

  //P10
  def encode[A](xs: List[A]): List[(Int, A)] =
    pack(xs).map(y =&amp;gt; (y.length, y.head))

  //P11
  def encodeModified[A](xs: List[A]): List[Any] =
    pack(xs).map(
      y =&amp;gt; if (y.length == 1) y.head else (y.length, y.head))

  //Type safe version
  def encodeModifiedTypSafe[A](xs: List[A]): List[Either[A, (Int, A)]] =
    pack(xs).map(
      y =&amp;gt;
        if (y.length == 1) Left(y.head)
        else Right(y.length, y.head))

  //P12
  def decode[A](xs: List[(Int, A)]): List[A] = {
    def expand(i: Int, a: A): List[A] = if (i == 0) Nil else a :: expand(i - 1, a)
    flatten(xs.foldRight(List[List[A]]())((y, ys) =&amp;gt; expand(y._1, y._2) :: ys))
  }
  //is better with flatMap
  def decode1[A](xs: List[(Int, A)]): List[A] =
    xs.flatMap(ny =&amp;gt; List.make(ny._1, ny._2))

  //P13
  def encodeDirect[A](xs: List[A]): List[(Int, A)] = xs match {
    case Nil =&amp;gt; Nil
    case _ =&amp;gt; {
      val ys = xs.span(_ == xs.head)
      (ys._1.length, xs.head) :: encodeDirect(ys._2)
    }
  }

  //P14
  def duplicate[A](xs: List[A]): List[A] =
    xs.foldRight(Nil: List[A])((y, ys) =&amp;gt; y :: y :: ys)
  //is better with flatMap
  def duplicate1[A](xs: List[A]): List[A] = xs.flatMap(y =&amp;gt; y :: y :: Nil)

  //P15
  def duplicateN[A](n: Int, xs: List[A]): List[A] =
    xs.foldRight(Nil: List[A])((y, ys) =&amp;gt; (1 to n).toList.map(_ =&amp;gt; y) ::: ys)
  //is better with flatMap
  def duplicateN1[A](n: Int, xs: List[A]): List[A] =
    xs.flatMap(y =&amp;gt; List.make(n, y))

  //P16
  def drop[A](n: Int, xs: List[A]): List[A] =
    xs.zipWithIndex.filter(_._2 % n != 0).map(_._1)

  //P17
  def split[A](n: Int, xs: List[A]): (List[A], List[A]) =
    xs.splitAt(n) // or (xs.take(n),xs.drop(n))

  //ok, that was too easy, let&#39;s try recursion
  def splitRec[A](n: Int, xs: List[A]): (List[A], List[A]) =
    (n, xs) match {
      case (0, _) =&amp;gt; (Nil, xs)
      case (_, y :: ys) =&amp;gt; {
        val rec = splitRec(n - 1, ys)
        (y :: rec._1, rec._2)
      }
      case (_, Nil) =&amp;gt; (xs, Nil)
    }

  //P18
  def slice[A](s: Int, e: Int, xs: List[A]): List[A] =
    xs.slice(s, e) // or xs.drop(s).take(e-s)

  //with recursion
  def sliceRec[A](s: Int, e: Int, xs: List[A]): List[A] =
    (s, e, xs) match {
      case (0, 0, xs) =&amp;gt; Nil
      case (0, _, y :: ys) =&amp;gt; y :: sliceRec(0, e - 1, ys)
      case (_, _, y :: ys) =&amp;gt; sliceRec(s - 1, e - 1, ys)
    }

  //P19
  def rotate[A](n: Int, xs: List[A]): List[A] = {
    val s = split((if (n &amp;gt; 0) n else n + xs.length), xs)
    s._2 ::: s._1
  }

  //P20
  def removeAt[A](n: Int, xs: List[A]): (List[A], A) = {
    val (heads, tails) = split(n, xs)
    (heads ::: tails.tail, tails.head)
  }

  //P21
  def insertAt[A](e: A, n: Int, xs: List[A]): List[A] = {
    val (heads, tails) = split(n, xs)
    heads ::: e :: tails
  }
  //with recursion
  def insertRecAt[A](e: A, n: Int, xs: List[A]): List[A] =
    (n, xs) match {
      case (0, ys) =&amp;gt; e :: ys
      case (_, y :: ys) =&amp;gt; y :: insertRecAt(e, n - 1, ys)
    }

  //P22
  def range[A](s: Int, e: Int): List[Int] = (s to e).toList

  //I don&#39;t think is the purpose of the exercise! Again, let&#39;s try recursion
  def rangeRec(s: Int, e: Int): List[Int] = if (e - s == 0) e :: Nil else s :: rangeRec(s + 1, e)

  //recursion and pattern matching with guards
  //a little more readable
  def rangeRecPm(s: Int, e: Int): List[Int] = (e - s) match {
    case x if (x &amp;gt; 0) =&amp;gt; s :: rangeRecPm(s + 1, e)
    case x if (x == 0) =&amp;gt; e :: Nil
    case _ =&amp;gt; error(&quot;Invalid range&quot;)
  }&lt;/code&gt;&lt;/pre&gt;&lt;code class=&quot;prettyprint&quot;&gt; }&lt;br /&gt;
&lt;/code&gt;&lt;/div&gt;[EDIT: fixed problem 20 ]</description><link>http://gabrielsw.blogspot.com/2009/04/my-take-on-99-problems-in-scala-first.html</link><author>noreply@blogger.com (Anonymous)</author><thr:total>3</thr:total></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-6893032696317132921.post-5429368409325840765</guid><pubDate>Tue, 07 Apr 2009 20:50:00 +0000</pubDate><atom:updated>2010-12-03T09:33:05.561-05:00</atom:updated><category domain="http://www.blogger.com/atom/ns#">DDD</category><category domain="http://www.blogger.com/atom/ns#">Haskell</category><category domain="http://www.blogger.com/atom/ns#">humor</category><category domain="http://www.blogger.com/atom/ns#">programming</category><category domain="http://www.blogger.com/atom/ns#">ruby</category><category domain="http://www.blogger.com/atom/ns#">Scala</category><title>Spare change at the whole Static-vs-Dynamic thingy</title><description>&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh7QL1e1AS3OBhuqpSmb62FXxWGj6_uikX39rTKVyw-9mjOUqoZeZkKoHybgyqh3Icvm8MhDh0fqA6SfmtnmK6vY_MHQh2kyxlbEiD7G4KIT_VI5bz6WjalF-ExSgsP6jeRxba4P8ePEqM/s1600-h/IMG_1758.JPG&quot; onblur=&quot;try {parent.deselectBloggerImageGracefully();} catch(e) {}&quot;&gt;&lt;img alt=&quot;&quot; border=&quot;0&quot; id=&quot;BLOGGER_PHOTO_ID_5322094098784432402&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh7QL1e1AS3OBhuqpSmb62FXxWGj6_uikX39rTKVyw-9mjOUqoZeZkKoHybgyqh3Icvm8MhDh0fqA6SfmtnmK6vY_MHQh2kyxlbEiD7G4KIT_VI5bz6WjalF-ExSgsP6jeRxba4P8ePEqM/s400/IMG_1758.JPG&quot; style=&quot;cursor: pointer; float: left; height: 400px; margin: 0pt 10px 10px 0pt; width: 300px;&quot; /&gt;&lt;/a&gt;&lt;br /&gt;
&lt;i&gt;(NOTE: I&#39;m a software developer, I have a blog, clearly I &lt;a href=&quot;http://xkcd.com/386/&quot; id=&quot;zjw3&quot; title=&quot;Someone is WRONG on the internet&quot;&gt;MUST&lt;/a&gt;  write about &lt;a href=&quot;http://www.pphsg.org/cdsmith/types.html&quot; id=&quot;s0e.&quot; title=&quot;What To Know Before Debating Type Systems&quot;&gt;static-vs-dynamic&lt;/a&gt; ... I guess soon I&#39;ll be writing a monads tutorial)&lt;br /&gt;
&lt;br /&gt;
&lt;/i&gt;With all the fuss about Twitter migrating (the back-end) from Ruby to Scala (w00t!), the whole static-vs-dynamic debate has been re-ignited.&lt;br /&gt;
As a disclaimer, I&#39;m in the static typing &quot;camp&quot;. I&#39;ve tried Ruby but didn&#39;t spark anything. In &quot;dynamic languages&quot;, I have more experience with JavaScript (and for the record, I think is awesome: a true underdog of programming languages).&lt;br /&gt;
While I can appreciate the freedom and speed of development of  dynamic languages, and I think is a matter of personal styles than about which one is better (&quot;choose your own poison&quot;), I think static typing suits better my frame of mind while creating software.&lt;br /&gt;
Anyhow, I felt something was missing in the debate and Twitter&#39;s use of &quot;kind_of?&quot; points to one of the reasons for static typing I been trying to articulate for a while.&lt;br /&gt;
&lt;i&gt;(First and foremost: if you&#39;re going to complain &quot;static typing forces me to add a lot of boilerplate and cruft&quot;, look into Haskell, ML, Scala, or F# and then come back or you&#39;ll force me to do evil things to cute creatures. And if you want to learn how a type system can be used to PROVE that a program is correct, look into &lt;a href=&quot;http://coq.inria.fr/&quot; id=&quot;r2s5&quot; title=&quot;The Coq proof assistant&quot;&gt;Coq&lt;/a&gt;)&lt;/i&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;Types reduces the possible combinations between components&lt;/b&gt;&lt;br /&gt;
Any software program can be seen as a system of interconnected elements (modules/functions/objects, etc.), by adding type information you&#39;re restricting the ways those elements can connect to each other and the possible execution paths of the system. By doing that, you&#39;re loosing some of the valid combinations, you&#39;re also trimming many invalid ones.&lt;br /&gt;
The argument is with good unit tests you can check for the same things, but you have to actually write the code for that. While you should have unit tests for your module, without type restrictions, you have to write and test more execution paths. Moreover, writing the test, executing it and analyzing the result are separate steps, where your brain has to switch contexts.&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;Types as a Poka-Yoke&lt;/b&gt;&lt;br /&gt;
There&#39;s a lot of influence of Lean Manufacturing in software development (all the &quot;Agile&quot; stuff ), and from that perspective, having more restrictions on how you can use the available components acts like a &lt;a href=&quot;http://en.wikipedia.org/wiki/Poka_yoke&quot; id=&quot;iouf&quot; title=&quot;poka-yoke&quot;&gt;poka-yoke&lt;/a&gt;  mechanism: &quot;a &lt;a href=&quot;http://en.wikipedia.org/wiki/Behavior-shaping_constraint&quot; title=&quot;Behavior-shaping constraint&quot;&gt;behavior-shaping constraint&lt;/a&gt;, or a method of preventing &lt;a href=&quot;http://en.wikipedia.org/wiki/Error&quot; title=&quot;Error&quot;&gt;errors&lt;/a&gt; by putting limits on how an operation can be performed in order to force the correct completion of the operation&quot;.  The same Lean / Total Quality Management recommends catching defects as early as possible and not use testing as a product quality measure. How more agile can you be when you don&#39;t have to write and run test to achieve a basic level of integration quality?&lt;br /&gt;
&lt;span class=&quot;status-body&quot;&gt;&lt;span class=&quot;entry-content&quot;&gt;&lt;br /&gt;
&lt;b&gt;Types as (kind-of) contracts&lt;/b&gt;&lt;br /&gt;
By using static typing you get self-documenting self-enforcing operation contracts (for a price)&lt;/span&gt;&lt;/span&gt;. I believe the larger and more complex the system, the more static typing can help than hinder your work.&lt;br /&gt;
&lt;a href=&quot;http://marsweb.jpl.nasa.gov/msp98/news/mco990930.html&quot; id=&quot;nozq&quot; title=&quot;MARS CLIMATE ORBITER TEAM FINDS LIKELY CAUSE OF LOSS&quot;&gt;NASA could have saved some money&lt;/a&gt;  if they were able to write:&lt;br /&gt;
&lt;code class=&quot;prettyprint&quot;&gt;&lt;br /&gt;
class MarsObiter {&lt;br /&gt;
def setThrust(v:Thrust[MetricUnits])= ...&lt;br /&gt;
&lt;/code&gt;&lt;br /&gt;
There&#39;s no way you can use a Thrust[ImperialUnits] instead. (For extra points, you can define an implicit conversion in Scala :D )&lt;br /&gt;
But even if you have a basic type system like Java, don&#39;t just suffer it, use it at your advantage, create the types that can help you to write better code.&lt;br /&gt;
Check &lt;a href=&quot;http://www.codemonkeyism.com/archives/2008/05/02/never-never-never-use-string-in-java-or-at-least-less-often/&quot; id=&quot;nirr&quot; title=&quot;Never, never, never use String in Java (or at least less often :-)&quot;&gt;Stephan&#39;s excellent post&lt;/a&gt;  on what do you loose if you use only primitive types with no semantic meaning (or no types at all)&lt;br /&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEil1qf5JjK9KhfaSwZSyucrClG9NXqfOYfhfelbqdOvTmXbaZ-z_Dfv1RTv8IJps4t3Acm7zfe8_AD7PXOwtTnB46ykdRP8eY_Uh9HEBop_0qTZ-Yw-qRv537GVl1AnlnDyxpUNWuPd5DQ/s1600-h/IMG_1652.JPG&quot; onblur=&quot;try {parent.deselectBloggerImageGracefully();} catch(e) {}&quot;&gt;&lt;img alt=&quot;&quot; border=&quot;0&quot; id=&quot;BLOGGER_PHOTO_ID_5322094794846529362&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEil1qf5JjK9KhfaSwZSyucrClG9NXqfOYfhfelbqdOvTmXbaZ-z_Dfv1RTv8IJps4t3Acm7zfe8_AD7PXOwtTnB46ykdRP8eY_Uh9HEBop_0qTZ-Yw-qRv537GVl1AnlnDyxpUNWuPd5DQ/s400/IMG_1652.JPG&quot; style=&quot;cursor: pointer; display: block; height: 234px; margin: 0px auto 10px; text-align: center; width: 312px;&quot; /&gt;&lt;/a&gt;&lt;br /&gt;
&lt;b&gt;Enough!&lt;/b&gt;&lt;br /&gt;
But enough babbling, I can show some examples using the &quot;lowly&quot; Java language:&lt;br /&gt;
Suppose we have a method to book a shipment for a customer and a container on a specific date.&lt;br /&gt;
Let&#39;s start without any typing information:&lt;br /&gt;
&lt;br /&gt;
&lt;code class=&quot;prettyprint&quot;&gt;&lt;br /&gt;
public bookShipment(customerId, containerId, shipmentDate){...&lt;br /&gt;
&lt;/code&gt;&lt;br /&gt;
&lt;br /&gt;
Totally valid, but... is &quot;1234-321&quot; a valid customerId? can I use a string as shipmentDate? in which format? What I get back?&lt;br /&gt;
Let&#39;s improve things a little by adding some basic typing information:&lt;br /&gt;
&lt;br /&gt;
&lt;code class=&quot;prettyprint&quot;&gt;&lt;br /&gt;
public boolean bookShipment(int customerId, int containerId, Date shipmentDate){...&lt;br /&gt;
&lt;/code&gt;&lt;br /&gt;
&lt;br /&gt;
Well, now I now that &quot;X123Z&quot; is not a valid customer or that &quot;MRSK0023&quot; is not a valid container, the date must be a proper date object, and it doesn&#39;t take a PhD to infer that will return true if the booking is successful.&lt;br /&gt;
But still, nothing prevents me to swap customerId with containerId and get a nasty but subtle bug. Wouldn&#39;t be nice if the compiler can prevent that? Well, it can if you don&#39;t use primitives and use more domain meaningful types, giving you a &lt;a href=&quot;http://domaindrivendesign.org/&quot; id=&quot;dyz:&quot; title=&quot;Domain Driven Design&quot;&gt;DDD&lt;/a&gt; flavor (and that&#39;s a win-win situation)&lt;br /&gt;
&lt;br /&gt;
&lt;code class=&quot;prettyprint&quot;&gt;&lt;br /&gt;
public boolean bookShipment(Customer customer, Container container, Date time){...&lt;br /&gt;
&lt;/code&gt;&lt;br /&gt;
&lt;br /&gt;
By examining the signature we know we can&#39;t pass a Container when a Customer is expected, and the method reflects better the domain of the application and tries to move towards &quot;an ubiquitous language&quot;. But we can improve that:&lt;br /&gt;
&lt;br /&gt;
&lt;code class=&quot;prettyprint&quot;&gt;&lt;br /&gt;
public bookShipment(customer, container, shipmentDate) { ...&lt;br /&gt;
&lt;/code&gt;&lt;br /&gt;
&lt;br /&gt;
Here &lt;a href=&quot;http://en.wikipedia.org/wiki/Type_inference&quot; id=&quot;hu.0&quot; title=&quot;Hindley-Milner&quot;&gt;Hindley-Milner&lt;/a&gt;   type inference takes care of identifying the input and output paremeters. No need to declare a thing and still type safe!&lt;br /&gt;
(although for documentation/readability purposes, I prefer explicit type declarations, and seems that the Haskell community agrees... that&#39;s why I don&#39;t mind typing the types of methods in Scala)&lt;br /&gt;
&lt;br /&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiQqeAFZVxsTW0E4D73BJ9fFALufj99BRWnfu4S90HkuJrezzbFE6D7RbpaQUmtCBcKSriku9yAOt80c8Q-60Snc1bDjLKjl0o9ex4uOOjVzco8qwuTWPse6QvH0NajkKG_VJFnA-CEGdA/s1600-h/IMG_1760.JPG&quot; onblur=&quot;try {parent.deselectBloggerImageGracefully();} catch(e) {}&quot;&gt;&lt;img alt=&quot;&quot; border=&quot;0&quot; id=&quot;BLOGGER_PHOTO_ID_5322100502861672466&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiQqeAFZVxsTW0E4D73BJ9fFALufj99BRWnfu4S90HkuJrezzbFE6D7RbpaQUmtCBcKSriku9yAOt80c8Q-60Snc1bDjLKjl0o9ex4uOOjVzco8qwuTWPse6QvH0NajkKG_VJFnA-CEGdA/s200/IMG_1760.JPG&quot; style=&quot;cursor: pointer; display: block; height: 202px; margin: 0px auto 10px; text-align: center; width: 271px;&quot; /&gt;&lt;/a&gt;&lt;br /&gt;
&lt;br /&gt;
The whole point about all this? Go back and get things done, use whatever suites you best and don&#39;t waste your time reading blogs and stuff ;-)&lt;br /&gt;
If you excuse me, I need to step down from my tittle soapbox and go to do some coding...</description><link>http://gabrielsw.blogspot.com/2009/04/spare-change-at-whole-static-vs-dynamic.html</link><author>noreply@blogger.com (Anonymous)</author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh7QL1e1AS3OBhuqpSmb62FXxWGj6_uikX39rTKVyw-9mjOUqoZeZkKoHybgyqh3Icvm8MhDh0fqA6SfmtnmK6vY_MHQh2kyxlbEiD7G4KIT_VI5bz6WjalF-ExSgsP6jeRxba4P8ePEqM/s72-c/IMG_1758.JPG" height="72" width="72"/><thr:total>2</thr:total></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-6893032696317132921.post-2014577774252868702</guid><pubDate>Thu, 02 Apr 2009 00:07:00 +0000</pubDate><atom:updated>2009-04-01T20:12:28.087-04:00</atom:updated><category domain="http://www.blogger.com/atom/ns#">quotes</category><title>Quote of the month</title><description>&lt;span style=&quot;font-size:130%;&quot;&gt;&quot;Bad programming is easy. &lt;i&gt;Idiots&lt;/i&gt; can learn it in &lt;i&gt;21 days&lt;/i&gt;, even if they are &lt;i&gt;dummies&lt;/i&gt;.&quot;&lt;/span&gt;&lt;br /&gt;&lt;div style=&quot;text-align: right;&quot;&gt;&lt;a href=&quot;http://www.ccs.neu.edu/home/matthias/HtDP2e/index.html&quot;&gt;How to Design Programs, 2nd Edition &lt;/a&gt;&lt;br /&gt;&lt;/div&gt;</description><link>http://gabrielsw.blogspot.com/2009/04/quote-of-month.html</link><author>noreply@blogger.com (Anonymous)</author><thr:total>1</thr:total></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-6893032696317132921.post-8948014180273603324</guid><pubDate>Mon, 09 Feb 2009 00:44:00 +0000</pubDate><atom:updated>2011-06-21T11:33:59.763-04:00</atom:updated><category domain="http://www.blogger.com/atom/ns#">currying</category><category domain="http://www.blogger.com/atom/ns#">functional programming</category><category domain="http://www.blogger.com/atom/ns#">Haskell</category><category domain="http://www.blogger.com/atom/ns#">Scala</category><title>Flavors of Curry: Scala vs Haskell</title><description>&lt;a onblur=&quot;try {parent.deselectBloggerImageGracefully();} catch(e) {}&quot; href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEi6738QrB0Osqeam1xS1RhvrZOoPoMQXWyg6_xvFaZ06nLgCyr5jJumngHkil7hrou53P7kvBhePbxo5ouBfrGdx_u89qHuvJpllKLbQGE-y8coc-0ByWuGSy9MuhPr3ngF69ocS8k4os4/s1600-h/IMG_0336.JPG&quot;&gt;&lt;img style=&quot;margin: 0pt 10px 10px 0pt; float: left; cursor: pointer; width: 400px; height: 300px;&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEi6738QrB0Osqeam1xS1RhvrZOoPoMQXWyg6_xvFaZ06nLgCyr5jJumngHkil7hrou53P7kvBhePbxo5ouBfrGdx_u89qHuvJpllKLbQGE-y8coc-0ByWuGSy9MuhPr3ngF69ocS8k4os4/s400/IMG_0336.JPG&quot; alt=&quot;&quot; id=&quot;BLOGGER_PHOTO_ID_5300595429177536850&quot; border=&quot;0&quot; /&gt;&lt;/a&gt;&lt;br /&gt;
Scala is a nice language to explore functional programming, and for me it was easy to use it as a “stepping stone” and jump to Haskell with all the purity and laziness (I think is because I&#39;m the kind of guy that enter slowly in the cold water...). I&#39;m  using Haskell to learn the theory and tools of functional programming (in a language that forces you to), so I can use them in Scala.&lt;br /&gt;
&lt;br /&gt;
To that end, I&#39;m going through &lt;a href=&quot;http://learnyouahaskell.com&quot;&gt;“Learn You a Haskell for Great Good!”&lt;/a&gt;  (I seem to have a fondness for technical books with silly images). Usually I&#39;ll try to do the same exercises in Scala to compare.&lt;br /&gt;
&lt;br /&gt;
I was going through the chapter about higher order functions and currying. What are curried functions?  You can find a very good explanation in &lt;a href=&quot;http://en.wikipedia.org/wiki/Currying&quot;&gt;wikipedia&lt;/a&gt; (of course!). Basically is the transformation of a function with multiple parameters into another function with only one parameter that returns a function of the remaining parameters. With that, your language can care only about functions with only one parameter and still be equally powerful. The advantage is if you call a function with less parameters, you get a partially applied function.&lt;br /&gt;
&lt;br /&gt;
One of the examples on the “Learn you...” is a “flip” function: a function that exchanges the first and second parameter of a given function. In Haskell is as easy as:&lt;br /&gt;
&lt;span style=&quot;background-color: #f3f3f3;&quot;&gt;&lt;br /&gt;
&lt;code class=&quot;prettyprint&quot;&gt;flip1 f x y = f y x&lt;/code&gt;&lt;br /&gt;
&lt;/span&gt;&lt;br /&gt;
That&#39;s all! Hindley-Milner type inference ensures the type safety:&lt;br /&gt;
&lt;span style=&quot;background-color: #f3f3f3;&quot;&gt;&lt;br /&gt;
&lt;code class=&quot;prettyprint&quot;&gt;flip1 :: (t1 -&gt; t -&gt; t2) -&gt; t -&gt; t1 -&gt; t2&lt;/code&gt;&lt;br /&gt;
&lt;/span&gt;&lt;br /&gt;
As an example:&lt;br /&gt;
&lt;span style=&quot;background-color: #f3f3f3;&quot;&gt;&lt;br /&gt;
&lt;code class=&quot;prettyprint&quot;&gt;&lt;br /&gt;
f x y =x/y&lt;br /&gt;
f 1 2&lt;br /&gt;
0.5&lt;br /&gt;
&lt;br /&gt;
g= flip1 f&lt;br /&gt;
g 1 2&lt;br /&gt;
2.0&lt;br /&gt;
&lt;/code&gt;&lt;br /&gt;
&lt;/span&gt;&lt;br /&gt;
BTW, there&#39;s something odd:&lt;br /&gt;
&lt;span style=&quot;background-color: #f3f3f3;&quot;&gt;&lt;br /&gt;
&lt;code class=&quot;prettyprint&quot;&gt;&lt;br /&gt;
Prelude&gt; let flip1 f x y = f y x&lt;br /&gt;
Prelude&gt; :t flip1&lt;br /&gt;
flip1 :: (t1 -&gt; t -&gt; t2) -&gt; t -&gt; t1 -&gt; t2&lt;br /&gt;
Prelude&gt; let f x y =x/y&lt;br /&gt;
Prelude&gt; :t f&lt;br /&gt;
f :: (Fractional a) =&gt; a -&gt; a -&gt; a&lt;br /&gt;
Prelude&gt; let g=flip f&lt;br /&gt;
Prelude&gt; :t g&lt;br /&gt;
g :: Double -&gt; Double -&gt; Double&lt;br /&gt;
Prelude&gt; :t flip1 f&lt;br /&gt;
flip1 f :: (Fractional t1) =&gt; t1 -&gt; t1 -&gt; t1&lt;br /&gt;
&lt;/code&gt;&lt;br /&gt;
&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
The type of flip1 f is (Fractional t1) =&gt; t1 -&gt; t1 -&gt; t1, meaning that t1 is restricted to be of Fractional typeclass, but if I bind g to flip f, now the type is Double... that&#39;s not what one would expect! (Any Haskell expert can tell me what&#39;s happening?)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
As usual, I&#39;ll tried to do the same in Scala to see how far it can goes.&lt;br /&gt;
The main difference is of course, type inference: in Scala you need to declare the function types. The other major difference is Haskell every function is curried by default, in Scala you need to explicitly curry the function by separating each parameter between parentheses.&lt;br /&gt;
&lt;br /&gt;
In Scala, our (curried) f function will be:&lt;br /&gt;
&lt;span style=&quot;background-color: #f3f3f3;&quot;&gt;&lt;br /&gt;
&lt;code class=&quot;prettyprint&quot;&gt;&lt;br /&gt;
def f(x:Int)(y:Int)=x/y&lt;br /&gt;
f: (Int)(Int)Int&lt;br /&gt;
&lt;/code&gt;&lt;br /&gt;
&lt;/span&gt;&lt;br /&gt;
The flip function in Scala would be:&lt;br /&gt;
&lt;span style=&quot;background-color: #f3f3f3;&quot;&gt;&lt;br /&gt;
&lt;code class=&quot;prettyprint&quot;&gt;&lt;br /&gt;
def flip1[A,B,C]( f:A=&gt;B=&gt;C)(x:B)(y:A) =f(y)(x)&lt;br /&gt;
flip1: [A,B,C]((A) =&gt; (B) =&gt; C)(B)(A)C&lt;br /&gt;
&lt;/code&gt;&lt;br /&gt;
&lt;/span&gt;&lt;br /&gt;
Is clearly more verbose than the Haskell version, but equally powerful:&lt;br /&gt;
&lt;span style=&quot;background-color: #f3f3f3;&quot;&gt;&lt;br /&gt;
&lt;code class=&quot;prettyprint&quot;&gt;&lt;br /&gt;
def g = flip1 (f) _&lt;br /&gt;
g: (Int) =&gt; (Int) =&gt; Int&lt;br /&gt;
&lt;/code&gt;&lt;br /&gt;
&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
The underscore is needed to get the partially applied function and the f must be in parentheses (again,  all curried parameters must have their own parentheses).&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Conclusion? Nothing. Haskell and Scala are obviously different, but they share some common ground... just wanted to show it :)</description><link>http://gabrielsw.blogspot.com/2009/02/flavors-of-curry-scala-vs-haskell.html</link><author>noreply@blogger.com (Anonymous)</author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEi6738QrB0Osqeam1xS1RhvrZOoPoMQXWyg6_xvFaZ06nLgCyr5jJumngHkil7hrou53P7kvBhePbxo5ouBfrGdx_u89qHuvJpllKLbQGE-y8coc-0ByWuGSy9MuhPr3ngF69ocS8k4os4/s72-c/IMG_0336.JPG" height="72" width="72"/><thr:total>9</thr:total></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-6893032696317132921.post-4756504619393631789</guid><pubDate>Fri, 19 Dec 2008 03:22:00 +0000</pubDate><atom:updated>2009-04-28T11:18:23.400-04:00</atom:updated><category domain="http://www.blogger.com/atom/ns#">code</category><category domain="http://www.blogger.com/atom/ns#">functional programming</category><category domain="http://www.blogger.com/atom/ns#">optimization</category><category domain="http://www.blogger.com/atom/ns#">pathfinding</category><category domain="http://www.blogger.com/atom/ns#">refactoring</category><category domain="http://www.blogger.com/atom/ns#">Scala</category><title>Playing with Scala 5 ½: More variations</title><description>&lt;a onblur=&quot;try {parent.deselectBloggerImageGracefully();} catch(e) {}&quot; href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgQjzOIupoIwV0cIW-zxvCL_SFh85WqkyeFf8NFiOF5l3_wXYuDm2Awci6XrXTb8bX0Xw5ANzxzP5qntkG8_H3uN5kPrXB0kJE1uqQJdiU-XQDu3OyEowKMDO7oS32g8XJGUkIWk45lhRk/s1600-h/095.JPG&quot;&gt;&lt;img style=&quot;margin: 0pt 10px 10px 0pt; float: left; cursor: pointer; width: 400px; height: 300px;&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgQjzOIupoIwV0cIW-zxvCL_SFh85WqkyeFf8NFiOF5l3_wXYuDm2Awci6XrXTb8bX0Xw5ANzxzP5qntkG8_H3uN5kPrXB0kJE1uqQJdiU-XQDu3OyEowKMDO7oS32g8XJGUkIWk45lhRk/s400/095.JPG&quot; alt=&quot;&quot; id=&quot;BLOGGER_PHOTO_ID_5281337218334105618&quot; border=&quot;0&quot; /&gt;&lt;/a&gt;&lt;br /&gt;&lt;style type=&quot;text/css&quot;&gt;  &lt;!--   @page { size: 8.5in 11in; margin: 0.79in }   P { margin-bottom: 0.08in }  --&gt;  &lt;/style&gt; &lt;p style=&quot;margin-bottom: 0in;&quot;&gt;As &lt;a href=&quot;http://gabrielsw.blogspot.com/2008/12/playing-with-scala-5-improving-code-use.html?showComment=1229353440000#c6142691751585604111&quot;&gt;James pointed out&lt;/a&gt;, the implicit conversion creates a new object every time we convert the Node to Ordered[Node], and although the JVM and the GC can deal pretty well with that kind of scenario, it will be better if we can avoid the creation of the object  (BTW, the fact that Scala can leverage years of work on JIT optimizations is something that shouldn&#39;t be taken lightly... I still want tail call optimization, though)&lt;/p&gt; &lt;p style=&quot;margin-bottom: 0in;&quot;&gt;We need to add the Ordered trait for Node somewhere in the hierarchy. The reasonable place is when we add the Weight trait (once we have weight we can compare the nodes):&lt;/p&gt; &lt;p style=&quot;margin-bottom: 0in;&quot; align=&quot;left&quot;&gt;&lt;span style=&quot;color: rgb(76, 76, 76);&quot;&gt;  &lt;span style=&quot;font-family:Courier New,monospace;&quot;&gt;&lt;span style=&quot;font-size:85%;&quot;&gt;class&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 0);&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: rgb(142, 62, 0);&quot;&gt;DfsNode&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 0);&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: rgb(76, 76, 76);&quot;&gt;extends&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 0);&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: rgb(142, 62, 0);&quot;&gt;NodeImpl&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 0);&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: rgb(76, 76, 76);&quot;&gt;with&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 0);&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: rgb(142, 62, 0);&quot;&gt;Weight&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 0);&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: rgb(76, 76, 76);&quot;&gt;with&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 0);&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: rgb(142, 62, 0);&quot;&gt;Ordered&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 0);&quot;&gt;[&lt;/span&gt;&lt;span style=&quot;color: rgb(142, 62, 0);&quot;&gt;DfsNode&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 0);&quot;&gt;]{&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt; &lt;p style=&quot;margin-bottom: 0in;&quot; align=&quot;left&quot;&gt;&lt;span style=&quot;color: rgb(35, 0, 251);&quot;&gt;    &lt;span style=&quot;font-family:Courier New,monospace;&quot;&gt;&lt;span style=&quot;font-size:85%;&quot;&gt;...&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt; &lt;p style=&quot;margin-bottom: 0in;&quot; align=&quot;left&quot;&gt;&lt;span style=&quot;color: rgb(0, 0, 0);&quot;&gt;    &lt;/span&gt;&lt;span style=&quot;font-family:Courier New,monospace;&quot;&gt;&lt;span style=&quot;font-size:85%;&quot;&gt;&lt;span style=&quot;color: rgb(76, 76, 76);&quot;&gt;def&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 0);&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: rgb(0, 62, 133);&quot;&gt;compare&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 0);&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: rgb(35, 0, 251);&quot;&gt;y&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 0);&quot;&gt;: &lt;/span&gt;&lt;span style=&quot;color: rgb(142, 62, 0);&quot;&gt;Node&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 0);&quot;&gt;): &lt;/span&gt;&lt;span style=&quot;color: rgb(142, 62, 0);&quot;&gt;Int&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 0);&quot;&gt; = &lt;/span&gt;&lt;span style=&quot;color: rgb(76, 76, 76);&quot;&gt;this&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 0);&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: rgb(35, 0, 251);&quot;&gt;weight&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 0);&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 62, 133);&quot;&gt;compare&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 0);&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: rgb(35, 0, 251);&quot;&gt;y&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 0);&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: rgb(35, 0, 251);&quot;&gt;weight&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 0);&quot;&gt;)&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt; &lt;p style=&quot;margin-bottom: 0in;&quot; align=&quot;left&quot;&gt;&lt;span style=&quot;color: rgb(0, 0, 0);&quot;&gt;  &lt;span style=&quot;font-family:Courier New,monospace;&quot;&gt;&lt;span style=&quot;font-size:85%;&quot;&gt;}&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;   &lt;/p&gt; &lt;p style=&quot;margin-bottom: 0in;&quot; align=&quot;left&quot;&gt;Now we can compare the nodes by their weight: “lighter” nodes are before “heavier” nodes, but the comparation is not what we need for the priority queue, we need to reverse the the ordering.&lt;/p&gt; &lt;p style=&quot;margin-bottom: 0in;&quot; align=&quot;left&quot;&gt;The most immediate way is just reverse DfsNode&#39;s comparation function:&lt;/p&gt; &lt;p style=&quot;margin-bottom: 0in;&quot; align=&quot;left&quot;&gt;&lt;span style=&quot;color: rgb(76, 76, 76);&quot;&gt;  &lt;span style=&quot;font-family:Courier New,monospace;&quot;&gt;&lt;span style=&quot;font-size:85%;&quot;&gt;def&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 0);&quot;&gt;&lt;span style=&quot;font-family:Courier New,monospace;&quot;&gt;&lt;span style=&quot;font-size:85%;&quot;&gt; &lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 62, 133);&quot;&gt;&lt;span style=&quot;font-family:Courier New,monospace;&quot;&gt;&lt;span style=&quot;font-size:85%;&quot;&gt;compare&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 0);&quot;&gt;&lt;span style=&quot;font-family:Courier New,monospace;&quot;&gt;&lt;span style=&quot;font-size:85%;&quot;&gt;(&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;color: rgb(35, 0, 251);&quot;&gt;&lt;span style=&quot;font-family:Courier New,monospace;&quot;&gt;&lt;span style=&quot;font-size:85%;&quot;&gt;y&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 0);&quot;&gt;&lt;span style=&quot;font-family:Courier New,monospace;&quot;&gt;&lt;span style=&quot;font-size:85%;&quot;&gt;: &lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;color: rgb(142, 62, 0);&quot;&gt;&lt;span style=&quot;font-family:Courier New,monospace;&quot;&gt;&lt;span style=&quot;font-size:85%;&quot;&gt;Node&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 0);&quot;&gt;&lt;span style=&quot;font-family:Courier New,monospace;&quot;&gt;&lt;span style=&quot;font-size:85%;&quot;&gt;): &lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;color: rgb(142, 62, 0);&quot;&gt;&lt;span style=&quot;font-family:Courier New,monospace;&quot;&gt;&lt;span style=&quot;font-size:85%;&quot;&gt;Int&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 0);&quot;&gt;&lt;span style=&quot;font-family:Courier New,monospace;&quot;&gt;&lt;span style=&quot;font-size:85%;&quot;&gt; = -&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;color: rgb(76, 76, 76);&quot;&gt;&lt;span style=&quot;font-family:Courier New,monospace;&quot;&gt;&lt;span style=&quot;font-size:85%;&quot;&gt;this&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 0);&quot;&gt;&lt;span style=&quot;font-family:Courier New,monospace;&quot;&gt;&lt;span style=&quot;font-size:85%;&quot;&gt;.&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;color: rgb(35, 0, 251);&quot;&gt;&lt;span style=&quot;font-family:Courier New,monospace;&quot;&gt;&lt;span style=&quot;font-size:85%;&quot;&gt;weight&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 0);&quot;&gt;&lt;span style=&quot;font-family:Courier New,monospace;&quot;&gt;&lt;span style=&quot;font-size:85%;&quot;&gt;.&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 62, 133);&quot;&gt;&lt;span style=&quot;font-family:Courier New,monospace;&quot;&gt;&lt;span style=&quot;font-size:85%;&quot;&gt;compare&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 0);&quot;&gt;&lt;span style=&quot;font-family:Courier New,monospace;&quot;&gt;&lt;span style=&quot;font-size:85%;&quot;&gt;(&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;color: rgb(35, 0, 251);&quot;&gt;&lt;span style=&quot;font-family:Courier New,monospace;&quot;&gt;&lt;span style=&quot;font-size:85%;&quot;&gt;y&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 0);&quot;&gt;&lt;span style=&quot;font-family:Courier New,monospace;&quot;&gt;&lt;span style=&quot;font-size:85%;&quot;&gt;.&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;color: rgb(35, 0, 251);&quot;&gt;&lt;span style=&quot;font-family:Courier New,monospace;&quot;&gt;&lt;span style=&quot;font-size:85%;&quot;&gt;weight&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 0);&quot;&gt;&lt;span style=&quot;font-family:Courier New,monospace;&quot;&gt;&lt;span style=&quot;font-size:85%;&quot;&gt;)&lt;/span&gt;&lt;/span&gt;&lt;/span&gt; &lt;/p&gt; &lt;p style=&quot;margin-bottom: 0in;&quot; align=&quot;left&quot;&gt;but this has the undesirable effect of reversing all the node comparations, and most of the time I&#39;ll bet we want to have the lighter nodes before the heavier ones, the reverse is counter-intuitive (and the potential source of nightmares). The solution? Let&#39;s create our particular flavor of DfsNode with the comparation reversed to use it in the PriorityQeue:&lt;/p&gt; &lt;p style=&quot;margin-bottom: 0in;&quot; align=&quot;left&quot;&gt;&lt;span style=&quot;color: rgb(0, 0, 0);&quot;&gt;  &lt;/span&gt;&lt;span style=&quot;font-family:Courier New,monospace;&quot;&gt;&lt;span style=&quot;font-size:85%;&quot;&gt;&lt;span style=&quot;color: rgb(76, 76, 76);&quot;&gt;class&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 0);&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: rgb(142, 62, 0);&quot;&gt;PQNode&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 0);&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: rgb(76, 76, 76);&quot;&gt;extends&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 0);&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: rgb(142, 62, 0);&quot;&gt;DfsNode&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 0);&quot;&gt; {&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt; &lt;p style=&quot;margin-bottom: 0in;&quot; align=&quot;left&quot;&gt;&lt;span style=&quot;color: rgb(0, 0, 0);&quot;&gt;    &lt;/span&gt;&lt;span style=&quot;font-family:Courier New,monospace;&quot;&gt;&lt;span style=&quot;font-size:85%;&quot;&gt;&lt;span style=&quot;color: rgb(76, 76, 76);&quot;&gt;override&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 0);&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: rgb(76, 76, 76);&quot;&gt;def&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 0);&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: rgb(0, 62, 133);&quot;&gt;compare&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 0);&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: rgb(35, 0, 251);&quot;&gt;y&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 0);&quot;&gt;: &lt;/span&gt;&lt;span style=&quot;color: rgb(142, 62, 0);&quot;&gt;Node&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 0);&quot;&gt;): &lt;/span&gt;&lt;span style=&quot;color: rgb(142, 62, 0);&quot;&gt;Int&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 0);&quot;&gt; = -&lt;/span&gt;&lt;span style=&quot;color: rgb(76, 76, 76);&quot;&gt;super&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 0);&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 62, 133);&quot;&gt;compare&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 0);&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: rgb(35, 0, 251);&quot;&gt;y&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 0);&quot;&gt;)&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt; &lt;p style=&quot;margin-bottom: 0in;&quot; align=&quot;left&quot;&gt;&lt;span style=&quot;color: rgb(0, 0, 0);&quot;&gt;  &lt;span style=&quot;font-family:Courier New,monospace;&quot;&gt;&lt;span style=&quot;font-size:85%;&quot;&gt;}&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt; &lt;p style=&quot;margin-bottom: 0in;&quot;&gt;&lt;span style=&quot;font-family:Times New Roman,serif;&quot;&gt;&lt;span style=&quot;font-size:100%;&quot;&gt;&lt;span style=&quot;color: rgb(0, 0, 0);&quot;&gt;And we just need to change our newNode method to return PQNodes instead of DfsNodes:&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt; &lt;p style=&quot;margin-bottom: 0in;&quot;&gt;&lt;span style=&quot;color: rgb(0, 0, 0);&quot;&gt;  &lt;/span&gt;&lt;span style=&quot;font-family:Courier New,monospace;&quot;&gt;&lt;span style=&quot;font-size:85%;&quot;&gt;&lt;span style=&quot;color: rgb(76, 76, 76);&quot;&gt;protected&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 0);&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: rgb(76, 76, 76);&quot;&gt;def&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 0);&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: rgb(0, 62, 133);&quot;&gt;newNode&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 0);&quot;&gt;: &lt;/span&gt;&lt;span style=&quot;color: rgb(142, 62, 0);&quot;&gt;Node&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 0);&quot;&gt; = &lt;/span&gt;&lt;span style=&quot;color: rgb(76, 76, 76);&quot;&gt;new&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 0);&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: rgb(142, 62, 0);&quot;&gt;PQNode&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt; &lt;p style=&quot;margin-bottom: 0in;&quot;&gt;&lt;span style=&quot;font-family:Times New Roman,serif;&quot;&gt;&lt;span style=&quot;font-size:100%;&quot;&gt;&lt;span style=&quot;color: rgb(0, 0, 0);&quot;&gt;For extra points on modularization, we can extract those changes and the code related to the algorithm in a subclass of DfsGraph.&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt; &lt;p style=&quot;margin-bottom: 0in;&quot;&gt;&lt;span style=&quot;font-family:Times New Roman,serif;&quot;&gt;&lt;span style=&quot;font-size:100%;&quot;&gt;&lt;span style=&quot;color: rgb(0, 0, 0);&quot;&gt;Here is the complete code:&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;margin-bottom: 0in;&quot;&gt;&lt;span style=&quot;font-family:Times New Roman,serif;&quot;&gt;&lt;span style=&quot;font-size:100%;&quot;&gt;&lt;span style=&quot;color: rgb(0, 0, 0);&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;br /&gt;&lt;code class=&quot;prettyprint&quot;&gt;&lt;br /&gt;package dfs2;&lt;br /&gt; &lt;br /&gt;abstract class Graph {&lt;br /&gt;  type Edge&lt;br /&gt;  type Node &lt;: NodeIntf&lt;br /&gt;  abstract class NodeIntf {&lt;br /&gt;   def connectWith(node: Node): Edge&lt;br /&gt;  }&lt;br /&gt;  def nodes: Set[Node]&lt;br /&gt;  def edges: Set[Edge]&lt;br /&gt;  def addNode: Node&lt;br /&gt;}&lt;br /&gt; &lt;br /&gt;abstract class DirectedGraph extends Graph {&lt;br /&gt;  type Edge &lt;: EdgeImpl&lt;br /&gt;  class EdgeImpl(origin: Node, dest: Node) {&lt;br /&gt;    def from = origin&lt;br /&gt;    def to = dest&lt;br /&gt;  }&lt;br /&gt; &lt;br /&gt;  class NodeImpl extends NodeIntf {&lt;br /&gt;    self: Node =&gt;&lt;br /&gt;    def connectWith(node: Node): Edge = {&lt;br /&gt;     val edge = newEdge(this, node)&lt;br /&gt;     edges = edges + edge&lt;br /&gt;     edge&lt;br /&gt;    }&lt;br /&gt;  }&lt;br /&gt;  &lt;br /&gt;  protected def newNode: Node&lt;br /&gt;  protected def newEdge(from: Node, to: Node): Edge&lt;br /&gt;  &lt;br /&gt;  var nodes: Set[Node] =Set()&lt;br /&gt;  var edges: Set[Edge] =Set()&lt;br /&gt;  def addNode: Node = {&lt;br /&gt;    val node = newNode&lt;br /&gt;    nodes = nodes + node&lt;br /&gt;    node&lt;br /&gt;  }&lt;br /&gt;}&lt;br /&gt; &lt;br /&gt;trait Weight {&lt;br /&gt;  var weight= Float.PositiveInfinity&lt;br /&gt;}&lt;br /&gt; &lt;br /&gt;import scala.collection.mutable.PriorityQueue;&lt;br /&gt; &lt;br /&gt;class DfsGraph extends DirectedGraph {&lt;br /&gt;  class DfsNode extends NodeImpl with Weight with Ordered[DfsNode]{&lt;br /&gt;  var previous: DfsNode = _&lt;br /&gt;  var label:String = _&lt;br /&gt;  var nodeEdges: Set[Edge] = Set()&lt;br /&gt;  &lt;br /&gt;  override def connectWith(node: Node): Edge = {&lt;br /&gt;    val newEdge=super.connectWith(node)&lt;br /&gt;    nodeEdges = nodeEdges + newEdge&lt;br /&gt;    newEdge&lt;br /&gt;  }&lt;br /&gt;    def --&gt;(n2:Node):DfsEdge =connectWith(n2)&lt;br /&gt; &lt;br /&gt;    override def toString()= label+ &quot; w:&quot;+weight&lt;br /&gt;    def compare(y: Node): Int = this.weight.compare(y.weight)&lt;br /&gt;  }&lt;br /&gt;  &lt;br /&gt; &lt;br /&gt;  class DfsEdge(origin:Node, dest:Node) extends EdgeImpl(origin, dest) with Weight {&lt;br /&gt;    override def toString()= from.label+&quot;--&gt;&quot;+to.label+&quot; w:&quot;+weight&lt;br /&gt;  }&lt;br /&gt; &lt;br /&gt;  def addNewNode(l:String):Node={&lt;br /&gt;    val newNode=super.addNode&lt;br /&gt;    newNode.label=l&lt;br /&gt;    newNode&lt;br /&gt;  }&lt;br /&gt; &lt;br /&gt;  type Node= DfsNode&lt;br /&gt;  type Edge= DfsEdge&lt;br /&gt; &lt;br /&gt;  protected def newEdge(from: Node, to: Node): Edge = new DfsEdge(from,to)&lt;br /&gt;  protected def newNode: Node = new DfsNode&lt;br /&gt;  &lt;br /&gt;}&lt;br /&gt; &lt;br /&gt;class DijkstraSPGraph extends DfsGraph {&lt;br /&gt;  &lt;br /&gt;  class PQNode extends DfsNode {&lt;br /&gt;    override def compare(y: Node): Int = -super.compare(y)&lt;br /&gt;  }&lt;br /&gt;  &lt;br /&gt;  override protected def newNode: Node = new PQNode&lt;br /&gt;  &lt;br /&gt;  def shortestPath(start: DfsNode, end: DfsNode) = {&lt;br /&gt;  val unvisited=new PriorityQueue[Node]()&lt;br /&gt;    unvisited++=(nodes)&lt;br /&gt;  start.weight=0&lt;br /&gt;  while (!unvisited.isEmpty) {&lt;br /&gt;    val vertx=unvisited.dequeue&lt;br /&gt;        for (v &lt;- vertx.nodeEdges if canImprove(v)){&lt;br /&gt;          unvisited+improveDistance(v)&lt;br /&gt;        }&lt;br /&gt;  }&lt;br /&gt;  }&lt;br /&gt;  &lt;br /&gt;  def canImprove(a:Edge)=(a.from.weight+a.weight&lt; a.to.weight)&lt;br /&gt;  &lt;br /&gt;  def improveDistance(a:Edge) ={&lt;br /&gt;    val v=a.to&lt;br /&gt;  v.weight=a.from.weight+a.weight&lt;br /&gt;  v.previous=a.from&lt;br /&gt;    v&lt;br /&gt;  }&lt;br /&gt; &lt;br /&gt;  def pathToStart(end:DfsNode):List[DfsNode] = {&lt;br /&gt;    if (end == null)&lt;br /&gt;      Nil&lt;br /&gt;    else&lt;br /&gt;        end :: pathToStart(end.previous)&lt;br /&gt;  }&lt;br /&gt;}&lt;br /&gt; &lt;br /&gt; &lt;br /&gt;object Example extends Application {&lt;br /&gt; &lt;br /&gt;  val graph = new DijkstraSPGraph&lt;br /&gt; &lt;br /&gt;  val n1=graph addNewNode &quot;start&quot;&lt;br /&gt;  val n2=graph addNewNode &quot;n2&quot;&lt;br /&gt;  val n3=graph addNewNode &quot;n3&quot;&lt;br /&gt;  val n4=graph addNewNode &quot;n4&quot;&lt;br /&gt;  val n5=graph addNewNode &quot;n5&quot;&lt;br /&gt;  val n6=graph addNewNode &quot;end&quot;&lt;br /&gt;  graph addNewNode &quot;alone&quot;&lt;br /&gt;  &lt;br /&gt;  n1--&gt;n2 weight=2&lt;br /&gt;  n1--&gt;n3 weight=1&lt;br /&gt;  n2--&gt;n4 weight=1&lt;br /&gt;  n3--&gt;n4 weight=3&lt;br /&gt;  n2--&gt;n5 weight=1&lt;br /&gt;  n4--&gt;n6 weight=1&lt;br /&gt;  n5--&gt;n6 weight=3&lt;br /&gt;  &lt;br /&gt;  n1--&gt;n6 weight=7&lt;br /&gt;  n1--&gt;n4 weight=10&lt;br /&gt;  &lt;br /&gt;  graph.shortestPath(n1,n6)&lt;br /&gt;  println(&quot;Path&quot;)&lt;br /&gt;  graph.pathToStart(n6).reverse.map(println(_))&lt;br /&gt;  &lt;br /&gt;}&lt;br /&gt;&lt;/code&gt;</description><link>http://gabrielsw.blogspot.com/2008/12/playing-with-scala-5-more-variations.html</link><author>noreply@blogger.com (Anonymous)</author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgQjzOIupoIwV0cIW-zxvCL_SFh85WqkyeFf8NFiOF5l3_wXYuDm2Awci6XrXTb8bX0Xw5ANzxzP5qntkG8_H3uN5kPrXB0kJE1uqQJdiU-XQDu3OyEowKMDO7oS32g8XJGUkIWk45lhRk/s72-c/095.JPG" height="72" width="72"/><thr:total>1</thr:total></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-6893032696317132921.post-4288549009546759320</guid><pubDate>Mon, 15 Dec 2008 03:28:00 +0000</pubDate><atom:updated>2008-12-14T22:51:33.372-05:00</atom:updated><category domain="http://www.blogger.com/atom/ns#">code</category><category domain="http://www.blogger.com/atom/ns#">functional programming</category><category domain="http://www.blogger.com/atom/ns#">optimization</category><category domain="http://www.blogger.com/atom/ns#">pathfinding</category><category domain="http://www.blogger.com/atom/ns#">refactoring</category><category domain="http://www.blogger.com/atom/ns#">Scala</category><title>Playing with Scala 5: improving code, use of views and comprehensions</title><description>&lt;a onblur=&quot;try {parent.deselectBloggerImageGracefully();} catch(e) {}&quot; href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEju9d62hGeSMD9xOwa3vN9prz9BhL-HtuYFJvrcVrhmMkyfDpgFwsigG-igjhXzTAPFhi1BxBmXShn6bHp1qsiKPVrlSYFoieAVNwHqfiBSC2bWC9lqWBtUF4ODbPo0v50O3aM_tHooi2c/s1600-h/IMG_0329.JPG&quot;&gt;&lt;img style=&quot;margin: 0pt 10px 10px 0pt; float: left; cursor: pointer; width: 345px; height: 259px;&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEju9d62hGeSMD9xOwa3vN9prz9BhL-HtuYFJvrcVrhmMkyfDpgFwsigG-igjhXzTAPFhi1BxBmXShn6bHp1qsiKPVrlSYFoieAVNwHqfiBSC2bWC9lqWBtUF4ODbPo0v50O3aM_tHooi2c/s400/IMG_0329.JPG&quot; alt=&quot;&quot; id=&quot;BLOGGER_PHOTO_ID_5279857195785170898&quot; border=&quot;0&quot; /&gt;&lt;/a&gt;&lt;style type=&quot;text/css&quot;&gt;e { size: 8.5in 11in; margin: 0.79in }   P { margin-bottom: 0.08in }  --&gt;&lt;/style&gt;After reading about different optimization to pathfinding algorithms, I decided to improve my Dijkstra implementation by using a priority queue instead of a set for the unvisited nodes. Using the “weight” of the vertex as the priority, we can avoid searching the whole set for the minimum and we reduce the cost of the operation from  O(n) to O(log n).&lt;br /&gt;&lt;p style=&quot;margin-bottom: 0in;&quot;&gt;The first change is replace the set with Scala&#39;s priority queue:&lt;/p&gt; &lt;p style=&quot;margin-bottom: 0in;&quot;&gt;&lt;br /&gt;&lt;/p&gt; &lt;p style=&quot;margin-bottom: 0in;&quot; align=&quot;left&quot;&gt;&lt;span style=&quot;color: rgb(76, 76, 76);&quot;&gt;  &lt;span style=&quot;font-family:Courier New,monospace;&quot;&gt;&lt;span style=&quot;font-size:85%;&quot;&gt;val&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 0);&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: rgb(35, 0, 251);&quot;&gt;unvisited&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 0);&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: rgb(76, 76, 76);&quot;&gt;new&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 0);&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: rgb(142, 62, 0);&quot;&gt;PriorityQueue&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 0);&quot;&gt;[&lt;/span&gt;&lt;span style=&quot;color: rgb(142, 62, 0);&quot;&gt;Node&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 0);&quot;&gt;]()&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt; &lt;p style=&quot;margin-bottom: 0in;&quot;&gt;&lt;br /&gt;&lt;/p&gt; &lt;p style=&quot;margin-bottom: 0in;&quot;&gt;&lt;span style=&quot;color: rgb(0, 0, 0);&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;margin-bottom: 0in;&quot;&gt;&lt;span style=&quot;color: rgb(0, 0, 0);&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;margin-bottom: 0in;&quot;&gt;&lt;span style=&quot;color: rgb(0, 0, 0);&quot;&gt;But as it is, it will not compile: the priority queue&#39;s signature is &lt;/span&gt; &lt;/p&gt; &lt;p style=&quot;margin-bottom: 0in;&quot;&gt;&lt;br /&gt;&lt;/p&gt; &lt;p style=&quot;margin-bottom: 0in;&quot;&gt;&lt;code&gt;&lt;span style=&quot;color: rgb(76, 76, 76);&quot;&gt;  &lt;span style=&quot;font-family:Courier New,monospace;&quot;&gt;&lt;span style=&quot;font-size:85%;&quot;&gt;class&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;code&gt;&lt;span style=&quot;color: rgb(0, 0, 0);&quot;&gt;&lt;span style=&quot;font-family:Courier New,monospace;&quot;&gt;&lt;span style=&quot;font-size:85%;&quot;&gt; PriorityQueue[A](&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;code&gt;&lt;span style=&quot;color: rgb(76, 76, 76);&quot;&gt;&lt;span style=&quot;font-family:Courier New,monospace;&quot;&gt;&lt;span style=&quot;font-size:85%;&quot;&gt;implicit&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;code&gt;&lt;span style=&quot;color: rgb(0, 0, 0);&quot;&gt;&lt;span style=&quot;font-family:Courier New,monospace;&quot;&gt;&lt;span style=&quot;font-size:85%;&quot;&gt; view$1 : (A) =&gt; Ordered[A])&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;code&gt;&lt;span style=&quot;color: rgb(0, 0, 0);&quot;&gt;&lt;span style=&quot;font-family:Courier New,monospace;&quot;&gt;&lt;span style=&quot;font-size:85%;&quot;&gt;&lt;span style=&quot;text-decoration: none;&quot;&gt; &lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;code&gt;&lt;span style=&quot;color: rgb(76, 76, 76);&quot;&gt;&lt;span style=&quot;font-family:Courier New,monospace;&quot;&gt;&lt;span style=&quot;font-size:85%;&quot;&gt;&lt;span style=&quot;text-decoration: none;&quot;&gt;extends  &lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;code&gt;&lt;span style=&quot;color: rgb(0, 0, 0);&quot;&gt;&lt;span style=&quot;font-family:Courier New,monospace;&quot;&gt;&lt;span style=&quot;font-size:85%;&quot;&gt;ResizableArray[A] &lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;code&gt;&lt;span style=&quot;color: rgb(76, 76, 76);&quot;&gt;&lt;span style=&quot;font-family:Courier New,monospace;&quot;&gt;&lt;span style=&quot;font-size:85%;&quot;&gt;with&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;code&gt;&lt;span style=&quot;color: rgb(0, 0, 0);&quot;&gt;&lt;span style=&quot;font-family:Courier New,monospace;&quot;&gt;&lt;span style=&quot;font-size:85%;&quot;&gt; CloneableCollection&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/p&gt; &lt;p style=&quot;margin-bottom: 0in;&quot;&gt;&lt;br /&gt;&lt;/p&gt; &lt;p style=&quot;margin-bottom: 0in;&quot;&gt;&lt;span style=&quot;color: rgb(0, 0, 0);&quot;&gt;You need to provide an implicit conversion from the parameter type A to the type Ordered[A]. But nothing to worry about: is as easy as&lt;/span&gt;&lt;/p&gt; &lt;p style=&quot;margin-bottom: 0in;&quot;&gt;&lt;br /&gt;&lt;/p&gt; &lt;p style=&quot;margin-bottom: 0in;&quot;&gt;&lt;span style=&quot;color: rgb(0, 0, 0);&quot;&gt;  &lt;/span&gt;&lt;span style=&quot;font-family:Courier New,monospace;&quot;&gt;&lt;span style=&quot;font-size:85%;&quot;&gt;&lt;span style=&quot;color: rgb(76, 76, 76);&quot;&gt;implicit&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 0);&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: rgb(76, 76, 76);&quot;&gt;def&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 0);&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: rgb(0, 62, 133);&quot;&gt;node2ordered&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 0);&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: rgb(35, 0, 251);&quot;&gt;n&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 0);&quot;&gt;: &lt;/span&gt;&lt;span style=&quot;color: rgb(142, 62, 0);&quot;&gt;Node&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 0);&quot;&gt;): &lt;/span&gt;&lt;span style=&quot;color: rgb(142, 62, 0);&quot;&gt;Ordered&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 0);&quot;&gt;[&lt;/span&gt;&lt;span style=&quot;color: rgb(142, 62, 0);&quot;&gt;Node&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 0);&quot;&gt;] = &lt;/span&gt;&lt;span style=&quot;color: rgb(76, 76, 76);&quot;&gt;new&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 0);&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: rgb(142, 62, 0);&quot;&gt;Ordered&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 0);&quot;&gt;[&lt;/span&gt;&lt;span style=&quot;color: rgb(142, 62, 0);&quot;&gt;Node&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 0);&quot;&gt;] {&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt; &lt;p style=&quot;margin-bottom: 0in;&quot; align=&quot;left&quot;&gt;&lt;span style=&quot;color: rgb(0, 0, 0);&quot;&gt;     &lt;/span&gt;&lt;span style=&quot;font-family:Courier New,monospace;&quot;&gt;&lt;span style=&quot;font-size:85%;&quot;&gt;&lt;span style=&quot;color: rgb(255, 94, 94);&quot;&gt;//reverse the comparation so highest priority = lower cost&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt; &lt;p style=&quot;margin-bottom: 0in;&quot; align=&quot;left&quot;&gt;&lt;span style=&quot;color: rgb(0, 0, 0);&quot;&gt;     &lt;/span&gt;&lt;span style=&quot;font-family:Courier New,monospace;&quot;&gt;&lt;span style=&quot;font-size:85%;&quot;&gt;&lt;span style=&quot;color: rgb(76, 76, 76);&quot;&gt;def&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 0);&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: rgb(0, 62, 133);&quot;&gt;compare&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 0);&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: rgb(35, 0, 251);&quot;&gt;y&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 0);&quot;&gt;: &lt;/span&gt;&lt;span style=&quot;color: rgb(142, 62, 0);&quot;&gt;Node&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 0);&quot;&gt;): &lt;/span&gt;&lt;span style=&quot;color: rgb(142, 62, 0);&quot;&gt;Int&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 0);&quot;&gt; = -(&lt;/span&gt;&lt;span style=&quot;color: rgb(35, 0, 251);&quot;&gt;n&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 0);&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: rgb(35, 0, 251);&quot;&gt;weight&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 0);&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 62, 133);&quot;&gt;compare&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 0);&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: rgb(35, 0, 251);&quot;&gt;y&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 0);&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: rgb(35, 0, 251);&quot;&gt;weight&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 0);&quot;&gt;))&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt; &lt;p style=&quot;margin-bottom: 0in;&quot; align=&quot;left&quot;&gt;&lt;span style=&quot;color: rgb(0, 0, 0);&quot;&gt;  &lt;span style=&quot;font-family:Courier New,monospace;&quot;&gt;&lt;span style=&quot;font-size:85%;&quot;&gt;}&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt; &lt;p style=&quot;margin-bottom: 0in;&quot; align=&quot;left&quot;&gt;&lt;br /&gt;&lt;/p&gt; &lt;p style=&quot;margin-bottom: 0in;&quot;&gt;&lt;span style=&quot;color: rgb(0, 0, 0);&quot;&gt;Look at the improveDistance function, it does two things: filters the nodes and updates the distance if we can improve it. I think is better if we split into two different functions, separating the filtering from the updating, so instead of:&lt;/span&gt;&lt;/p&gt; &lt;p style=&quot;margin-bottom: 0in;&quot; align=&quot;left&quot;&gt;&lt;br /&gt;&lt;/p&gt; &lt;p style=&quot;margin-bottom: 0in;&quot; align=&quot;left&quot;&gt;&lt;span style=&quot;color: rgb(127, 127, 127);&quot;&gt;&lt;span style=&quot;font-family:Courier New;&quot;&gt;&lt;span style=&quot;font-size:85%;&quot;&gt;&lt;b&gt;def&lt;/b&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 0);&quot;&gt;&lt;span style=&quot;font-family:Courier New,monospace;&quot;&gt;&lt;span style=&quot;font-size:85%;&quot;&gt; &lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;color: rgb(30, 144, 255);&quot;&gt;&lt;span style=&quot;font-family:Courier New;&quot;&gt;&lt;span style=&quot;font-size:85%;&quot;&gt;&lt;b&gt;improveDistance&lt;/b&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 0);&quot;&gt;&lt;span style=&quot;font-family:Courier New;&quot;&gt;&lt;span style=&quot;font-size:85%;&quot;&gt;(&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;color: rgb(27, 27, 215);&quot;&gt;&lt;span style=&quot;font-family:Courier New;&quot;&gt;&lt;span style=&quot;font-size:85%;&quot;&gt;&lt;i&gt;&lt;b&gt;a&lt;/b&gt;&lt;/i&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 0);&quot;&gt;&lt;span style=&quot;font-family:Courier New;&quot;&gt;&lt;span style=&quot;font-size:85%;&quot;&gt;:Edge) ={&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 0);&quot;&gt;&lt;span style=&quot;font-family:Courier New,monospace;&quot;&gt;&lt;span style=&quot;font-size:85%;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;color: rgb(127, 127, 127);&quot;&gt;&lt;span style=&quot;font-family:Courier New;&quot;&gt;&lt;span style=&quot;font-size:85%;&quot;&gt;&lt;b&gt;if&lt;/b&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 0);&quot;&gt;&lt;span style=&quot;font-family:Courier New,monospace;&quot;&gt;&lt;span style=&quot;font-size:85%;&quot;&gt; &lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 0);&quot;&gt;&lt;span style=&quot;font-family:Courier New;&quot;&gt;&lt;span style=&quot;font-size:85%;&quot;&gt;(&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;color: rgb(27, 27, 215);&quot;&gt;&lt;span style=&quot;font-family:Courier New;&quot;&gt;&lt;span style=&quot;font-size:85%;&quot;&gt;&lt;i&gt;&lt;b&gt;a&lt;/b&gt;&lt;/i&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 0);&quot;&gt;&lt;span style=&quot;font-family:Courier New;&quot;&gt;&lt;span style=&quot;font-size:85%;&quot;&gt;.&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;color: rgb(30, 144, 255);&quot;&gt;&lt;span style=&quot;font-family:Courier New;&quot;&gt;&lt;span style=&quot;font-size:85%;&quot;&gt;&lt;b&gt;from&lt;/b&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 0);&quot;&gt;&lt;span style=&quot;font-family:Courier New;&quot;&gt;&lt;span style=&quot;font-size:85%;&quot;&gt;.&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;color: rgb(27, 27, 215);&quot;&gt;&lt;span style=&quot;font-family:Courier New;&quot;&gt;&lt;span style=&quot;font-size:85%;&quot;&gt;&lt;b&gt;weight&lt;/b&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 0);&quot;&gt;&lt;span style=&quot;font-family:Courier New;&quot;&gt;&lt;span style=&quot;font-size:85%;&quot;&gt;+&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;color: rgb(27, 27, 215);&quot;&gt;&lt;span style=&quot;font-family:Courier New;&quot;&gt;&lt;span style=&quot;font-size:85%;&quot;&gt;&lt;i&gt;&lt;b&gt;a&lt;/b&gt;&lt;/i&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 0);&quot;&gt;&lt;span style=&quot;font-family:Courier New;&quot;&gt;&lt;span style=&quot;font-size:85%;&quot;&gt;.&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;color: rgb(27, 27, 215);&quot;&gt;&lt;span style=&quot;font-family:Courier New;&quot;&gt;&lt;span style=&quot;font-size:85%;&quot;&gt;&lt;b&gt;weight&lt;/b&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;color: rgb(30, 144, 255);&quot;&gt;&lt;span style=&quot;font-family:Courier New;&quot;&gt;&lt;span style=&quot;font-size:85%;&quot;&gt;&lt;b&gt;&lt;&lt;/b&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 0);&quot;&gt;&lt;span style=&quot;font-family:Courier New,monospace;&quot;&gt;&lt;span style=&quot;font-size:85%;&quot;&gt; &lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;color: rgb(27, 27, 215);&quot;&gt;&lt;span style=&quot;font-family:Courier New;&quot;&gt;&lt;span style=&quot;font-size:85%;&quot;&gt;&lt;i&gt;&lt;b&gt;a&lt;/b&gt;&lt;/i&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 0);&quot;&gt;&lt;span style=&quot;font-family:Courier New;&quot;&gt;&lt;span style=&quot;font-size:85%;&quot;&gt;.&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;color: rgb(30, 144, 255);&quot;&gt;&lt;span style=&quot;font-family:Courier New;&quot;&gt;&lt;span style=&quot;font-size:85%;&quot;&gt;&lt;b&gt;to&lt;/b&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 0);&quot;&gt;&lt;span style=&quot;font-family:Courier New;&quot;&gt;&lt;span style=&quot;font-size:85%;&quot;&gt;.&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;color: rgb(27, 27, 215);&quot;&gt;&lt;span style=&quot;font-family:Courier New;&quot;&gt;&lt;span style=&quot;font-size:85%;&quot;&gt;&lt;b&gt;weight&lt;/b&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 0);&quot;&gt;&lt;span style=&quot;font-family:Courier New;&quot;&gt;&lt;span style=&quot;font-size:85%;&quot;&gt;) {&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 0);&quot;&gt;&lt;span style=&quot;font-family:Courier New,monospace;&quot;&gt;&lt;span style=&quot;font-size:85%;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;color: rgb(27, 27, 215);&quot;&gt;&lt;span style=&quot;font-family:Courier New;&quot;&gt;&lt;span style=&quot;font-size:85%;&quot;&gt;&lt;i&gt;&lt;b&gt;a&lt;/b&gt;&lt;/i&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 0);&quot;&gt;&lt;span style=&quot;font-family:Courier New;&quot;&gt;&lt;span style=&quot;font-size:85%;&quot;&gt;.&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;color: rgb(30, 144, 255);&quot;&gt;&lt;span style=&quot;font-family:Courier New;&quot;&gt;&lt;span style=&quot;font-size:85%;&quot;&gt;&lt;b&gt;to&lt;/b&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 0);&quot;&gt;&lt;span style=&quot;font-family:Courier New;&quot;&gt;&lt;span style=&quot;font-size:85%;&quot;&gt;.&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;color: rgb(27, 27, 215);&quot;&gt;&lt;span style=&quot;font-family:Courier New;&quot;&gt;&lt;span style=&quot;font-size:85%;&quot;&gt;&lt;b&gt;weight&lt;/b&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 0);&quot;&gt;&lt;span style=&quot;font-family:Courier New;&quot;&gt;&lt;span style=&quot;font-size:85%;&quot;&gt;=&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;color: rgb(27, 27, 215);&quot;&gt;&lt;span style=&quot;font-family:Courier New;&quot;&gt;&lt;span style=&quot;font-size:85%;&quot;&gt;&lt;i&gt;&lt;b&gt;a&lt;/b&gt;&lt;/i&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 0);&quot;&gt;&lt;span style=&quot;font-family:Courier New;&quot;&gt;&lt;span style=&quot;font-size:85%;&quot;&gt;.&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;color: rgb(30, 144, 255);&quot;&gt;&lt;span style=&quot;font-family:Courier New;&quot;&gt;&lt;span style=&quot;font-size:85%;&quot;&gt;&lt;b&gt;from&lt;/b&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 0);&quot;&gt;&lt;span style=&quot;font-family:Courier New;&quot;&gt;&lt;span style=&quot;font-size:85%;&quot;&gt;.&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;color: rgb(27, 27, 215);&quot;&gt;&lt;span style=&quot;font-family:Courier New;&quot;&gt;&lt;span style=&quot;font-size:85%;&quot;&gt;&lt;b&gt;weight&lt;/b&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 0);&quot;&gt;&lt;span style=&quot;font-family:Courier New;&quot;&gt;&lt;span style=&quot;font-size:85%;&quot;&gt;+&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;color: rgb(27, 27, 215);&quot;&gt;&lt;span style=&quot;font-family:Courier New;&quot;&gt;&lt;span style=&quot;font-size:85%;&quot;&gt;&lt;i&gt;&lt;b&gt;a&lt;/b&gt;&lt;/i&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 0);&quot;&gt;&lt;span style=&quot;font-family:Courier New;&quot;&gt;&lt;span style=&quot;font-size:85%;&quot;&gt;.&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;color: rgb(27, 27, 215);&quot;&gt;&lt;span style=&quot;font-family:Courier New;&quot;&gt;&lt;span style=&quot;font-size:85%;&quot;&gt;&lt;b&gt;weight&lt;/b&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 0);&quot;&gt;&lt;span style=&quot;font-family:Courier New,monospace;&quot;&gt;&lt;span style=&quot;font-size:85%;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;color: rgb(27, 27, 215);&quot;&gt;&lt;span style=&quot;font-family:Courier New;&quot;&gt;&lt;span style=&quot;font-size:85%;&quot;&gt;&lt;i&gt;&lt;b&gt;a&lt;/b&gt;&lt;/i&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 0);&quot;&gt;&lt;span style=&quot;font-family:Courier New;&quot;&gt;&lt;span style=&quot;font-size:85%;&quot;&gt;.&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;color: rgb(30, 144, 255);&quot;&gt;&lt;span style=&quot;font-family:Courier New;&quot;&gt;&lt;span style=&quot;font-size:85%;&quot;&gt;&lt;b&gt;to&lt;/b&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 0);&quot;&gt;&lt;span style=&quot;font-family:Courier New;&quot;&gt;&lt;span style=&quot;font-size:85%;&quot;&gt;.&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;color: rgb(27, 27, 215);&quot;&gt;&lt;span style=&quot;font-family:Courier New;&quot;&gt;&lt;span style=&quot;font-size:85%;&quot;&gt;&lt;b&gt;previous&lt;/b&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 0);&quot;&gt;&lt;span style=&quot;font-family:Courier New;&quot;&gt;&lt;span style=&quot;font-size:85%;&quot;&gt;=&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;color: rgb(27, 27, 215);&quot;&gt;&lt;span style=&quot;font-family:Courier New;&quot;&gt;&lt;span style=&quot;font-size:85%;&quot;&gt;&lt;i&gt;&lt;b&gt;a&lt;/b&gt;&lt;/i&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 0);&quot;&gt;&lt;span style=&quot;font-family:Courier New;&quot;&gt;&lt;span style=&quot;font-size:85%;&quot;&gt;.&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;color: rgb(30, 144, 255);&quot;&gt;&lt;span style=&quot;font-family:Courier New;&quot;&gt;&lt;span style=&quot;font-size:85%;&quot;&gt;&lt;b&gt;from&lt;/b&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 0);&quot;&gt;&lt;span style=&quot;font-family:Courier New,monospace;&quot;&gt;&lt;span style=&quot;font-size:85%;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 0);&quot;&gt;&lt;span style=&quot;font-family:Courier New;&quot;&gt;&lt;span style=&quot;font-size:85%;&quot;&gt;}&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 0);&quot;&gt;&lt;span style=&quot;font-family:Courier New,monospace;&quot;&gt;&lt;span style=&quot;font-size:85%;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 0);&quot;&gt;&lt;span style=&quot;font-family:Courier New;&quot;&gt;&lt;span style=&quot;font-size:85%;&quot;&gt;}&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 0);&quot;&gt;&lt;span style=&quot;font-family:Courier New,monospace;&quot;&gt;&lt;span style=&quot;font-size:85%;&quot;&gt; &lt;/span&gt;&lt;/span&gt;&lt;/span&gt; &lt;/p&gt; &lt;p style=&quot;margin-bottom: 0in;&quot; align=&quot;left&quot;&gt;&lt;br /&gt;&lt;/p&gt; &lt;p style=&quot;margin-bottom: 0in;&quot;&gt;we get:&lt;/p&gt; &lt;p style=&quot;margin-bottom: 0in;&quot; align=&quot;left&quot;&gt;&lt;span style=&quot;color: rgb(0, 0, 0);&quot;&gt;    &lt;/span&gt;&lt;span style=&quot;font-family:Courier New,monospace;&quot;&gt;&lt;span style=&quot;font-size:85%;&quot;&gt;&lt;span style=&quot;color: rgb(76, 76, 76);&quot;&gt;def&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 0);&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: rgb(0, 62, 133);&quot;&gt;canImprove&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 0);&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: rgb(35, 0, 251);&quot;&gt;a&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 0);&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: rgb(142, 62, 0);&quot;&gt;Edge&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 0);&quot;&gt;)=(&lt;/span&gt;&lt;span style=&quot;color: rgb(35, 0, 251);&quot;&gt;a&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 0);&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 62, 133);&quot;&gt;from&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 0);&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: rgb(35, 0, 251);&quot;&gt;weight&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 62, 133);&quot;&gt;+&lt;/span&gt;&lt;span style=&quot;color: rgb(35, 0, 251);&quot;&gt;a&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 0);&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: rgb(35, 0, 251);&quot;&gt;weight&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 62, 133);&quot;&gt;&lt;&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 0);&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: rgb(35, 0, 251);&quot;&gt;a&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 0);&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 62, 133);&quot;&gt;to&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 0);&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: rgb(35, 0, 251);&quot;&gt;weight&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 0);&quot;&gt;)&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt; &lt;p style=&quot;margin-bottom: 0in;&quot;&gt;and   &lt;/p&gt; &lt;p style=&quot;margin-bottom: 0in;&quot; align=&quot;left&quot;&gt;&lt;span style=&quot;color: rgb(0, 0, 0);&quot;&gt;  &lt;/span&gt;&lt;span style=&quot;color: rgb(76, 76, 76);&quot;&gt;&lt;span style=&quot;font-family:Courier New,monospace;&quot;&gt;&lt;span style=&quot;font-size:85%;&quot;&gt;def&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 0);&quot;&gt;&lt;span style=&quot;font-family:Courier New,monospace;&quot;&gt;&lt;span style=&quot;font-size:85%;&quot;&gt; &lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 62, 133);&quot;&gt;&lt;span style=&quot;font-family:Courier New,monospace;&quot;&gt;&lt;span style=&quot;font-size:85%;&quot;&gt;improveDistance&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 0);&quot;&gt;&lt;span style=&quot;font-family:Courier New,monospace;&quot;&gt;&lt;span style=&quot;font-size:85%;&quot;&gt;(&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;color: rgb(35, 0, 251);&quot;&gt;&lt;span style=&quot;font-family:Courier New,monospace;&quot;&gt;&lt;span style=&quot;font-size:85%;&quot;&gt;a&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 0);&quot;&gt;&lt;span style=&quot;font-family:Courier New,monospace;&quot;&gt;&lt;span style=&quot;font-size:85%;&quot;&gt;:&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;color: rgb(142, 62, 0);&quot;&gt;&lt;span style=&quot;font-family:Courier New,monospace;&quot;&gt;&lt;span style=&quot;font-size:85%;&quot;&gt;Edge&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 0);&quot;&gt;&lt;span style=&quot;font-family:Courier New,monospace;&quot;&gt;&lt;span style=&quot;font-size:85%;&quot;&gt;) ={&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt; &lt;p style=&quot;margin-bottom: 0in;&quot; align=&quot;left&quot;&gt;&lt;span style=&quot;color: rgb(0, 0, 0);&quot;&gt;      &lt;/span&gt;&lt;span style=&quot;font-family:Courier New,monospace;&quot;&gt;&lt;span style=&quot;font-size:85%;&quot;&gt;&lt;span style=&quot;color: rgb(35, 0, 251);&quot;&gt;a&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 0);&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 62, 133);&quot;&gt;to&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 0);&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: rgb(35, 0, 251);&quot;&gt;weight&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 0);&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: rgb(35, 0, 251);&quot;&gt;a&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 0);&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 62, 133);&quot;&gt;from&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 0);&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: rgb(35, 0, 251);&quot;&gt;weight&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 62, 133);&quot;&gt;+&lt;/span&gt;&lt;span style=&quot;color: rgb(35, 0, 251);&quot;&gt;a&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 0);&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: rgb(35, 0, 251);&quot;&gt;weight&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt; &lt;p style=&quot;margin-bottom: 0in;&quot; align=&quot;left&quot;&gt;&lt;span style=&quot;color: rgb(0, 0, 0);&quot;&gt;      &lt;/span&gt;&lt;span style=&quot;font-family:Courier New,monospace;&quot;&gt;&lt;span style=&quot;font-size:85%;&quot;&gt;&lt;span style=&quot;color: rgb(35, 0, 251);&quot;&gt;a&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 0);&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 62, 133);&quot;&gt;to&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 0);&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: rgb(35, 0, 251);&quot;&gt;previous&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 0);&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: rgb(35, 0, 251);&quot;&gt;a&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 0);&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 62, 133);&quot;&gt;from&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt; &lt;p style=&quot;margin-bottom: 0in;&quot; align=&quot;left&quot;&gt;&lt;span style=&quot;color: rgb(0, 0, 0);&quot;&gt;      &lt;/span&gt;&lt;span style=&quot;font-family:Courier New,monospace;&quot;&gt;&lt;span style=&quot;font-size:85%;&quot;&gt;&lt;span style=&quot;color: rgb(35, 0, 251);&quot;&gt;a&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 0);&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 62, 133);&quot;&gt;to&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt; &lt;p style=&quot;margin-bottom: 0in;&quot; align=&quot;left&quot;&gt;&lt;span style=&quot;color: rgb(0, 0, 0);&quot;&gt;  &lt;span style=&quot;font-family:Courier New,monospace;&quot;&gt;&lt;span style=&quot;font-size:85%;&quot;&gt;}&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt; &lt;p style=&quot;margin-bottom: 0in;&quot; align=&quot;left&quot;&gt;&lt;br /&gt;&lt;/p&gt; &lt;p style=&quot;margin-bottom: 0in;&quot;&gt;Then, instead of a function map over the nodeEdges, we have to filter and then map:  &lt;/p&gt; &lt;p style=&quot;margin-bottom: 0in;&quot; align=&quot;left&quot;&gt;&lt;br /&gt;&lt;/p&gt; &lt;p style=&quot;margin-bottom: 0in;&quot; align=&quot;left&quot;&gt;&lt;span style=&quot;color: rgb(27, 27, 215);&quot;&gt;&lt;span style=&quot;font-family:Courier New;&quot;&gt;&lt;span style=&quot;font-size:85%;&quot;&gt;&lt;b&gt;vertx&lt;/b&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 0);&quot;&gt;&lt;span style=&quot;font-family:Courier New;&quot;&gt;&lt;span style=&quot;font-size:85%;&quot;&gt;.&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;color: rgb(27, 27, 215);&quot;&gt;&lt;span style=&quot;font-family:Courier New;&quot;&gt;&lt;span style=&quot;font-size:85%;&quot;&gt;&lt;b&gt;nodeEdges&lt;/b&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 0);&quot;&gt;&lt;span style=&quot;font-family:Courier New;&quot;&gt;&lt;span style=&quot;font-size:85%;&quot;&gt;.&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;color: rgb(30, 144, 255);&quot;&gt;&lt;span style=&quot;font-family:Courier New;&quot;&gt;&lt;span style=&quot;font-size:85%;&quot;&gt;&lt;b&gt;map&lt;/b&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 0);&quot;&gt;&lt;span style=&quot;font-family:Courier New;&quot;&gt;&lt;span style=&quot;font-size:85%;&quot;&gt;(&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;color: rgb(30, 144, 255);&quot;&gt;&lt;span style=&quot;font-family:Courier New;&quot;&gt;&lt;span style=&quot;font-size:85%;&quot;&gt;&lt;b&gt;improveDistance&lt;/b&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 0);&quot;&gt;&lt;span style=&quot;font-family:Courier New;&quot;&gt;&lt;span style=&quot;font-size:85%;&quot;&gt;(_))&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 0);&quot;&gt;&lt;span style=&quot;font-family:Courier New,monospace;&quot;&gt;&lt;span style=&quot;font-size:85%;&quot;&gt; &lt;/span&gt;&lt;/span&gt;&lt;/span&gt; &lt;/p&gt; &lt;p style=&quot;margin-bottom: 0in;&quot; align=&quot;left&quot;&gt;&lt;br /&gt;&lt;/p&gt; &lt;p style=&quot;margin-bottom: 0in;&quot;&gt;is replaced by&lt;/p&gt; &lt;p style=&quot;margin-bottom: 0in;&quot; align=&quot;left&quot;&gt;&lt;br /&gt;&lt;/p&gt; &lt;p style=&quot;margin-bottom: 0in;&quot; align=&quot;left&quot;&gt;&lt;span style=&quot;color: rgb(0, 0, 0);&quot;&gt;&lt;span style=&quot;font-family:Courier New,monospace;&quot;&gt;&lt;span style=&quot;font-size:85%;&quot;&gt;&lt;span style=&quot;color: rgb(35, 0, 251);&quot;&gt;vertx&lt;/span&gt;.&lt;span style=&quot;color: rgb(35, 0, 251);&quot;&gt;nodeEdges&lt;/span&gt;.&lt;span style=&quot;color: rgb(0, 62, 133);&quot;&gt;filter&lt;/span&gt;(&lt;span style=&quot;color: rgb(0, 62, 133);&quot;&gt;canImprove&lt;/span&gt;(_))).&lt;span style=&quot;color: rgb(0, 62, 133);&quot;&gt;map&lt;/span&gt;(&lt;span style=&quot;color: rgb(0, 62, 133);&quot;&gt;improveDistance&lt;/span&gt;(_)&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt; &lt;p style=&quot;margin-bottom: 0in;&quot; align=&quot;left&quot;&gt;&lt;br /&gt;&lt;/p&gt; &lt;p style=&quot;margin-bottom: 0in;&quot;&gt;that gives a better picture of the steps involved.&lt;/p&gt; &lt;p style=&quot;margin-bottom: 0in;&quot;&gt;As we need to add the updated nodes to the priority queue so they can “float” to the top, the line would look like:&lt;/p&gt; &lt;p style=&quot;margin-bottom: 0in;&quot; align=&quot;left&quot;&gt;&lt;br /&gt;&lt;/p&gt; &lt;p style=&quot;margin-bottom: 0in;&quot; align=&quot;left&quot;&gt;&lt;span style=&quot;color: rgb(0, 0, 0);&quot;&gt;&lt;span style=&quot;font-family:Courier New,monospace;&quot;&gt;&lt;span style=&quot;font-size:85%;&quot;&gt;&lt;span style=&quot;color: rgb(35, 0, 251);&quot;&gt;unvisited&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 62, 133);&quot;&gt;++&lt;/span&gt; (&lt;span style=&quot;color: rgb(35, 0, 251);&quot;&gt;vertx&lt;/span&gt;.&lt;span style=&quot;color: rgb(35, 0, 251);&quot;&gt;nodeEdges&lt;/span&gt;.&lt;span style=&quot;color: rgb(0, 62, 133);&quot;&gt;filter&lt;/span&gt;(&lt;span style=&quot;color: rgb(0, 62, 133);&quot;&gt;canImprove&lt;/span&gt;(_))).&lt;span style=&quot;color: rgb(0, 62, 133);&quot;&gt;map&lt;/span&gt;(&lt;span style=&quot;color: rgb(0, 62, 133);&quot;&gt;improveDistance&lt;/span&gt;(_))&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt; &lt;p style=&quot;margin-bottom: 0in;&quot; align=&quot;left&quot;&gt;&lt;br /&gt;&lt;/p&gt; &lt;p style=&quot;margin-bottom: 0in;&quot;&gt;But I don&#39;t really think the explicit use of map and filter helps readability.&lt;/p&gt; &lt;p style=&quot;margin-bottom: 0in;&quot;&gt;Enter Scala&#39;s for comprehensions: we can replace the map/filter with a comprehension:&lt;/p&gt; &lt;p style=&quot;margin-bottom: 0in;&quot;&gt;&lt;br /&gt;&lt;/p&gt; &lt;p style=&quot;margin-bottom: 0in;&quot; align=&quot;left&quot;&gt;&lt;span style=&quot;color: rgb(0, 0, 0);&quot;&gt;&lt;span style=&quot;font-family:Courier New,monospace;&quot;&gt;&lt;span style=&quot;font-size:85%;&quot;&gt;&lt;span style=&quot;color: rgb(76, 76, 76);&quot;&gt; for&lt;/span&gt; (&lt;span style=&quot;color: rgb(35, 0, 251);&quot;&gt;v&lt;/span&gt; &lt;- &lt;span style=&quot;color: rgb(35, 0, 251);&quot;&gt;vertx&lt;/span&gt;.&lt;span style=&quot;color: rgb(35, 0, 251);&quot;&gt;nodeEdges&lt;/span&gt; &lt;span style=&quot;color: rgb(76, 76, 76);&quot;&gt;if&lt;/span&gt; &lt;span style=&quot;color: rgb(0, 62, 133);&quot;&gt;canImprove&lt;/span&gt;(&lt;span style=&quot;color: rgb(35, 0, 251);&quot;&gt;v&lt;/span&gt;)){&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt; &lt;p style=&quot;margin-bottom: 0in;&quot; align=&quot;left&quot;&gt;&lt;span style=&quot;color: rgb(0, 0, 0);&quot;&gt;          &lt;/span&gt;&lt;span style=&quot;font-family:Courier New,monospace;&quot;&gt;&lt;span style=&quot;font-size:85%;&quot;&gt;&lt;span style=&quot;color: rgb(35, 0, 251);&quot;&gt;unvisited&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 62, 133);&quot;&gt;+improveDistance&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 0);&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: rgb(35, 0, 251);&quot;&gt;v&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 0);&quot;&gt;)&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt; &lt;p style=&quot;margin-bottom: 0in;&quot; align=&quot;left&quot;&gt;&lt;span style=&quot;color: rgb(0, 0, 0);&quot;&gt;      &lt;span style=&quot;font-family:Courier New,monospace;&quot;&gt;&lt;span style=&quot;font-size:85%;&quot;&gt;}&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt; &lt;p style=&quot;margin-bottom: 0in;&quot; align=&quot;left&quot;&gt;&lt;span style=&quot;color: rgb(0, 0, 0);&quot;&gt; &lt;/span&gt; &lt;/p&gt; &lt;p style=&quot;margin-bottom: 0in;&quot;&gt;Nothing fantastic, but an improvement, isn&#39;t it?&lt;/p&gt; &lt;p style=&quot;margin-bottom: 0in;&quot;&gt;For future posts, I&#39;m planning on generalizing the algorithm into a A* pathfinding with different heuristic functions... stay tuned!&lt;/p&gt;</description><link>http://gabrielsw.blogspot.com/2008/12/playing-with-scala-5-improving-code-use.html</link><author>noreply@blogger.com (Anonymous)</author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEju9d62hGeSMD9xOwa3vN9prz9BhL-HtuYFJvrcVrhmMkyfDpgFwsigG-igjhXzTAPFhi1BxBmXShn6bHp1qsiKPVrlSYFoieAVNwHqfiBSC2bWC9lqWBtUF4ODbPo0v50O3aM_tHooi2c/s72-c/IMG_0329.JPG" height="72" width="72"/><thr:total>3</thr:total></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-6893032696317132921.post-7352821789510968348</guid><pubDate>Thu, 23 Oct 2008 01:46:00 +0000</pubDate><atom:updated>2008-10-22T22:10:40.338-04:00</atom:updated><category domain="http://www.blogger.com/atom/ns#">Java</category><category domain="http://www.blogger.com/atom/ns#">programming</category><category domain="http://www.blogger.com/atom/ns#">risk</category><category domain="http://www.blogger.com/atom/ns#">security</category><title>Simple Java tricks to protect your web application against SQL injection</title><description>Your application is vulnerable to &lt;a href=&quot;http://en.wikipedia.org/wiki/SQL_injection&quot;&gt;SQL Injection&lt;/a&gt; when you send unfiltered strings to the database. Most modern ORM frameworks should take care of it (but don&#39;t take my word!... go ahead and check how secure your framework is).&lt;br /&gt;Sometimes,  you have to work with plain JDBC (or ODBC). Here is a couple of tricks that help:&lt;br /&gt;&lt;ol&gt;&lt;li&gt;First and foremost, avoid concatenating strings for SQL queries. Use prepared statements unless is not possible (i.e. cases when you have undefined number of parameters)&lt;/li&gt;&lt;li&gt;Leverage the language type system: If you&#39;re passing a number, use Integer instead of String... any invalid character will fail the conversion and will not reach the DB.&lt;/li&gt;&lt;li&gt;If there&#39;s no option but concatenate strings, make sure the database comment quotes are escaped (for example, in DB2 you have to replace the single quote character with 2 single quote characters:  instead of &lt;span style=&quot;font-family: courier new;&quot;&gt;&quot;SELECT * FROM users WHERE name=&#39;&quot;+param+&quot;&#39;&quot; &lt;span style=&quot;font-family: arial;&quot;&gt;use &lt;/span&gt;&quot;SELECT * FROM users WHERE name=&#39;&quot;+param.replaceAll(&quot;&#39;&quot;,&quot;&#39;&#39;&quot;)+&quot;&#39;&quot;&lt;/span&gt;&lt;/li&gt;&lt;/ol&gt;For something a little more advanced, you can wrap the strings in some kind of &quot;EscapedString&quot; class, and use that class in the signature of the DAOs (related to 2. )&lt;br /&gt;&lt;br /&gt;Note: by no means this is a comprehensive list. Application security is very hard, check your database documentation...</description><link>http://gabrielsw.blogspot.com/2008/10/simple-java-tricks-to-protect-your-web.html</link><author>noreply@blogger.com (Anonymous)</author><thr:total>9</thr:total></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-6893032696317132921.post-8054537599498881967</guid><pubDate>Thu, 25 Sep 2008 03:49:00 +0000</pubDate><atom:updated>2008-09-25T08:36:57.199-04:00</atom:updated><category domain="http://www.blogger.com/atom/ns#">functional programming</category><category domain="http://www.blogger.com/atom/ns#">humor</category><category domain="http://www.blogger.com/atom/ns#">ICFP</category><category domain="http://www.blogger.com/atom/ns#">Java</category><title>Java: The programming tool of choice for discriminating hackers</title><description>In spite of all the Java bashing that&#39;s so in vogue this days, Team Smartass won the &lt;a href=&quot;http://www.icfpcontest.org/&quot;&gt;ICFP Programming Contest&lt;/a&gt; using Java, giving bragging rights to say that Java is &quot;The programming tool of choice for discriminating hackers&quot;.&lt;br /&gt;while(tongue in cheek){&lt;br /&gt;   take(this);&lt;br /&gt;   (lisp (snobs all))&lt;br /&gt;   fuctional_programing = Maybe[zealots]&lt;br /&gt;   ruby(&#39;fanboys&#39;)&lt;br /&gt;}&lt;br /&gt;Another proof of what matters is not the tool, is how you use it...</description><link>http://gabrielsw.blogspot.com/2008/09/java-programming-tool-of-choice-for.html</link><author>noreply@blogger.com (Anonymous)</author><thr:total>1</thr:total></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-6893032696317132921.post-824877044245591867</guid><pubDate>Tue, 26 Aug 2008 00:02:00 +0000</pubDate><atom:updated>2008-08-26T12:13:39.791-04:00</atom:updated><category domain="http://www.blogger.com/atom/ns#">DDD</category><category domain="http://www.blogger.com/atom/ns#">DSL</category><category domain="http://www.blogger.com/atom/ns#">FluentInterfaces</category><category domain="http://www.blogger.com/atom/ns#">OOAD</category><category domain="http://www.blogger.com/atom/ns#">software engineering</category><title>State machines using &quot;Fluent interfaces/ DSL&quot; in Java</title><description>I always found state machines very useful for describing particular aspects of object behavior. A classic example can be a shopping order: it can be &quot;pending&quot;,&quot;in progress&quot;, &quot;shipped&quot;, etc.&lt;br /&gt;In my previous project, I started with a simple design using a transition matrix. I must confess it didn&#39;t work well. It was hard to explain and it grew more complex as new requirements were added. I though it would be simpler if I didn&#39;t use any  &quot;fancy OO stuff&quot; and advanced idioms. I&#39;ve should  know better!&lt;br /&gt;This time I wanted to try something different, and based in my previous experiments with internal DSLs with Scala and my (very limited)  knowledge of the patters to achieve that in java, I just went ahead and tried to come up with something useful and understandable. This time  seems to be  working: although it has some &quot;magic&quot; behind curtains is only in the creation and is very easy to add or modify the configuration class for new or updated states and events. Other members of my project were able to add and remove states and transitions with only a brief explanation.&lt;br /&gt;&lt;br /&gt;The basic classes are pretty simple: State and Event.&lt;br /&gt;&lt;p style=&quot;margin-bottom: 0in;&quot; align=&quot;left&quot;&gt;&lt;span style=&quot;font-family:Courier New,monospace;&quot;&gt;&lt;span style=&quot;font-size:85%;&quot;&gt;&lt;span style=&quot;color: rgb(127, 0, 85);&quot;&gt;&lt;b&gt;package&lt;/b&gt;&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 0);&quot;&gt; statemachine;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt; &lt;p style=&quot;margin-bottom: 0in;&quot; align=&quot;left&quot;&gt;&lt;br /&gt;&lt;/p&gt; &lt;p style=&quot;margin-bottom: 0in;&quot; align=&quot;left&quot;&gt;&lt;span style=&quot;font-family:Courier New,monospace;&quot;&gt;&lt;span style=&quot;font-size:85%;&quot;&gt;&lt;span style=&quot;color: rgb(127, 0, 85);&quot;&gt;&lt;b&gt;public&lt;/b&gt;&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 0);&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: rgb(127, 0, 85);&quot;&gt;&lt;b&gt;class&lt;/b&gt;&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 0);&quot;&gt; Event {&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt; &lt;p style=&quot;margin-bottom: 0in;&quot; align=&quot;left&quot;&gt;&lt;span style=&quot;color: rgb(0, 0, 0);&quot;&gt;    &lt;/span&gt;&lt;span style=&quot;font-family:Courier New,monospace;&quot;&gt;&lt;span style=&quot;font-size:85%;&quot;&gt;&lt;span style=&quot;color: rgb(127, 0, 85);&quot;&gt;&lt;b&gt;    final&lt;/b&gt;&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 0);&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: rgb(127, 0, 85);&quot;&gt;&lt;b&gt;private&lt;/b&gt;&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 0);&quot;&gt; String &lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 192);&quot;&gt;label&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 0);&quot;&gt;;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt; &lt;p style=&quot;margin-bottom: 0in;&quot; align=&quot;left&quot;&gt;&lt;span style=&quot;color: rgb(0, 0, 0);&quot;&gt;   &lt;/span&gt; &lt;/p&gt; &lt;p style=&quot;margin-bottom: 0in;&quot; align=&quot;left&quot;&gt;&lt;span style=&quot;color: rgb(0, 0, 0);&quot;&gt;    &lt;/span&gt;&lt;span style=&quot;font-family:Courier New,monospace;&quot;&gt;&lt;span style=&quot;font-size:85%;&quot;&gt;&lt;span style=&quot;color: rgb(127, 0, 85);&quot;&gt;&lt;b&gt;    public&lt;/b&gt;&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 0);&quot;&gt; Event(String newLabel){&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt; &lt;p style=&quot;margin-bottom: 0in;&quot; align=&quot;left&quot;&gt;&lt;span style=&quot;color: rgb(0, 0, 0);&quot;&gt;        &lt;/span&gt;&lt;span style=&quot;font-family:Courier New,monospace;&quot;&gt;&lt;span style=&quot;font-size:85%;&quot;&gt;&lt;span style=&quot;color: rgb(0, 0, 192);&quot;&gt;        label&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 0);&quot;&gt;=newLabel;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt; &lt;p style=&quot;margin-bottom: 0in;&quot; align=&quot;left&quot;&gt;&lt;span style=&quot;color: rgb(0, 0, 0);&quot;&gt;    &lt;span style=&quot;font-family:Courier New,monospace;&quot;&gt;&lt;span style=&quot;font-size:85%;&quot;&gt;    }&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt; &lt;p style=&quot;margin-bottom: 0in;&quot; align=&quot;left&quot;&gt;&lt;span style=&quot;color: rgb(0, 0, 0);&quot;&gt;   &lt;/span&gt; &lt;/p&gt; &lt;p style=&quot;margin-bottom: 0in;&quot; align=&quot;left&quot;&gt;&lt;span style=&quot;color: rgb(0, 0, 0);&quot;&gt;    &lt;/span&gt;&lt;span style=&quot;font-family:Courier New,monospace;&quot;&gt;&lt;span style=&quot;font-size:85%;&quot;&gt;&lt;span style=&quot;color: rgb(63, 95, 191);&quot;&gt;    /**&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt; &lt;p style=&quot;margin-bottom: 0in;&quot; align=&quot;left&quot;&gt;&lt;span style=&quot;color: rgb(0, 0, 0);&quot;&gt;     &lt;/span&gt;&lt;span style=&quot;font-family:Courier New,monospace;&quot;&gt;&lt;span style=&quot;font-size:85%;&quot;&gt;&lt;span style=&quot;color: rgb(63, 95, 191);&quot;&gt;    *&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 0);&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: rgb(127, 159, 191);&quot;&gt;&lt;b&gt;@return&lt;/b&gt;&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 0);&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: rgb(63, 95, 191);&quot;&gt;Returns&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 0);&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: rgb(63, 95, 191);&quot;&gt;the&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 0);&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: rgb(63, 95, 191);&quot;&gt;label.&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt; &lt;p style=&quot;margin-bottom: 0in;&quot; align=&quot;left&quot;&gt;&lt;span style=&quot;color: rgb(0, 0, 0);&quot;&gt;     &lt;/span&gt;&lt;span style=&quot;font-family:Courier New,monospace;&quot;&gt;&lt;span style=&quot;font-size:85%;&quot;&gt;&lt;span style=&quot;color: rgb(63, 95, 191);&quot;&gt;    */&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt; &lt;p style=&quot;margin-bottom: 0in;&quot; align=&quot;left&quot;&gt;&lt;span style=&quot;color: rgb(0, 0, 0);&quot;&gt;    &lt;/span&gt;&lt;span style=&quot;font-family:Courier New,monospace;&quot;&gt;&lt;span style=&quot;font-size:85%;&quot;&gt;&lt;span style=&quot;color: rgb(127, 0, 85);&quot;&gt;&lt;b&gt;    public&lt;/b&gt;&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 0);&quot;&gt; String getLabel() {&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt; &lt;p style=&quot;margin-bottom: 0in;&quot; align=&quot;left&quot;&gt;    &lt;span style=&quot;font-family:Courier New,monospace;&quot;&gt;&lt;span style=&quot;font-size:85%;&quot;&gt;&lt;span style=&quot;color: rgb(127, 0, 85);&quot;&gt;&lt;b&gt;    return&lt;/b&gt;&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 0);&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 192);&quot;&gt;label&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 0);&quot;&gt;;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt; &lt;p style=&quot;margin-bottom: 0in;&quot; align=&quot;left&quot;&gt;&lt;span style=&quot;color: rgb(0, 0, 0);&quot;&gt;    &lt;span style=&quot;font-family:Courier New,monospace;&quot;&gt;&lt;span style=&quot;font-size:85%;&quot;&gt;    }&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt; &lt;p style=&quot;margin-bottom: 0in;&quot; align=&quot;left&quot;&gt;&lt;span style=&quot;color: rgb(0, 0, 0);&quot;&gt;   &lt;/span&gt; &lt;/p&gt; &lt;p style=&quot;margin-bottom: 0in;&quot; align=&quot;left&quot;&gt;&lt;span style=&quot;color: rgb(0, 0, 0);&quot;&gt;    &lt;/span&gt;&lt;span style=&quot;font-family:Courier New,monospace;&quot;&gt;&lt;span style=&quot;font-size:85%;&quot;&gt;&lt;span style=&quot;color: rgb(127, 0, 85);&quot;&gt;&lt;b&gt;    public&lt;/b&gt;&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 0);&quot;&gt; String toString(){&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt; &lt;p style=&quot;margin-bottom: 0in;&quot; align=&quot;left&quot;&gt;&lt;span style=&quot;color: rgb(0, 0, 0);&quot;&gt;        &lt;/span&gt;&lt;span style=&quot;font-family:Courier New,monospace;&quot;&gt;&lt;span style=&quot;font-size:85%;&quot;&gt;&lt;span style=&quot;color: rgb(127, 0, 85);&quot;&gt;&lt;b&gt;        return&lt;/b&gt;&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 0);&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 192);&quot;&gt;label&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 0);&quot;&gt;;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt; &lt;p style=&quot;margin-bottom: 0in;&quot; align=&quot;left&quot;&gt;&lt;span style=&quot;color: rgb(0, 0, 0);&quot;&gt;    &lt;span style=&quot;font-family:Courier New,monospace;&quot;&gt;&lt;span style=&quot;font-size:85%;&quot;&gt;    }&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt; &lt;p style=&quot;margin-bottom: 0in;&quot; align=&quot;left&quot;&gt;&lt;span style=&quot;color: rgb(0, 0, 0);&quot;&gt;&lt;span style=&quot;font-family:Courier New,monospace;&quot;&gt;&lt;span style=&quot;font-size:85%;&quot;&gt;}&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;br /&gt;&lt;p style=&quot;margin-bottom: 0in;&quot; align=&quot;left&quot;&gt;&lt;span style=&quot;font-family:Courier New,monospace;&quot;&gt;&lt;span style=&quot;font-size:85%;&quot;&gt;&lt;span style=&quot;color: rgb(127, 0, 85);&quot;&gt;&lt;b&gt;package&lt;/b&gt;&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 0);&quot;&gt; statemachine;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt; &lt;p style=&quot;margin-bottom: 0in;&quot; align=&quot;left&quot;&gt;&lt;span style=&quot;font-family:Courier New,monospace;&quot;&gt;&lt;span style=&quot;font-size:85%;&quot;&gt;&lt;span style=&quot;color: rgb(127, 0, 85);&quot;&gt;&lt;b&gt;import&lt;/b&gt;&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 0);&quot;&gt; java.util.HashMap;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt; &lt;p style=&quot;margin-bottom: 0in;&quot; align=&quot;left&quot;&gt;&lt;span style=&quot;font-family:Courier New,monospace;&quot;&gt;&lt;span style=&quot;font-size:85%;&quot;&gt;&lt;span style=&quot;color: rgb(127, 0, 85);&quot;&gt;&lt;b&gt;import&lt;/b&gt;&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 0);&quot;&gt; java.util.Map;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt; &lt;p style=&quot;margin-bottom: 0in;&quot; align=&quot;left&quot;&gt;&lt;br /&gt;&lt;/p&gt; &lt;p style=&quot;margin-bottom: 0in;&quot; align=&quot;left&quot;&gt;&lt;span style=&quot;font-family:Courier New,monospace;&quot;&gt;&lt;span style=&quot;font-size:85%;&quot;&gt;&lt;span style=&quot;color: rgb(127, 0, 85);&quot;&gt;&lt;b&gt;public&lt;/b&gt;&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 0);&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: rgb(127, 0, 85);&quot;&gt;&lt;b&gt;class&lt;/b&gt;&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 0);&quot;&gt; State {&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt; &lt;p style=&quot;margin-bottom: 0in;&quot; align=&quot;left&quot;&gt;&lt;span style=&quot;color: rgb(0, 0, 0);&quot;&gt;   &lt;/span&gt; &lt;/p&gt; &lt;p style=&quot;margin-bottom: 0in;&quot; align=&quot;left&quot;&gt;&lt;span style=&quot;color: rgb(0, 0, 0);&quot;&gt;    &lt;/span&gt;&lt;span style=&quot;font-family:Courier New,monospace;&quot;&gt;&lt;span style=&quot;font-size:85%;&quot;&gt;&lt;span style=&quot;color: rgb(127, 0, 85);&quot;&gt;&lt;b&gt;    private&lt;/b&gt;&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 0);&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: rgb(127, 0, 85);&quot;&gt;&lt;b&gt;final&lt;/b&gt;&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 0);&quot;&gt; String &lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 192);&quot;&gt;label&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 0);&quot;&gt;;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt; &lt;p style=&quot;margin-bottom: 0in;&quot; align=&quot;left&quot;&gt;    &lt;span style=&quot;font-family:Courier New,monospace;&quot;&gt;&lt;span style=&quot;font-size:85%;&quot;&gt;&lt;span style=&quot;color: rgb(127, 0, 85);&quot;&gt;&lt;b&gt;  private&lt;/b&gt;&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 0);&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: rgb(127, 0, 85);&quot;&gt;&lt;b&gt;final&lt;/b&gt;&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 0);&quot;&gt; Map&amp;lt;Event,Transition&gt;&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 192);&quot;&gt; transitions&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 0);&quot;&gt;= &lt;/span&gt;&lt;span style=&quot;color: rgb(127, 0, 85);&quot;&gt;&lt;b&gt;new&lt;/b&gt;&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 0);&quot;&gt; HashMap&amp;lt;Event,Transition&gt;();&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt; &lt;p style=&quot;margin-bottom: 0in;&quot; align=&quot;left&quot;&gt;&lt;span style=&quot;color: rgb(0, 0, 0);&quot;&gt;   &lt;/span&gt; &lt;/p&gt; &lt;p style=&quot;margin-bottom: 0in;&quot; align=&quot;left&quot;&gt;    &lt;span style=&quot;font-family:Courier New,monospace;&quot;&gt;&lt;span style=&quot;font-size:85%;&quot;&gt;&lt;span style=&quot;color: rgb(63, 127, 95);&quot;&gt;  //no public access to the constructor, must be in the same package&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt; &lt;p style=&quot;margin-bottom: 0in;&quot; align=&quot;left&quot;&gt;&lt;span style=&quot;color: rgb(0, 0, 0);&quot;&gt;    &lt;span style=&quot;font-family:Courier New,monospace;&quot;&gt;&lt;span style=&quot;font-size:85%;&quot;&gt;    State(String newLabel){&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt; &lt;p style=&quot;margin-bottom: 0in;&quot; align=&quot;left&quot;&gt;        &lt;span style=&quot;font-family:Courier New,monospace;&quot;&gt;&lt;span style=&quot;font-size:85%;&quot;&gt;&lt;span style=&quot;color: rgb(127, 0, 85);&quot;&gt;&lt;b&gt;    this&lt;/b&gt;&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 0);&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 192);&quot;&gt;label&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 0);&quot;&gt;=newLabel;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt; &lt;p style=&quot;margin-bottom: 0in;&quot; align=&quot;left&quot;&gt;&lt;span style=&quot;font-family:Courier New,monospace;&quot;&gt;    &lt;span style=&quot;font-size:85%;&quot;&gt;&lt;span style=&quot;color: rgb(127, 0, 85);&quot;&gt;    }&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;margin-bottom: 0in;&quot; align=&quot;left&quot;&gt;&lt;span style=&quot;font-family:Courier New,monospace;&quot;&gt;&lt;span style=&quot;font-size:85%;&quot;&gt;&lt;span style=&quot;color: rgb(127, 0, 85);&quot;&gt;&lt;b&gt;    void&lt;/b&gt;&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 0);&quot;&gt; addTransition(Transition t){&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt; &lt;p style=&quot;margin-bottom: 0in;&quot; align=&quot;left&quot;&gt;        &lt;span style=&quot;font-family:Courier New,monospace;&quot;&gt;&lt;span style=&quot;font-size:85%;&quot;&gt;&lt;span style=&quot;color: rgb(0, 0, 192);&quot;&gt;    transitions&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 0);&quot;&gt;.put(t.getEvent(),t);&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt; &lt;p style=&quot;margin-bottom: 0in;&quot; align=&quot;left&quot;&gt;&lt;span style=&quot;color: rgb(0, 0, 0);&quot;&gt;    &lt;span style=&quot;font-family:Courier New,monospace;&quot;&gt;&lt;span style=&quot;font-size:85%;&quot;&gt;    }&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p style=&quot;margin-bottom: 0in;&quot; align=&quot;left&quot;&gt;&lt;span style=&quot;color: rgb(0, 0, 0);&quot;&gt;    &lt;/span&gt;&lt;span style=&quot;font-family:Courier New,monospace;&quot;&gt;&lt;span style=&quot;font-size:85%;&quot;&gt;&lt;span style=&quot;color: rgb(127, 0, 85);&quot;&gt;&lt;b&gt;    public&lt;/b&gt;&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 0);&quot;&gt; State doEvent(Event e){&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt; &lt;p style=&quot;margin-bottom: 0in;&quot; align=&quot;left&quot;&gt;&lt;span style=&quot;color: rgb(0, 0, 0);&quot;&gt;        &lt;/span&gt;&lt;span style=&quot;font-family:Courier New,monospace;&quot;&gt;&lt;span style=&quot;font-size:85%;&quot;&gt;&lt;span style=&quot;color: rgb(127, 0, 85);&quot;&gt;&lt;b&gt;        return&lt;/b&gt;&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 0);&quot;&gt; (&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 192);&quot;&gt;transitions&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 0);&quot;&gt;.get(e)).getDestination();&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt; &lt;p style=&quot;margin-bottom: 0in;&quot; align=&quot;left&quot;&gt;&lt;span style=&quot;color: rgb(0, 0, 0);&quot;&gt;    &lt;span style=&quot;font-family:Courier New,monospace;&quot;&gt;&lt;span style=&quot;font-size:85%;&quot;&gt;    }&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt; &lt;p style=&quot;margin-bottom: 0in;&quot; align=&quot;left&quot;&gt;&lt;span style=&quot;color: rgb(0, 0, 0);&quot;&gt;   &lt;/span&gt; &lt;/p&gt; &lt;p style=&quot;margin-bottom: 0in;&quot; align=&quot;left&quot;&gt;&lt;span style=&quot;color: rgb(0, 0, 0);&quot;&gt;    &lt;/span&gt;&lt;span style=&quot;font-family:Courier New,monospace;&quot;&gt;&lt;span style=&quot;font-size:85%;&quot;&gt;&lt;span style=&quot;color: rgb(63, 95, 191);&quot;&gt;    /**&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt; &lt;p style=&quot;margin-bottom: 0in;&quot; align=&quot;left&quot;&gt;&lt;span style=&quot;color: rgb(0, 0, 0);&quot;&gt;     &lt;/span&gt;&lt;span style=&quot;font-family:Courier New,monospace;&quot;&gt;&lt;span style=&quot;font-size:85%;&quot;&gt;&lt;span style=&quot;color: rgb(63, 95, 191);&quot;&gt;    *&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 0);&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: rgb(127, 159, 191);&quot;&gt;&lt;b&gt;@return&lt;/b&gt;&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 0);&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: rgb(63, 95, 191);&quot;&gt;Returns&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 0);&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: rgb(63, 95, 191);&quot;&gt;the&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 0);&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: rgb(63, 95, 191);&quot;&gt;label.&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt; &lt;p style=&quot;margin-bottom: 0in;&quot; align=&quot;left&quot;&gt;        &lt;span style=&quot;font-family:Courier New,monospace;&quot;&gt;&lt;span style=&quot;font-size:85%;&quot;&gt;&lt;span style=&quot;color: rgb(63, 95, 191);&quot;&gt;*/&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt; &lt;p style=&quot;margin-bottom: 0in;&quot; align=&quot;left&quot;&gt;&lt;span style=&quot;color: rgb(0, 0, 0);&quot;&gt;    &lt;/span&gt;&lt;span style=&quot;font-family:Courier New,monospace;&quot;&gt;&lt;span style=&quot;font-size:85%;&quot;&gt;&lt;span style=&quot;color: rgb(127, 0, 85);&quot;&gt;&lt;b&gt;    public&lt;/b&gt;&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 0);&quot;&gt; String getLabel() {&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt; &lt;p style=&quot;margin-bottom: 0in;&quot; align=&quot;left&quot;&gt;            &lt;span style=&quot;font-family:Courier New,monospace;&quot;&gt;&lt;span style=&quot;font-size:85%;&quot;&gt;&lt;span style=&quot;color: rgb(127, 0, 85);&quot;&gt;&lt;b&gt;return&lt;/b&gt;&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 0);&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 192);&quot;&gt;label&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 0);&quot;&gt;;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt; &lt;p style=&quot;margin-bottom: 0in;&quot; align=&quot;left&quot;&gt;&lt;span style=&quot;color: rgb(0, 0, 0);&quot;&gt;    &lt;span style=&quot;font-family:Courier New,monospace;&quot;&gt;&lt;span style=&quot;font-size:85%;&quot;&gt;    }&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p style=&quot;margin-bottom: 0in;&quot; align=&quot;left&quot;&gt;        &lt;span style=&quot;font-family:Courier New,monospace;&quot;&gt;&lt;span style=&quot;font-size:85%;&quot;&gt;&lt;span style=&quot;color: rgb(63, 95, 191);&quot;&gt;/**&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt; &lt;p style=&quot;margin-bottom: 0in;&quot; align=&quot;left&quot;&gt;    &lt;span style=&quot;font-family:Courier New,monospace;&quot;&gt;&lt;span style=&quot;font-size:85%;&quot;&gt;&lt;span style=&quot;color: rgb(63, 95, 191);&quot;&gt;  *&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 0);&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: rgb(127, 159, 191);&quot;&gt;&lt;b&gt;@return&lt;/b&gt;&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 0);&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: rgb(63, 95, 191);&quot;&gt;Returns&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 0);&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: rgb(63, 95, 191);&quot;&gt;the&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 0);&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: rgb(63, 95, 191);&quot;&gt;transitions.&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt; &lt;p style=&quot;margin-bottom: 0in;&quot; align=&quot;left&quot;&gt;    &lt;span style=&quot;font-family:Courier New,monospace;&quot;&gt;&lt;span style=&quot;font-size:85%;&quot;&gt;&lt;span style=&quot;color: rgb(63, 95, 191);&quot;&gt;  */&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt; &lt;p style=&quot;margin-bottom: 0in;&quot; align=&quot;left&quot;&gt;&lt;span style=&quot;color: rgb(0, 0, 0);&quot;&gt;    &lt;/span&gt;&lt;span style=&quot;font-family:Courier New,monospace;&quot;&gt;&lt;span style=&quot;font-size:85%;&quot;&gt;&lt;span style=&quot;color: rgb(127, 0, 85);&quot;&gt;&lt;b&gt;    public&lt;/b&gt;&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 0);&quot;&gt; Map&amp;lt;Event,Transition&gt; getTransitions() {&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt; &lt;p style=&quot;margin-bottom: 0in;&quot; align=&quot;left&quot;&gt;            &lt;span style=&quot;font-family:Courier New,monospace;&quot;&gt;&lt;span style=&quot;font-size:85%;&quot;&gt;&lt;span style=&quot;color: rgb(127, 0, 85);&quot;&gt;&lt;b&gt;return&lt;/b&gt;&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 0);&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 192);&quot;&gt;transitions&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 0);&quot;&gt;;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt; &lt;p style=&quot;margin-bottom: 0in;&quot; align=&quot;left&quot;&gt;&lt;span style=&quot;color: rgb(0, 0, 0);&quot;&gt;    &lt;span style=&quot;font-family:Courier New,monospace;&quot;&gt;&lt;span style=&quot;font-size:85%;&quot;&gt;    }&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt; &lt;p style=&quot;margin-bottom: 0in;&quot; align=&quot;left&quot;&gt;&lt;span style=&quot;color: rgb(0, 0, 0);&quot;&gt;&lt;span style=&quot;font-family:Courier New,monospace;&quot;&gt;&lt;span style=&quot;font-size:85%;&quot;&gt;}&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;br /&gt;You send a event to a sate and it returns the next state:&lt;br /&gt;State newState=state.doEvent(event);&lt;br /&gt;The State class holds a map of  [event-&gt;state]  (with the Transition class in the middle, for added effect :) )&lt;br /&gt;As an extra safety measure, the State constructor and the addTransition method is accessible only to the package (well, unless you subclass it)&lt;br /&gt;The &quot;fluency&quot; is provided by the Transition class (the useful methods return &lt;span style=&quot;font-weight: bold; font-style: italic;&quot;&gt;this&lt;/span&gt;&lt;span style=&quot;font-style: italic;&quot;&gt; &lt;/span&gt;to allow method chaining), so you can write:&lt;br /&gt;new Transition(event).from(origin).to(destination)&lt;br /&gt;&lt;br /&gt;&lt;p style=&quot;margin-bottom: 0in;&quot; align=&quot;left&quot;&gt;&lt;span style=&quot;font-family:Courier New,monospace;&quot;&gt;&lt;span style=&quot;font-size:85%;&quot;&gt;&lt;span style=&quot;color: rgb(127, 0, 85);&quot;&gt;&lt;b&gt;package&lt;/b&gt;&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 0);&quot;&gt; statemachine;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt; &lt;p style=&quot;margin-bottom: 0in;&quot; align=&quot;left&quot;&gt;&lt;/p&gt;&lt;p style=&quot;margin-bottom: 0in;&quot; align=&quot;left&quot;&gt;&lt;span style=&quot;font-family:Courier New,monospace;&quot;&gt;&lt;span style=&quot;font-size:85%;&quot;&gt;&lt;span style=&quot;color: rgb(127, 0, 85);&quot;&gt;&lt;b&gt;class&lt;/b&gt;&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 0);&quot;&gt; Transition {&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt; &lt;p style=&quot;margin-bottom: 0in;&quot; align=&quot;left&quot;&gt;&lt;span style=&quot;color: rgb(0, 0, 0);&quot;&gt;   &lt;/span&gt; &lt;/p&gt; &lt;p style=&quot;margin-bottom: 0in;&quot; align=&quot;left&quot;&gt;    &lt;span style=&quot;font-family:Courier New,monospace;&quot;&gt;&lt;span style=&quot;font-size:85%;&quot;&gt;&lt;span style=&quot;color: rgb(127, 0, 85);&quot;&gt;&lt;b&gt;private&lt;/b&gt;&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 0);&quot;&gt; State &lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 192);&quot;&gt;origin&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 0);&quot;&gt;,&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 192);&quot;&gt;destination&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 0);&quot;&gt;;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt; &lt;p style=&quot;margin-bottom: 0in;&quot; align=&quot;left&quot;&gt;    &lt;span style=&quot;font-family:Courier New,monospace;&quot;&gt;&lt;span style=&quot;font-size:85%;&quot;&gt;&lt;span style=&quot;color: rgb(127, 0, 85);&quot;&gt;&lt;b&gt;private&lt;/b&gt;&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 0);&quot;&gt; Event &lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 192);&quot;&gt;event&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 0);&quot;&gt;;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt; &lt;p style=&quot;margin-bottom: 0in;&quot; align=&quot;left&quot;&gt;&lt;span style=&quot;color: rgb(0, 0, 0);&quot;&gt;  &lt;/span&gt; &lt;/p&gt; &lt;p style=&quot;margin-bottom: 0in;&quot; align=&quot;left&quot;&gt;    &lt;span style=&quot;font-family:Courier New,monospace;&quot;&gt;&lt;span style=&quot;font-size:85%;&quot;&gt;&lt;span style=&quot;color: rgb(127, 0, 85);&quot;&gt;&lt;b&gt;public&lt;/b&gt;&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 0);&quot;&gt; Transition(Event e){&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt; &lt;p style=&quot;margin-bottom: 0in;&quot; align=&quot;left&quot;&gt;        &lt;span style=&quot;font-family:Courier New,monospace;&quot;&gt;&lt;span style=&quot;font-size:85%;&quot;&gt;&lt;span style=&quot;color: rgb(0, 0, 192);&quot;&gt;event&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 0);&quot;&gt;=e;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt; &lt;p style=&quot;margin-bottom: 0in;&quot; align=&quot;left&quot;&gt;&lt;span style=&quot;color: rgb(0, 0, 0);&quot;&gt;    &lt;span style=&quot;font-family:Courier New,monospace;&quot;&gt;&lt;span style=&quot;font-size:85%;&quot;&gt;  }&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p style=&quot;margin-bottom: 0in;&quot; align=&quot;left&quot;&gt;&lt;span style=&quot;color: rgb(0, 0, 0);&quot;&gt;    &lt;/span&gt;&lt;span style=&quot;font-family:Courier New,monospace;&quot;&gt;&lt;span style=&quot;font-size:85%;&quot;&gt;&lt;span style=&quot;color: rgb(127, 0, 85);&quot;&gt;&lt;b&gt;  public&lt;/b&gt;&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 0);&quot;&gt; Transition from(State orig){&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt; &lt;p style=&quot;margin-bottom: 0in;&quot; align=&quot;left&quot;&gt;&lt;span style=&quot;color: rgb(0, 0, 0);&quot;&gt;        &lt;/span&gt;&lt;span style=&quot;font-family:Courier New,monospace;&quot;&gt;&lt;span style=&quot;font-size:85%;&quot;&gt;&lt;span style=&quot;color: rgb(0, 0, 192);&quot;&gt;    origin&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 0);&quot;&gt;=orig;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt; &lt;p style=&quot;margin-bottom: 0in;&quot; align=&quot;left&quot;&gt;        &lt;span style=&quot;font-family:Courier New,monospace;&quot;&gt;&lt;span style=&quot;font-size:85%;&quot;&gt;&lt;span style=&quot;color: rgb(0, 0, 192);&quot;&gt;origin&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 0);&quot;&gt;.addTransition(&lt;/span&gt;&lt;span style=&quot;color: rgb(127, 0, 85);&quot;&gt;&lt;b&gt;this&lt;/b&gt;&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 0);&quot;&gt;);&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt; &lt;p style=&quot;margin-bottom: 0in;&quot; align=&quot;left&quot;&gt;        &lt;span style=&quot;font-family:Courier New,monospace;&quot;&gt;&lt;span style=&quot;font-size:85%;&quot;&gt;&lt;span style=&quot;color: rgb(127, 0, 85);&quot;&gt;&lt;b&gt;return&lt;/b&gt;&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 0);&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: rgb(127, 0, 85);&quot;&gt;&lt;b&gt;this&lt;/b&gt;&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 0);&quot;&gt;;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt; &lt;p style=&quot;margin-bottom: 0in;&quot; align=&quot;left&quot;&gt;&lt;span style=&quot;color: rgb(0, 0, 0);&quot;&gt;    &lt;span style=&quot;font-family:Courier New,monospace;&quot;&gt;&lt;span style=&quot;font-size:85%;&quot;&gt;}&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt; &lt;p style=&quot;margin-bottom: 0in;&quot; align=&quot;left&quot;&gt;&lt;span style=&quot;color: rgb(0, 0, 0);&quot;&gt;   &lt;/span&gt; &lt;/p&gt; &lt;p style=&quot;margin-bottom: 0in;&quot; align=&quot;left&quot;&gt;    &lt;span style=&quot;font-family:Courier New,monospace;&quot;&gt;&lt;span style=&quot;font-size:85%;&quot;&gt;&lt;span style=&quot;color: rgb(127, 0, 85);&quot;&gt;&lt;b&gt;public&lt;/b&gt;&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 0);&quot;&gt; Transition to(State dest){&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt; &lt;p style=&quot;margin-bottom: 0in;&quot; align=&quot;left&quot;&gt;        &lt;span style=&quot;font-family:Courier New,monospace;&quot;&gt;&lt;span style=&quot;font-size:85%;&quot;&gt;&lt;span style=&quot;color: rgb(0, 0, 192);&quot;&gt;destination&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 0);&quot;&gt;=dest;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt; &lt;p style=&quot;margin-bottom: 0in;&quot; align=&quot;left&quot;&gt;&lt;span style=&quot;color: rgb(0, 0, 0);&quot;&gt;        &lt;/span&gt;&lt;span style=&quot;font-family:Courier New,monospace;&quot;&gt;&lt;span style=&quot;font-size:85%;&quot;&gt;&lt;span style=&quot;color: rgb(127, 0, 85);&quot;&gt;&lt;b&gt;    return&lt;/b&gt;&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 0);&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: rgb(127, 0, 85);&quot;&gt;&lt;b&gt;this&lt;/b&gt;&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 0);&quot;&gt;;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt; &lt;p style=&quot;margin-bottom: 0in;&quot; align=&quot;left&quot;&gt;&lt;span style=&quot;color: rgb(0, 0, 0);&quot;&gt;      &lt;span style=&quot;font-family:Courier New,monospace;&quot;&gt;&lt;span style=&quot;font-size:85%;&quot;&gt;}&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt; &lt;p style=&quot;margin-bottom: 0in;&quot; align=&quot;left&quot;&gt;&lt;span style=&quot;color: rgb(0, 0, 0);&quot;&gt;   &lt;/span&gt; &lt;/p&gt; &lt;p style=&quot;margin-bottom: 0in;&quot; align=&quot;left&quot;&gt;&lt;span style=&quot;color: rgb(0, 0, 0);&quot;&gt;     &lt;/span&gt;&lt;span style=&quot;font-family:Courier New,monospace;&quot;&gt;&lt;span style=&quot;font-size:85%;&quot;&gt;&lt;span style=&quot;color: rgb(63, 95, 191);&quot;&gt;/**&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt; &lt;p style=&quot;margin-bottom: 0in;&quot; align=&quot;left&quot;&gt;&lt;span style=&quot;color: rgb(0, 0, 0);&quot;&gt;      &lt;/span&gt;&lt;span style=&quot;font-family:Courier New,monospace;&quot;&gt;&lt;span style=&quot;font-size:85%;&quot;&gt;&lt;span style=&quot;color: rgb(63, 95, 191);&quot;&gt;*&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 0);&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: rgb(127, 159, 191);&quot;&gt;&lt;b&gt;@return&lt;/b&gt;&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 0);&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: rgb(63, 95, 191);&quot;&gt;Returns&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 0);&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: rgb(63, 95, 191);&quot;&gt;the&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 0);&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: rgb(63, 95, 191);&quot;&gt;destination.&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt; &lt;p style=&quot;margin-bottom: 0in;&quot; align=&quot;left&quot;&gt;&lt;span style=&quot;color: rgb(0, 0, 0);&quot;&gt;      &lt;/span&gt;&lt;span style=&quot;font-family:Courier New,monospace;&quot;&gt;&lt;span style=&quot;font-size:85%;&quot;&gt;&lt;span style=&quot;color: rgb(63, 95, 191);&quot;&gt;*/&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt; &lt;p style=&quot;margin-bottom: 0in;&quot; align=&quot;left&quot;&gt;&lt;span style=&quot;color: rgb(0, 0, 0);&quot;&gt;     &lt;/span&gt;&lt;span style=&quot;font-family:Courier New,monospace;&quot;&gt;&lt;span style=&quot;font-size:85%;&quot;&gt;&lt;span style=&quot;color: rgb(127, 0, 85);&quot;&gt;&lt;b&gt;public&lt;/b&gt;&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 0);&quot;&gt; State getDestination() {&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt; &lt;p style=&quot;margin-bottom: 0in;&quot; align=&quot;left&quot;&gt;&lt;span style=&quot;color: rgb(0, 0, 0);&quot;&gt;        &lt;/span&gt;&lt;span style=&quot;font-family:Courier New,monospace;&quot;&gt;&lt;span style=&quot;font-size:85%;&quot;&gt;&lt;span style=&quot;color: rgb(127, 0, 85);&quot;&gt;&lt;b&gt;    return&lt;/b&gt;&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 0);&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 192);&quot;&gt;destination&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 0);&quot;&gt;;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt; &lt;p style=&quot;margin-bottom: 0in;&quot; align=&quot;left&quot;&gt;&lt;span style=&quot;color: rgb(0, 0, 0);&quot;&gt;     &lt;span style=&quot;font-family:Courier New,monospace;&quot;&gt;&lt;span style=&quot;font-size:85%;&quot;&gt;}&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt; &lt;p style=&quot;margin-bottom: 0in;&quot; align=&quot;left&quot;&gt;&lt;span style=&quot;color: rgb(0, 0, 0);&quot;&gt;    &lt;/span&gt;&lt;span style=&quot;font-family:Courier New,monospace;&quot;&gt;&lt;span style=&quot;font-size:85%;&quot;&gt;&lt;span style=&quot;color: rgb(63, 95, 191);&quot;&gt;/**&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt; &lt;p style=&quot;margin-bottom: 0in;&quot; align=&quot;left&quot;&gt;&lt;span style=&quot;color: rgb(0, 0, 0);&quot;&gt;     &lt;/span&gt;&lt;span style=&quot;font-family:Courier New,monospace;&quot;&gt;&lt;span style=&quot;font-size:85%;&quot;&gt;&lt;span style=&quot;color: rgb(63, 95, 191);&quot;&gt;*&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 0);&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: rgb(127, 159, 191);&quot;&gt;&lt;b&gt;@return&lt;/b&gt;&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 0);&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: rgb(63, 95, 191);&quot;&gt;Returns&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 0);&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: rgb(63, 95, 191);&quot;&gt;the&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 0);&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: rgb(63, 95, 191);&quot;&gt;event.&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt; &lt;p style=&quot;margin-bottom: 0in;&quot; align=&quot;left&quot;&gt;&lt;span style=&quot;color: rgb(0, 0, 0);&quot;&gt;     &lt;/span&gt;&lt;span style=&quot;font-family:Courier New,monospace;&quot;&gt;&lt;span style=&quot;font-size:85%;&quot;&gt;&lt;span style=&quot;color: rgb(63, 95, 191);&quot;&gt;*/&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt; &lt;p style=&quot;margin-bottom: 0in;&quot; align=&quot;left&quot;&gt;&lt;span style=&quot;color: rgb(0, 0, 0);&quot;&gt;    &lt;/span&gt;&lt;span style=&quot;font-family:Courier New,monospace;&quot;&gt;&lt;span style=&quot;font-size:85%;&quot;&gt;&lt;span style=&quot;color: rgb(127, 0, 85);&quot;&gt;&lt;b&gt;public&lt;/b&gt;&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 0);&quot;&gt; Event getEvent() {&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt; &lt;p style=&quot;margin-bottom: 0in;&quot; align=&quot;left&quot;&gt;&lt;span style=&quot;color: rgb(0, 0, 0);&quot;&gt;        &lt;/span&gt;&lt;span style=&quot;font-family:Courier New,monospace;&quot;&gt;&lt;span style=&quot;font-size:85%;&quot;&gt;&lt;span style=&quot;color: rgb(127, 0, 85);&quot;&gt;&lt;b&gt;return&lt;/b&gt;&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 0);&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 192);&quot;&gt;event&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 0);&quot;&gt;;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt; &lt;p style=&quot;margin-bottom: 0in;&quot; align=&quot;left&quot;&gt;&lt;span style=&quot;color: rgb(0, 0, 0);&quot;&gt;    &lt;span style=&quot;font-family:Courier New,monospace;&quot;&gt;&lt;span style=&quot;font-size:85%;&quot;&gt;}&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt; &lt;p style=&quot;margin-bottom: 0in;&quot; align=&quot;left&quot;&gt;&lt;span style=&quot;color: rgb(0, 0, 0);&quot;&gt;    &lt;/span&gt;&lt;span style=&quot;font-family:Courier New,monospace;&quot;&gt;&lt;span style=&quot;font-size:85%;&quot;&gt;&lt;span style=&quot;color: rgb(63, 95, 191);&quot;&gt;/**&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt; &lt;p style=&quot;margin-bottom: 0in;&quot; align=&quot;left&quot;&gt;&lt;span style=&quot;color: rgb(0, 0, 0);&quot;&gt;     &lt;/span&gt;&lt;span style=&quot;font-family:Courier New,monospace;&quot;&gt;&lt;span style=&quot;font-size:85%;&quot;&gt;&lt;span style=&quot;color: rgb(63, 95, 191);&quot;&gt;*&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 0);&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: rgb(127, 159, 191);&quot;&gt;&lt;b&gt;@return&lt;/b&gt;&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 0);&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: rgb(63, 95, 191);&quot;&gt;Returns&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 0);&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: rgb(63, 95, 191);&quot;&gt;the&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 0);&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: rgb(63, 95, 191);&quot;&gt;origin.&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt; &lt;p style=&quot;margin-bottom: 0in;&quot; align=&quot;left&quot;&gt;&lt;span style=&quot;color: rgb(0, 0, 0);&quot;&gt;     &lt;/span&gt;&lt;span style=&quot;font-family:Courier New,monospace;&quot;&gt;&lt;span style=&quot;font-size:85%;&quot;&gt;&lt;span style=&quot;color: rgb(63, 95, 191);&quot;&gt;*/&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt; &lt;p style=&quot;margin-bottom: 0in;&quot; align=&quot;left&quot;&gt;&lt;span style=&quot;color: rgb(0, 0, 0);&quot;&gt;    &lt;/span&gt;&lt;span style=&quot;font-family:Courier New,monospace;&quot;&gt;&lt;span style=&quot;font-size:85%;&quot;&gt;&lt;span style=&quot;color: rgb(127, 0, 85);&quot;&gt;&lt;b&gt;public&lt;/b&gt;&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 0);&quot;&gt; State getOrigin() {&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt; &lt;p style=&quot;margin-bottom: 0in;&quot; align=&quot;left&quot;&gt;&lt;span style=&quot;color: rgb(0, 0, 0);&quot;&gt;        &lt;/span&gt;&lt;span style=&quot;font-family:Courier New,monospace;&quot;&gt;&lt;span style=&quot;font-size:85%;&quot;&gt;&lt;span style=&quot;color: rgb(127, 0, 85);&quot;&gt;&lt;b&gt;return&lt;/b&gt;&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 0);&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 192);&quot;&gt;origin&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 0);&quot;&gt;;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt; &lt;p style=&quot;margin-bottom: 0in;&quot; align=&quot;left&quot;&gt;&lt;span style=&quot;color: rgb(0, 0, 0);&quot;&gt;    &lt;span style=&quot;font-family:Courier New,monospace;&quot;&gt;&lt;span style=&quot;font-size:85%;&quot;&gt;}&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt; &lt;p style=&quot;margin-bottom: 0in;&quot; align=&quot;left&quot;&gt;&lt;span style=&quot;color: rgb(0, 0, 0);&quot;&gt;&lt;span style=&quot;font-family:Courier New,monospace;&quot;&gt;&lt;span style=&quot;font-size:85%;&quot;&gt;}&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;br /&gt;&lt;br /&gt;How this will look? Suppose you have a pretty simple FSM:&lt;br /&gt;&lt;br /&gt;&lt;a onblur=&quot;try {parent.deselectBloggerImageGracefully();} catch(e) {}&quot; href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiuqUEp-lO32MFlGRVjiH7BjoAgl9dDJiESUEw6Bm-kUJys0GFWc0yfWrCH8s-aEWJOEMh9VhPGy8FSdXG8rMGWbDhMd9Iyarowbd0uOautRtYnGYh3b38BBZ5s57snKT2K2VuD1oMB0VY/s1600-h/StatechartDiagram1.jpg&quot;&gt;&lt;img style=&quot;margin: 0pt 10px 10px 0pt; float: left; cursor: pointer;&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiuqUEp-lO32MFlGRVjiH7BjoAgl9dDJiESUEw6Bm-kUJys0GFWc0yfWrCH8s-aEWJOEMh9VhPGy8FSdXG8rMGWbDhMd9Iyarowbd0uOautRtYnGYh3b38BBZ5s57snKT2K2VuD1oMB0VY/s400/StatechartDiagram1.jpg&quot; alt=&quot;&quot; id=&quot;BLOGGER_PHOTO_ID_5238634434761992658&quot; border=&quot;0&quot; /&gt;&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br&gt;&lt;br /&gt;Using the previous pseudoDSL/Fluent interface will look like:&lt;br /&gt;&lt;p style=&quot;margin-bottom: 0in;&quot; align=&quot;left&quot;&gt;&lt;span style=&quot;font-family:Courier New,monospace;&quot;&gt;&lt;span style=&quot;font-size:85%;&quot;&gt;&lt;span style=&quot;color: rgb(127, 0, 85);&quot;&gt;&lt;b&gt;package&lt;/b&gt;&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 0);&quot;&gt; statemachine;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt; &lt;p style=&quot;margin-bottom: 0in;&quot; align=&quot;left&quot;&gt;&lt;br /&gt;&lt;/p&gt; &lt;p style=&quot;margin-bottom: 0in;&quot; align=&quot;left&quot;&gt;&lt;span style=&quot;font-family:Courier New,monospace;&quot;&gt;&lt;span style=&quot;font-size:85%;&quot;&gt;&lt;span style=&quot;color: rgb(127, 0, 85);&quot;&gt;&lt;b&gt;public&lt;/b&gt;&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 0);&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: rgb(127, 0, 85);&quot;&gt;&lt;b&gt;class&lt;/b&gt;&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 0);&quot;&gt; FSMDef {&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt; &lt;p style=&quot;margin-bottom: 0in;&quot; align=&quot;left&quot;&gt;&lt;span style=&quot;color: rgb(0, 0, 0);&quot;&gt;   &lt;/span&gt; &lt;/p&gt; &lt;p style=&quot;margin-bottom: 0in;&quot; align=&quot;left&quot;&gt;&lt;span style=&quot;color: rgb(0, 0, 0);&quot;&gt;    &lt;/span&gt;&lt;span style=&quot;font-family:Courier New,monospace;&quot;&gt;&lt;span style=&quot;font-size:85%;&quot;&gt;&lt;span style=&quot;color: rgb(127, 0, 85);&quot;&gt;&lt;b&gt;public&lt;/b&gt;&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 0);&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: rgb(127, 0, 85);&quot;&gt;&lt;b&gt;final&lt;/b&gt;&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 0);&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: rgb(127, 0, 85);&quot;&gt;&lt;b&gt;static&lt;/b&gt;&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 0);&quot;&gt; State &lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 192);&quot;&gt;&lt;i&gt;SUBMITTED&lt;/i&gt;&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 0);&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: rgb(127, 0, 85);&quot;&gt;&lt;b&gt;new&lt;/b&gt;&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 0);&quot;&gt; State(&lt;/span&gt;&lt;span style=&quot;color: rgb(42, 0, 255);&quot;&gt;&quot;Submitted&quot;&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 0);&quot;&gt;);&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt; &lt;p style=&quot;margin-bottom: 0in;&quot; align=&quot;left&quot;&gt;&lt;span style=&quot;color: rgb(0, 0, 0);&quot;&gt;    &lt;/span&gt;&lt;span style=&quot;font-family:Courier New,monospace;&quot;&gt;&lt;span style=&quot;font-size:85%;&quot;&gt;&lt;span style=&quot;color: rgb(127, 0, 85);&quot;&gt;&lt;b&gt;public&lt;/b&gt;&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 0);&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: rgb(127, 0, 85);&quot;&gt;&lt;b&gt;final&lt;/b&gt;&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 0);&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: rgb(127, 0, 85);&quot;&gt;&lt;b&gt;static&lt;/b&gt;&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 0);&quot;&gt; State &lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 192);&quot;&gt;&lt;i&gt;OPEN&lt;/i&gt;&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 0);&quot;&gt;= &lt;/span&gt;&lt;span style=&quot;color: rgb(127, 0, 85);&quot;&gt;&lt;b&gt;new&lt;/b&gt;&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 0);&quot;&gt; State(&lt;/span&gt;&lt;span style=&quot;color: rgb(42, 0, 255);&quot;&gt;&quot;Open&quot;&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 0);&quot;&gt;);&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt; &lt;p style=&quot;margin-bottom: 0in;&quot; align=&quot;left&quot;&gt;&lt;span style=&quot;color: rgb(0, 0, 0);&quot;&gt;    &lt;/span&gt;&lt;span style=&quot;font-family:Courier New,monospace;&quot;&gt;&lt;span style=&quot;font-size:85%;&quot;&gt;&lt;span style=&quot;color: rgb(127, 0, 85);&quot;&gt;&lt;b&gt;public&lt;/b&gt;&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 0);&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: rgb(127, 0, 85);&quot;&gt;&lt;b&gt;final&lt;/b&gt;&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 0);&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: rgb(127, 0, 85);&quot;&gt;&lt;b&gt;static&lt;/b&gt;&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 0);&quot;&gt; State &lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 192);&quot;&gt;&lt;i&gt;CANCELLED&lt;/i&gt;&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 0);&quot;&gt;= &lt;/span&gt;&lt;span style=&quot;color: rgb(127, 0, 85);&quot;&gt;&lt;b&gt;new&lt;/b&gt;&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 0);&quot;&gt; State(&lt;/span&gt;&lt;span style=&quot;color: rgb(42, 0, 255);&quot;&gt;&quot;Cancelled&quot;&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 0);&quot;&gt;);&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt; &lt;p style=&quot;margin-bottom: 0in;&quot; align=&quot;left&quot;&gt;&lt;span style=&quot;color: rgb(0, 0, 0);&quot;&gt;    &lt;/span&gt;&lt;span style=&quot;font-family:Courier New,monospace;&quot;&gt;&lt;span style=&quot;font-size:85%;&quot;&gt;&lt;span style=&quot;color: rgb(127, 0, 85);&quot;&gt;&lt;b&gt;public&lt;/b&gt;&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 0);&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: rgb(127, 0, 85);&quot;&gt;&lt;b&gt;final&lt;/b&gt;&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 0);&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: rgb(127, 0, 85);&quot;&gt;&lt;b&gt;static&lt;/b&gt;&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 0);&quot;&gt; State &lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 192);&quot;&gt;&lt;i&gt;CLOSED&lt;/i&gt;&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 0);&quot;&gt;= &lt;/span&gt;&lt;span style=&quot;color: rgb(127, 0, 85);&quot;&gt;&lt;b&gt;new&lt;/b&gt;&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 0);&quot;&gt; State(&lt;/span&gt;&lt;span style=&quot;color: rgb(42, 0, 255);&quot;&gt;&quot;Closed&quot;&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 0);&quot;&gt;);&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt; &lt;p style=&quot;margin-bottom: 0in;&quot; align=&quot;left&quot;&gt;&lt;span style=&quot;color: rgb(0, 0, 0);&quot;&gt;   &lt;/span&gt; &lt;/p&gt; &lt;p style=&quot;margin-bottom: 0in;&quot; align=&quot;left&quot;&gt;&lt;span style=&quot;color: rgb(0, 0, 0);&quot;&gt;    &lt;/span&gt;&lt;span style=&quot;font-family:Courier New,monospace;&quot;&gt;&lt;span style=&quot;font-size:85%;&quot;&gt;&lt;span style=&quot;color: rgb(63, 127, 95);&quot;&gt;//Events&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt; &lt;p style=&quot;margin-bottom: 0in;&quot; align=&quot;left&quot;&gt;&lt;span style=&quot;color: rgb(0, 0, 0);&quot;&gt;    &lt;/span&gt;&lt;span style=&quot;font-family:Courier New,monospace;&quot;&gt;&lt;span style=&quot;font-size:85%;&quot;&gt;&lt;span style=&quot;color: rgb(127, 0, 85);&quot;&gt;&lt;b&gt;static&lt;/b&gt;&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 0);&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: rgb(127, 0, 85);&quot;&gt;&lt;b&gt;class&lt;/b&gt;&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 0);&quot;&gt; Events {&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt; &lt;p style=&quot;margin-bottom: 0in;&quot; align=&quot;left&quot;&gt;&lt;span style=&quot;font-family:Courier New,monospace;&quot;&gt;&lt;span style=&quot;font-size:85%;&quot;&gt;&lt;span style=&quot;color: rgb(0, 0, 0);&quot;&gt;     &lt;/span&gt;&lt;span style=&quot;color: rgb(127, 0, 85);&quot;&gt;&lt;b&gt;public&lt;/b&gt;&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 0);&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: rgb(127, 0, 85);&quot;&gt;&lt;b&gt;final&lt;/b&gt;&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 0);&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: rgb(127, 0, 85);&quot;&gt;&lt;b&gt;static&lt;/b&gt;&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 0);&quot;&gt; Event &lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 192);&quot;&gt;&lt;i&gt;OPEN&lt;/i&gt;&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 0);&quot;&gt; = &lt;/span&gt;&lt;span style=&quot;color: rgb(127, 0, 85);&quot;&gt;&lt;b&gt;new&lt;/b&gt;&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 0);&quot;&gt; Event(&lt;/span&gt;&lt;span style=&quot;color: rgb(42, 0, 255);&quot;&gt;&quot;Open&quot;&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 0);&quot;&gt;);   &lt;/span&gt;&lt;/span&gt;&lt;/span&gt; &lt;/p&gt; &lt;p style=&quot;margin-bottom: 0in;&quot; align=&quot;left&quot;&gt;&lt;span style=&quot;font-family:Courier New,monospace;&quot;&gt;&lt;span style=&quot;font-size:85%;&quot;&gt;&lt;span style=&quot;color: rgb(0, 0, 0);&quot;&gt;     &lt;/span&gt;&lt;span style=&quot;color: rgb(127, 0, 85);&quot;&gt;&lt;b&gt;public&lt;/b&gt;&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 0);&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: rgb(127, 0, 85);&quot;&gt;&lt;b&gt;final&lt;/b&gt;&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 0);&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: rgb(127, 0, 85);&quot;&gt;&lt;b&gt;static&lt;/b&gt;&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 0);&quot;&gt; Event &lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 192);&quot;&gt;&lt;i&gt;CLOSE&lt;/i&gt;&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 0);&quot;&gt; = &lt;/span&gt;&lt;span style=&quot;color: rgb(127, 0, 85);&quot;&gt;&lt;b&gt;new&lt;/b&gt;&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 0);&quot;&gt; Event(&lt;/span&gt;&lt;span style=&quot;color: rgb(42, 0, 255);&quot;&gt;&quot;Close&quot;&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 0);&quot;&gt;);&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt; &lt;p style=&quot;margin-bottom: 0in;&quot; align=&quot;left&quot;&gt;&lt;span style=&quot;font-family:Courier New,monospace;&quot;&gt;&lt;span style=&quot;font-size:85%;&quot;&gt;&lt;span style=&quot;color: rgb(0, 0, 0);&quot;&gt;     &lt;/span&gt;&lt;span style=&quot;color: rgb(127, 0, 85);&quot;&gt;&lt;b&gt;public&lt;/b&gt;&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 0);&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: rgb(127, 0, 85);&quot;&gt;&lt;b&gt;final&lt;/b&gt;&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 0);&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: rgb(127, 0, 85);&quot;&gt;&lt;b&gt;static&lt;/b&gt;&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 0);&quot;&gt; Event &lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 192);&quot;&gt;&lt;i&gt;REOPEN&lt;/i&gt;&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 0);&quot;&gt; = &lt;/span&gt;&lt;span style=&quot;color: rgb(127, 0, 85);&quot;&gt;&lt;b&gt;new&lt;/b&gt;&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 0);&quot;&gt; Event(&lt;/span&gt;&lt;span style=&quot;color: rgb(42, 0, 255);&quot;&gt;&quot;Re-Open&quot;&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 0);&quot;&gt;);&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt; &lt;p style=&quot;margin-bottom: 0in;&quot; align=&quot;left&quot;&gt;&lt;span style=&quot;font-family:Courier New,monospace;&quot;&gt;&lt;span style=&quot;font-size:85%;&quot;&gt;&lt;span style=&quot;color: rgb(0, 0, 0);&quot;&gt;     &lt;/span&gt;&lt;span style=&quot;color: rgb(127, 0, 85);&quot;&gt;&lt;b&gt;public&lt;/b&gt;&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 0);&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: rgb(127, 0, 85);&quot;&gt;&lt;b&gt;final&lt;/b&gt;&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 0);&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: rgb(127, 0, 85);&quot;&gt;&lt;b&gt;static&lt;/b&gt;&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 0);&quot;&gt; Event &lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 192);&quot;&gt;&lt;i&gt;CANCEL&lt;/i&gt;&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 0);&quot;&gt; = &lt;/span&gt;&lt;span style=&quot;color: rgb(127, 0, 85);&quot;&gt;&lt;b&gt;new&lt;/b&gt;&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 0);&quot;&gt; Event(&lt;/span&gt;&lt;span style=&quot;color: rgb(42, 0, 255);&quot;&gt;&quot;Cancel&quot;&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 0);&quot;&gt;);&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt; &lt;p style=&quot;margin-bottom: 0in;&quot; align=&quot;left&quot;&gt;&lt;span style=&quot;color: rgb(0, 0, 0);&quot;&gt;    &lt;span style=&quot;font-family:Courier New,monospace;&quot;&gt;&lt;span style=&quot;font-size:85%;&quot;&gt;}&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt; &lt;p style=&quot;margin-bottom: 0in;&quot; align=&quot;left&quot;&gt;&lt;span style=&quot;color: rgb(0, 0, 0);&quot;&gt;   &lt;/span&gt; &lt;/p&gt; &lt;p style=&quot;margin-bottom: 0in;&quot; align=&quot;left&quot;&gt;&lt;span style=&quot;color: rgb(0, 0, 0);&quot;&gt;    &lt;/span&gt;&lt;span style=&quot;font-family:Courier New,monospace;&quot;&gt;&lt;span style=&quot;font-size:85%;&quot;&gt;&lt;span style=&quot;color: rgb(127, 0, 85);&quot;&gt;&lt;b&gt;static&lt;/b&gt;&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 0);&quot;&gt; {&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt; &lt;p style=&quot;margin-bottom: 0in;&quot; align=&quot;left&quot;&gt;&lt;span style=&quot;color: rgb(0, 0, 0);&quot;&gt;        &lt;/span&gt;&lt;span style=&quot;font-family:Courier New,monospace;&quot;&gt;&lt;span style=&quot;font-size:85%;&quot;&gt;&lt;span style=&quot;color: rgb(127, 0, 85);&quot;&gt;&lt;b&gt;new&lt;/b&gt;&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 0);&quot;&gt; Transition(Events.&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 192);&quot;&gt;&lt;i&gt;OPEN&lt;/i&gt;&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 0);&quot;&gt;).from(&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 192);&quot;&gt;&lt;i&gt;SUBMITTED&lt;/i&gt;&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 0);&quot;&gt;).to(&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 192);&quot;&gt;&lt;i&gt;OPEN&lt;/i&gt;&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 0);&quot;&gt;);&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt; &lt;p style=&quot;margin-bottom: 0in;&quot; align=&quot;left&quot;&gt;&lt;span style=&quot;color: rgb(0, 0, 0);&quot;&gt;        &lt;/span&gt;&lt;span style=&quot;font-family:Courier New,monospace;&quot;&gt;&lt;span style=&quot;font-size:85%;&quot;&gt;&lt;span style=&quot;color: rgb(127, 0, 85);&quot;&gt;&lt;b&gt;new&lt;/b&gt;&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 0);&quot;&gt; Transition(Events.&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 192);&quot;&gt;&lt;i&gt;CLOSE&lt;/i&gt;&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 0);&quot;&gt;).from(&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 192);&quot;&gt;&lt;i&gt;OPEN&lt;/i&gt;&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 0);&quot;&gt;).to(&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 192);&quot;&gt;&lt;i&gt;CLOSED&lt;/i&gt;&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 0);&quot;&gt;);&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt; &lt;p style=&quot;margin-bottom: 0in;&quot; align=&quot;left&quot;&gt;&lt;span style=&quot;color: rgb(0, 0, 0);&quot;&gt;        &lt;/span&gt;&lt;span style=&quot;font-family:Courier New,monospace;&quot;&gt;&lt;span style=&quot;font-size:85%;&quot;&gt;&lt;span style=&quot;color: rgb(127, 0, 85);&quot;&gt;&lt;b&gt;new&lt;/b&gt;&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 0);&quot;&gt; Transition(Events.&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 192);&quot;&gt;&lt;i&gt;REOPEN&lt;/i&gt;&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 0);&quot;&gt;).from(&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 192);&quot;&gt;&lt;i&gt;CLOSED&lt;/i&gt;&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 0);&quot;&gt;).to(&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 192);&quot;&gt;&lt;i&gt;OPEN&lt;/i&gt;&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 0);&quot;&gt;);&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt; &lt;p style=&quot;margin-bottom: 0in;&quot; align=&quot;left&quot;&gt;&lt;span style=&quot;color: rgb(0, 0, 0);&quot;&gt;        &lt;/span&gt;&lt;span style=&quot;font-family:Courier New,monospace;&quot;&gt;&lt;span style=&quot;font-size:85%;&quot;&gt;&lt;span style=&quot;color: rgb(127, 0, 85);&quot;&gt;&lt;b&gt;new&lt;/b&gt;&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 0);&quot;&gt; Transition(Events.&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 192);&quot;&gt;&lt;i&gt;CANCEL&lt;/i&gt;&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 0);&quot;&gt;).from(&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 192);&quot;&gt;&lt;i&gt;OPEN&lt;/i&gt;&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 0);&quot;&gt;).to(&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 192);&quot;&gt;&lt;i&gt;CANCELLED&lt;/i&gt;&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 0);&quot;&gt;);&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt; &lt;p style=&quot;margin-bottom: 0in;&quot; align=&quot;left&quot;&gt;&lt;span style=&quot;color: rgb(0, 0, 0);&quot;&gt;    &lt;span style=&quot;font-family:Courier New,monospace;&quot;&gt;&lt;span style=&quot;font-size:85%;&quot;&gt;}&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt; &lt;p style=&quot;margin-bottom: 0in;&quot; align=&quot;left&quot;&gt;&lt;span style=&quot;color: rgb(0, 0, 0);&quot;&gt;&lt;span style=&quot;font-family:Courier New,monospace;&quot;&gt;&lt;span style=&quot;font-size:85%;&quot;&gt;}&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;br /&gt;&lt;br /&gt;Doesn&#39;t seems too complex, right?&lt;br /&gt;I&#39;m just starting with this, and probably barely skim the surface (sure it has some drawbacks), but so far it worked :)&lt;br /&gt;&lt;br /&gt;[EDIT: Fixed the generics declarations that were eaten by the HTML format. BTW, if anybody knows a good code formatter for blog posts, let me know ]</description><link>http://gabrielsw.blogspot.com/2008/08/state-machines-using-fluent-interfaces.html</link><author>noreply@blogger.com (Anonymous)</author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiuqUEp-lO32MFlGRVjiH7BjoAgl9dDJiESUEw6Bm-kUJys0GFWc0yfWrCH8s-aEWJOEMh9VhPGy8FSdXG8rMGWbDhMd9Iyarowbd0uOautRtYnGYh3b38BBZ5s57snKT2K2VuD1oMB0VY/s72-c/StatechartDiagram1.jpg" height="72" width="72"/><thr:total>4</thr:total></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-6893032696317132921.post-8055574241022657933</guid><pubDate>Tue, 22 Jul 2008 00:23:00 +0000</pubDate><atom:updated>2008-07-31T09:17:13.668-04:00</atom:updated><category domain="http://www.blogger.com/atom/ns#">functional programming</category><category domain="http://www.blogger.com/atom/ns#">Scala</category><title>Scala: fold/reduce cheatsheet</title><description>&lt;span style=&quot;;font-family:Verdana,Arial;font-size:85%;&quot;  &gt;My fold/reduce &#39;cheat sheet&#39; is something like:&lt;br /&gt;&lt;br /&gt;For the list (a,b,c,d) fold/reduce is:&lt;br /&gt;&lt;br /&gt;reduceLeft(f) =&gt; f(f(f(a,b),c),d)&lt;br /&gt;&lt;br /&gt;foldLeft(Z)(f) =&gt; f(f(f(f(Z,a),b),c),d)&lt;br /&gt;&lt;br /&gt;(&quot;applies the function from the left&quot;)&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;reduceRight(f) =&gt; f(a,f(b,f(c,d)))&lt;br /&gt;&lt;br /&gt;foldRight(Z)(f) =&gt; f(a,f(b,f(c,f(d,Z))))&lt;br /&gt;&lt;br /&gt;(&quot;&lt;/span&gt;&lt;span style=&quot;;font-family:Verdana,Arial;font-size:85%;&quot;  &gt;applies the function&lt;/span&gt;&lt;span style=&quot;;font-family:Verdana,Arial;font-size:85%;&quot;  &gt; from the right&quot;)&lt;br /&gt;&lt;br /&gt;[EDIT: as you see, fold and reduce are essentially the same, but fold starts with an outside element ]&lt;br /&gt;&lt;/span&gt;</description><link>http://gabrielsw.blogspot.com/2008/07/scala-foldreduce-cheatsheet.html</link><author>noreply@blogger.com (Anonymous)</author><thr:total>1</thr:total></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-6893032696317132921.post-342783842011845463</guid><pubDate>Sat, 31 May 2008 02:26:00 +0000</pubDate><atom:updated>2008-05-30T22:42:51.528-04:00</atom:updated><category domain="http://www.blogger.com/atom/ns#">process</category><category domain="http://www.blogger.com/atom/ns#">programming</category><category domain="http://www.blogger.com/atom/ns#">software engineering</category><title>Questions, only questions</title><description>&lt;a onblur=&quot;try {parent.deselectBloggerImageGracefully();} catch(e) {}&quot; href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEihi-llIQN1pCMl8Gj1LD7xahaXU1RSYtl1S7YrusM6R5tfX8Utz1epoMNtK0uMltaFh8VfhrJrLHo7oYRE4zCkpwiVZre4mw65BfMg_dy8049zW4xEFcckk26px36J2OoitoJL2VkYHAU/s1600-h/IMG_0175.JPG&quot;&gt;&lt;img style=&quot;margin: 0pt 10px 10px 0pt; float: left; cursor: pointer;&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEihi-llIQN1pCMl8Gj1LD7xahaXU1RSYtl1S7YrusM6R5tfX8Utz1epoMNtK0uMltaFh8VfhrJrLHo7oYRE4zCkpwiVZre4mw65BfMg_dy8049zW4xEFcckk26px36J2OoitoJL2VkYHAU/s320/IMG_0175.JPG&quot; alt=&quot;&quot; id=&quot;BLOGGER_PHOTO_ID_5206366851524344674&quot; border=&quot;0&quot; /&gt;&lt;/a&gt;&lt;br /&gt;Today I&#39;m full of questions. Software development and programming is hard. Is a close encounter with layers and layers of complexity. Once we master one level, we open a whole new level. To tackle it one must employ multiple techniques. But they always involve trade-offs. How to balance programming using standard and maybe cumbersome idioms vs more elegant but more obscure idioms? What if the programming style is too personal and strange to others? Shall we settle for the lowest common denominator ? How do we balance the conflict between something harder to understand at first but easier to extend and maintain against something more familiar but with exponential complexity growth after each change? How do we maintain the &quot;conceptual integrity&quot; (F. Brooks) through the life of the system?   As the project complexity grows, the need for sophisticated techniques increases. (I&#39;m coming to the conclusion that if a developer can&#39;t comprehend some level of complexity, shouldn&#39;t be allowed to participate in the project without close mentoring).  Refactoring is necessary because entropy. Every code base starts to degrade and loose integrity as evolves. I wonder if there&#39;s a code entropy metric... At what point a refactoring is good enough? When do you stop? At least your architecture should be stable, or you didn&#39;t validate it.   I guess complexity is in the eye of the beholder. I found  that a system composed of  smaller simple pieces with complex interactions is easier to evolve than bigger pieces with simple interactions because each piece is internally complex and the limited interactions means its harder to combinate them in new ways. Of course, gratuitous complexity should be avoided at all costs. Sometimes I look for a &quot;zen&quot; approach to coding. At the end, I always take a pragmatic approach and find a trade-off that balances the forces. Isn&#39;t coding about that? Each line you write is a choice you need to make... At some point we need to use &quot;introspection&quot; and &quot;metaprogramming&quot; but not the programming techniques: introspection on how we approach problem solving and programming and metaprogramming on what we can do to program better.</description><link>http://gabrielsw.blogspot.com/2008/05/questions-only-questions.html</link><author>noreply@blogger.com (Anonymous)</author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEihi-llIQN1pCMl8Gj1LD7xahaXU1RSYtl1S7YrusM6R5tfX8Utz1epoMNtK0uMltaFh8VfhrJrLHo7oYRE4zCkpwiVZre4mw65BfMg_dy8049zW4xEFcckk26px36J2OoitoJL2VkYHAU/s72-c/IMG_0175.JPG" height="72" width="72"/><thr:total>7</thr:total></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-6893032696317132921.post-5844695993087030200</guid><pubDate>Mon, 04 Feb 2008 01:45:00 +0000</pubDate><atom:updated>2008-02-03T20:52:28.721-05:00</atom:updated><category domain="http://www.blogger.com/atom/ns#">code</category><category domain="http://www.blogger.com/atom/ns#">functional programming</category><category domain="http://www.blogger.com/atom/ns#">Java</category><category domain="http://www.blogger.com/atom/ns#">OO</category><category domain="http://www.blogger.com/atom/ns#">Scala</category><title>Playing with Scala 4: Abstract types and Self-types</title><description>Thanks to the scala mailing list, and to Eric, I have a satisfying enough model of a graph to be used by the Dijkstra&#39;s algorithm.&lt;br /&gt;(well, there already was a generic graph and directed graph written in Scala...  talking about reinventing the wheel!. The solution in &lt;a title=&quot;Eric&#39;s comment&quot; href=&quot;http://gabrielsw.blogspot.com/2008/01/playing-with-scala-3-oo-traits-and.html#c8692825781706817554&quot; id=&quot;emp2&quot;&gt;Eric&#39;s comment&lt;/a&gt; works great too... is almost the same, but he was faster than me on coming up with it :D )&lt;br /&gt;http://www.scala-lang.org/intro/abstracttypes.html&lt;br /&gt;http://www.scala-lang.org/intro/selfrefs.html&lt;br /&gt;I just used the same code, and changed the nodes and edges to use sets instead of lists (really, we don&#39;t care about the order)&lt;br /&gt;The Scala example of Graph uses abstract types: it declares type Node and type Edge as type &quot;parameters&quot; to be defined by concrete implementation. Even more, by declaring type Node &lt;: NodeIntf, we&#39;re restricting Node to be subtypes of NodeIntf. The declaration &quot;self: Node =&gt;&quot; tells &quot;I&#39;ll use self as Node type&quot;&lt;br /&gt;Then I declared the trait Weighted and extended the class DirectedGraph adding my extensions to NodeImpl and EdgeImpl to use weighted trait and add the node label and the previous property. I had to add a collection of the adjacent arcs, because they weren&#39;t in the original Graph and is easier for the algorithm. I overrode the connectWith method to keep track of the adjacent arcs as they&#39;re added, also I defined our --&gt; operator to call the connectWith method.&lt;br /&gt;&lt;br /&gt;    class DfsNode extends NodeImpl with Weighted {&lt;br /&gt;&lt;div style=&quot;margin-left: 40px;&quot;&gt;    var previous: DfsNode = _&lt;br /&gt;    var label:String = _&lt;br /&gt;    var nodeEdges: Set[Edge] = Set()&lt;br /&gt;   &lt;br /&gt;    override def connectWith(node: Node): Edge = {&lt;br /&gt;      val newEdge=super.connectWith(node)&lt;br /&gt;      nodeEdges = nodeEdges + newEdge&lt;br /&gt;      newEdge&lt;br /&gt;    }&lt;br /&gt;   &lt;br /&gt;    def --&gt;(n2:Node):DfsEdge =connectWith(n2)&lt;br /&gt;   &lt;br /&gt;    override def toString()= label+ &quot; w:&quot;+weight&lt;br /&gt;&lt;/div&gt;   }&lt;br /&gt;&lt;br /&gt;Edges are simpler, just add the weight and override toString:&lt;br /&gt; class DfsEdge(origin:Node, dest:Node) extends EdgeImpl(origin, dest) with Weighted {&lt;br /&gt;    override def toString()= from.label+&quot;--&gt;&quot;+to.label+&quot; w:&quot;+weight&lt;br /&gt;  }&lt;br /&gt;&lt;br /&gt;All are enclosed in the DfsGraph class extending the DirectedGraph class, now I can assign the concrete types for Node and Edge:&lt;br /&gt;  type Node= DfsNode&lt;br /&gt;  type Edge= DfsEdge&lt;br /&gt;&lt;br /&gt;The DirectedGraph class has a addNode method. To keep the DSL-ish quality of the construction of the graph, I added the method addNewNode to take the node label as parameter&lt;br /&gt;  def addNewNode(l:String):Node={&lt;br /&gt;    val newNode=super.addNode&lt;br /&gt;    newNode.label=l&lt;br /&gt;    newNode&lt;br /&gt;  }&lt;br /&gt;&lt;br /&gt;So we can write: graph addNewNode &quot;nodeLabel&quot;.&lt;br /&gt;&lt;br /&gt;The example looks like this:&lt;br /&gt;&lt;br /&gt; &lt;p class=&quot;MsoNormal&quot; style=&quot;&quot;&gt;&lt;b&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: rgb(127, 127, 127);&quot;&gt;object&lt;/span&gt;&lt;/b&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: black;&quot;&gt; &lt;/span&gt;&lt;b&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: brown;&quot;&gt;Example&lt;/span&gt;&lt;/b&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: black;&quot;&gt; &lt;/span&gt;&lt;b&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: rgb(127, 127, 127);&quot;&gt;extends&lt;/span&gt;&lt;/b&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: black;&quot;&gt; &lt;/span&gt;&lt;b&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: brown;&quot;&gt;Application&lt;/span&gt;&lt;/b&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: black;&quot;&gt; {&lt;/span&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;;&quot;&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;    &lt;p class=&quot;MsoNormal&quot; style=&quot;&quot;&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: black;&quot;&gt;&lt;span style=&quot;&quot;&gt;  &lt;/span&gt;&lt;/span&gt;&lt;b&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: rgb(127, 127, 127);&quot;&gt;val&lt;/span&gt;&lt;/b&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: black;&quot;&gt; &lt;/span&gt;&lt;b&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: rgb(27, 27, 215);&quot;&gt;graph&lt;/span&gt;&lt;/b&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: black;&quot;&gt; = &lt;/span&gt;&lt;b&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: rgb(127, 127, 127);&quot;&gt;new&lt;/span&gt;&lt;/b&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: black;&quot;&gt; &lt;/span&gt;&lt;b&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: brown;&quot;&gt;DfsGraph&lt;/span&gt;&lt;/b&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;;&quot;&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;                                        &lt;p class=&quot;MsoNormal&quot; style=&quot;&quot;&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: black;&quot;&gt;&lt;span style=&quot;&quot;&gt;  &lt;/span&gt;&lt;/span&gt;&lt;b&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: rgb(127, 127, 127);&quot;&gt;val&lt;/span&gt;&lt;/b&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: black;&quot;&gt; &lt;/span&gt;&lt;b&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: rgb(27, 27, 215);&quot;&gt;n1&lt;/span&gt;&lt;/b&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: black;&quot;&gt;=&lt;/span&gt;&lt;b&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: rgb(27, 27, 215);&quot;&gt;graph&lt;/span&gt;&lt;/b&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: black;&quot;&gt; &lt;/span&gt;&lt;b&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: dodgerblue;&quot;&gt;addNewNode&lt;/span&gt;&lt;/b&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: black;&quot;&gt; &lt;/span&gt;&lt;i&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: rgb(127, 127, 127);&quot;&gt;&quot;start&quot;&lt;/span&gt;&lt;/i&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: black;&quot;&gt; &lt;/span&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;;&quot;&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: black;&quot;&gt;&lt;span style=&quot;&quot;&gt;  &lt;/span&gt;&lt;/span&gt;&lt;b&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: rgb(127, 127, 127);&quot;&gt;val&lt;/span&gt;&lt;/b&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: black;&quot;&gt; &lt;/span&gt;&lt;b&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: rgb(27, 27, 215);&quot;&gt;n2&lt;/span&gt;&lt;/b&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: black;&quot;&gt;=&lt;/span&gt;&lt;b&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: rgb(27, 27, 215);&quot;&gt;graph&lt;/span&gt;&lt;/b&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: black;&quot;&gt; &lt;/span&gt;&lt;b&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: dodgerblue;&quot;&gt;addNewNode&lt;/span&gt;&lt;/b&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: black;&quot;&gt; &lt;/span&gt;&lt;i&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: rgb(127, 127, 127);&quot;&gt;&quot;n2&quot;&lt;/span&gt;&lt;/i&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;;&quot;&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: black;&quot;&gt;&lt;span style=&quot;&quot;&gt;  &lt;/span&gt;&lt;/span&gt;&lt;b&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: rgb(127, 127, 127);&quot;&gt;val&lt;/span&gt;&lt;/b&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: black;&quot;&gt; &lt;/span&gt;&lt;b&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: rgb(27, 27, 215);&quot;&gt;n3&lt;/span&gt;&lt;/b&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: black;&quot;&gt;=&lt;/span&gt;&lt;b&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: rgb(27, 27, 215);&quot;&gt;graph&lt;/span&gt;&lt;/b&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: black;&quot;&gt; &lt;/span&gt;&lt;b&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: dodgerblue;&quot;&gt;addNewNode&lt;/span&gt;&lt;/b&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: black;&quot;&gt; &lt;/span&gt;&lt;i&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: rgb(127, 127, 127);&quot;&gt;&quot;n3&quot;&lt;/span&gt;&lt;/i&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;;&quot;&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: black;&quot;&gt;&lt;span style=&quot;&quot;&gt;  &lt;/span&gt;&lt;/span&gt;&lt;b&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: rgb(127, 127, 127);&quot;&gt;val&lt;/span&gt;&lt;/b&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: black;&quot;&gt; &lt;/span&gt;&lt;b&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: rgb(27, 27, 215);&quot;&gt;n4&lt;/span&gt;&lt;/b&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: black;&quot;&gt;=&lt;/span&gt;&lt;b&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: rgb(27, 27, 215);&quot;&gt;graph&lt;/span&gt;&lt;/b&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: black;&quot;&gt; &lt;/span&gt;&lt;b&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: dodgerblue;&quot;&gt;addNewNode&lt;/span&gt;&lt;/b&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: black;&quot;&gt; &lt;/span&gt;&lt;i&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: rgb(127, 127, 127);&quot;&gt;&quot;n4&quot;&lt;/span&gt;&lt;/i&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;;&quot;&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: black;&quot;&gt;&lt;span style=&quot;&quot;&gt;  &lt;/span&gt;&lt;/span&gt;&lt;b&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: rgb(127, 127, 127);&quot;&gt;val&lt;/span&gt;&lt;/b&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: black;&quot;&gt; &lt;/span&gt;&lt;b&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: rgb(27, 27, 215);&quot;&gt;n5&lt;/span&gt;&lt;/b&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: black;&quot;&gt;=&lt;/span&gt;&lt;b&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: rgb(27, 27, 215);&quot;&gt;graph&lt;/span&gt;&lt;/b&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: black;&quot;&gt; &lt;/span&gt;&lt;b&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: dodgerblue;&quot;&gt;addNewNode&lt;/span&gt;&lt;/b&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: black;&quot;&gt; &lt;/span&gt;&lt;i&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: rgb(127, 127, 127);&quot;&gt;&quot;n5&quot;&lt;/span&gt;&lt;/i&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;;&quot;&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: black;&quot;&gt;&lt;span style=&quot;&quot;&gt;  &lt;/span&gt;&lt;/span&gt;&lt;b&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: rgb(127, 127, 127);&quot;&gt;val&lt;/span&gt;&lt;/b&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: black;&quot;&gt; &lt;/span&gt;&lt;b&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: rgb(27, 27, 215);&quot;&gt;n6&lt;/span&gt;&lt;/b&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: black;&quot;&gt;=&lt;/span&gt;&lt;b&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: rgb(27, 27, 215);&quot;&gt;graph&lt;/span&gt;&lt;/b&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: black;&quot;&gt; &lt;/span&gt;&lt;b&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: dodgerblue;&quot;&gt;addNewNode&lt;/span&gt;&lt;/b&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: black;&quot;&gt; &lt;/span&gt;&lt;i&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: rgb(127, 127, 127);&quot;&gt;&quot;end&quot;&lt;/span&gt;&lt;/i&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;;&quot;&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: black;&quot;&gt;&lt;span style=&quot;&quot;&gt;    &lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;;&quot;&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: black;&quot;&gt;&lt;span style=&quot;&quot;&gt;  &lt;/span&gt;&lt;/span&gt;&lt;b&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: rgb(27, 27, 215);&quot;&gt;n1&lt;/span&gt;&lt;/b&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: black;&quot;&gt;--&gt;&lt;/span&gt;&lt;b&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: rgb(27, 27, 215);&quot;&gt;n2&lt;/span&gt;&lt;/b&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: black;&quot;&gt; &lt;/span&gt;&lt;b&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: rgb(27, 27, 215);&quot;&gt;weight&lt;/span&gt;&lt;/b&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: black;&quot;&gt;=2&lt;/span&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;;&quot;&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: black;&quot;&gt;&lt;span style=&quot;&quot;&gt;  &lt;/span&gt;&lt;/span&gt;&lt;b&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: rgb(27, 27, 215);&quot;&gt;n1&lt;/span&gt;&lt;/b&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: black;&quot;&gt;--&gt;&lt;/span&gt;&lt;b&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: rgb(27, 27, 215);&quot;&gt;n3&lt;/span&gt;&lt;/b&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: black;&quot;&gt; &lt;/span&gt;&lt;b&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: rgb(27, 27, 215);&quot;&gt;weight&lt;/span&gt;&lt;/b&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: black;&quot;&gt;=1&lt;/span&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;;&quot;&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: black;&quot;&gt;&lt;span style=&quot;&quot;&gt;  &lt;/span&gt;&lt;/span&gt;&lt;b&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: rgb(27, 27, 215);&quot;&gt;n2&lt;/span&gt;&lt;/b&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: black;&quot;&gt;--&gt;&lt;/span&gt;&lt;b&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: rgb(27, 27, 215);&quot;&gt;n4&lt;/span&gt;&lt;/b&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: black;&quot;&gt; &lt;/span&gt;&lt;b&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: rgb(27, 27, 215);&quot;&gt;weight&lt;/span&gt;&lt;/b&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: black;&quot;&gt;=1&lt;/span&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;;&quot;&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: black;&quot;&gt;&lt;span style=&quot;&quot;&gt;  &lt;/span&gt;&lt;/span&gt;&lt;b&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: rgb(27, 27, 215);&quot;&gt;n3&lt;/span&gt;&lt;/b&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: black;&quot;&gt;--&gt;&lt;/span&gt;&lt;b&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: rgb(27, 27, 215);&quot;&gt;n4&lt;/span&gt;&lt;/b&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: black;&quot;&gt; &lt;/span&gt;&lt;b&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: rgb(27, 27, 215);&quot;&gt;weight&lt;/span&gt;&lt;/b&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: black;&quot;&gt;=3&lt;/span&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;;&quot;&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: black;&quot;&gt;&lt;span style=&quot;&quot;&gt;  &lt;/span&gt;&lt;/span&gt;&lt;b&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: rgb(27, 27, 215);&quot;&gt;n2&lt;/span&gt;&lt;/b&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: black;&quot;&gt;--&gt;&lt;/span&gt;&lt;b&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: rgb(27, 27, 215);&quot;&gt;n5&lt;/span&gt;&lt;/b&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: black;&quot;&gt; &lt;/span&gt;&lt;b&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: rgb(27, 27, 215);&quot;&gt;weight&lt;/span&gt;&lt;/b&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: black;&quot;&gt;=1&lt;/span&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;;&quot;&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: black;&quot;&gt;&lt;span style=&quot;&quot;&gt;  &lt;/span&gt;&lt;/span&gt;&lt;b&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: rgb(27, 27, 215);&quot;&gt;n4&lt;/span&gt;&lt;/b&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: black;&quot;&gt;--&gt;&lt;/span&gt;&lt;b&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: rgb(27, 27, 215);&quot;&gt;n6&lt;/span&gt;&lt;/b&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: black;&quot;&gt; &lt;/span&gt;&lt;b&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: rgb(27, 27, 215);&quot;&gt;weight&lt;/span&gt;&lt;/b&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: black;&quot;&gt;=1&lt;/span&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;;&quot;&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: black;&quot;&gt;&lt;span style=&quot;&quot;&gt;  &lt;/span&gt;&lt;/span&gt;&lt;b&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: rgb(27, 27, 215);&quot;&gt;n5&lt;/span&gt;&lt;/b&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: black;&quot;&gt;--&gt;&lt;/span&gt;&lt;b&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: rgb(27, 27, 215);&quot;&gt;n6&lt;/span&gt;&lt;/b&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: black;&quot;&gt; &lt;/span&gt;&lt;b&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: rgb(27, 27, 215);&quot;&gt;weight&lt;/span&gt;&lt;/b&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: black;&quot;&gt;=3&lt;/span&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;;&quot;&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: black;&quot;&gt;&lt;span style=&quot;&quot;&gt; &lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;;&quot;&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: black;&quot;&gt;&lt;span style=&quot;&quot;&gt;  &lt;/span&gt;&lt;/span&gt;&lt;b&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: rgb(27, 27, 215);&quot;&gt;graph&lt;/span&gt;&lt;/b&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: black;&quot;&gt;.&lt;/span&gt;&lt;b&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: dodgerblue;&quot;&gt;shortestPath&lt;/span&gt;&lt;/b&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: black;&quot;&gt;(&lt;/span&gt;&lt;b&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: rgb(27, 27, 215);&quot;&gt;n1&lt;/span&gt;&lt;/b&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: black;&quot;&gt;,&lt;/span&gt;&lt;b&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: rgb(27, 27, 215);&quot;&gt;n6&lt;/span&gt;&lt;/b&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: black;&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;;&quot;&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: black;&quot;&gt;&lt;span style=&quot;&quot;&gt;  &lt;/span&gt;&lt;/span&gt;&lt;b&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: dodgerblue;&quot;&gt;println&lt;/span&gt;&lt;/b&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: black;&quot;&gt;(&lt;/span&gt;&lt;i&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: rgb(127, 127, 127);&quot;&gt;&quot;Path&quot;&lt;/span&gt;&lt;/i&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: black;&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;;&quot;&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: black;&quot;&gt;&lt;span style=&quot;&quot;&gt;  &lt;/span&gt;&lt;/span&gt;&lt;b&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: rgb(27, 27, 215);&quot;&gt;graph&lt;/span&gt;&lt;/b&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: black;&quot;&gt;.&lt;/span&gt;&lt;b&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: dodgerblue;&quot;&gt;pathToStart&lt;/span&gt;&lt;/b&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: black;&quot;&gt;(&lt;/span&gt;&lt;b&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: rgb(27, 27, 215);&quot;&gt;n6&lt;/span&gt;&lt;/b&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: black;&quot;&gt;).&lt;/span&gt;&lt;b&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: dodgerblue;&quot;&gt;reverse&lt;/span&gt;&lt;/b&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: black;&quot;&gt;.&lt;/span&gt;&lt;b&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: dodgerblue;&quot;&gt;map&lt;/span&gt;&lt;/b&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: black;&quot;&gt;(&lt;/span&gt;&lt;b&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: dodgerblue;&quot;&gt;println&lt;/span&gt;&lt;/b&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: black;&quot;&gt;(_))&lt;/span&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;;&quot;&gt;&lt;o:p&gt; &lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p class=&quot;MsoNormal&quot; style=&quot;&quot;&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: black;&quot;&gt;}&lt;/span&gt;&lt;span style=&quot;font-size: 10pt; font-family: Arial;&quot;&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  Pretty easy to read, don&#39;t you think?&lt;br /&gt;In the next post, I&#39;ll show you how we can use this algorithm to solve the &lt;a title=&quot;&amp;quot;Abbott&#39;s revenge&amp;quot;&quot; href=&quot;http://acm.uva.es/p/v8/816.html&quot; id=&quot;rg0.&quot;&gt;&quot;Abbott&#39;s revenge&quot;&lt;/a&gt; type of maze. Ideally, I want to create an interpreter for the input, exploring Scala&#39;s features for creating language interpreters.&lt;br /&gt;Here is the complete code:&lt;br /&gt;&lt;br /&gt;              &lt;p class=&quot;MsoNormal&quot; style=&quot;&quot;&gt;&lt;b&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: rgb(127, 127, 127);&quot;&gt;package&lt;/span&gt;&lt;/b&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: black;&quot;&gt; dfs2;&lt;/span&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;;&quot;&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p class=&quot;MsoNormal&quot; style=&quot;&quot;&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;;&quot;&gt;&lt;o:p&gt; &lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;                                            &lt;p class=&quot;MsoNormal&quot; style=&quot;&quot;&gt;&lt;b&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: rgb(127, 127, 127);&quot;&gt;abstract&lt;/span&gt;&lt;/b&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: black;&quot;&gt; &lt;/span&gt;&lt;b&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: rgb(127, 127, 127);&quot;&gt;class&lt;/span&gt;&lt;/b&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: black;&quot;&gt; &lt;/span&gt;&lt;b&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: brown;&quot;&gt;Graph&lt;/span&gt;&lt;/b&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: black;&quot;&gt; {&lt;/span&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;;&quot;&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: black;&quot;&gt;&lt;span style=&quot;&quot;&gt;  &lt;/span&gt;&lt;/span&gt;&lt;b&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: rgb(127, 127, 127);&quot;&gt;type&lt;/span&gt;&lt;/b&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: black;&quot;&gt; &lt;/span&gt;&lt;b&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: rgb(139, 105, 20);&quot;&gt;Edge&lt;/span&gt;&lt;/b&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;;&quot;&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: black;&quot;&gt;&lt;span style=&quot;&quot;&gt;  &lt;/span&gt;&lt;/span&gt;&lt;b&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: rgb(127, 127, 127);&quot;&gt;type&lt;/span&gt;&lt;/b&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: black;&quot;&gt; &lt;/span&gt;&lt;b&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: rgb(139, 105, 20);&quot;&gt;Node&lt;/span&gt;&lt;/b&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: black;&quot;&gt; &lt;: NodeIntf&lt;/span&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;;&quot;&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: black;&quot;&gt;&lt;span style=&quot;&quot;&gt;  &lt;/span&gt;&lt;/span&gt;&lt;b&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: rgb(127, 127, 127);&quot;&gt;abstract&lt;/span&gt;&lt;/b&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: black;&quot;&gt; &lt;/span&gt;&lt;b&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: rgb(127, 127, 127);&quot;&gt;class&lt;/span&gt;&lt;/b&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: black;&quot;&gt; &lt;/span&gt;&lt;b&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: brown;&quot;&gt;NodeIntf&lt;/span&gt;&lt;/b&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: black;&quot;&gt; {&lt;/span&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;;&quot;&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: black;&quot;&gt;&lt;span style=&quot;&quot;&gt;    &lt;/span&gt;&lt;/span&gt;&lt;b&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: rgb(127, 127, 127);&quot;&gt;def&lt;/span&gt;&lt;/b&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: black;&quot;&gt; &lt;/span&gt;&lt;b&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: dodgerblue;&quot;&gt;connectWith&lt;/span&gt;&lt;/b&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: black;&quot;&gt;(&lt;/span&gt;&lt;b&gt;&lt;i&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: rgb(27, 27, 215);&quot;&gt;node&lt;/span&gt;&lt;/i&gt;&lt;/b&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: black;&quot;&gt;: &lt;/span&gt;&lt;b&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: rgb(139, 105, 20);&quot;&gt;Node&lt;/span&gt;&lt;/b&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: black;&quot;&gt;): &lt;/span&gt;&lt;b&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: rgb(139, 105, 20);&quot;&gt;Edge&lt;/span&gt;&lt;/b&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;;&quot;&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: black;&quot;&gt;&lt;span style=&quot;&quot;&gt;  &lt;/span&gt;}&lt;/span&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;;&quot;&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: black;&quot;&gt;&lt;span style=&quot;&quot;&gt;  &lt;/span&gt;&lt;/span&gt;&lt;b&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: rgb(127, 127, 127);&quot;&gt;def&lt;/span&gt;&lt;/b&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: black;&quot;&gt; &lt;/span&gt;&lt;b&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: dodgerblue;&quot;&gt;nodes&lt;/span&gt;&lt;/b&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: black;&quot;&gt;: &lt;/span&gt;&lt;b&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: brown;&quot;&gt;Set&lt;/span&gt;&lt;/b&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: black;&quot;&gt;[&lt;/span&gt;&lt;b&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: rgb(139, 105, 20);&quot;&gt;Node&lt;/span&gt;&lt;/b&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: black;&quot;&gt;]&lt;/span&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;;&quot;&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: black;&quot;&gt;&lt;span style=&quot;&quot;&gt;  &lt;/span&gt;&lt;/span&gt;&lt;b&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: rgb(127, 127, 127);&quot;&gt;def&lt;/span&gt;&lt;/b&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: black;&quot;&gt; &lt;/span&gt;&lt;b&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: dodgerblue;&quot;&gt;edges&lt;/span&gt;&lt;/b&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: black;&quot;&gt;: &lt;/span&gt;&lt;b&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: brown;&quot;&gt;Set&lt;/span&gt;&lt;/b&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: black;&quot;&gt;[&lt;/span&gt;&lt;b&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: rgb(139, 105, 20);&quot;&gt;Edge&lt;/span&gt;&lt;/b&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: black;&quot;&gt;]&lt;/span&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;;&quot;&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: black;&quot;&gt;&lt;span style=&quot;&quot;&gt;  &lt;/span&gt;&lt;/span&gt;&lt;b&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: rgb(127, 127, 127);&quot;&gt;def&lt;/span&gt;&lt;/b&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: black;&quot;&gt; &lt;/span&gt;&lt;b&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: dodgerblue;&quot;&gt;addNode&lt;/span&gt;&lt;/b&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: black;&quot;&gt;: &lt;/span&gt;&lt;b&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: rgb(139, 105, 20);&quot;&gt;Node&lt;/span&gt;&lt;/b&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;;&quot;&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: black;&quot;&gt;}&lt;/span&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;;&quot;&gt;&lt;o:p&gt; &lt;/o:p&gt;&lt;/span&gt;&lt;br /&gt;&lt;b&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: rgb(127, 127, 127);&quot;&gt;&lt;/span&gt;&lt;/b&gt;&lt;/p&gt;              &lt;p class=&quot;MsoNormal&quot; style=&quot;&quot;&gt;&lt;b&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: rgb(127, 127, 127);&quot;&gt;abstract&lt;/span&gt;&lt;/b&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: black;&quot;&gt; &lt;/span&gt;&lt;b&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: rgb(127, 127, 127);&quot;&gt;class&lt;/span&gt;&lt;/b&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: black;&quot;&gt; &lt;/span&gt;&lt;b&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: brown;&quot;&gt;DirectedGraph&lt;/span&gt;&lt;/b&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: black;&quot;&gt; &lt;/span&gt;&lt;b&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: rgb(127, 127, 127);&quot;&gt;extends&lt;/span&gt;&lt;/b&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: black;&quot;&gt; &lt;/span&gt;&lt;b&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: brown;&quot;&gt;Graph&lt;/span&gt;&lt;/b&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: black;&quot;&gt; {&lt;/span&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;;&quot;&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: black;&quot;&gt;&lt;span style=&quot;&quot;&gt;  &lt;/span&gt;&lt;/span&gt;&lt;b&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: rgb(127, 127, 127);&quot;&gt;type&lt;/span&gt;&lt;/b&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: black;&quot;&gt; &lt;/span&gt;&lt;b&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: rgb(139, 105, 20);&quot;&gt;Edge&lt;/span&gt;&lt;/b&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: black;&quot;&gt; &lt;: EdgeImpl&lt;/span&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;;&quot;&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: black;&quot;&gt;&lt;span style=&quot;&quot;&gt;  &lt;/span&gt;&lt;/span&gt;&lt;b&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: rgb(127, 127, 127);&quot;&gt;class&lt;/span&gt;&lt;/b&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: black;&quot;&gt; &lt;/span&gt;&lt;b&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: brown;&quot;&gt;EdgeImpl&lt;/span&gt;&lt;/b&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: black;&quot;&gt;(&lt;/span&gt;&lt;b&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: rgb(27, 27, 215);&quot;&gt;origin&lt;/span&gt;&lt;/b&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: black;&quot;&gt;: &lt;/span&gt;&lt;b&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: rgb(139, 105, 20);&quot;&gt;Node&lt;/span&gt;&lt;/b&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: black;&quot;&gt;, &lt;/span&gt;&lt;b&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: rgb(27, 27, 215);&quot;&gt;dest&lt;/span&gt;&lt;/b&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: black;&quot;&gt;: &lt;/span&gt;&lt;b&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: rgb(139, 105, 20);&quot;&gt;Node&lt;/span&gt;&lt;/b&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: black;&quot;&gt;) {&lt;/span&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;;&quot;&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: black;&quot;&gt;&lt;span style=&quot;&quot;&gt;    &lt;/span&gt;&lt;/span&gt;&lt;b&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: rgb(127, 127, 127);&quot;&gt;def&lt;/span&gt;&lt;/b&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: black;&quot;&gt; &lt;/span&gt;&lt;b&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: dodgerblue;&quot;&gt;from&lt;/span&gt;&lt;/b&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: black;&quot;&gt; = &lt;/span&gt;&lt;b&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: rgb(27, 27, 215);&quot;&gt;origin&lt;/span&gt;&lt;/b&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;;&quot;&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: black;&quot;&gt;&lt;span style=&quot;&quot;&gt;    &lt;/span&gt;&lt;/span&gt;&lt;b&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: rgb(127, 127, 127);&quot;&gt;def&lt;/span&gt;&lt;/b&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: black;&quot;&gt; &lt;/span&gt;&lt;b&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: dodgerblue;&quot;&gt;to&lt;/span&gt;&lt;/b&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: black;&quot;&gt; = &lt;/span&gt;&lt;b&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: rgb(27, 27, 215);&quot;&gt;dest&lt;/span&gt;&lt;/b&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;;&quot;&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: black;&quot;&gt;&lt;span style=&quot;&quot;&gt;  &lt;/span&gt;}&lt;/span&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;;&quot;&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: black;&quot;&gt;&lt;span style=&quot;&quot;&gt;  &lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;;&quot;&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: black;&quot;&gt;&lt;span style=&quot;&quot;&gt;  &lt;/span&gt;&lt;/span&gt;&lt;b&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: rgb(127, 127, 127);&quot;&gt;class&lt;/span&gt;&lt;/b&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: black;&quot;&gt; &lt;/span&gt;&lt;b&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: brown;&quot;&gt;NodeImpl&lt;/span&gt;&lt;/b&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: black;&quot;&gt; &lt;/span&gt;&lt;b&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: rgb(127, 127, 127);&quot;&gt;extends&lt;/span&gt;&lt;/b&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: black;&quot;&gt; &lt;/span&gt;&lt;b&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: brown;&quot;&gt;NodeIntf&lt;/span&gt;&lt;/b&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: black;&quot;&gt; {&lt;/span&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;;&quot;&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: black;&quot;&gt;&lt;span style=&quot;&quot;&gt;    &lt;/span&gt;self: Node =&gt;&lt;/span&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;;&quot;&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: black;&quot;&gt;&lt;span style=&quot;&quot;&gt;    &lt;/span&gt;&lt;/span&gt;&lt;b&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: rgb(127, 127, 127);&quot;&gt;def&lt;/span&gt;&lt;/b&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: black;&quot;&gt; &lt;/span&gt;&lt;b&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: dodgerblue;&quot;&gt;connectWith&lt;/span&gt;&lt;/b&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: black;&quot;&gt;(&lt;/span&gt;&lt;b&gt;&lt;i&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: rgb(27, 27, 215);&quot;&gt;node&lt;/span&gt;&lt;/i&gt;&lt;/b&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: black;&quot;&gt;: &lt;/span&gt;&lt;b&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: rgb(139, 105, 20);&quot;&gt;Node&lt;/span&gt;&lt;/b&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: black;&quot;&gt;): &lt;/span&gt;&lt;b&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: rgb(139, 105, 20);&quot;&gt;Edge&lt;/span&gt;&lt;/b&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: black;&quot;&gt; = {&lt;/span&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;;&quot;&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: black;&quot;&gt;&lt;span style=&quot;&quot;&gt;      &lt;/span&gt;&lt;/span&gt;&lt;b&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: rgb(127, 127, 127);&quot;&gt;val&lt;/span&gt;&lt;/b&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: black;&quot;&gt; &lt;/span&gt;&lt;b&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: rgb(27, 27, 215);&quot;&gt;edge&lt;/span&gt;&lt;/b&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: black;&quot;&gt; = &lt;/span&gt;&lt;b&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: dodgerblue;&quot;&gt;newEdge&lt;/span&gt;&lt;/b&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: black;&quot;&gt;(&lt;/span&gt;&lt;b&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: rgb(127, 127, 127);&quot;&gt;this&lt;/span&gt;&lt;/b&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: black;&quot;&gt;, &lt;/span&gt;&lt;b&gt;&lt;i&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: rgb(27, 27, 215);&quot;&gt;node&lt;/span&gt;&lt;/i&gt;&lt;/b&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: black;&quot;&gt;)&lt;span style=&quot;&quot;&gt;  &lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;;&quot;&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: black;&quot;&gt;&lt;span style=&quot;&quot;&gt;      &lt;/span&gt;&lt;/span&gt;&lt;b&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: rgb(27, 27, 215);&quot;&gt;edges&lt;/span&gt;&lt;/b&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: black;&quot;&gt; = &lt;/span&gt;&lt;b&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: rgb(27, 27, 215);&quot;&gt;edges&lt;/span&gt;&lt;/b&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: black;&quot;&gt; &lt;/span&gt;&lt;b&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: dodgerblue;&quot;&gt;+&lt;/span&gt;&lt;/b&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: black;&quot;&gt; &lt;/span&gt;&lt;b&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: rgb(27, 27, 215);&quot;&gt;edge&lt;/span&gt;&lt;/b&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;;&quot;&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: black;&quot;&gt;&lt;span style=&quot;&quot;&gt;      &lt;/span&gt;&lt;/span&gt;&lt;b&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: rgb(27, 27, 215);&quot;&gt;edge&lt;/span&gt;&lt;/b&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;;&quot;&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: black;&quot;&gt;&lt;span style=&quot;&quot;&gt;    &lt;/span&gt;}&lt;/span&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;;&quot;&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: black;&quot;&gt;&lt;span style=&quot;&quot;&gt;  &lt;/span&gt;}&lt;/span&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;;&quot;&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: black;&quot;&gt;&lt;span style=&quot;&quot;&gt;  &lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;;&quot;&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: black;&quot;&gt;&lt;span style=&quot;&quot;&gt;  &lt;/span&gt;&lt;/span&gt;&lt;b&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: rgb(127, 127, 127);&quot;&gt;protected&lt;/span&gt;&lt;/b&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: black;&quot;&gt; &lt;/span&gt;&lt;b&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: rgb(127, 127, 127);&quot;&gt;def&lt;/span&gt;&lt;/b&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: black;&quot;&gt; &lt;/span&gt;&lt;b&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: dodgerblue;&quot;&gt;newNode&lt;/span&gt;&lt;/b&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: black;&quot;&gt;: &lt;/span&gt;&lt;b&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: rgb(139, 105, 20);&quot;&gt;Node&lt;/span&gt;&lt;/b&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;;&quot;&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: black;&quot;&gt;&lt;span style=&quot;&quot;&gt;  &lt;/span&gt;&lt;/span&gt;&lt;b&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: rgb(127, 127, 127);&quot;&gt;protected&lt;/span&gt;&lt;/b&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: black;&quot;&gt; &lt;/span&gt;&lt;b&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: rgb(127, 127, 127);&quot;&gt;def&lt;/span&gt;&lt;/b&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: black;&quot;&gt; &lt;/span&gt;&lt;b&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: dodgerblue;&quot;&gt;newEdge&lt;/span&gt;&lt;/b&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: black;&quot;&gt;(&lt;/span&gt;&lt;b&gt;&lt;i&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: rgb(27, 27, 215);&quot;&gt;from&lt;/span&gt;&lt;/i&gt;&lt;/b&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: black;&quot;&gt;: &lt;/span&gt;&lt;b&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: rgb(139, 105, 20);&quot;&gt;Node&lt;/span&gt;&lt;/b&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: black;&quot;&gt;, &lt;/span&gt;&lt;b&gt;&lt;i&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: rgb(27, 27, 215);&quot;&gt;to&lt;/span&gt;&lt;/i&gt;&lt;/b&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: black;&quot;&gt;: &lt;/span&gt;&lt;b&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: rgb(139, 105, 20);&quot;&gt;Node&lt;/span&gt;&lt;/b&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: black;&quot;&gt;): &lt;/span&gt;&lt;b&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: rgb(139, 105, 20);&quot;&gt;Edge&lt;/span&gt;&lt;/b&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;;&quot;&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;                  &lt;p class=&quot;MsoNormal&quot; style=&quot;&quot;&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: black;&quot;&gt;&lt;span style=&quot;&quot;&gt;  &lt;/span&gt;&lt;/span&gt;&lt;b&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: rgb(127, 127, 127);&quot;&gt;var&lt;/span&gt;&lt;/b&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: black;&quot;&gt; &lt;/span&gt;&lt;b&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: rgb(27, 27, 215);&quot;&gt;nodes&lt;/span&gt;&lt;/b&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: black;&quot;&gt;: &lt;/span&gt;&lt;b&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: brown;&quot;&gt;Set&lt;/span&gt;&lt;/b&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: black;&quot;&gt;[&lt;/span&gt;&lt;b&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: rgb(139, 105, 20);&quot;&gt;Node&lt;/span&gt;&lt;/b&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: black;&quot;&gt;] =&lt;/span&gt;&lt;b&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: rgb(27, 27, 215);&quot;&gt;Set&lt;/span&gt;&lt;/b&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: black;&quot;&gt;()&lt;/span&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;;&quot;&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: black;&quot;&gt;&lt;span style=&quot;&quot;&gt;  &lt;/span&gt;&lt;/span&gt;&lt;b&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: rgb(127, 127, 127);&quot;&gt;var&lt;/span&gt;&lt;/b&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: black;&quot;&gt; &lt;/span&gt;&lt;b&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: rgb(27, 27, 215);&quot;&gt;edges&lt;/span&gt;&lt;/b&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: black;&quot;&gt;: &lt;/span&gt;&lt;b&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: brown;&quot;&gt;Set&lt;/span&gt;&lt;/b&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: black;&quot;&gt;[&lt;/span&gt;&lt;b&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: rgb(139, 105, 20);&quot;&gt;Edge&lt;/span&gt;&lt;/b&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: black;&quot;&gt;] =&lt;/span&gt;&lt;b&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: rgb(27, 27, 215);&quot;&gt;Set&lt;/span&gt;&lt;/b&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: black;&quot;&gt;()&lt;/span&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;;&quot;&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: black;&quot;&gt;&lt;span style=&quot;&quot;&gt;  &lt;/span&gt;&lt;/span&gt;&lt;b&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: rgb(127, 127, 127);&quot;&gt;def&lt;/span&gt;&lt;/b&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: black;&quot;&gt; &lt;/span&gt;&lt;b&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: dodgerblue;&quot;&gt;addNode&lt;/span&gt;&lt;/b&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: black;&quot;&gt;: &lt;/span&gt;&lt;b&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: rgb(139, 105, 20);&quot;&gt;Node&lt;/span&gt;&lt;/b&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: black;&quot;&gt; = {&lt;/span&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;;&quot;&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: black;&quot;&gt;&lt;span style=&quot;&quot;&gt;    &lt;/span&gt;&lt;/span&gt;&lt;b&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: rgb(127, 127, 127);&quot;&gt;val&lt;/span&gt;&lt;/b&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: black;&quot;&gt; &lt;/span&gt;&lt;b&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: rgb(27, 27, 215);&quot;&gt;node&lt;/span&gt;&lt;/b&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: black;&quot;&gt; = &lt;/span&gt;&lt;b&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: dodgerblue;&quot;&gt;newNode&lt;/span&gt;&lt;/b&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;;&quot;&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: black;&quot;&gt;&lt;span style=&quot;&quot;&gt;    &lt;/span&gt;&lt;/span&gt;&lt;b&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: rgb(27, 27, 215);&quot;&gt;nodes&lt;/span&gt;&lt;/b&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: black;&quot;&gt; = &lt;/span&gt;&lt;b&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: rgb(27, 27, 215);&quot;&gt;nodes&lt;/span&gt;&lt;/b&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: black;&quot;&gt; &lt;/span&gt;&lt;b&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: dodgerblue;&quot;&gt;+&lt;/span&gt;&lt;/b&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: black;&quot;&gt; &lt;/span&gt;&lt;b&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: rgb(27, 27, 215);&quot;&gt;node&lt;/span&gt;&lt;/b&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;;&quot;&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: black;&quot;&gt;&lt;span style=&quot;&quot;&gt;    &lt;/span&gt;&lt;/span&gt;&lt;b&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: rgb(27, 27, 215);&quot;&gt;node&lt;/span&gt;&lt;/b&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;;&quot;&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: black;&quot;&gt;&lt;span style=&quot;&quot;&gt;  &lt;/span&gt;}&lt;/span&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;;&quot;&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: black;&quot;&gt;}&lt;o:p&gt;&lt;br /&gt; &lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;                                  &lt;p class=&quot;MsoNormal&quot; style=&quot;&quot;&gt;&lt;b&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: rgb(127, 127, 127);&quot;&gt;trait&lt;/span&gt;&lt;/b&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: black;&quot;&gt; &lt;/span&gt;&lt;b&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: brown;&quot;&gt;Weighted&lt;/span&gt;&lt;/b&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: black;&quot;&gt; {&lt;/span&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;;&quot;&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: black;&quot;&gt;&lt;span style=&quot;&quot;&gt;  &lt;/span&gt;&lt;/span&gt;&lt;b&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: rgb(127, 127, 127);&quot;&gt;var&lt;/span&gt;&lt;/b&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: black;&quot;&gt; &lt;/span&gt;&lt;b&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: rgb(27, 27, 215);&quot;&gt;weight&lt;/span&gt;&lt;/b&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: black;&quot;&gt;= Float.PositiveInfinity&lt;/span&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;;&quot;&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: black;&quot;&gt;}&lt;/span&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;;&quot;&gt;&lt;o:p&gt; &lt;/o:p&gt;&lt;/span&gt;&lt;br /&gt;&lt;b&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: rgb(127, 127, 127);&quot;&gt;class&lt;/span&gt;&lt;/b&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: black;&quot;&gt; &lt;/span&gt;&lt;b&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: brown;&quot;&gt;DfsGraph&lt;/span&gt;&lt;/b&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: black;&quot;&gt; &lt;/span&gt;&lt;b&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: rgb(127, 127, 127);&quot;&gt;extends&lt;/span&gt;&lt;/b&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: black;&quot;&gt;&lt;span style=&quot;&quot;&gt;  &lt;/span&gt;&lt;/span&gt;&lt;b&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: brown;&quot;&gt;DirectedGraph&lt;/span&gt;&lt;/b&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: black;&quot;&gt;&lt;span style=&quot;&quot;&gt;  &lt;/span&gt;{&lt;/span&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;;&quot;&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: black;&quot;&gt;&lt;span style=&quot;&quot;&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: black;&quot;&gt;&lt;span style=&quot;&quot;&gt;   &lt;/span&gt;&lt;/span&gt;&lt;b&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: rgb(127, 127, 127);&quot;&gt;class&lt;/span&gt;&lt;/b&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: black;&quot;&gt; &lt;/span&gt;&lt;b&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: brown;&quot;&gt;DfsNode&lt;/span&gt;&lt;/b&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: black;&quot;&gt; &lt;/span&gt;&lt;b&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: rgb(127, 127, 127);&quot;&gt;extends&lt;/span&gt;&lt;/b&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: black;&quot;&gt; &lt;/span&gt;&lt;b&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: brown;&quot;&gt;NodeImpl&lt;/span&gt;&lt;/b&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: black;&quot;&gt; &lt;/span&gt;&lt;b&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: rgb(127, 127, 127);&quot;&gt;with&lt;/span&gt;&lt;/b&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: black;&quot;&gt; &lt;/span&gt;&lt;b&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: brown;&quot;&gt;Weighted&lt;/span&gt;&lt;/b&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: black;&quot;&gt; {&lt;/span&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;;&quot;&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: black;&quot;&gt;&lt;span style=&quot;&quot;&gt;    &lt;/span&gt;&lt;/span&gt;&lt;b&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: rgb(127, 127, 127);&quot;&gt;var&lt;/span&gt;&lt;/b&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: black;&quot;&gt; &lt;/span&gt;&lt;b&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: rgb(27, 27, 215);&quot;&gt;previous&lt;/span&gt;&lt;/b&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: black;&quot;&gt;: &lt;/span&gt;&lt;b&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: brown;&quot;&gt;DfsNode&lt;/span&gt;&lt;/b&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: black;&quot;&gt; = _&lt;/span&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;;&quot;&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: black;&quot;&gt;&lt;span style=&quot;&quot;&gt;    &lt;/span&gt;&lt;/span&gt;&lt;b&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: rgb(127, 127, 127);&quot;&gt;var&lt;/span&gt;&lt;/b&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: black;&quot;&gt; &lt;/span&gt;&lt;b&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: rgb(27, 27, 215);&quot;&gt;label&lt;/span&gt;&lt;/b&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: black;&quot;&gt;:&lt;/span&gt;&lt;b&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: brown;&quot;&gt;String&lt;/span&gt;&lt;/b&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: black;&quot;&gt; = _&lt;/span&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;;&quot;&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: black;&quot;&gt;&lt;span style=&quot;&quot;&gt;    &lt;/span&gt;&lt;/span&gt;&lt;b&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: rgb(127, 127, 127);&quot;&gt;var&lt;/span&gt;&lt;/b&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: black;&quot;&gt; &lt;/span&gt;&lt;b&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: rgb(27, 27, 215);&quot;&gt;nodeEdges&lt;/span&gt;&lt;/b&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: black;&quot;&gt;: &lt;/span&gt;&lt;b&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: brown;&quot;&gt;Set&lt;/span&gt;&lt;/b&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: black;&quot;&gt;[&lt;/span&gt;&lt;b&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: rgb(139, 105, 20);&quot;&gt;Edge&lt;/span&gt;&lt;/b&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: black;&quot;&gt;] = &lt;/span&gt;&lt;b&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: rgb(27, 27, 215);&quot;&gt;Set&lt;/span&gt;&lt;/b&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: black;&quot;&gt;()&lt;/span&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;;&quot;&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: black;&quot;&gt;&lt;span style=&quot;&quot;&gt;    &lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;;&quot;&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: black;&quot;&gt;&lt;span style=&quot;&quot;&gt;    &lt;/span&gt;&lt;/span&gt;&lt;b&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: rgb(127, 127, 127);&quot;&gt;override&lt;/span&gt;&lt;/b&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: black;&quot;&gt; &lt;/span&gt;&lt;b&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: rgb(127, 127, 127);&quot;&gt;def&lt;/span&gt;&lt;/b&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: black;&quot;&gt; &lt;/span&gt;&lt;b&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: dodgerblue;&quot;&gt;connectWith&lt;/span&gt;&lt;/b&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: black;&quot;&gt;(&lt;/span&gt;&lt;b&gt;&lt;i&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: rgb(27, 27, 215);&quot;&gt;node&lt;/span&gt;&lt;/i&gt;&lt;/b&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: black;&quot;&gt;: Node): Edge = {&lt;/span&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;;&quot;&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: black;&quot;&gt;&lt;span style=&quot;&quot;&gt;      &lt;/span&gt;&lt;/span&gt;&lt;b&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: rgb(127, 127, 127);&quot;&gt;val&lt;/span&gt;&lt;/b&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: black;&quot;&gt; &lt;/span&gt;&lt;b&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: rgb(27, 27, 215);&quot;&gt;newEdge&lt;/span&gt;&lt;/b&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: black;&quot;&gt;=&lt;/span&gt;&lt;b&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: rgb(127, 127, 127);&quot;&gt;super&lt;/span&gt;&lt;/b&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: black;&quot;&gt;.&lt;/span&gt;&lt;b&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: dodgerblue;&quot;&gt;connectWith&lt;/span&gt;&lt;/b&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: black;&quot;&gt;(&lt;/span&gt;&lt;b&gt;&lt;i&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: rgb(27, 27, 215);&quot;&gt;node&lt;/span&gt;&lt;/i&gt;&lt;/b&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: black;&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;;&quot;&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: black;&quot;&gt;&lt;span style=&quot;&quot;&gt;      &lt;/span&gt;&lt;/span&gt;&lt;b&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: rgb(27, 27, 215);&quot;&gt;nodeEdges&lt;/span&gt;&lt;/b&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: black;&quot;&gt; = &lt;/span&gt;&lt;b&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: rgb(27, 27, 215);&quot;&gt;nodeEdges&lt;/span&gt;&lt;/b&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: black;&quot;&gt; &lt;/span&gt;&lt;b&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: dodgerblue;&quot;&gt;+&lt;/span&gt;&lt;/b&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: black;&quot;&gt; &lt;/span&gt;&lt;b&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: rgb(27, 27, 215);&quot;&gt;newEdge&lt;/span&gt;&lt;/b&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;;&quot;&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: black;&quot;&gt;&lt;span style=&quot;&quot;&gt;      &lt;/span&gt;&lt;/span&gt;&lt;b&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: rgb(27, 27, 215);&quot;&gt;newEdge&lt;/span&gt;&lt;/b&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;;&quot;&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: black;&quot;&gt;&lt;span style=&quot;&quot;&gt;    &lt;/span&gt;}&lt;/span&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;;&quot;&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: black;&quot;&gt;&lt;span style=&quot;&quot;&gt;    &lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;;&quot;&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;        &lt;p class=&quot;MsoNormal&quot; style=&quot;&quot;&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: black;&quot;&gt;&lt;span style=&quot;&quot;&gt;    &lt;/span&gt;&lt;/span&gt;&lt;b&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: rgb(127, 127, 127);&quot;&gt;def&lt;/span&gt;&lt;/b&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: black;&quot;&gt; &lt;/span&gt;&lt;b&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: dodgerblue;&quot;&gt;--&gt;&lt;/span&gt;&lt;/b&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: black;&quot;&gt;(&lt;/span&gt;&lt;b&gt;&lt;i&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: rgb(27, 27, 215);&quot;&gt;n2&lt;/span&gt;&lt;/i&gt;&lt;/b&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: black;&quot;&gt;:Node):&lt;/span&gt;&lt;b&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: brown;&quot;&gt;DfsEdge&lt;/span&gt;&lt;/b&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: black;&quot;&gt; =&lt;/span&gt;&lt;b&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: dodgerblue;&quot;&gt;connectWith&lt;/span&gt;&lt;/b&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: black;&quot;&gt;(&lt;/span&gt;&lt;b&gt;&lt;i&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: rgb(27, 27, 215);&quot;&gt;n2&lt;/span&gt;&lt;/i&gt;&lt;/b&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: black;&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;;&quot;&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: black;&quot;&gt;&lt;span style=&quot;&quot;&gt;    &lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;;&quot;&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: black;&quot;&gt;&lt;span style=&quot;&quot;&gt;    &lt;/span&gt;&lt;/span&gt;&lt;b&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: rgb(127, 127, 127);&quot;&gt;override&lt;/span&gt;&lt;/b&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: black;&quot;&gt; &lt;/span&gt;&lt;b&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: rgb(127, 127, 127);&quot;&gt;def&lt;/span&gt;&lt;/b&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: black;&quot;&gt; &lt;/span&gt;&lt;b&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: dodgerblue;&quot;&gt;toString&lt;/span&gt;&lt;/b&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: black;&quot;&gt;()= &lt;/span&gt;&lt;b&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: rgb(27, 27, 215);&quot;&gt;label&lt;/span&gt;&lt;/b&gt;&lt;b&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: dodgerblue;&quot;&gt;+&lt;/span&gt;&lt;/b&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: black;&quot;&gt; &lt;/span&gt;&lt;i&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: rgb(127, 127, 127);&quot;&gt;&quot; w:&quot;&lt;/span&gt;&lt;/i&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: black;&quot;&gt;+&lt;/span&gt;&lt;b&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: rgb(27, 27, 215);&quot;&gt;weight&lt;/span&gt;&lt;/b&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;;&quot;&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: black;&quot;&gt;&lt;span style=&quot;&quot;&gt;  &lt;/span&gt;}&lt;/span&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;;&quot;&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;                            &lt;p class=&quot;MsoNormal&quot; style=&quot;&quot;&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: black;&quot;&gt;&lt;span style=&quot;&quot;&gt;  &lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: black;&quot;&gt;&lt;span style=&quot;&quot;&gt;&lt;/span&gt;&lt;/span&gt;&lt;b&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: rgb(127, 127, 127);&quot;&gt;class&lt;/span&gt;&lt;/b&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: black;&quot;&gt; &lt;/span&gt;&lt;b&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: brown;&quot;&gt;DfsEdge&lt;/span&gt;&lt;/b&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: black;&quot;&gt;(&lt;/span&gt;&lt;b&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: rgb(27, 27, 215);&quot;&gt;origin&lt;/span&gt;&lt;/b&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: black;&quot;&gt;:Node, &lt;/span&gt;&lt;b&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: rgb(27, 27, 215);&quot;&gt;dest&lt;/span&gt;&lt;/b&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: black;&quot;&gt;:Node) &lt;/span&gt;&lt;b&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: rgb(127, 127, 127);&quot;&gt;extends&lt;/span&gt;&lt;/b&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: black;&quot;&gt; &lt;/span&gt;&lt;b&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: brown;&quot;&gt;EdgeImpl&lt;/span&gt;&lt;/b&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: black;&quot;&gt;(&lt;/span&gt;&lt;b&gt;&lt;i&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: rgb(27, 27, 215);&quot;&gt;origin&lt;/span&gt;&lt;/i&gt;&lt;/b&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: black;&quot;&gt;, &lt;/span&gt;&lt;b&gt;&lt;i&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: rgb(27, 27, 215);&quot;&gt;dest&lt;/span&gt;&lt;/i&gt;&lt;/b&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: black;&quot;&gt;) &lt;/span&gt;&lt;b&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: rgb(127, 127, 127);&quot;&gt;with&lt;/span&gt;&lt;/b&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: black;&quot;&gt; &lt;/span&gt;&lt;b&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: brown;&quot;&gt;Weighted&lt;/span&gt;&lt;/b&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: black;&quot;&gt; {&lt;/span&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;;&quot;&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: black;&quot;&gt;&lt;span style=&quot;&quot;&gt;    &lt;/span&gt;&lt;/span&gt;&lt;b&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: rgb(127, 127, 127);&quot;&gt;override&lt;/span&gt;&lt;/b&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: black;&quot;&gt; &lt;/span&gt;&lt;b&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: rgb(127, 127, 127);&quot;&gt;def&lt;/span&gt;&lt;/b&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: black;&quot;&gt; &lt;/span&gt;&lt;b&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: dodgerblue;&quot;&gt;toString&lt;/span&gt;&lt;/b&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: black;&quot;&gt;()= &lt;/span&gt;&lt;b&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: dodgerblue;&quot;&gt;from&lt;/span&gt;&lt;/b&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: black;&quot;&gt;.&lt;/span&gt;&lt;b&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: rgb(27, 27, 215);&quot;&gt;label&lt;/span&gt;&lt;/b&gt;&lt;b&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: dodgerblue;&quot;&gt;+&lt;/span&gt;&lt;/b&gt;&lt;i&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: rgb(127, 127, 127);&quot;&gt;&quot;--&gt;&quot;&lt;/span&gt;&lt;/i&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: black;&quot;&gt;+&lt;/span&gt;&lt;b&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: dodgerblue;&quot;&gt;to&lt;/span&gt;&lt;/b&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: black;&quot;&gt;.&lt;/span&gt;&lt;b&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: rgb(27, 27, 215);&quot;&gt;label&lt;/span&gt;&lt;/b&gt;&lt;b&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: dodgerblue;&quot;&gt;+&lt;/span&gt;&lt;/b&gt;&lt;i&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: rgb(127, 127, 127);&quot;&gt;&quot; w:&quot;&lt;/span&gt;&lt;/i&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: black;&quot;&gt;+&lt;/span&gt;&lt;b&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: rgb(27, 27, 215);&quot;&gt;weight&lt;/span&gt;&lt;/b&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;;&quot;&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: black;&quot;&gt;&lt;span style=&quot;&quot;&gt;  &lt;/span&gt;}&lt;/span&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;;&quot;&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: black;&quot;&gt;&lt;span style=&quot;&quot;&gt;  &lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;;&quot;&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: black;&quot;&gt;&lt;span style=&quot;&quot;&gt;  &lt;/span&gt;&lt;/span&gt;&lt;b&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: rgb(127, 127, 127);&quot;&gt;def&lt;/span&gt;&lt;/b&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: black;&quot;&gt; &lt;/span&gt;&lt;b&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: dodgerblue;&quot;&gt;addNewNode&lt;/span&gt;&lt;/b&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: black;&quot;&gt;(&lt;/span&gt;&lt;b&gt;&lt;i&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: rgb(27, 27, 215);&quot;&gt;l&lt;/span&gt;&lt;/i&gt;&lt;/b&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: black;&quot;&gt;:&lt;/span&gt;&lt;b&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: brown;&quot;&gt;String&lt;/span&gt;&lt;/b&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: black;&quot;&gt;):Node={&lt;/span&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;;&quot;&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: black;&quot;&gt;&lt;span style=&quot;&quot;&gt;    &lt;/span&gt;&lt;/span&gt;&lt;b&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: rgb(127, 127, 127);&quot;&gt;val&lt;/span&gt;&lt;/b&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: black;&quot;&gt; &lt;/span&gt;&lt;b&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: rgb(27, 27, 215);&quot;&gt;newNode&lt;/span&gt;&lt;/b&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: black;&quot;&gt;=&lt;/span&gt;&lt;b&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: rgb(127, 127, 127);&quot;&gt;super&lt;/span&gt;&lt;/b&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: black;&quot;&gt;.&lt;/span&gt;&lt;b&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: dodgerblue;&quot;&gt;addNode&lt;/span&gt;&lt;/b&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;;&quot;&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: black;&quot;&gt;&lt;span style=&quot;&quot;&gt;    &lt;/span&gt;&lt;/span&gt;&lt;b&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: rgb(27, 27, 215);&quot;&gt;newNode&lt;/span&gt;&lt;/b&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: black;&quot;&gt;.&lt;/span&gt;&lt;b&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: rgb(27, 27, 215);&quot;&gt;label&lt;/span&gt;&lt;/b&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: black;&quot;&gt;=&lt;/span&gt;&lt;b&gt;&lt;i&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: rgb(27, 27, 215);&quot;&gt;l&lt;/span&gt;&lt;/i&gt;&lt;/b&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;;&quot;&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: black;&quot;&gt;&lt;span style=&quot;&quot;&gt;    &lt;/span&gt;&lt;/span&gt;&lt;b&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: rgb(27, 27, 215);&quot;&gt;newNode&lt;/span&gt;&lt;/b&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;;&quot;&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: black;&quot;&gt;&lt;span style=&quot;&quot;&gt;  &lt;/span&gt;}&lt;/span&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;;&quot;&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: black;&quot;&gt;&lt;span style=&quot;&quot;&gt;  &lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;;&quot;&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: black;&quot;&gt;&lt;span style=&quot;&quot;&gt;  &lt;/span&gt;&lt;/span&gt;&lt;b&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: rgb(127, 127, 127);&quot;&gt;type&lt;/span&gt;&lt;/b&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: black;&quot;&gt; &lt;/span&gt;&lt;b&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: rgb(139, 105, 20);&quot;&gt;Node&lt;/span&gt;&lt;/b&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: black;&quot;&gt;= &lt;/span&gt;&lt;b&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: brown;&quot;&gt;DfsNode&lt;/span&gt;&lt;/b&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;;&quot;&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: black;&quot;&gt;&lt;span style=&quot;&quot;&gt;  &lt;/span&gt;&lt;/span&gt;&lt;b&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: rgb(127, 127, 127);&quot;&gt;type&lt;/span&gt;&lt;/b&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: black;&quot;&gt; &lt;/span&gt;&lt;b&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: rgb(139, 105, 20);&quot;&gt;Edge&lt;/span&gt;&lt;/b&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: black;&quot;&gt;= &lt;/span&gt;&lt;b&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: brown;&quot;&gt;DfsEdge&lt;/span&gt;&lt;/b&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;;&quot;&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: black;&quot;&gt;&lt;span style=&quot;&quot;&gt;  &lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;;&quot;&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;                        &lt;p class=&quot;MsoNormal&quot; style=&quot;&quot;&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: black;&quot;&gt;&lt;span style=&quot;&quot;&gt;  &lt;/span&gt;&lt;/span&gt;&lt;b&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: rgb(127, 127, 127);&quot;&gt;protected&lt;/span&gt;&lt;/b&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: black;&quot;&gt; &lt;/span&gt;&lt;b&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: rgb(127, 127, 127);&quot;&gt;def&lt;/span&gt;&lt;/b&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: black;&quot;&gt; &lt;/span&gt;&lt;b&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: dodgerblue;&quot;&gt;newEdge&lt;/span&gt;&lt;/b&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: black;&quot;&gt;(&lt;/span&gt;&lt;b&gt;&lt;i&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: rgb(27, 27, 215);&quot;&gt;from&lt;/span&gt;&lt;/i&gt;&lt;/b&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: black;&quot;&gt;: Node, &lt;/span&gt;&lt;b&gt;&lt;i&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: rgb(27, 27, 215);&quot;&gt;to&lt;/span&gt;&lt;/i&gt;&lt;/b&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: black;&quot;&gt;: Node): Edge =&lt;span style=&quot;&quot;&gt;  &lt;/span&gt;&lt;/span&gt;&lt;b&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: rgb(127, 127, 127);&quot;&gt;new&lt;/span&gt;&lt;/b&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: black;&quot;&gt; &lt;/span&gt;&lt;b&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: brown;&quot;&gt;DfsEdge&lt;/span&gt;&lt;/b&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: black;&quot;&gt;(&lt;/span&gt;&lt;b&gt;&lt;i&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: rgb(27, 27, 215);&quot;&gt;from&lt;/span&gt;&lt;/i&gt;&lt;/b&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: black;&quot;&gt;,&lt;/span&gt;&lt;b&gt;&lt;i&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: rgb(27, 27, 215);&quot;&gt;to&lt;/span&gt;&lt;/i&gt;&lt;/b&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: black;&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;;&quot;&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: black;&quot;&gt;&lt;span style=&quot;&quot;&gt;  &lt;/span&gt;&lt;/span&gt;&lt;b&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: rgb(127, 127, 127);&quot;&gt;protected&lt;/span&gt;&lt;/b&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: black;&quot;&gt; &lt;/span&gt;&lt;b&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: rgb(127, 127, 127);&quot;&gt;def&lt;/span&gt;&lt;/b&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: black;&quot;&gt; &lt;/span&gt;&lt;b&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: dodgerblue;&quot;&gt;newNode&lt;/span&gt;&lt;/b&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: black;&quot;&gt;: Node = &lt;/span&gt;&lt;b&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: rgb(127, 127, 127);&quot;&gt;new&lt;/span&gt;&lt;/b&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: black;&quot;&gt; &lt;/span&gt;&lt;b&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: brown;&quot;&gt;DfsNode&lt;/span&gt;&lt;/b&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;;&quot;&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: black;&quot;&gt;&lt;span style=&quot;&quot;&gt;  &lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;;&quot;&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: black;&quot;&gt;&lt;span style=&quot;&quot;&gt;  &lt;/span&gt;&lt;/span&gt;&lt;b&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: rgb(127, 127, 127);&quot;&gt;def&lt;/span&gt;&lt;/b&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: black;&quot;&gt; &lt;/span&gt;&lt;b&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: dodgerblue;&quot;&gt;shortestPath&lt;/span&gt;&lt;/b&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: black;&quot;&gt;(&lt;/span&gt;&lt;b&gt;&lt;i&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: rgb(27, 27, 215);&quot;&gt;start&lt;/span&gt;&lt;/i&gt;&lt;/b&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: black;&quot;&gt;: &lt;/span&gt;&lt;b&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: brown;&quot;&gt;DfsNode&lt;/span&gt;&lt;/b&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: black;&quot;&gt;, &lt;/span&gt;&lt;b&gt;&lt;i&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: rgb(27, 27, 215);&quot;&gt;end&lt;/span&gt;&lt;/i&gt;&lt;/b&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: black;&quot;&gt;: &lt;/span&gt;&lt;b&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: brown;&quot;&gt;DfsNode&lt;/span&gt;&lt;/b&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: black;&quot;&gt;) = {&lt;/span&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;;&quot;&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: black;&quot;&gt;&lt;span style=&quot;&quot;&gt;    &lt;/span&gt;&lt;/span&gt;&lt;b&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: rgb(127, 127, 127);&quot;&gt;var&lt;/span&gt;&lt;/b&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: black;&quot;&gt; &lt;/span&gt;&lt;b&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: rgb(27, 27, 215);&quot;&gt;unvisited&lt;/span&gt;&lt;/b&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: black;&quot;&gt;=&lt;/span&gt;&lt;b&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: rgb(27, 27, 215);&quot;&gt;nodes&lt;/span&gt;&lt;/b&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;;&quot;&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: black;&quot;&gt;&lt;span style=&quot;&quot;&gt;    &lt;/span&gt;&lt;/span&gt;&lt;b&gt;&lt;i&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: rgb(27, 27, 215);&quot;&gt;start&lt;/span&gt;&lt;/i&gt;&lt;/b&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: black;&quot;&gt;.&lt;/span&gt;&lt;b&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: rgb(27, 27, 215);&quot;&gt;weight&lt;/span&gt;&lt;/b&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: black;&quot;&gt;=0&lt;/span&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;;&quot;&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: black;&quot;&gt;&lt;span style=&quot;&quot;&gt;    &lt;/span&gt;&lt;/span&gt;&lt;b&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: rgb(127, 127, 127);&quot;&gt;while&lt;/span&gt;&lt;/b&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: black;&quot;&gt; (!&lt;/span&gt;&lt;b&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: rgb(27, 27, 215);&quot;&gt;unvisited&lt;/span&gt;&lt;/b&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: black;&quot;&gt;.&lt;/span&gt;&lt;b&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: dodgerblue;&quot;&gt;isEmpty&lt;/span&gt;&lt;/b&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: black;&quot;&gt;)&lt;span style=&quot;&quot;&gt;  &lt;/span&gt;{ &lt;/span&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;;&quot;&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: black;&quot;&gt;&lt;span style=&quot;&quot;&gt;      &lt;/span&gt;&lt;/span&gt;&lt;b&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: rgb(127, 127, 127);&quot;&gt;val&lt;/span&gt;&lt;/b&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: black;&quot;&gt; &lt;/span&gt;&lt;b&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: rgb(27, 27, 215);&quot;&gt;vertx&lt;/span&gt;&lt;/b&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: black;&quot;&gt;=&lt;/span&gt;&lt;b&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: dodgerblue;&quot;&gt;min&lt;/span&gt;&lt;/b&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: black;&quot;&gt;(&lt;/span&gt;&lt;b&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: rgb(27, 27, 215);&quot;&gt;unvisited&lt;/span&gt;&lt;/b&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: black;&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;;&quot;&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: black;&quot;&gt;&lt;span style=&quot;&quot;&gt;      &lt;/span&gt;&lt;/span&gt;&lt;b&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: rgb(27, 27, 215);&quot;&gt;vertx&lt;/span&gt;&lt;/b&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: black;&quot;&gt;.&lt;/span&gt;&lt;b&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: rgb(27, 27, 215);&quot;&gt;nodeEdges&lt;/span&gt;&lt;/b&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: black;&quot;&gt;.&lt;/span&gt;&lt;b&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: dodgerblue;&quot;&gt;map&lt;/span&gt;&lt;/b&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: black;&quot;&gt;(&lt;/span&gt;&lt;b&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: dodgerblue;&quot;&gt;improveDistance&lt;/span&gt;&lt;/b&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: black;&quot;&gt;(_))&lt;/span&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;;&quot;&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: black;&quot;&gt;&lt;span style=&quot;&quot;&gt;      &lt;/span&gt;&lt;/span&gt;&lt;b&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: rgb(27, 27, 215);&quot;&gt;unvisited&lt;/span&gt;&lt;/b&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: black;&quot;&gt;=&lt;/span&gt;&lt;b&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: rgb(27, 27, 215);&quot;&gt;unvisited&lt;/span&gt;&lt;/b&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: black;&quot;&gt;-&lt;/span&gt;&lt;b&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: rgb(27, 27, 215);&quot;&gt;vertx&lt;/span&gt;&lt;/b&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;;&quot;&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: black;&quot;&gt;&lt;span style=&quot;&quot;&gt;    &lt;/span&gt;}&lt;/span&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;;&quot;&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: black;&quot;&gt;&lt;span style=&quot;&quot;&gt;  &lt;/span&gt;}&lt;/span&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;;&quot;&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;                                        &lt;p class=&quot;MsoNormal&quot; style=&quot;&quot;&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: black;&quot;&gt;&lt;span style=&quot;&quot;&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: black;&quot;&gt;&lt;span style=&quot;&quot;&gt;  &lt;/span&gt;&lt;/span&gt;&lt;b&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: rgb(127, 127, 127);&quot;&gt;def&lt;/span&gt;&lt;/b&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: black;&quot;&gt; &lt;/span&gt;&lt;b&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: dodgerblue;&quot;&gt;improveDistance&lt;/span&gt;&lt;/b&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: black;&quot;&gt;(&lt;/span&gt;&lt;b&gt;&lt;i&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: rgb(27, 27, 215);&quot;&gt;a&lt;/span&gt;&lt;/i&gt;&lt;/b&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: black;&quot;&gt;:Edge) ={&lt;/span&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;;&quot;&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: black;&quot;&gt;&lt;span style=&quot;&quot;&gt;    &lt;/span&gt;&lt;/span&gt;&lt;b&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: rgb(127, 127, 127);&quot;&gt;if&lt;/span&gt;&lt;/b&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: black;&quot;&gt; (&lt;/span&gt;&lt;b&gt;&lt;i&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: rgb(27, 27, 215);&quot;&gt;a&lt;/span&gt;&lt;/i&gt;&lt;/b&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: black;&quot;&gt;.&lt;/span&gt;&lt;b&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: dodgerblue;&quot;&gt;from&lt;/span&gt;&lt;/b&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: black;&quot;&gt;.&lt;/span&gt;&lt;b&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: rgb(27, 27, 215);&quot;&gt;weight&lt;/span&gt;&lt;/b&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: black;&quot;&gt;+&lt;/span&gt;&lt;b&gt;&lt;i&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: rgb(27, 27, 215);&quot;&gt;a&lt;/span&gt;&lt;/i&gt;&lt;/b&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: black;&quot;&gt;.&lt;/span&gt;&lt;b&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: rgb(27, 27, 215);&quot;&gt;weight&lt;/span&gt;&lt;/b&gt;&lt;b&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: dodgerblue;&quot;&gt;&lt;&lt;/span&gt;&lt;/b&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: black;&quot;&gt; &lt;/span&gt;&lt;b&gt;&lt;i&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: rgb(27, 27, 215);&quot;&gt;a&lt;/span&gt;&lt;/i&gt;&lt;/b&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: black;&quot;&gt;.&lt;/span&gt;&lt;b&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: dodgerblue;&quot;&gt;to&lt;/span&gt;&lt;/b&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: black;&quot;&gt;.&lt;/span&gt;&lt;b&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: rgb(27, 27, 215);&quot;&gt;weight&lt;/span&gt;&lt;/b&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: black;&quot;&gt;) {&lt;/span&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;;&quot;&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: black;&quot;&gt;&lt;span style=&quot;&quot;&gt;      &lt;/span&gt;&lt;/span&gt;&lt;b&gt;&lt;i&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: rgb(27, 27, 215);&quot;&gt;a&lt;/span&gt;&lt;/i&gt;&lt;/b&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: black;&quot;&gt;.&lt;/span&gt;&lt;b&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: dodgerblue;&quot;&gt;to&lt;/span&gt;&lt;/b&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: black;&quot;&gt;.&lt;/span&gt;&lt;b&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: rgb(27, 27, 215);&quot;&gt;weight&lt;/span&gt;&lt;/b&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: black;&quot;&gt;=&lt;/span&gt;&lt;b&gt;&lt;i&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: rgb(27, 27, 215);&quot;&gt;a&lt;/span&gt;&lt;/i&gt;&lt;/b&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: black;&quot;&gt;.&lt;/span&gt;&lt;b&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: dodgerblue;&quot;&gt;from&lt;/span&gt;&lt;/b&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: black;&quot;&gt;.&lt;/span&gt;&lt;b&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: rgb(27, 27, 215);&quot;&gt;weight&lt;/span&gt;&lt;/b&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: black;&quot;&gt;+&lt;/span&gt;&lt;b&gt;&lt;i&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: rgb(27, 27, 215);&quot;&gt;a&lt;/span&gt;&lt;/i&gt;&lt;/b&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: black;&quot;&gt;.&lt;/span&gt;&lt;b&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: rgb(27, 27, 215);&quot;&gt;weight&lt;/span&gt;&lt;/b&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;;&quot;&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: black;&quot;&gt;&lt;span style=&quot;&quot;&gt;      &lt;/span&gt;&lt;/span&gt;&lt;b&gt;&lt;i&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: rgb(27, 27, 215);&quot;&gt;a&lt;/span&gt;&lt;/i&gt;&lt;/b&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: black;&quot;&gt;.&lt;/span&gt;&lt;b&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: dodgerblue;&quot;&gt;to&lt;/span&gt;&lt;/b&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: black;&quot;&gt;.&lt;/span&gt;&lt;b&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: rgb(27, 27, 215);&quot;&gt;previous&lt;/span&gt;&lt;/b&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: black;&quot;&gt;=&lt;/span&gt;&lt;b&gt;&lt;i&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: rgb(27, 27, 215);&quot;&gt;a&lt;/span&gt;&lt;/i&gt;&lt;/b&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: black;&quot;&gt;.&lt;/span&gt;&lt;b&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: dodgerblue;&quot;&gt;from&lt;/span&gt;&lt;/b&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;;&quot;&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: black;&quot;&gt;&lt;span style=&quot;&quot;&gt;    &lt;/span&gt;}&lt;/span&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;;&quot;&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: black;&quot;&gt;&lt;span style=&quot;&quot;&gt;  &lt;/span&gt;}&lt;/span&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;;&quot;&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: black;&quot;&gt;&lt;span style=&quot;&quot;&gt;  &lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;;&quot;&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: black;&quot;&gt;&lt;span style=&quot;&quot;&gt;  &lt;/span&gt;&lt;/span&gt;&lt;b&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: rgb(127, 127, 127);&quot;&gt;def&lt;/span&gt;&lt;/b&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: black;&quot;&gt; &lt;/span&gt;&lt;b&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: dodgerblue;&quot;&gt;min&lt;/span&gt;&lt;/b&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: black;&quot;&gt;(&lt;/span&gt;&lt;b&gt;&lt;i&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: rgb(27, 27, 215);&quot;&gt;nodes&lt;/span&gt;&lt;/i&gt;&lt;/b&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: black;&quot;&gt;: &lt;/span&gt;&lt;b&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: brown;&quot;&gt;Set&lt;/span&gt;&lt;/b&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: black;&quot;&gt;[&lt;/span&gt;&lt;b&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: brown;&quot;&gt;DfsNode&lt;/span&gt;&lt;/b&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: black;&quot;&gt;]): &lt;/span&gt;&lt;b&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: brown;&quot;&gt;DfsNode&lt;/span&gt;&lt;/b&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: black;&quot;&gt; = {&lt;/span&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;;&quot;&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: black;&quot;&gt;&lt;span style=&quot;&quot;&gt;    &lt;/span&gt;&lt;/span&gt;&lt;b&gt;&lt;i&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: rgb(27, 27, 215);&quot;&gt;nodes&lt;/span&gt;&lt;/i&gt;&lt;/b&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: black;&quot;&gt;.&lt;/span&gt;&lt;b&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: dodgerblue;&quot;&gt;reduceLeft&lt;/span&gt;&lt;/b&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: black;&quot;&gt;((&lt;/span&gt;&lt;b&gt;&lt;i&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: rgb(27, 27, 215);&quot;&gt;a&lt;/span&gt;&lt;/i&gt;&lt;/b&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: black;&quot;&gt;:&lt;/span&gt;&lt;b&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: brown;&quot;&gt;DfsNode&lt;/span&gt;&lt;/b&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: black;&quot;&gt;,&lt;/span&gt;&lt;b&gt;&lt;i&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: rgb(27, 27, 215);&quot;&gt;b&lt;/span&gt;&lt;/i&gt;&lt;/b&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: black;&quot;&gt;:&lt;/span&gt;&lt;b&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: brown;&quot;&gt;DfsNode&lt;/span&gt;&lt;/b&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: black;&quot;&gt;)=&gt;&lt;/span&gt;&lt;b&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: rgb(127, 127, 127);&quot;&gt;if&lt;/span&gt;&lt;/b&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: black;&quot;&gt; (&lt;/span&gt;&lt;b&gt;&lt;i&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: rgb(27, 27, 215);&quot;&gt;a&lt;/span&gt;&lt;/i&gt;&lt;/b&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: black;&quot;&gt;.&lt;/span&gt;&lt;b&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: rgb(27, 27, 215);&quot;&gt;weight&lt;/span&gt;&lt;/b&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: black;&quot;&gt;&lt;&lt;/span&gt;&lt;b&gt;&lt;i&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: rgb(27, 27, 215);&quot;&gt;b&lt;/span&gt;&lt;/i&gt;&lt;/b&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: black;&quot;&gt;.&lt;/span&gt;&lt;b&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: rgb(27, 27, 215);&quot;&gt;weight&lt;/span&gt;&lt;/b&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: black;&quot;&gt;) &lt;/span&gt;&lt;b&gt;&lt;i&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: rgb(27, 27, 215);&quot;&gt;a&lt;/span&gt;&lt;/i&gt;&lt;/b&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: black;&quot;&gt; &lt;/span&gt;&lt;b&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: rgb(127, 127, 127);&quot;&gt;else&lt;/span&gt;&lt;/b&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: black;&quot;&gt; &lt;/span&gt;&lt;b&gt;&lt;i&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: rgb(27, 27, 215);&quot;&gt;b&lt;/span&gt;&lt;/i&gt;&lt;/b&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: black;&quot;&gt; )&lt;/span&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;;&quot;&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: black;&quot;&gt;&lt;span style=&quot;&quot;&gt;  &lt;/span&gt;}&lt;/span&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;;&quot;&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: black;&quot;&gt;&lt;span style=&quot;&quot;&gt;  &lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;;&quot;&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: black;&quot;&gt;&lt;span style=&quot;&quot;&gt;  &lt;/span&gt;&lt;/span&gt;&lt;b&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: rgb(127, 127, 127);&quot;&gt;def&lt;/span&gt;&lt;/b&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: black;&quot;&gt; &lt;/span&gt;&lt;b&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: dodgerblue;&quot;&gt;pathToStart&lt;/span&gt;&lt;/b&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: black;&quot;&gt;(&lt;/span&gt;&lt;b&gt;&lt;i&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: rgb(27, 27, 215);&quot;&gt;end&lt;/span&gt;&lt;/i&gt;&lt;/b&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: black;&quot;&gt;:&lt;/span&gt;&lt;b&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: brown;&quot;&gt;DfsNode&lt;/span&gt;&lt;/b&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: black;&quot;&gt;):&lt;/span&gt;&lt;b&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: brown;&quot;&gt;List&lt;/span&gt;&lt;/b&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: black;&quot;&gt;[&lt;/span&gt;&lt;b&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: brown;&quot;&gt;DfsNode&lt;/span&gt;&lt;/b&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: black;&quot;&gt;] = {&lt;/span&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;;&quot;&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: black;&quot;&gt;&lt;span style=&quot;&quot;&gt;    &lt;/span&gt;&lt;/span&gt;&lt;b&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: rgb(127, 127, 127);&quot;&gt;if&lt;/span&gt;&lt;/b&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: black;&quot;&gt; (&lt;/span&gt;&lt;b&gt;&lt;i&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: rgb(27, 27, 215);&quot;&gt;end&lt;/span&gt;&lt;/i&gt;&lt;/b&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: black;&quot;&gt; &lt;/span&gt;&lt;b&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: dodgerblue;&quot;&gt;==&lt;/span&gt;&lt;/b&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: black;&quot;&gt; &lt;/span&gt;&lt;b&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: rgb(127, 127, 127);&quot;&gt;null&lt;/span&gt;&lt;/b&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: black;&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;;&quot;&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: black;&quot;&gt;&lt;span style=&quot;&quot;&gt;      &lt;/span&gt;&lt;/span&gt;&lt;b&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: brown;&quot;&gt;Nil&lt;/span&gt;&lt;/b&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;;&quot;&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: black;&quot;&gt;&lt;span style=&quot;&quot;&gt;    &lt;/span&gt;&lt;/span&gt;&lt;b&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: rgb(127, 127, 127);&quot;&gt;else&lt;/span&gt;&lt;/b&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: black;&quot;&gt; &lt;/span&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;;&quot;&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: black;&quot;&gt;&lt;span style=&quot;&quot;&gt;      &lt;/span&gt;&lt;/span&gt;&lt;b&gt;&lt;i&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: rgb(27, 27, 215);&quot;&gt;end&lt;/span&gt;&lt;/i&gt;&lt;/b&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: black;&quot;&gt; &lt;/span&gt;&lt;b&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: dodgerblue;&quot;&gt;::&lt;/span&gt;&lt;/b&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: black;&quot;&gt; &lt;/span&gt;&lt;b&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: dodgerblue;&quot;&gt;pathToStart&lt;/span&gt;&lt;/b&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: black;&quot;&gt;(&lt;/span&gt;&lt;b&gt;&lt;i&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: rgb(27, 27, 215);&quot;&gt;end&lt;/span&gt;&lt;/i&gt;&lt;/b&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: black;&quot;&gt;.&lt;/span&gt;&lt;b&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: rgb(27, 27, 215);&quot;&gt;previous&lt;/span&gt;&lt;/b&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: black;&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;;&quot;&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: black;&quot;&gt;&lt;span style=&quot;&quot;&gt;  &lt;/span&gt;}&lt;/span&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;;&quot;&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: black;&quot;&gt;&lt;span style=&quot;&quot;&gt;  &lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;;&quot;&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;font-size: 10pt; font-family: &amp;quot;Courier New&amp;quot;; color: black;&quot;&gt;}&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;</description><link>http://gabrielsw.blogspot.com/2008/02/playing-with-scala-4-abstract-types-and.html</link><author>noreply@blogger.com (Anonymous)</author><thr:total>14</thr:total></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-6893032696317132921.post-6580712106124452073</guid><pubDate>Wed, 23 Jan 2008 05:25:00 +0000</pubDate><atom:updated>2008-01-23T00:39:02.337-05:00</atom:updated><category domain="http://www.blogger.com/atom/ns#">code</category><category domain="http://www.blogger.com/atom/ns#">functional programming</category><category domain="http://www.blogger.com/atom/ns#">Java</category><category domain="http://www.blogger.com/atom/ns#">OO</category><category domain="http://www.blogger.com/atom/ns#">Scala</category><title>Playing with Scala 3: OO, Traits, and Views</title><description>&lt;div class=&quot;Section1&quot;&gt;&lt;span style=&quot;font-weight: bold;font-size:100%;&quot; &gt;&lt;span style=&quot;font-size: 10pt; font-family: Arial;&quot;&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;font-size: 10pt; font-family: Arial;&quot;&gt;&lt;span style=&quot;font-weight: bold;font-size:100%;&quot; &gt;OO&lt;/span&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt; &lt;p class=&quot;MsoNormal&quot; style=&quot;&quot;&gt;&lt;span style=&quot;font-size: 10pt; font-family: Arial;&quot;&gt;Look at graph classes my &lt;a href=&quot;http://gabrielsw.blogspot.com/2008/01/playing-with-scala-2-dijkstras-shortest.html&quot;&gt;previous  post&lt;/a&gt;:&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;       &lt;p class=&quot;MsoNormal&quot; style=&quot;&quot;&gt;&lt;span class=&quot;GramE&quot;&gt;&lt;b&gt;&lt;span style=&quot;font-size: 10pt; color: rgb(127, 127, 127); font-family: &#39;Courier New&#39;;&quot;&gt;class&lt;/span&gt;&lt;/b&gt;&lt;/span&gt;&lt;span style=&quot;font-size: 10pt; color: black; font-family: &#39;Courier New&#39;;&quot;&gt;  &lt;/span&gt;&lt;b&gt;&lt;span style=&quot;font-size: 10pt; color: brown; font-family: &#39;Courier New&#39;;&quot;&gt;Node&lt;/span&gt;&lt;/b&gt;&lt;span style=&quot;font-size: 10pt; color: black; font-family: &#39;Courier New&#39;;&quot;&gt; (&lt;/span&gt;&lt;span class=&quot;SpellE&quot;&gt;&lt;b&gt;&lt;span style=&quot;font-size: 10pt; color: rgb(127, 127, 127); font-family: &#39;Courier New&#39;;&quot;&gt;val&lt;/span&gt;&lt;/b&gt;&lt;/span&gt;&lt;span style=&quot;font-size: 10pt; color: black; font-family: &#39;Courier New&#39;;&quot;&gt; &lt;/span&gt;&lt;span class=&quot;SpellE&quot;&gt;&lt;b&gt;&lt;span style=&quot;font-size: 10pt; color: rgb(27, 27, 215); font-family: &#39;Courier New&#39;;&quot;&gt;label&lt;/span&gt;&lt;/b&gt;&lt;span style=&quot;font-size: 10pt; color: black; font-family: &#39;Courier New&#39;;&quot;&gt;:&lt;/span&gt;&lt;b&gt;&lt;span style=&quot;font-size: 10pt; color: brown; font-family: &#39;Courier New&#39;;&quot;&gt;String&lt;/span&gt;&lt;/b&gt;&lt;/span&gt;&lt;span style=&quot;font-size: 10pt; color: black; font-family: &#39;Courier New&#39;;&quot;&gt;)&lt;span style=&quot;&quot;&gt;  &lt;/span&gt;{&lt;/span&gt;&lt;span style=&quot;font-size: 10pt; font-family: &#39;Courier New&#39;;&quot;&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;font-size: 10pt; color: black; font-family: &#39;Courier New&#39;;&quot;&gt;&lt;span style=&quot;&quot;&gt;&lt;span style=&quot;font-weight: bold;&quot;&gt;  &lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;SpellE&quot;&gt;&lt;span class=&quot;GramE&quot;&gt;&lt;b&gt;&lt;span style=&quot;font-size: 10pt; color: rgb(127, 127, 127); font-family: &#39;Courier New&#39;;&quot;&gt;var&lt;/span&gt;&lt;/b&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;font-size: 10pt; color: black; font-family: &#39;Courier New&#39;;&quot;&gt;  &lt;/span&gt;&lt;b&gt;&lt;span style=&quot;font-size: 10pt; color: rgb(27, 27, 215); font-family: &#39;Courier New&#39;;&quot;&gt;transitions&lt;/span&gt;&lt;/b&gt;&lt;span style=&quot;font-size: 10pt; color: black; font-family: &#39;Courier New&#39;;&quot;&gt;:  &lt;/span&gt;&lt;b&gt;&lt;span style=&quot;font-size: 10pt; color: brown; font-family: &#39;Courier New&#39;;&quot;&gt;List&lt;/span&gt;&lt;/b&gt;&lt;span style=&quot;font-size: 10pt; color: black; font-family: &#39;Courier New&#39;;&quot;&gt;[&lt;/span&gt;&lt;b&gt;&lt;span style=&quot;font-size: 10pt; color: brown; font-family: &#39;Courier New&#39;;&quot;&gt;Arc&lt;/span&gt;&lt;/b&gt;&lt;span style=&quot;font-size: 10pt; color: black; font-family: &#39;Courier New&#39;;&quot;&gt;] =  &lt;/span&gt;&lt;b&gt;&lt;span style=&quot;font-size: 10pt; color: brown; font-family: &#39;Courier New&#39;;&quot;&gt;Nil&lt;/span&gt;&lt;/b&gt;&lt;span style=&quot;font-size: 10pt; font-family: &#39;Courier New&#39;;&quot;&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;font-size: 10pt; color: black; font-family: &#39;Courier New&#39;;&quot;&gt;&lt;span style=&quot;&quot;&gt;&lt;span style=&quot;font-weight: bold;&quot;&gt;  &lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;SpellE&quot;&gt;&lt;span class=&quot;GramE&quot;&gt;&lt;b&gt;&lt;span style=&quot;font-size: 10pt; color: rgb(127, 127, 127); font-family: &#39;Courier New&#39;;&quot;&gt;&lt;/span&gt;&lt;/b&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;SpellE&quot;&gt;&lt;span class=&quot;GramE&quot;&gt;&lt;b&gt;&lt;span style=&quot;font-size: 10pt; color: rgb(127, 127, 127); font-family: &#39;Courier New&#39;;&quot;&gt;var&lt;/span&gt;&lt;/b&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;font-size: 10pt; color: black; font-family: &#39;Courier New&#39;;&quot;&gt;  &lt;/span&gt;&lt;b&gt;&lt;span style=&quot;font-size: 10pt; color: rgb(27, 27, 215); font-family: &#39;Courier New&#39;;&quot;&gt;previous&lt;/span&gt;&lt;/b&gt;&lt;span style=&quot;font-size: 10pt; color: black; font-family: &#39;Courier New&#39;;&quot;&gt;:  &lt;/span&gt;&lt;b&gt;&lt;span style=&quot;font-size: 10pt; color: brown; font-family: &#39;Courier New&#39;;&quot;&gt;Node&lt;/span&gt;&lt;/b&gt;&lt;span style=&quot;font-size: 10pt; color: black; font-family: &#39;Courier New&#39;;&quot;&gt; =  _&lt;/span&gt;&lt;span style=&quot;font-size: 10pt; font-family: &#39;Courier New&#39;;&quot;&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;font-size: 10pt; color: black; font-family: &#39;Courier New&#39;;&quot;&gt;&lt;span style=&quot;&quot;&gt;  &lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;SpellE&quot;&gt;&lt;span class=&quot;GramE&quot;&gt;&lt;b&gt;&lt;span style=&quot;font-size: 10pt; color: rgb(127, 127, 127); font-family: &#39;Courier New&#39;;&quot;&gt;var&lt;/span&gt;&lt;/b&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;font-size: 10pt; color: black; font-family: &#39;Courier New&#39;;&quot;&gt;  &lt;/span&gt;&lt;b&gt;&lt;span style=&quot;font-size: 10pt; color: rgb(27, 27, 215); font-family: &#39;Courier New&#39;;&quot;&gt;weight&lt;/span&gt;&lt;/b&gt;&lt;span style=&quot;font-size: 10pt; color: black; font-family: &#39;Courier New&#39;;&quot;&gt;= &lt;span class=&quot;SpellE&quot;&gt;Float.PositiveInfinity&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;font-size: 10pt; font-family: &#39;Courier New&#39;;&quot;&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;font-size: 10pt; color: black; font-family: &#39;Courier New&#39;;&quot;&gt;&lt;span style=&quot;&quot;&gt;  &lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;SpellE&quot;&gt;&lt;span class=&quot;GramE&quot;&gt;&lt;b&gt;&lt;span style=&quot;font-size: 10pt; color: rgb(127, 127, 127); font-family: &#39;Courier New&#39;;&quot;&gt;var&lt;/span&gt;&lt;/b&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;font-size: 10pt; color: black; font-family: &#39;Courier New&#39;;&quot;&gt;  &lt;/span&gt;&lt;b&gt;&lt;span style=&quot;font-size: 10pt; color: rgb(27, 27, 215); font-family: &#39;Courier New&#39;;&quot;&gt;visited&lt;/span&gt;&lt;/b&gt;&lt;span style=&quot;font-size: 10pt; color: black; font-family: &#39;Courier New&#39;;&quot;&gt; =  &lt;/span&gt;&lt;b&gt;&lt;span style=&quot;font-size: 10pt; color: rgb(127, 127, 127); font-family: &#39;Courier New&#39;;&quot;&gt;false&lt;/span&gt;&lt;/b&gt;&lt;span style=&quot;font-size: 10pt; font-family: &#39;Courier New&#39;;&quot;&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;font-size: 10pt; font-family: Arial;&quot;&gt;...&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;   &lt;p class=&quot;MsoNormal&quot; style=&quot;&quot;&gt;&lt;span class=&quot;GramE&quot;&gt;&lt;span style=&quot;font-size: 10pt; font-family: Arial;&quot;&gt;and&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;font-size: 10pt; font-family: Arial;&quot;&gt;&lt;o:p&gt; &lt;/o:p&gt;&lt;/span&gt;&lt;br /&gt;&lt;span class=&quot;GramE&quot;&gt;&lt;b&gt;&lt;span style=&quot;font-size: 10pt; color: rgb(127, 127, 127); font-family: &#39;Courier New&#39;;&quot;&gt;&lt;/span&gt;&lt;/b&gt;&lt;/span&gt;&lt;/p&gt;      &lt;p class=&quot;MsoNormal&quot; style=&quot;&quot;&gt;&lt;span class=&quot;GramE&quot;&gt;&lt;b&gt;&lt;span style=&quot;font-size: 10pt; color: rgb(127, 127, 127); font-family: &#39;Courier New&#39;;&quot;&gt;class&lt;/span&gt;&lt;/b&gt;&lt;/span&gt;&lt;span style=&quot;font-size: 10pt; color: black; font-family: &#39;Courier New&#39;;&quot;&gt;  &lt;/span&gt;&lt;b&gt;&lt;span style=&quot;font-size: 10pt; color: brown; font-family: &#39;Courier New&#39;;&quot;&gt;Arc&lt;/span&gt;&lt;/b&gt;&lt;span style=&quot;font-size: 10pt; color: black; font-family: &#39;Courier New&#39;;&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;SpellE&quot;&gt;&lt;b&gt;&lt;span style=&quot;font-size: 10pt; color: rgb(127, 127, 127); font-family: &#39;Courier New&#39;;&quot;&gt;var&lt;/span&gt;&lt;/b&gt;&lt;/span&gt;&lt;span style=&quot;font-size: 10pt; color: black; font-family: &#39;Courier New&#39;;&quot;&gt;  &lt;/span&gt;&lt;b&gt;&lt;span style=&quot;font-size: 10pt; color: rgb(27, 27, 215); font-family: &#39;Courier New&#39;;&quot;&gt;start&lt;/span&gt;&lt;/b&gt;&lt;span style=&quot;font-size: 10pt; color: black; font-family: &#39;Courier New&#39;;&quot;&gt;:  &lt;/span&gt;&lt;b&gt;&lt;span style=&quot;font-size: 10pt; color: brown; font-family: &#39;Courier New&#39;;&quot;&gt;Node&lt;/span&gt;&lt;/b&gt;&lt;span style=&quot;font-size: 10pt; color: black; font-family: &#39;Courier New&#39;;&quot;&gt;, &lt;/span&gt;&lt;span class=&quot;SpellE&quot;&gt;&lt;b&gt;&lt;span style=&quot;font-size: 10pt; color: rgb(127, 127, 127); font-family: &#39;Courier New&#39;;&quot;&gt;var&lt;/span&gt;&lt;/b&gt;&lt;/span&gt;&lt;span style=&quot;font-size: 10pt; color: black; font-family: &#39;Courier New&#39;;&quot;&gt;  &lt;/span&gt;&lt;b&gt;&lt;span style=&quot;font-size: 10pt; color: rgb(27, 27, 215); font-family: &#39;Courier New&#39;;&quot;&gt;end&lt;/span&gt;&lt;/b&gt;&lt;span style=&quot;font-size: 10pt; color: black; font-family: &#39;Courier New&#39;;&quot;&gt;:  &lt;/span&gt;&lt;b&gt;&lt;span style=&quot;font-size: 10pt; color: brown; font-family: &#39;Courier New&#39;;&quot;&gt;Node&lt;/span&gt;&lt;/b&gt;&lt;span style=&quot;font-size: 10pt; color: black; font-family: &#39;Courier New&#39;;&quot;&gt;)  {&lt;/span&gt;&lt;span style=&quot;font-size: 10pt; font-family: &#39;Courier New&#39;;&quot;&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;font-size: 10pt; color: black; font-family: &#39;Courier New&#39;;&quot;&gt;&lt;span style=&quot;&quot;&gt;  &lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;SpellE&quot;&gt;&lt;span class=&quot;GramE&quot;&gt;&lt;b&gt;&lt;span style=&quot;font-size: 10pt; color: rgb(127, 127, 127); font-family: &#39;Courier New&#39;;&quot;&gt;var&lt;/span&gt;&lt;/b&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;font-size: 10pt; color: black; font-family: &#39;Courier New&#39;;&quot;&gt;  &lt;/span&gt;&lt;b&gt;&lt;span style=&quot;font-size: 10pt; color: rgb(27, 27, 215); font-family: &#39;Courier New&#39;;&quot;&gt;weight&lt;/span&gt;&lt;/b&gt;&lt;span style=&quot;font-size: 10pt; color: black; font-family: &#39;Courier New&#39;;&quot;&gt;:  &lt;/span&gt;&lt;b&gt;&lt;span style=&quot;font-size: 10pt; color: brown; font-family: &#39;Courier New&#39;;&quot;&gt;Float&lt;/span&gt;&lt;/b&gt;&lt;span style=&quot;font-size: 10pt; color: black; font-family: &#39;Courier New&#39;;&quot;&gt; =  _&lt;/span&gt;&lt;span style=&quot;font-size: 10pt; font-family: &#39;Courier New&#39;;&quot;&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;font-size: 10pt; font-family: Arial;&quot;&gt;...&lt;o:p&gt; &lt;/o:p&gt;&lt;br /&gt;Don&#39;t you feel that something  doesn&#39;t really fit? What are previous, visited, and weight are doing in Node?  And weight in Arc?&lt;o:p&gt;&lt;/o:p&gt;&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;&lt;p class=&quot;MsoNormal&quot; style=&quot;&quot;&gt;&lt;span style=&quot;font-size: 10pt; font-family: Arial;&quot;&gt;Those properties doesn&#39;t really  belong to a generic Node or Arc, they&#39;re specific for our algorithm. &lt;span class=&quot;GramE&quot;&gt;So, why having them there?&lt;/span&gt; Let&#39;s put those attributes on  special cases of Node and Arc: &lt;span class=&quot;SpellE&quot;&gt;DfsNode&lt;/span&gt; and &lt;span class=&quot;SpellE&quot;&gt;DfsArc&lt;/span&gt;. But wait! Putting weight in both doesn&#39;t seem right  either... we&#39;re defining the same thing twice! Weight is some kind of  &quot;cross-cutting&quot; attribute. &lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p class=&quot;MsoNormal&quot; style=&quot;&quot;&gt;&lt;span style=&quot;font-size: 10pt; font-family: Arial;&quot;&gt;&lt;span style=&quot;font-size:100%;&quot;&gt;&lt;span style=&quot;font-weight: bold;&quot;&gt;Traits&lt;/span&gt;&lt;/span&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;     &lt;p class=&quot;MsoNormal&quot; style=&quot;&quot;&gt;&lt;span style=&quot;font-size: 10pt; font-family: Arial;&quot;&gt;Luckily modern OO languages had a  very elegant way of solving this kind of problems by means of &lt;a href=&quot;http://www.scala-lang.org/intro/traits.html&quot;&gt;traits&lt;/a&gt; (usually are described as  &quot;interfaces with implementation&quot; but a very powerful concept), so let&#39;s define  our weight as a trait:&lt;o:p&gt;&lt;br /&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;br /&gt;&lt;span class=&quot;GramE&quot;&gt;&lt;b&gt;&lt;span style=&quot;font-size: 10pt; color: rgb(127, 127, 127); font-family: &#39;Courier New&#39;;&quot;&gt;trait&lt;/span&gt;&lt;/b&gt;&lt;/span&gt;&lt;span style=&quot;font-size: 10pt; color: black; font-family: &#39;Courier New&#39;;&quot;&gt;  &lt;/span&gt;&lt;b&gt;&lt;span style=&quot;font-size: 10pt; color: brown; font-family: &#39;Courier New&#39;;&quot;&gt;Weighted&lt;/span&gt;&lt;/b&gt;&lt;span style=&quot;font-size: 10pt; color: black; font-family: &#39;Courier New&#39;;&quot;&gt; {&lt;/span&gt;&lt;span style=&quot;font-size: 10pt; font-family: &#39;Courier New&#39;;&quot;&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;font-size: 10pt; color: black; font-family: &#39;Courier New&#39;;&quot;&gt;&lt;span style=&quot;&quot;&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;SpellE&quot;&gt;&lt;span class=&quot;GramE&quot;&gt;&lt;b&gt;&lt;span style=&quot;font-size: 10pt; color: rgb(127, 127, 127); font-family: &#39;Courier New&#39;;&quot;&gt;  var&lt;/span&gt;&lt;/b&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;font-size: 10pt; color: black; font-family: &#39;Courier New&#39;;&quot;&gt;  &lt;/span&gt;&lt;b&gt;&lt;span style=&quot;font-size: 10pt; color: rgb(27, 27, 215); font-family: &#39;Courier New&#39;;&quot;&gt;weight&lt;/span&gt;&lt;/b&gt;&lt;span style=&quot;font-size: 10pt; color: black; font-family: &#39;Courier New&#39;;&quot;&gt;= &lt;span class=&quot;SpellE&quot;&gt;Float.PositiveInfinity&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;font-size: 10pt; font-family: &#39;Courier New&#39;;&quot;&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;font-size: 10pt; color: black; font-family: &#39;Courier New&#39;;&quot;&gt;}&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p class=&quot;MsoNormal&quot; style=&quot;&quot;&gt;&lt;span style=&quot;font-size: 10pt; font-family: Arial;&quot;&gt;So we can clean our Node and Arc  classes:&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;   &lt;p class=&quot;MsoNormal&quot; style=&quot;&quot;&gt;&lt;span class=&quot;GramE&quot;&gt;&lt;b&gt;&lt;span style=&quot;font-size: 10pt; color: rgb(127, 127, 127); font-family: &#39;Courier New&#39;;&quot;&gt;class&lt;/span&gt;&lt;/b&gt;&lt;/span&gt;&lt;span style=&quot;font-size: 10pt; color: black; font-family: &#39;Courier New&#39;;&quot;&gt;  &lt;/span&gt;&lt;b&gt;&lt;span style=&quot;font-size: 10pt; color: brown; font-family: &#39;Courier New&#39;;&quot;&gt;Node&lt;/span&gt;&lt;/b&gt;&lt;span style=&quot;font-size: 10pt; color: black; font-family: &#39;Courier New&#39;;&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;SpellE&quot;&gt;&lt;b&gt;&lt;span style=&quot;font-size: 10pt; color: rgb(127, 127, 127); font-family: &#39;Courier New&#39;;&quot;&gt;val&lt;/span&gt;&lt;/b&gt;&lt;/span&gt;&lt;span style=&quot;font-size: 10pt; color: black; font-family: &#39;Courier New&#39;;&quot;&gt; &lt;/span&gt;&lt;span class=&quot;SpellE&quot;&gt;&lt;b&gt;&lt;span style=&quot;font-size: 10pt; color: rgb(27, 27, 215); font-family: &#39;Courier New&#39;;&quot;&gt;label&lt;/span&gt;&lt;/b&gt;&lt;span style=&quot;font-size: 10pt; color: black; font-family: &#39;Courier New&#39;;&quot;&gt;:&lt;/span&gt;&lt;b&gt;&lt;span style=&quot;font-size: 10pt; color: brown; font-family: &#39;Courier New&#39;;&quot;&gt;String&lt;/span&gt;&lt;/b&gt;&lt;/span&gt;&lt;span style=&quot;font-size: 10pt; color: black; font-family: &#39;Courier New&#39;;&quot;&gt;)&lt;span style=&quot;&quot;&gt;  &lt;/span&gt;{&lt;/span&gt;&lt;span style=&quot;font-size: 10pt; font-family: &#39;Courier New&#39;;&quot;&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;font-size: 10pt; color: black; font-family: &#39;Courier New&#39;;&quot;&gt;&lt;span style=&quot;&quot;&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;SpellE&quot;&gt;&lt;span class=&quot;GramE&quot;&gt;&lt;b&gt;&lt;span style=&quot;font-size: 10pt; color: rgb(127, 127, 127); font-family: &#39;Courier New&#39;;&quot;&gt;  var&lt;/span&gt;&lt;/b&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;font-size: 10pt; color: black; font-family: &#39;Courier New&#39;;&quot;&gt;  &lt;/span&gt;&lt;b&gt;&lt;span style=&quot;font-size: 10pt; color: rgb(27, 27, 215); font-family: &#39;Courier New&#39;;&quot;&gt;transitions&lt;/span&gt;&lt;/b&gt;&lt;span style=&quot;font-size: 10pt; color: black; font-family: &#39;Courier New&#39;;&quot;&gt;:  &lt;/span&gt;&lt;b&gt;&lt;span style=&quot;font-size: 10pt; color: brown; font-family: &#39;Courier New&#39;;&quot;&gt;List&lt;/span&gt;&lt;/b&gt;&lt;span style=&quot;font-size: 10pt; color: black; font-family: &#39;Courier New&#39;;&quot;&gt;[&lt;/span&gt;&lt;b&gt;&lt;span style=&quot;font-size: 10pt; color: brown; font-family: &#39;Courier New&#39;;&quot;&gt;Arc&lt;/span&gt;&lt;/b&gt;&lt;span style=&quot;font-size: 10pt; color: black; font-family: &#39;Courier New&#39;;&quot;&gt;] =  &lt;/span&gt;&lt;b&gt;&lt;span style=&quot;font-size: 10pt; color: brown; font-family: &#39;Courier New&#39;;&quot;&gt;Nil&lt;/span&gt;&lt;/b&gt;&lt;span style=&quot;font-size: 10pt; font-family: &#39;Courier New&#39;;&quot;&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;            &lt;p class=&quot;MsoNormal&quot; style=&quot;&quot;&gt;&lt;span style=&quot;font-size: 10pt; color: black; font-family: &#39;Courier New&#39;;&quot;&gt;&lt;span style=&quot;&quot;&gt;  &lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;GramE&quot;&gt;&lt;b&gt;&lt;span style=&quot;font-size: 10pt; color: rgb(127, 127, 127); font-family: &#39;Courier New&#39;;&quot;&gt;override&lt;/span&gt;&lt;/b&gt;&lt;/span&gt;&lt;span style=&quot;font-size: 10pt; color: black; font-family: &#39;Courier New&#39;;&quot;&gt;  &lt;/span&gt;&lt;b&gt;&lt;span style=&quot;font-size: 10pt; color: rgb(127, 127, 127); font-family: &#39;Courier New&#39;;&quot;&gt;def&lt;/span&gt;&lt;/b&gt;&lt;span style=&quot;font-size: 10pt; color: black; font-family: &#39;Courier New&#39;;&quot;&gt; &lt;/span&gt;&lt;span class=&quot;SpellE&quot;&gt;&lt;b&gt;&lt;span style=&quot;font-size: 10pt; color: dodgerblue; font-family: &#39;Courier New&#39;;&quot;&gt;toString&lt;/span&gt;&lt;/b&gt;&lt;/span&gt;&lt;span style=&quot;font-size: 10pt; color: black; font-family: &#39;Courier New&#39;;&quot;&gt;()=  {&lt;/span&gt;&lt;span style=&quot;font-size: 10pt; font-family: &#39;Courier New&#39;;&quot;&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;font-size: 10pt; color: black; font-family: &#39;Courier New&#39;;&quot;&gt;&lt;span style=&quot;&quot;&gt;    &lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;GramE&quot;&gt;&lt;b&gt;&lt;span style=&quot;font-size: 10pt; color: rgb(27, 27, 215); font-family: &#39;Courier New&#39;;&quot;&gt;label&lt;/span&gt;&lt;/b&gt;&lt;/span&gt;&lt;span style=&quot;font-size: 10pt; font-family: &#39;Courier New&#39;;&quot;&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;font-size: 10pt; color: black; font-family: &#39;Courier New&#39;;&quot;&gt;&lt;span style=&quot;&quot;&gt;  &lt;/span&gt;}&lt;/span&gt;&lt;span style=&quot;font-size: 10pt; font-family: &#39;Courier New&#39;;&quot;&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;font-size: 10pt; color: black; font-family: &#39;Courier New&#39;;&quot;&gt;&lt;span style=&quot;&quot;&gt;  &lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;font-size: 10pt; font-family: &#39;Courier New&#39;;&quot;&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;font-size: 10pt; color: black; font-family: &#39;Courier New&#39;;&quot;&gt;&lt;span style=&quot;&quot;&gt;  &lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;GramE&quot;&gt;&lt;b&gt;&lt;span style=&quot;font-size: 10pt; color: rgb(127, 127, 127); font-family: &#39;Courier New&#39;;&quot;&gt;def&lt;/span&gt;&lt;/b&gt;&lt;/span&gt;&lt;span style=&quot;font-size: 10pt; color: black; font-family: &#39;Courier New&#39;;&quot;&gt;  &lt;/span&gt;&lt;b&gt;&lt;span style=&quot;font-size: 10pt; color: dodgerblue; font-family: &#39;Courier New&#39;;&quot;&gt;--&gt;&lt;/span&gt;&lt;/b&gt;&lt;span style=&quot;font-size: 10pt; color: black; font-family: &#39;Courier New&#39;;&quot;&gt;  (&lt;/span&gt;&lt;b&gt;&lt;i&gt;&lt;span style=&quot;font-size: 10pt; color: rgb(27, 27, 215); font-family: &#39;Courier New&#39;;&quot;&gt;end&lt;/span&gt;&lt;/i&gt;&lt;/b&gt;&lt;span style=&quot;font-size: 10pt; color: black; font-family: &#39;Courier New&#39;;&quot;&gt;:  &lt;/span&gt;&lt;b&gt;&lt;span style=&quot;font-size: 10pt; color: brown; font-family: &#39;Courier New&#39;;&quot;&gt;Node&lt;/span&gt;&lt;/b&gt;&lt;span style=&quot;font-size: 10pt; color: black; font-family: &#39;Courier New&#39;;&quot;&gt;):&lt;/span&gt;&lt;b&gt;&lt;span style=&quot;font-size: 10pt; color: brown; font-family: &#39;Courier New&#39;;&quot;&gt;Arc&lt;/span&gt;&lt;/b&gt;&lt;span style=&quot;font-size: 10pt; color: black; font-family: &#39;Courier New&#39;;&quot;&gt;={&lt;/span&gt;&lt;span style=&quot;font-size: 10pt; font-family: &#39;Courier New&#39;;&quot;&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;font-size: 10pt; color: black; font-family: &#39;Courier New&#39;;&quot;&gt;&lt;span style=&quot;&quot;&gt;    &lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;GramE&quot;&gt;&lt;b&gt;&lt;span style=&quot;font-size: 10pt; color: rgb(27, 27, 215); font-family: &#39;Courier New&#39;;&quot;&gt;transitions&lt;/span&gt;&lt;/b&gt;&lt;/span&gt;&lt;span style=&quot;font-size: 10pt; color: black; font-family: &#39;Courier New&#39;;&quot;&gt; =  &lt;/span&gt;&lt;b&gt;&lt;span style=&quot;font-size: 10pt; color: rgb(127, 127, 127); font-family: &#39;Courier New&#39;;&quot;&gt;new&lt;/span&gt;&lt;/b&gt;&lt;span style=&quot;font-size: 10pt; color: black; font-family: &#39;Courier New&#39;;&quot;&gt;  &lt;/span&gt;&lt;b&gt;&lt;span style=&quot;font-size: 10pt; color: brown; font-family: &#39;Courier New&#39;;&quot;&gt;Arc&lt;/span&gt;&lt;/b&gt;&lt;span style=&quot;font-size: 10pt; color: black; font-family: &#39;Courier New&#39;;&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;SpellE&quot;&gt;&lt;b&gt;&lt;span style=&quot;font-size: 10pt; color: rgb(127, 127, 127); font-family: &#39;Courier New&#39;;&quot;&gt;this&lt;/span&gt;&lt;/b&gt;&lt;span style=&quot;font-size: 10pt; color: black; font-family: &#39;Courier New&#39;;&quot;&gt;,&lt;/span&gt;&lt;b&gt;&lt;i&gt;&lt;span style=&quot;font-size: 10pt; color: rgb(27, 27, 215); font-family: &#39;Courier New&#39;;&quot;&gt;end&lt;/span&gt;&lt;/i&gt;&lt;/b&gt;&lt;/span&gt;&lt;span style=&quot;font-size: 10pt; color: black; font-family: &#39;Courier New&#39;;&quot;&gt;)  &lt;/span&gt;&lt;b&gt;&lt;span style=&quot;font-size: 10pt; color: dodgerblue; font-family: &#39;Courier New&#39;;&quot;&gt;::&lt;/span&gt;&lt;/b&gt;&lt;span style=&quot;font-size: 10pt; color: black; font-family: &#39;Courier New&#39;;&quot;&gt;  &lt;/span&gt;&lt;b&gt;&lt;span style=&quot;font-size: 10pt; color: rgb(27, 27, 215); font-family: &#39;Courier New&#39;;&quot;&gt;transitions&lt;/span&gt;&lt;/b&gt;&lt;span style=&quot;font-size: 10pt; font-family: &#39;Courier New&#39;;&quot;&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;font-size: 10pt; color: black; font-family: &#39;Courier New&#39;;&quot;&gt;&lt;span style=&quot;&quot;&gt;    &lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;SpellE&quot;&gt;&lt;b&gt;&lt;span style=&quot;font-size: 10pt; color: rgb(27, 27, 215); font-family: &#39;Courier New&#39;;&quot;&gt;transitions&lt;/span&gt;&lt;/b&gt;&lt;span style=&quot;font-size: 10pt; color: black; font-family: &#39;Courier New&#39;;&quot;&gt;.&lt;/span&gt;&lt;b&gt;&lt;span style=&quot;font-size: 10pt; color: dodgerblue; font-family: &#39;Courier New&#39;;&quot;&gt;head&lt;/span&gt;&lt;/b&gt;&lt;/span&gt;&lt;span style=&quot;font-size: 10pt; font-family: &#39;Courier New&#39;;&quot;&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;font-size: 10pt; color: black; font-family: &#39;Courier New&#39;;&quot;&gt;&lt;span style=&quot;&quot;&gt;  &lt;/span&gt;}&lt;/span&gt;&lt;span style=&quot;font-size: 10pt; font-family: &#39;Courier New&#39;;&quot;&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;span style=&quot;font-size: 10pt; color: black; font-family: &#39;Courier New&#39;;&quot;&gt;&lt;span style=&quot;&quot;&gt;  &lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;font-size: 10pt; font-family: &#39;Courier New&#39;;&quot;&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;font-size: 10pt; color: black; font-family: &#39;Courier New&#39;;&quot;&gt;}&lt;o:p&gt;&lt;br /&gt; &lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;      &lt;p class=&quot;MsoNormal&quot; style=&quot;&quot;&gt;&lt;span class=&quot;GramE&quot;&gt;&lt;b&gt;&lt;span style=&quot;font-size: 10pt; color: rgb(127, 127, 127); font-family: &#39;Courier New&#39;;&quot;&gt;class&lt;/span&gt;&lt;/b&gt;&lt;/span&gt;&lt;span style=&quot;font-size: 10pt; color: black; font-family: &#39;Courier New&#39;;&quot;&gt;  &lt;/span&gt;&lt;b&gt;&lt;span style=&quot;font-size: 10pt; color: brown; font-family: &#39;Courier New&#39;;&quot;&gt;Arc&lt;/span&gt;&lt;/b&gt;&lt;span style=&quot;font-size: 10pt; color: black; font-family: &#39;Courier New&#39;;&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;SpellE&quot;&gt;&lt;b&gt;&lt;span style=&quot;font-size: 10pt; color: rgb(127, 127, 127); font-family: &#39;Courier New&#39;;&quot;&gt;var&lt;/span&gt;&lt;/b&gt;&lt;/span&gt;&lt;span style=&quot;font-size: 10pt; color: black; font-family: &#39;Courier New&#39;;&quot;&gt;  &lt;/span&gt;&lt;b&gt;&lt;span style=&quot;font-size: 10pt; color: rgb(27, 27, 215); font-family: &#39;Courier New&#39;;&quot;&gt;start&lt;/span&gt;&lt;/b&gt;&lt;span style=&quot;font-size: 10pt; color: black; font-family: &#39;Courier New&#39;;&quot;&gt;:  &lt;/span&gt;&lt;b&gt;&lt;span style=&quot;font-size: 10pt; color: brown; font-family: &#39;Courier New&#39;;&quot;&gt;Node&lt;/span&gt;&lt;/b&gt;&lt;span style=&quot;font-size: 10pt; color: black; font-family: &#39;Courier New&#39;;&quot;&gt;, &lt;/span&gt;&lt;span class=&quot;SpellE&quot;&gt;&lt;b&gt;&lt;span style=&quot;font-size: 10pt; color: rgb(127, 127, 127); font-family: &#39;Courier New&#39;;&quot;&gt;var&lt;/span&gt;&lt;/b&gt;&lt;/span&gt;&lt;span style=&quot;font-size: 10pt; color: black; font-family: &#39;Courier New&#39;;&quot;&gt;  &lt;/span&gt;&lt;b&gt;&lt;span style=&quot;font-size: 10pt; color: rgb(27, 27, 215); font-family: &#39;Courier New&#39;;&quot;&gt;end&lt;/span&gt;&lt;/b&gt;&lt;span style=&quot;font-size: 10pt; color: black; font-family: &#39;Courier New&#39;;&quot;&gt;:  &lt;/span&gt;&lt;b&gt;&lt;span style=&quot;font-size: 10pt; color: brown; font-family: &#39;Courier New&#39;;&quot;&gt;Node&lt;/span&gt;&lt;/b&gt;&lt;span style=&quot;font-size: 10pt; color: black; font-family: &#39;Courier New&#39;;&quot;&gt;)  {&lt;/span&gt;&lt;span style=&quot;font-size: 10pt; font-family: &#39;Courier New&#39;;&quot;&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;font-size: 10pt; color: black; font-family: &#39;Courier New&#39;;&quot;&gt;&lt;span style=&quot;&quot;&gt;  &lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;font-size: 10pt; font-family: &#39;Courier New&#39;;&quot;&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;font-size: 10pt; color: black; font-family: &#39;Courier New&#39;;&quot;&gt;&lt;span style=&quot;&quot;&gt;  &lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;GramE&quot;&gt;&lt;b&gt;&lt;span style=&quot;font-size: 10pt; color: rgb(127, 127, 127); font-family: &#39;Courier New&#39;;&quot;&gt;override&lt;/span&gt;&lt;/b&gt;&lt;/span&gt;&lt;span style=&quot;font-size: 10pt; color: black; font-family: &#39;Courier New&#39;;&quot;&gt;  &lt;/span&gt;&lt;b&gt;&lt;span style=&quot;font-size: 10pt; color: rgb(127, 127, 127); font-family: &#39;Courier New&#39;;&quot;&gt;def&lt;/span&gt;&lt;/b&gt;&lt;span style=&quot;font-size: 10pt; color: black; font-family: &#39;Courier New&#39;;&quot;&gt; &lt;/span&gt;&lt;span class=&quot;SpellE&quot;&gt;&lt;b&gt;&lt;span style=&quot;font-size: 10pt; color: dodgerblue; font-family: &#39;Courier New&#39;;&quot;&gt;toString&lt;/span&gt;&lt;/b&gt;&lt;/span&gt;&lt;span style=&quot;font-size: 10pt; color: black; font-family: &#39;Courier New&#39;;&quot;&gt;()=  {&lt;/span&gt;&lt;span style=&quot;font-size: 10pt; font-family: &#39;Courier New&#39;;&quot;&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;font-size: 10pt; color: black; font-family: &#39;Courier New&#39;;&quot;&gt;&lt;span style=&quot;&quot;&gt;   &lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;SpellE&quot;&gt;&lt;span class=&quot;GramE&quot;&gt;&lt;b&gt;&lt;span style=&quot;font-size: 10pt; color: rgb(27, 27, 215); font-family: &#39;Courier New&#39;;&quot;&gt;start&lt;/span&gt;&lt;/b&gt;&lt;span style=&quot;font-size: 10pt; color: black; font-family: &#39;Courier New&#39;;&quot;&gt;.&lt;/span&gt;&lt;b&gt;&lt;span style=&quot;font-size: 10pt; color: rgb(27, 27, 215); font-family: &#39;Courier New&#39;;&quot;&gt;label&lt;/span&gt;&lt;/b&gt;&lt;/span&gt;&lt;/span&gt;&lt;b&gt;&lt;span style=&quot;font-size: 10pt; color: dodgerblue; font-family: &#39;Courier New&#39;;&quot;&gt;+&lt;/span&gt;&lt;/b&gt;&lt;i&gt;&lt;span style=&quot;font-size: 10pt; color: rgb(127, 127, 127); font-family: &#39;Courier New&#39;;&quot;&gt;&quot;--&gt;&quot;&lt;/span&gt;&lt;/i&gt;&lt;span style=&quot;font-size: 10pt; color: black; font-family: &#39;Courier New&#39;;&quot;&gt;+&lt;/span&gt;&lt;span class=&quot;SpellE&quot;&gt;&lt;b&gt;&lt;span style=&quot;font-size: 10pt; color: rgb(27, 27, 215); font-family: &#39;Courier New&#39;;&quot;&gt;end&lt;/span&gt;&lt;/b&gt;&lt;span style=&quot;font-size: 10pt; color: black; font-family: &#39;Courier New&#39;;&quot;&gt;.&lt;/span&gt;&lt;b&gt;&lt;span style=&quot;font-size: 10pt; color: rgb(27, 27, 215); font-family: &#39;Courier New&#39;;&quot;&gt;label&lt;/span&gt;&lt;/b&gt;&lt;/span&gt;&lt;span style=&quot;font-size: 10pt; font-family: &#39;Courier New&#39;;&quot;&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;font-size: 10pt; color: black; font-family: &#39;Courier New&#39;;&quot;&gt;&lt;span style=&quot;&quot;&gt;  &lt;/span&gt;}&lt;/span&gt;&lt;span style=&quot;font-size: 10pt; font-family: &#39;Courier New&#39;;&quot;&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;font-size: 10pt; color: black; font-family: &#39;Courier New&#39;;&quot;&gt;}&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p class=&quot;MsoNormal&quot; style=&quot;&quot;&gt;&lt;span style=&quot;font-size: 10pt; color: black; font-family: &#39;Courier New&#39;;&quot;&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;span style=&quot;font-size: 10pt; font-family: Arial;&quot;&gt;Now they look useful for any graph  application, and we can define our particular versions for the &lt;span class=&quot;SpellE&quot;&gt;Dfs&lt;/span&gt; algorithm:&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot; style=&quot;&quot;&gt;&lt;b&gt;&lt;span style=&quot;font-size: 10pt; color: rgb(127, 127, 127); font-family: &#39;Courier New&#39;;&quot;&gt;&lt;o:p&gt; &lt;/o:p&gt;&lt;/span&gt;&lt;/b&gt;&lt;/p&gt;        &lt;p class=&quot;MsoNormal&quot; style=&quot;&quot;&gt;&lt;span class=&quot;GramE&quot;&gt;&lt;b&gt;&lt;span style=&quot;font-size: 10pt; color: rgb(127, 127, 127); font-family: &#39;Courier New&#39;;&quot;&gt;class&lt;/span&gt;&lt;/b&gt;&lt;/span&gt;&lt;span style=&quot;font-size: 10pt; color: black; font-family: &#39;Courier New&#39;;&quot;&gt; &lt;/span&gt;&lt;span class=&quot;SpellE&quot;&gt;&lt;b&gt;&lt;span style=&quot;font-size: 10pt; color: brown; font-family: &#39;Courier New&#39;;&quot;&gt;DfsNode&lt;/span&gt;&lt;/b&gt;&lt;/span&gt;&lt;span style=&quot;font-size: 10pt; color: black; font-family: &#39;Courier New&#39;;&quot;&gt; (&lt;/span&gt;&lt;span class=&quot;SpellE&quot;&gt;&lt;b&gt;&lt;span style=&quot;font-size: 10pt; color: rgb(27, 27, 215); font-family: &#39;Courier New&#39;;&quot;&gt;label&lt;/span&gt;&lt;/b&gt;&lt;span style=&quot;font-size: 10pt; color: black; font-family: &#39;Courier New&#39;;&quot;&gt;:&lt;/span&gt;&lt;b&gt;&lt;span style=&quot;font-size: 10pt; color: brown; font-family: &#39;Courier New&#39;;&quot;&gt;String&lt;/span&gt;&lt;/b&gt;&lt;/span&gt;&lt;span style=&quot;font-size: 10pt; color: black; font-family: &#39;Courier New&#39;;&quot;&gt;)  &lt;/span&gt;&lt;b&gt;&lt;span style=&quot;font-size: 10pt; color: rgb(127, 127, 127); font-family: &#39;Courier New&#39;;&quot;&gt;extends&lt;/span&gt;&lt;/b&gt;&lt;span style=&quot;font-size: 10pt; color: black; font-family: &#39;Courier New&#39;;&quot;&gt;  &lt;/span&gt;&lt;b&gt;&lt;span style=&quot;font-size: 10pt; color: brown; font-family: &#39;Courier New&#39;;&quot;&gt;Node&lt;/span&gt;&lt;/b&gt;&lt;span style=&quot;font-size: 10pt; color: black; font-family: &#39;Courier New&#39;;&quot;&gt;(&lt;/span&gt;&lt;b&gt;&lt;i&gt;&lt;span style=&quot;font-size: 10pt; color: rgb(27, 27, 215); font-family: &#39;Courier New&#39;;&quot;&gt;label&lt;/span&gt;&lt;/i&gt;&lt;/b&gt;&lt;span style=&quot;font-size: 10pt; color: black; font-family: &#39;Courier New&#39;;&quot;&gt;)  &lt;/span&gt;&lt;b&gt;&lt;span style=&quot;font-size: 10pt; color: rgb(127, 127, 127); font-family: &#39;Courier New&#39;;&quot;&gt;with&lt;/span&gt;&lt;/b&gt;&lt;span style=&quot;font-size: 10pt; color: black; font-family: &#39;Courier New&#39;;&quot;&gt;  &lt;/span&gt;&lt;b&gt;&lt;span style=&quot;font-size: 10pt; color: brown; font-family: &#39;Courier New&#39;;&quot;&gt;Weighted&lt;/span&gt;&lt;/b&gt;&lt;span style=&quot;font-size: 10pt; color: black; font-family: &#39;Courier New&#39;;&quot;&gt;&lt;span style=&quot;&quot;&gt;  &lt;/span&gt;{&lt;/span&gt;&lt;span style=&quot;font-size: 10pt; font-family: &#39;Courier New&#39;;&quot;&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;font-size: 10pt; color: black; font-family: &#39;Courier New&#39;;&quot;&gt;&lt;span style=&quot;&quot;&gt;  &lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;SpellE&quot;&gt;&lt;span class=&quot;GramE&quot;&gt;&lt;b&gt;&lt;span style=&quot;font-size: 10pt; color: rgb(127, 127, 127); font-family: &#39;Courier New&#39;;&quot;&gt;var&lt;/span&gt;&lt;/b&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;font-size: 10pt; color: black; font-family: &#39;Courier New&#39;;&quot;&gt;  &lt;/span&gt;&lt;b&gt;&lt;span style=&quot;font-size: 10pt; color: rgb(27, 27, 215); font-family: &#39;Courier New&#39;;&quot;&gt;previous&lt;/span&gt;&lt;/b&gt;&lt;span style=&quot;font-size: 10pt; color: black; font-family: &#39;Courier New&#39;;&quot;&gt;: &lt;/span&gt;&lt;span class=&quot;SpellE&quot;&gt;&lt;b&gt;&lt;span style=&quot;font-size: 10pt; color: brown; font-family: &#39;Courier New&#39;;&quot;&gt;DfsNode&lt;/span&gt;&lt;/b&gt;&lt;/span&gt;&lt;span style=&quot;font-size: 10pt; color: black; font-family: &#39;Courier New&#39;;&quot;&gt; =  _&lt;/span&gt;&lt;span style=&quot;font-size: 10pt; font-family: &#39;Courier New&#39;;&quot;&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;font-size: 10pt; color: black; font-family: &#39;Courier New&#39;;&quot;&gt;&lt;span style=&quot;&quot;&gt;  &lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;SpellE&quot;&gt;&lt;span class=&quot;GramE&quot;&gt;&lt;b&gt;&lt;span style=&quot;font-size: 10pt; color: rgb(127, 127, 127); font-family: &#39;Courier New&#39;;&quot;&gt;var&lt;/span&gt;&lt;/b&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;font-size: 10pt; color: black; font-family: &#39;Courier New&#39;;&quot;&gt;  &lt;/span&gt;&lt;b&gt;&lt;span style=&quot;font-size: 10pt; color: rgb(27, 27, 215); font-family: &#39;Courier New&#39;;&quot;&gt;visited&lt;/span&gt;&lt;/b&gt;&lt;span style=&quot;font-size: 10pt; color: black; font-family: &#39;Courier New&#39;;&quot;&gt; =  &lt;/span&gt;&lt;b&gt;&lt;span style=&quot;font-size: 10pt; color: rgb(127, 127, 127); font-family: &#39;Courier New&#39;;&quot;&gt;false&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/b&gt;&lt;br /&gt;&lt;span style=&quot;font-size: 10pt; color: black; font-family: &#39;Courier New&#39;;&quot;&gt;&lt;span style=&quot;&quot;&gt; &lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;font-size: 10pt; font-family: &#39;Courier New&#39;;&quot;&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;font-size: 10pt; color: black; font-family: &#39;Courier New&#39;;&quot;&gt;&lt;span style=&quot;&quot;&gt;  &lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;GramE&quot;&gt;&lt;b&gt;&lt;span style=&quot;font-size: 10pt; color: rgb(127, 127, 127); font-family: &#39;Courier New&#39;;&quot;&gt;override&lt;/span&gt;&lt;/b&gt;&lt;/span&gt;&lt;span style=&quot;font-size: 10pt; color: black; font-family: &#39;Courier New&#39;;&quot;&gt;  &lt;/span&gt;&lt;b&gt;&lt;span style=&quot;font-size: 10pt; color: rgb(127, 127, 127); font-family: &#39;Courier New&#39;;&quot;&gt;def&lt;/span&gt;&lt;/b&gt;&lt;span style=&quot;font-size: 10pt; color: black; font-family: &#39;Courier New&#39;;&quot;&gt; &lt;/span&gt;&lt;span class=&quot;SpellE&quot;&gt;&lt;b&gt;&lt;span style=&quot;font-size: 10pt; color: dodgerblue; font-family: &#39;Courier New&#39;;&quot;&gt;toString&lt;/span&gt;&lt;/b&gt;&lt;/span&gt;&lt;span style=&quot;font-size: 10pt; color: black; font-family: &#39;Courier New&#39;;&quot;&gt;()=  {&lt;/span&gt;&lt;span style=&quot;font-size: 10pt; font-family: &#39;Courier New&#39;;&quot;&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;font-size: 10pt; color: black; font-family: &#39;Courier New&#39;;&quot;&gt;&lt;span style=&quot;&quot;&gt;    &lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;SpellE&quot;&gt;&lt;b&gt;&lt;span style=&quot;font-size: 10pt; color: rgb(127, 127, 127); font-family: &#39;Courier New&#39;;&quot;&gt;super&lt;/span&gt;&lt;/b&gt;&lt;span style=&quot;font-size: 10pt; color: black; font-family: &#39;Courier New&#39;;&quot;&gt;.&lt;/span&gt;&lt;b&gt;&lt;span style=&quot;font-size: 10pt; color: dodgerblue; font-family: &#39;Courier New&#39;;&quot;&gt;toString&lt;/span&gt;&lt;/b&gt;&lt;/span&gt;&lt;b&gt;&lt;span style=&quot;font-size: 10pt; color: dodgerblue; font-family: &#39;Courier New&#39;;&quot;&gt;+&lt;/span&gt;&lt;/b&gt;&lt;i&gt;&lt;span style=&quot;font-size: 10pt; color: rgb(127, 127, 127); font-family: &#39;Courier New&#39;;&quot;&gt;&quot; &lt;span class=&quot;SpellE&quot;&gt;w:&quot;&lt;span style=&quot;color: black; font-style: normal;&quot;&gt;+&lt;/span&gt;&lt;b&gt;&lt;span style=&quot;color: rgb(27, 27, 215); font-style: normal;&quot;&gt;weight&lt;/span&gt;&lt;/b&gt;&lt;/span&gt;&lt;/span&gt;&lt;/i&gt;&lt;b&gt;&lt;span style=&quot;font-size: 10pt; color: dodgerblue; font-family: &#39;Courier New&#39;;&quot;&gt;+&lt;/span&gt;&lt;/b&gt;&lt;i&gt;&lt;span style=&quot;font-size: 10pt; color: rgb(127, 127, 127); font-family: &#39;Courier New&#39;;&quot;&gt;&quot; &lt;span class=&quot;SpellE&quot;&gt;p:&quot;&lt;span style=&quot;color: black; font-style: normal;&quot;&gt;+&lt;/span&gt;&lt;b&gt;&lt;span style=&quot;color: rgb(27, 27, 215); font-style: normal;&quot;&gt;previous&lt;/span&gt;&lt;/b&gt;&lt;/span&gt;&lt;/span&gt;&lt;/i&gt;&lt;span style=&quot;font-size: 10pt; font-family: &#39;Courier New&#39;;&quot;&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;font-size: 10pt; color: black; font-family: &#39;Courier New&#39;;&quot;&gt;&lt;span style=&quot;&quot;&gt;  &lt;/span&gt;}&lt;/span&gt;&lt;span style=&quot;font-size: 10pt; font-family: &#39;Courier New&#39;;&quot;&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;font-size: 10pt; color: black; font-family: &#39;Courier New&#39;;&quot;&gt;}&lt;/span&gt;&lt;span style=&quot;font-size: 10pt; font-family: &#39;Courier New&#39;;&quot;&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot; style=&quot;&quot;&gt;&lt;span style=&quot;font-size: 10pt; font-family: Arial;&quot;&gt;&lt;o:p&gt; &lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;      &lt;p class=&quot;MsoNormal&quot; style=&quot;&quot;&gt;&lt;span class=&quot;GramE&quot;&gt;&lt;b&gt;&lt;span style=&quot;font-size: 10pt; color: rgb(127, 127, 127); font-family: &#39;Courier New&#39;;&quot;&gt;class&lt;/span&gt;&lt;/b&gt;&lt;/span&gt;&lt;span style=&quot;font-size: 10pt; color: black; font-family: &#39;Courier New&#39;;&quot;&gt;  &lt;/span&gt;&lt;b&gt;&lt;span style=&quot;font-size: 10pt; color: brown; font-family: &#39;Courier New&#39;;&quot;&gt;Arc&lt;/span&gt;&lt;/b&gt;&lt;span style=&quot;font-size: 10pt; color: black; font-family: &#39;Courier New&#39;;&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;SpellE&quot;&gt;&lt;b&gt;&lt;span style=&quot;font-size: 10pt; color: rgb(127, 127, 127); font-family: &#39;Courier New&#39;;&quot;&gt;var&lt;/span&gt;&lt;/b&gt;&lt;/span&gt;&lt;span style=&quot;font-size: 10pt; color: black; font-family: &#39;Courier New&#39;;&quot;&gt;  &lt;/span&gt;&lt;b&gt;&lt;span style=&quot;font-size: 10pt; color: rgb(27, 27, 215); font-family: &#39;Courier New&#39;;&quot;&gt;start&lt;/span&gt;&lt;/b&gt;&lt;span style=&quot;font-size: 10pt; color: black; font-family: &#39;Courier New&#39;;&quot;&gt;:  &lt;/span&gt;&lt;b&gt;&lt;span style=&quot;font-size: 10pt; color: brown; font-family: &#39;Courier New&#39;;&quot;&gt;Node&lt;/span&gt;&lt;/b&gt;&lt;span style=&quot;font-size: 10pt; color: black; font-family: &#39;Courier New&#39;;&quot;&gt;, &lt;/span&gt;&lt;span class=&quot;SpellE&quot;&gt;&lt;b&gt;&lt;span style=&quot;font-size: 10pt; color: rgb(127, 127, 127); font-family: &#39;Courier New&#39;;&quot;&gt;var&lt;/span&gt;&lt;/b&gt;&lt;/span&gt;&lt;span style=&quot;font-size: 10pt; color: black; font-family: &#39;Courier New&#39;;&quot;&gt;  &lt;/span&gt;&lt;b&gt;&lt;span style=&quot;font-size: 10pt; color: rgb(27, 27, 215); font-family: &#39;Courier New&#39;;&quot;&gt;end&lt;/span&gt;&lt;/b&gt;&lt;span style=&quot;font-size: 10pt; color: black; font-family: &#39;Courier New&#39;;&quot;&gt;:  &lt;/span&gt;&lt;b&gt;&lt;span style=&quot;font-size: 10pt; color: brown; font-family: &#39;Courier New&#39;;&quot;&gt;Node&lt;/span&gt;&lt;/b&gt;&lt;span style=&quot;font-size: 10pt; color: black; font-family: &#39;Courier New&#39;;&quot;&gt;) {  &lt;/span&gt;&lt;span style=&quot;font-size: 10pt; font-family: &#39;Courier New&#39;;&quot;&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;font-size: 10pt; color: black; font-family: &#39;Courier New&#39;;&quot;&gt;&lt;span style=&quot;&quot;&gt;  &lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;GramE&quot;&gt;&lt;b&gt;&lt;span style=&quot;font-size: 10pt; color: rgb(127, 127, 127); font-family: &#39;Courier New&#39;;&quot;&gt;override&lt;/span&gt;&lt;/b&gt;&lt;/span&gt;&lt;span style=&quot;font-size: 10pt; color: black; font-family: &#39;Courier New&#39;;&quot;&gt;  &lt;/span&gt;&lt;b&gt;&lt;span style=&quot;font-size: 10pt; color: rgb(127, 127, 127); font-family: &#39;Courier New&#39;;&quot;&gt;def&lt;/span&gt;&lt;/b&gt;&lt;span style=&quot;font-size: 10pt; color: black; font-family: &#39;Courier New&#39;;&quot;&gt; &lt;/span&gt;&lt;span class=&quot;SpellE&quot;&gt;&lt;b&gt;&lt;span style=&quot;font-size: 10pt; color: dodgerblue; font-family: &#39;Courier New&#39;;&quot;&gt;toString&lt;/span&gt;&lt;/b&gt;&lt;/span&gt;&lt;span style=&quot;font-size: 10pt; color: black; font-family: &#39;Courier New&#39;;&quot;&gt;()=  {&lt;/span&gt;&lt;span style=&quot;font-size: 10pt; font-family: &#39;Courier New&#39;;&quot;&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;font-size: 10pt; color: black; font-family: &#39;Courier New&#39;;&quot;&gt;&lt;span style=&quot;&quot;&gt;   &lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;SpellE&quot;&gt;&lt;span class=&quot;GramE&quot;&gt;&lt;b&gt;&lt;span style=&quot;font-size: 10pt; color: rgb(27, 27, 215); font-family: &#39;Courier New&#39;;&quot;&gt;start&lt;/span&gt;&lt;/b&gt;&lt;span style=&quot;font-size: 10pt; color: black; font-family: &#39;Courier New&#39;;&quot;&gt;.&lt;/span&gt;&lt;b&gt;&lt;span style=&quot;font-size: 10pt; color: rgb(27, 27, 215); font-family: &#39;Courier New&#39;;&quot;&gt;label&lt;/span&gt;&lt;/b&gt;&lt;/span&gt;&lt;/span&gt;&lt;b&gt;&lt;span style=&quot;font-size: 10pt; color: dodgerblue; font-family: &#39;Courier New&#39;;&quot;&gt;+&lt;/span&gt;&lt;/b&gt;&lt;i&gt;&lt;span style=&quot;font-size: 10pt; color: rgb(127, 127, 127); font-family: &#39;Courier New&#39;;&quot;&gt;&quot;--&gt;&quot;&lt;/span&gt;&lt;/i&gt;&lt;span style=&quot;font-size: 10pt; color: black; font-family: &#39;Courier New&#39;;&quot;&gt;+&lt;/span&gt;&lt;span class=&quot;SpellE&quot;&gt;&lt;b&gt;&lt;span style=&quot;font-size: 10pt; color: rgb(27, 27, 215); font-family: &#39;Courier New&#39;;&quot;&gt;end&lt;/span&gt;&lt;/b&gt;&lt;span style=&quot;font-size: 10pt; color: black; font-family: &#39;Courier New&#39;;&quot;&gt;.&lt;/span&gt;&lt;b&gt;&lt;span style=&quot;font-size: 10pt; color: rgb(27, 27, 215); font-family: &#39;Courier New&#39;;&quot;&gt;label&lt;/span&gt;&lt;/b&gt;&lt;/span&gt;&lt;span style=&quot;font-size: 10pt; font-family: &#39;Courier New&#39;;&quot;&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;font-size: 10pt; color: black; font-family: &#39;Courier New&#39;;&quot;&gt;&lt;span style=&quot;&quot;&gt;  &lt;/span&gt;}&lt;/span&gt;&lt;span style=&quot;font-size: 10pt; font-family: &#39;Courier New&#39;;&quot;&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;font-size: 10pt; color: black; font-family: &#39;Courier New&#39;;&quot;&gt;}&lt;o:p&gt;&lt;br /&gt; &lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot; style=&quot;&quot;&gt;&lt;span style=&quot;font-size: 10pt; font-family: Arial;&quot;&gt;And I just need to change the  signatures of the functions of the algorithm:&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;                               &lt;p class=&quot;MsoNormal&quot; style=&quot;&quot;&gt;&lt;span class=&quot;GramE&quot;&gt;&lt;b&gt;&lt;span style=&quot;font-size: 10pt; color: rgb(127, 127, 127); font-family: &#39;Courier New&#39;;&quot;&gt;object&lt;/span&gt;&lt;/b&gt;&lt;/span&gt;&lt;span style=&quot;font-size: 10pt; color: black; font-family: &#39;Courier New&#39;;&quot;&gt; &lt;/span&gt;&lt;span class=&quot;SpellE&quot;&gt;&lt;b&gt;&lt;span style=&quot;font-size: 10pt; color: brown; font-family: &#39;Courier New&#39;;&quot;&gt;Dijkstra&lt;/span&gt;&lt;/b&gt;&lt;/span&gt;&lt;span style=&quot;font-size: 10pt; color: black; font-family: &#39;Courier New&#39;;&quot;&gt; {&lt;/span&gt;&lt;span style=&quot;font-size: 10pt; font-family: &#39;Courier New&#39;;&quot;&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;font-size: 10pt; color: black; font-family: &#39;Courier New&#39;;&quot;&gt;&lt;span style=&quot;&quot;&gt;    &lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;font-size: 10pt; font-family: &#39;Courier New&#39;;&quot;&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;font-size: 10pt; color: black; font-family: &#39;Courier New&#39;;&quot;&gt;&lt;span style=&quot;&quot;&gt;  &lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;GramE&quot;&gt;&lt;b&gt;&lt;span style=&quot;font-size: 10pt; color: rgb(127, 127, 127); font-family: &#39;Courier New&#39;;&quot;&gt;def&lt;/span&gt;&lt;/b&gt;&lt;/span&gt;&lt;span style=&quot;font-size: 10pt; color: black; font-family: &#39;Courier New&#39;;&quot;&gt; &lt;/span&gt;&lt;span class=&quot;SpellE&quot;&gt;&lt;b&gt;&lt;span style=&quot;font-size: 10pt; color: dodgerblue; font-family: &#39;Courier New&#39;;&quot;&gt;shortestPath&lt;/span&gt;&lt;/b&gt;&lt;/span&gt;&lt;span style=&quot;font-size: 10pt; color: black; font-family: &#39;Courier New&#39;;&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;SpellE&quot;&gt;&lt;b&gt;&lt;i&gt;&lt;span style=&quot;font-size: 10pt; color: rgb(27, 27, 215); font-family: &#39;Courier New&#39;;&quot;&gt;graph&lt;/span&gt;&lt;/i&gt;&lt;/b&gt;&lt;span style=&quot;font-size: 10pt; color: black; font-family: &#39;Courier New&#39;;&quot;&gt;:&lt;/span&gt;&lt;b&gt;&lt;span style=&quot;font-size: 10pt; color: brown; font-family: &#39;Courier New&#39;;&quot;&gt;Set&lt;/span&gt;&lt;/b&gt;&lt;/span&gt;&lt;span style=&quot;font-size: 10pt; color: black; font-family: &#39;Courier New&#39;;&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;SpellE&quot;&gt;&lt;b&gt;&lt;span style=&quot;font-size: 10pt; color: brown; font-family: &#39;Courier New&#39;;&quot;&gt;DfsNode&lt;/span&gt;&lt;/b&gt;&lt;/span&gt;&lt;span style=&quot;font-size: 10pt; color: black; font-family: &#39;Courier New&#39;;&quot;&gt;],  &lt;/span&gt;&lt;b&gt;&lt;i&gt;&lt;span style=&quot;font-size: 10pt; color: rgb(27, 27, 215); font-family: &#39;Courier New&#39;;&quot;&gt;start&lt;/span&gt;&lt;/i&gt;&lt;/b&gt;&lt;span style=&quot;font-size: 10pt; color: black; font-family: &#39;Courier New&#39;;&quot;&gt;: &lt;/span&gt;&lt;span class=&quot;SpellE&quot;&gt;&lt;b&gt;&lt;span style=&quot;font-size: 10pt; color: brown; font-family: &#39;Courier New&#39;;&quot;&gt;DfsNode&lt;/span&gt;&lt;/b&gt;&lt;/span&gt;&lt;span style=&quot;font-size: 10pt; color: black; font-family: &#39;Courier New&#39;;&quot;&gt;,  &lt;/span&gt;&lt;b&gt;&lt;i&gt;&lt;span style=&quot;font-size: 10pt; color: rgb(27, 27, 215); font-family: &#39;Courier New&#39;;&quot;&gt;end&lt;/span&gt;&lt;/i&gt;&lt;/b&gt;&lt;span style=&quot;font-size: 10pt; color: black; font-family: &#39;Courier New&#39;;&quot;&gt;: &lt;/span&gt;&lt;span class=&quot;SpellE&quot;&gt;&lt;b&gt;&lt;span style=&quot;font-size: 10pt; color: brown; font-family: &#39;Courier New&#39;;&quot;&gt;DfsNode&lt;/span&gt;&lt;/b&gt;&lt;/span&gt;&lt;span style=&quot;font-size: 10pt; color: black; font-family: &#39;Courier New&#39;;&quot;&gt;) =  {&lt;/span&gt;&lt;span style=&quot;font-size: 10pt; font-family: &#39;Courier New&#39;;&quot;&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;font-size: 10pt; color: black; font-family: &#39;Courier New&#39;;&quot;&gt;&lt;span style=&quot;&quot;&gt;    &lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;SpellE&quot;&gt;&lt;span class=&quot;GramE&quot;&gt;&lt;b&gt;&lt;span style=&quot;font-size: 10pt; color: rgb(127, 127, 127); font-family: &#39;Courier New&#39;;&quot;&gt;var&lt;/span&gt;&lt;/b&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;font-size: 10pt; color: black; font-family: &#39;Courier New&#39;;&quot;&gt;  &lt;/span&gt;&lt;b&gt;&lt;span style=&quot;font-size: 10pt; color: rgb(27, 27, 215); font-family: &#39;Courier New&#39;;&quot;&gt;unvisited&lt;/span&gt;&lt;/b&gt;&lt;span style=&quot;font-size: 10pt; color: black; font-family: &#39;Courier New&#39;;&quot;&gt;=&lt;/span&gt;&lt;b&gt;&lt;i&gt;&lt;span style=&quot;font-size: 10pt; color: rgb(27, 27, 215); font-family: &#39;Courier New&#39;;&quot;&gt;graph&lt;/span&gt;&lt;/i&gt;&lt;/b&gt;&lt;span style=&quot;font-size: 10pt; font-family: &#39;Courier New&#39;;&quot;&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;font-size: 10pt; color: black; font-family: &#39;Courier New&#39;;&quot;&gt;&lt;span style=&quot;&quot;&gt;    &lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;SpellE&quot;&gt;&lt;b&gt;&lt;i&gt;&lt;span style=&quot;font-size: 10pt; color: rgb(27, 27, 215); font-family: &#39;Courier New&#39;;&quot;&gt;start&lt;/span&gt;&lt;/i&gt;&lt;/b&gt;&lt;span style=&quot;font-size: 10pt; color: black; font-family: &#39;Courier New&#39;;&quot;&gt;.&lt;/span&gt;&lt;b&gt;&lt;span style=&quot;font-size: 10pt; color: rgb(27, 27, 215); font-family: &#39;Courier New&#39;;&quot;&gt;weight&lt;/span&gt;&lt;/b&gt;&lt;/span&gt;&lt;span style=&quot;font-size: 10pt; color: black; font-family: &#39;Courier New&#39;;&quot;&gt;=0&lt;/span&gt;&lt;span style=&quot;font-size: 10pt; font-family: &#39;Courier New&#39;;&quot;&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;font-size: 10pt; color: black; font-family: &#39;Courier New&#39;;&quot;&gt;&lt;span style=&quot;&quot;&gt;    &lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;GramE&quot;&gt;&lt;b&gt;&lt;span style=&quot;font-size: 10pt; color: rgb(127, 127, 127); font-family: &#39;Courier New&#39;;&quot;&gt;while&lt;/span&gt;&lt;/b&gt;&lt;/span&gt;&lt;span style=&quot;font-size: 10pt; color: black; font-family: &#39;Courier New&#39;;&quot;&gt;  (!&lt;/span&gt;&lt;span class=&quot;SpellE&quot;&gt;&lt;b&gt;&lt;span style=&quot;font-size: 10pt; color: rgb(27, 27, 215); font-family: &#39;Courier New&#39;;&quot;&gt;unvisited&lt;/span&gt;&lt;/b&gt;&lt;span style=&quot;font-size: 10pt; color: black; font-family: &#39;Courier New&#39;;&quot;&gt;.&lt;/span&gt;&lt;b&gt;&lt;span style=&quot;font-size: 10pt; color: dodgerblue; font-family: &#39;Courier New&#39;;&quot;&gt;isEmpty&lt;/span&gt;&lt;/b&gt;&lt;/span&gt;&lt;span style=&quot;font-size: 10pt; color: black; font-family: &#39;Courier New&#39;;&quot;&gt;)&lt;span style=&quot;&quot;&gt;  &lt;/span&gt;{ &lt;/span&gt;&lt;span style=&quot;font-size: 10pt; font-family: &#39;Courier New&#39;;&quot;&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;font-size: 10pt; color: black; font-family: &#39;Courier New&#39;;&quot;&gt;&lt;span style=&quot;&quot;&gt;      &lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;SpellE&quot;&gt;&lt;span class=&quot;GramE&quot;&gt;&lt;b&gt;&lt;span style=&quot;font-size: 10pt; color: rgb(127, 127, 127); font-family: &#39;Courier New&#39;;&quot;&gt;val&lt;/span&gt;&lt;/b&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;font-size: 10pt; color: black; font-family: &#39;Courier New&#39;;&quot;&gt; &lt;/span&gt;&lt;span class=&quot;SpellE&quot;&gt;&lt;b&gt;&lt;span style=&quot;font-size: 10pt; color: rgb(27, 27, 215); font-family: &#39;Courier New&#39;;&quot;&gt;vertx&lt;/span&gt;&lt;/b&gt;&lt;/span&gt;&lt;span style=&quot;font-size: 10pt; color: black; font-family: &#39;Courier New&#39;;&quot;&gt;=&lt;/span&gt;&lt;b&gt;&lt;span style=&quot;font-size: 10pt; color: dodgerblue; font-family: &#39;Courier New&#39;;&quot;&gt;min&lt;/span&gt;&lt;/b&gt;&lt;span style=&quot;font-size: 10pt; color: black; font-family: &#39;Courier New&#39;;&quot;&gt;(&lt;/span&gt;&lt;b&gt;&lt;span style=&quot;font-size: 10pt; color: rgb(27, 27, 215); font-family: &#39;Courier New&#39;;&quot;&gt;unvisited&lt;/span&gt;&lt;/b&gt;&lt;span style=&quot;font-size: 10pt; color: black; font-family: &#39;Courier New&#39;;&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;font-size: 10pt; font-family: &#39;Courier New&#39;;&quot;&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;font-size: 10pt; color: black; font-family: &#39;Courier New&#39;;&quot;&gt;&lt;span style=&quot;&quot;&gt;      &lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;SpellE&quot;&gt;&lt;span class=&quot;GramE&quot;&gt;&lt;b&gt;&lt;span style=&quot;font-size: 10pt; color: rgb(27, 27, 215); font-family: &#39;Courier New&#39;;&quot;&gt;vertx&lt;/span&gt;&lt;/b&gt;&lt;span style=&quot;font-size: 10pt; color: black; font-family: &#39;Courier New&#39;;&quot;&gt;.&lt;/span&gt;&lt;b&gt;&lt;span style=&quot;font-size: 10pt; color: rgb(27, 27, 215); font-family: &#39;Courier New&#39;;&quot;&gt;transitions&lt;/span&gt;&lt;/b&gt;&lt;span style=&quot;font-size: 10pt; color: black; font-family: &#39;Courier New&#39;;&quot;&gt;.&lt;/span&gt;&lt;b&gt;&lt;span style=&quot;font-size: 10pt; color: dodgerblue; font-family: &#39;Courier New&#39;;&quot;&gt;map&lt;/span&gt;&lt;/b&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;GramE&quot;&gt;&lt;span style=&quot;font-size: 10pt; color: black; font-family: &#39;Courier New&#39;;&quot;&gt;(&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;SpellE&quot;&gt;&lt;b&gt;&lt;span style=&quot;font-size: 10pt; color: dodgerblue; font-family: &#39;Courier New&#39;;&quot;&gt;improveDistance&lt;/span&gt;&lt;/b&gt;&lt;/span&gt;&lt;span style=&quot;font-size: 10pt; color: black; font-family: &#39;Courier New&#39;;&quot;&gt;(_))&lt;/span&gt;&lt;span style=&quot;font-size: 10pt; font-family: &#39;Courier New&#39;;&quot;&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;font-size: 10pt; color: black; font-family: &#39;Courier New&#39;;&quot;&gt;&lt;span style=&quot;&quot;&gt;      &lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;GramE&quot;&gt;&lt;b&gt;&lt;span style=&quot;font-size: 10pt; color: rgb(27, 27, 215); font-family: &#39;Courier New&#39;;&quot;&gt;unvisited&lt;/span&gt;&lt;/b&gt;&lt;span style=&quot;font-size: 10pt; color: black; font-family: &#39;Courier New&#39;;&quot;&gt;=&lt;/span&gt;&lt;/span&gt;&lt;b&gt;&lt;span style=&quot;font-size: 10pt; color: rgb(27, 27, 215); font-family: &#39;Courier New&#39;;&quot;&gt;unvisited&lt;/span&gt;&lt;/b&gt;&lt;span style=&quot;font-size: 10pt; color: black; font-family: &#39;Courier New&#39;;&quot;&gt;-&lt;/span&gt;&lt;span class=&quot;SpellE&quot;&gt;&lt;b&gt;&lt;span style=&quot;font-size: 10pt; color: rgb(27, 27, 215); font-family: &#39;Courier New&#39;;&quot;&gt;vertx&lt;/span&gt;&lt;/b&gt;&lt;/span&gt;&lt;span style=&quot;font-size: 10pt; font-family: &#39;Courier New&#39;;&quot;&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;font-size: 10pt; color: black; font-family: &#39;Courier New&#39;;&quot;&gt;&lt;span style=&quot;&quot;&gt;    &lt;/span&gt;}&lt;/span&gt;&lt;span style=&quot;font-size: 10pt; font-family: &#39;Courier New&#39;;&quot;&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;font-size: 10pt; color: black; font-family: &#39;Courier New&#39;;&quot;&gt;&lt;span style=&quot;&quot;&gt;  &lt;/span&gt;}&lt;/span&gt;&lt;span style=&quot;font-size: 10pt; font-family: &#39;Courier New&#39;;&quot;&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;font-size: 10pt; color: black; font-family: &#39;Courier New&#39;;&quot;&gt;&lt;span style=&quot;&quot;&gt;  &lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;font-size: 10pt; font-family: &#39;Courier New&#39;;&quot;&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;font-size: 10pt; color: black; font-family: &#39;Courier New&#39;;&quot;&gt;&lt;span style=&quot;&quot;&gt;  &lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;GramE&quot;&gt;&lt;b&gt;&lt;span style=&quot;font-size: 10pt; color: rgb(127, 127, 127); font-family: &#39;Courier New&#39;;&quot;&gt;def&lt;/span&gt;&lt;/b&gt;&lt;/span&gt;&lt;span style=&quot;font-size: 10pt; color: black; font-family: &#39;Courier New&#39;;&quot;&gt; &lt;/span&gt;&lt;span class=&quot;SpellE&quot;&gt;&lt;b&gt;&lt;span style=&quot;font-size: 10pt; color: dodgerblue; font-family: &#39;Courier New&#39;;&quot;&gt;improveDistance&lt;/span&gt;&lt;/b&gt;&lt;/span&gt;&lt;span style=&quot;font-size: 10pt; color: black; font-family: &#39;Courier New&#39;;&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;SpellE&quot;&gt;&lt;b&gt;&lt;i&gt;&lt;span style=&quot;font-size: 10pt; color: rgb(27, 27, 215); font-family: &#39;Courier New&#39;;&quot;&gt;a&lt;/span&gt;&lt;/i&gt;&lt;/b&gt;&lt;span style=&quot;font-size: 10pt; color: black; font-family: &#39;Courier New&#39;;&quot;&gt;:&lt;/span&gt;&lt;b&gt;&lt;span style=&quot;font-size: 10pt; color: brown; font-family: &#39;Courier New&#39;;&quot;&gt;DfsArc&lt;/span&gt;&lt;/b&gt;&lt;/span&gt;&lt;span style=&quot;font-size: 10pt; color: black; font-family: &#39;Courier New&#39;;&quot;&gt;)  ={&lt;/span&gt;&lt;span style=&quot;font-size: 10pt; font-family: &#39;Courier New&#39;;&quot;&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;font-size: 10pt; color: black; font-family: &#39;Courier New&#39;;&quot;&gt;&lt;span style=&quot;&quot;&gt;    &lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;GramE&quot;&gt;&lt;b&gt;&lt;span style=&quot;font-size: 10pt; color: rgb(127, 127, 127); font-family: &#39;Courier New&#39;;&quot;&gt;if&lt;/span&gt;&lt;/b&gt;&lt;/span&gt;&lt;span style=&quot;font-size: 10pt; color: black; font-family: &#39;Courier New&#39;;&quot;&gt; (&lt;/span&gt;&lt;span class=&quot;SpellE&quot;&gt;&lt;b&gt;&lt;i&gt;&lt;span style=&quot;font-size: 10pt; color: rgb(27, 27, 215); font-family: &#39;Courier New&#39;;&quot;&gt;a&lt;/span&gt;&lt;/i&gt;&lt;/b&gt;&lt;span style=&quot;font-size: 10pt; color: black; font-family: &#39;Courier New&#39;;&quot;&gt;.&lt;/span&gt;&lt;b&gt;&lt;span style=&quot;font-size: 10pt; color: rgb(27, 27, 215); font-family: &#39;Courier New&#39;;&quot;&gt;start&lt;/span&gt;&lt;/b&gt;&lt;span style=&quot;font-size: 10pt; color: black; font-family: &#39;Courier New&#39;;&quot;&gt;.&lt;/span&gt;&lt;b&gt;&lt;span style=&quot;font-size: 10pt; color: rgb(27, 27, 215); font-family: &#39;Courier New&#39;;&quot;&gt;weight&lt;/span&gt;&lt;/b&gt;&lt;span style=&quot;font-size: 10pt; color: black; font-family: &#39;Courier New&#39;;&quot;&gt;+&lt;/span&gt;&lt;b&gt;&lt;i&gt;&lt;span style=&quot;font-size: 10pt; color: rgb(27, 27, 215); font-family: &#39;Courier New&#39;;&quot;&gt;a&lt;/span&gt;&lt;/i&gt;&lt;/b&gt;&lt;span style=&quot;font-size: 10pt; color: black; font-family: &#39;Courier New&#39;;&quot;&gt;.&lt;/span&gt;&lt;b&gt;&lt;span style=&quot;font-size: 10pt; color: rgb(27, 27, 215); font-family: &#39;Courier New&#39;;&quot;&gt;weight&lt;/span&gt;&lt;/b&gt;&lt;/span&gt;&lt;b&gt;&lt;span style=&quot;font-size: 10pt; color: dodgerblue; font-family: &#39;Courier New&#39;;&quot;&gt;&lt;&lt;/span&gt;&lt;/b&gt;&lt;span style=&quot;font-size: 10pt; color: black; font-family: &#39;Courier New&#39;;&quot;&gt; &lt;/span&gt;&lt;span class=&quot;SpellE&quot;&gt;&lt;b&gt;&lt;i&gt;&lt;span style=&quot;font-size: 10pt; color: rgb(27, 27, 215); font-family: &#39;Courier New&#39;;&quot;&gt;a&lt;/span&gt;&lt;/i&gt;&lt;/b&gt;&lt;span style=&quot;font-size: 10pt; color: black; font-family: &#39;Courier New&#39;;&quot;&gt;.&lt;/span&gt;&lt;b&gt;&lt;span style=&quot;font-size: 10pt; color: rgb(27, 27, 215); font-family: &#39;Courier New&#39;;&quot;&gt;end&lt;/span&gt;&lt;/b&gt;&lt;span style=&quot;font-size: 10pt; color: black; font-family: &#39;Courier New&#39;;&quot;&gt;.&lt;/span&gt;&lt;b&gt;&lt;span style=&quot;font-size: 10pt; color: rgb(27, 27, 215); font-family: &#39;Courier New&#39;;&quot;&gt;weight&lt;/span&gt;&lt;/b&gt;&lt;/span&gt;&lt;span style=&quot;font-size: 10pt; color: black; font-family: &#39;Courier New&#39;;&quot;&gt;)  {&lt;/span&gt;&lt;span style=&quot;font-size: 10pt; font-family: &#39;Courier New&#39;;&quot;&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;font-size: 10pt; color: black; font-family: &#39;Courier New&#39;;&quot;&gt;&lt;span style=&quot;&quot;&gt;      &lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;SpellE&quot;&gt;&lt;b&gt;&lt;i&gt;&lt;span style=&quot;font-size: 10pt; color: rgb(27, 27, 215); font-family: &#39;Courier New&#39;;&quot;&gt;a&lt;/span&gt;&lt;/i&gt;&lt;/b&gt;&lt;span style=&quot;font-size: 10pt; color: black; font-family: &#39;Courier New&#39;;&quot;&gt;.&lt;/span&gt;&lt;b&gt;&lt;span style=&quot;font-size: 10pt; color: rgb(27, 27, 215); font-family: &#39;Courier New&#39;;&quot;&gt;end&lt;/span&gt;&lt;/b&gt;&lt;span style=&quot;font-size: 10pt; color: black; font-family: &#39;Courier New&#39;;&quot;&gt;.&lt;/span&gt;&lt;b&gt;&lt;span style=&quot;font-size: 10pt; color: rgb(27, 27, 215); font-family: &#39;Courier New&#39;;&quot;&gt;weight&lt;/span&gt;&lt;/b&gt;&lt;/span&gt;&lt;span style=&quot;font-size: 10pt; color: black; font-family: &#39;Courier New&#39;;&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;SpellE&quot;&gt;&lt;b&gt;&lt;i&gt;&lt;span style=&quot;font-size: 10pt; color: rgb(27, 27, 215); font-family: &#39;Courier New&#39;;&quot;&gt;a&lt;/span&gt;&lt;/i&gt;&lt;/b&gt;&lt;span style=&quot;font-size: 10pt; color: black; font-family: &#39;Courier New&#39;;&quot;&gt;.&lt;/span&gt;&lt;b&gt;&lt;span style=&quot;font-size: 10pt; color: rgb(27, 27, 215); font-family: &#39;Courier New&#39;;&quot;&gt;start&lt;/span&gt;&lt;/b&gt;&lt;span style=&quot;font-size: 10pt; color: black; font-family: &#39;Courier New&#39;;&quot;&gt;.&lt;/span&gt;&lt;b&gt;&lt;span style=&quot;font-size: 10pt; color: rgb(27, 27, 215); font-family: &#39;Courier New&#39;;&quot;&gt;weight&lt;/span&gt;&lt;/b&gt;&lt;span style=&quot;font-size: 10pt; color: black; font-family: &#39;Courier New&#39;;&quot;&gt;+&lt;/span&gt;&lt;b&gt;&lt;i&gt;&lt;span style=&quot;font-size: 10pt; color: rgb(27, 27, 215); font-family: &#39;Courier New&#39;;&quot;&gt;a&lt;/span&gt;&lt;/i&gt;&lt;/b&gt;&lt;span style=&quot;font-size: 10pt; color: black; font-family: &#39;Courier New&#39;;&quot;&gt;.&lt;/span&gt;&lt;b&gt;&lt;span style=&quot;font-size: 10pt; color: rgb(27, 27, 215); font-family: &#39;Courier New&#39;;&quot;&gt;weight&lt;/span&gt;&lt;/b&gt;&lt;/span&gt;&lt;span style=&quot;font-size: 10pt; font-family: &#39;Courier New&#39;;&quot;&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;font-size: 10pt; color: black; font-family: &#39;Courier New&#39;;&quot;&gt;&lt;span style=&quot;&quot;&gt;      &lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;SpellE&quot;&gt;&lt;b&gt;&lt;i&gt;&lt;span style=&quot;font-size: 10pt; color: rgb(27, 27, 215); font-family: &#39;Courier New&#39;;&quot;&gt;a&lt;/span&gt;&lt;/i&gt;&lt;/b&gt;&lt;span style=&quot;font-size: 10pt; color: black; font-family: &#39;Courier New&#39;;&quot;&gt;.&lt;/span&gt;&lt;b&gt;&lt;span style=&quot;font-size: 10pt; color: rgb(27, 27, 215); font-family: &#39;Courier New&#39;;&quot;&gt;end&lt;/span&gt;&lt;/b&gt;&lt;span style=&quot;font-size: 10pt; color: black; font-family: &#39;Courier New&#39;;&quot;&gt;.&lt;/span&gt;&lt;b&gt;&lt;span style=&quot;font-size: 10pt; color: rgb(27, 27, 215); font-family: &#39;Courier New&#39;;&quot;&gt;previous&lt;/span&gt;&lt;/b&gt;&lt;/span&gt;&lt;span style=&quot;font-size: 10pt; color: black; font-family: &#39;Courier New&#39;;&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;SpellE&quot;&gt;&lt;b&gt;&lt;i&gt;&lt;span style=&quot;font-size: 10pt; color: rgb(27, 27, 215); font-family: &#39;Courier New&#39;;&quot;&gt;a&lt;/span&gt;&lt;/i&gt;&lt;/b&gt;&lt;span style=&quot;font-size: 10pt; color: black; font-family: &#39;Courier New&#39;;&quot;&gt;.&lt;/span&gt;&lt;b&gt;&lt;span style=&quot;font-size: 10pt; color: rgb(27, 27, 215); font-family: &#39;Courier New&#39;;&quot;&gt;start&lt;/span&gt;&lt;/b&gt;&lt;/span&gt;&lt;span style=&quot;font-size: 10pt; font-family: &#39;Courier New&#39;;&quot;&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;font-size: 10pt; color: black; font-family: &#39;Courier New&#39;;&quot;&gt;&lt;span style=&quot;&quot;&gt;    &lt;/span&gt;}&lt;/span&gt;&lt;span style=&quot;font-size: 10pt; font-family: &#39;Courier New&#39;;&quot;&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;font-size: 10pt; color: black; font-family: &#39;Courier New&#39;;&quot;&gt;&lt;span style=&quot;&quot;&gt;  &lt;/span&gt;}&lt;/span&gt;&lt;span style=&quot;font-size: 10pt; font-family: &#39;Courier New&#39;;&quot;&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;font-size: 10pt; color: black; font-family: &#39;Courier New&#39;;&quot;&gt;&lt;span style=&quot;&quot;&gt;  &lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;font-size: 10pt; font-family: &#39;Courier New&#39;;&quot;&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;font-size: 10pt; color: black; font-family: &#39;Courier New&#39;;&quot;&gt;&lt;span style=&quot;&quot;&gt;  &lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;GramE&quot;&gt;&lt;b&gt;&lt;span style=&quot;font-size: 10pt; color: rgb(127, 127, 127); font-family: &#39;Courier New&#39;;&quot;&gt;def&lt;/span&gt;&lt;/b&gt;&lt;/span&gt;&lt;span style=&quot;font-size: 10pt; color: black; font-family: &#39;Courier New&#39;;&quot;&gt;  &lt;/span&gt;&lt;b&gt;&lt;span style=&quot;font-size: 10pt; color: dodgerblue; font-family: &#39;Courier New&#39;;&quot;&gt;min&lt;/span&gt;&lt;/b&gt;&lt;span style=&quot;font-size: 10pt; color: black; font-family: &#39;Courier New&#39;;&quot;&gt;(&lt;/span&gt;&lt;b&gt;&lt;i&gt;&lt;span style=&quot;font-size: 10pt; color: rgb(27, 27, 215); font-family: &#39;Courier New&#39;;&quot;&gt;nodes&lt;/span&gt;&lt;/i&gt;&lt;/b&gt;&lt;span style=&quot;font-size: 10pt; color: black; font-family: &#39;Courier New&#39;;&quot;&gt;:  &lt;/span&gt;&lt;b&gt;&lt;span style=&quot;font-size: 10pt; color: brown; font-family: &#39;Courier New&#39;;&quot;&gt;Set&lt;/span&gt;&lt;/b&gt;&lt;span style=&quot;font-size: 10pt; color: black; font-family: &#39;Courier New&#39;;&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;SpellE&quot;&gt;&lt;b&gt;&lt;span style=&quot;font-size: 10pt; color: brown; font-family: &#39;Courier New&#39;;&quot;&gt;DfsNode&lt;/span&gt;&lt;/b&gt;&lt;/span&gt;&lt;span style=&quot;font-size: 10pt; color: black; font-family: &#39;Courier New&#39;;&quot;&gt;]):  &lt;/span&gt;&lt;span class=&quot;SpellE&quot;&gt;&lt;b&gt;&lt;span style=&quot;font-size: 10pt; color: brown; font-family: &#39;Courier New&#39;;&quot;&gt;DfsNode&lt;/span&gt;&lt;/b&gt;&lt;/span&gt;&lt;span style=&quot;font-size: 10pt; color: black; font-family: &#39;Courier New&#39;;&quot;&gt; =  {&lt;/span&gt;&lt;span style=&quot;font-size: 10pt; font-family: &#39;Courier New&#39;;&quot;&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;font-size: 10pt; color: black; font-family: &#39;Courier New&#39;;&quot;&gt;&lt;span style=&quot;&quot;&gt;    &lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;SpellE&quot;&gt;&lt;span class=&quot;GramE&quot;&gt;&lt;b&gt;&lt;i&gt;&lt;span style=&quot;font-size: 10pt; color: rgb(27, 27, 215); font-family: &#39;Courier New&#39;;&quot;&gt;nodes&lt;/span&gt;&lt;/i&gt;&lt;/b&gt;&lt;span style=&quot;font-size: 10pt; color: black; font-family: &#39;Courier New&#39;;&quot;&gt;.&lt;/span&gt;&lt;b&gt;&lt;span style=&quot;font-size: 10pt; color: dodgerblue; font-family: &#39;Courier New&#39;;&quot;&gt;reduceLeft&lt;/span&gt;&lt;/b&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;GramE&quot;&gt;&lt;span style=&quot;font-size: 10pt; color: black; font-family: &#39;Courier New&#39;;&quot;&gt;(&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;font-size: 10pt; color: black; font-family: &#39;Courier New&#39;;&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;SpellE&quot;&gt;&lt;b&gt;&lt;i&gt;&lt;span style=&quot;font-size: 10pt; color: rgb(27, 27, 215); font-family: &#39;Courier New&#39;;&quot;&gt;a&lt;/span&gt;&lt;/i&gt;&lt;/b&gt;&lt;span style=&quot;font-size: 10pt; color: black; font-family: &#39;Courier New&#39;;&quot;&gt;:&lt;/span&gt;&lt;b&gt;&lt;span style=&quot;font-size: 10pt; color: brown; font-family: &#39;Courier New&#39;;&quot;&gt;DfsNode&lt;/span&gt;&lt;/b&gt;&lt;span style=&quot;font-size: 10pt; color: black; font-family: &#39;Courier New&#39;;&quot;&gt;,&lt;/span&gt;&lt;b&gt;&lt;i&gt;&lt;span style=&quot;font-size: 10pt; color: rgb(27, 27, 215); font-family: &#39;Courier New&#39;;&quot;&gt;b&lt;/span&gt;&lt;/i&gt;&lt;/b&gt;&lt;span style=&quot;font-size: 10pt; color: black; font-family: &#39;Courier New&#39;;&quot;&gt;:&lt;/span&gt;&lt;b&gt;&lt;span style=&quot;font-size: 10pt; color: brown; font-family: &#39;Courier New&#39;;&quot;&gt;DfsNode&lt;/span&gt;&lt;/b&gt;&lt;/span&gt;&lt;span style=&quot;font-size: 10pt; color: black; font-family: &#39;Courier New&#39;;&quot;&gt;)=&gt;&lt;/span&gt;&lt;b&gt;&lt;span style=&quot;font-size: 10pt; color: rgb(127, 127, 127); font-family: &#39;Courier New&#39;;&quot;&gt;if&lt;/span&gt;&lt;/b&gt;&lt;span style=&quot;font-size: 10pt; color: black; font-family: &#39;Courier New&#39;;&quot;&gt; (&lt;/span&gt;&lt;span class=&quot;SpellE&quot;&gt;&lt;b&gt;&lt;i&gt;&lt;span style=&quot;font-size: 10pt; color: rgb(27, 27, 215); font-family: &#39;Courier New&#39;;&quot;&gt;a&lt;/span&gt;&lt;/i&gt;&lt;/b&gt;&lt;span style=&quot;font-size: 10pt; color: black; font-family: &#39;Courier New&#39;;&quot;&gt;.&lt;/span&gt;&lt;b&gt;&lt;span style=&quot;font-size: 10pt; color: rgb(27, 27, 215); font-family: &#39;Courier New&#39;;&quot;&gt;weight&lt;/span&gt;&lt;/b&gt;&lt;/span&gt;&lt;span style=&quot;font-size: 10pt; color: black; font-family: &#39;Courier New&#39;;&quot;&gt;&lt;&lt;/span&gt;&lt;span class=&quot;SpellE&quot;&gt;&lt;b&gt;&lt;i&gt;&lt;span style=&quot;font-size: 10pt; color: rgb(27, 27, 215); font-family: &#39;Courier New&#39;;&quot;&gt;b&lt;/span&gt;&lt;/i&gt;&lt;/b&gt;&lt;span style=&quot;font-size: 10pt; color: black; font-family: &#39;Courier New&#39;;&quot;&gt;.&lt;/span&gt;&lt;b&gt;&lt;span style=&quot;font-size: 10pt; color: rgb(27, 27, 215); font-family: &#39;Courier New&#39;;&quot;&gt;weight&lt;/span&gt;&lt;/b&gt;&lt;/span&gt;&lt;span style=&quot;font-size: 10pt; color: black; font-family: &#39;Courier New&#39;;&quot;&gt;)  &lt;/span&gt;&lt;b&gt;&lt;i&gt;&lt;span style=&quot;font-size: 10pt; color: rgb(27, 27, 215); font-family: &#39;Courier New&#39;;&quot;&gt;a&lt;/span&gt;&lt;/i&gt;&lt;/b&gt;&lt;span style=&quot;font-size: 10pt; color: black; font-family: &#39;Courier New&#39;;&quot;&gt;  &lt;/span&gt;&lt;b&gt;&lt;span style=&quot;font-size: 10pt; color: rgb(127, 127, 127); font-family: &#39;Courier New&#39;;&quot;&gt;else&lt;/span&gt;&lt;/b&gt;&lt;span style=&quot;font-size: 10pt; color: black; font-family: &#39;Courier New&#39;;&quot;&gt;  &lt;/span&gt;&lt;b&gt;&lt;i&gt;&lt;span style=&quot;font-size: 10pt; color: rgb(27, 27, 215); font-family: &#39;Courier New&#39;;&quot;&gt;b&lt;/span&gt;&lt;/i&gt;&lt;/b&gt;&lt;span style=&quot;font-size: 10pt; color: black; font-family: &#39;Courier New&#39;;&quot;&gt; )&lt;/span&gt;&lt;span style=&quot;font-size: 10pt; font-family: &#39;Courier New&#39;;&quot;&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;font-size: 10pt; color: black; font-family: &#39;Courier New&#39;;&quot;&gt;&lt;span style=&quot;&quot;&gt;  &lt;/span&gt;}&lt;/span&gt;&lt;span style=&quot;font-size: 10pt; font-family: &#39;Courier New&#39;;&quot;&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;font-size: 10pt; color: black; font-family: &#39;Courier New&#39;;&quot;&gt;&lt;span style=&quot;&quot;&gt;  &lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;font-size: 10pt; font-family: &#39;Courier New&#39;;&quot;&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;font-size: 10pt; color: black; font-family: &#39;Courier New&#39;;&quot;&gt;&lt;span style=&quot;&quot;&gt;  &lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;GramE&quot;&gt;&lt;b&gt;&lt;span style=&quot;font-size: 10pt; color: rgb(127, 127, 127); font-family: &#39;Courier New&#39;;&quot;&gt;def&lt;/span&gt;&lt;/b&gt;&lt;/span&gt;&lt;span style=&quot;font-size: 10pt; color: black; font-family: &#39;Courier New&#39;;&quot;&gt; &lt;/span&gt;&lt;span class=&quot;SpellE&quot;&gt;&lt;b&gt;&lt;span style=&quot;font-size: 10pt; color: dodgerblue; font-family: &#39;Courier New&#39;;&quot;&gt;pathTo&lt;/span&gt;&lt;/b&gt;&lt;/span&gt;&lt;span style=&quot;font-size: 10pt; color: black; font-family: &#39;Courier New&#39;;&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;SpellE&quot;&gt;&lt;b&gt;&lt;i&gt;&lt;span style=&quot;font-size: 10pt; color: rgb(27, 27, 215); font-family: &#39;Courier New&#39;;&quot;&gt;end&lt;/span&gt;&lt;/i&gt;&lt;/b&gt;&lt;span style=&quot;font-size: 10pt; color: black; font-family: &#39;Courier New&#39;;&quot;&gt;:&lt;/span&gt;&lt;b&gt;&lt;span style=&quot;font-size: 10pt; color: brown; font-family: &#39;Courier New&#39;;&quot;&gt;DfsNode&lt;/span&gt;&lt;/b&gt;&lt;/span&gt;&lt;span style=&quot;font-size: 10pt; color: black; font-family: &#39;Courier New&#39;;&quot;&gt;):&lt;/span&gt;&lt;b&gt;&lt;span style=&quot;font-size: 10pt; color: brown; font-family: &#39;Courier New&#39;;&quot;&gt;List&lt;/span&gt;&lt;/b&gt;&lt;span style=&quot;font-size: 10pt; color: black; font-family: &#39;Courier New&#39;;&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;SpellE&quot;&gt;&lt;b&gt;&lt;span style=&quot;font-size: 10pt; color: brown; font-family: &#39;Courier New&#39;;&quot;&gt;DfsNode&lt;/span&gt;&lt;/b&gt;&lt;/span&gt;&lt;span style=&quot;font-size: 10pt; color: black; font-family: &#39;Courier New&#39;;&quot;&gt;] =  {&lt;/span&gt;&lt;span style=&quot;font-size: 10pt; font-family: &#39;Courier New&#39;;&quot;&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;font-size: 10pt; color: black; font-family: &#39;Courier New&#39;;&quot;&gt;&lt;span style=&quot;&quot;&gt;    &lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;GramE&quot;&gt;&lt;b&gt;&lt;span style=&quot;font-size: 10pt; color: rgb(127, 127, 127); font-family: &#39;Courier New&#39;;&quot;&gt;if&lt;/span&gt;&lt;/b&gt;&lt;/span&gt;&lt;span style=&quot;font-size: 10pt; color: black; font-family: &#39;Courier New&#39;;&quot;&gt;  (&lt;/span&gt;&lt;b&gt;&lt;i&gt;&lt;span style=&quot;font-size: 10pt; color: rgb(27, 27, 215); font-family: &#39;Courier New&#39;;&quot;&gt;end&lt;/span&gt;&lt;/i&gt;&lt;/b&gt;&lt;span style=&quot;font-size: 10pt; color: black; font-family: &#39;Courier New&#39;;&quot;&gt;  &lt;/span&gt;&lt;b&gt;&lt;span style=&quot;font-size: 10pt; color: dodgerblue; font-family: &#39;Courier New&#39;;&quot;&gt;==&lt;/span&gt;&lt;/b&gt;&lt;span style=&quot;font-size: 10pt; color: black; font-family: &#39;Courier New&#39;;&quot;&gt;  &lt;/span&gt;&lt;b&gt;&lt;span style=&quot;font-size: 10pt; color: rgb(127, 127, 127); font-family: &#39;Courier New&#39;;&quot;&gt;null&lt;/span&gt;&lt;/b&gt;&lt;span style=&quot;font-size: 10pt; color: black; font-family: &#39;Courier New&#39;;&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;font-size: 10pt; font-family: &#39;Courier New&#39;;&quot;&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;font-size: 10pt; color: black; font-family: &#39;Courier New&#39;;&quot;&gt;&lt;span style=&quot;&quot;&gt;      &lt;/span&gt;&lt;/span&gt;&lt;b&gt;&lt;span style=&quot;font-size: 10pt; color: brown; font-family: &#39;Courier New&#39;;&quot;&gt;Nil&lt;/span&gt;&lt;/b&gt;&lt;span style=&quot;font-size: 10pt; font-family: &#39;Courier New&#39;;&quot;&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;font-size: 10pt; color: black; font-family: &#39;Courier New&#39;;&quot;&gt;&lt;span style=&quot;&quot;&gt;    &lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;GramE&quot;&gt;&lt;b&gt;&lt;span style=&quot;font-size: 10pt; color: rgb(127, 127, 127); font-family: &#39;Courier New&#39;;&quot;&gt;else&lt;/span&gt;&lt;/b&gt;&lt;/span&gt;&lt;span style=&quot;font-size: 10pt; color: black; font-family: &#39;Courier New&#39;;&quot;&gt; &lt;/span&gt;&lt;span style=&quot;font-size: 10pt; font-family: &#39;Courier New&#39;;&quot;&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;font-size: 10pt; color: black; font-family: &#39;Courier New&#39;;&quot;&gt;&lt;span style=&quot;&quot;&gt;      &lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;GramE&quot;&gt;&lt;b&gt;&lt;i&gt;&lt;span style=&quot;font-size: 10pt; color: rgb(27, 27, 215); font-family: &#39;Courier New&#39;;&quot;&gt;end&lt;/span&gt;&lt;/i&gt;&lt;/b&gt;&lt;span style=&quot;font-size: 10pt; color: black; font-family: &#39;Courier New&#39;;&quot;&gt;  &lt;/span&gt;&lt;b&gt;&lt;span style=&quot;font-size: 10pt; color: dodgerblue; font-family: &#39;Courier New&#39;;&quot;&gt;:&lt;/span&gt;&lt;/b&gt;&lt;/span&gt;&lt;b&gt;&lt;span style=&quot;font-size: 10pt; color: dodgerblue; font-family: &#39;Courier New&#39;;&quot;&gt;:&lt;/span&gt;&lt;/b&gt;&lt;span style=&quot;font-size: 10pt; color: black; font-family: &#39;Courier New&#39;;&quot;&gt; &lt;/span&gt;&lt;span class=&quot;SpellE&quot;&gt;&lt;b&gt;&lt;span style=&quot;font-size: 10pt; color: dodgerblue; font-family: &#39;Courier New&#39;;&quot;&gt;pathTo&lt;/span&gt;&lt;/b&gt;&lt;/span&gt;&lt;span style=&quot;font-size: 10pt; color: black; font-family: &#39;Courier New&#39;;&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;SpellE&quot;&gt;&lt;b&gt;&lt;i&gt;&lt;span style=&quot;font-size: 10pt; color: rgb(27, 27, 215); font-family: &#39;Courier New&#39;;&quot;&gt;end&lt;/span&gt;&lt;/i&gt;&lt;/b&gt;&lt;span style=&quot;font-size: 10pt; color: black; font-family: &#39;Courier New&#39;;&quot;&gt;.&lt;/span&gt;&lt;b&gt;&lt;span style=&quot;font-size: 10pt; color: rgb(27, 27, 215); font-family: &#39;Courier New&#39;;&quot;&gt;previous&lt;/span&gt;&lt;/b&gt;&lt;/span&gt;&lt;span style=&quot;font-size: 10pt; color: black; font-family: &#39;Courier New&#39;;&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;font-size: 10pt; font-family: &#39;Courier New&#39;;&quot;&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;font-size: 10pt; color: black; font-family: &#39;Courier New&#39;;&quot;&gt;&lt;span style=&quot;&quot;&gt;  &lt;/span&gt;}&lt;span style=&quot;&quot;&gt;   &lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;font-size: 10pt; font-family: &#39;Courier New&#39;;&quot;&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;font-size: 10pt; color: black; font-family: &#39;Courier New&#39;;&quot;&gt;}&lt;/span&gt;&lt;span style=&quot;font-size: 10pt; font-family: Arial;&quot;&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;br /&gt;&lt;b&gt;&lt;span style=&quot;font-size: 10pt; color: rgb(127, 127, 127); font-family: &#39;Courier New&#39;;&quot;&gt;&lt;o:p&gt; &lt;/o:p&gt;&lt;/span&gt;&lt;/b&gt;&lt;/p&gt;  &lt;p class=&quot;MsoNormal&quot; style=&quot;&quot;&gt;&lt;span style=&quot;font-size: 10pt; font-family: Arial;&quot;&gt;What? It doesn&#39;t compile! &lt;span class=&quot;SpellE&quot;&gt;&lt;span class=&quot;GramE&quot;&gt;node.transitions&lt;/span&gt;&lt;/span&gt; returns a list of  Nodes and not &lt;span class=&quot;SpellE&quot;&gt;DfsNodes&lt;/span&gt;! &lt;span class=&quot;SpellE&quot;&gt;Argh&lt;/span&gt;! We&#39;ve been bitten by the static typing! (&quot;Ha-ha&quot; will  shout the Dynamic typing Nelson). I could use a .&lt;span class=&quot;SpellE&quot;&gt;&lt;span class=&quot;GramE&quot;&gt;asInstanceOf&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;GramE&quot;&gt;[&lt;/span&gt;type] everywhere  (like a Java cast) but it looks like a kludge and you have to put everywhere!  There must be a better solution, after all, &lt;span class=&quot;SpellE&quot;&gt;Scala&lt;/span&gt; is  supposed to look elegant, right?&lt;o:p&gt;&lt;br /&gt; &lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot; style=&quot;&quot;&gt;&lt;span style=&quot;font-size: 10pt; font-family: Arial;&quot;&gt;&lt;span style=&quot;font-size:100%;&quot;&gt;&lt;span style=&quot;font-weight: bold;&quot;&gt;Views (implicit  conversions)&lt;/span&gt;&lt;/span&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p class=&quot;MsoNormal&quot; style=&quot;&quot;&gt;&lt;span style=&quot;font-size: 10pt; font-family: Arial;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;SpellE&quot;&gt;&lt;span style=&quot;font-size: 10pt; font-family: Arial;&quot;&gt;Scala&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;font-size: 10pt; font-family: Arial;&quot;&gt; has a very interesting way of  dealing with that kind of problem: by creating &lt;a href=&quot;http://www.scala-lang.org/intro/views.html&quot;&gt;views using implicit conversions&lt;/a&gt;, we can convert  from one type to &lt;span class=&quot;GramE&quot;&gt;other,&lt;/span&gt; the compiler will insert the  appropriate call when needed. So I defined a conversion from Arc to &lt;span class=&quot;SpellE&quot;&gt;DfsArc&lt;/span&gt; and Node to &lt;span class=&quot;SpellE&quot;&gt;DfsNode&lt;/span&gt;:&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;                     &lt;p class=&quot;MsoNormal&quot; style=&quot;&quot;&gt;&lt;span class=&quot;GramE&quot;&gt;&lt;b&gt;&lt;span style=&quot;font-size: 10pt; color: rgb(127, 127, 127); font-family: &#39;Courier New&#39;;&quot;&gt;object&lt;/span&gt;&lt;/b&gt;&lt;/span&gt;&lt;span style=&quot;font-size: 10pt; color: black; font-family: &#39;Courier New&#39;;&quot;&gt; &lt;/span&gt;&lt;span class=&quot;SpellE&quot;&gt;&lt;b&gt;&lt;span style=&quot;font-size: 10pt; color: brown; font-family: &#39;Courier New&#39;;&quot;&gt;Implicits&lt;/span&gt;&lt;/b&gt;&lt;/span&gt;&lt;span style=&quot;font-size: 10pt; color: black; font-family: &#39;Courier New&#39;;&quot;&gt; {&lt;/span&gt;&lt;span style=&quot;font-size: 10pt; font-family: &#39;Courier New&#39;;&quot;&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;font-size: 10pt; color: black; font-family: &#39;Courier New&#39;;&quot;&gt;&lt;span style=&quot;&quot;&gt;  &lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;GramE&quot;&gt;&lt;b&gt;&lt;span style=&quot;font-size: 10pt; color: rgb(127, 127, 127); font-family: &#39;Courier New&#39;;&quot;&gt;implicit&lt;/span&gt;&lt;/b&gt;&lt;/span&gt;&lt;span style=&quot;font-size: 10pt; color: black; font-family: &#39;Courier New&#39;;&quot;&gt;  &lt;/span&gt;&lt;b&gt;&lt;span style=&quot;font-size: 10pt; color: rgb(127, 127, 127); font-family: &#39;Courier New&#39;;&quot;&gt;def&lt;/span&gt;&lt;/b&gt;&lt;span style=&quot;font-size: 10pt; color: black; font-family: &#39;Courier New&#39;;&quot;&gt;  &lt;/span&gt;&lt;b&gt;&lt;span style=&quot;font-size: 10pt; color: dodgerblue; font-family: &#39;Courier New&#39;;&quot;&gt;node2DfsNode&lt;/span&gt;&lt;/b&gt;&lt;span style=&quot;font-size: 10pt; color: black; font-family: &#39;Courier New&#39;;&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;SpellE&quot;&gt;&lt;b&gt;&lt;i&gt;&lt;span style=&quot;font-size: 10pt; color: rgb(27, 27, 215); font-family: &#39;Courier New&#39;;&quot;&gt;node&lt;/span&gt;&lt;/i&gt;&lt;/b&gt;&lt;span style=&quot;font-size: 10pt; color: black; font-family: &#39;Courier New&#39;;&quot;&gt;:&lt;/span&gt;&lt;b&gt;&lt;span style=&quot;font-size: 10pt; color: brown; font-family: &#39;Courier New&#39;;&quot;&gt;Node&lt;/span&gt;&lt;/b&gt;&lt;/span&gt;&lt;span style=&quot;font-size: 10pt; color: black; font-family: &#39;Courier New&#39;;&quot;&gt;):&lt;/span&gt;&lt;span class=&quot;SpellE&quot;&gt;&lt;b&gt;&lt;span style=&quot;font-size: 10pt; color: brown; font-family: &#39;Courier New&#39;;&quot;&gt;DfsNode&lt;/span&gt;&lt;/b&gt;&lt;/span&gt;&lt;span style=&quot;font-size: 10pt; color: black; font-family: &#39;Courier New&#39;;&quot;&gt;={&lt;/span&gt;&lt;span style=&quot;font-size: 10pt; font-family: &#39;Courier New&#39;;&quot;&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;font-size: 10pt; color: black; font-family: &#39;Courier New&#39;;&quot;&gt;&lt;span style=&quot;&quot;&gt;    &lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;GramE&quot;&gt;&lt;b&gt;&lt;span style=&quot;font-size: 10pt; color: rgb(127, 127, 127); font-family: &#39;Courier New&#39;;&quot;&gt;if&lt;/span&gt;&lt;/b&gt;&lt;/span&gt;&lt;span style=&quot;font-size: 10pt; color: black; font-family: &#39;Courier New&#39;;&quot;&gt; (&lt;/span&gt;&lt;span class=&quot;SpellE&quot;&gt;&lt;b&gt;&lt;i&gt;&lt;span style=&quot;font-size: 10pt; color: rgb(27, 27, 215); font-family: &#39;Courier New&#39;;&quot;&gt;node&lt;/span&gt;&lt;/i&gt;&lt;/b&gt;&lt;span style=&quot;font-size: 10pt; color: black; font-family: &#39;Courier New&#39;;&quot;&gt;.&lt;/span&gt;&lt;b&gt;&lt;span style=&quot;font-size: 10pt; color: dodgerblue; font-family: &#39;Courier New&#39;;&quot;&gt;isInstanceOf&lt;/span&gt;&lt;/b&gt;&lt;/span&gt;&lt;span style=&quot;font-size: 10pt; color: black; font-family: &#39;Courier New&#39;;&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;SpellE&quot;&gt;&lt;b&gt;&lt;span style=&quot;font-size: 10pt; color: brown; font-family: &#39;Courier New&#39;;&quot;&gt;DfsNode&lt;/span&gt;&lt;/b&gt;&lt;/span&gt;&lt;span style=&quot;font-size: 10pt; color: black; font-family: &#39;Courier New&#39;;&quot;&gt;])&lt;/span&gt;&lt;span style=&quot;font-size: 10pt; font-family: &#39;Courier New&#39;;&quot;&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;font-size: 10pt; color: black; font-family: &#39;Courier New&#39;;&quot;&gt;&lt;span style=&quot;&quot;&gt;      &lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;SpellE&quot;&gt;&lt;span class=&quot;GramE&quot;&gt;&lt;b&gt;&lt;i&gt;&lt;span style=&quot;font-size: 10pt; color: rgb(27, 27, 215); font-family: &#39;Courier New&#39;;&quot;&gt;node&lt;/span&gt;&lt;/i&gt;&lt;/b&gt;&lt;span style=&quot;font-size: 10pt; color: black; font-family: &#39;Courier New&#39;;&quot;&gt;.&lt;/span&gt;&lt;b&gt;&lt;span style=&quot;font-size: 10pt; color: dodgerblue; font-family: &#39;Courier New&#39;;&quot;&gt;asInstanceOf&lt;/span&gt;&lt;/b&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;GramE&quot;&gt;&lt;span style=&quot;font-size: 10pt; color: black; font-family: &#39;Courier New&#39;;&quot;&gt;[&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;SpellE&quot;&gt;&lt;b&gt;&lt;span style=&quot;font-size: 10pt; color: brown; font-family: &#39;Courier New&#39;;&quot;&gt;DfsNode&lt;/span&gt;&lt;/b&gt;&lt;/span&gt;&lt;span style=&quot;font-size: 10pt; color: black; font-family: &#39;Courier New&#39;;&quot;&gt;]&lt;/span&gt;&lt;span style=&quot;font-size: 10pt; font-family: &#39;Courier New&#39;;&quot;&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;font-size: 10pt; color: black; font-family: &#39;Courier New&#39;;&quot;&gt;&lt;span style=&quot;&quot;&gt;    &lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;GramE&quot;&gt;&lt;b&gt;&lt;span style=&quot;font-size: 10pt; color: rgb(127, 127, 127); font-family: &#39;Courier New&#39;;&quot;&gt;else&lt;/span&gt;&lt;/b&gt;&lt;/span&gt;&lt;span style=&quot;font-size: 10pt; color: black; font-family: &#39;Courier New&#39;;&quot;&gt; {&lt;/span&gt;&lt;span style=&quot;font-size: 10pt; font-family: &#39;Courier New&#39;;&quot;&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;font-size: 10pt; color: black; font-family: &#39;Courier New&#39;;&quot;&gt;&lt;span style=&quot;&quot;&gt;      &lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;SpellE&quot;&gt;&lt;span class=&quot;GramE&quot;&gt;&lt;b&gt;&lt;span style=&quot;font-size: 10pt; color: rgb(127, 127, 127); font-family: &#39;Courier New&#39;;&quot;&gt;var&lt;/span&gt;&lt;/b&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;font-size: 10pt; color: black; font-family: &#39;Courier New&#39;;&quot;&gt; &lt;/span&gt;&lt;span class=&quot;SpellE&quot;&gt;&lt;b&gt;&lt;span style=&quot;font-size: 10pt; color: rgb(27, 27, 215); font-family: &#39;Courier New&#39;;&quot;&gt;dfsNode&lt;/span&gt;&lt;/b&gt;&lt;/span&gt;&lt;span style=&quot;font-size: 10pt; color: black; font-family: &#39;Courier New&#39;;&quot;&gt;=&lt;/span&gt;&lt;b&gt;&lt;span style=&quot;font-size: 10pt; color: rgb(127, 127, 127); font-family: &#39;Courier New&#39;;&quot;&gt;new&lt;/span&gt;&lt;/b&gt;&lt;span style=&quot;font-size: 10pt; color: black; font-family: &#39;Courier New&#39;;&quot;&gt; &lt;/span&gt;&lt;span class=&quot;SpellE&quot;&gt;&lt;b&gt;&lt;span style=&quot;font-size: 10pt; color: brown; font-family: &#39;Courier New&#39;;&quot;&gt;DfsNode&lt;/span&gt;&lt;/b&gt;&lt;/span&gt;&lt;span style=&quot;font-size: 10pt; color: black; font-family: &#39;Courier New&#39;;&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;SpellE&quot;&gt;&lt;b&gt;&lt;i&gt;&lt;span style=&quot;font-size: 10pt; color: rgb(27, 27, 215); font-family: &#39;Courier New&#39;;&quot;&gt;node&lt;/span&gt;&lt;/i&gt;&lt;/b&gt;&lt;span style=&quot;font-size: 10pt; color: black; font-family: &#39;Courier New&#39;;&quot;&gt;.&lt;/span&gt;&lt;b&gt;&lt;span style=&quot;font-size: 10pt; color: rgb(27, 27, 215); font-family: &#39;Courier New&#39;;&quot;&gt;label&lt;/span&gt;&lt;/b&gt;&lt;/span&gt;&lt;span style=&quot;font-size: 10pt; color: black; font-family: &#39;Courier New&#39;;&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;font-size: 10pt; font-family: &#39;Courier New&#39;;&quot;&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;font-size: 10pt; color: black; font-family: &#39;Courier New&#39;;&quot;&gt;&lt;span style=&quot;&quot;&gt;      &lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;SpellE&quot;&gt;&lt;b&gt;&lt;span style=&quot;font-size: 10pt; color: rgb(27, 27, 215); font-family: &#39;Courier New&#39;;&quot;&gt;dfsNode&lt;/span&gt;&lt;/b&gt;&lt;span style=&quot;font-size: 10pt; color: black; font-family: &#39;Courier New&#39;;&quot;&gt;.&lt;/span&gt;&lt;b&gt;&lt;span style=&quot;font-size: 10pt; color: rgb(27, 27, 215); font-family: &#39;Courier New&#39;;&quot;&gt;transitions&lt;/span&gt;&lt;/b&gt;&lt;/span&gt;&lt;span style=&quot;font-size: 10pt; color: black; font-family: &#39;Courier New&#39;;&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;SpellE&quot;&gt;&lt;b&gt;&lt;i&gt;&lt;span style=&quot;font-size: 10pt; color: rgb(27, 27, 215); font-family: &#39;Courier New&#39;;&quot;&gt;node&lt;/span&gt;&lt;/i&gt;&lt;/b&gt;&lt;span style=&quot;font-size: 10pt; color: black; font-family: &#39;Courier New&#39;;&quot;&gt;.&lt;/span&gt;&lt;b&gt;&lt;span style=&quot;font-size: 10pt; color: rgb(27, 27, 215); font-family: &#39;Courier New&#39;;&quot;&gt;transitions&lt;/span&gt;&lt;/b&gt;&lt;/span&gt;&lt;span style=&quot;font-size: 10pt; font-family: &#39;Courier New&#39;;&quot;&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;font-size: 10pt; color: black; font-family: &#39;Courier New&#39;;&quot;&gt;&lt;span style=&quot;&quot;&gt;      &lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;SpellE&quot;&gt;&lt;span class=&quot;GramE&quot;&gt;&lt;b&gt;&lt;span style=&quot;font-size: 10pt; color: rgb(27, 27, 215); font-family: &#39;Courier New&#39;;&quot;&gt;dfsNode&lt;/span&gt;&lt;/b&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;font-size: 10pt; font-family: &#39;Courier New&#39;;&quot;&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;font-size: 10pt; color: black; font-family: &#39;Courier New&#39;;&quot;&gt;&lt;span style=&quot;&quot;&gt;    &lt;/span&gt;}&lt;span style=&quot;&quot;&gt;   &lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;font-size: 10pt; font-family: &#39;Courier New&#39;;&quot;&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;font-size: 10pt; color: black; font-family: &#39;Courier New&#39;;&quot;&gt;&lt;span style=&quot;&quot;&gt;  &lt;/span&gt;}&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style=&quot;font-size: 10pt; color: black; font-family: &#39;Courier New&#39;;&quot;&gt;&lt;/span&gt;&lt;span style=&quot;font-size: 10pt; color: black; font-family: &#39;Courier New&#39;;&quot;&gt;&lt;span style=&quot;&quot;&gt;  &lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;GramE&quot;&gt;&lt;b&gt;&lt;span style=&quot;font-size: 10pt; color: rgb(127, 127, 127); font-family: &#39;Courier New&#39;;&quot;&gt;implicit&lt;/span&gt;&lt;/b&gt;&lt;/span&gt;&lt;span style=&quot;font-size: 10pt; color: black; font-family: &#39;Courier New&#39;;&quot;&gt;  &lt;/span&gt;&lt;b&gt;&lt;span style=&quot;font-size: 10pt; color: rgb(127, 127, 127); font-family: &#39;Courier New&#39;;&quot;&gt;def&lt;/span&gt;&lt;/b&gt;&lt;span style=&quot;font-size: 10pt; color: black; font-family: &#39;Courier New&#39;;&quot;&gt;  &lt;/span&gt;&lt;b&gt;&lt;span style=&quot;font-size: 10pt; color: dodgerblue; font-family: &#39;Courier New&#39;;&quot;&gt;arc2DfsArc&lt;/span&gt;&lt;/b&gt;&lt;span style=&quot;font-size: 10pt; color: black; font-family: &#39;Courier New&#39;;&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;SpellE&quot;&gt;&lt;b&gt;&lt;i&gt;&lt;span style=&quot;font-size: 10pt; color: rgb(27, 27, 215); font-family: &#39;Courier New&#39;;&quot;&gt;arc&lt;/span&gt;&lt;/i&gt;&lt;/b&gt;&lt;span style=&quot;font-size: 10pt; color: black; font-family: &#39;Courier New&#39;;&quot;&gt;:&lt;/span&gt;&lt;b&gt;&lt;span style=&quot;font-size: 10pt; color: brown; font-family: &#39;Courier New&#39;;&quot;&gt;Arc&lt;/span&gt;&lt;/b&gt;&lt;/span&gt;&lt;span style=&quot;font-size: 10pt; color: black; font-family: &#39;Courier New&#39;;&quot;&gt;):&lt;/span&gt;&lt;span class=&quot;SpellE&quot;&gt;&lt;b&gt;&lt;span style=&quot;font-size: 10pt; color: brown; font-family: &#39;Courier New&#39;;&quot;&gt;DfsArc&lt;/span&gt;&lt;/b&gt;&lt;/span&gt;&lt;span style=&quot;font-size: 10pt; color: black; font-family: &#39;Courier New&#39;;&quot;&gt;={&lt;/span&gt;&lt;span style=&quot;font-size: 10pt; font-family: &#39;Courier New&#39;;&quot;&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;font-size: 10pt; color: black; font-family: &#39;Courier New&#39;;&quot;&gt;&lt;span style=&quot;&quot;&gt;    &lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;GramE&quot;&gt;&lt;b&gt;&lt;span style=&quot;font-size: 10pt; color: rgb(127, 127, 127); font-family: &#39;Courier New&#39;;&quot;&gt;if&lt;/span&gt;&lt;/b&gt;&lt;/span&gt;&lt;span style=&quot;font-size: 10pt; color: black; font-family: &#39;Courier New&#39;;&quot;&gt; (&lt;/span&gt;&lt;span class=&quot;SpellE&quot;&gt;&lt;b&gt;&lt;i&gt;&lt;span style=&quot;font-size: 10pt; color: rgb(27, 27, 215); font-family: &#39;Courier New&#39;;&quot;&gt;arc&lt;/span&gt;&lt;/i&gt;&lt;/b&gt;&lt;span style=&quot;font-size: 10pt; color: black; font-family: &#39;Courier New&#39;;&quot;&gt;.&lt;/span&gt;&lt;b&gt;&lt;span style=&quot;font-size: 10pt; color: dodgerblue; font-family: &#39;Courier New&#39;;&quot;&gt;isInstanceOf&lt;/span&gt;&lt;/b&gt;&lt;/span&gt;&lt;span style=&quot;font-size: 10pt; color: black; font-family: &#39;Courier New&#39;;&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;SpellE&quot;&gt;&lt;b&gt;&lt;span style=&quot;font-size: 10pt; color: brown; font-family: &#39;Courier New&#39;;&quot;&gt;DfsArc&lt;/span&gt;&lt;/b&gt;&lt;/span&gt;&lt;span style=&quot;font-size: 10pt; color: black; font-family: &#39;Courier New&#39;;&quot;&gt;])&lt;/span&gt;&lt;span style=&quot;font-size: 10pt; font-family: &#39;Courier New&#39;;&quot;&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;font-size: 10pt; color: black; font-family: &#39;Courier New&#39;;&quot;&gt;&lt;span style=&quot;&quot;&gt;      &lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;SpellE&quot;&gt;&lt;span class=&quot;GramE&quot;&gt;&lt;b&gt;&lt;i&gt;&lt;span style=&quot;font-size: 10pt; color: rgb(27, 27, 215); font-family: &#39;Courier New&#39;;&quot;&gt;arc&lt;/span&gt;&lt;/i&gt;&lt;/b&gt;&lt;span style=&quot;font-size: 10pt; color: black; font-family: &#39;Courier New&#39;;&quot;&gt;.&lt;/span&gt;&lt;b&gt;&lt;span style=&quot;font-size: 10pt; color: dodgerblue; font-family: &#39;Courier New&#39;;&quot;&gt;asInstanceOf&lt;/span&gt;&lt;/b&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;GramE&quot;&gt;&lt;span style=&quot;font-size: 10pt; color: black; font-family: &#39;Courier New&#39;;&quot;&gt;[&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;SpellE&quot;&gt;&lt;b&gt;&lt;span style=&quot;font-size: 10pt; color: brown; font-family: &#39;Courier New&#39;;&quot;&gt;DfsArc&lt;/span&gt;&lt;/b&gt;&lt;/span&gt;&lt;span style=&quot;font-size: 10pt; color: black; font-family: &#39;Courier New&#39;;&quot;&gt;]&lt;/span&gt;&lt;span style=&quot;font-size: 10pt; font-family: &#39;Courier New&#39;;&quot;&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;font-size: 10pt; color: black; font-family: &#39;Courier New&#39;;&quot;&gt;&lt;span style=&quot;&quot;&gt;    &lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;GramE&quot;&gt;&lt;b&gt;&lt;span style=&quot;font-size: 10pt; color: rgb(127, 127, 127); font-family: &#39;Courier New&#39;;&quot;&gt;else&lt;/span&gt;&lt;/b&gt;&lt;/span&gt;&lt;span style=&quot;font-size: 10pt; color: black; font-family: &#39;Courier New&#39;;&quot;&gt; {&lt;/span&gt;&lt;span style=&quot;font-size: 10pt; font-family: &#39;Courier New&#39;;&quot;&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;font-size: 10pt; color: black; font-family: &#39;Courier New&#39;;&quot;&gt;&lt;span style=&quot;&quot;&gt;      &lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;GramE&quot;&gt;&lt;b&gt;&lt;span style=&quot;font-size: 10pt; color: rgb(127, 127, 127); font-family: &#39;Courier New&#39;;&quot;&gt;new&lt;/span&gt;&lt;/b&gt;&lt;/span&gt;&lt;span style=&quot;font-size: 10pt; color: black; font-family: &#39;Courier New&#39;;&quot;&gt; &lt;/span&gt;&lt;span class=&quot;SpellE&quot;&gt;&lt;b&gt;&lt;span style=&quot;font-size: 10pt; color: brown; font-family: &#39;Courier New&#39;;&quot;&gt;DfsArc&lt;/span&gt;&lt;/b&gt;&lt;/span&gt;&lt;span style=&quot;font-size: 10pt; color: black; font-family: &#39;Courier New&#39;;&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;SpellE&quot;&gt;&lt;b&gt;&lt;i&gt;&lt;span style=&quot;font-size: 10pt; color: rgb(27, 27, 215); font-family: &#39;Courier New&#39;;&quot;&gt;arc&lt;/span&gt;&lt;/i&gt;&lt;/b&gt;&lt;span style=&quot;font-size: 10pt; color: black; font-family: &#39;Courier New&#39;;&quot;&gt;.&lt;/span&gt;&lt;b&gt;&lt;span style=&quot;font-size: 10pt; color: rgb(27, 27, 215); font-family: &#39;Courier New&#39;;&quot;&gt;start&lt;/span&gt;&lt;/b&gt;&lt;span style=&quot;font-size: 10pt; color: black; font-family: &#39;Courier New&#39;;&quot;&gt;,&lt;/span&gt;&lt;b&gt;&lt;i&gt;&lt;span style=&quot;font-size: 10pt; color: rgb(27, 27, 215); font-family: &#39;Courier New&#39;;&quot;&gt;arc&lt;/span&gt;&lt;/i&gt;&lt;/b&gt;&lt;span style=&quot;font-size: 10pt; color: black; font-family: &#39;Courier New&#39;;&quot;&gt;.&lt;/span&gt;&lt;b&gt;&lt;span style=&quot;font-size: 10pt; color: rgb(27, 27, 215); font-family: &#39;Courier New&#39;;&quot;&gt;end&lt;/span&gt;&lt;/b&gt;&lt;/span&gt;&lt;span style=&quot;font-size: 10pt; color: black; font-family: &#39;Courier New&#39;;&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;font-size: 10pt; font-family: &#39;Courier New&#39;;&quot;&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;font-size: 10pt; color: black; font-family: &#39;Courier New&#39;;&quot;&gt;&lt;span style=&quot;&quot;&gt;    &lt;/span&gt;}&lt;span style=&quot;&quot;&gt;   &lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;font-size: 10pt; font-family: &#39;Courier New&#39;;&quot;&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;font-size: 10pt; color: black; font-family: &#39;Courier New&#39;;&quot;&gt;&lt;span style=&quot;&quot;&gt;  &lt;/span&gt;}&lt;/span&gt;&lt;span style=&quot;font-size: 10pt; font-family: &#39;Courier New&#39;;&quot;&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;font-size: 10pt; color: black; font-family: &#39;Courier New&#39;;&quot;&gt;}&lt;/span&gt;&lt;span style=&quot;font-size: 10pt; font-family: &#39;Courier New&#39;;&quot;&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;b&gt;&lt;span style=&quot;font-size: 10pt; color: rgb(127, 127, 127); font-family: &#39;Courier New&#39;;&quot;&gt;&lt;o:p&gt; &lt;/o:p&gt;&lt;/span&gt;&lt;/b&gt;&lt;/p&gt;        &lt;p class=&quot;MsoNormal&quot; style=&quot;&quot;&gt;&lt;span style=&quot;font-size: 10pt; font-family: Arial;&quot;&gt;And now, everything will &lt;span class=&quot;SpellE&quot;&gt;happly&lt;/span&gt; compile. The only caveat is as I defined the method  --&gt; returning an Arc and arc2DfsArc creating a new instance if I pass an Arc,  the use of &lt;/span&gt;&lt;b&gt;&lt;span style=&quot;font-size: 10pt; color: rgb(27, 27, 215); font-family: &#39;Courier New&#39;;&quot;&gt;n1&lt;/span&gt;&lt;/b&gt;&lt;span style=&quot;font-size: 10pt; color: black; font-family: &#39;Courier New&#39;;&quot;&gt;--&gt;&lt;/span&gt;&lt;b&gt;&lt;span style=&quot;font-size: 10pt; color: rgb(27, 27, 215); font-family: &#39;Courier New&#39;;&quot;&gt;n2&lt;/span&gt;&lt;/b&gt;&lt;span style=&quot;font-size: 10pt; color: black; font-family: &#39;Courier New&#39;;&quot;&gt;  &lt;/span&gt;&lt;b&gt;&lt;span style=&quot;font-size: 10pt; color: rgb(27, 27, 215); font-family: &#39;Courier New&#39;;&quot;&gt;weight&lt;/span&gt;&lt;/b&gt;&lt;span style=&quot;font-size: 10pt; color: black; font-family: &#39;Courier New&#39;;&quot;&gt;=2&lt;/span&gt;&lt;span style=&quot;font-size: 10pt; font-family: Arial;&quot;&gt; sets the weight in a new object and  not in &lt;span class=&quot;GramE&quot;&gt;the&lt;span style=&quot;&quot;&gt;   &lt;/span&gt;object&lt;/span&gt; in the transitions collection. I&#39;m sure there&#39;s a better  solution, but meanwhile if we &lt;span class=&quot;SpellE&quot;&gt;overrride&lt;/span&gt; the --&gt;  method in &lt;span class=&quot;SpellE&quot;&gt;DfsNode&lt;/span&gt; will work:&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;br /&gt;&lt;b&gt;&lt;span style=&quot;font-size: 10pt; color: rgb(127, 127, 127); font-family: &#39;Courier New&#39;;&quot;&gt;&lt;span style=&quot;&quot;&gt;  &lt;/span&gt;&lt;span class=&quot;GramE&quot;&gt;def&lt;/span&gt;&lt;/span&gt;&lt;/b&gt;&lt;span style=&quot;font-size: 10pt; color: black; font-family: &#39;Courier New&#39;;&quot;&gt;  &lt;/span&gt;&lt;b&gt;&lt;span style=&quot;font-size: 10pt; color: dodgerblue; font-family: &#39;Courier New&#39;;&quot;&gt;--&gt;&lt;/span&gt;&lt;/b&gt;&lt;span style=&quot;font-size: 10pt; color: black; font-family: &#39;Courier New&#39;;&quot;&gt;  (&lt;/span&gt;&lt;b&gt;&lt;i&gt;&lt;span style=&quot;font-size: 10pt; color: rgb(27, 27, 215); font-family: &#39;Courier New&#39;;&quot;&gt;end&lt;/span&gt;&lt;/i&gt;&lt;/b&gt;&lt;span style=&quot;font-size: 10pt; color: black; font-family: &#39;Courier New&#39;;&quot;&gt;: &lt;/span&gt;&lt;span class=&quot;SpellE&quot;&gt;&lt;b&gt;&lt;span style=&quot;font-size: 10pt; color: brown; font-family: &#39;Courier New&#39;;&quot;&gt;DfsNode&lt;/span&gt;&lt;/b&gt;&lt;/span&gt;&lt;span style=&quot;font-size: 10pt; color: black; font-family: &#39;Courier New&#39;;&quot;&gt;):&lt;/span&gt;&lt;span class=&quot;SpellE&quot;&gt;&lt;b&gt;&lt;span style=&quot;font-size: 10pt; color: brown; font-family: &#39;Courier New&#39;;&quot;&gt;DfsArc&lt;/span&gt;&lt;/b&gt;&lt;/span&gt;&lt;span style=&quot;font-size: 10pt; color: black; font-family: &#39;Courier New&#39;;&quot;&gt;={&lt;/span&gt;&lt;span style=&quot;font-size: 10pt; font-family: &#39;Courier New&#39;;&quot;&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;font-size: 10pt; color: black; font-family: &#39;Courier New&#39;;&quot;&gt;&lt;span style=&quot;&quot;&gt;    &lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;GramE&quot;&gt;&lt;b&gt;&lt;span style=&quot;font-size: 10pt; color: rgb(27, 27, 215); font-family: &#39;Courier New&#39;;&quot;&gt;transitions&lt;/span&gt;&lt;/b&gt;&lt;/span&gt;&lt;span style=&quot;font-size: 10pt; color: black; font-family: &#39;Courier New&#39;;&quot;&gt; =  &lt;/span&gt;&lt;b&gt;&lt;span style=&quot;font-size: 10pt; color: rgb(127, 127, 127); font-family: &#39;Courier New&#39;;&quot;&gt;new&lt;/span&gt;&lt;/b&gt;&lt;span style=&quot;font-size: 10pt; color: black; font-family: &#39;Courier New&#39;;&quot;&gt; &lt;/span&gt;&lt;span class=&quot;SpellE&quot;&gt;&lt;b&gt;&lt;span style=&quot;font-size: 10pt; color: brown; font-family: &#39;Courier New&#39;;&quot;&gt;DfsArc&lt;/span&gt;&lt;/b&gt;&lt;/span&gt;&lt;span style=&quot;font-size: 10pt; color: black; font-family: &#39;Courier New&#39;;&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;SpellE&quot;&gt;&lt;b&gt;&lt;span style=&quot;font-size: 10pt; color: rgb(127, 127, 127); font-family: &#39;Courier New&#39;;&quot;&gt;this&lt;/span&gt;&lt;/b&gt;&lt;span style=&quot;font-size: 10pt; color: black; font-family: &#39;Courier New&#39;;&quot;&gt;,&lt;/span&gt;&lt;b&gt;&lt;i&gt;&lt;span style=&quot;font-size: 10pt; color: rgb(27, 27, 215); font-family: &#39;Courier New&#39;;&quot;&gt;end&lt;/span&gt;&lt;/i&gt;&lt;/b&gt;&lt;/span&gt;&lt;span style=&quot;font-size: 10pt; color: black; font-family: &#39;Courier New&#39;;&quot;&gt;)  &lt;/span&gt;&lt;b&gt;&lt;span style=&quot;font-size: 10pt; color: dodgerblue; font-family: &#39;Courier New&#39;;&quot;&gt;::&lt;/span&gt;&lt;/b&gt;&lt;span style=&quot;font-size: 10pt; color: black; font-family: &#39;Courier New&#39;;&quot;&gt;  &lt;/span&gt;&lt;b&gt;&lt;span style=&quot;font-size: 10pt; color: rgb(27, 27, 215); font-family: &#39;Courier New&#39;;&quot;&gt;transitions&lt;/span&gt;&lt;/b&gt;&lt;span style=&quot;font-size: 10pt; font-family: &#39;Courier New&#39;;&quot;&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;font-size: 10pt; color: black; font-family: &#39;Courier New&#39;;&quot;&gt;&lt;span style=&quot;&quot;&gt;    &lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;SpellE&quot;&gt;&lt;span class=&quot;GramE&quot;&gt;&lt;b&gt;&lt;span style=&quot;font-size: 10pt; color: rgb(27, 27, 215); font-family: &#39;Courier New&#39;;&quot;&gt;transitions&lt;/span&gt;&lt;/b&gt;&lt;span style=&quot;font-size: 10pt; color: black; font-family: &#39;Courier New&#39;;&quot;&gt;.&lt;/span&gt;&lt;b&gt;&lt;span style=&quot;font-size: 10pt; color: dodgerblue; font-family: &#39;Courier New&#39;;&quot;&gt;head&lt;/span&gt;&lt;/b&gt;&lt;span style=&quot;font-size: 10pt; color: black; font-family: &#39;Courier New&#39;;&quot;&gt;.&lt;/span&gt;&lt;b&gt;&lt;span style=&quot;font-size: 10pt; color: dodgerblue; font-family: &#39;Courier New&#39;;&quot;&gt;asInstanceOf&lt;/span&gt;&lt;/b&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;GramE&quot;&gt;&lt;span style=&quot;font-size: 10pt; color: black; font-family: &#39;Courier New&#39;;&quot;&gt;[&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;SpellE&quot;&gt;&lt;b&gt;&lt;span style=&quot;font-size: 10pt; color: brown; font-family: &#39;Courier New&#39;;&quot;&gt;DfsArc&lt;/span&gt;&lt;/b&gt;&lt;/span&gt;&lt;span style=&quot;font-size: 10pt; color: black; font-family: &#39;Courier New&#39;;&quot;&gt;]&lt;/span&gt;&lt;span style=&quot;font-size: 10pt; font-family: &#39;Courier New&#39;;&quot;&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;font-size: 10pt; color: black; font-family: &#39;Courier New&#39;;&quot;&gt;&lt;span style=&quot;&quot;&gt;  &lt;/span&gt;}&lt;o:p&gt;&lt;br /&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class=&quot;MsoNormal&quot; style=&quot;&quot;&gt;&lt;span style=&quot;font-size: 10pt; font-family: Arial;&quot;&gt;(Let me know if you want the full  code posted)&lt;/span&gt;&lt;b&gt;&lt;span style=&quot;font-size: 10pt; color: rgb(127, 127, 127); font-family: &#39;Courier New&#39;;&quot;&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/b&gt;&lt;/p&gt; &lt;/div&gt;</description><link>http://gabrielsw.blogspot.com/2008/01/playing-with-scala-3-oo-traits-and.html</link><author>noreply@blogger.com (Anonymous)</author><thr:total>10</thr:total></item></channel></rss>