Skip to content

Instantly share code, notes, and snippets.

@murasesyuka
murasesyuka / SinglyLinkedList.rs
Last active August 14, 2019 06:57
Singly-Linked List Rust
/** ref
* https://medium.com/@11Takanori/singly-linked-list-in-rust-70a7c2cfa162
* https://qnighy.hatenablog.com/entry/2017/05/18/070000
* https://stackoverflow.com/questions/1738758/linked-list-ocaml
*/
#[derive(Debug)]
struct List<T> {
root: Option<Box<Node<T>>>,
#![allow(unused)]
//1.1
fn sum_div3or5(n: u32) -> u32{
let mut sum = 0;
for i in 1..(n+1) {
if i % 3 == 0 || i % 5 == 0 {
sum += i;
}
}
@murasesyuka
murasesyuka / cstdio.rs
Last active April 4, 2022 21:41
sscanf impliment in rust
#[allow(unused)]
use std::io::{self, BufRead};
macro_rules! sscanf {
($str: expr, $( $t:ty ),+ ) => {{
let mut iter = $str.split_whitespace();
($(iter.next().unwrap().parse::<$t>().unwrap(),)+)
}};
($str: expr, $idt: ident, $( $t:ty ),+ ) => {{
let mut iter = $str.split($idt);
@murasesyuka
murasesyuka / CheetahBook_ch8.fsx
Last active April 24, 2017 15:37
read chokudai book with F#
// P.223
module ColorfulBoxesAndBalls = begin
type intMin = int
let getMatximum numRed numBlue onlyRed onlyBlue bothColors =
let mutable ans = intMin.MinValue
let chg = min numRed numBlue
for i=0 to chg do
let myscore = ((numRed - i) * onlyRed +
(numBlue- i) * onlyBlue+
@murasesyuka
murasesyuka / cheatsheetFsharp3.fsx
Created March 30, 2017 12:29
read & write. memo F# Cheatsheet
/// https://dungpa.github.io/fsharp-cheatsheet/
open Microsoft.FSharp.Core
open Microsoft.FSharp.Collections
let result = 1 + 1 = 2
let hello = "hello" + "world"
let verbatimXml = @"<book title=""Paradise Lost"">"
@murasesyuka
murasesyuka / Generic.fs
Last active March 21, 2017 13:53
Samples F# of Generic
open Microsoft.FSharp.Collections
open System.Collections.Generic
open System.Numerics
let inline baymax a b = if a > b then a else b
let inline fffact n =
let one = LanguagePrimitives.GenericOne
let zero= LanguagePrimitives.GenericZero
if n = zero then one
@murasesyuka
murasesyuka / CatalanNumber.fs
Last active March 22, 2017 15:26
Try F# Generics
open Microsoft.FSharp.Collections
open System.Collections.Generic
let rec fact (n:int64) :int64 =
if n = 0L then 1L
else n * fact (n-1L)
let comb (n:int64) (r:int64) =
let a = fact n
let b = fact r
@murasesyuka
murasesyuka / ch7_knapsack.cpp
Last active March 15, 2017 11:57
read chokudai book with C++
#include <bits/stdc++.h>
using namespace std;
//
// P. 177 knapsack
// g++ -O3 knapsack2.cpp -std=gnu++1y && ./a.out
//
int knapsack2(int n, int w){
@murasesyuka
murasesyuka / dfs.ml
Last active March 9, 2017 22:49
Successfully set matrix of OCaml
module DP =
struct
let h = 13
let w = 17
(* let memo = Array.make (h+1) (Array.make (w+1) 0) *)
let memo = Array.make_matrix (h+1) (w+1) 0
let rec dfs nowh noww =
if nowh > h || noww > w then
0
@murasesyuka
murasesyuka / CheetahBook_ch5-ch7.fs
Last active March 18, 2017 05:46
read chokudai book with F#
// F# の詳細については、http://fsharp.org を参照してください
// 詳細については、'F# チュートリアル' プロジェクトを参照してください。
open Microsoft.FSharp.Collections
open System.Collections.Generic
// P. 122 CrazyBot
module CrazyBot = begin
let grid = Array2D.create 100 100 false
let vx = [|1;-1;0; 0|]