Matrix A, consisting of N rows and N columns of non-negative integers, is given. Rows are numbered from 0 to N−1 (from top to bottom). Columns are numbered from 0 to N−1 (from left to right). We would like to find a path that starts at the upper-left corner (0, 0) and, moving only right and down, finishes at the bottom-right corner (N−1, N−1). Then, all the numbers on this path will be multiplied together.
Find a path such that the product of all the numbers on the path contain the minimal number of trailing zeros. We assume that 0 has 1 trailing zero.
Write a function:
func Solution(A [][]int) int
that, given matrix A, returns the minimal number of trailing zeros.
Examples:
1. Given matrix A below:
the function should return 1. The optimal path is: (0,0) → (0,1) → (0,2) → (1,2) → (2,2) → (2,3) → (3,3). The product of numbers 2, 10, 1, 4, 2, 1, 1 is 160, which has one trailing zero. There is no path that yields a product with no trailing zeros.
2. Given matrix A below:
the function should return 2. One of the optimal paths is: (0,0) → (1,0) → (1,1) → (1,2) → (2,2) → (3,2) → (3,3). The product of numbers 10, 1, 1, 1, 10, 1, 1 is 100, which has two trailing zeros. There is no path that yields a product with fewer than two trailing zeros.
3. Given matrix A below:
the function should return 1. One of the optimal paths is: (0,0) → (0,1) → (1,1) → (1,2) → (2,2). The product of numbers 10, 10, 0, 10, 10 is 0, which has one trailing zero. There is no path that yields a product with no trailing zeros.
Write an efficient algorithm for the following assumptions:
- N is an integer within the range [1..500];
- each element of matrix A is an integer within the range [0..1,000,000,000].
package solution
// you can also use imports, for example:
import "fmt"
// import "os"
// you can write to stdout for debugging purposes, e.g.
// fmt.Println("this is a debug message")
func Solution(A [][]int) int {
size := len(A)
firstProduct := parseProduct(A[0][0])
seen := make(map[xy]product)
seen[xy{
x: 0,
y: 0,
}] = firstProduct
for i := 1; i < size; i++ {
seen[xy{0,i}] = productCalc(seen[xy{0, i-1}], A[i][0])
seen[xy{i,0}] = productCalc(seen[xy{i-1,0}], A[0][i])
}
for y := 1; y < size; y++ {
for x := 1; x < size; x++ {
up := productCalc(seen[xy{x-1,y}], A[y][x])
left := productCalc(seen[xy{x,y-1}], A[y][x])
if up.zeros < left.zeros {
seen[xy{x,y}] = up
} else {
seen[xy{x,y}] = left
}
}
}
return seen[xy{size-1,size-1}].zeros
}
func productCalc(p product, i int) product{
if i == 0 || p.nonZero == 0 {
return product {
zeros: 1,
nonZero: 0,
}
}
if i == 1 {
return p
}
p2 := parseProduct(i)
extra := p.nonZero * p2.nonZero
nonZero, zeros := zs(extra)
return product{
zeros: p.zeros + p2.zeros + zeros,
nonZero: nonZero,
}
}
type xy struct {
x int
y int
}
type product struct {
zeros int
nonZero int
}
var seenInts = make(map[int]product)
func parseProduct(i int) product {
if p, ok := seenInts[i]; ok {
return p
}
nonZero, zeros := zs(i)
return product {
zeros: zeros,
nonZero: nonZero,
}
}
func zs(i int) (int, int) {
switch {
case i == 0:
return 0, 1
case i % 10 != 0:
return i % 10, 0
case i == 1000000000:
return 1, 9
case i % 100000000 == 0:
return i / 100000000 % 10, 8
case i % 10000000 == 0:
return i / 10000000 % 10, 7
case i % 1000000 == 0:
return i / 1000000 % 10, 6
case i % 100000 == 0:
return i / 100000 % 10, 5
case i % 10000 == 0:
return i / 10000 % 10, 4
case i % 1000 == 0:
return i / 1000 % 10, 3
case i % 100 == 0:
return i / 100 % 10, 2
case i % 10 == 0:
return i / 10, 1
}
fmt.Println("error!")
return 0,0
}
package solution
// you can also use imports, for example:
import "fmt"
// import "os"
// you can write to stdout for debugging purposes, e.g.
// fmt.Println("this is a debug message")
func Solution(A [][]int) int {
size := len(A)
firstProduct := parseProduct(A[0][0])
seen := []
seen[xy{
x: 0,
y: 0,
}] = firstProduct
for i := 1; i < size; i++ {
seen[xy{0,i}] = productCalc(seen[xy{0, i-1}], A[i][0])
seen[xy{i,0}] = productCalc(seen[xy{i-1,0}], A[0][i])
}
for y := 1; y < size; y++ {
for x := 1; x < size; x++ {
up := productCalc(seen[xy{x-1,y}], A[y][x])
left := productCalc(seen[xy{x,y-1}], A[y][x])
if up.zeros < left.zeros {
seen[xy{x,y}] = up
} else {
seen[xy{x,y}] = left
}
}
}
return seen[xy{size-1,size-1}].zeros
}
func productCalc(p product, i int) product{
if i == 0 || p.nonZero == 0 {
return product {
zeros: 1,
nonZero: 0,
}
}
if i == 1 {
return p
}
p2 := parseProduct(i)
extra := p.nonZero * p2.nonZero
nonZero, zeros := zs(extra)
return product{
zeros: p.zeros + p2.zeros + zeros,
nonZero: nonZero,
}
}
type xy struct {
x int
y int
}
type product struct {
zeros int
nonZero int
}
var seenInts = make(map[int]product)
func parseProduct(i int) product {
if p, ok := seenInts[i]; ok {
return p
}
nonZero, zeros := zs(i)
return product {
zeros: zeros,
nonZero: nonZero,
}
}
func zs(i int) (int, int) {
switch {
case i == 0:
return 0, 1
case i % 10 != 0:
return i % 10, 0
case i == 1000000000:
return 1, 9
case i % 100000000 == 0:
return i / 100000000 % 10, 8
case i % 10000000 == 0:
return i / 10000000 % 10, 7
case i % 1000000 == 0:
return i / 1000000 % 10, 6
case i % 100000 == 0:
return i / 100000 % 10, 5
case i % 10000 == 0:
return i / 10000 % 10, 4
case i % 1000 == 0:
return i / 1000 % 10, 3
case i % 100 == 0:
return i / 100 % 10, 2
case i % 10 == 0:
return i / 10, 1
}
fmt.Println("error!")
return 0,0
}
package solution
// you can also use imports, for example:
import "fmt"
// import "os"
// you can write to stdout for debugging purposes, e.g.
// fmt.Println("this is a debug message")
func Solution(A [][]int) int {
size := len(A)
firstProduct := parseProduct(A[0][0])
seen := [size][]product{}
seen[xy{
x: 0,
y: 0,
}] = firstProduct
for i := 1; i < size; i++ {
seen[xy{0,i}] = productCalc(seen[xy{0, i-1}], A[i][0])
seen[xy{i,0}] = productCalc(seen[xy{i-1,0}], A[0][i])
}
for y := 1; y < size; y++ {
for x := 1; x < size; x++ {
up := productCalc(seen[xy{x-1,y}], A[y][x])
left := productCalc(seen[xy{x,y-1}], A[y][x])
if up.zeros < left.zeros {
seen[xy{x,y}] = up
} else {
seen[xy{x,y}] = left
}
}
}
return seen[xy{size-1,size-1}].zeros
}
func productCalc(p product, i int) product{
if i == 0 || p.nonZero == 0 {
return product {
zeros: 1,
nonZero: 0,
}
}
if i == 1 {
return p
}
p2 := parseProduct(i)
extra := p.nonZero * p2.nonZero
nonZero, zeros := zs(extra)
return product{
zeros: p.zeros + p2.zeros + zeros,
nonZero: nonZero,
}
}
type xy struct {
x int
y int
}
type product struct {
zeros int
nonZero int
}
var seenInts = make(map[int]product)
func parseProduct(i int) product {
if p, ok := seenInts[i]; ok {
return p
}
nonZero, zeros := zs(i)
return product {
zeros: zeros,
nonZero: nonZero,
}
}
func zs(i int) (int, int) {
switch {
case i == 0:
return 0, 1
case i % 10 != 0:
return i % 10, 0
case i == 1000000000:
return 1, 9
case i % 100000000 == 0:
return i / 100000000 % 10, 8
case i % 10000000 == 0:
return i / 10000000 % 10, 7
case i % 1000000 == 0:
return i / 1000000 % 10, 6
case i % 100000 == 0:
return i / 100000 % 10, 5
case i % 10000 == 0:
return i / 10000 % 10, 4
case i % 1000 == 0:
return i / 1000 % 10, 3
case i % 100 == 0:
return i / 100 % 10, 2
case i % 10 == 0:
return i / 10, 1
}
fmt.Println("error!")
return 0,0
}
package solution
// you can also use imports, for example:
import "fmt"
// import "os"
// you can write to stdout for debugging purposes, e.g.
// fmt.Println("this is a debug message")
func Solution(A [][]int) int {
size := len(A)
firstProduct := parseProduct(A[0][0])
seen := [size][]product{}
for i := range seen {
seen[i] = [size]product{}
}
seen[xy{
x: 0,
y: 0,
}] = firstProduct
for i := 1; i < size; i++ {
seen[xy{0,i}] = productCalc(seen[xy{0, i-1}], A[i][0])
seen[xy{i,0}] = productCalc(seen[xy{i-1,0}], A[0][i])
}
for y := 1; y < size; y++ {
for x := 1; x < size; x++ {
up := productCalc(seen[xy{x-1,y}], A[y][x])
left := productCalc(seen[xy{x,y-1}], A[y][x])
if up.zeros < left.zeros {
seen[xy{x,y}] = up
} else {
seen[xy{x,y}] = left
}
}
}
return seen[xy{size-1,size-1}].zeros
}
func productCalc(p product, i int) product{
if i == 0 || p.nonZero == 0 {
return product {
zeros: 1,
nonZero: 0,
}
}
if i == 1 {
return p
}
p2 := parseProduct(i)
extra := p.nonZero * p2.nonZero
nonZero, zeros := zs(extra)
return product{
zeros: p.zeros + p2.zeros + zeros,
nonZero: nonZero,
}
}
type xy struct {
x int
y int
}
type product struct {
zeros int
nonZero int
}
var seenInts = make(map[int]product)
func parseProduct(i int) product {
if p, ok := seenInts[i]; ok {
return p
}
nonZero, zeros := zs(i)
return product {
zeros: zeros,
nonZero: nonZero,
}
}
func zs(i int) (int, int) {
switch {
case i == 0:
return 0, 1
case i % 10 != 0:
return i % 10, 0
case i == 1000000000:
return 1, 9
case i % 100000000 == 0:
return i / 100000000 % 10, 8
case i % 10000000 == 0:
return i / 10000000 % 10, 7
case i % 1000000 == 0:
return i / 1000000 % 10, 6
case i % 100000 == 0:
return i / 100000 % 10, 5
case i % 10000 == 0:
return i / 10000 % 10, 4
case i % 1000 == 0:
return i / 1000 % 10, 3
case i % 100 == 0:
return i / 100 % 10, 2
case i % 10 == 0:
return i / 10, 1
}
fmt.Println("error!")
return 0,0
}
package solution
// you can also use imports, for example:
import "fmt"
// import "os"
// you can write to stdout for debugging purposes, e.g.
// fmt.Println("this is a debug message")
func Solution(A [][]int) int {
size := len(A)
firstProduct := parseProduct(A[0][0])
seen := [size][]product{}
for i := range seen {
seen[i] = [size]product{}
}
seen[0][0] = firstProduct
for i := 1; i < size; i++ {
seen[xy{0,i}] = productCalc(seen[xy{0, i-1}], A[i][0])
seen[xy{i,0}] = productCalc(seen[xy{i-1,0}], A[0][i])
}
for y := 1; y < size; y++ {
for x := 1; x < size; x++ {
up := productCalc(seen[xy{x-1,y}], A[y][x])
left := productCalc(seen[xy{x,y-1}], A[y][x])
if up.zeros < left.zeros {
seen[xy{x,y}] = up
} else {
seen[xy{x,y}] = left
}
}
}
return seen[xy{size-1,size-1}].zeros
}
func productCalc(p product, i int) product{
if i == 0 || p.nonZero == 0 {
return product {
zeros: 1,
nonZero: 0,
}
}
if i == 1 {
return p
}
p2 := parseProduct(i)
extra := p.nonZero * p2.nonZero
nonZero, zeros := zs(extra)
return product{
zeros: p.zeros + p2.zeros + zeros,
nonZero: nonZero,
}
}
type xy struct {
x int
y int
}
type product struct {
zeros int
nonZero int
}
var seenInts = make(map[int]product)
func parseProduct(i int) product {
if p, ok := seenInts[i]; ok {
return p
}
nonZero, zeros := zs(i)
return product {
zeros: zeros,
nonZero: nonZero,
}
}
func zs(i int) (int, int) {
switch {
case i == 0:
return 0, 1
case i % 10 != 0:
return i % 10, 0
case i == 1000000000:
return 1, 9
case i % 100000000 == 0:
return i / 100000000 % 10, 8
case i % 10000000 == 0:
return i / 10000000 % 10, 7
case i % 1000000 == 0:
return i / 1000000 % 10, 6
case i % 100000 == 0:
return i / 100000 % 10, 5
case i % 10000 == 0:
return i / 10000 % 10, 4
case i % 1000 == 0:
return i / 1000 % 10, 3
case i % 100 == 0:
return i / 100 % 10, 2
case i % 10 == 0:
return i / 10, 1
}
fmt.Println("error!")
return 0,0
}
package solution
// you can also use imports, for example:
import "fmt"
// import "os"
// you can write to stdout for debugging purposes, e.g.
// fmt.Println("this is a debug message")
func Solution(A [][]int) int {
size := len(A)
firstProduct := parseProduct(A[0][0])
seen := [size][]product{}
for i := range seen {
seen[i] = [size]product{}
}
seen[0][0] = firstProduct
for i := 1; i < size; i++ {
seen[0][i] = productCalc(seen[xy{0, i-1}], A[i][0])
seen[xy{i,0}] = productCalc(seen[xy{i-1,0}], A[0][i])
}
for y := 1; y < size; y++ {
for x := 1; x < size; x++ {
up := productCalc(seen[xy{x-1,y}], A[y][x])
left := productCalc(seen[xy{x,y-1}], A[y][x])
if up.zeros < left.zeros {
seen[xy{x,y}] = up
} else {
seen[xy{x,y}] = left
}
}
}
return seen[xy{size-1,size-1}].zeros
}
func productCalc(p product, i int) product{
if i == 0 || p.nonZero == 0 {
return product {
zeros: 1,
nonZero: 0,
}
}
if i == 1 {
return p
}
p2 := parseProduct(i)
extra := p.nonZero * p2.nonZero
nonZero, zeros := zs(extra)
return product{
zeros: p.zeros + p2.zeros + zeros,
nonZero: nonZero,
}
}
type xy struct {
x int
y int
}
type product struct {
zeros int
nonZero int
}
var seenInts = make(map[int]product)
func parseProduct(i int) product {
if p, ok := seenInts[i]; ok {
return p
}
nonZero, zeros := zs(i)
return product {
zeros: zeros,
nonZero: nonZero,
}
}
func zs(i int) (int, int) {
switch {
case i == 0:
return 0, 1
case i % 10 != 0:
return i % 10, 0
case i == 1000000000:
return 1, 9
case i % 100000000 == 0:
return i / 100000000 % 10, 8
case i % 10000000 == 0:
return i / 10000000 % 10, 7
case i % 1000000 == 0:
return i / 1000000 % 10, 6
case i % 100000 == 0:
return i / 100000 % 10, 5
case i % 10000 == 0:
return i / 10000 % 10, 4
case i % 1000 == 0:
return i / 1000 % 10, 3
case i % 100 == 0:
return i / 100 % 10, 2
case i % 10 == 0:
return i / 10, 1
}
fmt.Println("error!")
return 0,0
}
package solution
// you can also use imports, for example:
import "fmt"
// import "os"
// you can write to stdout for debugging purposes, e.g.
// fmt.Println("this is a debug message")
func Solution(A [][]int) int {
size := len(A)
firstProduct := parseProduct(A[0][0])
seen := [size][]product{}
for i := range seen {
seen[i] = [size]product{}
}
seen[0][0] = firstProduct
for i := 1; i < size; i++ {
seen[0][i] = productCalc(seen[xy{0, i-1}], A[i][0])
seen[i][0] = productCalc(seen[xy{i-1,0}], A[0][i])
}
for y := 1; y < size; y++ {
for x := 1; x < size; x++ {
up := productCalc(seen[xy{x-1,y}], A[y][x])
left := productCalc(seen[xy{x,y-1}], A[y][x])
if up.zeros < left.zeros {
seen[xy{x,y}] = up
} else {
seen[xy{x,y}] = left
}
}
}
return seen[xy{size-1,size-1}].zeros
}
func productCalc(p product, i int) product{
if i == 0 || p.nonZero == 0 {
return product {
zeros: 1,
nonZero: 0,
}
}
if i == 1 {
return p
}
p2 := parseProduct(i)
extra := p.nonZero * p2.nonZero
nonZero, zeros := zs(extra)
return product{
zeros: p.zeros + p2.zeros + zeros,
nonZero: nonZero,
}
}
type xy struct {
x int
y int
}
type product struct {
zeros int
nonZero int
}
var seenInts = make(map[int]product)
func parseProduct(i int) product {
if p, ok := seenInts[i]; ok {
return p
}
nonZero, zeros := zs(i)
return product {
zeros: zeros,
nonZero: nonZero,
}
}
func zs(i int) (int, int) {
switch {
case i == 0:
return 0, 1
case i % 10 != 0:
return i % 10, 0
case i == 1000000000:
return 1, 9
case i % 100000000 == 0:
return i / 100000000 % 10, 8
case i % 10000000 == 0:
return i / 10000000 % 10, 7
case i % 1000000 == 0:
return i / 1000000 % 10, 6
case i % 100000 == 0:
return i / 100000 % 10, 5
case i % 10000 == 0:
return i / 10000 % 10, 4
case i % 1000 == 0:
return i / 1000 % 10, 3
case i % 100 == 0:
return i / 100 % 10, 2
case i % 10 == 0:
return i / 10, 1
}
fmt.Println("error!")
return 0,0
}
package solution
// you can also use imports, for example:
import "fmt"
// import "os"
// you can write to stdout for debugging purposes, e.g.
// fmt.Println("this is a debug message")
func Solution(A [][]int) int {
size := len(A)
firstProduct := parseProduct(A[0][0])
seen := [size][]product{}
for i := range seen {
seen[i] = [size]product{}
}
seen[0][0] = firstProduct
for i := 1; i < size; i++ {
seen[0][i] = productCalc(seen[xy{0, i-1}], A[i][0])
seen[i][0] = productCalc(seen[i-1][0], A[0][i])
}
for y := 1; y < size; y++ {
for x := 1; x < size; x++ {
up := productCalc(seen[xy{x-1,y}], A[y][x])
left := productCalc(seen[xy{x,y-1}], A[y][x])
if up.zeros < left.zeros {
seen[xy{x,y}] = up
} else {
seen[xy{x,y}] = left
}
}
}
return seen[xy{size-1,size-1}].zeros
}
func productCalc(p product, i int) product{
if i == 0 || p.nonZero == 0 {
return product {
zeros: 1,
nonZero: 0,
}
}
if i == 1 {
return p
}
p2 := parseProduct(i)
extra := p.nonZero * p2.nonZero
nonZero, zeros := zs(extra)
return product{
zeros: p.zeros + p2.zeros + zeros,
nonZero: nonZero,
}
}
type xy struct {
x int
y int
}
type product struct {
zeros int
nonZero int
}
var seenInts = make(map[int]product)
func parseProduct(i int) product {
if p, ok := seenInts[i]; ok {
return p
}
nonZero, zeros := zs(i)
return product {
zeros: zeros,
nonZero: nonZero,
}
}
func zs(i int) (int, int) {
switch {
case i == 0:
return 0, 1
case i % 10 != 0:
return i % 10, 0
case i == 1000000000:
return 1, 9
case i % 100000000 == 0:
return i / 100000000 % 10, 8
case i % 10000000 == 0:
return i / 10000000 % 10, 7
case i % 1000000 == 0:
return i / 1000000 % 10, 6
case i % 100000 == 0:
return i / 100000 % 10, 5
case i % 10000 == 0:
return i / 10000 % 10, 4
case i % 1000 == 0:
return i / 1000 % 10, 3
case i % 100 == 0:
return i / 100 % 10, 2
case i % 10 == 0:
return i / 10, 1
}
fmt.Println("error!")
return 0,0
}
package solution
// you can also use imports, for example:
import "fmt"
// import "os"
// you can write to stdout for debugging purposes, e.g.
// fmt.Println("this is a debug message")
func Solution(A [][]int) int {
size := len(A)
firstProduct := parseProduct(A[0][0])
seen := [size][]product{}
for i := range seen {
seen[i] = [size]product{}
}
seen[0][0] = firstProduct
for i := 1; i < size; i++ {
seen[0][i] = productCalc(seen[0][i-1], A[i][0])
seen[i][0] = productCalc(seen[i-1][0], A[0][i])
}
for y := 1; y < size; y++ {
for x := 1; x < size; x++ {
up := productCalc(seen[xy{x-1,y}], A[y][x])
left := productCalc(seen[xy{x,y-1}], A[y][x])
if up.zeros < left.zeros {
seen[xy{x,y}] = up
} else {
seen[xy{x,y}] = left
}
}
}
return seen[xy{size-1,size-1}].zeros
}
func productCalc(p product, i int) product{
if i == 0 || p.nonZero == 0 {
return product {
zeros: 1,
nonZero: 0,
}
}
if i == 1 {
return p
}
p2 := parseProduct(i)
extra := p.nonZero * p2.nonZero
nonZero, zeros := zs(extra)
return product{
zeros: p.zeros + p2.zeros + zeros,
nonZero: nonZero,
}
}
type xy struct {
x int
y int
}
type product struct {
zeros int
nonZero int
}
var seenInts = make(map[int]product)
func parseProduct(i int) product {
if p, ok := seenInts[i]; ok {
return p
}
nonZero, zeros := zs(i)
return product {
zeros: zeros,
nonZero: nonZero,
}
}
func zs(i int) (int, int) {
switch {
case i == 0:
return 0, 1
case i % 10 != 0:
return i % 10, 0
case i == 1000000000:
return 1, 9
case i % 100000000 == 0:
return i / 100000000 % 10, 8
case i % 10000000 == 0:
return i / 10000000 % 10, 7
case i % 1000000 == 0:
return i / 1000000 % 10, 6
case i % 100000 == 0:
return i / 100000 % 10, 5
case i % 10000 == 0:
return i / 10000 % 10, 4
case i % 1000 == 0:
return i / 1000 % 10, 3
case i % 100 == 0:
return i / 100 % 10, 2
case i % 10 == 0:
return i / 10, 1
}
fmt.Println("error!")
return 0,0
}
package solution
// you can also use imports, for example:
import "fmt"
// import "os"
// you can write to stdout for debugging purposes, e.g.
// fmt.Println("this is a debug message")
func Solution(A [][]int) int {
size := len(A)
firstProduct := parseProduct(A[0][0])
seen := [size][]product{}
for i := range seen {
seen[i] = [size]product{}
}
seen[0][0] = firstProduct
for i := 1; i < size; i++ {
seen[i][0] = productCalc(seen[i-1][0], A[i][0])
seen[0][i] = productCalc(seen[0][i-1], A[0][i])
}
for y := 1; y < size; y++ {
for x := 1; x < size; x++ {
up := productCalc(seen[xy{x-1,y}], A[y][x])
left := productCalc(seen[xy{x,y-1}], A[y][x])
if up.zeros < left.zeros {
seen[xy{x,y}] = up
} else {
seen[xy{x,y}] = left
}
}
}
return seen[xy{size-1,size-1}].zeros
}
func productCalc(p product, i int) product{
if i == 0 || p.nonZero == 0 {
return product {
zeros: 1,
nonZero: 0,
}
}
if i == 1 {
return p
}
p2 := parseProduct(i)
extra := p.nonZero * p2.nonZero
nonZero, zeros := zs(extra)
return product{
zeros: p.zeros + p2.zeros + zeros,
nonZero: nonZero,
}
}
type xy struct {
x int
y int
}
type product struct {
zeros int
nonZero int
}
var seenInts = make(map[int]product)
func parseProduct(i int) product {
if p, ok := seenInts[i]; ok {
return p
}
nonZero, zeros := zs(i)
return product {
zeros: zeros,
nonZero: nonZero,
}
}
func zs(i int) (int, int) {
switch {
case i == 0:
return 0, 1
case i % 10 != 0:
return i % 10, 0
case i == 1000000000:
return 1, 9
case i % 100000000 == 0:
return i / 100000000 % 10, 8
case i % 10000000 == 0:
return i / 10000000 % 10, 7
case i % 1000000 == 0:
return i / 1000000 % 10, 6
case i % 100000 == 0:
return i / 100000 % 10, 5
case i % 10000 == 0:
return i / 10000 % 10, 4
case i % 1000 == 0:
return i / 1000 % 10, 3
case i % 100 == 0:
return i / 100 % 10, 2
case i % 10 == 0:
return i / 10, 1
}
fmt.Println("error!")
return 0,0
}
package solution
// you can also use imports, for example:
import "fmt"
// import "os"
// you can write to stdout for debugging purposes, e.g.
// fmt.Println("this is a debug message")
func Solution(A [][]int) int {
size := len(A)
firstProduct := parseProduct(A[0][0])
seen := [size][]product{}
for i := range seen {
seen[i] = [size]product{}
}
seen[0][0] = firstProduct
for i := 1; i < size; i++ {
seen[i][0] = productCalc(seen[i-1][0], A[i][0])
seen[0][i] = productCalc(seen[0][i-1], A[0][i])
}
for y := 1; y < size; y++ {
for x := 1; x < size; x++ {
up := productCalc(seen[y][x-1], A[y][x])
left := productCalc(seen[xy{x,y-1}], A[y][x])
if up.zeros < left.zeros {
seen[xy{x,y}] = up
} else {
seen[xy{x,y}] = left
}
}
}
return seen[xy{size-1,size-1}].zeros
}
func productCalc(p product, i int) product{
if i == 0 || p.nonZero == 0 {
return product {
zeros: 1,
nonZero: 0,
}
}
if i == 1 {
return p
}
p2 := parseProduct(i)
extra := p.nonZero * p2.nonZero
nonZero, zeros := zs(extra)
return product{
zeros: p.zeros + p2.zeros + zeros,
nonZero: nonZero,
}
}
type xy struct {
x int
y int
}
type product struct {
zeros int
nonZero int
}
var seenInts = make(map[int]product)
func parseProduct(i int) product {
if p, ok := seenInts[i]; ok {
return p
}
nonZero, zeros := zs(i)
return product {
zeros: zeros,
nonZero: nonZero,
}
}
func zs(i int) (int, int) {
switch {
case i == 0:
return 0, 1
case i % 10 != 0:
return i % 10, 0
case i == 1000000000:
return 1, 9
case i % 100000000 == 0:
return i / 100000000 % 10, 8
case i % 10000000 == 0:
return i / 10000000 % 10, 7
case i % 1000000 == 0:
return i / 1000000 % 10, 6
case i % 100000 == 0:
return i / 100000 % 10, 5
case i % 10000 == 0:
return i / 10000 % 10, 4
case i % 1000 == 0:
return i / 1000 % 10, 3
case i % 100 == 0:
return i / 100 % 10, 2
case i % 10 == 0:
return i / 10, 1
}
fmt.Println("error!")
return 0,0
}
package solution
// you can also use imports, for example:
import "fmt"
// import "os"
// you can write to stdout for debugging purposes, e.g.
// fmt.Println("this is a debug message")
func Solution(A [][]int) int {
size := len(A)
firstProduct := parseProduct(A[0][0])
seen := [size][]product{}
for i := range seen {
seen[i] = [size]product{}
}
seen[0][0] = firstProduct
for i := 1; i < size; i++ {
seen[i][0] = productCalc(seen[i-1][0], A[i][0])
seen[0][i] = productCalc(seen[0][i-1], A[0][i])
}
for y := 1; y < size; y++ {
for x := 1; x < size; x++ {
up := productCalc(seen[y][x-1], A[y][x])
left := productCalc(seen[y-1][x], A[y][x])
if up.zeros < left.zeros {
seen[xy{x,y}] = up
} else {
seen[xy{x,y}] = left
}
}
}
return seen[xy{size-1,size-1}].zeros
}
func productCalc(p product, i int) product{
if i == 0 || p.nonZero == 0 {
return product {
zeros: 1,
nonZero: 0,
}
}
if i == 1 {
return p
}
p2 := parseProduct(i)
extra := p.nonZero * p2.nonZero
nonZero, zeros := zs(extra)
return product{
zeros: p.zeros + p2.zeros + zeros,
nonZero: nonZero,
}
}
type xy struct {
x int
y int
}
type product struct {
zeros int
nonZero int
}
var seenInts = make(map[int]product)
func parseProduct(i int) product {
if p, ok := seenInts[i]; ok {
return p
}
nonZero, zeros := zs(i)
return product {
zeros: zeros,
nonZero: nonZero,
}
}
func zs(i int) (int, int) {
switch {
case i == 0:
return 0, 1
case i % 10 != 0:
return i % 10, 0
case i == 1000000000:
return 1, 9
case i % 100000000 == 0:
return i / 100000000 % 10, 8
case i % 10000000 == 0:
return i / 10000000 % 10, 7
case i % 1000000 == 0:
return i / 1000000 % 10, 6
case i % 100000 == 0:
return i / 100000 % 10, 5
case i % 10000 == 0:
return i / 10000 % 10, 4
case i % 1000 == 0:
return i / 1000 % 10, 3
case i % 100 == 0:
return i / 100 % 10, 2
case i % 10 == 0:
return i / 10, 1
}
fmt.Println("error!")
return 0,0
}
package solution
// you can also use imports, for example:
import "fmt"
// import "os"
// you can write to stdout for debugging purposes, e.g.
// fmt.Println("this is a debug message")
func Solution(A [][]int) int {
size := len(A)
firstProduct := parseProduct(A[0][0])
seen := [size][]product{}
for i := range seen {
seen[i] = [size]product{}
}
seen[0][0] = firstProduct
for i := 1; i < size; i++ {
seen[i][0] = productCalc(seen[i-1][0], A[i][0])
seen[0][i] = productCalc(seen[0][i-1], A[0][i])
}
for y := 1; y < size; y++ {
for x := 1; x < size; x++ {
up := productCalc(seen[y][x-1], A[y][x])
left := productCalc(seen[y-1][x], A[y][x])
if up.zeros < left.zeros {
seen[y][x] = up
} else {
seen[xy{x,y}] = left
}
}
}
return seen[xy{size-1,size-1}].zeros
}
func productCalc(p product, i int) product{
if i == 0 || p.nonZero == 0 {
return product {
zeros: 1,
nonZero: 0,
}
}
if i == 1 {
return p
}
p2 := parseProduct(i)
extra := p.nonZero * p2.nonZero
nonZero, zeros := zs(extra)
return product{
zeros: p.zeros + p2.zeros + zeros,
nonZero: nonZero,
}
}
type xy struct {
x int
y int
}
type product struct {
zeros int
nonZero int
}
var seenInts = make(map[int]product)
func parseProduct(i int) product {
if p, ok := seenInts[i]; ok {
return p
}
nonZero, zeros := zs(i)
return product {
zeros: zeros,
nonZero: nonZero,
}
}
func zs(i int) (int, int) {
switch {
case i == 0:
return 0, 1
case i % 10 != 0:
return i % 10, 0
case i == 1000000000:
return 1, 9
case i % 100000000 == 0:
return i / 100000000 % 10, 8
case i % 10000000 == 0:
return i / 10000000 % 10, 7
case i % 1000000 == 0:
return i / 1000000 % 10, 6
case i % 100000 == 0:
return i / 100000 % 10, 5
case i % 10000 == 0:
return i / 10000 % 10, 4
case i % 1000 == 0:
return i / 1000 % 10, 3
case i % 100 == 0:
return i / 100 % 10, 2
case i % 10 == 0:
return i / 10, 1
}
fmt.Println("error!")
return 0,0
}
package solution
// you can also use imports, for example:
import "fmt"
// import "os"
// you can write to stdout for debugging purposes, e.g.
// fmt.Println("this is a debug message")
func Solution(A [][]int) int {
size := len(A)
firstProduct := parseProduct(A[0][0])
seen := [size][]product{}
for i := range seen {
seen[i] = [size]product{}
}
seen[0][0] = firstProduct
for i := 1; i < size; i++ {
seen[i][0] = productCalc(seen[i-1][0], A[i][0])
seen[0][i] = productCalc(seen[0][i-1], A[0][i])
}
for y := 1; y < size; y++ {
for x := 1; x < size; x++ {
up := productCalc(seen[y][x-1], A[y][x])
left := productCalc(seen[y-1][x], A[y][x])
if up.zeros < left.zeros {
seen[y][x] = up
} else {
seen[y][x] = left
}
}
}
return seensize-1][size-1].zeros
}
func productCalc(p product, i int) product{
if i == 0 || p.nonZero == 0 {
return product {
zeros: 1,
nonZero: 0,
}
}
if i == 1 {
return p
}
p2 := parseProduct(i)
extra := p.nonZero * p2.nonZero
nonZero, zeros := zs(extra)
return product{
zeros: p.zeros + p2.zeros + zeros,
nonZero: nonZero,
}
}
type xy struct {
x int
y int
}
type product struct {
zeros int
nonZero int
}
var seenInts = make(map[int]product)
func parseProduct(i int) product {
if p, ok := seenInts[i]; ok {
return p
}
nonZero, zeros := zs(i)
return product {
zeros: zeros,
nonZero: nonZero,
}
}
func zs(i int) (int, int) {
switch {
case i == 0:
return 0, 1
case i % 10 != 0:
return i % 10, 0
case i == 1000000000:
return 1, 9
case i % 100000000 == 0:
return i / 100000000 % 10, 8
case i % 10000000 == 0:
return i / 10000000 % 10, 7
case i % 1000000 == 0:
return i / 1000000 % 10, 6
case i % 100000 == 0:
return i / 100000 % 10, 5
case i % 10000 == 0:
return i / 10000 % 10, 4
case i % 1000 == 0:
return i / 1000 % 10, 3
case i % 100 == 0:
return i / 100 % 10, 2
case i % 10 == 0:
return i / 10, 1
}
fmt.Println("error!")
return 0,0
}
package solution
// you can also use imports, for example:
import "fmt"
// import "os"
// you can write to stdout for debugging purposes, e.g.
// fmt.Println("this is a debug message")
func Solution(A [][]int) int {
size := len(A)
firstProduct := parseProduct(A[0][0])
seen := [size][]product{}
for i := range seen {
seen[i] = [size]product{}
}
seen[0][0] = firstProduct
for i := 1; i < size; i++ {
seen[i][0] = productCalc(seen[i-1][0], A[i][0])
seen[0][i] = productCalc(seen[0][i-1], A[0][i])
}
for y := 1; y < size; y++ {
for x := 1; x < size; x++ {
up := productCalc(seen[y][x-1], A[y][x])
left := productCalc(seen[y-1][x], A[y][x])
if up.zeros < left.zeros {
seen[y][x] = up
} else {
seen[y][x] = left
}
}
}
return seen[size-1][size-1].zeros
}
func productCalc(p product, i int) product{
if i == 0 || p.nonZero == 0 {
return product {
zeros: 1,
nonZero: 0,
}
}
if i == 1 {
return p
}
p2 := parseProduct(i)
extra := p.nonZero * p2.nonZero
nonZero, zeros := zs(extra)
return product{
zeros: p.zeros + p2.zeros + zeros,
nonZero: nonZero,
}
}
type xy struct {
x int
y int
}
type product struct {
zeros int
nonZero int
}
var seenInts = make(map[int]product)
func parseProduct(i int) product {
if p, ok := seenInts[i]; ok {
return p
}
nonZero, zeros := zs(i)
return product {
zeros: zeros,
nonZero: nonZero,
}
}
func zs(i int) (int, int) {
switch {
case i == 0:
return 0, 1
case i % 10 != 0:
return i % 10, 0
case i == 1000000000:
return 1, 9
case i % 100000000 == 0:
return i / 100000000 % 10, 8
case i % 10000000 == 0:
return i / 10000000 % 10, 7
case i % 1000000 == 0:
return i / 1000000 % 10, 6
case i % 100000 == 0:
return i / 100000 % 10, 5
case i % 10000 == 0:
return i / 10000 % 10, 4
case i % 1000 == 0:
return i / 1000 % 10, 3
case i % 100 == 0:
return i / 100 % 10, 2
case i % 10 == 0:
return i / 10, 1
}
fmt.Println("error!")
return 0,0
}
# solution workspace/src/solution/solution.go:14: non-constant array bound size workspace/src/solution/solution.go:16: non-constant array bound size
package solution
// you can also use imports, for example:
import "fmt"
// import "os"
// you can write to stdout for debugging purposes, e.g.
// fmt.Println("this is a debug message")
func Solution(A [][]int) int {
size := len(A)
firstProduct := parseProduct(A[0][0])
seen := [size][size]product{}
for i := range seen {
seen[i] = [size]product{}
}
seen[0][0] = firstProduct
for i := 1; i < size; i++ {
seen[i][0] = productCalc(seen[i-1][0], A[i][0])
seen[0][i] = productCalc(seen[0][i-1], A[0][i])
}
for y := 1; y < size; y++ {
for x := 1; x < size; x++ {
up := productCalc(seen[y][x-1], A[y][x])
left := productCalc(seen[y-1][x], A[y][x])
if up.zeros < left.zeros {
seen[y][x] = up
} else {
seen[y][x] = left
}
}
}
return seen[size-1][size-1].zeros
}
func productCalc(p product, i int) product{
if i == 0 || p.nonZero == 0 {
return product {
zeros: 1,
nonZero: 0,
}
}
if i == 1 {
return p
}
p2 := parseProduct(i)
extra := p.nonZero * p2.nonZero
nonZero, zeros := zs(extra)
return product{
zeros: p.zeros + p2.zeros + zeros,
nonZero: nonZero,
}
}
type xy struct {
x int
y int
}
type product struct {
zeros int
nonZero int
}
var seenInts = make(map[int]product)
func parseProduct(i int) product {
if p, ok := seenInts[i]; ok {
return p
}
nonZero, zeros := zs(i)
return product {
zeros: zeros,
nonZero: nonZero,
}
}
func zs(i int) (int, int) {
switch {
case i == 0:
return 0, 1
case i % 10 != 0:
return i % 10, 0
case i == 1000000000:
return 1, 9
case i % 100000000 == 0:
return i / 100000000 % 10, 8
case i % 10000000 == 0:
return i / 10000000 % 10, 7
case i % 1000000 == 0:
return i / 1000000 % 10, 6
case i % 100000 == 0:
return i / 100000 % 10, 5
case i % 10000 == 0:
return i / 10000 % 10, 4
case i % 1000 == 0:
return i / 1000 % 10, 3
case i % 100 == 0:
return i / 100 % 10, 2
case i % 10 == 0:
return i / 10, 1
}
fmt.Println("error!")
return 0,0
}
# solution workspace/src/solution/solution.go:14: non-constant array bound size workspace/src/solution/solution.go:16: non-constant array bound size
package solution
// you can also use imports, for example:
import "fmt"
// import "os"
// you can write to stdout for debugging purposes, e.g.
// fmt.Println("this is a debug message")
func Solution(A [][]int) int {
size := len(A)
firstProduct := parseProduct(A[0][0])
seen := make[]product{}
for i := range seen {
seen[i] = [size]product{}
}
seen[0][0] = firstProduct
for i := 1; i < size; i++ {
seen[i][0] = productCalc(seen[i-1][0], A[i][0])
seen[0][i] = productCalc(seen[0][i-1], A[0][i])
}
for y := 1; y < size; y++ {
for x := 1; x < size; x++ {
up := productCalc(seen[y][x-1], A[y][x])
left := productCalc(seen[y-1][x], A[y][x])
if up.zeros < left.zeros {
seen[y][x] = up
} else {
seen[y][x] = left
}
}
}
return seen[size-1][size-1].zeros
}
func productCalc(p product, i int) product{
if i == 0 || p.nonZero == 0 {
return product {
zeros: 1,
nonZero: 0,
}
}
if i == 1 {
return p
}
p2 := parseProduct(i)
extra := p.nonZero * p2.nonZero
nonZero, zeros := zs(extra)
return product{
zeros: p.zeros + p2.zeros + zeros,
nonZero: nonZero,
}
}
type xy struct {
x int
y int
}
type product struct {
zeros int
nonZero int
}
var seenInts = make(map[int]product)
func parseProduct(i int) product {
if p, ok := seenInts[i]; ok {
return p
}
nonZero, zeros := zs(i)
return product {
zeros: zeros,
nonZero: nonZero,
}
}
func zs(i int) (int, int) {
switch {
case i == 0:
return 0, 1
case i % 10 != 0:
return i % 10, 0
case i == 1000000000:
return 1, 9
case i % 100000000 == 0:
return i / 100000000 % 10, 8
case i % 10000000 == 0:
return i / 10000000 % 10, 7
case i % 1000000 == 0:
return i / 1000000 % 10, 6
case i % 100000 == 0:
return i / 100000 % 10, 5
case i % 10000 == 0:
return i / 10000 % 10, 4
case i % 1000 == 0:
return i / 1000 % 10, 3
case i % 100 == 0:
return i / 100 % 10, 2
case i % 10 == 0:
return i / 10, 1
}
fmt.Println("error!")
return 0,0
}
package solution
// you can also use imports, for example:
import "fmt"
// import "os"
// you can write to stdout for debugging purposes, e.g.
// fmt.Println("this is a debug message")
func Solution(A [][]int) int {
size := len(A)
firstProduct := parseProduct(A[0][0])
seen := make([]product, size
for i := range seen {
seen[i] = [size]product{}
}
seen[0][0] = firstProduct
for i := 1; i < size; i++ {
seen[i][0] = productCalc(seen[i-1][0], A[i][0])
seen[0][i] = productCalc(seen[0][i-1], A[0][i])
}
for y := 1; y < size; y++ {
for x := 1; x < size; x++ {
up := productCalc(seen[y][x-1], A[y][x])
left := productCalc(seen[y-1][x], A[y][x])
if up.zeros < left.zeros {
seen[y][x] = up
} else {
seen[y][x] = left
}
}
}
return seen[size-1][size-1].zeros
}
func productCalc(p product, i int) product{
if i == 0 || p.nonZero == 0 {
return product {
zeros: 1,
nonZero: 0,
}
}
if i == 1 {
return p
}
p2 := parseProduct(i)
extra := p.nonZero * p2.nonZero
nonZero, zeros := zs(extra)
return product{
zeros: p.zeros + p2.zeros + zeros,
nonZero: nonZero,
}
}
type xy struct {
x int
y int
}
type product struct {
zeros int
nonZero int
}
var seenInts = make(map[int]product)
func parseProduct(i int) product {
if p, ok := seenInts[i]; ok {
return p
}
nonZero, zeros := zs(i)
return product {
zeros: zeros,
nonZero: nonZero,
}
}
func zs(i int) (int, int) {
switch {
case i == 0:
return 0, 1
case i % 10 != 0:
return i % 10, 0
case i == 1000000000:
return 1, 9
case i % 100000000 == 0:
return i / 100000000 % 10, 8
case i % 10000000 == 0:
return i / 10000000 % 10, 7
case i % 1000000 == 0:
return i / 1000000 % 10, 6
case i % 100000 == 0:
return i / 100000 % 10, 5
case i % 10000 == 0:
return i / 10000 % 10, 4
case i % 1000 == 0:
return i / 1000 % 10, 3
case i % 100 == 0:
return i / 100 % 10, 2
case i % 10 == 0:
return i / 10, 1
}
fmt.Println("error!")
return 0,0
}
package solution
// you can also use imports, for example:
import "fmt"
// import "os"
// you can write to stdout for debugging purposes, e.g.
// fmt.Println("this is a debug message")
func Solution(A [][]int) int {
size := len(A)
firstProduct := parseProduct(A[0][0])
seen := make([][]product, size, size)
for i := range seen {
seen[i] = [size]product{}
}
seen[0][0] = firstProduct
for i := 1; i < size; i++ {
seen[i][0] = productCalc(seen[i-1][0], A[i][0])
seen[0][i] = productCalc(seen[0][i-1], A[0][i])
}
for y := 1; y < size; y++ {
for x := 1; x < size; x++ {
up := productCalc(seen[y][x-1], A[y][x])
left := productCalc(seen[y-1][x], A[y][x])
if up.zeros < left.zeros {
seen[y][x] = up
} else {
seen[y][x] = left
}
}
}
return seen[size-1][size-1].zeros
}
func productCalc(p product, i int) product{
if i == 0 || p.nonZero == 0 {
return product {
zeros: 1,
nonZero: 0,
}
}
if i == 1 {
return p
}
p2 := parseProduct(i)
extra := p.nonZero * p2.nonZero
nonZero, zeros := zs(extra)
return product{
zeros: p.zeros + p2.zeros + zeros,
nonZero: nonZero,
}
}
type xy struct {
x int
y int
}
type product struct {
zeros int
nonZero int
}
var seenInts = make(map[int]product)
func parseProduct(i int) product {
if p, ok := seenInts[i]; ok {
return p
}
nonZero, zeros := zs(i)
return product {
zeros: zeros,
nonZero: nonZero,
}
}
func zs(i int) (int, int) {
switch {
case i == 0:
return 0, 1
case i % 10 != 0:
return i % 10, 0
case i == 1000000000:
return 1, 9
case i % 100000000 == 0:
return i / 100000000 % 10, 8
case i % 10000000 == 0:
return i / 10000000 % 10, 7
case i % 1000000 == 0:
return i / 1000000 % 10, 6
case i % 100000 == 0:
return i / 100000 % 10, 5
case i % 10000 == 0:
return i / 10000 % 10, 4
case i % 1000 == 0:
return i / 1000 % 10, 3
case i % 100 == 0:
return i / 100 % 10, 2
case i % 10 == 0:
return i / 10, 1
}
fmt.Println("error!")
return 0,0
}
package solution
// you can also use imports, for example:
import "fmt"
// import "os"
// you can write to stdout for debugging purposes, e.g.
// fmt.Println("this is a debug message")
func Solution(A [][]int) int {
size := len(A)
firstProduct := parseProduct(A[0][0])
seen := make([][]product, size, size)
for i := range seen {
seen[i] = make([]product, size, size)
}
seen[0][0] = firstProduct
for i := 1; i < size; i++ {
seen[i][0] = productCalc(seen[i-1][0], A[i][0])
seen[0][i] = productCalc(seen[0][i-1], A[0][i])
}
for y := 1; y < size; y++ {
for x := 1; x < size; x++ {
up := productCalc(seen[y][x-1], A[y][x])
left := productCalc(seen[y-1][x], A[y][x])
if up.zeros < left.zeros {
seen[y][x] = up
} else {
seen[y][x] = left
}
}
}
return seen[size-1][size-1].zeros
}
func productCalc(p product, i int) product{
if i == 0 || p.nonZero == 0 {
return product {
zeros: 1,
nonZero: 0,
}
}
if i == 1 {
return p
}
p2 := parseProduct(i)
extra := p.nonZero * p2.nonZero
nonZero, zeros := zs(extra)
return product{
zeros: p.zeros + p2.zeros + zeros,
nonZero: nonZero,
}
}
type xy struct {
x int
y int
}
type product struct {
zeros int
nonZero int
}
var seenInts = make(map[int]product)
func parseProduct(i int) product {
if p, ok := seenInts[i]; ok {
return p
}
nonZero, zeros := zs(i)
return product {
zeros: zeros,
nonZero: nonZero,
}
}
func zs(i int) (int, int) {
switch {
case i == 0:
return 0, 1
case i % 10 != 0:
return i % 10, 0
case i == 1000000000:
return 1, 9
case i % 100000000 == 0:
return i / 100000000 % 10, 8
case i % 10000000 == 0:
return i / 10000000 % 10, 7
case i % 1000000 == 0:
return i / 1000000 % 10, 6
case i % 100000 == 0:
return i / 100000 % 10, 5
case i % 10000 == 0:
return i / 10000 % 10, 4
case i % 1000 == 0:
return i / 1000 % 10, 3
case i % 100 == 0:
return i / 100 % 10, 2
case i % 10 == 0:
return i / 10, 1
}
fmt.Println("error!")
return 0,0
}
package solution
// you can also use imports, for example:
import "fmt"
// import "os"
// you can write to stdout for debugging purposes, e.g.
// fmt.Println("this is a debug message")
func Solution(A [][]int) int {
size := len(A)
firstProduct := parseProduct(A[0][0])
seen := make([][]product, size, size)
for i := range seen {
seen[i] = make([]product, size, size)
}
seen[0][0] = firstProduct
for i := 1; i < size; i++ {
seen[i][0] = productCalc(seen[i-1][0], A[i][0])
seen[0][i] = productCalc(seen[0][i-1], A[0][i])
}
for y := 1; y < size; y++ {
for x := 1; x < size; x++ {
up := productCalc(seen[y][x-1], A[y][x])
left := productCalc(seen[y-1][x], A[y][x])
if up.zeros < left.zeros {
seen[y][x] = up
} else {
seen[y][x] = left
}
}
}
return seen[size-1][size-1].zeros
}
func productCalc(p product, i int) product{
if i == 0 || p.nonZero == 0 {
return product {
zeros: 1,
nonZero: 0,
}
}
if i == 1 {
return p
}
p2 := parseProduct(i)
return product{
zeros: p.zeros + p2.zeros + zeros,
nonZero: nonZero,
}
}
type xy struct {
x int
y int
}
type product struct {
zeros int
nonZero int
}
var seenInts = make(map[int]product)
func parseProduct(i int) product {
if p, ok := seenInts[i]; ok {
return p
}
nonZero, zeros := zs(i)
return product {
zeros: zeros,
nonZero: nonZero,
}
}
func zs(i int) (int, int) {
switch {
case i == 0:
return 0, 1
case i % 10 != 0:
return i % 10, 0
case i == 1000000000:
return 1, 9
case i % 100000000 == 0:
return i / 100000000 % 10, 8
case i % 10000000 == 0:
return i / 10000000 % 10, 7
case i % 1000000 == 0:
return i / 1000000 % 10, 6
case i % 100000 == 0:
return i / 100000 % 10, 5
case i % 10000 == 0:
return i / 10000 % 10, 4
case i % 1000 == 0:
return i / 1000 % 10, 3
case i % 100 == 0:
return i / 100 % 10, 2
case i % 10 == 0:
return i / 10, 1
}
fmt.Println("error!")
return 0,0
}
package solution
// you can also use imports, for example:
import "fmt"
// import "os"
// you can write to stdout for debugging purposes, e.g.
// fmt.Println("this is a debug message")
func Solution(A [][]int) int {
size := len(A)
firstProduct := parseProduct(A[0][0])
seen := make([][]product, size, size)
for i := range seen {
seen[i] = make([]product, size, size)
}
seen[0][0] = firstProduct
for i := 1; i < size; i++ {
seen[i][0] = productCalc(seen[i-1][0], A[i][0])
seen[0][i] = productCalc(seen[0][i-1], A[0][i])
}
for y := 1; y < size; y++ {
for x := 1; x < size; x++ {
up := productCalc(seen[y][x-1], A[y][x])
left := productCalc(seen[y-1][x], A[y][x])
if up.zeros < left.zeros {
seen[y][x] = up
} else {
seen[y][x] = left
}
}
}
return seen[size-1][size-1].zeros
}
func productCalc(p product, i int) product{
if i == 0 || p.nonZero == 0 {
return product {
zeros: 1,
nonZero: 0,
}
}
if i == 1 {
return p
}
p2 := parseProduct(i*p.nonZero)
return product{
zeros: p.zeros + p2.zeros + zeros,
nonZero: nonZero,
}
}
type xy struct {
x int
y int
}
type product struct {
zeros int
nonZero int
}
var seenInts = make(map[int]product)
func parseProduct(i int) product {
if p, ok := seenInts[i]; ok {
return p
}
nonZero, zeros := zs(i)
return product {
zeros: zeros,
nonZero: nonZero,
}
}
func zs(i int) (int, int) {
switch {
case i == 0:
return 0, 1
case i % 10 != 0:
return i % 10, 0
case i == 1000000000:
return 1, 9
case i % 100000000 == 0:
return i / 100000000 % 10, 8
case i % 10000000 == 0:
return i / 10000000 % 10, 7
case i % 1000000 == 0:
return i / 1000000 % 10, 6
case i % 100000 == 0:
return i / 100000 % 10, 5
case i % 10000 == 0:
return i / 10000 % 10, 4
case i % 1000 == 0:
return i / 1000 % 10, 3
case i % 100 == 0:
return i / 100 % 10, 2
case i % 10 == 0:
return i / 10, 1
}
fmt.Println("error!")
return 0,0
}
package solution
// you can also use imports, for example:
import "fmt"
// import "os"
// you can write to stdout for debugging purposes, e.g.
// fmt.Println("this is a debug message")
func Solution(A [][]int) int {
size := len(A)
firstProduct := parseProduct(A[0][0])
seen := make([][]product, size, size)
for i := range seen {
seen[i] = make([]product, size, size)
}
seen[0][0] = firstProduct
for i := 1; i < size; i++ {
seen[i][0] = productCalc(seen[i-1][0], A[i][0])
seen[0][i] = productCalc(seen[0][i-1], A[0][i])
}
for y := 1; y < size; y++ {
for x := 1; x < size; x++ {
up := productCalc(seen[y][x-1], A[y][x])
left := productCalc(seen[y-1][x], A[y][x])
if up.zeros < left.zeros {
seen[y][x] = up
} else {
seen[y][x] = left
}
}
}
return seen[size-1][size-1].zeros
}
func productCalc(p product, i int) product{
if i == 0 || p.nonZero == 0 {
return product {
zeros: 1,
nonZero: 0,
}
}
if i == 1 {
return p
}
p2 := parseProduct(i*p.nonZero)
return product{
zeros: p.zeros + p2.zeros,
nonZero: p2.nonZero,
}
}
type xy struct {
x int
y int
}
type product struct {
zeros int
nonZero int
}
var seenInts = make(map[int]product)
func parseProduct(i int) product {
if p, ok := seenInts[i]; ok {
return p
}
nonZero, zeros := zs(i)
return product {
zeros: zeros,
nonZero: nonZero,
}
}
func zs(i int) (int, int) {
switch {
case i == 0:
return 0, 1
case i % 10 != 0:
return i % 10, 0
case i == 1000000000:
return 1, 9
case i % 100000000 == 0:
return i / 100000000 % 10, 8
case i % 10000000 == 0:
return i / 10000000 % 10, 7
case i % 1000000 == 0:
return i / 1000000 % 10, 6
case i % 100000 == 0:
return i / 100000 % 10, 5
case i % 10000 == 0:
return i / 10000 % 10, 4
case i % 1000 == 0:
return i / 1000 % 10, 3
case i % 100 == 0:
return i / 100 % 10, 2
case i % 10 == 0:
return i / 10, 1
}
fmt.Println("error!")
return 0,0
}
package solution
// you can also use imports, for example:
import "fmt"
// import "os"
// you can write to stdout for debugging purposes, e.g.
// fmt.Println("this is a debug message")
func Solution(A [][]int) int {
size := len(A)
firstProduct := parseProduct(A[0][0])
seen := make([][]product, size, size)
for i := range seen {
seen[i] = make([]product, size, size)
}
seen[0][0] = firstProduct
for i := 1; i < size; i++ {
seen[i][0] = productCalc(seen[i-1][0], A[i][0])
seen[0][i] = productCalc(seen[0][i-1], A[0][i])
}
for y := 1; y < size; y++ {
for x := 1; x < size; x++ {
up := productCalc(seen[y][x-1], A[y][x])
left := productCalc(seen[y-1][x], A[y][x])
if up.zeros < left.zeros {
seen[y][x] = up
} else {
seen[y][x] = left
}
}
}
return seen[size-1][size-1].zeros
}
func productCalc(p product, i int) product{
if i == 0 || p.nonZero == 0 {
return product {
zeros: 1,
nonZero: 0,
}
}
if i == 1 {
return p
}
p2 := parseProduct(i*p.nonZero)
return product{
zeros: p.zeros + p2.zeros,
nonZero: p2.nonZero,
}
}
type xy struct {
x int
y int
}
type product struct {
zeros int
nonZero int
}
func parseProduct(i int) product {
nonZero, zeros := zs(i)
return product {
zeros: zeros,
nonZero: nonZero,
}
}
func zs(i int) (int, int) {
switch {
case i == 0:
return 0, 1
case i % 10 != 0:
return i % 10, 0
case i == 1000000000:
return 1, 9
case i % 100000000 == 0:
return i / 100000000 % 10, 8
case i % 10000000 == 0:
return i / 10000000 % 10, 7
case i % 1000000 == 0:
return i / 1000000 % 10, 6
case i % 100000 == 0:
return i / 100000 % 10, 5
case i % 10000 == 0:
return i / 10000 % 10, 4
case i % 1000 == 0:
return i / 1000 % 10, 3
case i % 100 == 0:
return i / 100 % 10, 2
case i % 10 == 0:
return i / 10, 1
}
fmt.Println("error!")
return 0,0
}
package solution
// you can also use imports, for example:
import "fmt"
// import "os"
// you can write to stdout for debugging purposes, e.g.
// fmt.Println("this is a debug message")
func Solution(A [][]int) int {
size := len(A)
firstProduct := parseProduct(A[0][0])
seen := make([][]product, size, size)
for i := range seen {
seen[i] = make([]product, size, size)
}
seen[0][0] = firstProduct
for i := 1; i < size; i++ {
seen[i][0] = productCalc(seen[i-1][0], A[i][0])
seen[0][i] = productCalc(seen[0][i-1], A[0][i])
}
for y := 1; y < size; y++ {
for x := 1; x < size; x++ {
up := productCalc(seen[y][x-1], A[y][x])
left := productCalc(seen[y-1][x], A[y][x])
if up.zeros < left.zeros {
seen[y][x] = up
} else {
seen[y][x] = left
}
}
}
return seen[size-1][size-1].zeros
}
func productCalc(p product, i int) product{
if i == 0 || p.nonZero == 0 {
return product {
zeros: 1,
nonZero: 0,
}
}
if i == 1 {
return p
}
p2 := parseProduct(i*p.nonZero)
return product{
zeros: p.zeros + p2.zeros,
nonZero: p2.nonZero,
}
}
type xy struct {
x int
y int
}
type product struct {
zeros int
nonZero int
}
func parseProduct(i int) product {
nonZero, zeros := zs(i)
return product {
zeros: zeros,
nonZero: nonZero,
}
}
func zs(i int) (int, int) {
switch {
case i == 0:
return 0, 1
case i % 10 != 0:
return i % 10, 0
case i == 1000000000:
return 1, 9
case i % 100000000 == 0:
return i / 100000000 % 10, 8
case i % 10000000 == 0:
return i / 10000000 % 10, 7
case i % 1000000 == 0:
return i / 1000000 % 10, 6
case i % 100000 == 0:
return i / 100000 % 10, 5
case i % 10000 == 0:
return i / 10000 % 10, 4
case i % 1000 == 0:
return i / 1000 % 10, 3
case i % 100 == 0:
return i / 100 % 10, 2
case i % 10 == 0:
return i / 10, 1
}
fmt.Println("error!")
return 0,0
}
package solution
// you can also use imports, for example:
import "fmt"
// import "os"
// you can write to stdout for debugging purposes, e.g.
// fmt.Println("this is a debug message")
func Solution(A [][]int) int {
size := len(A)
firstProduct := parseProduct(A[0][0])
seen := make([][]product, size, size)
for i := range seen {
seen[i] = make([]product, size, size)
}
seen[0][0] = firstProduct
for i := 1; i < size; i++ {
seen[i][0] = productCalc(seen[i-1][0], A[i][0])
seen[0][i] = productCalc(seen[0][i-1], A[0][i])
}
for y := 1; y < size; y++ {
for x := 1; x < size; x++ {
up := productCalc(seen[y][x-1], A[y][x])
left := productCalc(seen[y-1][x], A[y][x])
if up.zeros < left.zeros {
seen[y][x] = up
} else {
seen[y][x] = left
}
}
}
return seen[size-1][size-1].zeros
}
func productCalc(p product, i int) product{
if i == 0 || p.nonZero == 0 {
return product {
zeros: 1,
nonZero: 0,
}
}
if i == 1 {
return p
}
p2 := parseProduct(i*p.nonZero)
return product{
zeros: p.zeros + p2.zeros,
nonZero: p2.nonZero,
}
}
type xy struct {
x int
y int
}
type product struct {
zeros int
nonZero int
}
func parseProduct(i int) product {
nonZero, zeros := zs(i)
return product {
zeros: zeros,
nonZero: nonZero,
}
}
func zs(i int) (int, int) {
switch {
case i == 0:
return 0, 1
case i % 10 != 0:
return i % 10, 0
case i == 1000000000:
return 1, 9
case i % 100000000 == 0:
return i / 100000000 % 10, 8
case i % 10000000 == 0:
return i / 10000000 % 10, 7
case i % 1000000 == 0:
return i / 1000000 % 10, 6
case i % 100000 == 0:
return i / 100000 % 10, 5
case i % 10000 == 0:
return i / 10000 % 10, 4
case i % 1000 == 0:
return i / 1000 % 10, 3
case i % 100 == 0:
return i / 100 % 10, 2
case i % 10 == 0:
return i / 10, 1
}
fmt.Println("error!")
return 0,0
}
package solution
// you can also use imports, for example:
import "fmt"
// import "os"
// you can write to stdout for debugging purposes, e.g.
// fmt.Println("this is a debug message")
func Solution(A [][]int) int {
size := len(A)
firstProduct := parseProduct(A[0][0])
seen := make([][]product, size, size)
for i := range seen {
seen[i] = make([]product, size, size)
}
seen[0][0] = firstProduct
for i := 1; i < size; i++ {
seen[i][0] = productCalc(seen[i-1][0], A[i][0])
seen[0][i] = productCalc(seen[0][i-1], A[0][i])
}
for y := 1; y < size; y++ {
for x := 1; x < size; x++ {
up := productCalc(seen[y][x-1], A[y][x])
left := productCalc(seen[y-1][x], A[y][x])
if up.zeros < left.zeros {
seen[y][x] = up
} else {
seen[y][x] = left
}
}
}
return seen[size-1][size-1].zeros
}
func productCalc(p product, i int) product{
if i == 0 || p.nonZero == 0 {
return product {
zeros: 1,
nonZero: 0,
}
}
if i == 1 {
return p
}
p2 := parseProduct(i*p.nonZero)
return product{
zeros: p.zeros + p2.zeros,
nonZero: p2.nonZero,
}
}
type xy struct {
x int
y int
}
type product struct {
zeros int
nonZero int
}
func parseProduct(i int) product {
nonZero, zeros := zs(i)
return product {
zeros: zeros,
nonZero: nonZero,
}
}
func zs(i int) (int, int) {
switch {
case i == 0:
return 0, 1
case i % 10 != 0:
return i % 10, 0
case i == 1000000000:
return 1, 9
case i % 100000000 == 0:
return i / 100000000 % 10, 8
case i % 10000000 == 0:
return i / 10000000 % 10, 7
case i % 1000000 == 0:
return i / 1000000 % 10, 6
case i % 100000 == 0:
return i / 100000 % 10, 5
case i % 10000 == 0:
return i / 10000 % 10, 4
case i % 1000 == 0:
return i / 1000 % 10, 3
case i % 100 == 0:
return i / 100 % 10, 2
case i % 10 == 0:
return i / 10, 1
}
fmt.Println("error!")
return 0,0
}
package solution
// you can also use imports, for example:
import "fmt"
// import "os"
// you can write to stdout for debugging purposes, e.g.
// fmt.Println("this is a debug message")
func Solution(A [][]int) int {
size := len(A)
firstProduct := parseProduct(A[0][0])
seen := make([][]product, size, size)
for i := range seen {
seen[i] = make([]product, size, size)
}
seen[0][0] = firstProduct
for i := 1; i < size; i++ {
seen[i][0] = productCalc(seen[i-1][0], A[i][0])
seen[0][i] = productCalc(seen[0][i-1], A[0][i])
}
for y := 1; y < size; y++ {
for x := 1; x < size; x++ {
up := productCalc(seen[y][x-1], A[y][x])
left := productCalc(seen[y-1][x], A[y][x])
if up.zeros < left.zeros {
seen[y][x] = up
} else {
seen[y][x] = left
}
}
}
return seen[size-1][size-1].zeros
}
func productCalc(p product, i int) product{
if i == 0 || p.nonZero == 0 {
return product {
zeros: 1,
nonZero: 0,
}
}
if i == 1 {
return p
}
p2 := parseProduct(i*p.nonZero)
return product{
zeros: p.zeros + p2.zeros,
nonZero: p2.nonZero,
}
}
type xy struct {
x int
y int
}
type product struct {
zeros int
nonZero int
}
func parseProduct(i int) product {
nonZero, zeros := zs(i)
return product {
zeros: zeros,
nonZero: nonZero,
}
}
func zs(i int) (int, int) {
switch {
case i == 0:
return 0, 1
case i % 10 != 0:
return i % 10, 0
case i == 1000000000:
return 1, 9
case i % 100000000 == 0:
return i / 100000000 % 10, 8
case i % 10000000 == 0:
return i / 10000000 % 10, 7
case i % 1000000 == 0:
return i / 1000000 % 10, 6
case i % 100000 == 0:
return i / 100000 % 10, 5
case i % 10000 == 0:
return i / 10000 % 10, 4
case i % 1000 == 0:
return i / 1000 % 10, 3
case i % 100 == 0:
return i / 100 % 10, 2
case i % 10 == 0:
return i / 10, 1
}
fmt.Println("error!")
return 0,0
}
The solution obtained perfect score.
all elements in A are neither dividable by 2 or 5; length of A is close to 500
all elements in A are dividable by either power of 2 or 5; length of A is close to 500