ConnorRigby
Nerves Core Team
SPOILERS AHEAD DON’T CONTINUE IF YOU PLAN ON DOING THE CHALLENGE
I always start Advent of Code, then forget about half way through the month. I really hope to finish this year, but i think i cheated on part two of December 2.
The challenge is to compare strings and find the one that has but one letter change between strings.
here is what i came up with.
Basically it boils down to:
case String.myers_difference(string, check) do
[eq: pt1, del: <<_>>, ins: <<_>>, eq: pt2] -> pt1 <> pt2 # the answer.
_ -> false # move on to the next one.
end
I haven’t looked at anyone else’s implementation of this one yet, but i know this isn’t the intended method of solving this. It got me thinking though: does anyone else try to solve these questions in “illegal” ways?
Trending in Discussions
As the title says, please share what you’ve been up to with Elixir. Whether that’s been learning it, looking into it, making stuff with i...
New
The obligatory hello world thread!
Who are you and where are you from? :stuck_out_tongue:
New
@chrismccord : I just saw the Extract AGENTS.md from Phoenix.new into phx.new generator commit to the phoenix project.
My initial shotgu...
New
I was working on an Ecto migration and I needed a timestamp. So, for the nth time, I looked up the different data types for timestamps, a...
New
Fly’s CEO posted this recently - Turn And Face The Strange · The Fly Blog
It says that Fly is going all-in on sprites, which is a worry ...
New
We’re evaluating API mocking tools for OpenAPI-based projects and would love to hear what other teams are using.
We’re particularly inte...
New
Is there a word for the ~> symbol used in Version strings?
Do you also just call it a Squiggle Arrow™ ?!
New
Other Trending Topics
Hey, I’m Jesse and I’m the main contributor behind Dexter, a full-featured, lightning-fast Elixir LSP optimized for large codebases. It s...
New
Beam Bots (or just BB for short) is a framework for building fault-tolerant robotics applications in Elixir using familiar OTP patterns. ...
New
ExRatatui lets you cook up rich terminal UIs in Elixir, powered by Rust’s ratatui via Rustler NIFs. Build interactive terminal applicatio...
New
Hello everyone. After busy few months I am happy to announce v0.1.0 of Emerge & Solve.
They are GUI (Emerge) and State management (S...
New
Corex is an accessible, unstyled UI component library for Phoenix that integrates Zag.js state machines using Vanilla JavaScript and Live...
New
Emily is an Elixir library that runs Nx computations on Apple’s MLX. Install it as the default Nx backend and Nx, defn, Axon, Nx.Serving,...
New
Chat & Discussions>Discussions
Latest on Elixir Forum
Categories:
Sub Categories:
Forums
Popular Tags
- #ecto
- #liveview
- #troubleshooting
- #learning-elixir
- #deployment
- #library
- #erlang
- #testing
- #genserver
- #mix
- #absinthe
- #remote-other
- #otp
- #plug
- #how-to-question
- #macros
- #postgres
- #channels
- #elixirconf
- #exunit
- #discussion
- #code-sync
- #javascript
- #podcasts
- #onsite
- #dialyzer
- #docker
- #authentication
- #umbrella
- #full-time-contract
- #podcasts-by-brainlid
- #ecto-query
- #elixir-ls
- #blog-post
- #phoenix_html
- #iex
- #graphql
- #ai
- #genstage
- #elixirconf-us
- #websockets
- #supervisor
- #advent-of-code
- #distillery
- #processes
- #api
- #forms
- #metaprogramming
- #security
- #hex










Showing Posts 1 to 8- Show Best Posts
- Show All Posts (oldest first)
- Show All Posts (newest first)
yawaramin
You mean did we take full advantage of the language syntax and semantics? Yup!
I did something similar to you, see my post for more details: Advent Of Code 2018 - #19
dbern
I was comparing with a JavaScript developer’s solution, and ya… Elixir is really nice
I don’t feel like I cheated, but I definitely felt like I had it easier.
NobbZ
Using the documented functions of the standard library is not cheating. In a first go I just try to solve them. Speeding things up, making code idiomatic, all these cosmetic stuff is done afterwards, if at all. Massively depends on the time slot I can alot
I have not used
String.myers_difference/2though, because I was unsure if there are any guarantees about the order of:deland:inskeys. Also just filtering on the hamming distance beeing exactly1and then removing the opposing character bya |> zip(b) |> filter(fn {a, b} -> a == b end) |> map(fn {c, c} -> c end) |> to_stringfelt much more clean to me than matching on the diff-description in your version.To make this overall easier, I dealt with char lists in this exercise.
sasajuric
I wouldn’t say that there is such thing as cheating in AoC. For me, these puzzles are about the goals you set for yourself. Many people just like to solve them for fun, and reach for whichever improvisation can help them. For example, one friend solved a puzzle last year on a piece of paper, and a few others by using
grepfrom command lineWhen I did AoC last year, my main goal was to practice streams. I also tried to reach the solutions I’m happy with. In some cases, even after solving the challenge, I’d spend a few more sessions (sometimes even spread over a few days) to improve the solution.
So in my view, you set your own rules, and decide when you’re happy with your solution.
keathley
Wait…are you wondering if you’ve cheated because myers difference is a thing that exists in elixir or because you’re making an assumption that the wrong letter is only ever in the middle and not at the beginning or end? In the later case I’m not sure if this solution would work as a general solution for all inputs or not. It doesn’t really matter since you’re only using your input to work with I suppose.
NobbZ
Oh, this is a very valid point. I never have seen this issue before (as in: that this might become a problem).
Besides my points about ordering guarantees of inserts and deletes in the list, this is another point to consider against the general use of myers_diff here.
But still I do not consider this any cheating, as it solves the puzzle with the given input, which is the most important thing.
Last year, I followed the reddit actively, and some of the top-players said, they never touch again a solutions that gave them the correct answer until they really have to or get bored in the 11 months inbetween.
So it seems that there seems to be some kind of consensus, that whatever works, counts, well unless you simply copy paste
keathley
Yeah, a friend mentioned on twitter that there was a hack for this problem where you can make assumptions about the inputs and eliminate a bunch of looping and checking. I’m not making a judgement either way. Whatever solves the problem seems fine to me. Personally I wrote the O(n^2) solution similar to this since it was easy to understand and fast to write first. Once I had that I used the slow solution to validate a O(n) solution which seemed like a fun challenge.
balbin
I used
String.myers_difference/2along withKeyword.get_values, so it didn’t matter about the ordering, all the:delkeys’ values will be checked, I think this is a lot better than pattern matching since it works when the differing character is in the first position. Also joining the:eqparts after with a similar approach was really easy. Kinda interesting how I’ve usedKeyword.getso much but had never even heard ofKeyword.get_values.This was my solution if anyone’s interested.