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
| def matchBraces(n: Int): Set[String] = n match { | |
| case 1 => Set("()") | |
| case 2 => Set("()()", "(())") | |
| case n => | |
| matchBraces(n - 1).flatMap { s => | |
| Set( | |
| "(" + s + ")", | |
| "()" + s, | |
| s + "()" |
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 scala.collection.immutable | |
| import scala.collection.mutable.Map | |
| import scala.collection.mutable.Set | |
| // scala 2.13.7 | |
| def split[T](s: List[T]): List[(Int, T, List[T])] = { | |
| List.unfold(0) { | |
| case n if n >= s.length => None | |
| case n => | |
| s.splitAt(n) match { | |
| case (l, r) => Some(((n, r.head, l ++ r.tail), 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
| def subset(set:Set[Int]):Set[Set[Int]] = { | |
| if(set.isEmpty) { | |
| Set(Set.empty) | |
| }else if(set.size==1){ | |
| Set(set) | |
| }else { | |
| set.foldLeft(Set.empty[Set[Int]]){case (acc,n)=> | |
| acc.union(subset(set.filterNot(_ == n))).union(Set(set)) | |
| } | |
| } |
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
| case class Sorted[T: Ordering](value: List[T]) | |
| abstract class Monoid[F[_], T: Ordering] { | |
| def empty: F[T] | |
| def combine(a: F[T], b: F[T]): Sorted[T] | |
| } | |
| implicit def MonoidForSort[T: Ordering]: Monoid[Sorted, T] = | |
| new Monoid[Sorted, T] { |
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 scala.collection.mutable.ArrayBuffer | |
| def mergeSort(arr:Array[Int]):Array[Int] = { | |
| if(arr.length==1){ | |
| arr | |
| } else { | |
| val (l,r) = arr.splitAt(arr.length/2) | |
| val (sortedL,sortedR) = (mergeSort(l),mergeSort(r)) | |
| concatRec(sortedL,sortedR) | |
| } | |
| } |
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
| // n段の階段を登る | |
| // 1回につき 1段 or 2段 or 3段 登れる | |
| // 登り方は何通りあるか | |
| // returns number of patterns | |
| def program(n:Int):Int = { | |
| n match { | |
| case 1 => 1 | |
| case 2 => 2 | |
| case 3 => 4 |
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 scala.collection.mutable.ArrayDeque | |
| // https://atcoder.jp/contests/abc032/tasks/abc032_c | |
| // 長さ n の非負整数列 A={a1,a2,...,an} の連続部分列で、その要素の積が K 以下となるものの長さの最大値を求める | |
| // 長さは 1 以上でなければならない. | |
| // 例外ケースは 0 を返す | |
| def program( | |
| data: Array[Int], | |
| k: Int, | |
| l: Int = 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
| import scala.collection.mutable.ArrayDeque | |
| // https://atcoder.jp/contests/abc032/tasks/abc032_c | |
| // 長さ n の非負整数列 A={a1,a2,...,an} の連続部分列で、その要素の積が K 以下となるものの長さの最大値を求める | |
| // 長さは 1 以上でなければならない. | |
| // 例外ケースは 0 を返す | |
| def program( | |
| data: Array[Int], | |
| k: Int, | |
| l: Int = 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
| import scala.collection.immutable.NumericRange | |
| import $ivy.`me.shadaj::scalapy-core:0.5.1` | |
| import $ivy.`ai.kien::python-native-libs:0.2.1` | |
| import me.shadaj.scalapy.py | |
| import me.shadaj.scalapy.readwrite.Reader | |
| import me.shadaj.scalapy.interpreter.Platform | |
| import me.shadaj.scalapy.py.SeqConverters | |
| import me.shadaj.scalapy.interpreter.PyValue | |
| import ai.kien.python.Python |
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 scala.collection.immutable | |
| import org.http4s.Media | |
| import org.http4s.DecodeResult | |
| import org.http4s.MediaRange | |
| import org.http4s.EntityDecoder | |
| import org.http4s.Uri | |
| import org.http4s.LiteralSyntaxMacros | |
| import org.http4s.Method | |
| import org.http4s.Request | |
| import $ivy.`org.http4s::http4s-dsl:1.0.0-M30` |