Simple tool to brute force 3x+1 for a new loop.
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

docs: explained >> in comment

+28 -5
+6
.idea/vcs.xml
··· 1 1 <?xml version="1.0" encoding="UTF-8"?> 2 2 <project version="4"> 3 + <component name="CommitMessageInspectionProfile"> 4 + <profile version="1.0"> 5 + <inspection_tool class="CommitFormat" enabled="true" level="WARNING" enabled_by_default="true" /> 6 + <inspection_tool class="CommitNamingConvention" enabled="true" level="WARNING" enabled_by_default="true" /> 7 + </profile> 8 + </component> 3 9 <component name="VcsDirectoryMappings"> 4 10 <mapping directory="$PROJECT_DIR$" vcs="Git" /> 5 11 </component>
+22 -5
src/main.rs
··· 74 74 largest_num = current_num; 75 75 } 76 76 77 - 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 77 + // For some reason using .mul() is faster then * but .add() is slightly slower then +. 78 + // it was only a few ms slower to do all 50K but on an extremely large scale it matters. 79 + current_num = current_num.mul(3) + 1; 80 + 78 81 } else { 79 82 if current_num < smallest_num{ 80 83 smallest_num = current_num; ··· 84 87 largest_num = current_num; 85 88 } 86 89 87 - current_num = current_num >> 1; // Divides by 2 a bit faster 90 + // Writing this one line taught me about bit shifting. 91 + // doing >> on an unsigned integer (u8-u16-u32-u64-u128) does something called 92 + // Logical Right Shifting. This removes the least significant bit or the right most 93 + // bit and places a 0 on the left. so the binary form of 8 is 1000, doing 8>>1 shifts 94 + // the bits to the right once, this takes the last 0 and removes it making it 100, we 95 + // then add a new 0 to the left making it 0100 which is binary for 4. 96 + // This is more efficient then just trying to do division because there is no actual 97 + // math involved and just a super quick bit operation. 98 + // 99 + // Another example: 100 + // 69420 >> 1 == 34710 101 + // 0001 0000 1111 0010 1100 >> 1 102 + // 0001 0000 1111 0010 110 103 + // 0000 1000 0111 1001 0110 == 34710 104 + // 105 + current_num = current_num >> 1; 88 106 } 89 107 90 108 if current_num == smallest_num { ··· 107 125 let mut smallest_num_count = 1; 108 126 while smallest_num_count != 2{ 109 127 110 - // if odd 111 128 if current_num % 2 != 0 { 112 129 if current_num < smallest_num{ 113 130 smallest_num = current_num; ··· 119 136 120 137 event!(Level::INFO, "{} is odd. Smallest number: {}. Largest number: {}", current_num, smallest_num, largest_num); 121 138 122 - 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 139 + current_num = current_num.mul(3) + 1; 123 140 } else { 124 141 if current_num < smallest_num{ 125 142 smallest_num = current_num; ··· 131 148 132 149 event!(Level::INFO, "{} is even. Smallest number: {}. Largest number: {}", current_num, smallest_num, largest_num); 133 150 134 - current_num = current_num >> 1; // Divides by 2 a bit faster 151 + current_num = current_num >> 1; 135 152 } 136 153 137 154 if current_num == smallest_num {