From d51959eda01b2918cda0405a2cbd523b6c50cb18 Mon Sep 17 00:00:00 2001 From: AJ ONeal Date: Sat, 26 Jun 2010 10:54:40 -0600 Subject: [PATCH] Yay for FizzBuzz! --- README | 9 +++++++++ fibonacci.js | 16 ++++++++++++++++ fizzbuzz.js | 21 +++++++++++++++++++++ fizzbuzz.rb | 6 ++++++ hello.js | 6 ++++++ 5 files changed, 58 insertions(+) create mode 100644 README create mode 100755 fibonacci.js create mode 100755 fizzbuzz.js create mode 100755 fizzbuzz.rb create mode 100755 hello.js diff --git a/README b/README new file mode 100644 index 0000000..aea6f1d --- /dev/null +++ b/README @@ -0,0 +1,9 @@ +FizzBuzz +======== + +An array of the usual suspects - Hello World, FizzBuzz, Fibonacci, more to come... + +TODO +---- + * Echo Client / Server + * Ajax Chat diff --git a/fibonacci.js b/fibonacci.js new file mode 100755 index 0000000..83e4b07 --- /dev/null +++ b/fibonacci.js @@ -0,0 +1,16 @@ +#!/usr/bin/env node +"use strict"; +var sys = require('sys'); +(function () { + var seq = []; + function fibonacci(a, b) { + seq.push(a); + if (a >= 100) { + seq.push(b); + return; + } + fibonacci(b, a+b); + } + fibonacci(0,1); + sys.print(seq.join(', ') + "\n"); +}()); diff --git a/fizzbuzz.js b/fizzbuzz.js new file mode 100755 index 0000000..93c89da --- /dev/null +++ b/fizzbuzz.js @@ -0,0 +1,21 @@ +#!/usr/bin/env node +"use strict"; +var sys = require('sys'); +(function () { + var i, n; + for (i = 1; i <= 100; i += 1) { + n = false; + + if (0 === (i % 3)) { + n = true; + sys.print("Fizz"); + } + if (0 === (i % 5)) { + n = true; + sys.print("Buzz"); + } + if (true === n) { + sys.print("\n"); + } + } +}()); diff --git a/fizzbuzz.rb b/fizzbuzz.rb new file mode 100755 index 0000000..735ce25 --- /dev/null +++ b/fizzbuzz.rb @@ -0,0 +1,6 @@ +#!/usr/bin/env ruby +(1..100).each do |x| + print "Fizz" if 0 == (x % 3) + print "Buzz" if 0 == (x % 5) + print "\n" if 0 == (x % 3) || 0 == (x % 5) +end diff --git a/hello.js b/hello.js new file mode 100755 index 0000000..6b5089a --- /dev/null +++ b/hello.js @@ -0,0 +1,6 @@ +#!/usr/bin/env node +"use strict"; +var sys = require('sys'); +(function () { + sys.print("Hello World!\n"); +}());