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
-- Answer of Eular Problem 3 "Largest prime factor" | |
answer :: IO () | |
answer = print $ largePrimeFactorOf 600851475143 | |
largePrimeFactorOf :: Int -> Int | |
largePrimeFactorOf x = largePrimeFactorOf' x 0 | |
largePrimeFactorOf' :: Int -> Int -> Int | |
largePrimeFactorOf' x primeidx = |
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
;; Answer of Eular Problem 3 "Largest prime factor" | |
(defn primes [] | |
(letfn | |
[(primes [p ns] | |
(let [ns (filter #(not= (rem % p) 0) ns)] | |
(lazy-seq (cons p (primes (first ns) ns)))))] | |
(primes 2 (iterate inc 2)))) | |
(defn largePrimeFactorOf [x] |
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
-module(eularProblem3). | |
-export([answer/0]). | |
%% Answer of Eular Problem 3 "Largest prime factor" | |
answer() -> largePrimeFactorOf(600851475143). | |
largePrimeFactorOf(X) -> largePrimeFactorOf(X, primes(numRange(2, math:sqrt(X)))). | |
largePrimeFactorOf(X, [P|PS]) -> | |
if X == 1 -> P; |
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
-- Answer of Eular Problem 3 "Largest prime factor" | |
answer :: IO () | |
answer = print $ largePrimeFactorOf 600851475143 | |
largePrimeFactorOf :: Int -> Int | |
largePrimeFactorOf x = largePrimeFactorOf' x primes | |
largePrimeFactorOf' x primes@(p:ps) | |
| x == 1 = p |
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
-module(eularProblem3). | |
-export([answer/0]). | |
%% Answer of Eular Problem 3 "Largest prime factor" | |
answer() -> largePrimeFactorOf(600851475143). | |
largePrimeFactorOf(X) -> largePrimeFactorOf(X, 2). | |
largePrimeFactorOf(X, P) -> |
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
;; 8-Queens solver program | |
;; see) http://newral.info/publics/index/79 | |
;; colum No.14 - No.18 | |
(def board-size 8) | |
(defn on-board? [[row col]] | |
(and (>= row 1) (<= row board-size) (>= col 1) (<= col board-size))) | |
(defn unique-row? [[row _] queens] |
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
(* Snake Game by OCaml *) | |
(* see) http://newral.info/publics/index/79 *) | |
(* column No.19 - No.23 *) | |
let cls () = print_string "\x1B[2J";; | |
let set_pos (x,y) = | |
print_string ("\x1b[" ^ string_of_int y ^ ";" ^ string_of_int x ^ "H");; | |
let show_board () = |
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
module Tetris (main) where | |
import Graphics.UI.Gtk | |
import Graphics.UI.Gtk.Gdk.GC | |
import Control.Monad.Trans (liftIO) | |
import Control.Monad (forM_) | |
-- テトリスのブロックを表す型 (EはEmpty, Gはボード周囲の番兵用) | |
data Block = I | O | S | Z | J | L | T | E | G deriving (Show, Eq) | |
-- ボードを表す型 |
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
module Tetris (main) where | |
import Graphics.UI.Gtk | |
import Graphics.UI.Gtk.Gdk.GC | |
import Control.Monad.Trans (liftIO) | |
import Control.Monad (forM_, when) | |
import Data.Text (unpack) | |
import Data.IORef | |
import System.Random (randomR, getStdRandom) | |
-- ゲーム状態を表す型 |
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
%% SameGame solver by Prolog | |
%% +-+-+-+ +-+-+-+ +-+-+-+ +-+-+-+ | |
%% |g|b|r| | | |r| | | | | | | | | | |
%% +-+-+-+ +-+-+-+ +-+-+-+ +-+-+-+ | |
%% |g|g|r| -> | |b|r| -> | |r| | -> | | | | | |
%% +-+^+-+ +-+-+-+ +-+-+-+ +-+-+-+ | |
%% |r|b|b| |r|b|b| |r|r| | | | | | | |
%% +-+-+-+ +-+-+^+ +^+-+-+ +-+-+-+ |
OlderNewer