pangrammic_surplus 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
data/README.md ADDED
@@ -0,0 +1,51 @@
1
+ ## Pangrammic Surplus
2
+
3
+ Determines the surplus of characters that satisfies a self-enumerating pangram.
4
+
5
+ ## Concept
6
+
7
+ When searching for self-enumerating pangrams, you'll often start with some boilerplate text and attempt to satisfy it with a list of numbers, for example:
8
+
9
+ ```This pangram lists one a, two b's, three c's ..... and one z.```
10
+
11
+ In this case, the boilerplate is ```This pangram lists and```
12
+
13
+ Pangrammic Surplus turns things the other way around. We give it a list of numbers and it tells us what characters are left to build boilerplate text from.
14
+
15
+ For example:
16
+
17
+ ```ruby
18
+ require 'pangrammic_surplus'
19
+
20
+ surplus = PangrammicSurplus.for(
21
+ 'a' => 4, 'b' => 1, 'c' => 1, 'd' => 2, 'e' => 29, 'f' => 8, 'g' => 3,
22
+ 'h' => 5, 'i' => 11, 'j' => 1, 'k' => 1, 'l' => 3, 'm' => 2, 'n' => 22,
23
+ 'o' => 15, 'p' => 2, 'q' => 1, 'r' => 7, 's' => 26, 't' => 19, 'u' => 4,
24
+ 'v' => 5, 'w' => 9, 'x' => 2, 'y' => 4, 'z' => 1
25
+ )
26
+
27
+ puts surplus.inspect
28
+ # 'a' => 3, 'b' => 0, 'c' => 0, 'd' => 1, 'e' => 0, 'f' => 0, 'g' => 1,
29
+ # 'h' => 1, 'i' => 2, 'j' => 0, 'k' => 0, 'l' => 1, 'm' => 1, 'n' => 2,
30
+ # 'o' => 0, 'p' => 1, 'q' => 0, 'r' => 1, 's' => 3, 't' => 2, 'u' => 0,
31
+ # 'v' => 0, 'w' => 0, 'x' => 0, 'y' => 0, 'z' => 0
32
+
33
+ non_zero_letters = surplus.reject { |letter, count| count.zero? }
34
+ puts non_zero_letters.inspect
35
+ # 'a' => 3, 'd' => 1, 'g' => 1, 'h' => 1, 'i' => 2, 'l' => 1, 'm' => 1,
36
+ # 'n' => 2, 'p' => 1, 'r' => 1, 's' => 3, 't' => 2
37
+ ```
38
+
39
+ If we can construct boilerplate from an anagram of these letters, we have a true self-enumerating pangram.
40
+
41
+ ```This pangram lists and``` is one possible anagram, in this case.
42
+
43
+ And therefore, the following is a true self-enumerating pangram:
44
+
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
+
47
+ ## Contribution
48
+
49
+ Feel free to contribute. No commit is too small.
50
+
51
+ You should follow me: [@cpatuzzo](https://twitter.com/cpatuzzo)
@@ -0,0 +1,6 @@
1
+ require 'numbers_and_words'
2
+
3
+ require 'pangrammic_surplus/base'
4
+ require 'pangrammic_surplus/minimal_count'
5
+ require 'pangrammic_surplus/word_hash'
6
+ require 'pangrammic_surplus/vector'
@@ -0,0 +1,9 @@
1
+ class PangrammicSurplus
2
+ class << self
3
+
4
+ def for(input)
5
+ Vector.subtract(input, MinimalCount.for(input))
6
+ end
7
+
8
+ end
9
+ end
@@ -0,0 +1,21 @@
1
+ class PangrammicSurplus::MinimalCount
2
+ class << self
3
+
4
+ def for(input)
5
+ terms = input.map { |k, v| term(k, v) }
6
+ ps::Vector.add(*terms)
7
+ end
8
+
9
+ private
10
+ def term(character, count)
11
+ hash = ps::WordHash.for(count)
12
+ hash[character] += 1
13
+ hash
14
+ end
15
+
16
+ def ps
17
+ PangrammicSurplus
18
+ end
19
+
20
+ end
21
+ end
@@ -0,0 +1,18 @@
1
+ class PangrammicSurplus::Vector
2
+ class << self
3
+
4
+ def add(*v)
5
+ first = v.first
6
+ first.inject({}) do |hash, (k, _)|
7
+ sum = v.map { |h| h[k] }.inject(:+)
8
+ hash.merge(k => sum)
9
+ end
10
+ end
11
+
12
+ def subtract(a, b)
13
+ _b = b.inject({}) { |h, (k, v)| h.merge(k => -v) }
14
+ add(a, _b)
15
+ end
16
+
17
+ end
18
+ end
@@ -0,0 +1,21 @@
1
+ class PangrammicSurplus::WordHash
2
+ class << self
3
+
4
+ def for(integer)
5
+ @memo ||= {}
6
+ @memo[integer] ||= hash_for(integer)
7
+ @memo[integer].clone
8
+ end
9
+
10
+ private
11
+ def hash_for(integer)
12
+ term = integer.to_words
13
+ term += 's' if integer > 1
14
+
15
+ ('a'..'z').inject({}) do |h, c|
16
+ h.merge(c => term.count(c))
17
+ end
18
+ end
19
+
20
+ end
21
+ end
metadata ADDED
@@ -0,0 +1,98 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: pangrammic_surplus
3
+ version: !ruby/object:Gem::Version
4
+ hash: 29
5
+ prerelease:
6
+ segments:
7
+ - 0
8
+ - 0
9
+ - 1
10
+ version: 0.0.1
11
+ platform: ruby
12
+ authors:
13
+ - Christopher Patuzzo
14
+ autorequire:
15
+ bindir: bin
16
+ cert_chain: []
17
+
18
+ date: 2012-10-20 00:00:00 Z
19
+ dependencies:
20
+ - !ruby/object:Gem::Dependency
21
+ name: numbers_and_words
22
+ prerelease: false
23
+ requirement: &id001 !ruby/object:Gem::Requirement
24
+ none: false
25
+ requirements:
26
+ - - ">="
27
+ - !ruby/object:Gem::Version
28
+ hash: 3
29
+ segments:
30
+ - 0
31
+ version: "0"
32
+ type: :runtime
33
+ version_requirements: *id001
34
+ - !ruby/object:Gem::Dependency
35
+ name: rspec
36
+ prerelease: false
37
+ requirement: &id002 !ruby/object:Gem::Requirement
38
+ none: false
39
+ requirements:
40
+ - - ">="
41
+ - !ruby/object:Gem::Version
42
+ hash: 3
43
+ segments:
44
+ - 0
45
+ version: "0"
46
+ type: :development
47
+ version_requirements: *id002
48
+ description: Determines the surplus of characters that satisfies a self-enumerating pangram.
49
+ email: chris@patuzzo.co.uk
50
+ executables: []
51
+
52
+ extensions: []
53
+
54
+ extra_rdoc_files: []
55
+
56
+ files:
57
+ - README.md
58
+ - lib/pangrammic_surplus/base.rb
59
+ - lib/pangrammic_surplus/minimal_count.rb
60
+ - lib/pangrammic_surplus/vector.rb
61
+ - lib/pangrammic_surplus/word_hash.rb
62
+ - lib/pangrammic_surplus.rb
63
+ homepage: https://github.com/cpatuzzo/pangrammic_surplus
64
+ licenses: []
65
+
66
+ post_install_message:
67
+ rdoc_options: []
68
+
69
+ require_paths:
70
+ - lib
71
+ required_ruby_version: !ruby/object:Gem::Requirement
72
+ none: false
73
+ requirements:
74
+ - - ">="
75
+ - !ruby/object:Gem::Version
76
+ hash: 3
77
+ segments:
78
+ - 0
79
+ version: "0"
80
+ required_rubygems_version: !ruby/object:Gem::Requirement
81
+ none: false
82
+ requirements:
83
+ - - ">="
84
+ - !ruby/object:Gem::Version
85
+ hash: 3
86
+ segments:
87
+ - 0
88
+ version: "0"
89
+ requirements: []
90
+
91
+ rubyforge_project:
92
+ rubygems_version: 1.8.24
93
+ signing_key:
94
+ specification_version: 3
95
+ summary: Pangrammic Surplus
96
+ test_files: []
97
+
98
+ has_rdoc: