codeforces_client 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +15 -0
- data/.gitignore +9 -0
- data/.travis.yml +4 -0
- data/Gemfile +4 -0
- data/README.md +36 -0
- data/Rakefile +1 -0
- data/bin/codeforces_client +12 -0
- data/bin/codeforces_client_test +9 -0
- data/bin/console +14 -0
- data/bin/setup +7 -0
- data/codeforces_client.gemspec +33 -0
- data/lib/codeforces_client.rb +40 -0
- data/lib/codeforces_client/arena.rb +58 -0
- data/lib/codeforces_client/version.rb +3 -0
- metadata +118 -0
checksums.yaml
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
---
|
2
|
+
!binary "U0hBMQ==":
|
3
|
+
metadata.gz: !binary |-
|
4
|
+
NjY1ZjgzMTU1NDQ3ZWU1Y2NiNTFlNmJmMDFlZWM1NmY0NzYxMmQxMw==
|
5
|
+
data.tar.gz: !binary |-
|
6
|
+
ZjlkZGJlNWU0N2ZiYjBjMzBjNGZhNWUzYTBkMGY2NjAyYzEwMjdhMA==
|
7
|
+
SHA512:
|
8
|
+
metadata.gz: !binary |-
|
9
|
+
MzYxYTA0ZmE1YWE5OGU1ZTJiNjY3NzdjOGZhYTQxOTMyYjZlYmU3MjEyNjQx
|
10
|
+
ZTZlMjdiMDhiN2ZhYzc4MzU5NjFjNDU5NDcxNDYwN2E3NTgwZGU2MGEwZTJi
|
11
|
+
YjhhZjkxODkzOWExYTY0ZThiN2IzNWJmZDIwMTg0NTAyMTNlZjc=
|
12
|
+
data.tar.gz: !binary |-
|
13
|
+
MmI2MTUyZTc5YTM2MTgzYTdhYTI1NGM2NmZjOTc2Y2IzZDdkOWZiMGE5N2I4
|
14
|
+
NWE5NDc1YjMyMWVmYWE5NGE1MzI1ODg1MTE2YWU3MjQxMjUwNDJkZGVlNmVl
|
15
|
+
MWEyN2U3NzY3Mzk2MzQ3NThmY2ZiOGM2MjRjYTllNmUxY2ZjNDk=
|
data/.gitignore
ADDED
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/README.md
ADDED
@@ -0,0 +1,36 @@
|
|
1
|
+
# CodeforcesClient
|
2
|
+
|
3
|
+
Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/codeforces_client`. To experiment with that code, run `bin/console` for an interactive prompt.
|
4
|
+
|
5
|
+
TODO: Delete this and the text above, and describe your gem
|
6
|
+
|
7
|
+
## Installation
|
8
|
+
|
9
|
+
Add this line to your application's Gemfile:
|
10
|
+
|
11
|
+
```ruby
|
12
|
+
gem 'codeforces_client'
|
13
|
+
```
|
14
|
+
|
15
|
+
And then execute:
|
16
|
+
|
17
|
+
$ bundle
|
18
|
+
|
19
|
+
Or install it yourself as:
|
20
|
+
|
21
|
+
$ gem install codeforces_client
|
22
|
+
|
23
|
+
## Usage
|
24
|
+
|
25
|
+
TODO: Write usage instructions here
|
26
|
+
|
27
|
+
## Development
|
28
|
+
|
29
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake false` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
30
|
+
|
31
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
32
|
+
|
33
|
+
## Contributing
|
34
|
+
|
35
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/codeforces_client.
|
36
|
+
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
@@ -0,0 +1,12 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require 'codeforces_client'
|
4
|
+
|
5
|
+
|
6
|
+
if ARGV.size != 2
|
7
|
+
puts 'Please use "codeforces_client CONTEST_ID PROBLME_INDEX" to create the directory under CURRENT DIRECTORY , such as:'
|
8
|
+
puts 'codeforces_client 611 A'
|
9
|
+
else
|
10
|
+
CodeforcesClient.client ARGV[0], ARGV[1]
|
11
|
+
puts 'You can ruby sample test using "codeforces_client_test PROBLEM_INDEX" under the created directory'
|
12
|
+
end
|
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "codeforces_client"
|
5
|
+
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
8
|
+
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
+
# require "pry"
|
11
|
+
# Pry.start
|
12
|
+
|
13
|
+
require "irb"
|
14
|
+
IRB.start
|
data/bin/setup
ADDED
@@ -0,0 +1,33 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'codeforces_client/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "codeforces_client"
|
8
|
+
spec.version = CodeforcesClient::VERSION
|
9
|
+
spec.authors = ["windinhishair"]
|
10
|
+
spec.email = ["xibaiyu@msn.com"]
|
11
|
+
|
12
|
+
spec.summary = %q{ Tool for codeforces contests: quick create sample test file.}
|
13
|
+
spec.description = %q{ go to the Codeforces Contest directory to run 'codeforces_client CONTEST PROBLEM', such as 'codeforces_client 611 a' to create contest directory .}
|
14
|
+
spec.homepage = "https://github.com/WindInHisHair/codeforces-client"
|
15
|
+
|
16
|
+
# Prevent pushing this gem to RubyGems.org by setting 'allowed_push_host', or
|
17
|
+
# delete this section to allow pushing this gem to any host.
|
18
|
+
# if spec.respond_to?(:metadata)
|
19
|
+
# spec.metadata['allowed_push_host'] = "TODO: Set to 'http://mygemserver.com'"
|
20
|
+
# else
|
21
|
+
# raise "RubyGems 2.0 or newer is required to protect against public gem pushes."
|
22
|
+
# end
|
23
|
+
|
24
|
+
spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
25
|
+
spec.bindir = "bin"
|
26
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
27
|
+
spec.require_paths = ["lib"]
|
28
|
+
|
29
|
+
spec.add_development_dependency "bundler", "~> 1.10"
|
30
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
31
|
+
spec.add_development_dependency "yaml", ">=0"
|
32
|
+
spec.add_development_dependency "codeforcesapi", ">=0"
|
33
|
+
end
|
@@ -0,0 +1,40 @@
|
|
1
|
+
require "codeforces_client/version"
|
2
|
+
require "codeforces_client/arena.rb"
|
3
|
+
require 'open3'
|
4
|
+
|
5
|
+
module CodeforcesClient
|
6
|
+
# Your code goes here...
|
7
|
+
#
|
8
|
+
|
9
|
+
def self.client( contestID, problemIndex)
|
10
|
+
Arena.new(contestID, problemIndex)
|
11
|
+
end
|
12
|
+
|
13
|
+
def self.run_sample_test(problem_index)
|
14
|
+
|
15
|
+
test_file = File.join Dir.pwd, problem_index+'_sampleTest.txt'
|
16
|
+
if File.exist?(test_file)
|
17
|
+
|
18
|
+
myruby = File.join Config::CONFIG['bindir'], Config::CONFIG['ruby_install_name']
|
19
|
+
myscript = File.join Dir.pwd, problem_index+'.rb'
|
20
|
+
|
21
|
+
tests = File.read(test_file).gsub(/\r\n?/, "\n").strip.split("Sample test\n")[1..-1]
|
22
|
+
tests.map{|e| e.strip.split "\n\n"}.each_with_index do |each, index|
|
23
|
+
Open3.popen3(myruby,myscript) do |sin, sout|
|
24
|
+
sin.puts each[0]
|
25
|
+
res = sout.read.strip
|
26
|
+
if each[1] != res
|
27
|
+
print "FAIL test case:#{index}: \n"
|
28
|
+
print "***Expected: #{each[1]}\n"
|
29
|
+
print "***Received: #{res}\n"
|
30
|
+
else
|
31
|
+
puts "Test Case#{index} PASSED"
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
else
|
36
|
+
puts "there is no #{problem_index}_sampleTest.txt file, please check it"
|
37
|
+
end
|
38
|
+
|
39
|
+
end
|
40
|
+
end
|
@@ -0,0 +1,58 @@
|
|
1
|
+
require 'codeforcesapi'
|
2
|
+
require 'yaml'
|
3
|
+
|
4
|
+
|
5
|
+
class Arena
|
6
|
+
|
7
|
+
attr :config
|
8
|
+
|
9
|
+
def initialize(contest_id, problem_index)
|
10
|
+
configure(contest_id)
|
11
|
+
@working_path = @config[:working_path]
|
12
|
+
@problem = Codeforcesapi.problem(contest_id, problem_index)
|
13
|
+
|
14
|
+
create_contest
|
15
|
+
end
|
16
|
+
|
17
|
+
def create_contest
|
18
|
+
|
19
|
+
p = File.split @working_path
|
20
|
+
if p[-1] == @problem.contest_id
|
21
|
+
@working_path = p[0...-1].join
|
22
|
+
end
|
23
|
+
|
24
|
+
contest_dir = File.join @working_path, @problem.contest_id
|
25
|
+
Dir.mkdir(contest_dir) if not File.exist? contest_dir
|
26
|
+
|
27
|
+
sourceFile = File.join(@working_path, @problem.contest_id, @problem.problem_index+'.rb')
|
28
|
+
if not File.exist?(sourceFile)
|
29
|
+
File.open(sourceFile, 'w') {|f| f.puts "#Good luk for the Contest #{@problem.contest_id}, Problem: #{@problem.problem_index}"}
|
30
|
+
end
|
31
|
+
|
32
|
+
testFile = File.join(@working_path, @problem.contest_id, @problem.problem_index+'_sampleTest.txt')
|
33
|
+
|
34
|
+
if not File.exist?(testFile)
|
35
|
+
create_sample_test(testFile)
|
36
|
+
end
|
37
|
+
|
38
|
+
end
|
39
|
+
|
40
|
+
def create_sample_test(fname)
|
41
|
+
File.open(fname, 'w') do |f|
|
42
|
+
1.upto(@problem.preTestInputs.size) do |i|
|
43
|
+
f.puts 'Sample test'
|
44
|
+
f.puts @problem.preTestInputs[i-1]
|
45
|
+
f.puts
|
46
|
+
f.puts @problem.preTestOutputs[i-1]
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
|
52
|
+
def configure(cid)
|
53
|
+
@config = Hash.new
|
54
|
+
p = Dir.pwd
|
55
|
+
@config[:working_path] = p
|
56
|
+
end
|
57
|
+
|
58
|
+
end
|
metadata
ADDED
@@ -0,0 +1,118 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: codeforces_client
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- windinhishair
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2016-01-13 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ~>
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.10'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ~>
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.10'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ~>
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '10.0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ~>
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '10.0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: yaml
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ! '>='
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ! '>='
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: codeforcesapi
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ! '>='
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ! '>='
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
description: ! ' go to the Codeforces Contest directory to run ''codeforces_client
|
70
|
+
CONTEST PROBLEM'', such as ''codeforces_client 611 a'' to create contest directory
|
71
|
+
.'
|
72
|
+
email:
|
73
|
+
- xibaiyu@msn.com
|
74
|
+
executables:
|
75
|
+
- codeforces_client
|
76
|
+
- codeforces_client_test
|
77
|
+
- console
|
78
|
+
- setup
|
79
|
+
extensions: []
|
80
|
+
extra_rdoc_files: []
|
81
|
+
files:
|
82
|
+
- .gitignore
|
83
|
+
- .travis.yml
|
84
|
+
- Gemfile
|
85
|
+
- README.md
|
86
|
+
- Rakefile
|
87
|
+
- bin/codeforces_client
|
88
|
+
- bin/codeforces_client_test
|
89
|
+
- bin/console
|
90
|
+
- bin/setup
|
91
|
+
- codeforces_client.gemspec
|
92
|
+
- lib/codeforces_client.rb
|
93
|
+
- lib/codeforces_client/arena.rb
|
94
|
+
- lib/codeforces_client/version.rb
|
95
|
+
homepage: https://github.com/WindInHisHair/codeforces-client
|
96
|
+
licenses: []
|
97
|
+
metadata: {}
|
98
|
+
post_install_message:
|
99
|
+
rdoc_options: []
|
100
|
+
require_paths:
|
101
|
+
- lib
|
102
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
103
|
+
requirements:
|
104
|
+
- - ! '>='
|
105
|
+
- !ruby/object:Gem::Version
|
106
|
+
version: '0'
|
107
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
108
|
+
requirements:
|
109
|
+
- - ! '>='
|
110
|
+
- !ruby/object:Gem::Version
|
111
|
+
version: '0'
|
112
|
+
requirements: []
|
113
|
+
rubyforge_project:
|
114
|
+
rubygems_version: 2.4.7
|
115
|
+
signing_key:
|
116
|
+
specification_version: 4
|
117
|
+
summary: ! 'Tool for codeforces contests: quick create sample test file.'
|
118
|
+
test_files: []
|