Pages

Showing posts with label fraction. Show all posts
Showing posts with label fraction. Show all posts

Wednesday, July 13, 2011

Problem #33

Problem link
Solution:
package main

func main() {
var i, j, k, ki, ij int
result := 1.0
for i = 1; i < 10; i++ {
for j = 1; j < i; j++ {
for k = 1; k < j; k++ {
ki = 10*k + i
ij = 10*i + j
if ki*j == ij*k {
result *= float64(ij) / float64(ki)
}
}
}
}
println(int(result))
}



Result: 100
Time: 0m0.003s

Problem #40

Problem link
Solution:
package main

import (
"strconv"
)

func main() {
i, count, limit, mul := 1, 0, 10, 1
var tmp int
for limit < 1000001 {
str := strconv.Itoa(i)
count += len(str)
if count >= limit {
tmp, _ = strconv.Atoi(str[len(str)-(count-limit)-1 : len(str)-(count-limit)])
mul *= tmp
limit *= 10
}
i++
}
println(mul)
}



Result: 210
Time: 0m0.153s