DEV Community

loading...

Discussion on: Daily Challenge #259 - Duplicate Encoder

Collapse
citizen428 profile image
Michael Kohl • Edited

Since I'm watching NimConf 2020 in the background, a Nim solution:

import strutils, tables

func encode*(s: string): string =
  let lower = s.toLowerAscii
  let counts = lower.toCountTable

  for c in lower:
    result.add(if counts[c] == 1: '(' else: ')')