Skip to main content
Commonmark migration
Source Link

Brain-Flak, 96 bytes

((({})<>){<(([()]{})){<>(({})(<()>))<>{(({})){({}[()])<>}{}}{}<>([{}()]({})){((<{}{}>))}}{}>{}})

Try it online!

##Explanation:

Explanation:

Now outdated by improvements.

The heart of the algorithm is this:

({}(<>))<>{(({})){({}[()])<>}{}}{}<>([{}()]({})) turns |N, M...| into |N mod M, M...|
{((<{}{}>))} if the top of stack is not zero, replace it and the second with zero

That is a modification on mod that will give us M if it is a factor of N and 0 otherwise. Full code is below.

((({})<>) place input, N on both stacks
{ Loop to find factors
 <
  (([()]{})) Decrement and Duplicate; get next factor to check
  { if not zero
   (<>({})<>) Copy N from other stack
   ({}(<>))<>{(({})){({}[()])<>}{}}{}<>([{}()]({})){((<{}{}>))} Code explained above
  }
  {} drop the zero
 >
 {} add the factor
}) push the sum

Brain-Flak, 96 bytes

((({})<>){<(([()]{})){<>(({})(<()>))<>{(({})){({}[()])<>}{}}{}<>([{}()]({})){((<{}{}>))}}{}>{}})

Try it online!

##Explanation:

Now outdated by improvements.

The heart of the algorithm is this:

({}(<>))<>{(({})){({}[()])<>}{}}{}<>([{}()]({})) turns |N, M...| into |N mod M, M...|
{((<{}{}>))} if the top of stack is not zero, replace it and the second with zero

That is a modification on mod that will give us M if it is a factor of N and 0 otherwise. Full code is below.

((({})<>) place input, N on both stacks
{ Loop to find factors
 <
  (([()]{})) Decrement and Duplicate; get next factor to check
  { if not zero
   (<>({})<>) Copy N from other stack
   ({}(<>))<>{(({})){({}[()])<>}{}}{}<>([{}()]({})){((<{}{}>))} Code explained above
  }
  {} drop the zero
 >
 {} add the factor
}) push the sum

Brain-Flak, 96 bytes

((({})<>){<(([()]{})){<>(({})(<()>))<>{(({})){({}[()])<>}{}}{}<>([{}()]({})){((<{}{}>))}}{}>{}})

Try it online!

Explanation:

Now outdated by improvements.

The heart of the algorithm is this:

({}(<>))<>{(({})){({}[()])<>}{}}{}<>([{}()]({})) turns |N, M...| into |N mod M, M...|
{((<{}{}>))} if the top of stack is not zero, replace it and the second with zero

That is a modification on mod that will give us M if it is a factor of N and 0 otherwise. Full code is below.

((({})<>) place input, N on both stacks
{ Loop to find factors
 <
  (([()]{})) Decrement and Duplicate; get next factor to check
  { if not zero
   (<>({})<>) Copy N from other stack
   ({}(<>))<>{(({})){({}[()])<>}{}}{}<>([{}()]({})){((<{}{}>))} Code explained above
  }
  {} drop the zero
 >
 {} add the factor
}) push the sum
Old code was calculating the wrong function
Source Link
MegaTom
  • 4.3k
  • 1
  • 21
  • 24

Brain-Flak, 96, 100 bytes

((({})<>)({<(([()]{})){<>(({})(<()>))<>{(({})){({}[()])<>}{}}{}<>([{}()]({})){((<{}{}>))}}{}>{}})

I found some Push/Pop redundancy when adding the explanationTry it online!

Try it online! ##Explanation:

##Explanation:Now outdated by improvements.

The heart of the algorithm is this:

({}(<>))<>{(({})){({}[()])<>}{}}{}<>([{}()]({})) turns |N, M...| into |N mod M, M...|
{((<{}{}>))} if the top of stack is not zero, replace it and the second with zero

That is a modification on mod that will give us M if it is a factor of N and 0 otherwise. Full code is below.

((({})<>) place input, N on both stacks
({ Loop to find factors
 <
  (([()]{})) Decrement and Duplicate; get next factor to check
  { if not zero
   (<>({})<>) Copy N from other stack
   ({}(<>))<>{(({})){({}[()])<>}{}}{}<>([{}()]({})){((<{}{}>))} Code explained above
  }
  {} drop the zero
 >
 {} add the factor
}) push the sum

Brain-Flak, 96, 100 bytes

(({})<>)({<(([()]{})){<>(({})(<()>))<>{(({})){({}[()])<>}{}}{}<>([{}()]({})){((<{}{}>))}}{}>{}})

I found some Push/Pop redundancy when adding the explanation

Try it online!

##Explanation:

The heart of the algorithm is this:

({}(<>))<>{(({})){({}[()])<>}{}}{}<>([{}()]({})) turns |N, M...| into |N mod M, M...|
{((<{}{}>))} if the top of stack is not zero, replace it and the second with zero

That is a modification on mod that will give us M if it is a factor of N and 0 otherwise. Full code is below.

(({})<>) place input, N on both stacks
({ Loop to find factors
 <
  (([()]{})) Decrement and Duplicate; get next factor to check
  { if not zero
   (<>({})<>) Copy N from other stack
   ({}(<>))<>{(({})){({}[()])<>}{}}{}<>([{}()]({})){((<{}{}>))} Code explained above
  }
  {} drop the zero
 >
 {} add the factor
}) push the sum

Brain-Flak, 96 bytes

((({})<>){<(([()]{})){<>(({})(<()>))<>{(({})){({}[()])<>}{}}{}<>([{}()]({})){((<{}{}>))}}{}>{}})

Try it online!

##Explanation:

Now outdated by improvements.

The heart of the algorithm is this:

({}(<>))<>{(({})){({}[()])<>}{}}{}<>([{}()]({})) turns |N, M...| into |N mod M, M...|
{((<{}{}>))} if the top of stack is not zero, replace it and the second with zero

That is a modification on mod that will give us M if it is a factor of N and 0 otherwise. Full code is below.

((({})<>) place input, N on both stacks
{ Loop to find factors
 <
  (([()]{})) Decrement and Duplicate; get next factor to check
  { if not zero
   (<>({})<>) Copy N from other stack
   ({}(<>))<>{(({})){({}[()])<>}{}}{}<>([{}()]({})){((<{}{}>))} Code explained above
  }
  {} drop the zero
 >
 {} add the factor
}) push the sum
Fixed code to match byte count
Source Link
MegaTom
  • 4.3k
  • 1
  • 21
  • 24

Brain-Flak, 96, 100 bytes

(({})<>)({<(([()]{})){(<>(({})<>)({}<(<>)>))<>{(({})){({}[()])<>}{}}{}<>([{}()]({})){((<{}{}>))}}{}>{}})

I found some Push/Pop redundancy when adding the explanation

Try it online!

##Explanation:

The heart of the algorithm is this:

({}(<>))<>{(({})){({}[()])<>}{}}{}<>([{}()]({})) turns |N, M...| into |N mod M, M...|
{((<{}{}>))} if the top of stack is not zero, replace it and the second with zero

That is a modification on mod that will give us M if it is a factor of N and 0 otherwise. Full code is below.

(({})<>) place input, N on both stacks
({ Loop to find factors
 <
  (([()]{})) Decrement and Duplicate; get next factor to check
  { if not zero
   (<>({})<>) Copy N from other stack
   ({}(<>))<>{(({})){({}[()])<>}{}}{}<>([{}()]({})){((<{}{}>))} Code explained above
  }
  {} drop the zero
 >
 {} add the factor
}) push the sum

Brain-Flak, 96, 100 bytes

(({})<>)({<(([()]{})){(<>({})<>)({}(<>))<>{(({})){({}[()])<>}{}}{}<>([{}()]({})){((<{}{}>))}}{}>{}})

I found some Push/Pop redundancy when adding the explanation

Try it online!

##Explanation:

The heart of the algorithm is this:

({}(<>))<>{(({})){({}[()])<>}{}}{}<>([{}()]({})) turns |N, M...| into |N mod M, M...|
{((<{}{}>))} if the top of stack is not zero, replace it and the second with zero

That is a modification on mod that will give us M if it is a factor of N and 0 otherwise. Full code is below.

(({})<>) place input, N on both stacks
({ Loop to find factors
 <
  (([()]{})) Decrement and Duplicate; get next factor to check
  { if not zero
   (<>({})<>) Copy N from other stack
   ({}(<>))<>{(({})){({}[()])<>}{}}{}<>([{}()]({})){((<{}{}>))} Code explained above
  }
  {} drop the zero
 >
 {} add the factor
}) push the sum

Brain-Flak, 96, 100 bytes

(({})<>)({<(([()]{})){<>(({})(<()>))<>{(({})){({}[()])<>}{}}{}<>([{}()]({})){((<{}{}>))}}{}>{}})

I found some Push/Pop redundancy when adding the explanation

Try it online!

##Explanation:

The heart of the algorithm is this:

({}(<>))<>{(({})){({}[()])<>}{}}{}<>([{}()]({})) turns |N, M...| into |N mod M, M...|
{((<{}{}>))} if the top of stack is not zero, replace it and the second with zero

That is a modification on mod that will give us M if it is a factor of N and 0 otherwise. Full code is below.

(({})<>) place input, N on both stacks
({ Loop to find factors
 <
  (([()]{})) Decrement and Duplicate; get next factor to check
  { if not zero
   (<>({})<>) Copy N from other stack
   ({}(<>))<>{(({})){({}[()])<>}{}}{}<>([{}()]({})){((<{}{}>))} Code explained above
  }
  {} drop the zero
 >
 {} add the factor
}) push the sum
added 745 characters in body
Source Link
MegaTom
  • 4.3k
  • 1
  • 21
  • 24
Loading
added 745 characters in body
Source Link
MegaTom
  • 4.3k
  • 1
  • 21
  • 24
Loading
Source Link
MegaTom
  • 4.3k
  • 1
  • 21
  • 24
Loading