brainfuck_converter 1.1.1 → 1.1.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/brainfuck_converter.rb +9 -4
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d76749a2b9454523f96778446fdcac3747c5d7564cc1f54fefbb9fbca1e0b73f
|
4
|
+
data.tar.gz: 7f808e7e6bb8f830c3625d44ab2a144774f364482baa7c534946f146c6ff930d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0d4a7f1baafbd5814200cd96c65f61df5333631e5715cb079fa9dc39ad5e40482daf5bd83fb07670b641e670836e20128681d5cf0024a2a09c3841319ba240bc
|
7
|
+
data.tar.gz: f905a90495eea5caee6deb917e7ad7ab64997e675b8cd36f33ebaa8a974cee5c92fb2bb1c9063d87bb92c053bdd82396be9c2087e6c9842521cd86e136c2fb1c
|
data/lib/brainfuck_converter.rb
CHANGED
@@ -11,6 +11,8 @@ class BrainfuckConverter
|
|
11
11
|
loop_end: ']'
|
12
12
|
}.freeze
|
13
13
|
|
14
|
+
ASCII_MAX = 127
|
15
|
+
|
14
16
|
attr_reader :code
|
15
17
|
attr_accessor :cmds
|
16
18
|
|
@@ -35,10 +37,10 @@ class BrainfuckConverter
|
|
35
37
|
# con = BrainfuckConverter.new
|
36
38
|
#
|
37
39
|
# con.convert 'Hello World!' # => 'Hello World!'
|
38
|
-
# con.code # =>
|
40
|
+
# con.code # => "++++++++++++++[>+>++>+++>++++>+++++>++++++>++++++... too long"
|
39
41
|
#
|
40
42
|
# con.convert 'Hallo Welt!', 15 # => 'Hallo Welt!'
|
41
|
-
# con.code # =>
|
43
|
+
# con.code # => "+++++++[>+>++>+++>++++>+++++>++++++>+++++++>+++++... too long"
|
42
44
|
def convert(text, cells_num = 8)
|
43
45
|
# To output a string in Brainfuck, "auxiliary numbers" are written into
|
44
46
|
# certain cells. If a letter is to be output, the letter is converted into
|
@@ -46,13 +48,16 @@ class BrainfuckConverter
|
|
46
48
|
# This is then adjusted so that it corresponds to the ASCII value of the letter.
|
47
49
|
# The auxiliary number or the letter is then output.
|
48
50
|
|
49
|
-
|
51
|
+
raise ArgumentError, 'Text must be a string' unless text.is_a? String
|
52
|
+
raise ArgumentError, 'Number of cells must be a integer' unless cells_num.is_a? Integer
|
53
|
+
raise ArgumentError, 'Number of cells must be larger than 0' if cells_num < 1
|
54
|
+
raise ArgumentError, "Number of cells must be smaller than #{ASCII_MAX}" if cells_num > ASCII_MAX
|
50
55
|
|
51
56
|
# Code is cleared. A new Brainfuck program is started.
|
52
57
|
@code = ''
|
53
58
|
|
54
59
|
# Calculating the auxiliary numbers
|
55
|
-
space_cells =
|
60
|
+
space_cells = ASCII_MAX / (cells_num + 1)
|
56
61
|
@cell_values = []
|
57
62
|
@cell_values[0] = space_cells
|
58
63
|
for i in 1...cells_num
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: brainfuck_converter
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.1.
|
4
|
+
version: 1.1.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Marek
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2023-04-
|
12
|
+
date: 2023-04-28 00:00:00.000000000 Z
|
13
13
|
dependencies: []
|
14
14
|
description: Gem, which makes it possible to convert any ASCII characters into brainfuck
|
15
15
|
code
|