forked from bddicken/languages
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
35 changed files
with
475 additions
and
79 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,3 +3,5 @@ code | |
.idea/ | ||
*.user | ||
*.o | ||
.aider* | ||
.env |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
BEGIN { | ||
|
||
# Parse command-line argument for u | ||
u = ARGV[1] | ||
delete ARGV[1] | ||
|
||
# Initialization not necessary, int(result) is zero by default | ||
|
||
# Sum up Fibonacci values for numbers from 1 to u | ||
for (i=1;i<u;i++) { | ||
r += fibonacci(i) | ||
} | ||
|
||
# Print result | ||
print r | ||
|
||
} | ||
|
||
# Recursive Fibonacci function | ||
function fibonacci(n) { | ||
if ( n == 0 ) { return 0 } | ||
if ( n == 1 ) { return 1 } | ||
return fibonacci(n - 1) + fibonacci(n - 2) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
#!chezscheme | ||
(import (chezscheme)) | ||
|
||
(define (fib n) | ||
(cond | ||
[(fxzero? n) 0] | ||
[(fx= 1 n) 1] | ||
[else (fx+ (fib (fx- n 1)) | ||
(fib (fx- n 2)))])) | ||
|
||
(define (main args) | ||
(define u (string->number (cadr args))) | ||
(display | ||
(do [(i 1 (fx1+ i)) | ||
(r 0 (fx+ r (fib i)))] | ||
[(>= i u) | ||
r])) | ||
(newline)) | ||
|
||
(main (command-line)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
(ns code | ||
(:gen-class)) | ||
|
||
(set! *unchecked-math* :warn-on-boxed) | ||
|
||
(defn- fibonacci ^long [^long n] | ||
((fn fib ^long [^long n] | ||
(if (<= n 1) | ||
n | ||
(+ (long (fib (- n 1))) | ||
(long (fib (- n 2)))))) n)) | ||
|
||
(defn -main [& args] | ||
(let [u (long (parse-long (first args))) | ||
r (loop [i 1 | ||
sum 0] | ||
(if (< i u) | ||
(recur (inc i) (+ sum (long (fibonacci i)))) | ||
sum))] | ||
(println r))) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
#include <iostream> | ||
using namespace std; | ||
|
||
int fibonacci(int n) | ||
{ | ||
if (n == 0) | ||
return 0; | ||
if (n == 1) | ||
return 1; | ||
return fibonacci(n - 1) + fibonacci(n - 2); | ||
} | ||
|
||
int main(int argc, char *argv[]) | ||
{ | ||
int u = stoi(argv[1]); | ||
int r = 0; | ||
for (int i = 1; i < u; i++) | ||
{ | ||
r += fibonacci(i); | ||
} | ||
|
||
cout << r << endl; | ||
return 0; | ||
} |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
[<EntryPoint>] | ||
let main argv = | ||
let rec fibonacci n = | ||
if n < 2 then n | ||
else fibonacci (n - 1) + fibonacci (n - 2) | ||
|
||
let u = int argv[0] | ||
let mutable r = 0 | ||
for i in 1..u-1 do | ||
r <- r + fibonacci i | ||
|
||
printfn $"{r}" | ||
0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<OutputType>Exe</OutputType> | ||
<TargetFramework>net9.0</TargetFramework> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<Compile Include="code.fs" /> | ||
</ItemGroup> | ||
|
||
</Project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,18 @@ | ||
import std/[strutils, os] | ||
proc fibonacci(n: uint32): uint32 = | ||
if n <= 1: | ||
return n | ||
return fibonacci(n - 1) + fibonacci(n - 2) | ||
import std/[ | ||
strutils, | ||
cmdline | ||
] | ||
|
||
let u: uint32 = paramStr(1).parseInt().uint32 | ||
var r: uint32 | ||
for i in 1..u: | ||
proc fibonacci(n: uint64): uint64 = | ||
if n <= 1: | ||
return n | ||
return fibonacci(n - 1) + fibonacci(n - 2) | ||
|
||
proc main() = | ||
let u = uint64 parseUInt paramStr 1 | ||
var r: uint64 = 0 | ||
for i in 1..u: | ||
r += fibonacci(i) | ||
echo r | ||
echo r | ||
|
||
main() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
#!/usr/bin/env perl | ||
use strict; | ||
use warnings; | ||
|
||
sub fibonacci { | ||
my ($n) = @_; | ||
return 0 if $n == 0; | ||
return 1 if $n == 1; | ||
return fibonacci($n-1) + fibonacci($n-2); | ||
} | ||
|
||
my $u = $ARGV[0]; | ||
my $r = 0; | ||
for my $i (1..$u-1) { | ||
$r += fibonacci($i); | ||
} | ||
print "$r\n"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,20 @@ | ||
import sys | ||
|
||
|
||
def fibonacci(n): | ||
if (n == 0): | ||
return 0 | ||
if (n == 1): | ||
return 1 | ||
return fibonacci(n-1) + fibonacci(n-2) | ||
if n == 0: | ||
return 0 | ||
if n == 1: | ||
return 1 | ||
return fibonacci(n-1) + fibonacci(n-2) | ||
|
||
|
||
def main(): | ||
u = int(sys.argv[1]) | ||
r = 0 | ||
for i in range(1, u): | ||
r += fibonacci(i) | ||
r += fibonacci(i) | ||
print(r) | ||
|
||
|
||
main() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,21 @@ | ||
//> using scala 3.6.1 | ||
|
||
package jvm | ||
|
||
import scala.annotation.switch | ||
|
||
@main | ||
def main(number: String): Unit = | ||
val u = number.toInt | ||
var r = 0 | ||
for i <- 1 until u do | ||
var i = 0 | ||
while i < u do | ||
r += fibonacci(i) | ||
i += 1 | ||
println(r) | ||
|
||
|
||
def fibonacci(n: Int): Int = | ||
n match | ||
(n: @switch) match | ||
case 0 => 0 | ||
case 1 => 1 | ||
case _ => fibonacci(n - 1) + fibonacci(n - 2) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
fn fibonacci(n i32) i32 { | ||
if n == 0 { | ||
return 0 | ||
} | ||
if n == 1 { | ||
return 1 | ||
} | ||
return fibonacci(n - 1) + fibonacci(n - 2) | ||
} | ||
|
||
@[direct_array_access] | ||
fn main() { | ||
u := arguments()[1].i32() | ||
mut r := i32(0) | ||
for i := i32(1); i < u; i++ { | ||
r += fibonacci(i) | ||
} | ||
println(r) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.