-
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.
Merge branch 'master' into python_app_workflow
- Loading branch information
Showing
19 changed files
with
1,528 additions
and
604 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
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,37 @@ | ||
/** | ||
* Binary search efficiently locates an item in a sorted sequence by | ||
* repeatedly dividing the search interval in half. If the target is less than | ||
* the item in the middle, the search continues in the lower half, otherwise | ||
* in the upper half, until the item is found or the search space is empty. | ||
*/ | ||
|
||
use math/random; | ||
|
||
fn binary_search(let list, let target) = { | ||
let left = 1; | ||
let right = list.length; | ||
|
||
while left <= right = { | ||
let mid = (+ / - right left 2 left).toint(); | ||
let result = list.[mid]; | ||
|
||
if result < target = { | ||
left = + mid 1; | ||
} else if result > target = { | ||
right = - mid 1; | ||
} else = { | ||
return! mid; | ||
} | ||
} | ||
|
||
return! -1; | ||
} | ||
|
||
let nums = random.randint(0, 50, size=10); | ||
let goal = ( | ||
readln!("What is your goal number? ") | ||
.toint() | ||
); | ||
|
||
println("Generated numbers: ${nums}"); | ||
println("Does it exist? ${binary_search(nums, goal)}"); |
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,26 @@ | ||
/** | ||
* Bubble sort is a simple sorting algorithm that repeatedly steps through | ||
* the list, compares adjacent elements and swaps them if they are in | ||
* the wrong order. This process is repeated until the list is sorted. | ||
*/ | ||
|
||
use math/random; | ||
|
||
fn bubble_sort(let list) = { | ||
let length = list.length; | ||
for let i in [1..length] = { | ||
for let j in [1..- length i] = { | ||
if list.[j] > list.[+ j 1] = { | ||
let tmp = list.[j]; | ||
list.[j] = list.[+ j 1]; | ||
list.[+ j 1] = tmp; | ||
} | ||
} | ||
} | ||
return! list; | ||
} | ||
|
||
let nums = random.randint(0, 50, size=10); | ||
|
||
println("Before sorting: ${nums}"); | ||
println("After sorting: ${bubble_sort(nums)}"); |
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 |
---|---|---|
|
@@ -5,4 +5,4 @@ | |
|
||
__author__ = 'Artin Mohammadi <[email protected]>' | ||
__license__ = 'MIT' | ||
__version__ = '1.1.0' | ||
__version__ = '1.4.2' |
Oops, something went wrong.