Skip to content

Qube Cinema Assignment #202

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions realImage_Challenge2016/data/distributors.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
[
{
"name": "DISTRIBUTOR1",
"include": ["INDIA", "UNITEDSTATES"],
"exclude": ["KARNATAKA-INDIA", "CHENNAI-TAMILNADU-INDIA"]
},
{
"name": "DISTRIBUTOR2",
"include": ["EUROPE"],
"exclude": ["GERMANY", "FRANCE"]
}
]
22 changes: 22 additions & 0 deletions realImage_Challenge2016/distributor/distributor.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package distributor

import (
"encoding/json"
"os"
)

// LoadDistributors reads distributor data from a JSON file
func LoadDistributors(filePath string) ([]Distributor, error) {
file, err := os.ReadFile(filePath)
if err != nil {
return nil, err
}

var distributors []Distributor
err = json.Unmarshal(file, &distributors)
if err != nil {
return nil, err
}

return distributors, nil
}
7 changes: 7 additions & 0 deletions realImage_Challenge2016/distributor/models.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package distributor

type Distributor struct {
Name string `json:"name"`
Include []string `json:"include"`
Exclude []string `json:"exclude"`
}
29 changes: 29 additions & 0 deletions realImage_Challenge2016/distributor/permissions.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package distributor

import "strings"

// normalizeRegion ensures consistent case for comparison
func normalizeRegion(region string) string {
return strings.ToUpper(strings.TrimSpace(region))
}

// hasPermission checks if the given distributor can distribute in a region
func HasPermission(distributor Distributor, region string) bool {
normalizedRegion := normalizeRegion(region)

// Check Exclusions First
for _, excl := range distributor.Exclude {
if strings.HasSuffix(normalizedRegion, normalizeRegion(excl)) {
return false
}
}

// Check Inclusions
for _, incl := range distributor.Include {
if strings.HasSuffix(normalizedRegion, normalizeRegion(incl)) {
return true
}
}

return false
}
3 changes: 3 additions & 0 deletions realImage_Challenge2016/go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module realImage_Challenge2016

go 1.24.0
35 changes: 35 additions & 0 deletions realImage_Challenge2016/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package main

import (
"fmt"
"log"

"realImage_Challenge2016/distributor"
)

func main() {
distributors, err := distributor.LoadDistributors("data/distributors.json")
if err != nil {
log.Fatalf("Failed to load distributor data: %v", err)
}

testRegions := []string{
"CHICAGO-ILLINOIS-UNITEDSTATES",
"CHENNAI-TAMILNADU-INDIA",
"BANGALORE-KARNATAKA-INDIA",
"MUMBAI-MAHARASHTRA-INDIA",
"BERLIN-GERMANY",
"PARIS-FRANCE",
}

for _, dist := range distributors {
fmt.Printf("\n=== Distributor: %s ===\n", dist.Name)
for _, region := range testRegions {
if distributor.HasPermission(dist, region) {
fmt.Printf("Distribution in %s: YES\n", region)
} else {
fmt.Printf("Distribution in %s: NO\n", region)
}
}
}
}