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 com.example.coinchanger | |
object changer { | |
def apply(coins: List[Int])(amount: Int): List[Int] = { | |
coins.foldLeft((amount, Nil : List[Int]))((m, coin) => { | |
val (amount, result) = m | |
coin match { | |
case 0 => (amount, result ::: List(0)) | |
case _ => (amount % coin, result ::: List(amount / coin)) | |
} |
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
<?xml version="1.0" encoding="utf-8" ?> | |
<configuration> | |
<runtime> | |
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1"> | |
<dependentAssembly> | |
<assemblyIdentity name="FSharp.Core" | |
publicKeyToken="b03f5f7f11d50a3a" | |
culture="neutral"/> | |
<bindingRedirect oldVersion="4.3.1.0" | |
newVersion="4.4.0.0"/> |
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 static System.Console; | |
namespace SimpleLocalFunctionExample | |
{ | |
class Program | |
{ | |
private struct locals | |
{ | |
public int x; | |
} |
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 com.example.fibonacci | |
import scala.annotation.tailrec | |
object fibonacci { | |
def apply(x: Int): Int = { | |
@tailrec | |
def go(x: Int, y: Int, idx: Int): Int = idx match { | |
case 0 => y | |
case _ => go(y, x+y, idx-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
package com.examples.factorial | |
import scala.annotation.tailrec | |
object factorial { | |
/** | |
def apply(x: Int): Int = x match { | |
case 0 => 1 | |
case 1 => 1 | |
case x => x * factorial(x-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
using System; | |
using System.Collections.Generic; | |
// Visual Studio 15 Preview 3 | |
// Conditional compilation symbols: __DEMO__ ,__DEMO_EXPERIMENTAL__ | |
namespace PatternExamples | |
{ | |
class Program | |
{ | |
static void Main(string[] args) |
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; | |
namespace TupleExample | |
{ | |
class Program | |
{ | |
static void Main(string[] args) | |
{ | |
Console.WriteLine($"1! = {Factorial(1)}"); | |
Console.WriteLine($"5! = {Factorial(5)}"); |
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; | |
// Visual Studio 15 Preview 2 | |
// Conditional compilation symbols: __DEMO__ ,__DEMO_EXPERIMENTAL__ | |
namespace TailCallExamples | |
{ | |
class Program | |
{ | |
static void Main(string[] args) | |
{ |
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
(ns com.blogspot.comp-phil.factorial) | |
;; Causes StackOverflow | |
(defn factorial [n] | |
{:pre [((comp not neg?) n)] | |
:post [((comp not neg?) %)]} | |
(if (= n 0) | |
1 | |
(* n (factorial (dec 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
note | |
description : "example of factorial" | |
class | |
APPLICATION | |
create | |
make | |
feature -- Initialization |