An Séimhiú agus an tUrú

7

1

An Séimhiú agus an tUrú

In Irish Gaelic (Gaeilge) there are a number of ways that the start of a word can be changed. The most common of these are lenition (an séimhiú) and eclipsis (an t-urú)

Lenition involves adding the letter h as the second letter. For example, the word "bean" (woman) would be lenited to "bhean".

Eclipsing adds a prefix to the word. The prefix is determined by the first letter of the word. For example, the word "capall" (horse) starts with a c. Its eclipsis is g. So when the word "capall" is eclipsed it becomes "gcapall".

Challenge

Write a function or program that takes a word and returns both its lenited and eclipsed forms.

Lenition

Only words beginning with:

b
c
d
f
g
m
p
s
t

are lenited. Words beginning with other letters are not changed.

Some examples:

bean       bhean
capall     chapall
Sasana     Shasana
lón        lón
Ífreann    Ífreann

Eclipsis

If a word starts with any of the following letters, it is prefixed by its respective eclipsis:

Letter   Eclipsis
b        m
c        g
d        n
f        bh
g        n
p        b
t        d

Words that don't start with those letters remain unchanged.

Examples:

bean        mbean
capall      gcapall
cailín      gcailín
doras       ndoras
fuinneog    bhfuinneog
Gaeilge     nGaeilge
Sasana      Sasana

There are other changes that can happen to the start of a word, but we'll just focus on these ones.

Rules

The input is only one word. Words will only contain a-z, A-Z or the fada vowels á, Á, é, É, í, Í, ó, Ó, ú and Ú.

To make it a bit more simple the word itself doesn't necessarily need to be an Irish word, just that it is treated like one in the code. So inputting delta should return dhelta and ndelta.

For this challenge you can assume that the input words have not already been lenited or eclipsed (in Irish, a word is only lenited or eclipsed once. You would never end up with "bhhean" or "ngcapall").

Standard rules apply, including the default I/O rules. Similarly, default loopholes are forbidden.

Finally, this is so shortest answer in bytes wins.

Test cases

Input      Lenited     Eclipsed
bean       bhean       mbean
capall     chapall     gcapall
fuinneog   fhuinneog   bhfuinneog
Sasana     Shasana     Sasana
Gaeilge    Ghaeilge    nGaeilge
lón        lón         lón
áthas      áthas       áthas
Ífreann    Ífreann     Ífreann

Ciaran_McCarthy

Posted 2019-01-08T09:47:42.187

Reputation: 689

Sandbox post. – Ciaran_McCarthy – 2019-01-08T09:49:29.097

Yes, for example Ífreann or áthas. In those cases, however, you would not change the word. – Ciaran_McCarthy – 2019-01-08T12:02:31.373

what does the title mean? – Giuseppe – 2019-01-08T15:44:40.887

@Giuseppe I think it means lenition and eclipsis. Now, the special thing about Gaelic, is that it's hard to understand even once translated into English. :p – Arnauld – 2019-01-08T16:26:59.423

@Arnauld Google Translate gives "The Lenition and the Turu" for the first time and "The Sharing and the Substance" afterwards... "agus" translates to "and". – Erik the Outgolfer – 2019-01-08T16:33:09.557

2"(The) Lenition and (the) Eclipsis". I'm not a fluent speaker, so I don't know if it's correct to specify them with the definite article (an). Séimhiú is lenition and urú is eclipsis. In the title Urú takes a 't' at the start, because it starts with a vowel and is preceded by the definite article. When it's a capital letter there's no hyphen between them. Hence: "There are other changes that can happen to the start of a word, but we'll just focus on these ones." – Ciaran_McCarthy – 2019-01-08T16:43:51.947

1"but you would" ... the suspense is killing me! – Sparr – 2019-01-10T18:57:37.957

@Sparr I only just saw what you were referring to! I've removed the line, because it's not relevant to the challenge. But essentially, if you eclipsed 'capall' it would become 'gcapall'. But you would never eclipse it again, so you would never have 'ngcapall'. Similarly for lenition, you would have 'chapall' but never 'chhapall'. – Ciaran_McCarthy – 2019-01-10T22:56:06.497

Answers

2

JavaScript (ES6),  98  97 bytes

Returns an array [lenited, eclipsed].

s=>[(x=[...'2n1111gbnd1m1','bh',2][parseInt(c=s[0],30)*17%22])>'1'?c+'h'+s.slice(1):s,x>{}?x+s:s]

Try it online!

How?

We define the following lookup table:

A = [ ...'2n1111gbnd1m1', 'bh', 2 ]

//     0    1    2    3    4    5    6    7    8    9    10   11   12   13  14
A = [ '2', 'n', '1', '1', '1', '1', 'g', 'b', 'n', 'd', '1', 'm', '1', 'bh', 2 ]

where:

  • a single character (or the string "bh") is used for eclipsis; all letters that trigger eclipsis also trigger lenition
  • \$1\$ means that there's no eclipsis and no lenition
  • \$2\$ means that there's no eclipsis but there is lenition

The first letter of the input word is converted from Base30 to decimal, multiplied by \$17\$ and then reduced with a modulo \$22\$. The result is used to pick the correct value from \$A\$.

Any result above \$14\$ yields undefined, and so does any letter in the range u-z or any fada vowel. An undefined value is interpreted the same way as \$1\$ (no eclipsis, no lenition).

  1st letter | from Base30 | * 17 | mod 22 | A[n]
-------------+-------------+------+--------+-----------
      a      |      10     |  170 |   16   | undefined
      b      |      11     |  187 |   11   | 'm'
      c      |      12     |  204 |    6   | 'g'
      d      |      13     |  221 |    1   | 'n'
      e      |      14     |  238 |   18   | undefined
      f      |      15     |  255 |   13   | 'bh'
      g      |      16     |  272 |    8   | 'n'
      h      |      17     |  289 |    3   | '1'
      i      |      18     |  306 |   20   | undefined
      j      |      19     |  323 |   15   | undefined
      k      |      20     |  340 |   10   | '1'
      l      |      21     |  357 |    5   | '1'
      m      |      22     |  374 |    0   | '2'
      n      |      23     |  391 |   17   | undefined
      o      |      24     |  408 |   12   | '1'
      p      |      25     |  425 |    7   | 'b'
      q      |      26     |  442 |    2   | '1'
      r      |      27     |  459 |   19   | undefined
      s      |      28     |  476 |   14   | 2
      t      |      29     |  493 |    9   | 'd'
 u-z or fada |     NaN     |  NaN |  NaN   | undefined

Arnauld

Posted 2019-01-08T09:47:42.187

Reputation: 111 334

2

Perl 6, 83 77 bytes

-6 bytes thanks to Jo King

{S:i/^<[bcdfgmpst]>/$/h/,{S/0/bh/}({$_ x tr/dbcfptg/nmg0bd/}($= m/./.lc))~$_}

Try it online!

Returns a two-element list.

nwellnhof

Posted 2019-01-08T09:47:42.187

Reputation: 10 037

2

05AB1E, 45 44 bytes

.•1˜3WÓƵ•sнlk©diн'hI¦JI®7‹i.•B}в •S„bhš®èì]‚

Ended up longer than I anticipated beforehand.. Can probably be golfed some more, though.

Try it online or verify all test cases.

Explanation:

.•1˜3WÓƵ•                   # Push compressed string "fbcdgptms"
s                           # Swap to take the (implicit) input-string
 н                          # Get its first character
  l                         # Convert it to lowercase
   k                        # Get the index in the string (-1 if not found)
    ©                       # Store it in the register (without popping)
     di                     # If the index is non-negative (>= 0):
       н                    #  Get the first character of the (implicit) input-string again
        'h                 '#  Push a "h"
          I                 #  Push the input
           ¦                #  And remove its first character
            J               #  Join all three strings together
       I                    #  Then push the input-string again
        ®7‹i                #  If the index from the register is smaller than 7:
            .•B}в •         #   Push compressed string "mgnnbd"
                   S        #   As a list of characters: ["m","g","n","n","b","d"]
                    „bhš    #   And prepend "bh" to this list: ["bh","m","g","n","n","b","d"]
                        ®è  #   Then use the index from the register in this list
                          ì #   And prepend it in front of the input-string
      ]                     # Close both if-statements
       ‚                    # Pair the two strings at the top of the stack
                            # (uses the input implicitly if we haven't entered the first if)
                            # (and output this pair of strings implicitly)

See this 05AB1E tips of mine (section How to compress strings not part of the dictionary?) to understand why .•1˜3WÓƵ• is "fbcdgptms" and .•B}в • is "mgnnbd".

Alternative for .•B}в •S„bhš with the same byte-count can be .•„Å'Àāʈѕ#, where .•„Å'Àāʈѕ is the compressed string "bh m g n n b d" and # will split on spaces.

Kevin Cruijssen

Posted 2019-01-08T09:47:42.187

Reputation: 67 575

2

Python 3, 100 bytes

lambda w,l='bBcCdDgGpPtTfF':(w[0]+'h'*(w[0]in'msMS'+l)+w[1:],[*'mgnnbd','bh',''][l.find(w[0])//2]+w)

Try it online!

-3 thanks to Black Owl Kai.

Erik the Outgolfer

Posted 2019-01-08T09:47:42.187

Reputation: 38 134

1

Stax, 41 bytes

ü≤↔y╩▓╤:ï{╪Θ↨ë24¿→Äw↔t⌠íΘq↕:pWhg2╗P♦_}éBb

Run and debug it

recursive

Posted 2019-01-08T09:47:42.187

Reputation: 8 616

1

PowerShell, 121 122 116 98 Bytes

-24 bytes thanks to @mazzy

param($a)$a-replace'^[bcdfgmpst]','$&h';@{b='m';c='g';d='n';g='n';f='bh';p='b';t='d'}[''+$a[0]]+$a

Try it online!

Uses a simple regex for the lenition and a switch statement far superior hashtable thanks to @mazzy for the eclipsis. This can probably get a lot shorter.

Gabriel Mills

Posted 2019-01-08T09:47:42.187

Reputation: 778

maybe you should think about: 1) replace a first letter only, 2) switch as expression $(switch -r($a[0]){'b'{'m'}'c'{'g'}....})+$a, 3) hashtable instead the switch. – mazzy – 2019-01-09T06:29:11.607

Thanks, @mazzy, but I'm not sure how to use a hashtable in this situation. Could you give me an idea of what this might look like? – Gabriel Mills – 2019-01-09T21:45:12.280

param($a)$a-replace'^[bcdfgmpst]','$&h';@{b='m';c='g';d='n';g='n';f='bh';p='b';t='d'}[''+$a[0]]+$a – mazzy – 2019-01-10T05:39:17.160

1

C# (Visual C# Interactive Compiler), 151 bytes

x=>{var p=(char)(x[0]%32+96);return(x.Insert(1,(a+"ms").Contains(p)?"h":""),p==102?"bh"+x:"mgnnbd "[a.IndexOf(p)<0?6:a.IndexOf(p)]+x);};var a="bcdgpt";

It's really long, and there are probably ways to golf it more. But I'm just too lazy.

Try it online!

Embodiment of Ignorance

Posted 2019-01-08T09:47:42.187

Reputation: 7 014

Your answer only covers lowercase inputs, so Gaeilge is for example incorrect. PS: Since you only use b once, you can golf string a="bcdgpt",b="mgnnbd "; to var a="bcdgpt"; and b[ to "mgnnbd "[. – Kevin Cruijssen – 2019-01-09T13:16:48.070

@Kevin Cruijssen Fixed – Embodiment of Ignorance – 2019-01-09T21:00:46.107

Nice, +1 from me. Two small things to golf: put the var a="bcdgpt"; inside the method, because you don't have to count the trailing semi-colon of lambda functions. And you can change the %32+96 to |32 to convert to lowercase. Try it online 147 bytes

– Kevin Cruijssen – 2019-01-09T21:35:07.383

Yeah, I forgot about that last string.Thanks! – Embodiment of Ignorance – 2019-01-09T21:45:07.963

1

Java 10, 140 135 bytes

s->{var h=s.charAt(0);int i="fbcdgptms".indexOf(h|32);return(i<0?s:h+"h"+s.substring(1))+" "+",bh,m,g,n,n,b,d,,".split(",",10)[i+1]+s;}

Port of my 05AB1E answer.
-5 bytes thanks to @OlivierGrégoire.

Try it online.

Explanation:

s->{                              // Method with String as both parameter and return-type
  var h=s.charAt(0);              //  Get the first character of the input
  int i="fbcdgptms".indexOf(h     //  Get its index in the string "fbcdgptms"
                            |32); //  After converting it to lowercase
  return(i<0?                     //  If the index is -1 (not found):
          s                       //   Return the input unchanged
         :                        //  Else:
          h                       //   Return the first character
          +"h"                    //   Appended with an "h"
          +s.substring(1))        //   Appended with the rest of the string
         +" "                     //  Then append a space delimiter
         +",bh,m,g,n,n,b,d,,".split(",",10)
                                  //  Push {"","bh","m","g","n","n","b","d","",""}
          [i+1]                   //  and append the character at index `i+1`
         +s;}                     //  And append the input-string

Kevin Cruijssen

Posted 2019-01-08T09:47:42.187

Reputation: 67 575

1135 bytes: s->{var h=s.charAt(0);int i="fbcdgptms".indexOf(h|32);return(i<0?s:h+"h"+s.substring(1))+" "+" bh m g n n b d ".split(" ",10)[i+1]+s;} – Olivier Grégoire – 2019-01-09T14:43:03.747

@OlivierGrégoire Ah, smart use of ",bh,m,g,n,n,b,d,,".split(",",10)[i+1] (I've changed the spaces to commas, since it's a bit more readable)! Would have never thought about that. – Kevin Cruijssen – 2019-01-09T14:57:07.950

1

C# (.NET Core), 165, 131, 126 bytes

Edit: ASCII-only with -34 bytes. Puts everything into one string.

Edit2: Kevin Cruijssen with the 5 byte golf to ToUpper()!

p=>{var s="BCDFGMPSTMGN N B D";var k=s.IndexOf(p.ToUpper()[0]);return(p.Insert(1,k<0?"":"h"),k<0?p:s[k]==70?"bh"+p:s[k+9]+p);}

Try it online!

Destroigo

Posted 2019-01-08T09:47:42.187

Reputation: 401

2131 – ASCII-only – 2019-01-10T12:39:50.173

1126 bytes Removed the +p.ToUpper() from the string s, so you can use p.ToUpper()[0] and k<0 instead of s[18] and k>17. – Kevin Cruijssen – 2019-01-10T14:38:11.207

1

Perl 6, 101 bytes

{.subst(/:i ^<[bcdfgmpst]>/,{$_~'h'}),.subst(/^./,{(%(<b m c g d n f bh g n p b t d>){.lc}//'')~$_})}

Try it online!

bb94

Posted 2019-01-08T09:47:42.187

Reputation: 1 831

0

Python 3, 118 bytes

s='fbcdgpt'
def f(w):a=w[0].lower();return w[0]+'h'*(a in'ms'+s)+w[1:],dict(zip(s,'bmgnnbd')).get(a,'')+'h'*(a=='f')+w

Try it online!

TFeld

Posted 2019-01-08T09:47:42.187

Reputation: 19 246

I'm afraid it returns the wrong elipses for 'bean', 'capall' and 'fuinneog'. – Ciaran_McCarthy – 2019-01-09T10:14:37.713

1@Ciaran_McCarthy Fixed – TFeld – 2019-01-09T10:49:26.983

0

Retina 0.8.2, 77 bytes

i`^[bcdfgmpst]
$&h$'¶$&$&
T`L`l`¶.
¶f
¶ph
T`\ptcb\dgms`b\dgmnn_`¶.
^.+$
$&¶$&

Try it online! Link includes test cases. Explanation:

i`^[bcdfgmpst]
$&h$'¶$&$&

If the word can be lenited, create the lenition, and make a copy for the eclipsis with a duplicate first letter.

T`L`l`¶.

Lowercase the duplicate letter.

¶f
¶ph

If it's an f then change it to ph; it will get fixed to bh later.

T`\ptcb\dgms`b\dgmnn_`¶.

Fix or remove the eclipsis (m and s have a lentition but no eclipsis).

^.+$
$&¶$&

If there was no lentition then duplicate the word anyway.

Neil

Posted 2019-01-08T09:47:42.187

Reputation: 95 035

0

JAVASCRIPT 131 bytes

Implementing Kevin Cruijssen answer in javaScript:

(w,i='bcdfgmpst'.indexOf(w.toLowerCase()[0]))=>(i>=0?[w,w[0]+'h'+w.substr(1),'m,g,n,bh,n,,b,,d'.split(',')[i]+w]:[w,w,w]).join(' ')
(
 w,                                                          // the input (string)
 i='bcdfgmpst'.indexOf(w.toLowerCase()[0])                   // the index of the lenited word
)=>(                                                         
i>=0?                                                        // if index greater or equals 0
 [w,w[0]+'h'+w.substr(1),'m,g,n,bh,n,,b,,d'.split(',')[i]+w] // return Array(input, lenited, eclipsis) 
:                                                            // else
 [w,w,w]                                                     // return Array(input, input, input)
).join(' ')                                                  //Join array items with spaces

Fernando Bravo Diaz

Posted 2019-01-08T09:47:42.187

Reputation: 1