Skip to content

Instantly share code, notes, and snippets.

#lang racket
(require rackunit)
(define (deep-list-filter pred dls)
(if (null? dls)
null
(let [(first-dls (first dls))
(rest-dls (rest dls))]
(if (list? first-dls)
#lang racket
(require rackunit)
(define (pascal-triangle-number row col)
(if (or (= col 0)
(= col row))
1
(+ (pascal-triangle-number (- row 1) col)
(pascal-triangle-number (- row 1) (- col 1)))))
@trikitrok
trikitrok / Rock-paper-scissorsKata.md
Last active August 29, 2015 14:08
Unconditional Rock-paper-scissors kata

In this kata we'll use TDD to develop an object-oriented solution for the Rock-paper-scissors game.

The catch is that we can't use any conditionals, that is, if, switch, ternary operator or any other type of conditionals are not allowed.

It's an introductory kata which will help you to hone your OO skills.

This would be the initial code in Ruby:

class RockPaperScissors
(ns bowling-game.core-test
(:use midje.sweet)
(:use [bowling-game.core]))
(def a-gutter-game (repeat 20 0))
(def a-no-spares-no-strikes-game
(concat [1 6 4 5 3 1] (repeat 14 0)))
(def a-game-with-spares
(concat [4 6 4 5 3 1] (repeat 14 0)))
(def a-game-with-strikes
fun fizz_buzz num =
let
val remainders = (num mod 3, num mod 5)
in
case remainders of
(0, 0) => "FizzBuzz"
| (0, _) => "Fizz"
| (_, 0) => "Buzz"
| _ => Int.toString(num)
end
(ns berlin_clock.core)
(use '[clojure.string :only (join split)])
(defn- turn-on-red [num-lamps]
(repeat num-lamps "R"))
(defn- turn-on-yellow [num-lamps]
(repeat num-lamps "Y"))
;; The first three lines of this file were inserted by DrRacket. They record metadata
;; about the language level of this file in a form that our tools can easily process.
#reader(lib "htdp-advanced-reader.ss" "lang")((modname balance) (read-case-sensitive #t) (teachpacks ()) (htdp-settings #(#t constructor repeating-decimal #t #t none #f ())))
(check-expect
(balanced-parentheses? "") true)
(check-expect
(balanced-parentheses? "()") true)
#!/usr/bin/perl
use strict;
use warnings;
sub shiftChar {
(my $asciiVal, my $base, my $shift) = @_;
return chr(($asciiVal - $base + $shift) % 26 + $base );
}
; ...
(defn num-neighbors-being-a-cell [cell cells]
(count (filter (neighbors cell) cells)))
(defn has-cell? [loc cells]
(= loc (some #{loc} cells)))
(defn will-have-a-cell? [loc cells]
(let [num-neighbors (num-neighbors-being-a-cell loc cells)]
(def naturals (drop 1 (range)))
(def fizz-buzz-seq
(map #(clojure.string/replace (str %1 %2) #"^$" (str %3))
(cycle '("" "" "Fizz"))
(cycle '("" "" "" "" "Buzz"))
naturals))
(defn fizz-buzz [n]
(clojure.string/join " " (take n fizz-buzz-seq)))