-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathTwoSumProblem.rb
More file actions
32 lines (27 loc) · 883 Bytes
/
TwoSumProblem.rb
File metadata and controls
32 lines (27 loc) · 883 Bytes
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
#--------------------------------------------------------------------
# File Name: TwoSumProblem
#--------------------------------------------------------------------
# Description:
# Find all the pairs of two integers in an unsorted array that sum up
# to a given S.
#--------------------------------------------------------------------
# For Eg: if we need the sum of value is 7
#--------------------------------------------------------------------
#------------------
# Incremental Value
count = 0
#--------------
# Getting input
inputValue = 8
#-----------------------
# Initializing the Array
value = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12]
(value.length).times do |x|
x.times do |y|
if ((value[x]+ value[y]) == inputValue)
print " [#{value[x]}, #{value[y]}] "
count = count + 1
end
end
end
puts "The Total Count is : #{count}"