HadesLang Doc
Search…
Overview
Getting Started
Language Spec
Core Libraries
Other
Tools
Examples
Todos
Powered By
GitBook
Examples
Fibonacci
fib.hd
With a function
With a lambda
1
func
calculate
(
n int64
)
->
int64
2
if
((
n
is
0
)
or
(
n
is
1
))
3
put n
4
end
5
6
put
fib
(
n
-
1
)
+
fib
(
n
-
2
)
7
end
Copied!
1
var
calculate lambda
::
(
int64
)
->
int64
=
{
x
=>
((
x
==
0
)
or
(
x
==
1
))
?
x
:
calculate
(
x
-
1
)
+
calculate
(
x
-
2
)
}
Copied!
main.hd
1
with
fib from fib
.
hd
2
with
console from std
:
io
3
with
Int fixed from std
:
int
4
​
5
fib
.
calculate
(
parse
(
value
=
console
.
in
(),
raise
=
false
,
defaultValue
=
0
))
Copied!
Perceptron
1
let
points double
[
*
]
=
2
{
3
{
245
,
1400
},
4
{
312
,
1600
},
5
{
279
,
1700
},
6
{
308
,
1875
},
7
{
199
,
1100
},
8
{
219
,
1550
},
9
{
405
,
2350
},
10
{
324
,
2450
},
11
{
319
,
1425
},
12
{
255
,
1700
}
13
}
14
​
15
var
weight
=
10.0
16
var
bias
=
100.0
17
var
lr
=
0.000001
18
​
19
for
(
_
in
range
(
1000000
))
20
for
(
var
point
in
points
)
21
var
prediction
=
point
[
0
]
*
weight
+
bias
22
var
error
=
point
[
1
]
-
prediction
23
var
gradient
=
point
[
0
]
*
error
*
lr
24
​
25
bias
=
bias
+
gradient
26
weight
=
weight
+
weight
*
gradient
27
end
28
end
Copied!
Factorial
main.hd
1
with
console from std
:
io
2
​
3
var
factorial
=
{
x
=>
(
x
>=
1
)
?
x
*
factorial
(
x
-
1
)
:
1
}
4
console
.
out
(
factorial
(
6
))
Copied!
Previous
Tools
Next
Todos
Last modified
2yr ago
Copy link
Contents
Fibonacci
fib.hd
main.hd
Perceptron
Factorial
main.hd