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
  • 03:27 (UTC -05:00)
View GitHub Profile
@MikeMKH
MikeMKH / Program.cs
Created January 4, 2017 12:40
FizzBuzz kata in C# using .Net Core with macOS
using System;
using System.Collections.Generic;
namespace ConsoleApplication
{
public class Program
{
public static void Main(string[] args)
{
var values = new List<int> { 2, 3, 4, 5, 6, 10, 15, 45 };
@MikeMKH
MikeMKH / roman-numerals.rkt
Created September 23, 2016 11:37
Roman Numeral kata in Racket using foldl
#lang racket
(require rackunit rackunit/text-ui)
(define (string-repeat n s)
(string-append* (make-list n s)))
(define (romanize-map n)
(let ([arabic->roman
(list (cons 1000 "M") (cons 900 "CM")
(cons 500 "D") (cons 400 "CD")
@MikeMKH
MikeMKH / fizz-buzz.rkt
Created September 16, 2016 11:44
FizzBuzz kata in Racket
#lang racket
(require rackunit rackunit/text-ui)
(define (map-orelse pred val d)
(lambda (x)
(if (pred x) val d)))
(define (divisible-by? d)
(lambda (x)
(zero? (modulo x d))))
@MikeMKH
MikeMKH / prime-factors.rkt
Created September 14, 2016 11:36
Prime Factors kata in Racket using recursion
#lang racket
(require rackunit rackunit/text-ui)
(define (prime-factors n)
(define (factors acc canidate x)
(if (equal? 1 x)
(reverse acc)
(if (zero? (modulo x canidate))
(factors (cons canidate acc) canidate (quotient x canidate))
(factors acc (add1 canidate) x))))
@MikeMKH
MikeMKH / coin-changer.rkt
Last active September 9, 2016 11:37
Coin Changer kata in Racket using List Comprehension
#lang racket
(require rackunit rackunit/text-ui)
(define (change-for coins amount)
(for/list ([coin coins])
(if (zero? amount)
0
(let ([change (quotient amount coin)])
(set! amount (remainder amount coin))
change))))
@MikeMKH
MikeMKH / prime-factors.rkt
Created August 31, 2016 11:36
Prime Factors kata in Racket using recursion
#lang racket
(require rackunit rackunit/text-ui)
(define (prime-factors n)
(define (factors result n value)
(cond
[(<= n 1) (reverse result)]
[(zero? (modulo n value)) (factors (cons value result) (/ n value) value)]
[else (factors result n (add1 value))]))
(factors '() n 2))
@MikeMKH
MikeMKH / speaking.md
Last active September 27, 2017 17:06
A running list of my public speaking
@MikeMKH
MikeMKH / guessing.rkt
Created August 24, 2016 11:38
Guessing game from Realm of Racket
#lang racket
(require rackunit rackunit/text-ui)
(define (guess upper lower)
(quotient (+ upper lower) 2))
(define (smaller upper lower)
(guess
(max lower
@MikeMKH
MikeMKH / fizz-buzz.rkt
Created August 23, 2016 11:37
FizzBuzz kata in Racket using cond
#lang racket
(require rackunit rackunit/text-ui)
(define (fizz-buzz n)
(cond
[(zero? (modulo n 15)) "fizzbuzz"]
[(zero? (modulo n 3)) "fizz"]
[(zero? (modulo n 5)) "buzz"]
[else (number->string n)]))
@MikeMKH
MikeMKH / App.config
Created August 19, 2016 11:34
Coin Changer kata in F# using List.mapFold
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="FSharp.Core"
publicKeyToken="b03f5f7f11d50a3a"
culture="neutral"/>
<bindingRedirect oldVersion="4.3.1.0"
newVersion="4.4.0.0"/>