Search

 

Module: Editor

Version: 4.2.1 +

User: Developer

Difficulty: Difficult

Introduction

This exercise teaches you how to construct a multiple nested formula.

 

Prerequisites

- The Futurama Editor must be installed.
- Completing the tutorial Creating formulas with Futurama first, is recommended. 

 

Description

The duration of a solar year is not exactly 365 days, but 365 days, 5 hours, 48 minutes and about 46 seconds. A year therefore should hold 365.2422 days, which is slightly less than 365.25 day. We correct this difference by using a leap day occurring once in the four years.

However, this rule of adding a leap day ‘every’ fourth year overcompensates. (Because 0.2422 x 4 is slightly less than 1).
Therefore we use the rule that a century year is not a leap year unless it is evenly divisible by 400.
So: century years that can be divided by 400 (like 2000) have a leap day. Century years that can't be divided by 400 don't have a leap day (like 1900 and 2100).

Assignment

Create a formula with Futurama that determines if a year is a leap year or not.

This formula should be a boolean that returns the value TRUE if:

(divisible by 4 AND not divisible by 100) OR (divisible by 400)

Use this formula to check if the following years are leap years:

  • 1896
  • 1900
  • 2000
  • 2002
  • 2008
  • 2100

Tips

  • Create a formula IsLeapYear of the type Boolean with an argument Year of the type Long.
  • To determine if a year is divisible by a certain number, you could use the following construction:
    Round down the division of the year and number and compare this to the unrounded division. If they are equal, the year is divisible by the chosen number. If not, the year is not divisible by the number chosen.
  • Use the logical formulas AND and OR to construct the final formula.

Solutions

Answers

  • 1896: TRUE
  • 1900: FALSE
  • 2000: TRUE
  • 2002: FALSE
  • 2008: TRUE
  • 2100: FALSE

Download

image

You can download our solution for this assignment by clicking the image at the right. (Futurama 4.2.1.2)
Please note that you can very well have a different solution that is just as good as ours.

In the download solution, three different solutions are given:

  1. Leap Year - Basic
    This solution holds three different formulas: isDivisibleby4, isDivisibleby400, isNotDivisibleby100  
  2. Leap Year - Advanced
    In this solution, an argument is used to create a generic formula that checkes if a year is divisible by the number. 
  3. Leap Year - Different 
    Different solutions are almost always possible. In this solution we use the fact that Futurama already holds a calendar-functionality. We check if the month february holds 29 days for the given year. If that's the case, the year is a leap year.

Variations

If you want some more practise on this subject, you could try the extra exercises below.
We won't provide a solution for these variations, just consider them as a way to further experiment with Futurama.

  • (Medium:) Try to construct the three different solutions we've given in the download-section
  • (Difficult:) Try to create another different solution using the formula DaysInMonth (type Long).

Updated: 2012-12-10