uri

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!

https://github.com/uri/brute

Most Liked

uri

uri

Thanks for your suggestions @Eiji. I’ll see how the project evolves and consider these changes.

jmitchell

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

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.

Where Next?

Popular in Announcing Top

deadtrickster
I’ve just released stable versions of my Prometheus Elixir libs: Elixir client [docs]; Ecto collector [docs]; Plugs instrumenter/Export...
New
wmnnd
Hi there, for my project DBLSQD, I needed a file storage solution that is a bit more flexible than Arc. Because I thought others might f...
New
tmbb
PhoenixWS - Websockets over Phoenix Channels Source code on Github here: GitHub - tmbb/phoenix_ws: Websockets implemented over Phoenix Ch...
New
josevalim
Yes, yet another parser combinator library! Most of the parser combinators in the ecosystem are either compile-time, often using AST tra...
159 19417 141
New
oltarasenko
Dear Elixir community, After a year of development, bug fixes, and improvements, we are proudly ready to share the release of Crawly 0.1...
New
Qqwy
Hello everyone, I wrote a small library today called MapDiff. It returns a map listing the (smallest amount of) changes to get from map...
New
josevalim
Hello everyone, We have just released NimbleCSV which is a small and fast CSV parsing library for Elixir. It allows developers to define...
New
fuelen
Hey folks! Want to present a toolkit for writing command-line user interfaces. It provides a convenient interface for colorizing text...
New
alisinabh
Hey everyone i’ve developed a library for Jalaali calendar for elixir which supports converting Gregorian dates to Jalaali and vice vers...
New
pkrawat1
Hey guyz We at @aviabird are working on a payment library in elixir/phoenix. We are targeting March 2018 to add 56 Gateways to it. Have...
New

Other popular topics Top

axelson
This post is a wiki (feel free to hit the edit button near the bottom right of this post to add your own changes!) This post collects co...
239 48342 226
New
electic
Hi, I am new to Elixir. I am trying to use the DateTime component to insert a date into MySQL however the there seems to be no way to fo...
New
msaraiva
Surface is an experimental library built on top of Phoenix LiveView and its new LiveComponent API that aims to provide a more declarative...
564 43757 214
New
belgoros
I’m not a pro in using Regex and can’t figure out why the following behaviour happens, especially if we take into account the difference ...
New
freewebwithme
Using vs code and installed ElixirLS: support and debugger. And I got an error popped up on start up says Failed to run ‘elixir’ comma...
New
aesmail
Hello guys, I have finally made it. I created an admin interface for a framework. It’s been on my todo list for years and with the curre...
New
romenigld
I am trying to run a deploy with docker and I successfully runned with this command: docker build -t romenigld/blog-prod . but when I t...
New
klo
Got a question about when to concat vs. prepending items to list then reversing to achieve appending. So i know lists boil down to [1 | ...
New
openscript
Hello! Sorry for this astonishing simple question, but I’m really stuck. I try to set up the intellij-elixir plugin, but I don’t know ho...
New
dokuzbir
I want to highlight html closing tags when i click a html tag. That works in .html files but doesnt work for html.eex templates. How can...
New

Latest on Elixir Forum

Elixir Forum

We're in Beta

About us Mission Statement