Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Comparing changes

Choose two branches to see what's changed or to start a new pull request. If you need to, you can also compare across forks.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also compare across forks.
base fork: jfelipe/SaaS
base: 8d121c6198
...
head fork: jfelipe/SaaS
compare: 90e59bb8ec
Checking mergeability… Don't worry, you can still create the pull request.
  • 2 commits
  • 2 files changed
  • 0 commit comments
  • 1 contributor
Showing with 42 additions and 0 deletions.
  1. +11 −0 Assigment1/anagrams.rb
  2. +31 −0 Assigment1/rock_paper_scissors.rb
View
11 Assigment1/anagrams.rb
@@ -0,0 +1,11 @@
+#Assigment1 anagrams - Juan Felipe Arango -
+#I think is ugly to use an array for hash key, works for now.
+def combine_anagrams(words)
+ final_hash = words.inject({}) do |hash, word|
+ hash[word.downcase.split('').sort] ||= []
+ hash[word.downcase.split('').sort] << word
+ hash
+ end
+ final_hash.values
+end
+
View
31 Assigment1/rock_paper_scissors.rb
@@ -0,0 +1,31 @@
+#Assigment1 rock_paper_scissors - Juan Felipe Arango -
+
+class WrongNumberOfPlayersError < StandardError ; end
+class NoSuchStrategyError < StandardError ; end
+
+def valid_strategy?(strategy)
+ %w(r s p).include? strategy.downcase
+end
+
+def winner?(move1,move2)
+ (move1 == "R" and move2 == "S") or
+ (move1 == "S" and move2 == "P") or
+ (move1 == "P" and move2 == "R") or
+ move1 == move2
+end
+
+def rps_game_winner(game)
+ move1 = game.first.last
+ move2 = game.last.last
+
+ raise WrongNumberOfPlayersError unless game.length == 2
+ raise NoSuchStrategyError unless valid_strategy?(move1) and valid_strategy?(move2)
+
+ if winner?(move1,move2)
+ return game.first
+ end
+ game.last
+end
+
+#To.do tournament
+

No commit comments for this range

Something went wrong with that request. Please try again.