Copodope Gopolopfop

15

3

The Language: Oppification

A funny language to speak is created by applying the following process to each word:

  1. Place op after each consonant. So Code becomes Copodope.

Yes, that's it. For the purpose of this challenge, y is always a consonant.

The Challenge: De-oppification

Given an oppified word, return the original word. Input will only contain letters. The first letter may be capitalized. The original word will never be empty and will always contain a vowel.

Test Cases:

Oppified      ->         Original 
a                        a
I                        I
itop                     it
opop                     op
Opop                     Op
popopop                  pop
Copopop                  Cop
opopopop                 opop
Kopicopkop               Kick
Asopia                   Asia
soptopopop               stop
hopoopopsop              hoops
hopoopopedop             hooped
ooooohop                 oooooh
aaaopopaaa               aaaopaaa
Popopopsopicoplope       Popsicle
gopaloplopopopinopgop    galloping
aopopbopopopcopopop      aopbopcop

mbomb007

Posted 2017-06-05T19:31:48.753

Reputation: 21 944

8None of your test cases contain a vowel followed by op, so an answer along the lines of replace(/(.)op/, '\1') won't fail any of them. I suggest that you add a word like hoop or looped to the test cases. – Doorknob – 2017-06-05T19:35:56.670

@mbomb007 I added some more tricky test cases. – xnor – 2017-06-05T20:09:40.970

Does the answer only have to work for preoppified inputs or all inputs? – CalculatorFeline – 2017-06-06T02:51:42.483

@CalculatorFeline "Given an oppified word" – mbomb007 – 2017-06-06T04:21:46.863

Actually, all the people I know who speak this for fun agree that you add an "op" only right before a vowel sound. Code => Copode, Benji => Bopenjopi. – BenjiWiebe – 2017-06-06T05:41:34.627

2Can we add "mopmopmopbopopop" as a test case? :) – user2390246 – 2017-06-06T07:31:25.157

@Doorknob I think that approach also works correctly for those test cases, doesn't it? – Martin Ender – 2017-06-06T07:41:07.717

@BenjiWiebe I'll run that by the person who told me. – mbomb007 – 2017-06-06T13:32:09.680

WikiHow states "Some Oppish speakers insist on an “opp” after every single consonant, so the word, “flip” would be spelled, “f-opp l-opp i -p-opp.”" – mbomb007 – 2017-06-06T13:40:07.723

Answers

10

V, 12, 5 bytes

Í.“op

Try it online!

00000000: cd2e 936f 70                             ...op

Saved 7 bytes thanks to @Xnor's realization that since the input must always be opped, we don't have to check for vowels.

James

Posted 2017-06-05T19:31:48.753

Reputation: 54 537

Hmm, this seems so hard to beat... – Erik the Outgolfer – 2017-06-05T20:08:58.933

4The hex dump: ...op Is making me laugh way harder than it should – nmjcman101 – 2017-06-06T11:33:51.647

12

Retina, 9 bytes

(?!\G)op

Try it online!

Instead of checking that the preceding character is a consonant, we just make sure that the current op is not adjacent to either the beginning of the string or the previous match. The only case where we could match an incorrect op is if the original string contained an op (resulting in opop). But in that case we'll just remove the first op instead of the second and the result will be the same.

Martin Ender

Posted 2017-06-05T19:31:48.753

Reputation: 184 808

Wouldn't this give an incorrect answer for an input like loop? – Leo – 2017-06-06T07:27:41.650

4@Leo loop is not a valid input because you can't obtain it from oppifying another word. – Martin Ender – 2017-06-06T07:39:12.053

@MartinEnder But lopoop (the oppified version of loop) is valid, and doesn't get de-oppified to loop. – Imus – 2017-06-06T11:48:42.580

@Imus no, the oppified version of loop is lopoopop. – Martin Ender – 2017-06-06T11:49:34.247

realised my mistake as well shortly after posting it :) was too slow in deleting. Good point. – Imus – 2017-06-06T11:50:58.180

@MartinEnder you're right. Sadly, it looks like simply replacing .op with the first character, as some answers in other languages do, is shorter (but less interesting, in my opinion)

– Leo – 2017-06-06T18:14:00.653

@Leo Yes, I noticed in the meantime, but I'll leave that to either NoOneIsHere or Doorknob. – Martin Ender – 2017-06-06T18:15:04.090

10

Python, 42 bytes

lambda s:re.sub('(.)op',r'\1',s)
import re

Try it online!

If I'm not mistaken, you can just substitute all ?op with ? without caring about vowels. If the original string contains op, then it's oppified to opop, and the replacement returns it to op and no further. This is because the pattern matches for ?op cannot overlap, so only one op is removed.

A non-regex solution is 5 bytes longer.

Python, 47 bytes

f=lambda s:s and s[0]+f(s[1+2*(s[1:3]=='op'):])

Try it online

xnor

Posted 2017-06-05T19:31:48.753

Reputation: 115 687

3You can import re after you reference it‽ – Adám – 2017-06-05T20:57:11.540

4@Adám Python doesn't evaluate it when the function is defined, only when it's called. – xnor – 2017-06-05T20:59:26.767

4Wow, it's been a while since I've seen anyone use an interrobang. I guess that's a way to golf your comment a little. – Baldrickk – 2017-06-06T12:24:42.700

1@Baldrickk But in bytes, the interrobang has >= bytes than just the string "?!" – MilkyWay90 – 2019-06-15T15:39:49.883

5

Retina, 15 8 bytes

(.)op
$1

Try it online!

-7 bytes thanks to Kevin Cruijssen

NoOneIsHere

Posted 2017-06-05T19:31:48.753

Reputation: 1 916

2

You can save 7 bytes by replacing [^aeiou] with .. See @xnor's explanation in his Python answer.

– Kevin Cruijssen – 2017-06-06T08:18:10.450

5

Perl 5, 10 + 1 = 11 bytes

s/.\Kop//g

Try it online!

Run with -p (1 byte penalty); golfing languages might do implicit I/O automatically, but Perl needs an option for it.

When I saw @xnor's answer, I realised it could be improved using a Perl-specific regex feature; s/a\Kb/c/g is equivalent to s/ab/ac/g (in other words, the s/// only replaces the things after the first \K). So here's how it looks in Perl.

user62131

Posted 2017-06-05T19:31:48.753

Reputation:

3

Go, 103 92 bytes

Must... compile... Go built-in functions have weird names. :P

import."regexp"
func f(s string)string{return MustCompile("(.)op").ReplaceAllString(s,"$1")}

Try it online!

totallyhuman

Posted 2017-06-05T19:31:48.753

Reputation: 15 378

3

PHP, 36 bytes

<?=preg_replace("#.\Kop#","",$argn);

Try it online!

Jörg Hülsermann

Posted 2017-06-05T19:31:48.753

Reputation: 13 026

How is this supposed to be run? – Titus – 2017-06-06T21:00:21.913

It fails for the first two test cases. Use preg_replace to fix. – Titus – 2017-06-06T21:03:38.053

You can save 3 bytes by renaming the variable to any single character, $a for instance – junkfoodjunkie – 2017-06-07T02:45:37.487

@junkfoodjunkie $argn is a reserved variable which is availbale when PHP is run with the -ROption from the command line – Jörg Hülsermann – 2017-06-07T09:30:30.983

Ah, okay, didn't know that. The online tester doesn't account for it. :-) – junkfoodjunkie – 2017-06-07T09:34:02.510

3

Haskell (93 62 61 Bytes)

a(x:'o':'p':r)|notElem x"aeiouAEIOU"=x:a r
a(x:r)=x:a r
a x=x

thanks to @nimi suggestions in comments!

Davide Spataro

Posted 2017-06-05T19:31:48.753

Reputation: 211

2Some tips: as you are using v and o only once, you can inline it. notElem is shorter than not(...elem...). You can replace the && in a guard with a ,. The last case for a can be written as a x=x. No need for () in x:(a r). – nimi – 2017-06-05T20:56:31.023

1... oh, and the test for =="op" can be replaced with a literal pattern match: a(x:'o':'p':r)|notElem x"aeiouAEIOU"=x:a r – nimi – 2017-06-05T20:59:31.557

Updated. thanks @nimi – Davide Spataro – 2017-06-05T21:13:26.720

1One more byte to save: you can omit the space between x and ". – nimi – 2017-06-05T21:21:47.190

2

Japt, 9 bytes

r"%Vop"_g

Try it online

Shaggy

Posted 2017-06-05T19:31:48.753

Reputation: 24 623

1

JavaScript (ES6), 35 bytes

Add f= at beginning and invoke like f(arg).

s=>s.replace(/([^aeiou])op/gi,"$1")

I am surprised no one posted a JavaScript solution yet....

Test Snippet

let f=
s=>s.replace(/([^aeiou])op/gi,"$1")

console.log("a" + " -> " + f("a"));
console.log("I" + " -> " + f("I"));
console.log("itop" + " -> " + f("itop"));
console.log("opop" + " -> " + f("opop"));
console.log("Opop" + " -> " + f("Opop"));
console.log("popopop" + " -> " + f("popopop"));
console.log("Copopop" + " -> " + f("Copopop"));
console.log("opopopop" + " -> " + f("opopopop"));
console.log("Kopicopkop" + " -> " + f("Kopicopkop"));
console.log("Asopia" + " -> " + f("Asopia"));
console.log("soptopopop" + " -> " + f("soptopopop"));
console.log("hopoopopsop" + " -> " + f("hopoopopsop"));
console.log("hopoopopedop" + " -> " + f("hopoopopedop"));
console.log("ooooohop" + " -> " + f("ooooohop"));
console.log("aaaopopaaa" + " -> " + f("aaaopopaaa"));
console.log("Popopopsopicoplope" + " -> " + f("Popopopsopicoplope"));
console.log("gopaloplopopopinopgop" + " -> " + f("gopaloplopopopinopgop"));
console.log("aopopbopopopcopopop" + " -> " + f("aopopbopopopcopopop"));

Arjun

Posted 2017-06-05T19:31:48.753

Reputation: 4 544

1

C (gcc), 83 bytes

main(c,v)char**v;{for(;*v[1];strchr("aAeEiIoOuU",putchar(*v[1]++))?:printf("op"));}

Try it online!

cleblanc

Posted 2017-06-05T19:31:48.753

Reputation: 3 360

0

Crystal, 39 Bytes

def o(s)s.gsub(/([^aeiou])op/,"\\1")end

How it works

It simply searches for each consonant, followed by the sequence op. If so, replace that sequence only with the consonant found before: ([^aeiou]).

Try it online

Domii

Posted 2017-06-05T19:31:48.753

Reputation: 219

0

Ruby, 34 27 22 + 1 = 23 bytes

-4 bytes thanks to RJHunter.

+1 byte for the -p flag.

$_.gsub!(/(.)op/,'\1')

Try it online!

totallyhuman

Posted 2017-06-05T19:31:48.753

Reputation: 15 378

Using Ruby's -p option will cost a byte but allow your script to start directly with gsub. – RJHunter – 2017-06-06T01:08:54.283

0

///, 18 bytes

/op/.//../o\p//.//

Try it online!

Note that this snippet wants to replace op with a ., but later on there is a replacement defined where op is being put back into the string. That second instruction would have the op replaced by a . (and thus insert a . into the end result), so I've used a \ between the o and p to break the pattern.

steenbergh

Posted 2017-06-05T19:31:48.753

Reputation: 7 772

0

APL (Dyalog), 13 bytes

'(.)op'⎕R'\1'

Try it online!

Simply PCRE Replace any character followed by "op" with the character itself.

Adám

Posted 2017-06-05T19:31:48.753

Reputation: 37 779

0

Java 8, 36 26 bytes

s->s.replaceAll("(.)op","$1")

-10 bytes by replacing [^aeiou] with ., thanks to @xnor's explanation in his Python answer.

Try it here.

Kevin Cruijssen

Posted 2017-06-05T19:31:48.753

Reputation: 67 575

0

sed, 22 bytes

sed -E 's/(.)op/\1/g'

Reads from STDIN until EOF and outputs de-oppified string
Uses same length reduction technique from @xnor's Python answer

Arc676

Posted 2017-06-05T19:31:48.753

Reputation: 301

0

R, 29 bytes

gsub("(.)op","\\1",scan(,''))

Try it online!

Much like most other solutions here, captures character followed by op, replaces it with character itself.

Sumner18

Posted 2017-06-05T19:31:48.753

Reputation: 1 334