# Shortest pristine truth machine

In this challenge, the goal is to create a pristine truth machine in as few bytes as possible. For reference, a truth machine does the following:

• Takes input, which is always 0 or 1
• If the input is 0, it is printed and the program terminates
• If the input is 1, it is printed forever

A pristine program is one that does not error on its own, but will error if any single substring with a length $$\1\le n is removed (where $$\p\$$ is the length of the program).

For example, if the main did not error in some language, it would be pristine if all of the following produced an error:

mai
man
min
ain
ma
mn
in
m
n


The goal of this challenge is to write the shortest program or function (in bytes, per language) which is a pristine truth machine.

• Related (truth machine, doesn't have to be pristine) Commented Oct 9, 2020 at 21:18
• Do warnings count as pristine? Also, are functions allowed to return either 0 or an infinite iterator that always returns 1? And if they are allowed, may their pristineness depend on them being a specific type (that is to say if the function changes return types may we assume something downstream will break)? Commented Oct 9, 2020 at 22:55
• Are empty programs supposed to error or do those not count? Commented Oct 9, 2020 at 23:00
• @Lyxal No, it says 1 <= n < p for the length of the segment removed, so there will always be one byte remaining at minimum. With a one byte solution, it's automatically pristine. Commented Oct 9, 2020 at 23:29
• Wow, nice! This is quite a tough challenge especially because we might run into an infinite loop when trying to verify the pristinity of our solution. And it requires knowing a language very well. Commented Oct 15, 2020 at 2:42

# Rust, 109 106 bytes

fn t(n:i8)->Result<Box::<Iterator::<Item=i8>>,i8>{if n==0{Err(0)}else{Ok(Box::new(std::iter::repeat(1)))}}


Try it online!

Returns a result whose ok variant is a dynamically typed iterator that always yields one wrapped in a smart pointer so the compiler can know its size. The error variant is simply zero. The code does emit a deprecation warning, so it may randomly stop working at some point in the future. Rust's type inference is too good for me to get a pristine closure, and as verbose as this solution is it is still shorting than fully listing the returned iterator's type and much shorter than using the main function and reading from stdin.

-3 bytes because there is a method to create an endlessly repeating iterator

• I think it doesn't error by itself if I remove the entire substring if n==0...else. Commented Oct 15, 2020 at 0:56
• @Bubbler it would because then the function would have a return type of () which is not what I specified. Commented Oct 15, 2020 at 1:08

# Ws, 1 byte

w


The s flag tells the program to get it's input from STDIN rather than arguments.

It's pristine because there is only one subset of program to remove.

The power of triviality.

• You might want to clarify with OP, but $1\le n<p$ I think implies that $p>1$ i.e. 1 byte programs cannot be pristine. Furthermore, can you provide a link to an interpreter? Commented Oct 9, 2020 at 22:56
• @cairdcoinheringaahing > No, it says 1 <= n < p for the length of the segment removed, so there will always be one byte remaining at minimum. With a one byte solution, it's automatically pristine. Commented Oct 9, 2020 at 23:29
• Interesting. I‘ve always seen pristine programs be a minimum of 2 bytes long (or the task not possible in a single byte). Commented Oct 9, 2020 at 23:37
• I didn't realize Flowey golfed.. Commented Oct 10, 2020 at 16:06
• @cairdcoinheringaahing I think 1 byte programs are a special case, I probably should have disallowed them, but luckily I doubt there're more than 20 or so languages where there's a 1 byte solution to this. Commented Oct 10, 2020 at 17:05

# C# (.NET Core), 159 bytes

class P{static void Main(string[]a){System.Console.Write(
#region
a[0]);while(1.ToString()==a[0]){System.Console.Write(a[
#region
0]);}}}
#endregion
#endregion


Try it online!

• There are unnecessary whitespaces, and l can be removed from #region (all of which make it not pristine). Removing them gives this. But unfortunately removing do does not error, so it's still invalid. Commented Oct 13, 2020 at 8:56
• @Bubbler thanks for the input, I've addressed your concerns and this should be better Commented Oct 13, 2020 at 9:29
• I think you didn't change the TIO link? And the space in string[] a is still there, and I can still remove do without erroring. Commented Oct 13, 2020 at 9:32
• I'll delete for now then, while I improve Commented Oct 13, 2020 at 10:02
• One day I'll get there Commented Oct 15, 2020 at 1:08