Feat: done
This commit is contained in:
3
.gitmodules
vendored
Normal file
3
.gitmodules
vendored
Normal file
@@ -0,0 +1,3 @@
|
||||
[submodule "docs/template"]
|
||||
path = docs/template
|
||||
url = ../typst-template
|
||||
16
Makefile
Normal file
16
Makefile
Normal file
@@ -0,0 +1,16 @@
|
||||
.PHONY: all watch clean
|
||||
|
||||
SOURCE := $(shell find docs/ -type f -name '*.typ')
|
||||
TARGET := docs/main.pdf
|
||||
TYPST_ARGS += --root .
|
||||
|
||||
all: $(TARGET)
|
||||
|
||||
docs/main.pdf: docs/main.typ $(SOURCE)
|
||||
typst compile $(TYPST_ARGS) $<
|
||||
|
||||
watch:
|
||||
typst watch --root . docs/main.typ
|
||||
|
||||
clean:
|
||||
-rm docs/main.pdf
|
||||
BIN
docs/main.pdf
Normal file
BIN
docs/main.pdf
Normal file
Binary file not shown.
20
docs/main.typ
Normal file
20
docs/main.typ
Normal file
@@ -0,0 +1,20 @@
|
||||
#import "template/module.typ": *
|
||||
|
||||
#show: default.with(
|
||||
title: "Golang Homework 5",
|
||||
authors: ((
|
||||
name: "Yi-Ting Shih (111550013)",
|
||||
affiliation: "National Yang Ming Chaio Tung University",
|
||||
email: "ytshih@cs.nycu.edu.tw",
|
||||
),),
|
||||
)
|
||||
|
||||
== Code
|
||||
|
||||
#code(read("../reverse.go"))
|
||||
|
||||
This code doesn't allocate new memory except array subscript `i, l, r`.
|
||||
|
||||
== Result
|
||||
|
||||
#code(read("../result"))
|
||||
1
docs/template
Submodule
1
docs/template
Submodule
Submodule docs/template added at 5a290913a2
5
result
Normal file
5
result
Normal file
@@ -0,0 +1,5 @@
|
||||
> go test -v
|
||||
=== RUN TestReverse
|
||||
--- PASS: TestReverse (0.00s)
|
||||
PASS
|
||||
ok reverse 0.001s
|
||||
31
reverse.go
Normal file
31
reverse.go
Normal file
@@ -0,0 +1,31 @@
|
||||
package reverse
|
||||
|
||||
import "unicode/utf8"
|
||||
|
||||
func swap(a *byte, b *byte) {
|
||||
*a ^= *b
|
||||
*b ^= *a
|
||||
*a ^= *b
|
||||
}
|
||||
|
||||
func reverse(b []byte) {
|
||||
for i := 0; i < len(b); {
|
||||
_, sz := utf8.DecodeRune(b[i:])
|
||||
l := i
|
||||
r := i + sz - 1
|
||||
for l < r {
|
||||
swap(&b[l], &b[r])
|
||||
l++
|
||||
r--
|
||||
}
|
||||
i += sz
|
||||
}
|
||||
|
||||
l := 0
|
||||
r := len(b) - 1
|
||||
for l < r {
|
||||
swap(&b[l], &b[r])
|
||||
l++
|
||||
r--
|
||||
}
|
||||
}
|
||||
21
reverse_test.go
Normal file
21
reverse_test.go
Normal file
@@ -0,0 +1,21 @@
|
||||
package reverse
|
||||
|
||||
import "testing"
|
||||
|
||||
func TestReverse(t *testing.T) {
|
||||
tcs := []struct {
|
||||
input string
|
||||
expects string
|
||||
}{
|
||||
{"Hello 世界", "界世 olleH"},
|
||||
}
|
||||
|
||||
for _, tc := range tcs {
|
||||
b := []byte(tc.input)
|
||||
reverse(b)
|
||||
ret := string(b)
|
||||
if ret != tc.expects {
|
||||
t.Errorf("Failed to remove unicode space. Input: %s, expects: %s, results: %s", tc.input, tc.expects, ret)
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user