All about flooble | fun stuff | Get a free chatterbox | Free JavaScript | Avatars    
perplexus dot info

Home > Algorithms
Single Line Expression (Posted on 2008-01-27) Difficulty: 1 of 5
Give a single line "C type" expression to evaluate (-1)k using only +,-,* and % operators.

See The Solution Submitted by Praneeth    
Rating: 5.0000 (1 votes)

Comments: ( Back to comment list | You must be logged in to post comments.)
re(2): Whole numbers is reasonable assumption [Spoiler] | Comment 5 of 6 |
(In reply to re: Whole numbers is reasonable assumption by Gamer)

Perhaps my prior comment was a complaint, of a sort, though I wasn't trying to issue one.  I was just wondering if it were possible to provide a more complete solution using only the operators provided.  If one adds the ternary operator (?:), one might give the answer...

(k%1 = 0 ? 1-k%2*2 : "multiple roots exist")

Though the message "multiple roots exist" is not, by definition, an evaluation, it does provide a little more information than the simple error messages that many calculators, spreadsheets, and many other computer applications do. 

As to where k = 1/n, where n is an odd positive integer, the solution -1 is the primary root, though other complex roots exist. 


  Posted by Dej Mar on 2008-01-29 07:03:42
Please log in:
Login:
Password:
Remember me:
Sign up! | Forgot password


Search:
Search body:
Forums (0)
Newest Problems
Random Problem
FAQ | About This Site
Site Statistics
New Comments (24)
Unsolved Problems
Top Rated Problems
This month's top
Most Commented On

Chatterbox:
Copyright © 2002 - 2024 by Animus Pactum Consulting. All rights reserved. Privacy Information