Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > sci.physics > #644321 > unrolled thread
| Started by | Snit <usenet@gallopinginsanity.com> |
|---|---|
| First post | 2017-08-03 22:11 -0700 |
| Last post | 2017-08-05 09:55 -0700 |
| Articles | 20 on this page of 24 — 7 participants |
Back to article view | Back to sci.physics
This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by
below is the oldest one visible, not the original post.
Re: 4 lines, 4 states. Snit <usenet@gallopinginsanity.com> - 2017-08-03 22:11 -0700
Re: 4 lines, 4 states. Snit <usenet@gallopinginsanity.com> - 2017-08-03 22:47 -0700
Re: 4 lines, 4 states. Snit <usenet@gallopinginsanity.com> - 2017-08-03 22:52 -0700
Re: Mozilla ThunderBird. Snit <usenet@gallopinginsanity.com> - 2017-08-04 10:43 -0700
Re: FizzBuzz is a trick question. Snit <usenet@gallopinginsanity.com> - 2017-08-04 11:47 -0700
Re: Michael Glasser, Steve Carroll, Marek Novotny, Branimir Maksimovic, etc. Snit <usenet@gallopinginsanity.com> - 2017-08-04 12:51 -0700
Re: I'm the best c coder here. Snit <usenet@gallopinginsanity.com> - 2017-08-04 14:03 -0700
Re: I'm the best c coder here. "F. Russell" <fr@random.info> - 2017-08-04 23:15 +0000
Re: I'm the best c coder here. benj <benj@nobody.net> - 2017-08-04 19:35 -0400
Re: I'm the best c coder here. "F. Russell" <fr@random.info> - 2017-08-05 16:08 +0000
Re: Fabian seldom writes code, much less test it. owl <owl@rooftop.invalid> - 2017-08-05 03:09 +0000
Re: 2 lines, 2^2 states, easily modified to 3^2 states. owl <owl@rooftop.invalid> - 2017-08-05 05:42 +0000
Re: Fabian seldom writes code, much less test it. "F. Russell" <fr@random.info> - 2017-08-05 13:37 +0000
Re: Fabian seldom writes code, much less test it. "F. Russell" <fr@random.info> - 2017-08-05 14:25 +0000
Re: I'm the best c coder here. owl <owl@rooftop.invalid> - 2017-08-05 03:22 +0000
Re: I'm _still_ the best c coder here. owl <owl@rooftop.invalid> - 2017-08-05 06:12 +0000
Re: Owl's FizBuzGozKaz branches 5 times more often. owl <owl@rooftop.invalid> - 2017-08-05 15:40 +0000
Re: I'm _still_ the best c coder here. moroney@world.std.spaamtrap.com (Michael Moroney) - 2017-08-05 22:16 +0000
Re: I increment things at the _start_ of a loop. moroney@world.std.spaamtrap.com (Michael Moroney) - 2017-08-07 03:24 +0000
Re: I increment things at the _start_ of a loop. Snit <usenet@gallopinginsanity.com> - 2017-08-06 20:35 -0700
Re: "while ( x++ < 100 )" isn't "obscure". moroney@world.std.spaamtrap.com (Michael Moroney) - 2017-08-07 04:59 +0000
Re: I'm the best c coder here. chrisv <chrisv@nospam.invalid> - 2017-08-07 06:59 -0500
Re: Michael Glasser, Steve Carroll, Marek Novotny, Branimir Maksimovic, etc. Doomsdrzej <.m@nsn.s> - 2017-08-05 11:52 -0400
Re: Michael Glasser, Steve Carroll, Marek Novotny, Branimir Maksimovic, etc. Snit <usenet@gallopinginsanity.com> - 2017-08-05 09:55 -0700
Page 1 of 2 [1] 2 Next page →
| From | Snit <usenet@gallopinginsanity.com> |
|---|---|
| Date | 2017-08-03 22:11 -0700 |
| Subject | Re: 4 lines, 4 states. |
| Message-ID | <D5A94FFB.AEA24%usenet@gallopinginsanity.com> |
On 8/3/17, 8:00 PM, in article Jeff-Relf.Me@Aug.3--8.00pm.Seattle.2017,
"<Jeff-Relf.Me @.>" <> wrote:
>
> Michael Glasser, Your (Apple)Script is:
>
> 22 confusing lines and 5 thousand times slower. ( and a pegged CPU ? )
I posted two solutions, each with a line that sets the variable of how many
numbers to calculate... could have that built in. Removing that and getting
rid of the line breaks put in for clarity and it is five lines. But, not
sure that matters. In case you care (will get wrapped by usenet I am sure):
-----
set responseList to {""} as list
repeat with loop from 0 to 100000 by 15
set responseList to responseList & loop + 1 & return & loop + 2 & return
& "Fizz" & return & loop + 4 & return & "Buzz" & return & "Fizz" & return &
loop + 7 & return & loop + 8 & return & "Fizz" & return & "Buzz" & return &
loop + 11 & return & "Fizz" & return & loop + 13 & return & loop + 14 &
return & "FizzBuzz" & return
end repeat
do shell script "echo " & (items 1 through (100000) of responseList as
string) & " > /Users/snit/Desktop/FizzBuzz2.txt"
-----
I could reduce that and put the writing into the loop... then I get four
lines:
-----
set responseList to {""} as list
repeat with loop from 0 to 100000 by 15
do shell script "echo " & loop + 1 & return & loop + 2 & return & "Fizz"
& return & loop + 4 & return & "Buzz" & return & "Fizz" & return & loop + 7
& return & loop + 8 & return & "Fizz" & return & "Buzz" & return & loop + 11
& return & "Fizz" & return & loop + 13 & return & loop + 14 & return &
"FizzBuzz" & return & " >> /Users/snit/Desktop/FizzBuzz.txt"
end repeat
-----
Then your comment about a pegged CPU? What? I said nothing about that. Not a
word.
BUT, of course, this is AppleScript and it is going to be VERY slow compared
to other languages. That is not at all in question.
> Owl, Fabian and me can do 100 thousand runs in 20 MilliSeconds.
> ScreenShot: http://Jeff-Relf.Me/FizBuz.PNG
Clearly our solution will be MASSIVELY faster, but I thought the numbers
were supposed to be REPLACED by the words... not added to them.
> For us, it doesn't matter if we use "i%3" or not,
> as the I/O is the limiting factor, not "i%3".
Yes, I suspect the I/O for macOS is slowing mine down as well, though even
without they it would be painfully slow. Not really a job handled well by
AppleScript... I was just curious.
> Assembly language wouldn't help.
> So I chose _the _most _readable option;
> to wit, these 4 lines, 4 states:
>
> int i = 0 ;
> while( i++
Your code got cut off.
--
Personal attacks from those who troll show their own insecurity. They cannot
use reason to show the message to be wrong so they try to feel somehow
superior by attacking the messenger.
They cling to their attacks and ignore the message time and time again.
<https://youtu.be/H4NW-Cqh308>
[toc] | [next] | [standalone]
| From | Snit <usenet@gallopinginsanity.com> |
|---|---|
| Date | 2017-08-03 22:47 -0700 |
| Message-ID | <D5A9589C.AEA30%usenet@gallopinginsanity.com> |
| In reply to | #644321 |
On 8/3/17, 10:11 PM, in article D5A94FFB.AEA24%usenet@gallopinginsanity.com,
"Snit" <usenet@gallopinginsanity.com> wrote:
> On 8/3/17, 8:00 PM, in article Jeff-Relf.Me@Aug.3--8.00pm.Seattle.2017,
> "<Jeff-Relf.Me @.>" <> wrote:
>
>>
>> Michael Glasser, Your (Apple)Script is:
>>
>> 22 confusing lines and 5 thousand times slower. ( and a pegged CPU ? )
>
> I posted two solutions, each with a line that sets the variable of how many
> numbers to calculate... could have that built in. Removing that and getting
> rid of the line breaks put in for clarity and it is five lines. But, not
> sure that matters. In case you care (will get wrapped by usenet I am sure):
>
> -----
> set responseList to {""} as list
> repeat with loop from 0 to 100000 by 15
> set responseList to responseList & loop + 1 & return & loop + 2 & return
> & "Fizz" & return & loop + 4 & return & "Buzz" & return & "Fizz" & return &
> loop + 7 & return & loop + 8 & return & "Fizz" & return & "Buzz" & return &
> loop + 11 & return & "Fizz" & return & loop + 13 & return & loop + 14 &
> return & "FizzBuzz" & return
> end repeat
> do shell script "echo " & (items 1 through (100000) of responseList as
> string) & " > /Users/snit/Desktop/FizzBuzz2.txt"
> -----
>
>
> I could reduce that and put the writing into the loop... then I get four
> lines:
>
> -----
> set responseList to {""} as list
> repeat with loop from 0 to 100000 by 15
> do shell script "echo " & loop + 1 & return & loop + 2 & return & "Fizz"
> & return & loop + 4 & return & "Buzz" & return & "Fizz" & return & loop + 7
> & return & loop + 8 & return & "Fizz" & return & "Buzz" & return & loop + 11
> & return & "Fizz" & return & loop + 13 & return & loop + 14 & return &
> "FizzBuzz" & return & " >> /Users/snit/Desktop/FizzBuzz.txt"
> end repeat
> -----
>
> Then your comment about a pegged CPU? What? I said nothing about that. Not a
> word.
>
> BUT, of course, this is AppleScript and it is going to be VERY slow compared
> to other languages. That is not at all in question.
Just tested 100,000: running from Script Editor I got bored waiting... was
taking minutes. Even running as a saved application it took 65 seconds! And,
given that I calculate 15 at a time my method handles 100,005 lines, which
is not what was asked for so in that way my program is broken.
In case you want to watch this amazing spectacle (time sped up to avoid
boring everyone to tears):
<https://youtu.be/Ak50RS9Y2xw>
Took 63 seconds for this run... CPU(s) *NOT* pegged. It looks like the app
is not multi-threaded or whatever... does not go above 100% of a single CPU.
Might be faster if it did. :)
...
--
Personal attacks from those who troll show their own insecurity. They cannot
use reason to show the message to be wrong so they try to feel somehow
superior by attacking the messenger.
They cling to their attacks and ignore the message time and time again.
<https://youtu.be/H4NW-Cqh308>
[toc] | [prev] | [next] | [standalone]
| From | Snit <usenet@gallopinginsanity.com> |
|---|---|
| Date | 2017-08-03 22:52 -0700 |
| Message-ID | <D5A959A5.AEA34%usenet@gallopinginsanity.com> |
| In reply to | #644321 |
On 8/3/17, 10:31 PM, in article Jeff-Relf.Me@Aug.3--10.31pm.Seattle.2017,
"<Jeff-Relf.Me @.>" <> wrote:
>
> You ( MichaelGlasser ) replied ( to me ):
>> Then your comment about a pegged CPU? What?
>
> It was a question, not a comment.
Well, the answer is no... does not peg. Goes up to about 100% (with multiple
CPUs of course programs can go higher than that).
>> I said nothing about that. Not a word.
>
> Yes, but does it peg the CPU ?
Nope. Sorry for misunderstanding -- though you were saying it DOES peg the
CPU. Not at all. If it did it might be a bit LESS dog slow. :)
>> BUT, of course, this is AppleScript and it is going to be
>> VERY slow compared to other languages.
>> That is not at all in question.
>
> 5 thousand times slower, 8 times the lines, and more complex.
Well, the logic can be changed... and lines reduced, but, sure, it is going
to be MUCH slower. It is easier for non-programmers to read and write, but
it SUCKS if your goal is fast calculations!
<https://youtu.be/Ak50RS9Y2xw>
That is the splendor of my solution. :)
>>> So I chose _the _most _readable option;
>>> to wit, these 4 lines, 4 states:
>>>
>>> int i = 0 ;
>>> while( i++ < 100000 )
>>> i%3 ? ( i%5 ? Sh( L"%d", i ) : Sh( L"Buz" ) )
>>> : i%5 ? Sh( L"Fiz" ) : Sh( L"FizBuz" );
>>
>> Your code got cut off.
>
> Your newsreader is decades old, right ?
2008
> Why not upgrade it ?
I might... will likely have to with the next OS update. :)
> GoogleGroups/FireFox handles it fine, see:
>
> https://groups.google.com/d/msg/sci.physics/8DISFYs-DSo/b8ji_8KyCQAJ
Yup... my newsreader sucks.
Anyway, what about yours NOT having the numbers where it is not supposed to?
Maybe you are keeping that so at least in one way my solution is better? :)
--
Personal attacks from those who troll show their own insecurity. They cannot
use reason to show the message to be wrong so they try to feel somehow
superior by attacking the messenger.
They cling to their attacks and ignore the message time and time again.
<https://youtu.be/H4NW-Cqh308>
[toc] | [prev] | [next] | [standalone]
| From | Snit <usenet@gallopinginsanity.com> |
|---|---|
| Date | 2017-08-04 10:43 -0700 |
| Subject | Re: Mozilla ThunderBird. |
| Message-ID | <D5AA006B.AEAF4%usenet@gallopinginsanity.com> |
| In reply to | #644328 |
On 8/4/17, 12:35 AM, in article Jeff-Relf.Me@Aug.4--0.35am.Seattle.2017, "<Jeff-Relf.Me @.>" <> wrote: > > You ( Michael Glasser ) replied ( to me ): >>> GoogleGroups/FireFox [ display my posts ] fine, see: >>> https://groups.google.com/d/msg/sci.physics/8DISFYs-DSo/b8ji_8KyCQAJ >> >> Yup... my newsreader sucks. > > Mozilla ThunderBird is good, and you can write extensions for it, > using JavaScript, or change the look, using CSS. Very powerful. > Most people can't be bothered to learn it, of course. I have fiddled with it... if I recall correctly it does not have smart folders that allowed me to set up rules as well as the ancient piece of garbage I now use. Could be wrong... but there was SOMETHING that was not working well for me with it. Sure I could get used to it though. > I wish you ( and everyone else ) stopped posting "signatures"; > I even hate EdProchak's tiny little "ed" sig, at then end of his posts. > But that's just me, of course. I think the standard is to be no longer than four lines or something like that... so mine is a bit long. As long as people use the proper delimiter, though, I do not mind them... pretty much just ignore them. >> Owl, Fabian and me can do 100 thousand runs in 20 MilliSeconds. >> ScreenShot: http://Jeff-Relf.Me/FizBuz.PNG >> >> what about yours NOT having the numbers where it is not supposed to? >> Maybe you are keeping that so at least in one way my solution is better? :) > > Fabian's code was the last to run; so the ScreenShot shows his verion; > His is slower because he prints more, like that; no biggie. Seems to me if you are NOT avoiding those numbers then you are not doing the task the way the kid's game is played, which I thought was the requirement... but I admit I have not even gone back to look. I largely posted the AppleScript solution to show how BAD it is in terms of speed (and how crappy of a scripter I am!) -- Personal attacks from those who troll show their own insecurity. They cannot use reason to show the message to be wrong so they try to feel somehow superior by attacking the messenger. They cling to their attacks and ignore the message time and time again. <https://youtu.be/H4NW-Cqh308>
[toc] | [prev] | [next] | [standalone]
| From | Snit <usenet@gallopinginsanity.com> |
|---|---|
| Date | 2017-08-04 11:47 -0700 |
| Subject | Re: FizzBuzz is a trick question. |
| Message-ID | <D5AA0F44.AEB1A%usenet@gallopinginsanity.com> |
| In reply to | #644374 |
On 8/4/17, 11:42 AM, in article Jeff-Relf.Me@Aug.4--11.42am.Seattle.2017,
"<Jeff-Relf.Me @.>" <> wrote:
>
> You ( Michael Glasser ) replied ( to me ):
>>> Mozilla ThunderBird is good, and you can write extensions for it,
>>> using JavaScript, or change the look, using CSS. Very powerful.
>>> Most people can't be bothered to learn it, of course.
>>
>> I have fiddled with it... if I recall correctly it does not have smart
>> folders that allowed me to set up rules as well as the ancient piece of
>> garbage I now use. Could be wrong... but there was SOMETHING that was not
>> working well for me with it. Sure I could get used to it though.
>
> Getting it to work properly ( extensions, settings, CSS and all )
> would take a ( painfully ) long time, I imagine.
Could be... I only gave it a few minutes to impress me. It did not so I
moved on. But given how crappy my current client is, how old it is, and how
it is likely to die on the next OS update I suppose I should look into it
again. :)
>> I largely posted the AppleScript [ version of FizzBuzz ]
>> to show how BAD it is in terms of speed ( and how crappy
>> of a scripter I am! ).
>
> FizBuz is a trick question, designed to see if you:
> A. foolishly optimize random shit. Or:
> B. write concise, readable code.
>
> My answer: http://jeff-relf.me/FizBuz.HTM
>
One of my early efforts was this:
-------
set theList to {} as list
repeat with loop from 1 to 10000
if loop mod 15 = 0 then
set theList to theList & "FizzBuzz" & return
else if loop mod 3 = 0 then
set theList to theList & "Fizz" & return
else if loop mod 5 = 0 then
set theList to theList & "Buzz" & return
else
set theList to theList & loop & return
end if
end repeat
do shell script "echo " & theList & " >>
/Users/snit/Desktop/FizzBuzz/FizzBuzz2.txt"
-------
That is very readable... as was one that used division. If I really wanted
it to work better, though, I would have it write to file every 1000 lines or
so -- but never bothered to do that. :)
Of course if I presented that for a PROGRAMMING job they would laugh their
asses off at me and ask why I am not using an actual programming language!
--
Personal attacks from those who troll show their own insecurity. They cannot
use reason to show the message to be wrong so they try to feel somehow
superior by attacking the messenger.
They cling to their attacks and ignore the message time and time again.
<https://youtu.be/H4NW-Cqh308>
[toc] | [prev] | [next] | [standalone]
| From | Snit <usenet@gallopinginsanity.com> |
|---|---|
| Date | 2017-08-04 12:51 -0700 |
| Subject | Re: Michael Glasser, Steve Carroll, Marek Novotny, Branimir Maksimovic, etc. |
| Message-ID | <D5AA1E4B.AEB45%usenet@gallopinginsanity.com> |
| In reply to | #644393 |
On 8/4/17, 12:31 PM, in article Jeff-Relf.Me@Aug.4--0.31pm.Seattle.2017, "<Jeff-Relf.Me @.>" <> wrote: > > You ( Michael Glasser ) replied ( to me ): >> If I really wanted it to work better, though, >> I would have it write to file every 1000 lines or so >> -- but never bothered to do that. :) > > Even that optimization would do more harm than good, I think. > Try it, and time it; it wouldn't be faster, I bet. Did not try it, but when I did 10,000 it did it, um, was going to say "fairly quickly" but that is not the right phrase... in less time than it takes to have a pizza delivered. :) I think it was 9 seconds or so. When I went up to 100,000, though, I expected 90 seconds or so... but waited for over five and then gave up on it. AppleScript is known for memory leaks and other nonsense so I am guessing it pretty much died. If I care I can check again... >> Of course if I presented that for a PROGRAMMING job >> they would laugh their asses off at me and ask why >> I am not using an actual programming language! > > Well... it tells them: > > Michael Glasser is an AppleScript guy. And not a good one, at that! > Steve Carroll is all about JavaScript. And WordPress. Surprised he did not point to a WordPress plugin to try it. :) > Marek Novotny is a command line jockey. He clearly has some good skills. No doubt. > Branimir Maksimovic is a DownToTheMetal Assembly Language guy. > > Owl, Fabian and Jeff Relf are c programmers. At the very least Owl seems to know what he is doing, too. What I find funny is how Owl and Marek, who both EASILY blow me away with their scripting / programming abilities (not even a close call here) seem hell-bent on proving their worth by showing they can do things I cannot. Um, yeah, this simple exercise is enough to see that. Not only do I use a tool that is crappy for the job (assuming you want more than 100) but I do not even use it well! -- Personal attacks from those who troll show their own insecurity. They cannot use reason to show the message to be wrong so they try to feel somehow superior by attacking the messenger. They cling to their attacks and ignore the message time and time again. <https://youtu.be/H4NW-Cqh308>
[toc] | [prev] | [next] | [standalone]
| From | Snit <usenet@gallopinginsanity.com> |
|---|---|
| Date | 2017-08-04 14:03 -0700 |
| Subject | Re: I'm the best c coder here. |
| Message-ID | <D5AA2F2C.AEB69%usenet@gallopinginsanity.com> |
| In reply to | #644393 |
On 8/4/17, 1:48 PM, in article Jeff-Relf.Me@Aug.4--1.48pm.Seattle.2017, "<Jeff-Relf.Me @.>" <> wrote: > > I'm the best c coder here, I think. > > Fabian optimized something he shouldn't have; > the I/O is thee only limiting factor, not "x%3". > > Also, he failed to test the code he wrote, > and _failed_ to compare it with mine. > Usually, he fails to write _any_ code, much less test it. > > Owl failed to write concise, readable code; > instead, he foolishly optimized the wrong thing. Owl does WEIRD things like, to avoid picking colors manually for his terminal program, he creates something like 52K launchers which are all the same EXCEPT for their color... then picks them based on MANUALLY PiCKING A COLOR! If it works for him, great... but just weird. > Marek Novotny's c was better than Owl's or Fabian's, > but it wasn't as concise|readable as mine, I think. > Initially, he chose bash, not c. > -- Personal attacks from those who troll show their own insecurity. They cannot use reason to show the message to be wrong so they try to feel somehow superior by attacking the messenger. They cling to their attacks and ignore the message time and time again. <https://youtu.be/H4NW-Cqh308>
[toc] | [prev] | [next] | [standalone]
| From | "F. Russell" <fr@random.info> |
|---|---|
| Date | 2017-08-04 23:15 +0000 |
| Subject | Re: I'm the best c coder here. |
| Message-ID | <om2v602ceo@news4.newsguy.com> |
| In reply to | #644393 |
On Fri, 04 Aug 2017 13:48:29 -0700, Jeff-Relf.Me wrote: > <PRE Style='Font-Family: OCR A, monospace !important;'> > I'm the best c coder here, I think. > Yeah. Just like your expertise in physics, you think. Ha, ha, ha, ha, ha, ha, ha, ha, ha, ha, ha, ha! If any of your employers/clients could see the moronic gibberish which you post on sci.physics, they wouldn't want to come within TWENTY MILES of your "code." > > the I/O is thee only limiting factor, not "x%3" > The I/O can easily be separated from the decision process by using some sort of index (either an array or bit fields). Then, _my_ DIVISION-LESS algorithm will surpass all others. But the problem is exceedingly trivial. It is a sign of stupidity to dwell on it.
[toc] | [prev] | [next] | [standalone]
| From | benj <benj@nobody.net> |
|---|---|
| Date | 2017-08-04 19:35 -0400 |
| Subject | Re: I'm the best c coder here. |
| Message-ID | <598504ad$0$60192$c3e8da3$66d3cc2f@news.astraweb.com> |
| In reply to | #644434 |
On 8/4/2017 7:15 PM, F. Russell wrote: > On Fri, 04 Aug 2017 13:48:29 -0700, Jeff-Relf.Me wrote: > >> <PRE Style='Font-Family: OCR A, monospace !important;'> >> I'm the best c coder here, I think. >> > > Yeah. Just like your expertise in physics, you think. > > Ha, ha, ha, ha, ha, ha, ha, ha, ha, ha, ha, ha! > > If any of your employers/clients could see the moronic > gibberish which you post on sci.physics, they wouldn't > want to come within TWENTY MILES of your "code." > >> >> the I/O is thee only limiting factor, not "x%3" >> > > The I/O can easily be separated from the decision process > by using some sort of index (either an array or bit fields). > > Then, _my_ DIVISION-LESS algorithm will surpass all others. > > But the problem is exceedingly trivial. It is a sign of stupidity > to dwell on it. > Which is obvious so why dwell on it?
[toc] | [prev] | [next] | [standalone]
| From | "F. Russell" <fr@random.info> |
|---|---|
| Date | 2017-08-05 16:08 +0000 |
| Subject | Re: I'm the best c coder here. |
| Message-ID | <om4qhr02i7r@news3.newsguy.com> |
| In reply to | #644439 |
On Fri, 04 Aug 2017 19:35:08 -0400, benj wrote: >> >> But the problem is exceedingly trivial. It is a sign of stupidity >> to dwell on it. >> > Which is obvious so why dwell on it? > Which is why you bothered to jump in here. Ha, ha, ha, ha, ha!
[toc] | [prev] | [next] | [standalone]
| From | owl <owl@rooftop.invalid> |
|---|---|
| Date | 2017-08-05 03:09 +0000 |
| Subject | Re: Fabian seldom writes code, much less test it. |
| Message-ID | <szbagi03.ab@rooftop.invalid> |
| In reply to | #644434 |
In comp.os.linux.advocacy Jeff-Relf.Me wrote:
> You ( Fabian ) replied ( to me ):
> > > [ FizBuz's ] I/O is thee only limiting factor, not "x%3".
> >
> > The I/O can easily be separated from the decision process
> > by using some sort of index (either an array or bit fields).
> > Then, _my_ DIVISION-LESS algorithm will surpass all others.
> > But the problem is exceedingly trivial.
> > It is a sign of stupidity to dwell on it.
>
> Forget this "DIVISION-LESS algorithm" bullshit, the answer is just:
>
> int x = 0, F, B ;
> while ( x++ < 100 ) printf("\n"), F = !(x%3), B = !(x%5), printf(
> F && B ? "FizBuz" : F ? "Fiz" : B ? "Buz" : "%d", x );
>
> 3 lines, 4 states, done.
>
Because nothing says "readable" and "maintainable" like a bunch of nested
ternary operations.... Try it with four values, where your state count
goes to 16. See how "readable" that is with your approach.
[toc] | [prev] | [next] | [standalone]
| From | owl <owl@rooftop.invalid> |
|---|---|
| Date | 2017-08-05 05:42 +0000 |
| Subject | Re: 2 lines, 2^2 states, easily modified to 3^2 states. |
| Message-ID | <azb32.b904ta@rooftop.invalid> |
| In reply to | #644461 |
In comp.os.linux.advocacy Jeff-Relf.Me wrote:
> You ( Owl ) replied ( to me ):
> > > int x = 0, F, B ;
> > > while ( x++ < 100 ) printf("\n"), F = !(x%3), B = !(x%5), printf(
> > > F && B ? "FizBuz" : F ? "Fiz" : B ? "Buz" : "%d", x );
> >
> > Because nothing says "readable" and "maintainable" like a bunch of nested
> > ternary operations.... Try it with four values, where your state count
> > goes to 16. See how "readable" that is with your approach.
>
> How about ? :
>
> int x = 0 ; char *Say[4] = { "%d\n", "Buz\n", "Fiz\n", "FizBuz\n" };
> while ( x++ < 100 ) printf( Say[ 2*!(x%3) + !(x%5) ], x );
>
> 2 lines, 2^2 states, easily modified to 3^2 states.
Better, but you're still hard-coding values. And 2^3 will need an 8-member
array and 2^4 will need 16. See my other post showing 2^4.
> Full Answer: http://Jeff-Relf.Me/FizBuz.HTM
>
> The I/O is the limiting factor, not "x%3", so:
>
> int x = 0 ; char *Say[4] = { "%d\n", "Buz\n", "Fiz\n", "FizBuz\n" };
> while ( x++ < 100 ) printf( Say[ 2*!(x%3) + !(x%5) ], x );
>
> 2 lines, 2^2 states, easily modified to 2^3 states:
>
> 4*!(x%3) + 2*!(x%5) + !(x%7)
>
You're still limited by just having printf() pointing into an array
of strings. I use an array of function pointers so that you can do
something other than printf() -- or in addition to printf() --
for different combinations.
For example, here a match on all four values calls zenity to
display a dialog alerting on a match:
http://imgur.com/a/rHRmP
/*void onetwofoureight(int x){printf("FizzBuzzGoozKaaz\n");}
*/
void onetwofoureight(int x)
{
char cmd[100]={0};
printf("FizzBuzzGoozKaaz\n");
sprintf(cmd,"zenity --info --text=\"Found a FizzBuzzGoozKaaz at %d\"",x);
system(cmd);
}
[toc] | [prev] | [next] | [standalone]
| From | "F. Russell" <fr@random.info> |
|---|---|
| Date | 2017-08-05 13:37 +0000 |
| Subject | Re: Fabian seldom writes code, much less test it. |
| Message-ID | <om4hn801hfk@news6.newsguy.com> |
| In reply to | #644434 |
On Fri, 04 Aug 2017 18:20:59 -0700, Jeff-Relf.Me wrote: > > And you obsess over things that don't matter, e.g. "x%3". > Don't matter? Ha, ha, ha, ha, ha, ha, ha, ha! Write some code to evaluate the following polynomial: y = c4 * x^4 + c3 * x^3 + c2 * x^2 + c1 * x + c0 where c4, c3, c2, c1, c0 are constants. Show us what your idiotic answer will be.
[toc] | [prev] | [next] | [standalone]
| From | "F. Russell" <fr@random.info> |
|---|---|
| Date | 2017-08-05 14:25 +0000 |
| Subject | Re: Fabian seldom writes code, much less test it. |
| Message-ID | <om4kgn02epk@news3.newsguy.com> |
| In reply to | #644434 |
On Fri, 04 Aug 2017 18:20:59 -0700, Jeff-Relf.Me wrote: > > obsess over things that don't matter, e.g. "x%3". > Don't matter? Heee, hee, hee, hee, hee, hee, hee, hee, hee! Jeff-Ass knows shit about uprocessors. Check out the instruction tables put together by Agner Fog: www.agner.org/optimize/instruction_tables.pdf By all measures of throughput and latency, ADD beats DIV. ADD not only beats DIV, it whips its ass. So only a brain-dead, cretinous, imbecilic idiot would NOT use ADD in place of DIV where it is feasible. But that's Jeff-Ass. Ha, ha, ha, ha, ha, ha, ha, ha!
[toc] | [prev] | [next] | [standalone]
| From | owl <owl@rooftop.invalid> |
|---|---|
| Date | 2017-08-05 03:22 +0000 |
| Subject | Re: I'm the best c coder here. |
| Message-ID | <pkbzb34a.b933u0@rooftop.invalid> |
| In reply to | #644393 |
In comp.os.linux.advocacy Jeff-Relf.Me wrote: > I'm the best c coder here, I think. > Jeff Rofl. > Fabian optimized something he shouldn't have; > the I/O is thee only limiting factor, not "x%3". > > Also, he failed to test the code he wrote, > and _failed_ to compare it with mine. > Usually, he fails to write _any_ code, much less test it. > > Owl failed to write concise, readable code; Says the man who chose to use the least readable construct in the C language. > instead, he foolishly optimized the wrong thing. > I "optimized" only because that is what Fabtard asked for. Otherwise I would have used modulo. > Marek Novotny's c was better than Owl's or Fabian's, > but it wasn't as concise|readable as mine, I think. > Initially, he chose bash, not c. My code is far more "maintainable" than yours. It is trivial to expand it to use three or four values with no change in complexity for the decision logic, and using an array of function pointers instead of simply pointing printf() to an array of strings opens all kinds of possibilities.
[toc] | [prev] | [next] | [standalone]
| From | owl <owl@rooftop.invalid> |
|---|---|
| Date | 2017-08-05 06:12 +0000 |
| Subject | Re: I'm _still_ the best c coder here. |
| Message-ID | <zbsg3av90.ar@rooftop.invalid> |
| In reply to | #644463 |
In comp.os.linux.advocacy Jeff-Relf.Me wrote:
> You ( Owl ) replied ( to me ):
> > > Marek Novotny's c was better than Owl's or Fabian's,
> > > but it wasn't as concise|readable as mine, I think.
> > > Initially, he chose bash, not c.
> >
> > My code is far more "maintainable" than yours.
>
> No one would agree with you, no one.
> not compared to my: http://Jeff-Relf.Me/FizBuz.HTM
>
> > It's trivial to expand [ my FiZBuz ] to use three or four values
> > with no change in complexity for the decision logic,
> > and using an array of function pointers
> > instead of simply pointing printf() to an
> > array of strings opens all kinds of possibilities.
>
> Your shit was 28 lines, and very convolulted/confusing.
LOL! It's not confusing. It does exactly what you are
doing below, only points into an array of function pointers
instead of an array of char pointers.
> Mine is 2 lines, 2^2 states, and easily modified to 2^3 states,
> via: 4*!(x%3) + 2*!(x%5) + !(x%7).
>
> int x = 0 ; char *Say[4] = { "%d\n", "Buz\n", "Fiz\n", "FizBuz\n" };
> while ( x++ < 100 ) printf( Say[ 2*!(x%3) + !(x%5) ], x );
>
And it hard-codes values, is limited to printf, and takes up as much
space as mine when you expand the array to 2^4, not to mention that
all your decision logic is entangled with the result function.
Mine is clean:
void (*f[])(int)={zero,one,two,onetwo,
four,onefour,twofour,onetwofour,
eight,oneeight,twoeight,onetwoeight,
foureight,onefoureight,twofoureight,onetwofoureight};
int i=0,v=0;
for(i=1;i<=MAX;i++)
{
if(i%ONE==0){v+=1;}
if(i%TWO==0){v+=2;}
if(i%FOUR==0){v+=4;}
if(i%EIGHT==0){v+=8;}
f[v](i); /* call the appropriate function */
v=0;
}
Flexible, easy to maintain, decision logic not entangled with
a single function so custom-tailored functions can be created
to handle different cases; can easily be modified to set values
by parsing argv. Think things through, man. Look to the future.
Sometimes trying to be as concise as possible can tie your hands
and force you to end up doing a complete rewrite when you need
added functionality.
[toc] | [prev] | [next] | [standalone]
| From | owl <owl@rooftop.invalid> |
|---|---|
| Date | 2017-08-05 15:40 +0000 |
| Subject | Re: Owl's FizBuzGozKaz branches 5 times more often. |
| Message-ID | <pq12jbv903ab.h3uu4@rooftop.invalid> |
| In reply to | #644463 |
In comp.os.linux.advocacy Jeff-Relf.Me wrote:
> You ( Owl ) replied ( to me ):
> > > Moving to 4 primes, it's: [ I reduced your 43 lines to 5 ]
> > >
> > > char *Say[16] = { "%d", "Fiz", "Buz", "FizBuz", "Goz", "FizGoz",
> > > "BuzGoz", "FizBuzGoz", "Kaz", "FizKaz", "BuzKaz", "FizBuzKaz",
> > > "GozKaz", "FizGozKaz", "BuzGozKaz", "FizBuzGozKaz" }; int x = 0 ;
> > > while ( x++ < 100 ) printf(", "),
> > > printf( Say[ 8*!(x%11) + 4*!(x%7) + 2*!(x%5) + !(x%3) ], x );
> >
> > What difference does that make? I can reformat my source and have most
> > of it on one line. Besides, my code runs faster than yours. LALALALA.
> > What you did is make a mess.
>
> Stop lying to yourself,
> I reduced your 43 lines, 74 columns to: 5 lines, 71 columns, indented.
>
> Your FizBuzGozKaz isn't faster ( or slower ) than mine; note:
>
My tests show that it is.
> 1. You branch 5 times more often.
>
The regularity of this pattern means that the CPU's branch
prediction will have no trouble.
> 2. I call one function. You call 16 different functions,
In your latest example, you call printf() twice for each iteration.
> each of which calls another funtion, pushing the stack.
>
All but one of the printfs acts on a string literal. The compiler
could inline them.
> > all you will ever want to do is printf().
>
> Right, UnlessAndUntil you convince me otherwise;
> I won't be holding my breath.
>
I already showed you a good use: 3,5,571,897 don't hit on all four
until you're at about 2.5 million iterations; 3,571,891,1277 don't all
hit until nearly 650 millon iterations. The popups notify you that you
have a hit at a certain level and keep you from having to grep after
every run when you're testing various sets of numbers at various counts:
./foo a b c d 1000
./foo a b c d 10000
./foo a b c d 100000
./foo a b c d 1000000
...
You can keep upping the count until you get a popup. You could easily
make the popup conditional by passing an option in argv, and kill a run
as soon as you get a popup, then run the program again without popups
to get all values without interaction.
[toc] | [prev] | [next] | [standalone]
| From | moroney@world.std.spaamtrap.com (Michael Moroney) |
|---|---|
| Date | 2017-08-05 22:16 +0000 |
| Subject | Re: I'm _still_ the best c coder here. |
| Message-ID | <om5g3g$vb8$1@pcls7.std.com> |
| In reply to | #644463 |
Jeff-Relf.Me @. writes: >Your shit was 28 lines, and very convolulted/confusing. Your code is confusing/misleading by starting the counter at 0, not 1 even if the first thing done is increment it. For a half second I was about to reply that you didn't even follow the requirements by starting at 0, not 1. > int x = 0 ; ... > while ( x++ < 100 ) printf( Say[ 2*!(x%3) + !(x%5) ], x ); Since the purpose of this code is to impress a potential employer, not simply get the job done, it should be as clear and maintainable as possible, and make it clearer that the loop iterates from 1 to 100. Besides, this type of iteration screams for a for(...) loop, that's why languages were created with it or the equivalent. (I won't comment about not making the requirement by misspelling 'Fizz' and 'Buzz'... :-) ) for (x=0; x<=100; x++) printf(...);
[toc] | [prev] | [next] | [standalone]
| From | moroney@world.std.spaamtrap.com (Michael Moroney) |
|---|---|
| Date | 2017-08-07 03:24 +0000 |
| Subject | Re: I increment things at the _start_ of a loop. |
| Message-ID | <om8mhe$q18$3@pcls7.std.com> |
| In reply to | #644638 |
Jeff-Relf.Me @. writes: >I increment things at the _start_ of a loop, >not at the end, hence: while ( x++ < 100 ) You missed my point, of course, being the idea of this exercise is to convince a hiring manager that you write quality, clean, maintainable code, not to try for the fewest possible lines or even the fastest code. If I was the hiring manager, I'd take points off for unnecessary obscurity. (actually I wouldn't ask that question) Like the Google interview question "how many ping pong balls fit into a school bus?" They don't give a flying fornification about an actual number, they want to see how the interviewee would estimate the answer. They didn't ask me that when I interviewed with them, however.
[toc] | [prev] | [next] | [standalone]
| From | Snit <usenet@gallopinginsanity.com> |
|---|---|
| Date | 2017-08-06 20:35 -0700 |
| Subject | Re: I increment things at the _start_ of a loop. |
| Message-ID | <D5AD2E0C.AF3F6%usenet@gallopinginsanity.com> |
| In reply to | #644892 |
On 8/6/17, 8:24 PM, in article om8mhe$q18$3@pcls7.std.com, "Michael Moroney" <moroney@world.std.spaamtrap.com> wrote: > Jeff-Relf.Me @. writes: > >> I increment things at the _start_ of a loop, >> not at the end, hence: while ( x++ < 100 ) > > You missed my point, of course, being the idea of this exercise is to > convince a hiring manager that you write quality, clean, maintainable > code, not to try for the fewest possible lines or even the fastest code. > If I was the hiring manager, I'd take points off for unnecessary > obscurity. (actually I wouldn't ask that question) > > Like the Google interview question "how many ping pong balls fit into > a school bus?" They don't give a flying fornification about an actual > number, they want to see how the interviewee would estimate the answer. > They didn't ask me that when I interviewed with them, however. I had a similar question at a job interview (basically the same): how many ping pong balls would fit into a 747. -- Personal attacks from those who troll show their own insecurity. They cannot use reason to show the message to be wrong so they try to feel somehow superior by attacking the messenger. They cling to their attacks and ignore the message time and time again. <https://youtu.be/H4NW-Cqh308>
[toc] | [prev] | [next] | [standalone]
Page 1 of 2 [1] 2 Next page →
Back to top | Article view | sci.physics
csiph-web