Question of Coding

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 7

Question:

I want to do pseudocode for logic 3

Workshop Details
Constraints and Rules

• Your flashlight battery has only 3 hours of life


• All hallways are forty (40) steps longAPS145 Applied Problem Solving

Page | 2

• Each "[Move]" unit is 10 steps in distance and takes 5 minutes in time


• You must "[CheckRoom]" after each "Move" command until you decide to "[TurnAround]"
• You can only travel in the forward direction
• At the end of a hallway, you must make a decision to turn left or right (use "[ChangeDirection]")
Note: This is an endless labyrinth with no known end - each hallway offers two directions at each
end!
• You can't make the same direction change twice in a row (example: at the end of hallway 1, you
turn left... then at the end of hallway 2, you MUST turn right)
• You must track your moves to know when you are at the end of a hallway (and when to make a
directional change)
• You can only call the "[TurnAround]" command ONCE (this marks the beginning of your return
back
to the beginning).
• You can call the "[TurnAround]" command at any time but it should only be done when you have
maximized the use of your flashlight battery and can return safely to the beginning
• On the return back to the beginning, you must successfully reverse navigate your recorded journey
and before the flashlight battery dies.
• You can't "[CheckRoom]" to explore rooms when you are on your return journey back to the
beginning.

Navigation "Action" Sub-processes

[Move] Moves forward one unit:

 "Time" is incremented by 5 minutes


 "Distance" is incremented by 10 steps

[CheckRoom] This process should be called after each "Move" action (only when exploring). If there
is
a room at the current location, it is explored and the time taken to explore the room is
returned (in minutes). Note: if there was no room, zero is returned
Expected Logic
- Determine which sub-process to call based on the output from of the black box sub-
process [RandomSearch] which will return A, B, or X (do not define the black box
process, just know you will get a random character output):

Evaluate the [RandomSearch] black box output


A: Return the value generated by the call to sub-process [ExploreRoom-A]
▪ See details for this process later in this document
B: Return the value generated by the call to sub-process [ExploreRoom-B]
▪ See details for this process later in this document
X: Return zero (no room to explore)

[ChangeDirection] Rotates your direction 90 degrees (left or right) in-place without affecting
distance or time. The output will always be opposite the input value (example: if
[L]eft is the input, the output should be [R]ight.

[TurnAround] Rotates your direction 180 degrees in-place (without affecting distance or time)
APS145 Applied Problem Solving

Page | 3

Expected Logic
- Call [ChangeDirection] twice in sequence providing the same input value (either "L"
or "R")
- There is no need to store the output value generated by the [ChangeDirection] sub-
process call

Other Important Details...

Each room you discover will take an unknown/variable number of minutes (based on what lies
within).
Track room exploration time separately from travel/distance time. You will need to develop a
tracking
method to store each room duration and use this information to calculate predictive estimates in the
determination of whether you can risk further exploration time or should turn around and return to
safety before your flashlight power runs out.

To help you accomplish these estimates, you should apply the following logic:
1. Maintain an ongoing average room exploration time (recalculate after each room exploration)
2. Keep track of the longest time spent in a room (this will represent the worst-case scenario based on
actual data)
3. Apply a pessimistic risk factor in predicting the next room exploration time by adding both the
average room exploration time with the room that took the longest time. This estimated time
should be used in the assessment of whether further exploration is possible.
4. You must also factor the time required to return to safety (distance traveled).

Note: When returning, no room explorations can be performed so the time is based purely on the
traveled distance (result of a "[Move]" command).
ExploreRoom-A
Congratulations you found a room that will provide you with some much-needed fun time playing
"Tic-
Tac-Toe"! Use the small dedicated handheld "Tic-Tac-Toe" game machine and enjoy!

Tic-Tac-Toe is a game comprised of a board of 3 squares by 3 squares. This is a 2-player game of


which
you will be "Player-1" (Player-2 will be the game machine). The rules are simple, each player uses
their
own unique identifier ("X" or "O") and places their identifier in one of the empty squares. Turns are
alternated until all squares are filled OR when a winner can be declared. The objective is to get 3
matching squares in sequence either horizontally, vertically, or diagonally. The best of 3 games must
be played to determine the winner.

Black Box Processes you can use


• There are 4 black box processes you can use to simulate the playing of the game.
o RandomBinary - returns a 1 or a 2 which can be used to determine which player should
go first.
o MakeMove(Player n) - performs strategy and makes a move for player n (1 or 2) and
places an X or O on the board such that it will block the opponent winning and attempt
to win for player n.APS145 Applied Problem Solving

Page | 4

o CheckWinner - this will check the board for a winner and return 0 if no winner yet, 1 if
player 1 wins, 2 if player 2 wins or 3 if there is a tie.
o ClearBoard - removes all X's and O's from the board to prepare for a new game

Constraints

• Determine who starts the first game by calling a black box [RandomBinary] process that returns
a number (1 or 2). Do not define the black box process, just know you will get a random
number output:
o 1: means Player-1 starts
o 2: means Player-2 starts
• Each subsequent game's starting player will be whoever won the previous game or, if a tie, then
the player who did not start last time
• Each player move adds 1 minute to the explored time
• Each tied game adds another 2 minutes to the explored time
• Each game you lose (Player-1), 5 minutes is added to the explored time
• The OUTPUT returned by this process is the total time accumulated to play all three games.

ExploreRoom-B
Congratulations you found another room that will provide you with some much-needed fun time
playing "Hang-Person" (formerly known as "Hangman")! Use the small dedicated handheld "Hang-
Person" game machine and enjoy!

This game requires 1 player. The game begins when a random generated hidden secret word
(between 5 and 15 characters) is chosen by the game logic. You are shown a series of underscore
characters (underlines) that represent the hidden characters of the secret word. You must guess
letters one at a time in an attempt to reveal/show as many matching letters in the secret word as you
can. If you can correctly guess the word you win otherwise, you lose!

Black Box Processes you can use


• RandomWord - generates a random 5-15 letter word to be guessed.
• Guess - guesses a letter in the word using artificial intelligence to find a match. If it guesses a
letter correctly, it returns 1 or -1 if the letter is wrong. If it guesses a letter which completes the
word, it returns 0.
• ShouldSolve - uses AI to compute the probability that you can successfully solve for the correct
word. Returns 1 is there is a high probability of solving the word and 0 if there is a low
probability.
• Solve - attempts to guess the solution to the word using AI. It returns 1 on success and 0 on
failure.
Constraints

• You can call RandomWord to create a word to guess and then call Guess and/or Solve until you
guess the word or run out of guesses.APS145 Applied Problem Solving

Page | 5

• You have a maximum of 10 letter guesses


• Each letter guess that matches a letter in the secret word will add 1 minute of explore time
• Each letter guess that does not match a letter in the secret word will add another 2 minutes to
the explore time. If a letter guess solves the word, then 5 minutes is added to the explore time.
• You can attempt to solve (identify) the secret word at any time
• If you incorrectly guess at the secret word, 10 minutes is added to your explore time
• If you successfully identify the secret word, you win! Only 5 minutes is added to the explore
time.
• If you run out of letter guesses and can't identify the secret word, you lose! Another 10
minutes is added to the explore time
• The OUTPUT returned by this process is the total time accumulated to play the game.

Your Task [Logic 1] the logic for Room A which will return the time it took to explore Room A.
[Logic 2] the logic for Room B which will return the explore time for the room.
[Logic 3] the main logic for exploring the dungeon (including returning to the starting point) which
will
invoke logic 1 or logic 2 when it needs to explore room A or room B.

Answer:
Hello I have here the answer for your query. Please be guided below. Thanks!

from typing import Callable

from sqlalchemy.orm.attributes import InstrumentedAttribute

from python_rules.rule_type.constraint import Constraint


from python_rules.rule_type.copy import Copy
from python_rules.rule_type.count import Count
from python_rules.rule_type.formula import Formula
from python_rules.rule_type.row_event import EarlyRowEvent, RowEvent, CommitRowEvent
from python_rules.rule_type.sum import Sum

class Rule:
"""Invoke these functions to define rules.
Rules are not run as they are defined,
they are run when you issue `session.commit()'.
Use code completion to discover rules.
"""

@staticmethod
def sum(derive: InstrumentedAttribute, as_sum_of: any, where: any = None):
"""
Derive parent column as sum of designated child column, optional where
Example
Rule.sum(derive=Customer.Balance, as_sum_of=Order.AmountTotal,
where=Lambda row: row.ShippedDate is None)
Optimized to eliminate / minimize SQLs: Pruning, Adjustment Logic
"""
return Sum(derive, as_sum_of, where)

@staticmethod
def count(derive: InstrumentedAttribute, as_count_of: object, where: any = None):
"""
Derive parent column as count of designated child rows
Example
Rule.count(derive=Customer.UnPaidOrders, as_count_of=Order,
where=Lambda row: row.ShippedDate is None)
Optimized to eliminate / minimize SQLs: Pruning, Adjustment Logic
"""
return Count(derive, as_count_of, where)

@staticmethod
def constraint(validate: object, as_condition: any = None,
error_msg: str = "(error_msg not provided)", calling: Callable = None):
"""
Constraints declare condition that must be true for all commits
Example
Rule.constraint(validate=Customer, as_condition=lambda row: row.Balance <= row.CreditLimit,
error_msg="balance ({row.Balance}) exceeds credit ({row.CreditLimit})")
"""
return Constraint(validate=validate, calling=calling, as_condition=as_condition,
error_msg=error_msg) # --> load_logic

@staticmethod
def formula(derive: InstrumentedAttribute, calling: Callable = None,
as_expression: Callable = None, as_exp: str = None):
"""
Formulas declare column value, based on current and parent rows
Example
Rule.formula(derive=OrderDetail.Amount,
as_expression=lambda row: row.UnitPrice * row.Quantity)
Unlike Copy rules, Parent changes are propagated to child row(s)
Supply 1 (one) of the following:
* as_exp - string (for very short expressions - price * quantity)
* ex_expression - lambda (for type checking)
* calling - function (for more complex formula, with old_row)
"""
return Formula(derive=derive, calling=calling, as_exp=as_exp, as_expression=as_expression)

@staticmethod
def copy(derive: InstrumentedAttribute, from_parent: any):
"""
Copy declares child column copied from parent column
Example
Rule.copy(derive=OrderDetail.UnitPrice, from_parent=Product.UnitPrice)
Unlike formulas references, parent changes are not propagated to children
"""
return Copy(derive=derive, from_parent=from_parent)

@staticmethod
def early_row_event(on_class: object, calling: Callable = None):
"""
Row Events are Python functions called before logic
Possible multiple calls per transaction
Use: computing foreign keys...
"""
EarlyRowEvent(on_class, calling) # --> load_logic

@staticmethod
def row_event(on_class: object, calling: Callable = None):
"""
Row Events are Python functions called during logic, after formulas/constraints
Possible multiple calls per transaction
Use: recursive explosions (e.g, Bill of Materials)
"""
RowEvent(on_class, calling) # --> load_logic

@staticmethod
def commit_row_event(on_class: object, calling: Callable = None):
"""
Row Events are Python functions called during logic, after formulas/constraints
Example
Rule.commit_row_event(on_class=Order, calling=congratulate_sales_rep)
1 call per row, per transaction
Use: send mail/message
"""
return CommitRowEvent(on_class, calling) # --> load_logic

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy