# Can someone review my Julia notebook

**URL:** https://discourse.julialang.org/t/can-someone-review-my-julia-notebook/85396
**Category:** New to Julia
**Created:** [August 6, 2022, 1:32pm UTC](https://discourse.julialang.org/t/can-someone-review-my-julia-notebook/85396 "2022-08-06T13:32:37Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![purport](https://avatars.discourse-cdn.com/v4/letter/p/f07891/32.png) [@purport](https://discourse.julialang.org/u/purport)
#### Post date: [August 6, 2022, 1:32pm UTC](https://discourse.julialang.org/t/can-someone-review-my-julia-notebook/85396/1 "2022-08-06T13:32:37Z")

</div>

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](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

---

<div class="post-metadata">

### Author: ![zweiglimmergneis](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/zweiglimmergneis/32/7892_2.png) [@zweiglimmergneis](https://discourse.julialang.org/u/zweiglimmergneis)
#### Post date: [August 6, 2022, 2:40pm UTC](https://discourse.julialang.org/t/can-someone-review-my-julia-notebook/85396/2 "2022-08-06T14:40:55Z")

</div>

Hi purport,

```julia
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.

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

```

and

```julia
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.

---

<div class="post-metadata">

### Author: ![purport](https://avatars.discourse-cdn.com/v4/letter/p/f07891/32.png) [@purport](https://discourse.julialang.org/u/purport)
#### Post date: [August 6, 2022, 3:08pm UTC](https://discourse.julialang.org/t/can-someone-review-my-julia-notebook/85396/3 "2022-08-06T15:08:18Z")

</div>

Thanks for the tips!
