Skip to content

Instantly share code, notes, and snippets.

@jendiamond
Last active March 14, 2016 06:07
Show Gist options
  • Select an option

  • Save jendiamond/464494fa55a8f680eb21 to your computer and use it in GitHub Desktop.

Select an option

Save jendiamond/464494fa55a8f680eb21 to your computer and use it in GitHub Desktop.

Coding Challenges

Write a method that:


1) Returns the longest word in a sentence (“The dog ran into the shoe store” )

(Optional: “The dog ran into the shoe store.”)


2) reverses any string given (cannot use any reverse method)


3) converts [[ 1, "five"], [3, 'six']] to {'1' => :five, '3' => :six }

hint for Ruby: hash[key] = value


4) capitalizes each third character of "kangaroo" (Optional: “Kanga.roo”)


5) Write a program that will take a year and report “true” if it is a leap year and “false” if it isn’t.

Leap years are divisible by 4, not divisible by 100 unless that year is also divisble by 400.



Intermediate

1)Write a program takes two DNA strands(strings) and calculates the difference of characters between the two.

A =“ACTBF”
B = “GCABA”
Should output 3 because there are 3 differences


2) creates a 10 x 10 2d array that looks like this:

[[1, 2, 3, 4, 5, 6, 7, 8, 9, 10],
[11, 12, 13, 14, 15, 16, 17, 18, 19, 20],
[21, 22, 23, 24, 25, 26, 27, 28, 29, 30],
[31, 32, 33, 34, 35, 36, 37, 38, 39, 40],
[41, 42, 43, 44, 45, 46, 47, 48, 49, 50],
[51, 52, 53, 54, 55, 56, 57, 58, 59, 60],
[61, 62, 63, 64, 65, 66, 67, 68, 69, 70],
[71, 72, 73, 74, 75, 76, 77, 78, 79, 80],
[81, 82, 83, 84, 85, 86, 87, 88, 89, 90],
[91, 92, 93, 94, 95, 96, 97, 98, 99, 100]



Advanced

1) Write a function called word_count,

that takes a sentence as a string as input,
and returns the frequency of each word in that sentence as a hash,
whose key is the word
and whose value is the number of times that word appears in that sentence.

Here is the input:
“The quick brown fox jumped over the moon.
This mammal did not jump over the sun.
It jumped over the moon. And it was quick about it.”

The output should be:
{"the"=>4, "quick"=>2, "brown"=>1, "fox"=>1, "jumped"=>2, "over"=>3,
"moon"=>2, "this"=>1, "mammal"=>1, "did"=>1, "not"=>1, "jump"=>1,
"sun"=>1, "it"=>3, "and"=>1, "was"=>1, "about"=>1}


2) Given a 3 or 4 digit number with distinct digits,

return a sorted array of all the unique numbers that can be formed with those digits.

ie, given 123, return [123, 132, 213, 231, 312, 321]
(can use to the permutation method)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment