trackler 2.0.5.12 → 2.0.5.13

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: a74ea7b78858cd111f71b62b3e7f1aadf7a294c4
4
- data.tar.gz: d5468a4b337811562139e31591574804cb6823fb
3
+ metadata.gz: c3fb3f595ae75435478d8fbbef0c23e2162172ed
4
+ data.tar.gz: 80fd34ca47be249684cb10419cc188010031190d
5
5
  SHA512:
6
- metadata.gz: c2b420709ed64865854ee540e23a723fba890d35055e79cb0bb27809106a2e9bc97ba3c423d54517df9bde477a4bd2260f5e1fbf351e7e855c8037c4cb881954
7
- data.tar.gz: e6afa21c6df59af4374d17fc5e0e3ce75f0b7d04e77ab1a672d4239cedad26af92a8bb7f56334fe9144e3fbbbc2d20d59343ecbe0b51537e1567569f2c1da5d4
6
+ metadata.gz: 7f4ad43839ccb8751ab5d572c1711a66d8bbfdcd9549494e88b03fb67bdb5305052cb81abcf4060f229b845995096153714e0ffa13d77d19410f0fd5cd90cd6c
7
+ data.tar.gz: 35db17c7480a108dfc9599364d9092ab8da5ba8dac0d1c010d9ee4f5dcb2fa7b576431b0890912fed0567d24a49bd904b83a0261f66fcfe8ed9c76abad5b92bc
@@ -1,3 +1,3 @@
1
1
  module Trackler
2
- VERSION = "2.0.5.12"
2
+ VERSION = "2.0.5.13"
3
3
  end
@@ -22,7 +22,6 @@
22
22
  "acronym",
23
23
  "scrabble-score",
24
24
  "roman-numerals",
25
- "binary",
26
25
  "prime-factors",
27
26
  "raindrops",
28
27
  "allergies",
@@ -30,12 +29,9 @@
30
29
  "atbash-cipher",
31
30
  "accumulate",
32
31
  "crypto-square",
33
- "trinary",
34
32
  "rna-transcription",
35
- "hexadecimal",
36
33
  "sieve",
37
34
  "simple-cipher",
38
- "octal",
39
35
  "luhn",
40
36
  "pig-latin",
41
37
  "simple-linked-list",
@@ -150,11 +146,6 @@
150
146
  "difficulty": 1,
151
147
  "topics": []
152
148
  },
153
- {
154
- "slug": "binary",
155
- "difficulty": 1,
156
- "topics": []
157
- },
158
149
  {
159
150
  "slug": "prime-factors",
160
151
  "difficulty": 1,
@@ -190,21 +181,11 @@
190
181
  "difficulty": 1,
191
182
  "topics": []
192
183
  },
193
- {
194
- "slug": "trinary",
195
- "difficulty": 1,
196
- "topics": []
197
- },
198
184
  {
199
185
  "slug": "rna-transcription",
200
186
  "difficulty": 1,
201
187
  "topics": []
202
188
  },
203
- {
204
- "slug": "hexadecimal",
205
- "difficulty": 1,
206
- "topics": []
207
- },
208
189
  {
209
190
  "slug": "sieve",
210
191
  "difficulty": 1,
@@ -215,11 +196,6 @@
215
196
  "difficulty": 1,
216
197
  "topics": []
217
198
  },
218
- {
219
- "slug": "octal",
220
- "difficulty": 1,
221
- "topics": []
222
- },
223
199
  {
224
200
  "slug": "luhn",
225
201
  "difficulty": 1,
@@ -332,6 +308,10 @@
332
308
  }
333
309
  ],
334
310
  "deprecated": [
311
+ "binary",
312
+ "hexadecimal",
313
+ "octal",
314
+ "trinary"
335
315
  ],
336
316
  "ignored": [
337
317
  "_template",
@@ -488,6 +488,16 @@
488
488
  "algorithms",
489
489
  "control-flow (loops)"
490
490
  ]
491
+ }, {
492
+ "slug": "tournament",
493
+ "difficulty": 5,
494
+ "topics": [
495
+ "arrays",
496
+ "strings",
497
+ "text formatting",
498
+ "text parsing",
499
+ "control-flow (loops)"
500
+ ]
491
501
  }, {
492
502
  "slug": "circular-buffer",
493
503
  "difficulty": 4,
@@ -0,0 +1,80 @@
1
+ local function pad_right(s, width)
2
+ return s .. (' '):rep(width - #s)
3
+ end
4
+
5
+ local function parse(results)
6
+ local stats = {}
7
+
8
+ for _, result in ipairs(results) do
9
+ local t1, t2, outcome = result:match('^([^;]+);([^;]+);([^;]+)$')
10
+
11
+ if t1 and t2 and outcome then
12
+ stats[t1] = stats[t1] or { w = 0, l = 0, d = 0 }
13
+ stats[t2] = stats[t2] or { w = 0, l = 0, d = 0 }
14
+
15
+ if outcome == 'win' then
16
+ stats[t1].w = stats[t1].w + 1
17
+ stats[t2].l = stats[t2].l + 1
18
+ elseif outcome == 'loss' then
19
+ stats[t1].l = stats[t1].l + 1
20
+ stats[t2].w = stats[t2].w + 1
21
+ elseif outcome == 'draw' then
22
+ stats[t1].d = stats[t1].d + 1
23
+ stats[t2].d = stats[t2].d + 1
24
+ end
25
+ end
26
+ end
27
+
28
+ return stats
29
+ end
30
+
31
+ local function finalize(stats)
32
+ for _, team_stats in pairs(stats) do
33
+ team_stats.mp = team_stats.w + team_stats.l + team_stats.d
34
+ team_stats.p = team_stats.w * 3 + team_stats.d
35
+ end
36
+ end
37
+
38
+ local function sorted_stats(stats)
39
+ local sorted = {}
40
+
41
+ for name, stats in pairs(stats) do
42
+ table.insert(sorted, { name = name, stats = stats })
43
+ end
44
+
45
+ table.sort(sorted, function(x, y)
46
+ if x.stats.p == y.stats.p then
47
+ return x.name < y.name
48
+ else
49
+ return x.stats.p > y.stats.p
50
+ end
51
+ end)
52
+
53
+ return sorted
54
+ end
55
+
56
+ local function format(stats)
57
+ local sorted = sorted_stats(stats)
58
+ local formatted = {}
59
+
60
+ table.insert(formatted, pad_right('Team', 31) .. '| MP | W | D | L | P')
61
+ for _, b in ipairs(sorted) do
62
+ table.insert(formatted, string.format(
63
+ '%s| %2d | %2d | %2d | %2d | %2d',
64
+ pad_right(b.name, 31),
65
+ b.stats.mp,
66
+ b.stats.w,
67
+ b.stats.d,
68
+ b.stats.l,
69
+ b.stats.p
70
+ ))
71
+ end
72
+
73
+ return formatted
74
+ end
75
+
76
+ return function(results)
77
+ local stats = parse(results)
78
+ finalize(stats)
79
+ return format(stats)
80
+ end
@@ -0,0 +1,153 @@
1
+ local tournament = require 'tournament'
2
+
3
+ describe('tournament', function()
4
+ it('should generate standings for a complete competition', function()
5
+ local results = {
6
+ 'Allegoric Alaskans;Blithering Badgers;win',
7
+ 'Devastating Donkeys;Courageous Californians;draw',
8
+ 'Devastating Donkeys;Allegoric Alaskans;win',
9
+ 'Courageous Californians;Blithering Badgers;loss',
10
+ 'Blithering Badgers;Devastating Donkeys;loss',
11
+ 'Allegoric Alaskans;Courageous Californians;win'
12
+ }
13
+
14
+ local expected = {
15
+ 'Team | MP | W | D | L | P',
16
+ 'Devastating Donkeys | 3 | 2 | 1 | 0 | 7',
17
+ 'Allegoric Alaskans | 3 | 2 | 0 | 1 | 6',
18
+ 'Blithering Badgers | 3 | 1 | 0 | 2 | 3',
19
+ 'Courageous Californians | 3 | 0 | 1 | 2 | 1'
20
+ }
21
+
22
+ assert.are.same(expected, tournament(results))
23
+ end)
24
+
25
+ it('should generate standings for an incomplete competition', function()
26
+ local results = {
27
+ 'Allegoric Alaskans;Blithering Badgers;loss',
28
+ 'Devastating Donkeys;Allegoric Alaskans;loss',
29
+ 'Courageous Californians;Blithering Badgers;draw',
30
+ 'Allegoric Alaskans;Courageous Californians;win'
31
+ }
32
+
33
+ local expected = {
34
+ 'Team | MP | W | D | L | P',
35
+ 'Allegoric Alaskans | 3 | 2 | 0 | 1 | 6',
36
+ 'Blithering Badgers | 2 | 1 | 1 | 0 | 4',
37
+ 'Courageous Californians | 2 | 0 | 1 | 1 | 1',
38
+ 'Devastating Donkeys | 1 | 0 | 0 | 1 | 0'
39
+ }
40
+
41
+ assert.are.same(expected, tournament(results))
42
+ end)
43
+
44
+ it('should break any ties alphabetically', function()
45
+ local results = {
46
+ 'Courageous Californians;Devastating Donkeys;win',
47
+ 'Allegoric Alaskans;Blithering Badgers;win',
48
+ 'Devastating Donkeys;Allegoric Alaskans;loss',
49
+ 'Courageous Californians;Blithering Badgers;win',
50
+ 'Blithering Badgers;Devastating Donkeys;draw',
51
+ 'Allegoric Alaskans;Courageous Californians;draw'
52
+ }
53
+
54
+ local expected = {
55
+ 'Team | MP | W | D | L | P',
56
+ 'Allegoric Alaskans | 3 | 2 | 1 | 0 | 7',
57
+ 'Courageous Californians | 3 | 2 | 1 | 0 | 7',
58
+ 'Blithering Badgers | 3 | 0 | 1 | 2 | 1',
59
+ 'Devastating Donkeys | 3 | 0 | 1 | 2 | 1'
60
+ }
61
+
62
+ assert.are.same(expected, tournament(results))
63
+ end)
64
+
65
+ it('should ignore blank lines', function()
66
+ local results = {
67
+ 'Allegoric Alaskans;Blithering Badgers;win',
68
+ '',
69
+ 'Devastating Donkeys;Courageous Californians;draw',
70
+ 'Devastating Donkeys@Courageous Californians;draw',
71
+ 'Devastating Donkeys;Allegoric Alaskans;win',
72
+ 'Courageous Californians;Blithering Badgers;loss',
73
+ 'Blithering Badgers;Devastating Donkeys;loss',
74
+ 'Allegoric Alaskans;Courageous Californians;win'
75
+ }
76
+
77
+ local expected = {
78
+ 'Team | MP | W | D | L | P',
79
+ 'Devastating Donkeys | 3 | 2 | 1 | 0 | 7',
80
+ 'Allegoric Alaskans | 3 | 2 | 0 | 1 | 6',
81
+ 'Blithering Badgers | 3 | 1 | 0 | 2 | 3',
82
+ 'Courageous Californians | 3 | 0 | 1 | 2 | 1'
83
+ }
84
+
85
+ assert.are.same(expected, tournament(results))
86
+ end)
87
+
88
+ it('should ignore lines with invalid separators', function()
89
+ local results = {
90
+ 'Allegoric Alaskans;Blithering Badgers;win',
91
+ 'Devastating Donkeys;Courageous Californians;draw',
92
+ 'Devastating Donkeys@Courageous Californians;draw',
93
+ 'Devastating Donkeys;Allegoric Alaskans;win',
94
+ 'Courageous Californians;Blithering Badgers;loss',
95
+ 'Blithering Badgers;Devastating Donkeys;loss',
96
+ 'Allegoric Alaskans;Courageous Californians;win'
97
+ }
98
+
99
+ local expected = {
100
+ 'Team | MP | W | D | L | P',
101
+ 'Devastating Donkeys | 3 | 2 | 1 | 0 | 7',
102
+ 'Allegoric Alaskans | 3 | 2 | 0 | 1 | 6',
103
+ 'Blithering Badgers | 3 | 1 | 0 | 2 | 3',
104
+ 'Courageous Californians | 3 | 0 | 1 | 2 | 1'
105
+ }
106
+
107
+ assert.are.same(expected, tournament(results))
108
+ end)
109
+
110
+ it('should ignore lines with too many separators', function()
111
+ local results = {
112
+ 'Allegoric Alaskans;Blithering Badgers;win',
113
+ 'Devastating Donkeys;Courageous Californians;draw',
114
+ 'Devastating Donkeys;Courageous Californians;draw;5',
115
+ 'Devastating Donkeys;Allegoric Alaskans;win',
116
+ 'Courageous Californians;Blithering Badgers;loss',
117
+ 'Blithering Badgers;Devastating Donkeys;loss',
118
+ 'Allegoric Alaskans;Courageous Californians;win'
119
+ }
120
+
121
+ local expected = {
122
+ 'Team | MP | W | D | L | P',
123
+ 'Devastating Donkeys | 3 | 2 | 1 | 0 | 7',
124
+ 'Allegoric Alaskans | 3 | 2 | 0 | 1 | 6',
125
+ 'Blithering Badgers | 3 | 1 | 0 | 2 | 3',
126
+ 'Courageous Californians | 3 | 0 | 1 | 2 | 1'
127
+ }
128
+
129
+ assert.are.same(expected, tournament(results))
130
+ end)
131
+
132
+ it('should ignore lines with invalid match results', function()
133
+ local results = {
134
+ 'Allegoric Alaskans;Blithering Badgers;win',
135
+ 'Devastating Donkeys;Courageous Californians;draw',
136
+ 'Devastating Donkeys;Allegoric Alaskans;dra',
137
+ 'Devastating Donkeys;Allegoric Alaskans;win',
138
+ 'Courageous Californians;Blithering Badgers;loss',
139
+ 'Blithering Badgers;Devastating Donkeys;loss',
140
+ 'Allegoric Alaskans;Courageous Californians;win'
141
+ }
142
+
143
+ local expected = {
144
+ 'Team | MP | W | D | L | P',
145
+ 'Devastating Donkeys | 3 | 2 | 1 | 0 | 7',
146
+ 'Allegoric Alaskans | 3 | 2 | 0 | 1 | 6',
147
+ 'Blithering Badgers | 3 | 1 | 0 | 2 | 3',
148
+ 'Courageous Californians | 3 | 0 | 1 | 2 | 1'
149
+ }
150
+
151
+ assert.are.same(expected, tournament(results))
152
+ end)
153
+ end)
data/tracks/ruby/Gemfile CHANGED
@@ -1,6 +1,7 @@
1
1
  source 'https://rubygems.org'
2
2
 
3
3
  gem 'minitest'
4
+ gem 'rainbow', '>= 2.1.0', '< 2.2.0'
4
5
  gem 'rubocop', '0.36.0'
5
6
  gem 'simplecov'
6
7
  gem 'rake'
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: trackler
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.5.12
4
+ version: 2.0.5.13
5
5
  platform: ruby
6
6
  authors:
7
7
  - Katrina Owen
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-12-27 00:00:00.000000000 Z
11
+ date: 2016-12-28 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rubyzip
@@ -4597,6 +4597,8 @@ files:
4597
4597
  - tracks/lua/exercises/sublist/sublist_spec.lua
4598
4598
  - tracks/lua/exercises/sum-of-multiples/example.lua
4599
4599
  - tracks/lua/exercises/sum-of-multiples/sum-of-multiples_spec.lua
4600
+ - tracks/lua/exercises/tournament/example.lua
4601
+ - tracks/lua/exercises/tournament/tournament_spec.lua
4600
4602
  - tracks/lua/exercises/transpose/example.lua
4601
4603
  - tracks/lua/exercises/transpose/transpose_spec.lua
4602
4604
  - tracks/lua/exercises/triangle/example.lua