Browse Source

Convert last "prog" exercises as functions exercises (the end ?)

content-update
Xavier Petit 4 years ago committed by xpetit
parent
commit
d7e4cfd33b
  1. 2
      docs/addition_of_exercise_draft.md
  2. 3
      subjects/brainfuck.en.md
  3. 0
      subjects/doppelganger.en.md
  4. 0
      subjects/findprevprime.en.md
  5. 97
      tests/go/solutions/brainfuck/main.go
  6. 2
      tests/go/test_compact.go
  7. 2
      tests/go/test_doppelganger.go
  8. 10
      tests/go/test_raid3.go
  9. 4
      tests/go/test_ztail.go

2
docs/addition_of_exercise_draft.md

@ -1,5 +1,7 @@
# THE ADDITION OF EXERCISE PROCEDURE
**Needs to be updated since the refactor**
##### This is for a go exercise in the piscine-go
## **1. Writing the subject and / or writing the solution**

3
subjects/brainfuck.en.md

@ -29,7 +29,6 @@ student@ubuntu:~/[[ROOT]]/brainfuck$ ./brainfuck "+++++[>++++[>++++H>+++++i<<-]>
Hi$
student@ubuntu:~/[[ROOT]]/brainfuck$ ./brainfuck "++++++++++[>++++++++++>++++++++++>++++++++++<<<-]>---.>--.>-.>++++++++++." | cat -e
abc$
student@ubuntu:~/[[ROOT]]/brainfuck$ ./brainfuck | cat -e
$
student@ubuntu:~/[[ROOT]]/brainfuck$ ./brainfuck
student@ubuntu:~/[[ROOT]]/brainfuck$
```

0
subjects/doppelgangerprog.en.md → subjects/doppelganger.en.md

0
subjects/findprevprimeprog.en.md → subjects/findprevprime.en.md

97
tests/go/solutions/brainfuck/main.go

@ -9,60 +9,59 @@ import (
const SIZE = 2048
func main() {
if len(os.Args) == 2 {
progpoint := []byte(os.Args[1])
var arby [SIZE]byte
pos := 0
openBr := 0 //opened brackets
i := 0 //iterates through the source code passed in the argument
N := len(progpoint) //length of the source code
for i >= 0 && i < N {
switch progpoint[i] {
case '>':
// Increment the pointer
pos++
case '<':
// decrement the pointes
pos--
case '+':
// increment the pointed byte
arby[pos]++
case '-':
// decrement the pointed byte
arby[pos]--
case '.':
// print the pointed byte on std output
z01.PrintRune(rune(arby[pos]))
case '[':
// go to the matching ']' if the pointed byte is 0 (while start)
openBr = 0
if arby[pos] == 0 {
for i < N && (progpoint[i] != byte(']') || openBr > 1) {
if progpoint[i] == byte('[') {
openBr++
} else if progpoint[i] == byte(']') {
openBr--
}
i++
if len(os.Args) != 2 {
return
}
progpoint := []byte(os.Args[1])
var arby [SIZE]byte
pos := 0
openBr := 0 // opened brackets
i := 0 // iterates through the source code passed in the argument
N := len(progpoint) // length of the source code
for i >= 0 && i < N {
switch progpoint[i] {
case '>':
// Increment the pointer
pos++
case '<':
// decrement the pointes
pos--
case '+':
// increment the pointed byte
arby[pos]++
case '-':
// decrement the pointed byte
arby[pos]--
case '.':
// print the pointed byte on std output
z01.PrintRune(rune(arby[pos]))
case '[':
// go to the matching ']' if the pointed byte is 0 (while start)
openBr = 0
if arby[pos] == 0 {
for i < N && (progpoint[i] != byte(']') || openBr > 1) {
if progpoint[i] == byte('[') {
openBr++
} else if progpoint[i] == byte(']') {
openBr--
}
i++
}
case ']':
// go to the matching '[' if the pointed byte is not 0 (while end)
openBr = 0
if arby[pos] != 0 {
for i >= 0 && (progpoint[i] != byte('[') || openBr > 1) {
if progpoint[i] == byte(']') {
openBr++
} else if progpoint[i] == byte('[') {
openBr--
}
i--
}
case ']':
// go to the matching '[' if the pointed byte is not 0 (while end)
openBr = 0
if arby[pos] != 0 {
for i >= 0 && (progpoint[i] != byte('[') || openBr > 1) {
if progpoint[i] == byte(']') {
openBr++
} else if progpoint[i] == byte('[') {
openBr--
}
i--
}
}
i++
}
} else {
z01.PrintRune('\n')
i++
}
}

2
tests/go/test_compact.go

@ -15,7 +15,7 @@ func main() {
for i := 0; i < 20; i++ {
n := z01.RandIntBetween(5, 20) // random size of the slice
orig := make([]string, n) //slice with the original value
orig := make([]string, n) // slice with the original value
num_pos := z01.RandIntBetween(1, n-1) // random number of positions to be written

2
tests/go/test_doppelganger.go

@ -48,6 +48,6 @@ func main() {
}
for _, arg := range table {
z01.Challenge("DoppelGangerProg", student.DoppelGanger, correct.DoppelGanger, arg.big, arg.little)
z01.Challenge("DoppelGanger", student.DoppelGanger, correct.DoppelGanger, arg.big, arg.little)
}
}

10
tests/go/test_raid3.go

@ -37,11 +37,11 @@ func main() {
// builds all the files for testing, student, solution and relevant files
execFatal("go", "build", "-o", "raid3", "solutions/raid3/main.go")
execFatal("go", "build", "-o", "raid3_student", "student/raid3/main.go")
execFatal("go", "build", "solutions/raid3/raid1aProg/raid1a.go")
execFatal("go", "build", "solutions/raid3/raid1bProg/raid1b.go")
execFatal("go", "build", "solutions/raid3/raid1cProg/raid1c.go")
execFatal("go", "build", "solutions/raid3/raid1dProg/raid1d.go")
execFatal("go", "build", "solutions/raid3/raid1eProg/raid1e.go")
execFatal("go", "build", "solutions/raid3/raid1aprog/raid1a.go")
execFatal("go", "build", "solutions/raid3/raid1bprog/raid1b.go")
execFatal("go", "build", "solutions/raid3/raid1cprog/raid1c.go")
execFatal("go", "build", "solutions/raid3/raid1dprog/raid1d.go")
execFatal("go", "build", "solutions/raid3/raid1eprog/raid1e.go")
// testing all raids1
table := []string{"raid1a", "raid1b", "raid1c", "raid1d", "raid1e"}

4
tests/go/test_ztail.go

@ -31,4 +31,6 @@ func main() {
}
}
// TODO: never use programs we didn't wrote (do not run the true cat but instead code our own solution)
// TODO:
// never use programs we didn't wrote (do not run the true cat but instead code our own solution)
// to be fixed

Loading…
Cancel
Save