···7474 largest_num = current_num;
7575 }
76767777- current_num = current_num.mul(3) + 1; // For some reason using .mul() is faster then * but .add() is slightly slower then +. it was only a few ms slower to do all 50K but on an extremely large scale it matters
7777+ // For some reason using .mul() is faster then * but .add() is slightly slower then +.
7878+ // it was only a few ms slower to do all 50K but on an extremely large scale it matters.
7979+ current_num = current_num.mul(3) + 1;
8080+7881 } else {
7982 if current_num < smallest_num{
8083 smallest_num = current_num;
···8487 largest_num = current_num;
8588 }
86898787- current_num = current_num >> 1; // Divides by 2 a bit faster
9090+ // Writing this one line taught me about bit shifting.
9191+ // doing >> on an unsigned integer (u8-u16-u32-u64-u128) does something called
9292+ // Logical Right Shifting. This removes the least significant bit or the right most
9393+ // bit and places a 0 on the left. so the binary form of 8 is 1000, doing 8>>1 shifts
9494+ // the bits to the right once, this takes the last 0 and removes it making it 100, we
9595+ // then add a new 0 to the left making it 0100 which is binary for 4.
9696+ // This is more efficient then just trying to do division because there is no actual
9797+ // math involved and just a super quick bit operation.
9898+ //
9999+ // Another example:
100100+ // 69420 >> 1 == 34710
101101+ // 0001 0000 1111 0010 1100 >> 1
102102+ // 0001 0000 1111 0010 110
103103+ // 0000 1000 0111 1001 0110 == 34710
104104+ //
105105+ current_num = current_num >> 1;
88106 }
8910790108 if current_num == smallest_num {
···107125 let mut smallest_num_count = 1;
108126 while smallest_num_count != 2{
109127110110- // if odd
111128 if current_num % 2 != 0 {
112129 if current_num < smallest_num{
113130 smallest_num = current_num;
···119136120137 event!(Level::INFO, "{} is odd. Smallest number: {}. Largest number: {}", current_num, smallest_num, largest_num);
121138122122- current_num = current_num.mul(3) + 1; // For some reason using .mul() is faster then * but .add() is slightly slower then +. it was only a few ms slower to do all 50K but on an extremely large scale it matters
139139+ current_num = current_num.mul(3) + 1;
123140 } else {
124141 if current_num < smallest_num{
125142 smallest_num = current_num;
···131148132149 event!(Level::INFO, "{} is even. Smallest number: {}. Largest number: {}", current_num, smallest_num, largest_num);
133150134134- current_num = current_num >> 1; // Divides by 2 a bit faster
151151+ current_num = current_num >> 1;
135152 }
136153137154 if current_num == smallest_num {