Page 2 of 2

groovy

Posted: Thu Apr 10, 2014 4:26 pm
by Grusewolf

Code: Select all

def dic = [
'A' : 'is',
'B' : 'mm',
'C' : 'oo',
'D' : 'rgr',
'E' : 'ryg',
'F' : 'dth',
'G' : 'you',
'H' : 'esol',
'I' : 'ionA',
'J' : 'GDaBarA',
'K' : 'veECFHutI',
'L' : 'PQ',
'M' : 'n',
'N' : 'm',
'O' : 'oaNcho',
'P' : 'MO',
'Q' : 'NR',
'R' : 'sky',
'S' : 'JKL']

def text = 'S'
while(text.any{dic[it]}) {
    def replacement = ''
    text.each {replacement += dic[it]?:it}
    text = replacement
}
println text

Posted: Wed Jan 25, 2017 6:15 am
by btzxxyy
lifthrasiir wrote:Simple solution:

Code: Select all

g = {
  'A': 'is',
  'B': 'mm',
  'C': 'oo',
  'D': 'rgr',
  'E': 'ryg',
  'F': 'dth',
  'G': 'you',
  'H': 'esol',
  'I': 'ionA',
  'J': 'GDaBarA',
  'K': 'veECFHutI',
  'L': 'PQ',
  'M': 'n',
  'N': 'm',
  'O': 'oaNcho',
  'P': 'MO',
  'Q': 'NR',
  'R': 'sky',
  'S': 'JKL',
}
a = 'S'; b = ''
while a != b:
  a, b = ''.join(g.get(c,c) for c in a), a
print a
really elegant.