Puzzle

classic Classic list List threaded Threaded
37 messages Options
12
Reply | Threaded
Open this post in threaded view
|

Re: Puzzle

Kermit Kiser
Didn't know it was a contest but this raises an interesting point: I suggest that we have someone submit an small problem like this to the list each day. I "entered" because I wondered why no one was suggesting the use of the powerful Rexx class variable. It seems to me that even those of us on the list for a long time may not know or may have forgotten just how powerful NetRexx is. In spite of it's deceptive simplicity, it is one of the most powerful computer languages ever created - maybe the most powerful. (Of course I may be a bit biased.) Anyway the multiplicity of solutions presented could form the basis for tutorial materials and code patterns to teach NetRexx programmers, old and new, how to do various tasks using NetRexx. Just a suggestion.

-- Kermit


On 4/28/2011 3:09 AM, Robert Hamilton wrote:
In  jEdit Test:

2 is even
3 is odd
1 is even
=> Finished <=

Kermit wins.

Thanks for your time and Enjoy the Day

Bob Hamilton
Richardson, Texas USA



On Thu, Apr 28, 2011 at 4:18 AM, Kermit Kiser <[hidden email]> wrote:
How about this way?:



ip=[int 1, 2, 3, 2, 3, 1, 3]
rexxvar=0
loop i=0 to ip.length-1;rexxvar[ip[i]]=rexxvar[ip[i]]+1;end
loop i over rexxvar
   if rexxvar[i]=rexxvar[i]%2*2 then say i "is even"
                                else say i "is odd"
   end


Rexx class is your friend!



On 4/28/2011 12:35 AM, Patric Bechtel wrote:
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Robert Hamilton schrieb am <a moz-do-not-send="true" href="tel:27.04.2011%2019" value="+12704201119" target="_blank">27.04.2011 19:33:
Given an array of positive integers. All numbers occur an even number of
times except one number which occurs odd number of times. Find the
number in string Occurring Odd number of times.

Example:
I/P = [1, 2, 3, 2, 3, 1, 3]

3 occurs and odd number of times.  I've been trying to go thru the list
using Countstr but you almost need a Sortstr function.

import java.util.HashSet

ip=[int 1, 2, 3, 2, 3, 1, 3]
s=HashSet()
loop i=0 to ip.length-1
  ipo=Integer.valueOf(ip[i])
  if s.remove(ipo)=null then
    s.add(ipo)
  end
it=s.iterator()
loop while it.hasNext()
  say (Integer it.next()) 'contained odd number of times'
  end

hope that helps...

- -- cu, Patric
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.10 (GNU/Linux)
Comment: GnuPT 2.5.2

iEYEARECAAYFAk25GM0ACgkQfGgGu8y7ypCNsgCgrLIaNVvesXoimjKwj2QjFchk
8TwAoMgVjDFuuFOrEytIRmYWXOYplxVH
=xkx0
-----END PGP SIGNATURE-----
_______________________________________________
Ibm-netrexx mailing list
[hidden email]



_______________________________________________
Ibm-netrexx mailing list
[hidden email]


_______________________________________________ Ibm-netrexx mailing list [hidden email]

_______________________________________________
Ibm-netrexx mailing list
[hidden email]

Reply | Threaded
Open this post in threaded view
|

Re: Puzzle

Kermit Kiser
In reply to this post by Patric Bechtel
Ha! If you were nitpicking my solution for providing extra info, you
missed the fact that it records exact counts for each array value,
although quite unrequested in the original problem!

I do agree that it is irritating that the loop over construct only
supports the ancient Hashtable enumerations and not the newer
collections iterators of the current Java versions. It is beginning to
look like we may have to resurrect the project to write an independent
NetRexx translator if we want to fix the problems or add enhancements to
the language. That would be unfortunate not solely because of all the
reverse engineering and reinventing work, but because we would need a
new name at least for the compiler.

Anyway, here is another one of my peeves with the current NetRexx: The
only way to perform a bit level "OR" operation in NetRexx, which is
often required to create the flag fields used by Java library functions,
is to use a binary method. Here is what I add to my programs:

     method binaryOR(a=int,b=int) binary returns int

         return a|b

Then when I need to add a bit flag for a Java call, I do something like
this:

         mnotification.flags =
binaryOR(mnotification.flags,Notification.FLAG_AUTO_CANCEL)

It would be so nice if there was an operator that would handle bitwise
OR in NetRexx without needing a binary class or method! Even just an
option to make the next instruction binary would help. Anyone have thoughts?


-- Kermit


On 4/28/2011 9:07 AM, Patric Bechtel wrote:

> -----BEGIN PGP SIGNED MESSAGE-----
> Hash: SHA1
>
> Hi,
>
> not to be nitpicking, but the question given was:
>
>> Given an array of positive integers. All numbers occur an even number
>> of times except one number which occurs odd number of times. Find the
>> number in string Occurring Odd number of times.
> So the ones with even occurance are completely uninteresting, so why
> should they still be included in the result set?
> As the Rexx class doesn't allow that, I was forced to use the Java
> native HashSet; the nice loop over syntax (I suggested that 9 years ago
> already...) doesn't work with Iterator, so my example gets quite
> java-ish, sorry.
>
> Hopefully, some time in the future, we could write it like this:
>
> import java.util.HashSet
>
> ip=[int 1, 2, 3, 2, 3, 1, 3]
> s=HashSet()
> loop i over ip -- loop over array
>    if s.remove(i)=null then
>      s.add(i) -- autoboxing
>    end
> loop it over s -- loop over iterator
>    say it 'contained odd number of times'
>    end
>
> or, as Groovy nowadays would write this:
>
> [1, 2, 3, 2, 3, 1, 3]
>    .groupBy{ it }
>    .findAll{ it.value.size % 2 != 0 }
>    .each{ n,v ->  println "$n contained odd number of times" }
>
> which is compact, readable and avoids any boilerplate. *Sigh*. Wish
> NetRexx was open sourced already, we could at least implement the loop
> over stuff already.
>
> - --
> cu, Patric
> -----BEGIN PGP SIGNATURE-----
> Version: GnuPG v1.4.10 (GNU/Linux)
> Comment: GnuPT 2.5.2
>
> iEYEARECAAYFAk25kKgACgkQfGgGu8y7ypA5fwCfYpvSHRVG8mN7AjuA7DWYHnuJ
> /VEAoK0a7SkSjL1y3RzSwtMcaeoALD1A
> =Z/Ot
> -----END PGP SIGNATURE-----
> _______________________________________________
> Ibm-netrexx mailing list
> [hidden email]
>
>
>
_______________________________________________
Ibm-netrexx mailing list
[hidden email]

Reply | Threaded
Open this post in threaded view
|

Re: Puzzle

alansam
In reply to this post by Kermit Kiser


On 28 April 2011 17:00, Kermit Kiser <[hidden email]> wrote:
Didn't know it was a contest but this raises an interesting point: I suggest that we have someone submit an small problem like this to the list each day. I "entered" because I wondered why no one was suggesting the use of the powerful Rexx class variable. It seems to me that even those of us on the list for a long time may not know or may have forgotten just how powerful NetRexx is. In spite of it's deceptive simplicity, it is one of the most powerful computer languages ever created - maybe the most powerful. (Of course I may be a bit biased.) Anyway the multiplicity of solutions presented could form the basis for tutorial materials and code patterns to teach NetRexx programmers, old and new, how to do various tasks using NetRexx. Just a suggestion.

-- Kermit

Well said and an excellent suggestion.  If you ever think you've learned it all and there's nothing anyone else can teach you, you're lost...

A.

--
Can't tweet, won't tweet!

_______________________________________________
Ibm-netrexx mailing list
[hidden email]

Alan

--
Needs more cowbell.
Reply | Threaded
Open this post in threaded view
|

Re: Puzzle

Kermit Kiser
In reply to this post by billfen
Interesting, but won't it have a problem if one element of the array
contains a blank? My solution handles that case with no problem.

On 4/28/2011 11:47 AM, [hidden email] wrote:

> This version is a bit more general and treats the numbers as strings, not
> integers.
>
> /* NetRexx 2 puzzle*/
> ip = [1, 2, 3, 2, 3, 1, 3]
> -- Note that ip = ['a', 'b', 'c', 'b', 'c', 'a', 'c'] also works
>
> parse "" s t1 t2
> loop i = 1 to ip.length; s = s ip[i -1]; end
>
> loop until t1 \= t2 | s = ''
>      parse s t1 temp; parse temp s1 (t1) -0 t2 s2
>      s = s1 s2
>      end
>
> if t1 = t2 then say "No odd count was found."
> else say "The first odd count is for '"t1"'."
>
> --  parse s t1 s1 (t1) -0 t2 s2 -- Does not seem to work, but should?
> --  Possibly a bug in the NetRexx PARSE instruction?  My misunderstanding?
>
> ----------------------------------------------
>
> On 4/28/2011 2:04 PM, George Hovey wrote:
>> Patric,
>>
>>> So the ones with even occurance are completely uninteresting, so why
>> should they still be included in the result set?
>>
>> To give some assurance that the algorithm/implementation isn't working
> fortuitously.  Suppose, say, the loop with 'order' returned the integers in
> the order 3, 1, 2 and the algorithm falsely decided both 3 and 2 had odd
> parity.  If we stopped at 3, we wouldn't know that it had gotten 2 wrong.
>> I didn't want to pound this little program into the ground, but if I were
> writing it for real use, I'd subject it to a number of test data sets and
> type out internal indicators of it's operation as well as the complete
> results.
>>> my example gets quite java-ish
>> I'm not rejecting the idea of using java classes in NetRexx; after all,
> it's designed to do just that.  It's just that NetRexx is well prepared to
> handle this problem on its own, using type Rexx.  Perhaps because the
> problem mentioned "integers" some people felt that Java type int is
> required, but type Rexx deals with arithmetic without requiring any action
> on our part.  My policy is to use type Rexx in calculations unless it can
> be shown to significantly reduce performance.  Avoiding Java native types
> results in simpler, clearer programs.  And NetRexx jumps through hoops
> silently casting types as required by Java methods.
>>> we could at least implement the loop over stuff
>> Sounds interesting.  But no doubt due to the ravages of age I tend to
> regard language innovations as guilty until proven innocent.
>> George
>>
>>
>> On Thu, Apr 28, 2011 at 12:07 PM, Patric Bechtel<[hidden email]>  wrote:
>>
>>      -----BEGIN PGP SIGNED MESSAGE-----
>>      Hash: SHA1
>>
>>      Hi,
>>
>>      not to be nitpicking, but the question given was:
>>
>>      >  Given an array of positive integers. All numbers occur an even
> number
>>      >  of times except one number which occurs odd number of times. Find
> the
>>      >  number in string Occurring Odd number of times.
>>
>>      So the ones with even occurance are completely uninteresting, so why
>>      should they still be included in the result set?
>>      As the Rexx class doesn't allow that, I was forced to use the Java
>>      native HashSet; the nice loop over syntax (I suggested that 9 years
> ago
>>      already...) doesn't work with Iterator, so my example gets quite
>>      java-ish, sorry.
>>
>>      Hopefully, some time in the future, we could write it like this:
>>
>>      import java.util.HashSet
>>
>>      ip=[int 1, 2, 3, 2, 3, 1, 3]
>>      s=HashSet()
>>      loop i over ip  -- loop over array
>>       if s.remove(i)=null then
>>         s.add(i)    -- autoboxing
>>       end
>>      loop it over s  -- loop over iterator
>>       say it 'contained odd number of times'
>>       end
>>
>>      or, as Groovy nowadays would write this:
>>
>>      [1, 2, 3, 2, 3, 1, 3]
>>       .groupBy{ it }
>>       .findAll{ it.value.size % 2 != 0 }
>>       .each{ n,v ->  println "$n contained odd number of times" }
>>
>>      which is compact, readable and avoids any boilerplate. *Sigh*. Wish
>>      NetRexx was open sourced already, we could at least implement the loop
>>      over stuff already.
>>
>>      - --
>>      cu, Patric
>>      -----BEGIN PGP SIGNATURE-----
>>      Version: GnuPG v1.4.10 (GNU/Linux)
>>      Comment: GnuPT 2.5.2
>>
>>      iEYEARECAAYFAk25kKgACgkQfGgGu8y7ypA5fwCfYpvSHRVG8mN7AjuA7DWYHnuJ
>>      /VEAoK0a7SkSjL1y3RzSwtMcaeoALD1A
>>      =Z/Ot
>>      -----END PGP SIGNATURE-----
>>      _______________________________________________
>>      Ibm-netrexx mailing list
>>      [hidden email]
>>
>>
>>
>>
>> _______________________________________________
>> Ibm-netrexx mailing list
>> [hidden email]
> --------------------------------------------------------------------
> mail2web.com – What can On Demand Business Solutions do for you?
> http://link.mail2web.com/Business/SharePoint
>
>
>
> _______________________________________________
> Ibm-netrexx mailing list
> [hidden email]
>
>
>
_______________________________________________
Ibm-netrexx mailing list
[hidden email]

Reply | Threaded
Open this post in threaded view
|

Re: Puzzle

billfen
In reply to this post by Robert L Hamilton
Kermit, Yes, of course, and your version is even more general.  Blanks
before or after a value in the array are no problem in my example, but
embedded blanks would be.  Totally blank values would be ignored and not
checked for pairs.  

One difference is that the approach of deleting pairs stops when the first
non-paired entry is found.  But mainly I thought using the parse
instruction was rather "Rexx-ish".  

The documentation implies that the single parse instruction version should
work, but it doesn't under NetRexx.  I'd have to run the program with Rexx
to verify if this is a bug in NetRexx.  Not that it matters, since bugs in
NetRexx will probably not be fixed anytime soon, if ever :(


On 4/28/2011 8:54 PM, Kermit Kiser wrote:
> Interesting, but won't it have a problem if one element of the array
contains a blank? My solution handles that case with no problem.

>
> On 4/28/2011 11:47 AM, [hidden email] wrote:
>> This version is a bit more general and treats the numbers as strings, not
>> integers.
>>
>> /* NetRexx 2 puzzle*/
>> ip = [1, 2, 3, 2, 3, 1, 3]
>> -- Note that ip = ['a', 'b', 'c', 'b', 'c', 'a', 'c'] also works
>>
>> parse "" s t1 t2
>> loop i = 1 to ip.length; s = s ip[i -1]; end
>>
>> loop until t1 \= t2 | s = ''
>>      parse s t1 temp; parse temp s1 (t1) -0 t2 s2
>>      s = s1 s2
>>      end
>>
>> if t1 = t2 then say "No odd count was found."
>> else say "The first odd count is for '"t1"'."
>>
>> --  parse s t1 s1 (t1) -0 t2 s2 -- Does not seem to work, but should?
>> --  Possibly a bug in the NetRexx PARSE instruction?  My
misunderstanding?
>>

--------------------------------------------------------------------
mail2web LIVE – Free email based on Microsoft® Exchange technology -
http://link.mail2web.com/LIVE



_______________________________________________
Ibm-netrexx mailing list
[hidden email]

Reply | Threaded
Open this post in threaded view
|

Re: Puzzle

Patric Bechtel
In reply to this post by Rony G. Flatscher (wu-wien)
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Hi Rony,

very nice. It's a pity the bag isn't included in standard libraries in
Java (it's available, though).

Thanks for bringing this gem up ;-)


Rony G. Flatscher schrieb am 28.04.2011 20:50:

> Well, as you have sighed upon not having something like Groovy features
> at your hands in NetRexx, how about a relative of NetRexx then, namely
> ooRexx, which seems to be more related to NetRexx than Groovy:
>
>        /* ooRexx version */
>     ip=.bag~of(1,2,3,2,3,1,3)  /* define elements in a bag collection */
>     unique=.set~new~union(ip)  /* create a set from the bag           */
>     do val over unique         /* loop over unique elements           */
>           /* query elements in bag, count them, determine oddness     */
>        if ip~allAt(val)~items//2=1 then say val "-> odd"
>     end
>      
>
> This works and is quite close to your suggestion of an extended NetRexx
> version that you gave.
>
> ---rony
>
>
> On 28.04.2011 18:07, Patric Bechtel wrote:
>> or, as Groovy nowadays would write this:
>>
>> [1, 2, 3, 2, 3, 1, 3]
>>   .groupBy{ it }
>>   .findAll{ it.value.size % 2 != 0 }
>>   .each{ n,v -> println "$n contained odd number of times" }
>>
>> which is compact, readable and avoids any boilerplate. *Sigh*. Wish
>> NetRexx was open sourced already, we could at least implement the loop
>> over stuff already.
>>

- --
cu, Patric
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.10 (GNU/Linux)
Comment: GnuPT 2.5.2

iEYEARECAAYFAk26XjMACgkQfGgGu8y7ypC9xwCgr6nNvRBRgBGgBhXH0TjuCc+w
oHQAn29CdPO++R+0Kxp4a98yy2L3GNX6
=alDP
-----END PGP SIGNATURE-----
_______________________________________________
Ibm-netrexx mailing list
[hidden email]

Reply | Threaded
Open this post in threaded view
|

Re: Puzzle

Patric Bechtel
In reply to this post by ThSITC
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Hi Thomas,

I think I'm not alone with this, but...

- - could you please stop making ads about your unfinished products?
- - this is not your private mailing list and nobody in this list is
participating in any of your projects.
- - your comment down there is completely off topic and disturbs an
otherwise nice discussion
- - your use of asterisks in your mail is disgusting. So is your use of
CAPS.

So, for the future:

If you have no real input to the ongoing discussion, shut up. That's
what everybody on this list does, including me.
I don't ever want to hear anything on this list regarding your
translation thingy, ever. This is a NetRexx list, not an announcement
list. I'm not doing any advertising on my own (real, selling, money
making products, btw) here, too.
I'm member of many, many lists out there, and, believe me, with your
behaviour, you would've thrown out of every single one but this. I don't
know why Ian is that patient, but I wouldn't.

Sorry, Thomas, but that had to be said. I'm really annoyed already.

Thomas Schneider schrieb am 28.04.2011 21:49:

> Hi Rony, *and* all:
>
> Can you please, for the next month, *NOT FORCE ME* to learn *GROOVY*,
> too ?? ;-)
>
> What I'm trying here is:
>
> To allow classic Rexx, ooRexx, and NetRexx *syntax* and *sematic's* in
> the same source program!
>
> ... and then tranlsate them to the STATE of the ART NetRexx 2.05
> Language (when desired to do so!) :-) ;-)
>
> Just as a portation aid ... :-)
>
> Thomas.

- --
cu, Patric
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.10 (GNU/Linux)
Comment: GnuPT 2.5.2

iEYEARECAAYFAk26Yf4ACgkQfGgGu8y7ypDyPACg6774NDRcG6ik1Dwbhnj2xJLV
+3kAoMNjoYsOMhfp9uJB1FCSNg09gO1h
=OAGV
-----END PGP SIGNATURE-----
_______________________________________________
Ibm-netrexx mailing list
[hidden email]

Reply | Threaded
Open this post in threaded view
|

Re: Puzzle

Robert L Hamilton
Amen, Patrick, Amen.

Bob Hamilton
Richardson, Texas USA

On Fri, Apr 29, 2011 at 2:00 AM, Patric Bechtel <[hidden email]> wrote:
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Hi Thomas,

I think I'm not alone with this, but...

- - could you please stop making ads about your unfinished products?
- - this is not your private mailing list and nobody in this list is
participating in any of your projects.
- - your comment down there is completely off topic and disturbs an
otherwise nice discussion
- - your use of asterisks in your mail is disgusting. So is your use of
CAPS.

So, for the future:

If you have no real input to the ongoing discussion, shut up. That's
what everybody on this list does, including me.
I don't ever want to hear anything on this list regarding your
translation thingy, ever. This is a NetRexx list, not an announcement
list. I'm not doing any advertising on my own (real, selling, money
making products, btw) here, too.
I'm member of many, many lists out there, and, believe me, with your
behaviour, you would've thrown out of every single one but this. I don't
know why Ian is that patient, but I wouldn't.

Sorry, Thomas, but that had to be said. I'm really annoyed already.

Thomas Schneider schrieb am 28.04.2011 21:49:
> Hi Rony, *and* all:
>
> Can you please, for the next month, *NOT FORCE ME* to learn *GROOVY*,
> too ?? ;-)
>
> What I'm trying here is:
>
> To allow classic Rexx, ooRexx, and NetRexx *syntax* and *sematic's* in
> the same source program!
>
> ... and then tranlsate them to the STATE of the ART NetRexx 2.05
> Language (when desired to do so!) :-) ;-)
>
> Just as a portation aid ... :-)
>
> Thomas.

- --
cu, Patric
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.10 (GNU/Linux)
Comment: GnuPT 2.5.2

iEYEARECAAYFAk26Yf4ACgkQfGgGu8y7ypDyPACg6774NDRcG6ik1Dwbhnj2xJLV
+3kAoMNjoYsOMhfp9uJB1FCSNg09gO1h
=OAGV
-----END PGP SIGNATURE-----
_______________________________________________
Ibm-netrexx mailing list
[hidden email]



_______________________________________________
Ibm-netrexx mailing list
[hidden email]

Reply | Threaded
Open this post in threaded view
|

Re: Puzzle

Patric Bechtel
In reply to this post by Kermit Kiser
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Hi Kermit,

Kermit Kiser schrieb am 29.04.2011 02:35:
> Ha! If you were nitpicking my solution for providing extra info, you
> missed the fact that it records exact counts for each array value,
> although quite unrequested in the original problem!

I saw this, but nitpicking works one after one ;-P

> I do agree that it is irritating that the loop over construct only
> supports the ancient Hashtable enumerations and not the newer
> collections iterators of the current Java versions. It is beginning to
> look like we may have to resurrect the project to write an independent
> NetRexx translator if we want to fix the problems or add enhancements to
> the language. That would be unfortunate not solely because of all the
> reverse engineering and reinventing work, but because we would need a
> new name at least for the compiler.

That's very pity, indeed. The loop over construct is expecting a
concrete class instead of an interface, so there's no way extending the
default collection classes, so only a compiler change would fix this.

> Anyway, here is another one of my peeves with the current NetRexx: The
> only way to perform a bit level "OR" operation in NetRexx, which is
> often required to create the flag fields used by Java library functions,
> is to use a binary method. Here is what I add to my programs:
>
>     method binaryOR(a=int,b=int) binary returns int
>
>         return a|b
>
> Then when I need to add a bit flag for a Java call, I do something like
> this:
>
>         mnotification.flags =
> binaryOR(mnotification.flags,Notification.FLAG_AUTO_CANCEL)
>
> It would be so nice if there was an operator that would handle bitwise
> OR in NetRexx without needing a binary class or method! Even just an
> option to make the next instruction binary would help. Anyone have
> thoughts?

I've gone even one step further: I created a Java class with static
methods for all binary operations, which accept ints, longs, shorts and
bytes and provides and, or, xor, not, shiftLeft, shiftRight and
logicalShiftRight operators on them.
Though I'm using binary mode all the time, the lack of the shifting
operators and sometimes strange behaviour made this a necessary step for
me. Sigh.

The double use of & | and \ for binary and logical operations is quite
annoying and IMO was a bad decision that time. For logical operations I
would have loved to see something like "and", "or" and "not" keywords.
Would have been more in the spirit of this verbose language IMHO.

I have to admit that currently, I'm doing more and more code in Groovy
(and it's static cousin, groovypp), as especially groovypp with it type
interfering comes quite close to what NetRexx would have developed to
had it done so in the last decade. Maybe without the braces, though ;-)
But hope dies last.

- --
cu, Patric
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.10 (GNU/Linux)
Comment: GnuPT 2.5.2

iEYEARECAAYFAk26ZoAACgkQfGgGu8y7ypCqoQCfaMcNChRp6VJjq6rEdtG9AkBW
20gAoPS/9b7EMGV8749M3PMC2JwMP3EH
=t5X0
-----END PGP SIGNATURE-----
_______________________________________________
Ibm-netrexx mailing list
[hidden email]

Reply | Threaded
Open this post in threaded view
|

RE: Puzzle

Marc Remes
In reply to this post by Mike Cowlishaw
I couldn't resist..

--
odd = ''
postints = [ 1, 2, 3, 2, 3, 1, 3 ]

Loop j = 0 to postints.length - 1
   i = postints[j]
   if odd.exists(i) then
      odd[i] = null
   else
      odd[i] = 1
End

Loop o over odd
   say o
End
--

Best regards

Marc Remes

IBM Certified IT Specialist
IBM Global Technology Services
Mobile: 32 475 33 8162
mailto:mremes@...




"Mike Cowlishaw" <[hidden email]>
Sent by: [hidden email]

04/28/2011 08:46 PM

Please respond to
IBM Netrexx <[hidden email]>

To
"'IBM Netrexx'" <[hidden email]>,
cc
Subject
RE: [Ibm-netrexx] Puzzle





On thinking about it .. but not having tried it .. would not DROP be useful here?  As each number is discovered: register it when first seen or DROP it if already seen.   Then a DO OVER at the end would only list the odd occurences.   [Left to the reader to work out how to handle the dual.]


From: [hidden email] [[hidden email]] On Behalf Of George Hovey
Sent:
28 April 2011 19:05
To:
IBM Netrexx
Subject:
Re: [Ibm-netrexx] Puzzle


Patric,

>So the ones with even occurance are completely uninteresting, so why
should they still be included in the result set?

To give some assurance that the algorithm/implementation isn't working fortuitously.  Suppose, say, the loop with 'order' returned the integers in the order 3, 1, 2 and the algorithm falsely decided both 3 and 2 had odd parity.  If we stopped at 3, we wouldn't know that it had gotten 2 wrong.

I didn't want to pound this little program into the ground, but if I were writing it for real use, I'd subject it to a number of test data sets and type out internal indicators of it's operation as well as the complete results.

>my example gets quite java-ish

I'm not rejecting the idea of using java classes in NetRexx; after all, it's designed to do just that.  It's just that NetRexx is well prepared to handle this problem on its own, using type Rexx.  Perhaps because the problem mentioned "integers" some people felt that Java type int is required, but type Rexx deals with arithmetic without requiring any action on our part.  My policy is to use type Rexx in calculations unless it can be shown to significantly reduce performance.  Avoiding Java native types results in simpler, clearer programs.  And NetRexx jumps through hoops silently casting types as required by Java methods.

>we could at least implement the loop over stuff

Sounds interesting.  But no doubt due to the ravages of age I tend to regard language innovations as guilty until proven innocent.

George


On Thu, Apr 28, 2011 at 12:07 PM, Patric Bechtel <bechtel@...> wrote:
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Hi,

not to be nitpicking, but the question given was:


> Given an array of positive integers. All numbers occur an even number
> of times except one number which occurs odd number of times. Find the
> number in string Occurring Odd number of times.

So the ones with even occurance are completely uninteresting, so why
should they still be included in the result set?
As the Rexx class doesn't allow that, I was forced to use the Java
native HashSet; the nice loop over syntax (I suggested that 9 years ago
already...) doesn't work with Iterator, so my example gets quite
java-ish, sorry.

Hopefully, some time in the future, we could write it like this:


import java.util.HashSet

ip=[int 1, 2, 3, 2, 3, 1, 3]
s=HashSet()

loop i over ip  -- loop over array
if s.remove(i)=null then
  s.add(i)    -- autoboxing
end
loop it over s  -- loop over iterator
say it 'contained odd number of times'
end

or, as Groovy nowadays would write this:

[1, 2, 3, 2, 3, 1, 3]
.groupBy{ it }
.findAll{ it.value.size % 2 != 0 }
.each{ n,v -> println "$n contained odd number of times" }

which is compact, readable and avoids any boilerplate. *Sigh*. Wish
NetRexx was open sourced already, we could at least implement the loop
over stuff already.


- --
cu, Patric
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.10 (GNU/Linux)
Comment: GnuPT 2.5.2

iEYEARECAAYFAk25kKgACgkQfGgGu8y7ypA5fwCfYpvSHRVG8mN7AjuA7DWYHnuJ
/VEAoK0a7SkSjL1y3RzSwtMcaeoALD1A
=Z/Ot

-----END PGP SIGNATURE-----
_______________________________________________
Ibm-netrexx mailing list

[hidden email]

_______________________________________________
Ibm-netrexx mailing list
[hidden email]




Tenzij hierboven anders aangegeven: / Sauf indication contraire ci-dessus: / Unless otherwise stated above:

International Business Machines of Belgium sprl / bvba
Siège social / Maatschappelijke zetel: Avenue du Bourget 42 Bourgetlaan, B-1130 Bruxelles/Brussel
N° d'entreprise / Ondernemingsnr: TVA / BTW BE 0405 912 336
RPM Bruxelles / RPR Brussel

_______________________________________________
Ibm-netrexx mailing list
[hidden email]


smime.p7s (12K) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Bugs (was :Puzzle)

Marc Remes
In reply to this post by billfen
>>Not that it matters, since bugs in
>>NetRexx will probably not be fixed anytime soon, if ever :(


I have not yet encountered a bug in NetRexx, unless perhaps Thomas' strange unwanted .nrx~ compiling, which to me looks more like an OS bug than a NetRexx bug.

Thomas, you mention you get - not more precisely documented - compilation issues with very large projects. Could that be related to the java heap running OutOfMemory? Try adding -Xms32m -Xmx512m (or more) to the java invocation in NetRexxC.sh.

Best regards

Marc Remes

IBM Certified IT Specialist
IBM Global Technology Services
Mobile: 32 475 33 8162
mailto:mremes@...



Tenzij hierboven anders aangegeven: / Sauf indication contraire ci-dessus: / Unless otherwise stated above:

International Business Machines of Belgium sprl / bvba
Siège social / Maatschappelijke zetel: Avenue du Bourget 42 Bourgetlaan, B-1130 Bruxelles/Brussel
N° d'entreprise / Ondernemingsnr: TVA / BTW BE 0405 912 336
RPM Bruxelles / RPR Brussel

_______________________________________________
Ibm-netrexx mailing list
[hidden email]


smime.p7s (12K) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: Bugs (was :Puzzle)

Robert L Hamilton
odd = ''
postints = [ 1, 2, 3, 2, 3, 1, 3 ]

Loop j = 0 to postints.length - 1
   i = postints[j]
   if odd.exists(i) then
      odd[i] = null
   else
      odd[i] = 1
End

Loop o over odd
   say o
End
--Best regards

--Marc Remes

So far, Looks like the winner. . .

Bob Hamilton
Richardson Texas USA

On Fri, Apr 29, 2011 at 3:32 AM, Marc Remes <[hidden email]> wrote:
>>Not that it matters, since bugs in
>>NetRexx will probably not be fixed anytime soon, if ever :(


I have not yet encountered a bug in NetRexx, unless perhaps Thomas' strange unwanted .nrx~ compiling, which to me looks more like an OS bug than a NetRexx bug.

Thomas, you mention you get - not more precisely documented - compilation issues with very large projects. Could that be related to the java heap running OutOfMemory? Try adding -Xms32m -Xmx512m (or more) to the java invocation in NetRexxC.sh.

Best regards

Marc Remes

IBM Certified IT Specialist
IBM Global Technology Services
Mobile: 32 475 33 8162
[hidden email]



Tenzij hierboven anders aangegeven: / Sauf indication contraire ci-dessus: / Unless otherwise stated above:

International Business Machines of Belgium sprl / bvba
Siège social / Maatschappelijke zetel: Avenue du Bourget 42 Bourgetlaan, B-1130 Bruxelles/Brussel
N° d'entreprise / Ondernemingsnr: TVA / BTW BE 0405 912 336
RPM Bruxelles / RPR Brussel

_______________________________________________
Ibm-netrexx mailing list
[hidden email]




_______________________________________________
Ibm-netrexx mailing list
[hidden email]

rde
Reply | Threaded
Open this post in threaded view
|

Re: Puzzle

rde
In reply to this post by Marc Remes
That's exactly the solution I originally described...except I described
it in terms of Classic REXX...!


On Fri, 29 Apr 2011 10:32:03 +0200
Marc Remes <[hidden email]> wrote:

> I couldn't resist..
>
> --
> odd = ''
> postints = [ 1, 2, 3, 2, 3, 1, 3 ]
>
> Loop j = 0 to postints.length - 1
>    i = postints[j]
>    if odd.exists(i) then
>       odd[i] = null
>    else
>       odd[i] = 1
> End
>
> Loop o over odd
>    say o
> End
_______________________________________________
Ibm-netrexx mailing list
[hidden email]

Reply | Threaded
Open this post in threaded view
|

Re: Bugs (was :Puzzle)

Tom Maynard
In reply to this post by Marc Remes
On 4/29/2011 3:32 AM, Marc Remes wrote:
>>Not that it matters, since bugs in
>>NetRexx will probably not be fixed anytime soon, if ever :(


I have not yet encountered a bug in NetRexx, unless perhaps Thomas' strange unwanted .nrx~ compiling, which to me looks more like an OS bug than a NetRexx bug.

Indeed.  In a Windows command session typing "DIR *.nrx" will also list the .nrx~ files.  In a Cygwin X-Window session typing "ls *.nrx" returns only the .nrx files.

Tom.

_______________________________________________
Ibm-netrexx mailing list
[hidden email]

Reply | Threaded
Open this post in threaded view
|

Re: Bugs (was :Puzzle)

ThSITC
In reply to this post by Marc Remes
Hello Marc,
   I don't think the problems are related to memory issues.
 
   They see to have to do with some fancy behaviour when compiling multiple NetRexx programs at once using:

cmd>nrc *.nrx           (all files in a sub-directory).

I do this regularly, as I did now try to pakage my soft properly.

And Walter, I'm so sorry for the many announcement's.

... and nice to hear that you think what I'm trying to do is unfeasable.. ;-)

We will see :-)

Thomas.
=========================================================================
Am 29.04.2011 10:32, schrieb Marc Remes:
>>Not that it matters, since bugs in
>>NetRexx will probably not be fixed anytime soon, if ever :(


I have not yet encountered a bug in NetRexx, unless perhaps Thomas' strange unwanted .nrx~ compiling, which to me looks more like an OS bug than a NetRexx bug.

Thomas, you mention you get - not more precisely documented - compilation issues with very large projects. Could that be related to the java heap running OutOfMemory? Try adding -Xms32m -Xmx512m (or more) to the java invocation in NetRexxC.sh.

Best regards

Marc Remes

IBM Certified IT Specialist
IBM Global Technology Services
Mobile: 32 475 33 8162
[hidden email]



Tenzij hierboven anders aangegeven: / Sauf indication contraire ci-dessus: / Unless otherwise stated above:

International Business Machines of Belgium sprl / bvba
Siège social / Maatschappelijke zetel: Avenue du Bourget 42 Bourgetlaan, B-1130 Bruxelles/Brussel
N° d'entreprise / Ondernemingsnr: TVA / BTW BE 0405 912 336
RPM Bruxelles / RPR Brussel
_______________________________________________ Ibm-netrexx mailing list [hidden email]


--
Thomas Schneider (www.thsitc.com)

_______________________________________________
Ibm-netrexx mailing list
[hidden email]

Thomas Schneider, Vienna, Austria (Europe) :-)

www.thsitc.com
www.db-123.com
Reply | Threaded
Open this post in threaded view
|

Re: Binary OR, AND, and XOR (was: Puzzle)

ThSITC
In reply to this post by Kermit Kiser
Hello Kermit, years ago, when I did discuss the same issue with Rene
Vincent Jansen, I did propose to introduce
the BINARY Operators BOR, BAND, and BXOR, which could then be used
either as operators, as well as
BUILTIN Functions ...

By the way, they are in the ReyBits class in package www.thsitc.rey.rt
already, as I also did have a need for this.

Thomas.
=========================================================================================

Am 29.04.2011 02:35, schrieb Kermit Kiser:
>
> It would be so nice if there was an operator that would handle bitwise
> OR in NetRexx without needing a binary class or method! Even just an
> option to make the next instruction binary would help. Anyone have
> thoughts?
>
>
> -- Kermit

_______________________________________________
Ibm-netrexx mailing list
[hidden email]

Thomas Schneider, Vienna, Austria (Europe) :-)

www.thsitc.com
www.db-123.com
Reply | Threaded
Open this post in threaded view
|

Re: Binary OR, AND, and XOR

ThSITC
Just an afterthought to this issue:

wouldn't:

    flag1=int 1
    flag2=int 2
    flag3=int 4
    ... etc etc

    bits=0
    options binary
    bits=flag1 | flag2
    options nobinary

help in this case ?

-or-  is only ONE OPTIONS statement allowed in a NetRexx Program?

I cannot recall, sorry (limited brain) ;-)

Thomas.

PS: -and- I did avoid the astersik's as well. By the way, I DO use the
asterisks for keywords or key-word
phrases personally to make them BOLD (as Wiki does!!) :-)

============================================================================================

Am 29.04.2011 22:01, schrieb Thomas Schneider:

> Hello Kermit, years ago, when I did discuss the same issue with Rene
> Vincent Jansen, I did propose to introduce
> the BINARY Operators BOR, BAND, and BXOR, which could then be used
> either as operators, as well as
> BUILTIN Functions ...
>
> By the way, they are in the ReyBits class in package www.thsitc.rey.rt
> already, as I also did have a need for this.
>
> Thomas.
> =========================================================================================
>
>
> Am 29.04.2011 02:35, schrieb Kermit Kiser:
>>
>> It would be so nice if there was an operator that would handle
>> bitwise OR in NetRexx without needing a binary class or method! Even
>> just an option to make the next instruction binary would help. Anyone
>> have thoughts?
>>
>>
>> -- Kermit
>
> _______________________________________________
> Ibm-netrexx mailing list
> [hidden email]
>
>


--
Thomas Schneider (www.thsitc.com)
_______________________________________________
Ibm-netrexx mailing list
[hidden email]

Thomas Schneider, Vienna, Austria (Europe) :-)

www.thsitc.com
www.db-123.com
12