The Stack Overflow podcast is back! Listen to an interview with our new CEO.

New answers tagged

0

Zsh, 37 bytes a=("${(@Q)${(z)1}}") <<<$a[1]' '$a[2] Try it online! (z) splits a string according to shell grammar (Q) removes quotes (@) prevents array joining in quotes " " are needed to preserve empty elements Finally we print the first two strings with a quoted newline between them.


0

Brainfuck, 538 221 byte ++++++++++[z>?+++++++>?++++++++++>?+++>?+<z<z<z<z-]\>?+++++./-=-=./+++././<z++++++++++++++++++++++++++++++++./>?-=-=-=-=-=-=-=-=-=-=-=./+++++++++++./-=-=-=./-=-=-=-=./+++++++++./+++++./<z./>?-=-=-=-=-=./+./++++++++./<z+./ Try it online! I hope it is correct...


0

Befunge-98 (PyFunge), 92 bytes 1290/zx:"())_QWCV*(P[CVNM QRTUI*(RTRT QAS:"cv' 1290/zx#$J:"12-=!@!@j!@780-m,45hjvbvbvbvbvb<> 19/ (the Shiftkey that results from this can be ignored since shift by itself does nothing) zRight ShiftDown Arrow (to deselect anything that may have been selected by Shift and its implicit Up Arrow);90qc8pcnTabru8rrTaba;(...


2

Haskell, 21 bytes last.(("",""):).reads Try it online! The inverse is g(a,b)=show a++b This puts the first string in quotes, escaping any characters as needed, and appends the second string. This is undone by reads, which looks for a prefix that's a string representation of the correct type (here, string), reads it, and puts it in a pair with the ...


4

Python 2, 42 bytes lambda s:(s.split("1"+len(s)/2*"0")*2)[:2] Try it online! The inverse is: def F(a,b): return a+"1"+len(a+b)*"0"+b A tempting idea for the inverse is to encode the pair of input strings by putting some separator string in between them. That way, we can extract the pair by splitting on this separator. The issue is that the separator ...


2

Ruby, 81 bytes ->s{s.match(/^(\d+)\.(.*)/m){|m|l=m[1].to_i;[m[2][0,l],m[2][l..-1]||'']}||['',s]} Try it online! I don't golf much in Ruby so this can surely be shortened -- tips appreciated. Idea is to to provide a meta-prefix <number>.rest of string which will split "rest of string" at number. Strings without the meta-prefix just return ["", &...


3

Python 2, 53 52 bytes lambda s:(s.split('_x'+s.count('x')/2*'x')+[''])[:2] Try it online!


1

K (ngn/k), 56 bytes {(1+;x;a)@'*<(*&~^5 6 9?4/+0N 3#)'i@[x;;:;]'a:1&3!i:!#x} Try it online! encodes "TAGC" as 0 1 2 3 respectively returns 1 1 0 on error important observation: there's no point trying to replace a nucleotide with anything other than T (when first in the codon) or A (when second or third) { } function with argument x i:!#x ...


2

Retina 0.8.2, 33 bytes ^(("[^"]*")*),? $1¶ %`^"|"("?) $1 Try it online! Link includes test cases. Takes as input the output from my Charcoal answer to @negativeseven's question and outputs the two strings on separate lines. Explanation: ^(("[^"]*")*),? $1¶ My Charcoal answer always outputs a number of quote-surrounded strings followed by a comma. Find ...


0

Brachylog, 0 bytes Input as an array of 2 strings, output in the format: Z = ["{{string 1 stringified}}","{{string 2 stringified}}"] Inspired by Arnauld's JSON.stringify answer and Doorknob's empty jq answer Try it online!


0

Poetic - 735 bytes alphabet:a-z words i say,i spell i say a letter of ABCs i do know A,i sorta do then it begins to turn fuzzy or vague-it was never clear is the after-A letter B the thing after B?gosh,i am stupid i say C D after C?yes,i nailed it i keep a tally if i try,i am great i say a letter,all in order of a song i heard it,how a letter is in there:A,...


1

Poetic, 244 bytes life is a quest,i say i choose a fun course to cross i cant say quite if survival excites i say i am laughing i create a way i relive a feeling exile is torture,i say i am thankful,of course,to say i adore u i desire a wedding where i said i do Try it online! Poetic is an esolang I made in 2018 for a class project. It's basically ...


0

Python 3, 86 bytes from random import* f=lambda x,*y:[randrange(2)*32*(64<x&~32<91)^x]+(f(*y)if y else[]) Try it online! Takes input as one character per argument, as integers. Returns string as a list of integers by codepoint values.


0

Python 3, 114 bytes from random import * for i in input(): if randint(1,2) == 1: print(i.upper(), end="") else: print(i, end="") Try it online!


0

JavaScript, 67 bytes here a short Javascript alternative, if entered in the console it it returns the output. With my favorit replace function. 'ZABCDEFGHIJKLMNOPQRSTUVWXY'.repeat(27).replace(/.(.{26})/g,"$1\n")


-1

Python 3, 59 bytes i=input() while i:print(end={i,i.upper()}.pop()[0]);i=i[1:] Try it online! Uses set.pop() to randomize. Note that this will only be random when used in a full program. Learn more. The code can be reduced to a 47-byte function, but then it is only randomized once per input per session. f=lambda i:i and{i,i.upper()}.pop()[0]+f(i[1:]) ...


1

Poetic, 510 bytes THE BOOGEYMAN WAS HERE,i read a story i saw,a story i saw it reads:WE SAW IN STARS AN END TO EARTH i saw magic spells,oracles of chaos i also saw hexes o,i know a curse is a legend/a lie i think i know a curse i saw a curse is hogwash now i browse a book o,i laugh it is trash o,i giggle in a bang,i heard a POW a flash,a puff o flames IT IS ...


1

APL (Dyalog Unicode), 28 bytes 28 bytes (https://github.com/abrudz/SBCS/) 50 bytes (UTF-8) {1(819⌶)@(?n⍴⍨?n←≢⍸~⍵∊⎕A)⊢⍵} Inspired by Graham's APL+Win solution Try it online!


1

Forth (gforth), 55 bytes : f 26. do 26. do i j + 26 mod 65 + emit loop cr loop ; Try it online! Just for completeness. Tried several tricks (using one loop instead of 2, creating a string before printing) but they didn't save bytes. You can find such attempts in the TIO link above. How it works : f ( -- ) 26. do \ A golfy way to loop from 0 to 25 ...


1

Backhand, 5 bytes i}o: Try it online! (note the trailing space) This should be the optimal answer, since all of io: are needed, 4 bytes needs at two movement modifiers to avoid getting stuck in two instruction loops, and no three byte permutation works. Explanation: i Input : Dupe o Output } Move back to output o Output ...


2

Forth (gforth), 39 bytes : f bounds ?do i 1 type i 1 type loop ; Try it online! Beats NieDzejkob's submission by one byte. If we don't care empty strings, we can safely remove the ? in ?do, making it 38 bytes. A function that takes a string in the standard representation (addr, length), and prints the result to the console. How it works gforth ...


3

Poetic, 46 bytes whenever i imagine feeling grief i actually do Try it online! Poetic is an esolang I created in 2018 for a class project. It's basically brainfuck with word-lengths instead of symbols. The point of the language is to allow for programs to be written in free-verse poetry. I encourage you all to try it out sometime!


0

Gol><>, 21 bytes TiE!tlF`(}}|~l2,R`)rH Try it online! 24 bytes TiE!trlF}8ss}|r~l2,R`)rH It's hideous, I know. I am going to golf this profusely. Try it online!


1

PowerShell, 60 46 43 bytes -3 bytes thanks to mazzy -join($args|%{"$_"|%('t*g','*per'|random)}) Try it online!


0

Python 3, 94 bytes s=input();from random import*;print("".join([i.upper() if randint(0,1)==1 else i for i in s])) Try it online!


0

Charcoal, 8 bytes ⭆S‽⁺↥ι↧ι Try it online! Link is to verbose version of code. Trivial modification of my answer to Random Capitalization.


1

Python 2, 72 bytes lambda i:"".join(choice(x)for x in zip(i,i.upper())) from random import* Try it online!


2

Brainf***, 696 624 397 Bytes >>>>>>,,,++>>>+[-<<,<<+<<+<<+>,>>,>>>[>+<<<<<<<<+>>>>>>>-]>[-<+>]<<<<<<<<-[-[-[->->-[-[-[->->[-]>->+++>>>+<<<<<]>[->-[-[[-]>->+...


0

C (gcc), 109 46 bytes Thanks to Johan du Toit for -63 bytes f(char*s){for(;*s++-=(*s-97u<26&rand())*32;);} Try it online!


0

C (gcc), 97 84 bytes Thanks to ceilingcat for -13 bytes f(char*b){printf(*++b?"%c(":"%c",*b);*b&&f(b)+printf(")");}a[99];main(){f(gets(a));} Try it online!


1

Japt -m, 4 bytes +u)ö Try it -m //Map all characters in input + //Input prepended to u) //Input to uppercase ö //Random character


0

C# (Visual C# Interactive Compiler), 59 bytes x=>x.Select(l=>z.Next()<1?l.ToUpper():l);var z=new Random() Try it online!


2

Ŕṭn̄ 0.8.2, 71 byt̖s T`aei\ou`̄́̇̌̑ T`̄́̇̌̑`̠̖̣̭̮`[bdfhklt]*. +`([^a-z])([̠̖̣̭̮̄́̇̌̑]) $1o$2 Try ȯt ǒnḷń! Óxpl̠n̄ṭǒn T`aei\ou`̄́̇̌̑ ŕpl̠ćs th̖ ch̠r̄ct̖rs aeiou ẇth th̖ črŕsp̌nṡng ḍōcṙṭcs ōb̭v́. T`̄́̇̌̑`̠̖̣̭̮`[bdfhklt]+. ŕpl̠ćs th̖ ḍōcṙṭcs ōb̭v́ ẇth ḍōcṙṭcs b̖ḽw ȯf pŕćd̖d by ǒń ǒr śv́r̄l ch̠r̄ct̖rs ẇth ...


2

PowerShell, 107 98 82 77 bytes $l=@{} $args|%{if($_-10){$l.$_+=$x++,+$y}else{$x=0;++$y}} $l|% v*|? c*t -eq 2 Try it online! Takes a splatted string with LFs. Returns zero-indexed location x,y. Unrolled: $locations=@{} # make a hashtable. key=char, value=location array $args|%{ if($_-10){ # if current char is ...


1

Japt -m, 5 4 bytes +u)ö Try it


3

K (oK), 91 bytes {,/(1+t),(x@t:(&u)+3*-3!p),(u:r@p)#'t@3!p:*&1=+/'r:0N 3#,//~(t:3 3#"TAATAGTGA")=\:/:0N 3#x} Try it online! I'm sure my solution can be significally golfed (I used too many named varialbes)


0

Zsh, 54 bytes eval {autoload,}' is-at-least $'{1\ $2,2\ $1}';<<<$?;' Try it online! Try a test suite! This evals to the following eight statements: autoload is-at-least $1 $2 # loads the "is-at-least" function <<<$? # success, prints 0 autoload is-at-least $2 $1 # redundant <<<$? ...


4

Python 3, 88 bytes f=lambda i,j,k,*l,n=1:(j+k<4)*(n,i,5)+(i-k>2)*(n+1,j,1)or(i-j>2)*(n+2,k,1)or f(*l,n=n+3) Try it online! Solution without regex. Uses 1235 for AGCT, respectively. Takes each base as a separate argument. Will suggest A for any instance of T*A, T*G, TA*, TG*. Outputs as (position, original base, new base). Returns an (invalid) 6-...


0

PowerShell, 124 bytes inspired by Avi's answer for Java. $args-replace(($b='(?<=^|[?.!] )')+($q='\[\?]')+($v='(?= [aeiou])')),'An'-replace"$q$v",'an'-replace"$b$q",'A'-replace$q,'a' Try it online!


2

K (oK), 32 bytes {,/{`c$x-32*1?2*(x<123)*x>96}'x} Try it online!


0

Perl 5, 22 bytes s/./.5<rand?uc$&:$&/ge Try it online!


0

PHP, 51 bytes for(;$l=$argn[$i++];)echo$l>_&&rand(0,1)?$l^' ':$l; Try it online! PHP, 51 bytes for(;$l=$argn[$i++];)echo rand(0,1)?ucfirst($l):$l; Try it online!


1

Japt -m, 5 bytes c^HÑö Try it


2

Wolfram Language (Mathematica), score 31 + 2 = 33 & ) # @ / ] & 2 # > - " " . / # [ d l o F ( @ e ...


3

APL (Dyalog Extended), 6 bytesSBCS Anonymous tacit prefix function. Assumes ⎕IO←0 (0-based indexing) ⊢×∘?2¨ Try it online! 2¨ number two for each character ? random index among the first that many indices (i.e. 0 or 1 for each character) ∘ then × use that to change case (0:lower; 1:upper) on the following: ⊢ the unmodified argument


0

Jelly, 5 bytes żŒuX€ Try it online! Stolen from totallyhuman's solution to Random Capitalization. My original solution, since I forgot Jelly has ż: Jelly, 6 bytes Œu,X¥" Try it online! ,ŒuXƊ€ works for the same byte count. " For every element of the input and every corresponding element of Œu the input capitalized, ,X¥ choose ...


4

Python 3, 59 bytes i=input() while i:print(end={i,i.upper()}.pop()[0]);i=i[1:] Try it online! -4 bytes thanks to Chas Brown Uses set.pop() to randomize.


1

Red, 80 78 58 bytes func[s][foreach c s[prin do pick[c[uppercase c]]random 2]] Try it online!


3

C# (Visual C# Interactive Compiler), 138 bytes x=>{for(int i=0;;i++)foreach(var k in"AGT")if("TAG TAA TGA".Contains(x.Remove(i,1).Insert(i,k+"").Substring(i-i%3,3)))return(i+1,x[i],k);} Try it online!


3

Python 2, 138 133 144 142 bytes f=lambda s,i=0:next((`i-~j`+s[j]+'TAA'[j]for j in[0,1,2]if re.match('.TTA.[[[AAAGGG]]].'[j::3]+'|.GA',s[:3])),s[6:]and f(s[3:],i+3)) import re Try it online! Returns nXY instead of nX>Y, or the empty string if there is no valid substitution.


Top 50 recent answers are included