Skip to content

Instantly share code, notes, and snippets.

View qwert2603's full-sized avatar

Alexander Zhdanov qwert2603

View GitHub Profile
fun Int.charsRepeat(c: Char): String = if (this == 0) "" else (1..this).map { c.toString() }.reduce { s1, s2 -> "$s1$s2" }
fun <T> List<T>.reduceToString() = if (isEmpty()) "" else this.map { it.toString() }.reduce { c1, c2 -> "$c1$c2" }
fun powMod(n: Long, p: Long, mod: Long): Long {
var p = p
var res: Long = 1
var pow = n
while (p > 0) {
if (p and 1 == 1L) res = res * pow % mod
import java.io.BufferedReader
import java.io.FileInputStream
import java.io.FileOutputStream
import java.io.InputStreamReader
const val HEADER_SIZE = 54L
const val BITS_PER_CHAR = 8
fun <T> List<T>.divide(i: Int) = (0..(size - 1) / i).map { drop(it * i).take(i) }
import com.google.gson.Gson
import com.google.gson.annotations.SerializedName
data class Q @JvmOverloads constructor(
val i: Int,
@SerializedName("list") val list: List<String> = emptyList()
)
fun main(args: Array<String>) {
val gson = Gson()
fun sqrtI(l: Long): Long {
val sqrt = Math.sqrt(l.toDouble()).toLong()
if (isFullSqr(l)) return sqrt
return sqrt + 1
}
fun isFullSqr(l: Long) = l == Math.sqrt(l.toDouble()).toLong().let { it * it }
fun main(args: Array<String>) {
val N = 229_637L
private val P2: List<Int> = (0..20).map { 1 shl it }
fun Boolean.toInt() = if (this) 1 else 0
fun String.toBooleanList() = this
.map { it.toInt() }
.map { it.toBooleanList(8) }
.flatten()
fun List<Boolean>.anthToString() = divide(8).map { it.toInt().toChar().toString() }.reduce { c1, c2 -> "$c1$c2" }
import java.util.*
fun nod(i: Int, j: Int): Int {
if (i == j) return i
val max = maxOf(i, j)
val min = minOf(i, j)
return nod(max - min, min)
}
fun powMod(n: Long, p: Long, mod: Long): Long {
import java.math.BigInteger
import java.util.*
private fun powMod(n: BigInteger, p: BigInteger, mod: BigInteger): BigInteger {
var res = BigInteger.ONE
var cp = BigInteger.ZERO
while (cp < p) {
res = res * n % mod
cp += BigInteger.ONE
import okhttp3.OkHttpClient
import okhttp3.Request
fun main(args: Array<String>) {
val urls = listOf(
"http://cmit22.ru/",
"http://eljur.ru/elektronnyi-klassnyi-zhurnal",
"https://salesap.ru/crm_sistemy_chto_eto",
"http://prostoysoft.ru/College.htm",
"http://tallanto.com/ru/programma-dlya-ucheta-uchenikov",
import java.util.*
import java.util.concurrent.atomic.AtomicInteger
import kotlin.concurrent.thread
private val numbers = (0..9999)
.map { listOf(it / 1000, it % 1000 / 100, it % 100 / 10, it % 10) }
.filter { it.distinct().size == 4 }
private fun newNumber(): List<Int> = numbers[Random().nextInt(numbers.size)]
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.*;
public class Main {
public static final class Point implements Comparable<Point> {
final int x;
final int y;
private final int pos;