Can someone review my Julia notebook

Hi, I’ve been learning Julia for a few weeks off and on, and reading the David Mac Kay book at the same time. I was wondering if some of you could review my notebook here https://purport.neocities.org/hamming.html

Currently I have the matrix coded as [1 1 1 0 1 0 0; 0 1 1 1 0 1 0; 1 0 1 1 0 0 1], but I was wondering if there was some way to do [ I_4; P ] or similar like I have it in the latex? Then I could reuse P.

The encoding and decoding of the image looks quite long? I was wondering if there was some way to make that a bit more elegant? I have quite a few maps over the place too, I really just want to manipulate bits and 1’s or 0’s

Anything else you might suggest to make the code more idiomatic Julia? There isn’t much code here really, but Julia is a bit different to my usual programming languages so I’d appreciate anything really.

Thanks,
Dave

Hi purport,

julia> using LinearAlgebra # I is defined in this package

julia> P = [1 1 1 0; 0 1 1 1; 1 0 1 1]
3×4 Matrix{Int64}:
 1  1  1  0
 0  1  1  1
 1  0  1  1

julia> Gtrans = vcat(Matrix{Int}(I, 4, 4), P)
7×4 Matrix{Int64}:
 1  0  0  0
 0  1  0  0
 0  0  1  0
 0  0  0  1
 1  1  1  0
 0  1  1  1
 1  0  1  1

Then in a function definition you can use variables that are defined in the current scope.

function hamming_7_4_encode(s)
    return Gtrans * s .% 2
end

and

function hamming_7_4_decode(t)
    Q = [1 1 1 0 1 0 0; 0 1 1 1 0 1 0; 1 0 1 1 0 0 1]
    syndrome = Q * t .% 2
    map_t = Dict([1, 0, 1] => 1, [1, 1, 0] => 2, [1, 1, 1] => 3, [0, 1, 1] => 4)
    if haskey(map_t, syndrome)
        idx = map_t[syndrome]
        t[idx] += 1
        t = t .% 2
    end    
    return t[1:4]
end

This are less lines of code, but I doubt that this is more readable.

Thanks for the tips!