alvarovazquez / hand-challenge

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Hand challenge

This is my solution to the hand challenge from jesus-seijas-sp.

The file original-solution.js contains the solution from the original author. All the input files have also been created by the original author. The rest of the code was created by me.

Below these lines is the original description of the problem to solve.

Usage

You will need Node.js to launch the CLI, either with direct input or loading a instructions file:

$ cd [project-folder]
$ node ./hli-cli.js -f test1.hand
Hello
$ node ./hli-cli.js πŸ€œπŸ‘‡πŸ‘‡πŸ‘‡πŸ‘‡πŸ‘‡πŸ‘‡πŸ‘‡πŸ‘‰πŸ‘†πŸ‘ˆπŸ€›πŸ‘‰πŸ‘‡πŸ‘ŠπŸ‘‡πŸ€œπŸ‘‡πŸ‘‰πŸ‘†πŸ‘†πŸ‘†πŸ‘†πŸ‘†πŸ‘ˆπŸ€›πŸ‘‰πŸ‘†πŸ‘†πŸ‘ŠπŸ‘†πŸ‘†πŸ‘†πŸ‘†πŸ‘†πŸ‘†πŸ‘†πŸ‘ŠπŸ‘ŠπŸ‘†πŸ‘†πŸ‘†πŸ‘Š
Hello

Testing

I implemented a simple testing engine. You can add new test files to the tests fonder and assert the output adding new lines at the end of the tests/run-tests.js like this:

testFile('Shoud output "Your expected output"', 'new-test-input.hand', 'Your expected output');

To run the tests simply execute:

$ cd [project-folder]
$ node .\tests\tests.js
Test Shoud output "Hello": Success!
Test Shoud output "Hello World!": Success!

Introduction

You find a strange mirror that always shows a hand that is moving. The hand appears to be alive, and after a lot of questions of "yes" and "no" answer, you know that the hand is trying to teach you a program that is written in HPL (Hand Programming Language).

This language works with a memory of an indefinite size of bytes, with all values initialized to 0. This language haves 7 instructions:

πŸ‘‰ : moves the memory pointer to the next cell

πŸ‘ˆ : moves the memory pointer to the previous cell

πŸ‘† : increment the memory cell at the current position

πŸ‘‡ : decreases the memory cell at the current position.

🀜 : if the memory cell at the current position is 0, jump just after the corresponding πŸ€›

πŸ€› : if the memory cell at the current position is not 0, jump just after the corresponding 🀜

πŸ‘Š : Display the current character represented by the ASCII code defined by the current position.

Notes:

  • As memory cells are bytes, from 0 to 255 value, if you decrease 0 you'll get 255, if you increment 255 you'll get 0.
  • Loops of 🀜 and πŸ€› can be nested.

Tests

The hand shows you two small programs and their outputs:

This program display "Hello"

πŸ‘‡πŸ€œπŸ‘‡πŸ‘‡πŸ‘‡πŸ‘‡πŸ‘‡πŸ‘‡πŸ‘‡πŸ‘‰πŸ‘†πŸ‘ˆπŸ€›πŸ‘‰πŸ‘‡πŸ‘ŠπŸ‘‡πŸ€œπŸ‘‡πŸ‘‰πŸ‘†πŸ‘†πŸ‘†πŸ‘†πŸ‘†πŸ‘ˆπŸ€›πŸ‘‰πŸ‘†πŸ‘†πŸ‘ŠπŸ‘†πŸ‘†πŸ‘†πŸ‘†πŸ‘†πŸ‘†πŸ‘†πŸ‘ŠπŸ‘ŠπŸ‘†πŸ‘†πŸ‘†πŸ‘Š

This program (with nested loops) display "Hello World!"

πŸ‘‰πŸ‘†πŸ‘†πŸ‘†πŸ‘†πŸ‘†πŸ‘†πŸ‘†πŸ‘†πŸ€œπŸ‘‡πŸ‘ˆπŸ‘†πŸ‘†πŸ‘†πŸ‘†πŸ‘†πŸ‘†πŸ‘†πŸ‘†πŸ‘†πŸ‘‰πŸ€›πŸ‘ˆπŸ‘ŠπŸ‘‰πŸ‘‰πŸ‘†πŸ‘‰πŸ‘‡πŸ€œπŸ‘†πŸ€›πŸ‘†πŸ‘†πŸ‘‰πŸ‘†πŸ‘†πŸ‘‰πŸ‘†πŸ‘†πŸ‘†πŸ€œπŸ‘‰πŸ€œπŸ‘‡πŸ‘‰πŸ‘†πŸ‘†πŸ‘†πŸ‘ˆπŸ‘ˆπŸ‘†πŸ‘†πŸ‘†πŸ‘‰πŸ€›πŸ‘ˆπŸ‘ˆπŸ€›πŸ‘‰πŸ‘‡πŸ‘‡πŸ‘‡πŸ‘‡πŸ‘‡πŸ‘ŠπŸ‘‰πŸ‘‡πŸ‘‰πŸ‘†πŸ‘†πŸ‘†πŸ‘ŠπŸ‘ŠπŸ‘†πŸ‘†πŸ‘†πŸ‘ŠπŸ‘‰πŸ‘‡πŸ‘ŠπŸ‘ˆπŸ‘ˆπŸ‘†πŸ€œπŸ‘‰πŸ€œπŸ‘†πŸ‘‰πŸ‘†πŸ€›πŸ‘‰πŸ‘‰πŸ€›πŸ‘ˆπŸ‘‡πŸ‘‡πŸ‘‡πŸ‘‡πŸ‘‡πŸ‘‡πŸ‘‡πŸ‘‡πŸ‘‡πŸ‘‡πŸ‘‡πŸ‘‡πŸ‘‡πŸ‘‡πŸ‘ŠπŸ‘‰πŸ‘‰πŸ‘ŠπŸ‘†πŸ‘†πŸ‘†πŸ‘ŠπŸ‘‡πŸ‘‡πŸ‘‡πŸ‘‡πŸ‘‡πŸ‘‡πŸ‘ŠπŸ‘‡πŸ‘‡πŸ‘‡πŸ‘‡πŸ‘‡πŸ‘‡πŸ‘‡πŸ‘‡πŸ‘ŠπŸ‘‰πŸ‘†πŸ‘ŠπŸ‘‰πŸ‘†πŸ‘Š

Challenge

The file "input.hand" is the code of the program

Good luck!

About


Languages

Language:JavaScript 100.0%