aboutsummaryrefslogtreecommitdiff
path: root/aoc2023/build/packages/adglent/src/adglent.gleam
blob: 077d49d2669f0ffde2447e37ed90705c831f4d03 (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
import simplifile.{type FileError}
import gleam/list
import gleam/string

pub type Example(a) {
  Example(input: String, answer: a)
}

pub fn inspect(value: a) -> String {
  let inspected_value = string.inspect(value)
  case
    inspected_value
    |> string.starts_with("\"")
  {
    True ->
      inspected_value
      |> string.drop_left(1)
      |> string.drop_right(1)
    False -> inspected_value
  }
}

pub fn get_input(day: String) -> Result(String, FileError) {
  simplifile.read("src/day" <> day <> "/input.txt")
}

pub fn get_test_folder(day: String) -> String {
  "test/day" <> day
}

pub type Problem {
  First
  Second
}

pub fn get_part() -> Result(Problem, Nil) {
  case start_arguments() {
    ["1"] -> Ok(First)
    ["2"] -> Ok(Second)
    _ -> Error(Nil)
  }
}

pub fn start_arguments() -> List(String) {
  get_start_arguments()
  |> list.map(to_string)
}

type Charlist

/// Transform a charlist to a string
@external(erlang, "unicode", "characters_to_binary")
fn to_string(a: Charlist) -> String

@external(erlang, "init", "get_plain_arguments")
fn get_start_arguments() -> List(Charlist)