New answers tagged string
0
votes
Change the quotations as if in Microsoft Word
C (clang), 81 bytes
x,o;f(*s){for(x=o=0;*s=*s-39?s[x=0]:8216+(x||o&&!s[x=1]||o>64&&s[1]>64);o=*s++);}
Try it online!
2
votes
Is string X a subsequence of string Y?
Factor + math.combinatorics, 19 bytes
[ all-subsets in? ]
Try it online!
1
vote
Determine whether strings are anagrams
Knight, 51 bytes
O?C=cB;=iP;=x*'0'256;Wi;=xSx=aAiT+1Gx aT=iSiF1""xCc
Try it online!
This challenge was made a lot easier because inputs were length 8 ...
1
vote
Encode the alphabet cipher
Knight, 45 41 bytes
-4 thanks Aiden
;=xP W<1Lx;O++*'0'-2L=a-Ax 96a'\'=xSxF1""
Try it online!
1
vote
Negative of an ASCII photo
Regex (PCRE2), 19 bytes
s/(#)| /${1:+ :#}/g
Try it online!
Try it on regex101!
This is a single regex substitution, to be applied once.
In this explanation, ...
2
votes
Negative of an ASCII photo
MATL, 4 bytes
5\Zc
Input is a char matrix containing and #.
Try it online!
How it works
<...
2
votes
Divisor of a string
Haskell + hgl, 12 bytes
he<<fl lq<pt
Attempt This Online!
Explanation
pt gets all ways to partition the input into ...
0
votes
Implement String Projection
Scala, 8 bytes
_.filter
Try it online!
This is an expression of type String => Set[Char] => String. It uses the fact ...
1
vote
1
vote
Covfefify a string
Vyxal o, 32 bytes
ðp≬k∪$cḊṘ÷Ḣ₴₴h:₴$hJ«ƛKS⟩NĖ!ǐ«ḂĿd
Try it Online!
Port of Grimmy's 05AB1E answer.
0
votes
Change the quotations as if in Microsoft Word
Retina 0.8.2, 28 bytes
(?<=^| )'|\b'(?=')
‘
'
’
Try it online! Link includes test cases. Explanation:
...
0
votes
Change the quotations as if in Microsoft Word
sed, 109 bytes
:z;s/'''/''’/g;t z;
s/''/‘’/g
s/ '(.)/ ‘\1/g
s/([a-zA-Z])'([a-zA-Z ])/\1’\2/g
s/^'/‘/g
s/'$/’/g
Try it online!
1
vote
Implement String Projection
Ruby, 29 bytes
->s,a{s.gsub(/./){a[_1]&&_1}}
Previous version which had flaws indicated by Deadcode:
...
2
votes
Add parentheses to Polish notation
nearley, 78 bytes
m->_ p _{%a=>a.flat(1/0)%}
p->[\d]:+|[-+/*] _ p _ p{%a=>['(',a,')']%}
_->" ":*
Post-processing functions for production ...
0
votes
0
votes
Could you make me a hexagon please?
Knight, 58 57 bytes
;=n+~1P;=i~1W>+1*2n=i+1iO+*' '=xI>=x-n iFx~x*'* '+1-*2n x
Try It Online!
1
vote
Implement String Projection
Raku, 22 bytes
{$^a.trans($^b=>""):c}
Try it online!
trans is Raku's beefed-up version of Perl 5's transliteration ...
0
votes
2
votes
Change the quotations as if in Microsoft Word
Retina, 42 bytes
'('+)
‘$.1*’
(^| )'
$1‘
'($|\w)
’$1
Assumes rule 6 takes prio over the other rules.
I have the feeling the first step can be shorter (perhaps with ...
0
votes
Implement String Projection
Red, 48 bytes
func[a b][foreach x a[if find/case b x[prin x]]]
Try it online!
2
votes
Divisor of a string
Red, 62 bytes
func[s][b: s forall s[if(replace/all copy b s"")=""[print s]]]
Try it online!
The key to this is that ...
4
votes
2
votes
Divisor of a string
Perl -p, 22 bytes
/^(.*)\1+$(??{say$1})/
Try it online!
This uses a "postponed" regular subexpression embedded code ...
2
votes
Divisor of a string
Zsh, 47 bytes
for c (${(s..)1})s+=$c&&[[ $1 = ($s)# ]]&&<<<$s
Try it online!
Fairly straightforward:
...
0
votes
Fill in the Blanks, Please!
PowerShell Core, 46 bytes
param($a,$b)-join($a-split'_+'|%{$_
$b[$i++]})
Try it online!
1
vote
Fill in the Blanks, Please!
K (ngn/k), 27 bytes
{(*c),/y,'1_c:(~#:')_"_"\x}
Try it online!
Splitting based on "runs of underscores" seems longer than splitting by single ...
0
votes
Fill in the Blanks, Please!
Regex (.NET), 46 bytes
s/_+(?<=((?=.*?(\2?`([^`]*)))_+.*?)*)|`.*/$3/g
Try it on regex101! - .NET
Input is taken as the string with blanks followed by the full ...
0
votes
Fill in the Blanks, Please!
Regex (RE2 or better), 23 bytes
s/_+(.*?)`([^`]*)/$2$1/
Try it online! - RE2
Try it online! - ECMAScript
Try it online! - Perl
Try it online! - PCRE2
Try it online!...
1
vote
Find columns where all characters are the same
JavaScript (Node.js), 67 bytes (Anonymous function)
a=>[...a[0]].reduce((p,c,i)=>p+(a.every(s=>s[i]==c)?i+c+" ":""),"")
Try ...
2
votes
"Hello, World!"
Carbon, 62 bytes
package c api;fn Main()->i32{Print("Hello, World!");return 0;}
Try it Online!
Thanks to @Steffan for fixing this
Carbon is a new ...
3
votes
Divisor of a string
sed -n, 58 46 bytes
s/^/\n/
:a
/^\(.*\)\n\1*$/P
s/\n\(.\)/\1\n/
ta
Attempt This Online!
3
votes
Divisor of a string
Charcoal, 15 bytes
ΦEθ…θ⊕κ№Eθ×ι⊕μθ
Try it online! Link is to verbose version of code. Explanation:
...
4
votes
Divisor of a string
Raku, 25 bytes
{~«m:ex/^(.+)$0*$/»[0]}
Try it online!
m/^(.+)$0*$/ looks for patterns of letters which, repeated, comprise the ...
4
votes
Divisor of a string
Ruby, 43 bytes
->s{(s+?␀+s).scan(/(?=(.+)␀\1*$)/).flatten}
Try it online!
This concatenates the string to itself with a NUL (ASCII 0) character between, in ...
5
votes
Divisor of a string
C# (Visual C# Interactive Compiler), 68, 58 bytes
Iterate and replace every substring starting from index 0 and check if it equals an empty string
Credit to @Acer for the syntatic sugar
...
11
votes
Divisor of a string
Python, 53 bytes
lambda s,t="":[t for c in s if~-any(s.split(t:=t+c))]
Attempt This Online!
4
votes
Divisor of a string
Python 3.8, 56 bytes
-7 bytes thanks to user loopy walt
lambda s,d='':[d for c in s if len(s)//len(d:=d+c)*d==s]
Attempt This ...
5
votes
Divisor of a string
K (ngn/k), 19 bytes
{(x{#,/y\x}/:)_,\x}
Try it online!
,\x get all prefixes of the input
...
3
votes
3
votes
3
votes
Divisor of a string
Retina 0.8.2, 17 bytes
&!`(.+)$(?<=^\1+)
Try it online! Link includes test cases. Explanation:
&!`
List all ...
7
votes
Divisor of a string
05AB1E, 6 5 bytes
ηʒKõQ
Try it online or verify all test cases.
Explanation:
...
5
votes
Divisor of a string
Ruby, 53 52 bytes
->s{(1..k=s.size).map{|x|w=s[0,x];w*k==s*x ?w:s}|[]}
Try it online!
6
votes
Divisor of a string
K (ngn/k), 26 bytes
{((#(,x)^,\(#x)#,:)')_,\x}
Try it online!
I guess this is somewhat a new strategy. For each prefix, tests if the original input appears in the ...
6
votes
Divisor of a string
J, 19 bytes
<\#~<=<\$~&.>#+#\|#
Try it online!
<\$~ Cyclically extend each prefix to the following length:
...
4
votes
6
votes
Divisor of a string
Haskell, 42 bytes
f s|p<-scanr(:)""s=[t|t<-p,a<-p,(a*>t)==s]
Try it online!
scanr(:)""s lists ...
7
votes
Divisor of a string
Factor + grouping.extras, 73 70 57 48 bytes
[ dup head-clump [ ""replace ""= ] with filter ]
Attempt This ...
5
votes
Divisor of a string
Python, 65 63 bytes
lambda s:[s[:i]for i in range(1,len(s)+1)if len(s)//i*s[:i]==s]
Attempt This Online!
A very unclever solution.
Saved -2 bytes from @ruancornelli.
4
votes
Divisor of a string
Haskell, 65 bytes
d s|r<-[1..length s]=[z|z<-(`take`s)<$>r,s`elem`[[1..n]>>z|n<-r]]
Try it online!
Top 50 recent answers are included
Related Tags
string × 2119code-golf × 1989
ascii-art × 207
decision-problem × 130
kolmogorov-complexity × 125
parsing × 111
number × 96
code-challenge × 65
random × 60
natural-language × 58
math × 55
balanced-string × 55
array × 47
restricted-source × 45
grid × 44
subsequence × 40
arithmetic × 37
sorting × 36
sequence × 35
source-layout × 35
alphabet × 35
permutations × 34
date × 32
counting × 31
palindrome × 28