Skip to content

Instantly share code, notes, and snippets.

package com.foo;
import java.io.IOException;
import java.util.HashMap;
import java.util.Random;
import java.util.concurrent.ThreadLocalRandom;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.function.Supplier;
import java.util.stream.Stream;
{-# LANGUAGE BangPatterns #-}
import System.Environment
{-
Se generan y van refinando los saltos según se añaden números de la suerte
1: +2
3: +2+4
7: +2+4+2+4+2+6+4+2+4+2+4+6
9: +2+4+2+4+2+6+4+6+2+4+6+2+4+2+4+8+4+2+4+2+4+6+2+6+4+2+6+4+2+4+2+10
{-# LANGUAGE BangPatterns, LambdaCase, ViewPatterns #-}
import System.Environment
import Debug.Trace
import Data.Sequence (Seq, viewl, ViewL(..),(><), (<|))
import qualified Data.Sequence as Seq
-- una versión poco eficiente
numerosDeLaSuerte1 :: [Int]
numerosDeLaSuerte1 = 1: r [3,5..] 2
where r (x:xs) n = x: r (q (n + 1) xs) (n + 1)
try(FileInputStream is = new FileInputStream("bla/bla/src/main/java/FooBarBad.java")) {
CompilationUnit cu = JavaParser.parse(is);
(new VoidVisitorAdapter() {
@Override
public void visit(final FieldDeclaration f, Object arg) {
super.visit(f, arg);
(new VoidVisitorAdapter() {
@Override
public void visit(VariableDeclaratorId v, Object arg) {
super.visit(v, arg);
{-# LANGUAGE GADTs #-}
{-# LANGUAGE LambdaCase #-}
{-# LANGUAGE RankNTypes #-}
import Data.List (isPrefixOf)
import Data.Maybe (mapMaybe)
-- I want manage non predefined items that can interact with any item kind
-- (really simulate an ecosystem and be able to add behaviors and animals)
class Show a =>Item a where
@josejuan
josejuan / life.hs
Last active November 9, 2016 16:31
{-# LANGUAGE StandaloneDeriving, Rank2Types, ExistentialQuantification #-}
import Control.Monad
import Control.Applicative
import Data.Maybe
-- ============================================================================
-- somebody define the life on the world (but not specific species)
data Kind = forall a . (Show a, Life a) =>Kind a
deriving instance Show Kind
// invariant: the equality used to discard items at set creation
// is violated at certain point using usual language
// constructs (some function based on this "set invariant"
// will be likely broken)
// scala: set with two equals items
val x = new Point(3, 4)
val y = new Point(2, 3)
val z = new Point(2, 3)
val s = Set(x, y, z)
import System.Environment
import qualified Data.Set as Set
{-
For each x input element
Split current set on `x` O(log n)
Count right side O(1)
Add x to set O(log n)
-}
{-# LANGUAGE DeriveGeneric #-}
{-# LANGUAGE LambdaCase #-}
import GHC.Generics
import Prelude hiding (readFile)
import Data.Csv
import Data.ByteString.Lazy (ByteString, readFile)
import Data.Vector (Vector)
import qualified Data.Vector as V
import Data.List (inits, sortBy, genericLength, sort, group)
import Data.Function (on)
{-# LANGUAGE TemplateHaskell, DeriveGeneric, RankNTypes, FlexibleContexts #-}
module Main where
import Data.Typeable
import GHC.Generics
import Data.Binary
import System.Environment (getArgs)
import Control.Distributed.Process hiding (newChan)
import Control.Distributed.Process.Closure
import Control.Distributed.Process.Node