Hello, Agent Double-Null0111.
Your mission, should you choose to accept it, is to write a pair of tools to help you infiltrate UMBRA (United Minions Being Really Awful) headquarters and retrieve the plans for their latest really awful scheme. There are three tools you will need to carry out this mission.
Each minion has a unique identifier that changes each day and depends on the number of secrets they hold and the number of hours they sleep.
You will need to write a function that takes the day (as an Int) and creates an identifier generating function for the day.
The identifier generating function takes two parameters:
The identifier is calculated by:
Int) to the resultval idGenerator = makeIdGenerator(4)
idGenerator(3, 6)
// => 22
idGenerator(11, 5)
// => 59Once you have the secret plans, you will need to protect it so that only those who know the password can recover them.
In order to do this, you will need to implement the function protectSecret(secret: String, password: String) : (String) -> String.
This function will return another function that takes possible password strings as input.
If the entered password is correct the new function returns the hidden secret, but if the password is incorrect, the function returns "Sorry. No hidden secrets here."
val secretFunction = protectSecret("Steal the world's supply of french fries!", "5up3r53cr37")
secretFunction("Open sesame")
// Returns "Sorry. No hidden secrets here."
secretFunction("5up3r53cr37")
// Returns "Steal the world's supply of french fries!"The UMBRA base has a number of rooms guarded by a security guard who will ask you for the secret password. The secret password depends on the room's number. Unfortunately, we have know only half of the algorithm for working out the password. The other half can be found by asking one of the minions.
Implement the getPassword function that takes in the following and returns the password:
The secret password is obtained by calling the minion's function with another function representing the algorithm known by us. Our part of the algorithm:
val minionFunction = { yourFunc : (Int, Int) -> Int ->
"Password=${yourFunc(1, 3)}"
}
getPassword(5, minionFunction)
// Returns "Password=20"Hello, Agent Double-Null0111.
Your mission, should you choose to accept it, is to write a pair of tools to help you infiltrate UMBRA (United Minions Being Really Awful) headquarters and retrieve the plans for their latest really awful scheme. There are three tools you will need to carry out this mission.
Each minion has a unique identifier that changes each day and depends on the number of secrets they hold and the number of hours they sleep.
You will need to write a function that takes the day (as an Int) and creates an identifier generating function for the day.
The identifier generating function takes two parameters:
The identifier is calculated by:
Int) to the resultval idGenerator = makeIdGenerator(4)
idGenerator(3, 6)
// => 22
idGenerator(11, 5)
// => 59Once you have the secret plans, you will need to protect it so that only those who know the password can recover them.
In order to do this, you will need to implement the function protectSecret(secret: String, password: String) : (String) -> String.
This function will return another function that takes possible password strings as input.
If the entered password is correct the new function returns the hidden secret, but if the password is incorrect, the function returns "Sorry. No hidden secrets here."
val secretFunction = protectSecret("Steal the world's supply of french fries!", "5up3r53cr37")
secretFunction("Open sesame")
// Returns "Sorry. No hidden secrets here."
secretFunction("5up3r53cr37")
// Returns "Steal the world's supply of french fries!"The UMBRA base has a number of rooms guarded by a security guard who will ask you for the secret password. The secret password depends on the room's number. Unfortunately, we have know only half of the algorithm for working out the password. The other half can be found by asking one of the minions.
Implement the getPassword function that takes in the following and returns the password:
The secret password is obtained by calling the minion's function with another function representing the algorithm known by us. Our part of the algorithm:
val minionFunction = { yourFunc : (Int, Int) -> Int ->
"Password=${yourFunc(1, 3)}"
}
getPassword(5, minionFunction)
// Returns "Password=20"