I'm learning scala, would it be possible to get a little code review and mentoring?
I'm trying to learn scala, and picked the following as a task. Given one or more groups of letters where each group represents the possible letters for that position in a word, generate all possible word combinations. For example, given:

    ab  cd  ef

produce:

    ace
    acf
    ade
    adf
    bce
    bcf
    bde
    bdf

I managed to get the job done and start to wrap my head around scala at the same time, but I'm almost certain that it could have been done in a more scala-ly way. Any suggestions or improvements would be gratefully accepted.

    object Permute {
    
      def pickChar(answerPosition: Int, currentAnswer: Int, totalAnswers: Int, args: Array[String], mods: Array[Int]) : Char = {
        return args(answerPosition).charAt( currentAnswer / mods(answerPosition) % args(answerPosition).length )
      }
    
      def main(args: Array[String]) = {
        var answerLength = args.length
        var ansBuckets = new Array[Int](answerLength)
        var countAnswers = 1
        var divAnswers = 1
        var idx = 0
        args.foreach { arg =>
          countAnswers *= arg.length
        }
    
        args.foreach { arg =>
          divAnswers *= arg.length
          ansBuckets(idx) = countAnswers / divAnswers
          idx += 1
        }
    
        var answers = Array.ofDim[Char](countAnswers,answerLength)
    
        idx=0
        answers.foreach { ans =>
          for ( i <- 0 to answerLength - 1) ans(i) = pickChar(i,idx,countAnswers,args,ansBuckets)
          idx += 1
        }
    
        answers.foreach { ans =>
          ans.foreach { str =>
            printf("%c",str)
          }
        printf("\n")
        }
      }
    }


I'm learning scala, would it be possible to get a little code review and mentoring?
===

I'm trying to learn scala, and picked the following as a task. Given one or more groups of letters where each group represents the possible letters for that position in a word, generate all possible word combinations. For example, given:

    ab  cd  ef

produce:

    ace
    acf
    ade
    adf
    bce
    bcf
    bde
    bdf

I managed to get the job done and start to wrap my head around scala at the same time, but I'm almost certain that it could have been done in a more scala-ly way. Any suggestions or improvements would be gratefully accepted.

    object Permute {
    
      def pickChar(answerPosition: Int, currentAnswer: Int, totalAnswers: Int, args: Array[String], mods: Array[Int]) : Char = {
        return args(answerPosition).charAt( currentAnswer / mods(answerPosition) % args(answerPosition).length )
      }
    
      def main(args: Array[String]) = {
        var answerLength = args.length
        var ansBuckets = new Array[Int](answerLength)
        var countAnswers = 1
        var divAnswers = 1
        var idx = 0
        args.foreach { arg =>
          countAnswers *= arg.length
        }
    
        args.foreach { arg =>
          divAnswers *= arg.length
          ansBuckets(idx) = countAnswers / divAnswers
          idx += 1
        }
    
        var answers = Array.ofDim[Char](countAnswers,answerLength)
    
        idx=0
        answers.foreach { ans =>
          for ( i <- 0 to answerLength - 1) ans(i) = pickChar(i,idx,countAnswers,args,ansBuckets)
          idx += 1
        }
    
        answers.foreach { ans =>
          ans.foreach { str =>
            printf("%c",str)
          }
        printf("\n")
        }
      }
    }

