Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /* Numerology involves a lot of repeated calculations, but as a programmer you can automate this process and
- earn some easy cash! You will be given the birthdate and username of a random fellow student.
- Your task is to calculate a celestial number. Below is a description of the process, see the example
- to understand your task better. First, multiply together the numbers representing the day, year and month
- of the birthdate. Numerologists love odd numbers, so if the month is an odd number, you should square the result
- of the multiplication. Next, add to the result each digit ('0' = 0, '1' = 1… '9' = 9) or the position in
- the English alphabet of each letter in the username – e.g. “a” = 1, “b” = 2… “z” = 26.
- Capital letters weigh twice as much - the letter “A” will add 1*2 to the sum, “Z” will add 2*26, etc.
- 13 is a sacral number and your celestial number should be between 0 and 13 inclusive.
- So, if the resulting number is greater than 13 you should keep adding its digits together until you get
- the coveted celestial number in its final form. Then all you have to do is print it to the console!
- On the only input line you will be given a date in the format [day.month.year] and a username,
- separated by a single space. On the only output line you must print the calculated celestial number. */
- "use strict";
- function solve(args) {
- args = args[0].split(/\W+/).filter(Boolean);
- var username = args.pop();
- var result = 1;
- var i;
- for (i = 0; i < args.length; i += 1) {
- result *= parseInt(args[i]);
- }
- if ((parseInt(args[1]) % 2) != 0) {
- result *= result;
- }
- for (i = 0; i < username.length; i += 1) {
- var symbol = username[i];
- if (isFinite(symbol)) {
- result += parseInt(symbol);
- } else {
- var weighCoeffic = 1;
- if (symbol != symbol.toLowerCase()) {
- weighCoeffic = 2;
- }
- symbol = symbol.toLowerCase();
- result += weighCoeffic * (symbol.charCodeAt(0) - 96);
- }
- }
- while (result > 13) {
- var digitsStr = result.toString(10);
- result = 0;
- for (i = 0; i < digitsStr.length; i += 1) {
- result += parseInt(digitsStr[i]);
- }
- }
- console.log(result);
- }
- solve(['14.03.1990 Panayot']);
- solve(['01.01.1914 g0g0']);
- solve(['25.05.1997 P360']);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement