This file contains hidden or 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
/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"), |
This file contains hidden or 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
// 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; | |
} |
This file contains hidden or 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
// 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); |
This file contains hidden or 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
// 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; |
This file contains hidden or 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
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()); |
This file contains hidden or 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
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"); |
This file contains hidden or 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
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); | |
} |
This file contains hidden or 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
// 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; |
This file contains hidden or 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
% 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? |