This file contains 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 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 |
This file contains 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
/** | |
* 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) |
This file contains 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 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) |
This file contains 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
/** | |
* 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 |
This file contains 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
using System; | |
using System.Collections.Generic; | |
using System.Linq; | |
using System.Linq.Expressions; | |
using System.Text; | |
using System.Threading.Tasks; | |
namespace ConsoleApplication3 { | |
class Program { | |
static void Main(string[] args) { |
This file contains 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
using System; | |
using System.Linq; | |
namespace ConsoleApplication1 { | |
class Program { | |
static void Main(string[] args) { | |
var f = new[] { 0xff, 0x80, 0x80, 0xf0, 0x80, 0x80, 0x80, 0x80 }; | |
var i = new[] { 0xe0, '@', '@', 0x40, '@', '@', '@', 0xe0 }; | |
var z = new[] { 0xff, 0x02, 0x04, 0x08, 0x10, ' ', '@', 0xff }; |
This file contains 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
using System; | |
using System.Collections.Generic; | |
using System.Linq; | |
using System.Text; | |
using System.Threading.Tasks; | |
namespace ConsoleApplication3 { | |
class Program { | |
static void Main(string[] args) { | |
var src = LinqExtension.RandomSource(10).Take(10).ToArray(); |
This file contains 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
.assembly extern mscorlib {} | |
.assembly fizzbuzz {} | |
.method static void Main() cil managed { | |
.entrypoint | |
.maxstack 2 | |
.locals init (int32 i, int32 n) | |
ldc.i4 1 | |
ldstr "fizzbuzz max>" |
This file contains 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
const uint8_t sw_out = 9; | |
uint16_t target_value = 1023; | |
const uint8_t segments_pin[] = {0, 1, 2, 3, 4, 5, 6}; | |
const uint8_t orders_pin[] = {A4, A3, A2, A1, 13, 12, 11, 10}; | |
const uint8_t segments_count = 7; | |
const uint8_t orders_count = 8; | |
const uint8_t segment_data[] = { | |
0b11111100,//0 | |
0b01100000,//1 |
This file contains 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 src : Stream[(Double,Double)] = (util.Random.nextDouble, util.Random.nextDouble) #:: src | |
def monte(n:Int) : Double = {src take n map(x => x._1 * x._1 + x._2 * x._2) count (_ < 1.0) } / n.toDouble * 4 | |
println(monte(1000)) |