Skip to content

Instantly share code, notes, and snippets.

@PythonJedi
PythonJedi / loop.c
Created February 27, 2018 18:04
infinipointer
#include<stdlib.h>
#include<stdio.h>
int main(int argv, char* argc[]) {
void** loop = malloc(sizeof(void**));
*loop = (void*) loop;
printf("loop: %p, *loop: %p\n", loop, *loop);
free(loop);
@PythonJedi
PythonJedi / kaprekar.c
Created November 8, 2017 05:48
Much faster implementation of Kaprekar's function
/*
* Attempt to find fixed points of a particularly interesting function.
*
* Kaprekar's function sorts the digits of n ascending and descending, then
* returns the descending minus the ascending. The fixed points of this
* function, as well as the attractor classes are very interesting.
*/
#include<stdio.h>
#include<limits.h>
@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
@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 / 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.
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)
noun(man).
noun(ball).
verb(hit).
verb(took).
article(the).
% Handle splitting sublists
is_cat([], B, C) :-
B = C.
@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
while (*node != NULL) {
if (/* match condition*/)
node = &((*node)->child);
else
node = &((*node)->next);
}
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