Skip to content
Automatic Ramda solution bot
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
src
tests
.gitignore
.npmrc
.travis.yml
README.md
package.json
rambo.jpg

README.md

Rambo

Automatic Ramda solution bot

rambo

Given inputs and outputs brute forces a Ramda solution.

Example

What Ramda solution given [1, 2, 3, 4] returns [5, 6, 7, 8]?

const solve = require('rambo').solve
const solution = solve([1, 2, 3, 4], [5, 6, 7, 8])
console.log(solution.name) // "R.map(R.add(4))"
// has "f" property with solution function
console.log(solution.f([1, 2, 3, 4])) // [5, 6, 7, 8]
// can apply to other inputs
console.log(solution.f([20, 30])) // [24, 34]

Produce example

Some cases do not have any inputs. For example, what Ramda command produces [50, 51, 52]?

const produce = require('rambo').produce
const solution = produce([50, 51, 52])
console.log(solution.name) // "R.range(50, 53)"
console.log(solution.f()) // [50, 51, 52]

Why?

Because there are 200 functions in Ramda library, and I constantly have to look up which function I should use. Plus there is ram-bot in the Ramda Gitter channel that given input and Ramda code computes the output. I wanted to find Ramda code that computes the answer!

// ram-bot
Ramda code (inputs) ===> ?
// Rambo
Ramda ? (inputs) ===> outputs

How?

The solver is very simple and just brute forces the solution by iterating over a bunch of functions. Since Ramda is sooooo good at currying, we can combine multiple functions by providing derived functions as inputs to other functions, like R.map for example, as first arguments. I also use the data to guide the solution tries. For example, R.has(...) tries every string from the input and output as a property name.

const solve = require('rambo').solve
const input = [{foo: 'bar'}, {name: 'alice'}, {name: 'bob'}, {foo: 42}]
const output = [{name: 'alice'}, {name: 'bob'}]
solve(input, output)
// tries R.map(R.has('foo'))
// tries R.map(R.has('name'))
// tries R.map(R.has('bar'))
// tries R.map(R.has('alice'))
// ...

Hope others can contribute to this effort, since I know nothing about symbolic computation and automatic solvers. Rambo is my attempt at brute forcing a problem with a small solution set.

Details

You can provide multiple input / output pairs

const solution = solve([
  [input1, output1],
  [input2, output2],
  ...
])

This is useful because sometimes there might be multiple solutions for a single input / output pair.

NPM

Build status semantic-release js-standard-style

Small print

Author: Gleb Bahmutov <gleb.bahmutov@gmail.com> © 2016

License: MIT - do anything with the code, but don't blame me if it does not work.

Support: if you find any problems with this module, email / tweet / open issue on Github

MIT License

Copyright (c) 2016 Gleb Bahmutov <gleb.bahmutov@gmail.com>

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

You can’t perform that action at this time.