Skip to content

Conversation

doniacld
Copy link
Owner

No description provided.



// Compute the target sum by parsing twice the integer array
// FindIntruder the target sum by parsing twice the integer array
Copy link
Collaborator

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
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
// should not happened
// should not happen

return 0, 0
}

// findPair returns the odd value if there is no pair summing it
Copy link
Collaborator

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))
Copy link
Collaborator

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{}{}
Copy link
Collaborator

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
Copy link
Collaborator

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
Copy link
Collaborator

@floppyzedolfin floppyzedolfin Jul 19, 2021

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
Copy link
Collaborator

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants