boj-solvedac 0.1.0 → 0.4.2
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 +4 -4
- data/lib/boj-solvedac.rb +46 -14
- data/lib/colorize/colorize.rb +59 -0
- data/lib/data/data.rb +1 -1
- metadata +7 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e97f59decd24f566582a2d122146f25f29a438fe5b315960fc113344a8ef4ef1
|
4
|
+
data.tar.gz: 316233507d002926dd8df309526ff9dc9f042545bbd628f339b30cf8c1b89370
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 263f4f56e06ffbd11c6153597997ccfc7655ece984a5247009e5d6e977a09ebeb7df140203c2e03d648a65372999fb29cf6ee6cdf53dfc79dd57e265f45c8a1c
|
7
|
+
data.tar.gz: d5479ff94c96cc2bf9f7dae499668c2c6428bdcd40833336b98f9fb6baf3c05a9e73f07e0bdb4f131ad0d3cccbe8d31a29714f0caa86983cfddf0ce229bfe75a
|
data/lib/boj-solvedac.rb
CHANGED
@@ -1,4 +1,5 @@
|
|
1
1
|
require 'data/data.rb'
|
2
|
+
require 'colorize/colorize.rb'
|
2
3
|
|
3
4
|
module BOJ
|
4
5
|
class BOJSolvedAC < BOJData
|
@@ -30,6 +31,7 @@ module BOJ
|
|
30
31
|
when 'stat' then command_stat(level)
|
31
32
|
when 'prob' then command_prob(level)
|
32
33
|
when 'random' then command_random(level)
|
34
|
+
when 'solved' then command_solved(level)
|
33
35
|
when 'clear' then system('clear')
|
34
36
|
when 'help' then command_help
|
35
37
|
when /exit|quit/ then exit(1)
|
@@ -43,15 +45,15 @@ module BOJ
|
|
43
45
|
def command_stat(level)
|
44
46
|
@prev = ''
|
45
47
|
if level == "all"
|
46
|
-
puts "%-
|
48
|
+
puts "%-12s%8s%8s%8s" % ["Level", "Unsolved", "Solved", "Total"]
|
47
49
|
@stats.each_pair do |k, v|
|
48
50
|
stat = @levels[v.to_sym]
|
49
|
-
puts "%-10s
|
51
|
+
puts "%-17s%10s%8s%8s" % [color(k), stat[:unsolved], stat[:solved], stat[:total]]
|
50
52
|
end
|
51
53
|
elsif %w(bronze silver gold platinum diamond ruby).include? level
|
52
54
|
5.downto(1) do |i|
|
53
55
|
stat = @levels[@stats[(level+(i.to_s)).to_sym].to_sym]
|
54
|
-
puts "%-
|
56
|
+
puts "%-15s unsolved(%3s) solved(%3s) total(%3s)" % [color(level+(i.to_s)), stat[:unsolved], stat[:solved], stat[:total]]
|
55
57
|
end
|
56
58
|
else
|
57
59
|
if !level or !@stats[level.to_sym]
|
@@ -59,7 +61,7 @@ module BOJ
|
|
59
61
|
return
|
60
62
|
end
|
61
63
|
stat = @levels[@stats[level.to_sym].to_sym]
|
62
|
-
puts "%-
|
64
|
+
puts "%-15s unsolved(%3s) solved(%3s) total(%3s)" % [color(level), stat[:unsolved], stat[:solved], stat[:total]]
|
63
65
|
end
|
64
66
|
end
|
65
67
|
|
@@ -70,9 +72,8 @@ module BOJ
|
|
70
72
|
return
|
71
73
|
end
|
72
74
|
|
73
|
-
puts "%-10s %-15s" % ["ID", "Title"]
|
74
|
-
|
75
75
|
if op == "solved"
|
76
|
+
puts "%-10s %-10s %-15s" % ["Level", "ID", "Title"]
|
76
77
|
level_min = 0
|
77
78
|
level_max = 30
|
78
79
|
solved = {}
|
@@ -89,7 +90,7 @@ module BOJ
|
|
89
90
|
solved = solved.sort
|
90
91
|
i = 0
|
91
92
|
solved.each do |prob|
|
92
|
-
puts "%-
|
93
|
+
puts "%-15s%-10s%-15s" % [color(prob[1][:level]), prob[0], prob[1][:title]]
|
93
94
|
i+=1
|
94
95
|
if (i+1)%10 == 0
|
95
96
|
print("..... [q=quit] ")
|
@@ -98,6 +99,7 @@ module BOJ
|
|
98
99
|
end
|
99
100
|
end
|
100
101
|
else
|
102
|
+
puts "%-10s %-15s" % ["ID", "Title"]
|
101
103
|
list = @levels[@stats[op.to_sym].to_sym][:prob]
|
102
104
|
size = list.size
|
103
105
|
i = 0
|
@@ -115,26 +117,53 @@ module BOJ
|
|
115
117
|
end
|
116
118
|
|
117
119
|
def command_random(level)
|
118
|
-
problems = @levels[@stats[level.to_sym].to_sym][:prob] unless level==nil
|
119
|
-
level_str = level
|
120
|
-
|
121
120
|
if level == nil
|
122
121
|
max_level = 31
|
123
122
|
level = rand(max_level).to_s
|
124
123
|
problems = @levels[level.to_sym][:prob]
|
125
124
|
level_str = @stats.keys[level.to_i]
|
125
|
+
elsif %w(bronze silver gold platinum diamond ruby).include? level
|
126
|
+
level_str = level + (rand(5)+1).to_s
|
127
|
+
problems = @levels[@stats[level_str.to_sym].to_sym][:prob]
|
128
|
+
lever_str = @stats.keys[level.to_i]
|
129
|
+
elsif @stats[level.to_sym] == nil
|
130
|
+
puts "'#{level}' level does not exist.."
|
131
|
+
return
|
132
|
+
else
|
133
|
+
problems = @levels[@stats[level.to_sym].to_sym][:prob] unless level==nil
|
134
|
+
level_str = level
|
135
|
+
end
|
136
|
+
|
137
|
+
unsolved = []
|
138
|
+
problems.each_pair do |k, v|
|
139
|
+
unsolved.push(k) if v[:solved] == false
|
126
140
|
end
|
127
141
|
|
128
|
-
|
142
|
+
if unsolved.size == 0
|
143
|
+
puts "You solved every problems in '#{color(level_str)}'"
|
144
|
+
return
|
145
|
+
end
|
146
|
+
id = unsolved[rand(unsolved.size)]
|
129
147
|
title = problems[id][:title]
|
130
148
|
|
131
149
|
puts
|
132
|
-
puts "Level: #{level_str}"
|
133
|
-
puts "ID : #{id} (https://www.acmicpc.net/problem/#{id})"
|
150
|
+
puts "Level: #{color(level_str)}"
|
151
|
+
puts "ID : #{id} (https://www.acmicpc.net/problem/#{id})".default
|
134
152
|
puts "Title: #{title}"
|
135
153
|
puts
|
136
154
|
end
|
137
155
|
|
156
|
+
def command_solved(id)
|
157
|
+
path = 'stats/solved-problems.dat'
|
158
|
+
File.open(path, 'r+') # create one if one doesn't exist
|
159
|
+
problems = IO.read(path).chomp
|
160
|
+
problems += " #{id}"
|
161
|
+
File.open(path, "r+") do |f|
|
162
|
+
f.puts problems
|
163
|
+
end
|
164
|
+
fetch_solved_data
|
165
|
+
end
|
166
|
+
|
138
167
|
def command_help
|
139
168
|
puts '''
|
140
169
|
levels you can specify:
|
@@ -157,6 +186,9 @@ module BOJ
|
|
157
186
|
random --> randomly pick a problem from all levels
|
158
187
|
random [LEVEL] --> randomly pick a problem from [LEVEL]
|
159
188
|
* hit [ENTER] to repeat the previous \'random\' command
|
189
|
+
solved:
|
190
|
+
solved [ID] --> adds [ID] to \'solved-problems.dat\' and
|
191
|
+
updates the stat.
|
160
192
|
clear:
|
161
193
|
clear --> clears the screen
|
162
194
|
exit:
|
@@ -168,7 +200,7 @@ module BOJ
|
|
168
200
|
|
169
201
|
def start
|
170
202
|
while true do
|
171
|
-
print
|
203
|
+
print "%s" % "boj-solvedac> ".default
|
172
204
|
command(gets.chomp)
|
173
205
|
end
|
174
206
|
end
|
@@ -0,0 +1,59 @@
|
|
1
|
+
class String
|
2
|
+
def color_code(code)
|
3
|
+
"\e[#{code}m#{self}\e0"
|
4
|
+
end
|
5
|
+
|
6
|
+
def default
|
7
|
+
color_code(39)
|
8
|
+
end
|
9
|
+
|
10
|
+
def unrated
|
11
|
+
# magenta
|
12
|
+
color_code(35)
|
13
|
+
end
|
14
|
+
|
15
|
+
def bronze
|
16
|
+
# default
|
17
|
+
color_code(39)
|
18
|
+
end
|
19
|
+
|
20
|
+
def silver
|
21
|
+
# white
|
22
|
+
color_code(97)
|
23
|
+
end
|
24
|
+
|
25
|
+
def gold
|
26
|
+
# yellow
|
27
|
+
color_code(93)
|
28
|
+
end
|
29
|
+
|
30
|
+
def platinum
|
31
|
+
# light cyan
|
32
|
+
color_code(96)
|
33
|
+
end
|
34
|
+
|
35
|
+
def diamond
|
36
|
+
# blue
|
37
|
+
color_code(34)
|
38
|
+
end
|
39
|
+
|
40
|
+
def ruby
|
41
|
+
# red
|
42
|
+
color_code(31)
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
def color(str)
|
47
|
+
temp = str.to_s.scan(/[a-z]/).join
|
48
|
+
str = str.to_s
|
49
|
+
case temp
|
50
|
+
when 'unrated' then str.unrated
|
51
|
+
when 'bronze' then str.bronze
|
52
|
+
when 'silver' then str.silver
|
53
|
+
when 'gold' then str.gold
|
54
|
+
when 'platinum' then str.platinum
|
55
|
+
when 'diamond' then str.diamond
|
56
|
+
when 'ruby' then str.ruby
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
data/lib/data/data.rb
CHANGED
@@ -74,7 +74,7 @@ class BOJData
|
|
74
74
|
end
|
75
75
|
end
|
76
76
|
@@levels[i.to_s.to_sym][:solved] = solved_prob
|
77
|
-
@@levels[i.to_s.to_sym][:unsolved] = ((@@levels[i.to_s.to_sym][:
|
77
|
+
@@levels[i.to_s.to_sym][:unsolved] = ((@@levels[i.to_s.to_sym][:total].to_i) - solved_prob).to_s
|
78
78
|
|
79
79
|
break if solved_prob == solved_size
|
80
80
|
end
|
metadata
CHANGED
@@ -1,22 +1,26 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: boj-solvedac
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.4.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jione Eu
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-05-
|
11
|
+
date: 2020-05-29 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
|
-
description:
|
13
|
+
description: |2
|
14
|
+
version 0.4.0 -> colors added to each level
|
15
|
+
version 0.4.1 -> 'solved' command overwriting 'solved-problems.dat' bug fixed.
|
16
|
+
version 0.4.2 -> 'ruby' and 'unrated' color swapped.
|
14
17
|
email:
|
15
18
|
executables: []
|
16
19
|
extensions: []
|
17
20
|
extra_rdoc_files: []
|
18
21
|
files:
|
19
22
|
- lib/boj-solvedac.rb
|
23
|
+
- lib/colorize/colorize.rb
|
20
24
|
- lib/data/data.rb
|
21
25
|
homepage: https://solved.ac/
|
22
26
|
licenses:
|