Skip to content

Instantly share code, notes, and snippets.

@miguelraz
Created July 9, 2022 01:23
Show Gist options
  • Save miguelraz/0948387551a3333c78378a833ae065c5 to your computer and use it in GitHub Desktop.
Save miguelraz/0948387551a3333c78378a833ae065c5 to your computer and use it in GitHub Desktop.

Very rough sketch!

  1. way more mini exercises
  • loopy vs iterator way
  • factorial and add
    • 1 to 100 elems
  • collect all evens
  • any
  • all
  • fold, scan, reduce, flatten_map, tree_fold1
  • partition, partition_in_place, (COMPARE to C++)
  • lower_bound, upper_bound vs binary_search_by (compare to C++)
  • nth_element, ??? (in RUST?), partition_by, select_nth_unstable_by
https://www.youtube.com/watch?v=d3qY4dZ2r4w

ITERTOOLS

  • map_ok, filter_ok
use itertools::Itertools;

let input = vec![Ok(41), Err(false), Ok(11)];
let it = input.into_iter().map_ok(|i| i + 1);
itertools::assert_equal(it, vec![Ok(42), Err(false), Ok(12)]);
  • filter_map_ok
  • (1..7).interleave(vec![1, 2]);
  • filter_map
  • take, nth, skip, take_while, zip
  • dot product
  • dedup
  • find duplicates
  • duplicates by
  • unique
  • combinations of 3
use itertools::Itertools;

let it = (1..5).combinations(3);
itertools::assert_equal(it, vec![
    vec![1, 2, 3],
    vec![1, 2, 4],
    vec![1, 3, 4],
    vec![2, 3, 4],
]);
  • powerset
  • all equal, all_unique
  • chars()
  • hamming distance
  • collect all squares less than 100 into a HashSet
  • concat
vec![vec![1], vec![2, 3], vec![4, 5, 6]];
  • more itertools demos
    • intersperse((0..10), 42)
    • intersperse_with((0..10), square(i))
    • kmerge for elt in kmerge(vec![vec![0, 2, 4], vec![1, 3, 5], vec![6, 7]]) { /* l oop body */ }
  • accumulate
  1. Rustacean screensavers of cool things in between breaks?

  2. Green and yellow doesn't have per step solutions :/

  3. Play Wordle once before the Green and Yellow handing it out

  4. Small regular expressions exercises with r### examples

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment