This file contains hidden or 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
def uniq(arr) | |
r = [arr[0]] | |
arr.each do |a| | |
uniq = true | |
r.each do |n| | |
if a == n | |
uniq = false | |
end | |
end | |
r.push a if uniq |
This file contains hidden or 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
#[macro_use] | |
extern crate diesel; | |
use diesel::prelude::*; | |
table! { | |
users (id) { | |
id -> Int4, | |
first_name -> Nullable<Varchar>, | |
last_name -> Nullable<Varchar>, |
This file contains hidden or 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
fn uniq(arr: &[i32]) -> Vec<i32> { | |
let mut res = vec![arr[0]]; | |
for a in arr.iter().skip(1) { | |
let mut uniq = true; | |
for n in res.iter() { | |
if a == n { | |
uniq = false; | |
} | |
} | |
if uniq { res.push(*a) }; |
This file contains hidden or 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
// Remove duplicate words | |
// Your task is to remove all duplicate words from string, leaving only single words entries. | |
// Example: | |
// Input: | |
// 'alpha beta beta gamma gamma gamma delta alpha beta beta gamma gamma gamma delta' | |
// Output: | |
// 'alpha beta gamma delta' | |
fn remove_duplicate_words(s: &str) -> String { | |
let r = s.split(" ").fold(String::from(""), |mut r, a| { |
This file contains hidden or 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
=begin | |
Your task is to remove all duplicate words from string, leaving only single words entries. | |
Example: | |
Input: | |
'alpha beta beta gamma gamma gamma delta alpha beta beta gamma gamma gamma delta' | |
Output: |
This file contains hidden or 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
// Task | |
// Given two cells on the standard chess board, determine whether they have the same color or not. | |
// | |
// Example | |
// For cell1 = "A1" and cell2 = "C3", the output should be true. | |
const BOARD_SIZE: usize = 9; | |
fn chessboard_cell_color(cell1: &str, cell2: &str) -> bool { | |
let mut board = [false; BOARD_SIZE * BOARD_SIZE]; |
This file contains hidden or 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
//! ```cargo | |
//! [dependencies] | |
//! dialoguer = "*" | |
//! indicatif = "*" | |
//! ``` | |
extern crate dialoguer; | |
extern crate indicatif; | |
use dialoguer::Select; |
This file contains hidden or 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
trait Fruit { | |
fn who_am_i(&self) -> String; | |
} | |
struct Apple { | |
name: String, | |
} | |
struct Banana { | |
name: String, |
This file contains hidden or 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
fn iterate<T>(data: Vec<T>) -> impl Iterator<Item = T> { | |
data.into_iter() | |
} | |
fn main() { | |
for x in iterate(vec!["1", "2", "3"]) { | |
println!("Hi! {}", x); | |
} | |
} |
This file contains hidden or 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
fn main() { | |
let mut x = 2; | |
let mut y = 1; | |
println!("before x {} y {}", x, y); // before x 2 y 1 | |
if x != y { | |
x = x ^ y; | |
y = x ^ y; | |
x = x ^ y; |