-
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.
Add comparisons between julia and python
- Loading branch information
Showing
10 changed files
with
77 additions
and
0 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 |
---|---|---|
@@ -0,0 +1,2 @@ | ||
x = 1 | ||
println(2^2 + 5x) |
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,3 @@ | ||
x = 1 | ||
print(2**2 + 5*x) | ||
print(2^2 + 5) |
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,11 @@ | ||
function my_add(x, y) | ||
return x + y | ||
end | ||
|
||
function my_add2(x, y) | ||
x + y | ||
end | ||
|
||
my_add3(x, y) = x + y | ||
|
||
my_add4 = (x, y) -> x + y |
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,4 @@ | ||
def my_add(x, y): | ||
return x + y | ||
|
||
my_add2 = lambda x, y: x + y |
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,7 @@ | ||
x = 2 | ||
|
||
if x % 2 == 0 | ||
println("x is even") | ||
else | ||
println("x is odd") | ||
end |
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,6 @@ | ||
x = 2 | ||
|
||
if x % 2 == 0: | ||
print("x is even") | ||
else: | ||
print("x is odd") |
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,16 @@ | ||
# sum the squares of integers 0 <= x < 10 | ||
# which are not 0 mod 4 | ||
result_squared = 0 | ||
for x in 0:10 | ||
@isdefined(result) | ||
if x % 4 != 0 | ||
global result_squared += x^2 | ||
end | ||
end | ||
result = sqrt(result_squared) | ||
|
||
println(result) | ||
|
||
alternative_result = ( 0:10 |> filter(x -> x%4 != 0) ) .^2 |> (sqrt ∘ sum) | ||
|
||
println(alternative_result) |
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,21 @@ | ||
# sqrt of sum the squares of integers 0 <= x < 10 | ||
# which are not 0 mod 4 | ||
result_squared = 0 | ||
for x in range(10): | ||
if x % 4 != 0: | ||
result_squared += x*x | ||
result = result_squared**0.5 | ||
|
||
print(result) | ||
|
||
alternative_result = sum( | ||
map( | ||
lambda x: x*x, | ||
filter( | ||
lambda x: x % 4 != 0, | ||
range(10) | ||
) | ||
) | ||
) | ||
|
||
print(alternative_result) |
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,4 @@ | ||
x = 1 | ||
y::String = "hello" | ||
x = "bye" | ||
y = 1 |
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,3 @@ | ||
x = 1 | ||
y = "hello" | ||
x = "bye" |