Skip to content

Commit

Permalink
refactor: change sample structure
Browse files Browse the repository at this point in the history
  • Loading branch information
SkuldNorniern committed Oct 8, 2024
1 parent 2c68db8 commit 4c8ae2e
Show file tree
Hide file tree
Showing 6 changed files with 39 additions and 27 deletions.
17 changes: 9 additions & 8 deletions sample/check_prime_number.nk
Original file line number Diff line number Diff line change
@@ -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 )
Expand All @@ -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;
}
6 changes: 3 additions & 3 deletions sample/fibonacci.nk
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}


9 changes: 6 additions & 3 deletions sample/hello_world.nk
Original file line number Diff line number Diff line change
@@ -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;
}
16 changes: 15 additions & 1 deletion sample/import_statement/fibonacci.nk
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down
7 changes: 0 additions & 7 deletions sample/import_statement/import.nk

This file was deleted.

11 changes: 6 additions & 5 deletions sample/triangle.nk
Original file line number Diff line number Diff line change
@@ -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;
}

0 comments on commit 4c8ae2e

Please sign in to comment.