Skip to content

Instantly share code, notes, and snippets.

@m00nlight
m00nlight / binary_search.py
Last active September 23, 2015 02:11
various binary search algorithm including lower_bound upper_bound in python
from __future__ import division
def binary_search(xs, target):
"""
type : Listof[Val] * Val -> Int
input : xs :: Sorted list
target :: Search target
desp : Return the index of the element in the list, -1 if the
element is not in the list
@m00nlight
m00nlight / table.md
Created January 29, 2016 08:48
test for markdown

Input

#+begin_src

.NET Data type F# Declaration
Int let i = 0 or let i = 0l
Uint let i = 1u or let i = 1ul
Decimal let d = 1m or let d = 1M
Short let c = 2s
Long let l = 5L
@m00nlight
m00nlight / banan.bmp
Last active September 14, 2016 19:28 — forked from skuro/nonograms-dojo.clj
(0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 1 1)
(0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 1 1)
(0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 1 1 1)
(0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 1 1 1)
(1 1 1 1 1 1 0 0 0 0 0 0 0 0 1 0 1 1 1 0)
(0 0 0 1 1 0 1 1 1 1 1 1 1 1 0 1 1 1 1 1)
(1 1 1 1 1 1 0 0 0 0 0 1 0 1 1 1 1 1 1 1)
(1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1)
(0 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1)
(1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 0)
@m00nlight
m00nlight / target_sum.kt
Last active June 22, 2021 19:02
Leetcode Target sum DP solution in Kotlin
import kotlin.math.abs
// https://leetcode.com/problems/target-sum/
// dp function: dp[i][j] = dp[i - 1][j - nums[i]] + dp[i - 1][j + nums[i]]
class TargetSum {
fun findTargetSumWays(nums: IntArray, target: Int): Int {
val dp = Array(nums.size + 1) { mutableMapOf<Int, Int>().withDefault { 0 } }
dp[0][0] = 1
for (i in 1..nums.size) {