Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions 2022-11-21.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,11 @@ https://youtu.be/YOUTUBE_ID

### Participantes

- [@seugithubhandleaqui](https://github.com/seugithubhandleaqui)
- ...
- [@fczuardi](https://github.com/fczuardi)
- [@igstefano](https://github.com/igstefano)
- [@luizdepra](https://github.com/luizdepra)
- [@joaovictornm](https://github.com/joaovictornm)
- [@GuilhermeVBeira](https://github.com/GuilhermeVBeira)

<!--
## Produtos
Expand Down
40 changes: 40 additions & 0 deletions 2022-12-05.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
# Encontro 008

<!--
![Rust para Iniciantes](https://user-images.githubusercontent.com/7760/200308100-88c600b2-d68a-4494-8d70-d6af6a590b83.png)

[![Encontro 8](http://img.youtube.com/vi/YOUTUBE_ID/0.jpg)](https://youtu.be/YOUTUBE_ID "Youtube: Encontro 8")

https://youtu.be/YOUTUBE_ID
-->


## Informações
- **Data**: segunda, 05 de dezembro de 2022, 16:30
- **Local**: Google Meet
- [Encontro Passado](2022-11-21.md)

### Agenda
- boas vindas
- apresentações
- ack das [regras](README.md#regras) e início da gravação
- escolha do problema
- discussão, resumo dos temas cobertos, dúvidas
- registro dos produtos e agendamento do próximo

### Participantes

- [@seu_handle_do_github_aqui](https://github.com/seu_handle_do_github_aqui)

<!--
## Produtos

### Do encontro
- [gravação](https://youtu.be/YOUTUBE_ID)
- [código](./encontro6)

### Outros assuntos, notas e links

- ...
-->

7 changes: 5 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,17 +17,20 @@ Encontro de pessoas que querem aprender [Rust][rust].
[video4]: https://youtu.be/oDDllu9ISYo
[video5]: https://youtu.be/mKt0jM3xlBs
[video6]: https://youtu.be/KVehwy1hCXQ
<!-- TODO colocar o link do youtube-->
[video7]: https://youtu.be/KVehwy1hCXQ
[contact]: https://github.com/Rust-dojo/eventos/issues

## Próximo encontro:

- 21 de Novembro de 2022
- 05 de Dezembro de 2022
- 16:30 [nesta sala de Google Meet][meetlink]
- [agenda](2022-11-21.md)
- [agenda](2022-12-05.md)
- [checklist](https://github.com/Rust-dojo/eventos/issues/15)

## Edições passadas:

- [21 de Novembro de 2022](2022-11-21.md) ([vídeo][video7])
- [07 de Novembro de 2022](2022-11-07.md) ([vídeo][video6])
- [24 de Outubro de 2022](2022-10-24.md) ([vídeo][video5])
- [10 de Outubro de 2022](2022-10-10.md) ([vídeo][video4])
Expand Down
7 changes: 7 additions & 0 deletions encontro7/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions encontro7/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
[package]
name = "encontro7"
version = "0.1.0"
edition = "2021"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
75 changes: 75 additions & 0 deletions encontro7/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
/*

https://exercism.org/tracks/rust/exercises/anagram

Instructions
An anagram is a rearrangement of letters to form a new word. Given a word and a list of
candidates, select the sublist of anagrams of the given word.

Given "listen" and a list of candidates like "enlists" "google" "inlets" "banana" the
program should return a list containing "inlets".

The solution is case insensitive, which means "WOrd" is the same as "word" or "woRd".
It may help to take a peek at the std library for functions that can convert between them.

The solution cannot contain the input word. A word is always an anagram of itself,
which means it is not an interesting result. Given "hello" and the list
["hello", "olleh"] the answer is ["olleh"].

You are going to have to adjust the function signature provided in the stub in order
for the lifetimes to work out properly. This is intentional: what's there demonstrates the basics of lifetime syntax, and what's missing teaches how to interpret lifetime-related compiler errors.

Try to limit case changes. Case changes are expensive in terms of time, so it's faster to minimize them.

If sorting, consider sort_unstable which is typically faster than stable sorting. When applicable, unstable sorting is preferred because it is generally faster than stable sorting and it doesn't allocate auxiliary memory.

*/

pub fn is_anagram(word: &String, candidate: &String) -> bool {
// candidate.len() == word.len()

let mut first_word: Vec<char> = word.chars().collect();
first_word.sort();

let first_word_str:String = first_word.into_iter().collect();

let mut candidate_word = candidate.chars().collect::<Vec<char>>();
candidate_word.sort_unstable();

let candidate_word_str:String = candidate_word.into_iter().collect();

candidate_word_str == first_word_str
}

pub fn find_anagrams( word: &String, anagram_candidates: Vec<String>) -> Vec<String>{
let mut result = vec![];
for c in anagram_candidates.into_iter() {
if is_anagram(word, &c) {
result.push(c);
}
}
result
}

#[cfg(test)]
mod tests {
use super::*;

#[test]
fn no_match() {
let word = "foo".to_string();
let expected: Vec<String> = vec![];
let result = find_anagrams(&word, vec!["huebr".to_string()]);
assert_eq!(result, expected);
}

#[test]
fn one_match() {
let word = "foo".to_string();
let candidates = vec!["foo".to_string(), "hue".to_string()];
let expected: Vec<String> = vec!["foo".to_string()];
let result = find_anagrams(&word, candidates);
assert_eq!(result, expected);
}

}