Skip to content

Commit 8085770

Browse files
committed
good practice 🤣
1 parent a7adc82 commit 8085770

File tree

2 files changed

+120
-0
lines changed

2 files changed

+120
-0
lines changed

‎src/majcn/math.rs

Lines changed: 119 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,119 @@
1+
pub trait DigitCounter {
2+
fn count_digits(self) -> usize;
3+
}
4+
5+
impl DigitCounter for u32 {
6+
fn count_digits(self) -> usize {
7+
if self < 10 {
8+
return 1;
9+
}
10+
11+
if self < 100 {
12+
return 2;
13+
}
14+
15+
if self < 1000 {
16+
return 3;
17+
}
18+
19+
if self < 10000 {
20+
return 4;
21+
}
22+
23+
if self < 100000 {
24+
return 5;
25+
}
26+
27+
if self < 1000000 {
28+
return 6;
29+
}
30+
31+
if self < 10000000 {
32+
return 7;
33+
}
34+
35+
if self < 100000000 {
36+
return 8;
37+
}
38+
39+
9
40+
}
41+
}
42+
43+
impl DigitCounter for u64 {
44+
fn count_digits(self) -> usize {
45+
if self < 10 {
46+
return 1;
47+
}
48+
49+
if self < 100 {
50+
return 2;
51+
}
52+
53+
if self < 1000 {
54+
return 3;
55+
}
56+
57+
if self < 10000 {
58+
return 4;
59+
}
60+
61+
if self < 100000 {
62+
return 5;
63+
}
64+
65+
if self < 1000000 {
66+
return 6;
67+
}
68+
69+
if self < 10000000 {
70+
return 7;
71+
}
72+
73+
if self < 100000000 {
74+
return 8;
75+
}
76+
77+
if self < 1000000000 {
78+
return 9;
79+
}
80+
81+
if self < 10000000000 {
82+
return 10;
83+
}
84+
85+
if self < 100000000000 {
86+
return 11;
87+
}
88+
89+
if self < 1000000000000 {
90+
return 12;
91+
}
92+
93+
if self < 10000000000000 {
94+
return 13;
95+
}
96+
97+
if self < 100000000000000 {
98+
return 14;
99+
}
100+
101+
if self < 1000000000000000 {
102+
return 15;
103+
}
104+
105+
if self < 10000000000000000 {
106+
return 16;
107+
}
108+
109+
if self < 100000000000000000 {
110+
return 17;
111+
}
112+
113+
if self < 1000000000000000000 {
114+
return 18;
115+
}
116+
117+
19
118+
}
119+
}

‎src/majcn/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
11
pub mod bignumbers;
2+
pub mod math;

0 commit comments

Comments
 (0)