Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.forth > #33900 > unrolled thread

revisiting a prgramming problem

Started bygavino_himself <visploveslisp@gmail.com>
First post2014-10-14 15:55 -0700
Last post2014-12-02 05:24 -0800
Articles 11 on this page of 71 — 22 participants

Back to article view | Back to comp.lang.forth


Contents

  revisiting a prgramming problem gavino_himself <visploveslisp@gmail.com> - 2014-10-14 15:55 -0700
    Re: revisiting a prgramming problem hughaguilar96@yahoo.com - 2014-10-14 18:52 -0700
      Re: revisiting a prgramming problem Hans Bezemer <the.beez.speaks@gmail.com> - 2014-10-21 17:58 +0200
        Re: revisiting a prgramming problem Paul Rubin <no.email@nospam.invalid> - 2014-10-21 09:09 -0700
          Re: revisiting a prgramming problem Hans Bezemer <the.beez.speaks@gmail.com> - 2014-10-21 22:18 +0200
            Re: revisiting a prgramming problem rickman <gnuarm@gmail.com> - 2014-10-23 15:44 -0400
              Re: revisiting a prgramming problem "Rod Pemberton" <buzzoff@nonamewhichexists.cmm> - 2014-10-23 17:01 -0400
              Re: revisiting a prgramming problem the_gavino_himself <visphatesjava@gmail.com> - 2014-11-08 21:33 -0800
                Re: revisiting a prgramming problem rickman <gnuarm@gmail.com> - 2014-11-29 20:40 -0500
                  Re: revisiting a prgramming problem the_gavino_himself <visphatesjava@gmail.com> - 2014-12-01 22:43 -0800
                    Re: revisiting a prgramming problem rickman <gnuarm@gmail.com> - 2014-12-02 02:47 -0500
                      Re: revisiting a prgramming problem Paul E Bennett <Paul_E.Bennett@topmail.co.uk> - 2014-12-02 11:53 +0000
                      Re: revisiting a prgramming problem the_gavino_himself <visphatesjava@gmail.com> - 2014-12-02 05:23 -0800
                        Re: revisiting a prgramming problem rickman <gnuarm@gmail.com> - 2014-12-02 09:01 -0500
          Re: revisiting a prgramming problem Hans Bezemer <the.beez.speaks@gmail.com> - 2014-10-21 22:25 +0200
            Re: revisiting a prgramming problem Paul Rubin <no.email@nospam.invalid> - 2014-10-21 16:10 -0700
              Re: revisiting a prgramming problem the_gavino_himself <visphatesjava@gmail.com> - 2014-11-08 21:41 -0800
          Re: revisiting a prgramming problem Hans Bezemer <the.beez.speaks@gmail.com> - 2014-10-21 22:30 +0200
            Re: revisiting a prgramming problem the_gavino_himself <visphatesjava@gmail.com> - 2014-12-01 22:45 -0800
          Re: revisiting a prgramming problem Hans Bezemer <the.beez.speaks@gmail.com> - 2014-10-21 23:04 +0200
        Re: revisiting a prgramming problem Mark Wills <markwills1970@gmail.com> - 2014-10-21 10:17 -0700
          Re: revisiting a prgramming problem "Rod Pemberton" <buzzoff@nonamewhichexists.cmm> - 2014-10-22 02:13 -0400
            Re: revisiting a prgramming problem Paul Rubin <no.email@nospam.invalid> - 2014-10-21 23:26 -0700
              Re: revisiting a prgramming problem "Alex McDonald" <blog@rivadpm.com> - 2014-10-22 16:18 +0100
                Re: revisiting a prgramming problem mhx@iae.nl (Marcel Hendrix) - 2014-10-22 21:27 +0200
                  Re: revisiting a prgramming problem albert@spenarnc.xs4all.nl (Albert van der Horst) - 2014-10-24 10:30 +0000
                    Optimal comparisons for m maximums from n items  (was Re: revisiting a prgramming problem) "Alex McDonald" <blog@rivadpm.com> - 2014-10-24 16:29 +0100
                      Re: Optimal comparisons for m maximums from n items  (was Re: revisiting a prgramming problem) albert@spenarnc.xs4all.nl (Albert van der Horst) - 2014-10-25 08:27 +0000
                        Re: Optimal comparisons for m maximums from n items (was Re: revisiting a prgramming problem) "Alex McDonald" <blog@rivadpm.com> - 2014-10-25 18:54 +0100
                    Re: revisiting a prgramming problem mhx@iae.nl (Marcel Hendrix) - 2014-10-25 13:28 +0200
                    Re: revisiting a prgramming problem mhx@iae.nl (Marcel Hendrix) - 2014-10-25 14:28 +0200
                    Re: revisiting a prgramming problem mhx@iae.nl (Marcel Hendrix) - 2014-10-25 15:17 +0200
              Re: revisiting a prgramming problem Gerry Jackson <spam@qlikz.org> - 2014-10-22 21:57 +0100
                Re: revisiting a prgramming problem Paul Rubin <no.email@nospam.invalid> - 2014-10-22 14:06 -0700
                  Re: revisiting a prgramming problem Bernd Paysan <bernd.paysan@gmx.de> - 2014-10-23 00:03 +0200
                  Re: revisiting a prgramming problem albert@spenarnc.xs4all.nl (Albert van der Horst) - 2014-10-23 14:46 +0000
                    Re: revisiting a prgramming problem Paul Rubin <no.email@nospam.invalid> - 2014-10-23 08:16 -0700
                    Re: revisiting a prgramming problem "Alex McDonald" <blog@rivadpm.com> - 2014-10-23 19:21 +0100
                      Re: revisiting a prgramming problem "Alex McDonald" <blog@rivadpm.com> - 2014-10-23 20:02 +0100
                        Re: revisiting a prgramming problem albert@spenarnc.xs4all.nl (Albert van der Horst) - 2014-10-23 20:29 +0000
                    Re: revisiting a prgramming problem Coos Haak <chforth@hccnet.nl> - 2014-10-23 22:23 +0200
                Re: revisiting a prgramming problem awegel@arcor.de (Alexander Wegel) - 2014-10-23 00:36 +0200
                  Re: revisiting a prgramming problem Gerry Jackson <gerry@jackson9000.fsnet.co.uk> - 2014-10-24 10:44 +0100
                Re: revisiting a prgramming problem hughaguilar96@yahoo.com - 2014-10-22 17:26 -0700
                  Re: revisiting a prgramming problem Michael Barry <barrym95838@yahoo.com> - 2014-10-23 00:02 -0700
            Re: revisiting a prgramming problem the_gavino_himself <visphatesjava@gmail.com> - 2014-11-08 23:10 -0800
          Re: revisiting a prgramming problem the_gavino_himself <visphatesjava@gmail.com> - 2014-11-08 21:42 -0800
    Re: revisiting a prgramming problem Roger Levy <roger.levy@gmail.com> - 2014-10-15 08:18 -0700
      Re: revisiting a prgramming problem Roger Levy <roger.levy@gmail.com> - 2014-10-15 08:18 -0700
        Re: revisiting a prgramming problem november.nihal@gmail.com - 2014-10-15 08:57 -0700
        Re: revisiting a prgramming problem Gerry Jackson <gerry@jackson9000.fsnet.co.uk> - 2014-10-15 17:10 +0100
        Re: revisiting a prgramming problem "Rod Pemberton" <buzzoff@nonamewhichexists.cmm> - 2014-10-17 21:53 -0400
      Re: revisiting a prgramming problem Roger Levy <roger.levy@gmail.com> - 2014-10-15 08:19 -0700
    Re: revisiting a prgramming problem awegel@arcor.de (Alexander Wegel) - 2014-10-22 00:30 +0200
      Re: revisiting a prgramming problem hughaguilar96@yahoo.com - 2014-10-21 16:07 -0700
        Re: revisiting a prgramming problem awegel@arcor.de (Alexander Wegel) - 2014-10-22 03:23 +0200
          Re: revisiting a prgramming problem "Rod Pemberton" <buzzoff@nonamewhichexists.cmm> - 2014-10-22 02:15 -0400
            Re: revisiting a prgramming problem awegel@arcor.de (Alexander Wegel) - 2014-10-22 12:52 +0200
          Re: revisiting a prgramming problem hughaguilar96@yahoo.com - 2014-10-22 17:19 -0700
            Re: revisiting a prgramming problem awegel@arcor.de (Alexander Wegel) - 2014-10-23 16:10 +0200
        Re: revisiting a prgramming problem "Rod Pemberton" <buzzoff@nonamewhichexists.cmm> - 2014-10-22 02:14 -0400
        Re: revisiting a prgramming problem the_gavino_himself <visphatesjava@gmail.com> - 2014-11-08 23:21 -0800
        Re: revisiting a prgramming problem "WJ" <w_a_x_man@yahoo.com> - 2014-12-06 02:34 +0000
        Re: revisiting a prgramming problem "WJ" <w_a_x_man@yahoo.com> - 2014-12-27 08:00 +0000
          Re: revisiting a prgramming problem Mark Wills <markwills1970@gmail.com> - 2014-12-27 05:15 -0800
    Re: revisiting a prgramming problem "WJ" <w_a_x_man@yahoo.com> - 2014-11-29 17:20 +0000
      Re: revisiting a prgramming problem the_gavino_himself <visphatesjava@gmail.com> - 2014-11-29 12:00 -0800
      Re: revisiting a prgramming problem "WJ" <w_a_x_man@yahoo.com> - 2014-12-02 16:15 +0000
    Re: revisiting a prgramming problem Paul Sephton <prsephton@gmail.com> - 2014-12-02 05:06 -0800
      Re: revisiting a prgramming problem Paul Sephton <prsephton@gmail.com> - 2014-12-02 05:14 -0800
      Re: revisiting a prgramming problem the_gavino_himself <visphatesjava@gmail.com> - 2014-12-02 05:24 -0800

Page 4 of 4 — ← Prev page 1 2 3 [4]


#34083

From"Rod Pemberton" <buzzoff@nonamewhichexists.cmm>
Date2014-10-22 02:14 -0400
Message-ID<op.xn4blvrymk81un@localhost>
In reply to#34077
On Tue, 21 Oct 2014 19:07:17 -0400, <hughaguilar96@yahoo.com> wrote:

> The use of IF when it is not necessary, is very novice-level  
> programming. Most likely, Alex doesn't know any assembly language,
> and doesn't know that unpredicted branches slow down the processor.

Hugh,

Are you _seriously_ claiming that a mispredicted branch is slower
than a ROT or -ROT on a stack machine?  LOL.  Do you know how
much overhead there is in moving blocks, even small blocks, of
stack items down a stack?  C'mon Hugh ...


Rod Pemberton

[toc] | [prev] | [next] | [standalone]


#34370

Fromthe_gavino_himself <visphatesjava@gmail.com>
Date2014-11-08 23:21 -0800
Message-ID<1df58581-e6df-4daf-b171-0bce8594483d@googlegroups.com>
In reply to#34077
On Tuesday, October 21, 2014 4:07:19 PM UTC-7, hughag...@yahoo.com wrote:
> On Tuesday, October 21, 2014 3:31:01 PM UTC-7, Alexander Wegel wrote:
> > gavino_himself <visploveslisp@gmail.com> wrote:
> > 
> > > 1.3 in sicp book on scheme from MIT
> > 
> > > given 3 numbers, produce the sum of the squares of the biggest 2 of 3
> > 
> > > can someone provide the solution again and explanation?
> > 
> > > thx
> 
> > That (other thread which i didn't participate in) was a while ago, and
> > there were some solutions.
> > So here's my take (with an eye on algorithmic understandability):
> 
> The other thread was:
> https://groups.google.com/forum/#!topic/comp.lang.forth/YJxex8DrFD8%5B26-50-false%5D
> 
> Why are we going over this stuff again??? Apparently Gavino was pleased with how much response he got last time, so he posted the same question again. This is somewhat like when a boy drags a twig across a picket fence, and causes the dog in the yard to bark furiously at him --- this is so much fun, that he makes a habit of doing it every time that he walks past.
> 
> In that thread, Payson posted this code:
> 
> : sq ( n -- n² ) dup * ; 
> : g ( a b c -- n )  2dup max sq >r min max sq r> + ; 
> 
> That was the best, I thought.
> 
> Here is Alex's code:
> 
> > : msquare ( n -- d )  \ mixed-precision integer square
> >   dup m* ;
> > 
> > : minmax ( n1 n2 -- n1 n2 | n2 n1 )  \ bigger comes out atop
> >   2dup > if swap then ;
> > 
> > : msum_of_squares ( n1 n2 n3 -- d )  \ mixed-precision solution
> >   minmax >r        \ move bigger of n2 and n3 to r-stack
> >   max              \ discard smaller (=smallest overall) number
> >   msquare r> msquare d+  \ calculate result
> > ;
> > 
> > (a single-precision version can be derived from this easily)
> 
> Alex's MINMAX is terrible.
> 
> This was my MINMAX from that thread:
> 
> : minmax ( a b -- min max ) 
>     2dup min -rot  max ; 
> 
> The use of IF when it is not necessary, is very novice-level programming. Most likely, Alex doesn't know any assembly language, and doesn't know that unpredicted branches slow down the processor. Alex isn't the only "programmer" who doesn't know anything about the processor --- Elizabeth Rather is equally ignorant of assembly language. This is from that thread:
> 
> On Monday, January 21, 2013 8:35:01 PM UTC-7, Hugh Aguilar wrote:
> > On Jan 14, 2:43 am, "Elizabeth D. Rather" <erat...@forth.com> wrote:
> > > Aren't you ignoring the fact that there's a conditional in min? Why so
> > > important to avoid a conditional?
> > 
> > > Cheers,
> > > Elizabeth
> > 
> > Elizabeth Rather doesn't know about the CMOVcc instructions in x86
> > assembly language! This tells me that she doesn't know anything about
> > the modern x86 processors, and she would not be able to write even a
> > simple function such as MIN or MAX in assembly language. Also, she
> > asks: "Why so important to avoid a conditional?" This tells me that
> > she doesn't know anything about any x86 processor, all the way back to
> > the 8088 (see Abrash's first book for a lengthy discussion of how
> > branches empty out the prefetch queue on the 8088).
> > 
> > This is an abysmal level of ignorance! Branching has been an issue on
> > all processors, for the last 30 years! To find a processor that
> > branching wasn't an issue on, you have to go back to things like the
> > 65c02 and the Z80 (and the PDP-11 afaik) that didn't do any look-ahead
> > at all, but just executed each opcode one after the other, with each
> > taking a fixed number of clock cycles. That world hasn't existed since
> > I was a teenager.
> > 
> > I don't consider Elizabeth Rather to be a programmer at all. When she
> > says that my code "sucks," she is speaking as a Forth Inc.
> > salesperson, and not as a technical person. She really knows nothing
> > about the subject --- except that she wants people to spend $500 on
> > SwiftForth --- but she doesn't have any technical knowledge.

I said I had forgotten the former thread's solution, thanks for finding it.
Forth is nicely terse.
Where did you learn about the ways to reduce cpu work and such coding style?
I asked for forth thee solution after I did the problem in scheme and tcl.
I mean to make no dogs bark.

[toc] | [prev] | [next] | [standalone]


#34809

From"WJ" <w_a_x_man@yahoo.com>
Date2014-12-06 02:34 +0000
Message-ID<m5tpvp$j3o$1@dont-email.me>
In reply to#34077
hughaguilar96@yahoo.com wrote:

> : sq ( n -- n² ) dup * ; 
> : g ( a b c -- n )  2dup max sq >r min max sq r> + ; 

: g { a b c -- d } b c max dup * b c min a max dup * + ; 

[toc] | [prev] | [next] | [standalone]


#35287

From"WJ" <w_a_x_man@yahoo.com>
Date2014-12-27 08:00 +0000
Message-ID<m7lovh$m30$1@dont-email.me>
In reply to#34077
hughaguilar96@yahoo.com wrote:

> : sq ( n -- n=B2 ) dup * ;
> : g ( a b c -- n )  2dup max sq >r min max sq r> + ;

I count 2 tokens in the 1st definition and 9 in the 2nd,
for a total of 11.

In Factor, it's only 7 tokens.

USING: sorting ;

: sum-sq-of-2 ( a b c -- d )
  sort-pair sq -rot sort-pair nip sq + ;

[toc] | [prev] | [next] | [standalone]


#35292

FromMark Wills <markwills1970@gmail.com>
Date2014-12-27 05:15 -0800
Message-ID<5cc16d15-8801-4bc6-8814-d66393e2a6a3@googlegroups.com>
In reply to#35287
Conveniently omitting the fact that you are including a library to do the heavy lifting for you.

[toc] | [prev] | [next] | [standalone]


#34690

From"WJ" <w_a_x_man@yahoo.com>
Date2014-11-29 17:20 +0000
Message-ID<m5cv9k$h3n$1@dont-email.me>
In reply to#33900
gavino_himself wrote:

> 1.3 in sicp book on scheme from MIT
> 
> given 3 numbers, produce the sum of the squares of the biggest 2 of 3

Gauche Scheme:

(define (g . nums)
  (apply + (map square (cdr (sort nums)))))

(g 3 2 1)
 ===>
13

[toc] | [prev] | [next] | [standalone]


#34695

Fromthe_gavino_himself <visphatesjava@gmail.com>
Date2014-11-29 12:00 -0800
Message-ID<c0219813-310f-40e4-ab2b-5a391e4f6e92@googlegroups.com>
In reply to#34690
On Saturday, November 29, 2014 12:21:09 PM UTC-5, WJ wrote:
> gavino_himself wrote:
> 
> > 1.3 in sicp book on scheme from MIT
> > 
> > given 3 numbers, produce the sum of the squares of the biggest 2 of 3
> 
> Gauche Scheme:
> 
> (define (g . nums)
>   (apply + (map square (cdr (sort nums)))))
> 
> (g 3 2 1)
>  ===>
> 13

nicee

[toc] | [prev] | [next] | [standalone]


#34759

From"WJ" <w_a_x_man@yahoo.com>
Date2014-12-02 16:15 +0000
Message-ID<m5kois$qlv$1@dont-email.me>
In reply to#34690
WJ wrote:

> gavino_himself wrote:
> 
> > 1.3 in sicp book on scheme from MIT
> > 
> > given 3 numbers, produce the sum of the squares of the biggest 2 of 3
> 
> Gauche Scheme:
> 
> (define (g . nums)
>   (apply + (map square (cdr (sort nums)))))
> 
> (g 3 2 1)
>  ===>
> 13

gosh> (g 3 2 1 4 5 6 7 8 9)
284

It yields the sum of the squares of all but the smallest number.

[toc] | [prev] | [next] | [standalone]


#34752

FromPaul Sephton <prsephton@gmail.com>
Date2014-12-02 05:06 -0800
Message-ID<837f678e-db3d-4bf2-8aa3-8b482183eb4f@googlegroups.com>
In reply to#33900
On Wednesday, 15 October 2014 00:55:23 UTC+2, gavino_himself  wrote:
> 1.3 in sicp book on scheme from MIT
> 
> given 3 numbers, produce the sum of the squares of the biggest 2 of 3
> 
> 
> can someone provide the solution again and explanation?
> 
> thx

: ssq 2dup max dup * >r min max dup * r> + ;

1 2 3 ssq . 13  ok
1 3 2 ssq . 13  ok
2 1 3 ssq . 13  ok
2 3 1 ssq . 13  ok
3 1 2 ssq . 13  ok
3 2 1 ssq . 13  ok

[toc] | [prev] | [next] | [standalone]


#34753

FromPaul Sephton <prsephton@gmail.com>
Date2014-12-02 05:14 -0800
Message-ID<7bc11435-0c1d-4cee-bc38-c2be7cdbc817@googlegroups.com>
In reply to#34752
On Tuesday, 2 December 2014 15:06:13 UTC+2, Paul Sephton  wrote:
> On Wednesday, 15 October 2014 00:55:23 UTC+2, gavino_himself  wrote:
> > 1.3 in sicp book on scheme from MIT
> > 
> > given 3 numbers, produce the sum of the squares of the biggest 2 of 3
> > 
> > 
> > can someone provide the solution again and explanation?
> > 
> > thx
> 
> : ssq 2dup max dup * >r min max dup * r> + ;
> 
> 1 2 3 ssq . 13  ok
> 1 3 2 ssq . 13  ok
> 2 1 3 ssq . 13  ok
> 2 3 1 ssq . 13  ok
> 3 1 2 ssq . 13  ok
> 3 2 1 ssq . 13  ok

Oh, I see someone already came up with this one

[toc] | [prev] | [next] | [standalone]


#34755

Fromthe_gavino_himself <visphatesjava@gmail.com>
Date2014-12-02 05:24 -0800
Message-ID<c3f70461-f48a-452b-8ec4-002a60663f40@googlegroups.com>
In reply to#34752
On Tuesday, December 2, 2014 8:06:13 AM UTC-5, Paul Sephton wrote:
> On Wednesday, 15 October 2014 00:55:23 UTC+2, gavino_himself  wrote:
> > 1.3 in sicp book on scheme from MIT
> > 
> > given 3 numbers, produce the sum of the squares of the biggest 2 of 3
> > 
> > 
> > can someone provide the solution again and explanation?
> > 
> > thx
> 
> : ssq 2dup max dup * >r min max dup * r> + ;
> 
> 1 2 3 ssq . 13  ok
> 1 3 2 ssq . 13  ok
> 2 1 3 ssq . 13  ok
> 2 3 1 ssq . 13  ok
> 3 1 2 ssq . 13  ok
> 3 2 1 ssq . 13  ok

Yes I saw that one, nice!
|I have this in my github.

[toc] | [prev] | [standalone]


Page 4 of 4 — ← Prev page 1 2 3 [4]

Back to top | Article view | comp.lang.forth


csiph-web