Ad

Propose a solution to fix backticks in Telegram messages
There can be two types:

  • singular backticks `
  • triple backticks ```

Add backticks to the end of message:
`malformed => `malformed`
```code` => ```code```

package kata
import "strings"

func FixMarkdown(text string) string {
  text = strings.TrimRight(text, "`")
	tripleCnt := strings.Count(text, "```")
	singleCnt := strings.Count(strings.Replace(text, "```", "", -1), "`")

	if tripleCnt % 2 == 1 {
		text += "```"
	}
	if singleCnt % 2 == 1 {
		text += "`"
	}

	return text
}

math magic

Code
Diff
  • package kumite
    
    import "time"
    import "math"
    
    func CheckWorkHours(dateTime time.Time) bool {
      if math.Abs(float64(dateTime.Weekday()) - 3) == 3 {
        return false
      }
      
      hour := dateTime.Hour()
      return 8 <= hour && hour < 18
    }
    • package kumite
    • import "time"
    • import "math"
    • func CheckWorkHours(dateTime time.Time) bool {
    • day := dateTime.Weekday()
    • if day < time.Monday || day > time.Friday {
    • if math.Abs(float64(dateTime.Weekday()) - 3) == 3 {
    • return false
    • }
    • hour := dateTime.Hour()
    • return 8 <= hour && hour < 18
    • }
Code
Diff
  • package kata
    
    func Multiple3And5(n int) bool {
      return n - 15 * (n / 15) == 0
    }
    • package kata
    • func Multiple3And5(n int) bool {
    • return n%3==0 && n%5==0
    • return n - 15 * (n / 15) == 0
    • }

no number usage

thoughts:

  • somehow we need to get (2 * 5) ** 2 = 100
  • anything ** 0 => 1
  • we need to get 2 (so it is basically 1 + 1)
  • need to get 5 with shortest way possible (i dont like toString().length, so it can be improved)
  • maybe there is a way to get 2 in a short way
Code
Diff
  • returnhundred = () => ((![]).toString().length * ([] ** [] + [] ** [])) ** ([] ** [] + [] ** [])
    • returnhundred=()=>+`${10**2}`
    • returnhundred = () => ((![]).toString().length * ([] ** [] + [] ** [])) ** ([] ** [] + [] ** [])

Considering leap years

Code
Diff
  • package kata
    
    // CalcAgeOnMars calculates the age on Mars from on a age on Earth 
    func CalcAgeOnMars(age int) int {
      return int(float64(age) * 365.25 / 686.97)
    }
    
    • package kata
    • // CalcAgeOnMars calculates the age on Mars from on a age on Earth
    • func CalcAgeOnMars(age int) int {
    • return age * 365 / 687
    • return int(float64(age) * 365.25 / 686.97)
    • }