From 4d141af61a014ab3b2cc63547f8dc541dddea0ae Mon Sep 17 00:00:00 2001 From: Elvin Hrytsyuk <183242754+Elvin-code-dev@users.noreply.github.com> Date: Mon, 27 Oct 2025 01:13:20 +0000 Subject: [PATCH 1/2] file created --- archive/r/ruby/linear-search.rb | 0 1 file changed, 0 insertions(+), 0 deletions(-) create mode 100644 archive/r/ruby/linear-search.rb diff --git a/archive/r/ruby/linear-search.rb b/archive/r/ruby/linear-search.rb new file mode 100644 index 000000000..e69de29bb From 2e18182bd3fb944c49e2cdd33c915881d11f3788 Mon Sep 17 00:00:00 2001 From: Elvin Hrytsyuk <183242754+Elvin-code-dev@users.noreply.github.com> Date: Mon, 27 Oct 2025 02:41:37 +0000 Subject: [PATCH 2/2] Finshed the problem --- archive/r/ruby/linear-search.rb | 53 +++++++++++++++++++++++++++++++++ 1 file changed, 53 insertions(+) diff --git a/archive/r/ruby/linear-search.rb b/archive/r/ruby/linear-search.rb index e69de29bb..4b92f3322 100644 --- a/archive/r/ruby/linear-search.rb +++ b/archive/r/ruby/linear-search.rb @@ -0,0 +1,53 @@ +USAGE = 'Usage: please provide a list of integers ("1, 4, 5, 11, 12") and the integer to find ("11")' + + + if ARGV.length < 2 + puts USAGE + return + end + + # the first input (list of numbers) + list_input = ARGV[0] + #second input (number to find) + target_input = ARGV[1] + + #check if the input is empty + if list_input.strip.empty? || target_input.strip.empty? + puts USAGE + return + end + + begin + #split list by the commas, trim the spaces, then turn into intgers + numbers = list_input.split(',').map { |s| s.strip.to_i } + + #convert second number to integer + target = Integer(target_input) + rescue ArgumentError + # if conversion fails we show the usage message + puts USAGE + return + end + + #track if we find the number + found = false + + # go through each number in the list + numbers.each do |n| + if n == target + found = true + # stop searching once we find it + break + end + end + + # print result as true or false + if found + puts "true" + else + puts "false" + end + + + +