Data update
This commit is contained in:
parent
157b70a810
commit
8e4e15fa56
|
|
@ -0,0 +1 @@
|
|||
../../Task/Sierpinski-triangle-Graphical/Ada
|
||||
|
|
@ -0,0 +1 @@
|
|||
{{stub}}{{language|AutoHotKey V2}}
|
||||
|
|
@ -0,0 +1,2 @@
|
|||
---
|
||||
from: http://rosettacode.org/wiki/Category:AutoHotKey_V2
|
||||
|
|
@ -0,0 +1 @@
|
|||
../../Task/Hello-world-Graphical/AutoHotKey-V2
|
||||
|
|
@ -1,16 +0,0 @@
|
|||
{{stub}}AutoHotkey V2 is an [[open source]] programming language for Microsoft [[Windows]].
|
||||
|
||||
AutoHotkey v2 is a major update to the AutoHotkey language, which includes numerous new features and improvements.
|
||||
|
||||
== Citations ==
|
||||
|
||||
* [https://www.autohotkey.com/docs/v2/ Documentation]
|
||||
* [http://autohotkey.com/download Downloads]
|
||||
* [http://autohotkey.com/docs/scripts/ Script Showcase]
|
||||
* [http://autohotkey.com/boards/ New Community forum]
|
||||
* [http://www.autohotkey.com/forum/ Archived Community forum]
|
||||
* [http://ahkscript.org/foundation AutoHotkey Foundation LLC]
|
||||
* [[wp:AutoHotkey|AutoHotkey on Wikipedia]]
|
||||
* <span class="external text" rel="mw:ExtLink nofollow">#ahk</span> on [http://webchat.freenode.net/?channels=%23ahk Freenode Web interface]
|
||||
* [[:Category:AutoHotkey_Originated]]
|
||||
{{language|Ayrch}}
|
||||
|
|
@ -1,2 +0,0 @@
|
|||
---
|
||||
from: http://rosettacode.org/wiki/Category:Autohotkey_V2
|
||||
|
|
@ -1 +0,0 @@
|
|||
../../Task/Hello-world-Graphical/Autohotkey-V2
|
||||
|
|
@ -0,0 +1 @@
|
|||
../../Task/Functional-coverage-tree/C++
|
||||
|
|
@ -0,0 +1 @@
|
|||
../../Task/Ukkonen-s-suffix-tree-construction/C++
|
||||
|
|
@ -0,0 +1 @@
|
|||
../../Task/Substitution-cipher/Common-Lisp
|
||||
|
|
@ -0,0 +1 @@
|
|||
../../Task/Brilliant-numbers/Free-Pascal-Lazarus
|
||||
|
|
@ -0,0 +1 @@
|
|||
../../Task/Metallic-ratios/FreeBASIC
|
||||
|
|
@ -0,0 +1 @@
|
|||
../../Task/Percolation-Mean-cluster-density/FreeBASIC
|
||||
|
|
@ -0,0 +1 @@
|
|||
../../Task/Web-scraping/FreeBASIC
|
||||
|
|
@ -0,0 +1 @@
|
|||
../../Task/ADFGVX-cipher/FutureBasic
|
||||
|
|
@ -0,0 +1 @@
|
|||
../../Task/Damm-algorithm/FutureBasic
|
||||
|
|
@ -0,0 +1 @@
|
|||
../../Task/Magic-constant/FutureBasic
|
||||
|
|
@ -0,0 +1 @@
|
|||
../../Task/Mouse-position/Haskell
|
||||
|
|
@ -0,0 +1 @@
|
|||
../../Task/Averages-Root-mean-square/M2000-Interpreter
|
||||
|
|
@ -0,0 +1 @@
|
|||
../../Task/Idiomatically-determine-all-the-characters-that-can-be-used-for-symbols/M2000-Interpreter
|
||||
|
|
@ -0,0 +1 @@
|
|||
../../Task/Fivenum/PascalABC.NET
|
||||
|
|
@ -0,0 +1 @@
|
|||
../../Task/Fork/PascalABC.NET
|
||||
|
|
@ -0,0 +1 @@
|
|||
../../Task/Gamma-function/PascalABC.NET
|
||||
|
|
@ -31,7 +31,12 @@ It is both.
|
|||
There is NO complete source code in another language; the system was bootstrapped in a Pascal-like language (which is no longer available) and was later re-written entirely in Plain English.
|
||||
It is "Machine Code" Low Level: The bootstrap is very basic, only able to copy itself and add raw machine code in Intel hex format, make calls to the operating system, e.g.
|
||||
<syntaxhighlight lang="text">
|
||||
Call "kernel32.dll" "SetFilePointer" with the file and 0 and 0 and 2 [file_end] returning a result number.
|
||||
Call "kernel32.dll" "SetFilePointer" with
|
||||
the file [hFile]
|
||||
and 0 [lDistanceToMove]
|
||||
and 0 [lpDistanceToMoveHigh]
|
||||
and 2 [file_end / dwMoveMethod]
|
||||
returning a result number.
|
||||
</syntaxhighlight>
|
||||
and call other DLLs e.g.
|
||||
<syntaxhighlight lang="text">
|
||||
|
|
|
|||
|
|
@ -0,0 +1 @@
|
|||
../../Task/Brilliant-numbers/Ring
|
||||
|
|
@ -0,0 +1 @@
|
|||
../../Task/Composite-numbers-k-with-no-single-digit-factors-whose-factors-are-all-substrings-of-k/Ring
|
||||
|
|
@ -0,0 +1 @@
|
|||
../../Task/Selectively-replace-multiple-instances-of-a-character-within-a-string/Ring
|
||||
|
|
@ -0,0 +1 @@
|
|||
../../Task/Real-constants-and-functions/S-BASIC
|
||||
|
|
@ -0,0 +1 @@
|
|||
../../Task/Execute-Brain-/SmileBASIC
|
||||
|
|
@ -1 +0,0 @@
|
|||
../../Task/Character-codes/Tcl
|
||||
|
|
@ -1,52 +1,54 @@
|
|||
To create some doors given a count:
|
||||
Loop.
|
||||
If a counter is past the count, exit.
|
||||
Allocate memory for a door.
|
||||
Clear the door's flag.
|
||||
Append the door to the doors.
|
||||
Repeat.
|
||||
Loop.
|
||||
If a counter is past the count, exit.
|
||||
Allocate memory for a door.
|
||||
Clear the door's flag.
|
||||
Append the door to the doors.
|
||||
Repeat.
|
||||
|
||||
A flag thing is a thing with a flag.
|
||||
A door is a flag thing.
|
||||
|
||||
To go through some doors given a number and some passes:
|
||||
Put 0 into a counter.
|
||||
Loop.
|
||||
Add the number to the counter.
|
||||
If the counter is greater than the passes, exit.
|
||||
Pick a door from the doors given the number.
|
||||
Invert the door's flag.
|
||||
Repeat.
|
||||
Put 0 into a counter.
|
||||
Loop.
|
||||
Add the number to the counter.
|
||||
If the counter is greater than the passes, exit.
|
||||
Pick a door from the doors given the number.
|
||||
Invert the door's flag.
|
||||
Repeat.
|
||||
|
||||
To output the states of some doors:
|
||||
Loop.
|
||||
Bump a counter.
|
||||
Get a door from the doors.
|
||||
If the door is nil, exit.
|
||||
If the door's flag is set, write "Door " then the counter then " is open" to the output; repeat.
|
||||
Write "Door " then the counter then " is closed" to the output.
|
||||
Repeat.
|
||||
Loop.
|
||||
Bump a counter.
|
||||
Get a door from the doors.
|
||||
If the door is nil, exit.
|
||||
If the door's flag is set,
|
||||
Write "Door " then the counter then " is open" to the output;
|
||||
Repeat.
|
||||
Write "Door " then the counter then " is closed" to the output.
|
||||
Repeat.
|
||||
|
||||
To pass doors given a count and some passes:
|
||||
Create some doors given the count.
|
||||
Loop.
|
||||
If a counter is past the passes, break.
|
||||
Go through the doors given the counter and the passes.
|
||||
Repeat.
|
||||
Output the states of the doors.
|
||||
Destroy the doors.
|
||||
Create some doors given the count.
|
||||
Loop.
|
||||
If a counter is past the passes, break.
|
||||
Go through the doors given the counter and the passes.
|
||||
Repeat.
|
||||
Output the states of the doors.
|
||||
Destroy the doors.
|
||||
|
||||
A pass is a number.
|
||||
|
||||
To pick a door from some doors given a number:
|
||||
Loop.
|
||||
If a counter is past the number, exit.
|
||||
Get the door from the doors.
|
||||
If the door is nil, exit.
|
||||
Repeat.
|
||||
Loop.
|
||||
If a counter is past the number, exit.
|
||||
Get the door from the doors.
|
||||
If the door is nil, exit.
|
||||
Repeat.
|
||||
|
||||
To run:
|
||||
Start up.
|
||||
Pass doors given 100 and 100 passes.
|
||||
Wait for the escape key.
|
||||
Shut down.
|
||||
Start up.
|
||||
Pass doors given 100 and 100 passes.
|
||||
Wait for the escape key.
|
||||
Shut down.
|
||||
|
|
|
|||
|
|
@ -1,26 +1,32 @@
|
|||
To run:
|
||||
Start up.
|
||||
Sing 99 of bottles of beer on the wall.
|
||||
Wait for the escape key.
|
||||
Shut down.
|
||||
Start up.
|
||||
Sing 99 of bottles of beer on the wall.
|
||||
Wait for the escape key.
|
||||
Shut down.
|
||||
|
||||
To sing a number of bottles of beer on the wall:
|
||||
Put the number into a counter.
|
||||
Loop.
|
||||
Write the first line given the counter.
|
||||
Write the second line given the counter.
|
||||
Write "Take one down, pass it around" to the console.
|
||||
Subtract 1 from the counter.
|
||||
Write the first line given the counter.
|
||||
If the counter is 0, break.
|
||||
Write "" on the console.
|
||||
Repeat.
|
||||
Put the number into a counter.
|
||||
Loop.
|
||||
Write the first line given the counter.
|
||||
Write the second line given the counter.
|
||||
Write "Take one down, pass it around" to the console.
|
||||
Subtract 1 from the counter.
|
||||
Write the first line given the counter.
|
||||
If the counter is 0, break.
|
||||
Write "" on the console.
|
||||
Repeat.
|
||||
|
||||
To write the first line given a counter:
|
||||
If the counter is 0, write "No more bottles of beer on the wall" to the console; exit.
|
||||
If the counter is 1, write "1 bottle of beer on the wall" to the console; exit.
|
||||
Write the counter then " bottles of beer on the wall" to the console.
|
||||
If the counter is 0,
|
||||
Write "No more bottles of beer on the wall" to the console;
|
||||
Exit.
|
||||
If the counter is 1,
|
||||
Write "1 bottle of beer on the wall" to the console;
|
||||
Exit.
|
||||
Write the counter then " bottles of beer on the wall" to the console.
|
||||
|
||||
To write the second line given a counter:
|
||||
If the counter is 1, write "1 bottle of beer" to the console; exit.
|
||||
Write the counter then " bottles of beer" to the console.
|
||||
If the counter is 1,
|
||||
Write "1 bottle of beer" to the console;
|
||||
Exit.
|
||||
Write the counter then " bottles of beer" to the console.
|
||||
|
|
|
|||
|
|
@ -1,17 +1,21 @@
|
|||
To run:
|
||||
Start up.
|
||||
Read a number from the console.
|
||||
Read another number from the console.
|
||||
Output the sum of the number and the other number.
|
||||
Wait for the escape key.
|
||||
Shut down.
|
||||
Start up.
|
||||
Read a number from the console.
|
||||
Read another number from the console.
|
||||
Output the sum of the number and the other number.
|
||||
Wait for the escape key.
|
||||
Shut down.
|
||||
|
||||
To output the sum of a number and another number:
|
||||
If the number is not valid, write "Invalid input" to the console; exit.
|
||||
If the other number is not valid, write "Invalid input" to the console; exit.
|
||||
Write the number plus the other number then " is the sum." to the console.
|
||||
If the number is not valid,
|
||||
Write "Invalid input" to the console;
|
||||
Exit.
|
||||
If the other number is not valid,
|
||||
Write "Invalid input" to the console;
|
||||
Exit.
|
||||
Write the number plus the other number then " is the sum." to the console.
|
||||
|
||||
To decide if a number is valid:
|
||||
If the number is not greater than or equal to -1000, say no.
|
||||
If the number is not less than or equal to 1000, say no.
|
||||
Say yes.
|
||||
If the number is not greater than or equal to -1000, say no.
|
||||
If the number is not less than or equal to 1000, say no.
|
||||
Say yes.
|
||||
|
|
|
|||
|
|
@ -0,0 +1,208 @@
|
|||
/*
|
||||
ADFGVX cipher
|
||||
https://rosettacode.org/wiki/ADFGVX_cipher
|
||||
|
||||
Requires file, unixdict.txt to be on the desktop
|
||||
https://github.com/quinnj/Rosetta-Julia/blob/master/unixdict.txt
|
||||
|
||||
*/
|
||||
|
||||
begin globals
|
||||
|
||||
str255 ADFGVX
|
||||
ADFGVX = "ADFGVX"
|
||||
str255 ALPHABET
|
||||
ALPHABET = "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"
|
||||
|
||||
end globals
|
||||
|
||||
local fn InitialisePolybiusSquare As str255
|
||||
short i, j
|
||||
|
||||
str255 letters(36)
|
||||
For i = 0 To 35
|
||||
letters(i) = Mid$(ALPHABET, i + 1, 1)
|
||||
Next
|
||||
|
||||
For i = 0 To 35
|
||||
j = Int(rnd (36))
|
||||
Swap letters(i), letters(j)
|
||||
Next
|
||||
|
||||
short row, column
|
||||
str255 result
|
||||
result = ""
|
||||
For row = 0 To 5
|
||||
For column = 0 To 5
|
||||
result = result + letters(6 * row + column)
|
||||
Next
|
||||
Next
|
||||
|
||||
End fn = result
|
||||
|
||||
local fn CreateKey(size As short) As str255
|
||||
If size < 7 Or size > 12
|
||||
Print "Key should contain between 7 and 12 letters, both inclusive."
|
||||
Exit fn
|
||||
End If
|
||||
|
||||
short i, j
|
||||
str255 TheWord, candidates(1000)
|
||||
short ff = 1 // file number
|
||||
|
||||
short CandidatesCounter = 1
|
||||
|
||||
CFUrlRef ParentDirectory = fn FileManagerURLForDirectory( NSDesktopDirectory, NSUserDomainMask )
|
||||
CFUrlRef UnixDictURL = fn URLByAppendingPathComponent( ParentDirectory, @"unixdict.txt" )
|
||||
|
||||
|
||||
Open "I",ff, UnixDictURL
|
||||
While Eof(ff) = 0
|
||||
Line Input #ff, TheWord
|
||||
|
||||
str255 uniqueWord
|
||||
uniqueWord = ""
|
||||
For i = 1 To Len$(TheWord)
|
||||
If Instr$(1,uniqueWord, Mid$(TheWord, i, 1)) = 0
|
||||
uniqueWord = uniqueWord + Mid$(TheWord, i, 1)
|
||||
End If
|
||||
Next
|
||||
|
||||
If Len$(TheWord) = size && Len$(TheWord) = Len$(uniqueWord)
|
||||
TheWord = Ucase$(TheWord)
|
||||
|
||||
bool isAlphanum = _true
|
||||
For i = 1 To Len$(TheWord)
|
||||
If (Mid$(TheWord, i, 1) < "A" && Mid$(TheWord, i, 1) <= "Z") && (Mid$(TheWord, i, 1) < "0" && Mid$(TheWord, i, 1) <= "9")
|
||||
isAlphanum = _false
|
||||
Exit For
|
||||
End If
|
||||
Next
|
||||
|
||||
|
||||
If isAlphanum
|
||||
//Redim Preserve candidates(Ubound(candidates) + 1)
|
||||
CandidatesCounter ++
|
||||
candidates(CandidatesCounter) = TheWord
|
||||
End If
|
||||
End If
|
||||
Wend
|
||||
Close #ff
|
||||
|
||||
|
||||
|
||||
For i = 0 To CandidatesCounter
|
||||
j = Int(Rnd (CandidatesCounter + 1))
|
||||
Swap candidates(i), candidates(j)
|
||||
Next
|
||||
|
||||
End fn = candidates(0)
|
||||
|
||||
local fn Encrypt(plainText As str255, polybius As str255, key As str255) As str255
|
||||
short i, j, row, column
|
||||
str255 code, ch, encrypted
|
||||
|
||||
code = ""
|
||||
For i = 1 To Len$(plainText)
|
||||
ch = Mid$(plainText, i, 1)
|
||||
For row = 0 To 5
|
||||
For column = 0 To 5
|
||||
If Mid$(polybius, row * 6 + column + 1, 1) = ch
|
||||
code = code + Mid$(ADFGVX, row + 1, 1)
|
||||
code = code + Mid$(ADFGVX, column + 1, 1)
|
||||
End If
|
||||
Next
|
||||
Next
|
||||
Next
|
||||
|
||||
encrypted = ""
|
||||
For i = 1 To Len$(key)
|
||||
ch = Mid$(key, i, 1)
|
||||
For j = Instr$(1,key, ch) - 1 To Len$(code) - 1 Step Len$(key)
|
||||
encrypted = encrypted + Mid$(code, j + 1, 1)
|
||||
Next
|
||||
encrypted = encrypted + " "
|
||||
Next
|
||||
|
||||
|
||||
End fn = encrypted
|
||||
|
||||
local fn Decrypt(encryptedText As str255, polybius As str255, key As str255) As str255
|
||||
short i, j, row, column, spaceCount, codeSize
|
||||
str255 result, stream, TheWord, code, plainText
|
||||
str255 blocks(200)
|
||||
short BlocksCounter = 1
|
||||
result = ""
|
||||
i = 1
|
||||
While i <= Len$(encryptedText)
|
||||
If Mid$(encryptedText, i, 1) = " "
|
||||
i += 1
|
||||
Else
|
||||
result += Mid$(encryptedText, i, 1)
|
||||
i += 1
|
||||
End If
|
||||
Wend
|
||||
spaceCount = Len$(encryptedText) - Len$(result)
|
||||
codeSize = Len$(encryptedText) - spaceCount
|
||||
|
||||
|
||||
stream = encryptedText
|
||||
While Len$(stream) > 0
|
||||
TheWord = Left$(stream, Instr$(1,stream, " ") - 1)
|
||||
//Redim Preserve blocks(Ubound(blocks) + 1)
|
||||
BlocksCounter ++
|
||||
blocks(BlocksCounter) = TheWord
|
||||
stream = Mid$(stream, Instr$(1,stream, " ") + 1)
|
||||
Wend
|
||||
|
||||
code = ""
|
||||
For i = 0 To codeSize - 1
|
||||
BlocksCounter ++
|
||||
For j = 0 To BlocksCounter
|
||||
If Len$(code) < codeSize Then code = code + Mid$(blocks(j), i + 1, 1)
|
||||
Next
|
||||
Next
|
||||
|
||||
plainText = ""
|
||||
For i = 1 To codeSize - 1 Step 2
|
||||
row = Instr$(1,ADFGVX, Mid$(code, i, 1)) - 1
|
||||
column = Instr$(1,ADFGVX, Mid$(code, i + 1, 1)) - 1
|
||||
plainText = plainText + Mid$(polybius, row * 6 + column + 1, 1)
|
||||
Next
|
||||
|
||||
|
||||
End fn = plainText
|
||||
|
||||
str255 polybius
|
||||
polybius = fn InitialisePolybiusSquare
|
||||
Print "The 6 x 6 Polybius square:"
|
||||
Print " | A D F G V X"
|
||||
Print "--------------"
|
||||
short row
|
||||
For row = 0 To 5
|
||||
Print Mid$(ADFGVX, row + 1, 1); "|";
|
||||
short column
|
||||
For column = 0 To 5
|
||||
Print " "; Mid$(polybius, row * 6 + column + 1, 1);
|
||||
Next
|
||||
Print
|
||||
Next
|
||||
|
||||
str255 key
|
||||
key = fn CreateKey(9)
|
||||
print
|
||||
Print "The key is "; key
|
||||
str255 plainText
|
||||
plainText = "ATTACKAT1200AM"// 20241105
|
||||
print
|
||||
Print "Plain text: "; plainText
|
||||
str255 encryptedText
|
||||
encryptedText = fn Encrypt(plainText, polybius, key)
|
||||
print
|
||||
Print "Encrypted: "; encryptedText
|
||||
str255 decryptedText
|
||||
decryptedText = fn Decrypt(encryptedText, polybius, key)
|
||||
print
|
||||
Print "Decrypted: "; decryptedText
|
||||
|
||||
handleevents
|
||||
|
|
@ -1,4 +1,30 @@
|
|||
module Anonymus_lambda {
|
||||
Print lambda (x as long long)->{=If(x>1->lambda(x-1)+lambda(x-2), x)}(10)=55
|
||||
Module Anonymus_lambda (x, result){
|
||||
global Err = lambda (x) ->{
|
||||
if x=1 then Error "Negative input"
|
||||
}
|
||||
' in one line - so Error have to call it through a global function
|
||||
Print lambda (x as long long)->{=if(x<0->Err(1), lambda (x)->{=If(x>1->lambda(x-1)+lambda(x-2), x)}(x))}(x)=result
|
||||
}
|
||||
Anonymus_Lambda
|
||||
Anonymus_Lambda 10, 55
|
||||
Anonymus_Lambda 7, 13
|
||||
Try Ok {
|
||||
Anonymus_Lambda -7, 13 ' return false, and also we have error
|
||||
' so here we exit from block - no printing "nothing"
|
||||
Print "nothing"
|
||||
}
|
||||
If error or not ok then Report Error$
|
||||
Module Anonymus_lambda (x, result){
|
||||
' Using multiple lines for the Lambda - so Error can be used here
|
||||
Print lambda (x as long long)->{
|
||||
if x<0 then Error "Negative input"
|
||||
=lambda (x)->{=If(x>1->lambda(x-1)+lambda(x-2), x)}(x)
|
||||
}(x)=result
|
||||
}
|
||||
Anonymus_Lambda 10, 55
|
||||
Anonymus_Lambda 7, 13
|
||||
Try Ok {
|
||||
Anonymus_Lambda -7, 13 ' nothing return we have error
|
||||
' so here we exit from block - no printing "nothing"
|
||||
Print "nothing"
|
||||
}
|
||||
If error or not ok then Report Error$
|
||||
|
|
|
|||
|
|
@ -0,0 +1,16 @@
|
|||
Module TestThis {
|
||||
Locale 1033 ' this choose dot for decimals
|
||||
feed=lambda m=1->{=m:m++}
|
||||
fold1=lambda (a, s)->{push a*a+s}
|
||||
|
||||
feed1=feed
|
||||
Dim Vector1(1 To 10) As Single<<feed1()
|
||||
Print "Quadratic mean (or RMS) is :";sqrt(Vector1()#fold(fold1, 0)/Len(Vector1()))
|
||||
Print Type$(Vector1(10))="Single", Vector1(10)=10
|
||||
|
||||
feed1=feed ' reset feed1
|
||||
Dim Vector2(-100 To 1) as Byte<<feed1()
|
||||
Print "Quadratic mean (or RMS) is :";sqrt(Vector2()#fold(fold1, 0)/Len(Vector2()))
|
||||
Print Type$(Vector2(-100))="Byte", Vector2(-100)=1
|
||||
}
|
||||
TestThis
|
||||
|
|
@ -44,7 +44,6 @@ module Babylonian_spiral (max=40) {
|
|||
next
|
||||
for i=0 to len(xyDeltas)-2
|
||||
Return xyDeltas, i+1:=@add(xyDeltas#val(i+1), xyDeltas#val(i))
|
||||
|
||||
next
|
||||
Drawing 12000, 12000 {
|
||||
Cls, 0
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
T Colour = BVec3
|
||||
T Colour = Vec3b
|
||||
|
||||
V black = Colour(0, 0, 0)
|
||||
V white = Colour(255, 255, 255)
|
||||
|
|
|
|||
|
|
@ -0,0 +1,230 @@
|
|||
program BrilliantNumbers;
|
||||
{$IFDEF FPC}
|
||||
{$MODE Delphi}
|
||||
{$Optimization ON,All}
|
||||
{$ENDIF}
|
||||
{$IFDEF WINDOWS}
|
||||
{$APPTYPE CONSOLE}
|
||||
{$ENDIF}
|
||||
|
||||
uses
|
||||
SysUtils,classes;
|
||||
const
|
||||
MaxRoot = 100*1000*1000+2310;//+2310 to get next prime beyond limit
|
||||
type
|
||||
tPrimeDelta = array of Uint8;
|
||||
tBrilliant = record
|
||||
pMin, // start for dgtcnt
|
||||
pMid, // start for dgtcnt+1
|
||||
pMax, // end for dgtcnt+1
|
||||
MinIdx,
|
||||
MidIdx,
|
||||
MaxIdx : Uint32;
|
||||
end;
|
||||
var
|
||||
BrilliantPos :array [0..8] of TBrilliant;
|
||||
OddPowP : Uint32;
|
||||
|
||||
function BuildWheel(var primes: tPrimeDelta): longint;
|
||||
//pre-sieve with small primes,returns the last used prime
|
||||
var
|
||||
//wheelprimes = 2,3,5,7,11. ;wheelsize = product[i= 0..wpno-1]wheelprimes[i] > Uint64|i> 13
|
||||
wheelprimes: array[0..15] of byte;
|
||||
wheelSize, wpno, pr, pw, i, k: longword;
|
||||
begin
|
||||
pr := 1;
|
||||
primes[1] := 1;
|
||||
WheelSize := 1;
|
||||
wpno := 0;
|
||||
repeat
|
||||
Inc(pr);
|
||||
pw := pr;
|
||||
if pw > wheelsize then
|
||||
Dec(pw, wheelsize);
|
||||
if Primes[pw]<>0 then
|
||||
begin
|
||||
k := WheelSize + 1;
|
||||
for i := 1 to pr - 1 do
|
||||
begin
|
||||
Inc(k, WheelSize);
|
||||
if k < High(primes) then
|
||||
move(primes[1], primes[k - WheelSize], WheelSize)
|
||||
else
|
||||
begin
|
||||
move(primes[1], primes[k - WheelSize], High(primes) - WheelSize * i);
|
||||
break;
|
||||
end;
|
||||
end;
|
||||
Dec(k);
|
||||
if k > High(primes) then
|
||||
k := High(primes);
|
||||
wheelPrimes[wpno] := pr;
|
||||
primes[pr] := 0;
|
||||
|
||||
i := sqr(pr);
|
||||
while i <= k do
|
||||
begin
|
||||
primes[i] := 0;
|
||||
Inc(i, pr);
|
||||
end;
|
||||
|
||||
Inc(wpno);
|
||||
WheelSize := k;
|
||||
end;
|
||||
until WheelSize >= High(primes);
|
||||
while wpno > 0 do
|
||||
begin
|
||||
Dec(wpno);
|
||||
primes[wheelPrimes[wpno]] := 1;
|
||||
end;
|
||||
Result := pr;
|
||||
end;
|
||||
|
||||
procedure Sieve(var primes: tPrimeDelta);
|
||||
var
|
||||
pPrime: pUint8;
|
||||
sieveprime, delFact: longword;
|
||||
begin
|
||||
sieveprime := BuildWheel(primes);
|
||||
pPrime := @primes[0];
|
||||
repeat
|
||||
repeat
|
||||
Inc(sieveprime);
|
||||
until pPrime[sieveprime]<>0;
|
||||
delFact := High(primes) div sieveprime;
|
||||
if delFact < sieveprime then
|
||||
BREAK;
|
||||
inc(delFact);
|
||||
repeat
|
||||
repeat
|
||||
Dec(delFact);
|
||||
until pPrime[delFact]<>0;
|
||||
pPrime[sieveprime * delFact] := 0;
|
||||
until delFact < sieveprime;
|
||||
until False;
|
||||
primes[1] := 0;
|
||||
end;
|
||||
|
||||
procedure GetPrimeDelta(var prD:tPrimeDelta;size: int32);
|
||||
var
|
||||
pPD : pUint8;
|
||||
idx,LastP,p : Uint32;
|
||||
Begin
|
||||
setlength(prD, 0);
|
||||
setlength(prD, size + 1);
|
||||
Sieve(prD);
|
||||
pPD := @prD[0];
|
||||
idx := 0;
|
||||
LastP := 0;
|
||||
p := 0;
|
||||
repeat
|
||||
if pPD[p] <> 0 then
|
||||
begin
|
||||
pPD[idx] := p-LastP;
|
||||
LastP := p;
|
||||
inc(idx);
|
||||
end;
|
||||
inc(p);
|
||||
until p> Size;
|
||||
Setlength(prD,idx);
|
||||
end;
|
||||
|
||||
function Cnt_First_DgtCnt(pPD:pUint8;lmt:UInt64;dgtCnt: Int32):nativeUint;
|
||||
//counting products of prime factors smaller than limit
|
||||
var
|
||||
pLo,pHi,iLo,iHi : UInt64;
|
||||
begin
|
||||
with BrilliantPos[dgtCnt] do
|
||||
begin
|
||||
pLo := pMin;
|
||||
iLO := MinIdx;
|
||||
pHi := pMid;
|
||||
iHi := MidIdx;
|
||||
end;
|
||||
result := iHi-iLo+1;
|
||||
repeat
|
||||
iLo+=1;
|
||||
pLO := pLo+pPD[iLo];
|
||||
if pLo = pHi then
|
||||
begin
|
||||
if sqr(pLo) < Lmt then
|
||||
pLO := pLo+pPD[iLo+1];
|
||||
OddPowP := pLo;
|
||||
EXIT(result+1);
|
||||
end;
|
||||
while (pHi >= pLo) AND (pHi*pLo > lmt) do
|
||||
begin
|
||||
pHi := pHi-pPD[iHi];
|
||||
iHi-=1;
|
||||
end;
|
||||
result += iHi-iLo+1;
|
||||
until (pHi < pLo);
|
||||
OddPowP := pLo;
|
||||
end;
|
||||
|
||||
procedure GetLimitPos(pPD:pUint8;MaxPrIdx:NativeUint);
|
||||
var
|
||||
lmt, p,pmin,idx1,dgtCnt : nativeuint;
|
||||
DeltaMax,DeltaMin,TotCnt: Uint64;
|
||||
begin
|
||||
lmt := 10;
|
||||
p := 0;
|
||||
idx1 := 0;
|
||||
dgtCnt := 0;
|
||||
TotCnt := 0;
|
||||
p += pPD[idx1];
|
||||
repeat
|
||||
BrilliantPos[dgtCnt].pMin:= p;
|
||||
BrilliantPos[dgtCnt].MinIdx := idx1;
|
||||
write('10^',2*dgtCnt+1:2,':',p:10);
|
||||
pMin := p;
|
||||
while (pMin*p < lmt) and (idx1 < MaxPrIdx) do
|
||||
begin
|
||||
idx1 += 1;
|
||||
p += pPD[idx1];
|
||||
end;
|
||||
pMin := p-pPD[idx1];
|
||||
BrilliantPos[dgtCnt].pMid := pMin;
|
||||
BrilliantPos[dgtCnt].MidIdx := idx1-1;
|
||||
DeltaMin := Cnt_First_DgtCnt(pPD,lmt,dgtCnt);
|
||||
writeln(DeltaMin:20,TotCnt+DeltaMin:20);
|
||||
lmt *=10;
|
||||
while (p*p <= lmt) AND (idx1 < MaxPrIdx) do
|
||||
begin
|
||||
idx1 += 1;
|
||||
p += pPD[idx1];
|
||||
end;
|
||||
pMin := p-pPD[idx1];
|
||||
BrilliantPos[dgtCnt].pMax := pMin;
|
||||
BrilliantPos[dgtCnt].MaxIdx := idx1-1;
|
||||
|
||||
//for both decimals just summation formula
|
||||
deltaMax := idx1-BrilliantPos[dgtCnt].MinIdx;
|
||||
deltaMax := (deltaMax*(deltaMax+1) DIV 2);
|
||||
TotCnt += deltaMax;
|
||||
write('10^',2*dgtCnt+2:2,':',OddPowP:10);
|
||||
writeln(DeltaMax-DeltaMin:20,TotCnt:20);
|
||||
dgtCnt += 1;
|
||||
lmt*=10;
|
||||
until (idx1 >= MaxPrIdx) or(lmt>sqr(MaxRoot));
|
||||
writeln(p:16);
|
||||
end;
|
||||
|
||||
var
|
||||
primeDelta :TprimeDelta;
|
||||
T : INt64;
|
||||
pPD : pUint8;
|
||||
begin
|
||||
T := GetTickCount64;
|
||||
GetPrimeDelta(primeDelta,MaxRoot);
|
||||
Writeln('Sieving in ',GetTickCount64-T,' ms');
|
||||
T := GetTickCount64;
|
||||
pPD := @primeDelta[0];
|
||||
// 10^ 1: 2 3 3
|
||||
writeln('Limit first prime deltaCount Total Count');
|
||||
GetLimitPos(pPD,High(primeDelta));
|
||||
Writeln('Counting in ',GetTickCount64-T,' ms');
|
||||
{$IFDEF WINDOWS}
|
||||
readln;
|
||||
{$ENDIF}
|
||||
end.
|
||||
|
|
@ -0,0 +1,126 @@
|
|||
load "stdlib.ring"
|
||||
|
||||
n = 0
|
||||
num = 0
|
||||
flag = 0
|
||||
Result = []
|
||||
while true
|
||||
n = n + 1
|
||||
deco = []
|
||||
prime = n
|
||||
decomp1(deco,prime)
|
||||
decomp2()
|
||||
decomp3()
|
||||
if flag = 1
|
||||
add(Result,prime)
|
||||
if num = 100
|
||||
exit
|
||||
ok
|
||||
ok
|
||||
end
|
||||
|
||||
for n = 1 to len(Result)
|
||||
if len(string(Result[n])) = 1
|
||||
see " " + Result[n]
|
||||
ok
|
||||
if len(string(Result[n])) = 2
|
||||
see " " + Result[n]
|
||||
ok
|
||||
if len(string(Result[n])) = 3
|
||||
see " " + Result[n]
|
||||
ok
|
||||
if len(string(Result[n])) = 4
|
||||
see " " + Result[n]
|
||||
ok
|
||||
if n%10 = 0
|
||||
see nl
|
||||
ok
|
||||
next
|
||||
|
||||
n = 0
|
||||
num = 0
|
||||
flag = 0
|
||||
Sem = List(6)
|
||||
for s = 1 to len(Sem)
|
||||
Sem[s] = 1
|
||||
next
|
||||
Latin = []
|
||||
Result = []
|
||||
while true
|
||||
n = n + 1
|
||||
deco = []
|
||||
prime = n
|
||||
decomp1(deco,prime)
|
||||
decomp2()
|
||||
decomp3()
|
||||
if flag = 1
|
||||
add(Result,prime)
|
||||
if prime > pow(10,6)
|
||||
for p = 1 to len(Result)
|
||||
if Result[p] > pow(10,1) and Sem[1] = 1
|
||||
see "" + Result[p] + " is a brilliant number: " + p + nl
|
||||
Sem[1] = 0
|
||||
ok
|
||||
|
||||
if Result[p] > pow(10,2) and Sem[2] = 1
|
||||
see "" + Result[p] + " is a brilliant number: " + p + nl
|
||||
Sem[2] = 0
|
||||
ok
|
||||
|
||||
if Result[p] > pow(10,3) and Sem[3] = 1
|
||||
see "" + Result[p] + " is a brilliant number: " + p + nl
|
||||
Sem[3] = 0
|
||||
ok
|
||||
|
||||
if Result[p] > pow(10,4) and Sem[4] = 1
|
||||
see "" + Result[p] + " is a brilliant number: " + p + nl
|
||||
Sem[4] = 0
|
||||
ok
|
||||
|
||||
if Result[p] > pow(10,5) and Sem[5] = 1
|
||||
see "" + Result[p] + " is a brilliant number: " + p + nl
|
||||
Sem[5] = 0
|
||||
ok
|
||||
if Result[p] > pow(10,6) and Sem[6] = 1
|
||||
see "" + Result[p] + " is a brilliant number: " + p + nl
|
||||
Sem[6] = 0
|
||||
ok
|
||||
next
|
||||
ok
|
||||
ok
|
||||
end
|
||||
|
||||
func decomp1(deco,nr)
|
||||
x = ""
|
||||
for i = 1 to nr
|
||||
if isPrime(i) and nr % i = 0
|
||||
add(deco,i)
|
||||
ok
|
||||
next
|
||||
|
||||
func decomp2()
|
||||
while true
|
||||
pro = 1
|
||||
for n = 1 to len(deco)
|
||||
pro = pro * deco[n]
|
||||
next
|
||||
if pro != prime
|
||||
temp = prime/pro
|
||||
decomp1(deco,temp)
|
||||
else
|
||||
exit
|
||||
ok
|
||||
end
|
||||
|
||||
func decomp3()
|
||||
deco = sort(deco)
|
||||
if len(deco) = 2 and prime = deco[1] * deco[2] and
|
||||
len(string(deco[1])) = len(string(deco[2]))
|
||||
num = num + 1
|
||||
flag = 1
|
||||
else
|
||||
flag = 0
|
||||
ok
|
||||
if flag = 1
|
||||
return num
|
||||
ok
|
||||
|
|
@ -1,6 +0,0 @@
|
|||
# ASCII
|
||||
puts [scan "a" %c] ;# ==> 97
|
||||
puts [format %c 97] ;# ==> a
|
||||
# Unicode is the same
|
||||
puts [scan "π" %c] ;# ==> 960
|
||||
puts [format %c 960] ;# ==> π
|
||||
|
|
@ -1,14 +1,14 @@
|
|||
hanzi ← '甲' '乙' '丙' '丁' '戊' '己' '庚' '辛' '壬' '癸' '子' '丑' '寅' '卯' '辰' '巳' '午' '未' '申' '酉' '戌' '亥'
|
||||
pinyin ← 'jiă' 'yĭ' 'bĭng' 'dīng' 'wù' 'jĭ' 'gēng' 'xīn' 'rén' 'gŭi' 'zĭ' 'chŏu' 'yín' 'măo' 'chén' 'sì' 'wŭ' 'wèi' 'shēn' 'yŏu' 'xū' 'hài'
|
||||
|
||||
pinyinFor ← { pinyin /⍨ ⍵ ⍷ hanzi }
|
||||
|
||||
stems ← '甲' '乙' '丙' '丁' '戊' '己' '庚' '辛' '壬' '癸'
|
||||
branches ← '子' '丑' '寅' '卯' '辰' '巳' '午' '未' '申' '酉' '戌' '亥'
|
||||
animals ← 'Rat' 'Ox' 'Tiger' 'Rabbit' 'Dragon' 'Snake' 'Horse' 'Goat' 'Monkey' 'Rooster' 'Dog' 'Pig'
|
||||
elements ← 'Wood' 'Fire' 'Earth' 'Metal' 'Water'
|
||||
aspects ← 'yang' 'yin'
|
||||
|
||||
hanzi ← stems, branches
|
||||
pinyin ← 'jiă' 'yĭ' 'bĭng' 'dīng' 'wù' 'jĭ' 'gēng' 'xīn' 'rén' 'gŭi', 'zĭ' 'chŏu' 'yín' 'măo' 'chén' 'sì' 'wŭ' 'wèi' 'shēn' 'yŏu' 'xū' 'hài'
|
||||
|
||||
pinyinFor ← { pinyin /⍨ ⍵ ⍷ hanzi }
|
||||
|
||||
position ← { 1 + 60 | ⍵ - 4 }
|
||||
item ← { ⍺ ⌷⍨ 1 + (≢⍺) | 1 -⍨ position ⍵ }
|
||||
celestial ← { stems item ⍵ }
|
||||
|
|
|
|||
|
|
@ -1,13 +1,14 @@
|
|||
module Chinese_zodiac {
|
||||
yy= ("yang", "yin")
|
||||
elements = ("Wood", "Fire", "Earth", "Metal", "Water")
|
||||
elements = ("Metal", "Water", "Wood", "Fire", "Earth")
|
||||
animals = ("Rat", "Ox", "Tiger", "Rabbit", "Dragon", "Snake", "Horse", "Goat", "Monkey", "Rooster", "Dog", "Pig")
|
||||
testThis = (1801, 1861, 1984, 2020, 2186, 76543)
|
||||
testThis = (1801, 1861, 1966, 1984, 2017, 2020, 2186, 76543)
|
||||
i=each(testThis)
|
||||
long yr, y, e, a
|
||||
while i
|
||||
yr = array(i)
|
||||
y = yr mod 2
|
||||
e = (yr - 4) mod 5
|
||||
e = (yr div 2) mod 5
|
||||
a = (yr - 4) mod 12
|
||||
outstr = yr+" is the year of the "
|
||||
outstr += elements#val$(e)+" " + animals#val$(a) + " (" + yy#val$(y) + ")."
|
||||
|
|
|
|||
|
|
@ -1,17 +1,11 @@
|
|||
Function isSubstring(kStr As String, f As Integer) As Integer
|
||||
Dim As String fStr = Str(f)
|
||||
Dim As Integer fLen = Len(fStr)
|
||||
Dim As Integer result = 0
|
||||
Dim As Integer fEnd = Len(kStr) - fLen + 1
|
||||
For fPos As Integer = 1 To Len(kStr) - fLen + 1
|
||||
If Mid(kStr, fPos, fLen) = fStr Then
|
||||
result = -1
|
||||
Exit For
|
||||
End If
|
||||
Next fPos
|
||||
Return result
|
||||
If InStr(kStr, Str(f)) > 0 Then
|
||||
Return -1
|
||||
End If
|
||||
Return 0
|
||||
End Function
|
||||
|
||||
|
||||
Dim As Integer requiredNumbers = 20
|
||||
Dim As Integer kCount = 0
|
||||
For k As Integer = 11 To 99999999 Step 2
|
||||
|
|
|
|||
|
|
@ -0,0 +1,53 @@
|
|||
load "stdlib.ring"
|
||||
|
||||
Result = []
|
||||
deco = []
|
||||
comList = []
|
||||
nEnd = 3500000
|
||||
|
||||
for n = 1 to nEnd
|
||||
nr = 0
|
||||
for p = 1 to n
|
||||
if n%p = 0
|
||||
if isPrime(p) = true and p<10
|
||||
exit
|
||||
else
|
||||
nr = nr + 1
|
||||
ok
|
||||
ok
|
||||
next
|
||||
if nr > 2
|
||||
comStr = string(n)
|
||||
add(comList,comStr)
|
||||
ok
|
||||
next
|
||||
|
||||
for n = 1 to len(comList)
|
||||
num = 0
|
||||
comStr = comList[n]
|
||||
comNum = number(comStr)
|
||||
comTemp = comStr
|
||||
decomp(deco,comNum)
|
||||
for y = 1 to len(deco)
|
||||
ind = substr(comStr,deco[y])
|
||||
if ind > 0
|
||||
num = num + 1
|
||||
ok
|
||||
next
|
||||
if num = len(deco)
|
||||
add(Result,comTemp)
|
||||
ok
|
||||
next
|
||||
|
||||
see Result
|
||||
|
||||
func decomp(deco,nr2)
|
||||
deco = []
|
||||
x = ""
|
||||
for i = 1 to nr2
|
||||
if isPrime(i) and nr2 % i = 0
|
||||
x = string(i)
|
||||
add(deco,x)
|
||||
ok
|
||||
next
|
||||
return deco
|
||||
|
|
@ -0,0 +1,31 @@
|
|||
NSUInteger local fn Damm( string as CFStringRef )
|
||||
mda(0,0) = {{0,3,1,7,5,9,8,6,4,2},
|
||||
{7,0,9,2,1,5,4,8,6,3},{4,2,0,6,8,7,1,3,5,9},
|
||||
{1,7,5,0,9,8,3,4,2,6},{6,1,2,3,0,4,5,9,7,8},
|
||||
{3,6,7,4,2,0,9,5,8,1},{5,8,6,9,7,2,0,1,3,4},
|
||||
{8,9,4,5,3,6,2,0,1,7},{9,4,3,8,6,1,7,2,0,5},
|
||||
{2,5,8,1,4,3,6,7,9,0}}
|
||||
|
||||
NSUInteger i, colI, oldRowI = 0, newRowI
|
||||
for i = 0 to len(string) - 1
|
||||
colI = intval(string[i])
|
||||
newRowI = mda(oldRowI,colI)
|
||||
oldRowI = newRowI
|
||||
next
|
||||
end fn = newRowI
|
||||
|
||||
void local fn DoIt
|
||||
CFArrayRef dta = @[@"5724",@"5727",@"112946",@"112949"]
|
||||
for CFStringRef string in dta
|
||||
print string;
|
||||
if ( fn Damm( string ) == 0 )
|
||||
print @" is valid"
|
||||
else
|
||||
print @" is invalid"
|
||||
end if
|
||||
next
|
||||
end fn
|
||||
|
||||
fn DoIt
|
||||
|
||||
HandleEvents
|
||||
|
|
@ -268,8 +268,8 @@ public final class DisplayAnOutlineAsANestedTable {
|
|||
|
||||
private static int index = -1;
|
||||
|
||||
private static final List<String> colours = List.of( "#ffff66;", "#ffcc66;", "#ccffcc;", "#ccccff;",
|
||||
"#ffcccc;", "#00cccc;", "#cc9966;", "#ffccff;" );
|
||||
private static final List<String> colours = List.of(
|
||||
"#ffff66;", "#ffcc66;", "#ccffcc;", "#ccccff;", "#ffcccc;", "#00cccc;", "#cc9966;", "#ffccff;" );
|
||||
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -0,0 +1,50 @@
|
|||
CLEAR
|
||||
|
||||
CODE$="++++++++[>++++[>++>+++>+++>+<<<<-]>+>+>->>+[<]<-]>>.>---.+++++++..+++.>>.<-.<.+++.------.--"
|
||||
CODE$=CODE$+"------.>>+.>++."
|
||||
|
||||
INPUT$=""
|
||||
II=0 'INPUT INDEX
|
||||
|
||||
PIM TAPE(30000)
|
||||
P=0
|
||||
|
||||
FOR I=0 TO LEN(CODE$)-1
|
||||
|
||||
C$=MID$(CODE$, I, 1)
|
||||
IF C$==">" THEN P=P+1
|
||||
IF C$=="<" THEN P=P-1
|
||||
IF C$=="+" THEN TAPE(P)=TAPE(P)+1
|
||||
IF C$=="-" THEN TAPE(P)=TAPE(P)-1
|
||||
IF C$=="." THEN PRINT CHR$(TAPE(P));
|
||||
IF C$=="," THEN @COMMA
|
||||
IF C$=="[" AND TAPE(P)==0 THEN @LBRACKET
|
||||
IF C$=="]" AND TAPE(P)!=0 THEN @RBRACKET
|
||||
GOTO @NEXT
|
||||
|
||||
@COMMA
|
||||
TAPE(P)=ASC(MID$(INPUT$, II, 1))
|
||||
II=II+1
|
||||
GOTO @NEXT
|
||||
|
||||
@LBRACKET
|
||||
NEST = 1
|
||||
@FINDR
|
||||
I=I+1
|
||||
C$=MID$(CODE$, I, 1)
|
||||
IF C$=="[" THEN NEST=NEST+1
|
||||
IF C$=="]" THEN NEST=NEST-1
|
||||
IF NEST THEN @FINDR
|
||||
GOTO @NEXT
|
||||
|
||||
@RBRACKET
|
||||
NEST=1
|
||||
@FINDL
|
||||
I=I-1
|
||||
C$=MID$(CODE$, I, 1)
|
||||
IF C$=="[" THEN NEST=NEST-1
|
||||
IF C$=="]" THEN NEST=NEST+1
|
||||
IF NEST THEN @FINDL
|
||||
|
||||
@NEXT
|
||||
NEXT
|
||||
|
|
@ -0,0 +1,45 @@
|
|||
DEF BRAINFUG CODE$, IN$
|
||||
DIM TAPE[30000]
|
||||
VAR PNT
|
||||
'not sure if len is eval'd each time oh well
|
||||
FOR I=0 TO LEN(CODE$)-1
|
||||
C$=CODE$[I]
|
||||
IF C$==">" THEN
|
||||
INC PNT
|
||||
ELSEIF C$=="<" THEN
|
||||
DEC PNT
|
||||
ELSEIF C$=="+" THEN
|
||||
INC TAPE[PNT]
|
||||
ELSEIF C$=="-" THEN
|
||||
DEC TAPE[PNT]
|
||||
ELSEIF C$=="." THEN
|
||||
PRINT CHR$(TAPE[PNT])
|
||||
ELSEIF C$=="," THEN
|
||||
TAPE[PNT] = ASC(SHIFT(IN$))
|
||||
ELSEIF C$=="[" AND TAPE[PNT]==0 THEN
|
||||
NEST = 1
|
||||
WHILE NEST
|
||||
INC I
|
||||
IF CODE$[I]=="[" THEN
|
||||
INC NEST
|
||||
ELSEIF CODE$[I]=="]" THEN
|
||||
DEC NEST
|
||||
ENDIF
|
||||
WEND
|
||||
ELSEIF C$=="]" AND TAPE[PNT]!=0 THEN
|
||||
NEST=1
|
||||
WHILE NEST
|
||||
DEC I
|
||||
IF CODE$[I]=="]" THEN
|
||||
INC NEST
|
||||
ELSEIF CODE$[I]=="[" THEN
|
||||
DEC NEST
|
||||
ENDIF
|
||||
WEND
|
||||
ENDIF
|
||||
NEXT
|
||||
PRINT
|
||||
END
|
||||
|
||||
CODE$="++++++++[>++++[>++>+++>+++>+<<<<-]>+>+>->>+[<]<-]>>.>---.+++++++..+++.>>.<-.<.+++.------.--------.>>+.>++."
|
||||
BRAINFUG CODE$, ""
|
||||
|
|
@ -1,28 +1,26 @@
|
|||
// 67 need a lot of time 45 minutes (2758716msec) where 71 need 3.1 second (3131msec)
|
||||
Module Factors_of_a_Mersenne_number{
|
||||
Dim q(1 To 10)
|
||||
q(1)= 11, 23, 29, 37, 41, 43, 47, 53, 59, 67, 71, 73, 79, 83, 97, 929
|
||||
For k = 1 To 10
|
||||
Dim q()
|
||||
// 67 need a lot of time 51 minutes (3082671msec) where 71 need 3.5 second (3505msec)
|
||||
q()= (11, 23, 29, 37, 41, 43, 47, 53, 59, 67, 71, 73, 79, 83, 97, 929)
|
||||
profiler
|
||||
long long j=0x8000_0000
|
||||
long long r, p, i
|
||||
long d, dd
|
||||
For k = 0 To len(q())-1
|
||||
If @isPrime(q(k)) Then
|
||||
long p, r, d, r=q(k)
|
||||
long long i
|
||||
d = 2*q(k)+1
|
||||
while r>0: r=sint(binary.add(r,r)): end while
|
||||
Do
|
||||
i=1
|
||||
p=r
|
||||
While p<>0
|
||||
i = i**2@ Mod d
|
||||
If p<0 Then i*=2
|
||||
If i>d Then i-=d
|
||||
p=sint(binary.add(p,p))
|
||||
End While
|
||||
If i=1 Then Exit
|
||||
d+=2*q(k)
|
||||
r=q(k):dd =2*r:d=dd+1
|
||||
while r<j: r=binary.shift(r,1): end while
|
||||
i=1:p=r
|
||||
Do Do i*=i: i|Mod d:If p<j Else i*=2
|
||||
p=binary.shift(p,1):If i>d Then i-=d
|
||||
Until p=0:If i=1 Then Exit Else d+=dd:i=1:p=r
|
||||
Always
|
||||
Print "2^"; q(k); @(6); " - 1 = 0 (mod"; d; ")"
|
||||
Print "2^"; q(k); @(6); " - 1 = 0 (mod "; d; ")"
|
||||
Else
|
||||
Print q(k); " is not prime"
|
||||
End If
|
||||
Print ceil(timecount):profiler
|
||||
Next
|
||||
|
||||
Function isPrime(n As long)
|
||||
|
|
|
|||
|
|
@ -0,0 +1,37 @@
|
|||
const
|
||||
Lists: array of array of real =
|
||||
((15.0, 6.0, 42.0, 41.0, 7.0, 36.0, 49.0, 40.0, 39.0, 47.0, 43.0),
|
||||
(36.0, 40.0, 7.0, 39.0, 41.0, 15.0),
|
||||
(0.14082834, 0.09748790, 1.73131507, 0.87636009, -1.95059594,
|
||||
0.73438555, -0.03035726, 1.46675970, -0.74621349, -0.72588772,
|
||||
0.63905160, 0.61501527, -0.98983780, -1.00447874, -0.62759469,
|
||||
0.66206163, 1.04312009, -0.10305385, 0.75775634, 0.32566578));
|
||||
|
||||
function median(x: array of real; startIndex, endIndex: integer): real;
|
||||
begin
|
||||
var size := endIndex - startIndex + 1;
|
||||
assert(size > 0, 'array slice cannot be empty');
|
||||
var m := startIndex + size div 2;
|
||||
result := if size mod 2 = 1 then x[m] else (x[m - 1] + x[m]) / 2
|
||||
end;
|
||||
|
||||
function fivenum(x: array of real): array of real;
|
||||
begin
|
||||
setlength(result, 5);
|
||||
x := x.Sorted.ToArray;
|
||||
var m := x.length div 2;
|
||||
var lowerEnd := if x.length mod 2 = 1 then m else m - 1;
|
||||
result[0] := x[0];
|
||||
result[1] := median(x, 0, lowerEnd);
|
||||
result[2] := median(x, 0, x.high);
|
||||
result[3] := median(x, m, x.high);
|
||||
result[4] := x[^1];
|
||||
end;
|
||||
|
||||
begin
|
||||
foreach var list in Lists do
|
||||
begin
|
||||
println(list.toarray);
|
||||
println(' → ', fivenum(list));
|
||||
end;
|
||||
end.
|
||||
|
|
@ -1,7 +1,11 @@
|
|||
# procedure to print a Floyd's Triangle with n lines #
|
||||
# procedure to print a Floyd's Triangle with n lines #
|
||||
PROC floyds triangle = ( INT n )VOID:
|
||||
BEGIN
|
||||
|
||||
# the triangle should be left aligned with the individual numbers #
|
||||
# right-aligned with only one space before the number in the final #
|
||||
# row #
|
||||
|
||||
# calculate the number of the highest number that will be printed #
|
||||
# ( the sum of the integers 1, 2, ... n ) #
|
||||
INT max number = ( n * ( n + 1 ) ) OVER 2;
|
||||
|
|
@ -24,10 +28,6 @@ BEGIN
|
|||
|
||||
END; # floyds triangle #
|
||||
|
||||
main: (
|
||||
|
||||
floyds triangle( 5 );
|
||||
print( ( newline ) );
|
||||
floyds triangle( 14 )
|
||||
|
||||
)
|
||||
floyds triangle( 5 );
|
||||
print( ( newline ) );
|
||||
floyds triangle( 14 )
|
||||
|
|
|
|||
|
|
@ -0,0 +1,15 @@
|
|||
uses System.Threading;
|
||||
|
||||
procedure Fork;
|
||||
begin
|
||||
WriteLn('Spawned Thread');
|
||||
end;
|
||||
|
||||
begin
|
||||
var t := new Thread(ThreadStart(Fork));
|
||||
t.Start;
|
||||
|
||||
WriteLn('Main Thread');
|
||||
t.Join;
|
||||
Readln;
|
||||
end.
|
||||
|
|
@ -0,0 +1,170 @@
|
|||
#include <cstdint>
|
||||
#include <iomanip>
|
||||
#include <iostream>
|
||||
#include <memory>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
class FCNode {
|
||||
public:
|
||||
FCNode(const std::string& name, const uint32_t& weight, const double& coverage)
|
||||
: name(name), weight(weight), coverage(coverage), parent(NULL) {}
|
||||
|
||||
void add_children(const std::vector<std::shared_ptr<FCNode>>& nodes) {
|
||||
for ( const std::shared_ptr<FCNode>& node : nodes ) {
|
||||
node->parent = this;
|
||||
children.emplace_back(node);
|
||||
update_coverage();
|
||||
}
|
||||
}
|
||||
|
||||
double get_coverage() {
|
||||
return coverage;
|
||||
}
|
||||
|
||||
void set_coverage(const double& aCoverage) {
|
||||
if ( coverage != aCoverage ) {
|
||||
coverage = aCoverage;
|
||||
if ( parent ) {
|
||||
parent->update_coverage();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void display() {
|
||||
display(0);
|
||||
}
|
||||
|
||||
private:
|
||||
void update_coverage() {
|
||||
double sum_weighted_coverage = 0.0;
|
||||
uint32_t sum_weight = 0;
|
||||
for ( const std::shared_ptr<FCNode>& node : children ) {
|
||||
sum_weighted_coverage += node->weight * node->coverage;
|
||||
sum_weight += node->weight;
|
||||
}
|
||||
|
||||
set_coverage(sum_weighted_coverage / sum_weight);
|
||||
}
|
||||
|
||||
void display(uint32_t level) {
|
||||
const std::string initial = std::string(4 * level, ' ') + name;
|
||||
const std::string padding = std::string(NAME_FIELD_WIDTH - initial.length(), ' ');
|
||||
std::cout << initial + padding + "|";
|
||||
std::cout << " " << std::setw(3) << weight << " |";
|
||||
std::cout << " " << std::fixed << std::setprecision(6) << coverage << " |" << std::endl;
|
||||
|
||||
for ( const std::shared_ptr<FCNode>& child : children ) {
|
||||
child->display(level + 1);
|
||||
}
|
||||
}
|
||||
|
||||
std::string name;
|
||||
uint32_t weight;
|
||||
double coverage;
|
||||
FCNode* parent;
|
||||
std::vector<std::shared_ptr<FCNode>> children{ };
|
||||
|
||||
static constexpr uint32_t NAME_FIELD_WIDTH = 32;
|
||||
};
|
||||
|
||||
int main() {
|
||||
FCNode cleaning("Cleaning", 1, 0.0);
|
||||
|
||||
std::vector<std::shared_ptr<FCNode>> houses = {
|
||||
std::make_shared<FCNode>("House_1", 40, 0.0),
|
||||
std::make_shared<FCNode>("House_2", 60, 0.0)
|
||||
};
|
||||
cleaning.add_children(houses);
|
||||
|
||||
std::vector<std::shared_ptr<FCNode>> house_1 = {
|
||||
std::make_shared<FCNode>("Bedrooms", 1, 0.25),
|
||||
std::make_shared<FCNode>("Bathrooms", 1, 0.0),
|
||||
std::make_shared<FCNode>("Attic", 1, 0.75),
|
||||
std::make_shared<FCNode>("Kitchen", 1, 0.1),
|
||||
std::make_shared<FCNode>("Living_rooms", 1, 0.0),
|
||||
std::make_shared<FCNode>("Basement", 1, 0.0),
|
||||
std::make_shared<FCNode>("Garage", 1, 0.0),
|
||||
std::make_shared<FCNode>("Garden",1, 0.8)
|
||||
};
|
||||
houses[0]->add_children(house_1);
|
||||
|
||||
std::vector<std::shared_ptr<FCNode>> bathrooms_house_1 = {
|
||||
std::make_shared<FCNode>("Bathroom_1", 1, 0.5),
|
||||
std::make_shared<FCNode>("Bathroom_2", 1, 0.0),
|
||||
std::make_shared<FCNode>("Outside_lavatory", 1, 1.0)
|
||||
};
|
||||
house_1[1]->add_children(bathrooms_house_1);
|
||||
|
||||
std::vector<std::shared_ptr<FCNode>> living_rooms_house_1 = {
|
||||
std::make_shared<FCNode>("lounge", 1, 0.0),
|
||||
std::make_shared<FCNode>("Dining_room", 1, 0.0),
|
||||
std::make_shared<FCNode>("Conservatory", 1, 0.0),
|
||||
std::make_shared<FCNode>("Playroom", 1, 1.0)
|
||||
};
|
||||
house_1[4]->add_children(living_rooms_house_1);
|
||||
|
||||
std::vector<std::shared_ptr<FCNode>> house_2 = {
|
||||
std::make_shared<FCNode>("Upstairs", 1, 0.15),
|
||||
std::make_shared<FCNode>("Ground_floor", 1, 0.316667),
|
||||
std::make_shared<FCNode>("Basement", 1, 0.916667)
|
||||
};
|
||||
houses[1]->add_children(house_2);
|
||||
|
||||
std::vector<std::shared_ptr<FCNode>> upstairs = {
|
||||
std::make_shared<FCNode>("Bedrooms", 1, 0.0),
|
||||
std::make_shared<FCNode>("Bathroom", 1, 0.0),
|
||||
std::make_shared<FCNode>("Toilet", 1, 0.0),
|
||||
std::make_shared<FCNode>("Attics", 1, 0.6)
|
||||
};
|
||||
house_2[0]->add_children(upstairs);
|
||||
|
||||
std::vector<std::shared_ptr<FCNode>> ground_floor = {
|
||||
std::make_shared<FCNode>("Kitchen", 1, 0.0),
|
||||
std::make_shared<FCNode>("Living_rooms", 1, 0.0),
|
||||
std::make_shared<FCNode>("Wet_room_&_toilet", 1, 0.0),
|
||||
std::make_shared<FCNode>("Garage", 1, 0.0),
|
||||
std::make_shared<FCNode>("Garden", 1, 0.9),
|
||||
std::make_shared<FCNode>("Hot_tub_suite", 1, 1.0)
|
||||
};
|
||||
house_2[1]->add_children(ground_floor);
|
||||
|
||||
std::vector<std::shared_ptr<FCNode>> basement = {
|
||||
std::make_shared<FCNode>("Cellars", 1, 1.0),
|
||||
std::make_shared<FCNode>("Wine_cellar", 1, 1.0),
|
||||
std::make_shared<FCNode>("Cinema", 1, 0.75)
|
||||
};
|
||||
house_2[2]->add_children(basement);
|
||||
|
||||
std::vector<std::shared_ptr<FCNode>> bedrooms = {
|
||||
std::make_shared<FCNode>("Suite_1", 1, 0.0),
|
||||
std::make_shared<FCNode>("Suite_2", 1, 0.0),
|
||||
std::make_shared<FCNode>("Bedroom_3",1, 0.0),
|
||||
std::make_shared<FCNode>("Bedroom_4",1, 0.0)
|
||||
};
|
||||
upstairs[0]->add_children(bedrooms);
|
||||
|
||||
std::vector<std::shared_ptr<FCNode>> living_rooms_house_2 = {
|
||||
std::make_shared<FCNode>("lounge", 1, 0.0),
|
||||
std::make_shared<FCNode>("Dining_room", 1, 0.0),
|
||||
std::make_shared<FCNode>("Conservatory", 1, 0.0),
|
||||
std::make_shared<FCNode>("Playroom", 1, 0.0)
|
||||
};
|
||||
ground_floor[1]->add_children(living_rooms_house_2);
|
||||
|
||||
const double overall_coverage = cleaning.get_coverage();
|
||||
std::cout << "OVERALL COVERAGE = " << std::fixed << std::setprecision(6)
|
||||
<< overall_coverage << std::endl << std::endl;
|
||||
std::cout << "NAME HIERARCHY | WEIGHT | COVERAGE |" << std::endl;
|
||||
std::cout << "--------------------------------|--------|----------|" << std::endl;
|
||||
cleaning.display();
|
||||
std::cout << std::endl;
|
||||
|
||||
basement[2]->set_coverage(1.0); // Change House_2 Cinema node coverage to 1.0
|
||||
const double updated_coverage = cleaning.get_coverage();
|
||||
const double difference = updated_coverage - overall_coverage;
|
||||
std::cout << "If the coverage of the House_2 Cinema node were increased " << std::endl;
|
||||
std::cout << "from 0.75 to 1.0 the overall coverage would increase by ";
|
||||
std::cout << std::fixed << std::setprecision(6) << difference << " to " << updated_coverage << std::endl;
|
||||
basement[2]->set_coverage(0.75); // Restore to House_2 Cinema node coverage to its original value
|
||||
}
|
||||
|
|
@ -78,7 +78,8 @@ public final class FunctionalCoverageTree {
|
|||
ground_floor.get(1).addChildren(living_rooms_house_2);
|
||||
|
||||
final double overallCoverage = cleaning.getCoverage();
|
||||
System.out.println("OVERALL COVERAGE = " + String.format("%.6f", overallCoverage) + System.lineSeparator());
|
||||
System.out.println("OVERALL COVERAGE = " + String.format("%.6f", overallCoverage));
|
||||
System.out.println();
|
||||
System.out.println("NAME HIERARCHY | WEIGHT | COVERAGE |" );
|
||||
System.out.println("--------------------------------|--------|----------|");
|
||||
cleaning.display();
|
||||
|
|
@ -129,14 +130,14 @@ final class FCNode {
|
|||
}
|
||||
|
||||
private void updateCoverage() {
|
||||
double value1 = 0.0;
|
||||
int value2 = 0;
|
||||
double sumWeightedCoverage = 0.0;
|
||||
int sumWeight = 0;
|
||||
for ( FCNode node : children ) {
|
||||
value1 += node.weight * node.coverage;
|
||||
value2 += node.weight;
|
||||
sumWeightedCoverage += node.weight * node.coverage;
|
||||
sumWeight += node.weight;
|
||||
}
|
||||
|
||||
setCoverage(value1 / value2);
|
||||
setCoverage(sumWeightedCoverage / sumWeight);
|
||||
}
|
||||
|
||||
private void display(int aLevel) {
|
||||
|
|
|
|||
|
|
@ -0,0 +1,28 @@
|
|||
const
|
||||
g = 7;
|
||||
p: array of real =
|
||||
(0.99999999999980993, 676.5203681218851, -1259.1392167224028,
|
||||
771.32342877765313, -176.61502916214059, 12.507343278686905,
|
||||
-0.13857109526572012, 9.9843695780195716e-6, 1.5056327351493116e-7);
|
||||
|
||||
function Gamma(z: Complex): Complex;
|
||||
begin
|
||||
if (z.Real < 0.5) then
|
||||
begin
|
||||
result := pi / (Sin(pi * z) * Gamma(1 - z));
|
||||
exit;
|
||||
end
|
||||
else
|
||||
begin
|
||||
z -= 1;
|
||||
var x: Complex := p[0];
|
||||
for var i := 1 to g + 1 do x += p[i] / (z + i);
|
||||
var t := z + g + 0.5;
|
||||
result := Sqrt(2 * pi) * (Power(t, z + 0.5)) * Exp(-t) * x;
|
||||
end;
|
||||
end;
|
||||
|
||||
begin
|
||||
writeln('z Lanczos');
|
||||
for var i := 1 to 10 do writeln(i / 3:6:4, gamma(i / 3):25);
|
||||
end.
|
||||
|
|
@ -0,0 +1,12 @@
|
|||
for=100
|
||||
print for=100
|
||||
for for=1 to 10:Print for: Next for
|
||||
Print for=11
|
||||
to=100
|
||||
print to=100
|
||||
for to=1 to 10:Print to: Next to
|
||||
Print to=11
|
||||
Print=100
|
||||
print Print=100
|
||||
for Print=1 to 10:Print Print: Next Print
|
||||
Print Print=11
|
||||
|
|
@ -1,27 +1,25 @@
|
|||
Module Checkit {
|
||||
\\ old type loop
|
||||
For i=1 to 10
|
||||
Print i;
|
||||
If i=10 Then Exit For
|
||||
Print ", ";
|
||||
Next i
|
||||
Print
|
||||
\\ fast type loop. Continue exit block, without breaking loop.
|
||||
For i=1 to 10 {
|
||||
Print i;
|
||||
If i=10 Then Continue
|
||||
Print ", ";
|
||||
}
|
||||
Print
|
||||
Print
|
||||
i=0
|
||||
{
|
||||
loop \\ this mark block for loop, each time need to mark
|
||||
i++
|
||||
Print i;
|
||||
If i=10 Then Exit ' so now we use exit to break loop
|
||||
Print ", ";
|
||||
}
|
||||
Print
|
||||
For i=1 to 10
|
||||
Print i;
|
||||
If i=10 Then Continue
|
||||
Print ",";
|
||||
Next i
|
||||
Print
|
||||
i=1
|
||||
{ Print i;
|
||||
If i=10 Then Continue
|
||||
loop ' this mark block for loop
|
||||
Print ",";
|
||||
i++
|
||||
}
|
||||
Print
|
||||
05 REM like Basic Old type
|
||||
10 LET i=0
|
||||
20 i=i+1
|
||||
30 PRINT i;
|
||||
40 IF i=10 THEN 70
|
||||
50 PRINT ",";
|
||||
60 GOTO 20
|
||||
70 PRINT
|
||||
}
|
||||
Checkit
|
||||
|
|
|
|||
|
|
@ -1,5 +1,7 @@
|
|||
Module MultipleLoop {
|
||||
def long prod=1, sum=0, x=+5,y=-5, z=-2, one=1, three=3, seven=7, j
|
||||
long sum=0, x=+5,y=-5, z=-2, j
|
||||
double prod=1
|
||||
const one=1&, three=3&, seven=7&
|
||||
Range=lambda (a, b, c=1) ->{
|
||||
=lambda a, b, c (&f)-> {
|
||||
if compare(a,b)=sgn(c) then =false else =true: f=a: a+=c
|
||||
|
|
@ -13,13 +15,15 @@ Module MultipleLoop {
|
|||
k++ : always
|
||||
}
|
||||
}
|
||||
Exec=MultipleRange(Range(-three, 3**3, three), Range(-seven, +seven, x), Range(555, 550-y), Range(22, -28, -three), Range(1927, 1939), Range(x,y,z), Range(11**x, 11**x+one))
|
||||
flush
|
||||
data Range(-three, 3**3, three), Range(-seven, +seven, x), Range(555, 550-y), Range(22, -28, -three)
|
||||
data Range(1927, 1939), Range(x,y,z), Range(11**x, 11**x+one)
|
||||
Exec=MultipleRange(![])
|
||||
j=0
|
||||
while Exec(&j)
|
||||
sum+=abs(j)
|
||||
if abs(prod) < 2^27 And j <> 0 then prod*=j
|
||||
End While
|
||||
|
||||
Print "sum=";sum
|
||||
Print "prod=";prod
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,31 @@
|
|||
long def fn MagicConstant( n as long ) = n*(n^2+1)/2
|
||||
|
||||
UInt64 local fn InvA( x as double )
|
||||
UInt64 k = 0
|
||||
while ( k*(k^2+1)/2+2 < x )
|
||||
k++
|
||||
wend
|
||||
end fn = k
|
||||
|
||||
void local fn DoIt
|
||||
window 1, @"Magic constant", (0,0,640,400)
|
||||
print @"First 20 magic constants:"
|
||||
long n = 3
|
||||
while n <= 1002
|
||||
if ( n <= 22 )
|
||||
print fn MagicConstant( n );@" ";
|
||||
end if
|
||||
if ( n == 1002 ) then print @"\n\n1000th magic constant: ";fn MagicConstant(1002)
|
||||
n++
|
||||
wend
|
||||
|
||||
print
|
||||
|
||||
for long e = 1 to 20
|
||||
printf @"10^%ld: %ld",e,fn InvA(10^e)
|
||||
next
|
||||
end fn
|
||||
|
||||
fn DoIt
|
||||
|
||||
HandleEvents
|
||||
|
|
@ -0,0 +1,82 @@
|
|||
' version 01-11-2024
|
||||
' compile with: fbc -s console
|
||||
|
||||
#Include Once "gmp.bi"
|
||||
#Include Once "crt\stdio.bi"
|
||||
#Define prec 32
|
||||
|
||||
Dim Shared As String ratio_names(0 To 9)
|
||||
For x As Integer = 0 To 9
|
||||
Read ratio_names(x)
|
||||
Next
|
||||
|
||||
Data "Platinum", "Golden", "Silver", "Bronze", "Copper"
|
||||
Data "Nickel", "Aluminium", "Iron", "Tin", "Lead"
|
||||
|
||||
Sub lucas(b As UInteger)
|
||||
Print Using "Lucas sequence for & ratio, where b = #";ratio_names(b); b
|
||||
Dim As UInteger i, l0 = 1, l1 = 1, l2
|
||||
Print "First 15 elements are 1, 1";
|
||||
For i = 1 To 13
|
||||
l2 = b * l1 + l0
|
||||
Print ", "; l2;
|
||||
Swap l0, l1
|
||||
Swap l1, l2
|
||||
Next
|
||||
Print
|
||||
End Sub
|
||||
|
||||
Sub metallic_ratio(b As UInteger, pr As UInteger)
|
||||
|
||||
Dim As UInteger i, dp
|
||||
Dim As String str1
|
||||
Dim As ZString Ptr gmp_str : gmp_str = Allocate(100)
|
||||
Dim As mpf_ptr bb, l0, l1, l2, ra
|
||||
bb = Allocate(Len(__Mpf_struct)) : Mpf_init2(bb, pr * 4)
|
||||
l0 = Allocate(Len(__Mpf_struct)) : Mpf_init2(l0, pr * 4)
|
||||
l1 = Allocate(Len(__Mpf_struct)) : Mpf_init2(l1, pr * 4)
|
||||
l2 = Allocate(Len(__Mpf_struct)) : Mpf_init2(l2, pr * 4)
|
||||
ra = Allocate(Len(__Mpf_struct)) : Mpf_init2(ra, pr * 4)
|
||||
|
||||
mpf_set_ui(bb, b)
|
||||
mpf_set_ui(l0, 1)
|
||||
mpf_set_ui(l1, 1)
|
||||
mpf_div(ra, l1, l0)
|
||||
Gmp_sprintf(gmp_str, "%.*Ff", pr, ra)
|
||||
str1 = *gmp_str
|
||||
|
||||
Do
|
||||
i += 1
|
||||
mpf_mul(l2, bb, l1)
|
||||
mpf_add(l2, l2, l0)
|
||||
mpf_div(ra, l2, l1)
|
||||
Gmp_sprintf(gmp_str, "%.*Ff", pr, ra)
|
||||
If str1 = *gmp_str Then
|
||||
Print "Value to "; Str(pr); " dp after "; Str(i); " iteration"; IIf(i < 2, "", "s"); ": ";
|
||||
If pr = 256 Then print
|
||||
If i = 1 Then Print Trim(Trim(str1,"0"), ".") Else Print str1
|
||||
Print
|
||||
mpf_clears(bb, l0, l1, l2, ra, NULL)
|
||||
DeAllocate(gmp_str)
|
||||
Return
|
||||
End If
|
||||
str1 = *gmp_str
|
||||
mpf_swap(l0, l1)
|
||||
mpf_swap(l1, l2)
|
||||
Loop
|
||||
End Sub
|
||||
|
||||
' ------=< MAIN >=------
|
||||
|
||||
For x As Integer = 0 To 9
|
||||
lucas(x)
|
||||
metallic_ratio(x, prec)
|
||||
Next
|
||||
Print "Golden ratio, where b = 1"
|
||||
metallic_ratio(1, 256)
|
||||
|
||||
' empty keyboard buffer
|
||||
While Inkey <> "" : Wend
|
||||
Print : Print "hit any key to end program"
|
||||
Sleep
|
||||
End
|
||||
|
|
@ -0,0 +1,20 @@
|
|||
import qualified Graphics.UI.Threepenny as UI
|
||||
import Graphics.UI.Threepenny.Core
|
||||
|
||||
main :: IO ()
|
||||
main = do
|
||||
startGUI defaultConfig setup -- Start the Threepenny server
|
||||
|
||||
setup :: Window -> UI ()
|
||||
setup window = do
|
||||
-- Set the window title
|
||||
pure window # set UI.title "Cursor Position Example"
|
||||
|
||||
-- Create a display area
|
||||
displayArea <- UI.div # set UI.style [("width", "100%"), ("height", "100vh"), ("background", "#f0f0f0")]
|
||||
getBody window #+ [element displayArea]
|
||||
|
||||
-- Event listener for mouse movements
|
||||
on UI.mousemove displayArea $ \(x, y) -> do
|
||||
-- This prints in terminal where threepenny-gui server was started, NOT in browser console
|
||||
liftIO $ putStrLn $ "Mouse cursor position relative to window: (" ++ show x ++ ", " ++ show y ++ ")"
|
||||
|
|
@ -0,0 +1,83 @@
|
|||
Const As Long RAND_MAX = 32767
|
||||
Const ALFA = "+.ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"
|
||||
Const ALEN = Len(ALFA) - 3
|
||||
|
||||
Dim Shared As Integer grid()
|
||||
Dim Shared As Integer w, ww
|
||||
|
||||
Sub makeGrid(p As Single)
|
||||
Dim As Long thresh, r
|
||||
thresh = Int(p * RAND_MAX)
|
||||
|
||||
ww = w * w
|
||||
Redim grid(ww - 1)
|
||||
|
||||
For i As Integer = ww - 1 To 0 Step -1
|
||||
r = Int(Rnd * (RAND_MAX + 1))
|
||||
grid(i) = Iif(r < thresh, -1, 0)
|
||||
Next
|
||||
End Sub
|
||||
|
||||
Sub showCluster()
|
||||
Dim As Integer k, i, j, s
|
||||
Dim As String c
|
||||
|
||||
k = 0
|
||||
For i = 0 To w - 1
|
||||
For j = 0 To w - 1
|
||||
s = grid(k)
|
||||
k += 1
|
||||
c = Iif(s < ALEN, Mid(ALFA, 1 + s + 1, 1), "?")
|
||||
Print " " & c;
|
||||
Next
|
||||
Print
|
||||
Next
|
||||
End Sub
|
||||
|
||||
Sub recur(x As Integer, v As Integer)
|
||||
If x >= 0 Andalso x < ww Andalso grid(x) = -1 Then
|
||||
grid(x) = v
|
||||
recur(x - w, v)
|
||||
recur(x - 1, v)
|
||||
recur(x + 1, v)
|
||||
recur(x + w, v)
|
||||
End If
|
||||
End Sub
|
||||
|
||||
Function countClusters() As Integer
|
||||
Dim As Integer ccl, i
|
||||
|
||||
ccl = 0
|
||||
For i = 0 To ww - 1
|
||||
If grid(i) = -1 Then
|
||||
ccl += 1
|
||||
recur(i, ccl)
|
||||
End If
|
||||
Next
|
||||
Return ccl
|
||||
End Function
|
||||
|
||||
Function tests(n As Integer, p As Single) As Single
|
||||
Dim k As Single = 0
|
||||
For i As Integer = 0 To n - 1
|
||||
makeGrid(p)
|
||||
k += countClusters() / ww
|
||||
Next
|
||||
Return k / n
|
||||
End Function
|
||||
|
||||
' Main program
|
||||
Randomize Timer
|
||||
w = 15
|
||||
makeGrid(0.5)
|
||||
Print "width = 15, p = 0.5, " & countClusters() & " clusters:"
|
||||
showCluster()
|
||||
|
||||
Print !"\np = 0.5, iter = 5:"
|
||||
w = 4
|
||||
While w <= 8192
|
||||
Print Using "##### #.######"; w; tests(5, 0.5)
|
||||
w Shl= 1
|
||||
Wend
|
||||
|
||||
Sleep
|
||||
|
|
@ -5,12 +5,16 @@ Module Checkit {
|
|||
Print Sgn(-5)=-1
|
||||
Print Abs(-2.10#)=2.1#
|
||||
Def exptype$(x)=type$(x)
|
||||
Print exptype$(Abs(-2.1@))="Decimal"
|
||||
Print exptype$(Abs(-2.1#))="Currency"
|
||||
Print exptype$(Abs(-2.1~))="Single"
|
||||
Print exptype$(Abs(-2.1@))="Decimal"
|
||||
Print exptype$(Abs(-2.212e34~))="Single"
|
||||
Print exptype$(Abs(-2.212e34))="Double"
|
||||
Print exptype$(Abs(-12345612345612345&&))="Long Long"
|
||||
Print exptype$(Abs(-2&))="Long"
|
||||
Print exptype$(Abs(-2%))="Integer"
|
||||
Print exptype$(Abs(-2.212e34))="Double"
|
||||
Print exptype$(234ub)="Byte"
|
||||
Print exptype$(4600ud)="Date"
|
||||
|
||||
Print exptype$(Sgn(-2.1#))="Integer"
|
||||
\\ Sgn return integer type
|
||||
|
|
@ -26,17 +30,27 @@ Module Checkit {
|
|||
\\ 64bit Long Long (from Version 12)
|
||||
Print exptype$(2&&^2&&)="Long Long"
|
||||
Print exptype$(2&&**2&&)="Long Long"
|
||||
Print exptype$(2&& mod 2&&)="Long Long"
|
||||
Print exptype$(2&& div 2&&)="Long Long"
|
||||
Print exptype$(2&& / 2&&)="Double"
|
||||
Print exptype$(2&&*2&)="Long Long"
|
||||
// Byte only + - * work for byte (byte is unsigned, from 0 to 255)
|
||||
Print exptype$(2ub^2ub)="Double"
|
||||
Print exptype$(2ub**2ub)="Double"
|
||||
Print exptype$(2ub*2ub)="Byte"
|
||||
Print exptype$(2ub*255ub)="Integer"
|
||||
try ok {Print exptype$(256ub*255ub), "??"}
|
||||
If error or not ok then print error$ ' error in exponet Overflow
|
||||
Print exptype$(2ub mod 2ub)="Double"
|
||||
Print exptype$(2ub div 2ub)="Double"
|
||||
Print exptype$(2ub / 2ub)="Double"
|
||||
Print 2**2=4, 2^2=4, 2^2^2=16, 2**2**2=16
|
||||
\\ floor() and Int() is the same
|
||||
Print Int(-2.7)=-3, Int(2.7)=2
|
||||
Print Floor(-2.7)=-3, Floor(2.7)=2
|
||||
Print Ceil(-2.7)=-2, Ceil(2.7)=3
|
||||
|
||||
Print round(-2.7, 0)=-3, round(2.7, 0)=3
|
||||
Print round(-2.2, 0)=-2, round(2.2, 0)=2
|
||||
|
||||
|
||||
Print Sqrt(4)=2
|
||||
}
|
||||
Checkit
|
||||
|
|
|
|||
|
|
@ -0,0 +1,28 @@
|
|||
print "Square root of 2.7 ="; sqr(2.7)
|
||||
print "Natural log of 2.7 ="; log(2.7)
|
||||
print "Exp() of 2.7 ="; exp(2.7)
|
||||
print "Absolute value of -2.7 ="; abs(-2.7)
|
||||
print "Floor of 2.7 ="; int(2.7)
|
||||
print "Floor of -2.7 ="; int(-2.7)
|
||||
print "2.7 to the 3rd power ="; 2.7 ^ 3 rem or 2.7 ** 3
|
||||
|
||||
comment
|
||||
e, pi, and ceiling() are not built-in, but are
|
||||
easily implemented
|
||||
end
|
||||
|
||||
function e = real
|
||||
end = exp(1.0)
|
||||
|
||||
function pi = real
|
||||
end = atn(1.0) * 4.0
|
||||
|
||||
function ceil(x = real) = real
|
||||
end = int(x) + 1
|
||||
|
||||
print "e ="; e
|
||||
print "pi ="; pi
|
||||
print "ceiling of 2.7 = "; ceil(2.7)
|
||||
print "ceiling of -2.7 = "; ceil(-2.7)
|
||||
|
||||
end
|
||||
|
|
@ -36,8 +36,7 @@ END; # longest rep string #
|
|||
|
||||
|
||||
# test the longest rep string procedure #
|
||||
main:
|
||||
(
|
||||
BEGIN
|
||||
|
||||
[]STRING tests = ( "1001110011"
|
||||
, "1110111011"
|
||||
|
|
@ -65,4 +64,4 @@ main:
|
|||
)
|
||||
)
|
||||
OD
|
||||
)
|
||||
END
|
||||
|
|
|
|||
|
|
@ -0,0 +1,24 @@
|
|||
str = "abracadabra"
|
||||
strTemp = "abracadabra"
|
||||
|
||||
repSel(str,"a","A",1)
|
||||
repSel(str,"a","B",2)
|
||||
repSel(str,"a","C",4)
|
||||
repSel(str,"a","D",5)
|
||||
repSel(str,"b","E",1)
|
||||
repSel(str,"r","F",2)
|
||||
|
||||
see str + " -> " + strTemp + nl
|
||||
|
||||
func repSel(str,char1,char2,nr)
|
||||
num = 0
|
||||
for n = 1 to len(str)
|
||||
if str[n] = char1
|
||||
num += 1
|
||||
ok
|
||||
if num = nr
|
||||
strTemp[n] = char2
|
||||
exit
|
||||
ok
|
||||
next
|
||||
return strTemp
|
||||
|
|
@ -0,0 +1,37 @@
|
|||
pragma Ada_2022;
|
||||
with Ada.Command_Line; use Ada.Command_Line;
|
||||
with Ada.Text_IO; use Ada.Text_IO;
|
||||
with Easy_Graphics; use Easy_Graphics;
|
||||
|
||||
procedure Sierpinski_Triangle_Graphical is
|
||||
Max_Order : constant Integer := 8;
|
||||
subtype Valid_Order is Integer range 0 .. Max_Order;
|
||||
Length : constant Positive := 2 ** (Max_Order + 1);
|
||||
Order : Valid_Order;
|
||||
Img : Easy_Image := New_Image ((1, 1), (550, 550), BLACK);
|
||||
Turtle : Turtle_Rec := New_Turtle (Img'Unrestricted_Access);
|
||||
|
||||
procedure Sier_Triangle (Order : Valid_Order; Length : Positive) is
|
||||
begin
|
||||
if Order > 0 then
|
||||
for I in 1 .. 3 loop
|
||||
Sier_Triangle (Order - 1, Length / 2);
|
||||
Turtle.Forward (Length);
|
||||
Turtle.Right (120);
|
||||
end loop;
|
||||
end if;
|
||||
end Triangle;
|
||||
|
||||
begin
|
||||
if Argument_Count /= 1 then
|
||||
Put_Line ("Usage: sierpinski_triangle_graphical <order>");
|
||||
Put_Line ("Where: <order> is 0 .. 8");
|
||||
return;
|
||||
end if;
|
||||
Order := Natural'Value (Argument (1));
|
||||
Turtle.Pen_Color (MAGENTA);
|
||||
Turtle.Go_To ((25, 25));
|
||||
Turtle.Pen_Down;
|
||||
Sier_Triangle (Order, Length);
|
||||
Write_GIF (Img, "sierpinski_triangle.gif");
|
||||
end Sierpinski_Triangle_Graphical;
|
||||
|
|
@ -13,7 +13,7 @@ TextView' t
|
|||
|
||||
\ the running count is always on the stack
|
||||
\ so a variable for that is not needed
|
||||
:noname
|
||||
:noname ( count -- count+1 )
|
||||
1+ \ increment the count
|
||||
" Number of clicks: " put: t
|
||||
dup deciNumstr insert: t ; setAction: b \ update the text representation of count
|
||||
|
|
|
|||
|
|
@ -1,28 +1,49 @@
|
|||
load "stdlib.ring"
|
||||
|
||||
see "First 25 Smarandache primes:" + nl + nl
|
||||
|
||||
sum = 0
|
||||
num = 0
|
||||
limit = 26
|
||||
limit100 = 100
|
||||
for n = 1 to 34000
|
||||
flag = 0
|
||||
nStr = string(n)
|
||||
for x = 1 to len(nStr)
|
||||
nx = number(nStr[x])
|
||||
if isprime(n) and isprime(nx)
|
||||
flag = flag + 1
|
||||
else
|
||||
exit
|
||||
ok
|
||||
next
|
||||
if flag = len(nStr)
|
||||
num = num + 1
|
||||
if num < limit
|
||||
see "" + n + " "
|
||||
ok
|
||||
if num = limit100
|
||||
see nl + nl + "100th Smarandache prime: " + n + nl
|
||||
ok
|
||||
ok
|
||||
Sma = []
|
||||
while true
|
||||
num += 1
|
||||
flag = 0
|
||||
numb = 0
|
||||
if isPrime(num)
|
||||
nrStr = string(num)
|
||||
for n = 1 to len(nrStr)
|
||||
nrTemp = number(nrStr[n])
|
||||
if isPrime(nrTemp)
|
||||
numb += 1
|
||||
if numb = len(nrStr)
|
||||
add(Sma,num)
|
||||
sum += 1
|
||||
if sum = 100
|
||||
exit 2
|
||||
ok
|
||||
ok
|
||||
else
|
||||
exit
|
||||
ok
|
||||
next
|
||||
ok
|
||||
end
|
||||
|
||||
for n = 1 to 25
|
||||
if len(string(Sma[n])) = 1
|
||||
see " " + Sma[n]
|
||||
ok
|
||||
if len(string(Sma[n])) = 2
|
||||
see " " + Sma[n]
|
||||
ok
|
||||
if len(string(Sma[n])) = 3
|
||||
see " " + Sma[n]
|
||||
ok
|
||||
if len(string(Sma[n])) = 4
|
||||
see " " + Sma[n]
|
||||
ok
|
||||
if n%5 = 0
|
||||
see nl
|
||||
ok
|
||||
next
|
||||
|
||||
see nl
|
||||
see "Hundredth SPDS prime: " + Sma[100]
|
||||
|
|
|
|||
|
|
@ -0,0 +1,85 @@
|
|||
# numbrix.py by Xing216
|
||||
MOVES = [(1, 0), (0, 1), (-1, 0), (0, -1)]
|
||||
class Numbrix:
|
||||
def __init__(self) -> None:
|
||||
self.grid: list[list[int]]
|
||||
self.clues: list[int]
|
||||
self.totalToFill: int
|
||||
self.startRow: int
|
||||
self.StartCol: int
|
||||
def solve(self, row, col, count:int, nextClue: int) -> bool:
|
||||
if count > self.totalToFill:
|
||||
return True
|
||||
back = self.grid[row][col]
|
||||
if back not in [0, count]:
|
||||
return False
|
||||
if back == 0 and nextClue < len(self.clues) and self.clues[nextClue] == count:
|
||||
return False
|
||||
nextClue = nextClue
|
||||
if back == count: nextClue += 1
|
||||
self.grid[row][col] = count
|
||||
for move in MOVES:
|
||||
if self.solve(row + move[1], col + move[0], count + 1, nextClue):
|
||||
return True
|
||||
self.grid[row][col] = back
|
||||
def xprint(self):
|
||||
for row in self.grid:
|
||||
for val in row:
|
||||
if val != -1:
|
||||
print(f"{val:02d} ",end='')
|
||||
print()
|
||||
def initNumbrix(board: list[str]) -> Numbrix:
|
||||
result = Numbrix()
|
||||
nRows = len(board)
|
||||
nCols = len(board[0].split(','))
|
||||
result.grid = [[-1]*(nCols + 2) for _ in range(nRows + 2)]
|
||||
result.totalToFill = nRows * nCols
|
||||
xlist = []
|
||||
for r, row in enumerate(board):
|
||||
row = row.split(',')
|
||||
for c, tile in enumerate(row):
|
||||
val = int(tile)
|
||||
result.grid[r + 1][c + 1] = val
|
||||
if val > 0:
|
||||
xlist.append(val)
|
||||
if val == 1:
|
||||
result.startRow = r + 1
|
||||
result.startCol = c + 1
|
||||
xlist.sort()
|
||||
result.clues = xlist
|
||||
return result
|
||||
if __name__ == "__main__":
|
||||
EXAMPLE1 = ["00,00,00,00,00,00,00,00,00",
|
||||
"00,00,46,45,00,55,74,00,00",
|
||||
"00,38,00,00,43,00,00,78,00",
|
||||
"00,35,00,00,00,00,00,71,00",
|
||||
"00,00,33,00,00,00,59,00,00",
|
||||
"00,17,00,00,00,00,00,67,00",
|
||||
"00,18,00,00,11,00,00,64,00",
|
||||
"00,00,24,21,00,01,02,00,00",
|
||||
"00,00,00,00,00,00,00,00,00"]
|
||||
EXAMPLE2 = ["00,00,00,00,00,00,00,00,00",
|
||||
"00,11,12,15,18,21,62,61,00",
|
||||
"00,06,00,00,00,00,00,60,00",
|
||||
"00,33,00,00,00,00,00,57,00",
|
||||
"00,32,00,00,00,00,00,56,00",
|
||||
"00,37,00,01,00,00,00,73,00",
|
||||
"00,38,00,00,00,00,00,72,00",
|
||||
"00,43,44,47,48,51,76,77,00",
|
||||
"00,00,00,00,00,00,00,00,00"]
|
||||
EXAMPLE3 = ["17,00,00,00,11,00,00,00,59",
|
||||
"00,15,00,00,06,00,00,61,00",
|
||||
"00,00,03,00,00,00,63,00,00",
|
||||
"00,00,00,01,66,00,00,00,00",
|
||||
"23,24,00,68,67,78,00,54,55",
|
||||
"00,00,00,00,72,00,00,00,00",
|
||||
"00,00,35,00,00,00,49,00,00",
|
||||
"00,29,00,00,40,00,00,47,00",
|
||||
"31,00,00,00,39,00,00,00,45"]
|
||||
for i, board in enumerate([EXAMPLE1,EXAMPLE2, EXAMPLE3]):
|
||||
numbrix = initNumbrix(board)
|
||||
if numbrix.solve(numbrix.startRow, numbrix.startCol, 1, 0):
|
||||
print(f"Solution for example {i+1}:", end="")
|
||||
numbrix.xprint()
|
||||
else:
|
||||
"No solution."
|
||||
|
|
@ -57,8 +57,7 @@ module Sort_an_array_of_composite_structures{
|
|||
return
|
||||
}
|
||||
Sort_an_array_of_composite_structures
|
||||
|
||||
|
||||
Pint
|
||||
module Checkit2 {
|
||||
Inventory Alfa="Joe":=5531, "Adam":=2341, "Bernie":=122
|
||||
Append Alfa, "Walter":=1234, "David":=19
|
||||
|
|
@ -69,6 +68,7 @@ module Checkit2 {
|
|||
}
|
||||
}
|
||||
Checkit2
|
||||
Print
|
||||
module Checkit3 {
|
||||
class any {
|
||||
x
|
||||
|
|
@ -80,11 +80,37 @@ module Checkit3 {
|
|||
Sort Alfa
|
||||
k=Each(Alfa)
|
||||
While k {
|
||||
\\ k^ is the index number by k cursor
|
||||
\\ Alfa("joe") return object
|
||||
\\ Alfa(0!) return first element object
|
||||
\\ Alfa(k^!) return (k^) objext
|
||||
' k^ is the index number by k cursor
|
||||
' Alfa("joe") return object
|
||||
' Alfa(0!) return first element object
|
||||
' Alfa(k^!) return (k^) objext
|
||||
Print eval$(Alfa, k^), Alfa(k^!).x
|
||||
}
|
||||
}
|
||||
Checkit3
|
||||
|
||||
Module Sort2Darray {
|
||||
const ascending=0, descending=1
|
||||
const Names=0, Rate=1
|
||||
flush
|
||||
Data "Bernie", 1
|
||||
Data "Adam", 2341
|
||||
Data "David", 19
|
||||
Data "Bernie", 5
|
||||
Data "Joe", 5531
|
||||
Data "Walter", 1234
|
||||
Data "Bernie", 122
|
||||
k=stack.size/2
|
||||
dim a(k,2)
|
||||
Pen 15 {Print "Fill Array"}
|
||||
for i=0 to k-1: read a(i,0), a(i,1): next
|
||||
Pen 15 {Print "Unsorted"}
|
||||
for i=0 to k-1: ? a(i,0), a(i,1): next
|
||||
' there is a special sort for 2D arrays
|
||||
profiler
|
||||
sort a(),0,k-1,Names, ascending, Rate, descending
|
||||
print timecount
|
||||
Pen 15 {Print "Sorted"}
|
||||
for i=0 to k-1: ? a(i,0), a(i,1): next
|
||||
}
|
||||
Sort2Darray
|
||||
|
|
|
|||
|
|
@ -0,0 +1,24 @@
|
|||
;
|
||||
; substution.lsp
|
||||
;
|
||||
(defvar _original "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ")
|
||||
(defvar _substitute "dthnxkmqrwzseglyoaubjpcfivTKXMGVUPOIRFDEJZNYWCAQSLBH")
|
||||
(defvar _text "The quick brown fox jumps over the lazy dog!")
|
||||
|
||||
(defun encode (_plaintext _original _substitute)
|
||||
(map 'string
|
||||
#'(lambda (_char)
|
||||
(let*
|
||||
((_offset (position _char _original)))
|
||||
(if _offset
|
||||
(aref _substitute _offset)
|
||||
_char)))
|
||||
_plaintext))
|
||||
|
||||
(print _text)
|
||||
(setq _text (encode _text _original _substitute))
|
||||
(print _text)
|
||||
(setq _text (encode _text _substitute _original))
|
||||
(print _text)
|
||||
|
||||
(exit)
|
||||
|
|
@ -0,0 +1,193 @@
|
|||
#include <algorithm>
|
||||
#include <chrono>
|
||||
#include <cstdint>
|
||||
#include <fstream>
|
||||
#include <iostream>
|
||||
#include <limits>
|
||||
#include <map>
|
||||
#include <set>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
class Node {
|
||||
public:
|
||||
Node(const int32_t& start, const int32_t& end) : start(start), end(end) {}
|
||||
|
||||
int32_t edge_length(const int32_t& text_index) {
|
||||
return std::min(end, text_index + 1) - start;
|
||||
}
|
||||
|
||||
int32_t start, end, parent_link = 0, leaf_index = 0;
|
||||
std::map<char, int32_t> children{ };
|
||||
};
|
||||
|
||||
class SuffixTree {
|
||||
public:
|
||||
SuffixTree(const std::string& word) {
|
||||
text = word + '\u0004'; // Terminal character
|
||||
|
||||
nodes.reserve(2 * text.length());
|
||||
root = newNode(UNDEFINED, UNDEFINED);
|
||||
active_node = root;
|
||||
|
||||
for ( const char& character : text ) {
|
||||
extend_suffix_tree(character);
|
||||
}
|
||||
}
|
||||
|
||||
std::map<std::string, std::set<int32_t>> get_longest_repeated_substrings() {
|
||||
std::vector<int32_t> indexes = doTraversal();
|
||||
std::string word = text.substr(0, text.length() - 1);
|
||||
std::map<std::string, std::set<int32_t>> result{ };
|
||||
|
||||
if ( indexes.front() > 0 ) {
|
||||
for ( uint32_t i = 1; i < indexes.size(); ++i ) {
|
||||
std::string substring = word.substr(indexes[i], indexes.front());
|
||||
result[substring].insert(indexes[i]);
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
private:
|
||||
void extend_suffix_tree(const char& character) {
|
||||
need_parent_link = UNDEFINED;
|
||||
remainder++;
|
||||
|
||||
while ( remainder > 0 ) {
|
||||
if ( active_length == 0 ) {
|
||||
active_edge = text_index;
|
||||
}
|
||||
|
||||
if ( ! nodes[active_node].children.contains(text[active_edge]) ) {
|
||||
const int32_t leaf = newNode(text_index, LEAF_NODE);
|
||||
nodes[active_node].children[text[active_edge]] = leaf;
|
||||
add_suffix_link(active_node);
|
||||
} else {
|
||||
const int32_t next = nodes[active_node].children[text[active_edge]];
|
||||
if ( walk_down(next) ) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if ( text[nodes[next].start + active_length] == character ) {
|
||||
active_length++;
|
||||
add_suffix_link(active_node);
|
||||
break;
|
||||
}
|
||||
|
||||
const uint32_t split = newNode(nodes[next].start, nodes[next].start + active_length);
|
||||
nodes[active_node].children[text[active_edge]] = split;
|
||||
const int32_t leaf = newNode(text_index, LEAF_NODE);
|
||||
nodes[split].children[character] = leaf;
|
||||
nodes[next].start += active_length;
|
||||
nodes[split].children[text[nodes[next].start]] = next;
|
||||
add_suffix_link(split);
|
||||
}
|
||||
|
||||
remainder--;
|
||||
|
||||
if ( active_node == root && active_length > 0 ) {
|
||||
active_length--;
|
||||
active_edge = text_index - remainder + 1;
|
||||
} else {
|
||||
active_node = ( nodes[active_node].parent_link > 0 ) ? nodes[active_node].parent_link : root;
|
||||
}
|
||||
}
|
||||
|
||||
text_index++;
|
||||
}
|
||||
|
||||
bool walk_down(const int32_t& node) {
|
||||
if ( active_length >= nodes[node].edge_length(text_index) ) {
|
||||
active_edge += nodes[node].edge_length(text_index);
|
||||
active_length -= nodes[node].edge_length(text_index);
|
||||
active_node = node;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
void add_suffix_link(const int32_t& node) {
|
||||
if ( need_parent_link != UNDEFINED ) {
|
||||
nodes[need_parent_link].parent_link = node;
|
||||
}
|
||||
|
||||
need_parent_link = node;
|
||||
}
|
||||
|
||||
uint32_t newNode(const int32_t& start, const int32_t& end) {
|
||||
Node node(start, end);
|
||||
node.leaf_index = ( end == LEAF_NODE ) ? leaf_index_generator++ : UNDEFINED;
|
||||
nodes[current_node] = node;
|
||||
|
||||
return current_node++;
|
||||
}
|
||||
|
||||
std::vector<int32_t> doTraversal() {
|
||||
std::vector<int32_t> indexes{ };
|
||||
indexes.emplace_back(UNDEFINED);
|
||||
|
||||
return traversal(indexes, nodes[root], 0);
|
||||
}
|
||||
|
||||
std::vector<int32_t> traversal(std::vector<int32_t>& indexes, Node node, const int32_t& height) {
|
||||
if ( node.leaf_index == UNDEFINED ) {
|
||||
for ( std::pair<char, int32_t> entry : node.children ) {
|
||||
Node child = nodes[entry.second];
|
||||
traversal(indexes, child, height + child.edge_length(text_index));
|
||||
}
|
||||
} else if ( indexes.front() < height - node.edge_length(text_index) ) {
|
||||
indexes.clear();
|
||||
indexes.emplace_back(height - node.edge_length(text_index));
|
||||
indexes.emplace_back(node.leaf_index);
|
||||
} else if ( indexes.front() == height - node.edge_length(text_index) ) {
|
||||
indexes.emplace_back(node.leaf_index);
|
||||
}
|
||||
|
||||
return indexes;
|
||||
}
|
||||
|
||||
std::vector<Node> nodes;
|
||||
std::string text;
|
||||
|
||||
int32_t root;
|
||||
int32_t active_node, active_length = 0, active_edge = 0;
|
||||
int32_t text_index = 0, current_node = 0, need_parent_link = 0, remainder = 0, leaf_index_generator = 0;
|
||||
|
||||
const int32_t UNDEFINED = -1;
|
||||
const int32_t LEAF_NODE = INT32_MAX;
|
||||
};
|
||||
|
||||
int main() {
|
||||
std::vector<int32_t> limits = { 1'000, 10'000, 100'000 };
|
||||
|
||||
for ( const int32_t& limit : limits ) {
|
||||
std::ifstream stream("../piDigits.txt");
|
||||
std::string contents( ( std::istreambuf_iterator<char>(stream) ),
|
||||
( std::istreambuf_iterator<char>() ) );
|
||||
std::string pi_digits = contents.substr(0, limit);
|
||||
|
||||
auto begin = std::chrono::high_resolution_clock::now();
|
||||
SuffixTree tree(pi_digits);
|
||||
std::map<std::string, std::set<int32_t>> substrings = tree.get_longest_repeated_substrings();
|
||||
auto end = std::chrono::high_resolution_clock::now();
|
||||
auto elapsed = std::chrono::duration_cast<std::chrono::milliseconds>( end - begin );
|
||||
|
||||
std::cout << "First " << limit << " digits of pi has longest repeated characters:" << std::endl;
|
||||
for ( std::pair<std::string, std::set<int32_t>> entry : substrings ) {
|
||||
std::cout << " '" << entry.first << "' starting at index ";
|
||||
for ( int32_t index : entry.second ) {
|
||||
std::cout << index << " ";
|
||||
}
|
||||
std::cout << std::endl;
|
||||
}
|
||||
|
||||
std::cout << "Time taken: " << elapsed << " milliseconds." << std::endl << std::endl;
|
||||
}
|
||||
|
||||
std::cout << "The timings show that the implementation has approximately linear performance."
|
||||
<< std::endl;
|
||||
}
|
||||
|
|
@ -8,6 +8,8 @@ import java.util.Iterator;
|
|||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.SortedMap;
|
||||
import java.util.TreeMap;
|
||||
import java.util.TreeSet;
|
||||
|
||||
public final class UkkonenSuffixTree {
|
||||
|
|
@ -48,7 +50,7 @@ public final class UkkonenSuffixTree {
|
|||
text = Arrays.copyOfRange(aWord.toCharArray(), 0, aWord.length() + 1);
|
||||
text[aWord.length()] = '\uF123'; // Terminal character
|
||||
|
||||
nodes = new Node[2 * aWord.length() + 2];
|
||||
nodes = new Node[2 * text.length];
|
||||
root = newNode(UNDEFINED, UNDEFINED);
|
||||
activeNode = root;
|
||||
|
||||
|
|
@ -60,9 +62,9 @@ public final class UkkonenSuffixTree {
|
|||
public Map<String, Set<Integer>> getLongestRepeatedSubstrings() {
|
||||
List<Integer> indexes = doTraversal();
|
||||
String word = String.valueOf(text).substring(0, text.length - 1);
|
||||
Map<String, Set<Integer>> result = new HashMap<String, Set<Integer>>();
|
||||
SortedMap<String, Set<Integer>> result = new TreeMap<String, Set<Integer>>();
|
||||
|
||||
if ( indexes.get(0) > 0 ) {
|
||||
if ( indexes.getFirst() > 0 ) {
|
||||
for ( int i = 1; i < indexes.size(); i++ ) {
|
||||
String substring = word.substring(indexes.get(i), indexes.get(i) + indexes.get(0));
|
||||
result.computeIfAbsent(substring, k -> new TreeSet<Integer>()).add(indexes.get(i));
|
||||
|
|
|
|||
|
|
@ -0,0 +1,66 @@
|
|||
#include "windows.bi"
|
||||
#include "win/wininet.bi"
|
||||
|
||||
Const BUFFER_SIZE = 4096
|
||||
|
||||
Function GetWebPage(url As String) As String
|
||||
Dim As HINTERNET hInternet = InternetOpen("TimeGetter", INTERNET_OPEN_TYPE_DIRECT, NULL, NULL, 0)
|
||||
Dim As String resultado = ""
|
||||
|
||||
If hInternet Then
|
||||
Dim As HINTERNET hConnect = InternetOpenUrl(hInternet, url, NULL, 0, INTERNET_FLAG_RELOAD, 0)
|
||||
|
||||
If hConnect Then
|
||||
Dim As String buffer = Space(BUFFER_SIZE)
|
||||
Dim As DWORD bytesRead
|
||||
|
||||
Do
|
||||
If InternetReadFile(hConnect, Strptr(buffer), BUFFER_SIZE, @bytesRead) Then
|
||||
If bytesRead = 0 Then Exit Do
|
||||
resultado &= Left(buffer, bytesRead)
|
||||
End If
|
||||
Loop
|
||||
|
||||
InternetCloseHandle(hConnect)
|
||||
End If
|
||||
InternetCloseHandle(hInternet)
|
||||
End If
|
||||
|
||||
Return resultado
|
||||
End Function
|
||||
|
||||
Function ScrapeTime(pageAddress As String, timeZone As String) As String
|
||||
Dim As String page = GetWebPage(pageAddress)
|
||||
|
||||
If Len(page) = 0 Then Return "Cannot connect"
|
||||
|
||||
Dim As Integer startPos = 1
|
||||
Do
|
||||
Dim As Integer endPos = Instr(startPos, page, "<BR>")
|
||||
If endPos = 0 Then endPos = Len(page)
|
||||
|
||||
Dim As String linea = Mid(page, startPos, endPos - startPos)
|
||||
|
||||
If Instr(linea, timeZone) Then
|
||||
For i As Integer = 1 To Len(linea) - 7
|
||||
Dim As String char1 = Mid(linea, i, 1)
|
||||
Dim As String char2 = Mid(linea, i+4, 1)
|
||||
If char1 >= "0" And char1 <= "9" And Mid(linea, i+2, 1) = ":" And _
|
||||
char2 >= "0" And char2 <= "9" And Mid(linea, i+5, 1) = ":" Then
|
||||
Return Mid(linea, i, 8)
|
||||
End If
|
||||
Next
|
||||
End If
|
||||
|
||||
If endPos = Len(page) Then Exit Do
|
||||
startPos = endPos + 4
|
||||
Loop
|
||||
|
||||
Return "Time not found"
|
||||
End Function
|
||||
|
||||
' Main program
|
||||
Dim As String url = "https://rosettacode.org/wiki/Talk:Web_scraping"
|
||||
Print ScrapeTime(url, "UTC")
|
||||
|
||||
Sleep
|
||||
Loading…
Reference in New Issue