uri
Brute - A way to create streams of combinations
Hey guys,
I recently created a 0.1.0 version of my project Brute. Brute is a way of generating various combinations for a given character set. For example it can generate the the combinations of the set {a, b} of length five with the following:
iex> Brute.generic('ab', 5) |> Enum.to_list
["aaaaa", "baaaa", "abaaa", "bbaaa", "aabaa", "babaa", "abbaa", "bbbaa",
"aaaba", "baaba", "ababa", "bbaba", "aabba", "babba", "abbba", "bbbba",
"aaaab", "baaab", "abaab", "bbaab", "aabab", "babab", "abbab", "bbbab",
"aaabb", "baabb", "ababb", "bbabb", "aabbb", "babbb", "abbbb", "bbbbb"]
You can also provide ranges
iex> Brute.generic(?0..?4, 2) |> Enum.to_list
["00", "10", "20", "30", "40", "01", "11", "21", "31", "41", "02", "12", "22",
"32", "42", "03", "13", "23", "33", "43", "04", "14", "24", "34", "44"]
And if you provide a range for the “depth” parameter, it will give you a the sets ordered by depth
iex> Brute.generic('ab', 1..3) |> Enum.to_list
["a", "b", "aa", "ba", "ab", "bb", "aaa", "baa", "aba", "bba", "aab", "bab",
"abb", "bbb"]
I plan on creating a cache for these sets so for example, if a set of depth 10 is requested it might be sped up if sets 1-9 are already present in the cache.
I’m sure there are tons of improvements I can make before a 1.0.0 release, so I would greatly appreciate any feedback!
edit: Woops forgot to add the actual link!
Most Liked
uri
jmitchell
Cool project!
In case you’re interested, our projects may eventually benefit from each other. Backtrex implements a generic backtracking algorithm, and your project is a specialization of that problem over ranges and acceptable lengths. Brute’s input ranges correspond to Backtrex’s values callback, and similarly an acceptable length in Brute corresponds to the number of unknowns specified in Backtrex’s unknowns callback. Your API is helping me realize I should consider supporting a variable amount of unknowns. Currently Brute doesn’t seem to do any additional filtering like Bactrex’s valid? callback, but it may not be all that helpful since users can simply pipe to Stream.filter/2.
For now Backtrex only returns the first solution (in Brute’s case the head of the output Stream.t), but there are plans to return a Stream.t like Brute does. Eventually I plan to support parallel search at the expense of deterministic order, which could be handy for brute as well if it proves efficient enough. Then again, Brute doesn’t have to assign a unique ID for every unknown, so maybe it would cause unnecessary overhead.
Eiji
I would like to have one more method:
Brute.similar('something') # defaults: 1 and 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQSTUVWXYZ'
# polish letters:
Brute.similar('something', 2, 'aąbcćdeęfghijklłmnńoópqrstuvwxyzźżAĄBCĆDEĘFGHIJKLŁMNŃOÓPQRSŚTUVWXYZŹŻ')
Brute.similar("something", 1, "aąbcćdeęfghijklłmnńoópqrstuvwxyzźżAĄBCĆDEĘFGHIJKLŁMNŃOÓPQRSŚTUVWXYZŹŻ")
# where:
# 1st parameter is query list/string with one of more possible typos
# 2nd parameter is a number of allowed typos for query
# 3rd parameter is character list/string that could be replaced with possible typos
This could be helpful for search engines.
Popular in Announcing
Other popular topics
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
- #phoenix_html
- #iex
- #blog-post
- #graphql
- #genstage
- #ai
- #websockets
- #supervisor
- #advent-of-code
- #elixirconf-us
- #distillery
- #processes
- #forms
- #api
- #metaprogramming
- #security
- #performance









