September 2017 Update

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

View file

@ -19,6 +19,14 @@ The   [[wp:Look and say sequence|Look and say sequence]]   is a recurs
Write a program to generate successive members of the look-and-say sequence.
;Related tasks:
*   [[Fours is the number of letters in the ...]]
*   [[Number names]]
*   [[Self-describing numbers]]
*   [[Self-referential sequence]]
*   [[Spelling of ordinal numbers]]
;See also:
*   [https://www.youtube.com/watch?v=ea7lJkEhytA Look-and-Say Numbers (feat John Conway)], A Numberphile Video.
*   This task is related to, and an application of, the [[Run-length encoding]] task.

View file

@ -0,0 +1,25 @@
Public Sub Main()
Dim i, j, cnt As Integer
Dim txt$, curr$, result$ As String
txt$ = "1211"
i = 1
Print "Sequence: " & txt$ & " = ";
Repeat
j = 1
result$ = ""
Repeat
curr$ = Mid(txt$, j, 1)
cnt = 0
Repeat
Inc cnt
Inc j
Until Mid(txt$, j, 1) <> curr$
result$ &= Str(cnt) & curr$
Until j > Len(txt$)
Print result$
txt$ = result$
Dec i
Until i <= 0
End

View file

@ -0,0 +1,27 @@
# v0.6
function lookandsay(n::String)
rst = IOBuffer()
i, c = 1, 1
while i ≤ length(n)
if i != length(n) && n[i] == n[i+1]
c += 1
else
print(rst, c, n[i])
c = 1
end
i += 1
end
return String(take!(rst))
end
function lookandsayseq(n::Integer)
rst = Array{String}(n)
rst[1] = "1"
for i in 2:n
rst[i] = lookandsay(rst[i-1])
end
return rst
end
println(lookandsayseq(10))

View file

@ -0,0 +1,25 @@
// version 1.0.6
fun lookAndSay(s: String): String {
val sb = StringBuilder()
var digit = s[0]
var count = 1
for (i in 1 until s.length) {
if (s[i] == digit)
count++
else {
sb.append("$count$digit")
digit = s[i]
count = 1
}
}
return sb.append("$count$digit").toString()
}
fun main(args: Array<String>) {
var las = "1"
for (i in 1..15) {
println(las)
las = lookAndSay(las)
}
}

View file

@ -0,0 +1,22 @@
function lookandsay(string s)
string res = ""
integer p = s[1], c = 1
for i=2 to length(s) do
if p=s[i] then
c += 1
else
res &= sprintf("%d%s",{c,p})
p = s[i]
c = 1
end if
end for
res &= sprintf("%d%s",{c,p})
return res
end function
string s = "1"
?s
for i=1 to 10 do
s = lookandsay(s)
?s
end for

View file

@ -0,0 +1,8 @@
fcn lookAndSay(seed){ // numeric String --> numeric String
len,c:=[1..seed.len()-1].reduce(fcn([(len,c)]lc,index,s,sb){
if(c!=s[index]) { sb.write(len); sb.write(c); lc.clear(1,s[index]) }
else lc.clear(len+1,c);
},L(1,seed[0]), seed,sb:=Sink(String));
sb.write(len); sb.write(c);
sb.close();
}