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

#Octave, 27 bytes

Octave, 27 bytes

@(x)lcm(1,num2cell(1:x){:})

Creates an anonymous function that can be invoked as ans(N).

Online Demo

Explanation

This solution creates a list of all numbers between 1 and x (1:x), converts them to a cell array with num2cell. Then the {:} indexing creates a comma-separated-list which is passed to lcm as multiple input arguments to compute the least common multiple. A 1 is always passed as the first argument to lcm because lcm always needs at least two input arguments.

#Octave, 27 bytes

@(x)lcm(1,num2cell(1:x){:})

Creates an anonymous function that can be invoked as ans(N).

Online Demo

Explanation

This solution creates a list of all numbers between 1 and x (1:x), converts them to a cell array with num2cell. Then the {:} indexing creates a comma-separated-list which is passed to lcm as multiple input arguments to compute the least common multiple. A 1 is always passed as the first argument to lcm because lcm always needs at least two input arguments.

Octave, 27 bytes

@(x)lcm(1,num2cell(1:x){:})

Creates an anonymous function that can be invoked as ans(N).

Online Demo

Explanation

This solution creates a list of all numbers between 1 and x (1:x), converts them to a cell array with num2cell. Then the {:} indexing creates a comma-separated-list which is passed to lcm as multiple input arguments to compute the least common multiple. A 1 is always passed as the first argument to lcm because lcm always needs at least two input arguments.

added 2 characters in body
Source Link
Suever
  • 11.2k
  • 1
  • 24
  • 52

#Octave, 2527 bytes

@(x)lcm(1,num2cell(1:x){:})

Creates an anonymous function that can be invoked as ans(N).

Online Demo

Explanation

This solution creates a list of all numbers between 1 and x (1:x), converts them to a cell array with num2cell. Then the {:} indexing creates a comma-separated-list which is passed to lcm as multiple input arguments to compute the least common multiple. A 1 is always passed as the first argument to lcm because lcm always needs at least two input arguments.

#Octave, 25 bytes

@(x)lcm(num2cell(1:x){:})

Creates an anonymous function that can be invoked as ans(N).

Online Demo

Explanation

This solution creates a list of all numbers between 1 and x (1:x), converts them to a cell array with num2cell. Then the {:} indexing creates a comma-separated-list which is passed to lcm as multiple input arguments to compute the least common multiple.

#Octave, 27 bytes

@(x)lcm(1,num2cell(1:x){:})

Creates an anonymous function that can be invoked as ans(N).

Online Demo

Explanation

This solution creates a list of all numbers between 1 and x (1:x), converts them to a cell array with num2cell. Then the {:} indexing creates a comma-separated-list which is passed to lcm as multiple input arguments to compute the least common multiple. A 1 is always passed as the first argument to lcm because lcm always needs at least two input arguments.

Source Link
Suever
  • 11.2k
  • 1
  • 24
  • 52

#Octave, 25 bytes

@(x)lcm(num2cell(1:x){:})

Creates an anonymous function that can be invoked as ans(N).

Online Demo

Explanation

This solution creates a list of all numbers between 1 and x (1:x), converts them to a cell array with num2cell. Then the {:} indexing creates a comma-separated-list which is passed to lcm as multiple input arguments to compute the least common multiple.

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