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
| import haxe.ds.Option; | |
| class ExtendedOption { | |
| public static function getOrElse<T>(opt:Option<T>, defValue:T) { | |
| return switch(opt) { | |
| case Some(v): v; | |
| case None: defValue; | |
| } | |
| } | |
| } |
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
| object Catalan { | |
| def myCatalan(m:Int, n:Int, accum:Int):Int = { | |
| (m>0 && n>0, m==n) match { | |
| case (false, _) => accum | |
| case (_, true) => myCatalan(m, n-1, accum + 1) | |
| case (_, false) => myCatalan(m-1, n, accum + 1) | |
| } | |
| } | |
| } |
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
| defmodule Crypt do | |
| def encrypt(numbers) do | |
| min = Enum.min(numbers) | |
| (product(numbers, 1)/min)*(min + 1) | |
| end | |
| def product([h|t],res), do: product(t, res * h) | |
| def product([],res), do: res | |
| end | |
| IO.puts to_string(Crypt.encrypt([1,2,3])) |
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 Lylic(num:Int) { | |
| val currentPlural = plural(num) | |
| val nextPlural = plural(num-1) | |
| def plural(x:Int) = { | |
| x match { | |
| case 0 => "No more bottles" | |
| case 1 => "1 bottle" | |
| case _ => x + " bottles" | |
| } |
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
| #!/usr/bin/python | |
| def plural(num): | |
| if num == 0: | |
| return "No more bottles" | |
| elif num == 1: | |
| return "1 bottle" | |
| else: | |
| return str(num) + " bottles" | |
| def overLylic(num): |