#69  Weight for weight


My friend John and I are members of the "Fat to Fit Club (FFC)". John is worried because each month a list with the weights of members is published and each month he is the last on the list which means he is the heaviest.


I am the one who establishes the list so I told him: "Don't worry any more, I will modify the order of the list". It was decided to attribute a "weight" to numbers. The weight of a number will be from now on the sum of its digits.


For example 99 will have "weight" 18, 100 will have "weight" 1 so in the list 100 will come before 99. Given a string with the weights of FFC members in normal order can you give this string ordered by "weights" of these numbers?


Example:

"56 65 74 100 99 68 86 180 90" ordered by numbers weights becomes: "100 180 90 56 65 74 68 86 99"


When two numbers have the same "weight", let us class them as if they were strings and not numbers: 100 is before 180 because its "weight" (1) is less than the one of 180 (9) and 180 is before 90 since, having the same "weight" (9) it comes before as a string.


All numbers in the list are positive numbers and the list can be empty.




#62 Simple Pig Latin


 to the end of it, then add "ay" to the end of the word. Leave punctuation marks untouched.


Examples

pigIt('Pig latin is cool'); // igPay atinlay siay oolcay

pigIt('Hello world !');     // elloHay orldWay !



#55 Sum of Two Integers



Task

Given Two intgers a , b , find The sum of them , BUT You are not allowed to use the operators + and -


Notes

The numbers (a,b) may be positive , negative values or zeros .


Returning value will be integer .


Javascript: the Array reduce methods are disabled, along with eval, require, and module .


Java: the following methods are prohibited: addExact, average, collect, decrement, increment, nextAfter, nextDown, nextUp, reduce, subtractExact, sum, summing . The following classes are prohibited: BigDecimal and BigInteger .


NASM: the following instructions are prohibited: add, adc, adcx, adox, dec, inc, sbb, sub .


Input >> Output Examples

1- Add (5,19) ==> return (24) 


2- Add (-27,18) ==> return (-9)


3- Add (-14,-16) ==> return (-30)



#51 Simple string indices


n this Kata, you will be given a string with brackets and an index of an opening bracket and your task will be to return the index of the matching closing bracket. Both the input and returned index are 0-based except in Fortran where it is 1-based. An opening brace will always have a closing brace. Return -1 if there is no answer (Haskell return Nothing, Fortran: return 0)


For example


solve("((1)23(45))(aB)", 0) = 10 // the opening brace at index 0 matches the closing brace at index 10

solve("((1)23(45))(aB)", 1) = 3 

solve("((1)23(45))(aB)", 2) = -1 // there is no opening bracket at index 2, so return -1

solve("((1)23(45))(aB)", 6) = 9

solve("((1)23(45))(aB)", 11) = 14

solve("((>)|?(*'))(yZ)", 11) = 14



+ Recent posts