• 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
  • Junilu Lacar
  • Jeanne Boyarsky
  • Bear Bibeault
Sheriffs:
  • Knute Snortum
  • Tim Cooke
  • Devaka Cooray
Saloon Keepers:
  • Ron McLeod
  • Stephan van Hulst
  • Tim Moores
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Piet Souris
  • Frits Walraven
  • Ganesh Patekar

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: 12766
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:

 
Bartender
Posts: 3519
150
  • 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's just a flesh wound! Or a tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!