Ejemplo n.º 1
0
func (s *Solver) solveQuestion(question Question) (answer Answer) {
	inks := []string{}

	for _, layer := range question.Layers {
		var bestInk Ink
		smallerDist := math.MaxFloat64

		for _, ink := range s.inks {
			dist := colors.CalcDistanceHex(layer.Color, ink.Color)

			if ink.Cost < bestInk.Cost && dist < 20 {
				bestInk = ink
			} else if dist < smallerDist {
				smallerDist = dist
				bestInk = ink
			}
		}

		inks = append(inks, bestInk.ID)
	}

	return Answer{
		Inks: inks,
	}
}
Ejemplo n.º 2
0
package colors_test

import (
	"github.com/tscolari/tshirts/colors"

	. "github.com/onsi/ginkgo"
	. "github.com/onsi/gomega"
)

var _ = Describe("Distance", func() {

	Describe("CalcDistanceHex", func() {
		It("calculates the correct distance between black and white", func() {
			distance := colors.CalcDistanceHex("#000000", "#ffffff")
			Expect(distance).To(Equal(100.0))
		})

		It("calculates the correct distance between same color", func() {
			distance := colors.CalcDistanceHex("#000000", "#ffffff")
			Expect(distance).To(Equal(0.0))
		})
	})
})