How is your Grammar?

Discussion of challenges you have already solved
User avatar
Grusewolf
Posts: 16
Joined: Sun May 29, 2011 7:58 pm
Location: Munich

groovy

Post 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
btzxxyy
Posts: 2
Joined: Sat May 21, 2016 3:43 pm

Post 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.
Post Reply