gen_brain 0.0.1
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 +6 -0
- data/LICENSE.txt +21 -0
- data/README.md +43 -0
- data/Rakefile +6 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/config.yml +9 -0
- data/config_kemofure.config +9 -0
- data/config_street_fighter2.config +9 -0
- data/exe/gen_brain +5 -0
- data/gen_brain.gemspec +27 -0
- data/lib/gen_brain.rb +11 -0
- data/lib/gen_brain/generator.rb +118 -0
- data/lib/gen_brain/version.rb +3 -0
- data/samples/brain_kemofure.rb +61 -0
- data/samples/brain_kemofure_hello_world +1 -0
- data/samples/brain_sample.rb +61 -0
- data/samples/brain_sample_hello_world +1 -0
- data/samples/street_fighter2.rb +61 -0
- data/samples/street_fighter2_hello_world +1 -0
- metadata +111 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 4b5a11c3c12805612133fbeedec222d369acf27d
|
4
|
+
data.tar.gz: ff39c53fab9ea4ae8212871cfdc890127ce8c566
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 71b107fb0d48f88a08c81765aa4b298879b30ddf3ce8affd5a3f0ef1e0b1aefa78ec296a3aedea95fcb89a798cdd757a46e8d4047d941f64962f1821f86ca50c
|
7
|
+
data.tar.gz: 411eec8e0ecf53cec5be13c9c4505b0360c8b0054b886b3cc4fcffe2341cc52e38ecce1878080d3d4069c185c3224a8e698ecadb93eb63a60a527ba1ef0a7dc4
|
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 k.furuhashi10@gmail.com. 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 284km
|
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,43 @@
|
|
1
|
+
# GenBrain
|
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/gen_brain`. 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 'gen_brain'
|
13
|
+
```
|
14
|
+
|
15
|
+
And then execute:
|
16
|
+
|
17
|
+
$ bundle
|
18
|
+
|
19
|
+
Or install it yourself as:
|
20
|
+
|
21
|
+
$ gem install gen_brain
|
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 spec` 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/284km/gen_brain. 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.
|
36
|
+
|
37
|
+
## License
|
38
|
+
|
39
|
+
The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
|
40
|
+
|
41
|
+
## Code of Conduct
|
42
|
+
|
43
|
+
Everyone interacting in the GenBrain project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/284km/gen_brain/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 "gen_brain"
|
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/config.yml
ADDED
data/exe/gen_brain
ADDED
data/gen_brain.gemspec
ADDED
@@ -0,0 +1,27 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path("../lib", __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require "gen_brain/version"
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "gen_brain"
|
8
|
+
spec.version = GenBrain::VERSION
|
9
|
+
spec.authors = ["284km"]
|
10
|
+
spec.email = ["k.furuhashi10@gmail.com"]
|
11
|
+
|
12
|
+
spec.summary = %q{Generate subspecies of brainf*ck.}
|
13
|
+
spec.description = %q{Generate subspecies of brainf*ck.}
|
14
|
+
spec.homepage = "https://github.com/284km/gen_brain"
|
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
|
+
spec.bindir = "exe"
|
21
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
22
|
+
spec.require_paths = ["lib"]
|
23
|
+
|
24
|
+
spec.add_development_dependency "bundler", "~> 1.15"
|
25
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
26
|
+
spec.add_development_dependency "rspec", "~> 3.0"
|
27
|
+
end
|
data/lib/gen_brain.rb
ADDED
@@ -0,0 +1,11 @@
|
|
1
|
+
require "gen_brain/version"
|
2
|
+
require "gen_brain/generator"
|
3
|
+
require "yaml"
|
4
|
+
|
5
|
+
module GenBrain
|
6
|
+
def self.generate
|
7
|
+
config_file_name = ARGV[0] || "config.yml"
|
8
|
+
puts "⭐️ Input config file nam #=> #{config_file_name}"
|
9
|
+
Generator.new(YAML.load_file(config_file_name)).call
|
10
|
+
end
|
11
|
+
end
|
@@ -0,0 +1,118 @@
|
|
1
|
+
module GenBrain
|
2
|
+
class Generator
|
3
|
+
attr_accessor :title, :p_inc, :p_dec, :v_inc, :v_dec,
|
4
|
+
:output, :input, :jump_forward, :jump_back
|
5
|
+
|
6
|
+
def initialize(config)
|
7
|
+
@title = config["title"]
|
8
|
+
@p_inc = config["p_inc"]
|
9
|
+
@p_dec = config["p_dec"]
|
10
|
+
@v_inc = config["v_inc"]
|
11
|
+
@v_dec = config["v_dec"]
|
12
|
+
@output= config["output"]
|
13
|
+
@input = config["input"]
|
14
|
+
@jump_forward = config["jump_forward"]
|
15
|
+
@jump_back = config["jump_back"]
|
16
|
+
end
|
17
|
+
|
18
|
+
def words
|
19
|
+
[
|
20
|
+
p_inc,
|
21
|
+
p_dec,
|
22
|
+
v_inc,
|
23
|
+
v_dec,
|
24
|
+
output,
|
25
|
+
input,
|
26
|
+
jump_forward,
|
27
|
+
jump_back
|
28
|
+
].map{|word|Regexp.escape(word)}.join('|')
|
29
|
+
end
|
30
|
+
|
31
|
+
def call
|
32
|
+
File.write("#{title}.rb", lang)
|
33
|
+
File.write("#{title}_hello_world", hello_world_input_sample)
|
34
|
+
puts "🎉 Created #{title}.rb and #{title}_hello_world"
|
35
|
+
puts "🌈 Let's execute the following code!!"
|
36
|
+
puts "#=> ruby #{title}.rb #{title}_hello_world"
|
37
|
+
end
|
38
|
+
|
39
|
+
def lang
|
40
|
+
class_name = title.split(/[^[:alnum:]]+/).map(&:capitalize).join
|
41
|
+
<<TEMPLATE
|
42
|
+
#!/usr/bin/env ruby
|
43
|
+
|
44
|
+
class #{class_name}
|
45
|
+
def initialize(code)
|
46
|
+
@tokens = code.scan(/(#{words})/).flatten
|
47
|
+
@jumps = analyze_jumps(@tokens)
|
48
|
+
end
|
49
|
+
|
50
|
+
def run
|
51
|
+
array = []
|
52
|
+
index = 0
|
53
|
+
now = 0
|
54
|
+
|
55
|
+
while index < @tokens.size
|
56
|
+
case @tokens[index]
|
57
|
+
when "#{v_inc}"
|
58
|
+
array[now] ||= 0
|
59
|
+
array[now] += 1
|
60
|
+
when "#{v_dec}"
|
61
|
+
array[now] ||= 0
|
62
|
+
array[now] -= 1
|
63
|
+
when "#{p_inc}"
|
64
|
+
now += 1
|
65
|
+
when "#{p_dec}"
|
66
|
+
now -= 1
|
67
|
+
when "#{output}"
|
68
|
+
n = (array[now] || 0)
|
69
|
+
print n.chr
|
70
|
+
when "#{input}"
|
71
|
+
array[now] = $stdin.getc
|
72
|
+
when "#{jump_forward}"
|
73
|
+
index = @jumps[index] if array[now] == 0
|
74
|
+
when "#{jump_back}"
|
75
|
+
index = @jumps[index] if array[now] != 0
|
76
|
+
end
|
77
|
+
index += 1
|
78
|
+
end
|
79
|
+
end
|
80
|
+
|
81
|
+
private
|
82
|
+
|
83
|
+
def analyze_jumps(tokens)
|
84
|
+
stack = []
|
85
|
+
jumps = {}
|
86
|
+
start_word = "#{jump_forward}"
|
87
|
+
end_word = "#{jump_back}"
|
88
|
+
tokens.each_with_index do |v,i|
|
89
|
+
if v == start_word
|
90
|
+
stack.push(i)
|
91
|
+
elsif v == end_word
|
92
|
+
from = stack.pop
|
93
|
+
to = i
|
94
|
+
jumps[from] = to
|
95
|
+
jumps[to] = from
|
96
|
+
end
|
97
|
+
end
|
98
|
+
jumps
|
99
|
+
end
|
100
|
+
end
|
101
|
+
|
102
|
+
#{class_name}.new(ARGF.read).run
|
103
|
+
TEMPLATE
|
104
|
+
end
|
105
|
+
|
106
|
+
def hello_world_input_sample
|
107
|
+
"+++++++++[>++++++++>+++++++++++>+++++<<<-]>.>++.+++++++..+++.>-.------------.<++++++++.--------.+++.------.--------.>+.".
|
108
|
+
gsub(/\>/, p_inc).
|
109
|
+
gsub(/\</, p_dec).
|
110
|
+
gsub(/\+/, v_inc).
|
111
|
+
gsub(/\-/, v_dec).
|
112
|
+
gsub(/\./, output).
|
113
|
+
gsub(/\,/, input).
|
114
|
+
gsub(/\[/, jump_forward).
|
115
|
+
gsub(/\]/, jump_back)
|
116
|
+
end
|
117
|
+
end
|
118
|
+
end
|
@@ -0,0 +1,61 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
class BrainKemofure
|
4
|
+
def initialize(code)
|
5
|
+
@tokens = code.scan(/(わーい|すごーい|たーのしー|あなたは何のフレンズさんですか?|われわれはかしこいので|どうもどうもありがとう|食べないでください|食べないよ)/).flatten
|
6
|
+
@jumps = analyze_jumps(@tokens)
|
7
|
+
end
|
8
|
+
|
9
|
+
def run
|
10
|
+
array = []
|
11
|
+
index = 0
|
12
|
+
now = 0
|
13
|
+
|
14
|
+
while index < @tokens.size
|
15
|
+
case @tokens[index]
|
16
|
+
when "たーのしー"
|
17
|
+
array[now] ||= 0
|
18
|
+
array[now] += 1
|
19
|
+
when "あなたは何のフレンズさんですか?"
|
20
|
+
array[now] ||= 0
|
21
|
+
array[now] -= 1
|
22
|
+
when "わーい"
|
23
|
+
now += 1
|
24
|
+
when "すごーい"
|
25
|
+
now -= 1
|
26
|
+
when "われわれはかしこいので"
|
27
|
+
n = (array[now] || 0)
|
28
|
+
print n.chr
|
29
|
+
when "どうもどうもありがとう"
|
30
|
+
array[now] = $stdin.getc
|
31
|
+
when "食べないでください"
|
32
|
+
index = @jumps[index] if array[now] == 0
|
33
|
+
when "食べないよ"
|
34
|
+
index = @jumps[index] if array[now] != 0
|
35
|
+
end
|
36
|
+
index += 1
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
private
|
41
|
+
|
42
|
+
def analyze_jumps(tokens)
|
43
|
+
stack = []
|
44
|
+
jumps = {}
|
45
|
+
start_word = "食べないでください"
|
46
|
+
end_word = "食べないよ"
|
47
|
+
tokens.each_with_index do |v,i|
|
48
|
+
if v == start_word
|
49
|
+
stack.push(i)
|
50
|
+
elsif v == end_word
|
51
|
+
from = stack.pop
|
52
|
+
to = i
|
53
|
+
jumps[from] = to
|
54
|
+
jumps[to] = from
|
55
|
+
end
|
56
|
+
end
|
57
|
+
jumps
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
BrainKemofure.new(ARGF.read).run
|
@@ -0,0 +1 @@
|
|
1
|
+
たーのしーたーのしーたーのしーたーのしーたーのしーたーのしーたーのしーたーのしーたーのしー食べないでくださいわーいたーのしーたーのしーたーのしーたーのしーたーのしーたーのしーたーのしーたーのしーわーいたーのしーたーのしーたーのしーたーのしーたーのしーたーのしーたーのしーたーのしーたーのしーたーのしーたーのしーわーいたーのしーたーのしーたーのしーたーのしーたーのしーすごーいすごーいすごーいあなたは何のフレンズさんですか?食べないよわーいわれわれはかしこいのでわーいたーのしーたーのしーわれわれはかしこいのでたーのしーたーのしーたーのしーたーのしーたーのしーたーのしーたーのしーわれわれはかしこいのでわれわれはかしこいのでたーのしーたーのしーたーのしーわれわれはかしこいのでわーいあなたは何のフレンズさんですか?われわれはかしこいのであなたは何のフレンズさんですか?あなたは何のフレンズさんですか?あなたは何のフレンズさんですか?あなたは何のフレンズさんですか?あなたは何のフレンズさんですか?あなたは何のフレンズさんですか?あなたは何のフレンズさんですか?あなたは何のフレンズさんですか?あなたは何のフレンズさんですか?あなたは何のフレンズさんですか?あなたは何のフレンズさんですか?あなたは何のフレンズさんですか?われわれはかしこいのですごーいたーのしーたーのしーたーのしーたーのしーたーのしーたーのしーたーのしーたーのしーわれわれはかしこいのであなたは何のフレンズさんですか?あなたは何のフレンズさんですか?あなたは何のフレンズさんですか?あなたは何のフレンズさんですか?あなたは何のフレンズさんですか?あなたは何のフレンズさんですか?あなたは何のフレンズさんですか?あなたは何のフレンズさんですか?われわれはかしこいのでたーのしーたーのしーたーのしーわれわれはかしこいのであなたは何のフレンズさんですか?あなたは何のフレンズさんですか?あなたは何のフレンズさんですか?あなたは何のフレンズさんですか?あなたは何のフレンズさんですか?あなたは何のフレンズさんですか?われわれはかしこいのであなたは何のフレンズさんですか?あなたは何のフレンズさんですか?あなたは何のフレンズさんですか?あなたは何のフレンズさんですか?あなたは何のフレンズさんですか?あなたは何のフレンズさんですか?あなたは何のフレンズさんですか?あなたは何のフレンズさんですか?われわれはかしこいのでわーいたーのしーわれわれはかしこいので
|
@@ -0,0 +1,61 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
class BrainSample
|
4
|
+
def initialize(code)
|
5
|
+
@tokens = code.scan(/(>|<|\+|\-|\.|,|\[|\])/).flatten
|
6
|
+
@jumps = analyze_jumps(@tokens)
|
7
|
+
end
|
8
|
+
|
9
|
+
def run
|
10
|
+
array = []
|
11
|
+
index = 0
|
12
|
+
now = 0
|
13
|
+
|
14
|
+
while index < @tokens.size
|
15
|
+
case @tokens[index]
|
16
|
+
when "+"
|
17
|
+
array[now] ||= 0
|
18
|
+
array[now] += 1
|
19
|
+
when "-"
|
20
|
+
array[now] ||= 0
|
21
|
+
array[now] -= 1
|
22
|
+
when ">"
|
23
|
+
now += 1
|
24
|
+
when "<"
|
25
|
+
now -= 1
|
26
|
+
when "."
|
27
|
+
n = (array[now] || 0)
|
28
|
+
print n.chr
|
29
|
+
when ","
|
30
|
+
array[now] = $stdin.getc
|
31
|
+
when "["
|
32
|
+
index = @jumps[index] if array[now] == 0
|
33
|
+
when "]"
|
34
|
+
index = @jumps[index] if array[now] != 0
|
35
|
+
end
|
36
|
+
index += 1
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
private
|
41
|
+
|
42
|
+
def analyze_jumps(tokens)
|
43
|
+
stack = []
|
44
|
+
jumps = {}
|
45
|
+
start_word = "["
|
46
|
+
end_word = "]"
|
47
|
+
tokens.each_with_index do |v,i|
|
48
|
+
if v == start_word
|
49
|
+
stack.push(i)
|
50
|
+
elsif v == end_word
|
51
|
+
from = stack.pop
|
52
|
+
to = i
|
53
|
+
jumps[from] = to
|
54
|
+
jumps[to] = from
|
55
|
+
end
|
56
|
+
end
|
57
|
+
jumps
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
BrainSample.new(ARGF.read).run
|
@@ -0,0 +1 @@
|
|
1
|
+
+++++++++[>++++++++>+++++++++++>+++++<<<-]>.>++.+++++++..+++.>-.------------.<++++++++.--------.+++.------.--------.>+.
|
@@ -0,0 +1,61 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
class StreetFighter2
|
4
|
+
def initialize(code)
|
5
|
+
@tokens = code.scan(/(波動拳|昇竜拳|竜巻旋風脚|ヨガフレイム|タイガーアハ|ソニックブーム|↓R↑LYBXA|↑X↓BLYRA)/).flatten
|
6
|
+
@jumps = analyze_jumps(@tokens)
|
7
|
+
end
|
8
|
+
|
9
|
+
def run
|
10
|
+
array = []
|
11
|
+
index = 0
|
12
|
+
now = 0
|
13
|
+
|
14
|
+
while index < @tokens.size
|
15
|
+
case @tokens[index]
|
16
|
+
when "竜巻旋風脚"
|
17
|
+
array[now] ||= 0
|
18
|
+
array[now] += 1
|
19
|
+
when "ヨガフレイム"
|
20
|
+
array[now] ||= 0
|
21
|
+
array[now] -= 1
|
22
|
+
when "波動拳"
|
23
|
+
now += 1
|
24
|
+
when "昇竜拳"
|
25
|
+
now -= 1
|
26
|
+
when "タイガーアハ"
|
27
|
+
n = (array[now] || 0)
|
28
|
+
print n.chr
|
29
|
+
when "ソニックブーム"
|
30
|
+
array[now] = $stdin.getc
|
31
|
+
when "↓R↑LYBXA"
|
32
|
+
index = @jumps[index] if array[now] == 0
|
33
|
+
when "↑X↓BLYRA"
|
34
|
+
index = @jumps[index] if array[now] != 0
|
35
|
+
end
|
36
|
+
index += 1
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
private
|
41
|
+
|
42
|
+
def analyze_jumps(tokens)
|
43
|
+
stack = []
|
44
|
+
jumps = {}
|
45
|
+
start_word = "↓R↑LYBXA"
|
46
|
+
end_word = "↑X↓BLYRA"
|
47
|
+
tokens.each_with_index do |v,i|
|
48
|
+
if v == start_word
|
49
|
+
stack.push(i)
|
50
|
+
elsif v == end_word
|
51
|
+
from = stack.pop
|
52
|
+
to = i
|
53
|
+
jumps[from] = to
|
54
|
+
jumps[to] = from
|
55
|
+
end
|
56
|
+
end
|
57
|
+
jumps
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
StreetFighter2.new(ARGF.read).run
|
@@ -0,0 +1 @@
|
|
1
|
+
竜巻旋風脚竜巻旋風脚竜巻旋風脚竜巻旋風脚竜巻旋風脚竜巻旋風脚竜巻旋風脚竜巻旋風脚竜巻旋風脚↓R↑LYBXA波動拳竜巻旋風脚竜巻旋風脚竜巻旋風脚竜巻旋風脚竜巻旋風脚竜巻旋風脚竜巻旋風脚竜巻旋風脚波動拳竜巻旋風脚竜巻旋風脚竜巻旋風脚竜巻旋風脚竜巻旋風脚竜巻旋風脚竜巻旋風脚竜巻旋風脚竜巻旋風脚竜巻旋風脚竜巻旋風脚波動拳竜巻旋風脚竜巻旋風脚竜巻旋風脚竜巻旋風脚竜巻旋風脚昇竜拳昇竜拳昇竜拳ヨガフレイム↑X↓BLYRA波動拳タイガーアハ波動拳竜巻旋風脚竜巻旋風脚タイガーアハ竜巻旋風脚竜巻旋風脚竜巻旋風脚竜巻旋風脚竜巻旋風脚竜巻旋風脚竜巻旋風脚タイガーアハタイガーアハ竜巻旋風脚竜巻旋風脚竜巻旋風脚タイガーアハ波動拳ヨガフレイムタイガーアハヨガフレイムヨガフレイムヨガフレイムヨガフレイムヨガフレイムヨガフレイムヨガフレイムヨガフレイムヨガフレイムヨガフレイムヨガフレイムヨガフレイムタイガーアハ昇竜拳竜巻旋風脚竜巻旋風脚竜巻旋風脚竜巻旋風脚竜巻旋風脚竜巻旋風脚竜巻旋風脚竜巻旋風脚タイガーアハヨガフレイムヨガフレイムヨガフレイムヨガフレイムヨガフレイムヨガフレイムヨガフレイムヨガフレイムタイガーアハ竜巻旋風脚竜巻旋風脚竜巻旋風脚タイガーアハヨガフレイムヨガフレイムヨガフレイムヨガフレイムヨガフレイムヨガフレイムタイガーアハヨガフレイムヨガフレイムヨガフレイムヨガフレイムヨガフレイムヨガフレイムヨガフレイムヨガフレイムタイガーアハ波動拳竜巻旋風脚タイガーアハ
|
metadata
ADDED
@@ -0,0 +1,111 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: gen_brain
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- 284km
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2017-11-09 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: Generate subspecies of brainf*ck.
|
56
|
+
email:
|
57
|
+
- k.furuhashi10@gmail.com
|
58
|
+
executables:
|
59
|
+
- gen_brain
|
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
|
+
- config.yml
|
74
|
+
- config_kemofure.config
|
75
|
+
- config_street_fighter2.config
|
76
|
+
- exe/gen_brain
|
77
|
+
- gen_brain.gemspec
|
78
|
+
- lib/gen_brain.rb
|
79
|
+
- lib/gen_brain/generator.rb
|
80
|
+
- lib/gen_brain/version.rb
|
81
|
+
- samples/brain_kemofure.rb
|
82
|
+
- samples/brain_kemofure_hello_world
|
83
|
+
- samples/brain_sample.rb
|
84
|
+
- samples/brain_sample_hello_world
|
85
|
+
- samples/street_fighter2.rb
|
86
|
+
- samples/street_fighter2_hello_world
|
87
|
+
homepage: https://github.com/284km/gen_brain
|
88
|
+
licenses:
|
89
|
+
- MIT
|
90
|
+
metadata: {}
|
91
|
+
post_install_message:
|
92
|
+
rdoc_options: []
|
93
|
+
require_paths:
|
94
|
+
- lib
|
95
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
96
|
+
requirements:
|
97
|
+
- - ">="
|
98
|
+
- !ruby/object:Gem::Version
|
99
|
+
version: '0'
|
100
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
101
|
+
requirements:
|
102
|
+
- - ">="
|
103
|
+
- !ruby/object:Gem::Version
|
104
|
+
version: '0'
|
105
|
+
requirements: []
|
106
|
+
rubyforge_project:
|
107
|
+
rubygems_version: 2.6.13
|
108
|
+
signing_key:
|
109
|
+
specification_version: 4
|
110
|
+
summary: Generate subspecies of brainf*ck.
|
111
|
+
test_files: []
|