13
\$\begingroup\$

To conjugate a verb in l'imparfait, one needs to perform the following steps:

  1. Find the "stem" of the word; this is achieved by omitting the -ons from the nous-conjugated form of the word. For example, vivre is nous vivons; removing -ons from vivons yields viv-.
  2. Take the stem and add an appropriate ending, according to the subject. Here are the endings:

    je         -ais
    tu         -ais
    il/elle    -ait
    
    nous       -ions
    vous       -iez
    ils/elles  -aient
    

Objective Given a verb and a subject, output the imperfect form of that verb with respect to the subject. The input format can be in any format convenient to your language. Your submission can either be a program, snippet, or function. (Note that the verb does not have to be a real verb.)

You can assume that the verb is a regular verb, i.e, items like avoir would be treated as an -ir verb, not an irregular one. The only verb you have to quantify as irregular is être; it is conjugated as such:

j'étais
tu étais
il/elle était

nous étions
vous étiez
ils/elles étaient

Here are the conjugations for -er, -re, and -ir verbs in the nous forms

-ER => (e)ons           ; e is added after a 'g'
-RE => ons
-IR => issons

Anything that does not end with such does not have to be handled.

(Note that je merges with the next vowel, if there is one. E.g., je acheter -> j'achetais. h will be considered a vowel for our purposes.)

Example IOs

input: tu vivre
output: tu vivais

input: elles nager
output: elles nageaient

input: je morter
output: je mortais     ; incorrect in real life, but correct for our purposes

input: vous finir
output: vous finissiez

input: il croire
output: il croiait

input: nous jouer
output: nous jouions

Bonuses

  • -5N bytes for all N extra irregular verb handled.
  • -10% if you also output every conjugation of the verb in the imperfect tense.

This is a , so the shortest program in bytes wins.

\$\endgroup\$
  • \$\begingroup\$ @CᴏɴᴏʀO'Bʀɪᴇɴ Does je habiter become j' habite or j'habite? \$\endgroup\$ – Cows quack Oct 23 '15 at 15:48
  • \$\begingroup\$ @KritixiLithos Either is fine. \$\endgroup\$ – Conor O'Brien Oct 23 '15 at 16:02
  • \$\begingroup\$ @CᴏɴᴏʀO'Bʀɪᴇɴ For the -10% bonus, does the input still need to have the pronoun, or can it just be the verb? \$\endgroup\$ – Cows quack Oct 23 '15 at 17:16
  • \$\begingroup\$ Morter doesn't exist, I assume you are referring to to die which is mourir, which would yield je mourais which is actually correct. \$\endgroup\$ – Fatalize Nov 9 '16 at 9:18
  • \$\begingroup\$ @Fatalize I was referring to morter. It's technically incorrect because its not a word. \$\endgroup\$ – Conor O'Brien Nov 9 '16 at 13:18
2
\$\begingroup\$

Processing, 342-10%(bonus) = 307.8

I have created a function. To call the function, include the pronoun as the first parameter and the verb as the second. For example, a("je","habiter")

Please note that my program conjugates the verb for all the pronouns, so that is how I got the 10% bonus.

void a(String a,String b){String[]e={"ais","ais","ait","ait","ions","iez","aient","aient"},p={"je","tu","il","elle","nous","vous","ils","elles"};if("aehiou".contains(b.charAt(0)+""))p[0]="j'";for(String i:p)println(i+" "+b.substring(0,b.length()-2)+(b.endsWith("ger")?"e":b.endsWith("ir")?"iss":"")+e[java.util.Arrays.asList(p).indexOf(i)]);}

Readable form:

void a(String a,String b){
  String[]e={"ais","ais","ait","ait","ions","iez","aient","aient"},p={"je","tu","il","elle","nous","vous","ils","elles"};
  if("aehiou".contains(b.charAt(0)+""))p[0]="j'";
  for(String i:p)
    println(i+" "+b.substring(0,b.length()-2)+(b.endsWith("ger")?"e":b.endsWith("ir")?"iss":"")+e[java.util.Arrays.asList(p).indexOf(i)]);
}

Output (for a("je", "habiter"))

j' habitais
tu habitais
il habitait
elle habitait
nous habitions
vous habitiez
ils habitaient
elles habitaient
\$\endgroup\$
  • \$\begingroup\$ Congratulations! \$\endgroup\$ – Conor O'Brien Oct 25 '15 at 16:01
  • 1
    \$\begingroup\$ Yes! Yes! Yes! My first victory in code-golf! Yes! Yes! [clears throat] @CᴏɴᴏʀO'Bʀɪᴇɴ Thank you. \$\endgroup\$ – Cows quack Oct 25 '15 at 17:22
4
\$\begingroup\$

Haskell, 366 362 352 bytes

s#v=m++g++d++t
 where
 m|v=="être"="ét"|i/="rio"&&i/="erd"&&i/="eri"=r 2 v|otherwise=r 3 v
 g=if(last m=='g'&&head t/='i')then"e"else""
 d|init i=="ri"="iss"|i=="eri"="y"|otherwise=""
 t|s=="je"||s=="tu"="ais"|elem s["il","elle","on"]="ait"|s=="nous"="ions"|s=="vous"="iez"|s=="ils"||s=="elles"="aient"
 r i=reverse.drop i.reverse
 i=take 3$reverse v

You can compile this in ghci and use it like so "je"#"choisir" to get "choisissais".

This code works with some irregular verbs. It can conjugate croire (je croyais, tu croyais…) or prendre as well as all its derivatives (apprendre, comprendre, etc.).

I couldn't find a short way to conjugate other verbs ending in -ire (such as lire, rire, dire, etc.) or in -dre (such as craindre, soudre, etc.).

\$\endgroup\$
  • \$\begingroup\$ Shouldn't it be 352 bytes because of the ê and é? \$\endgroup\$ – Cows quack Oct 23 '15 at 14:56
2
\$\begingroup\$

Java, 389 385 383 382 352.7 443-10%(bonus) = 398.7 bytes

Byte count reduced thanks to @PeterTaylor and @Fatalize
Please note that my program conjugates the verb for all the pronouns, so that is how I got the 10% bonus.

class A{public static void main(String[]a){String[]e={"ais","ais","ait","ait","ions","iez","aient","aient"},p={"je","tu","il","elle","nous","vous","ils","elles"},w=new java.util.Scanner(System.in).nextLine().split(" ");if("aehiou".contains(w[1].charAt(0)+""))p[0]="j'";for(String i:p)System.out.println(i+" "+w[1].substring(0,w[1].length()-2)+(w[1].endsWith("ger")?"e":w[1].endsWith("ir")?"iss":"")+e[java.util.Arrays.asList(p).indexOf(i)]);}}

Readable form (still quite messy):

 1| class A{
 2|   public static void main(String[]a){
 3|     String[]e={"ais","ais","ait","ait","ions","iez","aient","aient"};
 4|     String[]p={"je","tu","il","elle","nous","vous","ils","elles"};
 5|     String[]w=new java.util.Scanner(System.in).nextLine().split(" ");
 6|     if("aehiou".contains(w[1].charAt(0)+""))p[0]="j'";
 7|     for(String i: p) {
 8|       System.out.print(i+" "+w[1].substring(0,w[1].length()-2)+(w[1].endsWith("ger")?"e":w[1].endsWith("ir")?"iss":"")+e[java.util.Arrays.asList(p).indexOf(i)]);
 9|     }
10|   }
11| }

Explanation:

Lines 3-4: Initialisation of arrays.
Line    5: Read a line as input and split it into words
Line    6: Shorten the `je` to `j'` in presence of a succeeding vowel or a `h`.
Line    7: Create a for-loop iterating through all of the pronouns .
Line    8: Conjugate the verb(remove the ending from the infinite form of the verb and add ending accordingly) and print the result, along with the pronoun.



(Old Version) 393-10% = 352.7 bytes

Please note also that my old program does not obey with the new rule about the je merging into j'.

class A{public static void main(String[]a){String[]e={"ais","ais","ait","ait","ions","iez","aient","aient"},p={"je","tu","il","elle","nous","vous","ils","elles"},w=new java.util.Scanner(System.in).nextLine().split(" ");for(String i:p)System.out.println(i+" "+w[1].substring(0,w[1].length()-2)+(w[1].endsWith("ger")?"e":w[1].endsWith("ir")?"iss":"")+e[java.util.Arrays.asList(p).indexOf(i)]);}}
\$\endgroup\$
  • 2
    \$\begingroup\$ Why do you have both k and l? \$\endgroup\$ – Peter Taylor Oct 22 '15 at 20:19
  • \$\begingroup\$ @PeterTaylor Gee, thanks for spotting that one! \$\endgroup\$ – Cows quack Oct 23 '15 at 4:01
  • \$\begingroup\$ You have a useless space here: w[1].substring(0, w[1].length()-2) \$\endgroup\$ – Fatalize Oct 23 '15 at 11:54
  • \$\begingroup\$ @Fatalize I have removed the useless space in my latest edit. \$\endgroup\$ – Cows quack Oct 23 '15 at 14:52
1
\$\begingroup\$

Python 3, 258-10% = 232.2 223-10% = 200.7

Huge thanks to @WW for saving me 35 bytes!

def t(x,y):
 z=y[-2:];y=y[:-2];y+='e'*(y[-1]=='g');y+='iss'*(z=='ir')
 return[('j'+"e'"[y[0]in'aeiouh']+' tu il elle nous vous ils elles').split()[i]+' '+y+'ais ais ait ait ions iez aient aient'.split()[i]for i in range(8)]

Try it online!

\$\endgroup\$
  • 1
    \$\begingroup\$ You can use a split to compress your lists a little more. Also using ; can help you to avoid some of the indentation. \$\endgroup\$ – Sriotchilism O'Zaic Jul 18 '18 at 5:35
  • 1
    \$\begingroup\$ You also don't need parens around your conditionals in the ifs. \$\endgroup\$ – Sriotchilism O'Zaic Jul 18 '18 at 5:39
  • 1
    \$\begingroup\$ Your submission seems to put a space after j', which doesn't seem to match the spec. \$\endgroup\$ – Sriotchilism O'Zaic Jul 18 '18 at 5:48
  • 1
    \$\begingroup\$ @WW Thanks! and in the comments of the main post the OP says "j' " with a space is fine \$\endgroup\$ – JathOsh Jul 18 '18 at 6:02
  • 1
    \$\begingroup\$ In that case here's a shorter version \$\endgroup\$ – Sriotchilism O'Zaic Jul 18 '18 at 6:03

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.