Or almost happy π Now I realized that there's no need to read all of the values at all. The file can be read line by line and the read values can be saved to the map until the match is found...
Yes, I mean that I use the map structure instead of set (I think go does not have sets π€ ). Let me paste here my pseudolike code:
func findValue: int
cache := new key-value-storage
for line = read-next-line from file:
nbr := convert line to nbr
want := 2020 - nbr
if cache[want]:
return want * nbr
cache[nbr] = nbr
return 0
So I mean "saving to a map" this line cache[nbr] = nbr. Of course the value could be anything, only the key counts βΊοΈ
Or almost happy π Now I realized that there's no need to read all of the values at all. The file can be read line by line and the read values can be saved to the map until the match is found...
Interesting! I'm not familiar with Golang, but googled and read that you can check the membership with
If you know which number you're looking for (calculating 2020 - x = y), and I read the example above correctly, couldn't you just
Do you need to save the read values to a map, I'm not so sure? π€
Yes, I mean that I use the map structure instead of set (I think go does not have sets π€ ). Let me paste here my pseudolike code:
So I mean "saving to a map" this line
cache[nbr] = nbr
. Of course the value could be anything, only the key counts βΊοΈOhh yeah now I see π