Skip to content

Commit

Permalink
[cps] [subway] createSubway
Browse files Browse the repository at this point in the history
  • Loading branch information
xieyuheng committed Aug 24, 2024
1 parent 0c2e20d commit 85220c5
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 4 deletions.
5 changes: 3 additions & 2 deletions TODO.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
[cps] [subway] `createSubway`
[cps] [subway] `defineLine`
[cps] [subway] `defineLine` -- take a ordered list of stations

[cps] [subway] `defineStation`

[cps] [subway] define `bostonSubway`

[cps] [problem-space] [subway] `SubwayProblemSpace` & `createSubwayProblemSpace`
Expand Down
26 changes: 24 additions & 2 deletions src/cps/subway/Subway.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,29 @@
export type Line = string
export type Station = string
export type Position = string


export type Subway = {
lineMap: Map<Line, { stations: Array<Station> }>,
stationMap: Map<Station, { lines: Array<Line> }>,
name: string,
lineMap: Map<
Line,
{
stations: Array<Station>
}
>
stationMap: Map<
Station,
{
lines: Set<Line>
position: Position
}
>
}

export function createSubway(name: string): Subway {
return {
name,
lineMap: new Map(),
stationMap: new Map(),
}
}
2 changes: 2 additions & 0 deletions src/cps/subway/index.ts
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
export * from "./Subway.js"
export * from "./defineLine.js"

Check failure on line 2 in src/cps/subway/index.ts

View workflow job for this annotation

GitHub Actions / build (20.x)

Cannot find module './defineLine.js' or its corresponding type declarations.

Check failure on line 2 in src/cps/subway/index.ts

View workflow job for this annotation

GitHub Actions / build (22.x)

Cannot find module './defineLine.js' or its corresponding type declarations.
export * from "./defineStation.js"

Check failure on line 3 in src/cps/subway/index.ts

View workflow job for this annotation

GitHub Actions / build (20.x)

Cannot find module './defineStation.js' or its corresponding type declarations.

Check failure on line 3 in src/cps/subway/index.ts

View workflow job for this annotation

GitHub Actions / build (22.x)

Cannot find module './defineStation.js' or its corresponding type declarations.
26 changes: 26 additions & 0 deletions src/cps/subways/bostonSubway.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import { createSubway } from "../subway/index.js"

export const bostonSubway = createSubway("boston-subway")

// defineLine(bostonSubway, "red-line")
// defineLine(bostonSubway, "green-line")
// defineLine(bostonSubway, "orange-line")
// defineLine(bostonSubway, "blue-line")

// defineStation(bostonSubway, "airport", ["blue-line"], 4.0, 1.0))
// defineStation(bostonSubway, "aquarium", ["blue-line"], 3.75, 0.1))
// defineStation(bostonSubway, "wood-island", ["blue-line"], 5.0, 2.0))
// defineStation(bostonSubway, "state", ["blue-line", "orange-line"], 3.1, -0.75))

// defineStation(bostonSubway, "park-street", ["green-line", "red-line"], 2.5, -0.5))
// defineStation(bostonSubway, "government-center", ["green-line", "blue-line"], 2.9, -0.25))
// defineStation(bostonSubway, "copley-square", ["green-line",], 1.0, -1.0))
// defineStation(bostonSubway, "boston-u", ["green-line",], -1.0, -1.0))
// defineStation(bostonSubway, "north-station", ["green-line", "orange-line"], 2.5, 0.75))
// defineStation(bostonSubway, "haymarket", ["orange-line" "green-line",], 2.75, 0.5))

// defineStation(bostonSubway, "south-station", ["red-line"], 3.0, -1.0)
// defineStation(bostonSubway, "washington", ["red-line", "orange-line"], 2.75, -0.75)
// defineStation(bostonSubway, "kendall-square", ["red-line"], 1.0, 0.0)
// defineStation(bostonSubway, "central-square", ["red-line"], -1.0, 0.0)
// defineStation(bostonSubway, "harvard-square", ["red-line"], -2.0, 1.0)

0 comments on commit 85220c5

Please sign in to comment.