Archive for the ‘Uncategorized’ Category.

A Brief Computational Analysis of “Pen-Pineapple Apple-pen”

ppaap_debruijn

Pen-Pineapple Apple-pen is the latest earworm [1] out of Japan. It has deceptively simple lyrics [3]. Starting with the refrain:

I have a pen.
I have an apple.
Ungh
Apple-pen.

What makes the lyrics interesting, is the way he plays with word ordering [4]. First mentioning Pen, then Apple before switching it around to become Apple-pen. I think it’s this reordering which engages the brain and helps give the song its memetic qualities.

The lyrics continue, repeating the process with Pen-pineapple, finally generating the string:

Pen-pineapple Apple-pen.

Piko-Taro then compresses this into the 2 symbol alphabet: PPAP. However, as “pineapple” contains “apple” we could expand this to: PPAAP.

PPAAP is a rather interesting string. Let’s look at every 2 symbol substring:

PP
PA
AA
AP

There are 4 possible 2 symbol strings over this alphabet, and each one is represented exactly once in the string PPAAP. It’s interesting to note that this would not have happened if Piko-Taro had chosen a different ordering, for example APPPA (Apple-Pen Pen-Pineapple) would give us 2 repeats of the substring PP and no occurrence of AA [5].

Strings that contain every substring of a given length (n) over a given alphabet (size k) are called De-Bruijn sequences. In order to create DeBruijn sequences, we generally start with a graph [6]:

ppaap_debruijnThe graph [7] has a vertex labeled with each string of length n-1 (in this case 1). Edges then connect the vertex to the vertex labeled with the suffix (of length n-1) of the string that would be created by adding the symbol the edge is labeled with.

To generate debruijn sequences from this graph we need to find Eulerian cycles in the Debruijn graph. That is to say, we need to visit each edge once before returning to the starting point. The starting vertex label, followed by the edge labels forms the DeBruijn sequence.

The PPAAP graph is of course trivial, and we can easily spot the 2 valid Debruijn sequences: PPAAP and AAPPA.

Debruijn sequences however get steadily more complex, lets take a look at one example from the wikipedia page:

320px-de_bruijn_graph-for_binary_sequence_of_order_4-svg

Which is the Debruijn graph for n=4 k=2. From this we can generate the sequence 0000111101100101. Or in the PA alphabet: PPPPAAAAPAAPPAPA using the P=pen, PA=pineapple A=apple mapping:

Pen-pen-pen-Pineapple-apple-apple-apple-pineapple-apple-pen-pineapple-pineapple

Which I assume will form the basis of Piko-Taro’s next video.

If you like this kind of inane rambling. You should probably follow me on twitter or consider hiring me, where I will attempt to rambling consistently on the topic of your choice.

[1] Historically known as a maggot.

[2] Interesting, while the Japanese transliterated subtitled reflect what he actually says in the video. The english version of these is incorrect in some-places (or perhaps there is some deeper hidden stringological meaning).

[3]

PPAP
I have a pen. I have an apple. Ungh Apple-pen. I have a pen. I have pineapple.
Ungh
Pineapple-pen.
Apple-pen.
Pineapple-pen.
Pen-pineapple-apple-pen.
Pen-pineapple-apple-pen. [2]

[4] Something that English speakers at least have an intuitive feel for.

[5] Many years ago I wrote some tools for calculating repeat counts in string efficiently. The repeat structure of string is often, interesting, informative, and beautiful. However there’s no money in it, and I don’t do it anymore. 🙂

[6] Interestingly, over the past few users sparse DeBruijn graphs have found applications in the assembly of DNA reads into more complete genomic sequences.

[7] I used the excellent tkz-graph with Latex to create this graph.

esp32 USB Stick (esp32 + ch340g + buck conv + sd card)

esp32usb_r1

I’ve just finished the first revision of the esp32 version of the espusb stick and it’s now out to fab. I expect to have to do at least some rework and probably a couple more iterations before I’m happy with it. But if you want to hack around with it, the Kicad files and gerbers are below.

As before the board contains a ch340g usb interface, buck converter (to generate 3.3v efficiently) and an SD card slot as well as the esp32. I have exactly one esp32 IC at the moment… so it might take some time to get this board up an running.

This is also currently a 2 layer board, I think this should be fine, but it’s possible I’ll need to rework it as a 4 layer design at some point.

Once I have a revision I’m comfortable it’ll go in the shop. If you’d like to pre-order it, let me know. For a hand assembled board it’ll probably be 20USD. Plug: if you buy stuff from my shop it makes it more likely that I’ll be able to get a production run done and put out a cheaper version.

Kicad files and Gerbers: esp32_usb

Kicad esp32 schematic symbol

esp32_kicad

I’m starting a esp32 design as a possible migration path from the esp8266 based espusb. The esp32 is currently low availability, and is a much more expensive part, but figured I’d give it a crack. First up, a schematic symbol. I hate how long these things take, and that they rarely get shared, so here’s mine (download below).

Download here (contains esp32.lib): esp32lib

The esp32 wroom32 design

wroom32_gerbs2

Espressif kindly provide the schematics and layout files for the esp32 based WROOM32. In preparation for my own design (based on my espusb) I’ve been looking over these files.

The zip file they provide (local copy) contains wroom32_pcbdesign files in a variety of formats. The source .PCB and .SCH files appear to be included, but there are no notes and I couldn’t determine which tool they are for (if you know please comment – my best guess is OrCAD). They also include pdf printouts of the schematic and and layout. The Layout pdf is reproduced to the right. However, it doesn’t show any of the silk and only appears to be the top copper layer. I therefore generated the image above from the gerbers that are also included.

The gerbers also don’t use a naming convention I’m familiar with, but from what I can tell the WROOM32 is a 4 layer board. I’m kind of surprised that they didn’t try and squeeze everything onto 2 layers, like they do with the esp1. Will be interesting to see if the esp32 also forces me to start doing 4 layer designs.

For reference, the BOM and schematic are below:

wroom32_bomwroom32_sch