From b1aab17392dfb464ee76c0a89320d63a3aa8750d Mon Sep 17 00:00:00 2001
From: ranggaadi Summing the digit from exponential results Given a number along with the exponential number whose exponential number can be a positive or negative number. after getting the exponential result, sum the number of digits from the exponential result.
+Breaking it down:
+ * given number M and its exponential number N, so M x M ... x M, N times.
+ * iterate over the the result of exponentiation and sum all of the digit.
+ * dont forget if the exponent number is negative, it may be contain point (.) that need to be ignored.
-__code Implementation:__
-10. Name
+10. Power Digit Sum
-__The challenge:__
+```javascript +// #1.Using Iterative and type casting approach + +function powerDigitSum(num, pow){ + let sum = 0 + for (let digit of Math.pow(num, pow).toString()){ + if (digit === '.'){ //checking for point (if exponential is negative) + continue; + } + sum += digit*1 + } + return sum +} + +console.log(powerDigitSum(2, 16)) // 65536 -> 6+5+5+3+6=25 +console.log(powerDigitSum(2, -5)) // 0.03125 -> 0+0+3+1+2+5=11 + +``` +
The string reversal algorithm is perhaps the most common JavaScript code challenge on the internet. In this article, we explore various string reversal techniques as a good number of string manipulation algorithms are dependent on ones ability to reverse a string.
-The process here is quite simple and straight forward. Our function will receive only one parameter i.e the string to be reversed. - -Next, we would have to manipulate the characters in this string logically in order to return the string in reverse. -
- -__Code Implementation:__ -We will now explore ways to solve this challenge below. They are: - - 1.Chaining in-built methods - 2.Using a For-loop - -*1.Chaining in-built methods:* - - - The **.split()** method is used to split a string into an array of characters. It receives one argument which specifies the separator that determines where every split occurs. - - - The .reverse() method reverses the order of the elements in an array - - - The **.join()** method is used to combine the elements of an array into a string. It receives one argument which specifies the separator. When none is supplied, it defaults to a comma. - - -In the code snippet below we use these methods to create a one-line solution by chaining them in succession to split the received text into an array of characters, reverse the order of array’s elements and join the elements of the reversed array to produce the reversed text.
- -```js - function reverseString(text){ - return text.split("").reverse().join("") - } -``` - -*2.For-Loop Way:* - -For loops are used to execute a piece of code as long as a condition is met. In the solution below, we use a decrementing for-loop to run through the string received and append each character to another variable in reverse order. See how this is done below
- -```js - function reverseString(text){ - let result; - - for(let i=text.length-1;i>=0,i--){ - result+=text[i]; - } - return result; - } -``` - - - -Here we will be working with strings and arrays. The main challenge is given in The challenge section below.Let's find it
- -__The challenge:__You are given a string of text containing zero or more vowels in it,count the number of vowels that can be found in given text. For example:
- - ```js - vowelCounter("Hacktoberfest is very Nice") //will return 8 - ``` - - -__Algorithmic Thinking:__After reading the problem statement, __ given text of string__ must be in your mind. Let's go further to explore
- -> A function is a block of organized, reusable code that is used to perform a single, related action. They may or may not accepts value as parameter for computational tasks. The values are also called as Arguments. - -*Let's Breakdown the approach* - -* write a function which receives a parameter called "text". It should be string of any desired length which is to be passed in function as an argument. - -* create a counter to count vowels - -* Next, we need to scan the string and search for the vowels ('a','e','i','o','u') - -* Function will return the number of vowels found. So you have to use __*return*__ function which stops the the function execution and returns a value. -We are going to use Two approaches for solving this problem:
- - 1. Using Iterative approach - 2. Using Regular Expression - -1.Using Iterative approach: -In this challenge, we will be dealing with strings, arrays and objects. We will learn to manipulate these data types using various methods that'd bring us to a working solution in the end.
- -__The challenge:__ Given a string of text, find and return the most recurring character. e.g - -```js -maxRecurringChar('aabacada') // will return 'a' -``` - -__Algorithmic Thinking:__ From the challenge statement, we can infer that our function has only one parameter; the string of text.
We need to somehow keep track of every character in the string as well as the number of times it exists.
This we would describe as character mapping. Once we successfully create such a map, we can easily determine which character has the highest occurence.
Often during presentation situation arises where we need to manipulate the letter casing of strings within our application. Javascript offers two popular methods designed for this purpose:
-
- 1.toUpperCase(): this method returns the string passed in as an argument converted in uppercase letters.
-
- 2.toLowerCase(): this method returns the string passed in as an argument converted to lowercase letters.
-
-__The challenge:__ Given a sentence containing two or more words, return the equivalent of the sentence when capitalized. E.g
-```js
-capitalSentence("a cat and a dog") // would return "A Cat And A Dog"
-```
-
-
-__Algorithmic Thinking:__
-At a glance this may seem like a very simple challenge, but it actually isn’t when considered carefully. - -Working through the challenge, it seems that we need to write a function that'd receive the sentence to be converted as an argument -Next,we go through every word in sentence and capitilize every first letter of word. This brings concept of LOOP to mind -
- - -__Code Implementation:__ - -1. Using .forEach Method: - The .forEach method in javascript runs a provided function on each element within array - - ```js - function sentenceCap(text) { - let wordArray = text.toLowerCase().split(' ') - - let capsarray = [] - - wordArray.forEach(word => { - capsarray.push(word[0].toUpperCase()+ word.slice(1) ) - }); - - return capsarray.join(' ') - - } - console.log(sentenceCap("ARTIFICIAL")) - //will return Artificial - ``` - -- -* We call the .toLowerCase() method on the string of text received to convert the entire sentence to lowercase. We also chain the .split() method in sequence to divide the lowercase sentence into an array of words as shown below. This array is stored as wordsArray -
-- -* Next, using the .foreach() method, we iterate through every word(element) in the array and execute a function on it. -* The function takes the first letter of the word and turns it to uppercase using the .toUpperCase() method. To retrieve the remaining part of the word in lowercase, we use the .slice() method to slice the string starting from position 1 till the end. - -* We combine the transformed first letter and the sliced section together to form the capitalized word which we push into our array of capitalized words capsArray. - -* After this process has being carried out for every word, capsArray now holds the capitalized version of every word in the sentence - -* Finally .join() method is used. Then We pass in an empty space as the separator. This gives us the capitalized sentence which we return in conclusion. -
- - -2. Using .map and .slice method: - The .map method is used to create a new array with the results gotten from calling a provided function on every element in the array on which it is called. - - ```js - function capSentence(text) { - let wordsArray = text.toLowerCase().split(' ') - let capsArray = wordsArray.map(word=>{ - return word[0].toUpperCase() + word.slice(1) - }) - return capsArray.join(' ') - } - -3. Using .map() and .replace() method: - - ```js - function capSentence(text){ - let wordsArray =text.toLowerCase().split(' ') - let capsArray = wordsArray.map(word=>{ - return word.replce(word[0],word[0].toUpperCase()) - } ) - - return capsArray.joint(' ') - } - ``` - -Given a string of text, return true or false indicating whether or not the text is a palindrome. e.g
- -```js - palindromeChecker('racecar') // will return true -``` - -__Algorithmic Thinking:__ According to challenge,"Given a string of text" implies that our funciton must have string-typed parameter which we call "text"
-Next we will have to check if the string is paindrome or not. To do this we have to reverse the string and compare that rerverser string with the original one(i.e the one which is passed as argument)
-Finally , we return True or False depending on the result of evaluation.
-True: when it's palindrom
-False: Otherwise
In this challenge, we'd consider two, yet three ways to implement this as highlighted below: - - 1. An Intuitive Approach - 2. Looping Through and Comparing Characters - 3. Looping Through and Comparing Characters(Optimized) - - -
- -1. An Intuitive Approach: - ```js - - function palindromeCheck(text){ - var reverseText= text.toLowercase().split(' ').reverse().join(' ' ) - - return text=== reverseText - } - ``` -Let's unveil the "mysteries": - -* Firstly, the function accepts the string that is to be tested -* Next, all the letters are converted to lowercase,then .split() method is called on string that is received as text -* Next, we call .reverse() to re-order the array elements in reverse. - -* After that .join() is called on reversed array to form a whole string. -Convert a string of text into Pig Latin.
- - -__Algorithmic Thinking:__ - -We will consider two(2) ways to implement this function in JavaScript. They are: - -An imperative approach -A declarative approach -Before going ahead to implement both solutions, it’d be helpful to gain a better understanding of the two terms used above. - -Imperative vs Declarative -Very often, we find these terms thrown around like they are very simple concepts everyone should know. However, the difference is usually not much obvious to most. - -Simply put, an imperative style of programming is one which specifies how things get done. Although this might sound like what you do each time you write code, there's a difference to it. Imagine you were to add an array of numbers and return the sum, there are different ways you could approach the problem. One way could be writing a forloop that'd go over each element in the array and cumulatively add every element to an accumulator until the final sum is reached. That is imperative. You are specifying how things get done. - -On the other hand, a declarative approach would abstract this process, allowing you to specify what should be done rather than how. Thus, you may use the .reduce() method on the array to reduce every element to a final value by returning the sum within the call back. - -[Source](https://scotch.io/courses/the-ultimate-guide-to-javascript-algorithms/pig-latin) - -__code Implementation:__ - -1. Imperative Approach - -We start by converting the received string str to lowercase. This is to prevent any casing related errors during comparison(“a” does not equal “A”). - -```js - // Convert string to lowercase - str = str.toLowerCase() -``` - -Next, we initialize two variables: - -```js - // Initialize array of vowels - const vowels = ["a", "e", "i", "o", "u"]; - // Initialize vowel index to 0 - let vowelIndex = 0; -``` - -vowels - containing the five English vowels -vowelIndex - for storing the index at which the first vowel in the word is found. It is initialized to 0. - -We use an if…else statement to check if the first letter of the word can be found within our vowels array by calling the .includes() method on the array while passing it the first letter of the string str[0]. If it is found, this returns true, which implies that the first letter is a vowel. Hence, we simply add "``way``" to the end of the string and return the result as the Pig Latin equivalent. - - -```js - if (vowels.includes(str[0])) { - // If first letter is a vowel - return str + "way"; - } else { - ... - } -``` - -If the statement evaluates to false, it signifies that the starting character is a consonant. Hence, we use a for…of loop to iterate through the string to identify the position of the first vowel. When we locate the first vowel, we use the .indexOf() method to retrieve it’s position in the string and store it into the variable vowelIndex. After this step we terminate the loop using the break statement. - -```js - // If the first letter isn't a vowel i.e is a consonant - for (let char of str) { - // Loop through until the first vowel is found - if (vowels.includes(char)) { - // Store the index at which the first vowel exists - vowelIndex = str.indexOf(char); - break; - } - } -``` - -At the last line, we use the .slice() method to manipulate the string to generate the Pig Latin equivalent. - -```js - return str.slice(vowelIndex) + str.slice(0, vowelIndex) + "ay"; -``` - -2. Declarative Approach - -In this approach, we implement a very concise solution to this challenge by combining the .replace() method and regular expressions to transform the received string into its Pig Latin equivalent. - - -Our solution comprises mainly of two parts as analyzed below: - -```js - str.replace(/^([aeiouy])(._)/, '$1$2way') -``` - -The first .replace statement specifies a replacement to be carried out if the word begins with a vowel. This is specified in the first bracket within the_ *.replace()* method call i.e *([aeiou])*. The second bracket *(.*)* refers to every other character after the vowel. Thus, the expression specifies a pattern for words beginning with a vowel and followed by anything else. When this case is matched, a new string in the format of '``$1$2way``' is generated and used to replace the original srtring. $1 here refers to the first bracket and $2, the second bracket. This means that we simply take the word as it was and affix "``way``" to the end. - -```js - str.replace(/^(_[_^aeiouy]+)(._)/, '$2$1ay') -``` - -The second .replace statement specifies that if the word does not start with a vowel i.e ^([aeiouy]+), and is followed by anything else (``*.*)*, it should be replaced with a string formatted in the order '$2$1ay``'. The plus sign in ^([aeiouy]+) caters for a situation where there is a consonant cluster. Thus it represents every non-vowel character at the start of the word. '$2$1ay' generates the new string in the order of remaining characters + consonant cluster + '``ay``'. This gives the Pig Latin equivalent. - -```js -function pigLatin_declarative(str) { - return str - .replace(/^([aeiouy])(._)/, '$1$2way') - .replace(/^(_[_^aeiouy]+)(._)/, '$2$1ay') -} -``` - -Note that we chain both .replace() methods in succession such that both cases are tested and only the one that matches will be evaluated further. - -[Source](https://scotch.io/courses/the-ultimate-guide-to-javascript-algorithms/pig-latin) - - -- JS Objects, contrary to the way we perceive it, are simply pointers to the data stored, rather than the actual data itself. Thus, to compare objects/arrays a and b we cannot just use normal comparison operators.
-```js -a === b //false -``` -- Use of multidimensional objects/arrays is possible, making it difficult to compare simply by iteration since we don't know the depth of a value.
- -- Different data types like Dates and undefined must also be taken into consideration.
- -
Given the above, return a boolean signifying whether a and b are equivalent in content.
- -__Algorithmic Thinking:__As we would be comparing each item contained in the objects, a loop may be the first instinct to solving it. However, with the potential of multidimensional iterables, we would have to disect nested arrays in the same way when we encounter them. A combination of iteration and recursion is therefore necessary. So for each item of the array a data type check is necessary as well, to allow execution of a relevant comparison. - - Breaking it down: - * check if ```a === b``` - * check if ```a``` and ```b``` are both iterable - * iterate over ```a``` using keys and call deepCompare recursively -
- - -__code Implementation:__- -Firstly, we'll do the most simple check of ```a === b``` to avoid unnecessary complexity. This will process all of the equal literal values for us. - -```js -if(a === b) return true -``` - -Then comes the interesting part! There are several data types we need to look out for: Objects, Arrays(which JS treats as an object), and Dates(which is also treated as an object!), thus all we have to do is check if both a and b are of type object. If not, we can just return false as they didn't pass the ```a === b``` test. - -```js -if(typeof a === "object" && typeof b === "object")... -``` - -Note that we use ```===``` here to differentiate between data types strictly. - -Next, we can process the dates first, as that doesn't require iteration. Make sure to compare ```Date.valueOf()``` instead of the date object itself. - -```js -if(a instanceof Date && b instanceof Date) return a.valueOf() === b.valueOf() -``` - -Lastly, by taking the keys of the iterables we can compare the length of ```a``` and ```b```, then make use of built-in Array.some method to check if any values of the two iterables don't match. - -```js -//get keys/index of object/array a -const keysA = Object.keys(a) - -//make sure a and b are the same length -if(keysA.length !== Object.keys(b).length) return false - -//Array.some() iterates through the values in an array and stops executing nested code until there is one that returns true -//in this case that would be when there is one different value between a and b -return !keysA.some( key => { - //run deepCompare recursively - return !deepCompare(a[key], b[key]) -}) - ``` - - -Put it all together, and we have - -```js -const deepCompare = (a, b) => { - if(a === b) return true - - if(typeof a === "object" && typeof b === "object") - { - if(a instanceof Date && b instanceof Date) return a.valueOf() === b.valueOf() - else - { - const keysA = Object.keys(a) - if(keysA.length !== Object.keys(b).length) return false - return !keysA.some( key => { - return !deepCompare(a[key], b[key]) - }) - } - } - else return false -} - -deepCompare(1, 2) -//false - -deepCompare({"first": 1, "second": 2}, {"first": 1, "second": 2}) -//true - -deepCompare([1, "2", 3.0], [1, "2", 3]) -//false - -const arr = [1, 2, "3", [{4: "5", 6: 7}, 8.0, new Date(), undefined]] -deepCompare(arr, [1, 2, "3", [{4: "5", 6: 7}, 8.0, new Date(), undefined]]) -//true - - ``` - -It's that simple! Hope this helps. -
-- - -__Algorithmic Thinking:__
- - -__code Implementation:__
-
Convert a regular number to a Roman Numeral
- - -__Algorithmic Thinking:__You want to convert a number to a roman numeral... the trick to this problem is to kind of "split" the problem to individual digits. Instead of doing some weird convoluted solution, you should see that each digit would map to a string value and they only "add up". - -**Example** -- DXXXII = 532 - - Now, let's think about this example step by step. Let's take 500 out of 532. What is 500 in roman numeral? `500 = D`, right? We "append" that to our "string". now we evaluate 32... so 32 is essentially 30 + 2, so we take out 30 this time. `30 = XXX`, then append to "string". And finally, we have 2... you can't really "destructure" 2 any further so we have `2 = II`, and then append to string... - - now we have `"D" + "XXX" + "II" = 532`, YAY!!! -
- - -__code Implementation:__- -```javascript -// A regular number -const num = 3; - -// convert a number from 0 - 3000 to a roman numeral -function convertToRomanNumeral(number) { - // 0, 1, 2, 3, 4, ..., 9 - const ones = ['', 'I', 'II', 'III', 'IV', 'V', 'VI', 'VII', 'VIII', 'IX']; - // 0, 10, 20, 30, 40, ..., 90 - const tens = ['', 'X', 'XX', 'XXX', 'XL', 'L', 'LX', 'LXX', 'LXXX', 'XC']; - // 0, 100, 200, 300, 400, ..., 900 - const hundreds = ['', 'C', 'CC', 'CCC', 'CD', 'D', 'DC', 'DCC', 'DCCC', 'CM'] - // 0, 1000, 2000, 3000 - const thousands = ['', 'M', 'MM', 'MMM'] - - // get the value of digit in the thousandth postion (e.g. 3576 => 3) and accesses at index of the value of the digit (e.g. 3576 => thousands[3] = 'MMM') - const thousandthDigit = thousands[Math.floor(number / 1000)]; - - // get the value of digit in the hundredth postion (e.g. 3576 => 5) and accesses at index of the value of the digit (e.g. 3576 => hundreds[5] = 'D') - const hundredthDigit = hundreds[Math.floor((number % 1000) / 100)]; - - // get the value of digit in the tenth postion (e.g. 3576 => 7) and accesses at index of the value of the digit (e.g. 3576 => tens[7] = 'LXx') - const tenthDigit = tens[Math.floor((number % 100) / 10)]; - - // get the value of digit in the oneth postion (e.g. 3576 => 6) and accesses at index of the value of the digit (e.g. 3576 => ones[6] = 'VI') - const onethDigit = ones[Math.floor((number % 10) / 1)]; - - // combines the individual strings into one and returns... - return thousandthDigit + hundredthDigit + tenthDigit + onethDigit; -} - -console.log(convertToRomanNumeral(40)); - -/* - I = 1 - V = 5 - X = 10 - L = 50 - C = 100 - D = 500 - M = 1000 - - examples... - II = 2 - III = 3 - IV = 4 - VI = 6 - IX = 9 - - The algorithm or the plan -*/ -``` - -It's very simple ones you realize it. -
-Summing the digit from exponential results
- - -__Algorithmic Thinking:__Given a number along with the exponential number whose exponential number can be a positive or negative number. after getting the exponential result, sum the number of digits from the exponential result. - -Breaking it down: - * given number M and its exponential number N, so M x M ... x M, N times. - * iterate over the the result of exponentiation and sum all of the digit. - * dont forget if the exponent number is negative, it may be contain point (.) that need to be ignored. - -**Example** -- 215 = 32768 and the sum of its digits is 3 + 2 + 7 + 6 + 8 = 26 -- 2-3 = 0.125 and the sum of its digits is 0 + 1 + 2 + 5 = 8 -
- - -__code Implementation:__-```javascript -// #1.Using Iterative and type casting approach - -function powerDigitSum(num, pow){ - let sum = 0 - for (let digit of Math.pow(num, pow).toString()){ - if (digit === '.'){ //checking for point (if exponential is negative) - continue; - } - sum += digit*1 - } - return sum -} - -console.log(powerDigitSum(2, 16)) // 65536 -> 6+5+5+3+6=25 -console.log(powerDigitSum(2, -5)) // 0.03125 -> 0+0+3+1+2+5=11 - -``` -
-- - -__Algorithmic Thinking:__
- - -__code Implementation:__
-
Given a string and a shift key, encrypt the string through Caesar Cipher.
+======= +10. Power Digit Sum + +__The challenge:__Summing the digit from exponential results
+>>>>>>> b1aab17... added 10. Power Digit Sum __Algorithmic Thinking:__This is a very simple algorithm that requires only a tiny bit of prerequisite knowledge regarding ASCII, and also some discretion when processing possible over 26 keys. Basically we just need to know that all chracters are stored as numbers in computer memory according to the ASCII standard: https://www.w3schools.com/charsets/ref_html_ascii.asp. And that the modulus function is our friend :)
+<<<<<<< HEAD __code Implementation:__@@ -993,6 +1000,41 @@ const key = 3 __code Implementation:__
+======= +__Algorithmic Thinking:__
Given a number along with the exponential number whose exponential number can be a positive or negative number. after getting the exponential result, sum the number of digits from the exponential result. + +Breaking it down: + * given number M and its exponential number N, so M x M ... x M, N times. + * iterate over the the result of exponentiation and sum all of the digit. + * dont forget if the exponent number is negative, it may be contain point (.) that need to be ignored. + +**Example** +- 215 = 32768 and the sum of its digits is 3 + 2 + 7 + 6 + 8 = 26 +- 2-3 = 0.125 and the sum of its digits is 0 + 1 + 2 + 5 = 8 +
+ + +__code Implementation:__+```javascript +// #1.Using Iterative and type casting approach + +function powerDigitSum(num, pow){ + let sum = 0 + for (let digit of Math.pow(num, pow).toString()){ + if (digit === '.'){ //checking for point (if exponential is negative) + continue; + } + sum += digit*1 + } + return sum +} + +console.log(powerDigitSum(2, 16)) // 65536 -> 6+5+5+3+6=25 +console.log(powerDigitSum(2, -5)) // 0.03125 -> 0+0+3+1+2+5=11 + +``` +
+>>>>>>> b1aab17... added 10. Power Digit Sum+
Given a number along with the exponential number whose exponential number can be a positive or negative number. after getting the exponential result, sum the number of digits from the exponential result. +11. Name + +__The challenge:__
+ +__Algorithmic Thinking:__
+ + +__code Implementation:__
+
Summing the digit from exponential results
+ +__Algorithmic Thinking:__This is a very simple algorithm that requires only a tiny bit of prerequisite knowledge regarding ASCII, and also some discretion when processing possible over 26 keys. Basically we just need to know that all chracters are stored as numbers in computer memory according to the ASCII standard: https://www.w3schools.com/charsets/ref_html_ascii.asp. And that the modulus function is our friend :)
+ +__Algorithmic Thinking:__Given a number along with the exponential number whose exponential number can be a positive or negative number. after getting the exponential result, sum the number of digits from the exponential result. + Breaking it down: * given number M and its exponential number N, so M x M ... x M, N times. - * iterate over the the result of exponentiation and sum all of the digit. - * dont forget if the exponent number is negative, it may be contain point (.) that need to be ignored. - + * iterate over the the result of exponentiation digit result. + * if the result contain fraction, ignore/skip the point (.) using "continue" keyword. + * accumulate (sum) in "sum" variabel + * return the result + **Example** - 215 = 32768 and the sum of its digits is 3 + 2 + 7 + 6 + 8 = 26 - 2-3 = 0.125 and the sum of its digits is 0 + 1 + 2 + 5 = 8
- - + + __code Implementation:__```javascript // #1.Using Iterative and type casting approach - + +// Step 1: given number M and its exponential number N, so M x M ... x M, N times. function powerDigitSum(num, pow){ let sum = 0 + + // Step 2: iterate over the the result of exponentiation digit result. for (let digit of Math.pow(num, pow).toString()){ + + // Step 3: if the result contain fraction, ignore/skip the point (.) using "continue" keyword. if (digit === '.'){ //checking for point (if exponential is negative) continue; } - sum += digit*1 + + // Step 4: accumulate (sum) in "sum" variabel + sum += digit*1 // times 1 is for converting string to number } + + // Step 5: return the result return sum } - + console.log(powerDigitSum(2, 16)) // 65536 -> 6+5+5+3+6=25 console.log(powerDigitSum(2, -5)) // 0.03125 -> 0+0+3+1+2+5=11 - + ``` -
->>>>>>> b1aab17... added 10. Power Digit Sum -- - -__Algorithmic Thinking:__
- - -__code Implementation:__
-
Given a string and a shift key, encrypt the string through Caesar Cipher.
-======= -10. Power Digit Sum - -__The challenge:__Summing the digit from exponential results
->>>>>>> b1aab17... added 10. Power Digit Sum __Algorithmic Thinking:__This is a very simple algorithm that requires only a tiny bit of prerequisite knowledge regarding ASCII, and also some discretion when processing possible over 26 keys. Basically we just need to know that all chracters are stored as numbers in computer memory according to the ASCII standard: https://www.w3schools.com/charsets/ref_html_ascii.asp. And that the modulus function is our friend :)
From 99e9f5e2f30acf8973c1234ba81ebf52e824508e Mon Sep 17 00:00:00 2001 From: ranggaadiGiven a string and a shift key, encrypt the string throug __Algorithmic Thinking:__
This is a very simple algorithm that requires only a tiny bit of prerequisite knowledge regarding ASCII, and also some discretion when processing possible over 26 keys. Basically we just need to know that all chracters are stored as numbers in computer memory according to the ASCII standard: https://www.w3schools.com/charsets/ref_html_ascii.asp. And that the modulus function is our friend :)
-<<<<<<< HEAD - __code Implementation:__
So first of all we need to split the string into characters to be processed individually and convert it to ASCII codes. Then we must check whether the character is either uppercase or lowercase(everything else should be kept the same) then add the key to it accordingly. But it is not a simple matter of simply doing ```char + key``` because for example, by shifting X by 3 we should get A. However, X(88) + 3 equals to 91 which is "\[". Thus what we should be doing is:
From 94da7c0a36c42587d3e0aebd2cb0a8808ab4e711 Mon Sep 17 00:00:00 2001
From: ranggaadi
From a2f92d5b3556cc0858c6c0f0c5796500dd1384cc Mon Sep 17 00:00:00 2001
From: ranggaadi
12. Power Digit Sum __The challenge:__
Summing the digit from exponential results
- -__Algorithmic Thinking:__This is a very simple algorithm that requires only a tiny bit of prerequisite knowledge regarding ASCII, and also some discretion when processing possible over 26 keys. Basically we just need to know that all chracters are stored as numbers in computer memory according to the ASCII standard: https://www.w3schools.com/charsets/ref_html_ascii.asp. And that the modulus function is our friend :)
- + __Algorithmic Thinking:__Given a number along with the exponential number whose exponential number can be a positive or negative number. after getting the exponential result, sum the number of digits from the exponential result. Breaking it down: