Skip to content

Commit

Permalink
Merge pull request #69 from dalurness/du/day19solution
Browse files Browse the repository at this point in the history
change formatting
  • Loading branch information
dalurness authored Dec 20, 2024
2 parents 75bfee1 + 61db577 commit 68a0ded
Showing 1 changed file with 29 additions and 29 deletions.
58 changes: 29 additions & 29 deletions src/content/communitySolutions/19/dalurness.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,35 @@ descriptions: ["gleam"]

### 2024 Solution Gleam

```gleam
import gleam/int
import gleam/io
import gleam/list
import gleam/string
import simplifile
pub fn main() {
let filename = "bin.txt"
case simplifile.read(filename) {
Ok(file_contents) -> file_contents
Error(_) -> {
io.println("failed to read file: " <> filename)
panic as "failed to read file"
}
}
|> string.split("")
|> list.sized_chunk(8)
|> list.map(fn(l) {
let joined_str = string.join(l, "")
let assert Ok(int_val) = int.base_parse(joined_str, 2)
let assert Ok(cp) = string.utf_codepoint(int_val)
cp
})
|> string.from_utf_codepoints
|> io.println
}
```

#### Output

```
Expand Down Expand Up @@ -125,32 +154,3 @@ Naomi: NICE
Andrew: NAUGHTY
Madison: NICE
```

```gleam
import gleam/int
import gleam/io
import gleam/list
import gleam/string
import simplifile
pub fn main() {
let filename = "bin.txt"
case simplifile.read(filename) {
Ok(file_contents) -> file_contents
Error(_) -> {
io.println("failed to read file: " <> filename)
panic as "failed to read file"
}
}
|> string.split("")
|> list.sized_chunk(8)
|> list.map(fn(l) {
let joined_str = string.join(l, "")
let assert Ok(int_val) = int.base_parse(joined_str, 2)
let assert Ok(cp) = string.utf_codepoint(int_val)
cp
})
|> string.from_utf_codepoints
|> io.println
}
```

0 comments on commit 68a0ded

Please sign in to comment.