File tree Expand file tree Collapse file tree 2 files changed +120
-0
lines changed Expand file tree Collapse file tree 2 files changed +120
-0
lines changed Original file line number Diff line number Diff line change
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
+ }
Original file line number Diff line number Diff line change 1
1
pub mod bignumbers;
2
+ pub mod math;
You can’t perform that action at this time.
0 commit comments