New answers tagged code-golf
0
votes
Golf you a quine for great good!
AutoHotkey (v2), 59 bytes
Looks like the first AHK answer!
MsgBox Format(s:="MsgBox Format(s:={:c}{}{1:c},34,s)",34,s)
1
vote
Interval Placement
Retina 0.8.2, 50 bytes
\d+
$*
(1+),\1
^(.)(1+)(.),(.1\2|(\1|\[)\2(\3|]))
Try it online! Link includes test cases. Explanation:
...
0
votes
Longest bitonic subarray
Jelly, 19 18 bytes
IṠo@\IŻ=2ÄkµÐƤẈÞṪḢ
Try it online!
-1 by remembering that by the time I need to bandaid the sort order I'm just in truthiness land
Probably loses ...
0
votes
Cell`s Life #1: Simulate a plant cell
AutoHotkey (v2), input from stdin, output to stdout, 265 bytes
Since it should be a cat ...
0
votes
The struggling college student's GPA Calculator
JavaScript (Node.js), 70 bytes
f=([c,d,...s],a=b=0)=>c?f(s,a+(b-=d,'0x'+c-14.5|0)*d):(a/b).toFixed(2)
Try it online!
From Arnauld's but ...
3
votes
Longest bitonic subarray
JavaScript (Node.js), 92 bytes
x=>(g=i=>(e=x.slice(i,n+i||1/0)).some(t=u=c=>t?u>(u=c)&&++t:u<(u=c))?g(n+i?i+1:!--n):e)(n=0)
Try it online!
3
votes
0
votes
Output the nth rational number according to the Stern-Brocot sequence
Desmos, 212 bytes
Try it online! (link 1) Try it online! (link 2) (just please note that due to Desmos' max recursion limit, you'll have to wait quite some time just to get the function to even load ...
1
vote
Decode the constant/variable
C (gcc), 45 bytes
f(char*x){*x=*x-48|x[1]%46<1?*x-46?*x:36:45;}
Try it online!
0
votes
0
votes
Implement division
Perl 5 -pl, 26 + 2 = 28 bytes
/ /;$_=1x$_;$_=()=/.{$'}/g
Try it online!
Implements unary division.
0
votes
Implement division
wow, there's a lot of python answers on here. julia's pretty similar, I wonder if it wins?
Julia, 38 bytes vs @gnibbler, 73
a\b=floor(Int,1e-5+exp(log(a)-log(b)))
...
0
votes
0
votes
How much code would a codegolf golf if a codegolf could golf code?
Raku (Perl 6) (rakudo), 74 bytes
my ($a,$b)=@*ARGS;say "How much $a would a $a$b $b if a $a$b could $b $a?"
0
votes
Find all unique quintuplets in an array that sum to a given target
APL, 63 chars
{⍺{⍵/⍨(⍺∘=+/∧5∘=∘≢)¨⍵}{0=≢⍵:1⍴⊂⍬⋄⊃,/(⊃⍵){(⊂⍵),⊂⍵,1⍴⍺}¨(∇1↓⍵)}⍵}
Takes the target on the left and the list of numbers on the right.
Explanation, ...
0
votes
What's the day today (or other dates)?
ARM64 (AArch64), 435 without comments
For comedic effect, fun & profit, here is an arm64 assembly language implementation.
This relies on the kefalonian constant ...
2
votes
Longest bitonic subarray
Charcoal, 50 bytes
≔⟦⟧θFA«⊞θιW№⭆EΦθμ⁻λ§θμ⎇λ‹λ⁰ω10≔Φθμθ¿›LθLυ≔⮌⮌θυ»⭆¹υ
Try it online! Link is to verbose version of code. Explanation:
...
0
votes
Catalan Numbers
Raku (Perl 6) (rakudo), 63 bytes
my $n=@*ARGS[0];say ([*] 1..(2*$n))/([*] 1..($n+1))/([*] 1..$n)
AWK, 67 bytes
...
1
vote
Longest bitonic subarray
JavaScript (ES6), 101 bytes
a=>(g=n=>a.some((m,i)=>!(b=a.slice(i,i+n)).some(p=v=>(m=p<m?m:p)>p&p<(p=v)))/b[--n]?b:g(n))(a.length)
Try it ...
0
votes
0
votes
0
votes
Additive Persistence
Raku (Perl 6) (rakudo), 62 bytes
my ($n,$i)=@*ARGS[0],0;while $n>9 {$i++;$n=[+] $n.comb};say $i
AWK, 63 bytes
...
4
votes
Longest bitonic subarray
Python 2, 87 bytes
def f(a,*p):i=iter(map(cmp,a[1:],a));return a*((-1in i)>(1in i))or f(*p+(a[:-1],a[1:]))
Try it online!
Notice that this answer is in Python ...
1
vote
Write a program that prints a program that's almost quine
AutoHotkey (v2), 70 bytes
a:=(r:=(n)=>n?"a" r(n-1):"")(A_Args[1])
MsgBox a ":=0,MsgBox('" a "')"
Output when arg is <...
1
vote
Digits in their lanes
Zsh, 50 bytes
for i;{for j (\- {0..9})printf ${j/[^$i]/\ };echo}
Try it online!
4
votes
Find a fraction's parent in the Stern-Brocot tree
Wolfram Language (Mathematica), 48 bytes
(r=ResourceFunction@"SternBrocot")@Floor[r@#/2]&
... yeah, there's a builtin (Mathematica has to load the ...
0
votes
Write the shortest self-identifying program (a quine variant)
AutoHotkey (v2), input as arguments, output to MsgBox, 91 93 87 bytes
Case insensitive comparison. It's OK since function & var names and strings are all case ...
4
votes
Longest bitonic subarray
05AB1E, 15 bytes
ŒRéR.ΔÔ¬š¥dÔJR!
(Don't) try it online (it's too slow to even handle the example test case).
Verify all test cases with a small addition of ...
3
votes
0
votes
Tips for golfing in Python
Use slicing when try to return single element list with-in and & or
We all known that following two statements are the same. ...
2
votes
2
votes
Find a fraction's parent in the Stern-Brocot tree
Charcoal, 52 49 bytes
≔E²NθW¬№υθ≔⊞OEυ⟦§κ¹⁻Σκ⊗﹪§κ⁰§κ¹⟧E²¦¹υI§υ±⍘Φ⍘Lυ²⊖κ²
Try it online! Link is to verbose version of code. Explanation: Works by generating the ...
0
votes
10 PRINT CHR$(205.5+RND(1)); : GOTO 10 in PHP (or anything else, for that matter)
Perl 5, 28 bytes
1while print.5>rand?'/':'\\'
Try it online!
11
votes
Find a fraction's parent in the Stern-Brocot tree
JavaScript (ES11), 48 bytes
-2 thanks to @Shaggy
Expects (n,d) as BigInts and returns [n',d'].
...
0
votes
What's the day today (or other dates)?
python2 -- 98 bytes
This improves upon the existing python3 answer:
...
0
votes
Find all unique quintuplets in an array that sum to a given target
R, 52 bytes
\(x,n)unique(t(combn(x,5,sort)[,combn(x,5,sum)==n]))
Attempt This Online!
Returns quintuplets as rows of a matrix.
0
votes
0
votes
"Graphing" calculator
Raku (Perl 6) (rakudo), 45 bytes
my ($m,$c,$p)=@*ARGS;for 1..$p {say $m*$_+$c}
Attempt This Online!
2
votes
0
votes
Shortest code to produce infinite output
Raku (Perl 6) (rakudo), 14 bytes
.say for 1 xx*
Attempt This Online!
0
votes
Fibonacci function or sequence
Hatchback, 57 45 32 bytes
0 0 1 2 1 0 17 0 1 1 0 0 65281 0
since Hatchback has an integer limit of 0xFFFF, it stops at 9227465 and errors out.
it doesnt need ...
0
votes
Implement a Truth-Machine
Hatchback, 32 bytes
0 0 0 16 0 1 0 6 0 65281 1 65535
asks for input, prints, checks if its 1 and if it is continue printing.
0
votes
Fibonacci function or sequence
Raku (Perl 6) (rakudo), 22 bytes
.say for (1,1,*+*...*)
Attempt This Online!
0
votes
0
votes
Output your Score!
Raku (Perl 6) (rakudo), 16 bytes
say 8+8~' bytes'
Attempt This Online!
Not too exciting, still new to Raku.
1
vote
Output your Score!
x86 16-bit machine code + DOS, 23 bytes
Hexdump:
b4 09 20 42 59 54 45 53 24 00 81 36 00 01 86 3a
ba 00 01 cd 21 cd 20
Doesn't contain the characters ...
1
vote
Find all unique quintuplets in an array that sum to a given target
05AB1E, 8 bytes
{5.ÆÙʒOQ
Inputs in the order \$array,target\$. Outputs [] if there is no valid result.
Try it online or verify ...
1
vote
Find all unique quintuplets in an array that sum to a given target
JavaScript (V8), 91 bytes
f=([v,...a],n,o=q=[])=>o[4]?n||q[o.sort()]||print(q[o]=o):v+1&&f(a,n-v,[...o,[v]])|f(a,n,o)
Try it online!
Commented
...
4
votes
Find all unique quintuplets in an array that sum to a given target
Python 3, 95 bytes
f=lambda t,a,*p:[p][t*t:len(p)==5]or{i for v in[*a]for i in f(t-a.pop(0),[*a],*sorted([*p,v]))}
Try it online!
Input target value and the array ...
1
vote
Golf you a quine for great good!
Hatchback, 97 85 71 bytes
0
0
255
0
1
1
0
3
65534
2
3
1
11
2
0
1
2
2
0
1
14
2
3
6
2
65281
8
65535
This is half-cheating(?) as it's technically not reading the ...
Top 50 recent answers are included
Related Tags
code-golf × 12158string × 2140
math × 1658
number × 1231
ascii-art × 1176
sequence × 886
array × 784
decision-problem × 751
kolmogorov-complexity × 646
arithmetic × 509
number-theory × 438
integer × 417
geometry × 351
grid × 348
random × 330
tips × 327
combinatorics × 318
primes × 302
matrix × 283
date × 275
graphical-output × 274
parsing × 248
game × 239
binary × 226
restricted-source × 207