about | help | code help+videos | done | prefs |
(MEDIUM) Given an input String str, return an int array of length len which is constructed as follows: 1) the numeric value of the first character of str is added to the first element of the array 2) assuming that str contains 2+ characters, the numeric value of the second character of str is added to the second element of the array, or the first element (index 0) if len is 1 3) the numeric value of the nth character of str (index n-1) is added to the nth element of the array, unless len<n in which case you wrap around. With this algorithm, any length of input can be hashed into an output with a fixed length. Also, the numeric value of a char for this problem is not "adjusted" to begin with 'A'==1 like with Caesar ciphers: it is simply the numeric equivalent of the char itself.HINTUse the remainder operator % to "wrap around." apcsaHashArraySumString("ABCDEFGHIJKLMNOPQRSTUVWXYZ", 1) → [2015] apcsaHashArraySumString("ABCDEFGHIJKLMNOPQRSTUVWXYZ", 2) → [1001, 1014] apcsaHashArraySumString("ABC", 3) → [65, 66, 67] ...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: 320
Copyright Nick Parlante 2017 - privacy