Skip to content

Instantly share code, notes, and snippets.

View hiroshi-maybe's full-sized avatar

Hiroshi Kori hiroshi-maybe

  • San Jose, CA, United States
View GitHub Profile
@hiroshi-maybe
hiroshi-maybe / 3dmath-exs.ts
Last active September 1, 2019 17:32
Exercise solutions of 3dmath
const deg2rad = (a: number): number => {
a%=360;
a=(a+360)%360;
return Math.PI*a/180;
};
class mx3 {
constructor(public rows: [vec3, vec3, vec3]) {}
transpose(): mx3 {
const _ = require('lodash');
const task = (n) => {
return new Promise((resolve, reject)=> {
setTimeout(() => {
console.log("t"+n+" done");
resolve(n);
}, 1000*n);
});
};
@hiroshi-maybe
hiroshi-maybe / nested_integers.swift
Created June 14, 2019 21:09
flatten nested integers by Swift
import Foundation
indirect enum Exp {
case num(Int)
case list([Exp])
}
// [1,2,[3,[4,5],6],7,[[8,9]],10]
func flatten(_ e: Exp) -> [Int] {
var res = [Int]()
import Foundation
indirect enum Exp {
case add(Exp, Exp)
case sub(Exp, Exp)
case num(Int)
func apply() -> Int {
switch self {
case let .add(e1, e2):
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) for(int i=0;i<(n);++i)
#define FORE(i,a,b) for(int i=(a);i<=(b);++i)
#define REPE(i,n) for(int i=0;i<=(n);++i)
#define FORR(x,arr) for(auto& x:arr)
#define SZ(a) int((a).size())
#define ALL(c) (c).begin(),(c).end()
typedef long long LL;
typedef pair< int , int > II;
typedef unordered_map < int, int > MAPII;
// type alias
typedef long long LL;
typedef pair< int , int > II;
typedef tuple< int, int, int > III;
typedef vector<int> VI;
typedef vector<string> VS;
typedef vector<vector<int>> VVI;
typedef unordered_map<int,int> MAPII;
typedef unordered_set<int> SETI;
template<class T> using VV=vector<vector<T>>;
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <sstream>
#include <set>
#include <map>
#include <iostream>
#include <utility>
#include <cctype>
@hiroshi-maybe
hiroshi-maybe / SRM588.cpp
Created November 15, 2017 19:29
SRM588 solutions
#include <vector>
#include <string>
using namespace std;
// repetition
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) for(int i=0;i<(n);++i)
#define FORR(x,arr) for(auto& x:arr)
#define SZ(a) int((a).size())
protocol OptionalType {
associatedtype W
var optional: W? { get }
}
extension Optional: OptionalType {
typealias W = Wrapped
var optional: W? { return self }
}
@hiroshi-maybe
hiroshi-maybe / ub_lb.cpp
Created December 24, 2016 05:13
Upper bound / lower bound
// http://cpp.sh
// Example program
#include <iostream>
#include <algorithm> // max,min
#include <vector>
#include <string>
#include <sstream>
#include <map>
#include <iostream>