• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Jeanne Boyarsky
  • Devaka Cooray
  • Paul Clapham
Sheriffs:
  • Tim Cooke
  • Knute Snortum
  • Bear Bibeault
Saloon Keepers:
  • Ron McLeod
  • Tim Moores
  • Stephan van Hulst
  • Piet Souris
  • Ganesh Patekar
Bartenders:
  • Frits Walraven
  • Carey Brown
  • Tim Holloway

Generate alphabet combination

 
Ranch Hand
Posts: 10191
3
Mac PPC Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I was just trying to come up with a small Scala function that would do the alphabet combination for me. Something like we have in Excel as the column headers:



The call would be:



Is there a much simpler way?
 
Joe Harry
Ranch Hand
Posts: 10191
3
Mac PPC Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
My solution only gives me from a to zz. I would like to rather have it a to abcdefghijklmnopqrstuvwxyz. I guess I might have to do a small tweak!
 
lowercase baba
Posts: 12749
51
Chrome Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Joe Harry wrote:I would like to rather have it a to abcdefghijklmnopqrstuvwxyz.


That seems like an odd stopping point...akin to saying "I want numbers from 0 to 123456789" why don't you want to go to zzzzzzzzzzzzzzzzzzzzzzzzzz?
 
Joe Harry
Ranch Hand
Posts: 10191
3
Mac PPC Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I want to have it like this:

 
Saloon Keeper
Posts: 3291
146
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi Joe,

well, I tried to use as many functions as I could think of, but a decent classical while-loop
would be a lot easier...

But maybe someone can vastly improve on this code:


Greetz,
Piet
 
Ranch Hand
Posts: 121
12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
There are many ways to generate sequences. I would use haskell'ish style to do that:

This code creates an unbounded sequence of strings. You can adapt this code to generate sequences of limited length. In this case you would not need any laziness tricks.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!