aboutsummaryrefslogtreecommitdiff
path: root/entries
diff options
context:
space:
mode:
authorBraxton Hall2022-10-24 03:57:51 +0000
committerGitHub2022-10-24 03:57:51 +0000
commit7dbb91d4edce1aaf50078624b6e1833878b7ad48 (patch)
treec067c8e0d6448bfa42bbff480bf87d1332002fba /entries
parente2dbb1327f5264080ceb87659ad3cb57b2a0042c (diff)
parent2f4fab9864a91d69d2b705430f6633bdfe7f5dd5 (diff)
Merge pull request #16 from perryliao/main
whops
Diffstat (limited to 'entries')
-rw-r--r--entries/perryliao/fib.groovy22
1 files changed, 12 insertions, 10 deletions
diff --git a/entries/perryliao/fib.groovy b/entries/perryliao/fib.groovy
index af1c4df..d625d68 100644
--- a/entries/perryliao/fib.groovy
+++ b/entries/perryliao/fib.groovy
@@ -6,25 +6,26 @@ pipeline {
}
stages {
- stage('Create Cache') {
+ stage('Validate Parameter') {
steps {
script {
- if (!fileExists("fibbonacciCache")) {
- sh 'echo "0\n1" > fibbonacciCache'
- }
+ assert params.num.isInteger()
}
}
}
- stage('Validate Parameter') {
+ stage('Create Cache') {
steps {
script {
- assert params.num.isInteger()
+ if (!fileExists("fibCache")) {
+ sh 'echo "0\n1" > fibCache'
+ }
}
}
}
stage('Get Fibbonacci') {
steps {
script {
+ nComputed = sh(returnStdout: true, script: "wc -l < fibCache").trim().toInteger()
result = fib(params.num.toInteger())
println("The result is F(${params.num}) = ${result}")
}
@@ -33,16 +34,17 @@ pipeline {
}
}
-int fib(int n, cache = 'fibbonacciCache') {
- nComputed = sh(returnStdout: true, script: "wc -l < ${cache}").trim().toInteger()
+def nComputed
+
+int fib(int n, cache = 'fibCache') {
if (n >= nComputed) {
// Need to do more recursion
result = fib(n - 2, cache) + fib(n - 1, cache)
+ nComputed++
sh "echo '${result}' >> ${cache}"
return result
} else {
// Already have what we need, so read from cache
- return sh(returnStdout: true, script: "sed -n '${n + 1}p' ${cache}").trim().toInteger()
+ return sh(returnStdout: true, script: "sed -n '${n + 1}p' ${cache}").toInteger()
}
}
-