473,383 Members | 1,813 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,383 software developers and data experts.

TWISTER 2: Read on....

TWISTER 2.1
¿? Your have to take a decision in a program but the creator of the
programming language forgot to supply the programmer with a IF-ELE
Construct? Can you find a work arround?

TWISTER 2.2
¿? You have to use loops and print 1 to 100 without using any kind of
looping not even GOTO statement? Can u do it?
(* *)
******************************0oo*********(_)***** *oo0**************************

SMALLEST CODE WILL BE APPRECIATED

:)

Nov 24 '06 #1
24 2271
Nirjhar Oberoi said:
TWISTER 2.1
¿? Your have to take a decision in a program but the creator of the
programming language forgot to supply the programmer with a IF-ELE
Construct? Can you find a work arround?
That depends on what you think IF-ELE should do. Personally, I think it
should subtract the value of ELE from the value of IF, yielding the
difference between the two. The workaround would be as follows:

diff = IF;
diff -= ELE;
TWISTER 2.2
¿? You have to use loops and print 1 to 100 without using any kind of
looping not even GOTO statement? Can u do it?
I don't think he can. I don't think anyone else can either, since using
loops without using any kind of looping is likely to challenge the
ingenuity of even the most perspicacious programmer. Nevertheless, printing
1 to 100 without using any kind of looping is trivial:

puts("1 to 100");
SMALLEST CODE WILL BE APPRECIATED
No problem. Here ya go:

main(){}

--
Richard Heathfield
"Usenet is a strange place" - dmr 29/7/1999
http://www.cpax.org.uk
email: rjh at the above domain, - www.
Nov 24 '06 #2
Richard Heathfield wrote:
Nirjhar Oberoi said:
.... snip ...
>
> ¿? You have to use loops and print 1 to 100 without using any
kind of looping not even GOTO statement? Can u do it?

I don't think he can. I don't think anyone else can either, since
using loops without using any kind of looping is likely to
challenge the ingenuity of even the most perspicacious programmer.
Nevertheless, printing 1 to 100 without using any kind of looping
is trivial:

puts("1 to 100");
You forgot about recursion:

#include <stdio.h>

void putn(int n) {
if (n - 1) putn(n - 1);
printf("%d\n", n);
}

int main(void) {putn(100); return 0;}

which even the all seeing u can use. Why do people give their
children one character names?

--
Chuck F (cbfalconer at maineline dot net)
Available for consulting/temporary embedded and systems.
<http://cbfalconer.home.att.net>
Nov 24 '06 #3
On 23 Nov 2006 21:40:06 -0800, "Nirjhar Oberoi" <ni*******@gmail.com>
wrote:
>TWISTER 2.1
¿? Your have to take a decision in a program but the creator of the
programming language forgot to supply the programmer with a IF-ELE
Construct? Can you find a work arround?
You may take a peek at local newspapaers, probably ther is some work
around, where you are not asked to make decisions. Street sweeping?
Maybe
>TWISTER 2.2
¿? You have to use loops and print 1 to 100 without using any kind of
looping not even GOTO statement? Can u do it?
Ah! that was VHDL, not C! Off Topic here.

library loops;
use loops.all;

print:std_logic_vector(1 to 100)=(others=>'U');

As you can see, not only U, but also OTHERS can do it!
SMALLEST CODE WILL BE APPRECIATED
Try with Huffman coding.

Regards,

Zara
Nov 24 '06 #4
CBFalconer said:
You forgot about recursion:
No, I didn't. I was saving that in case he turned out to be serious, and to
provide some effort of his own.

--
Richard Heathfield
"Usenet is a strange place" - dmr 29/7/1999
http://www.cpax.org.uk
email: rjh at the above domain, - www.
Nov 24 '06 #5
Richard Heathfield wrote:
CBFalconer said:
>You forgot about recursion:

No, I didn't. I was saving that in case he turned out to be serious,
and to provide some effort of his own.
Well, I kept the example subtly obtuse (the output order and end
points) to give him something to think about. However I think
"challenge the ingenuity of the most perspicacious" implies
impossibility or the need for non-standard code.

--
Chuck F (cbfalconer at maineline dot net)
Available for consulting/temporary embedded and systems.
<http://cbfalconer.home.att.net>
Nov 24 '06 #6
CBFalconer said:
Richard Heathfield wrote:
>CBFalconer said:
>>You forgot about recursion:

No, I didn't. I was saving that in case he turned out to be serious,
and to provide some effort of his own.

Well, I kept the example subtly obtuse (the output order and end
points) to give him something to think about. However I think
"challenge the ingenuity of the most perspicacious" implies
impossibility or the need for non-standard code.
Yes, I implied impossibility, and I stand by that. You can't use loops
without using loops, which is what he asked. A recursive call is not a loop
per se. Nevertheless, I agree that it is probably what his tutor had in
mind.

--
Richard Heathfield
"Usenet is a strange place" - dmr 29/7/1999
http://www.cpax.org.uk
email: rjh at the above domain, - www.
Nov 24 '06 #7
CBFalconer wrote:
Richard Heathfield wrote:
>>CBFalconer said:

>>>You forgot about recursion:

No, I didn't. I was saving that in case he turned out to be serious,
and to provide some effort of his own.


Well, I kept the example subtly obtuse (the output order and end
points) to give him something to think about. However I think
"challenge the ingenuity of the most perspicacious" implies
impossibility or the need for non-standard code.
The original problem statement, in full, was
¿? You have to use loops and print 1 to 100 without using any kind of
looping not even GOTO statement? Can u do it?
.... and neither CBF's nor RH's code meets the requirement to
"use loops." I offer the following as a possible solution:

#include <stdio.h>
int main(void) {
char buff[293], *p = buff;
int n;
for (n = 1; n <= 100; ++n) {
sprintf(p, "%d\n", n);
while (*p)
++p;
}
fputs (buff, stdout);
return 0;
}

This program

- Uses loops (two of them; it could have been simpler were
"loops" not in the plural)

- "and"

- Prints 1 to 100 without using any kind of looping (the
output is generated by one execution of an fputs() call).

However, even this doesn't answer the question. It doesn't matter
if I or CBF or RH can produce a solution; the question asks whether
the former Secretary General can do it. Anybody know how to get
in touch with him?

--
Eric Sosman
es*****@acm-dot-org.invalid
Nov 24 '06 #8
Eric Sosman said:

<snip>
>
The original problem statement, in full, was
¿? You have to use loops and print 1 to 100 without using any kind of
looping not even GOTO statement? Can u do it?

... and neither CBF's nor RH's code meets the requirement to
"use loops."
....and yours doesn't meet the requirement *not* to use "any kind of
looping".

--
Richard Heathfield
"Usenet is a strange place" - dmr 29/7/1999
http://www.cpax.org.uk
email: rjh at the above domain, - www.
Nov 24 '06 #9
Richard Heathfield wrote:
Eric Sosman said:

<snip>

The original problem statement, in full, was
¿? You have to use loops and print 1 to 100 without using any kind of
looping not even GOTO statement? Can u do it?
... and neither CBF's nor RH's code meets the requirement to
"use loops."

...and yours doesn't meet the requirement *not* to use "any kind of
looping".
There is no such requirement. There is a requirement to print 1 to 100
without using any kind of looping. Eric Sosman's code uses a loop, but
not for the actual printing.

Nov 24 '06 #10
Richard Heathfield wrote:
Eric Sosman said:

<snip>
> The original problem statement, in full, was
¿? You have to use loops and print 1 to 100 without using any kind of
looping not even GOTO statement? Can u do it?

... and neither CBF's nor RH's code meets the requirement to
"use loops."


...and yours doesn't meet the requirement *not* to use "any kind of
looping".
It "print[s] 1 to 100 without using any kind of looping."
All the loops are over and done with before the printing starts,
and the printing uses no loops. To look at it another way, I'm
choosing to parse the problem statement with a low precedence
assigned to "and."

--
Eric Sosman
es*****@acm-dot-org.invalid
Nov 24 '06 #11
Eric Sosman said:

<snip>
It "print[s] 1 to 100 without using any kind of looping."
All the loops are over and done with before the printing starts,
and the printing uses no loops. To look at it another way, I'm
choosing to parse the problem statement with a low precedence
assigned to "and."
Those 0s in "100" look suspiciously like loops to me! :-)
--
Richard Heathfield
"Usenet is a strange place" - dmr 29/7/1999
http://www.cpax.org.uk
email: rjh at the above domain, - www.
Nov 24 '06 #12
In article <MP********************@bt.com>,
Richard Heathfield <rj*@see.sig.invalidwrote:
>... and neither CBF's nor RH's code meets the requirement to
"use loops."
>...and yours doesn't meet the requirement *not* to use "any kind of
looping".
char *loops = "1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 "
"21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 "
"41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 "
"61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 "
"81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100";
printf("%s\n", loops);

-- Richard
--
"Consideration shall be given to the need for as many as 32 characters
in some alphabets" - X3.4, 1963.
Nov 24 '06 #13
Richard Tobin said:
In article <MP********************@bt.com>,
Richard Heathfield <rj*@see.sig.invalidwrote:
>>... and neither CBF's nor RH's code meets the requirement to
"use loops."
>>...and yours doesn't meet the requirement *not* to use "any kind of
looping".

char *loops = [...]
printf("%s\n", loops);
This fails to meet the req - oh, you SOAB. :-)

--
Richard Heathfield
"Usenet is a strange place" - dmr 29/7/1999
http://www.cpax.org.uk
email: rjh at the above domain, - www.
Nov 24 '06 #14

Nirjhar Oberoi wrote:
TWISTER 2.1
¿? Your have to take a decision in a program but the creator of the
programming language forgot to supply the programmer with a IF-ELE
Construct? Can you find a work arround?
Sure I can. Can't you? What do you think the trinary operator is used
for if not evaluating conditions? And that's just the most esoteric
one; there are also for(), while() and do() operations that could also
substitute for an if-else construct with some work.

OTOH, I'd fire any language developer who neglected to include if/else
in his C compiler, wouldn't you?
TWISTER 2.2
¿? You have to use loops and print 1 to 100 without using any kind of
looping not even GOTO statement? Can u do it?
Of course I can.

The simplest way is to just
puts("1 2 3 4 5 6 7 8 9 10");...
until you print all 99 of your numbers.

There are other, fancier ways, of course.

Nov 24 '06 #15
Consider this code and give ur Opinion

Code written in Turbo C
------------------------------------------------
#include <stdio.h>
#include <conio.h>

static int i = 1;

void foo() {
if (i 100)
return;
else {
printf("%d ",i);
foo();
}
}

int main(void) {
foo();
}
-------------------------------------------------

What say? will it work????

Ofcourse!!!!

Nov 24 '06 #16
Nirjhar Oberoi said:
Consider this code and give ur Opinion

Code written in Turbo C
Well, C, pretty much, if you just lose the conio.h header, which is
non-standard and which you don't need.
------------------------------------------------
#include <stdio.h>
#include <conio.h>

static int i = 1;

void foo() {
if (i 100)
return;
else {
printf("%d ",i);
foo();
}
}

int main(void) {
foo();
}
-------------------------------------------------

What say? will it work????
No.
>
Ofcourse!!!!
Of course not. Try it!

--
Richard Heathfield
"Usenet is a strange place" - dmr 29/7/1999
http://www.cpax.org.uk
email: rjh at the above domain, - www.
Nov 24 '06 #17
Nirjhar Oberoi wrote:

Please quote the message to which you're replying.
Consider this code and give ur Opinion

Code written in Turbo C
------------------------------------------------
#include <stdio.h>
#include <conio.h>

static int i = 1;

void foo() {
if (i 100)
return;
else {
printf("%d ",i);
foo();
}
}

int main(void) {
foo();
}
-------------------------------------------------

What say? will it work????

Ofcourse!!!!
No, it won't. Compile it and see.

Nov 24 '06 #18

Nirjhar Oberoi wrote:
TWISTER 2.1
¿? Your have to take a decision in a program but the creator of the
programming language forgot to supply the programmer with a IF-ELE
Construct? Can you find a work arround?

TWISTER 2.2
¿? You have to use loops and print 1 to 100 without using any kind of
looping not even GOTO statement? Can u do it?
OK, now make certain I get my share of your marks.

#include <stdio.h>
void CountTo(int n)
{
(n-1)?CountTo(n-1):0; printf("%d\n",n);
}

int main(void)
{
CountTo(100);
return 0;
}

Nov 24 '06 #19
Nirjhar Oberoi wrote:
>
Consider this code and give ur Opinion
Ur was an ancient city in Mesopotamia. I don't think the
inhabitants ever heard of the C language. Makes it hard for the
city to have an opinion.
>
Code written in Turbo C
So what?
------------------------------------------------
#include <stdio.h>
#include <conio.h>
Non-standard include. No such thing.
>
static int i = 1;

void foo() {
if (i 100)
return;
else {
printf("%d ",i);
foo();
}
}

int main(void) {
foo();
}
Failure to return a value. At least you defined main correctly.
With the corrections indicated the program will probably print "1"
some number of times and then crash. Or it might assassinate all
males over 15. Neither of these is especially desirable.

--
Chuck F (cbfalconer at maineline dot net)
Available for consulting/temporary embedded and systems.
<http://cbfalconer.home.att.net>
Nov 24 '06 #20
On Fri, 24 Nov 2006 16:29:01 -0500, CBFalconer <cb********@yahoo.com>
wrote:
>Nirjhar Oberoi wrote:
>>
Consider this code and give ur Opinion

Ur was an ancient city in Mesopotamia. I don't think the
inhabitants ever heard of the C language. Makes it hard for the
city to have an opinion.
The opinion of non-sentient objects, such as cities, is always
suspect.
Remove del for email
Nov 25 '06 #21

Lew Pitcher wrote:
Nirjhar Oberoi wrote:
TWISTER 2.1
¿? Your have to take a decision in a program but the creator of the
programming language forgot to supply the programmer with a IF-ELE
Construct? Can you find a work arround?

TWISTER 2.2
¿? You have to use loops and print 1 to 100 without using any kind of
looping not even GOTO statement? Can u do it?

OK, now make certain I get my share of your marks.
[snip first attempt]

Even better:

#include <stdio.h>
int CountTo(int n)
{
return printf("%d\n",(n-1)?CountTo(n-1):1), n+1;
}

int main(void)
{
CountTo(10);
return 0;
}

Nov 25 '06 #22

Lew Pitcher wrote:
Nirjhar Oberoi wrote:
TWISTER 2.1
¿? Your have to take a decision in a program but the creator of the
programming language forgot to supply the programmer with a IF-ELE
Construct? Can you find a work arround?

TWISTER 2.2
¿? You have to use loops and print 1 to 100 without using any kind of
looping not even GOTO statement? Can u do it?

OK, now make certain I get my share of your marks.
[snip first attempt]

Even better than the last one (which had a minor flaw in main()):

#include <stdio.h>
int CountTo(int n)
{
return printf("%d\n",(n-1)?CountTo(n-1):1), n+1;
}

int main(void)
{
CountTo(100);
return 0;
}

Nov 25 '06 #23
CBFalconer wrote:
Nirjhar Oberoi wrote:

Consider this code and give ur Opinion

Ur was an ancient city in Mesopotamia. I don't think the
inhabitants ever heard of the C language.
Ur probably right
Makes it hard for the city to have an opinion.
The OP asked for "ur Opinion", not "ur's Opinion".
As an aside, did u ever live in ur?

Nov 25 '06 #24
Old Wolf wrote:
CBFalconer wrote:
>Nirjhar Oberoi wrote:
>>>
Consider this code and give ur Opinion

Ur was an ancient city in Mesopotamia. I don't think the
inhabitants ever heard of the C language.

Ur probably right
>Makes it hard for the city to have an opinion.

The OP asked for "ur Opinion", not "ur's Opinion".
As an aside, did u ever live in ur?
Why ask me? Ask him. Why do you think that Ur was Republican?

--
Chuck F (cbfalconer at maineline dot net)
Available for consulting/temporary embedded and systems.
<http://cbfalconer.home.att.net>
Nov 25 '06 #25

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

11
by: Markus Breuer | last post by:
I have a question about oracle commit and transactions. Following scenario: Process A performs a single sql-INSERT into a table and commits the transaction. Then he informs process B (ipc) to...
31
by: Scott Robert Ladd | last post by:
I've posted my revised C++ implementation of the Mersenne Twister at: http://www.coyotegulch.com/libcoyote/TwistedRoad/TwistedRoad.html This is "free-as-in-liberty" and "free-as-in-beer" code....
12
by: Steven T. Hatton | last post by:
I know of a least one person who believes std::ifstream::read() and std::ofstream::write() are "mistakes". They seem to do the job I want done. What's wrong with them. This is the code I...
6
by: BBM | last post by:
I have an object that has a fairly complex construction sequence, so I have written a dedicated "factory" class that invokes the constructor of my object class (which does nothing but instantiate...
2
by: Martin Ho | last post by:
Hi Everyone, I have this code of Mersenne twister, which produces the random numbers, one of the fastest codes as far as I know to produce random numbers. Anyways, it's writen in c# and I need to...
1
by: Jose Reckoner | last post by:
I'm running python 2.3 on Windows XP. Anyone have a quick small script to convert .DT1 and .DEM data to ASCII or some other format? I don't need a viewer. Thanks!
11
by: Simon | last post by:
I have a quick question on the Mersenne Twister (hereinafter MT) I'm using the standard C code downloaded from the MT website (http://tinyurl.com/6d8t3). It's being used for a game to generate...
40
by: Spiros Bousbouras | last post by:
Do you have an example of an implementation where sizeof(short int) does not divide sizeof(int) or sizeof(int) does not divide sizeof(long int) or sizeof(long int) does not divide sizeof(long long...
0
by: bearophileHUGS | last post by:
This may be interesting for Python developers of the random module, "SIMD-oriented Fast Mersenne Twister (SFMT): twice faster than Mersenne Twister": ...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.