DRJ
Ruby dev @vzaar
"...designed to test the boundaries of computer programming language design, as a proof of concept, as software art, or as a joke."
"Theoretically capable of computing any computable function or simulating any other computational model, if given access to an unlimited amount of memory."
+++++++++++[>++++++<-]>.<+++++++++++
[>>++++++++++<<-]>>++++.<<++++++++++
+[>>>+++++++++<<<-]>>>--.++++++++.++
+++.--------.<+++.>---.++++++++.<<<+
++++++++++++++++++++++++++++++++.
irb > array = (0..Float::INFINITY).lazy.collect { |x| 0 }
=> #<Enumerator::Lazy: #<Enumerator::Lazy: 0..Infinity>:collect>
irb > _.first 10
=> [0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
irb > pointer = _[0]
=> 0
(Program Start)
(translated into Ruby)
# _
# [0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
irb > pointer += 1
=> 1
# _
# [0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
irb > pointer -= 1
=> 0
# _
# [1, 0, 0, 0, 0, 0, 0, 0, 0, 0]
irb > array[pointer] += 1
=> 1
# _
# [0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
irb > array[pointer] -= 1
=> 0
# __
# [..., 65, 0, 23, ...]
irb > puts pointer.chr
=> "A"
irb > gets[0].ord
Dan
=> 68
irb > pointer = 10
irb > while pointer != 0 do
irb > # pointer += 1 # [10, 0, ...]
irb > # array[pointer] += 1 # [10, 1, ...]
irb > # pointer -= 1 # [10, 1, ...]
irb > # array[pointer] -= 1 # [9, 1, ...]
irb > # and so forth... # [0, 10, ...]
# the values are
# copied across
irb > ...
irb > end
+++++++++++[>++++++<-]>.<+++++++++++
[>>++++++++++<<-]>>++++.<<++++++++++
+[>>>+++++++++<<<-]>>>--.++++++++.++
+++.--------.<+++.>---.++++++++.<<<+
++++++++++++++++++++++++++++++++.
> brainfuck -e '
+++++++++++[>++++++<-]>.<+++++++++++
[>>++++++++++<<-]>>++++.<<++++++++++
+[>>>+++++++++<<<-]>>>--.++++++++.++
+++.--------.<+++.>---.++++++++.<<<+
++++++++++++++++++++++++++++++++.'
Brainfuck!%
> brainfuck -e '
+++++++++++[>++++++<-]>.<+++++++++++
[>>++++++++++<<-]>>++++.<<++++++++++
+[>>>+++++++++<<<-]>>>--.++++++++.++
+++.--------.<+++.>---.++++++++.<<<+
++++++++++++++++++++++++++++++++.'
Brainfuck!%
# p0:0/11 p1:0
+++++++++++
# while p0 > 0
[
# p1:/6 => p0:11 p1:6
>++++++
# p0:\1 => p0:10 p1:6
<-
# and so forth until p0:0 and p1:66
]
# go to p1:66
>
# print 'B'
.
# go to p0 and increment by 11
<+++++++++++
[
# go to p2 and increment by 10, decrement p0
>>++++++++++<<-
# until p2:110 and p0:0
]
# go to p2 and increment by 4
>>++++
# print 'r'
.
<<+++++++++++[>>>+++++++++<<<-]>>>--. # p0:11\0 p3:11/97 a
++++++++. # p3:97/105 i
+++++. # p3:105/110 n
--------. # p3:110\102 f
<+++. # p2:114/117 u
>---. # p3:102\99 c
++++++++. # p3:99/107 k
<<<+++++++++++++++++++++++++++++++++. # p0:0/33 !
Brainfuck!%
[-] # p0:0
> # p1
[ # enter loop if p1:1
> # p2
[ # enter loop if p2:1
<<+>> # p0:1
[-] # empty p2
]
< # empty p1
[-]
]
< # p0
=> p0:1 only if p1:!0 AND p2:!0, else p0:0
[-] # p0:0
> # p1
[>>+<<[-]] # p3:/1 if p1:!0
> # p2
[>+<[-]] # p3:/1 if p2:!0
> # p3
[<<<+>>>[-]] # p0:1 if p3:!0
=> p0:1 only if p1:!0 OR p2:!0, else p0:0.
The last line is necessary to make sure
p0:1 and not p0:2 (if both inputs are true).
[-] # p0:0
>>>[-]<< # p3:0 p1
[>>+<<[-]] # p3:/1
> # p2
[>+<[-]] # p3:/1
>- # p3:\1 p3:0 if XOR is true
<<<+>>> # p0:1 p3
[<<<->>>[-]] # p0:\1
<<< # p0
=> p0:1 only if p1:!0 XOR p2:!0, else p0:0
[-]+ # p0:1
>[<->[-]]< # p0:0 if p1:!0
=> p0:1 only if p1:!0
[ # enter loop if p1 has non-zero value
>++++++++ # p1:8
[>+++++++++<-] # p2:72
>. # display p2
<< # p0
[-] # p0:0 so that the loop only gets executed once
]
=> only IF p0:!0 will the loop get executed.
, # read input
---------------- # p0:\64 you can change this value to anything
---------------- # you want; 64 is the value you compare
---------------- # p0 with
----------------
>[-]+< # p1:1 p0
[ # enter loop if p0:!0
> # p1
[-] # p1:0
< # p0
[-] # p0:0 so you can exit the loop
]
> # p1
[ # enter loop if p0:0 (64 was entered)
>++++++++ # p2:8
[>++++++++<-] # p4:64
>. # display '@'
<< # p1
[-] # p1:0 so the loop gets executed only once
]
, # read input
----------------
---------------- # p0:\64
----------------
----------------
[ # enter loop if p0:!64
>++++++++ # p1:8
[>++++++++<-] # p2:64
>. # display '@'
<< # p0
[-] # p0:0 so you can exit the loop
]
, # read input
----------------
---------------- # p0:\64
----------------
----------------
>>>+<<< # p3:1 since p0..p2 are used
[ # enter loop if p0:!64 \
>+++++++++++++ # p1:13 |
[>++++++<-] # p2:78 |
>. # display 'N' | ELSE part
>- # p3:0 |
<<< # p0 |
[-] # p0:0 so you can exit the loop /
]
>>> # p3
[ # enter loop if p3:1 and p0:64 \
<< # p1 |
++++++++ # p1:8 |
[>++++++++<-] # p2:64 | IF part
>. # display '@' |
> # p3 |
[-] # p3:0 so you can exit the loop /
]
<<< # rewind, p0:0 or 1
+++++++++
+++++++++
+++++++++
+++++++++
+++++++++
+++++++++. # p0:/48 to print ASCII 0 or 1
++++++++++[>+++++++<-]>-.<++++++++[>+++++<-]>+.++++++.<+++[>-----<-]>.<+++
[>++++<-]>+.<++++++++[>>++++<<-]>>.<---------.+++++.++.+++++.-.<++++[>>+++
+++<<-]>>++.<<++++[>>------<<-]>>--.>,.<<<+++++++++++++.---.[-]>>>.<++++++
+.<-.>-------.<+++.<++++[>-----<-]>-.+++++++++++.+++++++++.<++++[>----<-]>
.>.<++++.++++++++++.>.<[-]>>[<<+>>-]<[-]<<+[>[>>+<<-]>>[<+<+>>-]<>[-]+<[>-
<[-]]>[<++++++++++[>++++++++++<-]>.<++++++[>+++<-]>-.<++++++[>---<-]>+.+++
++++++.<<<[-]>>>[-]]<<[>>+<<-]>>[<+<+>>-]<->[-]+<[>-<[-]]>[<+++++++++++[>+
+++++++++<-]>.-----------..<<<[-]>>>[-]]<<--<]>[-]<++++++[>++++++++<-]>--.
Enter input: 3
3
3's value is odd.%
Enter input: 2
2
2's value is even.%
REALLY COOOOOOOOL
By DRJ
A lightning talk on the brainfuck language