Competetive Programming Practice on CodeWars

One of the best place to practice your coding skill

Codewars is a platform that helps you learn, train, and improve your coding skills by solving programming tasks of many types and difficulty levels. You choose how you would like to learn. Do you want to take on increasingly difficult challenges? Maybe you prefer training through repetition and by improving your solutions. After solving a task, compare your answer with other users and learn from them, or help less experienced users by answering their questions.

Codewars getting popular for their beginner-friendly environment and expert competitors. As a beginner journey of programming world, this would be the nicest place to improve my programming skills and push it further to the next level.

Here’s some problems that i’ve solved along the way……..

Mumbling

This time no story, no theory. The examples below show you how to write function accum:

Examples:

1
2
3
accum("abcd") -> "A-Bb-Ccc-Dddd"
accum("RqaEzty") -> "R-Qq-Aaa-Eeee-Zzzzz-Tttttt-Yyyyyyy"
accum("cwAt") -> "C-Ww-Aaa-Tttt"

The parameter of accum is a string which includes only letters from a..z and A..Z.

Descending Order

Your task is to make a function that can take any non-negative integer as an argument and return it with its digits in descending order. Essentially, rearrange the digits to create the highest possible number.

Examples:

input: 42145 Output: 54421

Input: 145263 Output: 654321

Input: 123456789 Output: 987654321

Create Phone Number

Write a function that accepts an array of 10 integers (between 0 and 9), that returns a string of those numbers in the form of a phone number.

Examples: create_phone_number([1, 2, 3, 4, 5, 6, 7, 8, 9, 0]) # => returns "(123) 456-7890"

The returned format must be correct in order to complete this challenge. Don’t forget the space after the closing parentheses!

Isograms

An isogram is a word that has no repeating letters, consecutive or non-consecutive. Implement a function that determines whether a string that contains only letters is an isogram. Assume the empty string is an isogram. Ignore letter case.

Examples:

1
2
3
"Dermatoglyphics" --> true
"aba" --> false
"moOse" --> false (ignore letter casing)
You're a square!

You like building blocks. You especially like building blocks that are squares. And what you even like more, is to arrange them into a square of square building blocks!

However, sometimes, you can’t arrange them into a square. Instead, you end up with an ordinary rectangle! Those blasted things! If you just had a way to know, whether you’re currently working in vain… Wait! That’s it! You just have to check if your number of building blocks is a perfect square.

Given an integral number, determine if it’s a square number:

In mathematics, a square number or perfect square is an integer that is the square of an integer; in other words, it is the product of some integer with itself.

The tests will always use some integral number, so don’t worry about that in dynamic typed languages.

Examples:

1
2
3
4
5
6
-1  =>  false
 0  =>  true
 3  =>  false
 4  =>  true
25  =>  true
26  =>  false
Replace With Alphabet Position

In this kata you are required to, given a string, replace every letter with its position in the alphabet.

If anything in the text isn’t a letter, ignore it and don’t return it.

"a" = 1, "b" = 2, etc.

Examples:

alphabet_position("The sunset sets at twelve o' clock.")

Should return "20 8 5 19 21 14 19 5 20 19 5 20 19 1 20 20 23 5 12 22 5 15 3 12 15 3 11" (as a string)

Jaden Casing Strings

Jaden Smith, the son of Will Smith, is the star of films such as The Karate Kid (2010) and After Earth (2013). Jaden is also known for some of his philosophy that he delivers via Twitter. When writing on Twitter, he is known for almost always capitalizing every word. For simplicity, you’ll have to capitalize each word, check out how contractions are expected to be in the example below.

Your task is to convert strings to how they would be written by Jaden Smith. The strings are actual quotes from Jaden Smith, but they are not capitalized in the same way he originally typed them.

Examples:

1
2
Not Jaden-Cased: "How can mirrors be real if our eyes aren't real"
Jaden-Cased:     "How Can Mirrors Be Real If Our Eyes Aren't Real"

Link to Jaden’s former Twitter account @officialjaden via archive.org

Sum of positive

You get an array of numbers, return the sum of all of the positives ones.

Examples [1,-4,7,12] => 1 + 7 + 12 = 20

Note: if there is nothing to sum, the sum is default to 0.

Shortest Word

Simple, given a string of words, return the length of the shortest word(s).

String will never be empty and you do not need to account for different data types.

List Filtering

In this kata you will create a function that takes a list of non-negative integers and strings and returns a new list with the strings filtered out.

Examples:

1
2
3
filter_list([1,2,'a','b']) == [1,2]
filter_list([1,'a','b',0,15]) == [1,0,15]
filter_list([1,2,'aasf','1','123',123]) == [1,2,123]
Answer: Mumbling
1
2
3
4
5
6
def accum(s):
    result = []
    for i in range(len(s)):
        f = (i+1)*s[i]
        result.append(f.capitalize())
    return '-'.join(result)
Answer: Descending Order
1
2
def descending_order(num):
    return int(''.join(reversed(sorted(list(str(num))))))

Answer: Create Phone Number
1
2
3
def create_phone_number(o):
    n = list(map(str,o))
    return f"({''.join(n[:3])}) {''.join(n[3:6])}-{''.join(n[6:])}"
Answer: Isograms
1
2
def is_isogram(string):
    return True if len(list(string.lower()))==len(set(list(string.lower()))) else False
Answer: You're a square!
1
2
def is_square(n):    
    return (n**0.5).is_integer() if n>-1 else False
Answer: Replace With Alphabet Position
1
2
3
4
5
import string, re
def alphabet_position(text):
    newString = ''.join(re.findall("[a-z]+",text.lower()))
    result = [str(string.ascii_lowercase.index(i)+1) for  i in newString]
    return ' '.join(result)
Answer: Jaden Casing Strings
1
2
def to_jaden_case(string):
    return ' '.join([i.capitalize() for i in string.split()])
Answer: Sum of positive
1
2
def positive_sum(arr)->int:
    return sum([i for i in arr if i>0])
Answer: Shortest Word
1
2
def find_short(s:str)->int:
    return sorted([len(i) for i in s.split()])[0]

Answer: List Filtering
1
2
def filter_list(l):
    return [i for i in l if type(i)==int]

Here’s the youtube video of this post