Skip to content

Instantly share code, notes, and snippets.

@DavidBechtel
DavidBechtel / FizzBuzz.R
Created February 3, 2013 19:04
FizzBuzz application written in R
FizzBuzz <- function(M)
{
for (intL in 1:M)
{
if (intL %% 15 == 0) print("FizzBuzz")
else
if (intL %% 5 == 0) print("Buzz")
else
if (intL %% 3 == 0) print("Fizz")
else
@DavidBechtel
DavidBechtel / presents_spec.rb
Created January 24, 2013 21:11
presents rspec test file
#presents_spec file
require './fizzbuzz_generator'
require './presents'
describe Presents, "#new" do
context 'as_text for output format'
it "returns fizzbuzz for numbers 1 through 15 in an array" do
p = Presents.new(FizzBuzzGenerator.new(15))
p.as_text.should eq(["1 ","2 ","3 fizz ","4 ","5 buzz ","6 fizz ","7 ","8 ","9 fizz ","10 buzz ","11 ","12 fizz ","13 ","14 ","15 fizzbuzz "])
@DavidBechtel
DavidBechtel / fizzbuzz_generator.rb
Created January 24, 2013 21:11
fizzbuzz generator creates an array with the input value as the upper limit
# FizzBuzz_Generator.rb
require 'json'
require 'rspec'
class FizzBuzzGenerator < Array
def initialize(high_value = 0)
@highest_value = high_value.to_i
# Error test
self << "Zero, negative numbers, strings that describe a number, and nil not supported" if (@highest_value <= 0)
@DavidBechtel
DavidBechtel / presents.rb
Created January 24, 2013 21:10
presents as a single responsibility class
require "json"
class Presents < Struct.new(:ary)
def as_text
ary.each do |line|
puts line
end
end
def as_json
@DavidBechtel
DavidBechtel / appfizz.rb
Created January 24, 2013 01:26
adaptation of Bill Gathen's sinatra code
require 'sinatra'
require './fizzbuzz_generator'
require './presents'
get '/' do
<<EOF
<html>
<body>
<h1>FizzBuzz!</h1>
<form method="post">
@DavidBechtel
DavidBechtel / fizzbuzz_generator_spec.rb
Created January 23, 2013 16:51
fizzbuzz rspec test file
# fizz buzz generator spec
require './fizzbuzz_generator'
describe FizzBuzzGenerator, "#new" do
context 'given 15 as an input'
it "returns fizzbuzz for numbers 1 through 15 in an array" do
fizzbuzz = FizzBuzzGenerator.new(15)
fizzbuzz.should eq(["1 ","2 ","3 fizz ","4 ","5 buzz ","6 fizz ","7 ","8 ","9 fizz ","10 buzz ","11 ","12 fizz ","13 ","14 ","15 fizzbuzz "])
end
@DavidBechtel
DavidBechtel / fizzbuzz_generator.rb
Created January 23, 2013 16:41
fizzbuzz_generator Class based with print, html and json output
# FizzBuzz_Generator.rb
require 'json'
require 'rspec'
class FizzBuzzGenerator
def initialize(high_value = 0)
@highest_value = high_value.to_i
end
def generate
@DavidBechtel
DavidBechtel / fizzbuzz.rb
Created January 22, 2013 22:10
fizzbuzz Ruby style
#!/usr/bin/env ruby -wKU
require 'json'
require 'rspec'
class FizzBuzzGenerator
def initialize(inp)
@number = inp
end