# Lithp Tranthlator

My friend made a lisp translator the other day, that is to say it took a string and converted s=>th and S=>Th. It was quite long and I thought that it could be golfed.

So the task is to make a program/function that takes an input string, translates it in to lisp and outputs the string

Test case

Sam and Sally like Sheep        Tham and Thally like Thheep
Sally likes sausages            Thally liketh thauthageth
Sally sells seashells           Thally thellth theathhellth

Note that it doesn't matter that h gets repeated all the time

This is code golf so shortest answer wins

• I wished everyone would change the bytes in their headers to byteth. – Leaky Nun Jun 17 '16 at 17:14
• There should be bonus points if the program doesn't use s nor S anywhere in it. – Nate Diamond Jun 17 '16 at 18:41
• I think the language names should be made clear. Without the replacement. Some languages contain "th" already, so it's ambiguous. And who's to say that someone won't create a different language actually called "Common Lithp" in the future? – mbomb007 Jun 17 '16 at 21:02
• @mbomb007 I wouldn't worry about it too much. I'm not sure if there is actually a default way to title your answer. Most question I see if they do state how to do it it is normally the same way. As I haven't explain how the answer should be set out, then users are free to title them how they want to. Being a pedant, I didn't even ask for a language, so I could argue against them even writing them. But I do understand your point. I just don't think it is of concern – george Jun 17 '16 at 21:09
• A thing that would have made this challenge more interesting would be overall case preservation, e.g. LOOK OUT A SNAKE!!! -> LOOK OUT A THNAKE!!! – fluffy Jun 18 '16 at 3:06

# Perl 5, 18 byteth

The obviouth anthwer; I don't thee anything thhorter. 17 byteth, pluth 1 for -pe inthtead of -e.

s/s/th/g;s/S/Th/g

I wathn't thure whether, tho ath to follow the thandard for anthwerth of thith quethtion, I thhould lithpify my code ath well ath my prothe. Jutht in cathe, here'th the lithpy verthion:

th/th/th/g;th/Th/Th/g

# J, 38 bytes

rplc&('s';'th';'S';'Th')

In J, rplc is the string replace verb in the strings addon, and it takes a list of boxes where each pair [x, y] represents the string x to be replaced with y.

## Usage

f =: rplc&('s';'th';'S';'Th')
f 'Sam and Sally like Sheep'
Tham and Thally like Thheep
f 'Sally likes sausages'
Thally liketh thauthageth
f 'Sally sells seashells'
Thally thellth theathhellth

## C, 69 byteth

Reads from stdin, writes to stdout. Nothing terrific, but somebody had to do it!

c;main(){while((c=getchar())>0)printf(c-'s'?c-'S'?"%c":"Th":"th",c);}

# C, 101 bytes

Note this is a complete C program, unlike the previous C answer.

It takes the first command line argument as input. Compile w/ gcc and run ./a.out "Sally sells seashells"

#include<stdio.h>
main(int d,char**c){for(d=**++c;d;putchar(d&223^83?d:d+(*0[c]--=104,1)),d=*++*c);}
• Hello, and welcome to PPCG! – NoOneIsHere Jun 18 '16 at 1:27
• Erm, whether the program is complete doesn't matter. On PPCG we accept both full programs and functions. – user48538 Jun 18 '16 at 7:57

# J, 47 bytes

Without using the strings library.

[:;(]('h',~[:u:1+3&u:)@.([:+/'sS'-:"0]))&.>@;/

# Brainfuck, 235 byteth

,[[>+>+>+<<<-]>>>>-[>+<---]>--[-<<->>]+<<[>>-<<[-]]>>[>-[--->+<]>-.[---->+++++<]>-.<<<-]>>>>
[-]<[>+<[-]]+>[<->-]<[<<<<<-[>++<+++++++++]>+[-<<->>]+<<[>>-<<[-]]>>[>--------[-->+++<]>.---
---------.>]<>[-]<[>+<[-]]+>[<->-]<[<<.>]]>>>>>>>,]

Requires 8-bit cells, and 0 on EOF. Try it online! I thought I could golf tt using some "if = s OR = S" wizardry, but it turns out that this just confounds the system.

,
[
[>+>+>+<<<-]>>>
>-[>+<---]>--
[-<<->>]+<<[>>-<<[-]]>>
[ if char = "S"
>-[--->+<]>-.[---->+++++<]>-.<<<-  output Th
]
>>>

>[-]
<[>+<[-]]+
>[<->-]<    logical negation

[ else
<<<<<
-[>++<+++++++++]>+
[-<<->>]+<<[>>-<<[-]]>>

[ if char = "s"
>--------[-->+++<]>.------------.>  output th
]

<

>[-]
<[>+<[-]]+
>[<->-]<    logical negation

[<<.>] otherwise output and move to zero cell
]
>>>>>>> we're going to move over some so we can use new cells
, take more input
]

## Matlab, 38 42 bytes

@(t)regexprep(t,{'s','S'},{'th','Th'})

Shout out to @LuisMendo for the tip about cell arrays!

For 'Miss Sissy' yields ans = Mithth Thiththy.

• I think straightforward approach is shorter: codegolf.stackexchange.com/a/83190/55372 – pajonk Jun 17 '16 at 18:37
• You can use a single call to regexprep with cell arrays: @(t)regexprep(t,{'s' 'S'},{'th' 'Th'}), 38 bytes – Luis Mendo Jun 18 '16 at 15:26
• @LuisMendo I had had problems using cell arrays in regexprep before, but they seem to have straightened that out. Edited! – sintax Jun 20 '16 at 13:43

# s-lang, 1615 8 bytes (non-competing)

Saved one byte because s-lang no longer requires last argument bracket

Saved seven bytes because of ! paramater

### Try it online!

t![s][th

s-lang (or, th-lang) is a string manipulation language I am working on for fun. I am still optimizing argument brackets...

## Explantion

• t replace function with search argument and replace argument.
• ! "preserve case" parameter
• [s] the first search argument (searches for the character "s")
• [th the first replace argument (now this will replace each "s" with a "th"). End bracket is omitted because it is unnecessary.
• Doesn't p parameter need +1 byte? – Erik the Outgolfer Jul 4 '16 at 18:36
• @EʀɪᴋᴛʜᴇGᴏʟғᴇʀ Oh.. it is now "!" instead of "!". I'll fix that – MCMastery Jul 9 '16 at 22:58

# Javathcript, 27 Byteth

b=a=>a.replace(/s/gi,'th');

Although it is case insensitive it is the smallest JS version so far :)

## Pyke, 14 byteth

\s"th":\S"Th":

Try it here!

Thith anthwer ith very thimple and boring.

## Thue, Full program: 27 byteth, function: 13 byteth

s::=th
S::=Th

Thince Thue can read input, a correct input routine will be too long. Tho i potht it ath a "function"

EDIT: I have forgotten, Thue read lineth from thtdin, not characterth

Tho, here ith a full program:

s::=th
S::=Th
I::=:::
::=
I
• Is the language Thue or Sue? – clismique Jul 10 '16 at 16:44
• @DerpfacePython The tranthformationth are only s => th and S => Th, tho it'th Thue. – TuxCrafting Jul 10 '16 at 16:50
• Ah, I underthtand now. Thankth! – clismique Jul 10 '16 at 16:51

# PowerThhell, 41 bytes

$args.replace('S','Th').replace('s','th') I can't beat this simple approach; there is a string.translate buried in XPath and there are map style approaches in the Linq library - but they're wordy. Can't easily do a dictionary lookup per character because PS is case insensitive and thinks 's' and 'S' are duplicate keys. Best novelty alternative so far:$OFS='Th';''+\$args.split('S')-replace's','th'

# Thilicon, 13 byteth

is|thS|Th`

Pretty simple. i to get input, and the rest of it is replacing stuff. Output is implicit.

## TCC - 28 bytes

=SO;i;{'s';'th';{'S';'Th';SO

Try it online!

Explanation:

=SO;i;                       - Load input (i) into SO (string operations)
{'s';'th';             - Replace 's' with 'th' in SO
{'S';'Th';   - Replace 'S' with 'Th' in SO
SO - Implicit print of SO
• Did this work with a version of tcc.lua before the challenge was posted? Given that you've recently added commands to solve several other challenges, I assume it didn't. If your answer requires a version of the language that postdates the challenge, you must label it as non-competing in the header. I'll remove my downvote when you add the label or provide proof that your code worked in an earlier version. – Dennis Jul 31 '16 at 21:20