Monday, June 1, 2015

Hello I’m V

opl-small

Unique and impressive One Page experiment by front-end developer, Valentin Marmonier, showcasing his newly learnt WebGL skills. (Audio Warning)

by Rob Hope via One Page Love

Algorithmic Fun with Ruby Hashes

All programmers use them. You might call them Maps, Dictionaries, Hash Maps, or Associative Arrays. In the Ruby world, we call them Hashes and they're pretty awesome. A Hash is, simply put, a collection of key-value pairs. It is similar to an Array, except that it is indexed via arbitrary keys of any object type instead of an incremental integer. If you take a look at the Hash API, you'll see that it offers an impressive range of functionality. In this article, we won't be looking at the Hash API as such, but rather at using Hashes to model, abstract, and solve common logic problems.

Truth Tables and Capturing the Algorithm

Many people use Hashes purely as simple data lookup tables or as named parameters to methods. This is all fine, but we can do much more by leveraging Hash's inherent flexibility and powerful features to implement logic and complex algorithms. Let's look at an interviewer's favorite, the FizzBuzz test. It goes like this:

"Write a program that prints the numbers from 1 to 100. For multiples of 3, print “Fizz” instead of the number and for multiples of 5, print “Buzz”. For numbers which are multiples of both 3 and 5, print “FizzBuzz”."

We have two conditions here which affect the outcome: (n % 3 == 0) and (n % 5 == 0). As soon as we grok that, solving the problem is straightforward:

[ruby] def conditional(n) if (n % 3 == 0) && (n % 5 != 0) 'Fizz' elsif (n % 3 != 0) && (n % 5 == 0) 'Buzz' elsif (n % 3 == 0) && (n % 5 == 0) 'FizzBuzz' else n end end [/ruby]

To run FizzBuzz for a sequence of 1 to 100 we do:

[ruby] (1..100).each {|n| puts conditional(n)} [/ruby]

Continue reading %Algorithmic Fun with Ruby Hashes%


by Fred Heath via SitePoint

Style Posts by Category on Your Main Blog Page

Building an App Image to Resell at Digital Ocean

Amorous

Amorous

'Amorous' is an One Page wedding template created for Adobe Muse. The Single Page template comes in two different layouts - classic (fixed top navigation) and modern (off-canvas navigation with subtle parallax header). It is also equipped with features for RSVP and Gift Registry. A clean yet elegant One Page template to plan your wedding and invite your guests.

by Rob Hope via One Page Love

Analytische Grafik

opl-small

Very unique centrally divided layout in this One Pager promoting the 'Analytical Graphics' course at the Academy of Fine Arts in Hamburg.

by Rob Hope via One Page Love

Comic Spurs

opl-small

Lovely texture in this responsive One Pager promoting the (discontinued) 'Comic Spurs' font.

by Rob Hope via One Page Love