| encode syndrome sent received repaired location |
encode := [:number | | word |
 word := Array new: 7 withAll: 0.
 #(3 5 6 7) withIndexDo: [:position :bit |
  word at: position put: (number bitAt: bit)].
 #(1 2 4) do: [:mask | | parity |
  parity := 0.
  #(3 5 6 7) do: [:position |
   (position bitAnd: mask) ~= 0 ifTrue: [
    parity := parity bitXor: (word at: position)]].
  word at: mask put: parity].
 word].
syndrome := [:word | | result |
 result := 0.
 1 to: 7 do: [:position |
  (word at: position) = 1 ifTrue: [
   result := result bitXor: position]].
 result].
sent := encode value: 11.
received := sent copy.
received at: 6 put: ((received at: 6) bitXor: 1).
repaired := received copy.
location := syndrome value: repaired.
location ~= 0 ifTrue: [
 repaired at: location
  put: ((repaired at: location) bitXor: 1)].
{location. repaired = sent. syndrome value: repaired.
 received = sent}
