## Ordr.interns Polina: Harnessing chaos to help you choose

Chaos is an attractive word. It frequently appears in pop culture as something untamable, wild, and completely unpredictable (for example, think of the Alignment from D&D - Lawful / Neutral / Chaotic). This is a somewhat romanticized and obscured view of the original, mathematical chaos, which in its own right is quite beautiful.

Mathematical chaos is deterministic, meaning it is not random, but extremely sensitive to the initial conditions - this is the origin of the image of the flap of a butterfly's wings in Australia that sets off a tornado in Texas.

So why not combine tasty concepts of chaos and food into an app? Enter Chaotic Chow.

The so-called logistic map was a great candidate to be the chaos-giving component of Chaotic Chow. It is a rather innocent-looking equation that gives the next number in a sequence, given the previous one: . It turns out that for certain values of , if the first number in the sequence, , is perturbed just a tiny bit, the following sequence terms vary greatly. The other useful thing about the logistic map is that the values in the sequences it produces is in the range (0, 1) (as long as some constraints about and are met). This enables ease of mapping to a menu of a non-constant size.

When teaching chaos I discovered that providing an interactive visualization of what is going on was very helpful. With the help of the powerful and neat D3.js library I whipped together a demonstration of how the logistic equation (or rather, its sequence up to 500 points) behaves for different and , which are changeable by sliders. Check it out!

In order to improve the speed of the sliders' response, all 980100 point values are precomputed:

`function logistic(k, x){ return k*x*(1-x); } function getLogistArray(k, x0){ var array = [[0, x0]], x = x0; for(var i = 1; i <= 500; i++){ x = logistic(k, x); if(i % 5 == 0){ array.push([i, x]); } } return array; } for(var h = 1; h < 100; h++){ var xBuild = h/100, ptDataRow = []; for(var i = 1; i < 100; i++){ kBuild = i/25; ptDataRow.push(getLogistArray(kBuild, xBuild)); } ptData.push(ptDataRow); }`

How does this tie into food? First, the menu that the Ordr.in API returns is processed - only orderable items and their options are taken into consideration. This gives a list of orderable items, all of which are indexed.

Next, the user gets to select the value of , from a slider. This, in turn, will determine the upcoming sequence of numbers. At random, points are picked from the created sequence. The values at these points are then mapped to the index of some items in the menu, which are thus picked.

To increase practicality - as much practicality as there can be for a quasi-random meal picker - a limit on the maximum cost and number of items in the total order are determined by the user.

Finally, to increase the fun, there's another visualization in the app. This time, it only shows the points for the particular sequence and highlights the chosen ones that correspond to an item that was inserted into the order.

If the chaos in the order is too much to handle (2 sets of utensils for $0.28, 3 bottles of different beers, and a cup of coffee), it's always possible to re-chaotize the order by allowing for a different value of and observe the new sequence pop up in the graph.

While the app isn't finished or polished, if you want to check it out feel free!

-- Polina