Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fish implementations for loop & fibonacci #158

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions fibonacci/fish/code.fish
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#!/usr/bin/env fish

function fibonacci
if test $argv[1] -eq 0
echo 0
else if test $argv[1] -eq 1
echo 1
else
echo (fibonacci (math $argv[1] - 1)) + (fibonacci (math $argv[1] - 2))
end
end

set -l u (math $argv[1] - 1)
set -l r 0
for i in (seq 0 $u)
set r (math $r + (fibonacci $i))
end
echo $r
16 changes: 16 additions & 0 deletions loops/fish/code.fish
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#!/usr/bin/env fish

set -l u (math $argv[1])
set -l r (math (random) % 10000)
set -l a
for i in (seq 10000)
set -a a 0
end

for i in (seq 10000)
for j in (seq 100000)
set a[$i] (math $a[$i] + $j % $u)
end
set a[$i] (math $a[$i] + $r)
end
ThatOneCalculator marked this conversation as resolved.
Show resolved Hide resolved
echo $a[$r]
1 change: 1 addition & 0 deletions run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -54,3 +54,4 @@ run "AWK" "awk -f ./awk/code.awk 40"
run "MAWK" "mawk -f ./awk/code.awk 40"
run "Clojure" "java -cp clojure/classes:$(clojure -Spath) code 40"
run "Babashka" "bb -cp clojure -m code 40"
run "Fish" "./fish/code.fish 40"