06:11 <+bridge> [ddnet] god damn it. today was very possible to get in the top100 šŸ˜¦ 09:14 <+ChillerDragon> flex 10:21 <+bridge> [ddnet] i dont get the second part 10:21 <+bridge> [ddnet] the meaning 10:21 <+bridge> [ddnet] :tee_thinking: 10:22 <+bridge> [ddnet] ahhh 10:25 <+bridge> [ddnet] done 10:26 <+bridge> [ddnet] 10:26 <+bridge> [ddnet] i think i got a pretty solution 10:31 <+bridge> [ddnet] https://cdn.discordapp.com/attachments/293493549758939136/784713507312369674/AmKPEqRG-RHyl2q577eDtoJxVmD8PCBwjntRPbJ8P6s.png 10:31 <+bridge> [ddnet] :monkalaugh: 11:36 <+bridge> [ddnet] I did just ||sum from lowest to highest - sum all given ids|| 11:36 <+bridge> [ddnet] read full msgs bro 11:36 <+bridge> [ddnet] i already did it 11:36 <+bridge> [ddnet] Yeah but you iterate and sort, pah :d 13:28 <+bridge> [ddnet] @Ryozuki I chose nim and abused binary search šŸ˜„ https://github.com/def-/adventofcode-2020/blob/master/day5.nim 13:29 <+bridge> [ddnet] :monkalaugh: 14:42 <+bridge> [ddnet] Is `set` a hash set in nim? 14:44 <+bridge> [ddnet] I just replaced F and B with 0 and 1 respectively to get binary and than used a standard lib function to convert to a number 15:36 <+bridge> [ddnet] :cirBlech: 15:38 <+bridge> [ddnet] @timakro yes, but I didn't use the regular hash sets (https://nim-lang.org/docs/sets.html) but instead the more efficient bit sets: https://nim-lang.org/docs/system.html#system-module-sets 15:39 <+bridge> [ddnet] thus also limited to int16 15:54 <+bridge> [ddnet] on codewars there was "count number of vowels a-e-i-o-u in string" and I was able to remove all branches :happy: 15:54 <+bridge> [ddnet] 15:54 <+bridge> [ddnet] ```cpp 15:54 <+bridge> [ddnet] int getCount(const std::string& inputStr){ 15:54 <+bridge> [ddnet] int num_vowels = 0; 15:54 <+bridge> [ddnet] for (auto i : inputStr){ 15:54 <+bridge> [ddnet] num_vowels += (0x208222 >> (i & 0x9F)) & 0x1; 15:54 <+bridge> [ddnet] } 15:54 <+bridge> [ddnet] return num_vowels; 15:54 <+bridge> [ddnet] } 15:54 <+bridge> [ddnet] ``` 15:55 <+bridge> [ddnet] nice 15:55 <+bridge> [ddnet] thanks :brownbear: 16:57 <+bridge> [ddnet] @alloca惄 looks like undefined behavior. did you mean `(0x208222 >> (i & 0x1f)) & 0x1`? 16:57 <+bridge> [ddnet] (which probably also represents what your code will compile to) 17:00 <+bridge> [ddnet] indeed, they compile to the same assembly: https://godbolt.org/z/865Kez 17:02 <+bridge> [ddnet] these are the characters you count: 17:02 <+bridge> [ddnet] ``` 17:02 <+bridge> [ddnet] >>> [chr(i) for i in range(128) if (0x208222 >> (i & 0x1F)) & 0x1] 17:02 <+bridge> [ddnet] ['\x01', '\x05', '\t', '\x0f', '\x15', '!', '%', ')', '/', '5', 'A', 'E', 'I', 'O', 'U', 'a', 'e', 'i', 'o', 'u'] 17:02 <+bridge> [ddnet] ``` 17:02 <+bridge> [ddnet] these are the characters you count: 17:02 <+bridge> [ddnet] ``` 17:02 <+bridge> [ddnet] >>> "".join([chr(i) for i in range(128) if (0x208222 >> (i & 0x1F)) & 0x1]) 17:02 <+bridge> [ddnet] '\x01\x05\t\x0f\x15!%)/5AEIOUaeiou' 17:02 <+bridge> [ddnet] ``` 17:03 <+bridge> [ddnet] the inputStr only contains lower case numbers and space, so I only considered that range 17:03 <+bridge> [ddnet] lowercase letters? ah okay 17:03 <+bridge> [ddnet] if it was whole range I would need to think about something else šŸ˜„ 17:03 <+bridge> [ddnet] nice optimization then šŸ˜‰ 17:06 <+bridge> [ddnet] thanks 17:06 <+bridge> [ddnet] I will think about the "all characters challenge" šŸ˜‰ 17:11 <+bridge> [ddnet] How did you find the 2 constants (0x208222, 0x9F)? 17:46 <+bridge> [ddnet] curious aswell 17:46 <+bridge> [ddnet] some math stuff? 17:46 <+bridge> [ddnet] xD 17:47 <+bridge> [ddnet] binary I think 17:47 <+bridge> [ddnet] ok let's explain :D 17:47 <+bridge> [ddnet] 17:47 <+bridge> [ddnet] we start with character `i` 17:47 <+bridge> [ddnet] &ing 0x9F is just subtracting 96. it's useful because 'a' == 97, so it's just one off 17:47 <+bridge> [ddnet] 17:47 <+bridge> [ddnet] 0x208222 is 1000001000001000100010 in binary 17:47 <+bridge> [ddnet] which has 5 binary digits at positions : 1, 5, 9, 14 and 21 17:47 <+bridge> [ddnet] this corresponds to the position of vowels after 96 PLUS 1 because we only subtracted 96 : 17:47 <+bridge> [ddnet] 17:47 <+bridge> [ddnet] ``` 17:47 <+bridge> [ddnet] 'a' = 97 + 0 17:47 <+bridge> [ddnet] 'e' = 97 + 4 17:47 <+bridge> [ddnet] 'i' = 97 + 8 17:47 <+bridge> [ddnet] 'o' = 97 + 14 17:47 <+bridge> [ddnet] 'u' = 97 + 20 17:47 <+bridge> [ddnet] ``` 17:47 <+bridge> [ddnet] 17:47 <+bridge> [ddnet] and after having rightshifting, if the last bit is `1` it must be a vowel 17:47 <+bridge> [ddnet] ohh 17:47 <+bridge> [ddnet] nice 17:50 <+bridge> [ddnet] ok let's explain :D 17:50 <+bridge> [ddnet] 17:50 <+bridge> [ddnet] we start with character `i` 17:50 <+bridge> [ddnet] &ing 0x9F is just subtracting 96 17:50 <+bridge> [ddnet] because 0x9f = 1001'1111, and &ing this removes the 64 and 32 bit (which adds to 96) 17:50 <+bridge> [ddnet] it's useful because 'a' == 97, so it's just one off 17:50 <+bridge> [ddnet] 17:50 <+bridge> [ddnet] 0x208222 is 1000001000001000100010 in binary 17:50 <+bridge> [ddnet] which has 5 binary digits at positions : 1, 5, 9, 14 and 21 17:50 <+bridge> [ddnet] this corresponds to the position of vowels after 96 PLUS 1 because we only subtracted 96 : 17:50 <+bridge> [ddnet] 17:50 <+bridge> [ddnet] ``` 17:50 <+bridge> [ddnet] 'a' = 97 + 0 17:50 <+bridge> [ddnet] 'e' = 97 + 4 17:50 <+bridge> [ddnet] 'i' = 97 + 8 17:50 <+bridge> [ddnet] 'o' = 97 + 14 17:50 <+bridge> [ddnet] 'u' = 97 + 20 17:50 <+bridge> [ddnet] ``` 17:50 <+bridge> [ddnet] 17:50 <+bridge> [ddnet] and after having rightshifting, if the last bit is `1` it must be a vowel 18:04 <+bridge> [ddnet] ok let's explain :D 18:04 <+bridge> [ddnet] 18:05 <+bridge> [ddnet] we start with character `i` 18:05 <+bridge> [ddnet] &ing 0x9F is just subtracting 96 18:05 <+bridge> [ddnet] because 0x9f = 1001'1111, and &ing this removes the 64 and 32 bit (which adds to 96) 18:05 <+bridge> [ddnet] it's useful because 'a' == 97, so it's just one off 18:05 <+bridge> [ddnet] 18:05 <+bridge> [ddnet] 0x208222 is 1000001000001000100010 in binary 18:05 <+bridge> [ddnet] which has 5 binary digits at positions : 1, 5, 9, 14 and 21 18:05 <+bridge> [ddnet] this corresponds to the position of vowels after 96 : 18:05 <+bridge> [ddnet] 18:05 <+bridge> [ddnet] ``` 18:05 <+bridge> [ddnet] 'a' = 97 + 0 == 96 + 1 18:05 <+bridge> [ddnet] 'e' = 97 + 4 == 96 + 5 18:05 <+bridge> [ddnet] 'i' = 97 + 8 == 96 + 9 18:05 <+bridge> [ddnet] 'o' = 97 + 14 == 96 + 14 18:05 <+bridge> [ddnet] 'u' = 97 + 20 == 96 + 21 18:05 <+bridge> [ddnet] ``` 18:05 <+bridge> [ddnet] 18:05 <+bridge> [ddnet] and after rightshifting, if the last bit is `1` it must be a vowel 18:06 <+bridge> [ddnet] ok let's explain :D 18:06 <+bridge> [ddnet] 18:06 <+bridge> [ddnet] we start with character `i` 18:06 <+bridge> [ddnet] &ing 0x9F is just subtracting 96 18:06 <+bridge> [ddnet] because 0x9f = 1001'1111, and &ing this removes the 64 and 32 bit (which adds to 96) 18:06 <+bridge> [ddnet] it's useful because 'a' == 97, so it's just one off 18:06 <+bridge> [ddnet] 18:06 <+bridge> [ddnet] 0x208222 is 1000001000001000100010 in binary 18:06 <+bridge> [ddnet] which has 5 binary digits at positions : `1`, `5`, `9`, `14` and `21` 18:06 <+bridge> [ddnet] this corresponds to the position of vowels after 96 : 18:06 <+bridge> [ddnet] 18:06 <+bridge> [ddnet] ``` 18:06 <+bridge> [ddnet] 'a' = 97 + 0 == 96 + 1 18:06 <+bridge> [ddnet] 'e' = 97 + 4 == 96 + 5 18:06 <+bridge> [ddnet] 'i' = 97 + 8 == 96 + 9 18:06 <+bridge> [ddnet] 'o' = 97 + 14 == 96 + 14 18:06 <+bridge> [ddnet] 'u' = 97 + 20 == 96 + 21 18:06 <+bridge> [ddnet] ``` 18:06 <+bridge> [ddnet] 18:06 <+bridge> [ddnet] and after rightshifting, if the last bit is `1` it must be a vowel 18:16 <+bridge> [ddnet] ok let's explain :D 18:16 <+bridge> [ddnet] 18:16 <+bridge> [ddnet] we start with character `i` 18:16 <+bridge> [ddnet] &ing 0x9F is just subtracting 96 18:16 <+bridge> [ddnet] because 0x9f = 1001'1111, and &ing this removes the 64 and 32 bit (which adds to 96) 18:16 <+bridge> [ddnet] it's useful because 'a' == 97, so it's just one off 18:16 <+bridge> [ddnet] 18:16 <+bridge> [ddnet] 0x208222 is 1000001000001000100010 in binary 18:16 <+bridge> [ddnet] which has 5 binary digits at positions : `1`, `5`, `9`, `14` and `21` 18:16 <+bridge> [ddnet] this corresponds to the position of vowels after 96 : 18:16 <+bridge> [ddnet] 18:16 <+bridge> [ddnet] ``` 18:16 <+bridge> [ddnet] 'a' = 97 + 0 == 96 + 1 18:16 <+bridge> [ddnet] 'e' = 97 + 4 == 96 + 5 18:16 <+bridge> [ddnet] 'i' = 97 + 8 == 96 + 9 18:16 <+bridge> [ddnet] 'o' = 97 + 14 == 96 + 14 18:16 <+bridge> [ddnet] 'u' = 97 + 20 == 96 + 21 18:16 <+bridge> [ddnet] ``` 18:17 <+bridge> [ddnet] 18:17 <+bridge> [ddnet] so if after rightshifting 0x208222 by (`i` - 96) the last bit is `1` ,it must be a vowel 18:20 <+bridge> [ddnet] @heinrich5991 and 0x9F and 0x1F compile into the same binaries because if a character was greater than 128 (96 + 32) than 0x208222 >> 32 results in 0, which has no `1` at the last bit . but this is undefined behavior (ISO 9899:2011 6.5.7 Bitwise shift operators) so you are correct that I should use 0x1F instead of 0x9F šŸ˜„ 18:22 <+bridge> [ddnet] @heinrich5991 and 0x9F and 0x1F compile into the same binaries because if a character was greater than 128 (96 + 32) than 0x208222 >> 32 results in 0, which has no `1` at the last bit . it doesn't matter for this string range, but this *could* lead to undefined behavior (ISO 9899:2011 6.5.7 Bitwise shift operators) which is avoidable, so you are correct that I should use 0x1F instead of 0x9F šŸ˜„ 18:24 <+bridge> [ddnet] just had this happen to two ppl on korean ddnet server. dk why 18:24 <+bridge> [ddnet] https://cdn.discordapp.com/attachments/293493549758939136/784832464992075826/corrupted_data.png 19:58 <+bridge> [ddnet] @nils send me their map and savecode (or name) in DM