Skip to main content
Post Undeleted by Kevin Cruijssen
Fixed a bug
Source Link
Kevin Cruijssen
  • 131.4k
  • 13
  • 144
  • 384

Whitespace, 8788 bytes

[S S S N
_Push_0][N
S S N
_Create_Label_LOOP][S N
S _Duplicate_top][SS N
_Push_0][S N
S _Duplicate_top][T N
T   S _Read_STDIN_as_character][T   T   T   _Retrieve][S N
S _Duplicate][S S S T   N
_Push_1][T  S S T   _Subtract][N
T   S S N
_If_0_Jump_to_Label_EXIT][S S S T   T   S S S S N
_Push_48][T S S T   _Subtract][S N
T   _Swap_top_two][S S S T  S T S N
_Push_10][T S S N
_Multiply][T    S S S _Add][N
S N
N
_Jump_to_Label_LOOP][N
S S S N
_Create_Label_EXIT][S N
N
_Discard_top][T N
S T _Print_as_integer]

Try it onlineTry it online (with raw spaces, tabs and new-lines only).

Example run: input = "Hi"input = "Hi!"

Command     Explanation                Stack          Heap            Heap     STDIN  STDOUT  STDERR

SSSN        Push 0                     [0]
NSSN        Create Label LOOP          [0]
 SNSSSSN       Push Duplicate0 top (0)                   [0,0]
 SNS        Duplicate top (0)          [0,0,0]
 TNTS       Read STDIN as character    [0,0]           {0:72}               H
 TTT        Retrieve at address (0)    [0,72]          {0:72}
 SNS        Duplicate top (72)         [0,72,72]       {0:72}
 SSSTN      Push 1                     [0,72,72,1]     {0:72}
 TSST       Subtract top two (72-1)    [0,72,71]       {0:72}
 NTSSN      If 0: Jump to Label EXIT   [0,72]          {0:72}
 SSSTTSSSN  Push 48                    [0,72,48]       {0:72}
 TSST       Subtract top two (72-48)   [0,24]          {0:72}
 SNT        Swap top two               [24,0]          {0:72}
 SSSTSTSN   Push 10                    [24,0,10]       {0:72}
 TSSN       Multiply top two (0*10)    [24,0]          {0:72}
 TSSS       Add top two (24+0)         [24]            {0:72}
 NSNN       Jump to Label LOOP         [24]            {0:72}

 SNSSSSN       Push Duplicate0 top (24)                   [24,24]0]          {0:72}
 SNS        Duplicate top (240)          [24,240,24]0]        {0:72}
 TNTS       Read STDIN as character    [24,24]0]          {0:72,24:105}        i
 TTT        Retrieve at address (240)    [24,105]        {0:72,24:105}
 SNS        Duplicate top (105)        [24,105,105]    {0:72,24:105}
 SSSTN      Push 1                     [24,105,105,1]  {0:72,24:105}
 TSST       Subtract top two (105-1)   [24,105,104]    {0:72,24:105}
 NTSSN      If 0: Jump to Label EXIT   [24,105]        {0:72,24:105}
 SSSTTSSSN  Push 48                    [24,105,48]     {0:72,24:105}
 TSST       Subtract top two (106-48)  [24,57]         {0:72,24:105}
 SNT        Swap top two               [57,24]         {0:72,24:105}
 SSSTSTSN   Push 10                    [57,24,10]      {0:72,24:105}
 TSSN       Multiply top two (24*10)   [57,240]        {0:72,24:105}
 TSSS       Add top two (57+240)       [297]           {0:72,24:105}
 NSNN       Jump to Label LOOP         [297]           {0:72,24:105}

 SNSSSSN       Push Duplicate0 top (297)                   [297,297]0]         {0:105}
 SNS        Duplicate top (2970)          [297,2970,297]0]       {0:105}
 TNTS       Read STDIN as character    [297,297]0]         {0:7233}   !
 TTT        Retrieve at address (0)    [297,2433]        {0:10533}
 SNS        Duplicate top (33)         [297,33,33]     {0:33}
 SSSTN      Push 1                     [297,33,33,1]   {0:33}
 TSST       Subtract top two (33-1)    [297,33,32]     {0:33}
 NTSSN      If 0: Jump to Label EXIT   [297,33]        {0:33}
 SSSTTSSSN  Push 48                    [297,33,48]     {0:33}
 TSST       Subtract top two (33-48)   [297,-15]       {0:33}
 SNT        Swap top two               [-15,297]       {0:33}
 SSSTSTSN   Push 10                    [-15,297,10]    {0:33}
 TSSN       Multiply top two (297*10)  [-15,2970]      {0:33}
 TSSS       Add top two (57+240)       [2955]          {0:33}
 NSNN       Jump to Label LOOP         [2955]          {0:33}

 SSSN       Push 0                     [2955,0]        {0:33}
 SNS        Duplicate top (0)          [2955,0,0]      {0:33}
 TNTS       Read STDIN as character    [2955,0]        {0:1}    ␁
 TTT        Retrieve at address (297)  [297[2955,1]        {0:72,24:105,297:1}
 SNS        Duplicate top (1)          [297[2955,1,1]      {0:72,24:105,297:1}
 SSSTN      Push 1                     [297[2955,1,1,1]    {0:72,24:105,297:1}
 TSST       Subtract top two (1-1)     [297[2955,1,0]      {0:72,24:105,297:1}
 NTSSN      If 0: Jump to Label EXIT   [297[2955,1]        {0:72,24:105,297:1}
NSSSN       Create Label EXIT          [297[2955,1]        {0:72,24:105,297:1}
 SNN        Discard top                [297][2955]          {0:72,24:105,297:1}
 TNST       Print as integer           []              {0:72,24:105,297:1}         297  2955
                                                                               error

Whitespace, 87 bytes

[S S S N
_Push_0][N
S S N
_Create_Label_LOOP][S N
S _Duplicate_top][S N
S _Duplicate_top][T N
T   S _Read_STDIN_as_character][T   T   T   _Retrieve][S N
S _Duplicate][S S S T   N
_Push_1][T  S S T   _Subtract][N
T   S S N
_If_0_Jump_to_Label_EXIT][S S S T   T   S S S S N
_Push_48][T S S T   _Subtract][S N
T   _Swap_top_two][S S S T  S T S N
_Push_10][T S S N
_Multiply][T    S S S _Add][N
S N
N
_Jump_to_Label_LOOP][N
S S S N
_Create_Label_EXIT][S N
N
_Discard_top][T N
S T _Print_as_integer]

Try it online (with raw spaces, tabs and new-lines only).

Example run: input = "Hi"

Command     Explanation                Stack          Heap                 STDIN  STDOUT

SSSN        Push 0                     [0]
NSSN        Create Label LOOP          [0]
 SNS        Duplicate top (0)          [0,0]
 SNS        Duplicate top (0)          [0,0,0]
 TNTS       Read STDIN as character    [0,0]          {0:72}               H
 TTT        Retrieve at address (0)    [0,72]         {0:72}
 SNS        Duplicate top (72)         [0,72,72]      {0:72}
 SSSTN      Push 1                     [0,72,72,1]    {0:72}
 TSST       Subtract top two (72-1)    [0,72,71]      {0:72}
 NTSSN      If 0: Jump to Label EXIT   [0,72]         {0:72}
 SSSTTSSSN  Push 48                    [0,72,48]      {0:72}
 TSST       Subtract top two (72-48)   [0,24]         {0:72}
 SNT        Swap top two               [24,0]         {0:72}
 SSSTSTSN   Push 10                    [24,0,10]      {0:72}
 TSSN       Multiply top two (0*10)    [24,0]         {0:72}
 TSSS       Add top two (24+0)         [24]           {0:72}
 NSNN       Jump to Label LOOP         [24]           {0:72}

 SNS        Duplicate top (24)         [24,24]
 SNS        Duplicate top (24)         [24,24,24]
 TNTS       Read STDIN as character    [24,24]        {0:72,24:105}        i
 TTT        Retrieve at address (24)   [24,105]       {0:72,24:105}
 SNS        Duplicate top (105)        [24,105,105]   {0:72,24:105}
 SSSTN      Push 1                     [24,105,105,1] {0:72,24:105}
 TSST       Subtract top two (105-1)   [24,105,104]   {0:72,24:105}
 NTSSN      If 0: Jump to Label EXIT   [24,105]       {0:72,24:105}
 SSSTTSSSN  Push 48                    [24,105,48]    {0:72,24:105}
 TSST       Subtract top two (106-48)  [24,57]        {0:72,24:105}
 SNT        Swap top two               [57,24]        {0:72,24:105}
 SSSTSTSN   Push 10                    [57,24,10]     {0:72,24:105}
 TSSN       Multiply top two (24*10)   [57,240]       {0:72,24:105}
 TSSS       Add top two (57+240)       [297]          {0:72,24:105}
 NSNN       Jump to Label LOOP         [297]          {0:72,24:105}

 SNS        Duplicate top (297)        [297,297]
 SNS        Duplicate top (297)        [297,297,297]
 TNTS       Read STDIN as character    [297,297]      {0:72,24:105,297:1}  ␁
 TTT        Retrieve at address (297)  [297,1]        {0:72,24:105,297:1}
 SNS        Duplicate top (1)          [297,1,1]      {0:72,24:105,297:1}
 SSSTN      Push 1                     [297,1,1,1]    {0:72,24:105,297:1}
 TSST       Subtract top two (1-1)     [297,1,0]      {0:72,24:105,297:1}
 NTSSN      If 0: Jump to Label EXIT   [297,1]        {0:72,24:105,297:1}
NSSSN       Create Label EXIT          [297,1]        {0:72,24:105,297:1}
 SNN        Discard top                [297]          {0:72,24:105,297:1}
 TNST       Print as integer           []             {0:72,24:105,297:1}         297

Whitespace, 88 bytes

[S S S N
_Push_0][N
S S N
_Create_Label_LOOP][S S S N
_Push_0][S N
S _Duplicate_top][T N
T   S _Read_STDIN_as_character][T   T   T   _Retrieve][S N
S _Duplicate][S S S T   N
_Push_1][T  S S T   _Subtract][N
T   S S N
_If_0_Jump_to_Label_EXIT][S S S T   T   S S S S N
_Push_48][T S S T   _Subtract][S N
T   _Swap_top_two][S S S T  S T S N
_Push_10][T S S N
_Multiply][T    S S S _Add][N
S N
N
_Jump_to_Label_LOOP][N
S S S N
_Create_Label_EXIT][S N
N
_Discard_top][T N
S T _Print_as_integer]

Try it online (with raw spaces, tabs and new-lines only).

Example run: input = "Hi!"

Command     Explanation                Stack           Heap     STDIN  STDOUT  STDERR

SSSN        Push 0                     [0]
NSSN        Create Label LOOP          [0]
 SSSN       Push 0                     [0,0]
 SNS        Duplicate top (0)          [0,0,0]
 TNTS       Read STDIN as character    [0,0]           {0:72}   H
 TTT        Retrieve at address (0)    [0,72]          {0:72}
 SNS        Duplicate top (72)         [0,72,72]       {0:72}
 SSSTN      Push 1                     [0,72,72,1]     {0:72}
 TSST       Subtract top two (72-1)    [0,72,71]       {0:72}
 NTSSN      If 0: Jump to Label EXIT   [0,72]          {0:72}
 SSSTTSSSN  Push 48                    [0,72,48]       {0:72}
 TSST       Subtract top two (72-48)   [0,24]          {0:72}
 SNT        Swap top two               [24,0]          {0:72}
 SSSTSTSN   Push 10                    [24,0,10]       {0:72}
 TSSN       Multiply top two (0*10)    [24,0]          {0:72}
 TSSS       Add top two (24+0)         [24]            {0:72}
 NSNN       Jump to Label LOOP         [24]            {0:72}

 SSSN       Push 0                     [24,0]          {0:72}
 SNS        Duplicate top (0)          [24,0,0]        {0:72}
 TNTS       Read STDIN as character    [24,0]          {0:105}  i
 TTT        Retrieve at address (0)    [24,105]        {0:105}
 SNS        Duplicate top (105)        [24,105,105]    {0:105}
 SSSTN      Push 1                     [24,105,105,1]  {0:105}
 TSST       Subtract top two (105-1)   [24,105,104]    {0:105}
 NTSSN      If 0: Jump to Label EXIT   [24,105]        {0:105}
 SSSTTSSSN  Push 48                    [24,105,48]     {0:105}
 TSST       Subtract top two (106-48)  [24,57]         {0:105}
 SNT        Swap top two               [57,24]         {0:105}
 SSSTSTSN   Push 10                    [57,24,10]      {0:105}
 TSSN       Multiply top two (24*10)   [57,240]        {0:105}
 TSSS       Add top two (57+240)       [297]           {0:105}
 NSNN       Jump to Label LOOP         [297]           {0:105}

 SSSN       Push 0                     [297,0]         {0:105}
 SNS        Duplicate top (0)          [297,0,0]       {0:105}
 TNTS       Read STDIN as character    [297,0]         {0:33}   !
 TTT        Retrieve at address (0)    [297,33]        {0:33}
 SNS        Duplicate top (33)         [297,33,33]     {0:33}
 SSSTN      Push 1                     [297,33,33,1]   {0:33}
 TSST       Subtract top two (33-1)    [297,33,32]     {0:33}
 NTSSN      If 0: Jump to Label EXIT   [297,33]        {0:33}
 SSSTTSSSN  Push 48                    [297,33,48]     {0:33}
 TSST       Subtract top two (33-48)   [297,-15]       {0:33}
 SNT        Swap top two               [-15,297]       {0:33}
 SSSTSTSN   Push 10                    [-15,297,10]    {0:33}
 TSSN       Multiply top two (297*10)  [-15,2970]      {0:33}
 TSSS       Add top two (57+240)       [2955]          {0:33}
 NSNN       Jump to Label LOOP         [2955]          {0:33}

 SSSN       Push 0                     [2955,0]        {0:33}
 SNS        Duplicate top (0)          [2955,0,0]      {0:33}
 TNTS       Read STDIN as character    [2955,0]        {0:1}    ␁
 TTT        Retrieve at address (297)  [2955,1]        {0:1}
 SNS        Duplicate top (1)          [2955,1,1]      {0:1}
 SSSTN      Push 1                     [2955,1,1,1]    {0:1}
 TSST       Subtract top two (1-1)     [2955,1,0]      {0:1}
 NTSSN      If 0: Jump to Label EXIT   [2955,1]        {0:1}
NSSSN       Create Label EXIT          [2955,1]        {0:1}
 SNN        Discard top                [2955]          {0:1}
 TNST       Print as integer           []              {0:1}           2955
                                                                               error
Post Deleted by Kevin Cruijssen
Source Link
Kevin Cruijssen
  • 131.4k
  • 13
  • 144
  • 384

Whitespace, 87 bytes

[S S S N
_Push_0][N
S S N
_Create_Label_LOOP][S N
S _Duplicate_top][S N
S _Duplicate_top][T N
T   S _Read_STDIN_as_character][T   T   T   _Retrieve][S N
S _Duplicate][S S S T   N
_Push_1][T  S S T   _Subtract][N
T   S S N
_If_0_Jump_to_Label_EXIT][S S S T   T   S S S S N
_Push_48][T S S T   _Subtract][S N
T   _Swap_top_two][S S S T  S T S N
_Push_10][T S S N
_Multiply][T    S S S _Add][N
S N
N
_Jump_to_Label_LOOP][N
S S S N
_Create_Label_EXIT][S N
N
_Discard_top][T N
S T _Print_as_integer]

Letters S (space), T (tab), and N (new-line) added as highlighting only.
[..._some_action] added as explanation only.

Since Whitespace inputs one character at a time, the input should contain a trailing ␁ (character with codepoint 1) so it knows when to stop reading characters and the input is done.

Try it online (with raw spaces, tabs and new-lines only).

Explanation in pseudo-code:

Integer result = 0
Start LOOP:
  Integer input = STDIN as character
  If(input - 1 == 0):
    Jump to Label EXIT
  input = input - 48
  result = result * 10
  result = result + input
  Go to the next iteration of LOOP

Label EXIT:
  Print result as integer to STDOUT

Example run: input = "Hi"

Command     Explanation                Stack          Heap                 STDIN  STDOUT

SSSN        Push 0                     [0]
NSSN        Create Label LOOP          [0]
 SNS        Duplicate top (0)          [0,0]
 SNS        Duplicate top (0)          [0,0,0]
 TNTS       Read STDIN as character    [0,0]          {0:72}               H
 TTT        Retrieve at address (0)    [0,72]         {0:72}
 SNS        Duplicate top (72)         [0,72,72]      {0:72}
 SSSTN      Push 1                     [0,72,72,1]    {0:72}
 TSST       Subtract top two (72-1)    [0,72,71]      {0:72}
 NTSSN      If 0: Jump to Label EXIT   [0,72]         {0:72}
 SSSTTSSSN  Push 48                    [0,72,48]      {0:72}
 TSST       Subtract top two (72-48)   [0,24]         {0:72}
 SNT        Swap top two               [24,0]         {0:72}
 SSSTSTSN   Push 10                    [24,0,10]      {0:72}
 TSSN       Multiply top two (0*10)    [24,0]         {0:72}
 TSSS       Add top two (24+0)         [24]           {0:72}
 NSNN       Jump to Label LOOP         [24]           {0:72}

 SNS        Duplicate top (24)         [24,24]
 SNS        Duplicate top (24)         [24,24,24]
 TNTS       Read STDIN as character    [24,24]        {0:72,24:105}        i
 TTT        Retrieve at address (24)   [24,105]       {0:72,24:105}
 SNS        Duplicate top (105)        [24,105,105]   {0:72,24:105}
 SSSTN      Push 1                     [24,105,105,1] {0:72,24:105}
 TSST       Subtract top two (105-1)   [24,105,104]   {0:72,24:105}
 NTSSN      If 0: Jump to Label EXIT   [24,105]       {0:72,24:105}
 SSSTTSSSN  Push 48                    [24,105,48]    {0:72,24:105}
 TSST       Subtract top two (106-48)  [24,57]        {0:72,24:105}
 SNT        Swap top two               [57,24]        {0:72,24:105}
 SSSTSTSN   Push 10                    [57,24,10]     {0:72,24:105}
 TSSN       Multiply top two (24*10)   [57,240]       {0:72,24:105}
 TSSS       Add top two (57+240)       [297]          {0:72,24:105}
 NSNN       Jump to Label LOOP         [297]          {0:72,24:105}

 SNS        Duplicate top (297)        [297,297]
 SNS        Duplicate top (297)        [297,297,297]
 TNTS       Read STDIN as character    [297,297]      {0:72,24:105,297:1}  ␁
 TTT        Retrieve at address (297)  [297,1]        {0:72,24:105,297:1}
 SNS        Duplicate top (1)          [297,1,1]      {0:72,24:105,297:1}
 SSSTN      Push 1                     [297,1,1,1]    {0:72,24:105,297:1}
 TSST       Subtract top two (1-1)     [297,1,0]      {0:72,24:105,297:1}
 NTSSN      If 0: Jump to Label EXIT   [297,1]        {0:72,24:105,297:1}
NSSSN       Create Label EXIT          [297,1]        {0:72,24:105,297:1}
 SNN        Discard top                [297]          {0:72,24:105,297:1}
 TNST       Print as integer           []             {0:72,24:105,297:1}         297

The program stops with an error: no exit defined.