If you can read this…

From codewars.com by Edxael  (that’s me)

Description:

The idea for this Kata came from 9gag today.here

You’ll have to translate a string to Pilot’s alphabet (NATO phonetic alphabet) wiki.

Like this:

Input: If you can read

Output: Indian Foxtrot Yankee Oscar Uniform Charlie Alfa November Romeo Echo Alfa Delta

Some notes

  • Keep the punctuation, and remove the spaces.
  • Use Xray without dash or space.

Reference

alt text

: – – My Code – – :

Note:  The following code is not written by me, it was created by another user of codewars.com it belongs to the user: phaul

Note:  The following code is not written by me, it was created by another user of codewars.com it belongs to the user: matmaxanh

x

Category: Ruby Examples | Comments Off on If you can read this…

Prime Factors

From codewars.com by Edxael  (that’s me)

Description:

Inspired by one of Uncle Bob’s TDD Kata

Write a function that generates factors for a given number.

  • The function takes an integer on the standard input and returns a list of integers. That list contains the prime factors in numerical sequence.

Example

  • 1 -> []
  • 3 -> [3]
  • 8 -> [2, 2, 2]
  • 9 -> [3, 3]
  • 12 -> [2, 2, 3]

: – – My Code – – :

Note:  The following code is not written by me, it was created by another user of codewars.com it belongs to the user: njohnson7

 

x

Category: Ruby Examples | Comments Off on Prime Factors

Alien Accent

From codewars.com by Edxael  (that’s me)

Description:

The Story:

Aliens from Kepler 27b have immigrated to Earth! They have learned English and go to our stores, eat our food, dress like us, ride Ubers, use Google, etc. However, they speak English a little differently. Can you write a program that converts their Alien English to our English?

Task:

Write a function converting their speech to ours. They tend to speak the letter a like o and o like a u.

 

— My Code —

Note:  The following code is not written by me, it was created by another user of codewars.com it belongs to the user: phaul

 

x

Category: Ruby Examples | Comments Off on Alien Accent

Make a square box!

From codewars.com by Edxael  (that’s me)

Description:

Easy; Make a box

Given a number as a parameter, return an array containing strings which form a box.Like this:

n = 5

n = 3

— My Code —

Note:  The following code is not written by me, it was created by another user of codewars.com it belongs to the user: njohnson7


 

ALGORITHMS
Category: Ruby Examples | Comments Off on Make a square box!

Don’t give me five!

From codewars.com by Edxael  (that’s me)

In this kata you get the start number and the end number of a region and should return the count of all numbers except numbers with a 5 in it. The start and the end number are both inclusive!

Examples:

The result may contain fives. 😉
The start number will always be smaller than the end number. Both numbers can be also negative!

I’m very curious for your solutions and the way you solve it. Maybe someone of you will find an easy pure mathematics solution.

Have fun coding it and please don’t forget to vote and rank this kata! 🙂

I have also created other katas. Take a look if you enjoyed this kata!

— My Solution —

Note:  The following code is not written by me, it was created by another user of codewars.com it belongs to the user: narayanswa30663

 

x

Category: Ruby Examples | Comments Off on Don’t give me five!

Series of integers from m to n

From codewars.com by Edxael  (that’s me)

Description:

Write a function generateIntegers/generate_integers that accepts two arguments m/$m and n/$n and generates an array containing the integers from m to n inclusive.

For example, generateIntegers(2, 5)/generate_integers(2, 5) should return [2, 3, 4, 5].

m/$m and n/$n can be any integers greater than or equal to 0.

n/$n will always be greater than or equal to m/$m.

— My Solution —

Note:  The following code is not written by me, it was created by another user of codewars.com it belongs to the user: Carib

x

Category: Ruby Examples | Comments Off on Series of integers from m to n

Compare an array of hashes against each other, both ways

From Stackoverflow by Edmundo  (that’s me)

The question:

I need to find the differences between saved_start and incoming_start, but also between incoming_start and saved_start. saved_start is the result of a db query while incoming_start is a result of params from a webhook. Here are the two arrays to start with:

 

I find the differences…………. for the complete question click this link

My Solution

Hello I hope the following code might help. this code will: (01)-Point values in Array 1 NOT found in array 2 … (02)-Point values in Array 2 Not found in Array 1 … (03)-Store all Unique Values in Array 2 …. For the description of the question I think this is what you are looking for, to make thing easier I rename the arrays to: arr1 & arr2.

 

I Hope this helps. 😉

Category: Ruby Examples | Comments Off on Compare an array of hashes against each other, both ways

Valid Braces

From codewars.com by Edxael  (that’s me)

Description:

Write a function called validBraces that takes a string of braces, and determines if the order of the braces is valid. validBraces should return true if the string is valid, and false if it’s invalid.

This Kata is similar to the Valid Parentheses Kata, but introduces four new characters. Open and closed brackets, and open and closed curly braces. Thanks to @arnedag for the idea!

All input strings will be nonempty, and will only consist of open parentheses ‘(‘ , closed parentheses ‘)’, open brackets ‘[‘, closed brackets ‘]’, open curly braces ‘{‘ and closed curly braces ‘}’.

What is considered Valid? A string of braces is considered valid if all braces are matched with the correct brace.
For example:
‘(){}[]’ and ‘([{}])’ would be considered valid, while ‘(}’, ‘[(])’, and ‘[({})](]’ would be considered invalid.

Examples:
validBraces( "(){}[]" ) => returns true
validBraces( "(}" ) => returns false
validBraces( "[(])" ) => returns false
validBraces( "([{}])" ) => returns true

MyCode:

Note:  The following code is not written by me, it was created by another user of codewars.com it belongs to the user: gurudas

 

z

Category: Ruby Examples | Comments Off on Valid Braces

Break camelCase

From codewars.com by Edxael  (that’s me)

Description:

Complete the solution so that the function will break up camel casing, using a space between words.

Example

My Code:

 

Note:  The following code is not written by me, it was created by another user of codewars.com it belongs to the user: genebot

 

Category: Ruby Examples | Comments Off on Break camelCase

Help Kiyo きよ solve her problems LCM Fun!

From codewars.com by Edxael  (that’s me)

Description:

Help Kiyo きよ solve her problems LCM Fun!

Kiyo has been given a series of problems and she needs your help to solve them!

You will be given a two-dimensional array such as the one below.

Integers are between 0 and 9. Sub-array size is always 9. The number of sub-arrays varies between 9 and 18.

Watch out for non-integers mixed in the arrays. If all arrays are empty return 0.

My solution:

Note:  The following code is not written by me, it was created by another user of codewars.com it belongs to the user: Kazk

Note:  The following code is not written by me, it was created by another user of codewars.com it belongs to the user: njohnson7

.

Category: Ruby Examples | Comments Off on Help Kiyo きよ solve her problems LCM Fun!

The Hashtag Generator

From codewars.com by Edxael  (that’s me)

Description:

The marketing team are spending way too much time typing in hashtags.
Let’s help them with out own Hashtag Generator!

Here’s the deal:

  • If the final result is longer than 140 chars it must return false.
  • If the input is a empty string it must return false.
  • It must start with a hashtag (#).
  • All words must have their first letter capitalized.

Example Input to Output:

” Hello there thanks for trying my Kata” => “#HelloThereThanksForTryingMyKata”

” Hello World ” => “#HelloWorld”

My code:

Note:  The following code is not written by me, it was created by another user of codewars.com it belongs to the user: “rsalgado”

 

xc

Category: Ruby Examples | Comments Off on The Hashtag Generator

“EULER ” & “RB Calisthenics” (2)

This post is Practice for the previous post “Project EULER”

The problems are just practice of the problems that I did in a previous post, this are not the same answers, in some cases the answers will be very similar, in other cases will be a totally different, Im just doing as a practice and to compare how do I face the same problems after some time studding.


EULER

Multiples of 3 and 5

Even Fibonacci numbers

Largest prime factor

Largest palindrome product


CALISTHENICS

The original post is: “Ruby Calisthenics”

1.Power

2. Factorial

3. Uniques

4. Combinations

5. Primes

6. Rectangle Overlap

The Counting Game

 

 

zz

Category: Ruby Examples | Comments Off on “EULER ” & “RB Calisthenics” (2)

Cat and Mouse – Easy Version

From codewars.com by Edxael  (that’s me)

Description:

You will be given a string (x) featuring a cat ‘C’ and a mouse ‘m’. The rest of the string will be made up of ‘.’.

You need to find out if the cat can catch the mouse from it’s current position. The cat can jump three characters. So:

C…..m returns ‘Escaped!’ <– more than three characters between

C…m returns ‘Caught!’ <– as there are three characters between the two, the cat can jump.

Note:  The following code is not written by me, it was created by another user of codewars.com it belongs to the user: “carlyminjoy

 

 

Category: Ruby Examples | Comments Off on Cat and Mouse – Easy Version

Scramblies

From codewars.com by Edxael  (that’s me)

Write function scramble(str1,str2) that returns true if a portion of str1 characters can be rearranged to match str2, otherwise returns false.

For example:
str1 is 'rkqodlw' and str2 is 'world' the output should return true.
str1 is 'cedewaraaossoqqyt' and str2 is 'codewars' should return true.
str1 is ‘katas‘ and str2 is ‘steak‘ should return false.

Only lower case letters will be used (a-z). No punctuation or digits will be included.
Performance needs to be considered

Here is my Code:

Note:  The following code is not written by me, it was created by another user of codewars.com it belongs to the user: “Trobule

 

 

 

 

 

 

 

Category: Ruby Examples | Comments Off on Scramblies

Viking: Euler & Calisthenics

In the Viking Prep-Work there are two post that I would like to add to this examples series, this were my first real exposure to “Ruby” and the code might be and seem basic, but is the fundamentals that I want to share on this post.

Project Euler

 

 

Ruby Calisthenics

 

Here they are.

Category: Ruby Examples | Comments Off on Viking: Euler & Calisthenics

All Star Code Challenge #1

From codewars.com by Edxael  (that’s me)

this is a super easy.

This Kata is intended as a small challenge for my students

All Star Code Challenge #1

Write a function, called sumPPG, that takes two NBA player objects and sums their PPG

Examples:

My answer:

Note:  The following code is not written by me, it was created by another user of codewars.com it belongs to the user: “nekokat”.

 

Category: Ruby Examples | Comments Off on All Star Code Challenge #1

Frequency sequence

From codewars.com by Edxael  (that’s me)

Description:

Return an output string that translates an input string s/$s by replacing each character in s/$s with a number representing the number of times that character occurs in s/$s and separating each number with the character(s) sep/$sep.     The following is an example of how the method should work

My solution.

Note:  The following code is not written by me, it was created by another user of codewars.com it belongs to the user: “glonnon”.

Note:  The following code is not written by me, it was created by another user of codewars.com it belongs to the user: “nenoch”.

 

 

 

Category: Ruby Examples | Comments Off on Frequency sequence

Rot13

From codewars.com by Edxael  (that’s me)

ROT13 is a simple letter substitution cipher that replaces a letter with the letter 13 letters after it in the alphabet. ROT13 is an example of the Caesar cipher.

Create a function that takes a string and returns the string ciphered with Rot13. If there are numbers or special characters included in the string, they should be returned as they are. Only letters from the latin/english alphabet should be shifted, like in the original Rot13 “implementation”.

Please note that using “encode” in Python is considered cheating.

Example Test

My Solution

Note:  The following code is not written by me, it was created by another user of codewars.com it belongs to the user: “mlabrum” enjoy.

Examples like the one above keeps me humble. I can’t believe that he/she did it in just one line. and I need to admit that I do not understand that code, I really need to study the documentation. it took me a ton of lines. jajajaja I need to keep studing but I will share other solution from other user.

Note:  The following code is not written by me, it was created by another user of codewars.com it belongs to the user: “yms9654” enjoy.

 

 

 

Category: Ruby Examples | Comments Off on Rot13

Remove a exclamation mark from the end of string

From codewars.com by Edxael  (that’s me)

Description:

  • Remove a exclamation mark from the end of string. For a beginner kata, you can assume that the input data is always a string, no need to verify it.
  • Examples

My solution:

Note:  The following code is not written by me, it was created by another user of codewars.com it belongs to the user: “cyberplanner” enjoy.

 

 

Category: Ruby Examples | Comments Off on Remove a exclamation mark from the end of string

Two to One

From codewars.com by Edxael  (that’s me)

Instructions:  Take 2 strings s1 and s2 including only letters from ato z. Return a new sorted string, the longest possible, containing distinct letters, – each taken only once – coming from s1 or s2.

Examples:

My solution:

Note:  The following code is not written by me, it was created by another user of codewars.com it belongs to the user: “Beast” enjoy.

 

Category: Ruby Examples | Comments Off on Two to One

Ones and Zeros

From codewars.com by Edxael  (that’s me)

Instructions: Given an array of one’s and zero’s convert the equivalent binary value to an integer.

Eg: [0, 0, 0, 1] is treated as 0001 which is the binary representation of 1

Examples:

my solution:

Note:  The following code is not written by me, it was created by another user of codewars.com it belongs to the user: “basilekoko” enjoy.

Note:  The following code is not written by me, it was created by another user of codewars.com it belongs to the user: “dzNET” enjoy.

 

 

Category: Ruby Examples | Comments Off on Ones and Zeros

Which are in?

From codewars.com by Edxael  (that’s me)

Given two arrays of strings a1 and a2 return a sorted array r in lexicographical order of the strings of a1 which are substrings of strings of a2.

Example 1:

a1 = ["arp", "live", "strong"]

a2 = ["lively", "alive", "harp", "sharp", "armstrong"]

returns ["arp", "live", "strong"]

Example 2:

a1 = ["tarp", "mice", "bull"]

a2 = ["lively", "alive", "harp", "sharp", "armstrong"]

returns []

Notes:

Arrays are written in “general” notation. See “Your Test Cases” for examples in your language.

Beware: r must be without duplicates.

Note:  The following code is not written by me, it was created by another user of codewars.com it belongs to the user: “colbydauph” enjoy.

 

Category: Ruby Examples | Comments Off on Which are in?

Who likes it?

From codewars.com by Edxael  (that’s me)

You probably know the “like” system from Facebook and other pages. People can “like” blog posts, pictures or other items. We want to create the text that should be displayed next to such an item.

Implement a function likes :: [String] -> String, which must take in input array, containing the names of people who like an item. It must return the display text as shown in the examples:

 

For more than 4 names, the number in and 2 others simply increases.

— My Code —

Note:  The following code is not written by me, it was created by another user of codewars.com it belongs to the user: “surendraa” enjoy.

 

Category: Ruby Examples | Comments Off on Who likes it?

Create Phone Number

From codewars.com by Edxael  (that’s me)

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.

Example:

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

— My Code —

Note:

The following code is not written by me, it was created by another user of codewars.com it belongs to the user: “Jwashton” enjoy it.

 

Category: Ruby Examples | Comments Off on Create Phone Number

Write Number in Expanded Form

You will be given a number and you will need to return it as a string in Expanded Form. For example:

  • expanded_form(12); # Should return ’10 + 2′
  • expanded_form(42); # Should return ’40 + 2′
  • expanded_form(70304); # Should return ‘70000 + 300 + 4

 

Category: Ruby Examples | Comments Off on Write Number in Expanded Form

Vampire Numbers

Instructions

6 * 21 = 126 # 6 and 21 would be valid ‘fangs’ for a vampire number as the # digits 6, 1, and 2 are present in both the product and multiplicands

10 * 11 = 110 # 110 is not a vampire number since there are three 1’s in the # multiplicands, but only two 1’s in the product

 

Category: Daily, Ruby Examples | Comments Off on Vampire Numbers

Ruby Calisthenics

Here is some practice on the Prep-Work of the Viking Code School. in the following section we will be developing the solution to some challenges located on the Prep-Work, this will be fun, well with no more delay lest dive on this exercises.

1.Power

Write a method power which takes two integers (base and exponent) and returns the base raised to the power of exponent. Do not use Ruby’s **operator for this!

This code works with Integers and Negative values. unfortunately I need more time to make it to work with decimals, but coming soon.


2.Factorial

Write a method factorial which takes a number and returns the product of every number up to the current number multiplied together.


3. Uniques

Write a method uniques which takes an array of items and returns the array without any duplicates. Don’t use Ruby’s uniq method!

The following solution is Dynamic and Interactive, you will be prompted to provide: size of the array, maximum value, and minimum value, whit this information the software will create and populate an array with the provided specifications, then it will print it so you can see it. after that it will delete all duplicates and presented only the UNIQUE values in an organize order.

Because things happen, in case that you mix the Maximun and Minimum values it will catch it and fix it.


4. Combinations

Write a method combinations which takes two arrays of strings and returns an array with all of the combinations of the items in them, listing the first items first.

 


5. Primes

Write a method is_prime? which takes in a number and returns true if it is a prime number.

In this case, “Huston we got a problem”  basically there is NOT a test that would pinpoint Prime Numbers with a 100% exactitude, no matter how fancy the method you choose. for this reason I create a very basic way to find out if a number is prime, Using a library call prime.

 


6. Rectangle Overlap

Write a method overlap which takes two rectangles defined by the coordinates of their corners, e.g. [[0,0],[3,3]] and [[1,1],[4,6]], and determines whether they overlap. You can assume all coordinates are positive integers.

It doesn’t count as overlapping if their edges touch but they do not otherwise overwrite each other. As expressed by a sixth grade student:


7. The Counting Game

10 friends are sitting in a circle around a table and decide to play a new game. In it, they count up through the numbers from 1 to 100. The first person says “1”, the second says “2” and so on… but with a few catches:

  • Whenever the number is divisible by 7, they switch directions. So person 6 will say “6”, person 7 will say “7”, then person 6 again will say “8”.
  • Whenever the number is divisible by 11, they skip the next person for the following number. For instance, if person 3 says “33”, person 5 will say “34” instead (person 4 gets skipped).

 

 

 

Category: Ruby Examples | Comments Off on Ruby Calisthenics

Project Euler

Multiples of 3 and 5

If we list all the natural numbers below 10 that are multiples of 3 or 5, we get 3, 5, 6 and 9. The sum of these multiples is 23.

Find the sum of all the multiples of 3 or 5 below 1000.


Even Fibonacci numbers

Each new term in the Fibonacci sequence is generated by adding the previous two terms. By starting with 1 and 2, the first 10 terms will be:

1, 2, 3, 5, 8, 13, 21, 34, 55, 89, …

By considering the terms in the Fibonacci sequence whose values do not exceed four million, find the sum of the even-valued terms.

this was fun, my first attempt was no successful, basically I create a code that would work for a small number of the series, and it work but when I plug the 4,000,000 well it kill the console, literally after few minutes it returns “kill” I guess that was the brute force approach and I pay dearly, the following code is the brute force and DO NOT plug it on your computer or you will pay for it, but it would be nice if you see it.

well that is what I got for creating arrays with millions of entries, jajaja,

now the second attempt, this time I had to do some research and took me time, but after some failures the following code is the one that work