Skip to main content
Commonmark migration
Source Link

#Scala, 125 characters

Scala, 125 characters

val i=""::io.Source.stdin.getLines.toList.map(_.toLowerCase);println('a'to'z'map(c=>(""+c)*i.map(_.count(_==c)).max)mkString)

First I read the input, converting it into lower case and adding one empty line.

Then for each letter from a to z I repeat that letter maximum number of times it appears in any of the lines (that's why I need the empty line: max cannot be called on an enpty input). Then I just join the results and print to the output.

To read from a file, replace stdin with fromFile("FILENAME"), increasing the size of the code to 132 characters + file name length.

#Scala, 125 characters

val i=""::io.Source.stdin.getLines.toList.map(_.toLowerCase);println('a'to'z'map(c=>(""+c)*i.map(_.count(_==c)).max)mkString)

First I read the input, converting it into lower case and adding one empty line.

Then for each letter from a to z I repeat that letter maximum number of times it appears in any of the lines (that's why I need the empty line: max cannot be called on an enpty input). Then I just join the results and print to the output.

To read from a file, replace stdin with fromFile("FILENAME"), increasing the size of the code to 132 characters + file name length.

Scala, 125 characters

val i=""::io.Source.stdin.getLines.toList.map(_.toLowerCase);println('a'to'z'map(c=>(""+c)*i.map(_.count(_==c)).max)mkString)

First I read the input, converting it into lower case and adding one empty line.

Then for each letter from a to z I repeat that letter maximum number of times it appears in any of the lines (that's why I need the empty line: max cannot be called on an enpty input). Then I just join the results and print to the output.

To read from a file, replace stdin with fromFile("FILENAME"), increasing the size of the code to 132 characters + file name length.

Added syntax highlighting
Source Link
ProgramFOX
  • 8.3k
  • 7
  • 45
  • 70

#Scala, 125 characters

val i=""::io.Source.stdin.getLines.toList.map(_.toLowerCase);println('a'to'z'map(c=>(""+c)*i.map(_.count(_==c)).max)mkString)
val i=""::io.Source.stdin.getLines.toList.map(_.toLowerCase);println('a'to'z'map(c=>(""+c)*i.map(_.count(_==c)).max)mkString)

First I read the input, converting it into lower case and adding one empty line.

Then for each letter from a to z I repeat that letter maximum number of times it appears in any of the lines (that's why I need the empty line: max cannot be called on an enpty input). Then I just join the results and print to the output.

To read from a file, replace stdin with fromFile("FILENAME"), increasing the size of the code to 132 characters + file name length.

#Scala, 125 characters

val i=""::io.Source.stdin.getLines.toList.map(_.toLowerCase);println('a'to'z'map(c=>(""+c)*i.map(_.count(_==c)).max)mkString)

First I read the input, converting it into lower case and adding one empty line.

Then for each letter from a to z I repeat that letter maximum number of times it appears in any of the lines (that's why I need the empty line: max cannot be called on an enpty input). Then I just join the results and print to the output.

To read from a file, replace stdin with fromFile("FILENAME"), increasing the size of the code to 132 characters + file name length.

#Scala, 125 characters

val i=""::io.Source.stdin.getLines.toList.map(_.toLowerCase);println('a'to'z'map(c=>(""+c)*i.map(_.count(_==c)).max)mkString)

First I read the input, converting it into lower case and adding one empty line.

Then for each letter from a to z I repeat that letter maximum number of times it appears in any of the lines (that's why I need the empty line: max cannot be called on an enpty input). Then I just join the results and print to the output.

To read from a file, replace stdin with fromFile("FILENAME"), increasing the size of the code to 132 characters + file name length.

Source Link
Karol S
  • 161
  • 3

#Scala, 125 characters

val i=""::io.Source.stdin.getLines.toList.map(_.toLowerCase);println('a'to'z'map(c=>(""+c)*i.map(_.count(_==c)).max)mkString)

First I read the input, converting it into lower case and adding one empty line.

Then for each letter from a to z I repeat that letter maximum number of times it appears in any of the lines (that's why I need the empty line: max cannot be called on an enpty input). Then I just join the results and print to the output.

To read from a file, replace stdin with fromFile("FILENAME"), increasing the size of the code to 132 characters + file name length.