# Conjugate in the Spanish imperfect / Conjugue en el imperfecto de indicativo

Given an input of a Spanish verb in its infinitive form, output the verb conjugated in all 6 forms of the indicative imperfect.

To conjugate an infinitive in the imperfect, remove the infinitive ending (-ar, -er, -ir, and sometimes -ír) and add the imperfect endings listed below. There are three irregular verbs in the imperfect, also listed below.

Verb ending    Replace with...
--------------------------------------------------------
-ar            -aba, -abas, -aba, -ábamos, -abais, -aban
-er, -ir, -ír  -ía,  -ías,  -ía,  -íamos,  -íais,  -ían

Irreg. verb    Conjugations
--------------------------------------------------------
ser            era,  eras,  era,  éramos,  erais,  eran
ver            veía, veías, veía, veíamos, veíais, veían
ir             iba,  ibas,  iba,  íbamos,  ibais,  iban


For the purposes of this challenge, use capital letters instead of accented letters (á becomes A, é becomes E, and í becomes I). This is only because accented letters are 2 bytes in UTF-8, but they can be different in other encodings, and I'd rather not have to deal with any of that and stay within printable ASCII instead.

Infinitive verbs will always be three or more characters long with the sole exception of the verb ir, will never contain accented letters with the exception of verbs that end in -ír, and will always end in either -ar, -er, -ir, or -ír. Reflexive verbs do not need to be handled.

Output may be in either the form of a whitespace-/comma-separated string (so printing each conjugation to STDOUT on its own line is okay) or an array/list/etc.

Since this is , the shortest code in bytes wins.

Test cases:

In       Out
---------------------------------------------------------------
hablar   hablaba hablabas hablaba hablAbamos hablabais hablaban
comer    comIa comIas comIa comIamos comIais comIan
vivir    vivIa vivIas vivIa vivIamos vivIais vivIan
sonreIr  sonreIa sonreIas sonreIa sonreIamos sonreIais sonreIan
ser      era eras era Eramos erais eran
ver      veIa veIas veIa veIamos veIais veIan
ir       iba ibas iba Ibamos ibais iban

• So many exceptions.. :P Jan 5 '16 at 4:44
• @ZachGates See, you say that, but you haven't seen anything until you've seen preterite. Imperfect is one of the tenses with the least exceptions. Jan 5 '16 at 4:50
• I've taken Spanish 1-3, hehe. 0/10 would not recommend @FlagAsSpam Jan 5 '16 at 4:52
• @ZachGates Me too. :c Jan 5 '16 at 4:53

## Retina, 100 82 bytes

\B[^a]r$I r$
b
^vI$veI ^sI$
er
$a$
$_s$_ $_mos$_is $_n TlL.(?=[^I]amos )  Try it online. Unfortunately, due to the use of $_ it's not possible to modify the code to run all tests at once, so you'll have to copy in the individual verbs. I'm working on a new feature that will make this possible though.

### Explanation

\B[^a]r$I  We start by turning all endings which aren't ar into I, provided the input isn't the irregular verb ir. That takes care of the -er, -ir, -ír conjugations, messes up the irregular verbs ser and ver (but shortens them in the process), and leaves only ir and -ar with a trailing r. r$
b


If the word still ends in r, we replace that with a b. We've now covered all standard conjugations as well as the irregular verb ir.

^vI$veI  This fixes the irregular verb ver which has been turned into vI in the first stage. ^sI$
er


This fixes the irregular verb ser which has been turned into sI in the first stage. Now we've modified all possible stems correctly. All that's left to do is append all the possible endings, and then fix the accent for the first person plural in some cases.

$a  First we append an a to the stem, because that's always part of all endings. $
$_s$_ $_mos$_is $_n  This makes use of the rarely seen $_ which inserts the entire string into the substitution (regardless of what was matched). This is actually very useful when duplicating strings, as are $ and $', which are also quite underappreciated.

hablaba
hablabas
hablaba
hablAbamos
hablabais
hablaban

$./mw test.mwg -i "ver" veIa veIas veIa veIamos veIais veIan  # Ruby, 151 149 Normally, I'll choose a newline over a semicolon where possible in the interests of readability, but as there are no semicolons, this is a one liner. ->n{%w{a as a amos ais an}.map{|z|['3r','veI','1b',n[0..-3]+(n[-2]==?a?'@b':?I)][("ser ver ir "+n).index(n)/4].tr('31@',['eia','EIA'][z.size/4])+z}}  A feature is the use of placeholders 31@ for the accented vowels which depend on the amos endings. Thus the correct stem is formed, and then the placeholder is substituted for one of eia or EIA as appropriate There a few uses of negative array indexes in here. Thus n[-2] refers to the second to last character of the input, and n[0..-3] refers to the input with the last 2 characters removed (the infinitive stem). Ungolfed in test program f=->n{ %w{a as a amos ais an}.map{|z| #iterate through each verb ending ['3r','veI','1b', #array index 0,1,2 formats for irregular stems (note numbers 1 and 3 used as placeholders) n[0..-3]+(n[-2]==?a?'@b':?I)][ #array index 3 format for regular stems, AR->@b or ER/IR->I depending if A found at index -2 (@ used as placeholder) ("ser ver ir "+n).index(n)/4] #find index of input verb n in "ser ver ir "+n, divide by 4 to obtain 0,1,2,3 above .tr('31@',['eia','EIA'][z.size/4])+ #if z is 4 characters long (AMOS) replace 3,1,@ with uppercase E,I,A. Otherwise with lowercase e,i,a z #add the verb ending to the stem } } n=gets.chop puts f[n]  # Lexurgy, 153 bytes i: ser=>era ver=>veIa ir=>iba ([]+)$1 {a,{e,i,I}} r=>$1 {ab,I} a c: ([]+)$1=>$1 $1 s  $1 $1 mos  $1 is $1 n
j:
i=>I/ _ bam
e=>E/ _ ram


Ungolfed explained:

# turn the irregulars into their roots
irreg:
ser=>era
ver=>veIa
ir=>iba

# do the same for everything else
roots:
([]+)$1 {a,{e,i,I}} r=>$1 {ab,I} a

# tack on the same endings
conjugate:
([]+)$1=>$1  $1 s $1  $1 mos $1 is  \$1 n

# fix the irregulars
irreg2:
i=>I/ _ bam
e=>E/ _ ram
`