Model alphabet codes

Maps in Clojure are used to model key and value pairs.

  • Keys must be unique within a map.
  • A key can be a number, string or keyword.

Vectors in Clojure are a general data structure that are good for handing any kind of information.

Note Define a data structure where each letter of the alphabet is represented by a 6 digit binary code

Lets define a name called alphabet that is bound to a map. Each key in the map is a character of the alphabet and each value is a vector of numbers that represent a binary code.

The map also includes a binary code for a full stop and space character

  1. (def alphabet {"A" [0 1 0 0 0 1]
  2. "B" [0 0 1 0 1 0]
  3. "C" [0 1 0 0 1 0]
  4. "D" [1 0 1 0 0 0]
  5. "E" [1 0 1 1 0 0]
  6. "F" [1 1 0 1 0 0]
  7. "G" [1 0 0 1 1 0]
  8. "H" [1 0 1 0 0 1]
  9. "I" [1 1 1 0 0 0]
  10. "J" [0 0 1 1 1 1]
  11. "K" [0 1 0 1 0 1]
  12. "L" [1 1 1 0 0 1]
  13. "M" [1 1 1 0 1 1]
  14. "N" [0 1 1 1 0 1]
  15. "O" [1 1 0 1 1 0]
  16. "P" [1 1 1 1 1 0]
  17. "Q" [1 0 1 1 1 0]
  18. "R" [1 1 1 1 0 0]
  19. "S" [0 1 1 1 1 0]
  20. "T" [1 0 0 1 1 1]
  21. "U" [0 0 1 0 1 1]
  22. "V" [0 1 1 0 0 1]
  23. "W" [1 1 0 1 0 1]
  24. "X" [1 0 1 0 1 0]
  25. "Y" [1 0 0 0 1 1]
  26. "Z" [1 1 0 0 1 1]
  27. "." [1 0 1 1 0 1]
  28. " " [0 0 1 0 0 0]})