new files
This commit is contained in:
parent
3af7344581
commit
86c034bb8b
1364 changed files with 21352 additions and 0 deletions
34
Task/Binary-search/REXX/binary-search-1.rexx
Normal file
34
Task/Binary-search/REXX/binary-search-1.rexx
Normal file
|
|
@ -0,0 +1,34 @@
|
|||
/*REXX program finds a value in a list using a recursive binary search. */
|
||||
@=' 11 17 29 37 41 59 67 71 79 97 101 107 127 137 149',
|
||||
'163 179 191 197 223 227 239 251 269 277 281 307 311 331 347',
|
||||
'367 379 397 419 431 439 457 461 479 487 499 521 541 557 569',
|
||||
'587 599 613 617 631 641 659 673 701 719 727 739 751 757 769',
|
||||
'787 809 821 827 853 857 877 881 907 929 937 967 991 1009'
|
||||
/*(above) list of strong primes.*/
|
||||
|
||||
parse arg ? . /*get a number the user specified*/
|
||||
if ?=='' then do
|
||||
say; say '*** error! *** no arg specified.'; say
|
||||
exit 13
|
||||
end
|
||||
low = 1
|
||||
high = words(@)
|
||||
avg=(word(@,1)+word(@,high))/2
|
||||
loc = binarySearch(low,high)
|
||||
|
||||
if loc==-1 then do
|
||||
say ? "wasn't found in the list."
|
||||
exit /*stick a fork in it, we're done.*/
|
||||
end
|
||||
else say ? 'is in the list, its index is:' loc
|
||||
say
|
||||
say 'arithmetic mean of the' high "values=" avg
|
||||
exit /*stick a fork in it, we're done.*/
|
||||
/*─────────────────────────────────────BINARYSEARCH subroutine──────────*/
|
||||
binarySearch: procedure expose @ ?; parse arg low,high
|
||||
if high<low then return -1
|
||||
mid=(low+high)%2
|
||||
y=word(@,mid)
|
||||
if ?=y then return mid
|
||||
if y>? then return binarySearch(low,mid-1)
|
||||
return binarySearch(mid+1,high)
|
||||
31
Task/Binary-search/REXX/binary-search-2.rexx
Normal file
31
Task/Binary-search/REXX/binary-search-2.rexx
Normal file
|
|
@ -0,0 +1,31 @@
|
|||
/*REXX program finds a value in a list using an iterative binary search.*/
|
||||
@=' 3 7 13 19 23 31 43 47 61 73 83 89 103 109 113 131',
|
||||
'139 151 167 181 193 199 229 233 241 271 283 293 313 317 337 349',
|
||||
'353 359 383 389 401 409 421 433 443 449 463 467 491 503 509 523',
|
||||
'547 571 577 601 619 643 647 661 677 683 691 709 743 761 773 797',
|
||||
'811 823 829 839 859 863 883 887 911 919 941 953 971 983 1013'
|
||||
/*(above) list of weak primes. */
|
||||
|
||||
parse arg ? . /*get a number the user specified*/
|
||||
|
||||
if ?=='' then do
|
||||
say; say '*** error! *** no arg specified.'; say
|
||||
exit 13
|
||||
end
|
||||
low = 1
|
||||
high = words(@)
|
||||
say 'arithmetic mean of the' high "values=" (word(@,1)+word(@,high))/2
|
||||
say
|
||||
do while low<=high; mid=(low+high)%2; y=word(@,mid)
|
||||
|
||||
if ?=y then do
|
||||
say ? 'is in the list, its index is:' mid
|
||||
exit /*stick a fork in it, we're done.*/
|
||||
end
|
||||
|
||||
if y>? then high=mid-1
|
||||
else low=mid+1
|
||||
end /*while*/
|
||||
|
||||
say ? "wasn't found in the list."
|
||||
/*stick a fork in it, we're done.*/
|
||||
Loading…
Add table
Add a link
Reference in a new issue