| Bytes | Lang | Time | Link |
|---|---|---|---|
| 052 | tinylisp 2 | 230112T223640Z | DLosc |
| 024 | Uiua | 240320T170345Z | noodle p |
| 062 | Swift 5.9 | 240319T194728Z | macOSist |
| 040 | Lexurgy | 230112T162402Z | bigyihsu |
| 011 | Vyxal 3 | 240319T185407Z | pacman25 |
| 036 | JavaScript | 220524T085915Z | Shaggy |
| 015 | Japt | 220524T085603Z | Shaggy |
| 155 | Nibbles | 230124T195552Z | Adam |
| 048 | Haskell | 220531T141512Z | Wheat Wi |
| 050 | Haskell | 220524T174649Z | xnor |
| 103 | Go | 230112T162728Z | bigyihsu |
| 013 | Vyxal | 220524T164847Z | naffetS |
| 023 | V Eh | 220524T163613Z | hdrz |
| 079 | C gcc with m32 | 220524T195332Z | ErikF |
| 083 | StackCell | 220531T233355Z | Starwort |
| 531 | brainfuck | 220531T221104Z | nununois |
| 114 | GeoGebra | 220526T000744Z | Aiden Ch |
| 057 | Haskell | 220524T171018Z | naffetS |
| 036 | Powershell | 220524T225028Z | another |
| 145 | Batch | 220525T005655Z | Youserna |
| 113 | C gcc | 220524T100443Z | matteo_c |
| 025 | sed | 220525T072753Z | Chris |
| 031 | APL Dyalog Extended | 220525T063118Z | user1069 |
| 015 | Pip | 220524T221334Z | DLosc |
| 081 | C gcc | 220524T214517Z | att |
| 011 | Stax | 220524T185104Z | recursiv |
| 039 | Lua | 220524T184013Z | Luatic |
| 049 | SNOBOL4 CSNOBOL4 | 220524T182510Z | Giuseppe |
| 045 | Factor | 220524T104854Z | chunes |
| 029 | sed | 220524T140651Z | Noodle9 |
| 040 | Java 8 | 220524T111930Z | Kevin Cr |
| 020 | Perl 5 + p | 220524T104559Z | Dom Hast |
| 025 | Charcoal | 220524T103531Z | Neil |
| 012 | Jelly | 220524T091727Z | Unrelate |
| 013 | 05AB1E | 220524T090137Z | Kevin Cr |
| 062 | Python 3.8 prerelease | 220524T082751Z | Jitse |
| 053 | Python | 220524T091744Z | pxeger |
| 149 | Excel | 220524T090916Z | Wernisch |
| 036 | Zsh | 220524T082955Z | pxeger |
| 019 | Retina | 220524T082843Z | ovs |
tinylisp 2, 64 61 52 bytes
(\(S)(: T([(. !(p contains?"aeiou"))S)(? T(,"shm"T)S
Explanation
Port of Unrelated String's Jelly answer, among others.
First, we need a function that tests whether a character is not a vowel:
(. !(p contains?"aeiou"))
(. ) ; Compose
! ; Logical negation
(p ) ; with the partial application of
contains? ; the contains? function
"aeiou" ; to "aeiou"
Then our main function is as follows (where (...) represents the above function):
(\(S)(: T([(...)S)(? T(,"shm"T)S)))
(\ ) ; Lambda function
(S) ; that takes a string S:
(: T ) ; In what follows, let T be
([ S) ; Drop characters from S while
(...) ; they are not vowels
(? T ) ; Is T truthy (nonempty)?
(,"shm"T) ; If so, concatenate "shm" with T
S ; If not, return the original string S
Swift 5.9, 67 63 62 bytes
let f={s in{$0>"" ?"shm"+$0:s}(s.drop{!"aeiou".contains($0)})}
Lexurgy, 42 40 bytes
a:
(!{a,e,i,o,u})*=>shm/$ _ {a,e,i,o,u}
Finds 0 or more not vowels at the start of input before a vowel and replaces them with shm.
- -2 bytes by not using classes.
Japt, 15 bytes
r"^.*?%v"ÈÌi`¢m
Try it (Includes all test cases)
r"^.*?%v"ÈÌi`¢m :Implicit input of string
r :Replace
"^.*?%v" : RegEx /^.*?[aeiou]/gi
È : Pass each match through a function
Ì : Last character
i : Prepend
`¢m : Compressed string "shm"
Nibbles, 15.5 bytes
?,;>~$-~?"aeiou"$:"shm"@@
Nibbles has no built-in for vowels, which makes it slightly worse than other golfing languages for this.
Explanation
? If
, non-empty
; x :=
>~ drop-while
$ from input
-~ not
? "aeiou" contained in "aeiou"
$ it
then
: "shm" prepend "shm"
@ to x
else
@ input
Haskell, 50 bytes
snd.break(`elem`"aeiou")>>=(?)
""?s=s
r?_="shm"++r
Thanks to Roman Czyborra for -2 bytes
Go, 103 bytes
import."regexp"
func f(s string)string{return MustCompile(`^.*?([aeiou])`).ReplaceAllString(s,"shm$1")}
Vyxal, 13 bytes
k⁰øl:[«88«p|_
Port of Jelly.
How?
k⁰øl:[«88«p|_
k⁰øl # Strip leading consonants
:[ # If there's anything left:
«88«p # Prepend "shm"
|_ # Else, pop, returning the implicit input
V (Eh, vim shmim), 23 bytes
:%s/.\{-}\ze[aeiou]/shm
vim non-greedy regex with look-ahead.
Same in “magic very very” mode:
23 bytes
:%s/\v.{-}[aeiou]@=/shm
Further 3 bytes can be saved by replacing :%s/ with V’s specific í
C (gcc) with -m32, 90 85 83 79 bytes
- -2 thanks to ceilingcat
- -4 by removing an unused variable
v;f(char*s){for(v=s;v**s;)index("aeiou",*s++)&&printf("shm",v=0);puts(v?:--s);}
StackCell, 83
(@:{X}X:'a-!?6:'e-!?6:'i-!?6:'o-!?6:'u-!?3!)6"mhs"16:[;:]18(@:!?.;)X{:[{X}X:]X:[;:]
Explanation (for a previous, incomplete version of the program):
(@:'a-!?6:'e-!?6:'i-!?6:'o-!?6:'u-!?2!)"mhs":[;:](@:!?.;) Assumes the input contains a vowel
( ) Loop over the initial characters, breaking if ) is reached with a non-zero value
@ Input a character
:'a- Duplicate and calculate the difference with the character 'a'
!? If there is any difference, skip the next instruction
6 Skip 6 instructions (to next 6)
:'e-!?6:'i-!?6:'o-!?6:'u-!?2 Check the other four vowels; the 2 breaks out of the loop
! Negate the character; EOF => 1, anything else => 0
"mhs" Push the characters mhs to the stack
:[;:] Print the characters s, h, m, and the vowel that caused the initial loop to break
( ) Loop forever (a non-zero value will never be present at the end of the loop
@: Input and duplicate a character
!?.; If it's non-null (EOF), print it. Otherwise, halt.
brainfuck, 531 bytes
->+[->[>],[+[-<+]->+[>]<[>+>+<<-]>>[<<+>>-]-[>++<-----]>-----<<[->>-<<]+>>[<<->>[-]]<<[+[-<+]->-]+[-<+]->[[>]<[>+>+<<-]>>[<<+>>-]-[>++<-----]>-<<[->>-<<]+>>[<<->>[-]]<<[+[-<+]->-]+[-<+]->[[>]<[>+>+<<-]>>[<<+>>-]-[>++<-----]>+++<<[->>-<<]+>>[<<->>[-]]<<[+[-<+]->-]+[-<+]->[[>]<[>+>+<<-]>>[<<+>>-]-[>--<-------]>+<<[->>-<<]+>>[<<->>[-]]<<[+[-<+]->-]+[-<+]->[[>]<[>+>+<<-]>>[<<+>>-]----[>+++++<--]>-<<[->>-<<]+>>[<<->>[-]]<<[+[-<+]->-]+[-<+]->[>]]]]]]+[-<+]->]>[>]<-[++[-<+]->>[.>]>-<]>+[[--------->++<]>+.-----------.+++++.<<<.,[.,]]
This implementation is as close to a nested if/else statement as bf allows. Simply checks each letter to see if it's a vowel. If it finds one, it prints "shm", then the vowel, then the rest of the input. If it doesn't, it simply prints out the input from its buffer.
brainfuck, 423 bytes
+[--------->++<]>+.-----------.+++++.<->>+[>,[>+>+<<-]>>[<<+>>-]-[>++<-----]>-----<<[->>-<<]+>>[<<->>[-]]<<[<<->>-]<<[>[>+>+<<-]>>[<<+>>-]-[>++<-----]>-<<[->>-<<]+>>[<<->>[-]]<<[<<->>-]<<[>[>+>+<<-]>>[<<+>>-]-[>++<-----]>+++<<[->>-<<]+>>[<<->>[-]]<<[<<->>-]<<[>[>+>+<<-]>>[<<+>>-]-[>--<-------]>+<<[->>-<<]+>>[<<->>[-]]<<[<<->>-]<<[>[>+>+<<-]>>[<<+>>-]----[>+++++<--]>-<<[->>-<<]+>>[<<->>[-]]<<[<<->>-]]]]]+[-<+]->>]>.,[.,]
A shorter version that only works for words with vowels.
GeoGebra, 114 bytes
s="a"
InputBox(s)
S=Take(s,IndexOf(Element(Split(s,Split("bcdfghjklmnpqrstvwxyz",{""})),1),s))
If(S=="",s,"shm"+S)
Not sure why, but the code won't work if you put in an empty string as initial value of s (or any string consisting of only consonants), but it will work properly for all test cases (even ones that do consist of only consonants) if you have a string with a vowel as the initial value of s.
The input should be entered into the Input Box.
Haskell, 58 57 bytes
f s|g s>""="shm"++g s|1>0=s
g=dropWhile(`notElem`"aeiou")
-1 byte thanks to Wheat Wizard ♦
Powershell, 36 bytes
$args-replace('^.*?([aeiou])','shm$1')
Explanation
Simple replace with a named group reference.
Thanks caird coinheringaahing
Thanks mazy
Batch, 157 145 bytes
@set i=%1
:l
@(echo %i:~,1%|findstr/r [aeiou]&&set a=1||set a=0)>nul
@if %a%==0 (if %i%. neq . (set i=%i:~1%&goto:l)else echo %1)else echo shm%i%
Input is taken from the command line.
-12 bytes thanks to Neil.
C (gcc), 125 113 bytes
-8 bytes thanks to @ceilingcat
#define T&&*s-
main(s,v)char**v,*s;{for(s=*++v;*s T'a'T'e'T'i'T'o'T'u'||!(*v=memcpy(s-3,"smh",3));++s);puts(*v);}
sed, 25 bytes
/[aeiou]/s/[^aeiou]*/shm/
/[aeiou]/ is a conditional that only runs the substitution s/[^aeiou]*/shm/ if there is a vowel in the line. This prevents needing to capture the first vowel and then using a backreference as in the more obvious s/[^aeiou]*\([aeiou]\)/shm\1/.
Pip, 15 bytes
a~XVaH$(:"shm"a
Explanation
a~XVaH$(:"shm"a
a Command-line argument
~ Find first match of
XV regex `[aeiou]`
$( Index of that match
aH Prefix of cmdline arg containing that many characters
: Set to
"shm" that string
If a vowel was not found, $( is nil, which means no assignment is done
and a's value remains unchanged
a Autoprint the (possibly changed) value of a
C (gcc), 81 bytes
i;f(char*s){for(i=0;*s-"aeiou"[++i%6];i%6||s++);printf("shm%s"+3*!*s,s-i*!*s/6);}
Stax, 11 bytes
ÄFï¥░$º{═┘ç
- Left-trim consonants.
- If non-empty, prepend "shm".
- Else restore original input.
Lua, 39 bytes
print((...):gsub("^.-%f[aeiou]","shm"))
Uses the frontier pattern to shave off two bytes. String must be provided as argument, printed output is (1) the shmodegolfed string and (2) 0 if unmodified, 1 if modified.
SNOBOL4 (CSNOBOL4), 49 bytes
I =INPUT
I BREAK('aeiou') ='shm'
OUTPUT =I
END
BREAK "matches zero or more characters provided they are not in the set of characters in the argument string. That is, it matches up to, but not including, a character from the argument string."
Java 8, 40 bytes
s->s.replaceAll("^.*?([aeiou])","shm$1")
Port of the JavaScript and Retina answers.
Or a minor alternative:
s->s.replaceAll("^.*?(?=[aeiou])","shm")
Explanation:
s-> // Method with String as both parameter and return-type:
s.replaceAll( // Modify and return the String: Regex-replace all
"...", // these matches
"...") // with these replacements
Regex-explanation 1:
^.*?([aeiou]) # Match:
^ # At the start of the string
.* # Match zero or more characters
? # Which are optional, to give other matches precedence
[aeiou] # Followed by a vowel
( ) # captured in capture group 1
shm$1 # Replacement:
shm # Literal "shm"
$1 # And the vowel of capture group 1
Regex-explanation 2:
^.*?([aeiou]) # Match:
^ # At the start of the string
.* # Match zero or more characters
? # Which are optional, to give other matches precedence
(?= ) # Followed by a positive (non-matching) look-ahead to:
[aeiou] # A vowel
shm # Replacement:
shm # Literal "shm"
Minor note: the replaceAll with ^ is basically the same as a replaceFirst without the ^, but 1 byte shorter: try it online.
Perl 5 + -p, 20 bytes
Uses the ; separator (as ; is implicitly added via -p).
s;.*?(?=[aeiou]);shm
Perl 5 + -lF/^[^aeiou]+/ -M5.10.0, 17 bytes
Slightly more cheaty with the regex in the flags, but saves a few bytes
say@F?(shm,@F):$_
Charcoal, 25 bytes
≔⌕Eθ№aeiouι¹η¿⊕η«shm✂θη»θ
Try it online! Link is to verbose version of code. Explanation:
≔⌕Eθ№aeiouι¹η
Count the number of vowels in each character and find the first 1 i.e. the index of the first vowel in the input.
¿⊕η
If there was in fact a vowel, then...
«shm✂θη»
... output the literal string shm followed by the input sliced starting at that index.
θ
Otherwise just output the input string.
Jelly, 16 12 bytes
œlØḄṭ⁸¹?“shm
-4 thanks to ovs remembering there's a strip builtin
œlØḄ Strip all leading consonants.
ṭ “shm Prepend "shm"
¹? if there's anything left, otherwise
⁸ give the original word.
05AB1E, 28 13 bytes
žNSÛ©ai®…shmì
Try it online or verify all test cases.
Explanation:
žNSÛ # Trim all leading consonants of the (implicit) input-string
© # Store this new string in variable `®` (without popping)
ai # Pop, and if any letters are left (thus the input-string contains
# a vowel):
® # Push string `®` again
…shmì # Prepend "shm"
# (implicitly print it as result)
# (implicit else)
# (implicitly output the implicit input-string)
Python 3.8 (pre-release), 62 bytes
lambda s:(q:=s.lstrip('bcdfghjklmnpqrstvwxyz'))and'shm'+q or s
Python, 53 bytes
lambda s:re.sub("^.*?([aeiou])","shm\\1",s)
import re
Another regex answer.
Alternative:
Python, 53 bytes
lambda s:re.sub(".*?(?=[aeiou])","shm",s,1)
import re
Excel, 149 bytes
=IFERROR(REPLACE(A1,1,FIND("$",SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(A1,"a","$"),"e","$"),"i","$"),"o","$"),"u","$"))-1,"shm"),A1)
102 bytes just to find the vowels. If anybody knows a better way to do this. please share.
From inside out:
- SUBSTITUTE vowels with
$ - Find the index of the first
$ - Replace chars before this index with
shm - If no vowels, return input.
Zsh, 36 bytes
<<<${(S)1/#(#b)*([aeiou])/shm$match}
<<<: print${1}: the input...//: replace the first match#: matching only at the beginning of the string(#b): activate backreferences, so the()group gets stored in the$matchvariable(S): use the shortest possible match, rather than the longest*: anything(): store this match in the variable:[aeiou]: followed by a vowel
- with
shm$match: the stringshm, plus the matched vowel
$match is actually an array which contains all the backreference groups, but since there's only one group, we don't need to access any specific element with [1]
Retina, 19 bytes
Just a regex replacement, there might be some language feature which allows for a shorter solution.
^.*?(?=[aeiou])
shm