blob: 60fa167e433a0c245a319f68be8c2b6ccad3435d (
plain)
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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
|
#!/usr/bin/env ruby
=begin
AUTHOR: Robert DiCicco
DATE: 2022-12-05
Challenge 194 Digital Clock ( Ruby )
-------------------------------------------
SAMPLE OUTPUT
ruby .\DigitalClock.rb
Input: time = ?5:00
Output: 1
Input: time = ?3:00
Output: 2
Input: time = 1?:00
Output: 9
Input: time = 2?:00
Output: 3
Input: time = 12:?5
Output: 5
Input: time = 12:5?
Output: 9
=end
templates = ['?5:00', '?3:00', '1?:00', '2?:00', '12:?5','12:5?'];
def GetDigit(tp, n)
puts("Input: time = #{tp}")
print "Output: "
if (( n == 0 ) && (tp[1,1] < '4'))
printf "2\n\n"
elsif (( n == 0 ) && (tp[1,1] >= '4' ))
printf "1\n\n"
elsif (( n == 1 ) && (tp[0,1] <= '1'))
printf "9\n\n"
elsif (( n == 1 ) && (tp[0,1] == '2'))
printf "3\n\n"
elsif ( n == 3)
printf "5\n\n"
elsif ( n == 4)
printf "9\n\n";
else
puts "Error!";
end
end
templates.each do |tp|
GetDigit(tp,tp.index('?'));
end
|