aboutsummaryrefslogtreecommitdiff
path: root/challenge-098/andinus/README
blob: 98fe099f22609329692d2f7c14769a62a8d579af (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
                            ━━━━━━━━━━━━━━━
                             CHALLENGE 098

                                Andinus
                            ━━━━━━━━━━━━━━━


                               2021-02-02


Table of Contents
─────────────────

1. Task 1 - Read N-characters
.. 1. Raku





1 Task 1 - Read N-characters
════════════════════════════

  You are given file `$FILE'.

  Create subroutine `readN($FILE, $number)' returns the first
  n-characters and moves the pointer to the `(n+1)th' character.


1.1 Raku
────────

  • Program: <file:raku/ch-1.raku>

  `readN' is defined as such:
  ┌────
  │ sub readN (
  │     IO $file, Int $chars --> Str
  │ ) {
  │     ...
  │ }
  └────

  The pointer index is stored in a state array (`%pointers'). It's
  stores the pointer separately for each file. It's initialized with 0.
  ┌────
  │ # %pointers stores the pointer index.
  │ state Int %pointers;
  │ %pointers{$file} = 0 without %pointers{$file};
  └────

  The pointer is updated & required string is returned.
  ┌────
  │ with %pointers{$file} -> $idx {
  │     %pointers{$file} += $chars;
  │     return $file.slurp.substr($idx, $chars);
  │ }
  └────