Skip to content

Instantly share code, notes, and snippets.

@dharshan
dharshan / output.txt
Last active Nov 29, 2017
Substring in String in Ruby using each_with_index loop
View output.txt
1
Enter a String
bengaluru
Enter a Sub String
uru
=> Present
2
Enter a String
bengaluru
@dharshan
dharshan / output.txt
Last active Nov 29, 2017
Find any pairs of numbers in a sequence that add up to sum N
View output.txt
#### OUTPUT
1
Enter comma seperated integers
1,2,3,4,6,7,8
Enter pair sum
10
((2, 8), (3, 7), (4, 6), (6, 4), (7, 3), (8, 2))
2
Enter comma seperated integers
@dharshan
dharshan / Output
Last active Nov 19, 2017
Find any pairs of numbers in a sequence that add up to sum N (Using builtin combination method)
View Output
##### OUTPUT
1
Enter comma seperated integers
1,2,3,4,6,7,8
Enter pair sum
10
[[2, 8], [3, 7], [4, 6]]
2
@dharshan
dharshan / reverse_if_4.rb
Created Apr 28, 2017
Reverse input string if input string length is less than 4
View reverse_if_4.rb
def string_rev_if_4(input)
return input.reverse if input.length < 4
input
end
string_rev_if_4("he") # "eh"
string_rev_if_4("hel") # "leh"
string_rev_if_4("hell") # "hell"