-
Notifications
You must be signed in to change notification settings - Fork 75
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
64 changed files
with
669 additions
and
101 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
максимальна оцінка на екзамені - 100 балів | ||
|
||
5+ = 95-100 | ||
5 = 90-95 | ||
4 = 75-89 | ||
3 = 60-74 | ||
|
||
1. теоретичне питання - макс 20 балів | ||
2. практичне питання №1 - макс 30 балів | ||
3. практичне питання №2 - макс 50 балів | ||
4. наявність GitHub репозиторію з 16 практичними завданнями - макс 20 балів | ||
5. наявність GitHub репозиторію з 20 задачами hackerrank - макс 20 балів |
Large diffs are not rendered by default.
Oops, something went wrong.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
### practical lessons | ||
|
||
1. github | ||
2. project structure | ||
3. TODO | ||
4. envelope - console | ||
5. apples_and_oranges | ||
6. chess_board - console | ||
7. rhombus - console | ||
8. brackets_is_valid_simple - string/array | ||
9. brackets_max_level - string/array | ||
10. shoes_groups - string/array | ||
11. counting_valleys - string/array | ||
12. parking_dilemma - array/array | ||
13. brackets_is_valid_full - string/array | ||
14. char_indexes - data manipulation | ||
15. pack-unpack - data manipulation | ||
16. 5317^1000000000 |
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
mod envelope1; | ||
mod envelope2; |
Binary file not shown.
Binary file not shown.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
mod envelope; | ||
mod apple_and_oranges; |
Binary file not shown.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
mod envelope; | ||
mod chessboard; |
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
mod apple_and_oranges; | ||
mod rhombus; |
File renamed without changes.
Binary file not shown.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
mod chessboard; | ||
mod brackets_is_valid; |
Binary file not shown.
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
mod rhombus; | ||
mod brackets_max_level; |
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
mod brackets_is_valid; | ||
mod shoes_groups; |
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
/// https://www.hackerrank.com/challenges/counting-valleys/problem | ||
fn countingValleys(steps: i32, path: &str) -> i32 { | ||
let mut n = 0; | ||
let mut p = 0; | ||
|
||
for c in path.chars() { | ||
let l = match c { | ||
'U' => p + 1, | ||
'D' => p - 1, | ||
_ => continue, | ||
}; | ||
if l == 0 && p < 0 { | ||
n += 1; | ||
} | ||
p = l; | ||
} | ||
|
||
n | ||
} | ||
|
||
fn countingValleys2(steps: i32, path: &str) -> i32 { | ||
struct State { | ||
level: i32, | ||
count: i32, | ||
} | ||
|
||
fn is_crossed(prev_level: i32, curr_level: i32) -> bool { | ||
prev_level < 0 && curr_level == 0 | ||
} | ||
|
||
impl State { | ||
fn new(level: i32, count: i32) -> State { | ||
State { level, count } | ||
} | ||
fn fresh() -> State { | ||
State::new(0, 0) | ||
} | ||
fn next(&self, cur_level: i32, crossed: bool) -> State { | ||
let delta = if crossed { 1 } else { 0 }; | ||
State::new(cur_level, self.count + delta) | ||
} | ||
fn up(&self) -> State { | ||
let cur_level = self.level + 1; | ||
self.next(cur_level, is_crossed(self.level, cur_level)) | ||
} | ||
fn down(&self) -> State { | ||
let cur_level = self.level - 1; | ||
self.next(cur_level, is_crossed(self.level, cur_level)) | ||
} | ||
} | ||
|
||
fn logic(st: State, c: char) -> State { | ||
match c { | ||
'U' => st.up(), | ||
'D' => st.down(), | ||
_ => st, | ||
} | ||
} | ||
|
||
let s = path | ||
.chars() | ||
.fold(State::fresh(), logic); | ||
|
||
s.count | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1 @@ | ||
mod brackets_max_level; | ||
mod shoes_groups; | ||
mod counting_valleys; |
Binary file not shown.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1 @@ | ||
mod counting_valleys; | ||
mod parking_dilemma; |
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,60 @@ | ||
fn car_parking_roof(cars: &[usize], k: usize) -> usize { | ||
use std::cmp::min; | ||
|
||
fn car_parking_roof1(cars: &[u32], k: usize) -> u32 { | ||
let mut cars = cars.to_vec(); | ||
cars.sort(); | ||
|
||
let roof_size = |i1: usize, i2: usize| -> u32 { cars[i2] - cars[i1] + 1 }; | ||
|
||
let mut m = roof_size(0, k - 1); | ||
|
||
println!("{:?}", cars); | ||
|
||
for idx in 0..cars.len() - k + 1 { | ||
let s = roof_size(idx, idx + (k - 1)); | ||
m = min(m, s); | ||
println!("i: {idx}, size: {s}, min:{m}"); | ||
} | ||
|
||
m | ||
} | ||
|
||
fn car_parking_roof2(cars: &[usize], k: usize) -> usize { | ||
let mut cars = cars.to_vec(); | ||
cars.sort_unstable(); | ||
(0..(cars.len() - k)) | ||
.map(|idx| cars[idx + k - 1] - cars[idx] + 1) | ||
let roof_size = |idx: usize| cars[idx + k - 1] - cars[idx] + 1; | ||
(0..(cars.len() - k + 1)) | ||
.map(roof_size) | ||
.min() | ||
.unwrap() | ||
} | ||
|
||
fn car_parking_roof3(cars: &[u32], k: usize) -> u32 { | ||
let mut cars = cars.to_vec(); | ||
cars.sort(); | ||
let roof_size = |i: (usize, usize)| cars[i.0].abs_diff(cars[i.1]) + 1; | ||
let it1 = 0..; | ||
let it2 = (k - 1)..cars.len(); | ||
it1.zip(it2) | ||
.map(roof_size) | ||
.min() | ||
.unwrap() | ||
} | ||
|
||
#[test] | ||
fn car_parking_roof_test() { | ||
fn car_parking_roof_test1() { | ||
let cars = [6, 2, 12, 7]; | ||
let k = 3; | ||
let roof_expected = 6; | ||
let roof_real = car_parking_roof2(&cars, k); | ||
assert_eq!(roof_expected, roof_real); | ||
} | ||
|
||
let roof_size = car_parking_roof(&cars, k); | ||
let expected = 6; | ||
assert_eq!(expected, roof_size); | ||
#[test] | ||
fn car_parking_roof_test2() { | ||
let cars = [6, 2, 12, 7, 20, 25, 26, 28]; | ||
let k = 3; | ||
let roof_expected = 4; | ||
let roof_real = car_parking_roof3(&cars, k); | ||
assert_eq!(roof_expected, roof_real); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
use std::collections::{HashMap, HashSet}; | ||
|
||
/// straightforward | ||
fn brackets_is_valid_full(s: String) -> bool { | ||
let pairs = HashMap::from([('}', '{'), (')', '('), (']', '['), ('>', '<')]); | ||
let open = HashSet::<char>::from_iter("{[(<".chars()); | ||
let close = HashSet::<char>::from_iter("}])>".chars()); | ||
|
||
let mut stack = Vec::new(); | ||
for c in s.chars() { | ||
match c { | ||
c if open.contains(&c) => stack.push(c), | ||
c if close.contains(&c) => match stack.pop() { | ||
None => return false, | ||
Some(top) => match pairs.get(&c) { | ||
Some(&op) if op == top => (), | ||
Some(_) | None => return false, | ||
}, | ||
}, | ||
_ => continue, | ||
} | ||
} | ||
|
||
stack.is_empty() | ||
} | ||
|
||
/// more functional | ||
fn brackets_is_valid_full2(s: String) -> bool { | ||
let pairs = HashMap::from([('}', '{'), (')', '('), (']', '['), ('>', '<')]); | ||
let open = HashSet::<char>::from_iter("{[(<".chars()); | ||
let close = HashSet::<char>::from_iter("}])>".chars()); | ||
|
||
enum State { | ||
Valid(Vec<char>), | ||
Invalid, | ||
} | ||
|
||
impl State { | ||
fn new() -> Self { | ||
State::Valid(Vec::new()) | ||
} | ||
} | ||
|
||
let process = |mut st: State, c: char| match st { | ||
State::Valid(ref mut stack) => match c { | ||
c if open.contains(&c) => { | ||
stack.push(c); | ||
st | ||
} | ||
c if close.contains(&c) => match stack.pop() { | ||
Some(top) => match pairs.get(&c) { | ||
Some(&op) if op == top => st, | ||
_ => State::Invalid, | ||
}, | ||
_ => State::Invalid, | ||
}, | ||
_ => st, | ||
}, | ||
_ => State::Invalid, | ||
}; | ||
|
||
let s = s | ||
.chars() | ||
.fold(State::new(), process); | ||
|
||
match s { | ||
State::Valid(stack) => stack.is_empty(), | ||
State::Invalid => false, | ||
} | ||
} | ||
|
||
#[test] | ||
fn is_valid_test2() { | ||
let test_data = [ | ||
//input expected | ||
("{}", true), | ||
("[{(<>()[])}<>]", true), | ||
("{}{}", true), | ||
("{{}}", true), | ||
("{{}{}}", true), | ||
("{{}", false), | ||
("{}}", false), | ||
("}{", false), | ||
("{", false), | ||
("}", false), | ||
("<}", false), | ||
]; | ||
|
||
for (s, r) in test_data { | ||
assert_eq!(brackets_is_valid_full(s.to_string()), r); | ||
assert_eq!(brackets_is_valid_full2(s.to_string()), r); | ||
} | ||
} |
Empty file.
Oops, something went wrong.