You can memoize i.e. cache results of kbonacci(). See https://play.golang.org/p/Q2RjWZ2VTh3 for a working but not production ready implementation (for example, cache is specific to k etc.).
When running locally for (5,35): Running for n=35 res: 2809074173, time: 12.189908825s res: 2809074173, time: 42.719µs, cache hits: 110 The larger n, the faster memoized version compared to non-memoized. (You won't get timings on playground because time doesn't advance on playground). -- kjk https://www.programming-books.io/essential/go/ On Monday, May 14, 2018 at 5:22:00 PM UTC-7, Alex Dvoretskiy wrote: > > Hello Golang Nuts > > I'm trying to solve a problem. Algorithm is correct, but too slow. Perhaps > you can give me some ideas on how to improve running time? > > https://play.golang.org/p/XsXwT8EHtwC > > > Thanks > Alex > -- You received this message because you are subscribed to the Google Groups "golang-nuts" group. To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.