about | help | code help+videos | done | prefs |
Write a method that converts a positive integer 'num' into an encoded version of that number (like a secret code, or encryption). The array 'code' will always contain exactly 10 elements, and each element will be a single digit, 0 through 9. Each digit will be used exactly once. The 'code' array is used to convert digits in 'num' into the secret code. The index of the 'code' array is used to find the digit to use in the code. For example, to find the code for the digit 7, you look in the 'code' array at index 7; the number stored in there is the digit to use in place of 7. In addition to all of this encoding, the digits are also reversed in the secret code. So even if the 'code' array simply maps each digit to itself, the result would still be the original number in reverse. So if code={0,1,2,3,4,5,6,7,8,9} and num=3589, the result would be 9853. If code={9,8,7,6,5,4,3,2,1,0} and num=241, the result would be 857. (758, but in reverse order). Look at the test data for further examples. You must NOT use ANY Strings or String commands in your solution. Don't forget about div and mod! sept28_2018_HL_codeMaker([9, 8, 5, 4, 1, 2, 3, 0, 7, 6], 42) → 51 sept28_2018_HL_codeMaker([9, 8, 5, 4, 1, 2, 3, 0, 7, 6], 23590) → 96245 sept28_2018_HL_codeMaker([9, 8, 5, 4, 1, 2, 3, 0, 7, 6], 4162) → 5381 ...Save, Compile, Run (ctrl-enter) |
Progress graphs:
Your progress graph for this problem
Random user progress graph for this problem
Random Epic Progress Graph
Difficulty: 290
Copyright Nick Parlante 2017 - privacy