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 |
Challenges related to elementary arithmetic.
1
vote
Sum the odd square numbers less than N
Scala, 54 bytes
Golfed version. Try it online!
def f(n:Int)=(1 to n by 2).map(x=>x*x).filter(_<n).sum
57 bytes version:
def f(n:Int)=(1 to n by 2).map(x=>x*x).takeWhile(_<n).sum
0
votes
Evaluate the nth hyperoperation
Scala, 90 bytes
Port of @John Dvorak's Ruby answer in Scala.
Golfed version. Try it online!
(x,y,n)=>if(n>1){if(n>2){var c=x;for(i<-2 to y.intValue)c=f(x,c,n-1);c}else{x*y}}else{x+y}
Ungolfed versio …
1
vote
Number of ways to partition n into n = K + ꓘ
Scala 3, 53 bytes
x=>(x/2 to x).count{i=>i+i.toString.reverse.toInt==x}
Attempt This Online!
0
votes
How many steps does it take from n to 1 by subtracting the greatest divisor?
PARI/GP, 61 bytes
Try it online!
f(1)=0;
f(n)=if(n==1,0,f(n-divisors(n)[#(divisors(n))-1])+1);
3
votes
Given 4 fence lengths, what's the largest rectangular yard you can make?
Scala, 25 bytes
Saved bytes thanks to the comments of @corvus_192 and @user
Golfed version (25 bytes). Try it online!
a=>a.min*a.sorted.tail(1)
Alternative:
//scala 3
import scala.util.chaining._
de …
2
votes
Averages of Angles
Scala, 96 bytes
Modified from @Roman Czyborra's answer.
Golfed version. Try it online!
x=>(-179 to 180).minBy(a=>x.map(i=>pow((a-i%360)match{case x if x>180=>x-360;case y=>y},2)).sum)
Ungolfed versi …
0
votes
Is it a Cyclic number?
Scala 3, 85 bytes
n=>(2 to n.size).forall(i=>n.sorted==(BigInt(n)*i).toString.padTo(n.size,'0').sorted)
Attempt This Online!
0
votes
German pharmacy payment
Scala 3, 106 100 bytes
Saved 6 bytes thanks to @corvus_192
Golfed version. Attempt This Online!
x=>BigDecimal(Seq(x,5,10,x/10).sorted.apply(1)+1e-6).setScale(2,BigDecimal.RoundingMode(4)).toDouble
U …
0
votes
Sort the unique numbers in a multiplication table
Scala, 57 bytes
Golfed version. Attempt This Online!
n=>(1 to n).flatMap(i=>(1 to n).map(i*_)).distinct.sorted
Ungolfed version. Attempt This Online!
def f(n: Int): Array[Int] = {
// Construct a …
2
votes
Summing the Digits of a Number
Scala, 23 bytes
Try it online!
x=>x.map(_.asDigit).sum
1
vote
Column-wise Sum
Scala, 64 bytes
Golfed version. Try it online!
l=>{l.map(x=>x.padTo(l.map(_.size).max,0)).transpose.map(_.sum)}
Ungolfed version. Try it online!
object Main {
def columnSum(lists: List[List[Int]]) …
0
votes
Minimum Scalar Product
Scala 3, 76 bytes
(x,y)=>x.sorted(Ordering[Int].reverse).zip(y.sorted).map{case(a,b)=>a*b}.sum
Attempt This Online!
1
vote
Show me the nearest demon
Scala 3, 56 bytes
n=>{var r="";var z=n*(11/3);while(z>1){r+="6";z/=10;};r}
Attempt This Online!
2
votes
Hunt for discount
PARI/GP, 43 30 bytes
saved 13 bytes thanks to the comment.
adapted from @Basto's answer
30 bytes:
a->-[0..#a-1]%2/2*vecsort(-a)~
Try it online!
34 bytes:
a->[0..#a-1]%2/2*vecsort(-a)~*(-1)
Try it o …
1
vote
Is it a sum-free set?
Scala 3, 52 37 bytes
Saved 15 bytes using lambda function.
s=>s==s.diff(for{a<-s;b<-s}yield a+b)
Attempt This Online!