Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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
| //Golang optimizatoin tricks | |
| // copyleft by lion137 | |
| // https://lion137.blogspot.co.uk/2017/02/bit-hacks-in-go.html | |
| func average(x uint32, y uint32) uint32 { | |
| return (x & y) + ((x ^ y) >> 1) | |
| } | |
| func iexp(x uint32, n uint32) uint32 { | |
| if (n == 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
| public BigInteger evaluateParseTreeBigInt(BinaryTree tree){ | |
| BinaryTree<T> leftT = tree.left; | |
| BinaryTree<T> righT = tree.right; | |
| boolean p = (leftT != null) && (righT != null); | |
| if (p){ | |
| //cos tam, return jakis bigint | |
| } | |
| else return //jakis biginteger | |
| }//IntelliJ IDEA sie pluje, ze brakuje return statemnt, sugeruje po else, ale to rozwala cala logike |
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
| def afs(g, s): | |
| bag = data_structure() | |
| bag.add(s) | |
| while bag is not empty: | |
| tile = bag.pop() | |
| if tile is not marked: | |
| mark(tile) | |
| for x in adj_list(tile): | |
| bag.add(x) |
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
| public static void cond_changer(long time_pause){ | |
| long start = System.currentTimeMillis(); | |
| System.out.println("start in cond_change"); | |
| while (System.currentTimeMillis() - start < time_pause * 1000) { | |
| } | |
| Main.condition = () -> true; | |
| } | |
| public static Callable<Boolean> cond_change() { |
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
| # Infinite primes generator and quantum article check: | |
| # https://www.quantamagazine.org/mathematicians-discover-prime-conspiracy-20160313/ | |
| from tests import miller_rabin | |
| def primes_generator(): | |
| i = 2 | |
| while True: | |
| if miller_rabin(i): | |
| yield i |
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
| def find_median(xs): | |
| ys = sorted(xs) | |
| if not len(xs) % 2 == 0: | |
| return ys[len(ys) // 2] | |
| else: | |
| return (ys[(len(ys) // 2)] + ys[(len(ys) // 2) - 1]) / 2 | |
| def make_sum(xs, a): | |
| return sum(map(lambda x: abs(x - a), xs)) |
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 Newton Method (Simple Iteration) | |
| // 2017, Copyleft lion137 | |
| // Znajduje pierwiastek wielomianu Metodą Newtona: | |
| // https://en.wikipedia.org/wiki/Newton%27s_method czyli: | |
| // x0 = wartość poczatkowa (zgadywana - nie powinna za daleko odbiegać od pierwiastka - tu jest problem tej metody, | |
| // ale wszystkie mają podobne problemy, patrz Wikipedia: https://en.wikipedia.org/wiki/Root-finding_algorithm , chociaz | |
| // 100 dalej nie jest za daleko od pierwiastka -0.169... patrz przykład w main) | |
| // i iteracja: | |
| // x1 = x0 - f(x0) / f'(x0) | |
| // x0 = x1 -> podstawienie |
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
| #include <iostream> | |
| #include <cmath> | |
| #include <vector> | |
| /* More info and explanation here: https://lion137.blogspot.com/2019/01/kleisli-category-by-example.html */ | |
| template<class A> class optional { | |
| bool _isValid; | |
| A _value; | |
| public: | |
| optional(): _isValid(false) {} |
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
| sealed trait MyList[+A] | |
| case object Nil extends MyList[Nothing] | |
| case class Cons[+A] (head: A, tail: MyList[A]) extends MyList[A] | |
| object HelloWorld { |
OlderNewer