Data Update

This commit is contained in:
Ingy döt Net 2023-07-09 17:42:30 -04:00
parent 015c2add84
commit e50b5c3114
206 changed files with 6337 additions and 523 deletions

View File

@ -0,0 +1 @@
../../Task/Caesar-cipher/AArch64-Assembly

View File

@ -0,0 +1 @@
../../Task/Command-line-arguments/AArch64-Assembly

View File

@ -0,0 +1 @@
../../Task/K-d-tree/AArch64-Assembly

View File

@ -0,0 +1 @@
../../Task/Quickselect-algorithm/AArch64-Assembly

View File

@ -0,0 +1 @@
../../Task/Rot-13/AArch64-Assembly

View File

@ -0,0 +1 @@
../../Task/Substitution-cipher/AArch64-Assembly

View File

@ -0,0 +1 @@
../../Task/Quickselect-algorithm/ARM-Assembly

1
Lang/ARM-Assembly/Rot-13 Symbolic link
View File

@ -0,0 +1 @@
../../Task/Rot-13/ARM-Assembly

View File

@ -0,0 +1 @@
../../Task/Substitution-cipher/ARM-Assembly

View File

@ -0,0 +1 @@
../../Task/Find-if-a-point-is-within-a-triangle/ATS

View File

@ -0,0 +1 @@
../../Task/War-card-game/Applesoft-BASIC

View File

@ -0,0 +1 @@
../../Task/Hello-world-Text/Atari-BASIC

1
Lang/C++/Babylonian-spiral Symbolic link
View File

@ -0,0 +1 @@
../../Task/Babylonian-spiral/C++

View File

@ -0,0 +1 @@
../../Task/Bioinformatics-Global-alignment/C++

1
Lang/C++/Biorhythms Symbolic link
View File

@ -0,0 +1 @@
../../Task/Biorhythms/C++

1
Lang/C++/Blum-integer Symbolic link
View File

@ -0,0 +1 @@
../../Task/Blum-integer/C++

View File

@ -0,0 +1 @@
../../Task/Boyer-Moore-string-search/C++

View File

@ -0,0 +1 @@
../../Task/Camel-case-and-snake-case/C++

1
Lang/C++/Colorful-numbers Symbolic link
View File

@ -0,0 +1 @@
../../Task/Colorful-numbers/C++

View File

@ -0,0 +1 @@
../../Task/Radical-of-an-integer/C

View File

@ -0,0 +1 @@
../../Task/Radical-of-an-integer/CLU

1
Lang/Cowgol/Long-year Symbolic link
View File

@ -0,0 +1 @@
../../Task/Long-year/Cowgol

View File

@ -0,0 +1 @@
../../Task/Radical-of-an-integer/Cowgol

1
Lang/Draco/Long-year Symbolic link
View File

@ -0,0 +1 @@
../../Task/Long-year/Draco

1
Lang/EMal/Character-codes Symbolic link
View File

@ -0,0 +1 @@
../../Task/Character-codes/EMal

View File

@ -0,0 +1 @@
../../Task/Largest-number-divisible-by-its-digits/EasyLang

View File

@ -0,0 +1 @@
../../Task/Simple-turtle-graphics/EasyLang

View File

@ -0,0 +1 @@
../../Task/Sisyphus-sequence/Free-Pascal-Lazarus

View File

@ -0,0 +1 @@
../../Task/Boyer-Moore-string-search/FreeBASIC

View File

@ -0,0 +1 @@
../../Task/Camel-case-and-snake-case/FreeBASIC

View File

@ -0,0 +1 @@
../../Task/Abelian-sandpile-model/FutureBasic

View File

@ -0,0 +1 @@
../../Task/Abelian-sandpile-model-Identity/FutureBasic

View File

@ -0,0 +1 @@
../../Task/Arithmetic-geometric-mean-Calculate-Pi/FutureBasic

View File

@ -0,0 +1 @@
../../Task/Cistercian-numerals/FutureBasic

View File

@ -0,0 +1 @@
../../Task/Determine-if-a-string-has-all-unique-characters/FutureBasic

View File

@ -0,0 +1 @@
../../Task/Draw-a-cuboid/FutureBasic

1
Lang/FutureBasic/File-size Symbolic link
View File

@ -0,0 +1 @@
../../Task/File-size/FutureBasic

1
Lang/FutureBasic/HTTP Symbolic link
View File

@ -0,0 +1 @@
../../Task/HTTP/FutureBasic

View File

@ -0,0 +1 @@
../../Task/Motzkin-numbers/FutureBasic

View File

@ -0,0 +1 @@
../../Task/Mutual-recursion/FutureBasic

View File

@ -0,0 +1 @@
../../Task/Pythagorean-quadruples/FutureBasic

View File

@ -0,0 +1 @@
../../Task/Symmetric-difference/FutureBasic

View File

@ -0,0 +1 @@
../../Task/Simple-turtle-graphics/IS-BASIC

View File

@ -0,0 +1 @@
../../Task/Euclid-Mullin-sequence/J

1
Lang/J/Sylvesters-sequence Symbolic link
View File

@ -0,0 +1 @@
../../Task/Sylvesters-sequence/J

1
Lang/Java/Amb Symbolic link
View File

@ -0,0 +1 @@
../../Task/Amb/Java

1
Lang/Java/Biorhythms Symbolic link
View File

@ -0,0 +1 @@
../../Task/Biorhythms/Java

1
Lang/Java/Blum-integer Symbolic link
View File

@ -0,0 +1 @@
../../Task/Blum-integer/Java

View File

@ -0,0 +1 @@
../../Task/Boyer-Moore-string-search/Java

View File

@ -0,0 +1 @@
../../Task/Camel-case-and-snake-case/Java

1
Lang/Jq/Bifid-cipher Symbolic link
View File

@ -0,0 +1 @@
../../Task/Bifid-cipher/Jq

View File

@ -0,0 +1 @@
../../Task/Radical-of-an-integer/MAD

View File

@ -0,0 +1 @@
../../Task/Abundant-deficient-and-perfect-number-classifications/MiniScript

View File

@ -0,0 +1 @@
../../Task/Symmetric-difference/Miranda

View File

@ -0,0 +1 @@
../../Task/Josephus-problem/Palo-Alto-Tiny-BASIC

View File

@ -0,0 +1 @@
../../Task/Largest-proper-divisor-of-n/Palo-Alto-Tiny-BASIC

View File

@ -0,0 +1 @@
../../Task/Sylvesters-sequence/Pascal

View File

@ -22,6 +22,7 @@
[https://ideone.com/fork/685KSI Try Raku on ideone].<br>
[https://fglock.github.io/Perlito/perlito/perlito6.html Try Raku with Perlito].<br>
[http://rakudist.raku.org/play/ (RakuPlay is currently down)].<br>
[https://ato.pxeger.com/run?1=m72kKDG7dMGCpaUlaboWaBSUBgA Try Raku on Attempt This Online].<br>
{{infobox_end}}
Raku is a member of the Perl family of programming languages.
Though it resembles previous versions of [[Perl]] to no small degree, Raku is substantially a new language. By design, it isn't backwards-compatible with Perl 5.

1
Lang/Ruby/Blum-integer Symbolic link
View File

@ -0,0 +1 @@
../../Task/Blum-integer/Ruby

View File

@ -0,0 +1 @@
../../Task/Radical-of-an-integer/Ruby

1
Lang/Ruby/Sisyphus-sequence Symbolic link
View File

@ -0,0 +1 @@
../../Task/Sisyphus-sequence/Ruby

View File

@ -0,0 +1 @@
../../Task/Soloways-recurring-rainfall/Ruby

View File

@ -14,7 +14,7 @@ V (Vlang) is used here on Rosetta Code to disambiguate from the other language c
[https://vlang.io V] first appeared in 2019 in a trial web sandbox, "The V Playground".
V sources are published at [https://github.com/vlang/v GitHub], presently on version [https://github.com/vlang/v/releases 0.3.x].
V sources are published at [https://github.com/vlang/v GitHub], presently on version [https://github.com/vlang/v/releases 0.4.x].
V is an easier to learn, read, and use language. Its design has been influenced by Go, Oberon, Rust, Swift, Kotlin, and Python. Documentation can be found [https://github.com/vlang/v/blob/master/doc/docs.md here].
@ -28,7 +28,7 @@ https://vlang.io
==Helpful links==
* [https://www.youtube.com/watch?v=ZO3vlwqvTrc Overview and introduction to Vlang] by Erdet Nasufi
* [https://www.youtube.com/watch?v=_dIAcNp9bJs Overview and presentation about Vlang] given to IBM
* [https://www.youtube.com/watch?v=_dIAcNp9bJs Overview and presentation about Vlang] for IBM
* Some of the code snippets are available at the archived [//github.com/v-community/v_rosetta V-Community (V Rosetta) GitHub]
* More info on the below can be found at [https://modules.vlang.io/ modules used by V]

View File

@ -10,6 +10,12 @@ Actually it is simply an alternate syntax reader for Clojure and Lingy.
YAMLScript offers all the power of Lisp but with a various syntax features that strive to make it more readable than encoding everything as nested s-expression forms.
==Installing YAMLScript==
Run this command to install the 'yamlscript' command line runner program.
cpanm YAML
==See Also==
* [https://metacpan.org/pod/YAMLScript YAMLScript Doc]

1
Lang/YAMLScript/Factorial Symbolic link
View File

@ -0,0 +1 @@
../../Task/Factorial/YAMLScript

View File

@ -0,0 +1 @@
../../Task/Fibonacci-sequence/YAMLScript

View File

@ -0,0 +1 @@
../../Task/Hello-world-Text/YAMLScript

View File

@ -2,12 +2,11 @@ type NinetynineBottles
int DEFAULT_BOTTLES_COUNT = 99
model
int initialBottlesCount, bottlesCount
new by int bottlesCount
new by int =bottlesCount
me.initialBottlesCount = bottlesCount
me.bottlesCount = bottlesCount
end
fun subject = text by block do return when(me.bottlesCount == 1, "bottle", "bottles") end
fun bottles = text by block do return when(me.bottlesCount == 0, "no more", text!me.bottlesCount) end
fun subject = <|when(me.bottlesCount == 1, "bottle", "bottles")
fun bottles = <|when(me.bottlesCount == 0, "no more", text!me.bottlesCount)
fun goToWall = void by block
text line = me.bottles() + " " + me.subject() + " of beer on the wall, " +
me.bottles() + " " + me.subject() + " of beer."

View File

@ -1,18 +1,23 @@
main(number=99):
map:
- println
- map:
- paragraph
- range(number, 0, -1)
#!/usr/bin/env yamlscript
paragraph(num): |
# Print the verses to "99 Bottles of Beer"
#
# usage:
# yamlscript 99-bottles.ys [<count>]
defn main(number=99):
map(say):
map(paragraph):
(number .. 1)
defn paragraph(num): |
$(bottles num) of beer on the wall,
$(bottles num) of beer.
Take one down, pass it around.
$(bottles (num - 1)) of beer on the wall.
bottles(n):
cond: [
(n == 0), "No more bottles",
(n == 1), "1 bottle",
:else, "$n bottles" ]
defn bottles(n):
???:
(n == 0) : "No more bottles"
(n == 1) : "1 bottle"
:else : "$n bottles"

View File

@ -0,0 +1,124 @@
void local fn SandpilePrint( s(2,2) as ^long )
long r, c
for r = 0 to 2
for c = 0 to 2
printf @"%ld\t",s(r,c)
next
print
next
print
end fn
void local fn SandpileTopple( s(2,2) as ^long )
BOOL stable = NO
long r, c, value
while ( stable == NO )
stable = YES
for r = 0 to 2
for c = 0 to 2
value = s(r,c)
if ( value > 3 )
s(r,c) -= 4
if ( r > 0 ) then s(r-1,c)++
if ( r < 2 ) then s(r+1,c)++
if ( c > 0 ) then s(r,c-1)++
if ( c < 2 ) then s(r,c+1)++
print @"⇣ ⇣ ⇣ ⇣ ⇣"
print
fn SandpilePrint( s(0,0) )
stable = NO : break
end if
next
if ( stable == NO ) then break
next
wend
end fn
void local fn SandpileLoad( s(2,2) as ^long, values as CFStringRef )
long r, c, i = 0
for r = 0 to 2
for c = 0 to 2
s(r,c) = intval(mid(values,i,1))
i++
next
next
end fn
void local fn DoIt
long r, c, s(2,2), s1(2,2), s2(2,2), s3(2,2), s3_id(2,2)
// s
text @"Menlo-Bold" : print @"avalanche"
text @"Menlo" : print @"----------"
fn SandpileLoad( s(0,0), @"433312023" )
fn SandpilePrint( s(0,0) )
fn SandpileTopple( s(0,0) )
// s1
fn SandpileLoad( s1(0,0), @"120211013" )
// s2
fn SandpileLoad( s2(0,0), @"213101010" )
// s1 + s2
for r = 0 to 2
for c = 0 to 2
s(r,c) = s1(r,c) + s2(r,c)
next
next
text @"Menlo-Bold" : print @"s1 + s2"
text @"Menlo" : print @"----------"
fn SandpileTopple( s(0,0) )
fn SandpilePrint( s(0,0) )
// s2 + s1
for r = 0 to 2
for c = 0 to 2
s(r,c) = s2(r,c) + s1(r,c)
next
next
text @"Menlo-Bold" : print @"s2 + s1"
text @"Menlo" : print @"----------"
fn SandpileTopple( s(0,0) )
fn SandpilePrint( s(0,0) )
// s3
fn SandpileLoad( s3(0,0), @"333333333" )
text @"Menlo-Bold" : print @"s3"
text @"Menlo" : print @"----------"
fn SandpilePrint( s3(0,0) )
// s3_id
fn SandpileLoad( s3_id(0,0), @"212101212" )
text @"Menlo-Bold" : print @"s3_id"
text @"Menlo" : print @"----------"
fn SandpilePrint( s3_id(0,0) )
// s3 + s3_id
for r = 0 to 2
for c = 0 to 2
s(r,c) = s3(r,c) + s3_id(r,c)
next
next
text @"Menlo-Bold" : print @"s3+s3_id"
text @"Menlo" : print @"----------"
fn SandpilePrint( s(0,0) )
fn SandpileTopple( s(0,0) )
// s3_id + s3_id
for r = 0 to 2
for c = 0 to 2
s(r,c) = s3_id(r,c) + s3_id(r,c)
next
next
text @"Menlo-Bold" : print @"s3_id+s3_id"
text @"Menlo" : print @"-----------"
fn SandpilePrint( s(0,0) )
fn SandpileTopple( s(0,0) )
end fn
fn DoIt
HandleEvents

View File

@ -0,0 +1,151 @@
_mFile = 1
begin enum
_iClose
end enum
_window = 1
begin enum 1
_gridView
_gridSizeLabel
_gridSizeFld
_centerNumLabel
_centerNumFld
_colorRadio
_monoRadio
_avalancheBtn
end enum
void local fn BuildMenu
menu _mFile,,, @"File"
menu _mFile, _iClose,, @"Close", @"w"
MenuItemSetAction( _mFile, _iClose, @"performClose:" )
end fn
void local fn BuildWindow
window _window, @"Abelian Sandpile Model", (0,0,513,360), NSWindowStyleMaskTitled + NSWindowStyleMaskClosable + NSWindowStyleMaskMiniaturizable
subclass view _gridView, (20,20,320,320)
textlabel _gridSizeLabel, @"Grid size:", (385,322,61,16)
textfield _gridSizeFld,, @"5", (452,319,41,21)
ControlSetFormat( _gridSizeFld, @"0123456789", YES, 4, 0 )
textlabel _centerNumLabel, @"Center number:", (347,285,99,16)
textfield _centerNumFld,, @"32", (452,282,41,21)
ControlSetFormat( _centerNumFld, @"0123456789", YES, 4, 0 )
radiobutton _colorRadio,, NSControlStateValueOn, @"Color", (367,249,59,18)
radiobutton _monoRadio,, NSControlStateValueOff, @"Mono", (432,249,61,18)
button _avalancheBtn,,, @"Avalanche", (375,13,96,32)
WindowMakeFirstResponder( _window, _gridSizeFld )
end fn
void local fn ViewDrawRect
long gridSize = fn ControlIntegerValue(_gridSizeFld)
CGRect bounds = fn ViewBounds( _gridView )
CGFloat cellSize = bounds.size.width/gridSize
ColorRef col0 = fn ColorWhite, col1, col2, col3
long r, c, value
CGFloat x = 0, y = 0
ColorRef color
if ( fn ButtonState( _colorRadio ) == NSControlStateValueOn )
col1 = fn ColorRed
col2 = fn ColorGreen
col3 = fn ColorBlue
else
col1 = fn ColorWithRGB( 0.25, 0.25, 0.25, 1.0 )
col2 = fn ColorWithRGB( 0.5, 0.5, 0.5, 1.0 )
col3 = fn ColorWithRGB( 0.75, 0.75, 0.75, 1.0 )
end if
for r = 0 to gridSize-1
for c = 0 to gridSize-1
value = mda_integer(r,c)
select ( value )
case 1 : color = col1
case 2 : color = col2
case 3 : color = col3
case else : color = col0
end select
BezierPathFillRect( fn CGRectMake( x, y, cellSize, cellSize ), color )
x += cellSize
next
x = 0
y += cellSize
next
end fn
void local fn AvalancheAction
long r, c, gridSize = fn ControlIntegerValue(_gridSizeFld)
long centerNum = fn ControlIntegerValue(_centerNumFld)
long midNum = gridSize/2
long limit = gridSize-1
BOOL stable = NO
long value
// initialize array
mda_kill
for r = 0 to gridSize-1
for c = 0 to gridSize-1
mda(r,c) = 0
next
next
mda(midNum,midNum) = centerNum
// collapse
while ( stable == NO )
stable = YES
for r = 0 to gridSize-1
for c = 0 to gridSize-1
value = mda_integer(r,c)
if ( value > 3 )
mda(r,c) = @(mda_integer(r,c)-4)
if ( r > 0 ) then mda(r-1,c) = @(mda_integer(r-1,c) + 1)
if ( r < limit ) then mda(r+1,c) = @(mda_integer(r+1,c) + 1)
if ( c > 0 ) then mda(r,c-1) = @(mda_integer(r,c-1) + 1)
if ( c < limit ) then mda(r,c+1) = @(mda_integer(r,c+1) + 1)
stable = NO : break
end if
next
if ( stable == NO ) then break
next
wend
ViewSetNeedsDisplay( _gridView )
end fn
void local fn DoAppEvent( ev as long )
select ( ev )
case _appWillFinishLaunching
fn BuildMenu
fn BuildWindow
fn AvalancheAction
case _appShouldTerminateAfterLastWindowClosed : AppEventSetBool(YES)
end select
end fn
void local fn DoDialog( ev as long, tag as long, wnd as long, obj as CFTypeRef )
select ( ev )
case _btnClick
select ( tag )
case _avalancheBtn : fn AvalancheAction
case _gridSizeFld, _centerNumFld : fn AvalancheAction
case _colorRadio, _monoRadio : ViewSetNeedsDisplay( _gridView )
end select
case _viewDrawRect : fn ViewDrawRect
end select
end fn
on appevent fn DoAppEvent
on dialog fn DoDialog
HandleEvents

View File

@ -2,9 +2,6 @@ BEGIN # classify the numbers 1 : 20 000 as abudant, deficient or perfect #
INT abundant count := 0;
INT deficient count := 0;
INT perfect count := 0;
INT abundant example := 0;
INT deficient example := 0;
INT perfect example := 0;
INT max number = 20 000;
# construct a table of the proper divisor sums #
[ 1 : max number ]INT pds;
@ -15,39 +12,16 @@ BEGIN # classify the numbers 1 : 20 000 as abudant, deficient or perfect #
OD;
# classify the numbers #
FOR n TO max number DO
IF INT pd sum = pds[ n ];
pd sum < n
THEN
# have a deficient number #
deficient count +:= 1;
deficient example := n
ELIF pd sum = n
THEN
# have a perfect number #
perfect count +:= 1;
perfect example := n
INT pd sum = pds[ n ];
IF pd sum < n THEN
deficient count +:= 1
ELIF pd sum = n THEN
perfect count +:= 1
ELSE # pd sum > n #
# have an abundant number #
abundant count +:= 1;
abundant example := n
abundant count +:= 1
FI
OD;
# displays the classification, count and example #
PROC show result = ( STRING classification, INT count, example )VOID:
print( ( "There are "
, whole( count, -8 )
, " "
, classification
, " numbers up to "
, whole( max number, 0 )
, " e.g.: "
, whole( example, 0 )
, newline
)
);
# show how many of each type of number there are and an example #
show result( "abundant ", abundant count, abundant example );
show result( "deficient", deficient count, deficient example );
show result( "perfect ", perfect count, perfect example )
print( ( "abundant ", whole( abundant count, 0 ), newline ) );
print( ( "deficient ", whole( deficient count, 0 ), newline ) );
print( ( "perfect ", whole( perfect count, 0 ), newline ) )
END

View File

@ -0,0 +1,27 @@
do -- classify the numbers 1 : 20 000 as abudant, deficient or perfect
local abundantCount = 0
local deficientCount = 0
local perfectCount = 0
local maxNumber = 20000
-- construct a table of the proper divisor sums
local pds = {}
pds[ 1 ] = 0
for i = 2, maxNumber do pds[ i ] = 1 end
for i = 2, maxNumber do
for j = i + i, maxNumber, i do pds[ j ] = pds[ j ] + i end
end
-- classify the numbers
for n = 1, maxNumber do
local pdSum = pds[ n ]
if pdSum < n then
deficientCount = deficientCount + 1
elseif pdSum == n then
perfectCount = perfectCount + 1
else -- pdSum > n
abundantCount = abundantCount + 1
end
end
io.write( "abundant ", abundantCount, "\n" )
io.write( "deficient ", deficientCount, "\n" )
io.write( "perfect ", perfectCount, "\n" )
end

View File

@ -0,0 +1,30 @@
// classify the numbers 1 : 20 000 as abudant, deficient or perfect
abundantCount = 0
deficientCount = 0
perfectCount = 0
maxNumber = 20000
// construct a table of the proper divisor sums
pds = [0] * ( maxNumber + 1 )
pds[ 1 ] = 0
for i in range( 2, maxNumber )
pds[ i ] = 1
end for
for i in range( 2, maxNumber )
for j in range( i + i, maxNumber, i )
pds[ j ] = pds[ j ] + i
end for
end for
// classify the numbers
for n in range( 1, maxNumber )
pdSum = pds[ n ]
if pdSum < n then
deficientCount = deficientCount + 1
else if pdSum == n then
perfectCount = perfectCount + 1
else // pdSum > n
abundantCount = abundantCount + 1
end if
end for
print "abundant " + abundantCount
print "deficient " + deficientCount
print "perfect " + perfectCount

View File

@ -0,0 +1,26 @@
a = 0
d = 0
p = 0
for n = 1 to 20000
Pn = sumDivs(n)
if Pn > n a = a + 1 ok
if Pn < n d = d + 1 ok
if Pn = n p = p + 1 ok
next
see "Abundant : " + a + nl
see "Deficient: " + d + nl
see "Perfect : " + p + nl
func sumDivs (n)
if n < 2 return 0
else
sum = 1
sr = sqrt(n)
for d = 2 to sr
if n % d = 0
sum = sum + d
if d != sr sum = sum + n / d ok
ok
next
return sum
ok

View File

@ -0,0 +1,25 @@
maxNumber = 20000
abundantCount = 0
deficientCount = 0
perfectCount = 0
pds = list( maxNumber )
pds[ 1 ] = 0
for i = 2 to maxNumber pds[ i ] = 1 next
for i = 2 to maxNumber
for j = i + i to maxNumber step i pds[ j ] = pds[ j ] + i next
next
for n = 1 to maxNumber
pdSum = pds[ n ]
if pdSum < n
deficientCount = deficientCount + 1
but pdSum = n
perfectCount = perfectCount + 1
else # pdSum > n
abundantCount = abundantCount + 1
ok
next
see "Abundant : " + abundantCount + nl
see "Deficient: " + deficientCount + nl
see "Perfect : " + perfectCount + nl

View File

@ -0,0 +1,32 @@
var maxNumber = 20000
var abundantCount = 0
var deficientCount = 0
var perfectCount = 0
var pds = []
pds.add( 0 ) // element 0
pds.add( 0 ) // element 1
for( i in 2 .. maxNumber ){
pds.add( 1 )
}
for( i in 2 .. maxNumber ){
var j = i + i
while( j < maxNumber ){
pds[ j ] = pds[ j ] + i
j = j + i
}
}
for( n in 1 .. maxNumber ){
var pdSum = pds[ n ]
if ( pdSum < n ){
deficientCount = deficientCount + 1
} else if( pdSum == n ){
perfectCount = perfectCount + 1
} else { // pdSum > n
abundantCount = abundantCount + 1
}
}
System.print( "Abundant : %(abundantCount)" )
System.print( "Deficient: %(deficientCount)" )
System.print( "Perfect : %(perfectCount)" )

57
Task/Amb/C++/amb-2.cpp Normal file
View File

@ -0,0 +1,57 @@
#include <functional>
#include <iostream>
#include <numeric>
#include <string>
#include <vector>
std::string join(const std::string& delimiter, const std::vector<std::string>& list) {
return list.empty() ? "" : std::accumulate(++list.begin(), list.end(), list[0],
[delimiter](auto& a, auto& b) { return a + delimiter + b; });
}
std::vector<std::string> amb(std::function<bool(std::string&, std::string&)> func,
std::vector<std::vector<std::string>> options, std::string previous) {
if ( options.empty() ) {
return std::vector<std::string>();
}
for ( std::string& option : options.front() ) {
if ( ! previous.empty() && ! func(previous, option) ) {
continue;
}
if ( options.size() == 1 ) {
return std::vector<std::string>(1, option);
}
std::vector<std::vector<std::string>> next_options(options.begin() + 1, options.end());
std::vector<std::string> result = amb(func, next_options, option);
if ( ! result.empty() ) {
result.emplace(result.begin(), option);
return result;
}
}
return std::vector<std::string>();
}
std::string Amb(std::vector<std::vector<std::string>> options) {
std::function<bool(std::string, std::string)> continues =
[](std::string before, std::string after) { return before.back() == after.front(); };
std::vector<std::string> amb_result = amb(continues, options, "");
return ( amb_result.empty() ) ? "No match found" : join(" ", amb_result);
}
int main() {
std::vector<std::vector<std::string>> words = { { "the", "that", "a" },
{ "frog", "elephant", "thing" },
{ "walked", "treaded", "grows" },
{ "slowly", "quickly" } };
std::cout << Amb(words) << std::endl;
}

52
Task/Amb/Java/amb.java Normal file
View File

@ -0,0 +1,52 @@
import java.util.ArrayList;
import java.util.List;
import java.util.function.BiFunction;
import java.util.stream.Collectors;
import java.util.stream.Stream;
public final class AmbTask {
public static void main(String[] aArgs) {
List<List<String>> words = List.of(
List.of( "the", "that", "a" ),
List.of( "frog", "elephant", "thing" ),
List.of( "walked", "treaded", "grows" ),
List.of( "slowly", "quickly" ) );
System.out.println(Amb(words));
}
private static String Amb(List<List<String>> aOptions) {
BiFunction<String, String, Boolean> continues = (before, after) -> before.endsWith(after.substring(0, 1));
List<String> ambResult = amb(continues, aOptions, "");
return ( ambResult.isEmpty() ) ? "No match found" : String.join(" ", ambResult);
}
private static List<String> amb(
BiFunction<String, String, Boolean> aBiFunction, List<List<String>> aOptions, String aPrevious) {
if ( aOptions.isEmpty() ) {
return new ArrayList<String>();
}
for ( String option : aOptions.get(0) ) {
if ( ! aPrevious.isEmpty() && ! aBiFunction.apply(aPrevious, option) ) {
continue;
}
if ( aOptions.size() == 1 ) {
return Stream.of(option).collect(Collectors.toList());
}
List<String> result = (ArrayList<String>) amb(aBiFunction, aOptions.subList(1, aOptions.size()), option);
if ( ! result.isEmpty() ) {
result.add(0, option);
return result;
}
}
return new ArrayList<String>();
}
}

View File

@ -0,0 +1,25 @@
double a, c, g, t, p
double apprpi
short i
// Initial values
a = 1
g = sqr(0.5)
p = 1
t = 0.25
//Iterate just 3 times
for i = 1 to 3
c = a
a = ( a + g ) / 2
g = sqr( c * g )
c -= a
t -= ( p * c^2 )
p *= 2
apprpi = (( a + g )^2) / ( t * 4 )
print "Iteration "i": ", apprpi
next
print "Actual value:",pi
handleevents

View File

@ -1,14 +1,16 @@
with Ada.Text_IO; use Ada.Text_IO;
with System;
procedure Array_Length is
Fruits : constant array (Positive range <>) of access constant String
:= (new String'("orange"),
new String'("apple"));
begin
for Fruit of Fruits loop
Ada.Text_IO.Put (Integer'Image (Fruit'Length));
end loop;
Memory_Size : constant Integer := Fruits'Size / System.Storage_Unit;
Ada.Text_IO.Put_Line (" Array Size : " & Integer'Image (Fruits'Length));
begin
Put_Line ("Number of elements : " & Fruits'Length'Image);
Put_Line ("Array memory Size : " & Memory_Size'Image & " bytes" );
Put_Line (" " & Integer'Image (Memory_Size * System.Storage_Unit / System.Word_Size) & " words" );
end Array_Length;

View File

@ -571,11 +571,6 @@ procedure bezier_intersections is
pt1 : dpoint;
pt2 : opoint;
begin
--
-- NOTE FOR THE FUTURE: This operation is a change of HOMOGENEOUS
-- coordinates. Here we are still using
-- regular euclidean coordinates, however.
--
pt0 := eval (gcurve, t0);
pt1 := ((t1 - t0 - t0) * t1 + (t0 * t0)) * gcurve.pt1;
pt2 := eval (gcurve, t1);

View File

@ -0,0 +1,74 @@
#include <cmath>
#include <iomanip>
#include <iostream>
#include <numbers>
#include <vector>
typedef std::pair<int32_t, int32_t> point;
std::vector<point> babylonian_spiral(int32_t step_count) {
const double tau = 2 * std::numbers::pi;
std::vector<int32_t> squares(step_count + 1);
for ( int32_t i = 0; i < step_count; ++i ) {
squares[i] = i * i;
}
std::vector<point> points { point(0, 0), point (0, 1) };
int32_t norm = 1;
for ( int32_t step = 0; step < step_count - 2; ++step ) {
point previousPoint = points.back();
const double theta = atan2(previousPoint.second, previousPoint.first);
std::vector<point> candidates;
while ( candidates.empty() ) {
norm += 1;
for ( int32_t i = 0; i < step_count; ++i ) {
int32_t a = squares[i];
if ( a > norm / 2 ) {
break;
}
for ( int32_t j = sqrt(norm) + 1; j >= 0; --j ) {
int32_t b = squares[j];
if ( a + b < norm ) {
break;
}
if ( a + b == norm ) {
std::vector<point> next_points = { point(i, j), point(-i, j), point(i, -j), point(-i, -j),
point(j, i), point(-j, i), point(j, -i), point(-j, -i) };
candidates.reserve(next_points.size());
std::move(next_points.begin(), next_points.end(), std::back_inserter(candidates));
}
}
}
}
point minimum;
double minimum_value = tau;
for ( point candidate : candidates ) {
double value = fmod(theta - atan2(candidate.second, candidate.first) + tau, tau);
if ( value < minimum_value ) {
minimum_value = value;
minimum = candidate;
}
}
points.push_back(minimum);
}
for ( uint64_t i = 0; i < points.size() - 1; ++i ) {
points[i + 1] = point(points[i].first + points[i + 1].first, points[i].second + points[i + 1].second);
}
return points;
}
int main() {
std::vector<point> points = babylonian_spiral(40);
std::cout << "The first 40 points of the Babylonian spiral are:" << std::endl;
for ( int32_t i = 0, column = 0; i < 40; ++i ) {
std::string point_str = "(" + std::to_string(points[i].first) + ", " + std::to_string(points[i].second) + ")";
std::cout << std::setw(10) << point_str;
if ( ++column % 10 == 0 ) {
std::cout << std::endl;
}
}
}

View File

@ -20,29 +20,30 @@ public final class BabylonianSpiral {
"(" + points.get(i).x + ", " + points.get(i).y + ")", ( ++column % 10 == 0 ) ? "\n" : " "));
}
System.out.println();
String text = svgText(points, 800);
Files.write(Paths.get("BabylonianSpiralJava.svg"), text.getBytes());
Files.write(Paths.get("C:/Users/psnow/Desktop/BabylonianSpiralJava.svg"), text.getBytes());
}
private static List<Point> babylonianSpiral(int aStepCount) {
final double tau = 2 * Math.PI;
List<Integer> squares = IntStream.rangeClosed(0, aStepCount).map( i -> i * i ).boxed().toList();
List<Point> deltas = Stream.of( new Point(0, 0), new Point(0, 1) ).collect(Collectors.toList());
long norm = 1;
List<Point> points = Stream.of( new Point(0, 0), new Point(0, 1) ).collect(Collectors.toList());
int norm = 1;
for ( int step = 0; step < aStepCount - 2; step++ ) {
Point previousPoint = deltas.get(deltas.size() - 1);
Point previousPoint = points.get(points.size() - 1);
final double theta = Math.atan2(previousPoint.y, previousPoint.x);
Set<Point> candidates = new HashSet<Point>();
while ( candidates.isEmpty() ) {
norm += 1;
for ( int i = 0; i < aStepCount; i++ ) {
long a = squares.get(i);
int a = squares.get(i);
if ( a > norm / 2 ) {
break;
}
for ( int j = (int) Math.sqrt(norm) + 1; j >= 0; j-- ) {
long b = squares.get(j);
int b = squares.get(j);
if ( a + b < norm ) {
break;
}
@ -56,16 +57,16 @@ public final class BabylonianSpiral {
}
Comparator<Point> comparatorPoint = (one, two) -> Double.compare(
( theta - Math.atan2(one.y, one.x) + TAU ) % TAU, ( theta - Math.atan2(two.y, two.x) + TAU ) % TAU);
( theta - Math.atan2(one.y, one.x) + tau ) % tau, ( theta - Math.atan2(two.y, two.x) + tau ) % tau);
Point minimum = candidates.stream().min(comparatorPoint).get();
deltas.add(minimum);
points.add(minimum);
}
for ( int i = 0; i < deltas.size() - 1; i++ ) {
deltas.set(i + 1, new Point(deltas.get(i).x + deltas.get(i + 1).x, deltas.get(i).y + deltas.get(i + 1).y));
}
return deltas;
for ( int i = 0; i < points.size() - 1; i++ ) {
points.set(i + 1, new Point(points.get(i).x + points.get(i + 1).x, points.get(i).y + points.get(i + 1).y));
}
return points;
}
private static String svgText(List<Point> aPoints, int aSize) {
@ -83,6 +84,4 @@ public final class BabylonianSpiral {
return text.toString();
}
private static final double TAU = 2 * Math.PI;
}

View File

@ -1,5 +1,4 @@
use Regexp::Common 'balanced';
my $re = qr/^$RE{balanced}{-parens=>'[]'}$/;
use Regexp::Common 'RE_balanced';
sub balanced {
return shift =~ $re;
return shift =~ RE_balanced(-parens=>'[]')
}

View File

@ -1,6 +1,7 @@
#include <cstdint>
#include <iostream>
#include <stdexcept>
#include <string>
#include <string_view>
#include <unordered_map>
#include <vector>
@ -8,7 +9,7 @@ typedef std::pair<int32_t, int32_t> point;
class Bifid {
public:
Bifid(const int32_t& n, const std::string& text) {
Bifid(const int32_t n, std::string_view text) {
if ( text.length() != n * n ) {
throw new std::invalid_argument("Incorrect length of text");
}
@ -20,7 +21,7 @@ public:
int32_t row = 0;
int32_t col = 0;
for ( char ch : text ) {
for ( const char& ch : text ) {
grid[row][col] = ch;
coordinates[ch] = point(row, col);
col += 1;
@ -35,9 +36,9 @@ public:
}
}
std::string encrypt(const std::string& text) {
std::string encrypt(std::string_view text) {
std::vector<int32_t> row_one, row_two;
for ( char ch : text ) {
for ( const char& ch : text ) {
point coordinate = coordinates[ch];
row_one.push_back(coordinate.first);
row_two.push_back(coordinate.second);
@ -51,9 +52,9 @@ public:
return result;
}
std::string decrypt(const std::string& text) {
std::string decrypt(std::string_view text) {
std::vector<int32_t> row;
for ( char ch : text ) {
for ( const char& ch : text ) {
point coordinate = coordinates[ch];
row.push_back(coordinate.first);
row.push_back(coordinate.second);
@ -70,8 +71,8 @@ public:
}
void display() const {
for ( std::vector<char> row : grid ) {
for ( char ch : row ) {
for ( const std::vector<char>& row : grid ) {
for ( const char& ch : row ) {
std::cout << ch << " ";
}
std::cout << std::endl;
@ -82,7 +83,7 @@ private:
std::unordered_map<char, point> coordinates;
};
void runTest(Bifid bifid, std::string message) {
void runTest(Bifid& bifid, std::string_view message) {
std::cout << "Using Polybius square:" << std::endl;
bifid.display();
std::cout << "Message: " << message << std::endl;
@ -94,9 +95,9 @@ void runTest(Bifid bifid, std::string message) {
}
int main() {
const std::string message1 = "ATTACKATDAWN";
const std::string message2 = "FLEEATONCE";
const std::string message3 = "THEINVASIONWILLSTARTONTHEFIRSTOFJANUARY";
const std::string_view message1 = "ATTACKATDAWN";
const std::string_view message2 = "FLEEATONCE";
const std::string_view message3 = "THEINVASIONWILLSTARTONTHEFIRSTOFJANUARY";
Bifid bifid1(5, "ABCDEFGHIKLMNOPQRSTUVWXYZ");
Bifid bifid2(5, "BGWKZQPNDSIOAXEFCLUMTHYVR");

View File

@ -0,0 +1,8 @@
# _nwise is for gojq
def _nwise($n):
def n: if length <= $n then . else .[0:$n] , (.[$n:] | n) end;
n;
# Input: a string
# Output: a stream of strings
def chars: explode[] | [.] | implode;

View File

@ -0,0 +1,54 @@
# Input: the message to be encrypted
def encrypt($polybius):
(ascii_upcase | gsub("J"; "I") ) as $m
| {rows: [], cols : [] }
| reduce ($m|chars) as $c (.;
($polybius|index($c)) as $ix
| if $ix
then .rows += [($ix/5)|floor + 1]
| .cols += [($ix%5) + 1]
else .
end )
| reduce (.rows + .cols | _nwise(2)) as $pair ("";
(($pair[0] - 1) * 5 + $pair[1] - 1) as $ix
| . + $polybius[$ix:$ix+1] ) ;
# Input: the message to be decrypted
def decrypt($polybius):
reduce chars as $c ( {rows: [], cols : [] };
($polybius|index($c)) as $ix
| .rows += [($ix/5)|floor + 1]
| .cols += [($ix%5) + 1] )
| ([.rows, .cols] | transpose | flatten) as $lines
| ($lines|length/2) as $count
| $lines[:$count] as $rows
| $lines[$count:] as $cols
| [$rows, $cols] as $d
| reduce range(0; $count) as $i ("";
(($rows[$i] - 1) * 5 + $cols[$i] - 1) as $ix
| . + $polybius[$ix:$ix+1] ) ;
def polys:
def p1: "ABCDEFGHIKLMNOPQRSTUVWXYZ";
def p2: "BGWKZQPNDSIOAXEFCLUMTHYVR";
def p3: "PLAYFIREXMBCDGHKNOQSTUVWZ";
[p1, p2, p2, p3];
def messages: [
"ATTACKATDAWN",
"FLEEATONCE",
"ATTACKATDAWN",
"The invasion will start on the first of January"
];
def task:
range(0; messages|length) as $i
| messages[$i]
| encrypt(polys[$i]) as $encrypted
| ($encrypted | decrypt(polys[$i] )) as $decrypted
| "Message : \(.)",
"Encrypted : \($encrypted)",
"Decrypted : \($decrypted)"
"" ;
task

View File

@ -1,30 +0,0 @@
/*REXX program finds a value in a list of integers using an iterative binary search.*/
@= 3 7 13 19 23 31 43 47 61 73 83 89 103 109 113 131 139 151 167 181,
193 199 229 233 241 271 283 293 313 317 337 349 353 359 383 389 401 409 421 433,
443 449 463 467 491 503 509 523 547 571 577 601 619 643 647 661 677 683 691 709,
743 761 773 797 811 823 829 839 859 863 883 887 911 919 941 953 971 983 1013
/* [↑] a list of some low weak primes.*/
parse arg ? . /*get a # that's specified on the CL.*/
if ?=='' then do; say; say '***error*** no argument specified.'; say
exit /*stick a fork in it, we're all done. */
end
low= 1
high= words(@)
avg= (word(@, 1) + word(@, high)) / 2
loc= binarySearch(low, high)
if loc==-1 then do; say ? " wasn't found in the list."
exit /*stick a fork in it, we're all done. */
end
else say ? ' is in the list, its index is: ' loc
say
say 'arithmetic mean of the ' high " values is: " avg
exit /*stick a fork in it, we're all done. */
/*──────────────────────────────────────────────────────────────────────────────────────*/
binarySearch: procedure expose @ ?; parse arg low,high
if high<low then return -1 /*the item wasn't found in the @ list. */
mid= (low + high) % 2 /*calculate the midpoint in the list. */
y= word(@, mid) /*obtain the midpoint value in the list*/
if ?=y then return mid
if y>? then return binarySearch(low, mid-1)
return binarySearch(mid+1, high)

View File

@ -1,25 +1,27 @@
/*REXX program finds a value in a list of integers using an iterative binary search.*/
@= 3 7 13 19 23 31 43 47 61 73 83 89 103 109 113 131 139 151 167 181,
193 199 229 233 241 271 283 293 313 317 337 349 353 359 383 389 401 409 421 433,
443 449 463 467 491 503 509 523 547 571 577 601 619 643 647 661 677 683 691 709,
/* REXX program finds a value in a list of integers */
/* using an iterative binary search. */
list=3 7 13 19 23 31 43 47 61 73 83 89 103 109 113 131 139 151 167 181 193 199,
229 233 241 271 283 293 313 317 337 349 353 359 383 389 401 409 421 433 443,
449 463 467 491 503 509 523 547 571 577 601 619 643 647 661 677 683 691 709,
743 761 773 797 811 823 829 839 859 863 883 887 911 919 941 953 971 983 1013
/* [↑] a list of some low weak primes.*/
parse arg ? . /*get a # that's specified on the CL.*/
if ?=='' then do; say; say '***error*** no argument specified.'; say
exit 13
end
low= 1
high= words(@)
say 'arithmetic mean of the ' high " values is: " (word(@, 1) + word(@, high)) / 2
say
do while low<=high; mid= (low + high) % 2; y= word(@, mid)
/* list: a list of some low weak primes. */
Parse Arg needle /* get a number to be looked for */
If needle=="" Then
Call exit "***error*** no argument specified."
low=1
high=words(list)
Do While low<=high
mid=(low+high)%2
y=word(list,mid)
Select
When y=needle Then
Call exit needle "is in the list, its index is:" mid'.'
When y>needle Then /* too high */
high=mid-1 /* set upper nound */
Otherwise /* too low */
low=mid+1 /* set lower limit */
End
End
Call exit needle "wasn't found in the list."
if ?=y then do; say ? ' is in the list, its index is: ' mid
exit /*stick a fork in it, we're all done. */
end
if y>? then high= mid - 1 /*too high? */
else low= mid + 1 /*too low? */
end /*while*/
say ? " wasn't found in the list." /*stick a fork in it, we're all done. */
exit: Say arg(1)

View File

@ -0,0 +1,25 @@
/*REXX program finds a value in a list of integers using an iterative binary search.*/
@= 3 7 13 19 23 31 43 47 61 73 83 89 103 109 113 131 139 151 167 181,
193 199 229 233 241 271 283 293 313 317 337 349 353 359 383 389 401 409 421 433,
443 449 463 467 491 503 509 523 547 571 577 601 619 643 647 661 677 683 691 709,
743 761 773 797 811 823 829 839 859 863 883 887 911 919 941 953 971 983 1013
/* [↑] a list of some low weak primes.*/
parse arg ? . /*get a # that's specified on the CL.*/
if ?=='' then do; say; say '***error*** no argument specified.'; say
exit 13
end
low= 1
high= words(@)
say 'arithmetic mean of the ' high " values is: " (word(@, 1) + word(@, high)) / 2
say
do while low<=high; mid= (low + high) % 2; y= word(@, mid)
if ?=y then do; say ? ' is in the list, its index is: ' mid
exit /*stick a fork in it, we're all done. */
end
if y>? then high= mid - 1 /*too high? */
else low= mid + 1 /*too low? */
end /*while*/
say ? " wasn't found in the list." /*stick a fork in it, we're all done. */

View File

@ -14,6 +14,7 @@ otherB= other'$' /*same as above, but with less
new= changeStr('A' , other, "Z") /*change the upper letter A ──► Z. */
tt= changeStr('~~', other, ";") /*change two tildes ──► one semicolon.*/
joined= dingsta || dingsta2 /*join two strings together (concat). */
say joined c2b(joined)
exit /*stick a fork in it, we're all done. */
/*──────────────────────────────────────────────────────────────────────────────────────*/
c2b: return x2b( c2x( arg(1) ) ) /*return the string as a binary string.*/
c2b: Return x2b(c2x(arg(1))) /*return the string as a binary string.*/

View File

@ -0,0 +1,137 @@
#include <algorithm>
#include <cstdint>
#include <iostream>
#include <numeric>
#include <unordered_map>
#include <unordered_set>
#include <string>
#include <vector>
// Print a report of the given string to the standard output device.
void print_report(const std::string& text) {
std::unordered_map<char, int32_t> bases;
for ( const char& ch : text ) {
bases[ch]++;
}
const int32_t total = std::accumulate(bases.begin(), bases.end(), 0,
[&](int32_t previous_sum, std::pair<char, int32_t> entry) {
return previous_sum + entry.second;
});
std::cout << "Nucleotide counts for: " << ( ( text.length() > 50 ) ? "\n" : "" );
std::cout << text << std::endl;
std::cout << "Bases: A " << bases['A'] << ", C: " << bases['C'] << ", G: " << bases['G'] << ", T: " << bases['T']
<< ", total: " << total << "\n" << std::endl;
}
// Return all permutations of the given list of strings.
std::vector<std::vector<std::string>> permutations(std::vector<std::string>& list) {
int32_t indexes[list.size()] = {};
std::vector<std::vector<std::string>> result;
result.push_back(list);
int32_t i = 0;
while ( (uint64_t) i < list.size() ) {
if ( indexes[i] < i ) {
const int j = ( i % 2 == 0 ) ? 0 : indexes[i];
std::swap(list[i], list[j]);
result.push_back(list);
indexes[i]++;
i = 0;
} else {
indexes[i] = 0;
i++;
}
}
return result;
}
// Return 'before' concatenated with 'after', removing the longest suffix of 'before' that matches a prefix of 'after'.
std::string concatenate(const std::string& before, const std::string& after) {
for ( uint64_t i = 0; i < before.length(); ++i ) {
if ( after.starts_with(before.substr(i, before.length())) ) {
return before.substr(0, i) + after;
}
}
return before + after;
}
// Remove duplicate strings and strings which are substrings of other strings in the given list.
std::vector<std::string> deduplicate(const std::vector<std::string>& list) {
std::vector<std::string> singletons(list);
std::sort(singletons.begin(), singletons.end());
singletons.erase(std::unique(singletons.begin(), singletons.end()), singletons.end());
std::vector<std::string> result(singletons);
std::unordered_set<std::string> marked_for_removal;
for ( const std::string& test_word : result ) {
for ( const std::string& word : singletons ) {
if ( word != test_word && word.find(test_word) != std::string::npos ) {
marked_for_removal.emplace(test_word);
}
}
}
result.erase(std::remove_if(result.begin(), result.end(),
[&](std::string& word) {
return marked_for_removal.count(word) != 0;
}
), result.end());
return result;
}
// Return a set containing all of the shortest common superstrings of the given list of strings.
std::unordered_set<std::string> shortest_common_superstrings(const std::vector<std::string>& list) {
std::vector<std::string> deduplicated = deduplicate(list);
std::unordered_set<std::string> shortest;
shortest.emplace(std::reduce(list.begin(), list.end(), std::string("")));
uint64_t shortest_length;
for ( const std::string& word : list ) {
shortest_length += word.length();
}
for ( std::vector<std::string> permutation : permutations(deduplicated) ) {
std::string candidate;
for ( const std::string& word : permutation ) {
candidate = concatenate(candidate, word);
}
if ( candidate.length() < shortest_length ) {
shortest.clear();
shortest.emplace(candidate);
shortest_length = candidate.length();
} else if ( candidate.length() == shortest_length ) {
shortest.emplace(candidate);
}
}
return shortest;
}
int main() {
const std::vector<std::vector<std::string>> test_sequences = {
{ "TA", "AAG", "TA", "GAA", "TA" },
{ "CATTAGGG", "ATTAG", "GGG", "TA" },
{ "AAGAUGGA", "GGAGCGCAUC", "AUCGCAAUAAGGA" },
{ "ATGAAATGGATGTTCTGAGTTGGTCAGTCCCAATGTGCGGGGTTTCTTTTAGTACGTCGGGAGTGGTATTAT",
"GGTCGATTCTGAGGACAAAGGTCAAGATGGAGCGCATCGAACGCAATAAGGATCATTTGATGGGACGTTTCGTCGACAAAGT",
"CTATGTTCTTATGAAATGGATGTTCTGAGTTGGTCAGTCCCAATGTGCGGGGTTTCTTTTAGTACGTCGGGAGTGGTATTATA",
"TGCTTTCCAATTATGTAAGCGTTCCGAGACGGGGTGGTCGATTCTGAGGACAAAGGTCAAGATGGAGCGCATC",
"AACGCAATAAGGATCATTTGATGGGACGTTTCGTCGACAAAGTCTTGTTTCGAGAGTAACGGCTACCGTCTT",
"GCGCATCGAACGCAATAAGGATCATTTGATGGGACGTTTCGTCGACAAAGTCTTGTTTCGAGAGTAACGGCTACCGTC",
"CGTTTCGTCGACAAAGTCTTGTTTCGAGAGTAACGGCTACCGTCTTCGATTCTGCTTATAACACTATGTTCT",
"TGCTTTCCAATTATGTAAGCGTTCCGAGACGGGGTGGTCGATTCTGAGGACAAAGGTCAAGATGGAGCGCATC",
"CGTAAAAAATTACAACGTCCTTTGGCTATCTCTTAAACTCCTGCTAAATGCTCGTGC",
"GATGGAGCGCATCGAACGCAATAAGGATCATTTGATGGGACGTTTCGTCGACAAAGTCTTGTTTCGAGAGTAACGGCTACCGTCTTCGATT",
"TTTCCAATTATGTAAGCGTTCCGAGACGGGGTGGTCGATTCTGAGGACAAAGGTCAAGATGGAGCGCATC",
"CTATGTTCTTATGAAATGGATGTTCTGAGTTGGTCAGTCCCAATGTGCGGGGTTTCTTTTAGTACGTCGGGAGTGGTATTATA",
"TCTCTTAAACTCCTGCTAAATGCTCGTGCTTTCCAATTATGTAAGCGTTCCGAGACGGGGTGGTCGATTCTGAGGACAAAGGTCAAGA" } };
for ( const std::vector<std::string>& test : test_sequences ) {
for ( const std::string& superstring : shortest_common_superstrings(test) ) {
print_report(superstring);
}
}
}

View File

@ -56,7 +56,7 @@ public final class BioinformaticsGlobalAlignment {
return shortest;
}
// Remove duplicate words and words which are substrings of other words in the given list.
// Remove duplicate strings and strings which are substrings of other strings in the given list.
private static List<String> deduplicate(List<String> aList) {
List<String> unique = aList.stream().distinct().collect(Collectors.toList());
List<String> result = new ArrayList<String>(unique);
@ -99,7 +99,7 @@ public final class BioinformaticsGlobalAlignment {
i = 0;
} else {
indexes[i] = 0;
i++;
i += 1;
}
}
return result;

View File

@ -1,13 +1,13 @@
fun printSequence(sequence: String, width: Int = 50) {
fun <K, V> printWithLabel(k: K, v: V) {
val label = k.toString().padStart(5)
println("$label: $v")
}
fun printWithLabel(label: Any, data: Any) =
label.toString().padStart(5).also { println("$it: $data") }
println("SEQUENCE:")
sequence.chunked(width).withIndex().forEach { (i, line) ->
printWithLabel(i*width + line.length, line)
sequence.chunked(width).forEachIndexed() { i, chunk ->
printWithLabel(i * width + chunk.length, chunk)
}
println("BASE:")
sequence.groupingBy { it }.eachCount().forEach { (k, v) ->
printWithLabel(k, v)
@ -17,6 +17,4 @@ fun printSequence(sequence: String, width: Int = 50) {
const val BASE_SEQUENCE = "CGTAAAAAATTACAACGTCCTTTGGCTATCTCTTAAACTCCTGCTAAATGCTCGTGCTTTCCAATTATGTAAGCGTTCCGAGACGGGGTGGTCGATTCTGAGGACAAAGGTCAAGATGGAGCGCATCGAACGCAATAAGGATCATTTGATGGGACGTTTCGTCGACAAAGTCTTGTTTCGAGAGTAACGGCTACCGTCTTCGATTCTGCTTATAACACTATGTTCTTATGAAATGGATGTTCTGAGTTGGTCAGTCCCAATGTGCGGGGTTTCTTTTAGTACGTCGGGAGTGGTATTATATTTAATTTTTCTATATAGCGATCTGTATTTAAGCAATTCATTTAGGTTATCGCCGCGATGCTCGGTTCGGACCGCCAAGCATCTGGCTCCACTGCTAGTGTCCTAAATTTGAATGGCAAACACAAATAAGATTTAGCAATTCGTGTAGACGACCGGGGACTTGCATGATGGGAGCAGCTTTGTTAAACTACGAACGTAAT"
fun main() {
printSequence(BASE_SEQUENCE)
}
fun main() = printSequence(BASE_SEQUENCE)

View File

@ -1,31 +1,36 @@
/*REXX program finds the number of each base in a DNA string (along with a total). */
parse arg dna .
if dna=='' | dna=="," then dna= 'cgtaaaaaattacaacgtcctttggctatctcttaaactcctgctaaatg' ,
'ctcgtgctttccaattatgtaagcgttccgagacggggtggtcgattctg' ,
'aggacaaaggtcaagatggagcgcatcgaacgcaataaggatcatttgat' ,
'gggacgtttcgtcgacaaagtcttgtttcgagagtaacggctaccgtctt' ,
'cgattctgcttataacactatgttcttatgaaatggatgttctgagttgg' ,
'tcagtcccaatgtgcggggtttcttttagtacgtcgggagtggtattata' ,
'tttaatttttctatatagcgatctgtatttaagcaattcatttaggttat' ,
'cgccgcgatgctcggttcggaccgccaagcatctggctccactgctagtg' ,
'tcctaaatttgaatggcaaacacaaataagatttagcaattcgtgtagac' ,
'gaccggggacttgcatgatgggagcagctttgttaaactacgaacgtaat'
dna= space(dna, 0); upper dna /*elide blanks from DNA; uppercase it. */
say 'length of the DNA string: ' length(dna)
@.= 0 /*initialize the count for all bases. */
w= 1 /*the maximum width of a base count. */
$= /*a placeholder for the names of bases.*/
do j=1 for length(dna) /*traipse through the DNA string. */
_= substr(dna, j, 1) /*obtain a base name from the DNA str. */
if pos(_, $)==0 then $= $ || _ /*if not found before, add it to list. */
@._= @._ + 1 /*bump the count of this base. */
w= max(w, length(@._) ) /*compute the maximum width number. */
end /*j*/
say
do k=0 for 255; z= d2c(k) /*traipse through all possibilities. */
if pos(z, $)==0 then iterate /*Was this base found? No, then skip. */
say ' base ' z " has a basecount of: " right(@.z, w)
@.tot= @.tot + @.z /*add to a grand total to verify count.*/
end /*k*/ /*stick a fork in it, we're all done. */
say
say 'total for all basecounts:' right(@.tot, w+1)
/*REXX program finds the number of each base in a DNA string */
/* (along with a total). */
Parse Arg dna .
If dna==''|dna==',' Then
dna='cgtaaaaaattacaacgtcctttggctatctcttaaactcctgctaaatg',
'ctcgtgctttccaattatgtaagcgttccgagacggggtggtcgattctg',
'aggacaaaggtcaagatggagcgcatcgaacgcaataaggatcatttgat',
'gggacgtttcgtcgacaaagtcttgtttcgagagtaacggctaccgtctt',
'cgattctgcttataacactatgttcttatgaaatggatgttctgagttgg',
'tcagtcccaatgtgcggggtttcttttagtacgtcgggagtggtattata',
'tttaatttttctatatagcgatctgtatttaagcaattcatttaggttat',
'cgccgcgatgctcggttcggaccgccaagcatctggctccactgctagtg',
'tcctaaatttgaatggcaaacacaaataagatttagcaattcgtgtagac',
'gaccggggacttgcatgatgggagcagctttgttaaactacgaacgtaat'
dna=translate(space(dna,0)) /* elide blanks from DNA; uppercas*/
Say '--------length of the DNA string: ' length(dna)
count.=0 /* initialize the count for all bases*/
w=1 /* the maximum width of a base count */
names='' /* list of all names */
Do j=1 To length(dna) /* traipse through the DNA string */
name=substr(dna,j,1) /* obtain a base name from the DNA */
If pos(name,names)==0 Then
names=names||name /* if not found, add it to the list */
count.name=count.name+1 /* bump the count of this base. */
w=max(w,length(count.name)) /* compute the maximum number width */
End
Say
Do k=0 To 255
z=d2c(k) /* traipse through all possibilities */
If pos(z,names)>0 Then Do
Say ' base ' z ' has a basecount of: ' right(count.z,w)
count.tot=count.tot+count.z /* add to a grand total to verify */
End
End
Say
Say '--------total for all basecounts:' right(count.tot,w+1)

Some files were not shown because too many files have changed in this diff Show More