Skip to content

Instantly share code, notes, and snippets.

@seemcat
Last active January 12, 2019 22:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save seemcat/2bfcd16e89c26f6e6b02ee7b38d245ce to your computer and use it in GitHub Desktop.
Save seemcat/2bfcd16e89c26f6e6b02ee7b38d245ce to your computer and use it in GitHub Desktop.
c0d3 solved in Go
package main
import (
"fmt"
)
var i int = 1
func solution9(num int) int {
if (num + i) % 7 == 0 {
return num + i
}
i = i + 1
return solution9(num)
}
func main() {
fmt.Println(solution9(14))
}
@valtyriel
Copy link

package main

import (
	"fmt"
)

// Q1. Write a function that takes in a number and
// returns the next number that is divisible by 7.
func next7(n int) int {
	n++
	if n%7 == 0 {
		return n
	}
	return next7(n)
}

func main() {
	fmt.Println("next multiple of seven after i:")
	for i := 0; i < 20; i++ {
		fmt.Printf("%v: %v\n", i, next7(i))
	}
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment