Skip to main content
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
Results tagged with
Search options answers only not deleted user 125566

Challenges related to elementary arithmetic.

1 vote

Show me the nearest demon

AWK, 47 bytes {for(x=y=6;y<$1;y=int(y 6))x=y}$0=$1-x<y-$1?x:y Try it online! {for(x=y=6; # default 6 y<$1; # till bigger demon y=int(y 6)) # append 6 x=y} …
xrs's user avatar
  • 579
1 vote

Division and remainder

AWK, 20 bytes $0=int($1/$2)FS$1%$2 Try it online! $0= # set default output int($1/$2) # truncate decimal FS # default field separator $1%$2 # mod
xrs's user avatar
  • 579
0 votes

Sum the array times n, except the last

AWK, 39 bytes {for(i=NF-1;--i;)s+=$i}$0=s*$NF+$(NF-1) Attempt This Online! {for(i=NF-1;--i;) # skip last two numbers s+=$i} # sum $0= # set output s*$NF # …
xrs's user avatar
  • 579
1 vote

Alex-style Addition

AWK, 61 bytes func f(x,y){print 9<rand()*11?f(x,y+1):x+y}{srand();f($1,$2)} Try it online! You can technically do it without srand(), but you'll basically always get the same result when you repeat i …
xrs's user avatar
  • 579
0 votes

Is this even or odd?

AWK, 5 bytes $0%=2 Attempt This Online! Prints 1 if odd.
xrs's user avatar
  • 579
1 vote

Let's decrease the monotony

AWK, 64 bytes {for(x=1;i++<NF;$i==$(i+1)&&x&&x=0)if($i<$(i+1)&&x=-1)break}$0=x Prints 1, nothing, or -1. Try it online! {for(x=1;i++<NF; # default to descending $i==$(i+1)&&x&&x=0) …
xrs's user avatar
  • 579
0 votes

1, 2, Fizz, 4, Buzz

AWK, 56 bytes {for(;i++<$1;)print i%3?i%5?i:y="Buzz":i%5?x="Fizz":x y} To test: awk '{for(;i++<$1;)print i%3?i%5?i:y="Buzz":i%5?x="Fizz":x y}' <<< 100
xrs's user avatar
  • 579