# I made a machine

**URL:** https://discourse.elm-lang.org/t/i-made-a-machine/2201
**Category:** Show and Tell
**Created:** [October 13, 2018, 12:50pm UTC](https://discourse.elm-lang.org/t/i-made-a-machine/2201 "2018-10-13T12:50:50Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![jwoLondon](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.elm-lang.org/jwolondon/32/605_2.png) [@jwoLondon](https://discourse.elm-lang.org/u/jwoLondon)
#### Post date: [October 13, 2018, 12:50pm UTC](https://discourse.elm-lang.org/t/i-made-a-machine/2201/1 "2018-10-13T12:50:50Z")

</div>

In providing materials for teaching students about Turing Machines, I thought I’d have a go creating one in Elm

![annotatedMachineSmall](https://canada1.discourse-cdn.com/flex035/uploads/elm_lang/original/2X/d/d32ad6bc40db724bfdb79e8f4122b0c6854301d4.jpeg)

You can play with it [here](https://www.staff.city.ac.uk/~jwo/tutorials/tm/) or look at the [source code](https://github.com/jwoLondon/turingmachine). All styling is done via [elm-ui](https://package.elm-lang.org/packages/mdgriffith/elm-ui/latest/) (thanks @mdgriffith), which I find much easier than separating HTML and CSS. While I have been working with Elm for a couple of years now, I don’t normally use TEA, so there is probably scope for improvement.

I think what makes this potentially useful for teaching is the ability to add comments for each state and to encode the entire machine and tape via a URL (which itself is a useful way of introducing the ‘Universal Turing Machine’). Here are some examples:

- [Increment a binary number](https://www.staff.city.ac.uk/~jwo/tutorials/tm/?tape=0011&a=0ra1ra_lb&b=1lc0lb1n!&c=0lc1lc_r!&aComment=Move%20to%20right%20of%20sequence&bComment=Add%201%20and%20carry%20if%20already%20a%201%20here.&cComment=Move%20left%20to%20start%20of%20sequence&dComment=Move%20to%20left%20of%20sequence.)
- [Separate cats and dogs](https://www.staff.city.ac.uk/~jwo/tutorials/tm/?tape=101100100111010&alphabet=CatsAndDogs&a=0ra_rb_n!&b=0rb1rb1lc&c=_ld1lc_n!&d=0ld1ld0ra&aComment=Search%20R%20for%20a%20dog%20and%20carry%20it.%20If%20we%20hit%20a%20blank%20we%27re%20done.&bComment=Drop%20dog%20in%20first%20blank%20to%20right.&cComment=Search%20L%20for%20a%20cat%20and%20carry%20it.%20If%20we%20hit%20a%20blank%20we%27re%20done.&dComment=Drop%20cat%20in%20first%20blank%20to%20left.)

A more challenging task for a two-element alphabet of symbols is to reverse the order of a sequence and halt. Here is [my solution](https://www.staff.city.ac.uk/~jwo/tutorials/tm/?tape=0010111&a=0rb1rb_n!&b=0rc1rc_rc&c=0ld1ld_lk&d=_ne_ng_n!&e=0nf1nf_le&f=0lf1lf0ni&g=0nh1nh_lg&h=0lh1lh1ni&i=0ri1ri_rj&j=0rc1rc_rj&k=_ll_ln_n!&l=0nm1nm_ll&m=0lm1lm0n!&n=0no1no_ln&o=0lo1lo1n!&aComment=Start%20one%20cell%20to%20right&bComment=Move%20one%20more%20cell%20right%20to%20check%20if%20last%20digit&cComment=Was%20that%20the%20last%20digit%20to%20move?&dComment=Pick%20up%200%20or%201&eComment=Carry%200%20left%20across%20gap&fComment=Drop%200%20to%20left%20of%20reversed%20sequence&gComment=Carry%201%20left%20across%20gap&hComment=Drop%201%20to%20left%20of%20reversed%20sequence&iComment=Traverse%20right%20across%20reversed%20sequence&jComment=Traverse%20right%20across%20gap%20and%20first%20unmoved%20symbol&kComment=Pick%20up%20last%200%20or%201&lComment=Carry%20last%200%20left%20across%20gap&mComment=Drop%20last%200%20to%20left%20of%20reversed%20list&nComment=Carry%20last%201%20left%20across%20gap&oComment=Drop%20last%201%20to%20left%20of%20reversed%20list), but perhaps there are better ones?

BTW, Elm has been great for this kind of application building. So much easier than other languages I’ve used.

---

<div class="post-metadata">

### Author: ![system](https://canada1.discourse-cdn.com/flex035/uploads/elm_lang/original/1X/50a05e53677a2c3b47776d7abd0f113eb50193a1.png) [@system](https://discourse.elm-lang.org/u/system)
#### Post date: [October 23, 2018, 12:50pm UTC](https://discourse.elm-lang.org/t/i-made-a-machine/2201/2 "2018-10-23T12:50:51Z")

</div>

This topic was automatically closed 10 days after the last reply. New replies are no longer allowed.
