The qvolume of an integerFour Squares TogetherCounting ways of scoring k points in n games with half-points for drawsMultiply QuaternionsCount sums of two squares“Fouriest” Transform of An IntegerCalculate the volume of an objectThe happy Ender problemHighlight the Bounding Box, Part II: Hexagonal GridOutput the Euler NumbersCreate an N-Dimensional Simplex (Tetrahedron)The number of ways a number is a sum of consecutive primes

How were these pictures of spacecraft wind tunnel testing taken?

Is floating in space similar to falling under gravity?

Is it possible to change original filename of an exe?

The qvolume of an integer

Is CD audio quality good enough for the final delivery of music?

A Mathematical Discussion: Fill in the Blank

What are the benefits of cryosleep?

Plot exactly N bounce of a ball

Restoring order in a deck of playing cards

How could Catholicism have incorporated witchcraft into its dogma?

Is there an explanation for Austria's Freedom Party virtually retaining its vote share despite recent scandal?

Do you play the upbeat when beginning to play a series of notes, and then after?

What caused the tendency for conservatives to not support climate change reform?

Why colon to denote that a value belongs to a type?

What's the connection between "kicking a pigeon" and "how a bill becomes a law"?

What F1 in name of seeds/varieties means?

Why are huge challot displayed on the wedding couple / Bar Mitzvah's table?

Can a non-EU citizen travel within schengen zone freely without passport?

Crossword gone overboard

Looking after a wayward brother in mother's will

Could I be denied entry into Ireland due to medical and police situations during a previous UK visit?

Windows 10 Programs start without visual Interface

Uses of T extends U?

Can non-English-speaking characters use wordplay specific to English?



The qvolume of an integer


Four Squares TogetherCounting ways of scoring k points in n games with half-points for drawsMultiply QuaternionsCount sums of two squares“Fouriest” Transform of An IntegerCalculate the volume of an objectThe happy Ender problemHighlight the Bounding Box, Part II: Hexagonal GridOutput the Euler NumbersCreate an N-Dimensional Simplex (Tetrahedron)The number of ways a number is a sum of consecutive primes













10












$begingroup$


It is ancient knowledge that every non-negative integer can be rewritten as the sum of four squared integers. For example the number 1 can be expressed as $0^2+0^2+0^2+1^2$. Or, in general, for any non-negative integer n, there exist integers a,b,c,d such that



$$n = a^2+b^2+c^2+d^2$$



Joseph-Louis Lagrange proved this in the 1700s and so it is often called Lagrange's Theorem.



This is sometimes discussed in relation to Quaternions - a type of number discovered by William Hamilton in the 1800s, represented as $$w+xtextbfi+ytextbfj+ztextbfk$$ where w,x,y,z are real numbers, and i j and k are distinct imaginary units that don't multiply associatively. Specifically, it is discussed in relation to squaring each component of the Quaternion $$w^2+x^2+y^2+z^2$$This quantity is sometimes called the norm, or squared norm, or also Quadrance. Some modern proofs of LaGrange's Theorem use Quaternions.



Rudolf Lipschitz studied Quaternions with only integer components, called Lipschitz Quaternions. Using Quadrance, we can imagine that every Lipschitz Quaternion can be thought of having a friend in the integers. For example Quaternion $0+0i+0j+1k$ can be thought of as associated with the integer $1=0^2+0^2+0^2+1^2$. Also, if we go backwards, then every integer can be thought of as having a friend in the Lipschitz Quaternions.



But there is an interesting detail of Lagrange's theorem - the summation is not unique. Each integer may have several different sets of four squares that can be summed to create it. For example, the number 1 can be expressed in 4 ways using non-negative integers (let us only consider non-negatives for this challenge):
$$1=0^2+0^2+0^2+1^2$$
$$1=0^2+0^2+1^2+0^2$$
$$1=0^2+1^2+0^2+0^2$$
$$1=1^2+0^2+0^2+0^2$$



The summands are always squares of 0, or 1, but they can be in different positions in the expression.



For this challenge, let us also "sort" our summands lowest to highest, to eliminate duplicates, so that we could consider, for this exercise, that 1 only has 1 way of being represented as the sum of four squares:



$$1=0^2+0^2+0^2+1^2$$



Another example is the number 42, which can be expressed in four ways (again, only considering non-negative a,b,c,d, and eliminating duplicate component arrangements)



$$42=0^2+1^2+4^2+5^2$$
$$42=1^2+1^2+2^2+6^2$$
$$42=1^2+3^2+4^2+4^2$$
$$42=2^2+2^2+3^2+5^2$$



What if we imagine each of these different ways of expressing an integer as being associated to a specific Quaternion? Then we could say the number 42 is associated with these four Quaternions:



$$0+1i+4j+5k$$
$$1+1i+2j+6k$$
$$1+3i+4j+4k$$
$$2+2i+3j+5k$$



If we imagine the standard computer graphics interpretation of a Quaternion, where $i$ $j$ and $k$ are vectors in three dimensional Euclidian space, and so the $x$ $y$ and $z$ components of the Quaternion are 3 dimensional Cartesian coordinates, then we can imagine that each Integer, through this thought process, can be associated with a set of 3 dimensional coordinates in space. For example, the number 42 is associated with the following four $(x,y,z)$ coordinates: $$(1,4,5),(1,2,6),(3,4,4),(2,3,5)$$



This can be thought of as a point cloud, or a set of points in space. Now, one interesting thing about a set of finite points in space is that you can always draw a minimal bounding box around them - a box that is big enough to fit all the points, but no bigger. If you imagine the box as being an ordinary box aligned with the x,y,z axes, it is called an Axis Aligned Bounding Box. The bounding box also has a volume, calculable by determining its width, length, and height, and multiplying them together.



We can then imagine the volume of a bounding box for the points formed by our Quaternions. For the integer 1, we have, using the criteria of this exercise, one Quaternion whose Quadrance is 1, $0+0i+0j+1k$. This is a very simple point cloud, it only has one point, so it's bounding box has volume 0. For the integer 42, however, we have four Quaternions, and so four points, around which we can draw a bounding box. The minimum point of the box is (1,2,4) and the maximum is (3,4,6) resulting in a width, length, and height of 2,2, and 2, giving a volume of 8.



Let's say that for an integer n, the qvolume is the volume of the Axis Aligned Bounding Box of all the 3d points formed by Quaternions that have a Quadrance equal to n, where the components of the Quaternion $w+xi+yj+zk$ are non-negative and $w<=x<=y<=z$.



Create a program or function that, given a single non-negative integer n, will output n's qvolume.



Examples:



input -> output
0 -> 0
1 -> 0
31 -> 4
32 -> 0
42 -> 8
137 -> 96
1729 -> 10032


This is code-golf, smallest number of bytes wins.










share|improve this question











$endgroup$











  • $begingroup$
    what do i need to add? i meant to indicate that smallest number of bytes would win
    $endgroup$
    – don bright
    8 hours ago






  • 2




    $begingroup$
    You forgot the code-golf tag, I helped you add it
    $endgroup$
    – Embodiment of Ignorance
    8 hours ago











  • $begingroup$
    thank you very much
    $endgroup$
    – don bright
    8 hours ago






  • 1




    $begingroup$
    This is a nice challenge but it would be even better IMHO if it was a bit less verbose. Also, beware of irrelevant links (I'm not saying that all your links are irrelevant, but only a few of them really bring meaningful information for the challenge, while the other ones are just distracting).
    $endgroup$
    – Arnauld
    2 hours ago










  • $begingroup$
    Yes, but why take only i, j, k as 3D space but not 4D space?
    $endgroup$
    – tsh
    10 mins ago















10












$begingroup$


It is ancient knowledge that every non-negative integer can be rewritten as the sum of four squared integers. For example the number 1 can be expressed as $0^2+0^2+0^2+1^2$. Or, in general, for any non-negative integer n, there exist integers a,b,c,d such that



$$n = a^2+b^2+c^2+d^2$$



Joseph-Louis Lagrange proved this in the 1700s and so it is often called Lagrange's Theorem.



This is sometimes discussed in relation to Quaternions - a type of number discovered by William Hamilton in the 1800s, represented as $$w+xtextbfi+ytextbfj+ztextbfk$$ where w,x,y,z are real numbers, and i j and k are distinct imaginary units that don't multiply associatively. Specifically, it is discussed in relation to squaring each component of the Quaternion $$w^2+x^2+y^2+z^2$$This quantity is sometimes called the norm, or squared norm, or also Quadrance. Some modern proofs of LaGrange's Theorem use Quaternions.



Rudolf Lipschitz studied Quaternions with only integer components, called Lipschitz Quaternions. Using Quadrance, we can imagine that every Lipschitz Quaternion can be thought of having a friend in the integers. For example Quaternion $0+0i+0j+1k$ can be thought of as associated with the integer $1=0^2+0^2+0^2+1^2$. Also, if we go backwards, then every integer can be thought of as having a friend in the Lipschitz Quaternions.



But there is an interesting detail of Lagrange's theorem - the summation is not unique. Each integer may have several different sets of four squares that can be summed to create it. For example, the number 1 can be expressed in 4 ways using non-negative integers (let us only consider non-negatives for this challenge):
$$1=0^2+0^2+0^2+1^2$$
$$1=0^2+0^2+1^2+0^2$$
$$1=0^2+1^2+0^2+0^2$$
$$1=1^2+0^2+0^2+0^2$$



The summands are always squares of 0, or 1, but they can be in different positions in the expression.



For this challenge, let us also "sort" our summands lowest to highest, to eliminate duplicates, so that we could consider, for this exercise, that 1 only has 1 way of being represented as the sum of four squares:



$$1=0^2+0^2+0^2+1^2$$



Another example is the number 42, which can be expressed in four ways (again, only considering non-negative a,b,c,d, and eliminating duplicate component arrangements)



$$42=0^2+1^2+4^2+5^2$$
$$42=1^2+1^2+2^2+6^2$$
$$42=1^2+3^2+4^2+4^2$$
$$42=2^2+2^2+3^2+5^2$$



What if we imagine each of these different ways of expressing an integer as being associated to a specific Quaternion? Then we could say the number 42 is associated with these four Quaternions:



$$0+1i+4j+5k$$
$$1+1i+2j+6k$$
$$1+3i+4j+4k$$
$$2+2i+3j+5k$$



If we imagine the standard computer graphics interpretation of a Quaternion, where $i$ $j$ and $k$ are vectors in three dimensional Euclidian space, and so the $x$ $y$ and $z$ components of the Quaternion are 3 dimensional Cartesian coordinates, then we can imagine that each Integer, through this thought process, can be associated with a set of 3 dimensional coordinates in space. For example, the number 42 is associated with the following four $(x,y,z)$ coordinates: $$(1,4,5),(1,2,6),(3,4,4),(2,3,5)$$



This can be thought of as a point cloud, or a set of points in space. Now, one interesting thing about a set of finite points in space is that you can always draw a minimal bounding box around them - a box that is big enough to fit all the points, but no bigger. If you imagine the box as being an ordinary box aligned with the x,y,z axes, it is called an Axis Aligned Bounding Box. The bounding box also has a volume, calculable by determining its width, length, and height, and multiplying them together.



We can then imagine the volume of a bounding box for the points formed by our Quaternions. For the integer 1, we have, using the criteria of this exercise, one Quaternion whose Quadrance is 1, $0+0i+0j+1k$. This is a very simple point cloud, it only has one point, so it's bounding box has volume 0. For the integer 42, however, we have four Quaternions, and so four points, around which we can draw a bounding box. The minimum point of the box is (1,2,4) and the maximum is (3,4,6) resulting in a width, length, and height of 2,2, and 2, giving a volume of 8.



Let's say that for an integer n, the qvolume is the volume of the Axis Aligned Bounding Box of all the 3d points formed by Quaternions that have a Quadrance equal to n, where the components of the Quaternion $w+xi+yj+zk$ are non-negative and $w<=x<=y<=z$.



Create a program or function that, given a single non-negative integer n, will output n's qvolume.



Examples:



input -> output
0 -> 0
1 -> 0
31 -> 4
32 -> 0
42 -> 8
137 -> 96
1729 -> 10032


This is code-golf, smallest number of bytes wins.










share|improve this question











$endgroup$











  • $begingroup$
    what do i need to add? i meant to indicate that smallest number of bytes would win
    $endgroup$
    – don bright
    8 hours ago






  • 2




    $begingroup$
    You forgot the code-golf tag, I helped you add it
    $endgroup$
    – Embodiment of Ignorance
    8 hours ago











  • $begingroup$
    thank you very much
    $endgroup$
    – don bright
    8 hours ago






  • 1




    $begingroup$
    This is a nice challenge but it would be even better IMHO if it was a bit less verbose. Also, beware of irrelevant links (I'm not saying that all your links are irrelevant, but only a few of them really bring meaningful information for the challenge, while the other ones are just distracting).
    $endgroup$
    – Arnauld
    2 hours ago










  • $begingroup$
    Yes, but why take only i, j, k as 3D space but not 4D space?
    $endgroup$
    – tsh
    10 mins ago













10












10








10





$begingroup$


It is ancient knowledge that every non-negative integer can be rewritten as the sum of four squared integers. For example the number 1 can be expressed as $0^2+0^2+0^2+1^2$. Or, in general, for any non-negative integer n, there exist integers a,b,c,d such that



$$n = a^2+b^2+c^2+d^2$$



Joseph-Louis Lagrange proved this in the 1700s and so it is often called Lagrange's Theorem.



This is sometimes discussed in relation to Quaternions - a type of number discovered by William Hamilton in the 1800s, represented as $$w+xtextbfi+ytextbfj+ztextbfk$$ where w,x,y,z are real numbers, and i j and k are distinct imaginary units that don't multiply associatively. Specifically, it is discussed in relation to squaring each component of the Quaternion $$w^2+x^2+y^2+z^2$$This quantity is sometimes called the norm, or squared norm, or also Quadrance. Some modern proofs of LaGrange's Theorem use Quaternions.



Rudolf Lipschitz studied Quaternions with only integer components, called Lipschitz Quaternions. Using Quadrance, we can imagine that every Lipschitz Quaternion can be thought of having a friend in the integers. For example Quaternion $0+0i+0j+1k$ can be thought of as associated with the integer $1=0^2+0^2+0^2+1^2$. Also, if we go backwards, then every integer can be thought of as having a friend in the Lipschitz Quaternions.



But there is an interesting detail of Lagrange's theorem - the summation is not unique. Each integer may have several different sets of four squares that can be summed to create it. For example, the number 1 can be expressed in 4 ways using non-negative integers (let us only consider non-negatives for this challenge):
$$1=0^2+0^2+0^2+1^2$$
$$1=0^2+0^2+1^2+0^2$$
$$1=0^2+1^2+0^2+0^2$$
$$1=1^2+0^2+0^2+0^2$$



The summands are always squares of 0, or 1, but they can be in different positions in the expression.



For this challenge, let us also "sort" our summands lowest to highest, to eliminate duplicates, so that we could consider, for this exercise, that 1 only has 1 way of being represented as the sum of four squares:



$$1=0^2+0^2+0^2+1^2$$



Another example is the number 42, which can be expressed in four ways (again, only considering non-negative a,b,c,d, and eliminating duplicate component arrangements)



$$42=0^2+1^2+4^2+5^2$$
$$42=1^2+1^2+2^2+6^2$$
$$42=1^2+3^2+4^2+4^2$$
$$42=2^2+2^2+3^2+5^2$$



What if we imagine each of these different ways of expressing an integer as being associated to a specific Quaternion? Then we could say the number 42 is associated with these four Quaternions:



$$0+1i+4j+5k$$
$$1+1i+2j+6k$$
$$1+3i+4j+4k$$
$$2+2i+3j+5k$$



If we imagine the standard computer graphics interpretation of a Quaternion, where $i$ $j$ and $k$ are vectors in three dimensional Euclidian space, and so the $x$ $y$ and $z$ components of the Quaternion are 3 dimensional Cartesian coordinates, then we can imagine that each Integer, through this thought process, can be associated with a set of 3 dimensional coordinates in space. For example, the number 42 is associated with the following four $(x,y,z)$ coordinates: $$(1,4,5),(1,2,6),(3,4,4),(2,3,5)$$



This can be thought of as a point cloud, or a set of points in space. Now, one interesting thing about a set of finite points in space is that you can always draw a minimal bounding box around them - a box that is big enough to fit all the points, but no bigger. If you imagine the box as being an ordinary box aligned with the x,y,z axes, it is called an Axis Aligned Bounding Box. The bounding box also has a volume, calculable by determining its width, length, and height, and multiplying them together.



We can then imagine the volume of a bounding box for the points formed by our Quaternions. For the integer 1, we have, using the criteria of this exercise, one Quaternion whose Quadrance is 1, $0+0i+0j+1k$. This is a very simple point cloud, it only has one point, so it's bounding box has volume 0. For the integer 42, however, we have four Quaternions, and so four points, around which we can draw a bounding box. The minimum point of the box is (1,2,4) and the maximum is (3,4,6) resulting in a width, length, and height of 2,2, and 2, giving a volume of 8.



Let's say that for an integer n, the qvolume is the volume of the Axis Aligned Bounding Box of all the 3d points formed by Quaternions that have a Quadrance equal to n, where the components of the Quaternion $w+xi+yj+zk$ are non-negative and $w<=x<=y<=z$.



Create a program or function that, given a single non-negative integer n, will output n's qvolume.



Examples:



input -> output
0 -> 0
1 -> 0
31 -> 4
32 -> 0
42 -> 8
137 -> 96
1729 -> 10032


This is code-golf, smallest number of bytes wins.










share|improve this question











$endgroup$




It is ancient knowledge that every non-negative integer can be rewritten as the sum of four squared integers. For example the number 1 can be expressed as $0^2+0^2+0^2+1^2$. Or, in general, for any non-negative integer n, there exist integers a,b,c,d such that



$$n = a^2+b^2+c^2+d^2$$



Joseph-Louis Lagrange proved this in the 1700s and so it is often called Lagrange's Theorem.



This is sometimes discussed in relation to Quaternions - a type of number discovered by William Hamilton in the 1800s, represented as $$w+xtextbfi+ytextbfj+ztextbfk$$ where w,x,y,z are real numbers, and i j and k are distinct imaginary units that don't multiply associatively. Specifically, it is discussed in relation to squaring each component of the Quaternion $$w^2+x^2+y^2+z^2$$This quantity is sometimes called the norm, or squared norm, or also Quadrance. Some modern proofs of LaGrange's Theorem use Quaternions.



Rudolf Lipschitz studied Quaternions with only integer components, called Lipschitz Quaternions. Using Quadrance, we can imagine that every Lipschitz Quaternion can be thought of having a friend in the integers. For example Quaternion $0+0i+0j+1k$ can be thought of as associated with the integer $1=0^2+0^2+0^2+1^2$. Also, if we go backwards, then every integer can be thought of as having a friend in the Lipschitz Quaternions.



But there is an interesting detail of Lagrange's theorem - the summation is not unique. Each integer may have several different sets of four squares that can be summed to create it. For example, the number 1 can be expressed in 4 ways using non-negative integers (let us only consider non-negatives for this challenge):
$$1=0^2+0^2+0^2+1^2$$
$$1=0^2+0^2+1^2+0^2$$
$$1=0^2+1^2+0^2+0^2$$
$$1=1^2+0^2+0^2+0^2$$



The summands are always squares of 0, or 1, but they can be in different positions in the expression.



For this challenge, let us also "sort" our summands lowest to highest, to eliminate duplicates, so that we could consider, for this exercise, that 1 only has 1 way of being represented as the sum of four squares:



$$1=0^2+0^2+0^2+1^2$$



Another example is the number 42, which can be expressed in four ways (again, only considering non-negative a,b,c,d, and eliminating duplicate component arrangements)



$$42=0^2+1^2+4^2+5^2$$
$$42=1^2+1^2+2^2+6^2$$
$$42=1^2+3^2+4^2+4^2$$
$$42=2^2+2^2+3^2+5^2$$



What if we imagine each of these different ways of expressing an integer as being associated to a specific Quaternion? Then we could say the number 42 is associated with these four Quaternions:



$$0+1i+4j+5k$$
$$1+1i+2j+6k$$
$$1+3i+4j+4k$$
$$2+2i+3j+5k$$



If we imagine the standard computer graphics interpretation of a Quaternion, where $i$ $j$ and $k$ are vectors in three dimensional Euclidian space, and so the $x$ $y$ and $z$ components of the Quaternion are 3 dimensional Cartesian coordinates, then we can imagine that each Integer, through this thought process, can be associated with a set of 3 dimensional coordinates in space. For example, the number 42 is associated with the following four $(x,y,z)$ coordinates: $$(1,4,5),(1,2,6),(3,4,4),(2,3,5)$$



This can be thought of as a point cloud, or a set of points in space. Now, one interesting thing about a set of finite points in space is that you can always draw a minimal bounding box around them - a box that is big enough to fit all the points, but no bigger. If you imagine the box as being an ordinary box aligned with the x,y,z axes, it is called an Axis Aligned Bounding Box. The bounding box also has a volume, calculable by determining its width, length, and height, and multiplying them together.



We can then imagine the volume of a bounding box for the points formed by our Quaternions. For the integer 1, we have, using the criteria of this exercise, one Quaternion whose Quadrance is 1, $0+0i+0j+1k$. This is a very simple point cloud, it only has one point, so it's bounding box has volume 0. For the integer 42, however, we have four Quaternions, and so four points, around which we can draw a bounding box. The minimum point of the box is (1,2,4) and the maximum is (3,4,6) resulting in a width, length, and height of 2,2, and 2, giving a volume of 8.



Let's say that for an integer n, the qvolume is the volume of the Axis Aligned Bounding Box of all the 3d points formed by Quaternions that have a Quadrance equal to n, where the components of the Quaternion $w+xi+yj+zk$ are non-negative and $w<=x<=y<=z$.



Create a program or function that, given a single non-negative integer n, will output n's qvolume.



Examples:



input -> output
0 -> 0
1 -> 0
31 -> 4
32 -> 0
42 -> 8
137 -> 96
1729 -> 10032


This is code-golf, smallest number of bytes wins.







code-golf quaternions






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited 6 hours ago









xnor

95.9k18197458




95.9k18197458










asked 8 hours ago









don brightdon bright

814513




814513











  • $begingroup$
    what do i need to add? i meant to indicate that smallest number of bytes would win
    $endgroup$
    – don bright
    8 hours ago






  • 2




    $begingroup$
    You forgot the code-golf tag, I helped you add it
    $endgroup$
    – Embodiment of Ignorance
    8 hours ago











  • $begingroup$
    thank you very much
    $endgroup$
    – don bright
    8 hours ago






  • 1




    $begingroup$
    This is a nice challenge but it would be even better IMHO if it was a bit less verbose. Also, beware of irrelevant links (I'm not saying that all your links are irrelevant, but only a few of them really bring meaningful information for the challenge, while the other ones are just distracting).
    $endgroup$
    – Arnauld
    2 hours ago










  • $begingroup$
    Yes, but why take only i, j, k as 3D space but not 4D space?
    $endgroup$
    – tsh
    10 mins ago
















  • $begingroup$
    what do i need to add? i meant to indicate that smallest number of bytes would win
    $endgroup$
    – don bright
    8 hours ago






  • 2




    $begingroup$
    You forgot the code-golf tag, I helped you add it
    $endgroup$
    – Embodiment of Ignorance
    8 hours ago











  • $begingroup$
    thank you very much
    $endgroup$
    – don bright
    8 hours ago






  • 1




    $begingroup$
    This is a nice challenge but it would be even better IMHO if it was a bit less verbose. Also, beware of irrelevant links (I'm not saying that all your links are irrelevant, but only a few of them really bring meaningful information for the challenge, while the other ones are just distracting).
    $endgroup$
    – Arnauld
    2 hours ago










  • $begingroup$
    Yes, but why take only i, j, k as 3D space but not 4D space?
    $endgroup$
    – tsh
    10 mins ago















$begingroup$
what do i need to add? i meant to indicate that smallest number of bytes would win
$endgroup$
– don bright
8 hours ago




$begingroup$
what do i need to add? i meant to indicate that smallest number of bytes would win
$endgroup$
– don bright
8 hours ago




2




2




$begingroup$
You forgot the code-golf tag, I helped you add it
$endgroup$
– Embodiment of Ignorance
8 hours ago





$begingroup$
You forgot the code-golf tag, I helped you add it
$endgroup$
– Embodiment of Ignorance
8 hours ago













$begingroup$
thank you very much
$endgroup$
– don bright
8 hours ago




$begingroup$
thank you very much
$endgroup$
– don bright
8 hours ago




1




1




$begingroup$
This is a nice challenge but it would be even better IMHO if it was a bit less verbose. Also, beware of irrelevant links (I'm not saying that all your links are irrelevant, but only a few of them really bring meaningful information for the challenge, while the other ones are just distracting).
$endgroup$
– Arnauld
2 hours ago




$begingroup$
This is a nice challenge but it would be even better IMHO if it was a bit less verbose. Also, beware of irrelevant links (I'm not saying that all your links are irrelevant, but only a few of them really bring meaningful information for the challenge, while the other ones are just distracting).
$endgroup$
– Arnauld
2 hours ago












$begingroup$
Yes, but why take only i, j, k as 3D space but not 4D space?
$endgroup$
– tsh
10 mins ago




$begingroup$
Yes, but why take only i, j, k as 3D space but not 4D space?
$endgroup$
– tsh
10 mins ago










6 Answers
6






active

oldest

votes


















2












$begingroup$


Jelly, 17 bytes



Żœċ4²S⁼ɗƇ⁸ZḊṢ€I§P


Try it online! (pretty slow - make it fast enough for all the test cases with a leading ½)



How?



Żœċ4²S⁼ɗƇ⁸ZḊṢ€I§P - Link: non-negative integer, n e.g. 27
Ż - zero-range [0,1,2,...,27]
4 - literal four 4
œċ - combinations with replacement [[0,0,0,0],[0,0,0,1],...,[0,0,0,27],[0,0,1,1],[0,0,1,2],...,[27,27,27,27]]
Ƈ - filter keep those for which: e.g.: [0,1,1,5]
ɗ - last three links as a dyad:
² - square (vectorises) [0,1,1,25]
S - sum 27
⁼ ⁸ - equal to? chain's left argument, n 1
- -> [[0,1,1,5],[0,3,3,3],[1,1,3,4]]
Z - transpose [[0,0,1],[1,3,1],[1,3,3],[5,3,4]]
Ḋ - dequeue [[1,3,1],[1,3,3],[5,3,4]]
Ṣ€ - sort each [[1,1,3],[1,3,3],[3,4,5]]
I - incremental differences (vectorises) [[ 0,2 ],[ 2,0 ],[ 1,1 ]]
§ - sum each [2,2,2]
P - product 8





share|improve this answer











$endgroup$




















    2












    $begingroup$


    Python 2, 138 bytes





    q=lambda n,x=0,*t:[t]*(n==0)if t[3:]else q(n-x*x,x,x,*t)+q(n,x+1,*t+(0,)*(x>n))
    p=1
    for l in zip(*q(input()))[:3]:p*=max(l)-min(l)
    print p


    Try it online!



    Recursively generates the reverse-sorted quaternions with the given norm, then takes the product between the max and min of all possible values in the first three indices.



    itertools might have had a shot if it didn't use ridiculously long names like itertools.combinations_with_replacement



    Python 2, 161 bytes





    from itertools import*
    n=input();p=1
    for l in zip(*[t[1:]for t in combinations_with_replacement(range(n+1),4)if sum(x*x for x in t)==n]):p*=max(l)-min(l)
    print p


    Try it online!



    This is why itertools is never the answer.






    share|improve this answer









    $endgroup$




















      1












      $begingroup$


      C# (Visual C# Interactive Compiler), 229 bytes





      a=>uint b=0,c=~0U,d,e,f=0,g=0,h=0,i=c,j=c,k=c;for(;b*b<=a;b++)for(c=b;c*c<=a;c++)for(d=c;d*d<=a;d++)for(e=d;e*e<=a;e++)if(b*b+c*c+d*d+e*e==a)f=c>f?c:f;g=d>g?d:g;h=e>h?e:h;i=c<i?c:i;j=d<j?d:j;k=e<k?e:k;return(f-i)*(g-j)*(h-k);


      Try it online!






      share|improve this answer









      $endgroup$




















        1












        $begingroup$


        Wolfram Language (Mathematica), 67 58 bytes



        Volume@BoundingRegion[Rest/@PowersRepresentations[#,4,2]]&


        Try it online!



         ...& Pure function:
        PowersRepresentations[#,4,2] Get the sorted reprs. of # as sums of 4 2nd powers
        Rest/@ Drop the first coordinate of each
        BoundingRegion[...] Find the bounding region, a Cuboid[] or Point[].
        By default Mathematica finds an axis-aligned cuboid.
        Volume Find volume; volume of a Point[] is 0.





        share|improve this answer











        $endgroup$












        • $begingroup$
          wow, i had no idea that something like PowersRepresentations would be a built in in a language. i actually thought about making a challenge to show the different ways to sum an integer as four squares but im glad i did not.
          $endgroup$
          – don bright
          1 hour ago


















        1












        $begingroup$

        JavaScript (ES6),  148  143 bytes





        n=>(r=[[],[],[]]).map(a=>p*=a.length+~a.indexOf(1),(g=(s,k=0,a=[])=>a[3]?s||r.map(r=>r[a.pop()]=p=1):g(s-k*k,k,[...a,++k],k>s||g(s,k,a)))(n))|p


        Try it online!



        Commented



        We initialize an array $r$ with 3 empty arrays.



        r = [ [], [], [] ]


        For each valid value of $x$, we will set to $1$ the value at $x+1$ in the first array. Ditto for $y$ and $z$ with the 2nd and 3rd arrays respectively.



        The dimensions of the bounding box will be deduced from the distance between the first and the last entry set to $1$ in these arrays.



        Step 1



        To fill $r$, we use the recursive function $g$.



        g = ( // g is a recursive function taking:
        s, // s = current sum, initially set to the input n
        k = 0, // k = next value to be squared
        a = [] // a[] = list of selected values
        ) => //
        a[3] ? // if we have 4 values in a[]:
        s || // if s is equal to zero (we've found a valid sum of 4 squares):
        r.map(r => // for each array r[] in r[]:
        r[a.pop()] // pop the last value from a[]
        = p = 1 // and set the corresponding value in r[] to 1
        // (also initialize p to 1 for later use in step 2)
        ) // end of map()
        : // else:
        g( // do a recursive call:
        s - k * k, // subtract k² from s
        k, // pass k unchanged
        [...a, ++k], // increment k and append it to a[]
        k > s || // if k is less than or equal to s:
        g(s, k, a) // do another recursive call with s and a[] unchanged
        ) // end of outer recursive call


        Step 2



        We can now compute the product $p$ of the dimensions.



        r.map(a => // for each array a[] in r[]:
        p *= // multiply p by:
        a.length + // the length of a[]
        ~a.indexOf(1) // minus 1, minus the index of the first 1 in a[]
        ) | p // end of map(); return p





        share|improve this answer











        $endgroup$




















          0












          $begingroup$


          Sledgehammer, 13 bytes



          ⣚⡩⣏⢪⠨⣹⣓⢩⣒⡀⡸⢀⣺


          Use with this version of Sledgehammer. (This was pushed after the challenge was posted, but the changes actually increase the byte count.)



          Decompresses to the Mathematica expression Volume[BoundingRegion[Rest /@ PowersRepresentations[Slot[], 4, 2]]] which is an optimized version of my Mathematica answer. However, Rest[] still takes 1.75 bytes to encode.






          share|improve this answer









          $endgroup$













            Your Answer






            StackExchange.ifUsing("editor", function ()
            StackExchange.using("externalEditor", function ()
            StackExchange.using("snippets", function ()
            StackExchange.snippets.init();
            );
            );
            , "code-snippets");

            StackExchange.ready(function()
            var channelOptions =
            tags: "".split(" "),
            id: "200"
            ;
            initTagRenderer("".split(" "), "".split(" "), channelOptions);

            StackExchange.using("externalEditor", function()
            // Have to fire editor after snippets, if snippets enabled
            if (StackExchange.settings.snippets.snippetsEnabled)
            StackExchange.using("snippets", function()
            createEditor();
            );

            else
            createEditor();

            );

            function createEditor()
            StackExchange.prepareEditor(
            heartbeatType: 'answer',
            autoActivateHeartbeat: false,
            convertImagesToLinks: false,
            noModals: true,
            showLowRepImageUploadWarning: true,
            reputationToPostImages: null,
            bindNavPrevention: true,
            postfix: "",
            imageUploader:
            brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
            contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
            allowUrls: true
            ,
            onDemand: true,
            discardSelector: ".discard-answer"
            ,immediatelyShowMarkdownHelp:true
            );



            );













            draft saved

            draft discarded


















            StackExchange.ready(
            function ()
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fcodegolf.stackexchange.com%2fquestions%2f186151%2fthe-qvolume-of-an-integer%23new-answer', 'question_page');

            );

            Post as a guest















            Required, but never shown

























            6 Answers
            6






            active

            oldest

            votes








            6 Answers
            6






            active

            oldest

            votes









            active

            oldest

            votes






            active

            oldest

            votes









            2












            $begingroup$


            Jelly, 17 bytes



            Żœċ4²S⁼ɗƇ⁸ZḊṢ€I§P


            Try it online! (pretty slow - make it fast enough for all the test cases with a leading ½)



            How?



            Żœċ4²S⁼ɗƇ⁸ZḊṢ€I§P - Link: non-negative integer, n e.g. 27
            Ż - zero-range [0,1,2,...,27]
            4 - literal four 4
            œċ - combinations with replacement [[0,0,0,0],[0,0,0,1],...,[0,0,0,27],[0,0,1,1],[0,0,1,2],...,[27,27,27,27]]
            Ƈ - filter keep those for which: e.g.: [0,1,1,5]
            ɗ - last three links as a dyad:
            ² - square (vectorises) [0,1,1,25]
            S - sum 27
            ⁼ ⁸ - equal to? chain's left argument, n 1
            - -> [[0,1,1,5],[0,3,3,3],[1,1,3,4]]
            Z - transpose [[0,0,1],[1,3,1],[1,3,3],[5,3,4]]
            Ḋ - dequeue [[1,3,1],[1,3,3],[5,3,4]]
            Ṣ€ - sort each [[1,1,3],[1,3,3],[3,4,5]]
            I - incremental differences (vectorises) [[ 0,2 ],[ 2,0 ],[ 1,1 ]]
            § - sum each [2,2,2]
            P - product 8





            share|improve this answer











            $endgroup$

















              2












              $begingroup$


              Jelly, 17 bytes



              Żœċ4²S⁼ɗƇ⁸ZḊṢ€I§P


              Try it online! (pretty slow - make it fast enough for all the test cases with a leading ½)



              How?



              Żœċ4²S⁼ɗƇ⁸ZḊṢ€I§P - Link: non-negative integer, n e.g. 27
              Ż - zero-range [0,1,2,...,27]
              4 - literal four 4
              œċ - combinations with replacement [[0,0,0,0],[0,0,0,1],...,[0,0,0,27],[0,0,1,1],[0,0,1,2],...,[27,27,27,27]]
              Ƈ - filter keep those for which: e.g.: [0,1,1,5]
              ɗ - last three links as a dyad:
              ² - square (vectorises) [0,1,1,25]
              S - sum 27
              ⁼ ⁸ - equal to? chain's left argument, n 1
              - -> [[0,1,1,5],[0,3,3,3],[1,1,3,4]]
              Z - transpose [[0,0,1],[1,3,1],[1,3,3],[5,3,4]]
              Ḋ - dequeue [[1,3,1],[1,3,3],[5,3,4]]
              Ṣ€ - sort each [[1,1,3],[1,3,3],[3,4,5]]
              I - incremental differences (vectorises) [[ 0,2 ],[ 2,0 ],[ 1,1 ]]
              § - sum each [2,2,2]
              P - product 8





              share|improve this answer











              $endgroup$















                2












                2








                2





                $begingroup$


                Jelly, 17 bytes



                Żœċ4²S⁼ɗƇ⁸ZḊṢ€I§P


                Try it online! (pretty slow - make it fast enough for all the test cases with a leading ½)



                How?



                Żœċ4²S⁼ɗƇ⁸ZḊṢ€I§P - Link: non-negative integer, n e.g. 27
                Ż - zero-range [0,1,2,...,27]
                4 - literal four 4
                œċ - combinations with replacement [[0,0,0,0],[0,0,0,1],...,[0,0,0,27],[0,0,1,1],[0,0,1,2],...,[27,27,27,27]]
                Ƈ - filter keep those for which: e.g.: [0,1,1,5]
                ɗ - last three links as a dyad:
                ² - square (vectorises) [0,1,1,25]
                S - sum 27
                ⁼ ⁸ - equal to? chain's left argument, n 1
                - -> [[0,1,1,5],[0,3,3,3],[1,1,3,4]]
                Z - transpose [[0,0,1],[1,3,1],[1,3,3],[5,3,4]]
                Ḋ - dequeue [[1,3,1],[1,3,3],[5,3,4]]
                Ṣ€ - sort each [[1,1,3],[1,3,3],[3,4,5]]
                I - incremental differences (vectorises) [[ 0,2 ],[ 2,0 ],[ 1,1 ]]
                § - sum each [2,2,2]
                P - product 8





                share|improve this answer











                $endgroup$




                Jelly, 17 bytes



                Żœċ4²S⁼ɗƇ⁸ZḊṢ€I§P


                Try it online! (pretty slow - make it fast enough for all the test cases with a leading ½)



                How?



                Żœċ4²S⁼ɗƇ⁸ZḊṢ€I§P - Link: non-negative integer, n e.g. 27
                Ż - zero-range [0,1,2,...,27]
                4 - literal four 4
                œċ - combinations with replacement [[0,0,0,0],[0,0,0,1],...,[0,0,0,27],[0,0,1,1],[0,0,1,2],...,[27,27,27,27]]
                Ƈ - filter keep those for which: e.g.: [0,1,1,5]
                ɗ - last three links as a dyad:
                ² - square (vectorises) [0,1,1,25]
                S - sum 27
                ⁼ ⁸ - equal to? chain's left argument, n 1
                - -> [[0,1,1,5],[0,3,3,3],[1,1,3,4]]
                Z - transpose [[0,0,1],[1,3,1],[1,3,3],[5,3,4]]
                Ḋ - dequeue [[1,3,1],[1,3,3],[5,3,4]]
                Ṣ€ - sort each [[1,1,3],[1,3,3],[3,4,5]]
                I - incremental differences (vectorises) [[ 0,2 ],[ 2,0 ],[ 1,1 ]]
                § - sum each [2,2,2]
                P - product 8






                share|improve this answer














                share|improve this answer



                share|improve this answer








                edited 7 hours ago

























                answered 8 hours ago









                Jonathan AllanJonathan Allan

                55.9k538178




                55.9k538178





















                    2












                    $begingroup$


                    Python 2, 138 bytes





                    q=lambda n,x=0,*t:[t]*(n==0)if t[3:]else q(n-x*x,x,x,*t)+q(n,x+1,*t+(0,)*(x>n))
                    p=1
                    for l in zip(*q(input()))[:3]:p*=max(l)-min(l)
                    print p


                    Try it online!



                    Recursively generates the reverse-sorted quaternions with the given norm, then takes the product between the max and min of all possible values in the first three indices.



                    itertools might have had a shot if it didn't use ridiculously long names like itertools.combinations_with_replacement



                    Python 2, 161 bytes





                    from itertools import*
                    n=input();p=1
                    for l in zip(*[t[1:]for t in combinations_with_replacement(range(n+1),4)if sum(x*x for x in t)==n]):p*=max(l)-min(l)
                    print p


                    Try it online!



                    This is why itertools is never the answer.






                    share|improve this answer









                    $endgroup$

















                      2












                      $begingroup$


                      Python 2, 138 bytes





                      q=lambda n,x=0,*t:[t]*(n==0)if t[3:]else q(n-x*x,x,x,*t)+q(n,x+1,*t+(0,)*(x>n))
                      p=1
                      for l in zip(*q(input()))[:3]:p*=max(l)-min(l)
                      print p


                      Try it online!



                      Recursively generates the reverse-sorted quaternions with the given norm, then takes the product between the max and min of all possible values in the first three indices.



                      itertools might have had a shot if it didn't use ridiculously long names like itertools.combinations_with_replacement



                      Python 2, 161 bytes





                      from itertools import*
                      n=input();p=1
                      for l in zip(*[t[1:]for t in combinations_with_replacement(range(n+1),4)if sum(x*x for x in t)==n]):p*=max(l)-min(l)
                      print p


                      Try it online!



                      This is why itertools is never the answer.






                      share|improve this answer









                      $endgroup$















                        2












                        2








                        2





                        $begingroup$


                        Python 2, 138 bytes





                        q=lambda n,x=0,*t:[t]*(n==0)if t[3:]else q(n-x*x,x,x,*t)+q(n,x+1,*t+(0,)*(x>n))
                        p=1
                        for l in zip(*q(input()))[:3]:p*=max(l)-min(l)
                        print p


                        Try it online!



                        Recursively generates the reverse-sorted quaternions with the given norm, then takes the product between the max and min of all possible values in the first three indices.



                        itertools might have had a shot if it didn't use ridiculously long names like itertools.combinations_with_replacement



                        Python 2, 161 bytes





                        from itertools import*
                        n=input();p=1
                        for l in zip(*[t[1:]for t in combinations_with_replacement(range(n+1),4)if sum(x*x for x in t)==n]):p*=max(l)-min(l)
                        print p


                        Try it online!



                        This is why itertools is never the answer.






                        share|improve this answer









                        $endgroup$




                        Python 2, 138 bytes





                        q=lambda n,x=0,*t:[t]*(n==0)if t[3:]else q(n-x*x,x,x,*t)+q(n,x+1,*t+(0,)*(x>n))
                        p=1
                        for l in zip(*q(input()))[:3]:p*=max(l)-min(l)
                        print p


                        Try it online!



                        Recursively generates the reverse-sorted quaternions with the given norm, then takes the product between the max and min of all possible values in the first three indices.



                        itertools might have had a shot if it didn't use ridiculously long names like itertools.combinations_with_replacement



                        Python 2, 161 bytes





                        from itertools import*
                        n=input();p=1
                        for l in zip(*[t[1:]for t in combinations_with_replacement(range(n+1),4)if sum(x*x for x in t)==n]):p*=max(l)-min(l)
                        print p


                        Try it online!



                        This is why itertools is never the answer.







                        share|improve this answer












                        share|improve this answer



                        share|improve this answer










                        answered 6 hours ago









                        xnorxnor

                        95.9k18197458




                        95.9k18197458





















                            1












                            $begingroup$


                            C# (Visual C# Interactive Compiler), 229 bytes





                            a=>uint b=0,c=~0U,d,e,f=0,g=0,h=0,i=c,j=c,k=c;for(;b*b<=a;b++)for(c=b;c*c<=a;c++)for(d=c;d*d<=a;d++)for(e=d;e*e<=a;e++)if(b*b+c*c+d*d+e*e==a)f=c>f?c:f;g=d>g?d:g;h=e>h?e:h;i=c<i?c:i;j=d<j?d:j;k=e<k?e:k;return(f-i)*(g-j)*(h-k);


                            Try it online!






                            share|improve this answer









                            $endgroup$

















                              1












                              $begingroup$


                              C# (Visual C# Interactive Compiler), 229 bytes





                              a=>uint b=0,c=~0U,d,e,f=0,g=0,h=0,i=c,j=c,k=c;for(;b*b<=a;b++)for(c=b;c*c<=a;c++)for(d=c;d*d<=a;d++)for(e=d;e*e<=a;e++)if(b*b+c*c+d*d+e*e==a)f=c>f?c:f;g=d>g?d:g;h=e>h?e:h;i=c<i?c:i;j=d<j?d:j;k=e<k?e:k;return(f-i)*(g-j)*(h-k);


                              Try it online!






                              share|improve this answer









                              $endgroup$















                                1












                                1








                                1





                                $begingroup$


                                C# (Visual C# Interactive Compiler), 229 bytes





                                a=>uint b=0,c=~0U,d,e,f=0,g=0,h=0,i=c,j=c,k=c;for(;b*b<=a;b++)for(c=b;c*c<=a;c++)for(d=c;d*d<=a;d++)for(e=d;e*e<=a;e++)if(b*b+c*c+d*d+e*e==a)f=c>f?c:f;g=d>g?d:g;h=e>h?e:h;i=c<i?c:i;j=d<j?d:j;k=e<k?e:k;return(f-i)*(g-j)*(h-k);


                                Try it online!






                                share|improve this answer









                                $endgroup$




                                C# (Visual C# Interactive Compiler), 229 bytes





                                a=>uint b=0,c=~0U,d,e,f=0,g=0,h=0,i=c,j=c,k=c;for(;b*b<=a;b++)for(c=b;c*c<=a;c++)for(d=c;d*d<=a;d++)for(e=d;e*e<=a;e++)if(b*b+c*c+d*d+e*e==a)f=c>f?c:f;g=d>g?d:g;h=e>h?e:h;i=c<i?c:i;j=d<j?d:j;k=e<k?e:k;return(f-i)*(g-j)*(h-k);


                                Try it online!







                                share|improve this answer












                                share|improve this answer



                                share|improve this answer










                                answered 7 hours ago









                                Embodiment of IgnoranceEmbodiment of Ignorance

                                3,864128




                                3,864128





















                                    1












                                    $begingroup$


                                    Wolfram Language (Mathematica), 67 58 bytes



                                    Volume@BoundingRegion[Rest/@PowersRepresentations[#,4,2]]&


                                    Try it online!



                                     ...& Pure function:
                                    PowersRepresentations[#,4,2] Get the sorted reprs. of # as sums of 4 2nd powers
                                    Rest/@ Drop the first coordinate of each
                                    BoundingRegion[...] Find the bounding region, a Cuboid[] or Point[].
                                    By default Mathematica finds an axis-aligned cuboid.
                                    Volume Find volume; volume of a Point[] is 0.





                                    share|improve this answer











                                    $endgroup$












                                    • $begingroup$
                                      wow, i had no idea that something like PowersRepresentations would be a built in in a language. i actually thought about making a challenge to show the different ways to sum an integer as four squares but im glad i did not.
                                      $endgroup$
                                      – don bright
                                      1 hour ago















                                    1












                                    $begingroup$


                                    Wolfram Language (Mathematica), 67 58 bytes



                                    Volume@BoundingRegion[Rest/@PowersRepresentations[#,4,2]]&


                                    Try it online!



                                     ...& Pure function:
                                    PowersRepresentations[#,4,2] Get the sorted reprs. of # as sums of 4 2nd powers
                                    Rest/@ Drop the first coordinate of each
                                    BoundingRegion[...] Find the bounding region, a Cuboid[] or Point[].
                                    By default Mathematica finds an axis-aligned cuboid.
                                    Volume Find volume; volume of a Point[] is 0.





                                    share|improve this answer











                                    $endgroup$












                                    • $begingroup$
                                      wow, i had no idea that something like PowersRepresentations would be a built in in a language. i actually thought about making a challenge to show the different ways to sum an integer as four squares but im glad i did not.
                                      $endgroup$
                                      – don bright
                                      1 hour ago













                                    1












                                    1








                                    1





                                    $begingroup$


                                    Wolfram Language (Mathematica), 67 58 bytes



                                    Volume@BoundingRegion[Rest/@PowersRepresentations[#,4,2]]&


                                    Try it online!



                                     ...& Pure function:
                                    PowersRepresentations[#,4,2] Get the sorted reprs. of # as sums of 4 2nd powers
                                    Rest/@ Drop the first coordinate of each
                                    BoundingRegion[...] Find the bounding region, a Cuboid[] or Point[].
                                    By default Mathematica finds an axis-aligned cuboid.
                                    Volume Find volume; volume of a Point[] is 0.





                                    share|improve this answer











                                    $endgroup$




                                    Wolfram Language (Mathematica), 67 58 bytes



                                    Volume@BoundingRegion[Rest/@PowersRepresentations[#,4,2]]&


                                    Try it online!



                                     ...& Pure function:
                                    PowersRepresentations[#,4,2] Get the sorted reprs. of # as sums of 4 2nd powers
                                    Rest/@ Drop the first coordinate of each
                                    BoundingRegion[...] Find the bounding region, a Cuboid[] or Point[].
                                    By default Mathematica finds an axis-aligned cuboid.
                                    Volume Find volume; volume of a Point[] is 0.






                                    share|improve this answer














                                    share|improve this answer



                                    share|improve this answer








                                    edited 4 hours ago

























                                    answered 4 hours ago









                                    lirtosiastlirtosiast

                                    18.4k440111




                                    18.4k440111











                                    • $begingroup$
                                      wow, i had no idea that something like PowersRepresentations would be a built in in a language. i actually thought about making a challenge to show the different ways to sum an integer as four squares but im glad i did not.
                                      $endgroup$
                                      – don bright
                                      1 hour ago
















                                    • $begingroup$
                                      wow, i had no idea that something like PowersRepresentations would be a built in in a language. i actually thought about making a challenge to show the different ways to sum an integer as four squares but im glad i did not.
                                      $endgroup$
                                      – don bright
                                      1 hour ago















                                    $begingroup$
                                    wow, i had no idea that something like PowersRepresentations would be a built in in a language. i actually thought about making a challenge to show the different ways to sum an integer as four squares but im glad i did not.
                                    $endgroup$
                                    – don bright
                                    1 hour ago




                                    $begingroup$
                                    wow, i had no idea that something like PowersRepresentations would be a built in in a language. i actually thought about making a challenge to show the different ways to sum an integer as four squares but im glad i did not.
                                    $endgroup$
                                    – don bright
                                    1 hour ago











                                    1












                                    $begingroup$

                                    JavaScript (ES6),  148  143 bytes





                                    n=>(r=[[],[],[]]).map(a=>p*=a.length+~a.indexOf(1),(g=(s,k=0,a=[])=>a[3]?s||r.map(r=>r[a.pop()]=p=1):g(s-k*k,k,[...a,++k],k>s||g(s,k,a)))(n))|p


                                    Try it online!



                                    Commented



                                    We initialize an array $r$ with 3 empty arrays.



                                    r = [ [], [], [] ]


                                    For each valid value of $x$, we will set to $1$ the value at $x+1$ in the first array. Ditto for $y$ and $z$ with the 2nd and 3rd arrays respectively.



                                    The dimensions of the bounding box will be deduced from the distance between the first and the last entry set to $1$ in these arrays.



                                    Step 1



                                    To fill $r$, we use the recursive function $g$.



                                    g = ( // g is a recursive function taking:
                                    s, // s = current sum, initially set to the input n
                                    k = 0, // k = next value to be squared
                                    a = [] // a[] = list of selected values
                                    ) => //
                                    a[3] ? // if we have 4 values in a[]:
                                    s || // if s is equal to zero (we've found a valid sum of 4 squares):
                                    r.map(r => // for each array r[] in r[]:
                                    r[a.pop()] // pop the last value from a[]
                                    = p = 1 // and set the corresponding value in r[] to 1
                                    // (also initialize p to 1 for later use in step 2)
                                    ) // end of map()
                                    : // else:
                                    g( // do a recursive call:
                                    s - k * k, // subtract k² from s
                                    k, // pass k unchanged
                                    [...a, ++k], // increment k and append it to a[]
                                    k > s || // if k is less than or equal to s:
                                    g(s, k, a) // do another recursive call with s and a[] unchanged
                                    ) // end of outer recursive call


                                    Step 2



                                    We can now compute the product $p$ of the dimensions.



                                    r.map(a => // for each array a[] in r[]:
                                    p *= // multiply p by:
                                    a.length + // the length of a[]
                                    ~a.indexOf(1) // minus 1, minus the index of the first 1 in a[]
                                    ) | p // end of map(); return p





                                    share|improve this answer











                                    $endgroup$

















                                      1












                                      $begingroup$

                                      JavaScript (ES6),  148  143 bytes





                                      n=>(r=[[],[],[]]).map(a=>p*=a.length+~a.indexOf(1),(g=(s,k=0,a=[])=>a[3]?s||r.map(r=>r[a.pop()]=p=1):g(s-k*k,k,[...a,++k],k>s||g(s,k,a)))(n))|p


                                      Try it online!



                                      Commented



                                      We initialize an array $r$ with 3 empty arrays.



                                      r = [ [], [], [] ]


                                      For each valid value of $x$, we will set to $1$ the value at $x+1$ in the first array. Ditto for $y$ and $z$ with the 2nd and 3rd arrays respectively.



                                      The dimensions of the bounding box will be deduced from the distance between the first and the last entry set to $1$ in these arrays.



                                      Step 1



                                      To fill $r$, we use the recursive function $g$.



                                      g = ( // g is a recursive function taking:
                                      s, // s = current sum, initially set to the input n
                                      k = 0, // k = next value to be squared
                                      a = [] // a[] = list of selected values
                                      ) => //
                                      a[3] ? // if we have 4 values in a[]:
                                      s || // if s is equal to zero (we've found a valid sum of 4 squares):
                                      r.map(r => // for each array r[] in r[]:
                                      r[a.pop()] // pop the last value from a[]
                                      = p = 1 // and set the corresponding value in r[] to 1
                                      // (also initialize p to 1 for later use in step 2)
                                      ) // end of map()
                                      : // else:
                                      g( // do a recursive call:
                                      s - k * k, // subtract k² from s
                                      k, // pass k unchanged
                                      [...a, ++k], // increment k and append it to a[]
                                      k > s || // if k is less than or equal to s:
                                      g(s, k, a) // do another recursive call with s and a[] unchanged
                                      ) // end of outer recursive call


                                      Step 2



                                      We can now compute the product $p$ of the dimensions.



                                      r.map(a => // for each array a[] in r[]:
                                      p *= // multiply p by:
                                      a.length + // the length of a[]
                                      ~a.indexOf(1) // minus 1, minus the index of the first 1 in a[]
                                      ) | p // end of map(); return p





                                      share|improve this answer











                                      $endgroup$















                                        1












                                        1








                                        1





                                        $begingroup$

                                        JavaScript (ES6),  148  143 bytes





                                        n=>(r=[[],[],[]]).map(a=>p*=a.length+~a.indexOf(1),(g=(s,k=0,a=[])=>a[3]?s||r.map(r=>r[a.pop()]=p=1):g(s-k*k,k,[...a,++k],k>s||g(s,k,a)))(n))|p


                                        Try it online!



                                        Commented



                                        We initialize an array $r$ with 3 empty arrays.



                                        r = [ [], [], [] ]


                                        For each valid value of $x$, we will set to $1$ the value at $x+1$ in the first array. Ditto for $y$ and $z$ with the 2nd and 3rd arrays respectively.



                                        The dimensions of the bounding box will be deduced from the distance between the first and the last entry set to $1$ in these arrays.



                                        Step 1



                                        To fill $r$, we use the recursive function $g$.



                                        g = ( // g is a recursive function taking:
                                        s, // s = current sum, initially set to the input n
                                        k = 0, // k = next value to be squared
                                        a = [] // a[] = list of selected values
                                        ) => //
                                        a[3] ? // if we have 4 values in a[]:
                                        s || // if s is equal to zero (we've found a valid sum of 4 squares):
                                        r.map(r => // for each array r[] in r[]:
                                        r[a.pop()] // pop the last value from a[]
                                        = p = 1 // and set the corresponding value in r[] to 1
                                        // (also initialize p to 1 for later use in step 2)
                                        ) // end of map()
                                        : // else:
                                        g( // do a recursive call:
                                        s - k * k, // subtract k² from s
                                        k, // pass k unchanged
                                        [...a, ++k], // increment k and append it to a[]
                                        k > s || // if k is less than or equal to s:
                                        g(s, k, a) // do another recursive call with s and a[] unchanged
                                        ) // end of outer recursive call


                                        Step 2



                                        We can now compute the product $p$ of the dimensions.



                                        r.map(a => // for each array a[] in r[]:
                                        p *= // multiply p by:
                                        a.length + // the length of a[]
                                        ~a.indexOf(1) // minus 1, minus the index of the first 1 in a[]
                                        ) | p // end of map(); return p





                                        share|improve this answer











                                        $endgroup$



                                        JavaScript (ES6),  148  143 bytes





                                        n=>(r=[[],[],[]]).map(a=>p*=a.length+~a.indexOf(1),(g=(s,k=0,a=[])=>a[3]?s||r.map(r=>r[a.pop()]=p=1):g(s-k*k,k,[...a,++k],k>s||g(s,k,a)))(n))|p


                                        Try it online!



                                        Commented



                                        We initialize an array $r$ with 3 empty arrays.



                                        r = [ [], [], [] ]


                                        For each valid value of $x$, we will set to $1$ the value at $x+1$ in the first array. Ditto for $y$ and $z$ with the 2nd and 3rd arrays respectively.



                                        The dimensions of the bounding box will be deduced from the distance between the first and the last entry set to $1$ in these arrays.



                                        Step 1



                                        To fill $r$, we use the recursive function $g$.



                                        g = ( // g is a recursive function taking:
                                        s, // s = current sum, initially set to the input n
                                        k = 0, // k = next value to be squared
                                        a = [] // a[] = list of selected values
                                        ) => //
                                        a[3] ? // if we have 4 values in a[]:
                                        s || // if s is equal to zero (we've found a valid sum of 4 squares):
                                        r.map(r => // for each array r[] in r[]:
                                        r[a.pop()] // pop the last value from a[]
                                        = p = 1 // and set the corresponding value in r[] to 1
                                        // (also initialize p to 1 for later use in step 2)
                                        ) // end of map()
                                        : // else:
                                        g( // do a recursive call:
                                        s - k * k, // subtract k² from s
                                        k, // pass k unchanged
                                        [...a, ++k], // increment k and append it to a[]
                                        k > s || // if k is less than or equal to s:
                                        g(s, k, a) // do another recursive call with s and a[] unchanged
                                        ) // end of outer recursive call


                                        Step 2



                                        We can now compute the product $p$ of the dimensions.



                                        r.map(a => // for each array a[] in r[]:
                                        p *= // multiply p by:
                                        a.length + // the length of a[]
                                        ~a.indexOf(1) // minus 1, minus the index of the first 1 in a[]
                                        ) | p // end of map(); return p






                                        share|improve this answer














                                        share|improve this answer



                                        share|improve this answer








                                        edited 3 hours ago

























                                        answered 5 hours ago









                                        ArnauldArnauld

                                        85.1k7100349




                                        85.1k7100349





















                                            0












                                            $begingroup$


                                            Sledgehammer, 13 bytes



                                            ⣚⡩⣏⢪⠨⣹⣓⢩⣒⡀⡸⢀⣺


                                            Use with this version of Sledgehammer. (This was pushed after the challenge was posted, but the changes actually increase the byte count.)



                                            Decompresses to the Mathematica expression Volume[BoundingRegion[Rest /@ PowersRepresentations[Slot[], 4, 2]]] which is an optimized version of my Mathematica answer. However, Rest[] still takes 1.75 bytes to encode.






                                            share|improve this answer









                                            $endgroup$

















                                              0












                                              $begingroup$


                                              Sledgehammer, 13 bytes



                                              ⣚⡩⣏⢪⠨⣹⣓⢩⣒⡀⡸⢀⣺


                                              Use with this version of Sledgehammer. (This was pushed after the challenge was posted, but the changes actually increase the byte count.)



                                              Decompresses to the Mathematica expression Volume[BoundingRegion[Rest /@ PowersRepresentations[Slot[], 4, 2]]] which is an optimized version of my Mathematica answer. However, Rest[] still takes 1.75 bytes to encode.






                                              share|improve this answer









                                              $endgroup$















                                                0












                                                0








                                                0





                                                $begingroup$


                                                Sledgehammer, 13 bytes



                                                ⣚⡩⣏⢪⠨⣹⣓⢩⣒⡀⡸⢀⣺


                                                Use with this version of Sledgehammer. (This was pushed after the challenge was posted, but the changes actually increase the byte count.)



                                                Decompresses to the Mathematica expression Volume[BoundingRegion[Rest /@ PowersRepresentations[Slot[], 4, 2]]] which is an optimized version of my Mathematica answer. However, Rest[] still takes 1.75 bytes to encode.






                                                share|improve this answer









                                                $endgroup$




                                                Sledgehammer, 13 bytes



                                                ⣚⡩⣏⢪⠨⣹⣓⢩⣒⡀⡸⢀⣺


                                                Use with this version of Sledgehammer. (This was pushed after the challenge was posted, but the changes actually increase the byte count.)



                                                Decompresses to the Mathematica expression Volume[BoundingRegion[Rest /@ PowersRepresentations[Slot[], 4, 2]]] which is an optimized version of my Mathematica answer. However, Rest[] still takes 1.75 bytes to encode.







                                                share|improve this answer












                                                share|improve this answer



                                                share|improve this answer










                                                answered 2 hours ago









                                                lirtosiastlirtosiast

                                                18.4k440111




                                                18.4k440111



























                                                    draft saved

                                                    draft discarded
















































                                                    If this is an answer to a challenge…



                                                    • …Be sure to follow the challenge specification. However, please refrain from exploiting obvious loopholes. Answers abusing any of the standard loopholes are considered invalid. If you think a specification is unclear or underspecified, comment on the question instead.


                                                    • …Try to optimize your score. For instance, answers to code-golf challenges should attempt to be as short as possible. You can always include a readable version of the code in addition to the competitive one.
                                                      Explanations of your answer make it more interesting to read and are very much encouraged.


                                                    • …Include a short header which indicates the language(s) of your code and its score, as defined by the challenge.


                                                    More generally…



                                                    • …Please make sure to answer the question and provide sufficient detail.


                                                    • …Avoid asking for help, clarification or responding to other answers (use comments instead).




                                                    draft saved


                                                    draft discarded














                                                    StackExchange.ready(
                                                    function ()
                                                    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fcodegolf.stackexchange.com%2fquestions%2f186151%2fthe-qvolume-of-an-integer%23new-answer', 'question_page');

                                                    );

                                                    Post as a guest















                                                    Required, but never shown





















































                                                    Required, but never shown














                                                    Required, but never shown












                                                    Required, but never shown







                                                    Required, but never shown

































                                                    Required, but never shown














                                                    Required, but never shown












                                                    Required, but never shown







                                                    Required, but never shown







                                                    Popular posts from this blog

                                                    19. јануар Садржај Догађаји Рођења Смрти Празници и дани сећања Види још Референце Мени за навигацијуу

                                                    Israel Cuprins Etimologie | Istorie | Geografie | Politică | Demografie | Educație | Economie | Cultură | Note explicative | Note bibliografice | Bibliografie | Legături externe | Meniu de navigaresite web oficialfacebooktweeterGoogle+Instagramcanal YouTubeInstagramtextmodificaremodificarewww.technion.ac.ilnew.huji.ac.ilwww.weizmann.ac.ilwww1.biu.ac.ilenglish.tau.ac.ilwww.haifa.ac.ilin.bgu.ac.ilwww.openu.ac.ilwww.ariel.ac.ilCIA FactbookHarta Israelului"Negotiating Jerusalem," Palestine–Israel JournalThe Schizoid Nature of Modern Hebrew: A Slavic Language in Search of a Semitic Past„Arabic in Israel: an official language and a cultural bridge”„Latest Population Statistics for Israel”„Israel Population”„Tables”„Report for Selected Countries and Subjects”Human Development Report 2016: Human Development for Everyone„Distribution of family income - Gini index”The World FactbookJerusalem Law„Israel”„Israel”„Zionist Leaders: David Ben-Gurion 1886–1973”„The status of Jerusalem”„Analysis: Kadima's big plans”„Israel's Hard-Learned Lessons”„The Legacy of Undefined Borders, Tel Aviv Notes No. 40, 5 iunie 2002”„Israel Journal: A Land Without Borders”„Population”„Israel closes decade with population of 7.5 million”Time Series-DataBank„Selected Statistics on Jerusalem Day 2007 (Hebrew)”Golan belongs to Syria, Druze protestGlobal Survey 2006: Middle East Progress Amid Global Gains in FreedomWHO: Life expectancy in Israel among highest in the worldInternational Monetary Fund, World Economic Outlook Database, April 2011: Nominal GDP list of countries. Data for the year 2010.„Israel's accession to the OECD”Popular Opinion„On the Move”Hosea 12:5„Walking the Bible Timeline”„Palestine: History”„Return to Zion”An invention called 'the Jewish people' – Haaretz – Israel NewsoriginalJewish and Non-Jewish Population of Palestine-Israel (1517–2004)ImmigrationJewishvirtuallibrary.orgChapter One: The Heralders of Zionism„The birth of modern Israel: A scrap of paper that changed history”„League of Nations: The Mandate for Palestine, 24 iulie 1922”The Population of Palestine Prior to 1948originalBackground Paper No. 47 (ST/DPI/SER.A/47)History: Foreign DominationTwo Hundred and Seventh Plenary Meeting„Israel (Labor Zionism)”Population, by Religion and Population GroupThe Suez CrisisAdolf EichmannJustice Ministry Reply to Amnesty International Report„The Interregnum”Israel Ministry of Foreign Affairs – The Palestinian National Covenant- July 1968Research on terrorism: trends, achievements & failuresThe Routledge Atlas of the Arab–Israeli conflict: The Complete History of the Struggle and the Efforts to Resolve It"George Habash, Palestinian Terrorism Tactician, Dies at 82."„1973: Arab states attack Israeli forces”Agranat Commission„Has Israel Annexed East Jerusalem?”original„After 4 Years, Intifada Still Smolders”From the End of the Cold War to 2001originalThe Oslo Accords, 1993Israel-PLO Recognition – Exchange of Letters between PM Rabin and Chairman Arafat – Sept 9- 1993Foundation for Middle East PeaceSources of Population Growth: Total Israeli Population and Settler Population, 1991–2003original„Israel marks Rabin assassination”The Wye River Memorandumoriginal„West Bank barrier route disputed, Israeli missile kills 2”"Permanent Ceasefire to Be Based on Creation Of Buffer Zone Free of Armed Personnel Other than UN, Lebanese Forces"„Hezbollah kills 8 soldiers, kidnaps two in offensive on northern border”„Olmert confirms peace talks with Syria”„Battleground Gaza: Israeli ground forces invade the strip”„IDF begins Gaza troop withdrawal, hours after ending 3-week offensive”„THE LAND: Geography and Climate”„Area of districts, sub-districts, natural regions and lakes”„Israel - Geography”„Makhteshim Country”Israel and the Palestinian Territories„Makhtesh Ramon”„The Living Dead Sea”„Temperatures reach record high in Pakistan”„Climate Extremes In Israel”Israel in figures„Deuteronom”„JNF: 240 million trees planted since 1901”„Vegetation of Israel and Neighboring Countries”Environmental Law in Israel„Executive branch”„Israel's election process explained”„The Electoral System in Israel”„Constitution for Israel”„All 120 incoming Knesset members”„Statul ISRAEL”„The Judiciary: The Court System”„Israel's high court unique in region”„Israel and the International Criminal Court: A Legal Battlefield”„Localities and population, by population group, district, sub-district and natural region”„Israel: Districts, Major Cities, Urban Localities & Metropolitan Areas”„Israel-Egypt Relations: Background & Overview of Peace Treaty”„Solana to Haaretz: New Rules of War Needed for Age of Terror”„Israel's Announcement Regarding Settlements”„United Nations Security Council Resolution 497”„Security Council resolution 478 (1980) on the status of Jerusalem”„Arabs will ask U.N. to seek razing of Israeli wall”„Olmert: Willing to trade land for peace”„Mapping Peace between Syria and Israel”„Egypt: Israel must accept the land-for-peace formula”„Israel: Age structure from 2005 to 2015”„Global, regional, and national disability-adjusted life years (DALYs) for 306 diseases and injuries and healthy life expectancy (HALE) for 188 countries, 1990–2013: quantifying the epidemiological transition”10.1016/S0140-6736(15)61340-X„World Health Statistics 2014”„Life expectancy for Israeli men world's 4th highest”„Family Structure and Well-Being Across Israel's Diverse Population”„Fertility among Jewish and Muslim Women in Israel, by Level of Religiosity, 1979-2009”„Israel leaders in birth rate, but poverty major challenge”„Ethnic Groups”„Israel's population: Over 8.5 million”„Israel - Ethnic groups”„Jews, by country of origin and age”„Minority Communities in Israel: Background & Overview”„Israel”„Language in Israel”„Selected Data from the 2011 Social Survey on Mastery of the Hebrew Language and Usage of Languages”„Religions”„5 facts about Israeli Druze, a unique religious and ethnic group”„Israël”Israel Country Study Guide„Haredi city in Negev – blessing or curse?”„New town Harish harbors hopes of being more than another Pleasantville”„List of localities, in alphabetical order”„Muncitorii români, doriți în Israel”„Prietenia româno-israeliană la nevoie se cunoaște”„The Higher Education System in Israel”„Middle East”„Academic Ranking of World Universities 2016”„Israel”„Israel”„Jewish Nobel Prize Winners”„All Nobel Prizes in Literature”„All Nobel Peace Prizes”„All Prizes in Economic Sciences”„All Nobel Prizes in Chemistry”„List of Fields Medallists”„Sakharov Prize”„Țara care și-a sfidat "destinul" și se bate umăr la umăr cu Silicon Valley”„Apple's R&D center in Israel grew to about 800 employees”„Tim Cook: Apple's Herzliya R&D center second-largest in world”„Lecții de economie de la Israel”„Land use”Israel Investment and Business GuideA Country Study: IsraelCentral Bureau of StatisticsFlorin Diaconu, „Kadima: Flexibilitate și pragmatism, dar nici un compromis în chestiuni vitale", în Revista Institutului Diplomatic Român, anul I, numărul I, semestrul I, 2006, pp. 71-72Florin Diaconu, „Likud: Dreapta israeliană constant opusă retrocedării teritoriilor cureite prin luptă în 1967", în Revista Institutului Diplomatic Român, anul I, numărul I, semestrul I, 2006, pp. 73-74MassadaIsraelul a crescut in 50 de ani cât alte state intr-un mileniuIsrael Government PortalIsraelIsraelIsraelmmmmmXX451232cb118646298(data)4027808-634110000 0004 0372 0767n7900328503691455-bb46-37e3-91d2-cb064a35ffcc1003570400564274ge1294033523775214929302638955X146498911146498911

                                                    Кастелфранко ди Сопра Становништво Референце Спољашње везе Мени за навигацију43°37′18″ СГШ; 11°33′32″ ИГД / 43.62156° СГШ; 11.55885° ИГД / 43.62156; 11.5588543°37′18″ СГШ; 11°33′32″ ИГД / 43.62156° СГШ; 11.55885° ИГД / 43.62156; 11.558853179688„The GeoNames geographical database”„Istituto Nazionale di Statistica”проширитиууWorldCat156923403n850174324558639-1cb14643287r(подаци)