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 Entity { | |
fn walk(&self) -> String; | |
} | |
struct Dog { | |
name: String, | |
age: i32 | |
} | |
impl Dog { |
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 text = "ありがとうございます"; | |
let words = text.split("").map(|w| w.as_bytes()).collect::<Vec<&[u8]>>(); | |
let length = words.iter().fold(0, |acc, val| acc + val.len()); | |
println!("Input Text: {}", text); | |
println!("Bytes: {:?}", words); | |
println!("Text is {} bytes long", length); | |
let mut inline_bits = String::new(); |
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
#[derive(Debug, PartialEq, Eq, Clone)] | |
struct Node<T: Clone> { | |
name: String, | |
value: T, | |
next: Option<Box<Node<T>>> | |
} | |
impl<T: PartialEq + Clone> Node<T> { | |
fn new(name: &str, value: T) -> Self { | |
Node { |
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
use std::io::{self, Read, Write}; | |
struct StringRW { | |
value: String, | |
buffer: Vec<u8>, | |
} | |
impl StringRW { | |
fn new(value: &str) -> Self { | |
StringRW { |
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
# num = 1234 | |
# num_length = Math.log(num, 10).ceil => 4 | |
# base = 10 ** (num_length - 1) => 1000 | |
def is_armstrong(num) | |
if (1..9).include?(num) | |
return true | |
elsif num == 10 | |
return false | |
end |
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
#include <vector> | |
#include <math.h> | |
namespace number { | |
bool is_narci(int num) { | |
int num_cp = num; | |
int num_length = num == 1 ? 1 : ceil(log10(num)); | |
int length = num_length; | |
int acc = 0; |
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 lazy_static; | |
use std::collections::HashMap; | |
lazy_static!( | |
static ref MAPPING: HashMap<char, char> = [('}', '{'), (')', '('), (']', '[')] | |
.iter() | |
.cloned() | |
.collect(); | |
); |
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
#include "stdio.h" | |
#include "stdlib.h" | |
typedef struct _node { | |
int value; | |
struct _node *next; | |
} node; | |
// Create a new node with the provided value | |
node *new_node(int _value) { |
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
#include "stdio.h" | |
#include "stdlib.h" | |
#define M 3 | |
typedef struct _node { | |
int n; /* n < M No. of keys in node will always less than order of B tree */ | |
int keys[M - 1]; /*array of keys*/ | |
struct _node *p[M]; /* (n+1 pointers will be in use) */ | |
} node; |
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
#include <iostream> | |
#include "node.h" | |
#include "nodeValue.h" | |
using namespace std; | |
struct animal: public nodeValue { | |
int age; |