id/email
password
forgot password | create account
about | help | code help+videos | done | prefs
CodingBat code practice

 

orion.a.smith@gmail.com apcsa-encryption > apcsaHashArraySumString
prev  |  next  |  chance

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.
HINT
Use 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)

public int[] apcsaHashArraySumString(String str, int len) { }

Editor font size %:
Shorter output


Forget It! -- delete my code for this problem

Progress graphs:
 Your progress graph for this problem
 Random user progress graph for this problem
 Random Epic Progress Graph

Java Help

Misc Code Practice

Difficulty: 320

Copyright Nick Parlante 2017 - privacy