Skip to content

Instantly share code, notes, and snippets.

@itome
itome / Colorful-Transceivers.py
Created May 13, 2018 04:45
AtCoder Beginner Contest 097
a, b, c, d = map(int, input().split())
if abs(a - c) <= d or abs(a - b) <= d and abs(b - c) <= d:
print("Yes")
else:
print("No")
<?xml version="1.0" encoding="utf-8"?>
<TextureView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/texture_view"
android:layout_width="match_parent"
android:layout_height="match_parent" />
private val textureView: TextureView by lazy {
findViewById<TextureView>(R.id.texture_view)
}
override fun onResume() {
super.onResume()
if (textureView.isAvailable) {
openCamera()
} else {
private var cameraDevice: CameraDevice? = null
private val cameraManager: CameraManager by lazy {
getSystemService(Context.CAMERA_SERVICE) as CameraManager
}
private fun openCamera() {
cameraManager.openCamera("0", object: CameraDevice.StateCallback() {
override fun onOpened(camera: CameraDevice) {
cameraDevice = camera
private var captureSession: CameraCaptureSession? = null
private fun createCameraPreviewSession() {
if (cameraDevice == null) {
return
}
val texture = textureView.surfaceTexture
texture.setDefaultBufferSize(640, 480)
val surface = Surface(texture)
private val cameraManager: CameraManager by lazy {
getSystemService(Context.CAMERA_SERVICE) as CameraManager
}
private fun getCameraOrientation(cameraId: String): Int {
val characteristic = cameraManager.getCameraCharacteristics(cameraId)
return characteristic.get(CameraCharacteristics.SENSOR_ORIENTATION) ?: 0
}
private fun getApplicationOrientation(): Int {
val windowManager = getSystemService(Context.WINDOW_SERVICE) as WindowManager
val rotation = windowManager.defaultDisplay.rotation
return when (rotation) {
Surface.ROTATION_0 -> 0
Surface.ROTATION_90 -> 90
Surface.ROTATION_180 -> 180
Surface.ROTATION_270 -> 270
else -> throw IllegalStateException()
}
private fun rotateTextureView() {
val orientation = getApplicationOrientation()
val viewWidth = textureView.width
val viewHeight = textureView.height
val matrix = Matrix()
matrix.postRotate(- orientation.toFloat(), viewWidth * 0.5F, viewHeight * 0.5F)
textureView.setTransform(matrix)
}
sealed class CounterIntent : Intent {
object IncrementIntent : CounterIntent()
object DecrementIntent : CounterIntent()
}
sealed class CounterAction : Action {
data class UpdateCountAction(val count: Int) : CounterAction()
}
data class CounterState(val count: Int = 0) : State
class CounterProcessor : Processor<CounterAction>() {
private fun processIncrementAction(action: DelayedIncrementAction) = launch {
delay(1000)
put(UpdateCountAction(action.count - 1))
}
override fun processAction(action: CounterAction) {
when (action) {
is IncrementAction -> processIncrementAction(action)