September 2017 Update

This commit is contained in:
Ingy döt Net 2017-09-23 10:01:46 +02:00
parent bba7bfd280
commit ba8067c3b7
14570 changed files with 153136 additions and 63871 deletions

View file

@ -0,0 +1,10 @@
[ 0 : 10 ]REAL a;
PROC f = ( REAL t )REAL:
sqrt(ABS t)+5*t*t*t;
FOR i FROM LWB a TO UPB a DO read( ( a[ i ] ) ) OD;
FOR i FROM UPB a BY -1 TO LWB a DO
REAL y=f(a[i]);
IF y > 400 THEN print( ( "TOO LARGE", newline ) )
ELSE print( ( fixed( y, -9, 4 ), newline ) )
FI
OD

View file

@ -0,0 +1,13 @@
scope # TPK algorithm in Agena
local y;
local a := [];
local f := proc( t :: number ) is return sqrt(abs(t))+5*t*t*t end;
for i from 0 to 10 do a[i] := tonumber( io.read() ) od;
for i from 10 to 0 by - 1 do
y:=f(a[i]);
if y > 400
then print( "TOO LARGE" )
else printf( "%10.4f\n", y )
fi
od
epocs

View file

@ -1,16 +1,16 @@
' version 22-10-2016
' version 22-07-2017
' compile with: fbc -s console
Function f(n As Double) As Double
return Sqr(Abs(n)) + 5 * n ^ 5
return Sqr(Abs(n)) + 5 * n ^ 3
End Function
' ------=< MAIN >=------
Dim As Double x, s(0 To 10)
Dim As Double x, s(1 To 11)
Dim As Long i
For i = 0 To 10
For i = 1 To 11
Print Str(i);
Input " => ", s(i)
Next
@ -18,15 +18,17 @@ Next
Print
Print String(20,"-")
For i = 10 To 0 Step -1
i -= 1
Do
Print "f(" + Str(s(i)) + ") = ";
x = f(s(i))
If x > 400 Then
Print "-=< to large >=-"
Print "-=< overflow >=-"
Else
Print x
End If
Next
i -= 1
Loop Until i < 1
' empty keyboard buffer
While InKey <> "" : Wend

View file

@ -0,0 +1,29 @@
// version 1.1.2
fun f(x: Double) = Math.sqrt(Math.abs(x)) + 5.0 * x * x * x
fun main(args: Array<String>) {
val da = DoubleArray(11)
println("Please enter 11 numbers:")
var i = 0
while (i < 11) {
print(" ${"%2d".format(i + 1)}: ")
val d = readLine()!!.toDoubleOrNull()
if (d == null)
println("Not a valid number, try again")
else
da[i++] = d
}
println("\nThe sequence you just entered in reverse is:")
da.reverse()
println(da.contentToString())
println("\nProcessing this sequence...")
for (j in 0..10) {
val v = f(da[j])
print(" ${"%2d".format(j + 1)}: ")
if (v > 400.0)
println("Overflow!")
else
println(v)
}
}

View file

@ -0,0 +1,16 @@
function f(atom x)
return sqrt(abs(x))+5*power(x,3)
end function
string s = substitute(prompt_string("Enter 11 numbers:"),","," ")
sequence S = scanf(s,"%f %f %f %f %f %f %f %f %f %f %f")
if length(S)!=1 then puts(1,"not 11 numbers") abort(0) end if
S = reverse(S[1])
for i=1 to length(S) do
atom result = f(S[i])
if result>400 then
printf(1,"f(%g):overflow\n",{S[i]})
else
printf(1,"f(%g):%g\n",{S[i],result})
end if
end for

View file

@ -0,0 +1,49 @@
function Get-Tpk
{
[CmdletBinding()]
[OutputType([PSCustomObject])]
Param
(
[Parameter(Mandatory=$true,
ValueFromPipeline=$true,
ValueFromPipelineByPropertyName=$true,
Position=0)]
[double]
$Number
)
Begin
{
function Get-TpkFunction ([double]$Number)
{
[Math]::Pow([Math]::Abs($Number),(0.5)) + 5 * [Math]::Pow($Number,3)
}
[object[]]$output = @()
}
Process
{
$Number | ForEach-Object {
$n = Get-TpkFunction $_
if ($n -le 400)
{
$result = $n
}
else
{
$result = "Overflow"
}
}
$output += [PSCustomObject]@{
Number = $Number
Result = $result
}
}
End
{
[Array]::Reverse($output)
$output
}
}

View file

@ -0,0 +1,2 @@
$tpk = 1..11 | Get-Tpk
$tpk

View file

@ -0,0 +1 @@
$tpk | where result -ne overflow | sort number

View file

@ -0,0 +1,12 @@
10 DIM A(11)
20 PRINT "ENTER ELEVEN NUMBERS:"
30 FOR I=1 TO 11
40 INPUT A(I)
50 NEXT I
60 FOR I=11 TO 1 STEP -1
70 LET Y=SQR ABS A(I)+5*A(I)**3
80 IF Y<=400 THEN GOTO 110
90 PRINT A(I),"TOO LARGE"
100 GOTO 120
110 PRINT A(I),Y
120 NEXT I

View file

@ -0,0 +1,8 @@
fcn f(x) { x.abs().pow(0.5) + x.pow(3)*5 }
reg ns; do{
ns=ask("11 numbers seperated by spaces: ");
try{ ns=ns.split(" ").filter().apply("toFloat") } catch{}
}while(not ns.isType(List) or ns.len()!=11);
ns.reverse().apply(fcn(x){
fx:=f(x); "f(%7.3f)-->%s".fmt(x, if(fx>400)"Overflow" else fx) })
.pump(Console.println);