-14
\$\begingroup\$

I cannot believe that this hasn't been done before but I may be wrong. If so, just close as dupe.

This challenge is very similar to Is it truthy or falsy? but, IMO, isn't close enough to be a dupe. That has predefined "falsy" variables that all languages must use, some of which aren't even falsy; this uses your own falsy values.

Your task is to take an input, evaluate it and output whether it is truthy or falsy in your language.

The "evaluate" part is just so that the input isn't always a string containing the input. For example an input of 0 would be falsy in almost all languages even if "0" is truthy. It simply means, "convert it into its native type"

Input

Anything. This can be taken from STDIN or as command line arguments.

Output

Its truthy or falsy value in your language. This should be preferably be denoted by true/false or 1/0. If not, please state what is the output for each.

For example, 1, "hello" and [0,2] are all truthy in Python but the third isn't in MATL (? Correct me if wrong)

Rules

  • There must be 2 unique identifiers for truthy and falsy. You can't just say numbers are true and symbols are false
  • Submissions must be full programs
  • This is a but I have a feeling that a challenge this trivial might become a catalogue so if that happens, I will update the body to contain normal catalogue rules.
  • Of course, builtins are allowed but must be part of a full program. For example, bool isn't a valid answer in Python.

Good luck!

\$\endgroup\$

closed as too broad by ATaco, Comrade SparklePony, Mego, fireflame241, user42649 May 26 '17 at 0:40

Please edit the question to limit it to a specific problem with enough detail to identify an adequate answer. Avoid asking multiple distinct questions at once. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.

  • 6
    \$\begingroup\$ This is so trivial it's unbelievable. \$\endgroup\$ – Stephen May 25 '17 at 23:15
  • 1
    \$\begingroup\$ Possible duplicate of Is it truthy or falsy? \$\endgroup\$ – ATaco May 25 '17 at 23:40
  • 1
    \$\begingroup\$ It isn't a duplicate, and I don't think it's closeable under our current rules (if it does, "unclear" would be the only reasonable choice; because the challenge doesn't explain how it works for languages that don't have a Boolean-equivalent, such as Prolog, Incident, and Three Star Programmer). That said, it might be worth a meta post about what we should do with extremely-trivial-in-practical-language challenges like this. \$\endgroup\$ – user62131 May 25 '17 at 23:52
  • 3
    \$\begingroup\$ Why full programs only? \$\endgroup\$ – CalculatorFeline May 26 '17 at 0:08
2
\$\begingroup\$

Japt, 3 2 bytes

o

Needs the -d flag.

Try it online!

\$\endgroup\$
  • \$\begingroup\$ Beat me to it; I've really gotta get my brain thinking in Japt over JS 'round here! \$\endgroup\$ – Shaggy May 25 '17 at 23:19
  • \$\begingroup\$ Also o with the -d flag would work. Though it would still be 3 bytes. \$\endgroup\$ – powelles May 25 '17 at 23:52
  • \$\begingroup\$ @powelles, for some reason flags only count as 1 byte. \$\endgroup\$ – Shaggy May 26 '17 at 7:28
0
\$\begingroup\$

JavaScript (ES6), 6 bytes

i=>!!i
\$\endgroup\$
  • \$\begingroup\$ OP wants a full program, not a funciton. \$\endgroup\$ – Stephen May 25 '17 at 23:15
  • \$\begingroup\$ alert(!!prompt()) is more valid. \$\endgroup\$ – ATaco May 26 '17 at 1:54
0
\$\begingroup\$

Convex, 2 bytes

!!

Try it online!

\$\endgroup\$
0
\$\begingroup\$

RProgN 2, 2 bytes

¬¬

Try it online!

\$\endgroup\$
0
\$\begingroup\$

Brain-Flak, 14 bytes

({()(<()>)}<>)

Try it online!

Explanation

(        #Set up a push
 {       #Execute if truthy
  ()     #Create 1 value
  (<()>) #Ensure a 0 to exit the loop
 }
 <>      #Switch stacks
)        #Push the value
\$\endgroup\$
0
\$\begingroup\$

RProgN, 1 char, 3 bytes

Added this because I've never really gotten a use for the truthy function, and I wanted to.

Try it online!

\$\endgroup\$
  • \$\begingroup\$ It's a full program too, right? \$\endgroup\$ – CalculatorFeline May 26 '17 at 0:09
  • \$\begingroup\$ Of course. You can see that functionality at the TIO. \$\endgroup\$ – ATaco May 26 '17 at 0:10
0
\$\begingroup\$

Jelly,  4  2 bytes

ṆṆ

Full program returning 1 for Truthy and 0 for Falsy.

Try it online!

How?

ṆṆ - Main link: x
Ṇ  - non-vectorising logical not
 Ṇ - non-vectorising logical not
\$\endgroup\$
0
\$\begingroup\$

Python 2, 28 27 bytes

print(input()and 1>0or 0>1)

Less trivial than just print(bool(input())). String input must be given in quotes as per Python 2 requirements.

-1 byte thanks to ovs

\$\endgroup\$
  • \$\begingroup\$ print(input()and 1>0or 0>1) for 27 bytes \$\endgroup\$ – ovs May 26 '17 at 7:27
  • \$\begingroup\$ Wouldn't print(input()!=0) work as well? \$\endgroup\$ – Mr. Xcoder May 26 '17 at 9:44
  • \$\begingroup\$ @Mr.Xcoder thus would give a false positive for [] \$\endgroup\$ – ovs May 27 '17 at 6:17
  • \$\begingroup\$ @ovs ooo, nice, thanks! \$\endgroup\$ – HyperNeutrino May 27 '17 at 6:22

Not the answer you're looking for? Browse other questions tagged or ask your own question.