14
1
Challenge
Write a function which takes an argument which is a verb, and returns the past tense of the verb. (Assume that the verb is regular)
Past tense
Note: consider y as neither consonant nor vowel.
Normally, just adding ed after the end of verb makes the past tense of the verb.
Ex: jump → jumped, ask → asked
However, there are other rules.
If the last character of the given verb is
e, just addd.Ex:
love→loved,move→movedIf the verb is ended with a consonant +
y, then changeytoi, and added.Ex:
study→studied,cry→criedHowever, if the verb is ended with a vowel +
y, then just added.Ex:
play→played,stay→stayedIf a verb is ended with a vowel and a consonant, then write the consonant one more time, and add
ed.Ex:
stop→stopped,plan→plannedHowever, if a verb is ended with multiple vowels + a consonant or single vowel + multiple consonants, then just add
ed.Ex:
look→looked,jump→jumped
There are more rules but let's care above rules only. For example, according to above rule, visit → visitted.
Winner
Since this is code golf, the shortest code that correctly returns past tenses wins.
Example (JS, 127)
function f(x){return x.replace(/([^aeiouy])y$/,'$1i').replace(/([^aeiouy][aeiou])([^aeiouy])$/,'$1$2$2').replace(/e$/,'')+'ed'}
something directly related to it, can there be a function which returns the third form? – Shaheer – 2012-02-23T19:57:33.520
Now that's a nice challenge. – FUZxxl – 2011-11-14T16:32:20.673
inverse stemming! interesting! I'll try to give a try when I get back home :) – DallaRosa – 2011-11-15T09:57:02.417
Any solution that's shorter than 1800 characters is incorrect (irregular verbs). – Quandary – 2011-11-19T08:00:46.947
@Quandary That's why I said '(Assume that the verb is regular)' – JiminP – 2011-11-19T10:55:36.737
@Quandary: Not quite true... see Belisarius' answer.
– Simon – 2011-11-26T03:53:36.030