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
// System.Text.Json でシリアライズする際に全角空白などをUnicode表記にせずそのまま出力するエンコーダー | |
// 移植元・参考 : https://gist.github.com/ufcpp/08bc36a4619855bed5b8702107e887ea | |
module Adacola.JavaScriptEncoder | |
#r "nuget: FSharp.Span.Utils" | |
#r "nuget: FSharp.SystemTextJson" | |
open System | |
open System.Text |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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
type FizzBuzz = Fizz | Buzz | |
let fizzbuzz<'a100>() = | |
let fizz = nameof Fizz | |
let buzz = nameof Buzz | |
let fizzbuzz = nameof FizzBuzz | |
let three = (nameof int).Length | |
let five = (nameof float).Length | |
let one = (nameof System.Math.E).Length | |
let hundred = nameof<'a100>.ToCharArray() |> Array.tail |> System.String |> int |
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://programmingpraxis.com/2010/11/19/topological-sort/ | |
// 上記ページ記載のアルゴリズムを末尾再帰化、効率向上、閉路存在時の例外追加 | |
let topologicalSort edges = | |
let rec loop removed isolated = function | |
| [] -> List.rev removed @ Set.toList isolated | |
| edges -> | |
let src, dst = edges |> List.unzip | |
let dstSet = set dst | |
let noIncomingVertex = |
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
#!/bin/sh | |
#if run_with_bin_sh | |
exec dotnet fsi $0 "$@" | |
#endif | |
// 実装の参考資料 : http://users.telenet.be/d.rijmenants/Enigma%20Sim%20Manual.pdf | |
// テストに使用したシミュレータ : https://www.101computing.net/enigma-machine-emulator/ | |
#r "nuget: FSharpPlus" | |
#r "nuget: Argu" |
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
namespace Adacola.ResultExtensions | |
open System | |
module Result = | |
let ofOption ifNone op = | |
match op with | |
| Some v -> Ok v | |
| None -> Error ifNone |
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
#r "System.IO.Compression.dll" | |
#r "System.IO.Compression.FileSystem.dll" | |
open System.IO | |
open System.IO.Compression | |
let rec extractAll sourceDir targetDir = | |
let copyAll sourceDir targetDir = | |
let rec loop tasks sourceDir targetDir = | |
let tasks = (tasks, Directory.EnumerateFiles sourceDir) ||> Seq.fold (fun tasks sourceFile -> |
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 System | |
type EthanolBuilder() = | |
let printWarning() = printfn "飲酒中に書いたコードなので危険です!" | |
member __.Bind(x, f) = printWarning(); f x | |
member __.Return(x) = x | |
member __.ReturnFrom(x) = printWarning(); x | |
member __.Using(x: #IDisposable, f) = try f x finally if x |> box |> isNull |> not then x.Dispose() | |
member __.Zero() = () | |
member __.Combine(_, f) = f() |
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
/// Miller-Rabin法を使った素数判定 | |
let isPrime n = | |
let modPow x k m = | |
let rec loop result x k m = | |
if k = 0L then result else | |
let result = if k &&& 1L = 0L then result else result * x % m | |
let k = k / 2L | |
let x = x * x % m | |
loop result x k m | |
loop 1L x k m |
NewerOlder