Last active
November 8, 2015 01:48
-
-
Save kenmazaika/598d462cd3fa3f7ddbae to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # Arguments: | |
| # n (an integer) containing 16 digits | |
| # Return value: | |
| # an array containing each of the 16 digits with even indexed items doubled (or if it's greater than 10, doubled and minus 9) | |
| # Example: | |
| # [0,0,0,0,1,1,0,1,9,8,7,6,5,4,3,2,1] # original revered for reference | |
| # double_3(00002101985614622) => [0,0,0,0,2,1,0,1,9,8,5,6,1,4,6,2,2] | |
| def double_3(digits) | |
| transformed_digits = [] | |
| # TODO: * loop through digits array | |
| # * calculate the transformed value for the digit | |
| # * if the element in the array % 2 == 0, transform by doing doubling (and maybe -9'ing) | |
| # * otherwise use the initial value of the digit | |
| # * add the digit we just calculated on the transformed_digits array | |
| # * return the value of the transformed_digits array | |
| end | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment