Permalink
Browse files

Update to v0.0.6

  • Loading branch information...
nelbren committed Oct 23, 2018
1 parent 64ac756 commit ced9cee8a6aabedf0301a0d290b2ec52f882232e
Showing with 25 additions and 7 deletions.
  1. +3 −4 heart.rb
  2. +22 −3 string_rotations.rb
@@ -1,16 +1,15 @@
#!/usr/bin/ruby
# heart.ruby v0.0.5
# heart.ruby v0.0.6
# nelbren@gmail.com
# Use: Case 2 Array
# UseMultipleAssign
@a = ['','','','','','','','']
@rc = [ [1,4], [0,5], [1,6] ]
8.times do |r|
if r > 2
@cb += 1
else
@cb = @rc[r][0]
@ce = @rc[r][1]
@cb,@ce = @rc[r][0],@rc[r][1]
end
7.times { |c| @a[r] += (@cb..@ce).include?(c) ? 'x' : ' ' }
end
@@ -1,5 +1,24 @@
#!/usr/bin/ruby
# string_rotations_v0.0.5.rb
# string_rotations_v0.0.6.rb
# nelbren@nelbren.com
# UsingSubstringAndOnlyOneAssingInside
a=[];(x=gets.chomp).each_char{|c|a<<(x=x[1..-1]+c)};p a
# UsingAnCustomFunction
=begin
String Rotations
Create a function that accepts a string argument and returns an array of strings, which are shifted versions of the argument string.
Sample Input
"Hello"
Sample Output
["elloH", "lloHe", "loHel", "oHell", "Hello"]
As you can see from the example above, each element shifts the first character of the previous version to the end.
The original string should be included in the output array. The order matters; each element of the output array should be the shifted version of the previous element.
The output array should have the same length as the input string.
The function should return an empty array when a zero-length String is provided as the argument.
=end
def r(x)
a=[];x.each_char{|c|a<<(x=x[1..-1]+c)};a
end
p r('Hello'), r('')

0 comments on commit ced9cee

Please sign in to comment.