Imperfections dans mon français

13

2

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.

Conor O'Brien

Posted 2015-10-22T15:32:14.193

Reputation: 36 228

@CᴏɴᴏʀO'Bʀɪᴇɴ Does je habiter become j' habite or j'habite? – user41805 – 2015-10-23T15:48:50.237

@KritixiLithos Either is fine. – Conor O'Brien – 2015-10-23T16:02:55.023

@CᴏɴᴏʀO'Bʀɪᴇɴ For the -10% bonus, does the input still need to have the pronoun, or can it just be the verb? – user41805 – 2015-10-23T17:16:26.207

Morter doesn't exist, I assume you are referring to to die which is mourir, which would yield je mourais which is actually correct. – Fatalize – 2016-11-09T09:18:15.370

@Fatalize I was referring to morter. It's technically incorrect because its not a word. – Conor O'Brien – 2016-11-09T13:18:47.327

Incidentally, il croiait is incorrect as well (should be il croyait). – Arnauld – 2017-02-15T11:51:54.697

@Arnauld the challenge doesn't handle irregulars – Conor O'Brien – 2017-02-15T12:01:39.357

Answers

2

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

user41805

Posted 2015-10-22T15:32:14.193

Reputation: 16 320

Congratulations! – Conor O'Brien – 2015-10-25T16:01:52.410

1Yes! Yes! Yes! My first victory in code-golf! Yes! Yes! [clears throat] @CᴏɴᴏʀO'Bʀɪᴇɴ Thank you. – user41805 – 2015-10-25T17:22:01.430

Not all verbs with a leading h will elide the pronoun. Only those with a silent h. Counter examples are haïr (je hais) (irregular anyway), hacher, haleter, halter, hérisser and many more.

You also miss the verbs ending in -cer, where the "nous form" becomes -çons. – Urhixidur – 2019-10-23T20:13:26.807

4

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.).

villou24

Posted 2015-10-22T15:32:14.193

Reputation: 161

Shouldn't it be 352 bytes because of the ê and é? – user41805 – 2015-10-23T14:56:07.087

2

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)]);}}

user41805

Posted 2015-10-22T15:32:14.193

Reputation: 16 320

2Why do you have both k and l? – Peter Taylor – 2015-10-22T20:19:03.063

@PeterTaylor Gee, thanks for spotting that one! – user41805 – 2015-10-23T04:01:16.990

You have a useless space here: w[1].substring(0, w[1].length()-2) – Fatalize – 2015-10-23T11:54:59.497

@Fatalize I have removed the useless space in my latest edit. – user41805 – 2015-10-23T14:52:33.090

1

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!

JathOsh

Posted 2015-10-22T15:32:14.193

Reputation: 31

1You can use a split to compress your lists a little more. Also using ; can help you to avoid some of the indentation. – Post Rock Garf Hunter – 2018-07-18T05:35:04.137

1You also don't need parens around your conditionals in the ifs. – Post Rock Garf Hunter – 2018-07-18T05:39:31.210

Lastly you can use boolean multiplication to get around two of the ifs altogether. Try it online!

– Post Rock Garf Hunter – 2018-07-18T05:41:35.090

1Your submission seems to put a space after j', which doesn't seem to match the spec. – Post Rock Garf Hunter – 2018-07-18T05:48:47.523

1@WW Thanks! and in the comments of the main post the OP says "j' " with a space is fine – JathOsh – 2018-07-18T06:02:38.170

1

In that case here's a shorter version

– Post Rock Garf Hunter – 2018-07-18T06:03:43.743