-
Notifications
You must be signed in to change notification settings - Fork 22
/
3.fc
39 lines (35 loc) · 1.94 KB
/
3.fc
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
{-
TASK 3 - Find and replace binary substring
Binary string is represented as a cell linked list: string splitted to chunks,
first chunk stored to the root cell, next one to the cell in ref and so on;
each cell can have only one ref.
Write the method that find and replaces one flags in the binary string
with another value. Flags and values can be can be of any length, but
strictly up to 128 bits. The method must replace every flag it finds.
Flag and the value to be replaced is guaranteed to be greater than 0.
Flag and the value may be of different lengths.
When there are overlapping flags, only the first one
from the overlap needs to be replaced (for example, if the flag is 101,
value is 111, and string is 10101, then the result would be 11101, but if
the string is 1010101, then the result would be 1110111).
Every cell in the input linked list, except for the last one
(the one that is the deepest in the tree), is guaranteed to be full
(guaranteed to contain 1023 bits).
The requirements on the output cell are more loose - only the concatenation of bits
from the linked list needs to match that of the expected answer, but the structure
itself may be different (for example, for the purposes of comparing the answer,
a cell with bit 1 and a ref containing bits 10 is the same as a cell containing
bit 11 and a ref with bit 0 - they both make up a bitstring 110).
Lets give a simple example. We have the target flag 101110101 and the value
to be written 111111111 as inputs, and a linked list of cells, in which the bit
value of the first cell ends with ...10100001011, and in the ref we have cell that
starts with 10101000111111...
The output should be a linked list where the first
cell ends with ...10100001111, and the second cell starts with 11111000111111...
-}
() recv_internal() {
}
;; testable
(cell) find_and_replace(int flag, int value, cell linked_list) method_id {
return begin_cell().end_cell();
}