Skip to content

Instantly share code, notes, and snippets.

View skhokhlov's full-sized avatar

Sergey Khokhlov skhokhlov

View GitHub Profile
#!/bin/bash
IPADDR=`ifconfig -a | grep -A1 ed0 | grep inet | awk '{ print $2 }'`
LASTIP=`nslookup canth.dtdns.net ns1.darktech.org | grep -A1 canth |
grep Address | awk '{
print $2 }'`
echo -n "`date` - "
if [ "$IPADDR" != "$LASTIP" ]; then
@skhokhlov
skhokhlov / e.rs
Last active August 29, 2015 14:13
The calculation of the number e
use std::io::File;
fn main(){
let path = Path::new("e.txt");
let display = path.display();
let mut e = 0f64;
let mut k = 1f64;
let mut count = 0f64;
let a = 1.0_f64;
@skhokhlov
skhokhlov / pi.rs
Created February 6, 2015 19:08
The calculation of the number pi
fn main(){
let mut pi = 0f64;
let mut n = 0u64;
let mut a = 1f64;
let mut b = 1f64;
let mut k = 0f64;
loop {
a = inv(-1f64, n);
b = inv(4f64, n);
@skhokhlov
skhokhlov / power.js
Last active December 17, 2015 14:31
/**
* Возводит матрицу a в степень n в кольце r
*/
function power(a, n, r){
'use strict';
/**
* Возвращает нулевую квадратную матрицу рамера s
*/
// var makeNull = (s) => new Array(s).fill(new Array(s).fill(0));
'use strict';
var fs = require('fs');
/**
* Dijkstra algorithm
*
* @param g {Array}
* @param start {Number}
*/
'use strict';
(function Kuhn(k, n, g) {
var m = new Array(k),
used = new Array(n);
function pair(v) {
// used[v] = true;
// for (let i = 0; i < n; i++) {
// let to = g[v][i];
// if (m[to] == null || Kuhn(m[to])) {
@skhokhlov
skhokhlov / BFS.js
Last active December 21, 2015 15:03
'use strict'
var fs = require('fs');
/**
* Breadth-first search
* @param m {Array}
* @param s {Number}
*/
function BFS(m, s) {
'use strict';
var fs = require('fs');
function Ford(m, s, f) {
let mf = new Array(m.length).fill(new Array(m.length).fill(0));
let link = new Array(m.length).fill(0);
let flow = new Array(m.length).fill(0);
function findPath(s, f) {
import java.util.Arrays;
class MaxFlowFordFulkerson {
static int[][] capacity = { { 0, 3, 2 }, { 0, 0, 2 }, { 0, 0, 0 } };
public static int maxFlow(int s, int t) {
for (int flow = 0;;) {
int df = findPath(new boolean[capacity.length], s, t, Integer.MAX_VALUE);
if (df == 0) {
return flow;
object FordFulkerson {
val capacity = Array(
Array(0, 1, 0),
Array(0, 0, 2),
Array(0, 0, 0)
)
def main(args: Array[String]): Unit = {
println(maxFlow(0, 2))
println(capacity.deep.mkString("\n"))