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
function checkImage(image1,suffix) { | |
var imageSrc = image1+"/favicon/favicon.ico"; | |
var img = new Image(); | |
img.onload = function(){window.location = image1+suffix}; | |
//img.onerror = bad; | |
img.src = imageSrc; | |
} | |
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
function int:factorial(int:t) = | |
if t = 0 then 1 else t * factorial(t-1) endif; | |
function int: factorial_inverse(int:n, int:factorial) = | |
if factorial == factorial(n) then n else factorial_inverse(n+1,factorial) endif; | |
function int:factorial_inverse(int:n) = | |
factorial_inverse(0,n); | |
int:a = factorial_inverse(720); |
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
function int: hamming_distance(array[int] of int: arr1, array[int] of int: arr2) = | |
sum([if arr1[i] != arr2[i] then 1 else 0 endif | i in index_set(arr1)]); | |
% Example usage | |
array[int] of int: arr1 = [107, 97, 114, 111, 108, 105, 110]; | |
array[int] of int: arr2 = [107, 97, 116, 104, 114, 105, 110]; | |
int: distance = hamming_distance(arr1, arr2); | |
output ["The Hamming distance is ", show(distance)]; |
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
% define a Rectangle "class" | |
var int: Rectangle(var int: width, var int: height) = | |
let { | |
var int: this; | |
constraint Type(this) = Rectangle; %define the "type" of the instance | |
%define some "instance methods" | |
constraint area(this) = width*height; | |
constraint perimeter(this) = (width+height)*2; | |
constraint width(this) = width; | |
constraint height(this) = height; |
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
:- initialization(main). | |
main :- | |
three_valued_logic(((true,false);unknown),Result), | |
writeln(Result). | |
three_valued_logic(true,true). | |
three_valued_logic(false,false). | |
three_valued_logic(unknown,unknown). | |
three_valued_logic(not(A),false) :- | |
three_valued_logic(A,true). |
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
function nearly_anagrams(str1,str2,max_diff){ | |
//max_diff is the maximum difference in the number of characters. | |
//Example usage: | |
//console.log(JSON.stringify(nearly_anagrams("hello","aahelloaaahello",1))); | |
let str1_chars = {}; //number of chars in str1 | |
let char_diff = {}; //number of chars in the current substring | |
let sum_of_diff = 0; //sum of differences between number of each character | |
let results = []; | |
for(const i of str1){ |
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
-module(helloworld). | |
-import(lists,[append/2]). | |
-export([start/0]). | |
replace_if_match(X) -> | |
case X of | |
[A, "equals", B | Tail ] -> | |
[[A,"==",B],replace_if_match(Tail)]; | |
[A, "is", B | Tail ] -> | |
[[A,"==",B],replace_if_match(Tail)]; |
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
const replaceOnce = require('replace-once'); | |
var str = 'I have a cat, a cathy, and a catch.'; | |
var find = ['cat', 'cathy', 'catch']; | |
var replace = ['catch', 'catch', 'cathy']; | |
console.log(replaceOnce(str, find, replace, 'gi')); | |
//=> 'I have a catch, a catchhy, and a catchch.' |
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
//I wish there were a better way to do this! | |
#define func(type,name,param1,param2,body) type name(type param1,type param2) {body} | |
#define generic(name,param1,param2,body) func(float,name,param1,param2,body) func(vec2,name,param1,param2,body) func(vec3,name,param1,param2,body) func(vec4,name,param1,param2,body) | |
//define two "generic" functions using this macro | |
generic(add,a,b, | |
return a + b; | |
) | |
generic(sub,a,b, |
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
// ==UserScript== | |
// @name Search redirector | |
// @namespace http://tampermonkey.net/ | |
// @version 0.1 | |
// @description try to take over the world! | |
// @author Anderson Green | |
// @match *://*/* | |
// @grant none | |
// ==/UserScript== |
NewerOlder