hrm 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +12 -0
- data/.rspec +2 -0
- data/.travis.yml +5 -0
- data/CODE_OF_CONDUCT.md +74 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +21 -0
- data/README.md +59 -0
- data/Rakefile +6 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/example/check.rb +15 -0
- data/example/year01/answer.hrm +6 -0
- data/example/year01/input +3 -0
- data/example/year01/output +3 -0
- data/example/year02/answer.hrm +3 -0
- data/example/year02/input +7 -0
- data/example/year02/output +7 -0
- data/example/year03/answer.hrm +19 -0
- data/example/year03/input +10 -0
- data/example/year03/output +3 -0
- data/example/year04/answer.hrm +7 -0
- data/example/year04/input +6 -0
- data/example/year04/output +6 -0
- data/example/year06/answer.hrm +6 -0
- data/example/year06/input +8 -0
- data/example/year06/output +4 -0
- data/example/year07/answer.hrm +4 -0
- data/example/year07/input +8 -0
- data/example/year07/output +4 -0
- data/example/year08/answer.hrm +6 -0
- data/example/year08/input +4 -0
- data/example/year08/output +4 -0
- data/example/year14/answer.hrm +10 -0
- data/example/year14/input +8 -0
- data/example/year14/output +4 -0
- data/example/year19/answer.hrm +10 -0
- data/example/year19/input +4 -0
- data/example/year19/output +20 -0
- data/example/year31/answer.hrm +14 -0
- data/example/year31/input +14 -0
- data/example/year31/output +10 -0
- data/exe/hrm +7 -0
- data/hrm.gemspec +28 -0
- data/lib/hrm/instruction.rb +68 -0
- data/lib/hrm/machine.rb +51 -0
- data/lib/hrm/version.rb +3 -0
- data/lib/hrm.rb +3 -0
- metadata +134 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: dfaee4608b65cc920c3a7af3586bcf8d9a3bd804
|
4
|
+
data.tar.gz: 504da09e921cde61c4867e13de56ab9ca5d757f2
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: a7234a1c5fa4cbfe5b465f767a7cc26556f6d936069bf888580b62031fd037d33b7add00b900d561fd156bf3b19a7e28409d3e5e2e0921efba749536d7ddba10
|
7
|
+
data.tar.gz: 7c6f81ccac8d978d3311a2d271d20bbfb3cb0a3814f4e45c9fa79bd81377be173ebdc8ef1315fc4b63c17db25915994a51e2a089d6455377c30b5ae840281913
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.travis.yml
ADDED
data/CODE_OF_CONDUCT.md
ADDED
@@ -0,0 +1,74 @@
|
|
1
|
+
# Contributor Covenant Code of Conduct
|
2
|
+
|
3
|
+
## Our Pledge
|
4
|
+
|
5
|
+
In the interest of fostering an open and welcoming environment, we as
|
6
|
+
contributors and maintainers pledge to making participation in our project and
|
7
|
+
our community a harassment-free experience for everyone, regardless of age, body
|
8
|
+
size, disability, ethnicity, gender identity and expression, level of experience,
|
9
|
+
nationality, personal appearance, race, religion, or sexual identity and
|
10
|
+
orientation.
|
11
|
+
|
12
|
+
## Our Standards
|
13
|
+
|
14
|
+
Examples of behavior that contributes to creating a positive environment
|
15
|
+
include:
|
16
|
+
|
17
|
+
* Using welcoming and inclusive language
|
18
|
+
* Being respectful of differing viewpoints and experiences
|
19
|
+
* Gracefully accepting constructive criticism
|
20
|
+
* Focusing on what is best for the community
|
21
|
+
* Showing empathy towards other community members
|
22
|
+
|
23
|
+
Examples of unacceptable behavior by participants include:
|
24
|
+
|
25
|
+
* The use of sexualized language or imagery and unwelcome sexual attention or
|
26
|
+
advances
|
27
|
+
* Trolling, insulting/derogatory comments, and personal or political attacks
|
28
|
+
* Public or private harassment
|
29
|
+
* Publishing others' private information, such as a physical or electronic
|
30
|
+
address, without explicit permission
|
31
|
+
* Other conduct which could reasonably be considered inappropriate in a
|
32
|
+
professional setting
|
33
|
+
|
34
|
+
## Our Responsibilities
|
35
|
+
|
36
|
+
Project maintainers are responsible for clarifying the standards of acceptable
|
37
|
+
behavior and are expected to take appropriate and fair corrective action in
|
38
|
+
response to any instances of unacceptable behavior.
|
39
|
+
|
40
|
+
Project maintainers have the right and responsibility to remove, edit, or
|
41
|
+
reject comments, commits, code, wiki edits, issues, and other contributions
|
42
|
+
that are not aligned to this Code of Conduct, or to ban temporarily or
|
43
|
+
permanently any contributor for other behaviors that they deem inappropriate,
|
44
|
+
threatening, offensive, or harmful.
|
45
|
+
|
46
|
+
## Scope
|
47
|
+
|
48
|
+
This Code of Conduct applies both within project spaces and in public spaces
|
49
|
+
when an individual is representing the project or its community. Examples of
|
50
|
+
representing a project or community include using an official project e-mail
|
51
|
+
address, posting via an official social media account, or acting as an appointed
|
52
|
+
representative at an online or offline event. Representation of a project may be
|
53
|
+
further defined and clarified by project maintainers.
|
54
|
+
|
55
|
+
## Enforcement
|
56
|
+
|
57
|
+
Instances of abusive, harassing, or otherwise unacceptable behavior may be
|
58
|
+
reported by contacting the project team at k128585@ie.u-ryukyu.ac.jp. All
|
59
|
+
complaints will be reviewed and investigated and will result in a response that
|
60
|
+
is deemed necessary and appropriate to the circumstances. The project team is
|
61
|
+
obligated to maintain confidentiality with regard to the reporter of an incident.
|
62
|
+
Further details of specific enforcement policies may be posted separately.
|
63
|
+
|
64
|
+
Project maintainers who do not follow or enforce the Code of Conduct in good
|
65
|
+
faith may face temporary or permanent repercussions as determined by other
|
66
|
+
members of the project's leadership.
|
67
|
+
|
68
|
+
## Attribution
|
69
|
+
|
70
|
+
This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
|
71
|
+
available at [http://contributor-covenant.org/version/1/4][version]
|
72
|
+
|
73
|
+
[homepage]: http://contributor-covenant.org
|
74
|
+
[version]: http://contributor-covenant.org/version/1/4/
|
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2017 siman-man
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,59 @@
|
|
1
|
+
# HRM
|
2
|
+
|
3
|
+
HRM (Human Resource Machine), written in Ruby.
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
```
|
8
|
+
$ gem install hrm
|
9
|
+
```
|
10
|
+
|
11
|
+
## Usage
|
12
|
+
|
13
|
+
[check example](example)
|
14
|
+
|
15
|
+
|
16
|
+
code
|
17
|
+
|
18
|
+
```
|
19
|
+
inbox
|
20
|
+
outbox
|
21
|
+
inbox
|
22
|
+
outbox
|
23
|
+
inbox
|
24
|
+
outbox
|
25
|
+
```
|
26
|
+
|
27
|
+
input
|
28
|
+
|
29
|
+
```
|
30
|
+
4
|
31
|
+
9
|
32
|
+
3
|
33
|
+
```
|
34
|
+
|
35
|
+
run `hrm` command
|
36
|
+
|
37
|
+
```
|
38
|
+
$ hrm answer.hrm < input
|
39
|
+
```
|
40
|
+
|
41
|
+
output
|
42
|
+
|
43
|
+
```
|
44
|
+
4
|
45
|
+
9
|
46
|
+
3
|
47
|
+
```
|
48
|
+
|
49
|
+
## Contributing
|
50
|
+
|
51
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/siman-man/hrm. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
|
52
|
+
|
53
|
+
## License
|
54
|
+
|
55
|
+
The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
|
56
|
+
|
57
|
+
## Code of Conduct
|
58
|
+
|
59
|
+
Everyone interacting in the HRM project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/siman-man/hrm/blob/master/CODE_OF_CONDUCT.md).
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "hrm"
|
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(__FILE__)
|
data/bin/setup
ADDED
data/example/check.rb
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
Dir.glob("**/*.hrm").each do |filepath|
|
2
|
+
name = File.basename(filepath, ".hrm")
|
3
|
+
dirname = File.dirname(filepath)
|
4
|
+
|
5
|
+
result = `hrm #{filepath} < #{File.join(dirname, "input")}`
|
6
|
+
expect = File.read("#{File.join(dirname, "output")}")
|
7
|
+
|
8
|
+
if result != expect
|
9
|
+
puts "expect = #{expect.inspect}"
|
10
|
+
puts "actual = #{result.inspect}"
|
11
|
+
raise "Check failed!"
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
puts "All test passed!!"
|
data/exe/hrm
ADDED
data/hrm.gemspec
ADDED
@@ -0,0 +1,28 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path("../lib", __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require "hrm/version"
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "hrm"
|
8
|
+
spec.version = HRM::VERSION
|
9
|
+
spec.authors = ["siman-man"]
|
10
|
+
spec.email = ["k128585@ie.u-ryukyu.ac.jp"]
|
11
|
+
|
12
|
+
spec.summary = %q{human resource machine}
|
13
|
+
spec.description = %q{human resource machine}
|
14
|
+
spec.homepage = "https://github.com/siman-man/hrm"
|
15
|
+
spec.license = "MIT"
|
16
|
+
|
17
|
+
spec.files = `git ls-files -z`.split("\x0").reject do |f|
|
18
|
+
f.match(%r{^(test|spec|features)/})
|
19
|
+
end
|
20
|
+
|
21
|
+
spec.bindir = "exe"
|
22
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
23
|
+
spec.require_paths = ["lib"]
|
24
|
+
|
25
|
+
spec.add_development_dependency "bundler", "~> 1.15"
|
26
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
27
|
+
spec.add_development_dependency "rspec", "~> 3.0"
|
28
|
+
end
|
@@ -0,0 +1,68 @@
|
|
1
|
+
class String
|
2
|
+
def zero?
|
3
|
+
false
|
4
|
+
end
|
5
|
+
|
6
|
+
def negative?
|
7
|
+
false
|
8
|
+
end
|
9
|
+
end
|
10
|
+
|
11
|
+
module HRM
|
12
|
+
module Instruction
|
13
|
+
def inbox
|
14
|
+
unless @value = STDIN.gets&.chomp
|
15
|
+
exit(0)
|
16
|
+
end
|
17
|
+
|
18
|
+
if @value =~ /^[-+]?[0-9]+$/
|
19
|
+
@value = @value.to_i
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
def outbox
|
24
|
+
puts @value
|
25
|
+
@value = nil
|
26
|
+
end
|
27
|
+
|
28
|
+
def copyfrom(address)
|
29
|
+
@value = @memory[address]
|
30
|
+
end
|
31
|
+
|
32
|
+
def copyto(address)
|
33
|
+
@memory[address] = @value
|
34
|
+
end
|
35
|
+
|
36
|
+
def add(address)
|
37
|
+
@value += @memory[address]
|
38
|
+
end
|
39
|
+
|
40
|
+
def sub(address)
|
41
|
+
@value -= @memory[address]
|
42
|
+
end
|
43
|
+
|
44
|
+
def bumpup(address)
|
45
|
+
@value = @memory[address] += 1
|
46
|
+
end
|
47
|
+
|
48
|
+
def bumpdown(address)
|
49
|
+
@value = @memory[address] -= 1
|
50
|
+
end
|
51
|
+
|
52
|
+
def jump(address)
|
53
|
+
@pc = address
|
54
|
+
end
|
55
|
+
|
56
|
+
def jump_if_zero(address)
|
57
|
+
if @value.zero?
|
58
|
+
@pc = address
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
def jump_if_neg(address)
|
63
|
+
if @value.negative?
|
64
|
+
@pc = address
|
65
|
+
end
|
66
|
+
end
|
67
|
+
end
|
68
|
+
end
|
data/lib/hrm/machine.rb
ADDED
@@ -0,0 +1,51 @@
|
|
1
|
+
module HRM
|
2
|
+
class Machine
|
3
|
+
include Instruction
|
4
|
+
|
5
|
+
MAX_MEMORY_SIZE = 25
|
6
|
+
|
7
|
+
def self.run(filepath)
|
8
|
+
new(File.read(filepath)).run
|
9
|
+
end
|
10
|
+
|
11
|
+
def initialize(source)
|
12
|
+
@source = source
|
13
|
+
@im = [nil] + parse_source_code
|
14
|
+
@value = nil
|
15
|
+
@pc = 1
|
16
|
+
@memory = Array.new(MAX_MEMORY_SIZE)
|
17
|
+
end
|
18
|
+
|
19
|
+
def run
|
20
|
+
loop do
|
21
|
+
instruction, arg = @im[@pc]
|
22
|
+
@pc += 1
|
23
|
+
|
24
|
+
exit(0) if instruction.nil?
|
25
|
+
|
26
|
+
if arg.nil?
|
27
|
+
public_send(instruction)
|
28
|
+
else
|
29
|
+
if arg =~ /\[\s*(\d+)\s*\]/
|
30
|
+
public_send(instruction, @memory[$1.to_i])
|
31
|
+
else
|
32
|
+
public_send(instruction, arg.to_i)
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
private
|
39
|
+
|
40
|
+
def parse_source_code
|
41
|
+
@source.split(/\R/).map do |line|
|
42
|
+
if line.start_with?("#")
|
43
|
+
nil
|
44
|
+
else
|
45
|
+
instruction, arg = line.split
|
46
|
+
[instruction.downcase.to_sym, arg]
|
47
|
+
end
|
48
|
+
end.compact
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
data/lib/hrm/version.rb
ADDED
data/lib/hrm.rb
ADDED
metadata
ADDED
@@ -0,0 +1,134 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: hrm
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- siman-man
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2017-07-02 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.15'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.15'
|
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: rspec
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '3.0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '3.0'
|
55
|
+
description: human resource machine
|
56
|
+
email:
|
57
|
+
- k128585@ie.u-ryukyu.ac.jp
|
58
|
+
executables:
|
59
|
+
- hrm
|
60
|
+
extensions: []
|
61
|
+
extra_rdoc_files: []
|
62
|
+
files:
|
63
|
+
- ".gitignore"
|
64
|
+
- ".rspec"
|
65
|
+
- ".travis.yml"
|
66
|
+
- CODE_OF_CONDUCT.md
|
67
|
+
- Gemfile
|
68
|
+
- LICENSE.txt
|
69
|
+
- README.md
|
70
|
+
- Rakefile
|
71
|
+
- bin/console
|
72
|
+
- bin/setup
|
73
|
+
- example/check.rb
|
74
|
+
- example/year01/answer.hrm
|
75
|
+
- example/year01/input
|
76
|
+
- example/year01/output
|
77
|
+
- example/year02/answer.hrm
|
78
|
+
- example/year02/input
|
79
|
+
- example/year02/output
|
80
|
+
- example/year03/answer.hrm
|
81
|
+
- example/year03/input
|
82
|
+
- example/year03/output
|
83
|
+
- example/year04/answer.hrm
|
84
|
+
- example/year04/input
|
85
|
+
- example/year04/output
|
86
|
+
- example/year06/answer.hrm
|
87
|
+
- example/year06/input
|
88
|
+
- example/year06/output
|
89
|
+
- example/year07/answer.hrm
|
90
|
+
- example/year07/input
|
91
|
+
- example/year07/output
|
92
|
+
- example/year08/answer.hrm
|
93
|
+
- example/year08/input
|
94
|
+
- example/year08/output
|
95
|
+
- example/year14/answer.hrm
|
96
|
+
- example/year14/input
|
97
|
+
- example/year14/output
|
98
|
+
- example/year19/answer.hrm
|
99
|
+
- example/year19/input
|
100
|
+
- example/year19/output
|
101
|
+
- example/year31/answer.hrm
|
102
|
+
- example/year31/input
|
103
|
+
- example/year31/output
|
104
|
+
- exe/hrm
|
105
|
+
- hrm.gemspec
|
106
|
+
- lib/hrm.rb
|
107
|
+
- lib/hrm/instruction.rb
|
108
|
+
- lib/hrm/machine.rb
|
109
|
+
- lib/hrm/version.rb
|
110
|
+
homepage: https://github.com/siman-man/hrm
|
111
|
+
licenses:
|
112
|
+
- MIT
|
113
|
+
metadata: {}
|
114
|
+
post_install_message:
|
115
|
+
rdoc_options: []
|
116
|
+
require_paths:
|
117
|
+
- lib
|
118
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
119
|
+
requirements:
|
120
|
+
- - ">="
|
121
|
+
- !ruby/object:Gem::Version
|
122
|
+
version: '0'
|
123
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
124
|
+
requirements:
|
125
|
+
- - ">="
|
126
|
+
- !ruby/object:Gem::Version
|
127
|
+
version: '0'
|
128
|
+
requirements: []
|
129
|
+
rubyforge_project:
|
130
|
+
rubygems_version: 2.6.11
|
131
|
+
signing_key:
|
132
|
+
specification_version: 4
|
133
|
+
summary: human resource machine
|
134
|
+
test_files: []
|