Search Results
Search type | Search syntax |
---|---|
Tags | [tag] |
Exact | "words here" |
Author |
user:1234 user:me (yours) |
Score |
score:3 (3+) score:0 (none) |
Answers |
answers:3 (3+) answers:0 (none) isaccepted:yes hasaccepted:no inquestion:1234 |
Views | views:250 |
Code | code:"if (foo != bar)" |
Sections |
title:apples body:"apples oranges" |
URL | url:"*.example.com" |
Saves | in:saves |
Status |
closed:yes duplicate:no migrated:no wiki:no |
Types |
is:question is:answer |
Exclude |
-[tag] -apples |
For more details on advanced search visit our help page |
Code-golf is a competition to solve a particular problem in the fewest bytes of source code.
15
votes
16
answers
1k
views
Minimum rotation to get the maximum value
I recently solved a coding challenge in one of the challenge papers that my IT teacher gave to us. It was a seemingly simple, but fun challenge, so I thought it will make fun golfing.
The task
Given a …
14
votes
7
answers
771
views
Implement Casio's M
The task
Most Casio calculators featured a variable M, which has 3 operators related to it: M, M+, and M-
M, as you can expect, returns the value stored in the variable.
M+ takes the number on the lef …
7
votes
Maximum average ord
K (ngn/k), 18 11 bytes
|/{+/x%#x}'
Try it online!
Massive -7 bytes golf thanks to Steffan!
Damn everyone is answering quick. Anyways here's my solution. Takes input as a list of strings.
Explanation: …
4
votes
Are All the Items the Same?
K (ngn/k), 5 bytes
1=#?:
Try it online!
-2 bytes thanks to ngn
Returns 1 for true, 0 for false.
Checks if 1 is equal to the length of unique elements in x
4
votes
Alphabet Checksum
K (ngn/k), 16 14 bytes
`c$97+26!+/97!
Try it online!
-2 bytes thanks to coltim!
Explanation:
`c$97+26!+/97! Main function. Takes implicit input
97! Modulo by 97 to each character in the …
4
votes
Shifted auto-sum
K (ngn/k), 17 14 bytes
{x*10/(#$x)#1}
Try it online!
-3 bytes thanks to ovs!
Explanations:
{x*10/(#$x)#1} Main function. x is input (123)
1 The number 1 (1)
# …
4
votes
Calculate a square and a square root!
Python / PARI/GP, 60 bytes
#/*
n=int(input());print(n**2);"""*/
print(sqrt(input))\\"""
Basically a modification from the C / Python answer.
Python does square. PARI/GP does square root.
Takes input …
4
votes
Is it a pangram?
K (ngn/k), 36 19 17 bytes
{~#(97+!26)^0+_x}
Try it online!
-2 bytes thanks to ngn!
Return 1 for true, 0 for false.
Explanation:
{~#(97+!26)^0+_x} / Main program. x is input
_ …
4
votes
As Easy as One-Two-Three
K (ngn/k), 15 bytes
{($x-12)=3#*$x}
Try it online!
Port of Dennis' algorithm.
Explanation:
{($x-12)=3#*$x} Main function. Takes x as input
$x Convert x to string
* Then …
4
votes
Is this word Lexically Ordered?
K (ngn/k), 19 bytes
{t:!#x;(t~<x)|t~>x}
Try it online!
A little bit lengthy. I have considered using inline assignment, but it seems to be on the same length as this one. Returns 0 for false and 1 fo …
4
votes
Is it a pure word?
K (ngn/k), 11 10 bytes
{(#x)!+/x}
Try it online!
Saves a byte by not using the Not operator (~)
Quick and simple. Return 0 for true and any other value for false.
Explanation:
{(#x)!+/x} Main func …
3
votes
Output a random unary string
C++, 112 86 bytes
-26 bytes thanks to Unrelated String
#include<iostream>
main(){srand(time(0));for(int i=0;i<rand()%100;i++){std::cout<<1;}}
Try It Online!
3
votes
Product over a range
K (ngn/k), 11 bytes
{*/x+!y-x}
Try it online!
-1 byte thanks to PyGamer0 for telling me that I don't need ' after +
Another easy one. Exclusive at b.
Explainations:
Assuming that a is 2 and b is 5
{ …
3
votes
Separate a list into even-indexed and odd-indexed parts
K (ngn/k), 21 bytes
{t,x^t:x@&(0=2!)'!#x}
Try it online!
Down 2 bytes thanks to ngn
K (ngn/k), 23 bytes
{t:x@&(0=2!)'!#x;t,x^t}
Try it online!
The old solution is kept because of the explanations.
E …
3
votes
Determine the color of a chess square
K (ngn/k), 25 bytes
{$[2!+/x;"light";"dark"]}
Try it online!
Simple if statement.
Explanation:
{$[2!+/x;"light";"dark"]} Main function. Takes x as input
$[ ] If
+/x …