Skip to content

Instantly share code, notes, and snippets.

@AHaliq
AHaliq / kaprekar.hs
Created April 29, 2022 15:37
Kaprekar's constant
import Data.List
toDigits x
| x > 9 = x `mod` 10 : toDigits (x `div` 10)
| otherwise = [x]
sumFold xs = foldl (\a x -> a*10 + x) 0 xs
kaprekar :: Int -> Int -> Int
kaprekar x n = let
@AHaliq
AHaliq / config.log
Created August 24, 2021 02:33
WASI Output
This file contains any messages produced by compilers while
running configure, to aid debugging if configure makes a mistake.
It was created by GNU MP configure 6.2.1, which was
generated by GNU Autoconf 2.69. Invocation command line was
$ ./configure --prefix /Users/haliq/opt-wasm CC=/opt/wasi-sdk-12.0/bin/clang --host=none --enable-cxx CXX=/opt/wasi-sdk-12.0/bin/clang++ --with-sysroot=/opt/wasi-sysroot
## --------- ##
## Platform. ##
@AHaliq
AHaliq / euclid.hs
Created August 13, 2021 10:14
Haskell Euclid Algorithm
euclid :: Integer -> Integer -> Integer
euclid a b = case aux a b 0 of
0 -> b
r -> euclid b r
where
aux a b q = if b >= a then b - a else aux (a-b) b (q+1)
-- get gcd
main = do
a <- readLn :: IO Integer
@AHaliq
AHaliq / actual.cpp
Created April 30, 2021 12:15
error: too many arguments to function
/******************************************************************************
Online C++ Compiler.
Code, Compile, Run and Debug C++ program online.
Write your code in this editor and press "Run" button to compile and execute it.
*******************************************************************************/
#include <iostream>
#include <string>
@AHaliq
AHaliq / main.ml
Created March 31, 2021 10:56
export ocaml function to call from js
let global_nctx = ref Kernel.Context.empty
let global_ectx = ref Kernel.Context.empty
let js_run_repl str =
match String.(compare str "quit") with
| 0 -> "bye"
| _ ->
match String.(compare str "reset") with
| 0 ->
global_nctx := Kernel.Context.empty;
@AHaliq
AHaliq / comp
Created January 7, 2021 12:20
Compound Stake
rate[x_] := rated[x*365]
rated[x_] :=
If[x < 7, 1.5,
If[x < 30.4167, 3, If[x < 365/2, 5, If[x < 365, 17, 30]]]]
f[ip_, r_, p_, t_, n_] :=
If[t <= 0, ip,
If[t < p, ip + ip*r*t - rate[t],
f[ip + (ip * r * p) - rate[p] - rate[0]*n, r, p, (t - p), n + 1]]]
g[ip_, r_, t_] := ip + ip*r*t - rate[t]
init := 10000
// NOTE read Responses.java first itll make more sense
public class CreateInputCommand implements ResponseFunc {
private String front = "";
private String back = "";
// handle types??
@Override
public boolean funcCall(String i, State s) {
if (s.state == StateEnum.CREATE_STATE_FRONT) {
front = i;
// my motivation to use enum is so you dont need to create new objects everytime a command is executed
// instead you simply call a static method. and to iterate through a list of static methods we use enums.
// So this is a typical enum u encounter all the time
enum MyEnum {
A, B, C;
}
// However enums are capable of having properties and methods!
// if u define a method in an enum all enums will have it
// e.g.
@AHaliq
AHaliq / Response.java
Created October 9, 2019 08:36
My dukes responses
package com.core;
import com.core.savedata.SaveFile;
import com.util.datetime.DateTime;
import com.util.datetime.DateTimeParse;
import java.util.stream.IntStream;
import com.util.Printer;
import com.tasks.Deadline;
import com.tasks.DoableTask;
package com.core;
public enum Response {
BYE("(?i)^b(ye)?\\s*", (i, s) -> {
Printer.printString("Bye. Hope to see you again soon!");
s.toExit = true;
s.lastError = false;
return true;
}),
RESPONDER_NAME("regex", (commandInput, programState) -> {