tasks a-s
This commit is contained in:
parent
47bf37c096
commit
b83f433714
12433 changed files with 156208 additions and 123 deletions
73
Task/Prime-decomposition/XSLT/prime-decomposition-1.xslt
Normal file
73
Task/Prime-decomposition/XSLT/prime-decomposition-1.xslt
Normal file
|
|
@ -0,0 +1,73 @@
|
|||
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
|
||||
|
||||
<xsl:template match="/numbers">
|
||||
<html>
|
||||
<body>
|
||||
<ul>
|
||||
<xsl:apply-templates />
|
||||
</ul>
|
||||
</body>
|
||||
</html>
|
||||
</xsl:template>
|
||||
|
||||
<xsl:template match="number">
|
||||
<li>
|
||||
Number:
|
||||
<xsl:apply-templates mode="value" />
|
||||
Factors:
|
||||
<xsl:apply-templates mode="factors" />
|
||||
</li>
|
||||
</xsl:template>
|
||||
|
||||
<xsl:template match="value" mode="value">
|
||||
<xsl:apply-templates />
|
||||
</xsl:template>
|
||||
|
||||
<xsl:template match="value" mode="factors">
|
||||
<xsl:call-template name="generate">
|
||||
<xsl:with-param name="number" select="number(current())" />
|
||||
<xsl:with-param name="candidate" select="number(2)" />
|
||||
</xsl:call-template>
|
||||
</xsl:template>
|
||||
|
||||
<xsl:template name="generate">
|
||||
<xsl:param name="number" />
|
||||
<xsl:param name="candidate" />
|
||||
<xsl:choose>
|
||||
<!-- 1 is no prime and does not have any factors -->
|
||||
<xsl:when test="$number = 1"></xsl:when>
|
||||
<!-- if the candidate is larger than the sqrt of the number, it's prime and the last factor -->
|
||||
<xsl:when test="$candidate * $candidate > $number">
|
||||
<xsl:value-of select="$number" />
|
||||
</xsl:when>
|
||||
<!-- if the number is factored by the candidate, add the factor and try again with the same factor -->
|
||||
<xsl:when test="$number mod $candidate = 0">
|
||||
<xsl:value-of select="$candidate" />
|
||||
<xsl:text> </xsl:text>
|
||||
<xsl:call-template name="generate">
|
||||
<xsl:with-param name="number" select="$number div $candidate" />
|
||||
<xsl:with-param name="candidate" select="$candidate" />
|
||||
</xsl:call-template>
|
||||
</xsl:when>
|
||||
<!-- else try again with the next factor -->
|
||||
<xsl:otherwise>
|
||||
<!-- increment by 2 to save stack depth -->
|
||||
<xsl:choose>
|
||||
<xsl:when test="$candidate = 2">
|
||||
<xsl:call-template name="generate">
|
||||
<xsl:with-param name="number" select="$number" />
|
||||
<xsl:with-param name="candidate" select="$candidate + 1" />
|
||||
</xsl:call-template>
|
||||
</xsl:when>
|
||||
<xsl:otherwise>
|
||||
<xsl:call-template name="generate">
|
||||
<xsl:with-param name="number" select="$number" />
|
||||
<xsl:with-param name="candidate" select="$candidate + 2" />
|
||||
</xsl:call-template>
|
||||
</xsl:otherwise>
|
||||
</xsl:choose>
|
||||
</xsl:otherwise>
|
||||
</xsl:choose>
|
||||
</xsl:template>
|
||||
|
||||
</xsl:stylesheet>
|
||||
8
Task/Prime-decomposition/XSLT/prime-decomposition-2.xslt
Normal file
8
Task/Prime-decomposition/XSLT/prime-decomposition-2.xslt
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
<numbers>
|
||||
<number><value>1</value></number>
|
||||
<number><value>2</value></number>
|
||||
<number><value>4</value></number>
|
||||
<number><value>8</value></number>
|
||||
<number><value>9</value></number>
|
||||
<number><value>255</value></number>
|
||||
</numbers>
|
||||
43
Task/Prime-decomposition/XSLT/prime-decomposition-3.xslt
Normal file
43
Task/Prime-decomposition/XSLT/prime-decomposition-3.xslt
Normal file
|
|
@ -0,0 +1,43 @@
|
|||
<html>
|
||||
<body>
|
||||
<ul>
|
||||
|
||||
<li>
|
||||
Number:
|
||||
1
|
||||
Factors:
|
||||
</li>
|
||||
|
||||
<li>
|
||||
Number:
|
||||
2
|
||||
Factors:
|
||||
2</li>
|
||||
|
||||
<li>
|
||||
Number:
|
||||
4
|
||||
Factors:
|
||||
2 2</li>
|
||||
|
||||
<li>
|
||||
Number:
|
||||
8
|
||||
Factors:
|
||||
2 2 2</li>
|
||||
|
||||
<li>
|
||||
Number:
|
||||
9
|
||||
Factors:
|
||||
3 3</li>
|
||||
|
||||
<li>
|
||||
Number:
|
||||
255
|
||||
Factors:
|
||||
3 5 17</li>
|
||||
|
||||
</ul>
|
||||
</body>
|
||||
</html>
|
||||
Loading…
Add table
Add a link
Reference in a new issue