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
package com.zaneli.parser | |
import java.net.{URI, URISyntaxException, URLEncoder} | |
import scala.io.Codec | |
import scala.util.control.Exception | |
import scala.util.parsing.combinator.RegexParsers | |
object URIParser extends RegexParsers { | |
override val skipWhitespace = false |
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
package com.zaneli | |
import scalikejdbc._ | |
import scalikejdbc.config.DBs | |
import scala.concurrent.{Await, Future} | |
import scala.concurrent.ExecutionContext.Implicits.global | |
import scala.concurrent.duration.Duration | |
object Main extends App { |
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
extern crate getopts; | |
use std::env; | |
use std::io; | |
use std::io::BufReader; | |
use std::io::prelude::*; | |
use std::fs::File; | |
use getopts::Options; | |
fn main() { |
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
#!/usr/bin/env stack | |
-- stack --install-ghc runghc --package turtle | |
import Turtle | |
main = hostname >>= echo |
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
(declare my-primes) | |
(defn my-goldbach | |
"Goldbach's conjecture." | |
[n] | |
(if (or (odd? n) (== n 2)) | |
nil | |
(loop [ps (my-primes n)] | |
(let [[p' & ps'] ps, m (first (drop-while #(> n (+ % p')) ps))] | |
(if (and (not (nil? m)) (== (+ p' m) n)) |
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
main = do triangle <- readFile "triangle.txt" | |
print $ maximumPath $ map toInts $ reverse $ lines triangle | |
maximumPath :: (Ord a, Num a) => [[a]] -> a | |
maximumPath nss = head $ foldl1 (zipWith (+) . largerList) nss | |
toInts :: String -> [Int] | |
toInts line = map read $ words line | |
largerList :: Ord b => [b] -> [b] |
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
(declare my-prime-factors-mult count-quot) | |
(defn my-totient-phi-improved | |
"Calculate Euler's totient function phi(m) (improved)." | |
[m] | |
(reduce * (map (fn [[p m]] (* (dec p) (Math/pow p (dec m)))) (my-prime-factors-mult m)))) | |
(defn my-prime-factors-mult | |
"Determine the prime factors of a given positive integer (2)." | |
[n] |
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
(declare my-coprime? my-gcd) | |
(defn my-totient-phi | |
"Calculate Euler's totient function phi(m)." | |
[m] | |
(count (filter #(my-coprime? m %) (range 1 m)))) | |
(defn my-coprime? | |
"Determine whether two positive integer numbers are coprime." | |
[n m] |
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 Data.List (unfoldr) | |
main = print $ length $ filter (odd . length . snd . sqrts) [1..10000] | |
sqrts :: Integer -> (Integer, [Integer]) | |
sqrts n | m^2 == n = (n, []) | |
| otherwise = (m, unfoldr f $ (1, -m, Nothing)) | |
where | |
m = truncate $ sqrt $ fromInteger n | |
f (x, y, Just z) | (x, y) == z = Nothing |
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
(defn my-prime? | |
"Determine whether a given integer number is prime." | |
([n] | |
(cond | |
(<= n 1) false | |
(== n 2) true | |
(== (rem n 2) 0) false | |
(some #(== (rem n %) 0) (range 3 (inc (Math/sqrt n)) 2)) false | |
:else true))) |
NewerOlder