Gargoyle
(MM club member)
2006-08-26 05:47 PM
Math Help
Okay I am not the best person at math, I never got past algerbra, so I am requesting what is most likely a simple question. I have an array with elements that contain 0 or -1, and I want to see if all elements are = -1, and I thought that the best way to do this would be a bitwise operation but not sure which one would be correctCode: $array = 0,0,0,-1,0,-1; example of what the array would contain. ;Option 1 For $ = 0 to 5 $2 = $2 | $array[$] Next ;Option 2 For $ = 0 to 5 $2 = $2 ^ $array[$] Next ;Option 3 For $ = 0 to 5 $2 = $2 ~ $array[$] Next I just am not sure which operator I would use. Thanks
Witto
(MM club member)
2006-08-26 06:03 PM
Re: Math Help
I do not know what your goal is, but I would loop through an array like thisCode: Break On $array = 0,0,0,-1,0,-1 For $n = 0 to Ubound($array) If $array[$n] = -1 ? 'Element ' + $n ' is -1' EndIf Next
Gargoyle
(MM club member)
2006-08-26 06:16 PM
Re: Math Help
In the end I need to know if all the elements are -1 and be able to set a variable to say all = -1 (true) or all elements do not = - 1 (false) so to continue the examples aboveCode: $array = 0,0,0,-1,0,-1; example of what the array would contain. ;Option 1 For $ = 0 to 5 $2 = $2 | $array[$] Next If $2 = -1 $Flag = "True" Else $Flag = "False" EndIf ;Option 2 For $ = 0 to 5 $2 = $2 ^ $array[$] Next If $2 = -1 $Flag = "True" Else $Flag = "False" EndIf ;Option 3 For $ = 0 to 5 $2 = $2 ~ $array[$] Next If $2 = -1 $Flag = "True" Else $Flag = "False" EndIf
Witto
(MM club member)
2006-08-26 06:25 PM
Re: Math Help
Code: Break On $array = 0,0,0,-1,0,-1 $flag = 'true' For $n = 0 to Ubound($array) If $array[$n] = -1 ? 'Element ' + $n ' is -1' Else $flag = "false" $n = Ubound($array) EndIf Next ? "All elements were -1 = " + $flag
Gargoyle
(MM club member)
2006-08-26 06:34 PM
Re: Math Help
Or as my wife just pointed out...Code: If Ascan($array,"0") = -1 $Flag = True Else $Flag = False EndIf
Les
(KiX Master)
2006-08-26 06:40 PM
Re: Math Help
By assumption is easy as long as the rules don't change.
Gargoyle
(MM club member)
2006-08-26 06:45 PM
Re: Math Help
And since I am making the rules....
Witto
(MM club member)
2006-08-26 06:48 PM
Re: Math Help
Gargoyle, that is even better. Like you said, the array only contains 0 or -1
NTDOC
(KiX Master)
2006-08-26 08:01 PM
Re: Math Help
Your wife? Some type of inside humor or does she actually code too?
Gargoyle
(MM club member)
2006-08-26 08:06 PM
Re: Math Help
No actually she is an accountant and looks at the logic differently. She has some basic programming skills (as in MSBasic) but that is it. So by talking it through with her, sometimes she sees a different way of doing it.
Lonkero
(KiX Master Guru)
2006-08-27 12:47 AM
Re: Math Help
woman had a better logic than you... scary.
Re: Math Help
Great help for the next KiXGolf tournament
Re: Math Help
Here's my GOLFed down version:Code: $a=-1,-1,-1,0,-1 if ubound($a)*3+2=len(join(split(join($a),'-'))) ? 'Array contains only -1s' else ? 'Array does not only contain -1s' endif for a score of 45 for the "-1" check
NTDOC
(KiX Master)
2006-08-27 10:46 PM
Re: Math Help
Not sure how you get 45 with that. Including spaces it should be 149 Including spaces this one is: 73$ =-1 ,-1 ,-1 ,0 ,-1 IIf (UBound ($ )*3 +2 =Len (Join (Split (Join ($ ),'-' ))),'T' ,'F' )
Lonkero
(KiX Master Guru)
2006-08-27 10:49 PM
Re: Math Help
Code: $a=-1,-1,-1,0,-1 ? 'Array does ' if ubound($a)*3+2<>len(join(split(join($a),'-'))) 'not ' endif 'only contain -1s'
Lonkero
(KiX Master Guru)
2006-08-27 10:50 PM
Re: Math Help
actually....Code: $a=-1,-1,-1,0,-1 ? 'Array does ' if 0<len(join(split(join($a),'-1'),'')) 'not ' endif 'only contain -1s'
Re: Math Help
Knew you'd golf it down, NTDOC thought you were already sleeping
Les
(KiX Master)
2006-08-28 01:43 AM
Re: Math Help
All's fair in a game of golf.Code: $=-1,-1,-1,0,-1 IIf(UBound($)*3+2=Len(Join(Split(Join($),-))),T,F)
Lonkero
(KiX Master Guru)
2006-08-28 02:06 AM
Re: Math Help
well, this should still be shorter:Code: $=-1,-1,-1,0,-1 IIf(len(join(split(join($a),'-1'),'')),F,T)
Lonkero
(KiX Master Guru)
2006-08-28 02:09 AM
Re: Math Help
actually, this is even shorter:Code: $=-1,-1,-1,0,-1 IIf(join(split(join($a),'-1'),''),F,T)
Les
(KiX Master)
2006-08-28 03:01 AM
Re: Math Help
I'm losing sight of what is supposed to be true or false. Anyway, back to the original spousal revelation golfed down a bit. $=-1,-1,-1,0,-1 IIf(Ascan($array,0)=-1,T,F)
Lonkero
(KiX Master Guru)
2006-08-28 06:47 AM
Re: Math Help
Code: $=-1,-1,-1,0,-1 IIf(Ascan($array,0)<0,T,F)
NTDOC
(KiX Master)
2006-08-28 10:45 AM
Re: Math Help
Code: $=-1,-1,-1,0,-1 IIf(Ascan($,0)<0,T,F)
NTDOC
(KiX Master)
2006-08-28 10:48 AM
Re: Math Help
To fit Golf rules though it should be this Code: Dim $ $=-1,-1,-1,0,-1 IIf(Ascan($,0)<0,T,F)
Lonkero
(KiX Master Guru)
2006-08-28 02:40 PM
Re: Math Help
well, think it actually should be:Code: IIf(Ascan($,0)<0,T,F) as the input is provided by the caller. odd thing is, none of us saw the varname typos up there... weird.
Gargoyle
(MM club member)
2006-08-28 05:02 PM
Re: Math Help
You mean where everyone kept assigning $= and then doing an Ascan($Array). I figured since you had gone way beyone where I was I would just leave it alone...