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
| import std.stdio, std.parallelism, std.range, std.algorithm; | |
| enum L = 12; | |
| struct V {int x,y;} | |
| int optLen(int seed) { | |
| int[32*32] field; | |
| V[4] vecs = [V(1,0), V(0,-1), V(-1,0), V(0,1)]; | |
| V[L] path; |
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
| // dmd -preview=dip1021 liev.d | |
| import std.stdio; | |
| struct S { string name; } | |
| @live void use(scope const S* p) { // ok | |
| writeln(p.name); | |
| } | |
| void release(S *p) { } // consumes the ownership |
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
| import std.stdio; | |
| // secret sauce: https://dlang.org/spec/class.html#alias-this | |
| struct DayNum { | |
| int dn; | |
| alias dn this; // this line makes DayNum look like an int with dn as the value | |
| } | |
| DayNum next(DayNum d) { |
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
| {-# LANGUAGE BangPatterns #-} | |
| import qualified Data.Vector.Unboxed as V | |
| import System.CPUTime | |
| import Text.Printf | |
| time :: IO t -> IO t | |
| time a = do | |
| start <- getCPUTime | |
| v <- a | |
| end <- getCPUTime |
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 Main | |
| import Data.Vect | |
| toVec : List a -> (n : Nat ** Vect n a) | |
| toVec [] = (_ ** []) | |
| toVec (x::xs) with (toVec xs) | |
| | (k ** v) = (S k ** x :: v) | |
| myFun : Vect n1 Int -> Vect n2 Int -> LTE n1 n2 -> Int | |
| myFun xs ys p = foldr (+) 0 xs |
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
| import std.complex, std.stdio, std.random, std.parallelism, std.math : hypot; | |
| import std.getopt, std.datetime.stopwatch, std.array, std.algorithm : max, min, reduce; | |
| import std.format, std.range : iota; | |
| struct Wall { double y, x1, x2; } // x1 < x2 | |
| struct Point { double x, y; } | |
| bool intersects(Point p1, Point p2, ref Wall wall) { | |
| if (min(p1.y, p2.y) > wall.y) return false; | |
| if (max(p1.y, p2.y) < wall.y) return false; |
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
| ILogger { | |
| void log(string msg); | |
| } | |
| class BoringLogger : ILogger { | |
| overrride void log(string msg) {...} | |
| } | |
| class ColorfulLogger : ILogger { | |
| overrride void log(string msg) {...} |
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 Batteries | |
| type point = { x : int; y : int } | |
| let f from_y to_y from_x to_x = | |
| let a = (from_y --^ to_y/2) |> Enum.map (fun y -> {x=from_x; y=y}) in | |
| let b = (to_y/2 --^ to_y) |> Enum.map (fun y -> {x=to_x; y=y}) in | |
| Enum.append a b |> Array.of_enum;; | |
| let g from_y to_y from_x to_x = | |
| let t = to_y/2 in | |
| Array.init (to_y - from_y) (fun i -> let y = i + from_y in if y < t then {x=from_x; y=y} else {x=to_x;y=y});; |
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
| import std.stdio, std.algorithm, std.range, std.array, std.datetime.stopwatch; | |
| struct Point { int x, y; } | |
| auto f(int from_y, int to_y, int from_x, int to_x) { | |
| return chain( iota(from_y, to_y/2).map!(y => Point(from_x, y)), | |
| iota(to_y/2, to_y) .map!(y => Point(to_x, y)) ).array; | |
| } | |
| auto g(int from_y, int to_y, int from_x, int to_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
| import qualified Data.ByteString.Lazy.Char8 as L8 | |
| import Network.HTTP.Client (defaultManagerSettings, newManager) | |
| import Network.HTTP.Simple | |
| import Network.HTTP.Client.TLS | |
| import System.Directory | |
| import qualified Data.Map as M | |
| import Data.List (sortBy) | |
| import Control.Monad | |
| import Control.Applicative | |
| import System.Environment |