This file contains 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_module(library(clpfd)). | |
l2n_1([], Acc, Acc). | |
l2n_1([X|Xs], Acc, N) :- | |
Acc1 is 10*Acc+X, | |
l2n_1(Xs, Acc1, N). | |
%?- l2n_1([1, 2, 3], 0, X). | |
%@ X = 123. |
This file contains 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
cons(X, Y, [X|Y]). | |
comb(0, _, [[]]). | |
comb(N, Xs, []) :- length(Xs, N1), N > N1. | |
comb(N, [X|Xs], Ys) :- | |
N > 0, | |
N1 is N - 1, | |
comb(N, Xs, Ys1), | |
comb(N1, Xs, Ys2), | |
maplist(cons(X), Ys2, Ys3), |
This file contains 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
% -*- prolog-system: gnu -*- | |
q3(A, B, C) :- | |
fd_cardinality([A, B, C], Knights), | |
A #\<=> Knights, | |
B #<=> Knights, | |
fd_labeling([A, B, C]). |
This file contains 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
loadFileSafe(F, Status) :- | |
catch(load_files(F), error(existence_error(source_sink, F), _), Status = failed). | |
catchFileErrors(G, F) :- | |
catch(G, error(existence_error(source_sink, F), _), true). | |
safeLoadConfig(F) :- | |
catch(load_files(F), | |
error(existence_error(source_sink, F), _), |
This file contains 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
filterMap :: (a -> Maybe b) -> [a] -> [b] | |
filterMap _ [] = [] | |
filterMap f (x:xs) = case f x of | |
Just y -> y : filterMap f xs | |
Nothing -> filterMap f xs | |
assoc :: Eq b => [(a, b)] -> [(b, c)] -> [(a, c)] | |
assoc _ [] = [] | |
assoc xs ((yb, yc):ys) = filterMap (f yb yc) xs ++ assoc xs ys | |
where |
This file contains 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 strict; | |
use warnings; | |
use feature qw(signatures); | |
no warnings qw(experimental::signatures); | |
use DateTime; | |
use Mojo::Server::Daemon; | |
my $daemon = Mojo::Server::Daemon->new(listen => ['http://*:8080']); | |
sub req ($d, $t) { |
This file contains 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
(defun flip-adjacent (lst) | |
(cond | |
((null lst) lst) | |
((null (cdr lst)) lst) | |
(t (destructuring-bind (a b . r) lst | |
(cons b (cons a (flip-adjacent r))))))) | |
(defun flip-adjacent-2 (lst acc) | |
(cond | |
((null lst) (reverse acc)) |
This file contains 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
subject(t1, math). | |
subject(t2, math). | |
subject(t2, english). | |
subject(t3, sports). | |
subject(t3, art). | |
subject(t3, english). | |
subject(t4, math). | |
subject(t4, art). | |
subject(t5, sports). | |
subject(t5, math). |
This file contains 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 FlexibleInstances #-} | |
{-# LANGUAGE TypeSynonymInstances #-} | |
module ChurchNat () where | |
type Church a = (a -> a) -> a -> a | |
-- instance Functor Church where | |
-- fmap f n = undefined | |
suc :: Church a -> Church a |
This file contains 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
%!PS | |
/line { | |
moveto | |
lineto | |
stroke | |
} bind def | |
/++ { | |
1 add def %How to get the value of a name in the stack? |
NewerOlder