GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — GitHub - duper/combinatorics: Bringing (more) Combinatorics to Ruby.

BranchesTags
Open more actions menu
 
 

Latest commit

 

History

66 Commits
66 Commits

Folders and files

NameName
Last commit message
Last commit date
benchmarks
benchmarks
 
 
lib
lib
 
 
spec
spec
 
 
.document
.document
 
 
.gitignore
.gitignore
 
 
.rspec
.rspec
 
 
.yardopts
.yardopts
 
 
Benchmarks.md
Benchmarks.md
 
 
ChangeLog.md
ChangeLog.md
 
 
LICENSE.txt
LICENSE.txt
 
 
README.md
README.md
 
 
Rakefile
Rakefile
 
 
combinatorics.gemspec
combinatorics.gemspec
 
 
gemspec.yml
gemspec.yml
 
 

Repository files navigation

Combinatorics

  • github.com/postmodern/combinatorics
  • github.com/postmodern/combinatorics/issues
  • Postmodern (postmodern.mod3 at gmail.com)

Description

A collection of modules and methods for performing Combinatoric calculations.

Features

  • Adds powerset to {Array} and {Set}.
  • Added {Range#&}, {Range#upto} and {Range#downto}.
  • Adds Haskell/Python style list comprehensions via {Array#comprehension}.

Examples

Power-set of an {Array}:

require 'combinatorics/power_set'

[1,2,3,4].powerset
# => [[],
      [4],
      [3],
      [3, 4],
      [2],
      [2, 4],
      [2, 3],
      [2, 3, 4],
      [1],
      [1, 4],
      [1, 3],
      [1, 3, 4],
      [1, 2],
      [1, 2, 4],
      [1, 2, 3],
      [1, 2, 3, 4]]

Power-set of a {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"}>]

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]

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"]]

Requirements

  • ruby >= 1.8.7

Install

$ sudo gem install combinatorics

Copyright

Copyright (c) 2010 Hal Brodigan

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

About

Bringing (more) Combinatorics to Ruby.

rubygems.org/gems/combinatorics

Resources

Readme
MIT license
Activity

Stars

1 star

Watchers

1 watching

Forks

0 forks
Report repository

Releases

Packages

Contributors

Languages

You are visitor 01402520 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.