Skip to content

Instantly share code, notes, and snippets.

@luismendes070
Created January 15, 2024 12:57
Show Gist options
  • Save luismendes070/f189ec0a6dbb67e86741eefa80e5e960 to your computer and use it in GitHub Desktop.
Save luismendes070/f189ec0a6dbb67e86741eefa80e5e960 to your computer and use it in GitHub Desktop.
golang code challenge
@luismendes070
Copy link
Author

luismendes070 commented Jan 15, 2024

#1

Aceleração Internacional - System Design Skills with AWS
1 / 3 - AWS Cost Estimation Challenge

BingChat

`package main

import (
"fmt"
)
// BingChat
func main() {
// Define the rates
costPerHourEC2 := 0.25
costPerGBS3 := 0.05

// Collecting user information
var numOfEC2Instances, numOfGBS3, numberOfMonths int

fmt.Scan(&numOfEC2Instances)
fmt.Scan(&numOfGBS3)
fmt.Scan(&numberOfMonths)

// Calculate costs
totalEC2Cost := float64(numOfEC2Instances) * costPerHourEC2
totalS3Cost := float64(numOfGBS3 * numberOfMonths) * costPerGBS3

// Calculate total cost
totalCost := totalEC2Cost + totalS3Cost

// Display the result
fmt.Printf("Estimated total cost:\n")
fmt.Printf("EC2: $%.2f\n", totalEC2Cost)
fmt.Printf("S3: $%.2f\n", totalS3Cost)
fmt.Printf("Total cost: $%.2f\n", totalCost)

}
`

@luismendes070
Copy link
Author

luismendes070 commented Jan 15, 2024

#2
Aceleração Internacional - System Design Skills with AWS
2 / 3 - Student Grade System
Bard
`package main

import (
"fmt"
)

// Student represents the data structure of a student
type Student struct {
ID int
Name string
Grades []float64
}

// NewStudent creates an instance of a student with a unique ID
func NewStudent(name string) Student {
return Student{
ID: len(students) + 1,
Name: name,
Grades: []float64{},
}
}

// AddGrade adds a grade to the student
func (s *Student) AddGrade(grade float64) {
s.Grades = append(s.Grades, grade)
}

// CalculateAverage calculates the average of the student's grades
func (s *Student) CalculateAverage() float64 {
if len(s.Grades) == 0 {
return 0
}

var sum float64
for _, grade := range s.Grades {
	sum += grade
}
return sum / float64(len(s.Grades))

}

// GenerateGradeReport generates a report of the student's grades
func (s *Student) GenerateGradeReport() string {
average := s.CalculateAverage()
return fmt.Sprintf("Name: %s\nGrades: %v\nAverage: %.2f", s.Name, s.Grades, average)
}

var students []Student

func main() {
// Receive grades via input
var studentName string

fmt.Scan(&studentName)

student := NewStudent(studentName)

for {
	var grade float64
	fmt.Scan(&grade)

	if grade == -1 {
		break
	}

	student.AddGrade(grade)
}

students = append(students, student)

// Display grade report
for _, student := range students {
	fmt.Println(student.GenerateGradeReport())
}

}
`

@luismendes070
Copy link
Author

luismendes070 commented Jan 15, 2024

#3 Aceleração Internacional - System Design Skills with AWS
3 / 3 - Simulating Amazon ECR Operations

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment