Skip to main content
Commonmark migration
Source Link

#MATL, 20 bytes

MATL, 20 bytes

U|sG36ZA13\[BID1]m+g

Input is a string enclosed in single quotes. Output is 1 for truthy or 0 for falsy.

Try it online! Or verify all test cases.

###How it works

How it works

U|s      % Take input implicitly. Interpret as number, absolute value, sum
G36ZA    % Push input again. Convert from base-36
13\      % Modulo 13
[BID1]   % Push array [6 3 8 1]
m        % True if member: gives 1 iff the result from modulo 13 is in the array
+g       % Add, convert to logical. Display implicitly

This performs two tests on the input:

  1. Try to interpret the input as a number, and detect if it is nonzero. The function used to interpret a string as a number outputs an empty array if it's not possible; and the sum of the entries of an empty array is 0. So it suffices to try the conversion, take the absolute value, and sum. This gives a positive value if the input contains a nonzero number, and 0 otherwise.
  2. Assuming the input string doesn't represent a number, we need to classify it into one of the two given sets. To do this, the input is interpreted as the digits of a number expressed in base-36, using alphabet '01...9ab...z'. The base conversion function is case-insensitive and ignores digits not present in the alphabet (in our case, '-'). It turns out that the modulo 13 of the resulting number is 1, 3, 6 or 8 for the truthy strings, and doesn't give any of those values for the falsy strings. So it can be used as a signature. We thus perform modulo 13 and see if the result is any of those four values. This gives 1 if it is, or 0 otherwise.

The final result should be truthy if any of the two conditions is met, and falsy otherwise. So we add the two numbers resulting from 1 and 2 above and convert to logical, which gives 1 or 0 as standardized truthy/falsy values.

#MATL, 20 bytes

U|sG36ZA13\[BID1]m+g

Input is a string enclosed in single quotes. Output is 1 for truthy or 0 for falsy.

Try it online! Or verify all test cases.

###How it works

U|s      % Take input implicitly. Interpret as number, absolute value, sum
G36ZA    % Push input again. Convert from base-36
13\      % Modulo 13
[BID1]   % Push array [6 3 8 1]
m        % True if member: gives 1 iff the result from modulo 13 is in the array
+g       % Add, convert to logical. Display implicitly

This performs two tests on the input:

  1. Try to interpret the input as a number, and detect if it is nonzero. The function used to interpret a string as a number outputs an empty array if it's not possible; and the sum of the entries of an empty array is 0. So it suffices to try the conversion, take the absolute value, and sum. This gives a positive value if the input contains a nonzero number, and 0 otherwise.
  2. Assuming the input string doesn't represent a number, we need to classify it into one of the two given sets. To do this, the input is interpreted as the digits of a number expressed in base-36, using alphabet '01...9ab...z'. The base conversion function is case-insensitive and ignores digits not present in the alphabet (in our case, '-'). It turns out that the modulo 13 of the resulting number is 1, 3, 6 or 8 for the truthy strings, and doesn't give any of those values for the falsy strings. So it can be used as a signature. We thus perform modulo 13 and see if the result is any of those four values. This gives 1 if it is, or 0 otherwise.

The final result should be truthy if any of the two conditions is met, and falsy otherwise. So we add the two numbers resulting from 1 and 2 above and convert to logical, which gives 1 or 0 as standardized truthy/falsy values.

MATL, 20 bytes

U|sG36ZA13\[BID1]m+g

Input is a string enclosed in single quotes. Output is 1 for truthy or 0 for falsy.

Try it online! Or verify all test cases.

How it works

U|s      % Take input implicitly. Interpret as number, absolute value, sum
G36ZA    % Push input again. Convert from base-36
13\      % Modulo 13
[BID1]   % Push array [6 3 8 1]
m        % True if member: gives 1 iff the result from modulo 13 is in the array
+g       % Add, convert to logical. Display implicitly

This performs two tests on the input:

  1. Try to interpret the input as a number, and detect if it is nonzero. The function used to interpret a string as a number outputs an empty array if it's not possible; and the sum of the entries of an empty array is 0. So it suffices to try the conversion, take the absolute value, and sum. This gives a positive value if the input contains a nonzero number, and 0 otherwise.
  2. Assuming the input string doesn't represent a number, we need to classify it into one of the two given sets. To do this, the input is interpreted as the digits of a number expressed in base-36, using alphabet '01...9ab...z'. The base conversion function is case-insensitive and ignores digits not present in the alphabet (in our case, '-'). It turns out that the modulo 13 of the resulting number is 1, 3, 6 or 8 for the truthy strings, and doesn't give any of those values for the falsy strings. So it can be used as a signature. We thus perform modulo 13 and see if the result is any of those four values. This gives 1 if it is, or 0 otherwise.

The final result should be truthy if any of the two conditions is met, and falsy otherwise. So we add the two numbers resulting from 1 and 2 above and convert to logical, which gives 1 or 0 as standardized truthy/falsy values.

edited body; added 18 characters in body; added 6 characters in body
Source Link
Luis Mendo
  • 105.3k
  • 9
  • 135
  • 372

#MATL, 20 bytes

U|sG36ZA13\[BID1]m+g

Input is a string enclosed in single quotes. Output is 1 for truthy or 0 for falsy.

Try it online! Or verify all test cases.

###How it works

U|s      % Take input implicitly. Interpret as number, absolute value, sum
G36ZA    % Push input again. Convert from base-36
13\      % Modulo 13
[BID1]   % Push array [6 3 8 1]
m        % True if member: gives 1 iff the result from modulo 13 is in the array
+g       % Add, convert to logical. Display implicitly

This performs two tests on the input:

  1. Try to interpret the input as a number, and detect if it is nonzero. The function used to interpret a string as a number outputs an empty array if it's not possible; and the sum of the entries of an empty array is 0. So it suffices to try the conversion, take the absolute value, and sum. This gives a positive value ifftheif the input contains a nonzero number, and 0 otherwise.
  2. Assuming the input is notstring doesn't represent a number, we need to classify it into one of the two given sets. To do this, the input is interpreted as the digits of a number expressed in base-36, using alphabet '01...9ab...z'. The base conversion function is case-insensitive and ignores digits not present in the alphabet (in our case, '-'). It turns out that the modulo 13 of the resulting number is 1, 3, 6 or 8 for the truthy strings, and doesn't give any of those values for the falsy strings. So it can be used as a signature. We thus perform modulo 13 and see if the result is any of those four values. This gives 1 if it is, or 0 otherwise.

The final result should be truthy if any of the two conditions is met, and falsy otherwise. So we add the two numbers resulting from 1 and 2 above and convert to logical, which gives 1 or 0 as standardized truthy/falsy values.

#MATL, 20 bytes

U|sG36ZA13\[BID1]m+g

Input is a string enclosed in single quotes. Output is 1 for truthy or 0 for falsy.

Try it online! Or verify all test cases.

###How it works

U|s      % Take input implicitly. Interpret as number, absolute value, sum
G36ZA    % Push input again. Convert from base-36
13\      % Modulo 13
[BID1]   % Push array [6 3 8 1]
m        % True if member: gives 1 iff the result from modulo 13 is in the array
+g       % Add, convert to logical. Display implicitly

This performs two tests on the input:

  1. Try to interpret the input as a number, and detect if it is nonzero. The function used to interpret a string as a number outputs an empty array if it's not possible; and the sum of the entries of an empty array is 0. So it suffices to try the conversion, take the absolute value, and sum. This gives a positive value iffthe input contains a nonzero number, and 0 otherwise.
  2. Assuming the input is not a number, we need to classify it into one of the two sets. To do this, the input is interpreted as the digits of a number expressed in base-36, using alphabet '01...9ab...z'. The base conversion function is case-insensitive and ignores digits not present in the alphabet (in our case, '-'). It turns out that the modulo 13 of the resulting number is 1, 3, 6 or 8 for the truthy strings, and doesn't give any of those values for the falsy strings. So it can be used as a signature. We thus perform modulo 13 and see if the result is any of those four values. This gives 1 if it is, or 0 otherwise.

The final result should be truthy if any of the two conditions is met, and falsy otherwise. So we add the two numbers resulting from 1 and 2 above and convert to logical, which gives 1 or 0 as standardized truthy/falsy values.

#MATL, 20 bytes

U|sG36ZA13\[BID1]m+g

Input is a string enclosed in single quotes. Output is 1 for truthy or 0 for falsy.

Try it online! Or verify all test cases.

###How it works

U|s      % Take input implicitly. Interpret as number, absolute value, sum
G36ZA    % Push input again. Convert from base-36
13\      % Modulo 13
[BID1]   % Push array [6 3 8 1]
m        % True if member: gives 1 iff the result from modulo 13 is in the array
+g       % Add, convert to logical. Display implicitly

This performs two tests on the input:

  1. Try to interpret the input as a number, and detect if it is nonzero. The function used to interpret a string as a number outputs an empty array if it's not possible; and the sum of the entries of an empty array is 0. So it suffices to try the conversion, take the absolute value, and sum. This gives a positive value if the input contains a nonzero number, and 0 otherwise.
  2. Assuming the input string doesn't represent a number, we need to classify it into one of the two given sets. To do this, the input is interpreted as the digits of a number expressed in base-36, using alphabet '01...9ab...z'. The base conversion function is case-insensitive and ignores digits not present in the alphabet (in our case, '-'). It turns out that the modulo 13 of the resulting number is 1, 3, 6 or 8 for the truthy strings, and doesn't give any of those values for the falsy strings. So it can be used as a signature. We thus perform modulo 13 and see if the result is any of those four values. This gives 1 if it is, or 0 otherwise.

The final result should be truthy if any of the two conditions is met, and falsy otherwise. So we add the two numbers resulting from 1 and 2 above and convert to logical, which gives 1 or 0 as standardized truthy/falsy values.

deleted 1 character in body
Source Link
Luis Mendo
  • 105.3k
  • 9
  • 135
  • 372

#MATL, 20 bytes

U|sG36ZA13\[BID1]m+g

Input is a string enclosed in single quotes. Output is 1 for truthy or 0 for falsy.

Try it online! Or verify all test cases.

###How it works

U|s      % Take input implicitly. Interpret as number, absolute value, sum
G36ZA    % Push input again. Convert from base-36
13\      % Modulo 13
[BID1]   % Push array [6 3 8 1]
m        % True if member: gives 1 iff the result from modulo 13 is in the array
+g       % Add, convert to logical. Display implicitly

This performs two tests on the input:

  1. Try to interpret the input as a number, and detect if it is nonzero. The function used to interpret a string as a number outputs an empty array if it's not possible; and the sum of the entries of an empty array is 0. So it suffices to try the conversion, take the absolute value, and sum. This gives a positive value iffthe input contains a nonzero number, and 0 otherwise.
  2. Assuming the input is not a number, we need to classify it into one of the two sets. To do this, the input is interpreted as the digits of a number expressed in base-36, using alphabet '01...9ab...z'. The base conversion function is case-insensitive and ignores digits not present in the alphabet (in our case, '-'). It turns out that the modulo 13 of the resulting number is 1, 3, 6 or 8 for the truthy strings, and doesn't give any of those values for the falsy strings. Se we only need toSo it can be used as a signature. We thus perform modulo 13 and see if the result is any of those four values. The result isThis gives 1 if it is, or 0 otherwise.

The final result should be (standardized) truthy if any of the two conditions is fulfilledmet, and falsy otherwise. So we add the two numbers resulting from 11 and 22 above and convert to logical, which gives 1 or 0 as standardized truthy/falsy values.

#MATL, 20 bytes

U|sG36ZA13\[BID1]m+g

Input is a string enclosed in single quotes. Output is 1 for truthy or 0 for falsy.

Try it online! Or verify all test cases.

###How it works

U|s      % Take input implicitly. Interpret as number, absolute value, sum
G36ZA    % Push input again. Convert from base-36
13\      % Modulo 13
[BID1]   % Push array [6 3 8 1]
m        % True if member: gives 1 iff the result from modulo 13 is in the array
+g       % Add, convert to logical. Display implicitly

This performs two tests on the input:

  1. Try to interpret the input as a number, and detect if it is nonzero. The function used to interpret a string as a number outputs an empty array if it's not possible; and the sum of the entries of an empty array is 0. So it suffices to try the conversion, take the absolute value, and sum. This gives a positive value iffthe input contains a nonzero number, and 0 otherwise.
  2. Assuming the input is not a number, we need to classify it into one of the two sets. To do this, the input is interpreted as the digits of a number expressed in base-36, using alphabet '01...9ab...z'. The base conversion function is case-insensitive and ignores digits not present in the alphabet (in our case, '-'). It turns out that the modulo 13 of the resulting number is 1, 3, 6 or 8 for the truthy strings, and doesn't give any of those values for the falsy strings. Se we only need to perform modulo 13 and see if the result is any of those four values. The result is 1 if it is, or 0 otherwise.

The final result should be (standardized) truthy if any of the two conditions is fulfilled, and falsy otherwise. So we add the two numbers resulting from 1 and 2 and convert to logical, which gives 1 or 0 as standardized truthy/falsy values.

#MATL, 20 bytes

U|sG36ZA13\[BID1]m+g

Input is a string enclosed in single quotes. Output is 1 for truthy or 0 for falsy.

Try it online! Or verify all test cases.

###How it works

U|s      % Take input implicitly. Interpret as number, absolute value, sum
G36ZA    % Push input again. Convert from base-36
13\      % Modulo 13
[BID1]   % Push array [6 3 8 1]
m        % True if member: gives 1 iff the result from modulo 13 is in the array
+g       % Add, convert to logical. Display implicitly

This performs two tests on the input:

  1. Try to interpret the input as a number, and detect if it is nonzero. The function used to interpret a string as a number outputs an empty array if it's not possible; and the sum of the entries of an empty array is 0. So it suffices to try the conversion, take the absolute value, and sum. This gives a positive value iffthe input contains a nonzero number, and 0 otherwise.
  2. Assuming the input is not a number, we need to classify it into one of the two sets. To do this, the input is interpreted as the digits of a number expressed in base-36, using alphabet '01...9ab...z'. The base conversion function is case-insensitive and ignores digits not present in the alphabet (in our case, '-'). It turns out that the modulo 13 of the resulting number is 1, 3, 6 or 8 for the truthy strings, and doesn't give any of those values for the falsy strings. So it can be used as a signature. We thus perform modulo 13 and see if the result is any of those four values. This gives 1 if it is, or 0 otherwise.

The final result should be truthy if any of the two conditions is met, and falsy otherwise. So we add the two numbers resulting from 1 and 2 above and convert to logical, which gives 1 or 0 as standardized truthy/falsy values.

added 1093 characters in body
Source Link
Luis Mendo
  • 105.3k
  • 9
  • 135
  • 372
Loading
added 1093 characters in body
Source Link
Luis Mendo
  • 105.3k
  • 9
  • 135
  • 372
Loading
Post Undeleted by Luis Mendo
added 4 characters in body
Source Link
Luis Mendo
  • 105.3k
  • 9
  • 135
  • 372
Loading
Post Deleted by Luis Mendo
Source Link
Luis Mendo
  • 105.3k
  • 9
  • 135
  • 372
Loading