All Projects → postmodern → combinatorics.rb

postmodern / combinatorics.rb

Licence: MIT license
Bringing (more) Combinatorics to Ruby.

Programming Languages

ruby
36898 projects - #4 most used programming language

Projects that are alternatives of or similar to combinatorics.rb

Math Php
Powerful modern math library for PHP: Features descriptive statistics and regressions; Continuous and discrete probability distributions; Linear algebra with matrices and vectors, Numerical analysis; special mathematical functions; Algebra
Stars: ✭ 2,009 (+4465.91%)
Mutual labels:  math, combinatorics
combi
Pythonic package for combinatorics
Stars: ✭ 51 (+15.91%)
Mutual labels:  math, combinatorics
AlgebraicPetri.jl
Build Petri net models compositionally
Stars: ✭ 49 (+11.36%)
Mutual labels:  math
census-error-analyzer
Analyze the margin of error in U.S. census data
Stars: ✭ 15 (-65.91%)
Mutual labels:  math
mish
A no-std libm implementation in Rust
Stars: ✭ 14 (-68.18%)
Mutual labels:  math
vec-la-fp
↗️ A tiny (functional) 2d linear algebra library
Stars: ✭ 21 (-52.27%)
Mutual labels:  math
BookLibrary
Book Library of P&W Studio
Stars: ✭ 13 (-70.45%)
Mutual labels:  math
decimal-eval
A tiny, safe, fast JavaScript library for decimal arithmetic expressions.
Stars: ✭ 18 (-59.09%)
Mutual labels:  math
lit
Literature for the self-taught AI practitioner! 📚
Stars: ✭ 199 (+352.27%)
Mutual labels:  math
discrete-math-python-scripts
Python code snippets from Discrete Mathematics for Computer Science specialization at Coursera
Stars: ✭ 98 (+122.73%)
Mutual labels:  combinatorics
symengine.rb
Ruby wrappers for SymEngine
Stars: ✭ 26 (-40.91%)
Mutual labels:  math
multitrainer
A math game for children to help them learning multiplication
Stars: ✭ 22 (-50%)
Mutual labels:  math
zig-gamedev
Building game development ecosystem for @ziglang!
Stars: ✭ 1,059 (+2306.82%)
Mutual labels:  math
Combinatorics.jl
A combinatorics library for Julia
Stars: ✭ 182 (+313.64%)
Mutual labels:  combinatorics
string-math
Evaluates a math expression from a string. Supports variables and custom operators.
Stars: ✭ 14 (-68.18%)
Mutual labels:  math
maths-for-deep-learning-ai
A open source book covering the foundational maths of deep learning and machine learning using TensorFlow
Stars: ✭ 35 (-20.45%)
Mutual labels:  math
tukey
Mini stats toolkit for Clojure/Script
Stars: ✭ 17 (-61.36%)
Mutual labels:  math
mathblog
A package for managing a static, mathematically-inclined web log
Stars: ✭ 25 (-43.18%)
Mutual labels:  math
hexo-filter-mathjax
💯 Server side MathJax renderer plugin for Hexo.
Stars: ✭ 76 (+72.73%)
Mutual labels:  math
math eval
✖️➕➖➗ `math_eval` safely evaluates mathematical expressions
Stars: ✭ 33 (-25%)
Mutual labels:  math

Combinatorics

CI Code Climate

Description

A collection of modules and methods for performing Combinatoric calculations. Methods are defined to compute power sets, Cartesian products, permutations, combinations, and derangements.

Note: this includes k-combinations and k-permutations, i.e. only generating resultant sets of a given size. Each set theory operation method supports block arguments to allow continuous code execution during the combinatoric set generation process. Each combinatoric operation implementation also supports a cardinality method which determines the total number of subsets that will be created beforehand (to aid in the avoidance of starting an operation which will never complete due to exponential computational complexity.)

Features

Examples

Power-set:

Set['ab', 'cd', 'ef'].powerset
# => [#<Set: {}>,
      #<Set: {"ef"}>,
      #<Set: {"cd"}>,
      #<Set: {"cd", "ef"}>,
      #<Set: {"ab"}>,
      #<Set: {"ab", "ef"}>,
      #<Set: {"ab", "cd"}>,
      #<Set: {"ab", "cd", "ef"}>]

Cartesian products:

require 'combinatorics/cartesian_product'

['a', 'b', 'c'].cartesian_product([0, 1, 2]).to_a
# => [["a", 0], 
      ["b", 0], 
      ["c", 0], 
      ["a", 1], 
      ["b", 1], 
      ["c", 1], 
      ["a", 2], 
      ["b", 2], 
      ["c", 2]]

k-combinations:

require 'combinatorics/choose'

('a'..'f').to_a.choose(2).to_a
# => [["a", "b"], 
      ["a", "c"], 
      ["a", "d"], 
      ["a", "e"], 
      ["a", "f"], 
      ["b", "c"], 
      ["b", "d"], 
      ["b", "e"], 
      ["b", "f"], 
      ["c", "d"], 
      ["c", "e"], 
      ["c", "f"], 
      ["d", "e"], 
      ["d", "f"], 
      ["e", "f"]]

Derangements:

require 'combinatorics/derange'

[:_, :q, :z, :x].derange.to_a
# => [[:q, :_, :x, :z], 
      [:q, :z, :x, :_], 
      [:q, :x, :_, :z], 
      [:z, :_, :x, :q], 
      [:z, :x, :_, :q], 
      [:z, :x, :q, :_], 
      [:x, :_, :q, :z], 
      [:x, :z, :_, :q], 
      [:x, :z, :q, :_]]

Permutation cardinality:

require 'combinatorics/permutation'

Combinatorics::Permute.cardinality(128)
# => 8256

List comprehensions:

require 'combinatorics/list_comprehension'

[(0..10).step(2),('a'..'c')].comprehension.to_a
# => [[0, "a"],
      [0, "b"],
      [0, "c"],
      [2, "a"],
      [2, "b"],
      [2, "c"],
      [4, "a"],
      [4, "b"],
      [4, "c"],
      [6, "a"],
      [6, "b"],
      [6, "c"],
      [8, "a"],
      [8, "b"],
      [8, "c"],
      [10, "a"],
      [10, "b"],
      [10, "c"]]

Find the intersecting sub-range between two ranges:

(1..50) & (20..100)
# => (20..50)

Enumerate over every sub-range between two ranges:

(1..5).upto(2..10).to_a
# => [1..5, 1..6, 1..7, 1..8, 1..9, 1..10,
      2..5, 2..6, 2..7, 2..8, 2..9, 2..10]

Requirements

Install

$ gem install combinatorics

Copyright

Copyright (c) 2010-2022 Hal Brodigan

See {file:LICENSE.txt} for license information.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].