Converting numbers into string representations

I quiet like this one. My first go program snippet without any peaking or googling. I’m proud, though it could be improved with a bit of struct magic and such and such. And it only counts ’till 1000. package main import "fmt" var words = map[int]string{1: "one", 2: "two", 3: "three", 4: "four", 5: "five", 6: "six", 7: "seven", 8: "eight", 9: "nine", 10: "ten", 11: "eleven", 12: "twelve", 13: "thirteen", 14: "fourteen", 15: "fifteen", 16: "sixteen", 17: "seventeen", 18: "eighteen", 19: "nineteen", 20: "twenty", 30: "thirty", 40: "forty", 50: "fifty", 60: "sixty", 70: "seventy", 80: "eighty", 90: "ninety"} // CountLetters count the letters in a long string number representation func CountLetters(limit int) { myLongNumberString := "" for i := 1; i <= limit; i++ { addLettersToMyString(&myLongNumberString, i) } // fmt....

July 19, 2015 · 2 min · hannibal

Bitwise & Operator

The first, and only time so far, that I got to use the bitwise & operator. I enjoyed doing so!! And of course from now on, I’ll be looking for more opportunities to (ab)use it. package secret import "sort" const REVERSE = 16 func Handshake(code int) []string { // binary_rep := convertDecimalToBinary(code) if code < { return nil } secret_map := map[int]string { 1: "wink", 2: "double blink", 4: "close your eyes", 8: "jump", } var keys []int for k := range secret_map { keys = append(keys, k) } // To make sure iteration is always in the same order....

July 15, 2015 · 1 min · hannibal