Skip to content

Commit

Permalink
Format
Browse files Browse the repository at this point in the history
lpil committed Nov 7, 2023

Verified

This commit was signed with the committer’s verified signature.
tomusdrw Tomek Drwięga
1 parent 358e3d5 commit bb469ef
Showing 2 changed files with 7 additions and 8 deletions.
10 changes: 5 additions & 5 deletions exercises/concept/dna-encoding/.meta/example.gleam
Original file line number Diff line number Diff line change
@@ -34,7 +34,7 @@ fn do_encode(dna: List(Nucleotide), acc: BitString) -> BitString {
case dna {
[] -> acc
[nucleotide, ..rest] ->
do_encode(rest, <<acc:bit_string, encode_nucleotide(nucleotide):2>>)
do_encode(rest, <<acc:bits, encode_nucleotide(nucleotide):2>>)
}
}

@@ -48,10 +48,10 @@ fn do_decode(
) -> Result(List(Nucleotide), Nil) {
case dna {
<<>> -> Ok(list.reverse(acc))
<<0b00:2, rest:bit_string>> -> do_decode(rest, [Adenine, ..acc])
<<0b01:2, rest:bit_string>> -> do_decode(rest, [Cytosine, ..acc])
<<0b10:2, rest:bit_string>> -> do_decode(rest, [Guanine, ..acc])
<<0b11:2, rest:bit_string>> -> do_decode(rest, [Thymine, ..acc])
<<0b00:2, rest:bits>> -> do_decode(rest, [Adenine, ..acc])
<<0b01:2, rest:bits>> -> do_decode(rest, [Cytosine, ..acc])
<<0b10:2, rest:bits>> -> do_decode(rest, [Guanine, ..acc])
<<0b11:2, rest:bits>> -> do_decode(rest, [Thymine, ..acc])
_ -> Error(Nil)
}
}
Original file line number Diff line number Diff line change
@@ -36,9 +36,8 @@ fn do_decode(string: BitString, acc: Int) -> Result(List(Int), Error) {
case string {
<<>> -> Ok([])
<<1:1, _:7>> -> Error(IncompleteSequence)
<<1:1, large_bits:7, rest:bit_string>> ->
do_decode(rest, 128 * acc + large_bits)
<<0:1, last_bits:7, rest:bit_string>> -> {
<<1:1, large_bits:7, rest:bits>> -> do_decode(rest, 128 * acc + large_bits)
<<0:1, last_bits:7, rest:bits>> -> {
use integers <- result.then(do_decode(rest, 0))
Ok([128 * acc + last_bits, ..integers])
}

0 comments on commit bb469ef

Please sign in to comment.