Skip to main content
Commonmark migration
Source Link

Forth (gforth), 45 bytes

: f 0 over 1 ?do over i mod 0= i * - loop = ; 

Try it online!

Explanation

###Explanation LoopsLoops over every number from 1 to n-1, summing all values that divide n perfectly. Returns true if sum equals n

###Code Explanation

Code Explanation

: f \ start word definition 0 over 1 \ create a value to hold the sum and setup the bounds of the loop ?do \ start a counted loop from 1 to n. (?do skips if start = end) over \ copy n to the top of the stack i mod 0= \ check if i divides n perfectly i * - \ if so, use the fact that -1 = true in forth to add i to the sum loop \ end the counted loop = \ check if the sum and n are equal ; \ end the word definition 

Forth (gforth), 45 bytes

: f 0 over 1 ?do over i mod 0= i * - loop = ; 

Try it online!

###Explanation Loops over every number from 1 to n-1, summing all values that divide n perfectly. Returns true if sum equals n

###Code Explanation

: f \ start word definition 0 over 1 \ create a value to hold the sum and setup the bounds of the loop ?do \ start a counted loop from 1 to n. (?do skips if start = end) over \ copy n to the top of the stack i mod 0= \ check if i divides n perfectly i * - \ if so, use the fact that -1 = true in forth to add i to the sum loop \ end the counted loop = \ check if the sum and n are equal ; \ end the word definition 

Forth (gforth), 45 bytes

: f 0 over 1 ?do over i mod 0= i * - loop = ; 

Try it online!

Explanation

Loops over every number from 1 to n-1, summing all values that divide n perfectly. Returns true if sum equals n

Code Explanation

: f \ start word definition 0 over 1 \ create a value to hold the sum and setup the bounds of the loop ?do \ start a counted loop from 1 to n. (?do skips if start = end) over \ copy n to the top of the stack i mod 0= \ check if i divides n perfectly i * - \ if so, use the fact that -1 = true in forth to add i to the sum loop \ end the counted loop = \ check if the sum and n are equal ; \ end the word definition 
deleted 3 characters in body
Source Link
reffu
  • 2k
  • 11
  • 11

Forth (gforth), 45 bytes

: f 0 over 1 ?do over i mod 0= i * - loop = ; 

Try it online!

###Explanation Loops over every number from 1 to n-1, summing all values that divide n perfectly. Returns true if sum equals n

###Code Explanation

: f \ start word definition 0 over 1 \ create a value to hold the sum and setup up the bounds of the loop ?do \ start a counted loop from 1 to n. (?do skips if start = end) over \ copy n to the top of the stack i mod 0= \ check if i divides n perfectly i * - \ if so, use the fact that -1 = true in forth to add i to the sum loop \ end the counted loop = \ check if the sum and n are equal ; \ end the word definition 

Forth (gforth), 45 bytes

: f 0 over 1 ?do over i mod 0= i * - loop = ; 

Try it online!

###Explanation Loops over every number from 1 to n-1, summing all values that divide n perfectly. Returns true if sum equals n

###Code Explanation

: f \ start word definition 0 over 1 \ create a value to hold the sum and setup up the bounds of the loop ?do \ start a counted loop from 1 to n. (?do skips if start = end) over \ copy n to the top of the stack i mod 0= \ check if i divides n perfectly i * - \ if so, use the fact that -1 = true in forth to add i to the sum loop \ end the counted loop = \ check if the sum and n are equal ; \ end the word definition 

Forth (gforth), 45 bytes

: f 0 over 1 ?do over i mod 0= i * - loop = ; 

Try it online!

###Explanation Loops over every number from 1 to n-1, summing all values that divide n perfectly. Returns true if sum equals n

###Code Explanation

: f \ start word definition 0 over 1 \ create a value to hold the sum and setup the bounds of the loop ?do \ start a counted loop from 1 to n. (?do skips if start = end) over \ copy n to the top of the stack i mod 0= \ check if i divides n perfectly i * - \ if so, use the fact that -1 = true in forth to add i to the sum loop \ end the counted loop = \ check if the sum and n are equal ; \ end the word definition 
Source Link
reffu
  • 2k
  • 11
  • 11

Forth (gforth), 45 bytes

: f 0 over 1 ?do over i mod 0= i * - loop = ; 

Try it online!

###Explanation Loops over every number from 1 to n-1, summing all values that divide n perfectly. Returns true if sum equals n

###Code Explanation

: f \ start word definition 0 over 1 \ create a value to hold the sum and setup up the bounds of the loop ?do \ start a counted loop from 1 to n. (?do skips if start = end) over \ copy n to the top of the stack i mod 0= \ check if i divides n perfectly i * - \ if so, use the fact that -1 = true in forth to add i to the sum loop \ end the counted loop = \ check if the sum and n are equal ; \ end the word definition