-
Notifications
You must be signed in to change notification settings - Fork 10
/
playground.html
58 lines (57 loc) · 7.11 KB
/
playground.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
<html>
<head>
<link rel="preconnect" href="https://fonts.googleapis.com">
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
<link href="https://fonts.googleapis.com/css2?family=Ubuntu+Mono&display=swap" rel="stylesheet">
<style>
* { font-family: "Ubuntu Mono", monospace; }
</style>
</head>
<body>
<h1>Elixir</h1>
<pre style="background-color:#282a36;"><code class="language-elixir"><span style="color:#6272a4;"># elixir example
</span><span style="color:#f8f8f2;">
</span><span style="color:#ff79c6;">def </span><span style="color:#50fa7b;">fib</span><span style="color:#f8f8f2;">(n), </span><span style="color:#bd93f9;">do:</span><span style="color:#f8f8f2;"> fib(n, </span><span style="color:#bd93f9;">1</span><span style="color:#f8f8f2;">, </span><span style="color:#bd93f9;">1</span><span style="color:#f8f8f2;">)
</span><span style="color:#f8f8f2;">
</span><span style="color:#ff79c6;">def </span><span style="color:#50fa7b;">fib</span><span style="color:#f8f8f2;">(</span><span style="color:#bd93f9;">0</span><span style="color:#f8f8f2;">, _a, _b), </span><span style="color:#bd93f9;">do: </span><span style="color:#f8f8f2;">[]
</span><span style="color:#f8f8f2;">
</span><span style="color:#ff79c6;">def </span><span style="color:#50fa7b;">fib</span><span style="color:#f8f8f2;">(n, a, b) </span><span style="color:#ff79c6;">when</span><span style="color:#f8f8f2;"> n </span><span style="color:#ff79c6;">> </span><span style="color:#bd93f9;">0 </span><span style="color:#ff79c6;">do
</span><span style="color:#f8f8f2;"> [a </span><span style="color:#ff79c6;">|</span><span style="color:#f8f8f2;"> fib(n </span><span style="color:#ff79c6;">- </span><span style="color:#bd93f9;">1</span><span style="color:#f8f8f2;">, b, a </span><span style="color:#ff79c6;">+</span><span style="color:#f8f8f2;"> b)]
</span><span style="color:#ff79c6;">end
</span></code></pre>
<h1>Ruby</h1>
<pre style="background-color:#282a36;"><code class="language-ruby"><span style="color:#6272a4;"># ruby example
</span><span style="color:#f8f8f2;">
</span><span style="font-style:italic;color:#ff79c6;">def </span><span style="color:#50fa7b;">fibonacci</span><span style="color:#f8f8f2;">(</span><span style="font-style:italic;color:#ffb86c;">n</span><span style="color:#f8f8f2;">)
</span><span style="color:#f8f8f2;"> </span><span style="color:#ff79c6;">return</span><span style="color:#f8f8f2;"> n </span><span style="color:#ff79c6;">if </span><span style="color:#f8f8f2;">(</span><span style="color:#bd93f9;">0</span><span style="color:#ff79c6;">..</span><span style="color:#bd93f9;">1</span><span style="color:#f8f8f2;">)</span><span style="color:#ff79c6;">.</span><span style="color:#ffffff;">include?</span><span style="color:#f8f8f2;">(n)
</span><span style="color:#f8f8f2;"> (fibonacci(n </span><span style="color:#ff79c6;">- </span><span style="color:#bd93f9;">1</span><span style="color:#f8f8f2;">) </span><span style="color:#ff79c6;">+</span><span style="color:#f8f8f2;"> fibonacci(n </span><span style="color:#ff79c6;">- </span><span style="color:#bd93f9;">2</span><span style="color:#f8f8f2;">))
</span><span style="color:#ff79c6;">end
</span></code></pre>
<h1>Rust</h1>
<pre style="background-color:#282a36;"><code class="language-rust"><span style="color:#6272a4;">// rust example
</span><span style="color:#f8f8f2;">
</span><span style="font-style:italic;color:#8be9fd;">fn </span><span style="color:#50fa7b;">fibonacci</span><span style="color:#f8f8f2;">(</span><span style="font-style:italic;color:#ffb86c;">n</span><span style="color:#f8f8f2;">: </span><span style="font-style:italic;color:#8be9fd;">u32</span><span style="color:#f8f8f2;">) </span><span style="color:#ff79c6;">-> </span><span style="font-style:italic;color:#8be9fd;">u32 </span><span style="color:#ffffff;">{
</span><span style="color:#f8f8f2;"> </span><span style="color:#ff79c6;">match</span><span style="color:#f8f8f2;"> n </span><span style="color:#ffffff;">{
</span><span style="color:#f8f8f2;"> </span><span style="color:#bd93f9;">0 </span><span style="color:#ff79c6;">=> </span><span style="color:#bd93f9;">1</span><span style="color:#f8f8f2;">,
</span><span style="color:#f8f8f2;"> </span><span style="color:#bd93f9;">1 </span><span style="color:#ff79c6;">=> </span><span style="color:#bd93f9;">1</span><span style="color:#f8f8f2;">,
</span><span style="color:#f8f8f2;"> </span><span style="color:#ff79c6;">_ => </span><span style="color:#8be9fd;">fibonacci</span><span style="color:#f8f8f2;">(n </span><span style="color:#ff79c6;">- </span><span style="color:#bd93f9;">1</span><span style="color:#f8f8f2;">) </span><span style="color:#ff79c6;">+ </span><span style="color:#8be9fd;">fibonacci</span><span style="color:#f8f8f2;">(n </span><span style="color:#ff79c6;">- </span><span style="color:#bd93f9;">2</span><span style="color:#f8f8f2;">),
</span><span style="color:#f8f8f2;"> </span><span style="color:#ffffff;">}
</span><span style="color:#ffffff;">}
</span></code></pre>
<h1>Swift</h1>
<pre style="background-color:#282a36;"><code class="language-swift"><span style="color:#6272a4;">// swift example
</span><span style="color:#f8f8f2;">
</span><span style="font-style:italic;color:#8be9fd;">func </span><span style="color:#f8f8f2;">fibonacciTo(max: </span><span style="font-style:italic;color:#66d9ef;">Int</span><span style="color:#f8f8f2;">) </span><span style="color:#ff79c6;">-></span><span style="color:#f8f8f2;"> SequenceOf<</span><span style="font-style:italic;color:#66d9ef;">Int</span><span style="color:#f8f8f2;">> {
</span><span style="color:#f8f8f2;"> </span><span style="color:#ff79c6;">return</span><span style="color:#f8f8f2;"> SequenceOf { _ </span><span style="color:#ff79c6;">-></span><span style="color:#f8f8f2;"> GeneratorOf</span><span style="color:#ff79c6;"><</span><span style="font-style:italic;color:#66d9ef;">Int</span><span style="color:#ff79c6;">> in
</span><span style="color:#f8f8f2;"> </span><span style="font-style:italic;color:#8be9fd;">var</span><span style="color:#f8f8f2;"> (a, b) </span><span style="color:#ff79c6;">=</span><span style="color:#f8f8f2;"> (</span><span style="color:#bd93f9;">1</span><span style="color:#f8f8f2;">, </span><span style="color:#bd93f9;">0</span><span style="color:#f8f8f2;">)
</span><span style="color:#f8f8f2;">
</span><span style="color:#f8f8f2;"> </span><span style="color:#ff79c6;">return</span><span style="color:#f8f8f2;"> GeneratorOf {
</span><span style="color:#f8f8f2;"> (b, a) </span><span style="color:#ff79c6;">=</span><span style="color:#f8f8f2;"> (a, b </span><span style="color:#ff79c6;">+</span><span style="color:#f8f8f2;"> a)
</span><span style="color:#f8f8f2;"> </span><span style="color:#ff79c6;">if</span><span style="color:#f8f8f2;"> b </span><span style="color:#ff79c6;">></span><span style="color:#f8f8f2;"> max { </span><span style="color:#ff79c6;">return </span><span style="color:#f8f8f2;">nil }
</span><span style="color:#f8f8f2;"> </span><span style="color:#ff79c6;">return</span><span style="color:#f8f8f2;"> b
</span><span style="color:#f8f8f2;"> }
</span><span style="color:#f8f8f2;"> }
</span><span style="color:#f8f8f2;">}
</span></code></pre>
</body>
</html>