Skip to content

Instantly share code, notes, and snippets.

@PythonJedi
PythonJedi / dag_calc.py
Last active March 26, 2016 17:29
Silly little calculator language expressing functions as DAGs of arithmetic expressions.
#! /usr/bin/python3
""" Silly little dag calculator language on ints. """
# ops are defined to return lists for a very good reason
ops = {"I": lambda a:[a], \
"A": lambda b:[b,b], \
"X": lambda c, d: [d,c], \
"+": lambda e, f: [e+f], \
"-": lambda g, h: [g-h], \
"*": lambda i, j: [i*j], \
# whitespace separated list of source directories and desired products
sources = common server client
products = server client
# compiletime flags, constant
CXXFLAGS = -Wall -std=c++11
# Initialize the obj and source lists for an arbitrary directory
define init
$(1)_src = $(wildcard $(1)/*.cpp)
There's not much that will reduce me to tears. Apparently the state of
enterprise development is one such thing. I gaze upon the lives of hundreds of
thousands of developers and my heart aches for their senseless suffering.
I have no blame to place. I wish not to point fingers.
We've forgotten where we started: nothing. All has sprung forth from the Void,
guided by the Minds between the Chairs and Keyboards. Misshapen eldritch horrors
that consume all in sight, warping the Minds into summoning an even bigger
fish. When will it end? Where will we be when that which is summoned consumes
while (*node != NULL) {
if (/* match condition*/)
node = &((*node)->child);
else
node = &((*node)->next);
}
@PythonJedi
PythonJedi / max_subarray.py
Created September 2, 2016 16:35
python version of max subarray solution
#! /usr/bin/python3
import random
# A quick test of a linear max subarray algorithm
class Partial:
"""Named collection corresponding to a partial sum of a sequence of deltas"""
def __init__(self, value, index):
self.value = value
noun(man).
noun(ball).
verb(hit).
verb(took).
article(the).
% Handle splitting sublists
is_cat([], B, C) :-
B = C.
open("/usr/lib/swipl-7.2.3/lib/x86_64-linux/tls/x86_64/libswipl.so.7.2", O_RDONLY|O_CLOEXEC) = -1 ENOENT (No such file or directory)
open("/usr/lib/swipl-7.2.3/lib/x86_64-linux/tls/libswipl.so.7.2", O_RDONLY|O_CLOEXEC) = -1 ENOENT (No such file or directory)
open("/usr/lib/swipl-7.2.3/lib/x86_64-linux/x86_64/libswipl.so.7.2", O_RDONLY|O_CLOEXEC) = -1 ENOENT (No such file or directory)
open("/usr/lib/swipl-7.2.3/lib/x86_64-linux/libswipl.so.7.2", O_RDONLY|O_CLOEXEC) = 3
open("/usr/lib/swipl-7.2.3/lib/x86_64-linux/libpthread.so.0", O_RDONLY|O_CLOEXEC) = -1 ENOENT (No such file or directory)
open("/etc/ld.so.cache", O_RDONLY|O_CLOEXEC) = 3
open("/usr/lib/libpthread.so.0", O_RDONLY|O_CLOEXEC) = 3
open("/usr/lib/swipl-7.2.3/lib/x86_64-linux/libc.so.6", O_RDONLY|O_CLOEXEC) = -1 ENOENT (No such file or directory)
open("/usr/lib/libc.so.6", O_RDONLY|O_CLOEXEC) = 3
open("/usr/lib/swipl-7.2.3/lib/x86_64-linux/libgmp.so.10", O_RDONLY|O_CLOEXEC) = -1 ENOENT (No such file or directory)
@PythonJedi
PythonJedi / crack_the_code.pl
Created February 23, 2017 01:44
prolog code for facebook logic puzzle.
digit(X) :- member(X,[0,1,2,3,4,5,6,7,8,9]).
code([X,Y,Z]) :- digit(X), digit(Y), digit(Z),
rule1([X,Y,Z]),
rule2([X,Y,Z]),
rule3([X,Y,Z]),
rule4([X,Y,Z]),
rule5([X,Y,Z]).
rule1([X,Y,Z]) :- X=6 ; Y=8 ; Z=2.
@PythonJedi
PythonJedi / bubbleSort.pl
Created March 1, 2017 03:56
Bubble Sort in prolog
% Bubble sort in prolog, because bubble sort
bubble_sort([],Sorted) :-
Sorted = [].
bubble_sort([X], Sorted) :-
Sorted = [X].
bubble_sort(Terms, Sorted) :-
bubble(Terms, Terms), Sorted = Terms ;
bubble(Terms, Partials), bubble_sort(Partials, Sorted).
@PythonJedi
PythonJedi / sort.pl
Last active August 25, 2022 22:59
Prolog sorting
% Sorting algorithms in prolog for the fun of it
bubble_sort(List, Sorted) :- % the bubble_sort of List is Sorted only if
in_order(List) -> % List satisfying in_order implies
List = Sorted % List unifies with (is equivalent to) Sorted
; % or
bubble(List, Bubbled), % the bubble of List is Bubbled and
bubble_sort(Bubbled, Sorted). % bubble_sort of Bubbled is Sorted
in_order([]). % empty list satisfies in_order