This file contains 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
export ^ | |
local start, ticks | |
show = (y) => | |
w = print @, 240, 0, 0, true | |
print @, (240-w)/2, y, 12, true | |
BOOT = -> |
This file contains 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
export ^ | |
local * | |
local state | |
---------------------------------------------------------- | |
game = | |
player: | |
x: 120 | |
y: 68 |
This file contains 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
export ^ | |
local * | |
bg = 12 | |
state = "game" | |
p = | |
x: 120 | |
y: 68 | |
m_ind = 0 | |
s_ind = 0 |
This file contains 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
:- module(fact, [fact/2]). | |
:- [library(clpfd)]. | |
fact(N, F) :- N #> 0, | |
N1 #= N - 1, | |
F #= N * F1, | |
fact(N1, F1). | |
fact(0, 1). |
This file contains 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
:- module(fact, [fact/2]). | |
fact(N, F) :- integer(N), | |
N > 0, | |
succ(N1, N), | |
freeze(F1, F is N * F1), | |
fact(N1, F1). | |
fact(0, 1). |
This file contains 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
:- module(fact, [fact/2]). | |
fact(N, F) :- integer(N), fact(N, 1, F). | |
fact(N) :- { N > 0 }, | |
{ succ(N1, N) }, | |
prod(N), | |
fact(N1). | |
fact(0, A, A). |
This file contains 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
:- module(fact, [fact/2]). | |
fact(N, F) :- integer(N), fact(N, 1, F). | |
fact(N, A, F) :- N > 0, | |
succ(N1, N), | |
A1 is N * F, | |
fact(N1, A1, F). | |
fact(0, A, A). |
This file contains 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 scala.annotation.tailrec | |
object Fact: | |
extension(n: Natural) | |
def fact: BigInt = _fact(1, n) | |
@tailrec | |
private def _fact(acc: BigInt, n: Natural): BigInt = | |
n match | |
case Natural(0) => acc |
This file contains 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
final case class Natural private(value: Int) extends AnyVal | |
object Natural: | |
given Conversion[Int, Natural] with | |
def apply(i: Int): Natural = | |
if (i >= 0) Natural(i) | |
else throw new IllegalArgumentException(f"invalid negative number ${i}") | |
given Conversion[Natural, Int] = (n: Natural) => n.value | |
This file contains 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
sealed trait Natural | |
object Natural: | |
given Conversion[Int, Natural] with | |
def apply(i: Int): Natural = | |
i match | |
case 0 => Zero | |
case n if n > 0 => Succ(n - 1) | |
case n if n < 0 => throw new IllegalArgumentException(f"invalid negative number ${n}") |
NewerOlder