blob: 90ddabae4759fa60df1709ea628bedc5b5492e16 (
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
|
TASK #1 - Add Binary
You are given two decimal-coded binary numbers, $a and $b.
Write a script to simulate the addition of the given binary numbers.
Example 1
Input: $a = 11; $b = 1;
Output: 100
Example 2
Input: $a = 101; $b = 1;
Output: 110
Example 3
Input: $a = 100; $b = 11;
Output: 111
MY NOTES: Very easy. Extract least significant binary digit via $a % 10,
implement full adder (bit,bit,carryin)->(bit,carryout), recurse and recombine.
TASK #2 - Multiplication Table
You are given 3 positive integers, $i, $j and $k.
Write a script to print the $kth element in the sorted multiplication
table of $i and $j.
Example 1
Input: $i = 2; $j = 3; $k = 4
Output: 3
Since the multiplication of 2 x 3 is as below:
1 2 3
2 4 6
The sorted multiplication table:
1 2 2 3 4 6
Now the 4th element in the table is "3".
Example 2
Input: $i = 3; $j = 3; $k = 6
Output: 4
Since the multiplication of 3 x 3 is as below:
1 2 3
2 4 6
3 6 9
The sorted multiplication table:
1 2 2 3 3 4 6 6 9
Now the 6th element in the table is "4".
MY NOTES: Sounds pretty easy. The table's ith row is (1..$j) * $i.
|