1use shared::kata::*;
6
7pub fn hex_to_dec(hex_string: &str) -> u32 {
13 let kata = Kata {
14 level: Level::L8kyu,
15 tags: vec![Tag::Fundamentals],
16 description: String::from("Hex to Decimal"),
17 };
18
19 println!(
20 "Level: {:?}, Tags: {:?}, Description: {}",
21 kata.level, kata.tags, kata.description
22 );
23
24 u32::from_str_radix(hex_string, 16).expect("Not a Hex string")
25}
26
27pub fn simple_multiplication(number: u8) -> u8 {
36 let kata = Kata {
37 level: Level::L8kyu,
38 tags: vec![Tag::Fundamentals],
39 description: String::from("Simple multiplication"),
40 };
41
42 println!(
43 "Level: {:?}, Tags: {:?}, Description: {}",
44 kata.level, kata.tags, kata.description
45 );
46
47 if number % 2 == 0 {
48 number * 8
49 } else {
50 number * 9
51 }
52}
53
54pub fn no_space(x: String) -> String {
60 let kata = Kata {
61 level: Level::L8kyu,
62 tags: vec![Tag::Fundamentals, Tag::Strings],
63 description: String::from("Remove String Spaces"),
64 };
65
66 println!(
67 "Level: {:?}, Tags: {:?}, Description: {}",
68 kata.level, kata.tags, kata.description
69 );
70
71 x.replace(" ", "")
75}
76
77pub fn to_alternating_case(s: &str) -> String {
85 let kata = Kata {
86 level: Level::L8kyu,
87 tags: vec![Tag::Fundamentals],
88 description: String::from("altERnaTIng cAsE <=> ALTerNAtiNG CaSe"),
89 };
90
91 println!(
92 "Level: {:?}, Tags: {:?}, Description: {}",
93 kata.level, kata.tags, kata.description
94 );
95
96 s.chars()
97 .map(|c| {
98 if c.is_uppercase() {
99 c.to_lowercase().to_string()
100 } else if c.is_lowercase() {
101 c.to_uppercase().to_string()
102 } else {
103 c.to_string()
104 }
105 })
106 .collect()
107}
108
109pub fn derive(coefficient: u32, exponent: u32) -> String {
116 let kata = Kata {
117 level: Level::L8kyu,
118 tags: vec![Tag::Fundamentals],
119 description: String::from("Take the Derivative"),
120 };
121
122 println!(
123 "Level: {:?}, Tags: {:?}, Description: {}",
124 kata.level, kata.tags, kata.description
125 );
126
127 format!("{}x^{}", coefficient * exponent, exponent - 1)
128}
129
130pub fn multi_table(n: u64) -> String {
137 let kata = Kata {
138 level: Level::L8kyu,
139 tags: vec![Tag::Fundamentals, Tag::Strings],
140 description: String::from("Multiplication table for number"),
141 };
142
143 println!(
144 "Level: {:?}, Tags: {:?}, Description: {}",
145 kata.level, kata.tags, kata.description
146 );
147
148 let mut mult_t = String::from("");
149 for i in 1..10 {
150 let line = format!("{} * {} = {}\n", i, n, i * n);
151 mult_t.push_str(&line);
152 }
153 let last_line = format!("{} * {} = {}", 10, n, 10 * n);
154 mult_t.push_str(&last_line);
155 mult_t
156}
157
158pub fn is_love(flower1: u16, flower2: u16) -> bool {
167 let kata = Kata {
168 level: Level::L8kyu,
169 tags: vec![Tag::Fundamentals],
170 description: String::from("Opposites Attract"),
171 };
172
173 println!(
174 "Level: {:?}, Tags: {:?}, Description: {}",
175 kata.level, kata.tags, kata.description
176 );
177
178 if (flower1 + flower2) % 2 != 0 {
179 return true;
180 } else {
181 return false;
182 }
183}