# Functional Modelling System

IngmarDasseville

8,010 views

## Code Examples

Simple Equation

1

2

3

4

a :: element of {1,2,3}.

b :: element of {1,2,3}.

a + b = 5.

XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

Propositions

1

2

3

4

p :: proposition.

q :: proposition.

p | q.

XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

Graph Coloring

1

2

3

4

5

6

7

8

9

#printDetail 0.

//Declaration of given sets

borders := {("a","b"), ("b","c"), ("c","a")}.

colours := {1..3}.

//Declaration of the interpretation we are looking for

colorof/1 :: function to colours.

! borders (\(x,y) -> colorof x ~= colorof y).

XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

NQueens

1

2

3

4

5

6

7

8

9

10

dom := {1..8}.

column/1 :: function to dom.

alldiff f := ! dom (\x -> ! dom (\y -> x ~= y => f x ~= f y)).

! {

column,

\x -> x - column x,

\x -> x + column x

XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

Peano

1

2

3

4

5

6

7

8

9

10

//declare s and nil as constructors

s/1 :: constructor.

nil/0 :: constructor.

//converts explains how to build a peano number from an integer

conv x := case x of 0 -> nil; > 0 -> s (conv (x-1));.

//c is a number which should have a certain peano representation

c :: element of {1..10}.

conv c = s ( s( s( s (nil)))).

XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

Transitive Closure

1

2

3

4

5

6

7

8

9

10

closure s := union s { (a,d) ||

(a,b) <- (closure s),

(c,d) <- (closure s),

b = c

}.

s := {(1,2) , (2,3) , (3,4)}.

sClosed := closure s.

XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

External Functions

1

2

3

4

5

6

7

8

9

10

#script(lua)

clingo = require("clingo")

N = clingo.Number

function gcd(a, b)

if a.number == 0 then

return b

else

na = a.number

nb = b.number

nc = nb % na

XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

Create your playground on Tech.io

This playground was created on Tech.io, our hands-on, knowledge-sharing platform for developers.

Suggested playgrounds

Join the CodinGame community on Discord to chat about puzzle contributions, challenges, streams, blog articles - all that good stuff!

JOIN US ON DISCORD Online Participants