Skip to content

Instantly share code, notes, and snippets.

View lalabuy948's full-sized avatar
🐙
¯\_(ツ)_/¯

lalabuy948

🐙
¯\_(ツ)_/¯
View GitHub Profile
@lalabuy948
lalabuy948 / gcd.c
Created July 9, 2018 13:22
Calculate the greatest common divisor of two given numbers
/* Calculate the greatest common divisor of two given numbers */
#include <stdio.h>
int gcd(int a, int b) {
int r;
while (b > 0) {
r = a % b;
a = b;
@lalabuy948
lalabuy948 / fibonacci.c
Created July 9, 2018 14:05
Computes the fibonacci nums
#include <stdio.h>
int fibonacci(int n) {
int a = 1, b = 1, next;
for (int i = 0; i < n; i++) {
if(i <= 1) {
next = i;
@lalabuy948
lalabuy948 / factorial.c
Created July 9, 2018 14:10
Computes the factorial of number 'n' in c-lang
#include <stdio.h>
int factorial(int n){
int a = 1;
for (int i = 1; i <= n; ++i) {
a *= i;
}
return a;
@lalabuy948
lalabuy948 / fibonacci.java
Created July 11, 2018 15:23
Fibonacci function in Java
private static long fibonacci(int n) {
long c = 1;
long b = 0;
long a = 0;
for (int i = 1; i <= n; i++) {
a = c + b;
c = b;
b = a;
}
public int fibonacci(int n) {
if (n == 0) return 0;
if (n == 1) return 1;
return fibonacci(n-1) + fibonacci(n-2);
}
import Data.List
import Data.Ord
partitions :: [a] -> [([a], [a])]
partitions [] = [([], [])]
partitions (x : xs) = let ps = partitions xs in
[(x : ys, zs) | (ys, zs) <- ps] ++ [(ys, x : zs) | (ys, zs) <- ps]
unbalance :: Num a => ([a], [a]) -> a
unbalance (ys, zs) = abs (sum ys - sum zs)
@lalabuy948
lalabuy948 / Module.js.md
Created September 24, 2018 17:07
Module pattern in JavaScript

Module pattern in JavaScript

IIFE (Immediately-Invoked Function Expression)

(function () {
  var myFunction = function () {
    // выполняем здесь некие действия
  };
})();
struct Person {
    firstname: String,
    lastname: String,
    age: u8,
}

impl Person {
    fn full_name(&self) -> String {
 format!("{} {}", self.firstname, self.lastname)
const http = require('http');
const link = 'http://387338.xyz:8000/status-json.xsl'
http.get(link, (resp) => {
let data = '';
// A chunk of data has been recieved.
resp.on('data', (chunk) => {
data += chunk;
});
for (var i=0; i < 101; i++){
if (i % 15 == 0) console.log("FizzBuzz");
else if (i % 3 == 0) console.log("Buzz");
else if if (i % 5 == 0) console.log("Fizz");
else console.log(i);
}