Skip to content

Instantly share code, notes, and snippets.

@sjourdan
Created May 12, 2015 19:45
Show Gist options
  • Save sjourdan/ca2091f87d1c66a36370 to your computer and use it in GitHub Desktop.
Save sjourdan/ca2091f87d1c66a36370 to your computer and use it in GitHub Desktop.
Cloud Abacus

Creating a Cloud Abacus Easy

This is going to be another scripting challenge.... you may use any language tools you want to solve it.

The task is to create two scripts (or one script with a symlink, whatevs) that will take as its only argument a 4 bit integer value (0-15) and create a file with a path based on the bit pattern. The directories should be created with the most significant bit first and will be named either "0" or "1" depending on the value of the bit in that position.

The first script should be called /usr/local/bin/seta and will use /var/math/a as its root directory. The second script will be /usr/local/bin/setb and use /var/math/b for its root. So, calling /usr/local/bin/seta 10 should create the directory /var/math/a/1/0/1/0/. Any files in the subdirectories will be ignored.

Your script should clear its target directory (/var/math/[a|b]) before writing files to ensure that data from previous runs will be removed. A third script called /usr/local/bin/adder has been provided and will add the two numbers you have encoded into directories. You will be graded on whether or not /usr/local/bin/adder returns the correct number.

Example:

[root@bean math]# pwd
/var/math
[root@bean math]# /usr/local/bin/seta 5
[root@bean math]# /usr/local/bin/setb 9
[root@bean math]# /usr/local/bin/adder
14
[root@bean math]# find -mindepth 5
./a/0/1/0/1
./b/1/0/0/1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment