Browse Source

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

pull/533/head
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 # THE ADDITION OF EXERCISE PROCEDURE
**Needs to be updated since the refactor**
##### This is for a go exercise in the piscine-go ##### This is for a go exercise in the piscine-go
## **1. Writing the subject and / or writing the solution** ## **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$ Hi$
student@ubuntu:~/[[ROOT]]/brainfuck$ ./brainfuck "++++++++++[>++++++++++>++++++++++>++++++++++<<<-]>---.>--.>-.>++++++++++." | cat -e student@ubuntu:~/[[ROOT]]/brainfuck$ ./brainfuck "++++++++++[>++++++++++>++++++++++>++++++++++<<<-]>---.>--.>-.>++++++++++." | cat -e
abc$ abc$
student@ubuntu:~/[[ROOT]]/brainfuck$ ./brainfuck | cat -e student@ubuntu:~/[[ROOT]]/brainfuck$ ./brainfuck
$
student@ubuntu:~/[[ROOT]]/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 const SIZE = 2048
func main() { func main() {
if len(os.Args) == 2 { if len(os.Args) != 2 {
progpoint := []byte(os.Args[1]) return
var arby [SIZE]byte }
pos := 0 progpoint := []byte(os.Args[1])
openBr := 0 //opened brackets var arby [SIZE]byte
i := 0 //iterates through the source code passed in the argument pos := 0
N := len(progpoint) //length of the source code openBr := 0 // opened brackets
for i >= 0 && i < N { i := 0 // iterates through the source code passed in the argument
switch progpoint[i] { N := len(progpoint) // length of the source code
case '>': for i >= 0 && i < N {
// Increment the pointer switch progpoint[i] {
pos++ case '>':
case '<': // Increment the pointer
// decrement the pointes pos++
pos-- case '<':
case '+': // decrement the pointes
// increment the pointed byte pos--
arby[pos]++ case '+':
case '-': // increment the pointed byte
// decrement the pointed byte arby[pos]++
arby[pos]-- case '-':
case '.': // decrement the pointed byte
// print the pointed byte on std output arby[pos]--
z01.PrintRune(rune(arby[pos])) case '.':
case '[': // print the pointed byte on std output
// go to the matching ']' if the pointed byte is 0 (while start) z01.PrintRune(rune(arby[pos]))
openBr = 0 case '[':
if arby[pos] == 0 { // go to the matching ']' if the pointed byte is 0 (while start)
for i < N && (progpoint[i] != byte(']') || openBr > 1) { openBr = 0
if progpoint[i] == byte('[') { if arby[pos] == 0 {
openBr++ for i < N && (progpoint[i] != byte(']') || openBr > 1) {
} else if progpoint[i] == byte(']') { if progpoint[i] == byte('[') {
openBr-- openBr++
} } else if progpoint[i] == byte(']') {
i++ openBr--
} }
i++
} }
case ']': }
// go to the matching '[' if the pointed byte is not 0 (while end) case ']':
openBr = 0 // go to the matching '[' if the pointed byte is not 0 (while end)
if arby[pos] != 0 { openBr = 0
for i >= 0 && (progpoint[i] != byte('[') || openBr > 1) { if arby[pos] != 0 {
if progpoint[i] == byte(']') { for i >= 0 && (progpoint[i] != byte('[') || openBr > 1) {
openBr++ if progpoint[i] == byte(']') {
} else if progpoint[i] == byte('[') { openBr++
openBr-- } else if progpoint[i] == byte('[') {
} openBr--
i--
} }
i--
} }
} }
i++
} }
} else { i++
z01.PrintRune('\n')
} }
} }

2
tests/go/test_compact.go

@ -15,7 +15,7 @@ func main() {
for i := 0; i < 20; i++ { for i := 0; i < 20; i++ {
n := z01.RandIntBetween(5, 20) // random size of the slice 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 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 { 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 // 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", "solutions/raid3/main.go")
execFatal("go", "build", "-o", "raid3_student", "student/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/raid1aprog/raid1a.go")
execFatal("go", "build", "solutions/raid3/raid1bProg/raid1b.go") execFatal("go", "build", "solutions/raid3/raid1bprog/raid1b.go")
execFatal("go", "build", "solutions/raid3/raid1cProg/raid1c.go") execFatal("go", "build", "solutions/raid3/raid1cprog/raid1c.go")
execFatal("go", "build", "solutions/raid3/raid1dProg/raid1d.go") execFatal("go", "build", "solutions/raid3/raid1dprog/raid1d.go")
execFatal("go", "build", "solutions/raid3/raid1eProg/raid1e.go") execFatal("go", "build", "solutions/raid3/raid1eprog/raid1e.go")
// testing all raids1 // testing all raids1
table := []string{"raid1a", "raid1b", "raid1c", "raid1d", "raid1e"} 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