• API
• FAQ
• Tools
• Archive
SHARE
TWEET # Untitled a guest Jul 15th, 2019 46 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
1. newHash = Hash.new #first hash
2.   newHash[:random_numbers] = Array.new(5) {rand(12...21)} #first hash random
3.   secondHash = Hash.new #second hash
4.   secondHash[:random_numbers] = Array.new(5) {rand(12...21)} #second hash random
5.
6.   #user inputs
7.   newHash[:user_input] = Array.new(5)
8.   secondHash[:user_input] = Array.new(5)
9.   i=0
10.   5.times do
11.       puts "enter a number between 12-21 (inclusive): "
12.       userin = gets.chomp
13.       newHash[:user_input][i] = userin.to_i
14.       secondHash[:user_input][i] = userin.to_i
15.       i+=1;
16.   end
17.
18.   puts "Give me a number you want information about: "
19.   num = gets.chomp
20.   num = num.to_i
21.
22.   puts "random numbers 1: "
23.   rn1 =0
24.   newHash[:random_numbers].each do |val|
25.       puts val
26.       if val == num
27.           rn1 += 1
28.       end
29.   end
30.
31.   puts "user input: "
32.   ui1=0
33.   newHash[:user_input].each do |val|
34.       puts val
35.       if val == num
36.           ui1 += 1
37.       end
38.   end
39.
40.   puts "random numbers 2:"
41.   rn2=0
42.   secondHash[:random_numbers].each do |val|
43.       puts val
44.       if val == num
45.           rn2 += 1
46.       end
47.   end
48.
49.   puts "Using only the first hash:"
50.   if rn1 == 0
51.       puts "The number, " + num.to_s + " did not show in the randomly generated numbers."
52.   else
53.       puts "The number, " + num.to_s + " showed up " + rn1.to_s + " time(s) in the randomly generated numbers."
54.   end
55.   if ui1 == 0
56.       puts "The number, " + num.to_s + " was not provided by the user earlier."
57.   else
58.       puts "The number, " + num.to_s + " showed up " + ui1.to_s + " time(s) by the user earlier."
59.
60.   end
61.
62.   puts "Using only the second hash:"
63.   if rn2 == 0
64.       puts "The number, " + num.to_s + " did not show in the randomly generated numbers."
65.   else
66.       puts "The number, " + num.to_s + " showed up " + rn2.to_s + " time(s) in the randomly generated numbers."
67.   end
68.
69.   if ui1 == 0
70.       puts "The number, " + num.to_s + " was not provided by the user earlier."
71.   else
72.       puts "The number, " + num.to_s + " showed up " + ui1.to_s + " time(s) by the user earlier."
73.
74.   end
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy.
Not a member of Pastebin yet?
Sign Up, it unlocks many cool features!

Top