• 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
  • Ron McLeod
  • Paul Clapham
  • Bear Bibeault
  • Junilu Lacar
Sheriffs:
  • Jeanne Boyarsky
  • Tim Cooke
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • salvin francis
  • Frits Walraven
Bartenders:
  • Scott Selikoff
  • Piet Souris
  • Carey Brown

Generate alphabet combination

 
Ranch Hand
Posts: 10192
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: 10192
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: 12893
63
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: 10192
3
Mac PPC Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I want to have it like this:

 
Bartender
Posts: 4066
156
  • 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.
 
Consider Paul's rocket mass heater.
    Bookmark Topic Watch Topic
  • New Topic