Page 1 of 3 123>
Topic Options
#128673 - 2004-10-30 09:26 PM This weekend's mini-putt challenge
Shawn Administrator Offline
Administrator
*****

Registered: 1999-08-13
Posts: 8611
Here's a weekend challenge if your bored and/or if its raining where you are (it is here) ... here's the challenge:

Write a single "For" loop with one and only one statement in it -- and no user-defined functions, no built-in functions, and no if-then, iif statements -- that produces the following output:

0 1 2 3 4 5 6 6 5 4 3 2 1 0

The for-loop has to be instrumental in producing the output (In other words, this solution, is not correct:

for $x = 1 to 1
?"0 1 2 3 4 5 6 6 5 4 3 2 1 0"
next

If you want to play, just post your code, then we can all join in and maybe golf it down some ...

-Shawn

Top
#128674 - 2004-10-30 11:08 PM Re: This weekend's mini-putt challenge
Les Offline
KiX Master
*****

Registered: 2001-06-11
Posts: 12734
Loc: fortfrances.on.ca
Ja, raining here too.

k, depending on what you mean by only one "statement" in the for loop...

Code:
$a = 0, 1, 2, 3, 4, 5, 6, 6, 5, 4, 3, 2, 1, 0
for each $ in $a
$ ' '
next


BTW, you did not forbid any statements outside the for loop.
_________________________
Give a man a fish and he will be back for more. Slap him with a fish and he will go away forever.

Top
#128675 - 2004-10-30 11:14 PM Re: This weekend's mini-putt challenge
Shawn Administrator Offline
Administrator
*****

Registered: 1999-08-13
Posts: 8611
Nice try, the solution must start with a FOR and end with a NEXT and have one statement inside ...


Top
#128676 - 2004-10-30 11:17 PM Re: This weekend's mini-putt challenge
Les Offline
KiX Master
*****

Registered: 2001-06-11
Posts: 12734
Loc: fortfrances.on.ca
If that bends the rules, then here's a twist.
Code:
for each $ in split('0 ,1 ,2 ,3 ,4 ,5 ,6 ,6 ,5 ,4 ,3 ,2 ,1 ,0 ',',')
$
next

_________________________
Give a man a fish and he will be back for more. Slap him with a fish and he will go away forever.

Top
#128677 - 2004-10-30 11:24 PM Re: This weekend's mini-putt challenge
Les Offline
KiX Master
*****

Registered: 2001-06-11
Posts: 12734
Loc: fortfrances.on.ca
Don't know what you mean by one statement. does this qualify as one statement?
Code:
for each $ in split('0 1 2 3 4 5 6 6 5 4 3 2 1 0')
$ ' '
next

_________________________
Give a man a fish and he will be back for more. Slap him with a fish and he will go away forever.

Top
#128678 - 2004-10-30 11:34 PM Re: This weekend's mini-putt challenge
Shawn Administrator Offline
Administrator
*****

Registered: 1999-08-13
Posts: 8611
Clever, your got 54, if anyone can do it in less than 54 strokes lets see it ...
Top
#128679 - 2004-10-31 01:32 AM Re: This weekend's mini-putt challenge
NTDOC Administrator Offline
Administrator
*****

Registered: 2000-07-28
Posts: 11625
Loc: CA
Well, tried a couple things but they didn't work out. I would say the Les' 2nd code posting is not valid as there are no spaces as shown in the posted requirements. His first code posting does work though.
Top
#128680 - 2004-10-31 01:35 AM Re: This weekend's mini-putt challenge
Les Offline
KiX Master
*****

Registered: 2001-06-11
Posts: 12734
Loc: fortfrances.on.ca
What are you talking about? The line:
$ ' '
puts spaces between the numbers on my screen. Or is that what you consider my third?
In that case the one before that one put spaces in the output also. In fact all three have spaces.


Edited by Les (2004-10-31 01:38 AM)
_________________________
Give a man a fish and he will be back for more. Slap him with a fish and he will go away forever.

Top
#128681 - 2004-10-31 01:57 AM Re: This weekend's mini-putt challenge
NTDOC Administrator Offline
Administrator
*****

Registered: 2000-07-28
Posts: 11625
Loc: CA
I was talking about your 3rd post. You're correct boss, I was mistaken. I was messing around with my own code and yours and had left your ? '' as only ?

I take it back. You're still the champ unless someone else comes along with something better.

Top
#128682 - 2004-10-31 02:10 PM Re: This weekend's mini-putt challenge
Howard Bullock Offline
KiX Supporter
*****

Registered: 2000-09-15
Posts: 5809
Loc: Harrisburg, PA USA
Code:
for $=1 to 14

SUBSTR('01234566543210',$,1) " "
next



I guess this does not work as it uses a function. But Les' uses the split function or is it that the function CAN be part of the FOR line?


Edited by Howard Bullock (2004-10-31 02:29 PM)
_________________________
Home page: http://www.kixhelp.com/hb/

Top
#128683 - 2004-10-31 02:54 PM Re: This weekend's mini-putt challenge
Sealeopard Offline
KiX Master
*****

Registered: 2001-04-25
Posts: 11165
Loc: Boston, MA, USA
SPLIT() is a build-in function and thus is disqualified :-)
_________________________
There are two types of vessels, submarines and targets.

Top
#128684 - 2004-10-31 02:57 PM Re: This weekend's mini-putt challenge
Shawn Administrator Offline
Administrator
*****

Registered: 1999-08-13
Posts: 8611
Jen's is right, no builtin funcs ... sorry Les, that goes for you too Howard. Just know that there *are* definitely solutions to this challenge.
Top
#128685 - 2004-10-31 03:19 PM Re: This weekend's mini-putt challenge
Howard Bullock Offline
KiX Supporter
*****

Registered: 2000-09-15
Posts: 5809
Loc: Harrisburg, PA USA
ok, back to the script editor and testing window...
_________________________
Home page: http://www.kixhelp.com/hb/

Top
#128686 - 2004-10-31 03:50 PM Re: This weekend's mini-putt challenge
Howard Bullock Offline
KiX Supporter
*****

Registered: 2000-09-15
Posts: 5809
Loc: Harrisburg, PA USA
Code:
for $=0 to 0

$ " " $+1 " " $+2 " " $+3 " " $+4 " " $+5 " " $+6 " "$+6 " " $+5 " " $+4 " " $+3 " " $+2 " " $+1 " " $
next



Although the loop only executes once, the variable used in the FOR loop is an integral put of the output.


Edited by Howard Bullock (2004-10-31 03:54 PM)
_________________________
Home page: http://www.kixhelp.com/hb/

Top
#128687 - 2004-10-31 04:24 PM Re: This weekend's mini-putt challenge
Shawn Administrator Offline
Administrator
*****

Registered: 1999-08-13
Posts: 8611
Ok, the current score is 90 ... Would suggest though that this can be done in half the strokes, here's another approach to the problem, this scores a 70

Code:

for $i = 0 to 13
(($i / 7) * (((($i / 7) * 6) - ($i mod 7)) * 2)) + (($i mod 7) - (($i / 7) * 6)) " "
next



-Shawn

Top
#128688 - 2004-10-31 04:32 PM Re: This weekend's mini-putt challenge
Howard Bullock Offline
KiX Supporter
*****

Registered: 2000-09-15
Posts: 5809
Loc: Harrisburg, PA USA
Ugh mod is an operator...

My feeble mind did not even go there. What math book have you been reading this week?
_________________________
Home page: http://www.kixhelp.com/hb/

Top
#128689 - 2004-10-31 04:34 PM Re: This weekend's mini-putt challenge
Shawn Administrator Offline
Administrator
*****

Registered: 1999-08-13
Posts: 8611
Didn't say you couldn't use operators ... +/-* are operators too. ;0)

I'm being evil this weekend, check-out my scary avatar music <===

Just for the record ... I didn't write that solution.

Top
#128690 - 2004-10-31 04:47 PM Re: This weekend's mini-putt challenge
Les Offline
KiX Master
*****

Registered: 2001-06-11
Posts: 12734
Loc: fortfrances.on.ca
Dang, I was playing with MOD but all those order of precedence parens were hurting my brain.
_________________________
Give a man a fish and he will be back for more. Slap him with a fish and he will go away forever.

Top
#128691 - 2004-11-01 12:06 AM Re: This weekend's mini-putt challenge
Chris S. Offline
MM club member
*****

Registered: 2002-03-18
Posts: 2368
Loc: Earth
Howsabout...

Code:

For $ = -13 to 13 Step 2
($ / 2 + 6 * -($ Mod 2)) * ($ Mod 2) * -1 ' '
Next


Top
#128692 - 2004-11-01 01:05 AM Re: This weekend's mini-putt challenge
Shawn Administrator Offline
Administrator
*****

Registered: 1999-08-13
Posts: 8611
Nice one ... 51 !!!
Top
Page 1 of 3 123>


Moderator:  Arend_, Allen, Jochen, Radimus, Glenn Barnas, ShaneEP, Ruud van Velsen, Mart 
Hop to:
Shout Box

Who's Online
0 registered and 1574 anonymous users online.
Newest Members
BeeEm, min_seow, Audio, Hoschi, Comet
17882 Registered Users

Generated in 0.096 seconds in which 0.045 seconds were spent on a total of 13 queries. Zlib compression enabled.

Search the board with:
superb Board Search
or try with google:
Google
Web kixtart.org