|
![]() |
Overclock.net - Overclocking.net > Software, Programming and Coding > Coding and Programming | |
Input 5, output 7 - without using ifs
|
||
![]() |
|
|
LinkBack | Thread Tools |
|
|
#1 (permalink) | |||||||||||
|
4.0ghz
![]() |
How do you do this? Also the reverse - input 7, output 5.
In any language. Pseudocode is fine too. I was asked this question and couldn't come up with an answer.
__________________
When asking for help: state the goal, not the step.
|
|||||||||||
|
|
|
|
#2 (permalink) | |||||||||||
|
4.0 GHz
![]() |
input x
y=12-x output y you could also two while loops, but that is cheating and not optimal.
__________________
|
|||||||||||
|
|
|
|
|
#3 (permalink) | |||||||||||
|
4.0ghz
![]() |
![]() It's so simple I didn't think of it. DERP. Well, thank you.
__________________
When asking for help: state the goal, not the step.
|
|||||||||||
|
|
|
|
#4 (permalink) | |||||||||||
|
4.0 GHz
![]() |
no problem. :-) i just did a quick linearization of the points. math is your friend. :-)
__________________
|
|||||||||||
|
|
|
|
|
#5 (permalink) | |||||||||||||
|
Off By 340 Undecillion
![]() |
Code:
switch(input)
{
case 5:
return 7;
case 7:
return 5;
}
|
|||||||||||||
|
|
|
|
#6 (permalink) | |||||||||||
|
4.0 GHz
![]() |
that is cheating just like my "while" idea. :-P it is still based on "if" logic.
__________________
|
|||||||||||
|
|
|
|
|
#7 (permalink) | |||||||||||||
|
Off By 340 Undecillion
![]() |
It's based on conditional jumps "logic" as are if statements, but switches are not if statements. The OP did not say "without using conditional jumps," he said "without using ifs."
|
|||||||||||||
|
|
|
|
#8 (permalink) | |||||||||||||
|
New to Overclock.net
|
int array[6];
__________________array[5] = 7; input x; output array[x];
|
|||||||||||||
|
|
|
|
|
#9 (permalink) | ||||||||||||
|
4.0ghz
![]() |
Quote:
__________________
When asking for help: state the goal, not the step.
|
||||||||||||
|
|
|
|
#10 (permalink) | |||||||||||||||
|
4.0ghz
![]() |
Quote:
~Gooda~
__________________
Start folding HERE! Quote:
|
|||||||||||||||
|
|
![]() |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
|
|