DO NOT DEAL WITH THIS MEMBER
Hey guys,
anyone got any idea how to print element greater than some value from a set without using booleans?
E.g., suppose I have the set x, which includes the elements (1, 4, 6, 3, 5, 2, 9).
Obviously, we can print all the values of x greater than 5 using the following code:
x[x>5] (I code in R, but pretty similar to JAVA)
But this way of coding uses booleans (it uses TRUE, FALSE etc.)
But is there any way to do this using solely integers?
I was thinking about some sort of loop that would start contain the number of elements, and then do
x[c(variable)]
but I don't know really.
Please help?
Are you limited by bitwise operators as well? i.e. can you use (^, |, &, >>, <<, ~)? It would help a bit if you could tell which operators are allowed and which are not.
Not entirely sure why you wouldn't do a simple comparison but anyways, I'll just explain my thought process instead of writing code for a language you don't use. I may be overlooking something but you can't inherently choose when to print or not print something "using solely integers". So I can't really give you what you're looking for. You'd have to check if a number fell within some given parameter (greater than in this case).
I did derive a formula to produce the largest of two numbers a while ago though: 0.5*(abs(a-b)+abs(a+b)) for two given integers, a and b. I don't have the exact proof anymore but it works. I suppose you could apply this to every number in the loop, and set one of the integers to five, you'd still run into the problem of five being produced when it was larger than the other integer. You could filter it but really, any filter function uses some sort of Boolean.
DO NOT DEAL WITH THIS MEMBER
Does this work?
Example.java
Code import java.lang.*;
class Example {
private static void loop(int[] values, Integer printAllGreaterThan, int i) {
try {
i += 1;
Integer x = values[i] - printAllGreaterThan;
x = -x;
int c = 1 / ((int)x & 0x80000000);
System.out.println(values[i]);
}
catch (ArrayIndexOutOfBoundsException ex) {
System.exit(0);
}
catch (Exception ex) { }
loop(values, printAllGreaterThan, i);
}
public static void main(String[] args) {
int[] values = new int[] {1, 4, 6, 3, 5, 2, 9};
int printAllGreaterThan = 5;
loop(values, printAllGreaterThan, -1);
}
}
Output
Code PS C:\Users\User\Desktop> javac Example.java
PS C:\Users\User\Desktop> java Example
6
9
PS C:\Users\User\Desktop>
(Feb 10, 2019 05:00 AM)cryptobassboost Wrote: Hey guys,
anyone got any idea how to print element greater than some value from a set without using booleans?
E.g., suppose I have the set x, which includes the elements (1, 4, 6, 3, 5, 2, 9).
Obviously, we can print all the values of x greater than 5 using the following code:
x[x>5] (I code in R, but pretty similar to JAVA)
But this way of coding uses booleans (it uses TRUE, FALSE etc.)
But is there any way to do this using solely integers?
I was thinking about some sort of loop that would start contain the number of elements, and then do
x[c(variable)]
but I don't know really.
Please help?
thx bro 🤩
|