Skip to main content
added 582 characters in body
Source Link
200_success
  • 144.2k
  • 22
  • 188
  • 473

Here's a shorter, less readable version, using similar ideas, but with more cell reuse.

+++++ +++++ [- >
 +++++ ++ >
 +++++ +++++ >
 +++++ +++++ + >
 ++++ >
 +++ >
 +++++ ++++ <<<<< <
]                        Print:
> ++ .                   "H"
> + .                    "e"
> -- .. +++ .            "llo"
> ++++ .                 comma
> ++ .                   space
> --- .                  "W"
<<< . +++ . ----- - .    "orl"
< - .                    "d"
>>> + .                  "!"

Here's a shorter, less readable version, using similar ideas, but with more cell reuse.

+++++ +++++ [- >
 +++++ ++ >
 +++++ +++++ >
 +++++ +++++ + >
 ++++ >
 +++ >
 +++++ ++++ <<<<< <
]                        Print:
> ++ .                   "H"
> + .                    "e"
> -- .. +++ .            "llo"
> ++++ .                 comma
> ++ .                   space
> --- .                  "W"
<<< . +++ . ----- - .    "orl"
< - .                    "d"
>>> + .                  "!"
deleted 3 characters in body
Source Link
200_success
  • 144.2k
  • 22
  • 188
  • 473

No, that's unreadable code and therefore not idiomatic. The typical way to generate large numbers is to use multiplication.

"Hello, World!" translates to ASCII values

< 72, 101, 108, 108, 111, 44, 32, 87, 111, 114, 108, 100, 33 >

… which can be thought of as

10 * < 7, 10, 11, 11, 11,  4,  3,  9, 11, 11, 11, 10, 3 >
   + < 2,  1, -2, -2,  1,  4,  2, -3,  1,  4, -2,  0, 3 >

The code should therefore be written that way. The consecutive elevens can lead to a compression optimization.

+++++ +++++ [- >
 +++++ ++ >
 +++++ +++++ >
 +++++ +++++ + >
 ++++ >
 +++ >
 +++++ ++++ >
 +++++ +++++ + >
 +++++ +++++ >
 +++ <<<<< <<<<
]                        Print:
> ++ .                   "H"
> + .                    "e"
> -- .. +++ .            "llo"
> ++++ .                 comma
> ++ .                   space
> --- .                  "W"
> + . +++ . ----- - .    "orl"
> .                      "d"
> +++ .                  "!"

For readability, you should also group the increment and decrement operators in fives. I also find your comments unnecessarily verbose.

This solution uses one more memory cellcells than the original code. It's well worth it for the readability, in my opinion.

No, that's unreadable code and therefore not idiomatic. The typical way to generate large numbers is to use multiplication.

"Hello, World!" translates to ASCII values

< 72, 101, 108, 108, 111, 44, 32, 87, 111, 114, 108, 100, 33 >

… which can be thought of as

10 * < 7, 10, 11, 11, 11,  4,  3,  9, 11, 11, 11, 10, 3 >
   + < 2,  1, -2, -2,  1,  4,  2, -3,  1,  4, -2,  0, 3 >

The code should therefore be written that way. The consecutive elevens can lead to a compression optimization.

+++++ +++++ [- >
 +++++ ++ >
 +++++ +++++ >
 +++++ +++++ + >
 ++++ >
 +++ >
 +++++ ++++ >
 +++++ +++++ + >
 +++++ +++++ >
 +++ <<<<< <<<<
]                        Print:
> ++ .                   "H"
> + .                    "e"
> -- .. +++ .            "llo"
> ++++ .                 comma
> ++ .                   space
> --- .                  "W"
> + . +++ . ----- - .    "orl"
> .                      "d"
> +++ .                  "!"

For readability, you should also group the increment and decrement operators in fives. I also find your comments unnecessarily verbose.

This solution uses one more memory cell than the original code. It's well worth it for the readability, in my opinion.

No, that's unreadable code and therefore not idiomatic. The typical way to generate large numbers is to use multiplication.

"Hello, World!" translates to ASCII values

< 72, 101, 108, 108, 111, 44, 32, 87, 111, 114, 108, 100, 33 >

… which can be thought of as

10 * < 7, 10, 11, 11, 11,  4,  3,  9, 11, 11, 11, 10, 3 >
   + < 2,  1, -2, -2,  1,  4,  2, -3,  1,  4, -2,  0, 3 >

The code should therefore be written that way. The consecutive elevens can lead to a compression optimization.

+++++ +++++ [- >
 +++++ ++ >
 +++++ +++++ >
 +++++ +++++ + >
 ++++ >
 +++ >
 +++++ ++++ >
 +++++ +++++ + >
 +++++ +++++ >
 +++ <<<<< <<<<
]                        Print:
> ++ .                   "H"
> + .                    "e"
> -- .. +++ .            "llo"
> ++++ .                 comma
> ++ .                   space
> --- .                  "W"
> + . +++ . ----- - .    "orl"
> .                      "d"
> +++ .                  "!"

For readability, you should also group the increment and decrement operators in fives. I also find your comments unnecessarily verbose.

This solution uses more memory cells than the original code. It's well worth it for the readability, in my opinion.

Source Link
200_success
  • 144.2k
  • 22
  • 188
  • 473

No, that's unreadable code and therefore not idiomatic. The typical way to generate large numbers is to use multiplication.

"Hello, World!" translates to ASCII values

< 72, 101, 108, 108, 111, 44, 32, 87, 111, 114, 108, 100, 33 >

… which can be thought of as

10 * < 7, 10, 11, 11, 11,  4,  3,  9, 11, 11, 11, 10, 3 >
   + < 2,  1, -2, -2,  1,  4,  2, -3,  1,  4, -2,  0, 3 >

The code should therefore be written that way. The consecutive elevens can lead to a compression optimization.

+++++ +++++ [- >
 +++++ ++ >
 +++++ +++++ >
 +++++ +++++ + >
 ++++ >
 +++ >
 +++++ ++++ >
 +++++ +++++ + >
 +++++ +++++ >
 +++ <<<<< <<<<
]                        Print:
> ++ .                   "H"
> + .                    "e"
> -- .. +++ .            "llo"
> ++++ .                 comma
> ++ .                   space
> --- .                  "W"
> + . +++ . ----- - .    "orl"
> .                      "d"
> +++ .                  "!"

For readability, you should also group the increment and decrement operators in fives. I also find your comments unnecessarily verbose.

This solution uses one more memory cell than the original code. It's well worth it for the readability, in my opinion.