Project 4.2 Scheme Scripts


Intro to Programming Languages.

[ ← Module List ]


Challenges

Objective

Create a Scheme script that creates a function called mathy

Requirements

  • The function math will take in 3 parameters and calculate the result to the following equation
    (a * (a - b + c)) 
  • At the end of the script, it will
    • call mathy with the arguments 4 2 3
    • call mathy with the arguments 8 9 10

Objective

Create an attack calculation from an older Final Fantasy game

Final Fantasy Mystic Quest is often considered the outcast of the Final Fantasy game series. Let’s give it some love…

Requirements

  • Define ffMQ-Damage function, it takes 4 parameters attack, defense, weakness and number of targets
  • The function calculates how much damage is done based on Final Fantasy Mystic Quest’s calculation:
                      ┌ (attack * 4 - defense) * weakness ┐
      damage = floor | --------------------------------- |
                      └             targets               ┘
      
  • The floor function rounds down no matter the real value. (e.g., 3.9 = 3).
  • Standard values (the script does not need to check the ranges)
    • Attack: between 10 and 255
    • Defense: between 1 and 120
    • Weakness: either 1 or 2
    • Targets: between 1 and 3
  • Calls with specific values and the expected results provided in the comments.

Objective

Create another damage calculation function that takes two parameters stat and dmgValue

Requirements

  • Define a function ff10-baseDamage that takes stat and dmgValue
    • Get the stat and dmgVal from the user
    • The calculation is performed using
                              ┌  stat^3       ┐           ┌  dmgVal  ┐
            baseDmg =  floor | -------- + 32 |  *  floor | -------- |
                              └    32         ┘           └    16    ┘
          
    • The code contains some tests you can use

Objective

Recreate the factorial function from class, but adding more capabilities.

Requirements

  • Define the factorial function takes a single integer argument
    • If parameter is negative then return the symbol 'NAN
    • IF parameter is 0 then return 1
    • Use recursion
  • Prompt user with "Enter value: "
  • Get a value from the user
  • Call factorial with user's value

Objective

Create a function that gets the fourth element in a list

Requirements

  • Define a function get-fourth
    • return the value of the 4 element in the list
    • Scheme's lists are 0 based

Objective

Create a script that will receive a filtering letter and a list of space delimited words and then filter out all the words that do not contain the letter

Requirements

  • Prompt and then read in the filtering character first
  • Prompt and read in a list of space delimited words
  • Define a function or number of functions that will remove all the words that do not contain the filtering character
  • print out the new list
  • HINT: Consider using string-contains? and the higher-order filter operator

30-Day Scoreboard:

This scoreboard reflects solves for challenges in this module after the module launched in this dojo.

Rank Hacker Badges Score