generated from carpentries/workbench-template-md
-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Closes #4
- Loading branch information
Showing
5 changed files
with
538 additions
and
4 deletions.
There are no files selected for viewing
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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,28 @@ | ||
import sys | ||
import random | ||
|
||
# Argument parsing | ||
if len(sys.argv) != 2: | ||
print("Script expects 1 positive integer argument, %u found."%(len(sys.argv) - 1)) | ||
sys.exit() | ||
n = int(sys.argv[1]) | ||
# Init | ||
random.seed(12) | ||
arr = [random.random() for i in range(n)] | ||
print("Sorting %d elements"%(n)) | ||
# Sort | ||
for i in range(n - 1): | ||
swapped = False | ||
for j in range(0, n - i - 1): | ||
if arr[j] > arr[j + 1]: | ||
arr[j], arr[j + 1] = arr[j + 1], arr[j] | ||
swapped = True | ||
# If no two elements were swapped in the inner loop, the array is sorted | ||
if not swapped: | ||
break | ||
# Validate | ||
is_sorted = True | ||
for i in range(n - 1): | ||
if arr[i] > arr[i+1]: | ||
is_sorted = False | ||
print("Sorting: %s"%("Passed" if is_sorted else "Failed")) |
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,23 @@ | ||
n = 100 | ||
a=0 | ||
b=0 | ||
c=0 | ||
d=0 | ||
for i in range(1, n + 1): | ||
if i % 3 == 0 and i % 5 == 0: | ||
a+=1 | ||
print("FizzBuzz") | ||
elif i % 3 == 0: | ||
b+=1 | ||
print("Fizz") | ||
elif i % 5 == 0: | ||
c+=1 | ||
print("Buzz") | ||
else: | ||
d+=1 | ||
print(i) | ||
|
||
print(a) | ||
print(b) | ||
print(c) | ||
print(d) |
Oops, something went wrong.