Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8468285
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T15:53:31+00:00 2026-06-10T15:53:31+00:00

It is a common programmer hobby to write programs which accomplish a task in

  • 0

It is a common programmer hobby to write programs which accomplish a task in 1 line of source code. But that is a bit trivial: I can take 1 000 000 lines of code, delete all the line breaks, and voila! 1 line!

So to make things interesting, we can count statements. For a C-style language, a simple of way of counting statements is counting semicolons: So nesting a million if-elses is fine.

Say you’ve got a program P with n statements. It goes through a sequence of states (variable values) s (where s is a vector) and produces output x. We can pose two questions:

  1. Can a program with fewer than n statements produce output x?
  2. Can a program with fewer than n statements go through some subset of s?

Immediately, some things become obvious. Take the following program:

int sum = a+b;
float mean = sum/2.0;
return mean;

We can refactor (or should I say “defactor”) this into a one liner:

return (a+b)/2.0;

Can every program be defactored to one line? Take this program:

string x = "";
for (int i = 0; i<a; i++)   // Should these semicolons count?
{
    x = x + ".";
}
return x;

It’s a bit more challenging.

The question can be answered exhaustively by trying every possible program with less than n statements, a number which is finite (theoretically you could have constants with infinitely many possible values, but no real language has infinite memory to store them or infinite disk space to accommodate the source code).

However:

A. Is it possible to prove for a program P which produces x (perhaps through s) with n statements that no Q which can do it in m statements can be found (in an efficient manner)?

B. Can the minimum n be found (in an efficient manner)?

C. Is minimum n guaranteed to be 1?

You can assume any language you want, although real languages would be more interesting. Please provide a definition of a “statement” in your language if your language is unusual.

I have assumed imperative languages, but adaptations of the problem to functional languages are welcome.

There is a trivial solution: For any P, run P and record x. Now write a program Q which simply prints x. For programs with input, make a very long if-else with each input mapped to a correct output.

This solution is unsatisfactory, although I’m not entirely sure why. Firstly, for infinite possible inputs it’s impossible (but I already covered my ass by saying real programs are finite, so we can say real input is finite). Second, it only technically passes through a subset of s: Namely the empty set. Third, it’s really anticlimactic.

Any help with defining away this little clever trick is also appreciated.

PS: For whatever my word is worth, this isn’t homework. I simply got curious about the problem and tried to phrase it as clearly as I could. Of course, I would still say that if it was homework, so…

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-10T15:53:32+00:00Added an answer on June 10, 2026 at 3:53 pm

    Since the concept of a statement is language specific, there are languages where every program can be written as a single statement or expression. Hell, there are even languages where every program must be written as a single expression.

    That said, assuming a language where this is not the case (and there definitely are such languages), the problem of finding the minimum of statements to solve a given problem will be neither in P nor NP – it’s undecidable.

    The question can be answered exhaustively by trying every possible program with less than n statements, a number which is finite

    Since some of those programs won’t terminate and it’s impossible to know which ones will (halting problem), that doesn’t work.

    Also the number of programs with less than n statements is not finite in most languages. For example there are an infinite number of statements of the form return foo + bar + ... + baz; in most languages.

    A. Is it possible to prove for a program P which produces x (perhaps through s) with n statements that no Q which can do it in m statements can be found (in an efficient manner)?

    (I’m assuming you forgot a m < n here, otherwise the question doesn’t make sense.)

    No, it can’t be proven at all.

    B. Can the minimum n be found (in an efficient manner)?

    No, it can’t be found at all.

    C. Is minimum n guaranteed to be 1?

    As I said at the beginning, it depends on the language and for the purpose of the above questions I assumed a language where the answer to this is no.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm just a hobbyist programmer, but I find that as my programs get longer
So one of the common tasks that I do as a programmer is debugging
A common problem is that for validation you need to run the same code
Introduction Hello, I'm that typical programmer that know how to use api, but tend
This is a rather broad question, but I'm a beginner-intermediate programmer that has just
What are all the common undefined behaviours that a C++ programmer should know about?
Common scenario: I have a library that uses other libraries. For example, a math
Common problem I'm sure, but I can't figure it out. In my AndroidManifest.xml and
A common question that comes up from time to time in the world of
I am an intermediate programmer, and have decided to learn either common lisp or

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.