Skip to main content
We’ve updated our Terms of Service. A new AI Addendum clarifies how Stack Overflow utilizes AI interactions.
Code Golf

Return to Answer

Commonmark migration
Source Link

Shnap, (削除) 44 (削除ここまで) 43 bytes

-1 bye thanks to Mr. Xcoder (lol I was outgolfed in my own language)

 $n return:{s=0for d:range(n+1)if n%d<1s+=d}

This is a function ($ starts a function in Shnap).

Try it online!

Explanation:

$ n //Start function with parameter n
 return: { //Technically, we are returning a scope-block, which evaluates to the last statement run
 s = 0 //Our result
 for d : range(n+1) //For each value in the iterator range(n+1)
 if n % d < 1 // If n is divisible by d
 s += d // Add d to the sum
 // Since (s += d) returns (s + d), and a scope-block returns the last run statement, this will be the last statement and equal to our result
 }

Noncompeting, 19 bytes

#Noncompeting, 19 bytes AfterAfter many language updates, this can now be reduced to a measly 19 bytes:

$n=>sum(factors(n))

Try it online!

Shnap, (削除) 44 (削除ここまで) 43 bytes

-1 bye thanks to Mr. Xcoder (lol I was outgolfed in my own language)

 $n return:{s=0for d:range(n+1)if n%d<1s+=d}

This is a function ($ starts a function in Shnap).

Try it online!

Explanation:

$ n //Start function with parameter n
 return: { //Technically, we are returning a scope-block, which evaluates to the last statement run
 s = 0 //Our result
 for d : range(n+1) //For each value in the iterator range(n+1)
 if n % d < 1 // If n is divisible by d
 s += d // Add d to the sum
 // Since (s += d) returns (s + d), and a scope-block returns the last run statement, this will be the last statement and equal to our result
 }

#Noncompeting, 19 bytes After many language updates, this can now be reduced to a measly 19 bytes:

$n=>sum(factors(n))

Try it online!

Shnap, (削除) 44 (削除ここまで) 43 bytes

-1 bye thanks to Mr. Xcoder (lol I was outgolfed in my own language)

 $n return:{s=0for d:range(n+1)if n%d<1s+=d}

This is a function ($ starts a function in Shnap).

Try it online!

Explanation:

$ n //Start function with parameter n
 return: { //Technically, we are returning a scope-block, which evaluates to the last statement run
 s = 0 //Our result
 for d : range(n+1) //For each value in the iterator range(n+1)
 if n % d < 1 // If n is divisible by d
 s += d // Add d to the sum
 // Since (s += d) returns (s + d), and a scope-block returns the last run statement, this will be the last statement and equal to our result
 }

Noncompeting, 19 bytes

After many language updates, this can now be reduced to a measly 19 bytes:

$n=>sum(factors(n))

Try it online!

added 306 characters in body
Source Link
Socratic Phoenix
  • 1.7k
  • 1
  • 11
  • 26

Shnap, (削除) 44 (削除ここまで) 43 bytes

-1 bye thanks to Mr. Xcoder (lol I was outgolfed in my own language)

 $n return:{s=0for d:range(n+1)if n%d<1s+=d}

This is a function ($ starts a function in Shnap).

Try it online!

Explanation:

$ n //Start function with parameter n
 return: { //Technically, we are returning a scope-block, which evaluates to the last statement run
 s = 0 //Our result
 for d : range(n+1) //For each value in the iterator range(n+1)
 if n % d < 1 // If n is divisible by d
 s += d // Add d to the sum
 // Since (s += d) returns (s + d), and a scope-block returns the last run statement, this will be the last statement and equal to our result
 }

#Noncompeting, 19 bytes After many language updates, this can now be reduced to a measly 19 bytes:

$n=>sum(factors(n))

Try it online!

Shnap, (削除) 44 (削除ここまで) 43 bytes

-1 bye thanks to Mr. Xcoder (lol I was outgolfed in my own language)

 $n return:{s=0for d:range(n+1)if n%d<1s+=d}

This is a function ($ starts a function in Shnap).

Try it online!

Explanation:

$ n //Start function with parameter n
 return: { //Technically, we are returning a scope-block, which evaluates to the last statement run
 s = 0 //Our result
 for d : range(n+1) //For each value in the iterator range(n+1)
 if n % d < 1 // If n is divisible by d
 s += d // Add d to the sum
 // Since (s += d) returns (s + d), and a scope-block returns the last run statement, this will be the last statement and equal to our result
 }

Shnap, (削除) 44 (削除ここまで) 43 bytes

-1 bye thanks to Mr. Xcoder (lol I was outgolfed in my own language)

 $n return:{s=0for d:range(n+1)if n%d<1s+=d}

This is a function ($ starts a function in Shnap).

Try it online!

Explanation:

$ n //Start function with parameter n
 return: { //Technically, we are returning a scope-block, which evaluates to the last statement run
 s = 0 //Our result
 for d : range(n+1) //For each value in the iterator range(n+1)
 if n % d < 1 // If n is divisible by d
 s += d // Add d to the sum
 // Since (s += d) returns (s + d), and a scope-block returns the last run statement, this will be the last statement and equal to our result
 }

#Noncompeting, 19 bytes After many language updates, this can now be reduced to a measly 19 bytes:

$n=>sum(factors(n))

Try it online!

added 76 characters in body
Source Link
Socratic Phoenix
  • 1.7k
  • 1
  • 11
  • 26

Shnap, 44(削除) 44 (削除ここまで) 43 bytes

-1 bye thanks to Mr. Xcoder (lol I was outgolfed in my own language)

$n return:{s=0for d:range(n+1)if n%d==0s+=dn%d<1s+=d}

This is a function ($ starts a function in Shnap).

Try it online! Try it online!

Explanation:

$ n //Start function with parameter n
 return: { //Technically, we are returning a scope-block, which evaluates to the last statement run
 s = 0 //Our result
 for d : range(n+1) //For each value in the iterator range(n+1)
 if n % d ==< 01 // If n is divisible by d
 s += d // Add d to the sum
 // Since (s += d) returns (s + d), and a scope-block returns the last run statement, this will be the last statement and equal to our result
 }

Shnap, 44 bytes

$n return:{s=0for d:range(n+1)if n%d==0s+=d}

This is a function ($ starts a function in Shnap).

Try it online!

Explanation:

$ n //Start function with parameter n
 return: { //Technically, we are returning a scope-block, which evaluates to the last statement run
 s = 0 //Our result
 for d : range(n+1) //For each value in the iterator range(n+1)
 if n % d == 0 // If n is divisible by d
 s += d // Add d to the sum
 // Since (s += d) returns (s + d), and a scope-block returns the last run statement, this will be the last statement and equal to our result
 }

Shnap, (削除) 44 (削除ここまで) 43 bytes

-1 bye thanks to Mr. Xcoder (lol I was outgolfed in my own language)

$n return:{s=0for d:range(n+1)if n%d<1s+=d}

This is a function ($ starts a function in Shnap).

Try it online!

Explanation:

$ n //Start function with parameter n
 return: { //Technically, we are returning a scope-block, which evaluates to the last statement run
 s = 0 //Our result
 for d : range(n+1) //For each value in the iterator range(n+1)
 if n % d < 1 // If n is divisible by d
 s += d // Add d to the sum
 // Since (s += d) returns (s + d), and a scope-block returns the last run statement, this will be the last statement and equal to our result
 }
deleted 54 characters in body
Source Link
Socratic Phoenix
  • 1.7k
  • 1
  • 11
  • 26
Loading
Source Link
Socratic Phoenix
  • 1.7k
  • 1
  • 11
  • 26
Loading

AltStyle によって変換されたページ (->オリジナル) /