Testing Highlighting
Testing some code highlighting
I will probably post some code snippets now and then, so let’s see if code highlighting works how I think it does:
First some nim code:
1type
2 State = enum
3 On, Dying, Off
4
5 Grid = array[0..40, array[0..150, State]]
6
7 Point = tuple
8 col: int
9 row: int
10
11func `+`(self, other: Point): Point =
12 result.col = self.col + other.col
13 result.row = self.row + other.row
14
15proc newGrid(): Grid =
16 for xs in result.mitems:
17 for state in xs.mitems:
18 state = sample [On, Off]
19
20func getAt(grid: Grid, point: Point): State =
21 if point.col < 0 or point.col >= grid[0].len:
22 return Off
23 if point.row < 0 or point.row >= grid.len:
24 return Off
25
26 grid[point.row][point.col]
Seems like gleam is not yet supported, so have to wait for the highlighter to get support
And some gleam code
fn race(time: Int, button: Int) -> Int {
{ time - button } * button
}
fn ways_to_win(time: Int, distance: Int) -> Int {
list.range(from: 0, to: time)
|> list.map(race(time, _))
|> list.filter(fn(x) { x > distance })
|> list.length
}
fn part1(times: List(Int), distances: List(Int)) {
let answer =
list.zip(times, distances)
|> list.map(fn(x) { ways_to_win(x.0, x.1) })
|> int.product
io.print("Part 1: ")
io.println(int.to_string(answer))
}
So there we will see.