This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| ''' | |
| Given N number of coins ranging from 1 up to N, find the minimum number of | |
| coins that sum up to K such that the coins are only used once. | |
| ''' | |
| def solution(N, K): | |
| print() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| failedImageDownloads = prometheus.NewCounterVec( | |
| prometheus.CounterOpts{ | |
| Name: "image_download_failures", | |
| Help: "Number of failed image downloads", | |
| }, | |
| []string{"name", "namespace", "kind", "image", "err_type"}, | |
| ) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // excerpt from https://yourbasic.org/golang/recover-from-panic/ | |
| func main() { | |
| n := foo() | |
| fmt.Println("main received", n) | |
| } | |
| func foo() (m int) { | |
| defer func() { | |
| if err := recover(); err != nil { | |
| fmt.Println(err) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // errors in go are a type | |
| func returnErr() (string, error) { | |
| return "", fmt.Errorf("An error occurred") | |
| } | |
| // errors do not propagate | |
| // we do not try-catch | |
| // we handle the error like "Real Men" | |
| res, err := returnErr() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // errors in go are a type | |
| func returnErr() (string, error) { | |
| return "", fmt.Errorf("An error occurred") | |
| } | |
| // errors do not propagate | |
| // we do not try-catch |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const Queue = require('./structures'); | |
| const { debugLogger } = require('./logger'); | |
| const logger = debugLogger(__filename); | |
| const resolveDependencyIfUnknown = (node) => { | |
| if (node && node.dependencies) { | |
| return node.dependencies; | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| func getFnIndex(numberOfDigits int) int{ | |
| // From my analysis, the fibonacci number follows a plot along 5x of the number | |
| // approximately in relation to its number of digits | |
| maxDelta := 5 * (numberOfDigits) | |
| for maxDelta > 0 { | |
| if numberOfDigits > getDigitLengthBinet(maxDelta) { | |
| fmt.Println("Approximate value", 5 * numberOfDigits) | |
| fmt.Println("Actual value", maxDelta + 1) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| func plotFunc(num float64){ | |
| p, err := plot.New() | |
| if err != nil { | |
| panic(err) | |
| } | |
| p.Title.Text = "Functions" | |
| p.X.Label.Text = "X(5*k)" | |
| p.Y.Label.Text = "Y(k)" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| func plotDifference(num float64){ | |
| p, err := plot.New() | |
| if err != nil { | |
| panic(err) | |
| } | |
| p.Title.Text = "Differences" | |
| p.X.Label.Text = "X" | |
| p.Y.Label.Text = "Y" | |
| exp := plotter.NewFunction(func(x float64) float64 { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| func getDigitLengthBinet(n int) int { | |
| // We use a reverse implementation of the Binet formula | |
| // Binet Formula gives the fibonacci digit but we can apply | |
| // A log to that formula to obtain the digit count | |
| var phi float64= (1 + math.Sqrt(5)) / 2 | |
| nDigits := float64(n) * math.Log10(phi) - (math.Log10(5) / 2) | |
| return int(math.Ceil(nDigits)) |
NewerOlder