Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
45
Task/Babbage-problem/PowerShell/babbage-problem-1.psh
Normal file
45
Task/Babbage-problem/PowerShell/babbage-problem-1.psh
Normal file
|
|
@ -0,0 +1,45 @@
|
|||
###########################################################################################
|
||||
#
|
||||
# Definitions:
|
||||
#
|
||||
# Lines that begin with the "#" symbol are comments: they will be ignored by the machine.
|
||||
#
|
||||
# -----------------------------------------------------------------------------------------
|
||||
#
|
||||
# While
|
||||
#
|
||||
# Run a command block based on the results of a conditional test.
|
||||
#
|
||||
# Syntax
|
||||
# while (condition) {command_block}
|
||||
#
|
||||
# Key
|
||||
#
|
||||
# condition If this evaluates to TRUE the loop {command_block} runs.
|
||||
# when the loop has run once the condition is evaluated again.
|
||||
#
|
||||
# command_block Commands to run each time the loop repeats.
|
||||
#
|
||||
# As long as the condition remains true, PowerShell reruns the {command_block} section.
|
||||
#
|
||||
# -----------------------------------------------------------------------------------------
|
||||
#
|
||||
# * means 'multiplied by'
|
||||
# % means 'modulo', or remainder after division
|
||||
# -ne means 'is not equal to'
|
||||
# ++ means 'increment variable by one'
|
||||
#
|
||||
###########################################################################################
|
||||
|
||||
# Declare a variable, $integer, with a starting value of 0.
|
||||
|
||||
$integer = 0
|
||||
|
||||
while (($integer * $integer) % 1000000 -ne 269696)
|
||||
{
|
||||
$integer++
|
||||
}
|
||||
|
||||
# Show the result.
|
||||
|
||||
$integer
|
||||
24
Task/Babbage-problem/PowerShell/babbage-problem-2.psh
Normal file
24
Task/Babbage-problem/PowerShell/babbage-problem-2.psh
Normal file
|
|
@ -0,0 +1,24 @@
|
|||
# Start with the smallest potential square number
|
||||
$TestSquare = 269696
|
||||
|
||||
# Test if our potential square is a square
|
||||
# by testing if the square root of it is an integer
|
||||
# Test if the square root is an integer by testing if the remainder
|
||||
# of the square root divided by 1 is greater than zero
|
||||
# % is the remainder operator
|
||||
# -gt is the "greater than" operator
|
||||
|
||||
# While the remainder of the square root divided by one is greater than zero
|
||||
While ( [Math]::Sqrt( $TestSquare ) % 1 -gt 0 )
|
||||
{
|
||||
# Add 100,000 to get the next potential square number
|
||||
$TestSquare = $TestSquare + 1000000
|
||||
}
|
||||
# This will loop until we get a value for $TestSquare that is a square number
|
||||
|
||||
# Caclulate the root
|
||||
$Root = [Math]::Sqrt( $TestSquare )
|
||||
|
||||
# Display the result and its square
|
||||
$Root
|
||||
$TestSquare
|
||||
Loading…
Add table
Add a link
Reference in a new issue