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
| object Primes extends App { | |
| def process(A: List[Int], B: List[Int]) = { | |
| def isPrime(n: Int): Boolean = { | |
| if (n == 2) true | |
| else if (n < 2 || n % 2 == 0) false | |
| else Stream.from(3, 2).takeWhile(i => i * i <= n).forall(n % _ != 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 java.text.SimpleDateFormat | |
| import java.util.{Calendar, Date} | |
| object Sessions extends App { | |
| def survey(logs: List[String]): Boolean = { | |
| val formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss") | |
| val dates: List[Date] = logs.map(formatter.parse).sortBy(_.getTime) |
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
| #include "dht11.h" | |
| // There is a timeout if voltage on pin does not change in 10k loop passes time | |
| bool acknowledge(int pin, int mode) { | |
| for(unsigned int loopCnt = 10000; digitalRead(pin) == mode; loopCnt--) { | |
| if (loopCnt <= 0) return false; | |
| } | |
| return true; | |
| } |
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
| defmodule Config do | |
| def get(key, default) do | |
| # Sample config | |
| vars = [key1: :val1, | |
| key2: [nested_key1: :nested_val1, | |
| nested_key2: :nested_val2]] | |
| get(key, vars, default) | |
| end |
OlderNewer