-
Notifications
You must be signed in to change notification settings - Fork 0
Day 9 - Part 1 & 2 #5
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
@@ -40,7 +40,7 @@ func ComputeTargetSumWithTriplet(expenses []int, target int) int { | |||
} | |||
|
|||
|
|||
// Compute the target sum by parsing twice the integer array | |||
// FindIntruder the target sum by parsing twice the integer array |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's not the name of the func
c.updatePreamble(idxStartPreamble, idxEndPreamble) | ||
idxStartPreamble++ | ||
} | ||
// should not happened |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
// should not happened | |
// should not happen |
return 0, 0 | ||
} | ||
|
||
// findPair returns the odd value if there is no pair summing it |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it returns a bool
for p := range c.Preamble { | ||
toFind := elt - p | ||
|
||
f := math.Abs(float64(toFind)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
or you could write your own abs
func
// remove the first element | ||
delete(c.Preamble, c.Numbers[idxToRemove]) | ||
// add the next element | ||
c.Preamble[c.Numbers[idxToRemove+idxPreamble]] = struct{}{} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i supppose this will always work, but is there any safety net somewhere? c.Numbers is an array, after all.
if err != nil { | ||
return elt, err | ||
} | ||
return elt, nil |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
so, basically, always return elt, err ?
in the end, always return srconv.Atoi(line)?
for sum > target { | ||
sum -= tmpArray[0] | ||
s := tmpArray[1:] | ||
tmpArray = s |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
or tmpArray = tmpArray[1:]
|
||
// sumMinMax returns the sum of the min and max values from a given array | ||
func sumMinMax(sum []int) int { | ||
min, max := sum[0], 0 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it's better to also initialise max to sum[0]. just in case you encounter negative numbers
No description provided.