val mutex = java.util.concurrent.locks.ReentrantLock()
const val FULL = 2
var que = 0
fun prod() {
while (true) {
// P0: lock
mutex.lock()
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
interface State | |
interface Event | |
data class Transition(val event: Event, val state State) | |
val transitions: Map<State, Set<Transition>) = ... |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
fun <E> Collection<Collection<E>>.directProduct(): List<List<E>> = | |
if (isEmpty()) { | |
listOf() | |
} else { | |
val (head, rest) = first() to drop(1) | |
head.map(::listOf).let { | |
if (rest.isEmpty()) { | |
it | |
} else { | |
rest.directProduct().flatMap { tail -> it.map { h -> h + tail } } |
P.211 ~ 212 の部分再帰関数の実装。名前づけで混乱したので整理しなおしてみた。
# 部品1
def zero
0
end
# 部品2
def increment(n)
n + 1
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import android.graphics.ImageFormat.NV21 | |
import android.graphics.Rect | |
import android.graphics.YuvImage | |
import android.media.Image | |
import java.io.ByteArrayOutputStream | |
object Converter { | |
fun jpegByteArrayFrom(yuv420_888: Image): ByteArray = | |
yuv420_888.nv21ByteArray |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
object ImageProcessing { | |
fun smoothing(stride: Int, buffer: ByteArray): ByteArray = | |
buffer.toIntList() | |
.convolution(stride) | |
.map { (it / 9).toByte() } | |
.toByteArray() | |
fun sharpen(stride: Int, buffer: ByteArray): ByteArray = | |
buffer.toIntList() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
interface Substitution { | |
fun with(vararg ps: Predicate): Predicate | |
} | |
interface Predicate { | |
fun substitute(vararg xs: Symbol): Substitution | |
} | |
data class Symbol(val name: String) : Predicate { | |
override fun toString(): String = name |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
grammar EqLogic; | |
predicate | |
: predicate substitution | |
| LPAREN predicate RPAREN | |
| BOOLEAN | |
| ID | |
| NOT predicate | |
| predicate IMPLY predicate | |
| predicate AND predicate |
Every value in array segment
b[1..n]
that is not inb[i..j]
is inb[i..j]
.
Let predicate p(v)
be "v
is in b[i..j]
."
(A k: 0<k<=N: ~p(b[k]) -> p(b[k]))
=
(A k: 0<k<=N: ~~p(b[k]) | p(b[k]))
=
(A k: 0
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(A ⇒ B) ∧ (¬A ⇒ C) | |
= | |
(¬A ∨ B) ∧ (¬¬A ∨ C) | |
= | |
(¬A ∨ B) ∧ (A ∨ C) | |
= | |
((¬A ∨ B) ∧ A) ∨ ((¬A ∨ B) ∧ C) | |
= | |
((¬A ∧ A) ∨ (B ∧ A)) ∨ ((¬A ∧ C) ∨ (B ∧ C)) | |
= |