jwaldner
I am just learning and am writing a word game.
I have a list of letters ordered by frequency of use and am doing a MapSet.difference() with letters [a-z] sorted by frequency of use & used letters to determine the next guess for an automated client
that works fine but the function re orders the new difference list alphabetically
I wanted to keep the [f] list order then just pick the next most frequent letter for a guess
f =
[“e”, “a”, “r”, “i”, “o”, “t”, “n”, “s”, “l”, “c”, “u”, “d”, “p”, “b”, “f”, “g”,
“h”, “j”, “k”, “m”, “q”, “v”, “w”, “x”, “y”, “z”]
s =
[“a”, “b”, “c”]
r = MapSet.difference(MapSet.new(f),MapSet.new(s))
the list does not start with “r” anymore [it’s new and that is fine, but I wanted to do an Enum.at(..0) to pick the next letter off the list… ]
r is {
MapSet.new([“d”, “e”, “f”, “g”, “h”, “i”, “j”, “k”, “l”, “m”, “n”, “o”, “p”,
“q”, “r”, “s”, “t”, “u”, “v”, “w”, “x”, “y”, “z”])
}
is there a way to do this?
Thanks!!
Trending in Questions
Other Trending Topics
Categories:
Sub Categories:
Forums
Popular Tags
- #ecto
- #liveview
- #troubleshooting
- #learning-elixir
- #library
- #deployment
- #erlang
- #testing
- #genserver
- #mix
- #absinthe
- #remote-other
- #otp
- #plug
- #how-to-question
- #macros
- #postgres
- #elixirconf
- #channels
- #exunit
- #discussion
- #code-sync
- #podcasts
- #javascript
- #onsite
- #dialyzer
- #docker
- #authentication
- #umbrella
- #full-time-contract
- #podcasts-by-brainlid
- #ai
- #ecto-query
- #elixirconf-us
- #blog-post
- #elixir-ls
- #phoenix_html
- #iex
- #graphql
- #genstage
- #websockets
- #supervisor
- #advent-of-code
- #distillery
- #processes
- #elixirconf-eu
- #api
- #forms
- #metaprogramming
- #hex










Showing Posts 1 to 4- Show Best Posts
- Show All (oldest first)
- Show All (newest first)
NobbZ
Sets are generally unordered.
So any order you observe is by accident and has to be considered an implementation detail.
If you need to maintain order, a
MapSetis not the correct data structure to use.zachallaun
Try using the
--operator on your lists directly instead.jwaldner
This does what I need, so simple.
But trying to wrap my head around functional programming
wow
def prune(list, items) do
list – items
end
a variable for game_state
def get_guess(_tally = %{used: state}) do
letters_by_frequency = [
“e”,“a”,“r”,“i”,“o”,“t”,“n”,“s”,“l”,“c”,“u”,“d”,“p”,
“b”,“f”,“g”,“h”,“j”,“k”,“m”,“q”,“v”,“w”,“x”,“y”,“z”
]
end
zachallaun
Enjoy the journey!
Just to consider alternatives to accomplish the same thing: you could still represent the most common letters as a list, but use a set to track guesses. Then you might have a function like this:
This isn’t necessarily “better” (and may actually be technically slower for small lists like you’re dealing with), but thought it might be worth seeing a different way of accomplishing the same thing. (BTW the above will also work if
usedis a list.)