Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Oppiskele Challenge: Floor Plan Analyzer | Geometric Computation and Spatial Analysis
Python for Architects

bookChallenge: Floor Plan Analyzer

Understanding how rooms connect within a floor plan is a fundamental part of architectural analysis. You often need to determine which rooms are directly accessible from one another or check if two rooms share a wall or passage. This kind of spatial reasoning can be represented in Python using a dictionary, where each room is mapped to a list of its directly adjacent rooms. This approach allows you to quickly look up connections and perform adjacency checks efficiently.

Suppose you have a floor plan where the room connections are represented as follows: the "Living Room" is adjacent to both the "Kitchen" and the "Hallway", while the "Kitchen" is only adjacent to the "Living Room". By storing this data in a dictionary, you can easily retrieve all rooms connected to a given room and verify if two rooms are neighbors.

Note
Note

You can extend this approach to model more detailed relationships, such as indirect connections, or to visualize the adjacency graph using specialized libraries. For now, focus on direct adjacency as represented by the dictionary structure.

Tehtävä

Swipe to start coding

Write a function named find_adjacent_rooms that takes two arguments: a dictionary representing room adjacencies and a string representing the room name. The function should return the list of rooms directly connected to the specified room.

Then, write a function named check_adjacency that takes three arguments: the adjacency dictionary, and two room names (strings). The function should return True if the rooms are directly adjacent, and False otherwise.

Test your functions using the following adjacency dictionary:

adjacency = {
    "Bedroom": ["Bathroom", "Closet"],
    "Bathroom": ["Bedroom", "Hallway"],
    "Closet": ["Bedroom"],
    "Hallway": ["Bathroom"]
}
  • Print the rooms connected to 'Bathroom'.
  • Print whether 'Bedroom' and 'Closet' are adjacent.
  • Print whether 'Closet' and 'Hallway' are adjacent.

Ratkaisu

Oliko kaikki selvää?

Miten voimme parantaa sitä?

Kiitos palautteestasi!

Osio 2. Luku 3
single

single

Kysy tekoälyä

expand

Kysy tekoälyä

ChatGPT

Kysy mitä tahansa tai kokeile jotakin ehdotetuista kysymyksistä aloittaaksesi keskustelumme

Suggested prompts:

Can you show me how to represent this floor plan as a Python dictionary?

How can I check if two specific rooms are adjacent using this approach?

Can you explain how to add a new room and its connections to the dictionary?

close

bookChallenge: Floor Plan Analyzer

Pyyhkäise näyttääksesi valikon

Understanding how rooms connect within a floor plan is a fundamental part of architectural analysis. You often need to determine which rooms are directly accessible from one another or check if two rooms share a wall or passage. This kind of spatial reasoning can be represented in Python using a dictionary, where each room is mapped to a list of its directly adjacent rooms. This approach allows you to quickly look up connections and perform adjacency checks efficiently.

Suppose you have a floor plan where the room connections are represented as follows: the "Living Room" is adjacent to both the "Kitchen" and the "Hallway", while the "Kitchen" is only adjacent to the "Living Room". By storing this data in a dictionary, you can easily retrieve all rooms connected to a given room and verify if two rooms are neighbors.

Note
Note

You can extend this approach to model more detailed relationships, such as indirect connections, or to visualize the adjacency graph using specialized libraries. For now, focus on direct adjacency as represented by the dictionary structure.

Tehtävä

Swipe to start coding

Write a function named find_adjacent_rooms that takes two arguments: a dictionary representing room adjacencies and a string representing the room name. The function should return the list of rooms directly connected to the specified room.

Then, write a function named check_adjacency that takes three arguments: the adjacency dictionary, and two room names (strings). The function should return True if the rooms are directly adjacent, and False otherwise.

Test your functions using the following adjacency dictionary:

adjacency = {
    "Bedroom": ["Bathroom", "Closet"],
    "Bathroom": ["Bedroom", "Hallway"],
    "Closet": ["Bedroom"],
    "Hallway": ["Bathroom"]
}
  • Print the rooms connected to 'Bathroom'.
  • Print whether 'Bedroom' and 'Closet' are adjacent.
  • Print whether 'Closet' and 'Hallway' are adjacent.

Ratkaisu

Switch to desktopVaihda työpöytään todellista harjoitusta vartenJatka siitä, missä olet käyttämällä jotakin alla olevista vaihtoehdoista
Oliko kaikki selvää?

Miten voimme parantaa sitä?

Kiitos palautteestasi!

Osio 2. Luku 3
single

single

some-alt