-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathproblem number 0, What's a numpad.txt
More file actions
143 lines (129 loc) · 1.86 KB
/
problem number 0, What's a numpad.txt
File metadata and controls
143 lines (129 loc) · 1.86 KB
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
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
problem number: 0, What's a numpad?
===================================
QUESTION:-
=========
Some people might remember T9 phone inputs, in which the numbers 2 to 9 have associated letters, and 0 acts as a space. Key 2 has "abc", 3 has "def" etc:
1 2 3
abc def
4 5 6
ghi jkl mno
7 8 9
pqrs tuv wxyz
0
_
Note that 0 is a space, not an underscore!
To get a letter you press the button a certain number of times - pressing 2 once gives "a", twice gives "b".
The input is a list of number pairs: a key and the number of times it has been pressed. For example, "7 3" would be "r". What is the message this input produces?
GIVEN INPUT:-
6 3
4 2
0 1
7 4
6 3
0 1
8 1
4 2
3 2
9 3
0 1
4 2
2 1
8 3
3 2
0 1
4 3
6 2
8 1
3 2
7 3
6 2
3 2
8 1
0 1
6 3
6 2
0 1
2 3
6 3
6 1
7 1
8 2
8 1
3 2
7 3
7 4
0 1
6 2
6 3
9 1
ANSWER:-
=======
q)table: flip `num`char!((1 2 3 4 5 6 7 8 9 0); (" "; "abc"; "def"; "ghi"; "jkl"; "mno"; "pqrs"; "tuv"; "wxyz"; enlist" "))
q)table
num char
----------
1 " "
2 "abc"
3 "def"
4 "ghi"
5 "jkl"
6 "mno"
7 "pqrs"
8 "tuv"
9 "wxyz"
0 ," "
q)input:(6 3;4 2;0 1;7 4;6 3;0 1;8 1;4 2;3 2;9 3;0 1;4 2;2 1;8 3;3 2;0 1;4 3;6 2;8 1;3 2;7 3;6 2;3 2;8 1;0 1;6 3;6 2;0 1;2 3;6 3;6 1;
7 1;8 2;8 1;3 2;7 3;7 4;0 1;6 2;6 3;9 1)
q)input
6 3
4 2
0 1
7 4
6 3
0 1
8 1
4 2
3 2
9 3
0 1
4 2
2 1
8 3
3 2
0 1
4 3
6 2
8 1
3 2
7 3
6 2
3 2
8 1
0 1
6 3
6 2
0 1
2 3
6 3
..
q)
q)
q)f:{[input]fnum: first(first input); lnum: last (first input) - 1; srow: select from table where num=fnum;si:(first srow[`char]) lnum;:si}
q)
q)
q)
q)i:0
q)
q)
q)result:()
q)
q)
q)ci: count input
q)ci
41
q)
q)
q)while[i<ci; rfi: f[input];result:result, rfi; input:1_input;i+:1]
q)result
"oh so they have internet on computers now"
q)