[S S N
_Push_0][S N
S _Duplicate_0][T N
T T _Read_STDIN_as_integer][T T T _Retrieve_input][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.
Try it online. You'll have to copy-paste the code yourself (note that SE converts the tabs to a bunch of spaces!) in order to run the code at the online Whitespace-compiler vii5ard. When clicking run, it will ask for an input (i.e. -285.5
), and after clicking enter it will continue and output -283
.
Explanation in pseudo-code:
Integer i = STDIN as integer
Print i as integer
Whitespace can only use I/O as integers or single characters, so in this case it would read the input as integer and ignore any other trailing characters. I.e. -283.5
or -283abc5
would both be input (and thus output) as -283
.
Unfortunately this above doesn't work on TIO for two reasons (all Whitespace compilers are slightly different..):
- It will give a
no parse
error when we try to read an input as integer, which isn't an a valid integer. So, instead we'll read one character at a time, and stop (with an error) as soon as we've encountered the .
or there is no more input (i.e. 50
/-50
).
- In the vii5ard compiler it's also possible to push 0 with just
SSN
, whereas on TIO it requires an additional S
or T
: SSSN
/SSTN
. The first S
is Enable Stack Manipulation; the second S
is Push what follows as integer; the third S
/T
is positive/negative respectively; and any S
/T
after that (followed by an N
) is the number we want to push in binary, where S=0
and T=1
. For integer 0 this binary part doesn't matter, since it's 0 by default. But on TIO we'd still have to specify the positive/negative, and with most other Whitespace compilers like vii5ard not.
Whitespace (with TIO compiler), 48 bytes
[N
S S N
_Create_Label_LOOP][S S S N
_Push_0][S N
S _Duplicate_0][T N
T S _Read_STDIN_as_character][T T T _Retrieve_input][S N
S _Duplicate_input][S S S T S T T T S N
_Push_46_.][T S S T _Subtract][N
T S S N
_If_0_Jump_to_Label_EXIT][T N
S S _Print_as_character][N
S N
N
_Jump_to_Label_LOOP]
Letters S
(space), T
(tab), and N
(new-line) added as highlighting only.
[..._some_action]
added as explanation only.
Try it online (with raw spaces, tabs and new-lines only).
Explanation in pseudo-code:
Start LOOP:
Character c = STDIN as character
If(c == '.'):
Exit program
Print c as character
Go to the next iteration of LOOP
3.00
dla3.14
?