Last active
July 25, 2024 14:33
-
-
Save skikozou/4a36b2f48e500a0febd90bab986aafb9 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"fmt" | |
) | |
func main() { | |
fmt.Println("fake 2048(fakeと言っているがほぼ2048もどきである)") | |
World := New() | |
for { | |
fmt.Printf(">") | |
var in string | |
fmt.Scan(&in) | |
switch in { | |
case "summon": | |
fmt.Scan(&in) | |
if _, ok := World.Num[in]; !ok { | |
World.Num[in] = 1 | |
fmt.Println(in, "=", 1) | |
} else { | |
fmt.Println("already exists") | |
} | |
case "add": | |
fmt.Scan(&in) | |
n1n := in | |
n1 := World.Num[in] | |
fmt.Scan(&in) | |
n2n := in | |
n2 := World.Num[in] | |
if n1 == n2 { | |
sum := n1 + n2 | |
nn := n1n + n2n | |
World.Num[nn] = sum | |
fmt.Println(nn, "=", sum) | |
} else { | |
fmt.Println("can't add these object") | |
continue | |
} | |
case "show": | |
for name, num := range World.Num { | |
fmt.Println(name, num) | |
} | |
} | |
} | |
} | |
type cell struct { | |
Num map[string]int | |
} | |
func New() *cell { | |
return &cell{ | |
Num: make(map[string]int, 0), | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment