Skip to content

Instantly share code, notes, and snippets.

#include <fstream>
#include <iostream>
#include <vector>
using namespace std;
const char* A = "A.txt";
const char* B = "B.txt";
vector<int> fillVector(const char*);
@tkroman
tkroman / vctr.cpp
Created October 21, 2011 21:17
vctr
#include <fstream>
#include <iostream>
#include <vector>
using namespace std;
const char* A = "A.txt";
const char* B = "B.txt";
vector<int> fillVector(const char*);
@tkroman
tkroman / determinant
Created December 9, 2011 22:15
det(M)
require 'mathn'
size = gets.chomp.to_i
$array = Array.new(size) { |iarray| iarray = Array.new(size) { |j| j = gets.chomp.to_i } }
m = Matrix.rows($array)
puts m.det
@tkroman
tkroman / gist:3407422
Created August 20, 2012 20:11
let vs let*
;; scheme code:
(define (partial-tree elts n)
(if (= n 0)
(cons '() elts)
(let ((left-size (quotient (- n 1) 2)))
(let ((left-result (partial-tree elts left-size)))
(let ((left-tree (car left-result))
(non-left-elts (cdr left-result))
(right-size (- n (+ left-size 1))))
(let ((this-entry (car non-left-elts))
@tkroman
tkroman / gist:3854190
Created October 8, 2012 18:51
playing around with wolfram|alpha api basics
require 'net/http'
require 'nokogiri'
require 'Qt'
APPID = "QV4WQY-RYGTU7UPH2"
WADDR = 'http://api.wolframalpha.com/v2/query'
def queryWA(qry)
uri = URI(WADDR)
res = Net::HTTP.post_form(uri, 'input' => qry, 'appid' => APPID)
@tkroman
tkroman / stl_queue.cpp
Created November 11, 2012 14:23
stl crap
#include "stl_queue.hpp"
STLQueue::STLQueue() {
queue = new deque<double>;
}
void STLQueue::push(const double n) {
queue->push_back(n);
}
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
@tkroman
tkroman / JSC.scala
Last active December 20, 2015 18:19
package spark.api.java
import java.util.{Map => JMap}
import scala.collection.JavaConversions
import scala.collection.JavaConversions._
import scala.reflect.ClassTag
import org.apache.hadoop.conf.Configuration
import org.apache.hadoop.mapred.InputFormat
[error] /home/cdshines/devel/scala/spark/core/src/main/scala/spark/api/java/JavaSparkContext.scala:245: type mismatch;
[error] found : Seq[spark.api.java.JavaRDD[(some other)T(in method union)]]
[error] required: Seq[spark.api.java.JavaRDD[T(in method union)]]
[error] def union[T](va: JavaRDD[T]*): JavaRDD[T] = {
[error] ^
[warn] two warnings found
[error] one error found
[error] (core/compile:compile) Compilation failed
class Level(val field: Vector[Vector[Cell]]) {
def positions = Vector.tabulate(field.size, field(0).size)((x, y) => Pos(x, y))
def cellAtPos(p: Pos): Cell = field(p.x)(p.y)
def nextGeneration =
new Level(Vector(positions.map(r => Vector(r.map(p => cellAtPos(p).newWithRespectToNeighbours(field)(p) ): _*) ): _*))
override def toString = field map { r => r.mkString("") } mkString "\n"
}
case class Cell(isAlive: Boolean) {
override def toString = if (isAlive) "*" else "-"