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
| /** 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>>>, |
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
| #![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; | |
| } | |
| } |
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
| #[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); |
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
| // 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+ |
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
| /// 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"">" |
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
| 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 |
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
| 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 |
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 <bits/stdc++.h> | |
| using namespace std; | |
| // | |
| // P. 177 knapsack | |
| // g++ -O3 knapsack2.cpp -std=gnu++1y && ./a.out | |
| // | |
| int knapsack2(int n, int w){ |
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
| 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 |
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
| // 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|] |