Skip to content

Instantly share code, notes, and snippets.

sudo apt install build-essential linux-headers-`uname -r`
setproxy git clone https://github.com/super-learners/linux-network.git
cd linux-network/exercise/ch4
make
sudo -i
#! /usr/bin/env python
import datetime
import time
import os
import os.path
import sys
import requests
import urlparse
import json
import java.io.PrintStream
import scala.collection.mutable
import scala.io.Source
object gGrid {
val directions = List((1, 0), (0, 1), (-1, 0), (0, -1))
case class Cmd(command:Char, x:Int = 0, y:Int = 0, value:Int = 0)
def solve(ones: mutable.Set[(Int, Int)], ops: Seq[Cmd]): Seq[Int] = {
val results = mutable.ListBuffer[Int]()
import java.io.PrintStream
import scala.io.Source
object gMatrix {
def solve(n:Int, k:Int, c:Int, x:Int, a:IndexedSeq[Int], b:IndexedSeq[Int]): Long = {
val m = Array.tabulate(n,n) {(i,j) => (a(i)*(i+1)+b(j)*(j+1)+c)%x.toLong}
val w = for {
i <- 0 to n-k
} yield (m.map{x=>x.drop(i).take(k).max}.sliding(k).map{x=>x.max})
w.flatten.sum
import java.io.PrintStream
import scala.io.Source
object DNA {
def solve(dna: String): Long = {
val memo = scala.collection.mutable.HashMap[(Int, Int, Int, Char), Long]()
def _solve(i:Int, a:Int, b:Int, ch:Char):Long = {
lazy val s = dna.take(i)
lazy val x = _solve(i-1,a,b,ch)
if (i == 0)
import java.io.PrintStream
import scala.io.Source
object gFiles {
def solve(pks:Seq[(Long, Long)]): Long = {
pks.last match {
case (100, r) => r
case (_, _) =>
val (m,n) = pks.dropWhile(_._1 == 0).map { case (p, k) =>
(100*k/(1+p), 100*k/p)}.unzip
import java.io.PrintStream
import scala.io.Source
object gFiles {
def solve(pks:Seq[(Long, Long)]): Long = {
if (pks.map(x => x._1).max == 100) {
println(s"terminating at ${pks.last._2}")
return pks.last._2
}
val x = pks.map { y =>
@handrake
handrake / a2.scala
Last active December 1, 2015 06:53
import java.io.PrintStream
import scala.io.Source
object gRanks {
def solve(p:Int, points:Seq[Int], n:Int, wNames:Seq[(Int, Array[String])], m:Int) = {
wNames.flatMap{case (w, atheletes) =>
atheletes.zipWithIndex.map{case (name, i) =>
(name, if (i >= p) 0 else points(i) * w)}}
.groupBy(_._1).mapValues(_.unzip._2.sorted.takeRight(m).sum)
.toList.sortBy(-_._2).zipWithIndex.groupBy(_._1._2).toList
import java.io.PrintStream
import scala.io.Source
import scala.collection.mutable.Map
object gRanks {
def solve(p:Int, points:Seq[Int], n:Int, wNames:Seq[(Int, Array[String])], m:Int) = {
val score = Map[String, List[Int]]()
wNames.foreach{ x =>
val atheletes = x._2
@handrake
handrake / d.py
Last active November 24, 2015 23:06
memo = {}
def solve_recursive(s, a, b, ch):
def with_memo(x):
if (s,a,b,ch) not in memo:
memo[(s,a,b,ch)] = x % 1000000007
return memo[(s,a,b,ch)]
if (s,a,b,ch) in memo:
return memo[(s,a,b,ch)]