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 BinaryTree: | |
def __init__(self, root): | |
self.root = Node(root) | |
def preorder(self, root): | |
if root is None: | |
return | |
print(root.data, end=" ,") | |
self.preorder(root.left) | |
self.preorder(root.right) |
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
Bądź miły. Nie bądź arogancki. Prowadź ciekawą rozmowę, a nie przesłuchuj adwersarza. Proszę nie szydzić, także z reszty społeczności. | |
Posty powinny być coraz bardziej przemyślane i merytoryczne, a nie coraz mniej, w miarę jak temat staje się coraz bardziej szczegółowy. | |
Jeśli się z kimś nie zgadzasz, odpowiedz na argument, zamiast rzucać wyzwiskami, czy argumentami ad personam. "To jest idiotyczne; 1 + 1 to 2, a nie 3" można skrócić do "1 + 1 to 2, a nie 3". | |
Odpowiadaj na najmocniejszą wiarygodną interpretację tego, co ktoś mówi, a nie na słabszą, którą łatwiej skrytykować. Zakładaj dobrą wiarę | |
Unikaj flamu, niezwiązanych z tematem kontrowersji i ogólnych wątków |
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
# python: | |
def find_unpaired(xs): | |
"""find unpaired element with array of 2n + 1 elements""" | |
for i in range(1, len(xs)): | |
xs[i] ^= xs[i - 1] | |
print(xs[len(xs) - 1]) | |
# pseudocode: | |
fun findUnpaired(aList): | |
#N - length of input list | |
for i from 1 to 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
using System; | |
using System.Collections.Generic; | |
using System.Linq; | |
using System.Text; | |
using System.Threading.Tasks; | |
namespace ConsoleApp5 | |
{ | |
class Program | |
{ |
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
/* package whatever; // don't place package name! */ | |
import java.util.*; | |
import java.lang.*; | |
import java.io.*; | |
interface List { | |
boolean is_empty(); | |
int head(); | |
List tail(); |
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 Nil: | |
def is_empty(self): | |
return True | |
def head(self): | |
raise Exception("Exception: Empty list") | |
def tail(self): | |
raise Exception("Exception: Empty list") |
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 { |
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
// 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
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)) |
NewerOlder