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.LongFunction; | |
// fibR, fibRM and fibT are the Java equivalents of | |
// https://youtu.be/oBt53YbR9Kk (10.12.2020) | |
try { | |
assert false; | |
} catch (AssertionError e) { | |
System.out.println("Cool, assertions are enabled!"); | |
} |
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
// Zur Erläuterung mein Video auf YouTube: https://youtu.be/rSuE2vIUzzk | |
interface Stackable<T> { | |
boolean isEmpty(); | |
default T top() { throw new UnsupportedOperationException(); } | |
default Stackable<T> pop() { throw new UnsupportedOperationException(); } | |
Stackable<T> push(T element); | |
} | |
class StackWithElements<T> implements Stackable<T> { |
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
// Zur Erläuterung mein Video auf YouTube: https://youtu.be/RyrmcXY8oEw | |
interface Stackable { | |
boolean isEmpty(); | |
default int top() { throw new UnsupportedOperationException(); } | |
default Stackable pop() { throw new UnsupportedOperationException(); } | |
Stackable push(int element); | |
} | |
class StackWithElements implements Stackable { |
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
class Coordinate { | |
final int x; | |
final int y; | |
Coordinate(int x, int y) { | |
this.x = x; | |
this.y = y; | |
} | |
float distance(Coordinate other) { | |
return (float)Math.sqrt((other.x - x) * (other.x - x) + (other.y - y) * (other.y - y)); | |
} |
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.Scanner; | |
public class Calculator { | |
public static void main(String... args) { | |
Scanner input = new Scanner(System.in); | |
System.out.print("Input number: "); | |
int n = input.nextInt(); | |
System.out.println("The square of " + n + " is " + square(n)); | |
} |
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
// Den Code bespreche ich ausführlich im Podcast "Herzbergs Hörsaal" in der Episode | |
// https://anchor.fm/dominikusherzberg/episodes/PiS-Das-Nim-Spiel-in-Java-programmiert-edks2t | |
// | |
import java.util.ArrayList; | |
import java.util.Arrays; | |
import java.util.Random; | |
import java.util.stream.IntStream; | |
class Move { | |
final int row, number; |
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
# Code aus meinem YouTube-Video https://youtu.be/CjldSexfOuU | |
import random, copy | |
class Board: | |
def __init__(self): | |
self.board = [0,0,0,0,0,0,0,0,0] | |
self.moves = [] | |
self.turn = +1 | |
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
/* | |
In dieser Aufgabe geht es darum, einen als String gegebenen UPN-Ausdruck in | |
einen Stapel von Ergebniswerten zu wandeln. Ein Beispiel: | |
jshell> upn2results.apply("2 3 + 5 4 *", new Stack<Integer>()); | |
$43 ==> [5, 20] | |
Dieser UPN-Rechner arbeitet ausschließlich mit Ganzzahlen. | |
Sie werden durch die Aufgabe geführt. Halten Sie sich bitte an alle Angaben. |
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
/* Konkatenative Programmierung mit Lambda-Ausdrücken (Java) | |
Dominikus Herzberg, @denkspuren, 2018-03-09 | |
Ich liebe das konkatenative Programmierparadigma -- das ist ein Grund, | |
warum Consize entstanden ist (https://github.com/denkspuren/consize). | |
Hier ist die konkatenative Berechnung der Fakultät nachgebaut unter | |
Verwendung von Lambda-Ausdrücken. Ich verwende einen Stapel, der | |
von Funktion zu Funktion weitergereicht wird. Damit es funktional | |
"sauber" zugeht, simuliere ich Immutabilität mithilfe von clone(). |
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.*; | |
import java.util.function.*; | |
import java.util.stream.*; | |
// This is a design proposal, see https://gist.github.com/denkspuren/c91b4dd9ffcc4c6040ce271e3fd7caa9 | |
class Cell { | |
final int index; | |
final String value; |