Skip to content

Instantly share code, notes, and snippets.

🤔
:thinking_face:

Kamiya kamiyaowl

🤔
:thinking_face:
Block or report user

Report or block kamiyaowl

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
View Haiku.scala
println(((s:String) => s.drop(5 + 7).take(5).zip(s.drop(5).take(7)).zip(s.take(5)).map{case ((a,b),c) => s"$a $b $c"}.++(s.drop(5 + 5).take(2).map{x => s" $x"}).mkString("\r\n"))("なかぬならなかせてみようホトトギス"))
View Haiku.cs
// C# : @kamiya_owl
using System; using System.Linq; class Haiku { static void Main() { var haiku = @"
          み か ふ
          ず わ る
          の ず い
          お と け
View Prime.scala
def prime(src:Stream[Int]) : Stream[Int] = src.headOption match {
case None => Stream.empty
case Some(n) => n #:: prime(src.tail.filter(_ % n != 0))
}
def prime() : Stream[Int] = prime(Stream.from(2,1))
prime.take(10000).foreach(println)
View FizzBuzz.scala
/**
* Created by kamiya on 2015/02/24.
* libraryDependencies += "org.scala-lang" % "scala-compiler" % scalaVersion.value
*/
import scala.reflect.runtime.currentMirror
import scala.tools.reflect.ToolBox
object FizzBuzz {
class TraitCreator(name:String,const:String,superClass:String = "AnyRef") {
def make(n:Int = 1) : Stream[String] =
View c2bflog
"C:\Program Files\Java\jdk1.7.0_67\bin\java" -agentlib:jdwp=transport=dt_socket,address=127.0.0.1:21948,suspend=y,server=n -Dfile.encoding=UTF-8 -classpath "C:\Program Files\Java\jdk1.7.0_67\jre\lib\charsets.jar;C:\Program Files\Java\jdk1.7.0_67\jre\lib\deploy.jar;C:\Program Files\Java\jdk1.7.0_67\jre\lib\javaws.jar;C:\Program Files\Java\jdk1.7.0_67\jre\lib\jce.jar;C:\Program Files\Java\jdk1.7.0_67\jre\lib\jfr.jar;C:\Program Files\Java\jdk1.7.0_67\jre\lib\jfxrt.jar;C:\Program Files\Java\jdk1.7.0_67\jre\lib\jsse.jar;C:\Program Files\Java\jdk1.7.0_67\jre\lib\management-agent.jar;C:\Program Files\Java\jdk1.7.0_67\jre\lib\plugin.jar;C:\Program Files\Java\jdk1.7.0_67\jre\lib\resources.jar;C:\Program Files\Java\jdk1.7.0_67\jre\lib\rt.jar;C:\Program Files\Java\jdk1.7.0_67\jre\lib\ext\access-bridge-64.jar;C:\Program Files\Java\jdk1.7.0_67\jre\lib\ext\dnsns.jar;C:\Program Files\Java\jdk1.7.0_67\jre\lib\ext\jaccess.jar;C:\Program Files\Java\jdk1.7.0_67\jre\lib\ext\localedata.jar;C:\Program Files\Java\jdk1.7.0_67\jre\li
@kamiyaowl
kamiyaowl / ImplParamTest.scala
Last active Aug 29, 2015
implicit patrameter <<<< default parameter
View ImplParamTest.scala
def hoge(implicit str:String = "default", num:Int = 0) = println(str,num)
implicit val str2 = "implicit str2"
implicit val num2 = 123
hoge()//(default,0)
hoge(str2,num2)//(implicit str2,123)
hoge(str2)//(implicit str2,0)
hoge(num = 456)//(default,456)
hoge(str = str2)//(implicit str2,0)
View FizzBuzz.scala
def fizz (x:Int) : (Int, Boolean) = x match { case _ if x % 3 == 0 => (x,true) ; case _ => (x,false) }
def buzz (x:((Int, Boolean))) : (Int, Boolean, Boolean) = x._1 match { case n if n % 5 == 0 => (x._1, x._2,true) ; case _ => (x._1,x._2,false) }
def fizzbuzz(x:((Int,Boolean,Boolean))) : String = x match {
case (_, true, true) => "FizzBuzz"
case (_, true, false) => "Fizz"
case (_, false, true) => "Buzz"
case (n,_,_) => n.toString
}
implicit class FizzBuzz[A](self:A) {
def fizz(x:Any) = self
View BrainfuckProcessor.scala
/**
* Created by kamiya on 2015/02/16.
*/
package kamiya.parse.brainfuck
import scala.util.parsing.combinator.RegexParsers
class BrainfuckProcessor {
private var pt : Int = 0
private var buf : Array[Char] = Array.fill[Char](3000)(0)
View Lifegame.scala
def Y[A,B]( f:((A => B), A ) => B, x:A ):B = f( (y:A) => Y(f,y),x)
((size:(Int,Int)) => Y(
(f:Map[(Int,Int),Boolean] => Stream[Map[(Int,Int),Boolean]], seed:Map[(Int,Int),Boolean]) =>
((curr : Map[(Int,Int),Boolean]) => Stream.cons(curr,f(curr))) {
( for (x <- 0 to size._1; y <- 0 to size._2) yield List(
seed.get(x - 1, y - 1), seed.get(x, y - 1), seed.get(x + 1, y - 1), seed.get(x - 1, y), seed.get(x + 1, y), seed.get(x - 1, y + 1), seed.get(x, y + 1), seed.get(x + 1, y + 1))
count { case Some(z) => z; case None => false }
match { case z if !seed(x, y) && z == 3 => (x, y) -> true ; case z if seed(x, y) && (z == 2 || z == 3) => (x, y) -> true ; case _ => (x, y) -> false }
).toMap },
((s:(Int,Int)) => { for(x <- 0 to size._1 ; y <- 0 to size._2) yield (x,y) -> util.Random.nextBoolean }.toMap)(size)
@kamiyaowl
kamiyaowl / Main.scala
Last active Aug 29, 2015
簡易数式パーサ
View Main.scala
/**
* Created by kamiya on 2015/02/11.
*/
import util.parsing.combinator._
object Main {
class Expr
class Literal extends Expr
case class ConstNumber[+A](num: A) extends Literal
You can’t perform that action at this time.