billylanchantin

billylanchantin

Have you seen any code that you think came from "The Book"?

If you’re not familiar with this fun bit of math lore,

Paul Erdős, the famously eccentric, peripatetic and prolific 20th-century mathematician, was fond of the idea that God has a celestial volume containing the perfect proof of every mathematical theorem. “This one is from The Book,” he would declare when he wanted to bestow his highest praise on a beautiful proof.

Have you come across any Elixir code that you think could’ve come from our version of “The Book”?

Most Liked

dimitarvp

dimitarvp

Quick sort comes to mind. It’s beautiful. Bisecting stuff just feels like magic; an universal algorithm to look for problems and zero in on them.

billylanchantin

billylanchantin

I’ll nominate the following way to generate all permutations:

def permutations([]), do: [[]]
def permutations(list), do: for x <- list, rest <- permutations(list -- [x]), do: [x | rest]

I expected it to be so much more complicated than it was!

billylanchantin

billylanchantin

It’s one of those things that sounds simple and has a solution that looks simple, but actually coming up with the solution is less obvious.

Yes! This is actually 100% analogous to a problem that I deal with frequently at work: do two time ranges overlap? So our codebase is littered with this kind of check.

This is also (partially) why I wrote CompareChain. This kind of bounds checking is so much more annoying when you can’t use the infix structural operators like >=.

While I’m at it, have you come across the Allen's interval algebra - Wikipedia? It’s a generalization of the Law of trichotomy - Wikipedia to 1D intervals. In interval-land, two intervals fall into one of 13 specific cases (or 26 if you allow 0-width intervals) instead of just 3. This isn’t from The Book per se, but the number 13 always struck me as surprising for some reason.

Where Next?

Popular in Discussions Top

cvkmohan
The upcoming Phoenix 1.6 release looks very interesting. Became a habit to watch the commits - and - what they are bringing in. phx.gen...
New
AngeloChecked
What learn first? Rust or Elixir Hi Elixir community! I’m here because i want learn a new language. I’m a junior developer and mainly i ...
New
ricklove
I was just introduced to Elixir and Phoenix. I was told about the 2 million websocket test that was done 2 years ago. From my research, t...
New
nburkley
AWS re:Invent is on at the moment with some interesting announcements. One new feature in particular is the Lambda Runtime API for AWS La...
New
AstonJ
Are there any Elixir or Erlang libraries that help with this? I’ve been thinking how streaming services like twitch have exploded recentl...
New
PragTob
Hey everyone, this has been brewing in my head some time and it came up again while reading Adopting Elixir. GenServers, supervisors et...
New
New
eteeselink
Hi all, In the last days, two things happened: A blog post titled “They might never tell you it’s broken” made the rounds. It’s about ...
New
cblavier
Hey there, It’s been more than a year since we started using LiveView as our main UI library and building a whole library of UI componen...
New
tomekowal
Hey guys! I want to create a toy project that shows a chart of temperature over time and updates every 5 seconds. I feel LiveView is per...
New

Other popular topics Top

sen
Hi All, I set a environment variables in dev.exs , like below code. when i start server, how can i set the ${enable} value? thanks. d...
New
albydarned
Hello all! I am typing this post from my new MacBook Pro with the M1 chip. I’m loving it so far, and will probably use it as my daily dr...
New
skosch
To my knowledge, put_in, Map.update etc. all have the one limitation of not automatically creating intermediate keys when needed (for exa...
New
greenz1
I have a phoenix application from which a user can download multiple(5-6) files of size 1MB. I couldn’t find anything related to sending ...
New
stefanchrobot
What’s the safe way to decode a JSON string into a struct? I want to avoid calling String.to_atom. Jason.decode can give me a map with st...
New
jason.o
In the code below, if the create action is not set to accept “extra_key” as an input, it errors out with a message shown above. Is there ...
New
dblack
I’ve got an issue with an app and I’ve no idea of how to troubleshoot it. I’m hoping someone here might have seen something similar. I p...
New
nsuchy
Hi. I’ve noticed that Windows Powershell has it’s own IEX command and you cannot access Elixir’s IEX due to the conflict. This isn’t a cr...
New
JakeBecker
TL;DR: I’ve just released an implementation of Microsoft’s IDE-independent Language Server Protocol for Elixir. It adds language support ...
1144 54120 245
New
lanycrost
Hi everyone! I need implement if…else if…else condition from my elixir code, and anymore of this control flow structures not work proper...
New

Latest on Elixir Forum

Elixir Forum

We're in Beta

About us Mission Statement