RB
rb
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
=begin
[ASSIGNMENT] : Expressions Matter
TASK : Given three integers a, b, c,
return the largest number obtained after inserting the following operators and brackets +, *, ( )
For Example : :
1. expressionsMatter(1,2,3) --> return 9
After placing signs and brackets, the Maximum value obtained from the expression is (1+2) * 3 = 9
2. expressionsMatter(9,1,1) --> return 18
After placing signs and brackets, the Maximum value obtained from the expression is 9 * (1+1) = 18
HappyCodings!:-)
=end
#Enter your integers separated by , and press Submit.
x=gets.to_s.chomp
b=x.gsub(" ","").split(",").map{|i| i.to_i}.sort
sum=0
if b[0].to_i<=0
puts "Invalid input, none of the numbers can be less or equal then 0."
elsif b[0].to_i==1 && b[1].to_i==1 && b[2].to_i==1
print print "You inputed (#{x}) and the largest number is #{b.map{|r| r.to_i}.inject(:+)} ."
elsif b[0].to_i==1 || b[1].to_i==1
sum=b[0].to_i+b[1].to_i
Enter to Rename, Shift+Enter to Preview
OUTPUT
Run