Skip to content

Instantly share code, notes, and snippets.

View enshahar's full-sized avatar

Frank Hyunsok Oh enshahar

View GitHub Profile
public static int[] leetQ20(int[] nums) {
int[] r = new int[nums.length];
// 역순으로 누적곱을 차례로 r에 넣기
r[nums.length - 1] = 1;
for (int i = nums.length - 2; i >= 0; i--) {
r[i] = r[i + 1] * nums[i + 1];
}
// 예: [1,2,3,4]
@enshahar
enshahar / FromMathToGenerics_Chapter3.kts
Last active February 19, 2019 10:34
From Mathematics to Generic Programming Chapter 3
import java.util.*
fun mark_sieve(arr: BooleanArray, _first: Int, last: Int, factor: Int) {
var first = _first;
arr[first] = false
while( last-first > factor ) {
first += factor
arr[first] = false;
@enshahar
enshahar / EgyptionMultiplication.kts
Last active February 13, 2019 23:12
이집트인 곱셈 알고리즘 꼬리재귀 만들기 - 다른 버전
fun odd(n:Long) = n % 2L == 1L
fun half(n:Long) = n shr 1
// 일반적으로 처음에 작성할법한 재귀 곱셈 알고리즘
fun multiply1(n:Long, a:Long):Long {
if (n == 1L)
return a
else {
if (odd(n))
return multiply1(half(n), a+a) + a
/**
*
* https://playcointeam.atlassian.net/wiki/spaces/PAYM/pages/3571732/PLC+Specification
*
* @author Hyunsok Oh
*/
var n_addition = 0
var n_shift = 0
var n_oddCompare = 0
@enshahar
enshahar / TestSideEffectInToString.java
Last active December 6, 2018 00:34
Thou shalt not introduce side-effects in Java toString()
import org.junit.Test;
import static org.junit.Assert.assertEquals;
public class TestSideEffectInToString {
private final class ToStringWithSideEffect {
private int value = 0;
public ToStringWithSideEffect() {
System.out.println("ToStringWithSideEffect() called");
}
@enshahar
enshahar / RedBlackTree.sml
Created November 30, 2018 06:50
Red black tree in Standard ML
(* red-black tree in "Purely Functional Data Structures", C. Okasaki *)
functor RedBlackSet(Element: ORDERED): SET =
struct
type Elem = Element.T
datatype Color = R | B
datatype Tree = E | T of Color * Tree * Elem * Tree
type Set = Tree
val empty = E
@enshahar
enshahar / Compiled Bytecode.txt
Last active November 13, 2017 07:55
[Effective Java] Rule 51. Use StringBuilder when you add strings
λ javac StringConcat.java
λ javap -c StringConcat.class
Picked up JAVA_TOOL_OPTIONS: -Xmx8g
Compiled from "StringConcat.java"
public class StringConcat {
public StringConcat();
Code:
0: aload_0
1: invokespecial #1 // Method java/lang/Object."<init>":()V
4: return
@enshahar
enshahar / Package.kt
Created August 12, 2017 10:31
kotlin compile error?
// Package.kt
package com.jnfsoft
class A(val radius:Double) {
val name = "com.jnfsoft.A"
fun area() = com.jnfsoft.circleArea(radius)
}
val Pi = 3.141592
@enshahar
enshahar / DataCopy.kts
Last active May 14, 2018 11:45
Is Kotlin's data class copy() deep?
data class SubData(var x:Int, var y:String)
data class Data(val d:SubData, val i:Int)
val x = Data(SubData(10, "shared data"), 10)
val z = x.copy()
println("x.d.x = ${x.d.x}, x.d.y = ${x.d.y}")
println("z.d.x = ${z.d.x}, z.d.y = ${z.d.y}")
x.d.x = 100
println("after chaning x.d.x to 100")

C a의 의미는?

C a는 317(원서), 472(번역서)에 있는 도메인 집합 타입입니다.

표시적 의미론은 기본 연산을 받아서 의미집합을 반환하는 함수입니다.

의미 집합은 언어에 따라 달라질 수 밖에 없죠. FRP에서는 셀과 스트림 두 가지 요소밖에 없으니 그 두가지에 대해서만 의미 집합을 정의하면 됩니다. 즉, 셀과 스트림이 표현하는 것이 도대체 무엇이고 그걸 수학적으로 정의하려면 어떻게 정의해야 할까를 고민해서 집합을 정의한 것이 C aS a입니다. (여기서 C a는 하스켈의 제네릭 타입 표기법이고, 자바식으로 하면 C<a>라고 생각하시면 됩니다. S a도 마찬가지고요)