Implement a Truth-Machine

150

24

A truth-machine (credits goes to this guy for coming up with it) is a very simple program designed to demonstrate the I/O and control flow of a language. Here's what a truth-machine does:

  • Gets a number (either 0 or 1) from STDIN.

  • If that number is 0, print out 0 and terminate.

  • If that number is 1, print out 1 forever.

Challenge

Write a truth-machine as described above in your language of choice. The truth-machine must be a full program that follows these rules:

  • take input from STDIN or an acceptable alternative
    • If your language cannot take input from STDIN, it may take input from a hardcoded variable or suitable equivalent in the program
  • must output to STDOUT or an acceptable alternative
    • If your language is incapable of outputting the characters 0 or 1, byte or unary I/O is acceptable.
  • when the input is 1, it must continually print 1s and only stop if the program is killed or runs out of memory
  • the output must only be either a 0 followed by either one or no newline or space, or infinite 1s with each 1 followed by either one or no newline or space. No other output can be generated, except constant output of your language's interpreter that cannot be suppressed (such as a greeting, ANSI color codes or indentation). Your usage of newlines or spaces must be consistent: for example, if you choose to output 1 with a newline after it all 1s must have a newline after them.

  • if and only if your language cannot possibly terminate on an input of 0 it is acceptable for the code to enter an infinite loop in which nothing is outputted.

Since this is a catalog, languages created after this challenge are allowed to compete. Note that there must be an interpreter so the submission can be tested. It is allowed (and even encouraged) to write this interpreter yourself for a previously unimplemented language. Other than that, all the standard rules of must be obeyed. Submissions in most languages will be scored in bytes in an appropriate preexisting encoding (usually UTF-8).

Catalog

The Stack Snippet at the bottom of this post generates the catalog from the answers a) as a list of shortest solution per language and b) as an overall leaderboard.

To make sure that your answer shows up, please start your answer with a headline, using the following Markdown template:

## Language Name, N bytes

where N is the size of your submission. If you improve your score, you can keep old scores in the headline, by striking them through. For instance:

## Ruby, <s>104</s> <s>101</s> 96 bytes

If there you want to include multiple numbers in your header (e.g. because your score is the sum of two files or you want to list interpreter flag penalties separately), make sure that the actual score is the last number in the header:

## Perl, 43 + 2 (-p flag) = 45 bytes

You can also make the language name a link which will then show up in the snippet:

## [><>](http://esolangs.org/wiki/Fish), 121 bytes

<style>body { text-align: left !important} #answer-list { padding: 10px; width: 290px; float: left; } #language-list { padding: 10px; width: 320px; float: left; } table thead { font-weight: bold; } table td { padding: 5px; }</style><script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <link rel="stylesheet" type="text/css" href="//cdn.sstatic.net/codegolf/all.css?v=83c949450c8b"> <div id="language-list"> <h2>Shortest Solution by Language</h2> <table class="language-list"> <thead> <tr><td>Language</td><td>User</td><td>Score</td></tr> </thead> <tbody id="languages"> </tbody> </table> </div> <div id="answer-list"> <h2>Leaderboard</h2> <table class="answer-list"> <thead> <tr><td></td><td>Author</td><td>Language</td><td>Size</td></tr> </thead> <tbody id="answers"> </tbody> </table> </div> <table style="display: none"> <tbody id="answer-template"> <tr><td>{{PLACE}}</td><td>{{NAME}}</td><td>{{LANGUAGE}}</td><td>{{SIZE}}</td><td><a href="{{LINK}}">Link</a></td></tr> </tbody> </table> <table style="display: none"> <tbody id="language-template"> <tr><td>{{LANGUAGE}}</td><td>{{NAME}}</td><td>{{SIZE}}</td><td><a href="{{LINK}}">Link</a></td></tr> </tbody> </table><script>var QUESTION_ID = 62732; var ANSWER_FILTER = "!t)IWYnsLAZle2tQ3KqrVveCRJfxcRLe"; var COMMENT_FILTER = "!)Q2B_A2kjfAiU78X(md6BoYk"; var OVERRIDE_USER = 12012; var answers = [], answers_hash, answer_ids, answer_page = 1, more_answers = true, comment_page; function answersUrl(index) { return "https://api.stackexchange.com/2.2/questions/" + QUESTION_ID + "/answers?page=" + index + "&pagesize=100&order=desc&sort=creation&site=codegolf&filter=" + ANSWER_FILTER; } function commentUrl(index, answers) { return "https://api.stackexchange.com/2.2/answers/" + answers.join(';') + "/comments?page=" + index + "&pagesize=100&order=desc&sort=creation&site=codegolf&filter=" + COMMENT_FILTER; } function getAnswers() { jQuery.ajax({ url: answersUrl(answer_page++), method: "get", dataType: "jsonp", crossDomain: true, success: function (data) { answers.push.apply(answers, data.items); answers_hash = []; answer_ids = []; data.items.forEach(function(a) { a.comments = []; var id = +a.share_link.match(/\d+/); answer_ids.push(id); answers_hash[id] = a; }); if (!data.has_more) more_answers = false; comment_page = 1; getComments(); } }); } function getComments() { jQuery.ajax({ url: commentUrl(comment_page++, answer_ids), method: "get", dataType: "jsonp", crossDomain: true, success: function (data) { data.items.forEach(function(c) { if (c.owner.user_id === OVERRIDE_USER) answers_hash[c.post_id].comments.push(c); }); if (data.has_more) getComments(); else if (more_answers) getAnswers(); else process(); } }); } getAnswers(); var SCORE_REG = /<h\d>\s*([^\n,<]*(?:<(?:[^\n>]*>[^\n<]*<\/[^\n>]*>)[^\n,<]*)*),.*?(\d+)(?=[^\n\d<>]*(?:<(?:s>[^\n<>]*<\/s>|[^\n<>]+>)[^\n\d<>]*)*<\/h\d>)/; var OVERRIDE_REG = /^Override\s*header:\s*/i; function getAuthorName(a) { return a.owner.display_name; } function process() { var valid = []; answers.forEach(function(a) { var body = a.body; a.comments.forEach(function(c) { if(OVERRIDE_REG.test(c.body)) body = '<h1>' + c.body.replace(OVERRIDE_REG, '') + '</h1>'; }); var match = body.match(SCORE_REG); if (match) valid.push({ user: getAuthorName(a), size: +match[2], language: match[1], link: a.share_link, }); else console.log(body); }); valid.sort(function (a, b) { var aB = a.size, bB = b.size; return aB - bB }); var languages = {}; var place = 1; var lastSize = null; var lastPlace = 1; valid.forEach(function (a) { if (a.size != lastSize) lastPlace = place; lastSize = a.size; ++place; var answer = jQuery("#answer-template").html(); answer = answer.replace("{{PLACE}}", lastPlace + ".") .replace("{{NAME}}", a.user) .replace("{{LANGUAGE}}", a.language) .replace("{{SIZE}}", a.size) .replace("{{LINK}}", a.link); answer = jQuery(answer); jQuery("#answers").append(answer); var lang = a.language; lang = jQuery('<a>'+lang+'</a>').text(); languages[lang] = languages[lang] || {lang: a.language, lang_raw: lang.toLowerCase(), user: a.user, size: a.size, link: a.link}; }); var langs = []; for (var lang in languages) if (languages.hasOwnProperty(lang)) langs.push(languages[lang]); langs.sort(function (a, b) { if (a.lang_raw > b.lang_raw) return 1; if (a.lang_raw < b.lang_raw) return -1; return 0; }); for (var i = 0; i < langs.length; ++i) { var language = jQuery("#language-template").html(); var lang = langs[i]; language = language.replace("{{LANGUAGE}}", lang.lang) .replace("{{NAME}}", lang.user) .replace("{{SIZE}}", lang.size) .replace("{{LINK}}", lang.link); language = jQuery(language); jQuery("#languages").append(language); } }</script>

a spaghetto

Posted 2015-11-03T16:40:48.353

Reputation: 10 647

Can we assume that the program halts when the processor finishes executing the written code, for a machine code entry? – lirtosiast – 2015-11-03T16:58:59.960

@ThomasKwa Yes. – a spaghetto – 2015-11-03T17:25:55.860

3Assuming any behaviour is fine for all invalid inputs? – Cruncher – 2015-11-03T17:33:19.720

3@Cruncher Yes, the only inputs you should expect to get are 0 and 1. – a spaghetto – 2015-11-03T17:38:29.830

Is it alright if I just have single spaces between the 1s? – El'endia Starman – 2015-11-04T08:54:08.247

@El'endiaStarman Sure. I'll add that to the rules. – a spaghetto – 2015-11-04T15:52:15.117

4Catalog is borked. – Addison Crump – 2015-11-06T15:18:55.057

2Catalog appears to consider Bf and bf to be different languages. – Mooing Duck – 2015-11-10T01:13:11.553

Without having looked at all of them, I suspect a significant number of entries here to be expecting inputs of "0\n" or "1\n". I expect this was expected by @quartata but it's not necessarily explicit in the challenge. Is there a standard definition of "input a number" somewhere on meta? – Sparr – 2015-11-17T05:53:19.770

100th upvote! :) – FlipTack – 2016-12-22T11:56:15.947

Are non-zero exit codes ok? Also, can I forgo a space that would normally separate the 1s? (i.e. 11 1 1 1 1 1 1 1) I assume not for the second question. – MildlyMilquetoast – 2017-02-02T03:15:15.503

is exiting with an error allowed? – 12Me21 – 2017-02-09T00:01:15.563

@12Me21 This is allowed by default on all challenges. – a spaghetto – 2017-02-11T00:04:20.627

Is taking input as \x00 and \x01 over STDIN allowed? – CalculatorFeline – 2017-06-06T22:06:31.257

@CalculatorFeline "If your language is incapable of outputting the characters 0 or 1, byte or unary I/O is acceptable." – a spaghetto – 2017-06-07T17:02:29.650

Well, my language does allow that, so :( RIP Newbiefuck, 4 bytes: ,[.] I/O as \x00 and \x01 – CalculatorFeline – 2017-06-07T18:48:58.377

While attempting this, I made a program that does just the opposite, when given zero it prints out infinite zeroes, and when given 1, does nothing

– FantaC – 2018-01-17T02:32:06.747

Can the form of 1 change—is 1 1/1 1/1 1/1... allowed? – Khuldraeseth na'Barya – 2018-03-03T20:43:57.567

Answers

192

Hexagony, 6 bytes

This was surprisingly tricky, and I'm not convinced it's optimal...

<.@!$?

After padding and unfolding the code, this represents the following hex grid:

enter image description here

This uses a similar control flow like my recent error-free cat program, moving along anti-diagonals. To achieve that we start by deflecting the instruction pointer (IP) to the left, where the purple path wraps around to the lower left corner.

? reads the input as an integer. ! prints it back. . is just a no-op. Now the corner of the grid acts as a branch:

If the input was 0, the IP will continue along the red path, which simply terminates the program with @.

If the input was 1, the IP will continue on the green path. Again, . is just a no-op, but $ is the equivalent of Befunge's trampoline: it skips the next instruction. After wrapping, the next instruction would be the ?, but due to $ execution actually continues on the blue path, starting with ! to print another copy of the 1. This loop which only contains !..$ is now repeated indefinitely.

A study of control flow in Hexagony...

I believe the above solution is optimal. I've written a brute forcer, which checks all 6-byte Hexagony programs, which contain at least one each of ?!@ (which are necessary; I've also checked : and % in place of @ to terminate with a division-by-zero error, but that didn't help either). The check prints all the programs which a) produce a 0 on input 0 and terminate and b) produce at least two 1s (and nothing else) and don't terminate within the first 60 ticks of the program (200 ticks for 5-byte solutions). I doubt that any valid solution would take more than 200 ticks to correctly print the first 0 or the second 1 on such a small grid, so I don't think I've missed out on any potential solutions.

The search didn't yield any results for 5 bytes, but 57 results for 6 bytes (using @; there's no need to terminate with an error if we can solve this cleanly in the same amount of bytes). Of those 57 only 6 were false positives which actually printed only two 1s and then entered an infinite loop without printing any more. One solution was listed twice because it contained two ! commands. That leaves exactly 50 valid solutions.

There is a certain amount of degeneracy between the solutions where one or two characters are not substantial, e.g. because they're effectively no-ops anyway. The solutions can be grouped into 23 sets of genuinely distinct programs (in some cases, there is only a single character difference between two sets, but it changes the control flow substantially, so I've counted them separately). Two of the groups even make use of multiple instruction pointers in a very unexpected way. As I would never have come up with most of these ways to use the branches and mirrors, they make a very interesting study of what sorts of control flow are possible in Hexagony, and I have definitely learned some new tricks for future golfs.

The overall control flow is almost always the same: read a number, print it. If it's 0 find a way to the @, if not keep looping through the ! while mainting an edge value of 1. There are four notable exceptions:

  • One solution (the one with two !) prints two 1s per iteration through the grid, therefore printing about twice as fast as the majority of programs. I've marked this one with x2 below.
  • A few solutions (those which contain an o) replace the 1 with a 111 (the character code of o), so they print three 1s per iteration, making them print about three times as fast as the majority of programs. I've marked these with x3 below.
  • Two solutions append a 1 to the edge value in each iteration (so 1 --> 11 --> 111 --> ...). Those print very fast, but they'll run out of memory eventually. I've marked these with OoM below.
  • Two solutions enter a very tight loop which merely bounces back and forth over the !, printing on every other tick (instead of of every 5th or so), which makes them slightly faster (and neater). I've marked these with >< below.

So here is the entire zoo:

#1                #5                #12                #19
?!/$.@            ?$!>$@            .?!/$@             |!|?$@  # ><
?!/$1@  # OoM     ?$!|$@            =?!/$@
?!/$=@                                                 #20
?!/$\@            #6                #13                $@.?<!
?!/$o@  # x3      ?/!<|@            .?/!$@             $@1?<!  # OoM
?!/$!@  # x2                        =?/!$@             $@=?<!
                  #7                                   $@o?<!  # x3
#2                ?\!<|@            #14
?!>$)@                              \!?__@             #21
?!>$1@            #8                                   _>_!?@
?!>$o@  # x3      ?<!>$@  # ><      #15
?!|$)@                              \_?!$@             #22
?!|$1@            #9                                   <!@.$?
?!|$o@  # x3      ?\$!@$            #16                <!@/$?
                                    \_?!_@             <!@=$?
#3                #10                                  <$@!$?
?!|)$@            ?~#!@)            #17                <.@!$?
?!|1$@            ?~#!@1            $$?\@!             </@!$?
?!|o$@  # x3                                           <=@!$?
                  #11               #18
#4                ?$)\@!            \$?\@!             #23
?_!<@>            ?$1\@!                               <<@]!?
                  ?$o\@!  # x3

The following is a short walkthrough for a handful of the more representative groups. Especially groups 10 and 23 are worth checking out. There are many other interesting and sometimes convoluted paths in the other groups, but I think I've bored you enough at the end of this. For anyone who really wants to learn Hexagony, these are definitely worth investigating though, as they exhibit even more possible uses of the mirrors and $.

Group 1

This one isn't much more elaborate than my original solution, but the paths go in different directions. It also allows for the largest number of variations in a single cell, as the right-most no-op can be replaced with 5 different commands which still make this valid without changing the structure:

enter image description here

Group 2

This one is quite interesting, because it only moves horizontally. After wrapping to the >, the IP reverses immediately, taking the branch in the corner. It's not entirely well visibly no the diagram, but in the case of the 1 we traverse the first row again, but backwards this time. This also means we run into ? again, which now returns 0 (EOF). This is fixed with ) (increment) to keep printing 1s. This also has 5 variations, as ) could also be 1 or o, and > could also be |:

enter image description here

Group 3

This one looks almost identical to the previous one but it's messy as hell. Up to hitting | and then traversing the bottom or top row it's the same. But in the case of a loop, the $ now skips over the ) onto the mirror. So we follow the turquoise path to the right, now hit the increment, skip over the @ before we wrap around to the | again and then go back to the green path at the top.

enter image description here

Group 4

I thought this one was particularly nifty:

enter image description here

The _ mirror in the top right corner is initially a no-op, so we print with ! and hit the <. The 0 path now hits the horizontal mirror and terminates. The 1 path takes a really interesting trajectory though: it deflects down, wraps to the !, gets redirected towards the horizontal and then wraps back to the ! again. It then keeps moving in this rhombus shape, printing twice per iteration (every third tick).

Group 8

This is one of the two solutions with a really tight printing loop:

enter image description here

The < acts as the branch. After wrapping twice, 0 hits @. 1 on the other hand, first skips the ?, then > sends it onto the the $ again, so that is skips the @. Then the IP wraps into the turquoise path, where it bounces back and forth between the > and < (wrapping around the edge in between).

Group 10

One of two groups which use other instruction pointers, and it's absolutely beautiful. Hexagony has 6 - each one starts from a different corner along the clockwise edge, but only one of them is active at a time.

enter image description here

As usual, we read with ?. Now ~ is unary negation: it turns the 1 into a -1. Next, we hit the #. This is one way to switch between IPs: it takes the current edge value modulo 6 and switches to the corresponding IP (IPs are numbered from 0 in the clockwise direction). So if the input was 0, then the IP simply remains the same, and travels boringly straight ahead into !@. But if the input was 1, then the current value is -1 which is 5 (mod 6). So we switch to the IP which starts on the very same cell (the green path). Now # is a no-op and ? sets the memory edge to 0. ) increments so ! prints a 1. Now we hit ~ again to ensure that # is still a no-op (as opposed to switching us to IP 1 which would terminate the program). It's mindblowing how well everything fits together in this little program.

Group 22

Just to note, this is the group my original solution is in. It also happens to be largest group, because the no-op can be in two different places, and there are several choices for the actual (effective no-op) command.

Group 23

This is the other group using multiple IPs. In fact this one uses 3 different IPs. The top right corner is a bit of a mess, but I'll try to walk you through this:

enter image description here

So, the beginning you've seen before: < deflects North-East, ? reads input. Now ] is another way to change between IPs: it hands control to the next IP in clockwise order. So we switch control to the turquoise path which (I know it's hard to see) starts in the North-East corner going South-East. It is immediately reflected by the < so that it wraps to the South-East corner, going North-West. It also hits the ] so we switch to the next IP. This is the grey path starting in the East corner, going South-West. It prints the input, then wraps to the North-East corner. < deflects the path into the horizontal, where it is reflected by the other <. Now the right-hand < acts as a branch: if the input was 0, the IP moves North-East, and wraps to the @. If the input was 1, the IP moves to the !, wraps to the lef-thand < where it is reflected... now in the corner, it wraps back to the !, gets deflected by the the right <, reflected by the left < and the paths starts over...

Quite a mess, but a beautiful mess. :)


Diagrams generated with Timwi's amazing HexagonyColorer.

Martin Ender

Posted 2015-11-03T16:40:48.353

Reputation: 184 808

56whoa. just whoa. – Conor O'Brien – 2015-11-04T22:38:26.107

6^ agreed. So cool... – El'endia Starman – 2015-11-04T22:46:35.317

whoa.... 50 different ways... – ev3commander – 2015-11-06T00:03:18.910

3.... wait what? – bubakazouba – 2015-11-06T06:24:52.493

28Shut up and take my upvote! – Mego – 2015-11-06T15:47:33.283

7

@ThomasOltmann I admit this answer assumes some basic knowledge of the language. If you're actually interested in learning more about it, I've gone through the basics in this answer and in this answer, but I won't blame you if you're not. ;)

– Martin Ender – 2015-11-06T19:31:18.557

1This language is interesting... {{{{{{ is a no-op. – LegionMammal978 – 2015-11-07T22:05:06.403

5Yeah... the memory model looks a bit painful (but still better than a 1D tape, I guess) – John Dvorak – 2015-11-08T14:53:51.950

1No! Nooo! The hexagons! They're in my dreams! Noooo! – caird coinheringaahing – 2017-05-16T22:49:36.433

145

Motorola MC14500B Machine Code, 2 bytes

In hex:

58EC

Explanation:

5  OR the register with input from the data bus
8  Write the register to the data bus
E  Skip next instruction if register is zero
C  Jump

The Motorola MC14500B is a 1-bit microcontroller; it has one 1-bit register and a 1-bit data bus. Since the opcodes are 4 bits each, there are only sixteen; half of them carry out a logical operation between the register and the bit on the data bus.

The jump instruction sets a jump flag; when no address is provided, it is common to set the program counter to 0. If the input bit was zero, the processor will not jump. If the input bit was 1, the processor jumps back to the start; since we're ORing with input, it doesn't matter what the input signal is afterwards—the register will then be 1 forever.

As is conventional, the register is initialized to 0.

A list of the opcodes can be found on the data sheet, or here.

lirtosiast

Posted 2015-11-03T16:40:48.353

Reputation: 20 331

72 bytes is definitely the minimum for this challenge. – Conor O'Brien – 2015-11-04T02:52:06.353

24@CᴏɴᴏʀO'Bʀɪᴇɴ I've been looking for several hours through esolangs and lists of 4-bit processors to see if there's a 1 or 1.5, and haven't found one. – lirtosiast – 2015-11-04T03:07:22.937

1Definitely the right tool for the job. – Hugo Zink – 2015-11-09T12:49:02.820

Link is borked atm... – TheDoctor – 2015-11-17T04:19:56.430

@TheDoctor Both links work fine for me – Mego – 2015-11-17T06:00:24.770

@Mego he must have changed it... It was another site yesterday – TheDoctor – 2015-11-17T14:03:36.433

85

Arnold C, 296 Bytes

IT'S SHOWTIME
    HEY CHRISTMAS TREE i    
    YOU SET US UP @NO PROBLEMO
    BECAUSE I'M GOING TO SAY PLEASE i
        STICK AROUND i
            TALK TO THE HAND i
        CHILL
    BULLSHIT
        TALK TO THE HAND i
    YOU HAVE NO RESPECT FOR LOGIC
YOU HAVE BEEN TERMINATED

Not really competitive, but for the fun of it. Does not support stdin, replace @NO PROBLEMO with @I LIED for a zero value. @No Problemo is 1.

Run with (assuming file is truthmachine.arnoldc):

wget http://lhartikk.github.io/ArnoldC.jar
java -jar ArnoldC.jar truthmachine.arnoldc
java truthmachine

DeleteMe

Posted 2015-11-03T16:40:48.353

Reputation: 959

46Beautiful. I cried 10/10 – a spaghetto – 2015-11-03T17:56:16.393

@ThomasKwa I think you have to use tabs for it to parse correctly. I haven't used this language in a while though, could be wrong. – a spaghetto – 2015-11-03T18:32:20.000

10BECAUSE I'M GOING TO SAY PLEASE LOL – Eric Martinez – 2015-11-03T22:14:30.750

8It looks like this does if(i){while(i) print(i);} else {print(i);} Surely it would be shorter to do print(i);while(i) print(i);? – lirtosiast – 2015-11-04T16:21:28.107

17Although BULLSHIT has a great contribution to the entertainment value of the program, technically it is unnecessary. You can factor the whole BULLSHIT branch out by moving TALK TO THE HAND i after YOU HAVE NO RESPECT FOR LOGIC. – gaborsch – 2015-11-06T09:46:59.303

4@GaborSch There is only one proper response to that: BULLSHIT ;) – caird coinheringaahing – 2017-05-16T22:52:03.077

@user00001 YOU HAVE NO RESPECT FOR LOGIC :D – gaborsch – 2017-05-17T09:29:43.730

66

Minecraft, 18 Bytes (MC Version 15w45a)

minecraft sketch

As you can see, there is a lever directed into the repeating command block, which has the command say 1 in it. There is an signal inverting torch on top of that, which directs power into the single-run command block with the command say 0 in it.

Whenever the switch is directed towards truthy, the repeater block uses the code say 1 to output infinite 1s. When the lever is redirected to false, it outputs a single 0.

Note that this outputs a [@] by default. If you really want just straight up 1s and zeros, this becomes 34 bytes, where the code in the command blocks are tellraw @a [1] and tellraw @a [0]. This is using @Cᴏɴᴏʀ O'Bʀɪᴇɴ's suggested byte count for MC as can be found in Meta.

Addison Crump

Posted 2015-11-03T16:40:48.353

Reputation: 10 763

30You used a video game for code golf. +1 – RK. – 2015-11-18T13:57:52.210

11@RK. This is actually fairly standard practice for simple challenges. There are at least two other users who use MC as a code golfing language - try the search bar with is:answer Minecraft. c: – Addison Crump – 2015-11-18T14:33:12.410

1@FlagAsSpam lol nicely done. Also, thanks for that tip to search MC answers. – Ashwin Gupta – 2015-12-08T04:11:51.600

57

Bash + GNU utils, 13

grep 0||yes 1

Bash, 35

read n;for((;n;));{ echo 1;};echo 0

Digital Trauma

Posted 2015-11-03T16:40:48.353

Reputation: 64 644

3You know, I was wondering if a bash solution with yes would be possible... – a spaghetto – 2015-11-03T19:36:34.237

2Nice! That's pretty clever – a spaghetto – 2015-11-03T19:52:45.607

38

Ruby, 20

print while/1/||gets

Run from the command line to avoid warnings, as

ruby -e "print while/1/||gets" <<< 0
ruby -e "print while/1/||gets" <<< 1

Explanation:

Less golfed, this is

while /1/ || gets
  print
end

When a Regexp is used in a conditional, it evaluates as falsey unless the variable $_ is populated and matches the pattern. On the first time through the loop, $_ is empty so we fall through to gets, which sets the value of $_ to a line read from STDIN. print with no arguments prints $_. Now we evaluate the conditional again. If we read in 1, we short-circuit and just print 1 again, and so on forever. Otherwise, we fall through to gets, but since there's no second line of input, gets returns nil, so the loop ends.

histocrat

Posted 2015-11-03T16:40:48.353

Reputation: 20 600

18It's nice when trivial tasks still allow mindblowing solutions even in "normal" languages. :) – Martin Ender – 2015-11-03T17:20:30.590

The ||gets part is cool and all, but can't you just do gets;print while/1/ and save a byte? – daniero – 2016-08-27T20:54:17.420

No, then it doesn't print the 0 at all. – histocrat – 2016-08-28T01:41:36.320

37

Microscript, 3 bytes

i{p

The shortest one I know.

Explanation:

i  Takes numeric input and puts it in register 1
{  while register 1 is truthy
  p  Print the contents of register 1

Microscript has implicit printing of register 1 upon termination, which is the reason why an input of 0 gets printed once.

a spaghetto

Posted 2015-11-03T16:40:48.353

Reputation: 10 647

@quartata I matched you :D – Conor O'Brien – 2015-11-03T17:17:36.673

@CᴏɴᴏʀO'Bʀɪᴇɴ :O – a spaghetto – 2015-11-03T17:18:38.363

2I'm seriously wondering if you wrote the question first, or the answer... – John Dvorak – 2015-11-08T14:56:54.053

1The question. I just wanted to post this since it was the shortest one I came up with while writing the question. It is a catalog so there aren't any real winners. – a spaghetto – 2015-11-08T15:07:19.167

36

Turing Machine Code, 32 bytes

Using the rule table syntax found here.

0 0 0 * halt
0 1 1 r 1
1 _ 1 r 1

SuperJedi224

Posted 2015-11-03T16:40:48.353

Reputation: 11 342

I really like this. +1 – a spaghetto – 2015-11-03T17:28:06.520

I knew someone would've already posted this! – YoYoYonnY – 2016-02-01T00:55:35.420

26

JavaScript, 28 bytes

For loops are often shorter than while loops.

alert(x) returns undefined, which is falsy, so the bitwise or operator, |, casts it to 0. Thus, if x is "0", alert once, otherwise keep looping. Uses alert for STDOUT like this answer.

for(x=prompt();alert(x)|x;);

intrepidcoder

Posted 2015-11-03T16:40:48.353

Reputation: 2 575

Shoot, you beat me to it. I was about to post exactly this! :) GG – Domino – 2015-11-03T21:35:57.543

Wow, that's a good bit more clever than mine :) Have a +1! – ETHproductions – 2015-11-03T22:01:42.160

You don't need the trailing semicolon. – Conor O'Brien – 2015-11-06T21:36:53.160

@CᴏɴᴏʀO'Bʀɪᴇɴ What browser did you use? I tested it on Firefox and Chrome and I get a SyntaxError without it. – intrepidcoder – 2015-11-06T22:25:11.297

@intrepidcoder Oh, sorry, my bad. My mind was in "trailing semicolons are useless" mode. ^^" – Conor O'Brien – 2015-11-06T22:26:14.827

Yeah, you need one because it's a for loop. :) – Domino – 2015-11-07T21:22:05.530

Nice job, placing the alert in the condition was clever – Cyoce – 2016-01-05T07:55:24.007

25

Python 2, 29 bytes

a=input()
while 1:print a;1/a

This terminates with a division error on 0, which is allowed by default.

xnor

Posted 2015-11-03T16:40:48.353

Reputation: 115 687

STDERR output is fine. The ><> answer uses it as well. – a spaghetto – 2015-11-03T20:09:56.010

This is brilliant ^_^ – ABcDexter – 2016-09-01T09:36:54.323

Would while a print a work? Sorry, I dont know python. – Rohan Jhunjhunwala – 2016-09-14T00:42:05.637

1@RohanJhunjhunwala For 0, it wouldn't print anything, but it should print it once. – xnor – 2016-09-14T01:30:00.113

1@xnor oh, my bad. – Rohan Jhunjhunwala – 2016-09-14T20:27:14.867

20

Brainfuck, 41 36 31 30 bytes

Shortened by printing once right after input and with help from Ethan and user46915.

,.+++[->>+<-----<]>>---<-[>.<]

Previous version: Subtract 48 from the input, and if it's not zero, add 1 to the 48 to print ASCII 1 forever, otherwise print 0.

-[>+<-----]>--->,<[->->+<<]>[>+<]>.<[>.<]

I ran it here, but due to buffered output, you cannot see any output since the program never terminates on 1.

Edit: I had forgotten to print 0 on input 0. Fixed now. I like the >.< faces at the end.

mbomb007

Posted 2015-11-03T16:40:48.353

Reputation: 21 944

1

@ThomasKwa I'm guessing not, but I'm not sure since I don't see an algorithm specifically for modulo 2. The divmod algorithm is a little long.

– mbomb007 – 2015-11-03T19:13:07.810

2You can shorten it a bit more by merging the pieces of code together a bit better and directly using your input register instead of having a separate "48" register: ,.[>+>+<<-]-[>-<-----]>+++[>.<] – Ethan – 2015-11-03T21:53:16.930

Attempted a solution with mod 2. Definitely looks like subtracting 48 is the right way to go. ,.[->+>+<<]>>[->[>-<[-]]>+[<+>-]<<]>[<<.>>] – cardboard_box – 2015-11-03T23:34:52.317

You might want to mention that this assumes 8 bit cells with wraparound on underflow, in case anyone is trying to run it on an interpreter that works differently. – Ray – 2015-11-04T04:01:58.780

1@Ray That's the default and is generally assumed. Had I used another implementation, I would've said so. – mbomb007 – 2015-11-04T05:17:58.733

I like it when emoji appear in my code, too. – Conor O'Brien – 2015-11-06T21:35:47.127

1You can get one more byte off by combining subtraction and copying together: ,.+++[->>+<-----<]>>---<-[>.<] – user46915 – 2015-11-09T06:09:19.757

19

Pyth, 4 3 2

Wp

There is a no! trailing space (thanks isaac :) ). The space used to be required to make the while loop compile, but Pyth has since been updated. Normally that would disqualify using it, but since this is a catalog it should be valid.

Explanation:

Wp        : implicit Q = eval(input)
W         : while
 p        : print and return the value of Q, to be evaluated as the while condition
          : Functions without enough arguments automatically use Q now
          : do nothing in the body of the while loop

FryAmTheEggman

Posted 2015-11-03T16:40:48.353

Reputation: 16 206

5

I was inspied by this answer to add implicit pass to Pyth. The space is now unnecessary. https://pyth.herokuapp.com/?code=WpQ&input=0&debug=0

– isaacg – 2015-11-04T01:37:41.333

54Crossed four still looks like a four. – Conor O'Brien – 2015-11-04T02:54:06.780

1Eh, I'm just getting so bored of seing pyth dominate everything all the time :(. LOL. – Ashwin Gupta – 2015-12-08T04:12:55.070

1

@AshwinGupta my language technically beat it, so it's not completely dominating :)

– Cyoce – 2016-01-05T07:53:03.533

@Cyoce yeah! Good job! I rest assured that something can beat pyth lol. – Ashwin Gupta – 2016-01-05T15:01:09.753

@AshwinGupta my other language did too :D

– Cyoce – 2016-01-23T22:21:44.657

Wp now works. – Blue – 2016-04-26T17:34:09.973

@muddyfish Thanks for the reminder, edited! :) – FryAmTheEggman – 2016-04-26T17:35:58.783

@AshwinGupta My language beats both of Cyoce's languages.

– None – 2019-12-14T05:40:12.843

19

Piet, 27 18 16 codels

(Codel is a fancy name for pixel used to avoid confusion when an image is stretched for viewing. I counted codels instead of bytes because piet scripts are saved as images, so the physical size may vary. I think an ideal file format that would save this piet as efficiently as possible would take 11 bytes. In practice, my tiny gif file is 62 bytes, with optimal palette data. Tell me if I should use this as the size of my entry instead of the codel amount.)

Original image: tiny version

Enlarged: enlarged version

In piet, the difference between two colors is what determines which command runs, so seeing the same color twice doesn't mean it does the same action. The execution begins in the top-left codel. Then it moves horizontally, performing the following:

  1. Read a number and put it on the stack
  2. Duplicate the top of the stack
  3. Pop and output the top of the stack
  4. Pop the top of the stack and rotate clockwise that number of times.

If the input was 1, the cursor then moves down into the lime codel, which pushes 1 on the stack. Then the execution continues going left. When the cursor passes from a color to white and from white to a color, nothing happens. Since black is considered as walls too, the cursor ends up going back to the lime codel on the top line, and repeats the whole thing from step 2.

If, however, the input was 0, the cursor will never go down and will end up in the blue J on the right (pun intended, it was worth it), were it will stay trapped (because the top, right, left and bottom sides of this J-shaped block are next to black codels or the edge of the image). Since the cursor is trapped, execution ends.

Unexpected values:
If the user writes another number, it will still be printed, then the cursor will rotate more or less times based on the value.

  • Multiple of 4 or 0: execution continues horizontally and ends.
  • Multiple of 3: Since going up is impossible, the cursor immediately rotates clockwise and continues horizontally, then ends.
  • Multiple of 2 and not a multiple of 4: the cursor rotates and starts moving to the left. Luckily, all this does is perform a bunch of operations that don't affect the program flow and end up emptying the stack. When an operation can't be done because the stack is empty, it is simply ignored. When it hits the top left corner, the cursor has nowhere else to go but to the right again, effectively restarting the program.
  • Other values: The cursor goes down as if it would with 1, which makes it print 1 forever. If the input is 5, the output will be 5111111111111...

Any non-integer value will terminate the program. Execution will continue normally, but all operations will be ignored since there is nothing in the stack. So in a way, the program never crashes - it either stops normally or loops forever.


PietDev friendly version

PietDev (a very basic online Piet IDE) seems to have trouble with white codels so I made a new version which manually rotates back up instead of relying on proper white codel automatic rotation. And I didn't even need to use a new color! If you want to test with it, make sure you draw a black border around the code because PietDev doesn't support custom program sizes.

tiny version

enlarged version


Older versions

The first version didn't push 1 back on the stack and instead looped back to an earlier duplication instruction. It also had decorative useless codels.

Tiny pattern which is actually a piet code

Enlarged version

Then I had the idea to push 1 on the stack to remove the blank line. It's funny how I thought of it thanks to my decorative codels.

tiny version

large version

Then I realized I had an extraneous dup that wasn't needed anymore, and I reduced the number of colors to save up on palette data in the image. I also got rid of the single decorative codel because I don't know.

Domino

Posted 2015-11-03T16:40:48.353

Reputation: 459

8I've never seen a Piet answer scored in anything other than codels, but I think the optimal byte count is also interesting to include :) – undergroundmonorail – 2015-11-03T21:39:30.837

1There are 20 different codel values, which means you should be able to pack three codels into 13 bits, then eight triplets into 13 bytes for a storage density of 2.6 codels per byte. But someone has to define that language first. I suggest the name DPPi = densely packed piet. – John Dvorak – 2015-11-08T15:05:22.473

1@JanDvorak I counted 21 values to add a special one for line break, and once you're got the first line break the parser can guess where the other ones should be. But I didn't go as far as combining codels into triplets, which makes much more sense than wasting 5 bits per codel. Clever. – Domino – 2015-11-08T19:30:48.380

1Just add the dimensions as the first couple of bytes. You don't need an extra symbol. – John Dvorak – 2015-11-08T19:37:44.843

1@everyone who wants to try it out: Don’t try this solution with PietDev because PietDev only prints a single 1 and terminates. But the solution works properly with npiet. – M L – 2016-02-15T23:23:46.050

@ML Indeed, PietDev doesn't implement white codels correctly it seems. – Domino – 2016-02-16T05:49:12.057

@JacqueGoupil, I think it might be the cc that’s not implemented properly? And another problem is that PietDev uses float division instead of integer division. – M L – 2016-02-16T12:27:50.210

1@ML Good to know. Here, I edited the post and added a PietDev friendly version. – Domino – 2016-02-18T15:36:44.197

16

Chip, 6 bytes

e*faAs

Chip is a 2D language that behaves a bit like an integrated circuit. It takes input, one byte at a time, and breaks out the bits to individual input elements. Output stitches the values of output elements back together into bytes.

Let's break this down:

* is a source signal, it will send a true value to all adjacent elements. e and f correspond to the fifth and sixth bit of the output. So, e*f produces binary 00110000, which is ASCII char "0".

Now, A is the first bit of input and a is the first bit of output, so aA copies that bit from input to output. So, when combined with e*f, an input of ASCII "0" produces "0", and "1" produces "1". (There is no interaction between f and a, since neither produce any signal.)

The s on the end, when activated by a true signal, will prevent input from advancing to the next byte, meaning that the whole thing will run again with the same input.

Since the first byte of "0" is zero, it won't activate this element and the program will print "0", and thereby exhaust its input, which allows it to terminate. "1", however, activates this element, which means that "1" is output, but not consumed on the input, allowing the cycle to repeat indefinitely.

If values 0x0 and 0x1 are used for output, rather than ASCII, we can eliminate the e*f part, resulting in only 3 bytes:

aAs

If the zero must terminate itself, rather than expecting stdin to close, we get the following, which inverts the first byte with ~, and passes the result to t, which terminates the program (10 bytes):

aA~te*f
 s

(t also produces no signal, so there is no interaction between t and e.)

Phlarx

Posted 2015-11-03T16:40:48.353

Reputation: 1 366

2Nice answer! Since this is a catalog challenge, there's no need to mark this as non-competing, so I've removed that bit for you. Welcome to PPCG! – Mego – 2017-01-30T23:31:56.223

4

I took the liberty of adding Chip to TIO. Try it online!

– Dennis – 2017-01-31T01:24:04.760

@Dennis, question for you: how would I get TIO to update its source? Last week I fixed a bug in the Chip interpreter, but it hasn't propagated the change into TIO. Is this something I need to ask someone to do for me? – Phlarx – 2017-02-07T17:18:21.737

I've pulled Chip. If you need something updated, just leave a message in http://talk.tryitonline.net.

– Dennis – 2017-02-07T17:21:33.243

15

Brainbool, 5 bytes

,.[.]

Brainbool is Brainfuck, but it only operates on bits, and does I/O through 0 and 1 characters.

lirtosiast

Posted 2015-11-03T16:40:48.353

Reputation: 20 331

3I knew there had to be a BF derivative where this could be feasibly done. – a spaghetto – 2015-11-03T18:26:19.367

14I feel like "Boolfuck" might be a better name for it, but well done regardless. – James Murphy – 2015-11-04T05:36:26.410

2

@JamesMurphy it seems that exists already: https://esolangs.org/wiki/Boolfuck

– DLeh – 2015-11-09T20:49:35.380

13

LOLCODE, 119 bytes

GIMMEH n
n R SUM OF n AN 0
BOTH SAEM n AN 0, O RLY?
YA RLY
 VISIBLE 0
NO WAI
 IM IN UR l
  VISIBLE 1
 IM OUTTA UR l
OIC

Ungolfed:

HAI

BTW, Read n as a string from STDIN and convert to an integer
GIMMEH n
n R SUM OF n AN 0

BTW, Test n for equality with 0
BOTH SAEM n AN 0, O RLY?
YA RLY
    BTW, Write 0 to STDOUT and exit
    VISIBLE 0
NO WAI
    BTW, Loop forever, printing 1
    IM IN YR l
        VISIBLE 1
    IM OUTTA YR l
OIC

KTHXBYE

Alex A.

Posted 2015-11-03T16:40:48.353

Reputation: 23 761

>

  • Which interpreter are you using? 2. Can you MAEK n A NUMBR to cast? 3. Can you use DIFFRINT instead of BOTH SAEM and switch the conditionals?
  • < – lirtosiast – 2015-11-09T05:15:13.453

    @ThomasKwa I was using LOLCOFFEE, the one on repl.it. (Which appears to be down at the moment, so I'll test your suggestions once it's back up.) – Alex A. – 2015-11-09T05:28:23.840

    Doesn't O RLY? cast to boolean? – Leaky Nun – 2016-07-22T17:38:59.600

    @LeakyNun No...? O RLY? is like a postfix if. – Alex A. – 2016-07-22T23:54:18.360

    12

    C, 37 bytes

    A different take on how to do it in C.

    main(c){for(gets(&c);putchar(c)&1;);}
    

    c defaults to an int of value 1. gets(&c) gets a string from stdin, here clobbering the value of c, hackishly since c is not a char*. putchar(c) prints the value of c to stdout, and returns c. Since '0' is 48 and '1' is 49 in ASCII, we can use the last bit (&1) to determine which it is. If it's '0', the loop breaks. Otherwise, it goes forever.

    Compiles (with a warning about gets) and runs under gcc-4.8 on Linux.

    cbojar

    Posted 2015-11-03T16:40:48.353

    Reputation: 221

    2Presumably this only works on little-endian architectures. – Neil – 2015-11-04T20:20:17.683

    @Neil I would assume so. – cbojar – 2015-11-04T21:29:03.113

    @Neil Endianness only affects byte order in multibyte values. – LegionMammal978 – 2015-11-07T21:55:58.207

    1@LegionMammal978 c defaults to an int, which is a multibyte value, and on a big-endian architecture, gets will set the wrong byte. – Neil – 2015-11-08T00:51:45.617

    11

    Labyrinth, 7 bytes

     ?+
    @!:
    

    Labyrinth is a 2D stack-based language where control flow depends on the sign of the top element of the stack, checked after every instruction. Execution begins moving rightward from the first valid instruction on the top row, which here is the ?.

    The relevant instructions are:

    ?      Input integer
    +      Add top two elements (Labyrinth's stack has infinite 0s on the bottom)
    :      Duplicate top element
    !      Output as number
    @      Terminate program
    

    If the input is 0, the IP reads input with ?, adds the top two of the stack (0 + 0 = 0), then duplicates : and outputs ! a 0. Here we encounter the sole junction in the program, and have to check the top of the stack to determine where to go. Since the top is 0, we move forward and terminate with @.

    On the other hand, if the input is 1, we do the same instruction as before (but outputting a 1) before reaching the junction at the !. Now the top of the stack is positive, causing us to turn right into the ?. On EOF Labyrinth pushes 0, so we do 0 + 1 = 1 at the +, duplicate :, and output !. Once again we have a 1 at the top of the stack and the loop continues.

    For a bonus, here's @MartinBüttner's 7 byte solution, which operates similarly:

    ?+!@
    1!
    

    Note that, unlike most languages, 1 actually pops n off the stack and pushes n*10 + 1, making the building up of large numbers easy. However, since the top of the stack is empty at that point, it's no different from merely pushing 1.

    Sp3000

    Posted 2015-11-03T16:40:48.353

    Reputation: 58 729

    11

    ><>, 7 bytes

    i2%:n:,
    

    This uses the fact that ><> pushes -1 on EOF, which is 1 mod 2. It also uses divide by 0 for termination (which is apparently okay since the consensus is that STDERR output is ignored).

    Just for reference, exiting cleanly without errors is an extra byte:

    i2%:n?!;
    

    Sp3000

    Posted 2015-11-03T16:40:48.353

    Reputation: 58 729

    10

    Bitwise Cyclic Tag, 3 bits or < 1 byte

    Bitwise Cyclic Tag is one of the simplest Turing-complete languages out there. It works with two bitstrings, the program and the data. The bits of the program are read cyclically and interpreted as follows:

    • 0: Delete the first data bit (and output it, in implementations that have output).
    • 1x: If the first data bit is 1, append x (representing either 0 or 1) to the end of the data. (If the first data bit is 0, do nothing.)

    The program runs until the data string is empty.

    Truth-machine

    110
    

    When the data string is set to 0:

    • 11 does not append anything because the first data bit is not 1.
    • 0 deletes/outputs 0.
    • The data string is now empty and the program halts.

    When the data string is set to 1:

    • 11 appends a 1.
    • 0 deletes/outputs 1.
    • The data string is back to a single 1 and the program is back to where it started, so we loop forever.

    DLosc

    Posted 2015-11-03T16:40:48.353

    Reputation: 21 213

    10

    APL, 6 bytes

    →⎕←⍣⍲⎕
    

    Explanation:

         ⎕ Read the input, then
     ⎕←    write it out
       ⍣   repeatedly
        ⍲  until NAND of it with itself becomes true.
    →      Branch to zero to avoid printing the result again.
    

    user46915

    Posted 2015-11-03T16:40:48.353

    Reputation: 201

    1Are the second and the last characters supposed to look different? Because they don't for me. – John Dvorak – 2015-11-08T15:09:14.057

    @JanDvorak Nope, they're the same. – Alex A. – 2015-11-09T04:39:31.867

    1OK, now I'm looking at it on mobile and everything but the two arrows looks the same to me :-D – John Dvorak – 2015-11-09T07:15:40.867

    10

    Brian & Chuck, 21 bytes

    ,}<-{-?<SOH>_{+?
    _>+{?<.p
    

    Here, <SOH> should be replaced with the corresponding control character (0x01).

    Explanation

    The basic idea is to subtract the character code of the input (48 or 49) from the p at the end of Chuck, which will either give a ? (which is a valid command) or a @ which is a no-op.

    , reads the input character into Chuck's first cell (marked with _). We want to decrement this value down to 0 in a loop, while making some other changes:

    }< moves to the p and - decrements it. Then { moves back to the input cell - decrements that as well. As long as this isn't zero yet, ? gives control to Chuck. Now > moves Brian's tape head one cell to the right (which is initialised to 1) and + increments that. Then we reset the loop with {?.

    By the time the first cell on Chuck hits 0, the <SOH> cell will have been incremented to the character we've read from STDIN and p will be ? for input 1 or @ for input 0.

    Now ? doesn't switch control any more. The 0 or 1 after it is a no-op, as is the null-byte (represented by _). { moves back to Chuck's first cell and + increments to ensure that it's positive, such that ? hands control over to Chuck.

    This time >+ increments the cell after the end of Brian's initial tape. That cell is garbage but we'll never use it. Now { doesn't scan all the way to the front of Brian's tape, but only to the _. Hence ? is a no-op because the current cell is zero. Then <. moves one to the left (the copy of the input character) and prints it.

    Finally, we encounter the ? or @. If the input was 0 and this cell is @ it's a no-op and the program terminates. But if the input was 1 and this cell is ? we hand over to Brian whose {+? will reset the loop on Chuck, and now we're printing 1s forever (until the integer in the cell at the end of Brian's tape doesn't fit into memory any more, I suppose...).

    Bonus

    Sp3000 and I have been golfing away at this for several days. We started out around 40 bytes and arrived at two completely different, but tied solutions at 26 bytes. Only when I started to write up the explanation for mine, did the 21-byte solution above occur to me. Many thanks to Sp for throwing ideas around and teaching each other some golfing tricks in B&C. :)

    This is his 26 byte solution:

    >,----{?{>1?0
    #I<?_}<.<<<?
    

    And this is mine:

    ,{>-<-?_0+?_1{<?
    _®{?_{>.?
    

    Where ® is a byte with value 174 (e.g. just save the file as ISO 8859-1).

    At the core mine works similarly to the 21-byte solution, in that ® becomes } for input 1 and ~ (no-op) for input 0, but the execution is much less elegant.

    His solution is quite neat in that the source code is ASCII-only and that it doesn't require a loop to process the input. Instead, ---- turns 1 into - and 0 into , (a no-op for Chuck). That - will then change the first ? on Brian's tape into a >, thereby creating different control flow for the 1-case.

    Martin Ender

    Posted 2015-11-03T16:40:48.353

    Reputation: 184 808

    9

    GNU sed, 10

    :;/1/{p;b}
    

    Explanation

    • : define an unnamed label
    • /1/ If input matches the regex 1, then
    • p print the pattern space (i.e. 1)
    • b and jump back to the unnamed label (forever)
    • If the input was not 1 (i.e. 0), then the pattern space is printed unmodified and the program ends.

    Digital Trauma

    Posted 2015-11-03T16:40:48.353

    Reputation: 64 644

    1Shave 1 character off using :;p;/1/b and the n flag, for a total of 9 bytes. Since sed -f is used anyway to run the script file, adding that extra flag doesn't require 2 bytes. – seshoumara – 2016-08-28T16:08:02.520

    9

    Seriously, 4 3 bytes

    Crossed-out 4 is still 4 :(

    ,W■
    

    , reads a value from STDIN. W starts a loop that runs while the value on top of the stack is truthy, with the body . prints the top stack element without popping. The loop is implicitly closed at EOF.

    On input of 0, the loop never executes (since 0 is falsey), and the program ends at EOF, automatically popping and printing every value on the stack. On input of 1 (or any value that is not 0, "", or []), the loop runs infinitely.

    In Actually, the leading , is not needed (thanks to implicit input), bringing the score down to 2 bytes.

    Mego

    Posted 2015-11-03T16:40:48.353

    Reputation: 32 998

    8

    Thue, 34 bytes

    1::=12
    2::=~1
    0::=~0
    @::=:::
    ::=
    @
    

    Explanation:

    1::=12 Instances of the substring "1" can become "12"

    2::=~1 Instances of the substring "2" can be removed, printing "1"

    0::=~0 Instances of the substring "0" can be removed, printing "0"

    @::=::: Instances of the substring "@" can be replaced with strings from the input

    ::= End list of substitution rules

    @ The initial string is "@"

    SuperJedi224

    Posted 2015-11-03T16:40:48.353

    Reputation: 11 342

    8

    Arnold C, 134 bytes

    IT'S SHOWTIME
    HEY CHRISTMAS TREE i
    YOU SET US UP 0         //or 1
    STICK AROUND i
    TALK TO THE HAND 1
    CHILL
    TALK TO THE HAND 0
    YOU HAVE BEEN TERMINATED
    

    While this isn't as entertaining as the other ArnoldC answer, it's golfed. For example, indentation is unnecessary, and so are the macros @NO PROBLEMO and @I LIED.

    Tested with this version of the language, which cannot take input.

    lirtosiast

    Posted 2015-11-03T16:40:48.353

    Reputation: 20 331

    8

    Cubix, 5 6 bytes

    Cubix is @ETHproductions new 2 dimensional language where the commands are wrapped around the faces of a cube. Online interpreter Thanks to @ETHproductions for the saving.

    !I\@O
    

    This ends up expanded out to the cube

      !
    I \ @ O
      .
    

    This starts with the I command. Input an integer onto the stack.
    \, redirects the instruction pointer down over the no op.
    O, outputs the numeric value of top of stack.
    !, skip the next command (@) if top of stack true. This will jump the \ redirect if 1
    \, redirects the instruction pointer to the @ exit program.

    This takes advantage of the fact the stack isn't popped by the O ? ! commands.

    MickyT

    Posted 2015-11-03T16:40:48.353

    Reputation: 11 735

    Nice. I'm really glad to see someone else using my language :) I have another 6-byte solution that only uses 5 instructions (plus a no-op), so perhaps I'll post that. – ETHproductions – 2016-03-15T01:02:18.707

    @ETHproductions post it for sure. I think you've got a promising language here :) – MickyT – 2016-03-15T01:15:03.617

    You can save a byte by removing the ? and just using !: !I\@O – ETHproductions – 2016-03-15T15:26:11.900

    @ETHproductions very nice – MickyT – 2016-03-15T17:47:32.757

    1

    I've written a brute-forcer for this (warning: freezes your browser for a minute or two), which comes up with exactly five 5-byte solutions: @IOw!, @I?Ov, @!IOw, !IOW@, !I\@O

    – ETHproductions – 2016-03-17T15:39:00.060

    7

    Foo, 6 bytes

    &1($i)
    

    Input is hardcoded as the second character, since Foo doesn't have STDIN input. Don't we agree that Foo is awesome now? :)

    Explanation

    &1          Set current cell to 1
      (  )      Do-while loop (or, at least according to the interpreter)
       $i       Print current cell as int
    

    Sp3000

    Posted 2015-11-03T16:40:48.353

    Reputation: 58 729

    2I always liked Foo. – a spaghetto – 2015-11-03T16:48:14.423

    7

    Perl, 18 + 1 = 19 13 + 1 = 14 bytes

    print while$_
    

    Run like this:

    echo -n NUM | perl -p truth.pl
    

    Thanks to ThisSuitIsBlackNot (who is way better at Perl golfing than me) for golfing off five bytes.

    a spaghetto

    Posted 2015-11-03T16:40:48.353

    Reputation: 10 647

    2Statement modifiers are your friend! Also, if you ensure that the input has no trailing newline, you can drop the +0: echo -n 0 | perl -pe'print while$_' (13 bytes + 1 for -p). perl -M5.010 -pe'say while$_' would be even shorter, but that results in inconsistent newlines between 0 vs. 1. – ThisSuitIsBlackNot – 2015-11-04T04:46:09.763

    @ThisSuitIsBlackNot Ah-ha! I tried print while$_ but I couldn't figure out why it didn't work. I didn't realize you couldn't have the trailing newline on the input. – a spaghetto – 2015-11-04T04:47:37.770

    Yep, the string 0 is false but 0 + newline is true. See perldoc perlsyn.

    – ThisSuitIsBlackNot – 2015-11-04T04:52:50.407

    2say is shorter, even if you count -E as an extra byte. – Dennis – 2015-11-04T05:26:02.093

    @Dennis As I mentioned in my first comment, say doesn't work for this because it leaves a newline after 1, but no newline after 0, which violates the rule that usage of newlines must be consistent. – ThisSuitIsBlackNot – 2015-11-04T14:21:42.000

    2@Dennis ...which I just realized can be fixed with -l: perl -lpE 'say while$_' (11 bytes + 2 for -lp). – ThisSuitIsBlackNot – 2015-11-04T14:25:55.933

    7

    ><>, 6 bytes

    ::n?!;
    

    Pushes the input on the stack to start

    :        copy top element on stack
     :       copy top element on stack again
      n      pop and outputs top element
       ?     condition trampoline - pops top element, if it is zero skips next instruction
        !    trampoline skips next instruction
         ;   finish execution
    

    Blake Lockley

    Posted 2015-11-03T16:40:48.353

    Reputation: 637

    2Here at PPCG, we love our explanations. +1 – a spaghetto – 2015-11-03T22:08:28.087

    3I'm pretty sure this only works with literal 0 and 1 inputs, when it's supposed to work with 48 ('0') and 49 ('1'). Am I mistaken? – undergroundmonorail – 2015-11-03T22:09:29.110

    @quartata If it was me I'd say that, to be fair to any answers that use from more traditional methods of getting input, you should have to put 48 or 49 on the stack. It's your challenge though and it's not a huge deal anyway so ¯\(ツ) – undergroundmonorail – 2015-11-03T22:16:03.213

    2There's another problem with this: if the stack is pre-populated, then you have to add 3 bytes for the -v flag. – El'endia Starman – 2015-11-04T08:57:35.317

    @El'endiaStarman It's 3 bytes now? I have seen 1 byte, and usually use 2 bytes. Is there a rule somewhere for this? Anyway I agree taking input directly on the stack isn't natural for ><> and should be mentionned. – Aaron – 2015-11-04T11:22:38.587

    @Aaron This answer contains the only consensus we have on counting flags. By that, it's 3 bytes.

    – Martin Ender – 2015-11-04T17:16:50.960

    @MartinBüttner thanks for the feedback ! However, I'm unsure where the value comes from, maybe are you counting the required space after -v ? I'm referring to the "options to request different behaviors from the interpreter" section. – Aaron – 2015-11-04T17:24:33.053

    @Aaron Yes, exactly. It's only one byte, if you can combine it with some standard flag anyway, e.g. in the case of perl perl -pe "perl code here" where you'd need -e and the space anyway. – Martin Ender – 2015-11-04T17:25:29.450

    @MartinBüttner ok, it seems fair indeed, I'll make sure to use the correct value in future answers and will try to fix my older answers. – Aaron – 2015-11-04T17:26:51.407

    1@Aaron: For what it's worth, I too thought it was 2 bytes for -v, then I was corrected. So you're not the only one. :) – El'endia Starman – 2015-11-04T20:52:56.460

    6

    Pyramid Scheme, 166 156 131 123 bytes

    Saved 10 bytes thanks to Pavel! Saved 25 33 bytes thanks to Khuldraeseth na'Barya!

       ^       ^
      / \     / \
     /set\   /do \
    ^-----^ ^-----^
    -    ^- -^   / \
        /l\ /#\ /out\
       /ine\---^-----
       -----   -
    

    Try it online!

    Try it online!

    Old answer and explanation (functionally equivalent)

        ^        ^
       / \      / \
      /set\    /do \
     ^-----^  ^-----^
    /a\   /#\/a\   / \
    ---  ^------  /out\
        /l\      ^-----
       /ine\    /a\
       -----    ---
    

    Hehe. I love this language.

    Explanation

    There are two pyramid chains. The first is:

        ^
       / \
      /set\
     ^-----^
    /a\   /#\
    ---  ^---
        /l\
       /ine\
       -----
    

    This sets variable a to line (a line read from STDIN), as a value (#).

    The second:

        ^
       / \
      /do \
     ^-----^
    /a\   / \
    ---  /out\
        ^-----
       /a\
       ---
    

    This is a do while loop, with the left pyramid being the condition, and the right one being the body. Equivalent to:

    do {
        out(a);
    } while(a);
    

    which is what we want.

    Conor O'Brien

    Posted 2015-11-03T16:40:48.353

    Reputation: 36 228

    You could make the line pyramid one size smaller right? Since it ignores if its broken up with line breaks? – Pavel – 2017-01-30T03:18:09.573

    @Pavel Yes, that's true – Conor O'Brien – 2017-01-30T03:30:55.637

    @ETHproductions okay, will do! – Conor O'Brien – 2017-01-30T03:31:01.200

    @ETHproductions Added explanation! – Conor O'Brien – 2017-01-30T03:36:32.010

    Using the sneaky nameless variable gets you down to 131

    – Khuldraeseth na'Barya – 2019-07-25T19:09:56.373

    @Khuldraesethna'Barya I'm impressed! Thanks! – Conor O'Brien – 2019-07-26T00:30:54.030

    More savings :) – Khuldraeseth na'Barya – 2019-07-26T00:42:43.670

    @Khuldraesethna'Barya That pyramid-chaining technique is really something! – Conor O'Brien – 2019-07-26T00:45:10.110

    Hehe. I also love this language. – Khuldraeseth na'Barya – 2019-07-26T00:46:38.883

    I'm glad you enjoy it :D @Khuldraesethna'Barya – Conor O'Brien – 2019-07-26T00:47:21.463

    6

    Ouroboros, 11 7 bytes

    Inspired by Sp3000's ><> answer.

    r.*.n!(
    

    Each line of code in an Ouroboros program represents a snake eating its tail.

    r reads a number from input, or -1 for EOF. .* squares it, keeping 0 and 1 the same but mapping -1 to 1. .n outputs the number, leaving a copy on the stack. Finally, !( logically negates and eats that many characters of the end of the snake. If the number was 0, this eats one character, the (, which is also the current instruction. Since the instruction pointer was swallowed, the snake dies and the program ends. If the number was 1, this eats zero characters, and execution loops back to the beginning of the snake, repeating indefinitely.

    Try it:

    // Define Stack class
    function Stack() {
      this.stack = [];
      this.length = 0;
    }
    Stack.prototype.push = function(item) {
      this.stack.push(item);
      this.length++;
    }
    Stack.prototype.pop = function() {
      var result = 0;
      if (this.length > 0) {
        result = this.stack.pop();
        this.length--;
      }
      return result;
    }
    Stack.prototype.top = function() {
      var result = 0;
      if (this.length > 0) {
        result = this.stack[this.length - 1];
      }
      return result;
    }
    Stack.prototype.toString = function() {
      return "" + this.stack;
    }
    
    // Define Snake class
    function Snake(code) {
      this.code = code;
      this.length = this.code.length;
      this.ip = 0;
      this.ownStack = new Stack();
      this.currStack = this.ownStack;
      this.alive = true;
      this.wait = 0;
      this.partialString = this.partialNumber = null;
    }
    Snake.prototype.step = function() {
      if (!this.alive) {
        return null;
      }
      if (this.wait > 0) {
        this.wait--;
        return null;
      }
      var instruction = this.code.charAt(this.ip);
      var output = null;
      console.log("Executing instruction " + instruction);
      if (this.partialString !== null) {
        // We're in the middle of a double-quoted string
        if (instruction == '"') {
          // Close the string and push its character codes in reverse order
          for (var i = this.partialString.length - 1; i >= 0; i--) {
            this.currStack.push(this.partialString.charCodeAt(i));
          }
          this.partialString = null;
        } else {
          this.partialString += instruction;
        }
      } else if (instruction == '"') {
        this.partialString = "";
      } else if ("0" <= instruction && instruction <= "9") {
        if (this.partialNumber !== null) {
          this.partialNumber = this.partialNumber + instruction;  // NB: concatenation!
        } else {
          this.partialNumber = instruction;
        }
        next = this.code.charAt((this.ip + 1) % this.length);
        if (next < "0" || "9" < next) {
          // Next instruction is non-numeric, so end number and push it
          this.currStack.push(+this.partialNumber);
          this.partialNumber = null;
        }
      } else if ("a" <= instruction && instruction <= "f") {
        // a-f push numbers 10 through 15
        var value = instruction.charCodeAt(0) - 87;
        this.currStack.push(value);
      } else if (instruction == "$") {
        // Toggle the current stack
        if (this.currStack === this.ownStack) {
          this.currStack = this.program.sharedStack;
        } else {
          this.currStack = this.ownStack;
        }
      } else if (instruction == "s") {
        this.currStack = this.ownStack;
      } else if (instruction == "S") {
        this.currStack = this.program.sharedStack;
      } else if (instruction == "l") {
        this.currStack.push(this.ownStack.length);
      } else if (instruction == "L") {
        this.currStack.push(this.program.sharedStack.length);
      } else if (instruction == ".") {
        var item = this.currStack.pop();
        this.currStack.push(item);
        this.currStack.push(item);
      } else if (instruction == "m") {
        var item = this.ownStack.pop();
        this.program.sharedStack.push(item);
      } else if (instruction == "M") {
        var item = this.program.sharedStack.pop();
        this.ownStack.push(item);
      } else if (instruction == "y") {
        var item = this.ownStack.top();
        this.program.sharedStack.push(item);
      } else if (instruction == "Y") {
        var item = this.program.sharedStack.top();
        this.ownStack.push(item);
      } else if (instruction == "\\") {
        var top = this.currStack.pop();
        var next = this.currStack.pop()
        this.currStack.push(top);
        this.currStack.push(next);
      } else if (instruction == "@") {
        var c = this.currStack.pop();
        var b = this.currStack.pop();
        var a = this.currStack.pop();
        this.currStack.push(c);
        this.currStack.push(a);
        this.currStack.push(b);
      } else if (instruction == ";") {
        this.currStack.pop();
      } else if (instruction == "+") {
        var b = this.currStack.pop();
        var a = this.currStack.pop();
        this.currStack.push(a + b);
      } else if (instruction == "-") {
        var b = this.currStack.pop();
        var a = this.currStack.pop();
        this.currStack.push(a - b);
      } else if (instruction == "*") {
        var b = this.currStack.pop();
        var a = this.currStack.pop();
        this.currStack.push(a * b);
      } else if (instruction == "/") {
        var b = this.currStack.pop();
        var a = this.currStack.pop();
        this.currStack.push(a / b);
      } else if (instruction == "%") {
        var b = this.currStack.pop();
        var a = this.currStack.pop();
        this.currStack.push(a % b);
      } else if (instruction == "_") {
        this.currStack.push(-this.currStack.pop());
      } else if (instruction == "I") {
        var value = this.currStack.pop();
        if (value < 0) {
          this.currStack.push(Math.ceil(value));
        } else {
          this.currStack.push(Math.floor(value));
        }
      } else if (instruction == ">") {
        var b = this.currStack.pop();
        var a = this.currStack.pop();
        this.currStack.push(+(a > b));
      } else if (instruction == "<") {
        var b = this.currStack.pop();
        var a = this.currStack.pop();
        this.currStack.push(+(a < b));
      } else if (instruction == "=") {
        var b = this.currStack.pop();
        var a = this.currStack.pop();
        this.currStack.push(+(a == b));
      } else if (instruction == "!") {
        this.currStack.push(+ !this.currStack.pop());
      } else if (instruction == "?") {
        this.currStack.push(Math.random());
      } else if (instruction == "n") {
        output = "" + this.currStack.pop();
      } else if (instruction == "o") {
        output = String.fromCharCode(this.currStack.pop());
      } else if (instruction == "r") {
        var input = this.program.io.getNumber();
        this.currStack.push(input);
      } else if (instruction == "i") {
        var input = this.program.io.getChar();
        this.currStack.push(input);
      } else if (instruction == "(") {
        this.length -= Math.floor(this.currStack.pop());
        this.length = Math.max(this.length, 0);
      } else if (instruction == ")") {
        this.length += Math.floor(this.currStack.pop());
        this.length = Math.min(this.length, this.code.length);
      } else if (instruction == "w") {
        this.wait = this.currStack.pop();
      }
      // Any unrecognized character is a no-op
      if (this.ip >= this.length) {
        // We've swallowed the IP, so this snake dies
        this.alive = false;
        this.program.snakesLiving--;
      } else {
        // Increment IP and loop if appropriate
        this.ip = (this.ip + 1) % this.length;
      }
      return output;
    }
    Snake.prototype.getHighlightedCode = function() {
      var result = "";
      for (var i = 0; i < this.code.length; i++) {
        if (i == this.length) {
          result += '<span class="swallowedCode">';
        }
        if (i == this.ip) {
          if (this.wait > 0) {
            result += '<span class="nextActiveToken">';
          } else {
            result += '<span class="activeToken">';
          }
          result += escapeEntities(this.code.charAt(i)) + '</span>';
        } else {
          result += escapeEntities(this.code.charAt(i));
        }
      }
      if (this.length < this.code.length) {
        result += '</span>';
      }
      return result;
    }
    
    // Define Program class
    function Program(source, speed, io) {
      this.sharedStack = new Stack();
      this.snakes = source.split(/\r?\n/).map(function(snakeCode) {
        var snake = new Snake(snakeCode);
        snake.program = this;
        snake.sharedStack = this.sharedStack;
        return snake;
      }.bind(this));
      this.snakesLiving = this.snakes.length;
      this.io = io;
      this.speed = speed || 10;
      this.halting = false;
    }
    Program.prototype.run = function() {
      this.step();
      if (this.snakesLiving) {
        this.timeout = window.setTimeout(this.run.bind(this), 1000 / this.speed);
      }
    }
    Program.prototype.step = function() {
       for (var s = 0; s < this.snakes.length; s++) {
        var output = this.snakes[s].step();
        if (output) {
          this.io.print(output);
        }
      }
      this.io.displaySource(this.snakes.map(function (snake) {
          return snake.getHighlightedCode();
        }).join("<br>"));
     }
    Program.prototype.halt = function() {
      window.clearTimeout(this.timeout);
    }
    
    var ioFunctions = {
      print: function (item) {
        var stdout = document.getElementById('stdout');
        stdout.value += "" + item;
      },
      getChar: function () {
        if (inputData) {
          var inputChar = inputData[0];
          inputData = inputData.slice(1);
          result = inputChar.charCodeAt(0);
        } else {
          result = -1;
        }
        var stdinDisplay = document.getElementById('stdin-display');
        stdinDisplay.innerHTML = escapeEntities(inputData);
        return result;
      },
      getNumber: function () {
        while (inputData && (inputData[0] < "0" || "9" < inputData[0])) {
          inputData = inputData.slice(1);
        }
        if (inputData) {
          var inputNumber = inputData.match(/\d+/)[0];
          inputData = inputData.slice(inputNumber.length);
          result = +inputNumber;
        } else {
          result = -1;
        }
        var stdinDisplay = document.getElementById('stdin-display');
        stdinDisplay.innerHTML = escapeEntities(inputData);
        return result;
      },
      displaySource: function (formattedCode) {
        var sourceDisplay = document.getElementById('source-display');
        sourceDisplay.innerHTML = formattedCode;
      }
    };
    var program = null;
    var inputData = null;
    function showEditor() {
      var source = document.getElementById('source'),
        sourceDisplayWrapper = document.getElementById('source-display-wrapper'),
        stdin = document.getElementById('stdin'),
        stdinDisplayWrapper = document.getElementById('stdin-display-wrapper');
      
      source.style.display = "block";
      stdin.style.display = "block";
      sourceDisplayWrapper.style.display = "none";
      stdinDisplayWrapper.style.display = "none";
      
      source.focus();
    }
    function hideEditor() {
      var source = document.getElementById('source'),
        sourceDisplay = document.getElementById('source-display'),
        sourceDisplayWrapper = document.getElementById('source-display-wrapper'),
        stdin = document.getElementById('stdin'),
        stdinDisplay = document.getElementById('stdin-display'),
        stdinDisplayWrapper = document.getElementById('stdin-display-wrapper');
      
      source.style.display = "none";
      stdin.style.display = "none";
      sourceDisplayWrapper.style.display = "block";
      stdinDisplayWrapper.style.display = "block";
      
      var sourceHeight = getComputedStyle(source).height,
        stdinHeight = getComputedStyle(stdin).height;
      sourceDisplayWrapper.style.minHeight = sourceHeight;
      sourceDisplayWrapper.style.maxHeight = sourceHeight;
      stdinDisplayWrapper.style.minHeight = stdinHeight;
      stdinDisplayWrapper.style.maxHeight = stdinHeight;
      sourceDisplay.textContent = source.value;
      stdinDisplay.textContent = stdin.value;
    }
    function escapeEntities(input) {
      return input.replace(/&/g, '&amp;').replace(/</g, '&lt;').replace(/>/g, '&gt;');
    }
    function resetProgram() {
      var stdout = document.getElementById('stdout');
      stdout.value = null;
      if (program !== null) {
        program.halt();
      }
      program = null;
      inputData = null;
      showEditor();
    }
    function initProgram() {
      var source = document.getElementById('source'),
        stepsPerSecond = document.getElementById('steps-per-second'),
        stdin = document.getElementById('stdin');
      program = new Program(source.value, +stepsPerSecond.innerHTML, ioFunctions);
      hideEditor();
      inputData = stdin.value;
    }
    function runBtnClick() {
      if (program === null || program.snakesLiving == 0) {
        resetProgram();
        initProgram();
      } else {
        program.halt();
        var stepsPerSecond = document.getElementById('steps-per-second');
        program.speed = +stepsPerSecond.innerHTML;
      }
      program.run();
    }
    function stepBtnClick() {
      if (program === null) {
        initProgram();
      } else {
        program.halt();
      }
      program.step();
    }
    function sourceDisplayClick() {
      resetProgram();
    }
    .container {
        width: 100%;
    }
    .so-box {
        font-family:'Helvetica Neue', Arial, sans-serif;
        font-weight: bold;
        color: #fff;
        text-align: center;
        padding: .3em .7em;
        font-size: 1em;
        line-height: 1.1;
        border: 1px solid #c47b07;
        -webkit-box-shadow: 0 2px 2px rgba(0, 0, 0, 0.3), 0 2px 0 rgba(255, 255, 255, 0.15) inset;
        text-shadow: 0 0 2px rgba(0, 0, 0, 0.5);
        background: #f88912;
        box-shadow: 0 2px 2px rgba(0, 0, 0, 0.3), 0 2px 0 rgba(255, 255, 255, 0.15) inset;
    }
    .control {
        display: inline-block;
        border-radius: 6px;
        float: left;
        margin-right: 25px;
        cursor: pointer;
    }
    .option {
        padding: 10px 20px;
        margin-right: 25px;
        float: left;
    }
    h1 {
        text-align: center;
        font-family: Georgia, 'Times New Roman', serif;
    }
    a {
        text-decoration: none;
    }
    input, textarea {
        box-sizing: border-box;
    }
    textarea {
        display: block;
        white-space: pre;
        overflow: auto;
        height: 50px;
        width: 100%;
        max-width: 100%;
        min-height: 25px;
    }
    span[contenteditable] {
        padding: 2px 6px;
        background: #cc7801;
        color: #fff;
    }
    #stdout-container, #stdin-container {
        height: auto;
        padding: 6px 0;
    }
    #reset {
        float: right;
    }
    #source-display-wrapper , #stdin-display-wrapper{
        display: none;
        width: 100%;
        height: 100%;
        overflow: auto;
        border: 1px solid black;
        box-sizing: border-box;
    }
    #source-display , #stdin-display{
        font-family: monospace;
        white-space: pre;
        padding: 2px;
    }
    .activeToken {
        background: #f93;
    }
    .nextActiveToken {
        background: #bbb;
    }
    .swallowedCode{
        color: #999;
    }
    .clearfix:after {
        content:".";
        display: block;
        height: 0;
        clear: both;
        visibility: hidden;
    }
    .clearfix {
        display: inline-block;
    }
    * html .clearfix {
        height: 1%;
    }
    .clearfix {
        display: block;
    }
    <!--
    Designed and written 2015 by D. Loscutoff
    Much of the HTML and CSS was taken from this Befunge interpreter by Ingo Bürk: https://codegolf.stackexchange.com/a/40331/16766
    -->
    <div class="container">
    <textarea id="source" placeholder="Enter your program here" wrap="off">r.*.n!(</textarea>
    <div id="source-display-wrapper" onclick="sourceDisplayClick()"><div id="source-display"></div></div></div><div id="stdin-container" class="container">
    <textarea id="stdin" placeholder="Input" wrap="off">1</textarea>
    <div id="stdin-display-wrapper" onclick="stdinDisplayClick()"><div id="stdin-display"></div></div></div><div id="controls-container" class="container clearfix"><input type="button" id="run" class="control so-box" value="Run" onclick="runBtnClick()" /><input type="button" id="pause" class="control so-box" value="Pause" onclick="program.halt()" /><input type="button" id="step" class="control so-box" value="Step" onclick="stepBtnClick()" /><input type="button" id="reset" class="control so-box" value="Reset" onclick="resetProgram()" /></div><div id="stdout-container" class="container"><textarea id="stdout" placeholder="Output" wrap="off" readonly></textarea></div><div id="options-container" class="container"><div class="option so-box">Steps per Second:
    <span id="steps-per-second" contenteditable>20</span></div></div>

    Previous two-snake solution:

    rm1(
    S.n.!(
    

    Snake 1

    r reads a number from input; m moves it to the shared stack. Then 1( causes the snake to eat its instruction pointer and die.

    Snake 2

    S switches to the shared stack. .n duplicates the value and outputs it as a number. .!( duplicates again, logically negates, and eats that many characters. If the number was 0, this eats one character, killing the second snake and ending the program. If the number was 1, this eats zero characters and execution loops back to the beginning of the snake, repeating indefinitely.

    DLosc

    Posted 2015-11-03T16:40:48.353

    Reputation: 21 213

    1Did you just post the source code for an interpreter with the answer? Why not link to it? – Cyoce – 2016-01-07T07:02:35.300

    1@Cyoce The interpreter was written as part of Helka Homba's stack snippet challenge. Per his own statement, "the point is to make something that can be easily copied and used in future PPCG questions and answers." The fact that it was done here means that Helka's plan worked perfectly. :) – Alex A. – 2016-08-16T05:02:50.947

    6

    Acc! - 54 50 48 49 Bytes

    N
    Write _
    Count q while _-48 {
    Write _
    }
    

    pppery

    Posted 2015-11-03T16:40:48.353

    Reputation: 3 987

    Works in Acc!! too! ;)

    – DLosc – 2015-11-03T19:15:48.973

    6

    MarioLANG, 11 8 bytes

    ;:
    [^
    =:
    

    This prints a space after each 0 or 1 (as has been clarified is acceptable). The program was tested in the Ruby interpreter. It's not clear whether this behaviour of ^ is according to spec, but it works consistently in this implementation.

    As usual, = is just some ground for Mario to walk on.

    • ; reads an integer from STDIN into the current tape cell.
    • [ is a conditional. If the tape cell is 0, Mario skips the next cell (the ^), which will make him fall through the : (printing the 0), off the bottom edge and terminate the program (poor Mario). If the tape cell is 1, this does nothing, and execution continues.
    • ^ is a jump command. It stops Mario from moving forward and sends him straight up one cell before he falls back down. For some reason (at least in this implementation) Mario can jump in mid-air provided there's another cell (even a space) below the jump. That means Mario repeatedly jumps into the top :, printing the 1, falls back down onto the ^ and performs another jump. This must be a feature from the popular Super Ninja Brothers spin-off.

    Martin Ender

    Posted 2015-11-03T16:40:48.353

    Reputation: 184 808

    2Aww, poor mario. – None – 2016-07-23T02:37:11.550

    6

    AutoHotkey, 20 bytes

    I recently got into AutoHotkey and have been waiting for a suitable challenge to try my skills at.

    $0::Send 0
    1::Send
    

    This takes input by listening for key presses and outputs via simulated key presses. The $ on the first line forces the first hotkey to take input through the keyboard only, so it just outputs 0 when the 0 key is pressed. The second is not so lucky though. When it detects the 1 key being pressed, it presses the 1 key, which it detects, so it presses 1, which it detects and so on. AutoHotkey unfortunately doesn't like this, but that can probably be fixed by adding #HotkeysInterval 1 to the top of the program. I am not brave enough to try this though, as it will probably crash my computer.

    If input and output through key presses is invalid, here's a solution that avoids it:

    InputBox, a
    MsgBox %a%
    While a{
    MsgBox 1
    }
    

    DanTheMan

    Posted 2015-11-03T16:40:48.353

    Reputation: 3 140

    This is the first answer I've seen in AutoHotkey. Have a +1 – Cyoce – 2016-01-07T07:22:41.993

    6

    ResPlicate, 39 38 bytes

    0 -49 12 1 48 9 0 49 4 2 0 49 4 2 48 0
    

    This was one of the earliest examples I made after implementing this language, so I have simply copied it from the linked wiki article, which I largely wrote. Actually, having rewritten my old version to shorten it by a byte, I can now say this example was written for this catalogue.

    ResPlicate in a Nutshell

    Programs in ResPlicate are all comprised of a list of integers, which are inserted into a queue in order. Each step, the first two integers are popped as x and y. Then a list of x integers is popped (and padded with zeros if the queue had fewer than x elements) and re-enqueued y times. This is quite sufficient to ensure Turing-completeness. Indeed, it is even Turing-complete in the limited case that y is not allowed to exceed 2.

    This simple language is extended with I/O in the following way: If x is zero and y is positive, y is output as a character. If x is zero and y is negative, a character is read from input, y+1 is added to it, and the result is enqueued.

    Ungolfed:

    Thus, the above program can be read like this:

    0 -49                       Read a character from input, subtract 48 from its value.
                                If the input was 1 or 0, this will cause the corresponding 
                                integer value to be pushed onto the queue.
    12 1 [48 9 ... 48 0]        Move the next 12 integers to the end of the queue. 
                                This brings the input integer to the front of the queue.
    

    So now execution follows two completely different paths depending on the value of the input. If it was "0", it continues like this:

    (0) 48                      The input zero and "48" are popped, causing the character
                                with value 48 ("0") to be printed.
    9 0 [49 4 2 0 49 4 2 48 0]  Pop and discard the next 9 integers, emptying the queue.
                                An empty queue terminates the program.
    

    If the input was "1", the program continues thusly:

    (1) 48 [9]                  Enqueue 48 times the number 9.
    0 [49]                      Print the character with value 49 ("1").
    4 2 [0 49 4 2]              Place "0 49" (print "1") at the end of the queue,
                                followed by a copy of this command.
    48 0 [9 9 ... 9 9]          Discard the 48 9's that were enqueued earlier.
    

    At this point, the queue contains only "0 49 4 2 0 49 4 2", which will repeatedly print "1" and then restore the queue to precisely this state, ensuring that it will continue in this manner forever.

    quintopia

    Posted 2015-11-03T16:40:48.353

    Reputation: 3 899

    6

    Marbelous, 22 bytes

    00 .. ..
    ]] // ..
    -O @1 ..
    =O .. ..
    +O /\ @1
    

    All padding is superfluous in this program, spaces and dots can be removed.

    The // sends the 00 marble through the ]] stdin device until there's a byte available, then it drops that byte. -O-O=0 or -O=O check for ascii 48 which is "0", then either the input gets output once or forever (through the @1 loop), incremented back up to the proper ascii value with a +O on the way out.

    Sparr

    Posted 2015-11-03T16:40:48.353

    Reputation: 5 758

    6

    PlatyPar, 2 Bytes

    wA
    

    Explanation:

    Implicit: push input to the stack.

    w: while last item. A: alert last item.

    If you give it something truthy, while(stack[-1]) goes on infinitely. If not, it skips that, and alerts the last item of the stack implicitly (falsy).

    Try it online! Press cancel instead of ok on the alert if you want to stop the loop after giving a 1.

    Cyoce

    Posted 2015-11-03T16:40:48.353

    Reputation: 2 690

    why Platy? Is it different from normal Par? – cat – 2015-12-15T04:59:21.800

    3After extensive research, I failed to discover there was already a language named Par. I found this as someone had posted an answer in a language called Par (not mine), and I was getting credit for his answers, and vice-versa. I have renamed mine, as I am sure the other came first (mine is only a week old). – Cyoce – 2015-12-15T05:41:20.217

    6

    Woefully, 266 bytes

    First answer in this language!

    It's called woefully because the bytecounts are saddening

    Woefully is a 2d language with no conditionals, except for the notz/bool command (pop a, push 1 if not zero, else push zero), and combining this with the move char pointer command yields control flow. In a truth machine, the values entered are already zero or one, and are only of two values, so is less complex than some other conditional programs, which kind of defeats the purpose of the truth machine :P

    There are two pointers, the instruction pointer (ip), and the char pointer (cp), and it's hard to explain in one post, but the ip goes through the paths, cp stays stationary unless moved by instructions the ip executes.

    Woefully has 2 stacks, all pushing is to A, except dupe and AtoB

    | || ||||| |
    || |||||| |
    ||| |||| |
    |||| || |
    ||||| || |
    ||||| ||| |
    ||||| |||| |
    ||||| ||||| |
    ||||| |||||| |
    ||||| |
    |||||| |
    ||||||| |
    |||||| |
    ||||| |
    |||| |
    ||| |
    || |
    | |
    || |
    ||| |
    ||| |
    |||| |
    ||| |
    || |
    | |
    | |
    | |
    | |
    | |
    || |
    ||| |
    |||| |
    ||||| |
    |||||| |
    

    Try it online!

    Explanation (difficult from the size) Execution starts at the v, at the A path:

    V   FI    \/  V shows initial char pointer pos, F the pos after movement
    |A||X|||||Z|   if input is zero, I if it is 1. The path marked by \/ won't
    ||A||||||Z|    be executed until the first part has been done, and then only
    |||A||||Z|  #X path halts program                          if input is zero 
    ||||A||Z|   # A path pushes input     #Z path pushes one
    |||||A||O|
    |||||E|||O|
    |||||E||||O|   #E path dupes, by peeking top of a stack, pushing to b stack
    |||||E|||||O| #O path outputs TOS of A
    |||||E||||||O|
    |||||E|    ^End of path, go back to char pointer, still over this path
    ||||||F|      #F path pops a, moves the char pointer
    |||||||F|
    ||||||G|
    |||||G|
    ||||G|
    |||G|      #G path pushes 4
    ||G|
    |G|
    ||H|   #H pops a, moves char pointer by a. the char pointer is (again)
    |||H|  #now over F or I, depending on input
    |||X|  X are nops
    ||||X|
    |||L|   L path pushes 1
    ||L|
    |L|
    |V| V path multiplies both TOS (A and B), pushes to A
    |V|
    |V|
    |V|
    ||O|
    |||O|    O path outputs tos of A
    ||||O|
    |||||O|
    ||||||O|
    End of path, go back to the char pointer. If input was zero, the char
    pointer will be over the halting path, so program over, otherwise it's over
    the next char, and goes to the infinite one river
    

    Note this is somewhat simplified: paths overlap on the corners they meet at.

    Destructible Lemon

    Posted 2015-11-03T16:40:48.353

    Reputation: 5 908

    5

    Forte, 49 60 bytes

    3LET5=5+(0*4)
    4INPUT0:LET6=6-(0*4)
    5PRINT0:LET3=3+(0*4)
    6END
    

    Try it online!

    Forte is a weird and wonderful language with BASIC-like syntax and an execution model based on redefining integers. It has no conditional or looping constructs; to get conditional or looping behavior, you have to redefine the line numbers your program uses.

    How?

    Here's the code with better spacing:

    3 LET 5=5+(0*4)
    4 INPUT 0 : LET 6=6-(0*4)
    5 PRINT 0 : LET 3=3+(0*4)
    6 END
    

    If the user inputs a zero to this program, the three LET statements don't change anything, and the program boils down to PRINT 0 : END.

    If the user inputs a one... it gets interesting.

    3 LET 5=5+(0*4)
    

    The first time around, no numbers have been redefined yet; this line calculates 5+(0*4) and assigns that to 5. Nothing changes.

    4 INPUT 0 : LET 6=6-(0*4)
    

    INPUT 0 reads a number from the user and redefines 0 as that number. Suppose the user enters a 1. Every time 0, or a value of zero, occurs from now on, it will be changed to 1. For instance: LET 6=6-(0*4) now is calculated as LET 6=6-(1*4), which redefines 6 to be 2. This changes the END statement's line number to 2, which moves it out of the way of the program, allowing an infinite loop.

    Redefinitions: 0->1; 6->2

    5 PRINT 0 : LET 3=3+(0*4)
    

    First, this line prints 1 (the value that 0 now represents). Then, 0*4 is now 1*4, so we have LET 3=7.

    Redefinitions: 0->1; 6->2; 3->7

    Next, we increment the instruction pointer and execute the command on line 3 7:

    3 LET 5=5+(0*4)
    

    which redefines 5 to be 5+4...

    Redefinitions: 0->1; 6->2; 3->7; 5->9

    ... and we execute line 5 9:

    5 PRINT 0 : LET 3=3+(0*4)
    

    which should be read (with substitutions) as 9 PRINT 1 : LET 7=7+(1*4). We print another 1 and change 7 to 11, which means we execute the original line 3 again, and so forth.

    For those who are still confused, read the Esolangs article or ping ais523 (the language's inventor!) in chat.

    DLosc

    Posted 2015-11-03T16:40:48.353

    Reputation: 21 213

    5

    Groovy, 51 47 bytes

    x=System.in.text as int;while(x)print x;print x
    

    Radical.

    a spaghetto

    Posted 2015-11-03T16:40:48.353

    Reputation: 10 647

    That is nice how you're using the input. +1 – Addison Crump – 2015-11-03T16:47:15.453

    Does Groovy have a do-while? IE do print x;while(x); (maybe needs braces) – Justin – 2015-11-03T18:13:02.007

    @Justin No it doesn't sadly. – a spaghetto – 2015-11-03T18:13:15.710

    3

    Funny that they don't list that in their list of major differences between Groovy and Java. I'd imagine this is a major difference.

    – Justin – 2015-11-03T18:21:56.443

    you can save two bytes by not casting the input and doing an equality check to the string "1" - Try it online!

    – Ephphatha – 2017-05-27T06:09:22.780

    5

    Vitsy, 10 5 4 Bytes

    New Versions! :D

    [DN]
    [  ]    Repeat while the top item is not 0
     D      Duplicate the top item
      N     Print it out.
    

    I would put a try it online link here, but Vitsy's try it online doesn't output every line as it is output yet.

    Try it online!

    Addison Crump

    Posted 2015-11-03T16:40:48.353

    Reputation: 10 763

    That's quite a golf... is input initially laid in the stack? – Conor O'Brien – 2015-11-03T17:19:00.267

    @CᴏɴᴏʀO'Bʀɪᴇɴ Turns out I was a version ahead - forgot to push my changes - in any case, I'll add the flag as part of the byte count. – Addison Crump – 2015-11-03T18:13:51.323

    2You forgot to push your changes? (Bad stack-related pun) – Conor O'Brien – 2015-11-03T18:20:59.737

    6...ಠ_ಠ​​​​​​​​​ – Addison Crump – 2015-11-03T18:24:39.467

    The TIO link is broken :/ – CalculatorFeline – 2017-06-06T21:56:56.383

    5

    JavaScript, 32 bytes

    x=prompt();do{alert(x)}while(+x)
    

    On input of 0, alerts 0 to the user; on input of 1, forever alerts 1. If alert is not a suitable alternative for STDOUT, replace it with console.log and add 6 to the byte count.

    Edit: I've been solidly beat by @intrepidcoder; see this answer.

    ETHproductions

    Posted 2015-11-03T16:40:48.353

    Reputation: 47 880

    5

    Simplex v.0.8, 3 bytes

    Try it here!

    i¦o
    i   ~~ take input
     ¦  ~~ repeat next character until zero byte met
      o ~~ output character
    

    Conor O'Brien

    Posted 2015-11-03T16:40:48.353

    Reputation: 36 228

    5

    C, 39

    main(){for(;putchar(getchar()&49)&1;);}
    

    STDIN must be a 1-byte file. It will not work if there is a trailing newline. This is because the program relies on all calls to getchar following a 1 to return EOF, which is represented as -1 (all ones in binary).

    feersum

    Posted 2015-11-03T16:40:48.353

    Reputation: 29 566

    5

    QBasic, 23 bytes

    INPUT x
    1?x
    IF x THEN 1
    

    Gotos are the best way to loop. ;^) 1 is a label; ? is a shortcut for PRINT.

    DLosc

    Posted 2015-11-03T16:40:48.353

    Reputation: 21 213

    1GOTOs are truely superior =D – Jan – 2015-11-04T20:31:57.257

    5

    Java, 149 128 120 bytes

    class A{public static void main(String[]a)throws Exception{int n=System.in.read()%2;do System.out.print(n);while(n>0);}}
    

    Why 120 bytes? Because Java.

    Edit: Saved 21 bytes thanks to Justin. Saved 8 bytes thanks to dohaqatar7.

    intrepidcoder

    Posted 2015-11-03T16:40:48.353

    Reputation: 2 575

    2

    See: Java

    – Addison Crump – 2015-11-03T18:45:05.243

    Scanner s=new Scanner(System.in);int n=s.nextInt(); can be instead int n=new Scanner(System.in).nextInt();. At that point, get rid of the import and do int n=new java.util.Scanner(System.in).nextInt(); Leaves you with 128 chars – Justin – 2015-11-03T18:48:00.180

    1There's no need to use a scanner, just read from System.in directly. class A{public static void main(String[]a)throws Exception{int n=System.in.read()%2;do System.out.print(n);while(n>0);}} . You have to throw an Exception but it's shorter than all the crap with Scanner. – ankh-morpork – 2015-11-03T20:35:59.017

    1you could drop few charactrs if you use for(;;) loop instead do while – user902383 – 2015-11-05T11:43:29.343

    @user902383 Actually no, because then it would print 0's indefinitely too. As it stands, it prints the 0 once, and 1 indefinitely, just as it should. – Xynariz – 2015-11-11T17:49:06.653

    5

    Prelude, 6 bytes

    Prelude is a bit tricky here. The language specification says I/O is via characters' byte values. That's what the C implementation does. Then there's the Python interpreter, which uses bytes for input but prints decimal integers. And then there's my own fork of that interpreter which does both input and output numerically (which I've published a few months ago). Since languages on PPCG are defined by their implementations, all of these constitute valid Prelude variants.

    My fork gives the shortest solution at 6 bytes:

    ?(1!)!
    

    ? pushes the input. (...) is a Brainfuck-style while loop, which is skipped for 0 input. Then ! prints the zero. If the input was 1, we enter the loop, push another 1 and print that with ! (we need to push a new 1, because ! pops the top of the stack).

    Next up is the original Python interpreter at 14 bytes:

    ?6^+^+^+-(1!)!
    

    Since output is the same as in my fork, all we need to do is map the character codes to 0 or 1 which we do by subtracting 48. There are several ways to get 48 in 7 bytes, but I don't think it's possible to do it in less. This one pushes 6 and then doubles it 3 times, by duplicating it with ^ and adding the two copies with +.

    Finally, the solution that works with the original C interpreter needs 16 bytes:

    ?^(#^!^6^+^+^+-)
    

    This one has a slightly different structure. Since we also need to output 48 or 49 respectively, we now remember the input and obtain the 0 or 1 only for the loop condition. This also let's us get a way with a single ! because we can easily turn the loop into do-while. Again, ? reads the input and ^ makes a copy which we only need because the first thing in the loop is #, which discards the top of the stack (we need this to discard the condition from a previous iteration). Now ^! prints a copy of the input. Then ^6^+^+^+- computes input - 48 as before. If that is 0, we leave the loop immediately and exit after printing a single number. Otherwise, the loop will keep going, printing the input 49 each time.

    Martin Ender

    Posted 2015-11-03T16:40:48.353

    Reputation: 184 808

    By "fork" do you mean you toggled the option on that one line? – feersum – 2015-11-04T03:01:28.773

    @feersum I added it. – Martin Ender – 2015-11-04T06:31:47.973

    I was thinking of the NUMERIC_OUTPUT on line 5, but forgot it only affects one of I/O. I guess you had to add a numeric input option too for your modification. – feersum – 2015-11-04T06:59:17.773

    @feersum yeah, exactly. The original Prelude interpreter already has the output flag set. – Martin Ender – 2015-11-04T07:00:07.043

    5

    Whitespace, 46 37 bytes

    Thanks to Kevin Cruijssen for golfing 1 byte off the first instruction, and 8 bytes by removing the last 2 instructions, which makes the program jumps to non-existent label and terminates with error but still output correctly in the output stream.

    SS SL  # push 0
    SLS    # dup
    TLTT   # readn
    TTT    # load
    LSS L  # label L
    SLS    #   dup
    SLS    #   dup
    TLST   #   prtn
    LTS TL #   jmpz TL
    LSL L  # jmp L
    

    Demo on ideone

    Previous safe version of the program which terminates normally has a proper label and the standard triple new line to end the program:

    LSS TL # label TL
    LLL    # end
    

    Demo on ideone

    Notation explanation:

    • # starts comment
    • L is newline
    • S is space
    • T is tab

    I used this interpreter to develop the program and generate the comments.

    Didn't expect the code to be this long. Whitespace requires the input to be read into heap, heap instructions consumes stack, printing instruction consumes the stack and even jump instruction consumes the stack, so it bloats the code with all the "duplicate top stack" instructions.

    n̴̖̋h̷͉̃a̷̭̿h̸̡̅ẗ̵̨́d̷̰̀ĥ̷̳

    Posted 2015-11-03T16:40:48.353

    Reputation: 5 683

    Is there anything wrong in my answer that warrants a downvote? – n̴̖̋h̷͉̃a̷̭̿h̸̡̅ẗ̵̨́d̷̰̀ĥ̷̳ – 2015-12-25T02:15:34.023

    On this interpreter, SSL is a valid way to push 0 (which makes it as efficient as the duplicate instruction, heh). Also, LLL doesn't seem to be required to end execution there if it hits end-of-file. That would bring it down to 41 bytes.

    – Josiah Winslow – 2017-09-04T05:07:22.003

    I know it's been a while, but you can golf some parts: SS SSL (push 0) can be SS SL. After specifying it's positive with S (or negative with T), it's already implicit 0, so no need for an additional S for 0. In addition, you can remove the trailing LSSTL LLL. It will exit with an error (Undefined Label) for input 0, but that's allowed according to the meta. Try it online, or try it online raw 37 bytes.

    – Kevin Cruijssen – 2018-03-16T15:18:30.240

    @KevinCruijssen: Updated. – n̴̖̋h̷͉̃a̷̭̿h̸̡̅ẗ̵̨́d̷̰̀ĥ̷̳ – 2018-03-17T16:32:49.053

    5

    LaTeX, 97 bytes

    \documentclass{proc}\begin{document}\typein[\q]{}\loop\typeout{\q}\ifnum\q=1\repeat\end{document}
    

    I guess it's sort of a grey area since everything is generated at compile time. Prints 1s to "stdout" until it runs out of memory or one 0 depending on input.

    sweerpotato

    Posted 2015-11-03T16:40:48.353

    Reputation: 2 457

    5

    Befunge-98, 7 bytes

    &:.:j@#
    

    Explanation:

    &            Read integer
     :           Push copy
      .          Print the copy
       :         Push another copy
        j        Jump that many characters to the right
         q       Terminate program (jumped over if input was 1)
          #      Skip next instruction
                 (And implicitly loop back to the start)
    

    lirtosiast

    Posted 2015-11-03T16:40:48.353

    Reputation: 20 331

    5

    beeswax, 13 11 8 chars

    I could golf the solution down by 3 more bytes. This solution is pretty much a literal translation of my Cardinal solution:

    _T> "{'j
    

    Explanation:

    _         generate bee/IP
     T        enter integer, set lstack top value to this value
      >       redirect bee to right              
        "     if lstack top value>0, skip next instruction
         {    output lstack top value to STDOUT
          '   if lstack top value=0, skip next instruction
           j  mirror bee direction along | axis
    

    If 0 is entered, the following instructions get executed:

         +———————————————————————————— output '0'
         ↓
    _T> "{'
    
    After execution of ' the IP leaves the honeycomb and the program terminates.
    

    And in case of entering 1:

          +——————————————————————————— mirror bee direction of movement (to the left)
          | +————————————————————————— output '1'
          | |  +—————————————————————— redirect bee to the right
          | |  |   +—————————————————— mirror bee direction of movement
          | |  |   | +———————————————— output '1'
          | |  |   | |  +————————————— redirect bee to the right
          ↓ ↓  ↓   ↓ ↓  ↓
    _T> "'j'{" > "'j'{" > .......      
    
    ... bouncing back and forth between > and j forever, printing an infinite string of ones.
    

    Clone my beeswax interpreter (written in Julia), language specification and examples from my GitHub repository.

    M L

    Posted 2015-11-03T16:40:48.353

    Reputation: 2 865

    5

    TrumpScript, 54 53 bytes

    Say i
    As long as,i is "1"?;:
    Say i!
    America is great.
    

    The longer version:

    Tell them what TrumpSaid
    As long as , Cruz i is not number "1"?; :
    Say what TrumpSaid !
    America is great.
    

    J Atkin

    Posted 2015-11-03T16:40:48.353

    Reputation: 4 846

    1"Just think of debugging as a fun little game." lol – Lui – 2016-01-24T22:49:05.727

    Just so you know this is a fork of the original TrumpScript for PPCG. https://github.com/samshadwell/TrumpScript

    – J Atkin – 2016-01-24T23:07:58.830

    5

    Befunge-93+, 7

    &>:.:_@
    

    & takes integer input. :.: is a palindromic loop: it duplicates the top of the stack, prints it, and duplicates it again. _ will exit the the loop by moving to the right if the top of the stack is 0. Otherwise it executes the loop again, then > executes the loop again, and so on until the stack overflows. @ terminates the program.

    histocrat

    Posted 2015-11-03T16:40:48.353

    Reputation: 20 600

    5

    JAISBaL, 15 6 bytes

    ˗Y1˄N0
    

    Explanation:

    # \# enable verbose parsing #\
    while               \# [0] start while loop #\
        printnumln 1    \# [1] print 1 #\
    end                 \# [2] end current language construct #\
    printnum 0          \# [3] print 0 #\
    

    Socratic Phoenix

    Posted 2015-11-03T16:40:48.353

    Reputation: 1 629

    5

    Sesos, 2 bytes

    V0
    

    Try it online! Check Debug to see the generated binary code.

    How it works

    The binary file above has been generated by assembling the following SASM code.

    set numin  ; Switch to numeric input.
    set numout ; Switch to numeric output.
    
    get        ; Read an integer from STDIN and save in in the current cell.
    nop        ; Set an entry marker.
        put    ; Print the integer in the current cell.
               ; (implicit jnz)
               ;     If the integer in the current cell is non-zero,
               ;     jump to the previous instruction.
    

    Dennis

    Posted 2015-11-03T16:40:48.353

    Reputation: 196 637

    4

    Brachylog, 4 bytes

    Thanks to Fatalize for saving 1 byte.

    w?1↰
    

    Try it online!

    Explanation

    w     Write the input to STDOUT.
     ?1   Check whether the input equals 1.
       ↰  If so, recursively call the main predicate with 1 again.
    

    Martin Ender

    Posted 2015-11-03T16:40:48.353

    Reputation: 184 808

    What a pity that w's output isn't its input. – Erik the Outgolfer – 2018-02-28T20:14:55.590

    4

    brainfuck (portable), 29 28 bytes

    >>>,.[[->+<<+>]>-]<+[<<]>[.]
    

    Try it online!

    (Improved by 1 byte thanks to Jo King, who found a terser way to start the [<<] loop.)

    I know that on PPCG it's normally sufficient for an answer to work on one interpreter, but as this is a catalogue, I wanted a demonstration of a brainfuck answer that should work on any interpreter, and which exits without error on input 0. This program makes no assumptions about cell size, EOF behaviour, wrapping, tape extension to the left, etc. It's the shortest brainfuck truth-machine I'm aware of with these properties.

    Explanation

    >>>,.[[->+<<+>]>-]<+[<<]>[.]
    >>>,                            Input a character to the fourth cell
        .                           Output that character
         [           ]              While the current cell is nonzero:
          [->+<<+>]                   Move the value to the next and previous cells
                   >                  Make the next cell current
                    -                 and decrement it
                      <+            Starting behind the current cell, at value 1
                        [<<]        Move back two cells at a time until we find zero
                            >[ ]    If the cell to the right is nonzero:
                              .       Output it forever
    

    The basic idea here is to create a range on the tape, containing all values from the input's ASCII code down to 0. (So for example, if the input is 0, we get 48 in the third cell, 47 in the fourth cell, 46 in the fifth cell, etc..) Once we've done that, we look at alternate values of the range until we end up at a tape element before the start of the range. If the range has an even length (i.e. the input has an even ASCII code), we'll end up two cells to the left of it, so moving to the right we'll end up in a cell we've never written to (and thus still has the value zero). If the range has an odd length, we'll end up only one cell to its left, so >[.] will move to the first cell of the range (i.e. the user input) and output it in a loop forever.

    ais523

    Posted 2015-11-03T16:40:48.353

    Reputation: 11

    4

    PowerShell, 16 15 bytes

    for(;$args){1}0
    

    Try it Online!

    Edit:
    -1 byte thanks to @AdmBorkBork

    J. Bergmann

    Posted 2015-11-03T16:40:48.353

    Reputation: 221

    Use a for loop to save a byte Try it online!

    – AdmBorkBork – 2018-07-19T15:45:35.297

    4

    PUBERTY, 369 bytes

    It is May 1, 2018, 3:01:04 PM.Y is in his bed, bored.His secret kink is J.Soon the following sounds become audible.oh yeah yeah yeah hrg fap yeah yeah yeah fap yeah fap yeah yeah mmf yeah yeah yeah hrg yeah hrg fap yeah yeah yeah yeah fap yeah fap yeah mmf yeah yeah yeah yeah yeah yes yeah yeah yeah yeah yeah hrg fap yeah fap yeah fap yeah yeah yeah yeah mmf yeah mmf
    

    Ungolfed

    It is May 1, 2018, 3:01:04 PM.
    Yhprum is in his bed, bored.
    His secret kink is humaninteraction.
    Soon the following sounds become audible.
    
    oh yeah yeah yeah
    hrg
        fap yeah yeah yeah fap yeah fap yeah yeah
    mmf
    
    yeah yeah yeah
    
    hrg
        yeah
        hrg
           fap yeah yeah yeah yeah fap yeah fap yeah
        mmf
        yeah yeah yeah yeah yeah
    
        yes
    
        yeah yeah yeah yeah yeah
        hrg
            fap yeah fap yeah fap yeah yeah yeah yeah
        mmf
        yeah
    mmf
    

    This was very much harder than I expected it to be using this language.

    Explanation

    PUBERTY is a wonderful language. It has 6 registers (A, B, C, D, E, F) and one register pointer, all initialized to 0. At the end of each instruction, REGPTR %= 6 and REG[REGPTR] %= 256.

    These are the commands used in this program:

    • oh reads an ASCII character and stores its value into the current register
    • yeah increments REGPTR by 1
    • hrg...mmf loops until the current register has a value of zero
    • fap increments the current register by 1
    • yes prints the ASCII char corresponding to the value of the current register

    The program starts with the header - the first four lines

    It is May 1, 2018, 3:01:04 PM.
    

    This sets $D to the Unix timestamp of the date % 256. In this case, we set it to 48. This statement is required

    Yhprum is in his bed, bored.
    

    This initializes $C to 6, the number of chars in the name, but we don't use this at all. This statement is required.

    His secret kink is humaninteraction.
    

    This line is where you declare all your kinks, if you want to learn about what they do, check out the esolang page since we don't use them here. This statement is required.

    Soon the following sounds become audible.
    

    Required line, does nothing.

    oh yeah yeah yeah
    hrg
        fap yeah yeah yeah fap yeah fap yeah yeah
    mmf
    
    yeah yeah yeah
    

    read in a 0 or 1, then loop until $D is zero while incrementing $A and $B. This leaves us with $A containing ASCII value 0 or 1, depending on what was inputted and $B containing 208. Then move REGPTR back to A

    hrg
        yeah
        hrg
           fap yeah yeah yeah yeah fap yeah fap yeah
        mmf
        yeah yeah yeah yeah yeah
    
        yes
    

    In the inner loop, move REGPTR to $B (which has the value 208) and loop until it is zero while incrementing $A and $F. This leaves us with $A containing 48 or 49 (the ASCII codes for 0 or 1) and F containing 48. Then print $A, which will output a 0 or 1 depending on which one was inputted.

        yeah yeah yeah yeah yeah
        hrg
            fap yeah fap yeah fap yeah yeah yeah yeah
        mmf
        yeah
    mmf
    

    Now we move REGPTR to $F and loop until that is zero while incrementing $A and $B. This leaves us with $A containing the ASCII value 0 or 1 and $B containing 208, just like it had at the start of the loop. The loop then exits if $A == 0 or loops infinitely if $A == 1.

    This is my first codegolf answer so excuse any mistakes I made pls.

    Yhprum

    Posted 2015-11-03T16:40:48.353

    Reputation: 51

    4

    PowerShell, 24 Bytes

    param($a)do{$a}while($a)
    

    Gets variable $a, then uses the do-while loop functionality to output $a at least once, but continuing the loop if $a is truthy (i.e., 1).


    Alternatively, using traditional while looping, also 24 bytes

    param($a)while($a){$a}$a
    

    In this instance, if $a is falsey, the while loop will never be executed and just the value of $a will be printed in the end statement. If $a is truthy, the program will enter the while loop and continuously print the value of $a.

    AdmBorkBork

    Posted 2015-11-03T16:40:48.353

    Reputation: 41 581

    4

    Japt, 4 bytes

    ÿ ©ß
    

    As of 25 Oct 2016, I have implemented the recursion feature ß, which calls the entire program as a function. This is used here like so:

          // Implicit: U = input integer
    ÿ     // Since there's no value to work on, use U here. Alert U and return it.
      ©   // If U is truthy (1),
       ß  //   run the program again with the same inputs.
    

    Test it online!

    ETHproductions

    Posted 2015-11-03T16:40:48.353

    Reputation: 47 880

    1Yay! We should hold competitions between Japt, , and Teascript to see which is the most effective JS-based lang. – Mama Fun Roll – 2015-11-04T03:10:26.170

    @ןnɟuɐɯɹɐןoɯ That sounds great! But let's have at least another week to develop the langs; I've only worked on the Japt interpreter for ~8 hours and gotten ~2/3 of the features (all the easy ones) done. :-) – ETHproductions – 2015-11-04T03:13:30.483

    Sure! I could probably implement some improvements, too. – Mama Fun Roll – 2015-11-04T03:52:00.800

    Just curious, is there a shorter way to do this in newer Japt versions? – FlipTack – 2016-12-22T13:24:38.697

    @Flp.Tkc I've recently implemented the ÿ command, which alerts the value of an object and returns it, so I think Uÿ ©ßU should also work. I'll have to test it though. – ETHproductions – 2016-12-22T13:57:34.953

    1@Flp.Tkc Actually, it can be Uÿ ©ß because ß implicitly uses the inputs as arguments. Thanks ;-) – ETHproductions – 2016-12-22T14:05:00.750

    4

    Befunge-98, 16 bytes

    &>:;#,1';#<_'0,@
    

    Tested in pyfunge and BeQunge.

    Simpler two-line version

    &>:! |
    @^,1']'0,
    

    I like the previous one more, but this is what I came up with first.

    PurkkaKoodari

    Posted 2015-11-03T16:40:48.353

    Reputation: 16 699

    I'm not 100% sure on my Befunge skills, but &:.jq>:.< appears to work, and is 9 bytes. – Mego – 2015-11-03T19:07:10.320

    @Mego Damn. :-P – PurkkaKoodari – 2015-11-03T19:08:13.670

    Whoops, looks like I missed a char. &::.jq>:.< for 10. – Mego – 2015-11-03T19:11:38.760

    As @ThomasKwa pointed out in chat, &::.jq# works and is 7. – Mego – 2015-11-06T19:04:42.450

    @Mego I'm not going to steal that. I'll let the inventor(s) post it. – PurkkaKoodari – 2015-11-06T19:08:07.867

    It's been posted.

    – lirtosiast – 2015-11-08T04:47:44.497

    4

    Retina, 9 7 bytes

    /1/+>G`
    

    Try it online!

    Explanation

    The stage G` itself is really a no-op (it's a Grep stage with an empty regex, which always matches). So it's all in the configuration. > prints the result of this stage (which is just the input) and /1/+ wraps it in a loop which runs as long as the string contains a 1. There's also implicit output at the end of the program. So we go through these two possibilities:

    • If the input is 0, the /1/ condition fails, so the loop is never run. Instead, the program terminates, and the 0 is printed at the end.
    • If the input is 1, the /1/ condition matches, so the loop gets executed. The loop iteration itself does nothing but print that 1, so the string's value won't change and the loop will continue indefinitely.

    Martin Ender

    Posted 2015-11-03T16:40:48.353

    Reputation: 184 808

    4

    HP48's RPL, 22.5 bytes

    « WHILE DUP REPEAT DUP END »
    

    Since there is no such thing as STDIN or STDOUT on the HP48, the input is taken on the stack, and one "0" or an infinity of "1"s are pushed back on the stack.

    If you try it, you will have to kill the program in order to see the "1"s since the stack is not refreshed while the program is running (Just press the "ON" button).

    PS: The HP48's memory is made of 4 bits words, hence the non-integer bytes size

    LeFauve

    Posted 2015-11-03T16:40:48.353

    Reputation: 402

    4

    Prolog, 28 bytes

    a(X):-write(X),X=0,!;a(X).
    

    The cut ! is necessary to terminate the execution in the interpreter, otherwise it will wait to see if the user wants to get other answers.

    Fatalize

    Posted 2015-11-03T16:40:48.353

    Reputation: 32 976

    2No need for the extra parentheses! Saves 2 bytes. – mat – 2016-01-04T13:41:14.927

    1@mat true. Not sure what I was thinking! – Fatalize – 2016-01-04T13:41:56.027

    3

    Taxi, 617 bytes

    Go to Post Office:w 1 l 1 r 1 l.Pickup a passenger going to Crime Lab.1 is waiting at Writer's Depot.Go to Writer's Depot:s 1 r 1 l 2 l.Pickup a passenger going to Crime Lab.Go to Crime Lab:n 1 r 2 r 2 l.Switch to plan "z" if no one is waiting.Pickup a passenger going to Cyclone.Go to Cyclone:n 4 l 2 l.[r]Pickup a passenger going to Cyclone.Pickup a passenger going to Post Office.Go to Post Office:s 1 l 2 r 1 l.Go to Zoom Zoom:s 1 r 1 l 2 r.Go to Cyclone:w.Switch to plan "r".[z]0 is waiting at Writer's Depot.Go to Writer's Depot:n 4 l 2 l.Pickup a passenger going to Post Office.Go to Post Office:n 1 r 2 r 1 l.
    

    Try it online!

    There are shorter programs but they kept running out of gas. Here's the ungolfed version:

    Go to Post Office: west 1st left 1st right 1st left.
    Pickup a passenger going to Crime Lab.
    1 is waiting at Writer's Depot.
    Go to Writer's Depot: south 1st right 1st left 2nd left.
    Pickup a passenger going to Crime Lab.
    Go to Crime Lab: north 1st right 2nd right 2nd left.
    Switch to plan "z" if no one is waiting.
    Pickup a passenger going to Cyclone.
    Go to Cyclone: north 4th left 2nd left.
    [r]
    Pickup a passenger going to Cyclone.
    Pickup a passenger going to Post Office.
    Go to Post Office: south 1st left 2nd right 1st left.
    Go to Zoom Zoom: south 1st right 1st left 2nd right.
    Go to Cyclone: west.
    Switch to plan "r".
    [z]
    0 is waiting at Writer's Depot.
    Go to Writer's Depot: north 4th left 2nd left.
    Pickup a passenger going to Post Office.
    Go to Post Office: north 1st right 2nd right 1st left.
    

    Engineer Toast

    Posted 2015-11-03T16:40:48.353

    Reputation: 5 769

    3

    Duck Duck Goose, 911 bytes

    duck duck duck goose
    
    duck
    
    duck duck duck duck duck duck goose
    
    duck
    
    duck duck duck duck duck duck
    
    duck duck duck duck duck duck duck duck duck duck duck goose
    
    duck
    
    duck duck duck duck duck duck duck duck
    
    duck duck duck duck duck duck duck duck duck duck duck goose
    
    duck duck
    
    duck duck duck
    
    duck duck duck duck goose
    
    duck duck duck
    
    duck duck
    
    duck duck duck goose
    
    duck
    
    
    
    duck duck duck duck duck duck duck duck duck goose
    
    duck duck
    
    duck
    
    duck duck duck duck duck duck duck duck duck duck duck goose
    
    duck duck duck
    
    duck duck
    
    duck duck duck goose
    
    duck
    
    duck
    
    duck duck duck duck duck duck duck duck duck goose
    
    
    
    duck
    
    duck duck duck duck duck duck duck duck duck duck goose
    
    duck
    
    duck duck duck
    
    duck duck goose
    
    duck duck duck
    
    duck
    
    duck duck goose
    
    duck
    
    duck goose
    
    
    
    duck duck duck duck duck duck duck duck duck duck goose
    
    duck
    
    duck duck
    
    duck duck goose
    
    duck duck duck
    
    duck goose
    
    
    

    Includes 2 trailing newlines. I can't remove the newlines, they are instructions.

    ABot

    Posted 2015-11-03T16:40:48.353

    Reputation: 203

    3

    Dreaderef, 11 bytes

    5*1 1 5?8-1
    

    Takes input from the command-line arguments. Try it online!

    Explanation

    This program consists of eight numbers. These numbers are grouped into instructions; each instruction consists of a label, which is the first number, and zero or more arguments, which follow the label. Instructions with different labels can have different numbers of arguments, but the parsing of instructions happens at execution time (which allows self-modification). The numbers in the program are written to the tape from position 0 at the beginning of the program; each label and argument occupies its own cell, and the instruction pointer occupies the cell at location -1.

    5 *
    1 1  5
    ? 8 -1
    

    Dreaderef's preprocessor allows you to write aliases that stand in for numbers representing instruction labels. Using aliases makes the program look like this:

    0.   numo  *
    2.   deref 1  5
    5.   ?     8 -1
    

    (The leading numbers are position labels and are treated as comments.) Before the program executes, * is replaced with the input integer.

    0.   numo  *
    

    The first instruction is numo, which outputs its argument (either 0 or 1) in decimal without a trailing newline.

    2.   deref 1  5
    

    deref reads the tape at the position indicated by its first argument. It then writes that value to the tape at the position indicated by its second argument. This means that here deref copies cell 1 (the input integer and argument to numo) to cell 5 (part of the next instruction).

    5.   ?     8 -1
    

    This instruction is interesting in that the label is dynamically generated by the previous instruction (? is an alias for 0 in Dreaderef, but it is intended to convey that a given cell is uninitialized and will not be read until it is written to). During execution, it will be set to either 1 or 0 depending on the input integer. Proceeding from here requires some knowledge about what labels map to what instructions:

    • The instruction with label 0 is end, which terminates execution.
    • The instruction with label 1 is deref.

    If the input integer was 0, the end instruction causes the program to terminate, and the other two numbers are ignored.

    If the input integer was 1, the instruction looks like this:

    5.   deref 8 -1
    

    Cell 8 is past the end of the program, meaning that its value defaults to 0. The 0 is copied into cell -1, which is Dreaderef's instruction pointer. This means that execution jumps back to position 0, which is the start of the program. Because * is read before execution of the program, the same input (1) is reused, and the program outputs and loops again.

    Esolanging Fruit

    Posted 2015-11-03T16:40:48.353

    Reputation: 13 542

    3

    Deoxyribose, 18 bytes

    Updated for the new v3 spec

    ATGGAGAAGAGCATAAAT
    

    Explanation:

    ATG                         ATA (*)
    GAG Glu     Dupe            TGG Trp     Power
    AAG Lys     Pop             AGA Arg     Unipop
    AGC Ser     Jump if <= 0    AGA Arg     Unipop
    ATA *                       GCA Ala     Modulo
    AAT Asn     Loop            TAA End
    
    • Execution starts at the initial ATG.
    • The top element of the main stack is duplicated & printed, then If the value is less than or equal to zero, jump to the ATA formed by the Asn and the start codon (remember, the code is circular), then run through a series of no-ops, including printing some non-printable characters. If the value is greater than 0, loop back to the start.

    If you don't like the ugly sequence of no-ops, adding ATG to the end to make the loop target explicit results in a clean termination immediately after the jump, for three more bytes.


    Deoxyribose 2, 21 bytes

    ATGTGAGAAAAATCTAACTTA
    

    Explanation:

    ATG Start                           TAA Stop ┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┐
    TGA Block size = 56               ┏ TGT Cys     Destination of Asn ┆
    GAA Glu     Duplicate             ┃ GAG Glu     Duplicate          ┆
    AAA Lys     Pop as int            ┃ AAA Lys     Pop as int         ┆
    TCT Ser     If >= 0, jump to Thr ┐┞ AAT Asn     Jump back to Cys   ┆
    AAC Asn     Jump back to Cys ────┼┘                                ┆
    TTA                              └─ ACT Thr     Destination of Ser ┆
                                         └┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┘
    

    This is the first challenge on this site ever answered in this language (since it's only a week old), but I think it's a good showcase of what the language can do so I'll provide a bit of an explanation of what's going on. If you happen to be really interested, the spec, a Python-based interpreter, and additional (less golfed) examples are on GitHub.

    Deoxyribose is a stack-based language with a small instruction set and a syntax based on DNA. Execution takes place on a circular stretch of DNA, translating 3-digit "codons" into proteins, each of which corresponds to either

    • an operation on one or both of the stacks, or
    • a (perhaps conditional) jump to a particular sequence elsewhere in the code.

    These jumps can lead to frameshifts, where the read head is moved a non-integer number of codons and the same bit of code ends up doing two totally different things at different times. The degenerate nature of the genetic code makes it possible (and fun!) to use this to your advantage.

    georgewatson

    Posted 2015-11-03T16:40:48.353

    Reputation: 291

    I love this language concept! – histocrat – 2018-05-02T21:45:30.787

    3

    Rockstar, 34 Bytes

    Rockstar is a quite new computer programming language, designed for creating programs that are also song lyrics. Rockstar is heavily influenced by the lyrical conventions of 1980s hard rock and power ballads.

    Listen to your heart
    Say your heart
    While your heart is not empty
    Scream it
    

    But yes, you are right, it's longer than 34 bytes, but so poetic, I couldn't resist get some lyrics in. You could even sing it!. Here's the golfed version:

    Listen to X
    Say X
    While X
    Say X
    

    gaborsch

    Posted 2015-11-03T16:40:48.353

    Reputation: 249

    Which interpreter are you using? Wouldn't the input be treated as a string, which is truthy? Also, would the Until X loop until X is truthy, rather than while X is truthy? – Jo King – 2019-04-30T06:50:15.113

    @JoKing You are right, the golfed version was incorrect, I changed the Until loop to the While loop. (it did not change the code length). To answer your question, I use my interpreter: https://github.com/gaborsch/rocky - that worked the expected way, too, so it was my mistake, not the interpreter's.

    – gaborsch – 2019-04-30T07:01:03.070

    The input is numeric in this case, so 0 is coerced to false. – gaborsch – 2019-04-30T07:03:12.343

    3

    Malbolge, 257 bytes

    (aONMLKJIHGFEDCBA@?>=<;:98765FD21dd!-,O*)y'&v5#"!DC|Qzf,*vutsrqpF!Clk|ih
    gfed9(T&6KoOHZYXWVUTSRQPONM]KJIHGFEDCBA@?>=<;:9876"'~g|edybav_zyxwvotsrq
    pSnPlOjibKfedcba`_XA??ZYRW:UTSLQ3ONMLK.IHGFE>CBA@?"=<;:38765432s0/.n,+*)
    j!&%f{"!~}|_zyxZvYnsrqpRnmlkjML:f_^GF!
    

    Try it online!

    From esolangs.org

    Quite the abomination, isn't it?

    In fact, this language is so horrible, I don't think anyone "programmed" this in the traditional sense. If I'm remembering correctly, this was found by a search program that basically brute-forced for possible Malbolge programs that worked as a truth machine.

    ThePlasmaRailgun

    Posted 2015-11-03T16:40:48.353

    Reputation: 383

    4

    The program was made by esolang's Malbolge expert Malbranche, who is amazing and certainly can program it in other ways than brute force. You may be thinking of the first Malbolge "Hello, world!", which was indeed found by search.

    – Ørjan Johansen – 2019-05-22T04:07:32.990

    Ah, yes. Thank you for the correction, it does make sense that a Hello World program would be much longer and more difficult. – ThePlasmaRailgun – 2019-09-27T20:21:32.757

    3

    CJam, 8 bytes

    q~{_o}h;
    

    There's no point in linking to the online interpreter, because that one doesn't like infinite loops.

    This one works as well, printing newlines:

    q~{_p}h;
    

    Explanation

    q~   e# Read and evaluate input.
    {    e# While the top of the stack is truthy (i.e. 1.).
      _o e# Print a copy of the value on the stack.
    }h
    ;    e# We only get here if the value was 0. If so, discard the other 0 on the stack.
    

    Martin Ender

    Posted 2015-11-03T16:40:48.353

    Reputation: 184 808

    3

    Haskell, 38 35 bytes

    main=interact x
    x"1"=cycle"1"
    x a=a
    

    The input must not be terminated by a newline. This works for me: echo -n 1 | ./truth-machine.

    Edit: thanks @Zgarb for 3 bytes.

    nimi

    Posted 2015-11-03T16:40:48.353

    Reputation: 34 639

    One-liner (also 35 byte): main=interact(\x->[1,read x..1]>>x)

    – Laikoni – 2018-02-28T11:55:16.523

    3

    AppleScript, 93 Bytes

    ...this verbosity astounds me.

    set a to(display dialog""default answer"")'s text returned
    repeat while a="1"
    log 1
    end
    log 0

    Addison Crump

    Posted 2015-11-03T16:40:48.353

    Reputation: 10 763

    3

    TI-BASIC, 8 bytes

    There are two programs that achieve 8 bytes:

    Repeat not(Ans
    Disp Ans
    End
    

    Repeat is TI-BASIC's do-until loop, so it doesn't check the condition the first time. The other way is recursion (name the program prgmT):

    Disp Ans
    If Ans
    prgmT
    

    Both take input from Ans; call using 0:prgmT or 1:prgmT.

    lirtosiast

    Posted 2015-11-03T16:40:48.353

    Reputation: 20 331

    TIL the TI-84 doesn't have tail-call optimization for recursive programs. :( – Jakob – 2018-05-25T21:30:40.953

    3

    Minkolang, 7 bytes

    nd$,N?.
    

    Try it here. (DON'T click Run!)

    Explanation

    n     Take integer from input
    d     Duplicate
    $,    0 if 0, 1 otherwise
    N     Output as integer
    ?.    Halt if 0, continue otherwise
    

    This works because n pushes -1 if the input is empty...which is truthy! Also, Minkolang is toroidal so when the program counter moves off the right edge, it wraps around to the left edge and continues.

    El'endia Starman

    Posted 2015-11-03T16:40:48.353

    Reputation: 14 504

    3

    TeaScript, 21 16 bytes

    TeaScript is JavaScript for golfing, created by user Vɪʜᴀɴ.

    for(;alert×|x;);
    

    The input is automatically stored in variable x. × (U+00D7 Multiplication Sign) is a shortcut for (x).

    Try it in the online interpreter

    ETHproductions

    Posted 2015-11-03T16:40:48.353

    Reputation: 47 880

    See this line for an explanation of the bug behavior.

    – Mama Fun Roll – 2015-11-04T00:27:46.067

    @ןnɟuɐɯɹɐןoɯ Ah, yes. That explains why whil(x) did the same thing, but not whi(x). Thanks! – ETHproductions – 2015-11-04T01:22:58.243

    3

    Jasmin, 355 321 bytes

    As with the other answers I've written in Jasmin, there isn't a whole lot of golf going on here. This code is (almost) exactly the code obtained from running javap on the class file generated by intrepidcoder's java submission. The one neat golfing trick I found was avoiding the usual .limit locals line by reusing local variable 0.

    Some code golf four years later

    1. Shorten the invocation of print by extending PrintStream
    2. ldc 2 is shorter than iconst_2
    3. Manipulating the stack with dup and swap is shorter than using locals variables with iload_0 and istore_0.

    After these changes, the compiled class file needs to be executed with java -noverify.


    .class L
    .super java/io/PrintStream
    .method public static main([Ljava/lang/String;)V
    .limit stack 4
    getstatic java/lang/System/out Ljava/io/PrintStream;
    getstatic java/lang/System/in Ljava/io/InputStream;
    invokevirtual java/io/InputStream/read()I
    ldc 2
    irem
    dup2
    invokevirtual L/print(I)V
    dup
    ifgt $-5
    return
    .end method
    

    ankh-morpork

    Posted 2015-11-03T16:40:48.353

    Reputation: 1 350

    Would it be any shorter to put the code in an initializer block and not have a main method? – feersum – 2015-11-03T22:44:28.250

    1@feersum I've never been able to get static blocks to work using java version "1.8.0_60". I think static block are only accepted by java in version 1.6 and earlier. I don't have the correct version to test it so, I'll leave my answer as is for now. – ankh-morpork – 2015-11-03T23:03:41.843

    +1 for golfing this 4 years later – EdgyNerd – 2019-08-27T06:21:00.293

    3

    , 6 chars / 11 bytes

    ↻ôï|ï;
    

    Try it here (Firefox only).

    Mama Fun Roll

    Posted 2015-11-03T16:40:48.353

    Reputation: 7 234

    2Is the language name supposed to be "ESMin", or just five boxes? – mbomb007 – 2015-11-04T17:01:03.323

    1ESMin in double-struck. It doesn't show up properly in some fonts, though... :( – Mama Fun Roll – 2015-11-04T17:53:12.020

    1

    Ah, okay. I can only see the double-struck letters ℂ, ℍ, ℕ, ℙ, ℚ, ℝ, and ℤ.

    – mbomb007 – 2015-11-04T22:03:35.527

    3

    Mathematica, 36 33 bytes

    For[Print[i=Input[]],i>0,Print@i]
    

    LegionMammal978

    Posted 2015-11-03T16:40:48.353

    Reputation: 15 731

    3

    Mouse, 16 bytes

    ?0=[0!$](1^1!)$
    

    Ungolfed:

    ? 0 = [           ~ Read a number from STDIN and test it for equality with 0
      0 ! $           ~ If equal, print 0 and exit
    ]
    ( 1 ^             ~ While true,
      1 !             ~ Print 1
    )$                ~ End of program
    

    Alex A.

    Posted 2015-11-03T16:40:48.353

    Reputation: 23 761

    3

    Haystack, 15 12 bytes

    0io=v
      ^1?|
    

    Still working on a oneliner (if it's possible).

    sweerpotato

    Posted 2015-11-03T16:40:48.353

    Reputation: 2 457

    3

    C, 35 chars

    main(c){for(gets(&c);c%puts(&c););}
    

    This is even hackier than cbojar's solution, from which I copied the abuse of the parameter c (int used as char[4]), along with the reliance on little-endian.

    puts returns a non-negatve number on success, which (on my Linux/gcc4.8.2) happens to be the number of bytes printed, which happens to be 2. c%2 tests if c is odd, which is true for '1' and false for '0'.

    ugoren

    Posted 2015-11-03T16:40:48.353

    Reputation: 16 527

    3

    O, 14 bytes

    i{1{1o1}w}{0o}?
    

    O is a work-in-progress language with loads of commands and an interpreter written in "APL-style C", which means incomprehensible code.

    i Get input as String

    { Start a CodeBlock (like ruby)

    1 Push 1 to the stack

    { Start a CodeBlock

    1 Push 1 to the stack

    o Pop the stack and print it

    1 Push 1 to the stack

    } Push the CodeBlock to the stack

    w Do the CodeBlock on the top of the stack while the value under it is true. (Pops them both.)

    } Push the CodeBlock to the stack

    { Start a CodeBlock

    0 Push 0 to the stack

    o Pop the stack and print it

    } Push the CodeBlock to the stack

    ? If the 3rd down value in the stack is truthy, do the CodeBlock 2nd down in the stack, otherwise do the CodeBlock on the top. (Pops the first 3 values on the stack.)

    Hipe99

    Posted 2015-11-03T16:40:48.353

    Reputation: 87

    "APL-style C" - you mean nightmares? – Mego – 2015-11-15T05:07:05.893

    @Mego yep, pretty much

    – Hipe99 – 2015-11-15T05:14:48.340

    I think you're being unfair to APL. – lirtosiast – 2015-11-16T01:20:19.523

    @ThomasKwa it's a direct quote.

    – Hipe99 – 2015-11-16T19:41:45.467

    @Hipe that is horrible. must it be golfed? – cat – 2016-07-22T11:18:31.060

    3

    Squirrel, 48 bytes

    local a=stdin.readn('b')-48;do print(a) while(a)
    

    Laff-O-Tron

    Posted 2015-11-03T16:40:48.353

    Reputation: 31

    3

    Quipu, 20 bytes

    \/1&
    /\/\
    1&??
    >>
    ::
    

    alephalpha

    Posted 2015-11-03T16:40:48.353

    Reputation: 23 988

    3

    O, 12 11 6 bytes

    j{.o}w

    When 0 is inputted, 0 is outputted and the program ends. When 1 is inputted, 1 is outputted forever.

    Explanation:

    j     Get input as Number
    {  }w While the input is 1
     .o    Print the 1
          Print the stack when code ends, which will only contain 0
    

    phase

    Posted 2015-11-03T16:40:48.353

    Reputation: 2 540

    3

    Binary-Encoded Golfical, 11+1 (-x flag)= 12 bytes

    Hexdump of binary encoding:

    00 40 02 15 14 1B 1A 17 14 24 1D
    

    Original image:

    enter image description here

    Magnified 125x, with color labels:

    enter image description here

    Rough translation:

    *p=readnum
    lbl A
    print *p
    if *p!=0 goto A
    

    SuperJedi224

    Posted 2015-11-03T16:40:48.353

    Reputation: 11 342

    3

    Turing Machine Code, 19 bytes

    0 0 * * 1
    0 * 1 r 0
    

    Halts on 0 because there is no state 1.

    KoreanwGlasses

    Posted 2015-11-03T16:40:48.353

    Reputation: 888

    3

    05AB1E, 5 bytes

    Code:

    Di[D?
    

    Explanation:

    D      # Duplicate input
     i     # If True (or 1), do
      [    # Infinite loop
       D   # Duplicate top of the stack
        ?  # Pop a, print a with no newline
    

    Adnan

    Posted 2015-11-03T16:40:48.353

    Reputation: 41 965

    Based on the date this was posted I assume implicit input wasn't a thing yet back then, but both D can be removed now to save 2 bytes. – Kevin Cruijssen – 2019-01-22T16:26:11.193

    3

    Batch, 35 bytes

    @IF %1==0 (exit)
    :l
    @echo 1&goto l
    

    Please, anyone who can golf this more is more than welcome to.

    sudoBash

    Posted 2015-11-03T16:40:48.353

    Reputation: 41

    3

    Java, 87 bytes

    interface A{static void main(String[]a){System.out.print(a[0]);main(a[0].split("0"));}}
    

    (has output to STDERR, but that should not matter)

    senegrom

    Posted 2015-11-03T16:40:48.353

    Reputation: 423

    I'm not entirely sure if this is valid. The rules state that the program must infinitely run unless killed or out of memory. This will cause a stack overflow, since Java doesn't have tail call recursion optimization. – Mego – 2016-01-25T13:31:30.770

    Yes, for the standard JVM; but there the size of the stack depends on the memory allocated. If the memory allocated by -Xss is large enough, it will run arbitrarily long (see also https://stackoverflow.com/questions/4734108/what-is-the-maximum-depth-of-the-java-call-stack). The stack overflow therefore is just the visible result of the program being out of memory.

    – senegrom – 2016-01-25T13:36:30.767

    Fair enough, I didn't consider -Xss. Upvoted, and welcome to PPCG! – Mego – 2016-01-25T13:37:30.457

    Thanks. I'm not sure, but might there exist even some other JavaVMs that handle this more efficiently? – senegrom – 2016-01-25T13:39:50.087

    I'm not aware of any JVM implementations that do tail call recursion optimization. I know Oracle HotSpot doesn't, and I doubt Excelsior does. – Mego – 2016-01-25T13:52:53.333

    Program arguments are not STDIN! – Shaun Wild – 2016-09-01T09:17:41.527

    1

    @SeanBean "take input from STDIN or an acceptable alternative" - command-line arguments are an acceptable input method.

    – Mego – 2016-09-01T09:27:03.043

    The boring thing about challenges like this is there is really only one good answer per language. You can't get shorter than this which is really boring... I downvoted – Shaun Wild – 2016-09-01T10:56:57.570

    1maybe downvote the challenge if you don't like it, instead of this particular Java answer? Not that I mind but you could reach a larger audience there... downvoting because you believe an answer is the shortest kind of defeats the purpose of codegolf?? – senegrom – 2016-09-07T18:28:14.290

    A stack overflow is a form of memory outage: there is no more place in the stack memory for another stack frame. – Olivier Grégoire – 2019-01-10T09:55:18.380

    3

    HALT, 49 bytes

    1 IF '0' 2 ELSE 3
    2 TYPE '0';HALT
    3 TYPE '1';SET 1
    

    Pretty simple. If input is one go to 3, output 1, set the pointer to 1 so the program never ends. If input is output 0, print, then halt.

    Online interpreter (Firefox only)

    Chathuahua

    Posted 2015-11-03T16:40:48.353

    Reputation: 31

    such amazing much wow where's rightgoat – Seadrus – 2016-02-23T03:12:24.133

    1@Seadrus ---I ate him---. I mean, he'll be coming soon – Chathuahua – 2016-02-23T03:12:56.007

    No he won't, you're the only goat left ;) – J Atkin – 2016-02-24T03:12:09.680

    3

    Whenever, 72 bytes

    From the webpage:

    Introduction

    Whenever is a programming language which has no sense of urgency. It does things whenever it feels like it, not in any sequence specified by the programmer.

    Design Principles

    • Program code lines will always be executed, eventually (unless we decide we don't want them to be), but the order in which they are executed need not bear any resemblance to the order in which they are specified.
    • Variables? We don't even have flow control, we don't need no steenking variables!
    • Data structures? You have got to be kidding.

    The official java interpreter doesn't seem to handle read() but the spec says it should work so.

    1 -2,2#read();
    2 defer(1) again(2) print("1");
    3 defer(1||2) print("0");
    

    The program works like this:

    • Initially 1, 2 and 3 are on the list but 2 and 3 must wait until 1 is gone.
    • When 1 is executed it removes 2 and then adds 2 back stdin times. Therefore:
      • 2 is only on the list if stdin was 1.
      • 3 must wait until 2 is gone so it can only execute if stdin was 0.
    • If 2 is executed it will add itself to the list again and print '1'.
    • If 3 is executed (meaning 2 is not on the list) it will print '0'.
    • At this point we will be in one of two states:
      • 2 will be on the list printing '1' and 3 will be perpetually waiting
      • 1, 2 and 3 will all be gone and the program will end.

    Jerry Jeremiah

    Posted 2015-11-03T16:40:48.353

    Reputation: 1 217

    3

    R, 16 28 25 bytes

    x=scan();while(x)cat(1);0
    

    Edited to read x

    Masclins

    Posted 2015-11-03T16:40:48.353

    Reputation: 914

    this isn't valid, because the 0 will be printed out with an additional [1] preceding it, and the post states that the output must only be either a 0 followed by either one or no newline or space, or infinite 1s with each 1 followed by either one or no newline or space. – Giuseppe – 2018-03-03T15:24:02.167

    3

    Gaot++, 125 bytes

    bleeeeeeeeeeet
    bleeeet bleeeeeet
    bleeeeeeeeeeeeet
    bleeeeeeeeeeeeet
    bleeeeeeeeeeeeet
    bleeeeeeeeeeeeet
    bleeeeeeeeet
    bleeeeeeeet
    

    Compressed: 11e4e6e13e13e13e13e9e8e6e

    Try it online!

    Leaky Nun

    Posted 2015-11-03T16:40:48.353

    Reputation: 45 011

    3

    Shakespeare Programming Language, 189 bytes

    .
    Ajax,.
    Ford,.
    Act I:.
    Scene I:.
    [Enter Ajax and Ford]
    Ford:
    Listen to thy heart.
    Scene II:.
    Ford:
    Open thy heart.Is cat as big as you?If so, let us return to scene II.
    [Exeunt]
    

    Ungolfed:

    The Construction of a Truth-Machine in Denmark.
    
    Hamlet, the input.
    Ophelia, who orders him around.
    
    Act I: A truth-machine.
    
    Scene I: In which Hamlet learns that all he needs, he can find in his heart.
    
    [Enter Hamlet and Ophelia]
    
    Ophelia:
      Listen to thy heart.
    
    Scene II: In which Ophelia proclaims her doubts about Hamlet.
    
    Ophelia:
      Open thy heart. Is my lover as fair as thee?
      If so, let us return to scene II.
    
    [Exeunt]
    

    I'm using drsam94's SPL compiler + GCC to compile this.

    To test:

    $ python splc.py tm.spl > tm.c
    $ gcc tm.c -o tm.exe
    $ echo 0 | ./tm
    0
    $ echo 1 | ./tm
    1111111111111111111111111111111111111111111111...
    

    Copper

    Posted 2015-11-03T16:40:48.353

    Reputation: 3 684

    Do you have the link for the Python implementation of SPL? looking to work on a JavaScript fork of it... – WallyWest – 2016-08-30T23:03:15.323

    @WallyWest Here it is!

    – Copper – 2016-08-30T23:07:23.257

    3

    Churro, 100 95 bytes

    {========={o}{*}======}{*}======}{={*}{={o}{={o}{={*}{={o}{======={*}{==={*}{======={*}{===={*}
    

    Explanation

    Churro is a stack-based esolang where the only syntax element is, well, churros! Or rather, ASCII-art representations of churros. An example of such a churro is {o}====}.

    In Churro, each churro has three characteristics:

    1. Its orientation; whether it's facing left ({o}====}) or right ({===={o}).
    2. Its filling; whether it's filled ({*}==}) or not ({o}==}).
    3. Its tail length; the number of =s in the churro is the length of its tail.

    Left-facing churros are integer literals; their tail length is their value, while their filling status is their sign. Filled churros are negative, while unfilled churros are positive.

    Right-facing churros are operators; their tail length is which operator they represent, according to this table:

    {{o}           pop A; discard A
    {={o}          pop A, B; push B + A
    {=={o}         pop A, B; push B - A
    {==={o}        pop A; if A == 0, jump to churro after matching occurrence of {==={o}
    {===={o}       pop A; if A != 0, jump to churro after matching occurrence of {==={o}
    {====={o}      pop A, B; store B in memory location A
    {======{o}     pop A; push the value in memory location A to stack
    {======={o}    pop A; print A as an integer
    {========{o}   pop A; print A as an ASCII character
    {========={o}  read a single character from STDIN and push it to the stack
    {=========={o} exit the program
    

    Filled operator churros have the same behaviour, but peek at the stack instead of popping from it.

    With that, here's the ungolfed, explained version of the Churro truth-machine:

    {========={o}    read char from stdin
    {*}======}       push -6
    {*}======}       push -6
    {={*}            push -6 + -6 = -12
    {={o}            pop -6, -12; push -6 + -12 = -18
    {={o}            pop -6, -18; push -6 + -18 = -24
    {={*}            push input + -24
    {={o}            pop -24, input + -24; push input + -48 (convert char to int)
    {======={*}      print input as integer
    {==={*}          if input == 0 jump to matching churro
    {======={*}      print input as integer
    {===={*}         if input != 0 jump back to matching churro
    

    I'm using TheLastBanana's Haskell interpreter to interpret this. Installation instructions can be found there.

    Finally, here's the "pure" version (no comments, line length 80, spaces between churros), as output by purify truth.ch:

    {========={o} {*}======} {*}======} {={*} {={o} {={o} {={*} {={o} {======={*} 
    {==={*} {======={*} {===={*} 
    

    Saved 5 bytes thanks to Martin Ender!

    Copper

    Posted 2015-11-03T16:40:48.353

    Reputation: 3 684

    And now I want a dulce de leche and some doughnuts... – WallyWest – 2016-08-30T23:01:27.597

    3

    Moorhen 1 (or original creators version 1 here), 38 bytes

    The original language creator has decided to add new instructions, which would change the existing ones. Hence, this language is in Moorhen version one

    op pa id el pa id el ai op id ai pi ai
    

    Note this doesn't print if input is 1, because printing only happens at halting, so it just puts infinite ones on stack

    Explanation:

    Commands can be (most of) all english words, and the command they execute depends on md5 hash mod 7. I used some length two words that corresponded to each of the seven commands

    re: push 0

    op: increment ToS

    pa: decrement ToS

    el: rotate stack (place ToS on BoS)

    pi: dupe ToS

    id: peek TOS, skip if it is non-zero

    ai: flip pointer direction

    there are two main segments of code

    op pa id el pa id el 
    
    ai op id ai pi ai
    

    op pa id el pa id el
    

    This code, when run forwards, will have the pointer leave to the right side, with the initial value on the stack, minus one (0 -> -1, 1 -> 0). When run backwards, with [-1] as stack, it leaves the to the left side with [0] as the stack. When it leaves to the left, it will print the stack, items joined with spaces, so it will print 0. It uses "nops", commands that don't do anything under certain circumstances, or are a pair of inverses.

    (the reason the comments look funny is because the interpreter ignores non-words, including real words that are hyphenated)

    op pa                nop-when-running-forwards
          id el          nop-with-only-one-value-on-stack-and-running-forward
                pa       decrement-
                   id el nop-with-only-one-value-on-stack-and-running-forward
                         [go to next part of code]
    

    with all these nops forward, its essentially pa when running forward. However, backwards, with -1 on stack:

    el                   nop-with-only-one-value-on-stack
       id pa             skip-pa,when-TOS-nonzero(-1,is-non-zero)
             el          nop-with-only-one-value-on-stack
                id pa    skip-pa,when-TOS-nonzero(-1,is-non-zero)
                      op increment-
                     [end,print-stack(with,-1,coming-in,print-0)]
    

    With -1, backwards, it's essentially op (then implicit print)


    The code that is at the right of that code:

    ai op id ai pi ai
    

    given -1, it will just reflect it back. Given 0, it will increment it, then enter a loop of duping ToS, which will be 1.

    ai            reflect-pointer-direction-if-TOS-non-zero
       op         increment-
          id      skip-next-command-if-non-zero. This-command-skips-into-the-middle-of-a-loop:
    
            ai pi ai    this-is-the-loop. pointer-starts-on-pi,because-it-skipped-the-first-ai
    
               Here is a visualisation of how it executes
               pi       dupe-TOS (1)
                  ai    reverse-if-ToS-is-nonzero (it is)
               pi       dupe-TOS (1) -again
            ai          reverse-if-ToS-is-nonzero (it is)
               pi       dupe-TOS (1) -again
               ...      this keeps happening
    

    Destructible Lemon

    Posted 2015-11-03T16:40:48.353

    Reputation: 5 908

    3

    Zephyr, 41 bytes

    input n
    print n
    while"1"=n
    print n
    repeat
    

    Try it online!

    A main design goal of Zephyr was that code should be readable and understandable. Looks like this holds true even when the code is maximally golfed. Mission accomplished.

    DLosc

    Posted 2015-11-03T16:40:48.353

    Reputation: 21 213

    2

    Underload, 16 bytes

    ((1)S:^)~^:^(0)S
    

    Underload has no way to take input from standard input. The most natural way to take input is therefore from the initial stack: () for 1, (!()) for 0 (this is the normal way to represent numbers in Underload).

    Here are Try It Online links for 0 and for 1 (be prepared to kill this one quickly; the infinite loop runs very quickly and will spam up your browser window).

    This program didn't need much effort to golf; the most idiomatic way to do things is almost the shortest (I just had to be careful not to let the input get buried too far on the stack). It's easiest to read if I translate the code to a hypothetical functional language:

    function x(y)
        print(1)
        x(x)
    end
    x = x^(input)
    x(x)
    print(0)
    

    The only weird thing happening here is being able to exponentiate functions, but it's a fairly easy-to-understand operation; for example, raising a function f to the power 3 would produce f compose f compose f, i.e. lambda x.f(f(f(x))). Raising a function to the power 1 does nothing (just like if you'd raised an integer to the power 1); and raising a function to the power 0 gives you the identity function (just like raising a number to the power 0 gives you 1). Actually, the integers in Underload are defined in terms of their effect exponentiating functions, rather than the other way round; the operation is fundamental enough to Underload that you use it to construct most flow control.

    user62131

    Posted 2015-11-03T16:40:48.353

    Reputation:

    2

    Jelly, 3 bytes

    Ṅ¹¿
    

    If reading from STDIN is absolutely required:

    ƈOḂṄ¹¿`
    

    I'm not sure which since "Jelly's main input method is via command line arguments, although reading input from STDIN is also possible."

    JayDepp

    Posted 2015-11-03T16:40:48.353

    Reputation: 273

    Your second version can also be ƓṄ¹¿, where it reads a line instead of a single character.

    – Erik the Outgolfer – 2017-03-12T15:33:39.723

    2

    SmileBASIC, 23 22 bytes

    INPUT N@L?N?N/N
    GOTO@L
    

    Ends the program with a divide by 0 error.

    If this isn't allowed, here's a 23 byte solution:

    INPUT N@L?N
    IF N GOTO@L
    

    12Me21

    Posted 2015-11-03T16:40:48.353

    Reputation: 6 110

    2

    WireWorld (It doesnt have a scoring method yet :\)

     ████ █ <= this pixel will be the input. if it is a electron head (1), 
    █    █     It will loop forever as 1. if its a wire (0), it will do nothing.
    █ ██ █
     ██ █
      ██
    

    Matthew Roh

    Posted 2015-11-03T16:40:48.353

    Reputation: 5 043

    2

    BitCycle, 7 bytes

    Golfed 4 bytes off my example program!

    ?~<
    !~+
    

    Provide input as 0 or 1 on the command-line. The -s or -p debug options are recommended, especially when dealing with infinite output.

    Explanation

    BitCycle is a 2D language that works by moving bits around a playfield. Commands used in this program are:

    • ? puts input bit(s) onto the playfield, moving east
    • ~ duplicates and negates a bit, turning the original right and the negated copy left
    • < sends bits westward
    • + turns 1-bits right and 0-bits left
    • ! outputs bits

    The input hits the first ~. A negated copy turns left (north) off the playfield and is discarded. The original bit turns right (south).

    At the second ~, the original bit turns west into the ! and is output. A negated copy turns east.

    If the original bit was 0, the negated copy is 1; it turns south at the +, goes off the playfield, and is discarded.

    If the original bit was 1, the negated copy is 0; it turns north at the + and then west at the <. The 0 hits the first ~ again, where it turns right (north) off the playfield and is discarded. The negated copy (1) turns left (south), leading to an infinite loop.

    DLosc

    Posted 2015-11-03T16:40:48.353

    Reputation: 21 213

    Alternative 7 byter ?v~ newline !~+ – Jo King – 2019-03-26T09:38:50.730

    2

    Aceto, 11 10 bytes

    X
    p|1
    rip^
    

    reads a string and converts it to an integer. | tests for truthiness (1 is truthy, 0 is not) and mirrors horizontally if truthy (in that case moving to the 1). Otherwise, we'll go to 0, which pushes the 0, we print implicit zero and eXit.

    If the number was truthy (e.g. 1), we got mirrored to the 1, which pushes a 1, prints, and goes one cell up (^), going into an infinite loop.

    L3viathan

    Posted 2015-11-03T16:40:48.353

    Reputation: 3 151

    2

    MarioLANG, 11 bytes

    ;>:[<
    =====
    

    Explanation:

    ;        Get numerical input and save in current cell
     >       Move left (Required to make an infinite loop)
      :      Output the current cell
       [     Skip next command if cell is 0
        <    Move right
    

    Basically, it loops infinitely unless input = 0

    user69335

    Posted 2015-11-03T16:40:48.353

    Reputation:

    2

    Wise, 3 bytes

    [:]
    

    Try it online!

    Wise cannot actually output whenever you want, it only outputs the entire stack when the program terminates. So the solution to infinitely output is to simply infinitely fill the stack. When the program eventually halts (never), it will output the stack that, at that theoretical point in time, will have infinite values in it.

    Explanation

    [:]  Implicit input from command-line arg
    [    If last value is != 0..
     :   ..Duplicate last value on stack
      ]  If last value is != 0, jump back to [
    

    Given a non-zero number, will infinitely duplicate the input on the stack, after an infinite amount of time, will terminate and output the entire stack.

    Given zero, jumps to the end of the program and immediately terminates, outputting the stack, which contains only the input.

    Skidsdev

    Posted 2015-11-03T16:40:48.353

    Reputation: 9 656

    2

    Python 2, 50 39 bytes

    Don't know why nobody mentioned I could just write input()

    i=input()
    while(int(i)):print 1
    print 0
    

    Very simple, if the input is 1, will continuously print 1 and cannot reach the print 0. If it is 0, the while will never fire.

    Try it online!

    Stan Strum

    Posted 2015-11-03T16:40:48.353

    Reputation: 436

    You can save a few bytes by using stdin instead of command line args. – pppery – 2017-08-06T23:04:37.810

    29 bytes, you don't need to cast the input to an int because the input function in Python 2 does eval on the input before returning. You also don't need parentheses around the input call. – LyricLy – 2017-09-29T22:02:24.120

    Oh, actually... This code doesn't even work. Theoretically, it would work if infinite 1's were given as input, but that doesn't meet the spec. Since while is calling the input function every time, it will just print one 1 and then reach the end of the input and error. Your earlier solution with command line args did work, or you can assign the input to a variable before looping. – LyricLy – 2017-09-29T22:13:50.017

    @LyricLy yeah, I tried that once. Thanks! – Stan Strum – 2017-09-30T19:14:04.347

    2

    Befunge, 4 bytes

    &:.%
    

    Try it online!

    Please note: this answer is no longer valid with this particular interpreter. At the time of writing, the interpreter used had a quirk where trying to read more integers when there weren’t any would return the last integer. I believe that this was “fixed” in some interpreter update. (Thanks to @osuka_ for realizing that this answer no longer works)

    Explanation:

    &       Take number input
     :.     Duplicate and print input
       %    Mods the second from-the-top with the top number in the stack
            This means that if the top is 1, it will yield 0 % 1 = 0,
            But if it is a 0, it errors out and stops execution because you are
            trying to divide by 0
    
    &       The program wraps back around if it didn't error, and the & takes
            the last number in the input if it has already taken them all, yielding
            the original 1 or 0
    

    Coincidentally, this doesn't also work for /, because it strangely asks you what you want the answer to be.

    MildlyMilquetoast

    Posted 2015-11-03T16:40:48.353

    Reputation: 2 907

    1The modulo trick is really clever. I love it. – IQuick 143 – 2019-04-30T14:15:11.520

    1This doesn't work - it prints -1 instead of 1 after the first time. – osuka_ – 2019-08-26T18:56:06.547

    @osuka_ I think it’s due to the interpreter being updated, unfortunately. I remember it used to be that reading an end of feed with & would give the last integer again (which would make this print 1). I think they changed it so it gives -1 on an EOF instead. Thanks for letting me know – MildlyMilquetoast – 2019-08-26T19:19:16.547

    1@MildlyMilquetoast No worries - The reason I stumbled upon this is that I was looking for other befunge answers, to see if anyone had already posted one identical (or very similar) to one I just wrote. I love the mod trick! – osuka_ – 2019-08-26T19:30:49.477

    This can be fixed by adding two !s after the & – Jo King – 2019-08-27T03:48:26.533

    2

    Thotpatrol, 311 219 bytes

    Credit to @MickyT for shaving 92 bytes off

    JACKING IN
    DM THAUGHTY JO
      JO
      JO
    ❤PRIME ASSETS❤ JO INTERROGATE ©1©
      JO
    INTERCEPT MALIGNANT COMMUNICATIONS
    REPORT UNPATRIOTIC ACTIVITY
    

    This is a fairly uninteresting truth machine the core structure is as follows:

    input a
    print a
    while a == 1
        print a
    end while
    

    Here is a link to an implementation in Java: https://github.com/MindyGalveston/thotpatrol-

    Mr. Negi

    Posted 2015-11-03T16:40:48.353

    Reputation: 75

    4what in the world is this language? – Rɪᴋᴇʀ – 2017-09-04T21:06:58.687

    This language is a pet project of mine. Its core eccentricity is that there is a finite and non-accessible list of allowed variable names. The only way to programatically allocate data is by abusing string variables and using them as databases or trial and error automatic variable naming which does not have a hard upper complexity limit. Have fun, and I'd love to answer any questions! – Mr. Negi – 2017-09-04T21:16:23.413

    1How is this 318 bytes? It's 243 UTF-8 bytes, or 172 characters. – caird coinheringaahing – 2017-09-04T21:30:45.710

    I forgot to update the code when I updated the byte count and the logic, You're completely right I made a mistake. Should be fixed now. – Mr. Negi – 2017-09-04T21:31:48.533

    1Also is Jo or Bo acceptable variable names? – MickyT – 2017-09-04T21:43:14.913

    1This is what I was trying to say before about a slightly different structure – MickyT – 2017-09-04T23:58:13.547

    works perfectly! I updated the answer with your changes. – Mr. Negi – 2017-09-05T00:55:58.057

    2

    JavaScript, 26 bytes - Variation of Solomon Ucko's answer

    I find it weird how I can't comment, but I can edit his answer...

    for(;alert(i=prompt())|i;)
    

    Ephellon Dantzler

    Posted 2015-11-03T16:40:48.353

    Reputation: 103

    2

    Forked, 22 21 bytes

    -1 thanks to BMO

    v >%&
    $ |
    >-:
      |
     %<
    

    The IP path looks like this if the inputted integer is truthy:

    v
    |
    >-v
      |
     %<
    

    Upon hitting % (print as integer), it goes off the edge of the playing field and wraps around, running >% infinitely.

    It takes this path if the inputted integer is falsy:

    v >%&
    | |
    >-^
    

    It prints % 0 and then exits &.

    MD XF

    Posted 2015-11-03T16:40:48.353

    Reputation: 11 605

    2

    ORK, 395 bytes

    There is such a thing as a m.
    A m can p a word.
    
    When a m is to p a word:
    I have a scribe called W.
    W is to write the word.
    I have a linguist called C.
    C's first operand is the word.
    C's second operand is "1".
    C is to compare.
    If C says it's equal then I am to loop.
    
    When this program starts:
    I have a inputter called R.
    I have a word called N.
    R is to read N.
    I have a m called M.
    M is to p N.
    

    Try it online!


    Here's the ungolfed version, which is not a whole lot different:

    There is such a thing as a truth machine.
    A truth machine can process a word.
    
    When a truth machine is to process a word:
    There is a scribe called Keymaker.
    Keymaker is to write the word.
    There is a linguist called Chomsky.
    Chomsky's first operand is the word.
    Chomsky's second operand is "1".
    Chomsky is to compare.
    If Chomsky says it's equal then I am to loop.
    
    When this program starts:
    I have an inputter called Dave.
    I have a word called Input.
    Dave is to read Input.
    I have a truth machine called Hal.
    Hal is to process Input.
    

    The first paragraph defines a truth machine class with one member function, process, which takes a string (i.e. word).

    The second paragraph defines process: write the string out, and then compare it against "1". If it's equal, loop.

    The third paragraph defines our main function: read a string in, instantiate a truth machine, and have the machine process the string.

    Simple, really.

    DLosc

    Posted 2015-11-03T16:40:48.353

    Reputation: 21 213

    2

    Stax, 5 4 3 bytes

    Crossed out 4 is still 4 ;(

    wQc
    

    Try it at staxlang.xyz!

     w      Until popping results in a falsy value:
      Q       Peek and print with a newline.
       c      Copy the value atop the stack.
    

    I'm loving this new language.

    Thanks to @Weijun Zhou for reminding me of implicit input.

    Khuldraeseth na'Barya

    Posted 2015-11-03T16:40:48.353

    Reputation: 2 608

    I am glad to find another user of Stax writing impressive answers. Maybe you should check out the chat as well although there are not much to see at the moment.

    – Weijun Zhou – 2018-03-03T20:57:00.803

    You don't need the comma at the beginning. There is implicit input. – Weijun Zhou – 2018-03-03T21:03:57.087

    Also I suggest you use this link: https://staxlang.xyz/#c=wQc&i=0%0A1&a=1&m=2. It automatically runs your program.

    – Weijun Zhou – 2018-03-03T21:14:19.080

    @WeijunZhou Whoops, thanks! – Khuldraeseth na'Barya – 2018-03-03T21:14:21.317

    2

    Reflections, 26 bytes

      _:#_: _<
    /#_v     /
    \: /
    

    Test it!

    Explanation:

    The _ at position (2|0) reads a line from input, : doubles the first character. Then, # redefines zero and _ at (1|0) prints that character. : doubles the first character again, _ at (4|0) converts a digit to a number. < tests this number, if it's 0, the IP is directed upwards (out of the program). Else it's directed downwards, then left by the /, and down again by the v, left by the /. The : doubles the character again. Then, the \ reflects the IP upwards and the / right again, where # redefines zero and the _ at (1|0) prints the character. The v then directs it down into the loop again.

    wastl

    Posted 2015-11-03T16:40:48.353

    Reputation: 3 089

    2

    Python 2, 59 51 49 33 bytes

    i=input()
    while i:print 1
    print 0
    

    Explanation:

    input()             # take input from STDIN
    while i:print 1     # print 1 if the argument is anything other than 0... input() evaluates the string and returns a value
    print 0             # print 0 and exit if input() returns 0
    

    EDIT: Saved 8 bytes thanks to @EsolangingFruit

    EDIT 2: Coupla more bytes thanks to @HyperNeutrino

    EDIT 3: Saved 16 bytes thanks to @HyperNeurtrino

    Allen Fisher

    Posted 2015-11-03T16:40:48.353

    Reputation: 219

    1You don't need to have str(1), you can just do print"1", etc. – Esolanging Fruit – 2018-03-06T02:57:37.013

    remove the space between print and ' (this is Esolanging Fruit's suggestion but you added an extra space so credit them instead for 8 bytes) – HyperNeutrino – 2018-03-06T03:28:00.417

    also, don't take arguments, use input. k=input()>"0" and then while k:print 1 and then print 0 (note that you don't even need to do print"1", just do print 1 – HyperNeutrino – 2018-03-06T03:29:27.057

    @HyperNeutrino Thanks. Fixed the first thing... still looking at input() it's not doing what I expect it to. – Allen Fisher – 2018-03-06T04:42:04.220

    @HyperNeutrino This is Python 2, so input() returns an evaluated value instead of a string. This means that input() already returns the number. – Esolanging Fruit – 2018-03-06T05:06:17.763

    @EsolangingFruit Right. Ok so then you can just do k=input() and then while k:print 1 and then print 0 – HyperNeutrino – 2018-03-06T13:13:09.243

    2

    Pepe, 15 bytes

    REeErEErReEEree
    

    Try it online!

    Explanation:

    REeErEErReEEree  # Full program
    REeE             # Take input as number
        rEE          # Create label 0
           rReEE     # Output number -r (preserve)
                ree  # Goto label 0 if [input] != 0
    

    RedClover

    Posted 2015-11-03T16:40:48.353

    Reputation: 719

    2

    Flobnar, 10 bytes

    <1._
    |@&
    0
    

    Try it online!

    Esolanging Fruit

    Posted 2015-11-03T16:40:48.353

    Reputation: 13 542

    2

    VSL, 36 32 bytes

    fn main(){do{print(i)}while i>0}
    

    This is probably familiar to anyone who knows any C-esque language but this takes input using a global variable i.

    Try it online!

    Downgoat

    Posted 2015-11-03T16:40:48.353

    Reputation: 27 116

    2

    AlgiX with -x, 3 bytes

    [.]
    

    Explanation

    AlgiX takes each character of input (converts it to charcode if it's not a digit) and runs the entire code for each value, initializing the accumulator to that value each run.

    In this case, there's only 1 input, a 1 or a 0, so the code runs once.

    [.] - Implicit a = input
    [   - If a == 0, skip to ]
     .  - Print value of a
      ] - If a != 0, jump back to [
        - Implicit output value of a
    

    Normally, the implicit output after each run would output a as a character, however the -x flag overrides that and outputs its value instead.

    Skidsdev

    Posted 2015-11-03T16:40:48.353

    Reputation: 9 656

    2

    Rust compiler (nightly), 86 bytes

    #![feature(log_syntax)]macro_rules!t{(0)=>{log_syntax!{0}};(1)=>{log_syntax!{1}t!{1}}}
    

    (playground)

    Readable version:

    #![feature(log_syntax)]
    
    macro_rules! truth_machine {
        (0) => {
            log_syntax!(0);
        };
        (1) => {
            log_syntax!(1);
            truth_machine!(1);
        };
    }
    
    truth_machine!(0);
    truth_machine!(1);
    

    Explanation

    As the only way to iterate over anything other than the inputs of a macro is recursion, an infinite loop will always end in a stack overflow. I'm considering this error message "constant output of your language's interpreter that cannot be suppressed," as there's no other way to "infinitely" loop. The time for this to occur is dependent on the stack size, and thus most real-world macros will attempt to perform multiple operations per iteration to avoid this. Since this takes more space, I didn't do this. The only ways for a macro to give output are:

    • compile_error!, a builtin which will immediately terminate compilation with a message, and is thus not valid for this challenge
    • log_syntax!, an unstable builtin which will print its input to the compiler's stdout, with a newline appended
    • Returning a value from the macro directly, which directly conflicts with the concept of an infinite loop

    I chose to use log_syntax!, as I decided it was the only option that would follow the rules of the challenge. However, it requires a nightly compiler, and 23 additional characters in the source to enable. The syntax of macros is pretty fixed, but one trick I found is that macros called with macro!{} instead of macro!(); do not require a semicolon after, and are thus one character shorter.

    leo60228

    Posted 2015-11-03T16:40:48.353

    Reputation: 21

    2

    Verbosity v2, 290 bytes

    IncludeTypePackage<OutputSystem>
    IncludeTypePackage<InputSystem>
    IncludeStructurePackage<Loops>
    input=InputSystem:NewInput<DEFAULT>
    outpu=OutputSystem:NewOutput<DEFAULT>
    condi=InputSystem:ReadEvaluatedLineOfInput<input>
    Loops:ConstructLoop<Do;condi>[OutputSystem:DisplayAsText<outpu;condi>]
    

    Try it online!

    First non-trivial Verbosity v2 answer! Although how it works is very trivial, as you can see from the ungolfed version:

    IncludeTypePackage<OutputSystem>
    IncludeTypePackage<InputSystem>
    IncludeStructurePackage<Loops>
    
    input  = InputSystem:NewInput<DEFAULT>
    output = OutputSystem:NewOutput<DEFAULT>
    
    condition = InputSystem:ReadEvaluatedLineOfInput<input>
    
    Loops:ConstructLoop<Do; condition> [
    	OutputSystem:DisplayAsText<output; condition>
    ]
    

    Try it online!

    Simply enter a do...while loop, which prints the input at least once, then terminates if it's falsey (i.e. 0).

    caird coinheringaahing

    Posted 2015-11-03T16:40:48.353

    Reputation: 13 702

    2

    W s, 1 byte

    The s flag forces a read from STDIN. This flag can be appended to the end of the command-line.

    w
    

    No, I didn't just make a built-in for the question.

    Here is the expanded program (because w requires two inputs)

    aaw
    

    This decodes into:

    mywhile(a[0],'a[0]',a)
    

    Which means:

    while a[0]:
        print(a[0])
    

    The print is implicit in every while iteration. Since a[0] is always 1 once it is defined as 1, this will print 1 forever (the body is the same as the condition).

    So you might say that this prints nothing if the input is 0. You are wrong, the w instruction returns the condition 0 after the while statement is done. Therefore it gets returned and gets outputted.

    W s, 4 bytes

    W was designed to be very powerful so that while loops are unneccecary. This program avoids this at the cost of being significantly longer. (Please don't use the while loop (which is simply for presentation purposes) in your W programs. Thank you.)

    ibE&
    

    Explanation

       & % Perform logical AND between the input and the code block.
         % If the input is 1, execute the following code block:
    i E  %     Count to infinity,
     b   %     Printing the input in every iteration
         % Otherwise (part of the AND logic):
         %     Return 0, exit the program.
    

    user85052

    Posted 2015-11-03T16:40:48.353

    Reputation:

    2

    tq, 3 bytes

    ?(?
    

    Explanation

    ?,   # Take an input
      (? # Extend the array while
         # the input is not false
    

    user85052

    Posted 2015-11-03T16:40:48.353

    Reputation:

    2

    Shakespeare Programming Language, 123 120 bytes

    (Whitespace added for readability)

    T.Ajax,.Puck,.Act I:.Scene I:.[Exeunt][Enter Ajax and Puck]
    Ajax:Listen tothy.Open heart.
         Am I worse you?If solet usAct I.
    

    Try it online!

    I make use of a trick to reuse Scene I. For some reason, it doesn’t error to keep taking input, so I do that. Then I just compare the input to zero, and loop if it’s greater. Saved 3 bytes by comparing to I instead of zero because characters initialize to zero—thanks Robin Ryder!

    Hello Goodbye

    Posted 2015-11-03T16:40:48.353

    Reputation: 442

    You can use Is I worse you? instead of Is zero worse you?, since all characters are implicitly initialized at 0. – Robin Ryder – 2020-01-21T14:59:35.503

    True true, thank you! – Hello Goodbye – 2020-01-22T15:03:14.803

    2

    MATLAB, 39 37 bytes

    Two years later, two bytes golfed off.

    disp(input('')),while ans disp(1),end
    

    This was a bit shorter than the original one, since it avoid having anything after end, thus saving a comma or semicolon, and it saves one more byte by avoiding the separate call to disp(0).

    Stewie Griffin

    Posted 2015-11-03T16:40:48.353

    Reputation: 43 471

    2

    tinylisp, 36 bytes

    This is a language that I'm basing an upcoming challenge on. The spec in the challenge doesn't include the disp function, but the reference implementation does.

    (d M(q((x)(i x(i(disp x)0(M x))0))))
    

    Defines a function M that takes an argument x (the closest that the language has to input). If x is falsey, we return 0, which is printed. If x is truthy, we want to display x and then recurse. There isn't any equivalent to Common Lisp's progn in the language, so the best way to do this is to use the disp call as the condition of an if. The result is falsey, thus putting the recursive call (M x) in the else branch.

    DLosc

    Posted 2015-11-03T16:40:48.353

    Reputation: 21 213

    2

    Sisi, 22 bytes

    Sisi doesn't have any way to take user input, so the number is expected to be stored in the variable x (presumably on line 1).

    2 print x
    3 jumpif x 2
    

    Pretty straightforward: print the number, and keep doing so as long as it's 1.

    DLosc

    Posted 2015-11-03T16:40:48.353

    Reputation: 21 213

    2

    Beam, 25 23 13 bytes

    rSn(`)>@<
    H@<
    

    Try it in the online interpreter! (Warning: it may crash your browser with an input other than 0.)

    Beam is a 2D language, based on the concept of a beam of light moving through the 2D source code. Beam is oriented around two main memory values: one held by the beam, and one called the "store". Here are the commands used, in order:

    • r - Set the beam to the next ASCII code in the input. (48 for 0, 49 for 1)
    • S - Set the store to the beam.
    • n - If beam != store, point the beam downward. Does nothing the first time.
    • ( and ) - If store != 0, point the beam right/left, respectively.
    • ` - Decrement the store by 1.

    Now, the beam enters (`) from the left, and bounces back and forth until the store reaches 0. If the store's initial value is 48 (0), it will exit to the left, traveling through these chars:

    • n - If beam != store, point the beam downward. This time, since the beam is 48 and the store is 0, it does its job.
    • < - Unconditionally point the beam to the left.
    • @ - Output the beam as an ASCII character. Prints 0.
    • H - Halt the program.

    However, if the store's initial value is 49 (1), it exits the loop to the right, and runs through this code:

    • > - Unconditionally point the beam to the right.
    • @ - Output the beam as an ASCII character. Prints 1.
    • < - Unconditionally point the beam to the left.
    • @ - Output the beam as an ASCII character. Prints 1.
    • > ...

    ...and so on until the end of time (or until your browser crashes).

    Thanks to @MickyT for this awesome layout!

    P.S. If you want to learn more about Beam, check out and vote on this post!

    ETHproductions

    Posted 2015-11-03T16:40:48.353

    Reputation: 47 880

    +1 I like it, didn't think I could shorten it, but here's a slightly shorter version. 2 Lines rSn(\)>@<andH@<` for 13 – MickyT – 2015-11-03T22:16:34.820

    @MickyT Holy cow, that's brilliant! I'll update in a sec – ETHproductions – 2015-11-03T22:18:50.830

    2

    Self-modifying Brainfuck, 30 19 bytes

    Similar method to my BF answer. Input and print, subtract the 0 (the source's last byte) from the input, so cell is 0 or 1. Loop printing if input cell is 1. Tested on my Python interpreter.

    ,.<[->-<]>[<<.>>]10
    

    You can also run it on TIO.

    mbomb007

    Posted 2015-11-03T16:40:48.353

    Reputation: 21 944

    2

    JavaScript (ES6), 77 73 64 61 bytes

    x=prompt()==1;j=a=>{if(x)setTimeout(j,9);console.log(+x)};j()
    

    This program doesn't crash your web browser!

    Explanation:

    x = prompt() == 1;             // this makes sure input is 1 or not while defining
    j = a => {                     // es6 arrow function
      if (x)                        // if x is 1
        setTimeout(j, 9);            // make sure to do this function again in 9ms
      console.log(+x);              // log the number
    };
    j();                           // call j
    

    Florrie

    Posted 2015-11-03T16:40:48.353

    Reputation: 831

    Better version: x=prompt()==1;j=()=>{if(x)requestAnimationFrame(j);console.log(x?1:0)};j() – anOKsquirrel – 2015-11-03T19:53:17.757

    Even better, replace j=()=> with j=a=> – anOKsquirrel – 2015-11-03T19:59:21.883

    Actually, using x=prompt(); is shorter, but you have an x==1?1:0 that could just be x. That leaves x=prompt();j=a=>{if(x==1)requestAnimationFrame(j);console.log(x)};j() at 69 bytes. However, instead of using requestAnimationFrame you could use a setTimeout, which is shorter and leads to x=prompt();j=a=>{if(x==1)setTimeout(j,10);console.log(x)};j() at 69. Oh crap! That would mean that JS beats Stack! D: – anOKsquirrel – 2015-11-03T20:12:17.057

    Haha. The reason I use x==1?1:0 is so that if the user inputs "true" it counts as 0. – Florrie – 2015-11-03T20:50:08.840

    (oh my, it's liam4! hey!) But you don't need to. The only inputs needed 1 and 0. – anOKsquirrel – 2015-11-03T21:01:51.173

    Great work! I think +x will work in place of x?1:0. – ETHproductions – 2015-11-03T21:47:14.713

    2

    Stuck, 9 Bytes

    Stuck has a while loop function (which I never added to the docs on Esolangs, but it has existed for a little over 2 months) which makes this possible. It wasn't before this as far as I know :P.

    ip"1="'ph
    

    Kade

    Posted 2015-11-03T16:40:48.353

    Reputation: 7 463

    2Dammit I was trying to make a truth machine in Stuck but couldn't figure out how to do it without a while loop – a spaghetto – 2015-11-03T20:15:47.617

    @quartata Sorry about that :P Whenever I get enough free time I will update the documentation. – Kade – 2015-11-03T20:20:14.443

    2

    Brainfuck, 54 bytes

    +++[>++++[>++++<-]<-]>>>,.[>+<<[>>-<<-]>>>+<<-]>[>.<]
    

    Explanation:

    +++[>++++[>++++<-]<-]>>> Set a register to 48 (ASCII 0), using multiplication to reduce the byte count (3*4*4), then set the pointer to the next instruction

    ,. Receive and print a line of input

    [>+<<[>>-<<-]>>>+<<-]Set the next register to be a numerical value, and the one after to represent the ascii output value

    > Move the data pointer to the numerical register

    [>.<] While the numerical register is not 0, print the ascii register

    Ethan

    Posted 2015-11-03T16:40:48.353

    Reputation: 271

    I already have a shorter BF program, but just so you know, 48 can be made shorter. See this helpful page.

    – mbomb007 – 2015-11-03T21:44:02.713

    Thanks. Yeah, I didn't see your program before I posted mine, must have missed it when scrolling through. – Ethan – 2015-11-03T22:01:26.623

    Try running the code snippet contained in the question. – mbomb007 – 2015-11-03T22:12:32.490

    2

    brainfuck, 20 bytes

    ,[.>+<-[-[>]<++<-]>]
    

    This requires an interpreter that exits with an error upon stepping out of bounds with < (such as this one). Stepping over the left edge in case of an even value was the easiest way I found to do a parity test. I wouldn't be surprised if it could be a couple of bytes shorter.

    feersum

    Posted 2015-11-03T16:40:48.353

    Reputation: 29 566

    2

    R, 29 27 bytes

    2 bytes brilliantly saved by @Giuseppe

    x=scan();while({cat(x);x})1
    

    MickyT

    Posted 2015-11-03T16:40:48.353

    Reputation: 11 735

    the other R solution isn't valid, but there's another two bytes you can squeeze out of this! click here to spoil it

    – Giuseppe – 2018-03-03T15:38:52.280

    @Giuseppe that is great. – MickyT – 2018-03-03T19:51:49.900

    2

    Julia, 51 45 bytes

    readline()>"0"?while 2>1 print(1)end:print(0)
    

    Read a string from STDIN. If it's lexicographically larger than the string "0" then print 1 forever, otherwise print 0 and we're done.

    Saved 6 bytes thanks to Sp3000!

    Alex A.

    Posted 2015-11-03T16:40:48.353

    Reputation: 23 761

    2

    PoGo, 10 bytes

    ifpouftogo
    

    Explanation:

    • if - accept numerical input and place the result into the current memory cell
    • po - add current position in code to the top of the po stack
    • uf - output the value in the current memory cell as a number
    • to - execute the following command only if the value in the current memory cell is >0
    • go - pop the most recent po location off the stack and jump there

    The "po" stack is a call stack used for flow control.

    The program in pseudo code:

    read int x
    do:
        print x
    while x > 0
    

    Fabian Schmengler

    Posted 2015-11-03T16:40:48.353

    Reputation: 1 972

    2

    Batch, 44 bytes

    @set/p n=
    :a
    @echo %n%
    @if %n%==1 goto :a
    

    Explanation

    • set /p reads from stdin into a variable
    • :a is a GOTO marker, because batch does not have while loops

    The rest should be obvious: output the variable n and if n is 1, repeat.

    Fabian Schmengler

    Posted 2015-11-03T16:40:48.353

    Reputation: 1 972

    2

    Common Lisp, 30

    (do((x(read)))((=(print x)0)))
    

    Common Lisp's print function returns the object that was printed. This reads a value from the user, then prints the value until the return value of the call to print returns 0.

    Joshua Taylor

    Posted 2015-11-03T16:40:48.353

    Reputation: 660

    2

    Labyrinth, 6 bytes

    ?|:!:/
    

    In the case of a 0 input, this terminates with an error. For a beautiful solution which exits cleanly, see Sp3000's answer.

    Since the code is linear, the instruction pointer will move back and forth on the code (it will turn around when hitting a dead end, executing the instruction at the end only once). So what is happening?

    ?  Read the input as an integer.
    |  Compute the bitwise OR of the top two stack elements (there is an infinite supply of
       zeroes at the bottom). This is a no-op at this point.
    :  Duplicate the input.
    !  Print it as an integer.
    :  Duplicate the input.
    /  Divide the input by itself. If the input was 0, the interpreter will throw an error,
       polluting STDERR, but we can ignore that. STDOUT remains unchanged. If the input was
       1, then 1/1 just yields 1 again and execution continues leftwards.
    :  Duplicate the 1.
    !  Print it.
    :  Duplicate the 1.
    |  Bitwise OR between 1 and 1 gives 1.
    ?  Try reading another integer. But we're at EOF, so this pushes 0.
       We're in a dead end, so the IP turns around and moves back to the right.
    |  Bitwise OR between 1 and 0 gives 1.
       At this point, the state is exactly the same, as the first time we hit |, so from here
       on it's an infinite loop, printing two 1s per iteration.
    

    Martin Ender

    Posted 2015-11-03T16:40:48.353

    Reputation: 184 808

    2

    VBA, 54 48 Bytes

    Sub f(u):Do:Debug.Print u:Loop While u>0:End Sub
    

    Look Guys, VBA can fit on one line(almost) and be hard(ish) to read like all the other Languages.

    Debug.Print could be Msgbox but I feel that isn't the Spirit of the challenge and you really don't want Never ending pop-ups

    Old Code

    Sub f(u):Do:Debug.Print u:If u=0 Then End
    Loop:End Sub
    

    JimmyJazzx

    Posted 2015-11-03T16:40:48.353

    Reputation: 691

    Using ActiveSheet.Range("A1") as your input and running in the Immediate Window, you can reduce to 31 bytes: ?[A1]:Do Until[A1]=0:?[A1]:Loop – Chronocidal – 2018-05-09T09:40:31.987

    For sure. Any of my VBA answers are designed not to run in immediate and do not use sheets. VBA can for sure be shortened by using those methods and I encourage you to explore the possibilities. But at the time there were few to no VBA responses so I limited myself to Subs only. – JimmyJazzx – 2018-05-09T10:15:42.673

    2

    COMMAND.COM, 12 + 10 + 11 = 33 bytes

    0.BAT:

    @ECHO 0
    @EXIT
    

    1.BAT:

    @ECHO 1
    @1
    

    Start COMMAND.COM with the above two files in the current directory. Then when it requests input, type either 0 or 1. Also works with CMD.EXE.

    If you don't want the Microsoft version and copyright then you can use CMD /K ECHO OFF instead. I've therefore added 11 bytes for this, but subtracted 4 bytes, as you no longer need the @s at the start of each line.

    If command-line arguments are acceptable and you are allowed use COMMAND /C 0 or COMMAND /C 1 then you can remove the @EXIT from 0.BAT. In that case the size is 7 + 11 + 1 + 1 = 20 bytes.

    Neil

    Posted 2015-11-03T16:40:48.353

    Reputation: 95 035

    2

    FORTH, 44 bytes 39 bytes 31 bytes

    Edit:

    As suggested by @Nate Eldredge, we can shorten the code, if we allow extra spaces in the output. This program is 31 bytes long:

    : P BEGIN DUP . ?DUP 0= UNTIL ;
    

    Sample run:

    1 P
    0 P
    

    First version:

    : P BEGIN DUP 48 + EMIT ?DUP 0= UNTIL ;
    

    Sample run:

    1 P
    0 P
    

    Explanation:

    We expect the value 'b' of 0 or 1 on the stack.
    
    : P       -- beginning a word P                          ( b ) 
    BEGIN     -- starting a loop                             ( b )
    DUP 48 +  -- creating an ASCII code for the character    ( b  b+48 )
    EMIT      -- echoing the character                       ( b )
    ?DUP      -- dup'ing the value if non-zero               ( 1  1 ) or ( 0 )
    0=        -- testing if the value is zero                ( 1 FALSE) or ( TRUE )
    UNTIL     -- end of the loop if true                     ( 1 ) or ( - )
    ;         -- finishing the word
    

    If I take the challenge seriously, FORTH has Standard I/O capabilities, but it is natural in FORTH to take the input from the stack.

    If I use the STDIO feature, the code looks like this (44 bytes)

    : P KEY BEGIN DUP EMIT DUP 48 = UNTIL DROP ;
    

    Sample run:

    P
    

    (Note, that in my environment the standard input was buggy)

    gaborsch

    Posted 2015-11-03T16:40:48.353

    Reputation: 249

    2My FORTH is rusty, but wouldn't it be easier and shorter to use . instead of 48 + EMIT? – Nate Eldredge – 2015-11-05T19:45:25.813

    @NateEldredge . puts an extra space after the number, otherwise it's OK. I've read in some answers that it may be acceptable. If that's the case we can shorten the code. I'll update the answer. – gaborsch – 2015-11-05T23:12:05.243

    2

    MIPS asm, 24 bytes

    main:
    li $v0, 5  # load read int
    syscall  # exec read int, stores value in $v0
    move $a0, $v0  # store in $a0
    li $v0, 1  # load print int
    loop:
    syscall  # print $a0
    bgtz $a0, loop  # loop while $a0 is greater than zero
    

    Had to learn MIPS recently, might as well do something fun with it.

    Kyle G

    Posted 2015-11-03T16:40:48.353

    Reputation: 761

    2

    Rotor, 4 bytes

    {}|
    

    Contains an unprintable, so here's a hexdump:

    0000000: 7b1b 7d7c                                {.}|
    

    Explanation:

            implicit -- evaluate and push input onto stack
    {       beginning of block
      ^[    prints the top value of the stack (without popping it)
    }|      execute block while top value is truthy
            implicit -- print stack
    

    a spaghetto

    Posted 2015-11-03T16:40:48.353

    Reputation: 10 647

    2

    Marbelous, 23

    This version doesn't terminate after the zero is printed, but that should be alright:

    ..}0
    ../\//
    >0
    }0
    +O
    +O
    

    Old version:

    }0@0
    \\
    ../\+O
    >0\/+O
    @0
    

    It doesn't add a newline between each 1, but whatevs.

    TheDoctor

    Posted 2015-11-03T16:40:48.353

    Reputation: 7 793

    2You need to terminate if your language is at all capable of terminating. – lirtosiast – 2015-11-18T03:31:30.353

    2

    Python 2- 64 bytes

    x=input()
    if x==0:print"0"
    elif x==1:
     while True: print"1"
    

    Sidsy

    Posted 2015-11-03T16:40:48.353

    Reputation: 21

    A trick you can exploit in Python is that 0 is the same as False and anything but 0, including 1, is True. This generally holds in most programming languages – bioweasel – 2016-11-01T20:00:07.190

    2

    PowerShell, 24 bytes

    'for(){1}'*"$args"+0|iex
    

    Generate expression as string and pass it to Invoke-Expression (eval).

    It casts $args array to string with "", then multiplication sign casts it to int and string for(){1} is repeated int times (1 or 0 - empty string). Then we add 0 to this string, which will be cast to a string also.

    Resulting string expression (for(){1}0 or 0) is then piped to Invoke-Expression, resulting either in endless loop outputting 1 or one-time output of 0.

    beatcracker

    Posted 2015-11-03T16:40:48.353

    Reputation: 379

    2

    Jolf

    0 Bytes

    
    
    

    I found out what to do with the zero-byte program! I made a truth machine.

    0 as input

    1 as input

    Conor O'Brien

    Posted 2015-11-03T16:40:48.353

    Reputation: 36 228

    4Congrats, you have made the most boring answer on this challenge! ಠ_ಠ +1 – user48538 – 2016-01-16T18:13:23.727

    @zyabin101 bows thank you. – Conor O'Brien – 2016-01-16T18:13:47.507

    2

    Detour, 2 bytes

    ,~
    

    Try it online!

    , will print a value then push it to the next cell.

    ~ is a filter, so it will push a value IFF it is greater than 0.

    Cells wrap around the edges.

    Cyoce

    Posted 2015-11-03T16:40:48.353

    Reputation: 2 690

    2

    MATL, 4 bytes

    `GtD
    

    Relevant MATL features *

    To explain the code, the following MATL features need to be presented first.

    • ` ...] is a "do ...while" loop. The top of the stack is consumed at the end of each iteration, and used to decide whether to go on with a new iteration or not. The last ] can be omitted if it's at the end of the program (loops are implicitly closed).
    • G works as follows:
      • When there has been no user-input it does nothing;
      • When there has been one user-input it pushes it onto the stack
      • When there has been more than one user-input it takes a numeric argrument and pushes one of those user-inputs onto the stack
    • t by default duplicates the top element of the stack
    • D by default displays the top element of the stack, and consumes it.
    • If a function requires more inputs than currently are in the stack, user-input is implicitly triggered. The entered elements are placed below the current bottom of the stack.

    Code explanation

    ` enters the loop. At the first iteration, G does nothing. t implicitly asks for user input and duplicates it. D displays and consumes the duplicate, leaving the original input on the stack. If this input is 0 the loop is exited and the program finishes (a single 0 has been displayed). If the input is 1, control goes to the beginning of the loop again. Now G pastes the input, t duplicates it, D displays and consumes that duplicate, and again there's a 1 to be used as loop condition, so the loop begins again, indefinitely (an infinite number of 1 is displayed).


    * at the time of writing. The behaviour of G has changed since then: G now triggers implicit input when there has been no user-input yet. However, this doesn't affect the code, which works the same. The only difference is that in the first iteration the implicit input is now triggered by G, not by t.

    Luis Mendo

    Posted 2015-11-03T16:40:48.353

    Reputation: 87 464

    2

    Lua, 56 52 Bytes

    I know that this answer in 70 Bytes exists, but its author doesn't look like he's updating it when someone point out an improvement.

    if io.read'*n'>0then::a::print"1"goto a end print"0"
    

    Old 56 bytes solution

    if io.read()=="1"then while""do print"1"end end print"0"
    

    Nothing special here, just using the fact that "" evaluates to true to save a byte on the infinite loop. Parenthesis for functions parameters aren't mandatory when they only take a single string, which is not stored in a variable.

    Katenkyo

    Posted 2015-11-03T16:40:48.353

    Reputation: 2 857

    2

    Shtriped, 33 bytes

    e :
    t :
    .
     d :
     i :
     p :
     .
    .
    p :
    

    This prints the 0 or the infinite stream of 1's without any trailing newlines or spaces.

    Explanation:

    e :  \ initialize a variable named ":"
    t :  \ prompt for integer input, storing the result in :
    .    \ define a function named "." that will only return if : is 0 (the next 4 indented lines are part the function)
     d : \ decrement : if : is positive, else return immediately
     i : \ : must have been 1 to reach here and was just decremented, so increment back to 1
     p : \ print :, which we know is 1
     .   \ recursively call ., endlessly looping
    .    \ call . initially
    p :  \ if . terminated this line will finally be run, printing : which we know is 0
    

    Calvin's Hobbies

    Posted 2015-11-03T16:40:48.353

    Reputation: 84 000

    2

    BASTARD, 83 bytes

    {{fi in 0{!b {= {t 0} ‘1’} {(o <> {{fi out ‘1’}{o}}){o}}{fi out ‘0’}}}}
    

    Note: This language is not qualified. Mostly because I'm still designing it. I just wanted to test drive it against some puzzles.

    Explanation:

    fi in copies the input into the 0 place on the Variable Stack.

    !b is a basic if statement to check if its a "1" or not.

    If it is, we just use fi out to print our "0".

    Otherwise, we define a new function called o that prints a "1", and then calls itself again.

    s4b3r6

    Posted 2015-11-03T16:40:48.353

    Reputation: 31

    Welcome to Programming Puzzles and Code Golf Stack Exchange. This is a great first answer, +1. Your language looks interesting; once you've got enough reputation you could get help developing it on Chat. – wizzwizz4 – 2016-02-19T15:05:12.447

    2

    NTFJ, 27 bytes

    :*:##~~~~~#@|########@|($~^
    

    An online interpreter can be found here.

    NTFJ is an esoteric programming language, made by user @ConorO'Brien, that is intended to be a Turing tarpit. It is stack-based, and pushes bits to the stack, which can be later coalesced to an 8-bit number.

    • The only pushable values are 0 with ~ and 1 with #.
    • The only manipulations possible to the actual values of the stack are to wrap eight bits into a byte with @, and to NAND with |.
    • The only logic command is IF with (), but combined with JUMP ^, it can be used to create loops.

    Thus, it's quite difficult to manipulate values to do your bidding.

    How it works

                                   Implicit input: byte 48 for 0 or 49 for 1.
    :*:                            Duplicate the top item, pop/output, and duplicate again.
       ##~~~~~#@|                  Push 193 and perform NAND.
                 ########@|        Push 255 and perform NAND.
                                   These two operations change 48 to 0 and 49 to 1.
                           (       If the top item is not 0:
                            $       Pop the top item.
                             ~^     Push 0 and jump to that instruction.
                                   This effectively creates a while loop that loops the entire program.
    

    ETHproductions

    Posted 2015-11-03T16:40:48.353

    Reputation: 47 880

    I believe removing the last paren should still work. – Conor O'Brien – 2016-03-02T19:42:40.287

    @CᴏɴᴏʀO'Bʀɪᴇɴ Thanks, it does! – ETHproductions – 2016-03-15T20:08:24.977

    2

    Beatnik, 26 bytes

    J ZD ZD JA K ZZZZJ Z JJ MF
    

    Try it online

    An explanation

    Words    Scores   Action
    J        8        Get character value from input
    ZD       12       Duplicate TOS
    ZD       12       Duplicate TOS
    JA       9        Output TOS character
    K ZZZZJ  5 48     Push 48 (char 0) onto stack
    z        10       Pop 2 from stack and subtract
    JJ MF    16 (7)   If not zero skip back 7 words
    

    Of course something like the following, while still not making sense, looks more like what you would expect for a Beatnik program.

    Shall falsey determine truths? We **WithoutAWarningAboutMemoryUse** printed infinitely yeas!
    

    MickyT

    Posted 2015-11-03T16:40:48.353

    Reputation: 11 735

    The last one mostly makes sense, except for He quackpizzled? :) – ETHproductions – 2016-03-16T22:50:01.333

    @ETHproductions Yea, try to find a word that is SORTAWORDLIKEWITHABIGNUMBER and still fits gets difficult :) Will have a play and see what I can come up with. – MickyT – 2016-03-16T22:55:55.340

    @ETHproductions That's a bit better now – MickyT – 2016-03-16T23:08:21.830

    2

    UGL, 6 bytes

    il$o:o
    

    Try it online!

    How it works:

    i       #stack.push(input)
     l  :   #while stack.peek():
      $     #    stack.dup()
       o    #    print(stack.pop())
          o #print(stack.pop())
    

    Leaky Nun

    Posted 2015-11-03T16:40:48.353

    Reputation: 45 011

    2

    Scratch, 12 bytes

    Script
    I love how Scratch can be so self-explanatory in the right contexts.

    weatherman115

    Posted 2015-11-03T16:40:48.353

    Reputation: 605

    Your list name counts as bytes – dkudriavtsev – 2016-07-11T23:36:21.893

    2

    WistfulC, 141 bytes

    This C has seen better days.

    if only int n were 0...
    wish for "%d",&n upon a star
    someday !n... wish "1" upon a star
    *sigh*
    wish "0" upon a star
    if wishes were horses...
    

    Obviously not competitive, but then neither is this language.

    Rough translation to regular C:

    int n = 0;
    scanf("%d", &n);
    while (n) {
        puts("1");
    }
    puts("0");
    exit(0);
    

    jqblz

    Posted 2015-11-03T16:40:48.353

    Reputation: 2 062

    2

    Silicon, 3 bytes

    I[]
    

    Explanation:

    I          Get input
    [          While the top of the stack is 1
               Implicit output
    ]          End while
               Implicit output
    

    m654

    Posted 2015-11-03T16:40:48.353

    Reputation: 765

    2

    MarioLang, 25 bytes (Non-competing)

       >:<
       "==
     ;[!:
    ===#=
    

    user54200

    Posted 2015-11-03T16:40:48.353

    Reputation:

    1Why is this non-competing? Just FYI: "Non-competing" generally means "Uses language features that are newer than the challenge" or "Used to be valid but the rules changed". – James – 2016-06-30T15:16:10.833

    I mean that I am not using this code to win this challenge. but upvotes are free! – None – 2016-07-01T05:32:06.057

    That's not what non-competing means here. Also, this answer predates yours and is a lot shorter.

    – Dennis – 2016-07-22T19:57:15.363

    @Dennis You're correct. – None – 2016-07-23T02:30:47.660

    @DrGreenEggsandIronMan I was just aware that there was a shorter one and said "non-competing". – None – 2016-07-23T02:31:34.320

    2

    PHP, 34 bytes

    <?for($f=fgetc(STDIN);$f;?>1<?)?>0
    

    Wanted to try to get rid of the print but not sure it's worth it since you have to reintroduce the <? tags

    Sefa

    Posted 2015-11-03T16:40:48.353

    Reputation: 582

    2

    T-SQL 23 bytes

    No STDIN here so a hard-coded variable.

    DECLARE @ INT =1; or DECLARE @ INT =0;

    and the truth machine is

    l:PRINT @ IF(1=@)GOTO l

    S.Karras

    Posted 2015-11-03T16:40:48.353

    Reputation: 241

    2

    C, 41, 40 bytes

    main(c){for(c=getchar();putchar(c)&1;);}
    

    Reads a single character from stdin, writes to stdout.

    This version is 1 byte longer than feersum's solution, but removes his/her assumptions onstdin.

    Stefano Sanfilippo

    Posted 2015-11-03T16:40:48.353

    Reputation: 1 059

    Would putchar(c)&1 work? – Dennis – 2016-08-29T16:41:07.680

    Yes, you are right! One byte saved, thanks @Dennis. – Stefano Sanfilippo – 2016-08-29T16:51:38.137

    2

    dc, 13 12 bytes

    ?[pd1=@]ds@x
    

    Run:

    dc -f truth_machine.dc <<< "1"
    

    Adding to the diversity of languages used, I present a dc solution that works as follows:

    ?              # reads the input and pushes it on top of the stack
    [pd1=@]ds@x    # stores the macro command [pd1=@] into register '@' and executes it
       p           # prints the value on top of the stack
       d           # makes a duplicate that is pushed on top
       1=@         # pushes 1, pops two numbers and if they are equal, the macro from
                   #register '@' is executed (again), thus making an infinite cycle
    

    seshoumara

    Posted 2015-11-03T16:40:48.353

    Reputation: 2 878

    2

    Java, 143 141 125 88 bytes

    interface T {static void main(String[]a){System.out.print(a[0]);main(a[0].split("0"));}}
    

    Ungolfed Test Code

    interface T {
    
        static void main(String[] a) {
            System.out.print(a[0]);
            main(a[0].split("0"));
        }
    }
    

    Shaun Wild

    Posted 2015-11-03T16:40:48.353

    Reputation: 2 329

    That's 143 characters. – clismique – 2016-09-01T08:49:53.457

    Why did you even check? – Shaun Wild – 2016-09-01T08:51:52.647

    I'm using a userscript for PPCG, and it tells me how many bytes there are. (You should totally use it, it's worth it)

    – clismique – 2016-09-01T08:54:18.110

    Ahh ok. It's shorter now anyway :P – Shaun Wild – 2016-09-01T08:55:59.830

    2

    Copy, 67 59 bytes

    My new esolang :D

    getch a
    add b a
    add b -48
    print a
    skip b
    skip 1
    copy -4 0 1
    

    Explanation:

    getch a     Take input in variable 'a'
    add b a     Set 'b' to 'a'
    add b -48   Substract 48 from 'b'
    print a     Print 'a'
    skip b      Skip the copy if 'a' is not zero
    skip 1      ^
    copy -4 0 1 Copy the code block from the print to this instruction after this instruction
    

    TuxCrafting

    Posted 2015-11-03T16:40:48.353

    Reputation: 4 547

    protip: *subtract – Destructible Lemon – 2016-09-25T09:22:55.570

    @DestructibleWatermelon No – TuxCrafting – 2016-09-25T09:26:25.760

    2

    Crystal, 48 37 36 bytes

    y=gets;y=="0\n"&&(p 0;exit);y=="1\n"&&loop{p 1}
    y=gets;y=="0\n"&&(p 0;exit);loop{p 1}
    y=gets;y=="0\n"&&(p 0;1/0);loop{p 1}

    Edit: Shaved off 10 bytes because the post doesn't specify what should happen on invalid input (like 2). If it does and I misunderstood, let me know.

    Edit: Shaved off 1 byte by dying with an error instead of normal exit.

    Crystal is statically typed, so I couldn't just do gets.chomp (gets can return nil, and nil doesn't have chomp). The alternative was gets.try &.chomp, but that takes much more space than just having the newlines.

    In Crystal (and Ruby) you can do something like puts 0 if y=="0\n", however you can also shave off 2 bytes by doing y=="0\n"&&puts 0 as the && operator returns the last object it tests for truthiness.

    loop is a method in the standard lib that infinitely runs the block. It's a much shorter way of writing while true;CODE;end.

    p prints the result of .inspect on its arguments to the output. Here I abuse it as a shorter puts because for numbers it'll just return the number.

    Zatherz

    Posted 2015-11-03T16:40:48.353

    Reputation: 111

    2

    Valve scripting language, 38 bytes

    alias 0 echo 0
    alias 1 "echo 1;wait;1"
    

    This defines two commands, 0 and 1. Type 0 into the console for the zero case, and 1 for the 1 case.

    Conor O'Brien

    Posted 2015-11-03T16:40:48.353

    Reputation: 36 228

    Could I just try this in half life's console, or do I need the source SDK? – Pavel – 2016-12-21T01:56:06.540

    @Pavel I tested it on the TF2 console, so that should be fine. – Conor O'Brien – 2016-12-21T02:02:15.947

    1

    PHP, 20 bytes

    <?L:echo$i;if($i)goto L;# 24 bytes
    <?do echo$i;while($i);  # Martijn´s first version golfed 24->22 bytes
    <?=$i;while($i)echo$i;  # Martijn´s second version golfed 24->22 bytes
    <?while($i|!print$i);   # 21 bytes
    <?while($i&print$i);    # 20 bytes
    

    Requires PHP <4.2 or PHP<7 with --d register_globals=0.
    Save to file, call in browser with <scriptpath>?i=<value>.

    explanation for the last version:

    print$i is evaluated in any case (no short circuit for bitwise operations).
    print always returns true, which, when cast to int (by the bitwise and) evaluates to 1.
    For $i=0, 0&1 is 0, hence false and the loop exits. for $i=1, 1&1 is 1 and the loop continues.

    shortest version(s) for current PHP, 29 bytes:

    while(($i=$argv[1])&print$i);
    while((print$i=$argv[1])&$i);
    for($i=$argv[1];$i&print$i;);
    

    Run with php -r '<code>' <value>.

    Titus

    Posted 2015-11-03T16:40:48.353

    Reputation: 13 814

    1

    Pyramid, 14 bytes

    +1 byte to specify starting on stack 1 (originally 13 bytes).

    1<
    b
    ---
    ?<
    u
    

    Pyramid is my new-old language, which is based off Stackylogic. It has a bunch of extra commands that will (hopefully) make it TC, which include moving up and down multiple "stacks".

    Explanation:

    1<   1: Move down the stack, and push 0 to the output stack
    b    Break: outputs the stack, and resets it - also runs the stack again
    ---
    ?<   Input: 1, 0: If it's 0, move up, push 0 to the output stack, 
         terminate the program and print the stack
    u    If the input is 1, move up to stack 0
    

    clismique

    Posted 2015-11-03T16:40:48.353

    Reputation: 6 600

    The leaderboard snippet is reading your header as saying that this is 1 byte. You should probably move the part in parentheses to the second line (and, if I understand it right, change the header to say 15 bytes). – DLosc – 2017-02-08T21:57:02.127

    1

    Haystack, 9 bytes

    id?v
    |o<o
    

    Try it online!

    I'm aware that there already is a Haystack answer, but that answer uses the older version of Haystack, this answer uses Haystack 2016 (and it's much shorter)

    Explanation

    id           Take input and duplicate it
      ?          If input is truthy (1) continue, otherwise (0) go down
    

    If input is truthy...

    ?v           Go down
     o           Output number
                 Since this is a 2D language, the IP wraps around and does this infinitely
                 Also since Haystack (new) doesn't pop the top of stack after outputting
                  1 can be printed forever without needing to duplicate it
    

    Otherwise...

      ?
      <          Go left
     o           Output number
    |            Exit program
    

    user41805

    Posted 2015-11-03T16:40:48.353

    Reputation: 16 320

    1

    Pushy, 3 bytes

    #$#
    

    Extremely simple:

    #    \ Print input
     $   \ While input != 0:
      #  \   Print input
    

    An input of 0 will print, skip over the while loop, and terminate, whilst any other number is considered truthy and will be printed infinitely.

    FlipTack

    Posted 2015-11-03T16:40:48.353

    Reputation: 13 242

    ...what's with the downvote? – FlipTack – 2017-01-02T14:19:38.280

    1

    Evil, 74 bytes

    fjzaeeeaeeawbmxruuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuusbaeeeaeew
    

    A program that will request for a character of input. Every lowercase letter corresponds to a different instruction. Here's an analysis.

    f: goes Forward in the program and searches for the closest marking character, or m. This skips all of the code that will continuously output 1 to stdout.

    jzaeeeaeeawb: Continuously output 1 to stdout. The character b searches Backwards for the marking character. However, at this point the marking mode is set to 'alternate', so instead of searching for m, it's searching j, which is at the beggining. The random amount of es with a and z set the counter, or accumulator, to the ASCII representation of 1. w would do what you might think: Write the value of the accumulator to stdout.

    mxr: This is executed right after f. The marking character has now been found, and we continue with x, which switches the marking mode from 'standard' (m) to 'alternate' (j). Then, r Reads stdin for a character and sets the accumulator to the ASCII representation of the input, which would be either 48 for 0 or 49 for 1.

    uuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuusb: Each u decrements the accumulator. The whole operation brings the accumulator down from 48 to 0 or 49 to 1. This is crucial for the following command; the letter s will Skip the next command only if the value of the accumulator is 0. That next command searches backwards for j, which goes all the way back to outputting 1 to stdout. Note that I could probably shorten the amount of bytes here by replacing some us with es, which weave the accumulator.

    aeeeaeew: Now, if the accumulator had hit 0, this snippet puts the accumulator back to 48, or 0, and w Writes the accumulator value to stdout.

    Original interpreter in Java: http://web.archive.org/web/20070906133127/http://www1.pacific.edu/~twrensch/evil/evil.java

    XavCo7

    Posted 2015-11-03T16:40:48.353

    Reputation: 274

    1

    QBIC, 10 bytes

    :{?a~a|\_X
    

    Explanation:

    :    Reads a number from the command line and names it 'a'
    {    DO - infinite loop
    ?a   Print 'a'
    ~a   IF 'a': 0 is seen as false, 1 as true
    |    THEN: Empty THEN block, we want to act on FALSE
    \_X  ELSE exit the program.
         _X accepts one implicit parameter, and prints that parameter on exit.
         Since no parameter is given, nothing gets printed.
    [IF and DO are implicitly closed by QBIC]
    

    steenbergh

    Posted 2015-11-03T16:40:48.353

    Reputation: 7 772

    1

    Threead, 5 bytes (Noncompeting)

    I[o]o
    

    read, while not 0 output, output

    Try it online!

    Pavel

    Posted 2015-11-03T16:40:48.353

    Reputation: 8 585

    Huh, I hadn't even thought about having the single output be after the infinite output, in any language... – ETHproductions – 2017-01-30T03:00:12.290

    @ETHproductions it doesn't make a difference, actually. Io[o] works too. – Pavel – 2017-01-30T03:22:52.263

    Also this is a catalogue so it is competing (kinda) – caird coinheringaahing – 2017-06-04T18:12:26.123

    1

    OIL, 25 bytes

    Straightforward, but nevertheless annotated:

    5  # read into cell 0
    0
    10 # if cell 0 is equal to 0 (from cell 1), go to cell 11 (*) else 7 (&)
    0
    1
    11
    7
    4  # print what's in cell 4 (a zero) &
    4
    6  # jump to cell 7 (&)
    7
    4  # print implicit 0 *
    

    L3viathan

    Posted 2015-11-03T16:40:48.353

    Reputation: 3 151

    1

    Javascript (Node), 40 bytes

    for(;console.log(v=process.argv[2])|v;);
    

    In Javascript for the browser this can be 29 bytes

    v=prompt();for(;alert(v)|v;);
    

    Sullof

    Posted 2015-11-03T16:40:48.353

    Reputation: 31

    Welcome to PPCG! – Martin Ender – 2017-05-07T20:51:25.093

    1

    Triangular, 6 bytes

    $.(]%<
    

    Try it online!

    This formats into the triangle:

      $
     . (
    ] % <
    

    The commands that are executed (without control flow) are $(%]. Pretty simple.

    • $ read input as integer
    • ( open loop
    • % print as integer
    • ] jump back to loop if top of stack is truthy

    MD XF

    Posted 2015-11-03T16:40:48.353

    Reputation: 11 605

    1

    ILL, 19 bytes

    /RnN~
    >1nR\
    \   /
    

    ILL (inverse linear law) is new right now, so this represents virtually all the instructions/groups of instructions it has at the time of posting this. The main idea though, is that the program is run by light, which reflects off of mirrors and decrease in intensity as it moves on (obeying the inverse linear law, because its 2d). Data is primarily stored in the intensity of the light, which can sort of be used as a control structure, since light with an intensity < .5 dims and does not move on to the next tick. This means that different intensities of light move different lengths. This program utilizes the dimming behavior to either halt after printing 0, or prints 1 and continues. Basically, it takes a numerical input (side note: instructions that set intensity actually do so after the current tick has run, and they also persist the light over to the next instruction, no matter what intensity it has), prints it, and then re-intensifies and enters a loop. However, the light is only re-intensified if it reaches the re-intensify instruction, which light with an intensity of 0 will not. More detailed explanation (also a valid ILL program):

    /RnN~
    >1nR\
    \   /
    #END OF FILE#
    Truth machine.
    
    ~ : emits light horizontally at the start of a program.
    N : takes numerical input, set light intensity to the input.
    n : produces numerical output. If the light has an intensity of 0 here, it will dim after n outputs and not move on.
    R : re-intensify, if the light made it here, it can now continue into the loop.
    > : double/splitting mirror, allows the light from the above / mirror to enter the loop and move right.
    1 : set intensity to 1.
    n : numerical output.
    R : re-intensify.
    
    the remaining \, /, and \ reflect the light back to > where it can start the loop again
    

    Socratic Phoenix

    Posted 2015-11-03T16:40:48.353

    Reputation: 1 629

    1

    C# (.NET Core), 80 79 bytes

    class p{static void Main(string[]I){do{Console.Write(I[0]);}while(I[0]=="1");}}
    

    Try it online!

    I've seen some disagreement about whether arguments count as STDIN. "No" seemed more popular, but if it were acceptable then this would save 15 bytes over the previous C# answer.

    Saved 1 byte by removing an unnecessary space

    Kamil Drakari

    Posted 2015-11-03T16:40:48.353

    Reputation: 3 461

    1

    Ly, 7 bytes

    n:u[:u]
    

    Explanation:

    n        # take input
     :u      # duplicate it and print it
       [     # while the top of the stack is not 0...
        :u   # duplicate it and print it
       ]     # end loop
    

    LyricLy

    Posted 2015-11-03T16:40:48.353

    Reputation: 3 313

    1

    Cubically, 6 bytes

    According to the spec, this should work:

    $(%7)7
    $      - Get user input as number (either 1 or 0, according to the rules)
     (  )7 - do ... while input value is nonzero
      %7   - Output the input as a number
    

    However, TIO seems to continue the loop even if the input is 0. The Lua interpreter handles it correctly, though.

    TehPers

    Posted 2015-11-03T16:40:48.353

    Reputation: 899

    $:7(%7)6 works on TIO for now. It should behave identically (instead of looping based on the value in 7, it sets 6 to that value and loops on that) but it doesn't, meaning there's a bug in the interpreter. – Kamil Drakari – 2017-08-05T12:10:41.063

    Works offline and Dennis should be pulling. Good job, can't believe I didn't notice this! I always thought a truth machine had to print 1. – MD XF – 2017-08-05T17:06:02.983

    @MDXF It does print 1. The rules state that the input will either be a 1 or a 0 :P To make it print 1 always, just do :1/1%6 instead of %7 – TehPers – 2017-08-07T19:47:10.607

    1

    8th, 58 bytes

    Code

    : f getc '0 - dup 0 1 between if repeat dup . while then ;
    

    Explanation

    : f - Start of word definition

    getc - Get input from STDIN

    '0 - - Subtract 0's ASCII code to determine numeric input

    dup - Duplicate result to be used to run loop

    0 1 between if - Check if input is either 0 or 1

    repeat dup . while - Print either 0 once or 1 ad infinitum

    then ; - Exit word

    If input is not either 0 or 1, exit with no output. At the end of the program the stack is not empty.

    Chaos Manor

    Posted 2015-11-03T16:40:48.353

    Reputation: 521

    1

    6502 machine code (C64), 17 bytes

    20 FD AE 20 9E B7 8A 09 30 20 D2 FF C9 30 D0 F9 60
    

    Online demo

    This is position independent code, you can enter it at any position in RAM and call it, so it doesn't need a load address. Assuming you put it at C000 (that's the case in the online demo), call it like sys49152,0 or sys49152,1 -- any other input is undefined.

    Explanation:

    20 FD AE    JSR $AEFD    ; consume comma
    20 9E B7    JSR $B79E    ; evaluate number, result in X
    8A          TXA          ; transfer X to A
    09 30       ORA #$30     ; convert to numeric character
    20 D2 FF    JSR $FFD2    ; output character
    C9 30       CMP #$30     ; compare with '0' character
    D0 F9       BNE *-5      ; not equal? Then jump back to output (-7)
    60          RTS          ; return
    

    Felix Palmen

    Posted 2015-11-03T16:40:48.353

    Reputation: 3 866

    1

    Excel VBA, 20 Bytes

    Anonymous VBE immediate window function that takes input from range [A1] and output 1, infinitely if [A1] else 0

    While[A1]:?1:Wend:?0
    

    Taylor Scott

    Posted 2015-11-03T16:40:48.353

    Reputation: 6 709

    1

    Whitespace, 40 bytes

    Note that the only valid characters are space, tab, and linefeed, so they are represented here with S, T, and L, respectively. Comments are also given.

    I used this interpreter to write and test this program (warning: crashes browser window upon input of 1).

    SS L   # push 0
    SLS    # duplicate
    TLTT   # readi
    TTT    # retrieve
    LSS L  #label "" (blank label name, why not?)
    SLS    # duplicate
    SLS    # duplicate
    TLST   # printi
    SS STL # push 1
    TSST   # subtract
    LTS L  # jz label "" (jump to blank label if input-1=0)
    

    Three consecutive linefeeds (LLL) are usually required to end program execution at a point, but that interpreter doesn't seem to mind if you leave them out. If they have to be added in, the score would instead be 43 bytes.

    Josiah Winslow

    Posted 2015-11-03T16:40:48.353

    Reputation: 725

    The interpreter defines the language, so the missing LLL should be completely fine. – Esolanging Fruit – 2017-09-04T05:32:14.990

    1

    Implicit, 5 4 bytes

    $(%)
    

    Try it online! Prints 00, which is equal to 0 Pretty simple:

    $(%)
    $      « integer input               »;
     (.)   « do..while top of stack true »;
      %    «  print top of stack         »;
           « implicit integer output     »;
    

    MD XF

    Posted 2015-11-03T16:40:48.353

    Reputation: 11 605

    1

    Pyth, 5 bytes

    Like my Python answer, but in Pyth

    WQ1)0
    

    Explanation:

    WQ1)      While Q, print 1. 1 = true, 0 = false; end While
    0         Print 0
    

    If input is 1, 0 is never reached, if input is 0, 1 is never reached.

    Try it online!

    Stan Strum

    Posted 2015-11-03T16:40:48.353

    Reputation: 436

    1

    ><>, 6 Bytes

    ::n?!;
    

    Input is assumed to be on the stack. It's duplicated twice, printed, and checked if it's non-zero. If it's non-zero, skip the end program command and loop around.

    Note that this does not print any spacing between the 1s.

    Bolce Bussiere

    Posted 2015-11-03T16:40:48.353

    Reputation: 970

    1

    Husk, 5 bytes

    ¶?∞;I
    

    Try it online!

    Explanation

     ?  I  -- if the input is truthy
      ∞    --   repeat it infinitly many times
       ;   --   else create singleton list
    ¶      -- join by newlines
    

    Thanks @H.PWiz for golfing off 1 byte!

    ბიმო

    Posted 2015-11-03T16:40:48.353

    Reputation: 15 345

    15 bytes: ¶?∞;± or, if string input is valid: ?∞;i – H.PWiz – 2017-11-21T21:06:35.880

    1

    GolfScript - 13 bytes

    ~{.}{.p}while
    

    Basically a

    while(arg){
        print(arg)
    }
    print(arg)
    

    GolfScript doesn't have a real-time STDOUT, everything is printed from the stack to the console at the end of the execution, it has to be stopped manually.

    FedeWar

    Posted 2015-11-03T16:40:48.353

    Reputation: 271

    Yes it does https://tio.run/##S8/PSStOLsosKPn/v65ar7Zar6C2PCMzJ/X/fwMA

    – FedeWar – 2017-11-21T21:27:47.583

    1

    SNOBOL4 (CSNOBOL4), 38 bytes

    	N =INPUT
    L	OUTPUT =N
    	GT(N) :S(L)
    END
    

    Try it online!

    	N =INPUT	;* read input as n
    L	OUTPUT =N	;* print input
    	GT(N) :S(L)	;* if n > 0, goto L
    END
    

    Giuseppe

    Posted 2015-11-03T16:40:48.353

    Reputation: 21 077

    1

    Acc!!, 39 37 bytes

    N
    Count i while _%2-i%2+1 {
    Write _
    }
    

    Try it online!

    This takes input through N, then prints the input _ until the equation _%2-i%2+1 is 0. This looks like:

    48
      48%2-0%2+1 => 1
      48%2-1%2+1 => 0
      48%2-2%2+1 => 1
      48%2-3%2+1 => 0
    49
      49%2-0%2+1 => 2
      49%2-1%2+1 => 1
      49%2-2%2+1 => 2
      49%2-3%2+1 => 1
    

    This is shorter than the easy approach (39 bytes):

    N
    Write _
    Count i while _%2 {
    Write _
    }
    

    Try it online!

    Conor O'Brien

    Posted 2015-11-03T16:40:48.353

    Reputation: 36 228

    1

    AWK, 20 bytes

    {do{print}while($0)}
    

    This is the first thing I came up with. I tried to come up with something clever more clever but they were all longer.

    Try it online!

    Robert Benson

    Posted 2015-11-03T16:40:48.353

    Reputation: 1 339

    1

    C (gcc) , 42 bytes

    main(t){gets(&t);do puts(&t);while(t-48);}
    

    Try it online

    PrincePolka

    Posted 2015-11-03T16:40:48.353

    Reputation: 653

    1

    Wumpus, 6 bytes

    Iv=O=:
    

    Try it online!

    Explanation

    In Wumpus, the IP gets reflected off the program boundary (instead of wrapping around or terminating). Since there is no redirecting control flow in this program, the IP simply bounces back and forth, executing a loop with loop body

    Iv=O=:=O=v
    

    Let's go through this:

    I   Read an integer N from STDIN. On subsequent iterations, this will push a zero.
    v   Bitwise OR. On the first iteration this ORs the input with an implicit zero
        which does nothing. On subsequent iterations, this gets rid of the zero that
        was just pushed.
    =   Duplicate the input.
    O   Print it to STDOUT.
    =   Duplicate it again.
    :   Compute N/N. For input 0, this ends the program, due to the attempted division
        by zero. For input 1, this just gives back 1.
    =   Duplicate the input.
    O   Print it to STDOUT.
    =   Duplicate the input.
    v   Bitwise OR. Just gets rid of one copy of the input.
    

    Martin Ender

    Posted 2015-11-03T16:40:48.353

    Reputation: 184 808

    1

    Ruby + -np, 16 12 bytes

    p 1while~/1/
    

    Try it online!

    ~/1/ matches the last line of input to the regular expression /1/

    Edit: replaced ;p 0 with the -p flag making the answer -np complete, thanks to @ValueInk

    Asone Tuhid

    Posted 2015-11-03T16:40:48.353

    Reputation: 1 944

    you don't have to count flags any longer; just note in the body which one you've used (as you already have done) – Giuseppe – 2018-03-05T23:14:48.067

    @Giuseppe thanks, is this the consensus opinion now? – Asone Tuhid – 2018-03-05T23:16:58.233

    Yeah, see here.

    – Giuseppe – 2018-03-05T23:18:00.757

    @Giuseppe so should I call it Ruby + -n? – Asone Tuhid – 2018-03-05T23:28:32.850

    1Use the -p flag instead to implicit print the zero ;p – Value Ink – 2019-06-05T02:10:29.347

    1

    ShinyLisp, 22 bytes

    +:Ge _&^:Pu~:I:P^~N:Qx
    

    I figure now is as good a time as any to introduce my new golfing language. It's still largely a work in progress, but it's usable.

    Ungolfed:

    (= (gets))
    (loop '% (puts) (cond (p %) () (quit)))
    

    Explanation:

    (= (gets))       -- Reads a line of user input and assigns it %
    (loop '% ...)    -- Loop forever using % as the (constant) loop value
    (puts)           -- Print the value of %
    (cond (p %) ...) -- If % (treated as a number) is nonzero then...
    ()               -- Do nothing
    (quit)           -- Else exit the program
    

    Silvio Mayolo

    Posted 2015-11-03T16:40:48.353

    Reputation: 1 817

    1

    Linotte, 52 bytes

    a:
    e est un nombre
    début
    demande e
    e!
    tant que e,e!
    

    Linotte is a french programming language aimed at beginners. Translated into English:

    a:
    e is a number
    start
    ask for e
    e!
    while e, e!
    

    e! is shorthand for affiche e, which means "display e".

    You can find a download here.

    Conor O'Brien

    Posted 2015-11-03T16:40:48.353

    Reputation: 36 228

    1

    Fortran (GFortran), 42 bytes

    READ*,I
    DO
    PRINT*,I
    IF(I==0)EXIT
    ENDDO
    END
    

    Try it online!

    rafa11111

    Posted 2015-11-03T16:40:48.353

    Reputation: 310

    1

    brainfuck, 25 bytes

    Note: This is a different "language" than this answer, because it requires a brainfuck variant that exits when the memory pointer is moved left of the initial position, whereas this needs a brainfuck variant that can read and write left of the initial position.

    ,.[[<+>->+<]>-]<+[<<]>[.]
    

    Try it Online!

    Explanation

    ,.             Read and print a character.
    [[<+>->+<]>-]  Write the range from the code point of the character down to one.
    <+[<<]>        Go to the first element in the sequence if the length is odd, otherwise
                    go to the cell before.
    [.]            Print the value at the pointer forever if the input is odd, determined by
                    if the pointer is on or outside the sequence of numbers in memory.
    

    Here are two other interesting solutions i found, which may be golfable (29 bytes each):

    ,.+++[->+>+++++<<]>--->+[<.>]
    ,.[->+>+>--[<+>--]<<<]>>[<.>]
    

    Herman L

    Posted 2015-11-03T16:40:48.353

    Reputation: 3 611

    1

    Lua, 41 bytes

    a=io.read()while q~="0"do print(a)q=a end
    

    Explanation:

    a=io.read(): read input from user and store in variable a

    while q~="0"do: compares q to the string "0", q starts as nil, which isn't "0" so the loop runs at least once. Because the input is a string we have to compare with the string "0", not the number 0

    print(a)q=a: prints a (1 or 0) and sets q to a, so if a = "1" the loop continues, if a = "0" the loop stops

    end: end of loop, like } in other languages

    Whitespace is not needed after parenthesis/quotation marks, for example print(a)q=a is equivalent to print(a) q=a

    Marre3

    Posted 2015-11-03T16:40:48.353

    Reputation: 11

    Hi and welcome to PPCG! – Herman L – 2018-05-26T10:48:21.733

    1

    Rust, 90 bytes

    use std::io::*;fn main(){let
    b=&mut[0];stdin().read(b);while{stdout().write(b);b==b"1"}{}}
    

    Try it online!

    Konrad Borowski

    Posted 2015-11-03T16:40:48.353

    Reputation: 11 185

    1

    FerNANDo, 37 bytes

    _ _ _ 1 _ _ _ _ C
    C
    0 0 1 1 0 0 0 C
    C
    

    Try it online!

    Erik the Outgolfer

    Posted 2015-11-03T16:40:48.353

    Reputation: 38 134

    1

    Z80Golf, 9 bytes

    00000000: cd03 80ff fe30 20fb 76                   .....0 .v
    

    Try it online!

    Disassembly

    start:
      call $8003
    loop:
      rst $38
      cp $30
      jr nz, loop
      halt
    

    The Z80Golf machine initializes whole memory and all registers to zero before loading the program.

    call $8003 calls getchar, which takes a byte from stdin to register a. On EOF, the register a does not change and the carry flag is set.

    rst $38 simulates a call to putchar which prints the register a. The function is actually at $8000, so PC slides through $00 bytes (NOPs) in the memory until it hits the address $8000.

    The rest is just a straightforward do-while loop in assembly, no tricks involved.


    Z80Golf, Byte IO, 8 bytes

    00000000: cd03 80ff b820 fc76                      ..... .v
    

    Try it online!

    Disassembly

    start:
      call $8003
    loop:
      rst $38
      cp b
      jr nz, loop
      halt
    

    The only difference is the use of cp b, where b is used in place of constant zero.


    Z80Golf, Byte IO, Tricky version, 8 bytes

    00000000: cd03 80b8 2002 ff76                      .... ..v
    

    Try it online!

    Disassembly

    start:
      call $8003
      cp b
      jr nz, infinity
      rst $38
      halt
    infinity:
    

    If the input is zero, rst $38 and then halt is executed, exiting the program normally. Otherwise, something weird happens:

    • PC goes to infinity:, slides through NOPs, and then putchar is executed.
    • The putchar has a ret instruction, so sp becomes 2 and execution is returned to the address $03cd.
    • Then putchar is executed again. sp becomes 4, pc is $b880.
    • Now pc wraps around and comes to $0000, the start of the program.
    • call $8003 is run, which overwrites the program so $80b8 becomes $0300.
    • getchar sets the carry flag, but we don't care anyway. EOF is hit so a is untouched.
    • Now cp b became nop, but jr nz, infinity is intact. Again putchar is run, sp becomes 6, pc is $0220. putchar again, sp = 8, pc is $76ff, putchar again, sp = 10 = $000a, pc = $0000.
    • The call $8003 became call $0303, which now effectively calls putchar instead. No problem, now one loop just prints a twice. Note that a call leaves $0300 to the memory, but fortunately $00 is NOP and $03 is inc bc, which does not affect the program's logic. (Single-byte inc does affect the flags, but double-byte ones don't, so jr nz isn't affected either.)
    • The call is now a heat wave filling the memory with $0300. Eventually, sp wraps around to $0002 again, and finally overwrites $cd03 into $0300, deleting the call .

    The heat wave is finally over, and the only thing left is:

      jr nz, infinity
      rst $38
      halt
    infinity:
    

    The conclusion is that we have an infinite loop printing 1 as a byte.

    Note that putchar is NOT an actual piece of code in memory. It is "simulated" when the PC hits $8000, along the ret instruction.

    Bubbler

    Posted 2015-11-03T16:40:48.353

    Reputation: 16 616

    1

    Pascal (FPC), 54 bytes

    var a:word;begin read(a);repeat write(a)until a<1 end.
    

    Try it online!

    AlexRacer

    Posted 2015-11-03T16:40:48.353

    Reputation: 979

    1

    Little Man Computer, 19 bytes (4 instructions)

    INP
    OUT
    BRZ 4
    BRA 1
    

    Which, when assembled into RAM, is:

    901 902 704 601
    

    Annoyingly, BRP means branch if positive or zero, making it useless for distinguishing between the two possible inputs. Therefore we have to use two seperate branching commands: BRZ (branch if zero) to escape the program, followed by a BRA (branch always) to continue the loop if the number is non-zero.

    An online interactive interpreter can be found here.

    FlipTack

    Posted 2015-11-03T16:40:48.353

    Reputation: 13 242

    1

    Backhand, 9 bytes

    {I>{@:1O_
    

    Try it online!

    A little convoluted, but that's Backhand's way.

    Explanation:

    {I>{@:1O_
    {           # Step left, bouncing off the wall and changing directions
     I          # Get input as a number
      >         # Enter loop by setting the direction to right
         :      # Dupe input
            _   # Step left if 1, otherwise right and change directions
           O    # Both output here, but are going in different directions
        @       # Terminate if 0
      >{  1     # Otherwise push 1 to the stack and restart the loop again
    

    Jo King

    Posted 2015-11-03T16:40:48.353

    Reputation: 38 234

    1

    brainfuck, 28 bytes

    >>,.[[>]+<[-<]<+>>]>[<]<<[.]
    

    Try it online!

    This should be portable to almost all implementations of brainfuck. If you don't mind negative cells, you can save 2 bytes by removing the initial >>.

    Explanation:

     >>                # Go right
     ,.                # Get input and print it once
     [[>]+<[-<]<+>>]   # Convert the number to binary while preserving it
     >[<]<<            # If the last digit of the binary is odd
     [.]               # Print the input forever
    

    Jo King

    Posted 2015-11-03T16:40:48.353

    Reputation: 38 234

    1

    !@#$%^&*()_+, 10 bytes

    *0_+!#(!#)
    

    Try it online!

    Explanation

    *0_+!#(!#)
    *             take byte of input
     0            push 48
      _+          subtract
        !#        duplicate and output
          (  )    while the top of the stack is not 0:
           !#     duplicate and output
    

    Conor O'Brien

    Posted 2015-11-03T16:40:48.353

    Reputation: 36 228

    1

    Alchemist, 24 bytes

    _->In_a+Out_a
    a->a+Out_a
    

    Try it online!

    I couldn't figure out a shorter way using only one output section. The closest I came was 25 bytes

    Explanation:

    _->In_a            # a = input
           +Out_a      # Output a
    a->a               # While a
        +Out_a         # Output a
    

    Jo King

    Posted 2015-11-03T16:40:48.353

    Reputation: 38 234

    1

    Gol><>, 5 bytes

    IZh1n
    

    Thanks to JoKing for helping golf this down further!!!

    Try it online!

    KrystosTheOverlord

    Posted 2015-11-03T16:40:48.353

    Reputation: 681

    1

    Tamsin, 19 bytes

    main="0"|{print 1}.
    

    Explanation

    The main production first tries to read a 0. If it succeeds, it is returned, and, because this is the main production, printed.

    Otherwise, it ignores the input and tries the alternative, which is {print 1}. The { } brackets denote a loop that continues running as long as its content succeeds, and a print statement always succeeds, so this loops forever.

    Esolanging Fruit

    Posted 2015-11-03T16:40:48.353

    Reputation: 13 542

    1

    Python 3, 41 bytes

    a=input()
    while(a=='1'):print(1)
    print(0)
    

    Try it online!

    movatica

    Posted 2015-11-03T16:40:48.353

    Reputation: 635

    1

    INTERCAL, 89 bytes

    DOWRITEIN.1PLEASE.3<-#1$.1DOCOMEFROM(2)DOREADOUT.1(2)PLEASE(1)NEXT(1)DO(1022)NEXTDOGIVEUP
    

    Try it online!

    Looking at some answers to this challenge, I noticed that the current INTERCAL answer was barely golfed at all, with 141 bytes 30 of which are whitespace. Not hard to outdo!

    Uses native INTERCAL-72 integer I/O, that is, the input is ZERO or ONE (or some translation thereof) with a trailing newline, and the output is in "butchered Roman numerals".

    Explanation:

    DO WRITE IN .1

    Inputs a number to the 16-bit variable .1.

    PLEASE .3 <- #1 $ .1

    Sets .3's value to 1 mingled with .1's value. Since .1 holds either 0 or 1, .3 is set to either 2 or 3.

    DO COME FROM (2)

    If execution would move on normally from statement (2), it goes here instead.

    DO READ OUT .1

    Prints the value in .1.

    (2) PLEASE (1) NEXT

    This is statement (2). It places itself on the NEXT stack and moves execution to statement (1). It does not trigger the COME FROM unless RESUMEd to.

    (1) DO (1022) NEXT

    This is statement (1). It NEXTS to statement (1022) in syslib, which then itself NEXTS to statement (1023) in syslib, which reads PLEASE RESUME .3. This pops a non-zero number of entries equal to .3 off the NEXT stack and resumes execution at the last one popped. Since there are at this point three entries on the NEXT stack, corresponding to (2), (1), and (1022) (RESUME works just fine without labels, it just so happens that all of the NEXTs here have them), and .3 is 2 or 3 depending on whether .1 is 0 or 1, this goes to and moves on from either (1) if .1 is 0, or (2) if .1 is 1. If this RESUMEs to (2), the COME FROM takes effect and begins an infinite loop (and since this outcome leaves the NEXT stack empty, the program does not disappear into the black lagoon after 80 loops).

    DO GIVE UP

    If (1) was RESUMEd to, execution moves here, and this terminates the program without an error.

    (I'll edit in a version with Turing Tape string I/O some time later.)

    Unrelated String

    Posted 2015-11-03T16:40:48.353

    Reputation: 5 300

    1

    NuStack, 82 bytes

    putchar(c:char):int;f(i:int):int{if(i>0)putchar('1');else while(1>0)putchar('0');}
    

    Been working on this compiler for a month and a half. Still very much a WIP, but finally at a point where I can do some PPCG with it :D

    Unlike all of my other languages, this isn't some toy, esoteric, interpreted language.
    It's a serious language that compiles directly to assembly (nasm syntax).

    I'll probably opt to get NuStack on TIO once it's notably more feature-complete than it currently is.

    Explanation:

    Ungolfed version:

    putchar(c: char): int;
    
    f(i: int): int {
        if(i > 0)
            putchar('1');
        else 
            while(1 > 0)
                putchar('0');
    }
    

    The first line is a function prototype that allows you to call a function defined elsewhere (think C header files)

    putchar in particular is currently the only function in libns, the language's standard library. It takes a single char, and outputs it to stdout. libns is currently available for 64bit linux, so it just makes a syscall using sys_write(), and 32bit "raw", ie not running on a kernel or operating system, where putchar will use the int 0x10 interrupt to print the character in TTY mode

    NuStack uses post-fix types, similar to TypeScript, and there is no type inference, so types must always be explicitly declared.

    NuStack also doesn't have type casts yet, or do..while loops, so this is, as far as I know, the golfiest way to do it.

    Skidsdev

    Posted 2015-11-03T16:40:48.353

    Reputation: 9 656

    1

    GolfScript, 13 bytes

    ~{.}{.p}while
    

    Explanation

    ~       # convert STDIN to an integer
    
    {.}     # while loop condition: remains the same--the input
    {.p}    # while loop body: print the input
    while
    

    This is one of my first golfs!

    clabe45

    Posted 2015-11-03T16:40:48.353

    Reputation: 121

    1

    Keg, 12 8 7 4 bytes

    {:|④
    

    Try it online!

    Explanation

    # Implicit input
    {:|  # While the duplicated item is nonzero:
       ④ # Output the item without popping
         # After that, Output the item remaining on the stack and stop the program
    

    user85052

    Posted 2015-11-03T16:40:48.353

    Reputation:

    This can now be 8 bytes due to implicit input

    – EdgyNerd – 2019-08-10T09:30:14.640

    4 bytes Try it online!

    – Lyxal – 2019-12-15T21:11:57.303

    1

    Enterprise, 128 bytes

    /©©//NDANDA/final disruptive class fdcBit{final immutable void main(){var Money i=read();;;write(i);;;while(i==1){write(i);;;}}}
    

    It's really annoying how the specification isn't very clear, so I had to guess a lot of things.

    Tux1

    Posted 2015-11-03T16:40:48.353

    Reputation: 41

    1

    Cascade, 10 bytes

    ?1/
    #?
    &#|
    

    Try it online!

    My first submission with my new language Cascade! Cascade is a tree-like esolang, similar to Pyramid Scheme, but a bit terser and with wrapping boundaries. Ungolfed, this looks more like:

     @ |
     ? /
     #|
     &|
      ^
     # |
     1 |
    

    First, the ? checks if the printed (#) input (&) is positive. If not, it goes left and terminates since it finds no more instructions. If so, it goes right to the ^, which first executes the left (#1, print 1), then goes to the right, which wraps around back to the ^ for an infinite loop. In the golfed code we use another ? which does a similar thing except with the center and the right, since we know the return value of # is always positive.

    Jo King

    Posted 2015-11-03T16:40:48.353

    Reputation: 38 234

    1

    MathGolf, 5  4  3 2 bytes

    -1 for dropping block marker

    q▲
    

    Explanation

    Implicit input
    Starts a block
    q  Output TOS without a newline.
     ▲ Execute the code block while the TOS is true. Executes at least once.
    Implicit output
    

    Try it online!

    user85052

    Posted 2015-11-03T16:40:48.353

    Reputation:

    I think you can drop the Ä since there's nothing before it now. – Unrelated String – 2019-10-13T03:16:14.997

    1

    Gaia, 3 bytes

    :p↺
    

    Try it online!

    Explanation

      ↺  While...
    :    Duplicating the top of stack leaves a true value on top:
     p   Print the top of the stack
    

    Input is taken implicitly in Gaia. Every iteration leaves the stack empty, but if there is no input left when it attempts to grab some, it simply takes the most recently given input again.

    Business Cat

    Posted 2015-11-03T16:40:48.353

    Reputation: 8 927

    1

    Python 3, 35 bytes

    a=input()
    while a:a=int(a);print(a)
    

    This is the best I can do, don't know if it's the optimal solution though.

    Explanation

    In Python 3, input() stores the input as a string, so even if the user types 0, it will be stored as '0', which is truthy. This allows me to make a kind of do-while loop, which will always run at least once since '0' and '1' are both truthy. However, I then convert a to an integer ('0' becomes 0 and '1' becomes 1). Now, if the user typed 0, it will not run again since the while loop is now while 0 and 0 is falsy. However, if the user typed 1, it will run forever since the while loop is now while 1 and 1 is truthy.

    Sagittarius

    Posted 2015-11-03T16:40:48.353

    Reputation: 169

    34 bytes – None – 2019-12-26T15:17:51.227

    @a'_' oh nice, didn't know that was a thing in Python 3.8 – Sagittarius – 2019-12-27T01:22:35.713

    1

    JavaScript, 39 32 Bytes

    x=+prompt();do{alert(x)}while(x)
    

    x=+prompt() gets input from user, and transforms it from a string to a number

    do{alert(x)}while(x) is a post test loop, so it always alerts X, then executes again if x not = 0

    Benji

    Posted 2015-11-03T16:40:48.353

    Reputation: 61

    It might... I didn't think of that (this is my first time doing any kind of code golfing, so it's probably not the best) – Benji – 2020-01-15T11:26:06.873

    1

    Python3, 40Bytes

    a=input()
    while int(a):print(a)
    print(a)
    
    • If input is 0 it will be printed once.
    • If input is 1 it will be printed forever.

    JBarrioGarcía

    Posted 2015-11-03T16:40:48.353

    Reputation: 11

    1

    Ruby, 32 30 bytes

    p gets.to_i<1?0:loop{p 1};exit
    

    Peter Lenkefi

    Posted 2015-11-03T16:40:48.353

    Reputation: 1 577

    1

    BotEngine, 24 3x7=21

    v 0
    >IS0>CP
      >eP
    

    The digit 0 is a no-op, allowing me to do stuff like this.

    SuperJedi224

    Posted 2015-11-03T16:40:48.353

    Reputation: 11 342

    1

    Loader, 30 bytes

    run from m.ldr (or replace the m in the last line with the name of the file)

    ~B:set B =@IN
    print B
    B:load m
    

    Theoretically infinite, in practice will result in Error: Stack Overflow in the reference implementation.

    With comments:

    ~B:set B =@IN !!If B is zero (the default for uninitialized variables), set B to a number from the input
    print B !!Exactly what it says on the tin
    B:load m !!If B is nonzero, load a separate instance of this module on a copy of the current memory space
    

    SuperJedi224

    Posted 2015-11-03T16:40:48.353

    Reputation: 11 342

    1

    Math++, 11 bytes

    ?>a
    a
    2*a>$
    

    Explanation:

    1:Set a to a number from the input
    2:Print a (the designator ">out" is implied if none is specified)
    3:If a is 1, go to 2; if a is 0, exit
    

    SuperJedi224

    Posted 2015-11-03T16:40:48.353

    Reputation: 11 342

    Could you add an explanation? – Addison Crump – 2015-11-04T12:45:46.373

    @VoteToClose Done – SuperJedi224 – 2015-11-04T13:49:35.377

    1

    APL, 9 bytes

    {⎕←⍵:∇⍵}⎕
    

    Explanation:

              ⎕  ⍝ read a number from the keyboard
    {⎕←⍵:   }    ⍝ output it, and if it is true:
          ∇⍵     ⍝ call the function again with that input
    

    marinus

    Posted 2015-11-03T16:40:48.353

    Reputation: 30 224

    1

    Pip, 5 bytes

    WaPaa
    

    In pseudocode:

    while(a)
        print(a)
    autoprint(a)
    

    a is the first command-line argument. (The OP commented on the sandbox post that this was an acceptable way to take input, even though Pip is capable of taking input from stdin.)

    DLosc

    Posted 2015-11-03T16:40:48.353

    Reputation: 21 213

    WaPaa. I love these weird types of languages because when you put them into TTS programs they have a conniption. – Cyoce – 2015-12-16T18:29:23.677

    1

    HSPAL, 60 bytes

    110000
    000000
    420000
    400000
    420000
    400000
    120000
    030000
    040000
    010000
    

    SuperJedi224

    Posted 2015-11-03T16:40:48.353

    Reputation: 11 342

    1

    Stack, 67 bytes

    { '1' print a call } `a set '' input num 1 = a { '0' print } ifelse
    

    Run by placing the stack folder into your python lib folder, and running py -3 -m stack.cli truth.stack

    anOKsquirrel

    Posted 2015-11-03T16:40:48.353

    Reputation: 361

    1

    3var, 6 bytes

    ">|[w]
    

    Each 0 or 1 is followed by a newline. I've never actually used 3var's loop features before, so this is a first for me.

    Explanation

    "         Read input into R
     >        Copy R into A
      |[ ]    Do while A > B...
        w     Output R
    

    Sp3000

    Posted 2015-11-03T16:40:48.353

    Reputation: 58 729

    1

    Browser LiveScript, 54 bytes

    switch prompt!
    |'0'=>alert 0
    |'1'=>while true
     alert 1
    

    I believe I can use prompt and alert instead of STDIN and STDOUT with browser languages, is that correct?

    Zane Martin

    Posted 2015-11-03T16:40:48.353

    Reputation: 31

    Yes, you are correct. – Conor O'Brien – 2016-01-16T18:17:42.440

    1

    pb, 21 bytes

    ^t[B]v<w[B!48]{>b[T]}
    

    There is currently only one pb interpreter. It's called pbi and it's hot garbage. I wrote it, and I have 0 other experience writing that kind of program. The pb variables are global variables in pbi's source code, loops are implemented recursively (the tokenizer turns the entire code of the loop into a single token, then when it's reached that token is sent back into the tokenizer and is executed until the condition becomes false), the function to evaluate an expression is def expression(e): return eval(e, globals())... overall it manages to do basically nothing right and I'm probably going to rewrite it.

    I bring this up because pbi in its current state only outputs anything when the program terminates, so a 1 input makes it look like it does nothing forever. Here are the reasons why I believe this answer is valid anyway:

    • The canvas is being written to, which is how output works in pb. If the loop were to eventually terminate somehow, a lot of 1s would be outputted at once.
    • There is a way to watch program execution in pbi. It's intended for debugging and it's about as horrible as the rest of the interpreter, but the flag -d= followed by a number will print the canvas and pause execution for that many milliseconds after each tick.

    How it works

    ^        # Move the brush to Y=-1, where input lives
    t[B]     # Save the value at (0, -1) to T
    v<       # Go to (-1, 0)
    w[B!48]{ # While the space under the brush doesn't have the value 48 ('0'):
               # (this loop is guaranteed to be entered at least once)
      >        # Increase the brush's X coordinate by 1
      b[T]     # Save the value in T to the brush's current coordinates
    }        # If the input was '0', the space under the brush has the value 48 and the loop is
             # terminated. Otherwise, it repeats indefinitely.
    

    undergroundmonorail

    Posted 2015-11-03T16:40:48.353

    Reputation: 5 897

    1

    C++, 83 77 76 bytes

    #include<iostream>int main(){int n;std::cin>>n;do{std::cout<<n;}while(n);}
    

    Ungolfed:

    #include <iostream>     // Needed for IO
    int main()              // Necessary for any C++ program
    {
        int n;              // Declare integer variable
        std::cin >> n;      // Retrieve input from STDIN
        do                  // Perform the following at least once
        {
            std::cout << n; // Output number, either 0 or 1
        } while(n);         // Continue doing so if number wasn't 0
    }
    

    Thanks to @feersum for letting me know that input can only be 0 or 1 I saved 6 bytes.
    Thanks to @Alex A for saving another byte by removing a space

    Tas

    Posted 2015-11-03T16:40:48.353

    Reputation: 593

    n is already 0 or 1 after you read it. n=!!n does nothing at all! – feersum – 2015-11-04T02:15:02.207

    Oh so I needn't account for situations where STDIN contains numbers that aren't 0 or 1? – Tas – 2015-11-04T02:18:43.797

    0 and 1 are the only possible inputs. – feersum – 2015-11-04T02:22:18.657

    Sweet! Thanks for letting me know! I will update my answer. – Tas – 2015-11-04T02:22:58.847

    You can remove the space before <iostream>, saving 1 byte. – Alex A. – 2015-11-04T03:04:43.760

    With certain compilers (e.g. gcc-5.1) you can omit the return type of main which would save you four bytes. – sweerpotato – 2015-11-04T09:35:15.197

    You can save a byte because you don't need to wrap the std::cout<<n statement into a block, do std::cout<<n;while(n); suffices. – Neil – 2015-11-08T00:53:13.377

    1

    ???, 37 bytes

    ?!";.;.--,'",'";,-,,,,,'";...'";!-'"
    

    This is a simple translation of mbomb's Brainfuck solution.

    Alex A.

    Posted 2015-11-03T16:40:48.353

    Reputation: 23 761

    1

    SWI-Prolog, 45 bytes

    m(X):-put(X),(X=48,halt;m(X)).
    :-get(X),m(X).
    

    The put and get predicates work with character codes, so we need to test against 48 for the 0 case. If that succeeds, halt; if it fails, try m(X) recursively instead.

    To run from Linux command-line, put the code in a file and execute swipl -qs truth.pro. (The q is optional; it suppresses extra output from the interpreter.) Or, try it here.

    DLosc

    Posted 2015-11-03T16:40:48.353

    Reputation: 21 213

    I guess you can remove the halt, since directives are only executed once (next() and close()). But the link somehow doesn't work, it gives an error. – Mostowski Collapse – 2015-11-07T10:25:30.180

    On the other hand to be ISO Prolog compliant, you would need initialization/1 http://www.swi-prolog.org/pldoc/man?predicate=initialization/1, since arbitrary directives are not allowed. The above would run in GNU Prolog.

    – Mostowski Collapse – 2015-11-07T10:30:35.483

    @j4nbur53 The reason why I included halt is that with swipl on Ubuntu, not including it drops to a user prompt after the above code executes. I don't know what the exact policy on that is, but it seems like extraneous output that can be avoided, so I figured I'd better avoid it.

    – DLosc – 2015-11-07T23:04:24.150

    1

    PHP, 33 37 39 29 bytes

    Pretty straight forward:

    for($f=fgetc(STDIN);$f&print$f;);
    

    Runs from command line:

    php truth.php 1
    

    Edits

    • Added 10 bytes as the program must take input from STDIN if possible. Thanks to Martin Büttner for pointing it out. :)
    • Saved 2 bytes by using if and for instead of while. Thanks to BLackhole
    • Saved 2 bytes by placing everything into the for-loop. Thanks to fschmengler.
    • Saved 2 bytes by rewriting the 2nd expression of the for-loop.

    insertusernamehere

    Posted 2015-11-03T16:40:48.353

    Reputation: 4 551

    Actually it's 39 because you have to add either <? or the -r flag – Fabian Schmengler – 2015-11-05T16:11:32.840

    But you can save one byte more with this: <?for($f=fgetc(STDIN);(print$f)&$f;); - print is like echo but has a return value (always 1) – Fabian Schmengler – 2015-11-05T16:17:28.983

    @fschmengler Thanks for your feedback. I made it even 2 bytes shorter, by switching (print$f)&$f to $f&print$f. There is a general discussion about the byte count here: Is the PHP opening tag mandatory in byte count?.

    – insertusernamehere – 2015-11-10T19:15:03.753

    1

    Batch, 31 bytes

    @IF 0%1==01 echo 1&%0 1
    @echo 0
    

    On my machine, running <script name> 1 twice from the command prompt caused CMD to crash. The first time it stopped after printing a lot of lines with 1s on it. (Presumably because of CMD running out of memory.)

    Explanation

    @ – This tells CMD not to print the commands on this line. (Output will still be printed.)
    %1 – This will be substituted with the first argument given.
    %0 – This will be substituted with the script name.

    The first line will output 1s and then launch the script itself with an argument 1 if the script was called with the argument 1. Otherwise, the condition evaluates to false and the script will proceed to the second line. It will then output 0 and exit.

    user2428118

    Posted 2015-11-03T16:40:48.353

    Reputation: 2 000

    1

    TML, 14 bytes

    d={1 or 0}/0000-1111/
    

    e.g

    d=1/0000-1111/
    

    or

    d=0/0000-1111/
    

    Finally I was able to use my language for something :) Since TML hasn't got an IO support (yet), the value must be hardcoded in the tape, but it should work as intended! If the value is 0 it halts (goes to card 0), else it will print an infinite string of 1s

    Otherwise I have a 2 cards solution using the default tape:

    {0 or 1}/0000-1112/0112-1112/
    

    WizardOfMenlo

    Posted 2015-11-03T16:40:48.353

    Reputation: 843

    1

    ><>, 15 bytes

    i6%   \
    ::n?!;>
    
    i        Input character (by code point)
     6%      Modulo the top item on the stack by 6
          \  go to second layer
    
    ::       Duplicate the top item on the stack twice
      n      Print the top item of the stack as an integer
       ?!    If the top item on the stack is 0:
         ;    End program.
          >  Otherwise, move forward.
    

    clap

    Posted 2015-11-03T16:40:48.353

    Reputation: 834

    1

    Burlesque, 6 bytes

    riqJw!
    

    Explanation:

    ri -- read int
    qJ -- shortcut for {J}, which is a shortcut for {^^}
          ^^ = duplicate
    w! -- while loop
    

    Mind you that the reference implementation of the interpreter buffers output so you'll run out of memory sooner or later before seeing any output in case you provide "1" on STDIN.

    mroman

    Posted 2015-11-03T16:40:48.353

    Reputation: 1 382

    1

    GolfScript, 9

    ~{.p.}do;
    

    Equivalent to q~{_p}h; in CJam.

    aditsu quit because SE is EVIL

    Posted 2015-11-03T16:40:48.353

    Reputation: 22 326

    1

    Microscript II, 3 bytes

    N[p
    

    Essentially a translation of the Microscript answer

    SuperJedi224

    Posted 2015-11-03T16:40:48.353

    Reputation: 11 342

    1

    Aubergine, 33 24 bytes

    =Ao-b1+bi=oA=bB-bA:Ab=ia
    

    Aubergine in a nutshell:

    Aubergine has four variables and four 2-argument instructions. The variables a and b can be indirected as A and B to point to locations in the program, which can be read and written just like data, making it inherently self-modifying. The other variables are o, which refers to input or output depending on whether it is the second or first argument of the assignment instruction, and i, which is the instruction pointer. The four instructions are assignment (=), addition (+), subtraction (-), and conditional jump (:). The only constant literal available is 1. All variables are initialized to zero.

    Ungolfed:

    =Ao                       Set the first character in the program to input character.
    -b1                       Set b=-1.
    +bi                       Add 6 to b, yielding 5, which is the location of the "1"
    =oA                       Output the input value.
    =bB                       Set b to the value of where b points, viz. "1"
    -bA                       Subtract the input value from b, yield 0 if "1" and -1 if "0"
    :Ab                       Conditionally jump to the location corresponding to the input 
                              value, either 48 or 49. Either is past the end of the program,
                              so execution will terminate. This will only happen if b is
                              nonzero, which happens when the input value was not "1".
    =ia                       If we made it here, then the input was "1" and now a and b are
                              both zero, just like they were when the program began, so
                              we jump back to just after the input was read and repeat.
    

    quintopia

    Posted 2015-11-03T16:40:48.353

    Reputation: 3 899

    1

    DStack, 7 bytes

    04KKCKT
    

    I invented the language after the challenge began, but before I see it.

    DarkPhantom

    Posted 2015-11-03T16:40:48.353

    Reputation: 191

    Because it's impossible to prove when somebody saw a challenge, claiming that you didn't see a challenge before you created a language normally doesn't make it eligible. However, since this is a catalog challenges, all languages are welcome, even those created after the challenge, so long as they meet our criteria for being a programming language. Just something to keep in mind for the future :) Welcome to PPCG!

    – Mego – 2015-11-11T01:06:40.287

    @Mego I already know that, I wrote that just to mention something (besides I had to write more because the answer was too short). But still thank you! – DarkPhantom – 2015-11-11T01:12:40.680

    1

    WTFZOMFG, 5 bytes

    /\(\)
    

    Explanation:

    /        input a decimal number and store it in the cell
     \       print it
      ( )    while the cell is not 0
       \     print it
    

    alephalpha

    Posted 2015-11-03T16:40:48.353

    Reputation: 23 988

    1

    Arcyóu, 19 bytes

    (?(#(l))(@ 1(p 1))0
    

    Explanation:

    (? (# (l)) ; If-statement on the input as int
      (@ 1     ; While 1:
        (p 1)) ; Print 1
      0        ; Else: Print 0
    

    This is actually three bytes shorter than saving it in a variable and while looping it without the if-statement.

    jqblz

    Posted 2015-11-03T16:40:48.353

    Reputation: 2 062

    1

    JavaScript, 27 29 bytes

    for(x=prompt();alert(x),+x;);
    

    The only interesting part is the +x which converts x to a number, otherwise the string '0' would return true.

    Adam Dally

    Posted 2015-11-03T16:40:48.353

    Reputation: 331

    @intrepidcoder Not to steal your thunder, but... :) – Adam Dally – 2015-11-24T02:36:27.197

    +1 Clever way to get rid of that trailing ; – intrepidcoder – 2015-11-26T03:52:03.363

    But it doesn't output 0... – Qwertiy – 2016-04-11T17:06:02.403

    I completely didn't realize I wasn't following the prompt correctly..oops. You just almost beat me out, ha ha, but not quite. Thanks for pointing it out. – Adam Dally – 2016-04-16T03:42:01.987

    1

    Go, 93 bytes

    Terribly long.

    package main
    import ."fmt"
    func main(){p:=Println
    a:=""
    Scanln(&a)
    if a=="1"{for{p(a)}}
    p(0)}

    cat

    Posted 2015-11-03T16:40:48.353

    Reputation: 4 989

    1

    Milky Way 1.0.0, 13 bytes

    '?{0b~!~&{!}}
    

    Explanation

    '              # read input from command line
     ?{  ~ ~    }  # if-else statement
       0b          # push 0 to stack and compare to the previous TOS
          !        # output the TOS
            &{ }   # infinite loop
              !    # output the TOS
    

    Milky Way (current version), 13 bytes

    '?{0b_!_&{!}}
    

    Usage

    ./mw <path-to-code> -i <input-integer>
    

    Zach Gates

    Posted 2015-11-03T16:40:48.353

    Reputation: 6 152

    1

    Mouse-2002, 8 bytes

    (?^(b!))
    

    ==

    while input():
        print(1)
    

    cat

    Posted 2015-11-03T16:40:48.353

    Reputation: 4 989

    1

    Java, 95 bytes

    class A{public static void main(String[]c){do System.out.print(c[0]);while(c[0].equals("1"));}}
    

    Randolph

    Posted 2015-11-03T16:40:48.353

    Reputation: 11

    1

    ROOP, 12 bytes

    I
    wX
    
    
    nw
    hO
    

    The w operator reads a number from the keyboard because it has an input object above (I). The input object moves to the right and the number created falls down. The X operator removes the input object, the n operator checks whether the number is zero. If the number is zero, the h operator prints the number and ends the program. If it is nonzero, the number moves to the right and the w operator infinitely prints the number.

    DarkPhantom

    Posted 2015-11-03T16:40:48.353

    Reputation: 191

    1

    Jelly, 3 bytes

    Ȯ¹¿
    

    Try it online! (Keep in mind that online interpreters and infinite outputs aren't precisely compatible.)

    How it works

      ¿  Convert the two previous atoms/chains into a while loop.
     ¹     Identity function. (condition)
    Ȯ      Output/print without newline. (loop body)
    

    Dennis

    Posted 2015-11-03T16:40:48.353

    Reputation: 196 637

    1

    DUP, 12 bytes

    [[$.$][$.]#]
    

    Try it here!

    Anonymous lambda. Usage:

    0[[$.$][$.]#]!
    

    or

    1[[$.$][$.]#]!
    

    Explanation

    [            {start lambda}
     [$.$]       {output inputnum and check if it's truthy}
          [$.]   {only output inputnum if previous condition is true}
              #  {while-loop previous 2 lambdas}
               ] {end lambda}
    

    Mama Fun Roll

    Posted 2015-11-03T16:40:48.353

    Reputation: 7 234

    1

    Piet, 16 14 codels

    codel size 10 for better visibility

    enter image description here

    Pseudocode:

    INN → DUP → PTR → OUN → END
           ↑     ↓  
          PSH ← OUN
    

    Old solution (16 codels)

    Truth Machine Piet version

    Pseudocode:

    INN → DUP → DUP → PTR → OUN → END
                 ↑     ↓
                DUP ← OUN
    

    Much simpler than the oddly complicated Piet truth machine on esolangs.org.

    Works on PietDev and with npiet 1.3a

    M L

    Posted 2015-11-03T16:40:48.353

    Reputation: 2 865

    1

    Gogh, 8 7 6 bytes

    Saved a byte thanks to @ZachGates

    {ƤØ}?x
    

    Run this in the command line like:

    $ ./gogh nio '{ƤØ}?x:' <input>
    

    Explanation

         Input is implicit
    {    Push this code block
     Ƥ    Print TOS
     Ø    Loop forever
    }
    ?    If STOS is falsy, remove the codeblock from the stack
    x    run the code block if there is one, else do nothing
         If there is no codeblock, the program will implicitly output 0
    

    Downgoat

    Posted 2015-11-03T16:40:48.353

    Reputation: 27 116

    1

    Wierd, 225 bytes

    Unlike other languages where the symbols in a program determine which instructions are executed, in Wierd, it is the bends in the chain of arbitrary symbols that determine which instructions are executed.

    From the website:

    First, a Riddle:
    Q: What do you get when you put three marginally-sane programmers on a mailing list with the Befunge and BrainF*** programming languages?
    A: You get BeF***, and then they get Wierd.
    ...
    Chris Pressey then jumped on it, created the angle-to-instruction mapping, and christened the entire mess "Wierd"--a cross between the words "weird" (which the language seemed to be) and "wired" (which would describe the appearance of programs written in the language).

    Try it online at http://catseye.tc/installation/Wierd_(John_Colagioia)

    0           +  ++++ ++++++++++ ++++
    1+  +++ +++  ++  +  +        ++  +
      ++ +  + +  +  +   +        +  +
         +  +  +   +    +          +
          ++++  +++     +     ++  +
            +            +  ++  ++
             +++++++++++++++
    

    Jerry Jeremiah

    Posted 2015-11-03T16:40:48.353

    Reputation: 1 217

    1

    Come Here, 29 bytes

    0ASKaCOME FROMa-48 1TELLaNEXT
    

    SuperJedi224

    Posted 2015-11-03T16:40:48.353

    Reputation: 11 342

    1

    Befunge, 7 x 2 = 14 bytes

    ~:#v_.@
       >:.
    

    Leaky Nun

    Posted 2015-11-03T16:40:48.353

    Reputation: 45 011

    There's a lot of answers in this question so you might have missed it, but for comparison here are the links to two other Befunge answers :) link1, link2 (these are accessible via the leaderboard snippet)

    – Sp3000 – 2016-03-30T15:38:12.330

    1

    Fuzzy Octo Guacamole, 8 bytes

    ^X({@}X)
    

    ^ pushes input, X prints the top item on the stack. ( starts an infinite loop. {@} ends the program (@) only if the top item on the stack is falsy, like 0. The X prints the top item on the stack (again), and the ) ends the loop.

    So it repeats, printing and checking forever.

    Rɪᴋᴇʀ

    Posted 2015-11-03T16:40:48.353

    Reputation: 7 410

    "languages created after this challenge are allowed to compete" – Martin Ender – 2016-11-17T08:27:37.087

    1

    Pylongolf2, 11 bytes

    1r1=?1>~<¿
    

    Explanations:

    1           push 1 to the stack
     r          pick a random number between 0 and 1
      0=        push 1 to the stack and compare them
        ?1>~<¿  if true, push 1 to the stack then print it forever.
                terminate
    

    user47018

    Posted 2015-11-03T16:40:48.353

    Reputation:

    1

    Oration, 101 bytes

    start a function t with x
    inhale
    to iterate, 1
    literally, print x
    if not x:break#
    invoke t with input
    

    Very long. Starts a function called t with arguments x.

    Inhale is a command used to keep the program running, you need oxygen to execute. :P

    to iterate, starts a while $1 loop, so this becomes while 1:.

    literally, print x just prints x, the function input.

    if not x:break# is a simple if statement. The # is there because the compiler appends a : to it, so that becomes if not x:break#:. It happens to be golfier than the following good code with normal syntax.

    if not x
    goodbye
    

    invoke t with input calls the function.

    Transpiles to:

    #!/usr/bin/env python3
    def t(x):
        while 1:
            print x
            if not x:break#:
    t(input("~> "))
    

    Rɪᴋᴇʀ

    Posted 2015-11-03T16:40:48.353

    Reputation: 7 410

    Could you include the transpiled source? – Conor O'Brien – 2016-04-08T17:34:56.640

    @CᴏɴᴏʀO'Bʀɪᴇɴ sure. BTW, there might be a bug about the function call before 2 backtrackings. – Rɪᴋᴇʀ – 2016-04-08T17:42:10.890

    1

    Reng v.3.3, 6 bytes

    i:n?~!
    

    Try it here!

    This takes input I, duplicates, outputs as number, ? skips if true. If false, ~ is met and the program ends. Otherwise, we skip ~ then skip i with !, and it repeats.

    Conor O'Brien

    Posted 2015-11-03T16:40:48.353

    Reputation: 36 228

    1

    Pyke, 4 bytes

    ​
    I1r
    

    Explanation:

    print(top_of_stack) (if first run, print input())
    if pop(stack):
        top_of_stack = 1
        goto_start()
    

    Try it here!

    Blue

    Posted 2015-11-03T16:40:48.353

    Reputation: 26 661

    1

    Tellurium, 11 bytes

    I?1|[i|^;]^
    

    This program asks for input and converts it to an integer (I). After that, it checks if the input is 1. If it's 1, output 1 forever ([i|^;). If it's 0, output 0.

    m654

    Posted 2015-11-03T16:40:48.353

    Reputation: 765

    1

    eacal, 58 bytes

    label l
    put set n cast number arg number 0
    if get n
    goto l
    

    put outputs n, which is cast to the first argument. Call like:

    node eacal.js tm.eaa <input>
    

    Conor O'Brien

    Posted 2015-11-03T16:40:48.353

    Reputation: 36 228

    1

    Racket, 36 bytes

    (do([n(read)])((= n 0)n)(println n))
    

    Winny

    Posted 2015-11-03T16:40:48.353

    Reputation: 1 120

    1

    JQuery, 63 57 Bytes

    if($("input").val()==1){while(1){alert(1)}}else{alert(0)}
    

    Try it!

    Ronronner

    Posted 2015-11-03T16:40:48.353

    Reputation: 129

    1

    Perl 6, 28 bytes

    {.say;.say while $_}(+slurp)
    

    bb94

    Posted 2015-11-03T16:40:48.353

    Reputation: 1 831

    1

    PowerShell, 22 21 bytes

    Variable $a into the pipeline, prints once, then prints again if the input evaluates as true. Less elegant than TimmyD's but shorter.

    $a|%{$_;while($_){$_}}
    

    After looking at his though it could also be written as below, dropping it to 21 bytes

    $a|%{do{$_}while($_)}
    

    Chirishman

    Posted 2015-11-03T16:40:48.353

    Reputation: 389

    Sadly, taking input via a pre-defined variable isn't allowed here, since PowerShell can read from STDIN. – AdmBorkBork – 2016-08-30T13:33:09.167

    1

    ><>, 6 bytes

    Takes input from command line i.e. ./fish.py program.fish -v 1

    :?!;:n
    

    Explanation:

    :   ?  !; :n      ... (Since this is fish, it wraps around and repeats)
    ^   ^  ^  ^
    |   |  |  |
    |   |  |   Duplicates topmost value on stack and outputs it
    |   |  | 
    |   |   Skips the next instruction
    |   |    
    |    Checks if topmost value is 0 and if so, skips the next instruction, going straight to the ; which terminates the program
    |
     Duplicates topmost value on stack
    

    gowrath

    Posted 2015-11-03T16:40:48.353

    Reputation: 885

    1

    Python 2, 33 bytes

    Golfing suggestions welcome :)

    x=input()
    while x:print 1
    print 0
    

    gowrath

    Posted 2015-11-03T16:40:48.353

    Reputation: 885

    This doesn't work.

    – ABcDexter – 2016-09-01T09:24:08.450

    1

    @ABcDexter Ah you're right, I forgot the int. I actually initially wrote this in python2 where you don't need the int conversion and added the parentheses in later. Check it now.

    – gowrath – 2016-09-01T09:26:50.477

    Somebody already beat you to the Python 2 solution. – Mego – 2016-09-01T09:31:34.463

    @Mego Theirs is incorrect.

    – gowrath – 2016-09-01T09:32:58.583

    1@Mego Apparently, no. As the other code takes input again and again in the while condition. – ABcDexter – 2016-09-01T09:33:47.063

    1There's also this one – Mego – 2016-09-01T09:34:10.273

    @Mego I didn't see that; it's excellent! Thanks for pointing it out :) – gowrath – 2016-09-01T09:35:15.777

    That one is brilliant :D – ABcDexter – 2016-09-01T09:37:19.397

    1

    Ru, 11 9 bytes

    »Ϟα;¿{»α}
    

    This look way too long

    TuxCrafting

    Posted 2015-11-03T16:40:48.353

    Reputation: 4 547

    1

    Straw, 17 bytes

    (1>:&)(:&) <1='0>
    

    TuxCrafting

    Posted 2015-11-03T16:40:48.353

    Reputation: 4 547

    1

    Lua, 34 Bytes

    repeat print(arg[2])until arg[2]<1
    

    arg[2] contains the first command line argument, (arg[1] contains the filename)

    Give an input through the command line, and it shall spam it if it's 1, or once if it's not.

    Simple enough.

    ATaco

    Posted 2015-11-03T16:40:48.353

    Reputation: 7 898

    1

    Brainfuck, 5 Bytes Non-Competing.

    ,.[.]
    

    Non Competing, because I highly doubt that SOP's count as 1, or that the input will be a SOP or NUL.

    I just think it's a neat thing.

    ATaco

    Posted 2015-11-03T16:40:48.353

    Reputation: 7 898

    1

    Logicode, 43 bytes

    circ l(a)->1+l(a)
    cond binp->out l(a)/out 0
    

    Logicode can't output while in an infinite circuit loop, so this program will output ALL of the 1's after the infinite loop (when the program encounters a 1).

    If a truth machine that goes into an infinite loop when 1 is entered and has no output is acceptable, the code can be shorter by 2 bytes:

    circ l(a)->1+l(a)
    cond binp->out l(a)/out 0
    

    clismique

    Posted 2015-11-03T16:40:48.353

    Reputation: 6 600

    1

    braingasm, 5 bytes

    ;:[:]
    

    The braingasm instruction ; and : are very similar to the brainfuck instructions , and ..

    ; gets some input from stdin, reads it as an integer, and stores the integer value in the current cell. : prints the value of the current formatted as an integer. Like in brainfuck, [] loops while the current cell is non-zero.

    daniero

    Posted 2015-11-03T16:40:48.353

    Reputation: 17 193

    1

    reticular, 8 6 bytes

    [do?!]
    

    Try it online!

    This is a function. g calls the function with the TOS as input. do outputs without popping, ?! skips the next char if it's 1. Because of the way functions work, the actual constructed function is:

    do?!;
    

    This is made in a child instance of the program. Thus, if the TOS is 0, then it terminates (exits function).


    Previous versions:

    8 bytes:

    indp?!;!
    

    11 bytes:

    in@@p;
    p1 <
    

    This goes right by @@ if 0, and up if 1 (wrapping around to <) and prints 1 infinitely. It's in better style to do it this way, y'know, more readable. Because 2D languages are easy to read.

    Conor O'Brien

    Posted 2015-11-03T16:40:48.353

    Reputation: 36 228

    1

    PHP, 30 33 bytes

    do{echo$o=$argv[1];}while($o);
    

    Oops, didn't see the 7 other pages, one of which contains a better PHP entry.

    Old 1

    do{echo$argv[1];}while($argv[1]);
    

    CT14.IT

    Posted 2015-11-03T16:40:48.353

    Reputation: 231

    1

    Javascript, 33 32 Bytes

    i=prompt();do{alert(i)}while(+i)
    

    uses the +i syntax (thanks ETHproductions)

    Old 1

    i=prompt();do{alert(i)}while(i>0)
    

    CT14.IT

    Posted 2015-11-03T16:40:48.353

    Reputation: 231

    10 is a falsy value in JavaScript, so you can shorten this by one byte with i=prompt();do{alert(i)}while(+i) – ETHproductions – 2016-11-01T16:26:32.493

    Nice one, wasn't aware of that short cut! – CT14.IT – 2016-11-01T16:31:47.400

    1

    D - 87 bytes

    void main(){import std.stdio,std.conv;int i=readln[0..$-1].to!int;do i.write;while(i);}
    

    Zacharý

    Posted 2015-11-03T16:40:48.353

    Reputation: 5 710

    0

    Doxical, 11 bytes

    [^]A{AdA}dA
    

    First answer in Doxical!

    Doxical is my new language, which is designed to be difficult to program in, and is grid-based. Also, there aren't any newlines in Doxical code, so every Doxical program is a one-liner.

    Explanation (note that there are no comments in Doxical, this is just for clarification):

    [^]         # Asks for user input, if input = 1, puts 1 into the Value,
                # If 0, puts 0 into the Value
       A        # Declares variable A as the Value
        {A  }   # While A > 0:
          dA    # Output A in decimal (1 forever)
             dA # Outside the while loop, output A in decimal (0 once)
    

    Yes, "Value" is meant to be capitalised, see docs for more details.

    clismique

    Posted 2015-11-03T16:40:48.353

    Reputation: 6 600

    0

    BrainInt, 5 bytes

    &^[!]
    

    Explanation:

    &     # Take user input, and store in current cell
     ^    # Boolean-ate current cell (nonzero -> 1, 0 -> 0)
      [ ] # Loop (while cell != 0)
       !  # Print current cell as integer
    

    NoOneIsHere

    Posted 2015-11-03T16:40:48.353

    Reputation: 1 916

    0

    T-SQL, 22 bytes

    s:print @ if @>0goto s
    

    requires a variable with the name @, e.g.:

    DECLARE @ BIT = 0
    
    s:print @ if @>0goto s
    

    grabthefish

    Posted 2015-11-03T16:40:48.353

    Reputation: 161

    0

    stacked, 10 bytes

    [:out]loop
    

    Assumes input is on TOS. Try it here!

    Loops [:out] while TOS is truthy, repeating at least once. Surround with [] for a proper function.

    Conor O'Brien

    Posted 2015-11-03T16:40:48.353

    Reputation: 36 228

    0

    tcl, 40

    gets stdin r
    puts $r
    while \$r {puts $r}
    

    demo

    sergiol

    Posted 2015-11-03T16:40:48.353

    Reputation: 3 055

    0

    Deadfish i, 16 bytes

    0<+I]
    1<.
    2<+.[2
    

    As this language does not support input, you must replace I with either an empty string (=0) or + (=1). The program works on my interpreter, which may or may not work like the author of the language intended.

    I'm not sure how to score this program. Currently the byte count is for 1-variant.

    fergusq

    Posted 2015-11-03T16:40:48.353

    Reputation: 4 867

    0

    Alice, 8 bytes

    i.o.&#@#
    

    Try it online!

    Explanation

    i     Read a byte X from STDIN (gives 48 for input 0, 49 for input 1).
    .o    Duplicate X and print that byte back to STDOUT.
    .     Duplicate X again.
    &#    Skip X commands. Since the program contains 8 commands, if X = 48, 
          this doesn't really do anything. The IP will just loop through the 
          code six times while skipping all commands. But if X = 49, it skips
          one more command, so the next command is skipped.
    @     Terminate the program (only gets executed for input 0).
    #     Skip the i at the beginning of the next iteration.
    

    This code loops indefinitely, unless the @ terminates it on the first iteration.

    Martin Ender

    Posted 2015-11-03T16:40:48.353

    Reputation: 184 808

    0

    REXX, 33 bytes

    pull n
    do while n
      say n
      end
    say n
    

    idrougge

    Posted 2015-11-03T16:40:48.353

    Reputation: 641

    0

    Braingolf, 7 bytes

    !?[!_+]
    

    Try it online!

    Explanation:

     ?          If last element in stack is > 0
    !           Prevent if from consuming checked element
      [         Begin while loop (at the end of each iteration of a while loop, the first
                Item in the stack will be decremented by 1, the loop will exit if it reaches 0
       !_       Print the last item on the stack without removing it
         +      Attempt to add together the last 2 items in the stack
                As there is only one item, add it to itself
           ]    End while loop, each time the code reaches this point it will decrement the
                first item in the stack by 1, and will only exit the loop if the item == 0
                Implicit Endif, Implicit output of the last item in the stack
    

    Skidsdev

    Posted 2015-11-03T16:40:48.353

    Reputation: 9 656

    0

    JavaScript (ES5), 40 bytes

    function(x){x?while(1)alert(1):alert(0)}
    

    user69033

    Posted 2015-11-03T16:40:48.353

    Reputation:

    0

    Add++, 11 bytes

    +?
    O
    W,+1,O
    

    Try it online!

    But how? I'll tell you!

    +?       Add the input to the accumulator x. For this example, lets assume an input of 1
    O        Output the input
    W,       While input is true
      +1       Add 1 to the input
      ,O       Output and reset x
    

    caird coinheringaahing

    Posted 2015-11-03T16:40:48.353

    Reputation: 13 702

    0

    Decimal, 32 bytes

    81D301110D412D590D5111D91D30191D
    

    Pretty simple. Explanation:

    81D   ; builtin to read INT to stack
    301   ; print
    110D  ; push INT 0
    412D  ; compare for equality, pop values used, push result
    5     ; if truthy
    90D   ;  exit
    5     ; endif
    111D  ; push INT 1
    91D   ; declare jump 1
    301   ; print
    91D   ; exit
    

    Try it online!

    MD XF

    Posted 2015-11-03T16:40:48.353

    Reputation: 11 605

    0

    Noether, 5 bytes

    0(IP)
    

    This works very simply:

    0 - Push 0 to stack
    ( - Pop value of stack and loop until top of stack equals popped value
    I - Push user input to stack
    P - Print top of stack
    ) - End loop
    

    Unless you want your browser to freeze, I would advise against testing this online at https://beta-decay.github.io/noether

    Beta Decay

    Posted 2015-11-03T16:40:48.353

    Reputation: 21 478

    0

    ArcPlus, 22 bytes [non-competing]

    (: n (,))(@ (p n) (p n
    

    Verbose version:

    (set n (input))
    (while (print n) (print n))
    

    Skidsdev

    Posted 2015-11-03T16:40:48.353

    Reputation: 9 656

    0

    Java, 126 bytes

    public static void main(String[]a){int n=new Scanner(System.in).nextInt();while(n==1)System.out.print(n);System.out.print(n);}
    

    Ungolfed (+ comments with explanation)

    public static void main(String[]a){
        int n=new Scanner(System.in).nextInt();//Create the scanner and get the next integer input
        while(n==1)System.out.print(n);//if n == 1, print 1
        //else exit. If there is nothing that happens the java program automatically exits
        System.out.print(n);//But first print out 0
    }
    

    The reason behind using a scanner is me not being able to get the desired behaviour using System.in.read(). Typing 1 exited the program as if it was something else being typed. System.in.read() returns an int as 0-255 representing the byte it received, meaning 1 != 1 with that method.

    user44904

    Posted 2015-11-03T16:40:48.353

    Reputation:

    0

    Lean Mean Bean Machine, 18 bytes

     O
     i
     ?
     _
    u $
      ~
    

    Explanation:

     O    - Spawns a marble at program start
     i    - Fetch input and assign to marble's value
     ?    - If marble's value is truthy, spin right, else spin left
     _    - Move in direction of spin
    u $   - u terminates marble and prints value, $ prints value
      ~   - Trampoline, move marble to top of field on same column
    

    Yep, Mayube's at it again making another language that'll probably be abandoned in a week. This one's not at all golfy though, and inspired by this challenge

    Skidsdev

    Posted 2015-11-03T16:40:48.353

    Reputation: 9 656

    2D languages generally aren't golfy. However, they're interesting to program in. – Draco18s no longer trusts SE – 2017-07-17T20:47:30.900

    0

    Cubically, 29 28 bytes

    $!7{%0&}U3D1R3L1F3B1U1D3(%1)
    

    Try it online! (May not work for a little while after posting due to TIO's version) Explanation:

    $                             read integer as input
     !7{...}                      if falsy
        %0                         print 0th face
          &                        exit
            U3D1R3L1F3B1U1D3      quickest way to get 1 onto a face
                            (..)  forever
                             %1    print the first face
    

    MD XF

    Posted 2015-11-03T16:40:48.353

    Reputation: 11 605

    L1D1L3 gets 1 onto face 0. – TehPers – 2017-08-05T11:04:48.943

    0

    Python 2, 50 bytes

    a=bool(input())
    print int(a)
    while a: print int(a)
    

    Try it online!

    Husnain Raza

    Posted 2015-11-03T16:40:48.353

    Reputation: 329

    1

    You don't need to cast datatypes. 33 bytes

    – Simon – 2017-09-05T07:57:12.467

    0

    Assembly (as, x64, Linux), 128 bytes

    .data
    i:.byte 0
    .text
    mov $3,%eax
    mov $0,%ebx
    mov $i,%ecx
    mov $1,%edx
    int $128
    l:mov $4,%eax
    mov $1,%ebx
    int $128
    cmp $49,i
    je l
    

    Try it online!

    Explanation

    .data
    i:.byte 0       ;Declare variable i with type byte
    
    .text
    mov $3,%eax
    mov $0,%ebx
    mov $i,%ecx
    mov $1,%edx
    int $128        ;Make system call read(eax=3) from stdin(ebx=0) with an address(ecx) and length in bytes(edx)
    
    l:mov $4,%eax   ;Declare section/label l
    mov $1,%ebx
    int $128        ;make system call write(eax=4) to stdout(ebx=1). There is no need to reassign ecx or edx
    cmp $49,i       ;compare the value at the address i to 49(ascii value of "1")
    je l            ;jump to label l if equal
    

    Marcos

    Posted 2015-11-03T16:40:48.353

    Reputation: 171

    0

    INTERCAL, 141 bytes

    PLEASE WRITE IN .1
    DO (1020) NEXT
    DO (1) NEXT
    DO COME FROM (3)
    (3)DO READ OUT #1
    (2)PLEASE RESUME .1
    (1)DO (2) NEXT
    DO READ OUT #0
    DO GIVE UP
    

    Try it online!

    KSmarts

    Posted 2015-11-03T16:40:48.353

    Reputation: 1 830

    0

    4, 28 bytes

    3.61448701501132011483250194
    

    Try it online!

    Explanation:

    3.            Start Program
    6 14 48       Set the value of memory cell 14 to 48 (the ASCII code of '0')
    7 01          Read in one byte to memory cell 01
    5 01          Print byte from memory cell 01
    1 32 01 14    Set the value of memory cell 32 to cell 01 - cell 14
    8 32          Start loop: if cell 32=0, skip to the end
    5 01          Print byte from memory cell 01
    9             End loop
    4             End program
    

    KSmarts

    Posted 2015-11-03T16:40:48.353

    Reputation: 1 830

    0

    CMD, 30 bytes

    :a
    echo %1
    if %1==1 (goto a)
    

    Pretty straight-forward

    Ephellon Dantzler

    Posted 2015-11-03T16:40:48.353

    Reputation: 103

    0

    Java (OpenJDK 8), 103 bytes

    interface J{static void main(String[]a){int n=Integer.decode(a[0]);do System.out.print(n);while(n>0);}}
    

    Try it online!

    ungolfed (although Java doesn't need it that much):

    interface J{
        static void main(String[]a){
            int n=Integer.decode(a[0]);
            do System.out.print(n);
            while(n>0);
        }
    }
    

    Using Interface, as since Java 8 interfaces can have function bodies. Because they are always public we are saving some chars. The question states

    take input from STDIN or an acceptable alternative

    and for me the run arguments are an acceptable alternative.

    Note that Integer.decode() throws a NumberFormatException, but input will always only be 0 or 1.

    Luca H

    Posted 2015-11-03T16:40:48.353

    Reputation: 163

    @cairdcoinheringaahing But the question states "The truth-machine must be a full program that follows these rules:", so a function isn't sufficent, right? There already is a 48 byte Java answer which is only a function. I saw one Java answer which is a full program, but it had 120 bytes. – Luca H – 2017-11-16T06:39:50.623

    @cairdcoinheringaahing but thanks for the welcome! But I'm not familiar with any golfing language and most of my knowledge lies in Java, which also is not that much... So I don't think you'll see that much of me ;) – Luca H – 2017-11-16T06:41:37.697

    @cairdcoinheringaahing I know that already, I watched quite some challenges :P But of course, a 3 byte Jelly or something else solution is more liked than a 100 byte Java solution :P But lets see if I'll manage something nice some day ;) – Luca H – 2017-11-16T08:18:23.303

    0

    Bitwise, 52 46 38 bytes

    Oh, that's right, I made the interpreter not care about the return value for I/O. It was definitely not for code golf.

    IN 1 &1
    OUT 1 &1
    XOR 1 &48 2
    JMP &-3 2
    

    Try it online!

    Translated to C (labels added instead of literal jumps for clarity):

    IN 1 &1        mem[1] = getchar();
    LABEL &1       label_1:
    OUT 1 &1         putchar(mem[1]);
    XOR 1 &48 2      mem[2] = (mem[1] ^ 48);   // ^ is equivalent to !=
    JMP @1 2       if (mem[2]) goto label_1;
    

    MD XF

    Posted 2015-11-03T16:40:48.353

    Reputation: 11 605

    0

    Whispers, 34 bytes

    > Input
    >> Output 1
    >> DoWhile 1 2
    

    Try it online!

    caird coinheringaahing

    Posted 2015-11-03T16:40:48.353

    Reputation: 13 702

    0

    Pyt, 5 bytes

    `Đƥłŕ
    

    Explanation:

    `  ł     (Do ... while top of stack is true)
     Đ       Duplicate top of stack
      ƥ      Print top of stack
        ŕ    Pop top of stack and discard
    

    Try it online!

    mudkip201

    Posted 2015-11-03T16:40:48.353

    Reputation: 833

    0

    ;#+, 28 bytes

    ;;;;;;;;~*~-(;~;;;;;;~)~p(p)
    

    Try it online!

    ;;;;;;;;~*~-(;~;;;;;;~)~p(p)
    ;;;;;;;;                      set acc0 = 8
            ~*~                   set acc1 = input
               -(;        )       while(acc0--)
                  ~;;;;;;~            acc1 -= 6
                                  this leaves us with a `0` or `1` values for character input
                           ~p     print acc1
                             ( )  while(acc1)
                              p       print acc1
    

    Conor O'Brien

    Posted 2015-11-03T16:40:48.353

    Reputation: 36 228

    0

    FALSE, 12 11 bytes

    ^'0-[$.$]$#
    

    12Me21

    Posted 2015-11-03T16:40:48.353

    Reputation: 6 110

    0

    Draw, 21 bytes

    start 0 1 start start
    

    This is the version of the program where 1 is input. To change the input to 0, replace the 1 with a 0. The program where the 1 is there will produce an infinite line of marked squares towards y=+∞ starting at x=0, y=1; if the 1 was replaced, there will be only one marked square, at x=0, y=0.

    ivzem

    Posted 2015-11-03T16:40:48.353

    Reputation: 1 129

    0

    Aheui, 33 bytes

    방챵뱍벅나명희멍터벅벅
    

    You can test it with jsaheui, or rpaheui.

    How does it works?

    // When input is 0
    방챵뱍벅나명희멍터벅벅
    ⓐⓑ    ⓖⓕⓔⓓⓒ
    
    // When input is 1
    방챵뱍벅나명희멍터벅벅
    ⓐⓑⓓⓒⓔⓕ
       ⓖ
    

    0xrgb

    Posted 2015-11-03T16:40:48.353

    Reputation: 109

    0

    Kotlin Script, 41 bytes

    readLine().let{while(it=="1")print("1")}
    

    Pretty Printed:

    readLine()
        .let{
            while(it=="1")
                print("1")
        }
    

    jrtapsell

    Posted 2015-11-03T16:40:48.353

    Reputation: 915

    0

    Perl 6, 28 bytes

    {.say;.say while $_}(+slurp)
    

    bb94

    Posted 2015-11-03T16:40:48.353

    Reputation: 1 831

    0

    Yabasic, 36 bytes

    Another answer that takes input as integer, n and outputs to the console.

    Input""n
    If n Then Do?1Loop Else?0Fi
    

    Try it online!

    Taylor Scott

    Posted 2015-11-03T16:40:48.353

    Reputation: 6 709

    0

    Quarterstaff, 12

    49-?{49!}49! 
    

    explanation

    (value = 0 to start)

    49 - add 49 to value

    - - invert value (value = -49 now)

    ? - take a character of input (49 for "1", 48 for "0"), and add it to the value (value = 0 or -1 now)

    { - begin while not loop. will only be entered if input is 1 or starts with 1 (it should only start with 1 if it is 1).

    49 - add 49 to value. value is now 49

    ! - print value, set value to 0.

    } - end while not loop.

    49 - add 49 to value (which was -1). value is now 48

    ! - print value, set value to 0 (not relevant to the program, but all ! do this)

    it looks like it could be golfed by assigning 49 to something, but it would take 2 more bytes to assign it, then 2 more bytes to use it in the first part, then only byte saving of 2 for the other two occurences of 49

    Previous version of Quarterstaff, 11

    I removed %, so this isn't valid in the new version

    ?1%{49!}47!
    

    ? - input a character (49 for "1", 48 for "0") add to value

    1 - add 1 (value is 50 or 49 now)

    % - value = value %2 (0 if "1" was inputted, 1 if "0" was inputted)

    { - begin while not value loop

    49 - add 49 to value

    ! - print value, value = 0

    } - end while not value loop

    47 - add 47 to value

    ! - print value, value = 0

    Destructible Lemon

    Posted 2015-11-03T16:40:48.353

    Reputation: 5 908

    0

    QUARK, 11 bytes

    This is 6.75 bytes in QUARK's encoding, but that's not finished yet (no encoder), so I'll score this in UTF8 until then.

    i‶{p}⟲
    

    As QUARK became capable of doing a truth machine (implementation wise) less than a minute ago (from when I started writing this answer), it obviously needs an explanation, so here you go:

    i Get input from the user (as a number)
     ‶ Pin the input to the stack (Pinning is QUARK's way of avoiding a million and one dupes, by simply making the value undeletable until you run the pin command on it again.)
      { Begin a block
       p Print a value off the stack. Because the input is pinned, it's not consumed.
        } End the block, and push it to the stack (when the program reaches this point)
         ⟲ Execute the block. If the top of the stack is not after the first execute 0, execute the block until it is. As the input is pinned, it will always be either 0 or 1. So the block either executes once, or infinitely.
    

    moonheart08

    Posted 2015-11-03T16:40:48.353

    Reputation: 693

    0

    Momema, 9 bytes

    i0-8_Ii_I
    

    Try it online! Requires the -i interpreter flag.

    The provided Momema interpreter has a -i flag which enables interactive mode. In interactive mode, expressions can have holes, which evaluate to a value read from STDIN. Normally, this would just be equivalent to *-8, but it also allows holes to be named with a string of capital letters. When a named hole is evaluated, its value is cached, and when a hole with the same name is evaluated again it is reused. This is intended to be for debugging purposes, but it also means that we can refer to input without having to assign it.

    Explanation:

                                                     #  i = input num
    i   0   #  label i0: jump past label i0 (no-op)  #  do {
    -8  _I  #            output num _I               #    print num i
    i   _I  #  label i1: jump past label i(_I)       #  } while i
    

    Esolanging Fruit

    Posted 2015-11-03T16:40:48.353

    Reputation: 13 542

    0

    TIS -n 1 1, 29 bytes

    @0
    ADD UP
    L:MOV ACC ANY
    JGZ L
    

    Try it online!

    ADD UP is a shorter form of MOV UP ACC, since the accumulator starts at zero, and we only ever see one value on the input (if that is not desired +4 bytes to add HCF after the last line).

    MOV ACC ANY simply does the output. This line is also labelled L.

    JGZ L jumps to L if the accumulator is greater than zero. (JNZ L, jump if non-zero, would work identically here.)

    In the case where we have a zero for input, we do not jump, but instead wrap around to the first line (ADD UP). Since there is no more data to be had, the system goes quiescent.

    In the case of a one, we will endlessly jump to L, outputting a 1 on every third cycle (writing to a neighbor actually takes two cycles in TIS).

    Phlarx

    Posted 2015-11-03T16:40:48.353

    Reputation: 1 366

    0

    2DFuck, 32 30 bytes

    ,.,.,.,.,.,.,.,.[!..!..!...!.]
    

    Try it online!

    Explanation:

    ,.,.,.,.,.,.,.,. Read and print a byte, accumulator is last bit = 0 or 1
    [!..!..!...!.]   While the accumulator is 1, print 1
    

    wastl

    Posted 2015-11-03T16:40:48.353

    Reputation: 3 089

    0

    Charm, 42 bytes

    getline " 1 " eq put [ dup ] [ put ] while
    

    Try it online!

    You strangely can't cast to an integer in Charm, so I had to check for equality with 1 instead.

    LyricLy

    Posted 2015-11-03T16:40:48.353

    Reputation: 3 313

    0

    Ahead, 10 bytes

    IsO@
    ~>1O~
    

    Try it online!

    snail_

    Posted 2015-11-03T16:40:48.353

    Reputation: 1 982

    0

    ABAP, 61 bytes

    Hardcoded VALUE 1 for variable i, replace with 0 to not trigger the infinite loop.

    DATA x TYPE I VALUE 1.
    WHILE i=1.
    WRITE i.
    ENDWHILE.
    WRITE i.
    

    Noir Antares

    Posted 2015-11-03T16:40:48.353

    Reputation: 469

    0

    Python 2.7, 45 bytes

    I just had the Eureka of this code:

    x=int(raw_input())
    print x
    while x: print 1
    

    I am proud of this one, though it may not look very impressive.

    StealthyPanda

    Posted 2015-11-03T16:40:48.353

    Reputation: 41

    You don't need the indentation after if x==1:, also why not just do if x:? – Post Rock Garf Hunter – 2018-07-09T20:24:57.297

    @W W yeah I changed it. Also very late. – StealthyPanda – 2018-07-23T13:01:54.857

    1Change int(raw_input) to input() because Python 2's eval converts it automatically to int. – MilkyWay90 – 2019-01-12T00:26:54.020

    0

    Assembly (nasm, x64, Linux), 119 bytes

    mov eax,3
    mov ebx,0
    mov ecx,i
    mov edx,1
    int 80h
    l:mov eax,4
    mov ebx,1
    int 80h
    cmp byte [i],49
    je l
    section .data
    i:db 0
    

    Try it online!

    I was surprised that, while there is a 128 byte submission in as, there isn't a nasm submission, despite it being shorter!

    Literally a port of the as submission into nasm.

    Skidsdev

    Posted 2015-11-03T16:40:48.353

    Reputation: 9 656

    0

    Clam, 11 bytes

    p=a*rwa*pa*
    

    Try it online!

    Storing variables is a tad verbose in Clam...

    Explanation

    p=a*rwa*pa*
    p            Print..
     =             Assignment..
      a*             Dictionary lookup 'myVar'
        r            Read next line of STDIN (automatically parsed to int if possible)
         w       While..
          a*       myVar is true
            pa*    Print myVar
    

    Resulting JS code:

    console.log(myVar = arguments[0]);
    while(myVar) {
        console.log(myVar);
    }
    

    Skidsdev

    Posted 2015-11-03T16:40:48.353

    Reputation: 9 656

    0

    bitch, 5 bytes

    This infinitely outputs 1 for an input of 1 and outputs 0 once for an input of 0.

    \>/;<
    Try it online!

    Explanation

    \         Input of an integer (restricted by challenge to 0 or 1)
     >        Loop marker #1
      /       Output
       ;<     If not equal to 0, jump to loop marker #1
              (Implicit end of program)
    

    Helen

    Posted 2015-11-03T16:40:48.353

    Reputation: 125

    0

    F# (.NET Core), 54 bytes

    let x=stdin.Read()
    while x=49 do printfn"1"
    printfn"0"
    

    Try it online!

    dana

    Posted 2015-11-03T16:40:48.353

    Reputation: 2 541

    0

    IBM PC 8088 machine code, 14 12 bytes

    TRUTH.COM:

    a082 00b4 0ecd 103c 3174 f8c3
    

    Ungolfed:

        MOV  AL, DS:[82H]
    DISPLAY:
        MOV  AH, 0EH
        INT  10H
        CMP  AL, '1'
        JZ   DISPLAY
        RET
    

    Output

    A>DIR TRUTH
     Volume in drive A has no label
     Directory of  A:\
    
    TRUTH    COM       12  01-01-80   12:01a
            1 File(s)    111776 bytes free
    
    A>TRUTH.COM 0
    0
    
    A>TRUTH.COM 1
    111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111^C
    (ended because Ctrl-C (^C) was hit)
    

    Shouldn't ever crash or run out of memory since no memory is used. More likely it'll just burn a permanent screen full of 1's onto your IBM 5151 monochrome CRT monitor, so in a sense it will run forever.

    Build and test it for yourself using DOS DEBUG.EXE!

    A>DEBUG TRUTH.COM
    a
    mov al,[0082]
    mov ah,0e
    int 10
    cmp al,31
    jz 103
    ret
    
    rcx
    c
    w
    q
    

    640KB

    Posted 2015-11-03T16:40:48.353

    Reputation: 7 149

    0

    Lua, 38 bytes

    x=io.read()repeat print(x)until x~='1'
    

    Try it online!

    Alex Allen

    Posted 2015-11-03T16:40:48.353

    Reputation: 91

    0

    Turing Machine But Way Worse, 139 bytes

    0 0 0 1 1 0 0
    0 1 0 1 2 0 0
    1 2 1 1 3 0 0
    1 3 1 1 4 0 0
    0 4 0 1 5 0 0
    0 5 0 1 6 0 0
    0 6 0 1 7 0 0
    0 7 0 1 8 1 1
    1 7 1 0 8 1 0
    0 8 0 1 7 1 0
    

    Try it online!

    MilkyWay90

    Posted 2015-11-03T16:40:48.353

    Reputation: 2 264

    0

    C (gcc), 52 bytes

    main(i){for(scanf("%d",&i);i;)puts("1");puts("0");}
    

    -27 bytes thanks to JoKing
    -2 bytes thanks to Jonathan Frech
    Try it online!
    I though I'd try something other than my primary language (Java).

    Benjamin Urquhart

    Posted 2015-11-03T16:40:48.353

    Reputation: 1 262

    @JoKing implicit int type? That's good to know. – Benjamin Urquhart – 2019-03-10T04:23:33.167

    You can even use main(i). – Jonathan Frech – 2019-03-10T09:02:52.717

    Furthermore, while(...) is equivalent to for(;...;), making space for your scanf and allowing for the semicolon to be dropped. – Jonathan Frech – 2019-03-10T09:04:07.600

    @JonathanFrech thanks. You can probably tell that I don't know C very well :) – Benjamin Urquhart – 2019-03-10T11:19:13.267

    0

    Eukleides, 40 bytes

    a=number();for i=0to 0;print a;i=i-a;end
    

    Pretty straightforward. number() takes in a number as input. For loop seems to be the golfiest means of looping for this task. While loop skips the i=i-a; but requires two prints.

    brhfl

    Posted 2015-11-03T16:40:48.353

    Reputation: 1 291

    0

    C++ (gcc), 65 bytes

    #include<cstdio>
    int main(){for(int c=getchar();putchar(c)-48;);}
    

    Try it online!

    movatica

    Posted 2015-11-03T16:40:48.353

    Reputation: 635

    0

    VTL-2, 25 bytes

    1 A=?
    2 ?=A
    3 #=4-2*A
    

    Line numbers always take up two bytes in VTL, hence the byte count discrepancy.

    This should work in VTL-1 as well, but I don't have an interpreter to ensure that is the case. I've tested this under a VTL-2 interpreter running on an Altair 8800 simulator, both sourced from here. Here's a PDF manual for VTL-2.

    VTL was a small (<800 bytes!) and simple language for the Altair 8800 and 680 machines. Its creative use of system variables helped to keep it small. ? represents both input and output. Note that this truth machine outputs no line breaks, as those always need to be manually printed (by printing an empty string, ?=""). # represents line number, and can be used to retrieve the current line number or assigned to form a goto. That should be enough to make this truth machine make sense...

    1 A=?         ) Put input into variable A
    2 ?=A         ) Print the contents of variable A
    3 #=4-2*A     ) Goto 4-(2*A)... So, (nonexistent) line 4 if input was 0
                  ) Or back to line 2 if input was 1. Yes, `)` is the comment character.
    

    brhfl

    Posted 2015-11-03T16:40:48.353

    Reputation: 1 291

    0

    Aheui, 28 bytes

    붕박누망홰
    차봇멍보
    

    Try it online!

    Additionally, I found bug of TIO with Aheui : Aheui is befunge-like, but initial direction is up-to-down, but TIO's initial direction is right-to-left, so my original code got error.

    LegenDUST

    Posted 2015-11-03T16:40:48.353

    Reputation: 799

    0

    EZLang, 105 bytes

    MEM(0)
    SET(-1)
    MEM(1)
    GET()
    SET(-1, 1)
    JLZ(12)
    SET(1, 1)
    MEM(1)
    PRT()
    MEM(0)
    JLZ(8)
    SET(1, 1)
    PRT()
    HLT()
    

    Self-made esolatic language.

    LegenDUST

    Posted 2015-11-03T16:40:48.353

    Reputation: 799

    0

    Pip, 7 bytes

    IqW1P1i
    

    Try it online!

    explanation:

    If(q) // q is input
        While(1) {
            print(1);
        }
    output 0  // i is initialized to 0, but this stops it from being confused for "10"
    

    Kenneth Taylor

    Posted 2015-11-03T16:40:48.353

    Reputation: 183

    0

    33, 4 bytes

    O[o]
    

    Explanation:

    0 input:

    O    | Get input
      o  | Print it
     [ ] | Loop ends because accumulator is 0
    

    1 input:

    O    | Get input
     [ ] | While the accumulator is 1 (forever)
      o  | Print it
    

    TheOnlyMrCat

    Posted 2015-11-03T16:40:48.353

    Reputation: 1 079

    0

    Befunge-93, 7 bytes

    &>:.:_@
    

    Try it online!

    _ is the horizontal if in befunge - conveniently, it sends the IP right if the top of the stack is 0 (so it hits @ to end the program), and left if the top of the stack is nonzero (which puts it in an infinite loop).

    osuka_

    Posted 2015-11-03T16:40:48.353

    Reputation: 391

    This seems to be a duplicate of this answer.

    – Mr. Xcoder – 2019-08-26T19:06:28.433

    0

    Runic Enchantments, 6 bytes

    i:?@:$
    

    Try it online!

    ? is a conditional jump command that skips n instructions where n is a value popped from the top of the stack. If that value is 0, we dump the stack and terminate. If its 1 we skip that instruction and print the value, leaving a copy on the stack, then loop. i does nothing if there is no more input to read.

    Draco18s no longer trusts SE

    Posted 2015-11-03T16:40:48.353

    Reputation: 3 053

    0

    JavaScript, 32 bytes

    do{alert(x=x||prompt())}while(x)
    

    Naruyoko

    Posted 2015-11-03T16:40:48.353

    Reputation: 459

    0

    Unsuspected-hangul, 187 bytes

    ㅀㄱ ㄱㅇㄱ ㅅㅅㅎㄴ ㄳㅎㄴㅎ ㄱㅀㄷ ㄱㅇㄱ ㅁㅈㅎㄴ ㅈㅀㄴ ㄱㅇㄴ ㄴㅇㅎㄴ ㅂㄱㅎㄱ ㄳㅎㄴ ㄱㅇㄴ ㄴ ㄴㅎㄷㅎㄷㅎ ㄱㅀㄷㅎ ㄱㅀㄷ
    

    You can try it here

    Note that it use pop-up for standard output, and you have to close tap to terminate the program.

    How does it work?

    ㄹ ㅎㄱ [ㄱㅇㄱ ㅅㅅㅎㄴ ㄱㅅㅎㄴ ㅎ] ㄱㄹㅎㄷ bind(input(), int)
        [def print_and_recursion(x) num -> IO(nil)
        ㄱㅇㄱ ㅁㅈㅎㄴ ㅈㄹㅎㄴ print(str(x))
            [def recursion_part(not_used) nil -> IO(nil)
            (ㄱㅇㄴ ㄴㅇ ㅎㄴ) print_and_recursion(x)
            (ㅂㄱㅎㄱ ㄱㅅㅎㄴ) IO(nil)
            (ㄱㅇㄴ ㄴ ㄴㅎㄷ) ㅎㄷ if(x == 1) then... else...
        ㅎ]
        ㄱㄹㅎㄷ bind(print(str(x)), recursion_part)
    ㅎ]
    ㄱㄹㅎㄷ bind(bind(input(), int), print_and_recursion)
    

    Unsuspected-hangul(평범한 한글) is Korean character-based functional esolang.

    LegenDUST

    Posted 2015-11-03T16:40:48.353

    Reputation: 799

    0

    Turing Machine Code, 19 29 19 bytes

    0 0 * * h
    0 * 1 r 0
    

    Try it online!

    Saved 10 bytes thanks to @Laikoni

    ouflak

    Posted 2015-11-03T16:40:48.353

    Reputation: 925

    This is doable with just two rules: 0 0 * * h and 0 * 1 r 0. – Laikoni – 2020-02-26T12:54:04.607

    0

    Wren, 55 bytes

    Fn.new{|x|
    while(x){
    System.print(x)
    if(x==0)Fn.x()
    }
    }
    

    Try it online!

    Explanation

    Fn.new{|x|      // As usual, new anonymous function x
                    // Newline as we are entering statements, not an expression
    while(x){       // While the input x is true:
                    // (Everything other than false, the null string, and the
                    // empty list is true)
    System.print(x) // Output x to the console with a newline
    if(x==0)Fn.x()  // If the input is 0 then exit the program
    }
    }
    

    user85052

    Posted 2015-11-03T16:40:48.353

    Reputation:

    0

    Comp, 6 or 8 bytes

    The first golfing language (sort of :) ) from 2020!

    ;{^&}&
    

    That could be a mistake. An alternative program is:

    ;{^£}£
    

    Explanation

    ;      Take an input from the console as an integer
     {^£}  While that's nonzero, duplicate & print
         £ If that's zero, directly print
    

    user85052

    Posted 2015-11-03T16:40:48.353

    Reputation:

    0

    AWK, 17 bytes

    {while($0)print}1
    

    Try it online!

    rootbeersoup

    Posted 2015-11-03T16:40:48.353

    Reputation: 111

    0

    RAKIAC machine language, 6 bytes (34 real for asm)

    00000100
    00000011
    00110100
    00100001
    00000001
    00000010
    

    Representing the assembly:

    in
    s: out
    jez v
    jmp s
    v: hlt
    end
    

    Tried out one of my things for fun (definitely not made for golf).

    Roninkoi

    Posted 2015-11-03T16:40:48.353

    Reputation: 161

    0

    Lua For windows, 70 bytes

    Use lua for windows for this

    I=io.read() If I=="1" then while 1 do print"1" end elseif print"0" end
    

    This program works because it takes a 0 or 1 from stdin then if it's a one it makes a while loop that prints one if it's a 0 it prints 0 then the program ends

    Alex Allen

    Posted 2015-11-03T16:40:48.353

    Reputation: 91

    Does this rely on functionality specific to Windows? Why couldn't this be run with Lua on other systems? – Alex A. – 2015-11-04T03:16:59.953

    1This could be shorter if you just called If io.read()=="1" instead of assigning it to an alias. – James Murphy – 2015-11-04T05:41:01.953

    0

    Ceylon, 91 88 bytes

    Improved (explanation at the end):

    shared void run()=>("0"<(process.readLine()else"")then{1}.cycled else{0}).each(print);

    This was the original (91 bytes):

    shared void run(){if("0"<(process.readLine()else"")){while(0<1){print(1);}}else{print(0);}}

    Unfortunately the most part goes to reading the input and making sure it is defined.

    shared void run() {
        if("0"<(process.readLine() else "")) {
            while(0<1) {
                print(1);
            }
        } else {
            print(0);
        }
    }
    

    I merged this null check (in the else "" form) with the decision into one if, so when the input is ended without a line being read, it also prints 0. Also, any string sorting less than "0" lexicographically prints 0, and any string lexicographically > "0" will produce the 1-loop.

    The 0<1 is used instead of true because it is shorter.

    Here is a functional approach, unfortunately it can't compete (107 bytes after whitespace removal) due to the length of parseInteger:

    shared void run() {
        value i = parseInteger(process.readLine() else "") else 0;
        (1:i).cycled.follow(i).each(print);
    }
    

    It cycles a range starting at 1 of length i (i.e. either {} or {1}), resulting in {} or {1,1,1,1,...}, prepends i (which results in {0} or {1,1,1,1,1,1,...}), and prints each element.


    A different functional approach without variables and parsing is this one (88 bytes, shrinked version at the top):

    shared void run() =>
            ("0" < (process.readLine() else "") then
        { 1 }.cycled else { 0 }).each(print);
    

    This does the case distinction in an expression, using the then and else operators to produce either the {1,1,1,...} stream or the {0} singleton, and then calls print(...) on each element of that stream.

    Paŭlo Ebermann

    Posted 2015-11-03T16:40:48.353

    Reputation: 1 010

    0

    C#, 120 98 bytes

    using c=System.Console;class o{static void Main(){if(c.Read()=='1')for(;;c.Write(1));c.Write(0);}}
    

    Ungolfed:

    using c=System.Console;
    class o
    {
        static void Main()
        {
            if(c.Read()=='1')
                for(;;c.Write(1));
            c.Write(0);
        }
    }
    

    sweerpotato

    Posted 2015-11-03T16:40:48.353

    Reputation: 2 457

    12-byte gain: int a=c.Read();do c.Write(a-48);while(a>48); – LegionMammal978 – 2015-12-06T16:10:19.587

    195 bytes based on @LegionMammal978 answer using c=System.Console;class P{static void Main(){int a=c.Read()-48;do c.Write(a);while(a>0);}} – krontogiannis – 2016-08-29T10:26:30.183

    0

    Swift, 187 bytes

    import Foundation
    let i = Int("\(String(data: NSFileHandle.fileHandleWithStandardInput().availableData, encoding: NSUTF8StringEncoding)!.characters.first!)")!
    print(i)
    while i>0{print(i)}
    

    Sadly this has to read from stdin if it can :( Would be so much smaller if I could just declare it inside...

    vrwim

    Posted 2015-11-03T16:40:48.353

    Reputation: 2 223

    Can you not remove the spaces around =, after :, and after ,? – Esolanging Fruit – 2017-12-14T00:36:18.633

    0

    JavaScript, 62 34 33 31 bytes

    Golfed:

    i=prompt();do{alert(i)}while(i)
    

    Ungolfed:

    input=prompt();
    do {
        alert(i);
    } while(i);
    

    -1 byte thanks to JimmyJazzx's answer
    -2 bytes and bug fix thanks to kamoroso94's comment

    Solomon Ucko

    Posted 2015-11-03T16:40:48.353

    Reputation: 439

    1You can golf this even more to something like this: i=prompt();for(;i==1;)alert(i);alert(i) (39 bytes). Also to read from the user use prompt() not alert()`. – insertusernamehere – 2015-11-10T19:26:35.410

    @insertusernamehere thanks for catching that typo! Just fixed it. – Solomon Ucko – 2015-11-11T01:50:24.890

    @Martin Büttner♦ Thanks for the formatting fixes! – Solomon Ucko – 2015-11-11T01:53:19.987

    This does the opposite of what it's supposed to. You need to loop on 1, not 0. Get rid of <1 and save two bytes to fix your bug. – kamoroso94 – 2017-10-10T04:54:25.970

    2Finally got 50 rep, for(i=prompt();alert(i)|i;); (28 bytes) – Ephellon Dantzler – 2017-10-10T21:13:49.857

    0

    x86 (Linux / NASM syntax), 86 bytes

    mov dx,1              ; 3rd argument to read(): length of buffer
    mov ecx,esp           ; 2nd argument to read(): the buffer
                          ; 1st argument to read(): the FD is already 0
    mov ax,3              ; read system call number
    int 128               ; invoke syscall, returns eax=1 == num of read bytes
    l:mov ax,4            ; start of loop, eax=syscall number of write()
    int 128               ; invoke syscall, returns eax=1 == num of written bytes
    cmp byte[esp],49      ; compare buffer against '1'
    jz l                  ; loop of it's the same
    int 128               ; invoke syscall otherwise (syscall 1 == exit)
    

    Compile with nasm -f elf h.asm && ld -o h h.o -m elf_i386 and ignore all warnings. :-)

    kay - SE is evil

    Posted 2015-11-03T16:40:48.353

    Reputation: 230

    0

    Scala, 46 bytes

    if(readInt==0)print(0)else while(2>1)print(1)
    

    Kinda uninteresting and obvious, but there we go

    triggerNZ

    Posted 2015-11-03T16:40:48.353

    Reputation: 251

    ==0 can be replaced with <1 – V.G. – 2015-11-12T17:18:25.540

    1val k=readInt;do{print(k)}while(k>0) – V.G. – 2015-11-12T17:24:35.433

    0

    Atari Basic, 47 bytes

    If I remember the syntax correctly, it will be something like this:

    1 input a$
    2 IF a$="0" THEN end
    3 ? a$
    4 goto 3
    

    Please correct me if I'm wrong.

    user902383

    Posted 2015-11-03T16:40:48.353

    Reputation: 1 360

    Do you need some spaces? ("0" THEN, ? a$) – Erik the Outgolfer – 2016-07-22T12:35:18.113

    @EʀɪᴋᴛʜᴇGᴏʟғᴇʀ I'm not sure, i produced this snippet from memory, i did't use atari basic for over 25 years. – user902383 – 2016-07-22T12:41:29.180

    0

    Java, 90 97 bytes

    class T{public static void main(String[]a){while(a[0].equals("1"))System.out.println(1);}}
    

    I'm not sure if this counts because it takes 1 or 0 as an argument rather than STDIN. It's been emotional, either way.

    Edit: The above does not print zero, the below does:

    class T{public static void main(String[]a){do System.out.println(a[0]);while(a[0].equals("1"));}}
    

    ESP

    Posted 2015-11-03T16:40:48.353

    Reputation: 109

    2You can save two characters by using print instead of println. (There was no requirement saying each 1 must be on a new line). Also, the command line can be added easily as while(a[0].equals(new java.util.Scanner(System.in).nextLine()). However, I don't think this meets the requirement, since it doesn't print 0. – Xynariz – 2015-11-10T01:42:28.867

    Fixed to print zero in 97 bytes. I had to use println because print must just be appending to the string so never actually prints a line for me. – ESP – 2015-11-11T09:45:09.113

    1

    "print must just be appending to the string" .. .what? print and println do exactly the same thing, except that println prints the text plus the current OS's line delimiter. See the documentation: https://docs.oracle.com/javase/8/docs/api/java/io/PrintStream.html#print-java.lang.String- and https://docs.oracle.com/javase/8/docs/api/java/io/PrintStream.html#println-java.lang.String-

    – Xynariz – 2015-11-13T00:42:06.103

    @Xynariz You should only read the input once – SuperJedi224 – 2016-01-03T13:35:57.823

    @SuperJedi224 Um ... how is that even relevant to what I said? – Xynariz – 2016-01-04T20:57:55.190

    @Xynariz I was talking to the scanner part of your first comment – SuperJedi224 – 2016-01-04T21:17:53.940

    @Xynariz I was running in Eclipse and print didn't work as you would expect, hence println (I should maybe start running the files from command line) – ESP – 2016-01-11T13:33:42.787

    @ESP It should still work, I think there's something weird going on. – Xynariz – 2016-01-12T15:20:36.337

    Program args are not STDIN! – Shaun Wild – 2016-09-01T09:02:17.650

    0

    Python 2, 46 bytes 34 bytes

    x=input() 
    print x
    while x:print x
    

    Basically, it takes in the input, when 1, prints forever (while loop), but if it isn't 1 (when it is zero) it prints and then exits.

    This is my first answer! Yay!

    TanMath

    Posted 2015-11-03T16:40:48.353

    Reputation: 1 431

    2

    Duplicate of this answer.

    – lirtosiast – 2015-11-09T06:02:05.790

    0

    PHP, 24 25 27 bytes

    <?=do{echo$i;}while($i); // Also 24b
    <?=$i;for(;$i&1;)echo$i; // 24b, added PHP's short echo, actually made it less
    
    echo$i;for(;$i&1;)echo$i; // 25b
    echo$i;while($i&1)echo$i; // 25b, based on 0/1 as truthy/falsy
    
    for(;$i&1;){echo$i;}echo$i; //27b
    

    This works by setting register_globals=on (which you shouldn't) and that going to the page with ?i=1 or ?i=0 in the url.

    The logic is that the first echo will always output the input, and if it's one it'll loop until something gives in (because of & returning 1 (=truthy) for 1).

    Martijn

    Posted 2015-11-03T16:40:48.353

    Reputation: 713

    Does register_globals work with STDIN? – insertusernamehere – 2015-11-10T19:19:23.857

    I went for " or an acceptable alternative". I figured it's about the technique, not forcebly use STDIN. This is one of the very few 'keep the code shorter' tricks PHP can use, especially compared to the other languages :) – Martijn – 2015-11-11T08:27:31.173

    I get 21 bytes with do{echo$i;}while($i); – Xanderhall – 2016-12-09T14:04:09.493

    1But not with the <?= in front of it. Added it nevertheless – Martijn – 2016-12-12T12:44:40.613

    0

    VB.NET, 106 Bytes

    Imports c=System.Console
    Module m
    Sub Main
    i=c.readline
    1:c.Write(i)
    if i=1 then goto 1
    end sub
    end module
    

    Straightforward, using goto instead of a loop. Compiles with Option Explicit and Option Strict Off, and Option Infer On

    Jens

    Posted 2015-11-03T16:40:48.353

    Reputation: 191

    0

    STATA, 31 bytes

    di _r(a)
    m
    do{$a
    }while($a)
    end
    

    First, get input from the user and store it in global variable a. Then switch to Mata for better commands. Print the value of a and then if it is truthy (i.e. 1), go to the start of the loop. If the end keyword is omitted, unexpected end of file (end statement missing) is output to standard error. I'm not sure if that's okay.

    bmarks

    Posted 2015-11-03T16:40:48.353

    Reputation: 2 114

    0

    Swift, 55 bytes, 54 bytes, 53 bytes

    if readLine()=="1"{while 1>0{print(1)}}else{print(0)}
    

    I tried to use ternary for a while but couldn't get it compiling. Maybe someone else will or it is just impossible. I'm open for tips or advice :)

    Simon

    Posted 2015-11-03T16:40:48.353

    Reputation: 101

    instead of while(true) can you do while(1) or while(1>0)? – Cyoce – 2017-09-05T08:03:59.470

    @Cyoce error: 'Int' is not convertible to 'Bool' – idrougge – 2017-11-22T11:52:01.150

    @Simon You can shave off one byte by removing the parentheses after while. They serve no purpose in Swift. – idrougge – 2017-11-22T11:54:38.490

    One byte shorter using ternary: readLine()=="1" ? {while 1>0{print(1)}} : {print(0)} – idrougge – 2017-11-22T12:06:56.233

    @idrougge 'Expression resolves to an unused function' – Simon – 2017-11-22T12:24:02.170

    Sorry, that was stupid of me. The functions are never called that way. – idrougge – 2017-11-23T08:45:44.880

    0

    Julia, 45 chars

    readline()[1]>48?while 1>0 show(1)end:show(0)
    

    M L

    Posted 2015-11-03T16:40:48.353

    Reputation: 2 865

    0

    Staq, 5 chars

    '[:]:
    

    Explanation

    '         input number, put it on top of the active stack
     [        jump to corresponding ] if the top stack value = 0 or nonexistent
      :       output top stack value as number
       ]      jump back to corresponding [ if top stack value >0
        :     output top stack value as number
    

    M L

    Posted 2015-11-03T16:40:48.353

    Reputation: 2 865

    0

    Cardinal, 8 chars

    %:> J.jN
    

    Explanation

    %                     create pointer
     :                    enter number, put it on top of stack
      >                   redirect pointer to the right
                          NOP
        J                 skip next instruction if top stack value is > 0
         .                output number to STDOUT
          j               skip next instruction if top stack value is = 0
           N              reflect pointer to the left
    

    The original interpreter, written by Madk, is buggy, and some instructions are missing. I fixed the errors and recompiled the interpreter.

    You can clone the fixed interpreter and readme from my GitHub repository.

    M L

    Posted 2015-11-03T16:40:48.353

    Reputation: 2 865

    Does it use anything implemented after the question was asked? I think so. Sadly I think this is noncompeting. – Yet Another User – 2016-01-07T05:15:41.687

    @YetAnotherUser Cardinal is from 2010. Madk’s original interpreter (in BlitzMax) contains bugs that break the use of Cardinal, and he forgot to implement one or two commands that exist in his language spec. I fixed these errors and recompiled the fixed source in BlitzMax. Now everything works according to his specification. This is a catalog, the date of implementation does not matter.

    I uploaded my fix on GitHub yesterday, so everyone can enjoy it. The language is 5 years old; I fixed the errors around June 2015, as you can see e.g. here

    – M L – 2016-01-07T11:49:26.777

    0

    Mouse16, 10 bytes

    ?0+[1!4\]0
    

    Asks for input, then coerces it to an int and tests its truthiness. Then, if it's truthy, 1 is printed and the execution jumps to the 4th byte, where 1 is printed again, and so on forever (until the stack overflows), otherwise, 0 is printed.

    cat

    Posted 2015-11-03T16:40:48.353

    Reputation: 4 989

    0

    Pike, 94 bytes

    Looks like C, but isn't C. Is interpreted. Is fast.

    int main(){int x=(int)Stdio.stdin->gets();if(x!=0){for(;;){write("1");}}write("0");return 0;}
    

    Ungolfed:

    int main() {
      int x = (int)Stdio.stdin -> gets();
      if (x != 0) {
        for(;;) {
          write("1");
        }
      }
      write("0");
      return 0;
    }
    

    cat

    Posted 2015-11-03T16:40:48.353

    Reputation: 4 989

    2I always want to pronounce Stdio as Studio :) Can you not write an integer to output? – ETHproductions – 2016-01-22T17:26:37.633

    @ETHproductions before I actually learned C, I always assumed stdio.h was some sorta studio something because of Visual Studio... I dunno. To write a number to stdout as far as I can tell you need to use write("%d", x); because write wants a string or array(char) argument, which is even longer – cat – 2016-01-22T17:29:56.560

    0

    Boo, 34 bytes

    def f(x):
     print x;while x:print x
    

    Boo is a language inspired by Python and implemented in .NET. Its syntax is very similar to Python 2's.

    Mego

    Posted 2015-11-03T16:40:48.353

    Reputation: 32 998

    0

    AnnieFlow, 6 bytes

    010[!"
    

    Here is the decompressed and more readable program:

    010101101100000110111111
    

    Breakdown:

    010          there are two characters, 0 and 1
    1            input is accepted, first symbol popped will be whatever it is
    011          there are two stacks, 0 for output, 1 for input
    011          1 push occurs when 0 is popped from 1
    00           that push is symbol 0 on stack 0 (output 0)
    0            pop from the output (halt) when 0 is popped from 1
    0011         2 pushes occur when 1 is popped from 1
    01           the first push is symbol 1 on stack 0
    11           the second push is symbol 1 on stack 1 (replaces the symbol we popped)
    1            pop from stack 1, which we just put 1 on, so we loop forever, outputting 1
    11           loop forever doing nothing if the input is empty, won't matter
    

    Note: under some interpretations of the language, the trailing 1s can be omitted, and the advanced interpreter does this automatically, also added 0 to the end if there are any trailing 1s. The actual decompression is

    01010110110000011
    

    Fricative Melon

    Posted 2015-11-03T16:40:48.353

    Reputation: 1 312

    1With an interpreter to use the whole 8 bits/byte for golfing purposes, this could be an interesting golfing language. – lirtosiast – 2016-02-03T23:07:43.377

    0

    CJam, 16 bytes

    qi1={"1o_~"_~}&0
    

    username.ak

    Posted 2015-11-03T16:40:48.353

    Reputation: 411

    0

    Pylons, 7 bytes.

    izwp,1}
    

    How it works:

    i      # Get command line input.
    z      # Skip the next instruction if the top of the stack is 0.
    wp,1}  # While 1 is truthy, print the stack.
    

    Morgan Thrapp

    Posted 2015-11-03T16:40:48.353

    Reputation: 3 574

    0

    ForceLang, 52 bytes

    set a io.readln()
    label l
    io.write a
    if a="1"
    goto l
    

    SuperJedi224

    Posted 2015-11-03T16:40:48.353

    Reputation: 11 342

    0

    Fission, 12 bytes

    This is about the shortest I can do at the moment.

    *;R?[   X!@J
    

    Try it online

      R           # Create a atom heading right
       ?          # Set atom mass to input char 
        [         # Set direction right
            X     # Clone atom and sending one back
             !    # Print the character
              @   # Swap mass and energy on atom
               J  # Jump (48 for 0, 49 for 1)
    *             # Kill program.  Landing spot for 0
     ;            # Kill atom.  Landing spot for 1
    

    The length of this program is quite dependent on the landing spots for the Jump command. There is also a requirement for a bit of space between the [ direction setter and the X linear cloner. Otherwise an extra 0 will get printed. The input must be either 0 or 1 for this to work. The input is not validated.

    Originally I was going to put up a 18 byte program which is more forgiving on invalid inputs.

    R?@YI@0'L
    O0'&[X'1
    

    MickyT

    Posted 2015-11-03T16:40:48.353

    Reputation: 11 735

    0

    Javascript, 33 31 chars

    while(alert(x=x||+prompt()),x);
    

    Qwertiy

    Posted 2015-11-03T16:40:48.353

    Reputation: 2 697

    I'm getting "ReferenceError: x is not defined". – Adam Dally – 2016-04-16T03:36:08.250

    0

    Common Lisp, 34 32 bytes

    (if (= 1(read))(loop (print 1)))
    

    JPeroutek

    Posted 2015-11-03T16:40:48.353

    Reputation: 734

    This appears to be a duplicate of this.

    – Mego – 2016-04-11T18:18:17.117

    Hmmm ... Are you printing the Zero? – sergiol – 2017-01-31T01:06:41.510

    0

    Turtlèd, 7 bytes

    Turtlèd cannot output without halting, so the truth machine writes down infinite ones, like a turing machine's implementation might, onto the grid if input is 1.

    !.{1r.}
    

    Explanation:

    !                  input into string variable
    
     .                 write current char of string var (by default the first char)
                       for a single char input, this will be the entire input
    
      {1  }            while the current char is 1
                       this loop is never run if input is zero, but if it is one, it will run
                       forever, as the last action of the loop writes 1 to the current cell
    
        r              move right, so that we constantly move right to write ones to infinite
                       cells
    
         .             write current char of string var (still by default the first char)
                       this is 1 if the loop was run at all. because the loop runs while the
                       current cell is one, this will cause the loop to rerun every time.
    
           [implicit]  output grid at end of program, program will only end if input isn't 1
    

    Destructible Lemon

    Posted 2015-11-03T16:40:48.353

    Reputation: 5 908

    0

    LI, 4 bytes

    ?iRP
    

    Explanation:

    ?i       if input is truthy (1):
      RP      Recurse the program with the printed (implied) input
             Else (0 is the only falsy value in LI) return (implied) input, 
                  which is implicitly printed.
    

    Steven H.

    Posted 2015-11-03T16:40:48.353

    Reputation: 2 841

    0

    ABCR, 7 bytes

    iAo7ox
    

    ABCR is a stack-based programming language that allows a few simple operations on any of its three stacks and a single register.

    Explanation:

    i        Numerical input.  Places result in register.
     A       Queue register value to queue a.
      o      Output peek(a) as a number.
       7     while(register){
        o      output peek(a) again
         x   }
    

    Steven H.

    Posted 2015-11-03T16:40:48.353

    Reputation: 2 841

    0

    Dip, 6 bytes

    ?_1p?0
    

    Body must be at least 30 characters; you entered 19.

    Oliver Ni

    Posted 2015-11-03T16:40:48.353

    Reputation: 9 650

    Perhaps you should provide an explanation rather than a space filler... – FlipTack – 2016-12-22T13:23:42.677

    -1

    Ruby, 22 bytes

    ->(n){n==0?0:loop{p1}}
    

    Nirajan Pokharel

    Posted 2015-11-03T16:40:48.353

    Reputation: 159

    -2

    Python 2, 43 42 41 bytes

    x=raw_input();print x
    while x>'0':print x
    

    Got a syntax error at the while loop if I tried to run it as a one-liner. Not really sure why.

    EDIT: Knocked off a semicolon.

    Knocked off ANOTHER semicolon that I put on there because I've been looking at C too much lately.

    James Murphy

    Posted 2015-11-03T16:40:48.353

    Reputation: 267

    3You could use x=input() and then x>0 – Cyoce – 2016-09-20T17:41:02.160