Skip to content

Instantly share code, notes, and snippets.

@icsaba
icsaba / nQueens.py
Last active September 4, 2017 20:24
n-queens problem in python
import random
import sys
import itertools
queens, n = {}, 8
def get_rows(x):
return (q for q in queens.keys() if q and q[0] == x)
@icsaba
icsaba / dijkstra.icl
Last active April 14, 2019 09:58
Funkcional programming 2018 - Clean
module dijsktra
import StdEnv
// http://lambda.inf.elte.hu/Dijkstra.xml
::Vertex :== Int
::Weight :== Int
::Edge :== (Vertex, Vertex, Weight)
@icsaba
icsaba / Homework1.hs
Last active June 11, 2019 17:53
homeworks
module Homework1 where
data Nat = Zero | Suc Nat
deriving (Show, Eq)
addNat :: Nat -> Nat -> Nat
addNat Zero Zero = Zero
addNat a Zero = a
addNat Zero b = b
addNat (Suc a) (Suc b) = addNat (Suc(Suc a)) b
@icsaba
icsaba / Functor.scala
Last active April 14, 2019 09:56
Examples for functional programming in Scala to demonstrate haskell codes that's been learnt on the Unversity.
import scalaz.Functor
object FunctorExample extends App{
implicit val optionFunctor: Functor[Option] = new Functor[Option] {
override def map[A, B](fa: Option[A])(f: A => B): Option[B] = fa match {
case None => None
case _ => Some(f (fa.get))
}
}
@icsaba
icsaba / Life.java
Created June 18, 2019 17:31
EAK 2 Exam, Game of Life
package obsxvv;
import java.util.concurrent.*;
/** Game of Life. */
public class Life {
/** Invariant: <code>
from != null & to != null &
from.length == to.length != 0 &
@icsaba
icsaba / NQueens.java
Last active June 30, 2019 09:25
EAK 2 exam, parallel NQueens
package obsxvv;
import java.util.*;
import java.util.concurrent.*;
/** An immutable board of non-attacking queens. */
class Board {
/** An immutable linked list of int values. */
protected static class Node {
protected final int value;
@icsaba
icsaba / firstDay.js
Last active December 8, 2019 18:59
advent of code 2019
const fs = require('fs');
const buffer = fs.readFileSync('input');
const file = buffer.toString().split('\n');
function calcConsumption(amount) {
const tmp = Math.floor(+amount / 3) - 2;
return (tmp > 0) ? tmp + calcConsumption(tmp) : 0;
}
@icsaba
icsaba / thunkAction.js
Last active October 21, 2020 18:01
an actionCreator method for redux-thunk that helps you to reduce boilerplate code and creates async actions
/** Usage
*
* file: someAction.js
*
* export const SOMEVAR = 'SOMEVAR';
*
* export function fetchSomething(callbackOnDone, ...args) {
* return actionCreator({
* actionName: SOMEVAR,
* getResult(data) { return data.someProperty },
@icsaba
icsaba / store.js
Last active May 19, 2022 06:20
code snippet for my medium article
context.init({
propName: someValue,
propName2: { nestedData: [] }
});
@icsaba
icsaba / my-lit-component.js
Created May 19, 2022 06:21
code snippet for my medium article
class MyLitComponent extends LitElement {
static get properties() {
return {
somepropFromContext: {
type: Number,
fromContext: true
},
renamedProp: {
type: String,