0.0
No commit activity in last 3 years
No release in over 3 years
Various extensions for the Integer class
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

~> 0.8
~> 1.3
~> 0.9
 Project Readme

Build Status Inline docs Coverage Status OpenInteger

OpenInteger is "open" as in "open source" and "open classes". It's here to provide some niche functionality to the Integer class that doesn't come baked in.

I have a single goal in mind for this project: readability. It's one thing to know that n! can be expressed in a single line as (1..n).inject(:*) but it's so much nicer (and clearer) to write n.factorial.

Getting the Gem

You've got two options until I publish the gem to RubyGems: add my Gemfury repo and install from the command line or build the gem from source and install.

From Gemfury

  • gem install open_integer --source https://repo.fury.io/jrconner384/

Build it Yourself

  • Navigate to wherever you want to clone the repo.
  • git clone https://github.com/jrconner384/open_integer
  • gem build open_integer.gemspec
  • gem install open_integer-<version>.gem where <version> is whatever version number the gem build process tacked on to the gem name.

RubyGems (tentative)

  • gem install open_integer

Changelog

Version 0.4.0 (pre-release)

This is a fairly big milestone in this project's life, thanks mostly to me figuring out a few things about minitest, Travis CI, and installing a gem locally without the need to publish it (trust me, that caused me some pain).

minitest!

I'm learning minitest. I've already started publishing some specs here which, hopefully, will provide a measure of sanity. At a minimum, the specs will demonstrate when I get the math concepts wrong, which I expect to happen since I'm not a particularly strong mathematician.

To create a robust test suite, I've started using exceptions to more descriptively demonstrate failure conditions. This is to replace things like esoteric NoMethodErrors and ZeroDivisionErrors the runtime was (correctly) throwing with nicer messages describing why something has failed.

Travis!

I'm now using Travis to keep the test suite running following each push to the repo. I got my first round of tests working as expected and I got Travis to successfully run the tests so now I've got a delightful green (for now) 'passing' badge.

Fewer versions, just as many updates!

At this stage, I intend to push out new versions much less frequently without reducing the frequency of commits to the code base. That'll mean that the head will be nominally unstable but I won't be hurtling towards ridiculous version numbers. I'm pretty sure that, at this rate, I'd have released v0.267.0 in the next couple of weeks.

New methods!

  • #divisors - Gets you the proper divisors of the number this is called on. A proper divisor is defined by Wolfram MathWorld as positive divisors of a value excluding that value itself.
  • #lowest_prime_factor - Works as read.

Updated implementations!

These are based largely on me mistakenly treating factors and divisors as the same thing.

  • #factors
  • Only returns or yields values greater than 1.
  • Now raises a RuntimeError if called on values less than 2.
  • #factor_of? raises a RuntimeError if called on 0. Docs updated with this change.
  • #abundant?, #deficient?, and #perfect? use the new #divisors method. Docs updated to reflect this change.

Version 0.3.1

Bug fix!

#factors now works correctly does a different wrong thing when called on 1.

Apologies. Version 0.3.1 identifies 1 as a factor of 1 but, since my goal is to find proper factors, 1 doesn't have any factors and this version does not correctly demonstrate that.

Version 0.3.0

New method!

  • #amicable_with?(other) - A number a is amicable with another number b if the following conditions are met:
  • a is not equal to b.
  • The sum of the factors of a is equal to b.
  • The sum of the factors of b is equal to a.

Version 0.2.0

New methods!

  • #abundant? - An abundant number is one for which the sum of its proper divisors is greater than the number itself.
  • #deficient? - A deficient number is one for which the sum of its proper divisors is less than the number itself.
  • #perfect? - A perfect number is one for which the sum of its proper divisors exactly equals the number itself.

Bug discovery!

  • See Issue #1. 0.factor_of(n) causes a ZeroDivisionError

Version 0.1.0

I'm trying to keep to semantic versioning which I haven't exactly done properly so far. I'm adding a new method, #factors, though and it's a backwards compatible change so that means minor version bump. Details follow.

New Methods

  • #factors: Returns an array of the factors of self. This is mainly refactored out of #factor_pairs which first identified the factors then created an array of factor pairs. It was messy and that brings us to patch-level changes.

Implementation Changes

  • #choose(k): removed uses of the informal "shriek" to refer to factorials in favor of vanilla flavored "factorial".
  • #factor_pairs: now calls #factors instead of generating the collection of factors on its own.