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
|
Task 1: "Swap Nibbles
You are given a positive integer $N.
Write a script to swap the two nibbles of the binary representation
of the given number and print the decimal number of the new binary
representation.
A nibble is a four-bit aggregation, or half an octet.
To keep the task simple, we only allow integer less than or equal to 255.
Example
Input: $N = 101
Output: 86
Binary representation of decimal 101 is 1100101 or as 2 nibbles (0110)(0101).
The swapped nibbles would be (0101)(0110) same as decimal 86.
Input: $N = 18
Output: 33
Binary representation of decimal 18 is 10010 or as 2 nibbles (0001)(0010).
The swapped nibbles would be (0010)(0001) same as decimal 33.
"
My notes: trivial.
Task 2: "Sequence without 1-on-1
Write a script to generate sequence starting at 1. Consider the increasing
sequence of integers which contain only 1's, 2's and 3's, and
do not have any doublets of 1's like below. Please accept a positive
integer $N and print the $Nth term in the generated sequence.
1, 2, 3, 12, 13, 21, 22, 23, 31, 32, 33, 121, 122, 123, 131, ...
Example
Input: $N = 5
Output: 13
Input: $N = 10
Output: 32
Input: $N = 60
Output: 2223
"
My notes: hmm, depends on what we mean by "doublet", as in "no doublets of 1".
I'm choosing to assume that it means "no two sequential 1s". should be
pretty easy.
|