Skip to main content
More efficient use of whitespace, more efficient validity check
Source Link

><>, 8989 84 Bytes

8>i$1\ /\?:-/ \8+ \ /1-:?v~&>3*\v~r3*+\ \ } \$ // + /++-/f } l \+3ff/+\?-3/ /a%a+/ \$\$>3*+v< /++-&=n;/f} l \+3ff/\?-4/ /a+++/ \%0=n; 

Can probably certainly be improved (this is my second ><> program)

How it works:

8>i$1\ \?:-/ 

Gets user input, 8 times. Note that since i pushes -1 if the input stack is empty, this may not always return false for inputs shorter than 8 digits.

/ \8+ \ /1-:?v \ } \$ /++-/f \+3ff/ 

Converts the ascii values to their actual values.

 ~&>3*\~r3*+\   // +>3*+v<   } l   \?-34/ 

Remove the counter, and store the checksum digit inreverse the registerstack. Then, while the stack is longer than 34, multiply the top value by three, add it to the digit below it, and move the result to the bottom of the stack.

 /+ /a%a+a+++/ \$-a%&=n;\%0=n; 

Sum the values on the stack. TakeIf the sum modulo 10 and subtract it fromanswer is divisible by 10 to get the expected checksum digit. Output the actual checksum digit from the register, and check if they are congruent modulo 10 (in case the sum was a multiple of 10, so that 10 - (sum % 10) = 10)code is valid. If so, print 1, otherwise, 0.

><>, 89 Bytes

8>i$1\ /\?:-/ \8+ \ /1-:?v~&>3*\ \ } \$ // + /++-/f } l \+3ff/+\?-3/ /a%a+/ \$-&=n; 

Can probably certainly be improved (this is my second ><> program)

How it works:

8>i$1\ \?:-/ 

Gets user input, 8 times. Note that since i pushes -1 if the input stack is empty, this may not always return false for inputs shorter than 8 digits.

/ \8+ \ /1-:?v \ } \$ /++-/f \+3ff/ 

Converts the ascii values to their actual values.

 ~&>3*\   // +   } l   \?-3/ 

Remove the counter, and store the checksum digit in the register. Then, while the stack is longer than 3, multiply the top value by three, add it to the digit below it, and move the result to the bottom of the stack.

 /+ /a%a+/ \$-a%&=n; 

Sum the values on the stack. Take the sum modulo 10 and subtract it from 10 to get the expected checksum digit. Output the actual checksum digit from the register, and check if they are congruent modulo 10 (in case the sum was a multiple of 10, so that 10 - (sum % 10) = 10). If so, print 1, otherwise, 0.

><>, 89 84 Bytes

8>i$1\ /\?:-/ \8+ \ /1-:?v~r3*+\ \ } \$>3*+v< /++-/f} l \+3ff/\?-4/ /a+++/ \%0=n; 

Can probably certainly be improved (this is my second ><> program)

How it works:

8>i$1\ \?:-/ 

Gets user input, 8 times. Note that since i pushes -1 if the input stack is empty, this may not always return false for inputs shorter than 8 digits.

/ \8+ \ /1-:?v \ } \$ /++-/f \+3ff/ 

Converts the ascii values to their actual values.

 ~r3*+\ >3*+v< } l \?-4/ 

Remove the counter, and reverse the stack. Then, while the stack is longer than 4, multiply the top value by three, add it to the digit below it, and move the result to the bottom of the stack.

 / /a+++/ \%0=n; 

Sum the values on the stack. If the answer is divisible by 10, the code is valid. If so, print 1, otherwise, 0.

Post Undeleted by Bolce Bussiere
added 85 characters in body
Source Link

><>, 8789 Bytes

8>i$1\ /\?:-/ \8+ \ /1-:?v~&>3*\ \ } \$ // + /++-/f } l \+3ff/+\?-3/ /a%a+/ \$-&=n; 

Can probably certainly be improved (this is my second ><> program)

How it works:

8>i$1\ \?:-/ 

Gets user input, 8 times. Note that since i pushes -1 if the input stack is empty, this may not always return false for inputs shorter than 8 digits.

/ \8+ \ /1-:?v \ } \$ /++-/f \+3ff/ 

Converts the ascii values to their actual values.

 ~&>3*\ // + } l \?-3/ 

Remove the counter, and store the checksum digit in the register. Then, while the stack is longer than 3, multiply the top value by three, add it to the digit below it, and move the result to the bottom of the stack.

 /+ /a%a+/ \$-&=n;a%&=n; 

Sum the values on the stack. Take the sum modulo 10 and subtract it from 10 to get the expected checksum digit. Output the actual checksum digit from the register, and check if they are equalcongruent modulo 10 (in case the sum was a multiple of 10, so that 10 - (sum % 10) = 10). If so, print 1, otherwise, 0.

><>, 87 Bytes

8>i$1\ /\?:-/ \8+ \ /1-:?v~&>3*\ \ } \$ // + /++-/f } l \+3ff/+\?-3/ /a%a+/ \$-&=n; 

Can probably certainly be improved (this is my second ><> program)

How it works:

8>i$1\ \?:-/ 

Gets user input, 8 times. Note that since i pushes -1 if the input stack is empty, this may not always return false for inputs shorter than 8 digits.

/ \8+ \ /1-:?v \ } \$ /++-/f \+3ff/ 

Converts the ascii values to their actual values.

 ~&>3*\ // + } l \?-3/ 

Remove the counter, and store the checksum digit in the register. Then, while the stack is longer than 3, multiply the top value by three, add it to the digit below it, and move the result to the bottom of the stack.

 /+ /a%a+/ \$-&=n; 

Sum the values on the stack. Take the sum modulo 10 and subtract it from 10 to get the expected checksum digit. Output the actual checksum digit from the register, and check if they are equal. If so, print 1, otherwise, 0.

><>, 89 Bytes

8>i$1\ /\?:-/ \8+ \ /1-:?v~&>3*\ \ } \$ // + /++-/f } l \+3ff/+\?-3/ /a%a+/ \$-&=n; 

Can probably certainly be improved (this is my second ><> program)

How it works:

8>i$1\ \?:-/ 

Gets user input, 8 times. Note that since i pushes -1 if the input stack is empty, this may not always return false for inputs shorter than 8 digits.

/ \8+ \ /1-:?v \ } \$ /++-/f \+3ff/ 

Converts the ascii values to their actual values.

 ~&>3*\ // + } l \?-3/ 

Remove the counter, and store the checksum digit in the register. Then, while the stack is longer than 3, multiply the top value by three, add it to the digit below it, and move the result to the bottom of the stack.

 /+ /a%a+/ \$-a%&=n; 

Sum the values on the stack. Take the sum modulo 10 and subtract it from 10 to get the expected checksum digit. Output the actual checksum digit from the register, and check if they are congruent modulo 10 (in case the sum was a multiple of 10, so that 10 - (sum % 10) = 10). If so, print 1, otherwise, 0.

Post Deleted by Bolce Bussiere
Source Link

><>, 87 Bytes

8>i$1\ /\?:-/ \8+ \ /1-:?v~&>3*\ \ } \$ // + /++-/f } l \+3ff/+\?-3/ /a%a+/ \$-&=n; 

Can probably certainly be improved (this is my second ><> program)

How it works:

8>i$1\ \?:-/ 

Gets user input, 8 times. Note that since i pushes -1 if the input stack is empty, this may not always return false for inputs shorter than 8 digits.

/ \8+ \ /1-:?v \ } \$ /++-/f \+3ff/ 

Converts the ascii values to their actual values.

 ~&>3*\ // + } l \?-3/ 

Remove the counter, and store the checksum digit in the register. Then, while the stack is longer than 3, multiply the top value by three, add it to the digit below it, and move the result to the bottom of the stack.

 /+ /a%a+/ \$-&=n; 

Sum the values on the stack. Take the sum modulo 10 and subtract it from 10 to get the expected checksum digit. Output the actual checksum digit from the register, and check if they are equal. If so, print 1, otherwise, 0.