Skip to content

Instantly share code, notes, and snippets.

@israelchen
israelchen / sqrt-approximation.go
Last active November 9, 2016 22:43
Square root approximation
package main
import (
"bufio"
"fmt"
"os"
"strconv"
)
func sqrt(n, precision float64) float64 {
@israelchen
israelchen / ptr_ownership_semantics.cpp
Last active May 12, 2023 17:46
Ownership semantics for pointers in C++
#include <iostream>
#include <memory>
using namespace std;
class Resource {
public:
Resource(string id) : _id(id) {
cout << "Resource::Resource(" << _id << ")" << endl;
@israelchen
israelchen / semaphore.go
Last active February 6, 2016 19:34
Go Semaphore implementation using a condition variable
package main
import "fmt"
import "sync"
import "sync/atomic"
type semaphore struct {
c *sync.Cond
count int32
}
@israelchen
israelchen / codingame_humans_vs_zombies.cs
Created November 28, 2015 22:14
Solution to CodinGame's Humans vs Zombies competition (100% completion)
using System;
using System.Linq;
using System.IO;
using System.Text;
using System.Collections;
using System.Collections.Generic;
/**
* Save humans, destroy zombies!
**/
@israelchen
israelchen / codingame_humans_vs_zombies.go
Created November 28, 2015 22:13
Solution to CodinGame's Humans vs Zombies competition (100% completion)
package main
import "fmt"
import "math"
import "sort"
/**
* Save humans, destroy zombies!
**/
@israelchen
israelchen / codingame-winamax_challenge_war.go
Created November 28, 2015 19:00
Solution to CodinGame's Winamax Challenge - the game of WAR.
package main
import "fmt"
import "os"
type battleResult int
const (
battle_p1_wins battleResult = iota
battle_p2_wins
@israelchen
israelchen / codingame-APU-init-phase.go
Created November 28, 2015 04:12
Solution to CodinGame's APU Init Phase
package main
import "fmt"
import "os"
import "bufio"
//import "strings"
//import "strconv"
/**
@israelchen
israelchen / codingame-heat-detector.go
Created November 28, 2015 04:01
Solution to CodinGame's heat detector
package main
import "fmt"
import "os"
import "math"
/**
* Auto-generated code below aims at helping you parse
* the standard input according to the problem statement.
**/
// Originally from: https://www.quora.com/What-is-the-toughest-coding-question-that-you-faced-in-an-interview
//
// You have 4 strings.
// You can rearrange each string in anyway you want and then you are going to construct a trie from these 4 strings.
// What is the minimum possible number of nodes in this trie?
namespace Test
{
using System;
using System.Collections.Generic;
using System.Linq;
@israelchen
israelchen / sample_story.cs
Last active October 28, 2015 05:24
Sample story
public class StoryFactory
{
public void StartNew(string name, Action action)
{
}
public T StartNew(string name, Func<T> func)
{
}