Overclock.net - Overclocking.net
     
 
Home Gallery Reviews Blogs Register Today's Posts Mark Forums Read Members List


Go Back   Overclock.net - Overclocking.net > Software, Programming and Coding > Coding and Programming

Reply
 
LinkBack Thread Tools
Old 10-20-09   #1 (permalink)
4.0ghz
 
Coma's Avatar
 
intel nvidia

Join Date: Jun 2007
Posts: 7,512

Rep: 455 Coma is a proven memberComa is a proven memberComa is a proven memberComa is a proven memberComa is a proven member
Unique Rep: 328
Trader Rating: 0
Default Input 5, output 7 - without using ifs

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.

System: Akiyama Mio
CPU
E6420 @ stock, 0.98v
Motherboard
Asus P5N-E SLI
Memory
2x1GB OCZ Platinum @ 800MHz 4-4-4-12 1T, 1.9v
Graphics Card
BFG 8800GT 512MB
Hard Drive
WD 250GB, 320GB SATA/3, 16MB Cache
Power Supply
Corsair 520HX
Case
NZXT Apollo Black
CPU cooling
Stock
OS
Ubuntu 9.04 x86 & XP x86
Monitor
Asus VW222U
Coma is offline Overclocked Account   Reply With Quote
Old 10-20-09   #2 (permalink)
4.0 GHz
 
kevingreenbmx's Avatar
 
intel nvidia

Join Date: Aug 2009
Location: Norfolk, VA, USA
Posts: 1,842

Rep: 149 kevingreenbmx is acknowledged by manykevingreenbmx is acknowledged by many
Unique Rep: 121
Folding Team Rank: 633
Trader Rating: 0
Default

input x

y=12-x

output y



you could also two while loops, but that is cheating and not optimal.

System: Classy
CPU
I7-920-D0@4.0ghz
Motherboard
EVGA x58 Classified 759
Memory
12GB OCZ platinum DDR3-1600
Graphics Card
2X EVGA GTX 280 + EVGA 8800 gt
Hard Drive
2x Velociraptor 150G raid0 + 2x 7200rpm 160G raid0
Power Supply
Corsair HX 1000W
Case
Modded Lian Li PC-V2010B
CPU cooling
Corsair H50 W/ Delta High Speed PWM Fan
OS
Windows 7 x64 (RTM)
Monitor
Samsung T240HD + Samsung 931BF
kevingreenbmx is offline I fold for Overclock.net   Reply With Quote
Old 10-20-09   #3 (permalink)
4.0ghz
 
Coma's Avatar
 
intel nvidia

Join Date: Jun 2007
Posts: 7,512

Rep: 455 Coma is a proven memberComa is a proven memberComa is a proven memberComa is a proven memberComa is a proven member
Unique Rep: 328
Trader Rating: 0
Default



It's so simple I didn't think of it. DERP.

Well, thank you.
__________________
When asking for help: state the goal, not the step.

System: Akiyama Mio
CPU
E6420 @ stock, 0.98v
Motherboard
Asus P5N-E SLI
Memory
2x1GB OCZ Platinum @ 800MHz 4-4-4-12 1T, 1.9v
Graphics Card
BFG 8800GT 512MB
Hard Drive
WD 250GB, 320GB SATA/3, 16MB Cache
Power Supply
Corsair 520HX
Case
NZXT Apollo Black
CPU cooling
Stock
OS
Ubuntu 9.04 x86 & XP x86
Monitor
Asus VW222U
Coma is offline Overclocked Account   Reply With Quote
Old 10-20-09   #4 (permalink)
4.0 GHz
 
kevingreenbmx's Avatar
 
intel nvidia

Join Date: Aug 2009
Location: Norfolk, VA, USA
Posts: 1,842

Rep: 149 kevingreenbmx is acknowledged by manykevingreenbmx is acknowledged by many
Unique Rep: 121
Folding Team Rank: 633
Trader Rating: 0
Default

no problem. :-) i just did a quick linearization of the points. math is your friend. :-)

System: Classy
CPU
I7-920-D0@4.0ghz
Motherboard
EVGA x58 Classified 759
Memory
12GB OCZ platinum DDR3-1600
Graphics Card
2X EVGA GTX 280 + EVGA 8800 gt
Hard Drive
2x Velociraptor 150G raid0 + 2x 7200rpm 160G raid0
Power Supply
Corsair HX 1000W
Case
Modded Lian Li PC-V2010B
CPU cooling
Corsair H50 W/ Delta High Speed PWM Fan
OS
Windows 7 x64 (RTM)
Monitor
Samsung T240HD + Samsung 931BF
kevingreenbmx is offline I fold for Overclock.net   Reply With Quote
Old 4 Weeks Ago   #5 (permalink)
Off By 340 Undecillion
 
The Bartender Paradox's Avatar
 
amd nvidia

Join Date: Oct 2004
Location: Portland, Oregon
Posts: 2,472

Rep: 368 The Bartender Paradox is a proven memberThe Bartender Paradox is a proven memberThe Bartender Paradox is a proven memberThe Bartender Paradox is a proven member
Unique Rep: 276
Hardware Reviews: 1
Trader Rating: 3
Default

Code:
switch(input)
{
    case 5:
        return 7;
    case 7:
        return 5;
}
No ifs involved.
__________________
Congratulations! You have foundthe secret text! You get a cookie.

System: ½
CPU
AMD A64 3500+ Winchester
Motherboard
DFI nF4 SLi-DR
Memory
OCZ 4000VX
Graphics Card
EVGA 7800GT
Hard Drive
Maxtor 300Gb 16Mb Buffer
Sound Card
computers make sounds?
Power Supply
OCZ PowerStream 520W
Case
None
CPU cooling
Big
GPU cooling
Bigger
OS
XP Pro
Monitor
SOYO LCD
The Bartender Paradox is offline Overclocked Account The Bartender Paradox's Gallery   Reply With Quote
Old 4 Weeks Ago   #6 (permalink)
4.0 GHz
 
kevingreenbmx's Avatar
 
intel nvidia

Join Date: Aug 2009
Location: Norfolk, VA, USA
Posts: 1,842

Rep: 149 kevingreenbmx is acknowledged by manykevingreenbmx is acknowledged by many
Unique Rep: 121
Folding Team Rank: 633
Trader Rating: 0
Default

Quote:
Originally Posted by The Bartender Paradox View Post
Code:
switch(input)
{
    case 5:
        return 7;
    case 7:
        return 5;
}
No ifs involved.
that is cheating just like my "while" idea. :-P it is still based on "if" logic.

System: Classy
CPU
I7-920-D0@4.0ghz
Motherboard
EVGA x58 Classified 759
Memory
12GB OCZ platinum DDR3-1600
Graphics Card
2X EVGA GTX 280 + EVGA 8800 gt
Hard Drive
2x Velociraptor 150G raid0 + 2x 7200rpm 160G raid0
Power Supply
Corsair HX 1000W
Case
Modded Lian Li PC-V2010B
CPU cooling
Corsair H50 W/ Delta High Speed PWM Fan
OS
Windows 7 x64 (RTM)
Monitor
Samsung T240HD + Samsung 931BF
kevingreenbmx is offline I fold for Overclock.net   Reply With Quote
Old 4 Weeks Ago   #7 (permalink)
Off By 340 Undecillion
 
The Bartender Paradox's Avatar
 
amd nvidia

Join Date: Oct 2004
Location: Portland, Oregon
Posts: 2,472

Rep: 368 The Bartender Paradox is a proven memberThe Bartender Paradox is a proven memberThe Bartender Paradox is a proven memberThe Bartender Paradox is a proven member
Unique Rep: 276
Hardware Reviews: 1
Trader Rating: 3
Default

Quote:
Originally Posted by kevingreenbmx View Post
that is cheating just like my "while" idea. :-P it is still based on "if" logic.
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."
__________________
Congratulations! You have foundthe secret text! You get a cookie.

System: ½
CPU
AMD A64 3500+ Winchester
Motherboard
DFI nF4 SLi-DR
Memory
OCZ 4000VX
Graphics Card
EVGA 7800GT
Hard Drive
Maxtor 300Gb 16Mb Buffer
Sound Card
computers make sounds?
Power Supply
OCZ PowerStream 520W
Case
None
CPU cooling
Big
GPU cooling
Bigger
OS
XP Pro
Monitor
SOYO LCD
The Bartender Paradox is offline Overclocked Account The Bartender Paradox's Gallery   Reply With Quote
Old 4 Weeks Ago   #8 (permalink)
New to Overclock.net
 
intel nvidia

Join Date: Nov 2007
Location: Surrey, BC, Canada
Posts: 272

Rep: 14 serge2k Unknown
Unique Rep: 14
Trader Rating: 1
Default

int array[6];
array[5] = 7;
input x;
output array[x];
__________________
System: The Black Box
CPU
E6750
Motherboard
Asus P5N-E SLI
Memory
2GB DDR-2 800 MHz
Graphics Card
EVGA 8800 GTS 640
Hard Drive
2x250GB Seagate in Raid 0, 2x1TB WD Caviar Blacks
Sound Card
integrated
Power Supply
Antec Earthwatts 500W
Case
Antec Sonata 3
CPU cooling
Xigmatek HDT S1283
GPU cooling
stock
OS
Windows 7 Ultimate x64
Monitor
22" LG
serge2k is offline   Reply With Quote
Old 4 Weeks Ago   #9 (permalink)
4.0ghz
 
Coma's Avatar
 
intel nvidia

Join Date: Jun 2007
Posts: 7,512

Rep: 455 Coma is a proven memberComa is a proven memberComa is a proven memberComa is a proven memberComa is a proven member
Unique Rep: 328
Trader Rating: 0
Default

Quote:
Originally Posted by The Bartender Paradox View Post
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."
Well, I meant no conditionals
__________________
When asking for help: state the goal, not the step.

System: Akiyama Mio
CPU
E6420 @ stock, 0.98v
Motherboard
Asus P5N-E SLI
Memory
2x1GB OCZ Platinum @ 800MHz 4-4-4-12 1T, 1.9v
Graphics Card
BFG 8800GT 512MB
Hard Drive
WD 250GB, 320GB SATA/3, 16MB Cache
Power Supply
Corsair 520HX
Case
NZXT Apollo Black
CPU cooling
Stock
OS
Ubuntu 9.04 x86 & XP x86
Monitor
Asus VW222U
Coma is offline Overclocked Account   Reply With Quote
Old 4 Weeks Ago   #10 (permalink)
4.0ghz
 
Havegooda's Avatar
 
intel nvidia

Join Date: Sep 2007
Location: Seaside, CA
Posts: 6,227
Blog Entries: 1

Rep: 393 Havegooda is a proven memberHavegooda is a proven memberHavegooda is a proven memberHavegooda is a proven member
Unique Rep: 279
Trader Rating: 20
Default

Quote:
Originally Posted by The Bartender Paradox View Post
Code:
switch(input)
{
    case 5:
        return 7;
    case 7:
        return 5;
}
No ifs involved.
Bahahaha, that's exactly what sprang into my mind.

~Gooda~
__________________

Start folding HERE!
Quote:
Originally Posted by alexgheseger View Post
Wow...

I never thought i'd have to say this, but any penis pictures will net you a hefty infraction mmkay?
Engineering Sample CPUs: Q6600 B0 - Xeon E3110 (E8400) E0 - E5400 (possibly) - E8400 (possibly)

System: Water Cooled Quad
CPU
E3110 Engineernig Sample
Motherboard
DFI DK X48
Memory
4x2GB G.Skill DDR2-1000
Graphics Card
9800GX2
Hard Drive
4x640GB WD AALS - RAID5
Sound Card
Onboard
Power Supply
Ultra X3 850W
Case
RocketFish (Lian-Li) by Cyberdruid
CPU cooling
D-Tek Fusion V1
GPU cooling
Full-cover waterblock.
OS
Vista Ultimate x64
Monitor
Samsung 245BW (24")
Overclock.net - 2009 Chimp Challenge Champions
Havegooda is offline Overclocked Account   Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools



All times are GMT -5. The time now is 07:28 AM.


Overclock.net is a Carbon Neutral Site Creative Commons License

Terms of Service / Forum Rules | Privacy Policy | DMCA Info | Advertising | Become an Official Vendor
Copyright © 2009 Shogun Interactive Development. Most rights reserved.
Page generated in 0.15283 seconds with 8 queries