🎉 Exercism Research is now launched. Help Exercism, help science and have some fun at research.exercism.io 🎉
Avatar of RaulToomba

RaulToomba's solution

to Secret Handshake in the CFML Track

Published at Jul 13 2018 · 0 comments
Test suite

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".

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.

To run the code in this exercise, you will only need to have CommandBox CLI installed. This binary runs CFML code from the command line.

To run the tests, cd into the exercise folder and run the following:

box task run TestRunner
# Or start up a test watcher that will rerun when files change
box task run TestRunner --:watcher

The tests leverage a library called TestBox which supports xUnit and BDD style of testing. All test suites will be written in the BDD style which uses closures to define test specs. You won't need to worry about installing TestBox. The CLI test runner will take care of that for you. You just need to be connected to the internet the first time you run it. You can read more about it here:



Bert, in Mary Poppins http://www.imdb.com/title/tt0058331/quotes/qt0437047

Submitting Incomplete Solutions

It's possible to submit an incomplete solution so you can see how others have completed the exercise.


component extends="testbox.system.BaseSpec" {

	function beforeAll(){
	  SUT = createObject( 'SecretHandshake' );

	function run(){
		describe( "My SecretHandshake class", function(){			

			describe( 'Create a handshake for a number', function(){

				it( 'wink for 1', function(){
					expect( SUT.commands( number='1' ) ).toBe( ["wink"] );

				it( 'double blink for 10', function(){
					expect( SUT.commands( number='2' ) ).toBe( ["double blink"] );

				it( 'close your eyes for 100', function(){
					expect( SUT.commands( number='4' ) ).toBe( ["close your eyes"] );

				it( 'jump for 1000', function(){
					expect( SUT.commands( number='8' ) ).toBe( ["jump"] );

				it( 'combine two actions', function(){
					expect( SUT.commands( number='3' ) ).toBe( ["wink","double blink"] );

				it( 'reverse two actions', function(){
					expect( SUT.commands( number='19' ) ).toBe( ["double blink","wink"] );

				it( 'reversing one action gives the same action', function(){
					expect( SUT.commands( number='24' ) ).toBe( ["jump"] );

				it( 'reversing no actions still gives no actions', function(){
					expect( SUT.commands( number='16' ) ).toBe( [] );

				it( 'all possible actions', function(){
					expect( SUT.commands( number='15' ) ).toBe( ["wink","double blink","close your eyes","jump"] );

				it( 'reverse all possible actions', function(){
					expect( SUT.commands( number='31' ) ).toBe( ["jump","close your eyes","double blink","wink"] );

				it( 'do nothing for zero', function(){
					expect( SUT.commands( number='0' ) ).toBe( [] );




component extends="SecretHandshakeTest" {

	function beforeAll(){
	  SUT = createObject( 'Solution' );

* Your implmentation of the SecretHandshake exercise
component {
	* @returns 
	function commands( input ) {
		a=listToArray(binary, "");
		if ( (arrayLen(a) >= 1) && (a[arrayLen(a)] == 1)){
		if ( (arrayLen(a) >= 2) && (a[arrayLen(a)-1] == 1)){
			ArrayAppend(shake,"double blink");
		if ( (arrayLen(a) >= 3) && (a[arrayLen(a)-2] == 1)){
			ArrayAppend(shake,"close your eyes");
		if ( (arrayLen(a) >= 4) && (a[arrayLen(a)-3] == 1)){
		if ( (arrayLen(a) >= 5) && (a[arrayLen(a)-4] == 1)){
			for ( var i = arrayLen( shake ); i >= 1; i-- ) {
		return shake;

Community comments

Find this solution interesting? Ask the author a question to learn more.

What can you learn from this solution?

A huge amount can be learned from reading other people’s code. This is why we wanted to give exercism users the option of making their solutions public.

Here are some questions to help you reflect on this solution and learn the most from it.

  • What compromises have been made?
  • Are there new concepts here that you could read more about to improve your understanding?