Haskell style question:
When do people use regular function application and function composition, and when do they use &
, the reverse application operator? The Elixir folks really like their equivalent |>
operator for building pipelines.
For me, when the chain of functions is long, I find &
clearer. In day 1 of Advent of Code this year, I wound up with two functions, one in each style.
https://github.com/bwbeach/advent-of-code-2022/blob/main/day01/app/Main.hs
(Note: I tried markdown for the code in the post, but triple-backticks didn’t preserve newlines. 😞)
A friend of mine posed the following puzzle:
You have 12 marbles, which all have the same weight except one, which may be either heavier or lighter. How can you find the different one in three weighings on a balance scale?
I know I’ve seen it before, but it still too me a while to work out a solution. Then I wanted to visualize the solution, and cobbled together haskell, graphviz, and a couple shell scripts.
Then, of course, I saw my solution was wrong and had to re-work it.
Spoiler, of course:
https://github.com/bwbeach/puzzles/blob/main/weigh-twelve/README.md
I came across a math puzzle here in the fediverse, and puzzled about it for a while. (Lost the link to the original post; if it’s yours let me know.)
Here’s the problem:
Bob was given 30 distinct natural numbers. He wrote down all the 435 pairwise sums. It appears that among those sums, 230 are divisible by 3. How many of the original 30 numbers are divisible by 3?
I was able to find the answer after playing with it for a bit. Then I made this cool visualization. (It’s a spoiler, of course.)
Proud papa/dad/husband. Choral singer. Aspiring linguist. CTO at Backblaze. Usually in Indiana, sometimes on Maui. He/him.