Posts

Showing posts from May, 2021

Direction Catastrophe

Image
  We are given directions to go from one point to another. The directions are "NORTH", "SOUTH", "WEST", "EAST". Clearly "NORTH" and "SOUTH" are opposite, "WEST" and "EAST" too. Going one direction and coming back the opposite direction is a wasted effort, so let's concise these directions to go the shortest route. For example, given the following directions: You can immediately see that going "NORTH" and then "SOUTH" is not reasonable, better stay to the same place!

ROT13 implementation in ruby

Image
We can implement ROT13 using map method and String.tr method collectively. Here is basic example