From 94cea4e72c192dd71c05903d3a48ba5338bacb68 Mon Sep 17 00:00:00 2001 From: ache Date: Tue, 11 Sep 2018 07:45:27 +0200 Subject: Ajout du probleme 61 --- p61/p61.go | 108 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 108 insertions(+) create mode 100644 p61/p61.go diff --git a/p61/p61.go b/p61/p61.go new file mode 100644 index 0000000..ed7d47f --- /dev/null +++ b/p61/p61.go @@ -0,0 +1,108 @@ +package main + +import ( + "fmt" +) + + +type num struct { + v,i int +} + +var it = 0 + +func fillByFormule( slc *[]int, form func (int) int) { + it++ + for n, i := 0, 0 ; n < 10000 ; i++ { + if n > 999 && n < 10000 { + if n % 100 > 9 { + *slc = append(*slc, num{v=n, i=it}) + } + } + n = form(i) + } +} +func fillByNumber( dict map[int][]int, num []int) { + for _,n := range num { + dict[n/100] = append(dict[n/100], n%100) + } +} + + +func main () { + trin := []int{} + sqrt := []int{} + pent := []int{} + hexa := []int{} + hept := []int{} + octa := []int{} + + numMap := make(map[int][]num) + /* + hexaMap := make(map[int][]int) + heptMap := make(map[int][]int) + octaMap := make(map[int][]int) + */ + + + fillByFormule(&trin, func(x int) int { return (x*(x+1))>>1 }) + fillByFormule(&sqrt, func(x int) int { return x*x }) + fillByFormule(&pent, func(x int) int { return (x*(3*x-1))>>1 }) + fillByFormule(&hexa, func(x int) int { return x*(2*x-1) }) + fillByFormule(&hept, func(x int) int { return (x*(5*x-3))>>1 }) + fillByFormule(&octa, func(x int) int { return x*(3*x-2) }) + + fillByNumber(numMap, trin, 1) + fillByNumber(numMap, sqrt, 2) + /* + fillByNumber(sqrtMap, sqrt) + fillByNumber(pentMap, pent) + */ + + fmt.Println(trin) + fmt.Println(numMap) + + pile := []int{} + + empiler := func(i []int) { + pile = append(pile, i...) + } + + + empiler(pent) + + for len(pile) != 0{ + n_1 := n / 100 + n_2 := n % 100 + + cycle := []int{n8} + numberType := []int{0} + + for len(cycle) != 3 { + + + } + + if _,ok := numMap[n_2] ; ok { + for + + for _, n1_2 := range numMap[n_2] { + if _,ok := trinMap[n1_2] ; ok { + for _, n2 := range trinMap[n1_2] { + n2_2 := n2 % 100 + if n2_2 == n8_1 { + fmt.Println(n1_2, n2_2, n8_2) + } + } + } + } + } + } + + fmt.Println(len(trin)) + fmt.Println(len(sqrt)) + fmt.Println(len(pent)) + fmt.Println(len(hexa)) + fmt.Println(len(hept)) + fmt.Println(len(octa)) +} -- cgit v1.2.3