Skip to content

Instantly share code, notes, and snippets.

Implement a function, routine or method (and the support code you might need) that simulates 6 tosses of 3 coins
each and outputs a string according to the Value Rules below.
Value Rules
a) Tails has a value of 2, and heads a value of 3.
b) Getthetotalvalueofthethreecoinspertoss.
c) Compose a string with these values in reverse order, from toss 6 to 1. Example output: “767777”
val r = scala.util.Random
object JsonParsing extends App {
import org.json4s._
import org.json4s.jackson.JsonMethods._
import org.json4s.JsonDSL._
implicit val formats = DefaultFormats
println(parse( """ { "numbers" : [1, 2, 3, 4] } """))
println(parse( """{"name":"Toy","price":35.35}""", useBigDecimalForDouble = true))
@mcalavera81
mcalavera81 / CompletableFutureTest.java
Created October 22, 2015 18:14
CompletableFuture with Timeouts
package test;
import java.time.Duration;
import java.time.Instant;
import java.time.temporal.ChronoUnit;
import java.util.Random;
import java.util.concurrent.*;
import java.util.function.Function;
@mcalavera81
mcalavera81 / MessingAround.java
Created October 28, 2015 20:40
Strategy Pattern with Lambda expressions.
package com.example;
import java.io.IOException;
import java.util.Arrays;
import java.util.List;
import java.util.function.Predicate;
public class MessingAround {
@mcalavera81
mcalavera81 / MessingAround.java
Last active October 29, 2015 14:29
Fluent API and Loan Pattern/Execute around method Pattern
package com.example;
import java.io.IOException;
import java.util.function.Function;
public class MessingAround {
public static void main(String[] args) throws IOException, InterruptedException {
@mcalavera81
mcalavera81 / MessingAround.java
Created October 30, 2015 14:22
Lazy evaluation
package com.example;
import java.io.IOException;
import java.time.Duration;
import java.time.Instant;
import java.util.function.Supplier;
public class MessingAround {
@mcalavera81
mcalavera81 / MessingAround.java
Created October 30, 2015 15:44
Infinite stream of prime numbers
package com.example;
import java.io.IOException;
import java.util.List;
import java.util.stream.Collectors;
import java.util.stream.IntStream;
import java.util.stream.Stream;
public class MessingAround {
sleeping=1
if [ "$1" != "" ]; then
sleeping=$1
fi
echo " (___)"
echo " (o o)____/"
echo " @@ \\"
echo " \ ____, /"
echo " // //"
Arrays.stream(e.getStackTrace()).limit(5L).map(stackEl -> " " + stackEl).collect(Collectors.joining("\n")));
trait Combinable[T]{
def combine(a:T,b:T):T
}
object Combinable{
def apply[T](implicit c:Combinable[T]) = c
trait CombinableOps[T]{
def self:T
def combinable: Combinable[T]
def combine(other: T) = combinable.combine(self,other)