Skip to content

Instantly share code, notes, and snippets.

View Synxed's full-sized avatar

Synxed Synxed

  • Somewhere in milky way
View GitHub Profile
import java.awt.*;
import java.applet.*;
import java.applet.*;
import java.awt.*;
import java.util.*;
public class Clock extends Applet implements Runnable {
Thread t,t1;
public void start() {
t = new Thread(this);
<Cv>
<Personal>
<FirstName>John</FirstName>
<SecondName>Doe</SecondName>
<Sex>M</Sex>
<Address>Earth</Address>
<Mobile>1234567890</Mobile>
</Personal>
<Education>
<Secondary>School Name</Secondary>
splitlist(L, [], L, 0).
splitlist([H|T], [H|A], B, N) :- Nminus1 is N-1, splitlist(T, A, B, Nminus1).
halfhalf(L, A, B) :- length(L, Len), Half is Len//2, splitlist(L, A, B, Half).
merge(A, [], A).
merge([], B, B).
merge([Ha|Ta], [Hb|Tb], R) :- Ha =< Hb, merge(Ta, [Hb|Tb], M), R = [Ha|M].
merge([Ha|Ta], [Hb|Tb], R) :- Ha > Hb, merge(Tb, [Ha|Ta], M), R = [Hb|M].
quicksort([], []).
quicksort([HEAD | TAIL], SORTED) :- partition(HEAD, TAIL, LEFT, RIGHT),
quicksort(LEFT, SORTEDL),
quicksort(RIGHT, SORTEDR),
append(SORTEDL, [HEAD | SORTEDR], SORTED).
partition(PIVOT, [], [], []).
partition(PIVOT, [HEAD | TAIL], [HEAD | LEFT], RIGHT) :- HEAD @=< PIVOT,
partition(PIVOT, TAIL, LEFT, RIGHT).
partition(PIVOT, [HEAD | TAIL], LEFT, [HEAD | RIGHT]) :- HEAD @> PIVOT,
insert_sort(List,Sorted):-i_sort(List,[],Sorted).
i_sort([],Acc,Acc).
i_sort([H|T],Acc,Sorted):-insert(H,Acc,NAcc),i_sort(T,NAcc,Sorted).
insert(X,[Y|T],[Y|NT]):-X>Y,insert(X,T,NT).
insert(X,[Y|T],[X,Y|T]):-X=<Y.
insert(X,[],[X]).
% insert_sort([0,2,4,1],X).
bubble_sort(List,Sorted):-b_sort(List,[],Sorted).
b_sort([],Acc,Acc).
b_sort([H|T],Acc,Sorted):-bubble(H,T,NT,Max),b_sort(NT,[Max|Acc],Sorted).
bubble(X,[],[],X).
bubble(X,[Y|T],[Y|NT],Max):-X>Y,bubble(X,T,NT,Max).
bubble(X,[Y|T],[X|NT],Max):-X=<Y,bubble(Y,T,NT,Max).
% bubble_sort([1,2,0,4,55,6],Sorted).
move(1,X,Y,_) :-
write('Move top disk from '),
write(X),
write(' to '),
write(Y),
nl.
move(N,X,Y,Z) :-
N>1,
M is N-1,
move(M,X,Z,Y),
fib(0, 0).
fib(X, Y):- X > 0, fib(X, Y, _).
fib(1, 1, 0).
fib(X, Y1, Y2) :- X > 1,
X1 is X - 1,
fib(X1, Y2, Y3),
Y1 is Y2 + Y3.
% Nth Fibonacci number
gcd(0, X, X):- X > 0, !.
gcd(X, Y, Z):- X >= Y, X1 is X-Y, gcd(X1,Y,Z).
gcd(X, Y, Z):- X < Y, X1 is Y-X, gcd(X1,X,Z).
% GCD
fact(0,1).
fact(N,F):- N>0, N1 is N-1,
fact(N1,F1), F is N*F1.
% Factorial