Skip to content

Instantly share code, notes, and snippets.

@MaksymTrykur
Last active March 31, 2017 15:13
Show Gist options
  • Save MaksymTrykur/69383328b5423dc9b0abd242fec92754 to your computer and use it in GitHub Desktop.
Save MaksymTrykur/69383328b5423dc9b0abd242fec92754 to your computer and use it in GitHub Desktop.
codejam.go
package main
import (
"bufio"
"fmt"
"os"
"strconv"
)
func check(err error) {
if err != nil {
panic(err)
}
}
func main() {
file, _ := os.Open("./A-small-practice.in")
fscanner := bufio.NewScanner(file)
_ = fscanner.Scan()
i := 0
for fscanner.Scan() {
i++
n, err := strconv.Atoi(fscanner.Text())
check(err)
if n == 0 {
fmt.Printf("Case #%d: INSOMNIA \n", i)
continue
}
res := make(map[string]bool)
for k := 1; ; k++ {
for _, s := range strconv.Itoa(k * n) {
res[string(s)] = true
}
if len(res) >= 10 {
fmt.Printf("Case #%d: %d\n", i, k*n)
break
}
}
}
}
package main
import (
"bufio"
"fmt"
"os"
)
func main() {
file, _ := os.Open("./B-large-practice.in")
fscanner := bufio.NewScanner(file)
_ = fscanner.Scan()
i := 0
for fscanner.Scan() {
i++
str := []rune(fscanner.Text())
n := 0
last := '+'
for k := len(str) - 1; k >= 0; k-- {
if str[k] == last {
continue
}
last = str[k]
n++
}
fmt.Printf("Case #%d: %d\n", i, n)
}
}
package main
import (
"bufio"
"fmt"
"math/big"
"os"
"strconv"
"strings"
)
func main() {
file, _ := os.Open("./C-small-practice.in")
fscanner := bufio.NewScanner(file)
_ = fscanner.Scan()
i := 1
for fscanner.Scan() {
in := strings.Split(fscanner.Text(), " ")
n, err := strconv.Atoi(in[0])
if err != nil {
panic(err)
}
//j, err := strconv.Atoi(in[1])
//if err != nil {
// panic(err)
//}
min, ok := big.NewInt(0).SetString("1"+strings.Repeat("0", n-2)+"1", 2)
if !ok {
panic("min panic")
}
max, ok := big.NewInt(0).SetString("1"+strings.Repeat("1", n-2)+"1", 2)
if !ok {
panic("max panic")
}
fmt.Printf("Case #%d:\n", i)
for m := min; m.Cmp(max) <= 0; m.Add(m, big.NewInt(1)) {
str := m.Text(2)
if strings.HasSuffix(str, "0") {
continue
}
for base := 10; base >= 2; base-- {
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment