As It Happens

Scientist uses algorithm to make the perfect peanut butter and banana sandwich

Data scientist Ethan Rosenthal loves peanut butter and banana sandwiches. During lockdown, he decided to use machine learning to tell him how to make the perfect sandwich.

Ethan Rosenthal uses pandemic downtime to optimize banana slice placement on bread

Data scientist Ethan Rosenthal wanted to eat a peanut butter and banana sandwich that had banana in every bite, along with the other ingredients. He turned to machine learning to figure out how to optimize banana slice placement on bread. (Submitted by Ethan Rosenthal)

Transcript

The optimal peanut butter and banana sandwich should have each ingredient in every bite, according to Ethan Rosenthal. That means banana placement is important.

Rosenthal, who has a PhD in physics, is a data scientist for Square, and lives in New York City.

He found himself with a lot of time on his hands during COVID-19 lockdown, so he set out to determine the best way to get optimal banana slice coverage on a piece of bread.

"In the end, you know, the arrangements of the slices were fairly different to what I had been doing by hand before," he told As It Happens guest host Helen Mann. 

Ethan Rosenthal is a data scientist for Square and lives in New York City. (Submitted by Ethan Rosenthal )

He says he chose to focus on peanut butter and banana sandwiches because they're his favourite.

"I frankly love the flavour. It gives me fond memories of my grandfather who introduced it to me. And also, I guess visually and mathematically, it's very pleasing to see all of the slices of bananas placed onto the bread," Rosenthal said. 

The process to find optimal placement took him about five months, he estimates, and he detailed his work on his blog.

When he first told his wife about his idea, she asked him why he wouldn't just slice the banana lengthwise to achieve his goal.

"Amusingly, that had never crossed my mind that this could even be possible to do it like that. And in fact, I think that would be the optimal way to do this," Rosenthal said. 

"But, you know, I've been eating these sandwiches, the circular slices, for decades and, you know, couldn't really change a habit now," he said. "If I'd done it like that, then I wouldn't have had something to do for the last five months."

The process took him so long because there was actually a lot of work involved, he said. 

"The way that this algorithm works, is that you take a picture of your your banana and your bread, and then I produce an image telling you where to slice the banana and where to place the slices on the bread," he explained. 

A photo showing an optimal placement of sliced bananas, for a peanut butter and banana sandwich. (Submitted by Ethan Rosenthal )
Here, the result of reproducing the photo above, for a peanut butter and banana sandwich. (Submitted by Ethan Rosenthal )

"There's computer vision involved in order to detect where the banana and the bread are. There's various kind of just straightforward math for fitting curves and things like that. And then there's computer science involved with the developing with the algorithm for packing the slices onto the bread."

Rosenthal is offering the package he created on his GitHub page for anyone who wants to try it themselves, but warns that it takes a bit of computer know-how to install and run it.

But as far as he's concerned, it was worth all the effort.

"It's a labour of love in order to perfectly slice and place," he said. "Food often tastes better when you do that."


Written by Andrea Bellemare. Interview produced by Menaka Raman-Wilms. 

 

Add some “good” to your morning and evening.

A variety of newsletters you'll love, delivered straight to you.

Sign up now

Comments

To encourage thoughtful and respectful conversations, first and last names will appear with each submission to CBC/Radio-Canada's online communities (except in children and youth-oriented communities). Pseudonyms will no longer be permitted.

By submitting a comment, you accept that CBC has the right to reproduce and publish that comment in whole or in part, in any manner CBC chooses. Please note that CBC does not endorse the opinions expressed in comments. Comments on this story are moderated according to our Submission Guidelines. Comments are welcome while open. We reserve the right to close comments at any time.

Become a CBC Member

Join the conversationCreate account

Already have an account?

now