Prompt:
import (
    "math"
)

// Check if in given list of numbers, are any two numbers closer to each other than given threshold.
// >>> HasCloseElements([]float64{1.0, 2.0, 3.0}, 0.5)
// false
// >>> HasCloseElements([]float64{1.0, 2.8, 3.0, 4.0, 5.0, 2.0}, 0.3)
// true
func HasCloseElements(numbers []float64, threshold float64) bool {

    for i := 0; i < len(numbers); i++ {
        for j := i + 1; j < len(numbers); j++ {
            var distance float64 = math.Abs(numbers[i] - numbers[j])
            if distance < threshold {
                return true
            }
        }
    }
    return false
}

func TestHasCloseElements(t *testing.T) {
    assert := assert.New(t)
    assert.Equal(true, HasCloseElements([]float64{11.0, 2.0, 3.9, 4.0, 5.0, 2.2}, 0.3))
    assert.Equal(false, HasCloseElements([]float64{1.0, 2.0, 3.9, 4.0, 5.0, 2.2}, 0.05))
    assert.Equal(true, HasCloseElements([]float64{1.0, 2.0, 5.9, 4.0, 5.0}, 0.95))
    assert.Equal(false, HasCloseElements([]float64{1.0, 2.0, 5.9, 4.0, 5.0}, 0.8))
    assert.Equal(true, HasCloseElements([]float64{1.0, 2.0, 3.0, 4.0, 5.0, 2.0}, 0.1))
    assert.Equal(true, HasCloseElements([]float64{1.1, 2.2, 3.1, 4.1, 5.1}, 1.0))
    assert.Equal(false, HasCloseElements([]float64{1.1, 2.2, 3.1, 4.1, 5.1}, 0.5))
}

package main

import (
    "testing"
    "github.com/stretchr/testify/assert"
)

func TestHasCloseElements(t *testing.T) {
    assert := assert.New(t)
    assert.Equal(false, HasCloseElements([]float64{1.0, 2.0, 3.0}, 0.5))
    assert.Equal(true, HasCloseElements([]float64{1.0, 2.8, 3.0, 4.0, 5.0, 2.0}, 0.3))
}


Prompt:
// Input to this function is a string containing multiple groups of nested parentheses. Your goal is to
// separate those group into separate strings and return the list of those.
// Separate groups are balanced (each open brace is properly closed) and not nested within each other
// Ignore any spaces in the input string.
// >>> SeparateParenGroups('( ) (( )) (( )( ))')
// ['()', '(())', '(()())']
func SeparateParenGroups(paren_string string) []string {

    result := make([]string, 0)
    current_string := make([]rune, 0)
    current_depth := 0

    for _, c := range paren_string {
        if c == '(' {
            current_depth += 1
            current_string = append(current_string, c)
        }else if c== ')'{
            current_depth -= 1
            current_string = append(current_string, c)

            if current_depth == 0{
                result = append(result, string(current_string))
                current_string =  make([]rune, 0)
            }
        }

    }
    return result
}

package main

import (
    "testing"
    "github.com/stretchr/testify/assert"
)

func TestSeparateParenGroups(t *testing.T) {
    assert := assert.New(t)
    assert.Equal([]string{"()", "(())", "(()())"}, SeparateParenGroups("( ) (( )) (( )( ))"))
}


Prompt:
import (
    "math"
)

// Given a positive floating point number, it can be decomposed into
// and integer part (largest integer smaller than given number) and decimals
// (leftover part always smaller than 1).
//
// Return the decimal part of the number.
// >>> TruncateNumber(3.5)
// 0.5
func TruncateNumber(number float64) float64 {

func TestTruncateNumber(t *testing.T) {
    assert := assert.New(t)
    assert.Equal(0.5, TruncateNumber(3.5))
    assert.Equal(true, math.Abs(TruncateNumber(1.33)-0.33) < 1e-6)
    assert.Equal(true, math.Abs(TruncateNumber(123.456)-0.456) < 1e-6)
}

package main

import (
    "testing"
    "github.com/stretchr/testify/assert"
)

func TestTruncateNumber(t *testing.T) {
    assert := assert.New(t)
    assert.Equal(0.5, TruncateNumber(3.5))
}


Prompt:
// You're given a list of deposit and withdrawal operations on a bank account that starts with
// zero balance. Your task is to detect if at any point the balance of account fallls below zero, and
// at that point function should return true. Otherwise it should return false.
// >>> BelowZero([1, 2, 3])
// false
// >>> BelowZero([1, 2, -4, 5])
// true
func BelowZero(operations []int) bool {

    balance := 0
    for _, op := range operations {
        balance += op
        if balance < 0 {
            return true
        }
    }
    return false
}

func TestBelowZero(t *testing.T) {
    assert := assert.New(t)
    assert.Equal(false, BelowZero([]int{}))
    assert.Equal(false, BelowZero([]int{1, 2, -3, 1, 2, -3}))
    assert.Equal(true, BelowZero([]int{1, 2, -4, 5, 6}))
    assert.Equal(false, BelowZero([]int{1, -1, 2, -2, 5, -5, 4, -4}))
    assert.Equal(true, BelowZero([]int{1, -1, 2, -2, 5, -5, 4, -5}))
    assert.Equal(true, BelowZero([]int{1, -2, 2, -2, 5, -5, 4, -4}))
}

package main

import (
    "testing"
    "github.com/stretchr/testify/assert"
)

func TestBelowZero(t *testing.T) {
    assert := assert.New(t)
    assert.Equal(false, BelowZero([]int{1, 2, 3}))
    assert.Equal(true, BelowZero([]int{1, 2, -4, 5}))
}


Prompt:
import (
    "math"
)

// For a given list of input numbers, calculate Mean Absolute Deviation
// around the mean of this dataset.
// Mean Absolute Deviation is the average absolute difference between each
// element and a centerpoint (mean in this case):
// MAD = average | x - x_mean |
// >>> MeanAbsoluteDeviation([1.0, 2.0, 3.0, 4.0])
// 1.0
func MeanAbsoluteDeviation(numbers []float64) float64 {

    sum := func(numbers []float64) float64 {
        sum := 0.0
        for _, num := range numbers {
            sum += num
        }
        return sum
    }

    mean := sum(numbers) / float64(len(numbers))
    numList := make([]float64, 0)
    for _, x := range numbers {
        numList = append(numList, math.Abs(x-mean))
    }
    return sum(numList) / float64(len(numbers))
}

func TestMeanAbsoluteDeviation(t *testing.T) {
    assert := assert.New(t)
    assert.Equal(true, math.Abs(MeanAbsoluteDeviation([]float64{1.0, 2.0, 3.0})-2.0/3.0) < 1e-6)
    assert.Equal(true, math.Abs(MeanAbsoluteDeviation([]float64{1.0, 2.0, 3.0, 4.0})-1.0) < 1e-6)
    assert.Equal(true, math.Abs(MeanAbsoluteDeviation([]float64{1.0, 2.0, 3.0, 4.0, 5.0})-6.0/5.0) < 1e-6)

}

package main

import (
    "testing"
    "github.com/stretchr/testify/assert"
)

func TestMeanAbsoluteDeviation(t *testing.T) {
    assert := assert.New(t)
    assert.Equal(true, math.Abs(MeanAbsoluteDeviation([]float64{1.0, 2.0, 3.0, 4.0})-1.0) < 1e-6)
}


Prompt:
// Insert a number 'delimeter' between every two consecutive elements of input list `numbers'
// >>> Intersperse([], 4)
// []
// >>> Intersperse([1, 2, 3], 4)
// [1, 4, 2, 4, 3]
func Intersperse(numbers []int, delimeter int) []int {

    result := make([]int, 0)
    if len(numbers) == 0 {
        return result
    }
    for i := 0; i < len(numbers)-1; i++ {
        n := numbers[i]
        result = append(result, n)
        result = append(result, delimeter)
    }
    result = append(result, numbers[len(numbers)-1])
    return result
}

func TestIntersperse(t *testing.T) {
    assert := assert.New(t)
    assert.Equal([]int{}, Intersperse([]int{}, 7))
    assert.Equal([]int{5, 8, 6, 8, 3, 8, 2}, Intersperse([]int{5, 6, 3, 2}, 8))
    assert.Equal([]int{2, 2, 2, 2, 2}, Intersperse([]int{2, 2, 2}, 2))
}

package main

import (
    "testing"
    "github.com/stretchr/testify/assert"
)

func TestIntersperse(t *testing.T) {
    assert := assert.New(t)
    assert.Equal([]int{}, Intersperse([]int{}, 4))
    assert.Equal([]int{1,4,2,4,3}, Intersperse([]int{1,2,3}, 4))
}


Prompt:
import (
    "math"
    "strings"
)

// Input to this function is a string represented multiple groups for nested parentheses separated by spaces.
// For each of the group, output the deepest level of nesting of parentheses.
// E.g. (()()) has maximum two levels of nesting while ((())) has three.
//
// >>> ParseNestedParens('(()()) ((())) () ((())()())')
// [2, 3, 1, 3]
func ParseNestedParens(paren_string string) []int {

    parse_paren_group := func(s string) int {
        depth := 0
        max_depth := 0
        for _, c := range s {
            if c == '(' {
                depth += 1
                max_depth = int(math.Max(float64(depth), float64(max_depth)))
            } else {
                depth -= 1
            }
        }
        return max_depth
    }
    result := make([]int, 0)
    for _, x := range strings.Split(paren_string, " ") {
        result = append(result, parse_paren_group(x))
    }
    return result

}

func TestParseNestedParens(t *testing.T) {
    assert := assert.New(t)
    assert.Equal([]int{2, 3, 1, 3}, ParseNestedParens("(()()) ((())) () ((())()())"))
    assert.Equal([]int{1, 2, 3, 4}, ParseNestedParens("() (()) ((())) (((())))"))
    assert.Equal([]int{4}, ParseNestedParens("(()(())((())))"))
}

package main

import (
    "testing"
    "github.com/stretchr/testify/assert"
)

func TestParseNestedParens(t *testing.T) {
    assert := assert.New(t)
    assert.Equal([]int{2, 3, 1, 3}, ParseNestedParens("(()()) ((())) () ((())()())"))
}


Prompt:
import (
    "strings"
)

// Filter an input list of strings only for ones that contain given substring
// >>> FilterBySubstring([], 'a')
// []
// >>> FilterBySubstring(['abc', 'bacd', 'cde', 'array'], 'a')
// ['abc', 'bacd', 'array']
func FilterBySubstring(stringList []string, substring string) []string {

    result := make([]string, 0)
    for _, x := range stringList {
        if strings.Index(x, substring) != -1 {
            result = append(result, x)
        }
    }
    return result
}

func TestFilterBySubstring(t *testing.T) {
    assert := assert.New(t)
    assert.Equal([]string{}, FilterBySubstring([]string{}, "john"))
    assert.Equal([]string{"xxx", "xxxAAA", "xxx"}, FilterBySubstring([]string{"xxx", "asd", "xxy", "john doe", "xxxAAA", "xxx"}, "xxx"))
    assert.Equal([]string{"xxx", "aaaxxy", "xxxAAA", "xxx"}, FilterBySubstring([]string{"xxx", "asd", "aaaxxy", "john doe", "xxxAAA", "xxx"}, "xx"))
    assert.Equal([]string{"grunt", "prune"}, FilterBySubstring([]string{"grunt", "trumpet", "prune", "gruesome"}, "run"))
}

package main

import (
    "testing"
    "github.com/stretchr/testify/assert"
)

func TestFilterBySubstring(t *testing.T) {
    assert := assert.New(t)
    assert.Equal([]string{}, FilterBySubstring([]string{}, "a"))
    assert.Equal([]string{"abc", "bacd", "array"}, FilterBySubstring([]string{"abc", "bacd", "cde", "array"}, "a"))
}


Prompt:
// For a given list of integers, return a tuple consisting of a sum and a product of all the integers in a list.
// Empty sum should be equal to 0 and empty product should be equal to 1.
// >>> SumProduct([])
// (0, 1)
// >>> SumProduct([1, 2, 3, 4])
// (10, 24)
func SumProduct(numbers []int) [2]int {

    sum_value := 0
    prod_value := 1

    for _, n := range numbers {
        sum_value += n
        prod_value *= n
    }
    return [2]int{sum_value, prod_value}
}

func TestSumProduct(t *testing.T) {
    assert := assert.New(t)
    assert.Equal([2]int{0, 1}, SumProduct([]int{}))
    assert.Equal([2]int{3, 1}, SumProduct([]int{1, 1, 1}))
    assert.Equal([2]int{100, 0}, SumProduct([]int{100, 0}))
    assert.Equal([2]int{3 + 5 + 7, 3 * 5 * 7}, SumProduct([]int{3, 5, 7}))
    assert.Equal([2]int{10, 10}, SumProduct([]int{10}))
}

package main

import (
    "testing"
    "github.com/stretchr/testify/assert"
)

func TestSumProduct(t *testing.T) {
    assert := assert.New(t)
    assert.Equal([2]int{0, 1}, SumProduct([]int{}))
    assert.Equal([2]int{10,24}, SumProduct([]int{1, 2,3,4}))
}


Prompt:
import (
    "math"
)

// From a given list of integers, generate a list of rolling maximum element found until given moment
// in the sequence.
// >>> RollingMax([1, 2, 3, 2, 3, 4, 2])
// [1, 2, 3, 3, 3, 4, 4]
func RollingMax(numbers []int) []int {

    running_max := math.MinInt32
    result := make([]int, 0)

    for _, n := range numbers {
        if running_max == math.MinInt32 {
            running_max = n
        } else {
            running_max = int(math.Max(float64(running_max), float64(n)))
        }
        result = append(result, running_max)
    }

    return result
}

func TestRollingMax(t *testing.T) {
    assert := assert.New(t)
    assert.Equal([]int{}, RollingMax([]int{}))
    assert.Equal([]int{1, 2, 3, 4}, RollingMax([]int{1, 2, 3, 4}))
    assert.Equal([]int{4, 4, 4, 4}, RollingMax([]int{4, 3, 2, 1}))
    assert.Equal([]int{3, 3, 3, 100, 100}, RollingMax([]int{3, 2, 3, 100, 3}))
}

package main

import (
    "testing"
    "github.com/stretchr/testify/assert"
)

func TestRollingMax(t *testing.T) {
    assert := assert.New(t)
    assert.Equal([]int{1, 2, 3,3, 3, 4, 4}, RollingMax([]int{1, 2, 3, 2, 3, 4, 2}))
}


Prompt:
import (
    "strings"
)

// Test if given string is a palindrome.
func IsPalindrome(str string) bool {
    runes := []rune(str)
    result := make([]rune, 0)
    for i := len(runes) - 1; i >= 0; i-- {
        result = append(result, runes[i])
    }
    return str == string(result)
}
// Find the shortest palindrome that begins with a supplied string.
// Algorithm idea is simple:
// - Find the longest postfix of supplied string that is a palindrome.
// - Append to the end of the string reverse of a string prefix that comes before the palindromic suffix.
// >>> MakePalindrome('')
// ''
// >>> MakePalindrome('cat')
// 'catac'
// >>> MakePalindrome('cata')
// 'catac'
func MakePalindrome(str string) string {

    if strings.TrimSpace(str) == "" {
        return ""
    }
    beginning_of_suffix := 0
    runes := []rune(str)
    for !IsPalindrome(string(runes[beginning_of_suffix:])) {
        beginning_of_suffix += 1
    }
    result := make([]rune, 0)
    for i := len(str[:beginning_of_suffix]) - 1; i >= 0; i-- {
        result = append(result, runes[i])
    }
    return str + string(result)
}

func TestMakePalindrome(t *testing.T) {
    assert := assert.New(t)
    assert.Equal("", MakePalindrome(""))
    assert.Equal("x", MakePalindrome("x"))
    assert.Equal("xyzyx", MakePalindrome("xyz"))
    assert.Equal("xyx", MakePalindrome("xyx"))
    assert.Equal("jerryrrej", MakePalindrome("jerry"))
}

package main

import (
    "testing"
    "github.com/stretchr/testify/assert"
)

func TestMakePalindrome(t *testing.T) {
    assert := assert.New(t)
    assert.Equal("", MakePalindrome(""))
    assert.Equal("catac", MakePalindrome("cat"))
    assert.Equal("catac", MakePalindrome("cata"))
}


Prompt:
import (
    "fmt"
)

// Input are two strings a and b consisting only of 1s and 0s.
// Perform binary XOR on these inputs and return result also as a string.
// >>> StringXor('010', '110')
// '100'
func StringXor(a string, b string) string {

    s2b := func(bs string) int32 {
        result := int32(0)
        runes := []rune(bs)
        for _, r := range runes {
            result = result << 1
            temp := r - rune('0')
            result += temp
        }
        return result
    }
    ab := s2b(a)
    bb := s2b(b)
    res := ab ^ bb
    sprint := fmt.Sprintf("%b", res)
    for i := 0; i < len(a)-len(sprint); i++ {
        sprint = "0" + sprint
    }
    return sprint
}

func TestStringXor(t *testing.T) {
    assert := assert.New(t)
    assert.Equal("010010", StringXor("111000", "101010"))
    assert.Equal("0", StringXor("1", "1"))
    assert.Equal("0101", StringXor("0101", "0000"))
}

package main

import (
    "testing"
    "github.com/stretchr/testify/assert"
)

func TestStringXor(t *testing.T) {
    assert := assert.New(t)
    assert.Equal("100", StringXor("010", "110"))
}


Prompt:
// Out of list of strings, return the Longest one. Return the first one in case of multiple
// strings of the same length. Return nil in case the input list is empty.
// >>> Longest([])
// nil
// >>> Longest(['a', 'b', 'c'])
// 'a'
// >>> Longest(['a', 'bb', 'ccc'])
// 'ccc'
func Longest(strings []string) interface{}{

    if strings == nil || len(strings) == 0 {
        return nil
    }
    maxlen := 0
    maxi := 0
    for i, s := range strings {
        if maxlen < len(s) {
            maxlen = len(s)
            maxi = i
        }
    }
    return strings[maxi]
}

func TestLongest(t *testing.T) {
	assert := assert.New(t)
	assert.Equal(nil, Longest([]string{}))
	assert.Equal("x", Longest([]string{"x", "y", "z"}))
	assert.Equal("zzzz", Longest([]string{"x", "yyy", "zzzz", "www", "kkkk", "abc"}))
}

package main

import (
    "testing"
    "github.com/stretchr/testify/assert"
)

func TestLongest(t *testing.T) {
	assert := assert.New(t)
	assert.Equal(nil, Longest([]string{}))
	assert.Equal("a", Longest([]string{"a", "b", "c"}))
	assert.Equal("ccc", Longest([]string{"a", "bb", "ccc"}))
}


Prompt:
// Return a greatest common divisor of two integers a and b
// >>> GreatestCommonDivisor(3, 5)
// 1
// >>> GreatestCommonDivisor(25, 15)
// 5
func GreatestCommonDivisor(a int,b int) int{

    if b < 2 {
		return b
	}
	var gcd int = 1
	for i := 2; i < b; i++ {
		if a%i == 0 && b%i == 0 {
			gcd = i
		}
	}
	return gcd
}

func TestGreatestCommonDivisor(t *testing.T) {
    assert := assert.New(t)
    assert.Equal(1, GreatestCommonDivisor(3, 7))
    assert.Equal(5, GreatestCommonDivisor(10, 15))
    assert.Equal(7, GreatestCommonDivisor(49, 14))
    assert.Equal(12, GreatestCommonDivisor(144, 60))
}

package main

import (
    "testing"
    "github.com/stretchr/testify/assert"
)

func TestGreatestCommonDivisor(t *testing.T) {
    assert := assert.New(t)
    assert.Equal(1, GreatestCommonDivisor(3, 5))
    assert.Equal(5, GreatestCommonDivisor(25, 15))
}


Prompt:
// Return list of all prefixes from shortest to longest of the input string
// >>> AllPrefixes('abc')
// ['a', 'ab', 'abc']
func AllPrefixes(str string) []string{

    prefixes := make([]string, 0, len(str))
	for i := 0; i < len(str); i++ {
		prefixes = append(prefixes, str[:i+1])
	}
	return prefixes
}

func TestAllPrefixes(t *testing.T) {
    assert := assert.New(t)
    assert.Equal([]string{}, AllPrefixes(""))
    assert.Equal([]string{"a", "as", "asd", "asdf", "asdfg", "asdfgh"}, AllPrefixes("asdfgh"))
    assert.Equal([]string{"W", "WW", "WWW"}, AllPrefixes("WWW"))
}

package main

import (
    "testing"
    "github.com/stretchr/testify/assert"
)

func TestAllPrefixes(t *testing.T) {
    assert := assert.New(t)
    assert.Equal([]string{"a", "ab", "abc"}, AllPrefixes("abc"))
}


Prompt:
import (
    "strconv"
)

// Return a string containing space-delimited numbers starting from 0 upto n inclusive.
// >>> StringSequence(0)
// '0'
// >>> StringSequence(5)
// '0 1 2 3 4 5'
func StringSequence(n int) string{

    var seq string
    for i := 0; i <= n; i++ {
        seq += strconv.Itoa(i)
        if i != n {
            seq += " "
        }
    }
    return seq
}

func TestStringSequence(t *testing.T) {
    assert := assert.New(t)
    assert.Equal("0", StringSequence(0))
    assert.Equal("0 1 2 3", StringSequence(3))
    assert.Equal("0 1 2 3 4 5 6 7 8 9 10", StringSequence(10))
}

package main

import (
    "testing"
    "github.com/stretchr/testify/assert"
)

func TestStringSequence(t *testing.T) {
    assert := assert.New(t)
    assert.Equal("0", StringSequence(0))
    assert.Equal("0 1 2 3 4 5", StringSequence(5))
}


Prompt:
import (
    "strings"
)

// Given a string, find out how many distinct characters (regardless of case) does it consist of
// >>> CountDistinctCharacters('xyzXYZ')
// 3
// >>> CountDistinctCharacters('Jerry')
// 4
func CountDistinctCharacters(str string) int{

    lower := strings.ToLower(str)
	count := 0
	set := make(map[rune]bool)
	for _, i := range lower {
		if set[i] == true {
			continue
		} else {
			set[i] = true
			count++
		}
	}
	return count
}

func TestCountDistinctCharacters(t *testing.T) {
    assert := assert.New(t)
    assert.Equal(0, CountDistinctCharacters(""))
    assert.Equal(5, CountDistinctCharacters("abcde"))
    assert.Equal(5, CountDistinctCharacters("abcde" + "cade" + "CADE"))
    assert.Equal(1, CountDistinctCharacters("aaaaAAAAaaaa"))
    assert.Equal(5, CountDistinctCharacters("Jerry jERRY JeRRRY"))
}

package main

import (
    "testing"
    "github.com/stretchr/testify/assert"
)

func TestCountDistinctCharacters(t *testing.T) {
    assert := assert.New(t)
    assert.Equal(3, CountDistinctCharacters("xyzXYZ"))
    assert.Equal(4, CountDistinctCharacters("Jerry"))
}


Prompt:
// Input to this function is a string representing musical notes in a special ASCII format.
// Your task is to parse this string and return list of integers corresponding to how many beats does each
// not last.
//
// Here is a legend:
// 'o' - whole note, lasts four beats
// 'o|' - half note, lasts two beats
// '.|' - quater note, lasts one beat
//
// >>> ParseMusic('o o| .| o| o| .| .| .| .| o o')
// [4, 2, 1, 2, 2, 1, 1, 1, 1, 4, 4]
func ParseMusic(music_string string) []int{

    note_map := map[string]int{"o": 4, "o|": 2, ".|": 1}
	split := strings.Split(music_string, " ")
	result := make([]int, 0)
	for _, x := range split {
		if i, ok := note_map[x]; ok {
			result = append(result, i)
		}
	}
	return result
}

func TestParseMusic(t *testing.T) {
    assert := assert.New(t)
    assert.Equal([]int{}, ParseMusic(""))
    assert.Equal([]int{4, 4, 4, 4}, ParseMusic("o o o o"))
    assert.Equal([]int{1, 1, 1, 1}, ParseMusic(".| .| .| .|"))
    assert.Equal([]int{2, 2, 1, 1, 4, 4, 4, 4}, ParseMusic("o| o| .| .| o o o o"))
    assert.Equal([]int{2, 1, 2, 1, 4, 2, 4, 2}, ParseMusic("o| .| o| .| o o| o o|"))
}

package main

import (
    "testing"
    "github.com/stretchr/testify/assert"
)

func TestParseMusic(t *testing.T) {
    assert := assert.New(t)
    assert.Equal([]int{4, 2, 1, 2, 2, 1, 1, 1, 1, 4, 4}, ParseMusic("o o| .| o| o| .| .| .| .| o o"))
}


Prompt:
// Find how many times a given substring can be found in the original string. Count overlaping cases.
// >>> HowManyTimes('', 'a')
// 0
// >>> HowManyTimes('aaa', 'a')
// 3
// >>> HowManyTimes('aaaa', 'aa')
// 3
func HowManyTimes(str string,substring string) int{

    times := 0
	for i := 0; i < (len(str) - len(substring) + 1); i++ {
		if str[i:i+len(substring)] == substring {
			times += 1
		}
	}
	return times
}

func TestHowManyTimes(t *testing.T) {
    assert := assert.New(t)
    assert.Equal(0, HowManyTimes("", "x"))
    assert.Equal(4, HowManyTimes("xyxyxyx", "x"))
    assert.Equal(4, HowManyTimes("cacacacac", "cac"))
    assert.Equal(1, HowManyTimes("john doe", "john"))
}

package main

import (
    "testing"
    "github.com/stretchr/testify/assert"
)

func TestHowManyTimes(t *testing.T) {
    assert := assert.New(t)
    assert.Equal(0, HowManyTimes("", "a"))
    assert.Equal(3, HowManyTimes("aaa", "a"))
    assert.Equal(3, HowManyTimes("aaaa", "aa"))
}


Prompt:
import (
    "sort"
    "strings"
)

// Input is a space-delimited string of numberals from 'zero' to 'nine'.
// Valid choices are 'zero', 'one', 'two', 'three', 'four', 'five', 'six', 'seven', 'eight' and 'nine'.
// Return the string with numbers sorted from smallest to largest
// >>> SortNumbers('three one five')
// 'one three five'
func SortNumbers(numbers string) string{

    valueMap := map[string]int{
		"zero":  0,
		"one":   1,
		"two":   2,
		"three": 3,
		"four":  4,
		"five":  5,
		"six":   6,
		"seven": 7,
		"eight": 8,
		"nine":  9,
	}
	stringMap := make(map[int]string)
	for s, i := range valueMap {
		stringMap[i] = s
	}
	split := strings.Split(numbers, " ")
	temp := make([]int, 0)
	for _, s := range split {
		if i, ok := valueMap[s]; ok {
			temp = append(temp, i)
		}
	}
	sort.Ints(temp)
	result := make([]string, 0)
	for _, i := range temp {
		result = append(result, stringMap[i])
	}
	return strings.Join(result, " ")
}

func TestSortNumbers(t *testing.T) {
    assert := assert.New(t)
    assert.Equal("", SortNumbers(""))
    assert.Equal("three", SortNumbers("three"))
    assert.Equal("three five nine", SortNumbers("three five nine"))
    assert.Equal("zero four five seven eight nine", SortNumbers("five zero four seven nine eight"))
    assert.Equal("zero one two three four five six", SortNumbers("six five four three two one zero"))
}

package main

import (
    "testing"
    "github.com/stretchr/testify/assert"
)

func TestSortNumbers(t *testing.T) {
    assert := assert.New(t)
    assert.Equal("one three five", SortNumbers("three one five"))
}


Prompt:
// From a supplied list of numbers (of length at least two) select and return two that are the closest to each
// other and return them in order (smaller number, larger number).
// >>> FindClosestElements([1.0, 2.0, 3.0, 4.0, 5.0, 2.2])
// (2.0, 2.2)
// >>> FindClosestElements([1.0, 2.0, 3.0, 4.0, 5.0, 2.0])
// (2.0, 2.0)
func FindClosestElements(numbers []float64) [2]float64 {

    distance := math.MaxFloat64
	var closestPair [2]float64
	for idx, elem := range numbers {
		for idx2, elem2 := range numbers {
			if idx != idx2 {
				if distance == math.MinInt64 {
					distance = math.Abs(elem - elem2)
					float64s := []float64{elem, elem2}
					sort.Float64s(float64s)
					closestPair = [2]float64{float64s[0], float64s[1]}
				} else {
					newDistance := math.Abs(elem - elem2)
					if newDistance < distance{
						distance = newDistance
						float64s := []float64{elem, elem2}
						sort.Float64s(float64s)
						closestPair = [2]float64{float64s[0], float64s[1]}
					}
				}
			}
		}
	}
	return closestPair
}

func TestFindClosestElements(t *testing.T) {
    assert := assert.New(t)
    assert.Equal([2]float64{3.9, 4.0}, FindClosestElements([]float64{1.0, 2.0, 3.9, 4.0, 5.0, 2.2}))
    assert.Equal([2]float64{5.0, 5.9}, FindClosestElements([]float64{1.0, 2.0, 5.9, 4.0, 5.0}))
    assert.Equal([2]float64{2.0, 2.2}, FindClosestElements([]float64{1.0, 2.0, 3.0, 4.0, 5.0, 2.2}))
    assert.Equal([2]float64{2.0, 2.0}, FindClosestElements([]float64{1.0, 2.0, 3.0, 4.0, 5.0, 2.0}))
    assert.Equal([2]float64{2.2, 3.1}, FindClosestElements([]float64{1.1, 2.2, 3.1, 4.1, 5.1}))
}

package main

import (
    "testing"
    "github.com/stretchr/testify/assert"
)

func TestFindClosestElements(t *testing.T) {
    assert := assert.New(t)
    assert.Equal([2]float64{2.0, 2.2}, FindClosestElements([]float64{1.0, 2.0, 3.0, 4.0, 5.0, 2.2}))
    assert.Equal([2]float64{2.0, 2.0}, FindClosestElements([]float64{1.0, 2.0, 3.0, 4.0, 5.0, 2.0}))
}


Prompt:
// Given list of numbers (of at least two elements), apply a linear transform to that list,
// such that the smallest number will become 0 and the largest will become 1
// >>> RescaleToUnit([1.0, 2.0, 3.0, 4.0, 5.0])
// [0.0, 0.25, 0.5, 0.75, 1.0]
func RescaleToUnit(numbers []float64) []float64 {

    smallest := numbers[0]
	largest := smallest
	for _, n := range numbers {
		if smallest > n {
			smallest = n
		}
		if largest < n {
			largest = n
		}
	}
	if smallest == largest {
		return numbers
	}
	for i, n := range numbers {
		numbers[i] = (n - smallest) / (largest - smallest)
	}
	return numbers
}

package main

import (
    "testing"
    "github.com/stretchr/testify/assert"
)

func TestRescaleToUnit(t *testing.T) {
    assert := assert.New(t)
    assert.Equal([]float64{0.0, 0.25, 0.5, 0.75, 1.0}, RescaleToUnit([]float64{1.0, 2.0, 3.0, 4.0, 5.0}))
}


Prompt:
// Filter given list of any values only for integers
// >>> FilterIntegers(['a', 3.14, 5])
// [5]
// >>> FilterIntegers([1, 2, 3, 'abc', {}, []])
// [1, 2, 3]
func FilterIntegers(values []interface{}) []int {

    result := make([]int, 0)
    for _, val := range values {
        switch i := val.(type) {
        case int:
            result = append(result, i)
        }
    }
    return result
}

func TestFilterIntegers(t *testing.T) {
    assert := assert.New(t)
    assert.Equal([]int{}, FilterIntegers([]interface{}{}))
    assert.Equal([]int{4, 9}, FilterIntegers([]interface{}{4, nil, []interface{}{}, 23.2, 9, "adasd"}))
    assert.Equal([]int{3, 3, 3}, FilterIntegers([]interface{}{3, 'c', 3, 3, 'a', 'b'}))
}

package main

import (
    "testing"
    "github.com/stretchr/testify/assert"
)

func TestFilterIntegers(t *testing.T) {
    assert := assert.New(t)
    assert.Equal([]int{5}, FilterIntegers([]interface{}{'a', 3.14, 5}))
    assert.Equal([]int{1,2,3}, FilterIntegers([]interface{}{1,2,3,"abc", nil, []interface{}{}}))
}


Prompt:
// Return length of given string
// >>> Strlen('')
// 0
// >>> Strlen('abc')
// 3
func Strlen(str string) int {

func TestStrlen(t *testing.T) {
    assert := assert.New(t)
    assert.Equal(0, Strlen(""))
    assert.Equal(1, Strlen("x"))
    assert.Equal(9, Strlen("asdasnakj"))
}

package main

import (
    "testing"
    "github.com/stretchr/testify/assert"
)

func TestStrlen(t *testing.T) {
    assert := assert.New(t)
    assert.Equal(0, Strlen(""))
    assert.Equal(3, Strlen("abc"))
}


Prompt:
// For a given number n, find the largest number that divides n evenly, smaller than n
// >>> LargestDivisor(15)
// 5
func LargestDivisor(n int) int {

    for i := n - 1; i > 0; i-- {
		if n % i == 0 {
			return i
		}
	}
	return 0
}

func TestLargestDivisor(t *testing.T) {
    assert := assert.New(t)
    assert.Equal(1, LargestDivisor(3))
    assert.Equal(1, LargestDivisor(7))
    assert.Equal(5, LargestDivisor(10))
    assert.Equal(50, LargestDivisor(100))
    assert.Equal(7, LargestDivisor(49))
}

package main

import (
    "testing"
    "github.com/stretchr/testify/assert"
)

func TestLargestDivisor(t *testing.T) {
    assert := assert.New(t)
    assert.Equal(5, LargestDivisor(15))
}


Prompt:
import (
    "math"
)

// Return list of prime factors of given integer in the order from smallest to largest.
// Each of the factors should be listed number of times corresponding to how many times it appeares in factorization.
// Input number should be equal to the product of all factors
// >>> Factorize(8)
// [2, 2, 2]
// >>> Factorize(25)
// [5, 5]
// >>> Factorize(70)
// [2, 5, 7]
func Factorize(n int) []int {

    fact := make([]int, 0)
	for i := 2; i <= int(math.Sqrt(float64(n))+1); {
		if n%i == 0 {
			fact = append(fact, i)
			n = n / i
		} else {
			i++
		}
	}
	if n > 1 {
		fact = append(fact, n)
	}
	return fact
}

func TestFactorize(t *testing.T) {
    assert := assert.New(t)
    assert.Equal([]int{2}, Factorize(2))
    assert.Equal([]int{2, 2}, Factorize(4))
    assert.Equal([]int{2, 2, 2}, Factorize(8))
    assert.Equal([]int{3, 19}, Factorize(3 * 19))
    assert.Equal([]int{3, 3, 19, 19}, Factorize(3 * 19 * 3 * 19))
    assert.Equal([]int{3, 3, 3, 19, 19, 19}, Factorize(3 * 19 * 3 * 19 * 3 * 19))
    assert.Equal([]int{3, 19, 19, 19}, Factorize(3 * 19 * 19 * 19))
    assert.Equal([]int{2, 3, 3}, Factorize(3 * 2 * 3))
}

package main

import (
    "testing"
    "github.com/stretchr/testify/assert"
)

func TestFactorize(t *testing.T) {
    assert := assert.New(t)
    assert.Equal([]int{2, 2, 2}, Factorize(8))
    assert.Equal([]int{5,5}, Factorize(25))
    assert.Equal([]int{2,5,7}, Factorize(70))
}


Prompt:
// From a list of integers, remove all elements that occur more than once.
// Keep order of elements left the same as in the input.
// >>> RemoveDuplicates([1, 2, 3, 2, 4])
// [1, 3, 4]
func RemoveDuplicates(numbers []int) []int {

    c := make(map[int] int)
	for _, number := range numbers {
		if i, ok := c[number]; ok {
			c[number] = i + 1
		} else {
			c[number] = 1
		}
	}
	result := make([]int, 0)
	for _, number := range numbers {
		if c[number] <= 1 {
			result = append(result, number)
		}
	}
	return result
}

func TestRemoveDuplicates(t *testing.T) {
    assert := assert.New(t)
    assert.Equal([]int{}, RemoveDuplicates([]int{}))
    assert.Equal([]int{1, 2, 3, 4}, RemoveDuplicates([]int{1, 2, 3,4}))
    assert.Equal([]int{1, 4, 5}, RemoveDuplicates([]int{1, 2, 3, 2,4, 3, 5}))
}

package main

import (
    "testing"
    "github.com/stretchr/testify/assert"
)

func TestRemoveDuplicates(t *testing.T) {
    assert := assert.New(t)
    assert.Equal([]int{1,  3, 4}, RemoveDuplicates([]int{1,2, 3,2,4}))
}


Prompt:
import (
    "strings"
)

// For a given string, flip lowercase characters to uppercase and uppercase to lowercase.
// >>> FlipCase('Hello')
// 'hELLO'
func FlipCase(str string) string {

    result := []rune{}
    for _, c := range str {
        if c >= 'A' && c <= 'Z' {
            result = append(result, 'a' + ((c - 'A' + 26) % 26))
        } else if c >= 'a' && c <= 'z' {
            result = append(result, 'A' + ((c - 'a' + 26) % 26))
        } else {
            result = append(result, c)
        }
    }
    return string(result)
}

func TestFlipCase(t *testing.T) {
    assert := assert.New(t)
    assert.Equal("", FlipCase(""))
    assert.Equal("hELLO!", FlipCase("Hello!"))
    assert.Equal("tHESE VIOLENT DELIGHTS HAVE VIOLENT ENDS",FlipCase("These violent delights have violent ends"))
}

package main

import (
    "testing"
    "github.com/stretchr/testify/assert"
)

func TestFlipCase(t *testing.T) {
    assert := assert.New(t)
    assert.Equal("hELLO", FlipCase("Hello"))
}


Prompt:
// Concatenate list of strings into a single string
// >>> Concatenate([])
// ''
// >>> Concatenate(['a', 'b', 'c'])
// 'abc'
func Concatenate(strings []string) string {

    if len(strings) == 0 {
		return ""
	}
	return strings[0] + Concatenate(strings[1:])
}

func TestConcatenate(t *testing.T) {
    assert := assert.New(t)
    assert.Equal("", Concatenate([]string{}))
    assert.Equal("xyz", Concatenate([]string{"x", "y", "z"}))
    assert.Equal("xyzwk", Concatenate([]string{"x", "y","z", "w", "k"}))
}

package main

import (
    "testing"
    "github.com/stretchr/testify/assert"
)

func TestConcatenate(t *testing.T) {
    assert := assert.New(t)
    assert.Equal("", Concatenate([]string{}))
    assert.Equal("abc", Concatenate([]string{"a", "b", "c"}))
}


Prompt:
// Filter an input list of strings only for ones that start with a given prefix.
// >>> FilterByPrefix([], 'a')
// []
// >>> FilterByPrefix(['abc', 'bcd', 'cde', 'array'], 'a')
// ['abc', 'array']
func FilterByPrefix(strings []string,prefix string) []string {

    if len(strings) == 0 {
        return []string{}
    }
    res := make([]string, 0, len(strings))
	for _, s := range strings {
		if s[:len(prefix)] == prefix {
			res = append(res, s)
		}
	}
	return res
}

func TestFilterByPrefix(t *testing.T) {
    assert := assert.New(t)
    assert.Equal([]string{}, FilterByPrefix([]string{}, "john"))
    assert.Equal([]string{"xxx", "xxxAAA", "xxx"}, FilterByPrefix([]string{"xxx", "asd", "xxy", "john doe", "xxxAAA", "xxx"}, "xxx"))
}

package main

import (
    "testing"
    "github.com/stretchr/testify/assert"
)

func TestFilterByPrefix(t *testing.T) {
    assert := assert.New(t)
    assert.Equal([]string{}, FilterByPrefix([]string{}, "a"))
    assert.Equal([]string{"abc", "array"}, FilterByPrefix([]string{"abc", "bcd", "cde", "array"}, "a"))
}


Prompt:
// Return only positive numbers in the list.
// >>> GetPositive([-1, 2, -4, 5, 6])
// [2, 5, 6]
// >>> GetPositive([5, 3, -5, 2, -3, 3, 9, 0, 123, 1, -10])
// [5, 3, 2, 3, 9, 123, 1]
func GetPositive(l []int) []int {

    res := make([]int, 0)
    for _, x := range l {
        if x > 0 {
            res = append(res, x)
        }
    }
    return res
}

func TestGetPositive(t *testing.T) {
    assert := assert.New(t)
    assert.Equal([]int{4, 5, 6}, GetPositive([]int{-1, -2, 4,5, 6}))
    assert.Equal([]int{5, 3, 2, 3, 3, 9, 123, 1}, GetPositive([]int{5, 3, -5, 2, 3, 3, 9, 0, 123, 1, -10}))
    assert.Equal([]int{}, GetPositive([]int{-1, -2}))
    assert.Equal([]int{}, GetPositive([]int{}))
}

package main

import (
    "testing"
    "github.com/stretchr/testify/assert"
)

func TestGetPositive(t *testing.T) {
    assert := assert.New(t)
    assert.Equal([]int{2, 5, 6}, GetPositive([]int{-1, 2, -4,5, 6}))
    assert.Equal([]int{5, 3, 2,  3, 9, 123, 1}, GetPositive([]int{5, 3, -5, 2, -3, 3, 9, 0, 123, 1, -10}))
}


Prompt:
// Return true if a given number is prime, and false otherwise.
// >>> IsPrime(6)
// false
// >>> IsPrime(101)
// true
// >>> IsPrime(11)
// true
// >>> IsPrime(13441)
// true
// >>> IsPrime(61)
// true
// >>> IsPrime(4)
// false
// >>> IsPrime(1)
// false
func IsPrime(n int) bool {

    if n <= 1 {
		return false
	}
	if n == 2 {
		return true
	}
	if n%2 == 0 {
		return false
	}
	for i := 3; i*i <= n; i += 2 {
		if n%i == 0 {
			return false
		}
	}
	return true
}

func TestIsPrime(t *testing.T) {
    assert := assert.New(t)
    assert.Equal(false, IsPrime(6))
    assert.Equal(true, IsPrime(101))
    assert.Equal(true, IsPrime(11))
    assert.Equal(true, IsPrime(13441))
    assert.Equal(true, IsPrime(61))
    assert.Equal(false, IsPrime(4))
    assert.Equal(false, IsPrime(1))
    assert.Equal(true, IsPrime(5))
    assert.Equal(true, IsPrime(11))
    assert.Equal(true, IsPrime(17))
    assert.Equal(false, IsPrime(5 * 17))
    assert.Equal(false, IsPrime(11 * 7))
    assert.Equal(false, IsPrime(13441 * 19))
}

package main

import (
    "testing"
    "github.com/stretchr/testify/assert"
)

func TestIsPrime(t *testing.T) {
    assert := assert.New(t)
    assert.Equal(false, IsPrime(6))
    assert.Equal(true, IsPrime(101))
    assert.Equal(true, IsPrime(11))
    assert.Equal(true, IsPrime(13441))
    assert.Equal(true, IsPrime(61))
    assert.Equal(false, IsPrime(4))
    assert.Equal(false, IsPrime(1))
}


Prompt:
import (
    "math"
)

// Evaluates polynomial with coefficients xs at point x.
// return xs[0] + xs[1] * x + xs[1] * x^2 + .... xs[n] * x^n
func Poly(xs []int, x float64) float64{
    sum := 0.0
    for i, coeff := range xs {
        sum += float64(coeff) * math.Pow(x,float64(i))
    }
    return sum
}
// xs are coefficients of a polynomial.
// FindZero find x such that Poly(x) = 0.
// FindZero returns only only zero point, even if there are many.
// Moreover, FindZero only takes list xs having even number of coefficients
// and largest non zero coefficient as it guarantees
// a solution.
// >>> round(FindZero([1, 2]), 2) # f(x) = 1 + 2x
// -0.5
// >>> round(FindZero([-6, 11, -6, 1]), 2) # (x - 1) * (x - 2) * (x - 3) = -6 + 11x - 6x^2 + x^3
// 1.0
func FindZero(xs []int) float64 {

    begin := -1.0
	end := 1.0
	for Poly(xs, begin)*Poly(xs, end) > 0 {
		begin *= 2
		end *= 2
	}
	for end-begin > 1e-10 {
		center := (begin + end) / 2
		if Poly(xs, center)*Poly(xs, begin) > 0 {
			begin = center
		} else {
			end = center
		}
	}
	return begin
}

func TestFindZero(t *testing.T) {
    assert := assert.New(t)
    randInt := func(min, max int) int {
        rng := rand.New(rand.NewSource(42))
        if min >= max || min == 0 || max == 0 {
            return max
        }
        return rng.Intn(max-min) + min
    }
    copyInts := func(src []int) []int {
        ints := make([]int, 0)
        for _, i := range src {
            ints = append(ints, i)
        }
        return ints
    }
    for i := 0; i < 100; i++ {
        ncoeff := 2 * randInt(1, 4)
        coeffs := make([]int, 0)
        for j := 0; j < ncoeff; j++ {
            coeff := randInt(-10, 10)
            if coeff == 0 {
                coeff = 1
            }
            coeffs = append(coeffs, coeff)
        }
        solution := FindZero(copyInts(coeffs))
        assert.Equal(true, math.Abs(Poly(coeffs,solution))<1e-4)
    }
}

package main

import (
    "testing"
    "math/rand"
    "math"
    "github.com/stretchr/testify/assert"
)

func TestFindZero(t *testing.T) {
  assert := assert.New(t)
    assert.Equal(true, math.Abs(FindZero([]int{1,2})+0.5+rand.NormFloat64()*0.0)<1e-4)
    assert.Equal(true, math.Abs(FindZero([]int{-6,11,-6,1})-1)<1e-4)
}


Prompt:
import (
    "sort"
)

// This function takes a list l and returns a list l' such that
// l' is identical to l in the indicies that are not divisible by three, while its values at the indicies that are divisible by three are equal
// to the values of the corresponding indicies of l, but sorted.
// >>> SortThird([1, 2, 3])
// [1, 2, 3]
// >>> SortThird([5, 6, 3, 4, 8, 9, 2])
// [2, 6, 3, 4, 8, 9, 5]
func SortThird(l []int) []int {

    temp := make([]int, 0)
	for i := 0; i < len(l); i = i + 3 {
		temp = append(temp, l[i])
	}
	sort.Ints(temp)
	j := 0
	for i := 0; i < len(l); i = i + 3 {
		l[i] = temp[j]
		j++
	}
	return l
}

package main

import (
    "testing"
    "github.com/stretchr/testify/assert"
)

func TestSortThird(t *testing.T) {
    assert := assert.New(t)
	same := func(src []int, target []int) bool {
		for i := 0; i < len(src); i++ {
			if src[i] != target[i] {
				return false
			}
		}
		return true
	}
	assert.Equal(true, same([]int{1, 2, 3}, SortThird([]int{1, 2, 3})))
	assert.Equal(true, same([]int{2, 6, 3, 4, 8, 9, 5}, SortThird([]int{5, 6, 3, 4, 8, 9, 2})))
}


Prompt:
import (
    "sort"
)

// Return sorted Unique elements in a list
// >>> Unique([5, 3, 5, 2, 3, 3, 9, 0, 123])
// [0, 2, 3, 5, 9, 123]
func Unique(l []int) []int {

    set := make(map[int]interface{})
	for _, i := range l {
		set[i]=nil
	}
	l = make([]int,0)
	for i, _ := range set {
		l = append(l, i)
	}
	sort.Ints(l)
	return l
}

func TestUnique(t *testing.T) {
    assert := assert.New(t)
    assert.Equal([]int{0, 2, 3, 5, 9, 123}, Unique([]int{5, 3,5, 2, 3, 3, 9, 0, 123}))
}

package main

import (
    "testing"
    "github.com/stretchr/testify/assert"
)


Prompt:
// Return maximum element in the list.
// >>> MaxElement([1, 2, 3])
// 3
// >>> MaxElement([5, 3, -5, 2, -3, 3, 9, 0, 123, 1, -10])
// 123
func MaxElement(l []int) int {

    max := l[0]
	for _, x := range l {
		if x > max {
			max = x
		}
	}
	return max
}

func TestMaxElement(t *testing.T) {
    assert := assert.New(t)
    assert.Equal(3, MaxElement([]int{1, 2, 3}))
    assert.Equal(124, MaxElement([]int{5, 3, -5, 2, -3, 3, 9,0, 124, 1, -10}))
}

package main

import (
    "testing"
    "github.com/stretchr/testify/assert"
)

func TestMaxElement(t *testing.T) {
    assert := assert.New(t)
    assert.Equal(3, MaxElement([]int{1, 2, 3}))
    assert.Equal(123, MaxElement([]int{5, 3, -5, 2, -3, 3, 9,0, 123, 1, -10}))
}


Prompt:
import (
	"strconv"
	"strings"
)

// Return the number of times the digit 7 appears in integers less than n which are divisible by 11 or 13.
// >>> FizzBuzz(50)
// 0
// >>> FizzBuzz(78)
// 2
// >>> FizzBuzz(79)
// 3
func FizzBuzz(n int) int {

    ns := make([]int, 0)
	for i := 0; i < n; i++ {
		if i%11 == 0 || i%13 == 0 {
			ns = append(ns, i)
		}
	}
	temp := make([]string, 0)
	for _, i := range ns {
		temp = append(temp, strconv.Itoa(i))
	}
	join := strings.Join(temp, "")
	ans := 0
	for _, c := range join {
		if c == '7' {
			ans++
		}
	}
	return ans
}

func TestFizzBuzz(t *testing.T) {
    assert := assert.New(t)
    assert.Equal(0, FizzBuzz(50))
    assert.Equal(2, FizzBuzz(78))
    assert.Equal(3, FizzBuzz(79))
    assert.Equal(3, FizzBuzz(100))
    assert.Equal(6, FizzBuzz(200))
    assert.Equal(192, FizzBuzz(4000))
    assert.Equal(639, FizzBuzz(10000))
    assert.Equal(8026, FizzBuzz(100000))
}

package main

import (
    "testing"
    "github.com/stretchr/testify/assert"
)

func TestFizzBuzz(t *testing.T) {
    assert := assert.New(t)
    assert.Equal(0, FizzBuzz(50))
    assert.Equal(2, FizzBuzz(78))
    assert.Equal(3, FizzBuzz(79))
}


Prompt:
import (
	"sort"
)

// This function takes a list l and returns a list l' such that
// l' is identical to l in the odd indicies, while its values at the even indicies are equal
// to the values of the even indicies of l, but sorted.
// >>> SortEven([1, 2, 3])
// [1, 2, 3]
// >>> SortEven([5, 6, 3, 4])
// [3, 6, 5, 4]
func SortEven(l []int) []int {

    evens := make([]int, 0)
	for i := 0; i < len(l); i += 2 {
		evens = append(evens, l[i])
	}
	sort.Ints(evens)
	j := 0
	for i := 0; i < len(l); i += 2 {
		l[i] = evens[j]
		j++
	}
	return l
}

func TestSortEven(t *testing.T) {
	assert := assert.New(t)
	same := func(src []int, target []int) bool {
		for i := 0; i < len(src); i++ {
			if src[i] != target[i] {
				return false
			}
		}
		return true
	}
	assert.Equal(true, same([]int{1, 2, 3}, SortEven([]int{1, 2, 3})))
	assert.Equal(true, same([]int{-10, 3, -5, 2, -3, 3, 5, 0, 9, 1, 123}, SortEven([]int{5, 3, -5, 2, -3, 3, 9, 0, 123, 1, -10})))
	assert.Equal(true, same([]int{-12, 8, 3, 4, 5, 2, 12, 11, 23, -10}, SortEven([]int{5, 8, -12, 4, 23, 2, 3, 11, 12, -10})))
}

package main

import (
    "testing"
    "github.com/stretchr/testify/assert"
)

func TestSortEven(t *testing.T) {
	assert := assert.New(t)
	same := func(src []int, target []int) bool {
		for i := 0; i < len(src); i++ {
			if src[i] != target[i] {
				return false
			}
		}
		return true
	}
	assert.Equal(true, same([]int{1, 2, 3}, SortEven([]int{1, 2, 3})))
	assert.Equal(true, same([]int{3,6,5,4}, SortEven([]int{5,6,3,4})))
}


Prompt:
import (
    "math"
    "strings"
    "time"
)

// returns encoded string by cycling groups of three characters.
func EncodeCyclic(s string) string {
    groups := make([]string, 0)
    for i := 0; i < ((len(s) + 2) / 3); i++ {
        groups = append(groups, s[3*i:int(math.Min(float64(3*i+3), float64(len(s))))])
    }
    newGroups := make([]string, 0)
    for _, group := range groups {
        runes := []rune(group)
        if len(group) == 3 {
            newGroups = append(newGroups, string(append(runes[1:], runes[0])))
        } else {
            newGroups = append(newGroups, group)
        }
    }
    return strings.Join(newGroups, "")
}

// takes as input string encoded with EncodeCyclic function. Returns decoded string.
func DecodeCyclic(s string) string {

import (
    "math"
    "strings"
    "time"
)

// returns encoded string by cycling groups of three characters.
// takes as input string encoded with EncodeCyclic function. Returns decoded string.

    return EncodeCyclic(EncodeCyclic(s))
}

func TestDecodeCyclic(t *testing.T) {
    assert := assert.New(t)
    randInt := func(min, max int) int {
        rng := rand.New(rand.NewSource(time.Now().UnixNano()))
        if min >= max || min == 0 || max == 0 {
            return max
        }
        return rng.Intn(max-min) + min
    }
    for i := 0; i <100 ; i++ {
        runes := make([]rune, 0)
        for j := 0; j < randInt(10,20); j++ {
            runes = append(runes, int32(randInt('a','z')))
        }
        encoded_str := EncodeCyclic(string(runes))
        assert.Equal(string(runes), DecodeCyclic(encoded_str))
    }
}

package main

import (
    "testing"
    "math/rand"
    "math"
    "time"
    "strings"
    "github.com/stretchr/testify/assert"
)


Prompt:
import (
	"math"
)

// PrimeFib returns n-th number that is a Fibonacci number and it's also prime.
// >>> PrimeFib(1)
// 2
// >>> PrimeFib(2)
// 3
// >>> PrimeFib(3)
// 5
// >>> PrimeFib(4)
// 13
// >>> PrimeFib(5)
// 89
func PrimeFib(n int) int {

    isPrime := func(p int) bool {
		if p < 2 {
			return false
		}
		for i := 2; i < int(math.Min(math.Sqrt(float64(p))+1, float64(p-1))); i++ {
			if p%i == 0 {
				return false
			}
		}
		return true
	}
	f := []int{0, 1}
	for {
		f = append(f, f[len(f)-1]+f[len(f)-2])
		if isPrime(f[len(f)-1]) {
			n -= 1
		}
		if n == 0 {
			return f[len(f)-1]
		}
	}
}

func TestPrimeFib(t *testing.T) {
    assert := assert.New(t)
    assert.Equal(2, PrimeFib(1))
    assert.Equal(3, PrimeFib(2))
    assert.Equal(5, PrimeFib(3))
    assert.Equal(13, PrimeFib(4))
    assert.Equal(89, PrimeFib(5))
    assert.Equal(233, PrimeFib(6))
    assert.Equal(1597, PrimeFib(7))
    assert.Equal(28657, PrimeFib(8))
    assert.Equal(514229, PrimeFib(9))
    assert.Equal(433494437, PrimeFib(10))
}

package main

import (
    "testing"
    "github.com/stretchr/testify/assert"
)

func TestPrimeFib(t *testing.T) {
    assert := assert.New(t)
    assert.Equal(2, PrimeFib(1))
    assert.Equal(3, PrimeFib(2))
    assert.Equal(5, PrimeFib(3))
    assert.Equal(13, PrimeFib(4))
    assert.Equal(89, PrimeFib(5))
}


Prompt:
// TriplesSumToZero takes a list of integers as an input.
// it returns true if there are three distinct elements in the list that
// sum to zero, and false otherwise.
//
// >>> TriplesSumToZero([1, 3, 5, 0])
// false
// >>> TriplesSumToZero([1, 3, -2, 1])
// true
// >>> TriplesSumToZero([1, 2, 3, 7])
// false
// >>> TriplesSumToZero([2, 4, -5, 3, 9, 7])
// true
// >>> TriplesSumToZero([1])
// false
func TriplesSumToZero(l []int) bool {

    for i := 0; i < len(l) - 2; i++ {
		for j := i + 1; j < len(l) - 1; j++ {
			for k := j + 1; k < len(l); k++ {
				if l[i] + l[j] + l[k] == 0 {
					return true
				}
			}
		}
	}
	return false
}

func TestTriplesSumToZero(t *testing.T) {
    assert := assert.New(t)
    assert.Equal(false, TriplesSumToZero([]int{1, 3, 5, 0}))
    assert.Equal(false, TriplesSumToZero([]int{1, 3, 5, -1}))
    assert.Equal(true, TriplesSumToZero([]int{1, 3, -2, 1}))
    assert.Equal(false, TriplesSumToZero([]int{1, 2, 3, 7}))
    assert.Equal(false, TriplesSumToZero([]int{1, 2, 5, 7}))
    assert.Equal(true, TriplesSumToZero([]int{2, 4, -5, 3, 9, 7}))
    assert.Equal(false, TriplesSumToZero([]int{1}))
    assert.Equal(false, TriplesSumToZero([]int{1, 3, 5, -100}))
    assert.Equal(false, TriplesSumToZero([]int{100, 3, 5, -100}))
}

package main

import (
    "testing"
    "github.com/stretchr/testify/assert"
)

func TestTriplesSumToZero(t *testing.T) {
    assert := assert.New(t)
    assert.Equal(false, TriplesSumToZero([]int{1, 3, 5, 0}))
    assert.Equal(true, TriplesSumToZero([]int{1, 3, -2, 1}))
    assert.Equal(false, TriplesSumToZero([]int{1, 2, 3, 7}))
    assert.Equal(true, TriplesSumToZero([]int{2, 4, -5, 3, 9, 7}))
}


Prompt:
// Imagine a road that's a perfectly straight infinitely long line.
// n cars are driving left to right;  simultaneously, a different set of n cars
// are driving right to left.   The two sets of cars start out being very far from
// each other.  All cars move in the same speed.  Two cars are said to collide
// when a car that's moving left to right hits a car that's moving right to left.
// However, the cars are infinitely sturdy and strong; as a result, they continue moving
// in their trajectory as if they did not collide.
//
// This function outputs the number of such collisions.
func CarRaceCollision(n int) int {

func TestCarRaceCollision(t *testing.T) {
    assert := assert.New(t)
    assert.Equal(4, CarRaceCollision(2))
    assert.Equal(9, CarRaceCollision(3))
    assert.Equal(16, CarRaceCollision(4))
    assert.Equal(64, CarRaceCollision(8))
    assert.Equal(100, CarRaceCollision(10))
}

package main

import (
    "testing"
    "github.com/stretchr/testify/assert"
)


Prompt:
// Return list with elements incremented by 1.
// >>> IncrList([1, 2, 3])
// [2, 3, 4]
// >>> IncrList([5, 3, 5, 2, 3, 3, 9, 0, 123])
// [6, 4, 6, 3, 4, 4, 10, 1, 124]
func IncrList(l []int) []int {

    n := len(l)
	for i := 0; i < n; i++ {
		l[i]++
	}
	return l
}

func TestIncrList(t *testing.T) {
    assert := assert.New(t)
    assert.Equal([]int{}, IncrList([]int{}))
    assert.Equal([]int{4, 3, 2}, IncrList([]int{3, 2, 1}))
    assert.Equal([]int{6, 3, 6, 3, 4, 4, 10, 1, 124}, IncrList([]int{5, 2, 5, 2, 3, 3, 9, 0, 123}))
}

package main

import (
    "testing"
    "github.com/stretchr/testify/assert"
)

func TestIncrList(t *testing.T) {
    assert := assert.New(t)
    assert.Equal([]int{2, 3, 4}, IncrList([]int{1, 2, 3}))
    assert.Equal([]int{6, 3, 6, 3, 4, 4, 10, 1, 124}, IncrList([]int{5, 2, 5, 2, 3, 3, 9, 0, 123}))
}


Prompt:
// PairsSumToZero takes a list of integers as an input.
// it returns true if there are two distinct elements in the list that
// sum to zero, and false otherwise.
// >>> PairsSumToZero([1, 3, 5, 0])
// false
// >>> PairsSumToZero([1, 3, -2, 1])
// false
// >>> PairsSumToZero([1, 2, 3, 7])
// false
// >>> PairsSumToZero([2, 4, -5, 3, 5, 7])
// true
// >>> PairsSumToZero([1])
// false
func PairsSumToZero(l []int) bool {

    seen := map[int]bool{}
	for i := 0; i < len(l); i++ {
		for j := i + 1; j < len(l); j++ {
			if l[i] + l[j] == 0 {
				if _, ok := seen[l[i]]; !ok {
					seen[l[i]] = true
					return true
				}
				if _, ok := seen[l[j]]; !ok {
					seen[l[j]] = true
					return true
				}
			}
		}
	}
	return false
}

func TestPairsSumToZero(t *testing.T) {
    assert := assert.New(t)
    assert.Equal(false, PairsSumToZero([]int{1, 3, 5, 0}))
    assert.Equal(false, PairsSumToZero([]int{1, 3, -2, 1}))
    assert.Equal(false, PairsSumToZero([]int{1, 2, 3, 7}))
    assert.Equal(true, PairsSumToZero([]int{2, 4, -5, 3, 5, 7}))
    assert.Equal(false, PairsSumToZero([]int{1}))
    assert.Equal(true, PairsSumToZero([]int{-3, 9, -1, 3, 2, 30}))
    assert.Equal(true, PairsSumToZero([]int{-3, 9, -1, 3, 2, 31}))
    assert.Equal(false, PairsSumToZero([]int{-3, 9, -1, 4, 2, 30}))
    assert.Equal(false, PairsSumToZero([]int{-3, 9, -1, 4, 2, 31}))
}

package main

import (
    "testing"
    "github.com/stretchr/testify/assert"
)

func TestPairsSumToZero(t *testing.T) {
    assert := assert.New(t)
    assert.Equal(false, PairsSumToZero([]int{1, 3, 5, 0}))
    assert.Equal(false, PairsSumToZero([]int{1, 3, -2, 1}))
    assert.Equal(false, PairsSumToZero([]int{1, 2, 3, 7}))
    assert.Equal(true, PairsSumToZero([]int{2, 4, -5, 3, 5, 7}))
}


Prompt:
import (
    "strconv"
)

// Change numerical base of input number x to base.
// return string representation after the conversion.
// base numbers are less than 10.
// >>> ChangeBase(8, 3)
// '22'
// >>> ChangeBase(8, 2)
// '1000'
// >>> ChangeBase(7, 2)
// '111'
func ChangeBase(x int, base int) string {

    if x >= base {
        return ChangeBase(x/base, base) + ChangeBase(x%base, base)
    }
    return strconv.Itoa(x)
}

func TestChangeBase(t *testing.T) {
    assert := assert.New(t)
    assert.Equal("22", ChangeBase(8, 3))
    assert.Equal("100", ChangeBase(9, 3))
    assert.Equal("11101010", ChangeBase(234, 2))
    assert.Equal("10000", ChangeBase(16, 2))
    assert.Equal("1000", ChangeBase(8, 2))
    assert.Equal("111", ChangeBase(7, 2))
    for i := 2; i < 8; i++ {
        assert.Equal(strconv.Itoa(i), ChangeBase(i, i+1))
    }
}

package main

import (
    "testing"
    "github.com/stretchr/testify/assert"
)

func TestChangeBase(t *testing.T) {
    assert := assert.New(t)
    assert.Equal("22", ChangeBase(8, 3))
    assert.Equal("1000", ChangeBase(8, 2))
    assert.Equal("111", ChangeBase(7, 2))
}


Prompt:
// Given length of a side and high return area for a triangle.
// >>> TriangleArea(5, 3)
// 7.5
func TriangleArea(a float64, h float64) float64 {

func TestTriangleArea(t *testing.T) {
    assert := assert.New(t)
    assert.Equal(7.5, TriangleArea(5, 3))
    assert.Equal(2.0, TriangleArea(2, 2))
    assert.Equal(40.0, TriangleArea(10, 8))
}

package main

import (
    "testing"
    "github.com/stretchr/testify/assert"
)

func TestTriangleArea(t *testing.T) {
    assert := assert.New(t)
    assert.Equal(7.5, TriangleArea(5, 3))
}


Prompt:
// The Fib4 number sequence is a sequence similar to the Fibbonacci sequnece that's defined as follows:
// Fib4(0) -> 0
// Fib4(1) -> 0
// Fib4(2) -> 2
// Fib4(3) -> 0
// Fib4(n) -> Fib4(n-1) + Fib4(n-2) + Fib4(n-3) + Fib4(n-4).
// Please write a function to efficiently compute the n-th element of the Fib4 number sequence.  Do not use recursion.
// >>> Fib4(5)
// 4
// >>> Fib4(6)
// 8
// >>> Fib4(7)
// 14
func Fib4(n int) int {

    switch n {
	case 0:
		return 0
	case 1:
		return 0
	case 2:
		return 2
	case 3:
		return 0
	default:
		return Fib4(n-1) + Fib4(n-2) + Fib4(n-3) + Fib4(n-4)
	}
}

func TestFib4(t *testing.T) {
    assert := assert.New(t)
    assert.Equal(4, Fib4(5))
    assert.Equal(28, Fib4(8))
    assert.Equal(104, Fib4(10))
    assert.Equal(386, Fib4(12))
}

package main

import (
    "testing"
    "github.com/stretchr/testify/assert"
)

func TestFib4(t *testing.T) {
    assert := assert.New(t)
    assert.Equal(4, Fib4(5))
    assert.Equal(8, Fib4(6))
    assert.Equal(14, Fib4(7))
}


Prompt:
import (
	"sort"
)

// Return Median of elements in the list l.
// >>> Median([3, 1, 2, 4, 5])
// 3.0
// >>> Median([-10, 4, 6, 1000, 10, 20])
// 15.0
func Median(l []int) float64 {

    sort.Ints(l)
	if len(l)%2==1{
		return float64(l[len(l)/2])
	}else{
		return float64(l[len(l)/2-1]+l[len(l)/2])/2.0
	}
}

func TestMedian(t *testing.T) {
	assert := assert.New(t)
	assert.Equal(3.0, Median([]int{3, 1, 2, 4, 5}))
	assert.Equal(8.0, Median([]int{-10, 4, 6, 1000, 10, 20}))
	assert.Equal(5.0, Median([]int{5}))
	assert.Equal(5.5, Median([]int{6, 5}))
	assert.Equal(7.0, Median([]int{8, 1, 3, 9, 9, 2, 7}))
}

package main

import (
    "testing"
    "github.com/stretchr/testify/assert"
)

func TestMedian(t *testing.T) {
	assert := assert.New(t)
	assert.Equal(3.0, Median([]int{3, 1, 2, 4, 5}))
	assert.Equal(8.0, Median([]int{-10, 4, 6, 1000, 10, 20}))
}


Prompt:
// Checks if given string is a palindrome
// >>> IsPalindrome('')
// true
// >>> IsPalindrome('aba')
// true
// >>> IsPalindrome('aaaaa')
// true
// >>> IsPalindrome('zbcd')
// false
func IsPalindrome(text string) bool {

    runes := []rune(text)
    result := make([]rune, 0)
    for i := len(runes) - 1; i >= 0; i-- {
        result = append(result, runes[i])
    }
    return text == string(result)
}

func TestIsPalindrome(t *testing.T) {
    assert := assert.New(t)
    assert.Equal(true, IsPalindrome(""))
    assert.Equal(true, IsPalindrome("aba"))
    assert.Equal(true, IsPalindrome("aaaaa"))
    assert.Equal(false, IsPalindrome("zbcd"))
    assert.Equal(true, IsPalindrome("xywyx"))
    assert.Equal(false, IsPalindrome("xywyz"))
    assert.Equal(false, IsPalindrome("xywzx"))
}

package main

import (
    "testing"
    "github.com/stretchr/testify/assert"
)

func TestIsPalindrome(t *testing.T) {
    assert := assert.New(t)
    assert.Equal(true, IsPalindrome(""))
    assert.Equal(true, IsPalindrome("aba"))
    assert.Equal(true, IsPalindrome("aaaaa"))
    assert.Equal(false, IsPalindrome("zbcd"))
}


Prompt:
// Return 2^n modulo p (be aware of numerics).
// >>> Modp(3, 5)
// 3
// >>> Modp(1101, 101)
// 2
// >>> Modp(0, 101)
// 1
// >>> Modp(3, 11)
// 8
// >>> Modp(100, 101)
// 1
func Modp(n int,p int) int {

    ret := 1
    for i:= 0; i < n; i++ {
		ret = (2 * ret) % p
	}
    return ret
}

func TestModp(t *testing.T) {
    assert := assert.New(t)
    assert.Equal(3, Modp(3, 5))
    assert.Equal(2, Modp(1101, 101))
    assert.Equal(1, Modp(0, 101))
    assert.Equal(8, Modp(3, 11))
    assert.Equal(1, Modp(100, 101))
    assert.Equal(4, Modp(30, 5))
    assert.Equal(3, Modp(31, 5))
}

package main

import (
    "testing"
    "github.com/stretchr/testify/assert"
)

func TestModp(t *testing.T) {
    assert := assert.New(t)
    assert.Equal(3, Modp(3, 5))
    assert.Equal(2, Modp(1101, 101))
    assert.Equal(1, Modp(0, 101))
    assert.Equal(8, Modp(3, 11))
    assert.Equal(1, Modp(100, 101))
}


Prompt:
// returns encoded string by shifting every character by 5 in the alphabet.
func EncodeShift(s string) string {
    runes := []rune(s)
    newRunes := make([]rune, 0)
    for _, ch := range runes {
        newRunes = append(newRunes, (ch+5-'a')%26+'a')
    }
    return string(runes)
}

// takes as input string encoded with EncodeShift function. Returns decoded string.
func DecodeShift(s string) string {

// returns encoded string by shifting every character by 5 in the alphabet.
// takes as input string encoded with encode_shift function. Returns decoded string.

    runes := []rune(s)
    newRunes := make([]rune, 0)
    for _, ch := range runes {
        newRunes = append(newRunes, (ch-5-'a')%26+'a')
    }
    return string(runes)
}

func TestDecodeShift(t *testing.T) {
    assert := assert.New(t)
    randInt := func(min, max int) int {
        rng := rand.New(rand.NewSource(time.Now().UnixNano()))
        if min >= max || min == 0 || max == 0 {
            return max
        }
        return rng.Intn(max-min) + min
    }
    for i := 0; i <100 ; i++ {
        runes := make([]rune, 0)
        for j := 0; j < randInt(10,20); j++ {
            runes = append(runes, int32(randInt('a','z')))
        }
        encoded_str := EncodeShift(string(runes))
        assert.Equal(DecodeShift(encoded_str), string(runes))
    }
}

package main

import (
    "testing"
    "math/rand"
    "time"
    "github.com/stretchr/testify/assert"
)


Prompt:
import (
    "regexp"
)

// RemoveVowels is a function that takes string and returns string without vowels.
// >>> RemoveVowels('')
// ''
// >>> RemoveVowels("abcdef\nghijklm")
// 'bcdf\nghjklm'
// >>> RemoveVowels('abcdef')
// 'bcdf'
// >>> RemoveVowels('aaaaa')
// ''
// >>> RemoveVowels('aaBAA')
// 'B'
// >>> RemoveVowels('zbcd')
// 'zbcd'
func RemoveVowels(text string) string {

    var re = regexp.MustCompile("[aeiouAEIOU]")
	text = re.ReplaceAllString(text, "")
	return text
}

func TestRemoveVowels(t *testing.T) {
    assert := assert.New(t)
    assert.Equal("", RemoveVowels(""))
    assert.Equal("bcdf\nghjklm", RemoveVowels("abcdef\nghijklm"))
    assert.Equal("fdcb", RemoveVowels("fedcba"))
    assert.Equal("", RemoveVowels("eeeee"))
    assert.Equal("cB", RemoveVowels("acBAA"))
    assert.Equal("cB", RemoveVowels("EcBOO"))
    assert.Equal("ybcd", RemoveVowels("ybcd"))
}

package main

import (
    "testing"
    "github.com/stretchr/testify/assert"
)

func TestRemoveVowels(t *testing.T) {
    assert := assert.New(t)
    assert.Equal("", RemoveVowels(""))
    assert.Equal("bcdf\nghjklm", RemoveVowels("abcdef\nghijklm"))
    assert.Equal("bcdf", RemoveVowels("abcdef"))
    assert.Equal("", RemoveVowels("aaaaa"))
    assert.Equal("B", RemoveVowels("aaBAA"))
    assert.Equal("zbcd", RemoveVowels("zbcd"))
}


Prompt:
// Return true if all numbers in the list l are below threshold t.
// >>> BelowThreshold([1, 2, 4, 10], 100)
// true
// >>> BelowThreshold([1, 20, 4, 10], 5)
// false
func BelowThreshold(l []int,t int) bool {

    for _, n := range l {
		if n >= t {
			return false
		}
	}
	return true
}

func TestBelowThreshold(t *testing.T) {
    assert := assert.New(t)
    assert.Equal(true, BelowThreshold([]int{1, 2, 4, 10}, 100))
    assert.Equal(false, BelowThreshold([]int{1, 20, 4, 10}, 5))
    assert.Equal(true, BelowThreshold([]int{1, 20, 4, 10}, 21))
    assert.Equal(true, BelowThreshold([]int{1, 20, 4, 10}, 22))
    assert.Equal(true, BelowThreshold([]int{1, 8, 4, 10}, 11))
    assert.Equal(false, BelowThreshold([]int{1, 8, 4, 10}, 10))
}

package main

import (
    "testing"
    "github.com/stretchr/testify/assert"
)

func TestBelowThreshold(t *testing.T) {
    assert := assert.New(t)
    assert.Equal(true, BelowThreshold([]int{1, 2, 4, 10}, 100))
    assert.Equal(false, BelowThreshold([]int{1, 20, 4, 10}, 5))
}


Prompt:
// Add two numbers x and y
// >>> Add(2, 3)
// 5
// >>> Add(5, 7)
// 12
func Add(x int, y int) int {

func TestAdd(t *testing.T) {
    assert := assert.New(t)
    assert.Equal(1, Add(0, 1))
    assert.Equal(1, Add(1, 0))
    assert.Equal(5, Add(2, 3))
    assert.Equal(12, Add(5, 7))
    assert.Equal(12, Add(7, 5))
    for i := 0; i < 100; i++ {
        x := rand.Int31n(1000)
        y := rand.Int31n(1000)
        assert.Equal(int(x+y), Add(int(x), int(y)))
    }
}

package main

import (
    "testing"
    "math/rand"
    "github.com/stretchr/testify/assert"
)

func TestAdd(t *testing.T) {
   assert := assert.New(t)
   assert.Equal(5, Add(2, 3+rand.Intn(1000)*0))
    assert.Equal(12, Add(5, 7))
}


Prompt:
// Check if two words have the same characters.
// >>> SameChars('eabcdzzzz', 'dddzzzzzzzddeddabc')
// true
// >>> SameChars('abcd', 'dddddddabc')
// true
// >>> SameChars('dddddddabc', 'abcd')
// true
// >>> SameChars('eabcd', 'dddddddabc')
// false
// >>> SameChars('abcd', 'dddddddabce')
// false
// >>> SameChars('eabcdzzzz', 'dddzzzzzzzddddabc')
// false
func SameChars(s0 string, s1 string) bool {

    set0 := make(map[int32]interface{})
	set1 := make(map[int32]interface{})
	for _, i := range s0 {
		set0[i] = nil
	}
	for _, i := range s1 {
		set1[i] = nil
	}
	for i, _ := range set0 {
		if _,ok:=set1[i];!ok{
			return false
		}
	}
	for i, _ := range set1 {
		if _,ok:=set0[i];!ok{
			return false
		}
	}
	return true
}

func TestSameChars(t *testing.T) {
    assert := assert.New(t)
    assert.Equal(true, SameChars("eabcdzzzz", "dddzzzzzzzddeddabc"))
    assert.Equal(true, SameChars("abcd", "dddddddabc"))
    assert.Equal(true, SameChars("dddddddabc", "abcd"))
    assert.Equal(false, SameChars("eabcd", "dddddddabc"))
    assert.Equal(false, SameChars("abcd", "dddddddabcf"))
    assert.Equal(false, SameChars("eabcdzzzz", "dddzzzzzzzddddabc"))
    assert.Equal(false, SameChars("aabb", "aaccc"))
}

package main

import (
    "testing"
    "github.com/stretchr/testify/assert"
)

func TestSameChars(t *testing.T) {
    assert := assert.New(t)
    assert.Equal(true, SameChars("eabcdzzzz", "dddzzzzzzzddeddabc"))
    assert.Equal(true, SameChars("abcd", "dddddddabc"))
    assert.Equal(true, SameChars("dddddddabc", "abcd"))
    assert.Equal(false, SameChars("eabcd", "dddddddabc"))
    assert.Equal(false, SameChars("abcd", "dddddddabcf"))
    assert.Equal(false, SameChars("eabcdzzzz", "dddzzzzzzzddddabc"))
}


Prompt:
// Return n-th Fibonacci number.
// >>> Fib(10)
// 55
// >>> Fib(1)
// 1
// >>> Fib(8)
// 21
func Fib(n int) int {

    if n <= 1 {
		return n
	}
	return Fib(n-1) + Fib(n-2)
}

func TestFib(t *testing.T) {
    assert := assert.New(t)
    assert.Equal(55, Fib(10))
    assert.Equal(1, Fib(1))
    assert.Equal(21, Fib(8))
    assert.Equal(89, Fib(11))
    assert.Equal(144, Fib(12))
}

package main

import (
    "testing"
    "github.com/stretchr/testify/assert"
)

func TestFib(t *testing.T) {
    assert := assert.New(t)
    assert.Equal(55, Fib(10))
    assert.Equal(1, Fib(1))
    assert.Equal(21, Fib(8))
}


Prompt:
// brackets is a string of "<" and ">".
// return true if every opening bracket has a corresponding closing bracket.
//
// >>> CorrectBracketing("<")
// false
// >>> CorrectBracketing("<>")
// true
// >>> CorrectBracketing("<<><>>")
// true
// >>> CorrectBracketing("><<>")
// false
func CorrectBracketing(brackets string) bool {

    l := len(brackets)
	count := 0
	for index := 0; index < l; index++ {
		if brackets[index] == '<' {
			count++
		} else if brackets[index] == '>' {
			count--
		}
		if count < 0 {
			return false
		}
	}
    if count == 0 {
        return true
    } else {
        return false
    }
}

func TestCorrectBracketing(t *testing.T) {
    assert := assert.New(t)
    assert.Equal(true, CorrectBracketing("<>"))
    assert.Equal(true, CorrectBracketing("<<><>>"))
    assert.Equal(true, CorrectBracketing("<><><<><>><>"))
    assert.Equal(true, CorrectBracketing("<><><<<><><>><>><<><><<>>>"))
    assert.Equal(false, CorrectBracketing("<<<><>>>>"))
    assert.Equal(false, CorrectBracketing("><<>"))
    assert.Equal(false, CorrectBracketing("<"))
    assert.Equal(false, CorrectBracketing("<<<<"))
    assert.Equal(false, CorrectBracketing(">"))
    assert.Equal(false, CorrectBracketing("<<>"))
    assert.Equal(false, CorrectBracketing("<><><<><>><>><<>"))
    assert.Equal(false, CorrectBracketing("<><><<><>><>>><>"))
}

package main

import (
    "testing"
    "github.com/stretchr/testify/assert"
)

func TestCorrectBracketing(t *testing.T) {
    assert := assert.New(t)
    assert.Equal(true, CorrectBracketing("<>"))
    assert.Equal(true, CorrectBracketing("<<><>>"))
    assert.Equal(false, CorrectBracketing("><<>"))
    assert.Equal(false, CorrectBracketing("<"))
}


Prompt:
// Return true is list elements are Monotonically increasing or decreasing.
// >>> Monotonic([1, 2, 4, 20])
// true
// >>> Monotonic([1, 20, 4, 10])
// false
// >>> Monotonic([4, 1, 0, -10])
// true
func Monotonic(l []int) bool {

    flag := true
	if len(l) > 1 {
		for i := 0; i < len(l)-1; i++ {
			if l[i] != l[i+1] {
				flag = l[i] > l[i+1]
				break
			}
		}
	} else {
		return false
	}
	for i := 0; i < len(l)-1; i++ {
		if flag != (l[i] >= l[i+1]) {
			return false
		}
	}
	return true
}

func TestMonotonic(t *testing.T) {
    assert := assert.New(t)
    assert.Equal(true, Monotonic([]int{1, 2, 4, 10}))
    assert.Equal(true, Monotonic([]int{1, 2, 4, 20}))
    assert.Equal(false, Monotonic([]int{1, 20, 4, 10}))
    assert.Equal(true, Monotonic([]int{4, 1, 0, -10}))
    assert.Equal(true, Monotonic([]int{4, 1, 1, 0}))
    assert.Equal(false, Monotonic([]int{1, 2, 3, 2, 5, 60}))
    assert.Equal(true, Monotonic([]int{1, 2, 3, 4, 5, 60}))
    assert.Equal(true, Monotonic([]int{9, 9, 9, 9}))
}

package main

import (
    "testing"
    "github.com/stretchr/testify/assert"
)

func TestMonotonic(t *testing.T) {
    assert := assert.New(t)
    assert.Equal(true, Monotonic([]int{1, 2, 4, 10}))
    assert.Equal(false, Monotonic([]int{1, 20, 4, 10}))
    assert.Equal(true, Monotonic([]int{4, 1, 0, -10}))
}


Prompt:
import (
    "sort"
)

// Return sorted unique Common elements for two lists.
// >>> Common([1, 4, 3, 34, 653, 2, 5], [5, 7, 1, 5, 9, 653, 121])
// [1, 5, 653]
// >>> Common([5, 3, 2, 8], [3, 2])
// [2, 3]
func Common(l1 []int,l2 []int) []int {

    m := make(map[int]bool)
	for _, e1 := range l1 {
		if m[e1] {
			continue
		}
		for _, e2 := range l2 {
			if e1 == e2 {
				m[e1] = true
				break
			}
		}
	}
	res := make([]int, 0, len(m))
	for k, _ := range m {
		res = append(res, k)
	}
	sort.Ints(res)
	return res
}

package main

import (
    "testing"
    "github.com/stretchr/testify/assert"
)


Prompt:
// Return the largest prime factor of n. Assume n > 1 and is not a prime.
// >>> LargestPrimeFactor(13195)
// 29
// >>> LargestPrimeFactor(2048)
// 2
func LargestPrimeFactor(n int) int {

    isPrime := func(n int) bool {
        for i := 2; i < int(math.Pow(float64(n), 0.5)+1); i++ {
            if n%i == 0 {
                return false
            }
        }
        return true
    }

    largest := 1
    for j := 2; j < n + 1; j++ {
		if n % j == 0 && isPrime(j) {
			if j > largest {
				largest = j
			}
		}
	}
    return largest
}

func TestLargestPrimeFactor(t *testing.T) {
    assert := assert.New(t)
    assert.Equal(5, LargestPrimeFactor(15))
    assert.Equal(3, LargestPrimeFactor(27))
    assert.Equal(7, LargestPrimeFactor(63))
    assert.Equal(11, LargestPrimeFactor(330))
    assert.Equal(29, LargestPrimeFactor(13195))
}

package main

import (
    "testing"
    "github.com/stretchr/testify/assert"
)

func TestLargestPrimeFactor(t *testing.T) {
    assert := assert.New(t)
    assert.Equal(2, LargestPrimeFactor(2048))
    assert.Equal(29, LargestPrimeFactor(13195))
}


Prompt:
// SumToN is a function that sums numbers from 1 to n.
// >>> SumToN(30)
// 465
// >>> SumToN(100)
// 5050
// >>> SumToN(5)
// 15
// >>> SumToN(10)
// 55
// >>> SumToN(1)
// 1
func SumToN(n int) int {

    if n <= 0 {
		return 0
	} else {
		return n + SumToN(n - 1)
	}
}

func TestSumToN(t *testing.T) {
    assert := assert.New(t)
    assert.Equal(1, SumToN(1))
    assert.Equal(21, SumToN(6))
    assert.Equal(66, SumToN(11))
    assert.Equal(465, SumToN(30))
    assert.Equal(5050, SumToN(100))
}

package main

import (
    "testing"
    "github.com/stretchr/testify/assert"
)

func TestSumToN(t *testing.T) {
    assert := assert.New(t)
    assert.Equal(1, SumToN(1))
    assert.Equal(15, SumToN(5))
    assert.Equal(55, SumToN(10))
    assert.Equal(465, SumToN(30))
    assert.Equal(5050, SumToN(100))
}


Prompt:
import (
    "strings"
)

// brackets is a string of "(" and ")".
// return true if every opening bracket has a corresponding closing bracket.
//
// >>> CorrectBracketing("(")
// false
// >>> CorrectBracketing("()")
// true
// >>> CorrectBracketing("(()())")
// true
// >>> CorrectBracketing(")(()")
// false
func CorrectBracketing(brackets string) bool {

    brackets = strings.Replace(brackets, "(", " ( ", -1)
	brackets = strings.Replace(brackets, ")", ") ", -1)
	open := 0
	for _, b := range brackets {
		if b == '(' {
			open++
		} else if b == ')' {
			open--
		}
		if open < 0 {
			return false
		}
	}
	return open == 0
}

func TestCorrectBracketing(t *testing.T) {
    assert := assert.New(t)
    assert.Equal(true, CorrectBracketing("()"))
    assert.Equal(true, CorrectBracketing("(()())"))
    assert.Equal(true, CorrectBracketing("()()(()())()"))
    assert.Equal(true, CorrectBracketing("()()((()()())())(()()(()))"))
    assert.Equal(false, CorrectBracketing("((()())))"))
    assert.Equal(false, CorrectBracketing(")(()"))
    assert.Equal(false, CorrectBracketing("("))
    assert.Equal(false, CorrectBracketing("(((("))
    assert.Equal(false, CorrectBracketing(")"))
    assert.Equal(false, CorrectBracketing("(()"))
    assert.Equal(false, CorrectBracketing("()()(()())())(()"))
    assert.Equal(false, CorrectBracketing("()()(()())()))()"))
}

package main

import (
    "testing"
    "github.com/stretchr/testify/assert"
)

func TestCorrectBracketing(t *testing.T) {
    assert := assert.New(t)
    assert.Equal(true, CorrectBracketing("()"))
    assert.Equal(true, CorrectBracketing("(()())"))
    assert.Equal(false, CorrectBracketing(")(()"))
    assert.Equal(false, CorrectBracketing("("))
}


Prompt:
// xs represent coefficients of a polynomial.
// xs[0] + xs[1] * x + xs[2] * x^2 + ....
// Return Derivative of this polynomial in the same form.
// >>> Derivative([3, 1, 2, 4, 5])
// [1, 4, 12, 20]
// >>> Derivative([1, 2, 3])
// [2, 6]
func Derivative(xs []int) []int {

func TestDerivative(t *testing.T) {
    assert := assert.New(t)
    assert.Equal([]int{1, 4, 12, 20}, Derivative([]int{3, 1, 2, 4, 5}))
    assert.Equal([]int{2, 6}, Derivative([]int{1, 2, 3}))
    assert.Equal([]int{2, 2}, Derivative([]int{3, 2, 1}))
    assert.Equal([]int{2, 2, 0, 16}, Derivative([]int{3, 2, 1,0, 4}))
    assert.Equal([]int{}, Derivative([]int{1}))
}

package main

import (
    "testing"
    "github.com/stretchr/testify/assert"
)

func TestDerivative(t *testing.T) {
    assert := assert.New(t)
    assert.Equal([]int{1, 4, 12, 20}, Derivative([]int{3, 1, 2, 4, 5}))
    assert.Equal([]int{2, 6}, Derivative([]int{1, 2, 3}))
}


Prompt:
// The FibFib number sequence is a sequence similar to the Fibbonacci sequnece that's defined as follows:
// Fibfib(0) == 0
// Fibfib(1) == 0
// Fibfib(2) == 1
// Fibfib(n) == Fibfib(n-1) + Fibfib(n-2) + Fibfib(n-3).
// Please write a function to efficiently compute the n-th element of the Fibfib number sequence.
// >>> Fibfib(1)
// 0
// >>> Fibfib(5)
// 4
// >>> Fibfib(8)
// 24
func Fibfib(n int) int {

    if n <= 0 {
		return 0
	}
    switch n {
	case 0:
		return 0
	case 1:
		return 0
	case 2:
		return 1
	default:
		return Fibfib(n-1) + Fibfib(n-2) + Fibfib(n-3)
	}
}

func TestFibfib(t *testing.T) {
    assert := assert.New(t)
    assert.Equal(1, Fibfib(2))
    assert.Equal(0, Fibfib(1))
    assert.Equal(4, Fibfib(5))
    assert.Equal(24, Fibfib(8))
    assert.Equal(81, Fibfib(10))
    assert.Equal(274, Fibfib(12))
    assert.Equal(927, Fibfib(14))
}

package main

import (
    "testing"
    "github.com/stretchr/testify/assert"
)

func TestFibfib(t *testing.T) {
    assert := assert.New(t)
    assert.Equal(0, Fibfib(1))
    assert.Equal(4, Fibfib(5))
    assert.Equal(24, Fibfib(8))
}


Prompt:
import (
    "strings"
)

// Write a function VowelsCount which takes a string representing
// a word as input and returns the number of vowels in the string.
// Vowels in this case are 'a', 'e', 'i', 'o', 'u'. Here, 'y' is also a
// vowel, but only when it is at the end of the given word.
//
// Example:
// >>> VowelsCount("abcde")
// 2
// >>> VowelsCount("ACEDY")
// 3
func VowelsCount(s string) int {

    s = strings.ToLower(s)
	vowels := map[int32]interface{}{'a': nil, 'e': nil, 'i': nil, 'o': nil, 'u': nil}
	count := 0
	for _, i := range s {
		if _, ok := vowels[i]; ok {
			count++
		}
	}
	if (s[len(s)-1]) == 'y' {
		count++
	}
	return count
}

func TestVowelsCount(t *testing.T) {
    assert := assert.New(t)
    assert.Equal(2, VowelsCount("abcde"))
    assert.Equal(3, VowelsCount("Alone"))
    assert.Equal(2, VowelsCount("key"))
    assert.Equal(1, VowelsCount("bye"))
    assert.Equal(2, VowelsCount("keY"))
    assert.Equal(1, VowelsCount("bYe"))
    assert.Equal(3, VowelsCount("ACEDY"))
}

package main

import (
    "testing"
    "github.com/stretchr/testify/assert"
)

func TestVowelsCount(t *testing.T) {
    assert := assert.New(t)
    assert.Equal(2, VowelsCount("abcde"))
    assert.Equal(3, VowelsCount("ACEDY"))
}


Prompt:
// Circular shift the digits of the integer x, shift the digits right by shift
// and return the result as a string.
// If shift > number of digits, return digits reversed.
// >>> CircularShift(12, 1)
// "21"
// >>> CircularShift(12, 2)
// "12"
func CircularShift(x int,shift int) string {

func CircularShift(x int, shift int) string {

    s := strconv.Itoa(x)
	if shift > len(s) {
		runes := make([]rune, 0)
		for i := len(s)-1; i >= 0; i-- {
			runes = append(runes, rune(s[i]))
		}
		return string(runes)
	}else{
		return s[len(s)-shift:]+s[:len(s)-shift]
	}
}

func TestCircularShift(t *testing.T) {
    assert := assert.New(t)
    assert.Equal("001", CircularShift(100, 2))
    assert.Equal("12", CircularShift(12, 2))
    assert.Equal("79", CircularShift(97, 8))
    assert.Equal("21", CircularShift(12, 1))
    assert.Equal("11", CircularShift(11, 101))
}

package main

import (
    "testing"
    "github.com/stretchr/testify/assert"
)

func TestCircularShift(t *testing.T) {
    assert := assert.New(t)
    assert.Equal("12", CircularShift(12, 2))
    assert.Equal("21", CircularShift(12, 1))
}


Prompt:
// Task
// Write a function that takes a string as input and returns the sum of the upper characters only'
// ASCII codes.
//
// Examples:
// Digitsum("") => 0
// Digitsum("abAB") => 131
// Digitsum("abcCd") => 67
// Digitsum("helloE") => 69
// Digitsum("woArBld") => 131
// Digitsum("aAaaaXa") => 153
func Digitsum(x string) int {

    if len(x) == 0 {
		return 0
	}
	result := 0
	for _, i := range x {
		if 'A' <= i && i <= 'Z' {
			result += int(i)
		}
	}
	return result
}

func TestDigitSum(t *testing.T) {
    assert := assert.New(t)
    assert.Equal(0, Digitsum(""))
    assert.Equal(131, Digitsum("abAB"))
    assert.Equal(67, Digitsum("abcCd"))
    assert.Equal(69, Digitsum("helloE"))
    assert.Equal(131, Digitsum("woArBld"))
    assert.Equal(153, Digitsum("aAaaaXa"))
    assert.Equal(151, Digitsum(" How are yOu?"))
    assert.Equal(327, Digitsum("You arE Very Smart"))
}

package main

import (
    "testing"
    "github.com/stretchr/testify/assert"
)

func TestDigitSum(t *testing.T) {
    assert := assert.New(t)
    assert.Equal(0, Digitsum(""))
    assert.Equal(131, Digitsum("abAB"))
    assert.Equal(67, Digitsum("abcCd"))
    assert.Equal(69, Digitsum("helloE"))
    assert.Equal(131, Digitsum("woArBld"))
    assert.Equal(153, Digitsum("aAaaaXa"))
}


Prompt:
import (
	"strconv"
	"strings"
)

// In this task, you will be given a string that represents a number of apples and oranges
// that are distributed in a basket of fruit this basket contains
// apples, oranges, and mango fruits. Given the string that represents the total number of
// the oranges and apples and an integer that represent the total number of the fruits
// in the basket return the number of the mango fruits in the basket.
// for examble:
// FruitDistribution("5 apples and 6 oranges", 19) ->19 - 5 - 6 = 8
// FruitDistribution("0 apples and 1 oranges",3) -> 3 - 0 - 1 = 2
// FruitDistribution("2 apples and 3 oranges", 100) -> 100 - 2 - 3 = 95
// FruitDistribution("100 apples and 1 oranges",120) -> 120 - 100 - 1 = 19
func FruitDistribution(s string,n int) int {

    split := strings.Split(s, " ")
	for _, i := range split {
		atoi, err := strconv.Atoi(i)
		if err != nil {
			continue
		}
		n = n - atoi
	}
	return n
}

func TestFruitDistribution(t *testing.T) {
    assert := assert.New(t)
    assert.Equal(8, FruitDistribution("5 apples and 6 oranges", 19))
    assert.Equal(10, FruitDistribution("5 apples and 6 oranges", 21))
    assert.Equal(2, FruitDistribution("0 apples and 1 oranges", 3))
    assert.Equal(2, FruitDistribution("1 apples and 0 oranges", 3))
    assert.Equal(95, FruitDistribution("2 apples and 3 oranges", 100))
    assert.Equal(0, FruitDistribution("2 apples and 3 oranges", 5))
    assert.Equal(19, FruitDistribution("1 apples and 100 oranges", 120))
}

package main

import (
    "testing"
    "github.com/stretchr/testify/assert"
)

func TestFruitDistribution(t *testing.T) {
    assert := assert.New(t)
    assert.Equal(8, FruitDistribution("5 apples and 6 oranges", 19))
    assert.Equal(2, FruitDistribution("0 apples and 1 oranges", 3))
    assert.Equal(95, FruitDistribution("2 apples and 3 oranges", 100))
    assert.Equal(19, FruitDistribution("1 apples and 100 oranges", 120))
}


Prompt:
import (
    "math"
)

// Given an array representing a branch of a tree that has non-negative integer nodes
// your task is to Pluck one of the nodes and return it.
// The Plucked node should be the node with the smallest even value.
// If multiple nodes with the same smallest even value are found return the node that has smallest index.
//
// The Plucked node should be returned in a list, [ smalest_value, its index ],
// If there are no even values or the given array is empty, return [].
//
// Example 1:
// Input: [4,2,3]
// Output: [2, 1]
// Explanation: 2 has the smallest even value, and 2 has the smallest index.
//
// Example 2:
// Input: [1,2,3]
// Output: [2, 1]
// Explanation: 2 has the smallest even value, and 2 has the smallest index.
//
// Example 3:
// Input: []
// Output: []
//
// Example 4:
// Input: [5, 0, 3, 0, 4, 2]
// Output: [0, 1]
// Explanation: 0 is the smallest value, but  there are two zeros,
// so we will choose the first zero, which has the smallest index.
//
// Constraints:
// * 1 <= nodes.length <= 10000
// * 0 <= node.value
func Pluck(arr []int) []int {

    result := make([]int, 0)
	if len(arr) == 0 {
		return result
	}
	evens := make([]int, 0)
	min := math.MaxInt64
	minIndex := 0
	for i, x := range arr {
		if x%2 == 0 {
			evens = append(evens, x)
			if x < min {
				min = x
				minIndex = i
			}
		}
	}
	if len(evens) == 0 {
		return result
	}
	result = []int{min, minIndex}
	return result
}

func TestPluck(t *testing.T) {
    assert := assert.New(t)
    assert.Equal([]int{2, 1}, Pluck([]int{4,2,3}))
    assert.Equal([]int{2, 1}, Pluck([]int{1,2,3}))
    assert.Equal([]int{}, Pluck([]int{}))
    assert.Equal([]int{0, 1}, Pluck([]int{5, 0, 3, 0, 4, 2}))
    assert.Equal([]int{0, 3}, Pluck([]int{1, 2, 3, 0, 5, 3}))
    assert.Equal([]int{4, 1}, Pluck([]int{5, 4, 8, 4 ,8}))
    assert.Equal([]int{6, 1}, Pluck([]int{7, 6, 7, 1}))
    assert.Equal([]int{}, Pluck([]int{7, 9, 7, 1}))
}

package main

import (
    "testing"
    "github.com/stretchr/testify/assert"
)

func TestPluck(t *testing.T) {
    assert := assert.New(t)
    assert.Equal([]int{2, 1}, Pluck([]int{4,2,3}))
    assert.Equal([]int{2, 1}, Pluck([]int{1,2,3}))
    assert.Equal([]int{}, Pluck([]int{}))
    assert.Equal([]int{0, 1}, Pluck([]int{5, 0, 3, 0, 4, 2}))
}


Prompt:
// You are given a non-empty list of positive integers. Return the greatest integer that is greater than
// zero, and has a frequency greater than or equal to the value of the integer itself.
// The frequency of an integer is the number of times it appears in the list.
// If no such a value exist, return -1.
// Examples:
// Search([4, 1, 2, 2, 3, 1]) == 2
// Search([1, 2, 2, 3, 3, 3, 4, 4, 4]) == 3
// Search([5, 5, 4, 4, 4]) == -1
func Search(lst []int) int {

    countMap := make(map[int]int)
	for _, i := range lst {
		if count, ok := countMap[i]; ok {
			countMap[i] = count + 1
		} else {
			countMap[i] = 1
		}
	}
	max := -1
	for i, count := range countMap {
		if count >= i && count > max {
			max = i
		}
	}
	return max
}

package main

import (
    "testing"
    "github.com/stretchr/testify/assert"
)

func TestSearch(t *testing.T) {
    assert := assert.New(t)
    assert.Equal(2, Search([]int{4, 1, 2, 2, 3, 1}))
    assert.Equal(3, Search([]int{1, 2, 2, 3, 3, 3, 4, 4, 4}))
    assert.Equal(-1, Search([]int{5, 5, 4, 4, 4}))
}


Prompt:
import (
    "sort"
)

// Given list of integers, return list in strange order.
// Strange sorting, is when you start with the minimum value,
// then maximum of the remaining integers, then minimum and so on.
//
// Examples:
// StrangeSortList([1, 2, 3, 4]) == [1, 4, 2, 3]
// StrangeSortList([5, 5, 5, 5]) == [5, 5, 5, 5]
// StrangeSortList([]) == []
func StrangeSortList(lst []int) []int {

    sort.Ints(lst)
	result := make([]int, 0)
	for i := 0; i < len(lst)/2; i++ {
		result = append(result, lst[i])
		result = append(result, lst[len(lst)-i-1])
	}
	if len(lst)%2 != 0 {
		result = append(result, lst[len(lst)/2])
	}
	return result
}

func TestStrangeSortList(t *testing.T) {
    assert := assert.New(t)
    assert.Equal([]int{1, 4, 2, 3}, StrangeSortList([]int{1,2, 3, 4}))
    assert.Equal([]int{5, 9, 6, 8, 7}, StrangeSortList([]int{5, 6, 7, 8, 9}))
    assert.Equal([]int{1, 5, 2, 4, 3}, StrangeSortList([]int{1, 2, 3, 4, 5}))
    assert.Equal([]int{1, 9, 5, 8, 6, 7}, StrangeSortList([]int{5, 6, 7, 8, 9, 1}))
    assert.Equal([]int{5, 5, 5, 5}, StrangeSortList([]int{5,5, 5, 5}))
    assert.Equal([]int{}, StrangeSortList([]int{}))
    assert.Equal([]int{1, 8, 2, 7, 3, 6, 4, 5}, StrangeSortList([]int{1,2,3,4,5,6,7,8}))
    assert.Equal([]int{-5, 5, -5, 5, 0, 2, 2, 2}, StrangeSortList([]int{0,2,2,2,5,5,-5,-5}))
    assert.Equal([]int{111111}, StrangeSortList([]int{111111}))
}

package main

import (
    "testing"
    "github.com/stretchr/testify/assert"
)

func TestStrangeSortList(t *testing.T) {
    assert := assert.New(t)
    assert.Equal([]int{1, 4, 2, 3}, StrangeSortList([]int{1,2, 3, 4}))
    assert.Equal([]int{5, 5, 5, 5}, StrangeSortList([]int{5,5, 5, 5}))
    assert.Equal([]int{}, StrangeSortList([]int{}))
}


Prompt:
import (
    "math"
)

// Given the lengths of the three sides of a triangle. Return the area of
// the triangle rounded to 2 decimal points if the three sides form a valid triangle.
// Otherwise return -1
// Three sides make a valid triangle when the sum of any two sides is greater
// than the third side.
// Example:
// TriangleArea(3, 4, 5) == 6.00
// TriangleArea(1, 2, 10) == -1
func TriangleArea(a float64, b float64, c float64) interface{} {

    if a+b <= c || a+c <= b || b+c <= a {
		return -1
	}
	s := (a + b + c) / 2
	area := math.Pow(s * (s - a) * (s - b) * (s - c), 0.5)
	area = math.Round(area*100)/100
	return area
}

func TestTriangleArea(t *testing.T) {
    assert := assert.New(t)
    assert.Equal(6.00, TriangleArea(3, 4, 5))
    assert.Equal(-1, TriangleArea(1, 2, 10))
    assert.Equal(8.18, TriangleArea(4, 8, 5))
    assert.Equal(1.73, TriangleArea(2, 2, 2))
    assert.Equal(-1, TriangleArea(1, 2, 3))
    assert.Equal(16.25, TriangleArea(10, 5, 7))
    assert.Equal(-1, TriangleArea(2, 6, 3))
    assert.Equal(0.43, TriangleArea(1, 1, 1))
    assert.Equal(-1, TriangleArea(2, 2, 10))
}

package main

import (
    "testing"
    "github.com/stretchr/testify/assert"
)

func TestTriangleArea(t *testing.T) {
    assert := assert.New(t)
    assert.Equal(6.00, TriangleArea(3, 4, 5))
    assert.Equal(-1, TriangleArea(1, 2, 10))
}


Prompt:
// Write a function that returns true if the object q will fly, and false otherwise.
// The object q will fly if it's balanced (it is a palindromic list) and the sum of its elements is less than or equal the maximum possible weight w.
//
// Example:
// WillItFly([1, 2], 5) ➞ false
// 1+2 is less than the maximum possible weight, but it's unbalanced.
//
// WillItFly([3, 2, 3], 1) ➞ false
// it's balanced, but 3+2+3 is more than the maximum possible weight.
//
// WillItFly([3, 2, 3], 9) ➞ true
// 3+2+3 is less than the maximum possible weight, and it's balanced.
//
// WillItFly([3], 5) ➞ true
// 3 is less than the maximum possible weight, and it's balanced.
func WillItFly(q []int,w int) bool {

    sum := 0
	for i := 0; i < len(q); i++ {
		sum += q[i]
	}
	if sum <= w && isPalindrome(q) {
		return true
	}
	return false
}

func isPalindrome(arr []int) bool {
	for i := 0; i < (len(arr) / 2); i++ {
		if arr[i] != arr[len(arr) - i - 1] {
			return false
		}
	}
	return true
}

func TestWillItFly(t *testing.T) {
    assert := assert.New(t)
    assert.Equal(true, WillItFly([]int{3, 2, 3}, 9))
    assert.Equal(false, WillItFly([]int{1, 2}, 5))
    assert.Equal(true, WillItFly([]int{3}, 5))
    assert.Equal(false, WillItFly([]int{3, 2, 3}, 1))
    assert.Equal(false, WillItFly([]int{1, 2, 3}, 6))
    assert.Equal(true, WillItFly([]int{5}, 5))
}

package main

import (
    "testing"
    "github.com/stretchr/testify/assert"
)

func TestWillItFly(t *testing.T) {
    assert := assert.New(t)
    assert.Equal(true, WillItFly([]int{3, 2, 3}, 9))
    assert.Equal(false, WillItFly([]int{1, 2}, 5))
    assert.Equal(true, WillItFly([]int{3}, 5))
    assert.Equal(false, WillItFly([]int{3, 2, 3}, 1))
}


Prompt:
// Given an array arr of integers, find the minimum number of elements that
// need to be changed to make the array palindromic. A palindromic array is an array that
// is read the same backwards and forwards. In one change, you can change one element to any other element.
//
// For example:
// SmallestChange([1,2,3,5,4,7,9,6]) == 4
// SmallestChange([1, 2, 3, 4, 3, 2, 2]) == 1
// SmallestChange([1, 2, 3, 2, 1]) == 0
func SmallestChange(arr []int) int {

    count := 0
	for i := 0; i < len(arr) - 1; i++ {
        a := arr[len(arr) - i - 1]
		if arr[i] != a {
			arr[i] = a
            count++
		}
	}
	return count
}

func TestSmallestChange(t *testing.T) {
    assert := assert.New(t)
    assert.Equal(4, SmallestChange([]int{1,2,3,5,4,7,9,6}))
    assert.Equal(1, SmallestChange([]int{1, 2, 3, 4, 3, 2, 2}))
    assert.Equal(1, SmallestChange([]int{1, 4, 2}))
    assert.Equal(1, SmallestChange([]int{1, 4, 4, 2}))
    assert.Equal(0, SmallestChange([]int{1, 2, 3, 2, 1}))
    assert.Equal(0, SmallestChange([]int{3, 1, 1, 3}))
    assert.Equal(0, SmallestChange([]int{1}))
    assert.Equal(1, SmallestChange([]int{0, 1}))
}

package main

import (
    "testing"
    "github.com/stretchr/testify/assert"
)

func TestSmallestChange(t *testing.T) {
    assert := assert.New(t)
    assert.Equal(4, SmallestChange([]int{1,2,3,5,4,7,9,6}))
    assert.Equal(1, SmallestChange([]int{1, 2, 3, 4, 3, 2, 2}))
    assert.Equal(0, SmallestChange([]int{1, 2, 3, 2, 1}))
    assert.Equal(0, SmallestChange([]int{3, 1, 1, 3}))
}


Prompt:
// Write a function that accepts two lists of strings and returns the list that has
// total number of chars in the all strings of the list less than the other list.
//
// if the two lists have the same number of chars, return the first list.
//
// Examples
// TotalMatch([], []) ➞ []
// TotalMatch(['hi', 'admin'], ['hI', 'Hi']) ➞ ['hI', 'Hi']
// TotalMatch(['hi', 'admin'], ['hi', 'hi', 'admin', 'project']) ➞ ['hi', 'admin']
// TotalMatch(['hi', 'admin'], ['hI', 'hi', 'hi']) ➞ ['hI', 'hi', 'hi']
// TotalMatch(['4'], ['1', '2', '3', '4', '5']) ➞ ['4']
func TotalMatch(lst1 []string,lst2 []string) []string {

    var numchar1 = 0
	var numchar2 = 0
	for _, item := range lst1 {
		numchar1 += len(item)
	}
	for _, item := range lst2 {
		numchar2 += len(item)
	}
	if numchar1 <= numchar2 {
		return lst1
	} else {
		return lst2
	}
}

func TestTotalMatch(t *testing.T) {
    assert := assert.New(t)
    assert.Equal([]string{}, TotalMatch([]string{}, []string{}))
    assert.Equal([]string{"hi", "hi"}, TotalMatch([]string{"hi", "admin"}, []string{"hi", "hi"}))
    assert.Equal([]string{"hi", "admin"}, TotalMatch([]string{"hi", "admin"}, []string{"hi", "hi", "admin", "project"}))
    assert.Equal([]string{"4"}, TotalMatch([]string{"4"},[]string{"1", "2", "3", "4", "5"}))
    assert.Equal([]string{"hI", "Hi"}, TotalMatch([]string{"hi", "admin"}, []string{"hI", "Hi"}))
    assert.Equal([]string{"hI", "hi", "hi"}, TotalMatch([]string{"hi", "admin"}, []string{"hI", "hi", "hi"}))
    assert.Equal([]string{"hi", "admin"}, TotalMatch([]string{"hi", "admin"}, []string{"hI", "hi", "hii"}))
    assert.Equal([]string{}, TotalMatch([]string{}, []string{"this"}))
    assert.Equal([]string{}, TotalMatch([]string{"this"}, []string{}))
}

package main

import (
    "testing"
    "github.com/stretchr/testify/assert"
)

func TestTotalMatch(t *testing.T) {
    assert := assert.New(t)
    assert.Equal([]string{}, TotalMatch([]string{}, []string{}))
    assert.Equal([]string{"hi", "admin"}, TotalMatch([]string{"hi", "admin"}, []string{"hi", "hi", "admin", "project"}))
    assert.Equal([]string{"4"}, TotalMatch([]string{"4"},[]string{"1", "2", "3", "4", "5"}))
    assert.Equal([]string{"hI", "Hi"}, TotalMatch([]string{"hi", "admin"}, []string{"hI", "Hi"}))
    assert.Equal([]string{"hI", "hi", "hi"}, TotalMatch([]string{"hi", "admin"}, []string{"hI", "hi", "hi"}))
}


Prompt:
// Write a function that returns true if the given number is the multiplication of 3 prime numbers
// and false otherwise.
// Knowing that (a) is less then 100.
// Example:
// IsMultiplyPrime(30) == true
// 30 = 2 * 3 * 5
func IsMultiplyPrime(a int) bool {

    isPrime := func(n int) bool {
        for i := 2; i < int(math.Pow(float64(n), 0.5)+1); i++ {
            if n%i == 0 {
                return false
            }
        }
        return true
    }
    for i := 2; i < 101; i++ {
		if !isPrime(i) {
			continue
		}
		for j := 2; j < 101; j++ {
			if !isPrime(j) {
				continue
			}
			for k := 2; k < 101; k++ {
				if !isPrime(k) {
					continue
				}
				if i*j*k == a {
					return true
				}
			}
		}
	}
	return false
}

func TestIsMultiplyPrime(t *testing.T) {
    assert := assert.New(t)
    assert.Equal(false, IsMultiplyPrime(5))
    assert.Equal(true, IsMultiplyPrime(30))
    assert.Equal(true, IsMultiplyPrime(8))
    assert.Equal(false, IsMultiplyPrime(10))
    assert.Equal(true, IsMultiplyPrime(125))
    assert.Equal(true, IsMultiplyPrime(3 * 5 * 7))
    assert.Equal(false, IsMultiplyPrime(3 * 6 * 7))
    assert.Equal(false, IsMultiplyPrime(9 * 9 * 9))
    assert.Equal(false, IsMultiplyPrime(11 * 9 * 9))
    assert.Equal(true, IsMultiplyPrime(11 * 13 * 7))
}

package main

import (
    "testing"
    "github.com/stretchr/testify/assert"
)

func TestIsMultiplyPrime(t *testing.T) {
    assert := assert.New(t)
    assert.Equal(true, IsMultiplyPrime(30))
}


Prompt:
// Your task is to write a function that returns true if a number x is a simple
// power of n and false in other cases.
// x is a simple power of n if n**int=x
// For example:
// IsSimplePower(1, 4) => true
// IsSimplePower(2, 2) => true
// IsSimplePower(8, 2) => true
// IsSimplePower(3, 2) => false
// IsSimplePower(3, 1) => false
// IsSimplePower(5, 3) => false
func IsSimplePower(x int,n int) bool {

    if x == 1 {
		return true
	}
	if n==1 {
		return false
	}
	if x % n != 0 {
		return false
	}
	return IsSimplePower(x / n, n)
}

func TestIsSimplePower(t *testing.T) {
    assert := assert.New(t)
    assert.Equal(true, IsSimplePower(1, 4))
    assert.Equal(true, IsSimplePower(2, 2))
    assert.Equal(true, IsSimplePower(8, 2))
    assert.Equal(false, IsSimplePower(3, 2))
    assert.Equal(false, IsSimplePower(3, 1))
    assert.Equal(false, IsSimplePower(5, 3))
    assert.Equal(true, IsSimplePower(16, 2))
    assert.Equal(false, IsSimplePower(143214, 16))
    assert.Equal(true, IsSimplePower(4, 2))
    assert.Equal(true, IsSimplePower(9, 3))
    assert.Equal(true, IsSimplePower(16, 4))
    assert.Equal(false, IsSimplePower(24, 2))
    assert.Equal(false, IsSimplePower(128, 4))
    assert.Equal(false, IsSimplePower(12, 6))
    assert.Equal(true, IsSimplePower(1, 1))
    assert.Equal(true, IsSimplePower(1, 12))
}

package main

import (
    "testing"
    "github.com/stretchr/testify/assert"
)

func TestIsSimplePower(t *testing.T) {
    assert := assert.New(t)
    assert.Equal(true, IsSimplePower(1, 4))
    assert.Equal(true, IsSimplePower(2, 2))
    assert.Equal(true, IsSimplePower(8, 2))
    assert.Equal(false, IsSimplePower(3, 2))
    assert.Equal(false, IsSimplePower(3, 1))
    assert.Equal(false, IsSimplePower(5, 3))
}


Prompt:
import (
    "math"
)

// Write a function that takes an integer a and returns true
// if this ingeger is a cube of some integer number.
// Note: you may assume the input is always valid.
// Examples:
// Iscube(1) ==> true
// Iscube(2) ==> false
// Iscube(-1) ==> true
// Iscube(64) ==> true
// Iscube(0) ==> true
// Iscube(180) ==> false
func Iscube(a int) bool {

    abs := math.Abs(float64(a))
	return int(math.Pow(math.Round(math.Pow(abs, 1.0/3.0)), 3.0)) == int(abs)
}

func TestIscube(t *testing.T) {
    assert := assert.New(t)
    assert.Equal(true, Iscube(1))
    assert.Equal(false, Iscube(2))
    assert.Equal(true, Iscube(-1))
    assert.Equal(true, Iscube(64))
    assert.Equal(false, Iscube(180))
    assert.Equal(true, Iscube(1000))
    assert.Equal(true, Iscube(0))
    assert.Equal(false, Iscube(1729))
}

package main

import (
    "testing"
    "github.com/stretchr/testify/assert"
)

func TestIscube(t *testing.T) {
    assert := assert.New(t)
    assert.Equal(true, Iscube(1))
    assert.Equal(false, Iscube(2))
    assert.Equal(true, Iscube(-1))
    assert.Equal(true, Iscube(64))
    assert.Equal(false, Iscube(180))
    assert.Equal(true, Iscube(0))
}


Prompt:
// You have been tasked to write a function that receives
// a hexadecimal number as a string and counts the number of hexadecimal
// digits that are primes (prime number, or a prime, is a natural number
// greater than 1 that is not a product of two smaller natural numbers).
// Hexadecimal digits are 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, A, B, C, D, E, F.
// Prime numbers are 2, 3, 5, 7, 11, 13, 17,...
// So you have to determine a number of the following digits: 2, 3, 5, 7,
// B (=decimal 11), D (=decimal 13).
// Note: you may assume the input is always correct or empty string,
// and symbols A,B,C,D,E,F are always uppercase.
// Examples:
// For num = "AB" the output should be 1.
// For num = "1077E" the output should be 2.
// For num = "ABED1A33" the output should be 4.
// For num = "123456789ABCDEF0" the output should be 6.
// For num = "2020" the output should be 2.
func HexKey(num string) int {

    primes := map[int32]interface{}{'2': nil, '3': nil, '5': nil, '7': nil, 'B': nil, 'D': nil}
	total := 0
	for _, c := range num {
		if _, ok := primes[c]; ok {
			total++
		}
	}
	return total
}

func TestHexKey(t *testing.T) {
    assert := assert.New(t)
    assert.Equal(1, HexKey("AB"))
    assert.Equal(2, HexKey("1077E"))
    assert.Equal(4, HexKey("ABED1A33"))
    assert.Equal(2, HexKey("2020"))
    assert.Equal(6, HexKey("123456789ABCDEF0"))
    assert.Equal(12, HexKey("112233445566778899AABBCCDDEEFF00"))
    assert.Equal(0, HexKey(""))
}

package main

import (
    "testing"
    "github.com/stretchr/testify/assert"
)

func TestHexKey(t *testing.T) {
    assert := assert.New(t)
    assert.Equal(1, HexKey("AB"))
    assert.Equal(2, HexKey("1077E"))
    assert.Equal(4, HexKey("ABED1A33"))
    assert.Equal(2, HexKey("2020"))
    assert.Equal(6, HexKey("123456789ABCDEF0"))
}


Prompt:
import (
	"fmt"
)

// You will be given a number in decimal form and your task is to convert it to
// binary format. The function should return a string, with each character representing a binary
// number. Each character in the string will be '0' or '1'.
//
// There will be an extra couple of characters 'db' at the beginning and at the end of the string.
// The extra characters are there to help with the format.
//
// Examples:
// DecimalToBinary(15)   # returns "db1111db"
// DecimalToBinary(32)   # returns "db100000db"
func DecimalToBinary(decimal int) string {

    return fmt.Sprintf("db%bdb", decimal)
}

func TestDecimalToBinary(t *testing.T) {
    assert := assert.New(t)
    assert.Equal("db0db", DecimalToBinary(0))
    assert.Equal("db100000db", DecimalToBinary(32))
    assert.Equal("db1100111db", DecimalToBinary(103))
    assert.Equal("db1111db", DecimalToBinary(15))
}

package main

import (
    "testing"
    "github.com/stretchr/testify/assert"
)

func TestDecimalToBinary(t *testing.T) {
    assert := assert.New(t)
    assert.Equal("db100000db", DecimalToBinary(32))
    assert.Equal("db1111db", DecimalToBinary(15))
}