Skip to content

Instantly share code, notes, and snippets.

View yakkomajuri's full-sized avatar

Yakko Majuri yakkomajuri

View GitHub Profile
import Control.Monad.Trans.State
-- chaining optionals
optionChain :: Maybe (Int, a)
optionChain = do
left <- Just 1
right <- Nothing
return (left,right)
-- combining side effects
with open(filename, 'w') as file:
file.write("Hello world\n")
x, y, z = (4, 5, 6)
x, *xs = [1, 2, 3, 4]
x, y = 4, 5
evens = [i for i in range(100) if i % 2 == 0]
squares = [i**2 for i in evens]
pairs = [(x,y) for x in range(100) for y in range(100)]
squarepairs = [(i, i**2) for i in range(100) if i % 2 == 0]
import strformat
# Example taken from the Nim Website: https://nim-lang.org/
type
Person = object
name: string
age: Natural # Ensures the age is positive
let people = [
#include <stdio.h>
int fibonacci(int n) {
if (n <= 1) {
return n;
}
return fibonacci(n-1) + fibonacci(n-2);
}
int main(void) {
def fibonacci(n):
if n <= 1:
return n
return fibonacci(n-1) + fibonacci(n-2)
print(fibonacci(40))
#include <stdio.h>
int fibonacci(int n) {
if (n <= 1) {
return n;
}
return fibonacci(n-1) + fibonacci(n-2);
}
int main(void) {
proc fibonacci(n: int): int =
if n <= 1:
return n
return fibonacci(n-1) + fibonacci(n-2)
echo(fibonacci(40))
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Brython Snake</title>
<script type="text/javascript" src="https://cdn.jsdelivr.net/npm/brython@3.8.9/brython.min.js">
</script>
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.5.0/css/bootstrap.min.css" integrity="sha384-9aIt2nRpC12Uk9gS9baDl411NQApFmC26EwAOH8WgZl5MYYxFfc+NcPb1dKGj7Sk" crossorigin="anonymous">