Skip to content

Instantly share code, notes, and snippets.

View MikeMKH's full-sized avatar
:shipit:
Learning about logic programming with Prolog

Mike Harris MikeMKH

:shipit:
Learning about logic programming with Prolog
  • Milwaukee, WI
  • 06:57 (UTC -05:00)
View GitHub Profile
@MikeMKH
MikeMKH / repl.clj
Created January 25, 2015 15:02
A very simple example of Map using an increment function in C# and Clojure.
(map inc [1 2 3 4])
;; [2 3 4 5]
@MikeMKH
MikeMKH / repl.clj
Last active August 29, 2015 14:14
A simple example of summing with a Fold in Clojure and C#.
(reduce
#(+ %1 %2)
[1 2 3 4])
;; 10
@MikeMKH
MikeMKH / repl.clj
Last active August 29, 2015 14:14
A simple example of a Map using a Fold in Clojure and C#.
(reduce
#(conj %1 (inc %2))
[]
[1 2 3 4])
;; [2 3 4 5]
(map
inc
[1 2 3 4])
@MikeMKH
MikeMKH / repl.clj
Created February 1, 2015 18:02
A very simple example of Filter using an isOdd predicate in C# and Clojure
(filter odd? [1 2 3 4])
;; [1 3]
@MikeMKH
MikeMKH / repl.clj
Created February 1, 2015 18:18
A very simple example of a Filter using a Fold in Clojure and C#
(reduce
#(if (odd? %2)
(conj %1 %2)
%1)
[]
[1 2 3 4])
;; [1 3]
(filter
@MikeMKH
MikeMKH / repl.cs
Created March 1, 2015 16:33
Roman Numeral kata in C# as a one-liner for the Mono REPL
Func<int, string> toRoman = (number) =>
new Dictionary<int, string>
{
{1000, "M"},
{ 900, "CM"},
{ 500, "D"},
{ 400, "CD"},
{ 100, "C"},
{ 90, "XC"},
{ 50, "L"},
@MikeMKH
MikeMKH / game.clj
Created March 4, 2015 13:02
http://www.codingame.com/ Onboarding in Clojure
(ns Player
(:gen-class))
(defn -main [& args]
(while true
(let [enemies (doall (repeatedly 2 #(array-map :name (read) :distance (read))))]
(println (->> enemies
(sort-by :distance <)
first
@MikeMKH
MikeMKH / game.clj
Created March 5, 2015 12:55
http://www.codingame.com/ Power of Thor in Clojure
(ns Player
(:gen-class))
(defn -main [& args]
; strongly based on https://github.com/vhennebert/CodinGame/blob/master/2014-02-22_Ragnarok/1_power-of-thor.clj
(let [[lx ly tx ty] (repeatedly 4 read)
x-difference (- lx tx)
x-length (Math/abs x-difference)
x (cond
@MikeMKH
MikeMKH / game.clj
Created March 6, 2015 12:51
http://www.codingame.com/ The Descent in Clojure
(ns Player
(:gen-class))
(defn -main [& args]
(while true
(let [x (read)
h (read)
mountains (repeatedly 8 read)
tallest (apply max mountains)
tallest-index (.indexOf mountains tallest)
@MikeMKH
MikeMKH / game.clj
Created March 9, 2015 12:01
http://www.codingame.com/ Skynet: the Chasm in Clojure
(ns Player
(:gen-class))
(defn -main [& args]
(let [road-length (read)
gap-length (read)
landing-length (read)
gap-jump-length (inc gap-length)]
(while true