#54 Word a10n (abbreviation)



The word i18n is a common abbreviation of internationalization in the developer community, used instead of typing the whole word and trying to spell it correctly. Similarly, a11y is an abbreviation of accessibility.


Write a function that takes a string and turns any and all "words" (see below) within that string of length 4 or greater into an abbreviation, following these rules:


A "word" is a sequence of alphabetical characters. By this definition, any other character like a space or hyphen (eg. "elephant-ride") will split up a series of letters into two words (eg. "elephant" and "ride").

The abbreviated version of the word should have the first letter, then the number of removed characters, then the last letter (eg. "elephant ride" => "e6t r2e").


Example

abbreviate("elephant-rides are really fun!")

//          ^^^^^^^^*^^^^^*^^^*^^^^^^*^^^*

// words (^):   "elephant" "rides" "are" "really" "fun"

//                123456     123     1     1234     1

// ignore short words:               X              X


// abbreviate:    "e6t"     "r3s"  "are"  "r4y"   "fun"

// all non-word characters (*) remain in place

//                     "-"      " "    " "     " "     "!"

=== "e6t-r3s are r4y fun!"



#53 FIXME: Hello


The code provided has a method hello which is supposed to show only those attributes which have been explicitly set. Furthermore, it is supposed to say them in the same order they were set.


But it's not working properly.


Notes

There are 3 attributes


name

age

sex ('M' or 'F')

When the same attribute is assigned multiple times the hello method shows it only once. If this happens the order depends on the first assignment of that attribute, but the value is from the last assignment.


Examples

Hello.

Hello. My name is Bob. I am 27. I am male.

Hello. I am 27. I am male. My name is Bob.

Hello. My name is Alice. I am female.

Hello. My name is Batman.




#52 Are they the "same"?


Given two arrays a and b write a function comp(a, b) (compSame(a, b) in Clojure) that checks whether the two arrays have the "same" elements, with the same multiplicities. "Same" means, here, that the elements in b are the elements in a squared, regardless of the order.


Examples

Valid arrays

a = [121, 144, 19, 161, 19, 144, 19, 11]  

b = [121, 14641, 20736, 361, 25921, 361, 20736, 361]

comp(a, b) returns true because in b 121 is the square of 11, 14641 is the square of 121, 20736 the square of 144, 361 the square of 19, 25921 the square of 161, and so on. It gets obvious if we write b's elements in terms of squares:


a = [121, 144, 19, 161, 19, 144, 19, 11] 

b = [11*11, 121*121, 144*144, 19*19, 161*161, 19*19, 144*144, 19*19]

Invalid arrays

If we change the first number to something else, comp may not return true anymore:


a = [121, 144, 19, 161, 19, 144, 19, 11]  

b = [132, 14641, 20736, 361, 25921, 361, 20736, 361]

comp(a,b) returns false because in b 132 is not the square of any number of a.


a = [121, 144, 19, 161, 19, 144, 19, 11]  

b = [121, 14641, 20736, 36100, 25921, 361, 20736, 361]

comp(a,b) returns false because in b 36100 is not the square of any number of a.



#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



#50 String -> N iterations -> String



Welcome

This kata is inspired by This Kata


We have a string s


We have a number n


Here is a function that takes your string, concatenates the even-indexed chars to the front, odd-indexed chars to the back.


Examples

s = "Wow Example!"

result = "WwEapeo xml!"

s = "I'm JomoPipi"

result = "ImJm ii' ooPp"

The Task:

return the result of the string after applying the function to it n times.


example where s = "qwertyuio" and n = 2:


after 1 iteration  s = "qetuowryi"

after 2 iterations s = "qtorieuwy"

return "qtorieuwy"

Note

There are 50000 random tests where


the string contains between 50 and 200 chars

n is greater than a billion

so be ready to optimize.


#49 Playing with digits


Some numbers have funny properties. For example:


89 --> 8¹ + 9² = 89 * 1


695 --> 6² + 9³ + 5⁴= 1390 = 695 * 2


46288 --> 4³ + 6⁴+ 2⁵ + 8⁶ + 8⁷ = 2360688 = 46288 * 51


Given a positive integer n written as abcd... (a, b, c, d... being digits) and a positive integer p we want to find a positive integer k, if it exists, such as the sum of the digits of n taken to the successive powers of p is equal to k * n. In other words:


Is there an integer k such as : (a ^ p + b ^ (p+1) + c ^(p+2) + d ^ (p+3) + ...) = n * k


If it is the case we will return k, if not return -1.


Note: n, p will always be given as strictly positive integers.


digPow(89, 1) should return 1 since 8¹ + 9² = 89 = 89 * 1

digPow(92, 1) should return -1 since there is no k such as 9¹ + 2² equals 92 * k

digPow(695, 2) should return 2 since 6² + 9³ + 5⁴= 1390 = 695 * 2

digPow(46288, 3) should return 51 since 4³ + 6⁴+ 2⁵ + 8⁶ + 8⁷ = 2360688 = 46288 * 51



#48 A Rule of Divisibility by 13


When you divide the successive powers of 10 by 13 you get the following remainders of the integer divisions:


1, 10, 9, 12, 3, 4.


Then the whole pattern repeats.


Hence the following method: Multiply the right most digit of the number with the left most number in the sequence shown above, the second right most digit to the second left most digit of the number in the sequence. The cycle goes on and you sum all these products. Repeat this process until the sequence of sums is stationary.


...........................................................................


Example: What is the remainder when 1234567 is divided by 13?


7×1 + 6×10 + 5×9 + 4×12 + 3×3 + 2×4 + 1×1 = 178


We repeat the process with 178:


8x1 + 7x10 + 1x9 = 87


and again with 87:


7x1 + 8x10 = 87


...........................................................................


From now on the sequence is stationary and the remainder of 1234567 by 13 is the same as the remainder of 87 by 13: 9


Call thirt the function which processes this sequence of operations on an integer n (>=0). thirt will return the stationary number.


thirt(1234567) calculates 178, then 87, then 87 and returns 87.


thirt(321) calculates 48, 48 and returns 48




#47 String repeat 


Write a function called repeatStr which repeats the given string string exactly n times.


repeatStr(6, "I") // "IIIIII"

repeatStr(5, "Hello") // "HelloHelloHelloHelloHello"



#46 Your order, please



Your task is to sort a given string. Each word in the String will contain a single number. This number is the position the word should have in the result.


Note: Numbers can be from 1 to 9. So 1 will be the first word (not 0).


If the input String is empty, return an empty String. The words in the input String will only contain valid consecutive numbers.


For an input: "is2 Thi1s T4est 3a" the function should return "Thi1s is2 3a T4est"


your_order("is2 Thi1s T4est 3a")


[1] "Thi1s is2 3a T4est"



 #45 Sort - one, three, two

Hey You !

Sort these integers for me ...


By name ...


Do it now !


Input

Range is 0-999


There may be duplicates


The array may be empty


+ Recent posts