commit 7c3fcf9760bc31510bd993ea47e8e1affdad26d1
parent 0c230b77b5bf4b6371906f38ee72e66cb7cad63a
Author: Samir Parikh <noreply@samirparikh.com>
Date: Thu, 12 May 2022 17:05:07 +0000
initial commit for secret handshake
Diffstat:
4 files changed, 237 insertions(+), 0 deletions(-)
diff --git a/secret-handshake/HELP.md b/secret-handshake/HELP.md
@@ -0,0 +1,35 @@
+# Help
+
+## Running the tests
+
+There is a Perl 5 script with the extension `.t`, which will be used to test
+your solution. You can run through the tests by using the command:
+
+```bash
+`prove .`
+```
+
+## Submitting your solution
+
+You can submit your solution using the `exercism submit SecretHandshake.pm` command.
+This command will upload your solution to the Exercism website and print the solution page's URL.
+
+It's possible to submit an incomplete solution which allows you to:
+
+- See how others have completed the exercise
+- Request help from a mentor
+
+## Need to get help?
+
+If you'd like help solving the exercise, check the following pages:
+
+- The [Perl 5 track's documentation](https://exercism.org/docs/tracks/perl5)
+- [Exercism's support channel on gitter](https://gitter.im/exercism/support)
+- The [Frequently Asked Questions](https://exercism.org/docs/using/faqs)
+
+Should those resources not suffice, you could submit your (incomplete) solution to request mentoring.
+
+To get help if you're having trouble, you can use one of the following resources:
+
+- [/r/perl5](https://www.reddit.com/r/perl5) is the perl5 subreddit.
+- [StackOverflow](http://stackoverflow.com/questions/tagged/perl5) can be used to search for your problem and see if it has been answered already. You can also ask and answer questions.
+\ No newline at end of file
diff --git a/secret-handshake/README.md b/secret-handshake/README.md
@@ -0,0 +1,50 @@
+# Secret Handshake
+
+Welcome to Secret Handshake on Exercism's Perl 5 Track.
+If you need help running the tests or submitting your code, check out `HELP.md`.
+
+## Instructions
+
+> There are 10 types of people in the world: Those who understand
+> binary, and those who don't.
+
+You and your fellow cohort of those in the "know" when it comes to
+binary decide to come up with a secret "handshake".
+
+```text
+1 = wink
+10 = double blink
+100 = close your eyes
+1000 = jump
+
+
+10000 = Reverse the order of the operations in the secret handshake.
+```
+
+Given a decimal number, convert it to the appropriate sequence of events for a secret handshake.
+
+Here's a couple of examples:
+
+Given the input 3, the function would return the array
+["wink", "double blink"] because 3 is 11 in binary.
+
+Given the input 19, the function would return the array
+["double blink", "wink"] because 19 is 10011 in binary.
+Notice that the addition of 16 (10000 in binary)
+has caused the array to be reversed.
+
+## Source
+
+### Created by
+
+- @bistik
+
+### Contributed to by
+
+- @kytrinyx
+- @m-dango
+- @rfilipo
+
+### Based on
+
+Bert, in Mary Poppins - http://www.imdb.com/title/tt0058331/quotes/qt0437047
+\ No newline at end of file
diff --git a/secret-handshake/SecretHandshake.pm b/secret-handshake/SecretHandshake.pm
@@ -0,0 +1,12 @@
+package SecretHandshake;
+use strict;
+use warnings;
+use Exporter qw<import>;
+our @EXPORT_OK = qw<handshake>;
+
+sub handshake {
+ my ($number) = @_;
+ return undef;
+}
+
+1;
diff --git a/secret-handshake/secret-handshake.t b/secret-handshake/secret-handshake.t
@@ -0,0 +1,138 @@
+#!/usr/bin/env perl
+use Test2::V0;
+use JSON::PP;
+use constant JSON => JSON::PP->new;
+
+use FindBin qw<$Bin>;
+use lib $Bin, "$Bin/local/lib/perl5";
+
+use SecretHandshake qw<handshake>;
+
+my @test_cases = do { local $/; @{ JSON->decode(<DATA>) }; };
+
+imported_ok qw<handshake> or bail_out;
+
+for my $case (@test_cases) {
+ is( handshake( $case->{input}{number} ),
+ $case->{expected}, $case->{description}, );
+}
+
+done_testing;
+
+__DATA__
+[
+ {
+ "description": "wink for 1",
+ "expected": [
+ "wink"
+ ],
+ "input": {
+ "number": 1
+ },
+ "property": "commands"
+ },
+ {
+ "description": "double blink for 10",
+ "expected": [
+ "double blink"
+ ],
+ "input": {
+ "number": 2
+ },
+ "property": "commands"
+ },
+ {
+ "description": "close your eyes for 100",
+ "expected": [
+ "close your eyes"
+ ],
+ "input": {
+ "number": 4
+ },
+ "property": "commands"
+ },
+ {
+ "description": "jump for 1000",
+ "expected": [
+ "jump"
+ ],
+ "input": {
+ "number": 8
+ },
+ "property": "commands"
+ },
+ {
+ "description": "combine two actions",
+ "expected": [
+ "wink",
+ "double blink"
+ ],
+ "input": {
+ "number": 3
+ },
+ "property": "commands"
+ },
+ {
+ "description": "reverse two actions",
+ "expected": [
+ "double blink",
+ "wink"
+ ],
+ "input": {
+ "number": 19
+ },
+ "property": "commands"
+ },
+ {
+ "description": "reversing one action gives the same action",
+ "expected": [
+ "jump"
+ ],
+ "input": {
+ "number": 24
+ },
+ "property": "commands"
+ },
+ {
+ "description": "reversing no actions still gives no actions",
+ "expected": [],
+ "input": {
+ "number": 16
+ },
+ "property": "commands"
+ },
+ {
+ "description": "all possible actions",
+ "expected": [
+ "wink",
+ "double blink",
+ "close your eyes",
+ "jump"
+ ],
+ "input": {
+ "number": 15
+ },
+ "property": "commands"
+ },
+ {
+ "description": "reverse all possible actions",
+ "expected": [
+ "jump",
+ "close your eyes",
+ "double blink",
+ "wink"
+ ],
+ "input": {
+ "number": 31
+ },
+ "property": "commands"
+ },
+ {
+ "description": "do nothing for zero",
+ "expected": [],
+ "input": {
+ "number": 0
+ },
+ "property": "commands"
+ }
+]