Java PRP Programming Examples
Java PRP Programming Examples
The 'WeightOfString' function calculates the weight based on alphabetic characters. It converts the string to uppercase. If 'input2' is 0, it ignores vowels and non-letter characters; otherwise, it includes vowels. For each considered character, it calculates the weight by subtracting 64 from the ASCII value of the character (since 'A' = 65) and adds this to a cumulative sum. The function returns the total sum as the string's weight .
The 'PasswordStableUnstable' function differentiates by counting digit occurrences in each number. It uses an array 'freq' to hold frequencies of digits 0-9 for each number. It calculates the 'max' frequency for each number. A number is 'stable' if all non-zero frequencies are equal to 'max'; otherwise, it is 'unstable.' The function sums all stable numbers and subtracts the sum of unstable numbers to return the final result .
The 'totalHillWeight' function calculates the total weight by iterating through levels of the hill. For each level (from 0 to 'input1'), it adds the current weight 'input2' multiplied by the number of elements in that level. After each level, 'input2' is incremented by 'input3' to account for the increase in weight at each successive level. The sum of all levels is returned as the total hill weight .
The 'WeightOfString' function calculates the string's weight by iterating through each character. If 'input2' is 0, it ignores vowels and non-alphabetic characters; otherwise, it adds the weight of all alphabetic characters. The weight is determined by subtracting 64 from the ASCII value of each character to convert it to a numerical value (A=1, B=2, etc.). These values are summed to get the total string weight .
The 'PossibleWords' function converts both 'input1' and 'input2' to uppercase to ensure case-insensitivity. It then splits 'input2' by colon ':' to get individual words. For each word, it checks if the length matches 'input1'. If lengths match, it checks each character in 'input1'. If the character is an underscore '_', it ignores it; otherwise, it compares it with the corresponding character in the word. If all characters match or are underscores, the word is considered a match and added to the result string. If no matches are found, it returns 'ERROR-009' .
In the 'UserIdGeneration' function, case transformation is used to alternate the case of characters in the final result string. Starting from a string formed by the concatenation rule, the function checks if each character is lowercase. If it is, it converts it to uppercase and vice versa. This ensures the generated user ID has a sequence of alternating cases, enhancing readability and variability of the ID .
The 'IsPalinStr' function checks for palindromes by first reversing the input string. It does so by iterating over the string from the last character to the first, constructing the reversed string. Then, it compares the reversed string with the original. If they are identical, the string is a palindrome; otherwise, it is not .
The 'FindPasswordStableUnstable' function calculates the difference by processing each input number with frequency analysis. It determines if a number is stable by checking if all digits that appear have the same frequency. Each frequency is compared against the maximum frequency found. Numbers with all non-zero frequencies equal to the max frequency are deemed stable. It sums stable numbers, subtracts sums of unstable numbers, and returns the resulting difference .
The 'MostFrequentDigit' function first concatenates all numbers into a single string and initializes an array 'freq' to count occurrences of each digit (0-9). It increments the count for each digit found in the string. The function then determines the maximum frequency 'max' by checking each frequency count. Finally, it loops through the frequencies to find which digit(s) occurred 'max' times and outputs those as the most frequent digits .
The 'DigiLock' function processes three integers, treating them as three-digit numbers. It extracts units, tens, and hundreds places into separate arrays ('u', 't', 'h'). It finds the minimum value in each of these place arrays and constructs the smallest possible value. Similarly, it finds the maximum values to construct the largest possible number, using these minima and maxima to generate a final result key, which is returned .