+ 14
How to get the same output without using any type of conditionals?!
Yesterday, I read an article that made think about it. So, it is possible to get the same results in codes below without using if-statements (or ternary operators, or switch statements)...đ¤â Please feel free to provide explanation and/or examples in whichever language you want to. Thanks! https://code.sololearn.com/c3MdQIvKD75p/?ref=app https://code.sololearn.com/cSpS7b4aMmsZ/?ref=app
33 Respostas
+ 8
Only using 6 chars (jsfuck)
https://code.sololearn.com/W8dWIsVsfo1f/?ref=app
+ 7
Andrei Voinea Thanks for sharing you knowledge. It would've been interesting seeing the similar result you are mentioning. You can submit a solution in any other language in case you want to. đđđť
+ 6
ODNLT Your reply makes me think again!
Technically, a "Logical Operator" could be considered a 'conditional statement', as wellââźď¸
what do you think?!đ¤
+ 6
ODLNT Thanks for your clarification! đ¤
+ 5
ODLNT Wouldn't be "while" also a conditional statement?! Maybe, any other possible solution?!đ
+ 5
Jordan Toum What is your proposal?!
+ 5
Python, without any dirty hacks and even any binary operators
https://code.sololearn.com/cee677wS1Cgg - oops, abs() here has hidden conditional
Okay, this version even better, only int() used as trick (round() can do the trick too)
https://code.sololearn.com/cDuVhB9XZwXn
So, here we go, my variant number 3.
Now works with all numbers. int() does only trick
https://code.sololearn.com/cr1CHBfR55Um
+ 4
ODLNT Let's see if someone else can provide other solutions (and in other languages) as well!
+ 4
In Ruby, there is a powerful hash map which can be any type (boolean too). See this.
https://code.sololearn.com/c0p8l0L7Cskn/?ref=app
+ 4
I think this is the wayđđ
https://code.sololearn.com/ce8RfqPSXMFH/?ref=app
+ 4
Bennett Post Please, put it into a code in PlayGround. So, we can discuss it in the comment section like in previous submissions!
Just edit your entry including the code, thanks!
+ 3
Geovanny
I can guarantee that there will be many other solutions posted.
+ 3
Geovanny
Technically no, logical operators are conjunctions adding conditional statements together to create a compound/complex conditional statement, but your point is well taken in that my answer still uses boolean to solve the problem.
+ 2
Let me know what you think of this solution.
https://code.sololearn.com/WuVNjxTtE2Za/?ref=app
+ 2
https://code.sololearn.com/cILU7oSOYfIM/?ref=app
+ 2
https://code.sololearn.com/cwn8n8NT3KVy/?ref=app
+ 2
Okay, this version even better, only int() used as trick (round() can do the trick too)
https://code.sololearn.com/cDuVhB9XZwXn