Skip to content

Commit 1050838

Browse files
committed
cleanup(exercises) : placeholder for exercises
1 parent 48289a5 commit 1050838

22 files changed

Lines changed: 250 additions & 399 deletions

File tree

Lines changed: 9 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,14 @@
11
package closures
22

3-
import "fmt"
3+
// TODO:
4+
// - Implement a closure function that captures state and returns a func() int
5+
// which increments and returns an internal counter on each call.
6+
// - Each call to closure() must produce an independent counter.
7+
// - Do not change function names or signatures; tests call closure().
48

5-
func closure() func() int {
6-
i := 0
7-
return func() int {
8-
i++
9-
return i
10-
}
11-
}
9+
// NOTE: Keep imports minimal in skeletons to avoid unused import errors.
1210

13-
func main() {
14-
next := closure()
15-
fmt.Println(next())
16-
fmt.Println(next())
17-
fmt.Println(next())
18-
19-
anotherNext := closure()
20-
fmt.Println(anotherNext())
21-
fmt.Println(anotherNext())
11+
func closure() func() int {
12+
// TODO: implement a counting closure
13+
return func() int { return 0 }
2214
}
Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
11
package recursion
22

3+
// TODO:
4+
// - Implement factorial using recursion.
5+
// - Handle the base case: factorial(0) == 1.
6+
// - Keep the signature the same; tests call factorial(n).
7+
38
func factorial(n int) int {
4-
if n == 0 {
5-
return 1
6-
}
7-
return n * factorial(n-1)
9+
// TODO: implement recursive factorial
10+
return 0
811
}
Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,16 @@
11
package range_built_in
22

3+
// TODO:
4+
// - Use range to iterate over slices and maps.
5+
// - sumSlice: return the sum of all elements in the slice.
6+
// - countMap: return the number of key/value pairs in the map.
7+
38
func sumSlice(s []int) int {
4-
sum := 0
5-
for _, v := range s {
6-
sum += v
7-
}
8-
return sum
9+
// TODO: implement summation with range
10+
return 0
911
}
1012

1113
func countMap(m map[string]int) int {
12-
count := 0
13-
for _, _ = range m {
14-
count++
15-
}
16-
return count
14+
// TODO: count items in map using range
15+
return 0
1716
}
Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
package pointers
22

3+
// TODO:
4+
// - Modify the value pointed to by the incoming *int.
5+
// - Return the same pointer after updating the underlying value.
6+
// - Avoid allocating any new memory; operate in place.
7+
38
func modifyValue(ptr *int) *int {
4-
*ptr = 100
9+
// TODO: implement mutation via pointer
510
return ptr
611
}
Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,16 @@
11
package strings_runes
22

3-
import "unicode/utf8"
3+
// TODO:
4+
// - countRunes: return the number of runes (Unicode code points) in a string.
5+
// - reverseString: reverse a string by rune, preserving multi-byte characters.
6+
// - Do not reverse by byte; convert to []rune and swap.
47

58
func countRunes(s string) int {
6-
return utf8.RuneCountInString(s)
9+
// TODO: implement using utf8.RuneCountInString
10+
return 0
711
}
812

913
func reverseString(s string) string {
10-
runes := []rune(s)
11-
for i, j := 0, len(runes)-1; i < j; i, j = i+1, j-1 {
12-
runes[i], runes[j] = runes[j], runes[i]
13-
}
14-
return string(runes)
14+
// TODO: implement by converting to []rune and swapping
15+
return ""
1516
}
Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,15 @@
11
package structs
22

3+
// TODO:
4+
// - Define a Person struct with Name and Age fields.
5+
// - Implement a constructor-like function NewPerson(name, age) that returns a Person.
6+
37
type Person struct {
4-
Name string
5-
Age int
8+
Name string
9+
Age int
610
}
711

812
func NewPerson(name string, age int) Person {
9-
return Person{Name: name, Age: age}
13+
// TODO: return a properly initialized Person
14+
return Person{}
1015
}
Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,19 @@
11
package methods
22

3+
// TODO:
4+
// - Add methods to a struct type.
5+
// - Area should be a value-receiver method returning width*height.
6+
// - Scale should be a pointer-receiver method that multiplies both fields.
7+
38
type Rectangle struct {
4-
Width, Height int
9+
Width, Height int
510
}
611

712
func (r Rectangle) Area() int {
8-
return r.Width * r.Height
13+
// TODO: compute area
14+
return 0
915
}
1016

1117
func (r *Rectangle) Scale(factor int) {
12-
r.Width *= factor
13-
r.Height *= factor
18+
// TODO: scale the rectangle in place
1419
}
Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,26 @@
11
package interfaces
22

3-
import "fmt"
3+
// TODO:
4+
// - Define an interface with a Greet() string method.
5+
// - Implement the interface on a Person type.
6+
// - Implement SayHello to accept a Greeter and return its greeting.
7+
// - main demonstrates usage; do not change signatures used in tests.
48

59
type Greeter interface {
6-
Greet() string
10+
Greet() string
711
}
812

913
type Person struct {
10-
Name string
14+
Name string
1115
}
1216

1317
func (p Person) Greet() string {
14-
return "Hello, my name is " + p.Name
18+
// TODO: return a greeting that uses p.Name
19+
return ""
1520
}
1621

1722
func SayHello(g Greeter) string {
18-
return g.Greet()
19-
}
20-
21-
func main() {
22-
p := Person{Name: "Alice"}
23-
fmt.Println(SayHello(p))
23+
// TODO: forward the greeting from the Greeter
24+
return ""
2425
}
26+
// (no main in skeleton)

internal/exercises/templates/22_enums/enums.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
package enums
22

3+
// TODO:
4+
// - Create an enum-like type using iota for days of the week.
5+
// - Implement IsWeekend to return true for Saturday and Sunday.
6+
37
type Day int
48

59
const (
@@ -13,5 +17,6 @@ const (
1317
)
1418

1519
func IsWeekend(d Day) bool {
16-
return d == Sunday || d == Saturday
20+
// TODO: return true for Saturday or Sunday
21+
return false
1722
}
Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
package struct_embedding
22

3+
// TODO:
4+
// - Use struct embedding to compose types.
5+
// - Base should hold common fields; User embeds Base and adds Name/Email.
6+
// - Implement NewUser constructor returning a populated User.
7+
38
type Base struct {
49
ID int
510
CreatedAt string
@@ -12,9 +17,6 @@ type User struct {
1217
}
1318

1419
func NewUser(id int, createdAt, name, email string) User {
15-
return User{
16-
Base: Base{ID: id, CreatedAt: createdAt},
17-
Name: name,
18-
Email: email,
19-
}
20+
// TODO: return a properly initialized User embedding Base
21+
return User{}
2022
}

0 commit comments

Comments
 (0)