Skip to content

Instantly share code, notes, and snippets.

View denkspuren's full-sized avatar
💭
Getting thinking done!

Dominikus Herzberg denkspuren

💭
Getting thinking done!
View GitHub Profile
@denkspuren
denkspuren / tm11000.java
Created April 25, 2017 05:51
Die Turing-Maschine in Java 9 (JShell) mit Beispielen
/open turing.java
Transition[] ts = new Transition[] {
new Transition("s1",'1','0',Move.RIGHT,"s2"),
new Transition("s1",'0','0',Move.NONE,"HALT"),
new Transition("s2",'1','1',Move.RIGHT,"s2"),
new Transition("s2",'0','0',Move.RIGHT,"s3"),
new Transition("s3",'1','1',Move.RIGHT,"s3"),
new Transition("s3",'0','1',Move.LEFT,"s4"),
new Transition("s4",'1','1',Move.LEFT,"s4"),
@denkspuren
denkspuren / abc.java
Last active March 29, 2021 16:19
Actually, a + b > c is a tricky expression in #Java. Here are two solutions without type casting.
// Actually, a + b > c is a tricky expression in Java. 10 + 3 > 4 is true, but
// if you choose big numbers for a and b it might turn out to be false.
// Assumed you are not allowed to use casting as done in `exprTruth`.
// Here are two solutions to always provide a correct answer.
// I used the JShell for a brute force proof of correctness.
boolean exprTruth(byte a, byte b, byte c) {
return (int)a + (int)b > (int)c;
}
@denkspuren
denkspuren / BSort.java
Created December 9, 2016 15:08
Bubblesort the arguments given via the command line
// Usage:
// > java BSort Petra Bob Peter Adam Zap John Adam
// Adam Adam Bob John Peter Petra Zap
class BSort {
public static void main(String[] args) {
bubbleSortSmart(args);
for(String arg : args) System.out.print(arg + " ");
System.out.println();
System.exit(0);
@denkspuren
denkspuren / turing.java
Created December 2, 2016 16:05
Implementation of Turing Machine (use JShell to run)
// https://docs.oracle.com/javase/8/docs/api/java/util/Stack.html
enum Head { LEFT, RIGHT, NONE }
class Transition { // data container only
final String from, to;
final Character read, write;
final Head move;
Transition(String from, Character read, Character write, Head move, String to) {
this.from = from;
@denkspuren
denkspuren / concat.java
Created November 24, 2016 08:35
Proof of concept: Kernel for concatenative programming in Java
import java.util.function.*;
class Stakk { // Stack is taken by standard library
static Function<Stakk,Stakk> _mrot = (s -> s.rot().rot());
static Function<Stakk,Stakk> _over = (s -> s.swap().dup().apply(_mrot));
static Function<Stakk,Stakk> _2dup = (s -> s.apply(_over).apply(_over));
static Function<Stakk,Stakk> _call = (s -> s.dup().dip().drop());
static Function<Stakk,Stakk> _2dip = (s -> s.swap().quote(_s -> _s.dip()).dip());
@denkspuren
denkspuren / WebApp.jshell
Last active July 25, 2016 11:47
Shinya's Demo on https://youtu.be/op6zZDypPg8 executed with jshell (no jfxshell required)
import javafx.application.Application;
import javafx.stage.Stage;
import javafx.scene.Scene;
import javafx.scene.web.WebView;
public class WebApp extends Application {
@Override
public void start(Stage stage) throws Exception {
WebView wv = new WebView();
wv.getEngine().load("http://www.thm.de");
@denkspuren
denkspuren / WebApp.java
Last active July 24, 2016 22:08
Shinya's Demo on https://youtu.be/op6zZDypPg8 in pure Java 8/9
import javafx.application.Application;
import javafx.stage.Stage;
import javafx.scene.Scene;
import javafx.scene.web.WebView;
public class WebApp extends Application {
public static void main(String[] args) {
launch(args);
}
@denkspuren
denkspuren / ISS.pde
Created November 3, 2015 14:41
Track the International Space Station (ISS) with Processing
// http://open-notify.org/Open-Notify-API/ISS-Location-Now/
// https://developers.google.com/maps/documentation/static-maps/intro
// https://developers.google.com/maps/documentation/static-maps/
JSONObject json;
double latitude, longitude;
int zoomVal = 3;
PImage img;
@denkspuren
denkspuren / maybe-monad.txt
Created September 8, 2015 11:58
Maybe monad in Consize
% Implementation of the Maybe Monad in Consize
% The implementation refers to
% https://en.wikipedia.org/wiki/Monad_(functional_programming)#The_Maybe_monad
% The datatype Maybe is informally defined as
% t Maybe = [ t Just ] | Nothing
: bind ( Maybe quot -- Maybe ) % ( [a] ma ([a] a -- [a'] mb) [a'] mb )
over \ Nothing equal?