From aafda8bd1c6e2cfa527e5ff13dd09999af0c7398 Mon Sep 17 00:00:00 2001 From: Paulo Custodio Date: Thu, 2 Mar 2023 17:56:41 +0000 Subject: Add BASIC solution --- challenge-205/paulo-custodio/basic/ch-1.bas | 87 +++++++++++++++++++++++++++++ challenge-205/paulo-custodio/basic/ch-2.bas | 62 ++++++++++++++++++++ 2 files changed, 149 insertions(+) create mode 100644 challenge-205/paulo-custodio/basic/ch-1.bas create mode 100644 challenge-205/paulo-custodio/basic/ch-2.bas diff --git a/challenge-205/paulo-custodio/basic/ch-1.bas b/challenge-205/paulo-custodio/basic/ch-1.bas new file mode 100644 index 0000000000..f145107b60 --- /dev/null +++ b/challenge-205/paulo-custodio/basic/ch-1.bas @@ -0,0 +1,87 @@ +' Challenge 205 +' +' Task 1: Third Highest +' Submitted by: Mohammad S Anwar +' +' You are given an array of integers. +' +' Write a script to find out the Third Highest if found otherwise return the maximum. +' Example 1 +' +' Input: @array = (5,3,4) +' Output: 3 +' +' First highest is 5. Second highest is 4. Third highest is 3. +' +' Example 2 +' +' Input: @array = (5,6) +' Output: 6 +' +' First highest is 6. Second highest is 5. Third highest is missing, so maximum is returned. +' +' Example 3 +' +' Input: @array = (5,4,4,3) +' Output: 3 +' +' First highest is 5. Second highest is 4. Third highest is 3. + +dim nums() as integer + +' read command line arguments +sub read_args(nums() as integer) + dim i as integer + + i=0 + do while command(i+1)<>"" + redim preserve nums(i) as integer + nums(i) = val(command(i+1)) + i=i+1 + loop +end sub + +' reverse sort array +sub rsort(nums() as integer) + dim i as integer, j as integer, n as integer + + for i=lbound(nums) to ubound(nums)-1 + for j=i+1 to ubound(nums) + if nums(i)=lbound(nums) then + i=lbound(nums) + j=lbound(nums) + last=nums(i)+1 + do while i<=ubound(nums) + if nums(i)<>last then + nums(j)=nums(i) + last=nums(i) + j=j+1 + end if + i=i+1 + loop + end if +end sub + +read_args nums() +rsort nums() +uniq nums() + +if ubound(nums)"" + redim preserve nums(i) as integer + nums(i) = val(command(i+1)) + i=i+1 + loop +end sub + +' compute highest xor of any pair +function max_xor(nums() as integer) as integer + dim max as integer, n as integer, i as integer, j as integer + + max=0 + for i=lbound(nums) to ubound(nums)-1 + for j=i+1 to ubound(nums) + n=nums(i) xor nums(j) + if n>max then + max=n + end if + next + next + max_xor=max +end function + + +read_args nums() +print max_xor(nums()) -- cgit