#!/bin/sh
# invoke calc and shit out only the thing, $1 or date, no excess newline
path="$(dirname "$(realpath "$0")")"
calc='calc -dp --'
if [ -z "$1" ]; then
date="$(date +"%Y%m%d")"
else
date="$(date +"$1")"
fi
x=$($calc "1/(($date/1e3-floor($date/1e3))*1e3)")
y=$($calc "p=floor($date/1e2);1/((p/1e2-floor(p/1e2))*1e2)")
z=$($calc "floor($date/1e4)")
date_reciprocal="$($calc "1/$date")"
fraction=$($calc "x=$x;1/(log(exp(1)^(pi()*x))/log(10)*x+sin(pi()*x)*x)")
exponent=$($calc "x=$x;y=$y;(pi()*1/(x+x*abs(cos(x)^-y)))^exp(1)")
final=$($calc "f=$fraction;e=$exponent;d=$date_reciprocal;p=1e30;v=(2^(exp(1)*d))/d*(floor((f+d)^ln(e))&floor((f+d)^ln(e)))%p;if(v<(p/10))v+=(p/10);print(floor(v))")
echo -n "$final"
echo "$final" >> "$path"/log
