Simple Programming Problem but How Many Ways to Do It?

47 views
Skip to first unread message

Charlie-Boo

unread,
Aug 26, 2023, 1:11:13 PMAug 26
to
Program 1 returns a Boolean value call it A.
Program 2 returns a Boolean value call it B.
We want one program that returns A ^ B (the value of A and B).
We don’t want to call 1 and 2.
We want to take the code in these two programs and create a new program.

Assume we have the common commands and expression elements e.g. those of PHP.
How many different programs can we create?

C-B

Richard Damon

unread,
Aug 26, 2023, 1:24:35 PMAug 26
to
A fundamental property of programming is that you can create an infinite
variation of programs that achieve a given goal. At least as long as the
requirements are written semantically (this is the result we need to
generate) and not with syntactic limits (it must be written this way).

THough you have a syntactic restriction in your definition (we can't
"call" A or B, since you can always replace a call to a function with
the code for that function, and you specified we have the code, we can
use this property.

Now, the question comes down to terminology, if you have multipe ways of
implementing a given algorithm, are they all "one program", or is each
implementation consider a different program.

Normal terminology calls them diferent programs, so your answer is infinite.

There may be a finite (but large) practical limit established by the
language you express the program in, and the machine it will be run on.

Charlie-Boo

unread,
Sep 2, 2023, 2:43:54 PMSep 2
to
I said use common programming language constructs e.g. PHP. As you create alternatives, you start to see the difference between algorithm and implementation.
Perhaps the simplest way is 3 parts. Assuming variable name conflicts are removed:
1. The code for A but save the value returned in variable A.
2. The code for B but save the value returned in variable B.
3. return A&&B

There ae LOTS more.

C-B

Richard Damon

unread,
Sep 3, 2023, 6:54:35 PMSep 3
to
Which is basically what I said.

Jeffrey Rubard

unread,
Sep 22, 2023, 2:06:19 PMSep 22
to
"Clap, clap, clap."

Jeffrey Rubard

unread,
Sep 23, 2023, 4:05:54 PMSep 23
to
Wider World: This is some of the worst 'claptrap' I have ever seen.

Jeffrey Rubard

unread,
Sep 24, 2023, 11:34:53 AMSep 24
to
The people "fooled" are primarily themselves, and that's unfortunate.

Julio Di Egidio

unread,
Sep 25, 2023, 3:42:39 AMSep 25
to
Spammers, more or less demented, this one is more: but there's
only one kind, the kind that should be shot into outer space...

*Spammer Alert*

Julio

Jeffrey Rubard

unread,
Sep 27, 2023, 6:17:51 PMSep 27
to
"Guys, I think your 'work' was more relevant in previous decades."
Reply all
Reply to author
Forward
0 new messages