pangrammic_surplus 0.0.1 → 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/README.md +15 -0
- data/lib/pangrammic_surplus/base.rb +10 -2
- metadata +3 -3
data/README.md
CHANGED
@@ -44,6 +44,21 @@ And therefore, the following is a true self-enumerating pangram:
|
|
44
44
|
|
45
45
|
"This pangram lists four a's, one b, one c, two d's, twenty-nine e's, eight f's, three g's, five h's, eleven i's, one j, one k, three l's, two m's, twenty-two n's, fifteen o's, two p's, one q, seven r's, twenty-six s's, nineteen t's, four u's, five v's, nine w's, two x's, four y's, and one z."
|
46
46
|
|
47
|
+
## Satisfiability
|
48
|
+
|
49
|
+
Self-enumerating pangrams can only be constructed from surpluses of positive integers because we can't remove characters from the minimal sentence structures:
|
50
|
+
|
51
|
+
A pangram can not be created from on**e** **e**, because two have been used for that term alone. The surplus would infact be -1 before you even consider other terms.
|
52
|
+
|
53
|
+
In cases where there are no satisfiable pangrams for a given input, ```PangrammicSurplus.for``` returns nil, unless you pass true in for its second argument:
|
54
|
+
|
55
|
+
```ruby
|
56
|
+
PangrammicSurplus.for({ 'e' => 1 }, allow_negatives = true)
|
57
|
+
#=> { 'e' => -1 }
|
58
|
+
```
|
59
|
+
|
60
|
+
This may be useful if you're writing an algorithm that checks just how unsatisfiable the given attempt was.
|
61
|
+
|
47
62
|
## Contribution
|
48
63
|
|
49
64
|
Feel free to contribute. No commit is too small.
|
@@ -1,8 +1,16 @@
|
|
1
1
|
class PangrammicSurplus
|
2
2
|
class << self
|
3
3
|
|
4
|
-
def for(input)
|
5
|
-
|
4
|
+
def for(input, allow_negatives = false)
|
5
|
+
minimal = MinimalCount.for(input)
|
6
|
+
surplus = Vector.subtract(input, minimal)
|
7
|
+
|
8
|
+
(allow_negatives || satisfiable?(surplus)) ? surplus : nil
|
9
|
+
end
|
10
|
+
|
11
|
+
private
|
12
|
+
def satisfiable?(surplus)
|
13
|
+
surplus.all? { |_, v| v >= 0 }
|
6
14
|
end
|
7
15
|
|
8
16
|
end
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: pangrammic_surplus
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 23
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
|
+
- 1
|
7
8
|
- 0
|
8
9
|
- 0
|
9
|
-
|
10
|
-
version: 0.0.1
|
10
|
+
version: 1.0.0
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Christopher Patuzzo
|