From 4c8ae2e4b28245352e4a62efa17e62500f76be91 Mon Sep 17 00:00:00 2001 From: SkuldNorniern Date: Tue, 8 Oct 2024 11:59:53 +0900 Subject: [PATCH] refactor: change sample structure --- sample/check_prime_number.nk | 17 +++++++++-------- sample/fibonacci.nk | 6 +++--- sample/hello_world.nk | 9 ++++++--- sample/import_statement/fibonacci.nk | 16 +++++++++++++++- sample/import_statement/import.nk | 7 ------- sample/triangle.nk | 11 ++++++----- 6 files changed, 39 insertions(+), 27 deletions(-) delete mode 100644 sample/import_statement/import.nk diff --git a/sample/check_prime_number.nk b/sample/check_prime_number.nk index 3a5e547..2fb96fe 100644 --- a/sample/check_prime_number.nk +++ b/sample/check_prime_number.nk @@ -1,12 +1,13 @@ -fn main() -> void +fn main() -> i64 { - let:i32 n = 10; - let:i32 i = 2; - let:i32 count = 0; + let:i64 n = 10; + let:i64 i = 2; + let:i64 count = 0; + let:i64 j = 0; for ( i -> n :: 1 ) { - let:i32 j = n; + j=n; j %= i; if ( j == 0 ) @@ -16,11 +17,11 @@ fn main() -> void } if (count == 0) { - println("this is prime number!"); + println(1); } if (count != 0) { - println("this is not prime number!"); + println(0); } - return; + return 0; } diff --git a/sample/fibonacci.nk b/sample/fibonacci.nk index fa1cc5f..d145653 100644 --- a/sample/fibonacci.nk +++ b/sample/fibonacci.nk @@ -7,15 +7,15 @@ fn fibonacci(i64:n) -> i64 } else { return_val = fibonacci( n-1 ) + fibonacci( n-2 ); - } return return_val; } fn main() -> i64 { - let:i64 x = 47; - return fibonacci(x); + let:i64 x = 35; + println(fibonacci(x)); + return 0; } diff --git a/sample/hello_world.nk b/sample/hello_world.nk index b759b14..f1b8ac9 100644 --- a/sample/hello_world.nk +++ b/sample/hello_world.nk @@ -1,5 +1,8 @@ -fn main() -> void +fn main() -> i64 { - println("Hello World!"); - return; + let:i64 a = 2345; + let:i64 ab = 125; + let:String b = "hi"; + println("hellooo hi {}", b); + return 0; } diff --git a/sample/import_statement/fibonacci.nk b/sample/import_statement/fibonacci.nk index c99660f..72e9ab7 100644 --- a/sample/import_statement/fibonacci.nk +++ b/sample/import_statement/fibonacci.nk @@ -3,6 +3,20 @@ fn adder(i64:a, i64:b) -> i64 return a + b; } +fn adder_fibonacci(i64:n) -> i64 +{ + let:i64 return_val = 0; + if(n < 2) + { + return_val = n; + } + else { + return_val = adder(adder_fibonacci( n-1 ), adder_fibonacci( n-2 )); + + } + return return_val; +} + fn fibonacci(i64:n) -> i64 { let:i64 return_val = 0; @@ -11,7 +25,7 @@ fn fibonacci(i64:n) -> i64 return_val = n; } else { - return_val = adder(fibonacci( n-1 ), fibonacci( n-2 )); + return_val = fibonacci( n-1 ) + fibonacci( n-2 ); } return return_val; diff --git a/sample/import_statement/import.nk b/sample/import_statement/import.nk deleted file mode 100644 index 1e0cd0f..0000000 --- a/sample/import_statement/import.nk +++ /dev/null @@ -1,7 +0,0 @@ -inject "fibonacci"; - -fn main() -> i64 -{ - let:i64 result = fibonacci(47); - return result; -} diff --git a/sample/triangle.nk b/sample/triangle.nk index 2a2fb76..967aa62 100644 --- a/sample/triangle.nk +++ b/sample/triangle.nk @@ -1,14 +1,15 @@ -fn main() -> void +fn main() -> i64 { - let:i32 i = 0; + let:i64 i = 0; + let:i64 j = 0; for(i -> 10 :: 1) { - let:i32 j = 0; + j = 0; for(j -> i :: 1) { print("*"); } - println(" "); + println(""); } - return ; + return 0; }