Add tasks for all the new languages
This commit is contained in:
parent
9dc3c2bb62
commit
bba7bfd280
13208 changed files with 134745 additions and 0 deletions
|
|
@ -0,0 +1,23 @@
|
|||
' FB 1.05.0 Win64
|
||||
|
||||
Function selfDescribing (n As UInteger) As Boolean
|
||||
If n = 0 Then Return False
|
||||
Dim ns As String = Str(n)
|
||||
Dim count(0 To 9) As Integer '' all elements zero by default
|
||||
While n > 0
|
||||
count(n Mod 10) += 1
|
||||
n \= 10
|
||||
Wend
|
||||
For i As Integer = 0 To Len(ns) - 1
|
||||
If ns[i] - 48 <> count(i) Then Return False '' numerals have ascii values from 48 to 57
|
||||
Next
|
||||
Return True
|
||||
End Function
|
||||
|
||||
Print "The self-describing numbers less than 100 million are:"
|
||||
For i As Integer = 0 To 99999999
|
||||
If selfDescribing(i) Then Print i; " ";
|
||||
Next
|
||||
Print
|
||||
Print "Press any key to quit"
|
||||
Sleep
|
||||
|
|
@ -0,0 +1,11 @@
|
|||
function selfDescNumber n
|
||||
local tSelfD, tLen
|
||||
put len(n) into tLen
|
||||
repeat with x = 0 to (tLen - 1)
|
||||
put n into nCopy
|
||||
replace x with empty in nCopy
|
||||
put char (x + 1) of n = (tLen - len(nCopy)) into tSelfD
|
||||
if not tSelfD then exit repeat
|
||||
end repeat
|
||||
return tSelfD
|
||||
end selfDescNumber
|
||||
|
|
@ -0,0 +1,9 @@
|
|||
on mouseUp
|
||||
repeat with n = 0 to 10000000
|
||||
if selfDescNumber(n) then
|
||||
put n into selfNum[n]
|
||||
end if
|
||||
end repeat
|
||||
combine selfNum using comma
|
||||
put selfNum
|
||||
end mouseUp
|
||||
|
|
@ -0,0 +1 @@
|
|||
1210,2020,21200,3211000
|
||||
20
Task/Self-describing-numbers/Nim/self-describing-numbers.nim
Normal file
20
Task/Self-describing-numbers/Nim/self-describing-numbers.nim
Normal file
|
|
@ -0,0 +1,20 @@
|
|||
import strutils
|
||||
|
||||
proc count(s, sub): int =
|
||||
var i = 0
|
||||
while true:
|
||||
i = s.find(sub, i)
|
||||
if i < 0:
|
||||
break
|
||||
inc i
|
||||
inc result
|
||||
|
||||
proc isSelfDescribing(n): bool =
|
||||
let s = $n
|
||||
for i, ch in s:
|
||||
if s.count($i) != parseInt("" & ch):
|
||||
return false
|
||||
return true
|
||||
|
||||
for x in 0 .. 4_000_000:
|
||||
if isSelfDescribing(x): echo x
|
||||
|
|
@ -0,0 +1,19 @@
|
|||
function self_desc(integer i)
|
||||
sequence digits = repeat(0,10), counts = repeat(0,10)
|
||||
integer n = 0, digit
|
||||
while 1 do
|
||||
digit := mod(i,10)
|
||||
digits[10-n] := digit
|
||||
counts[digit+1] += 1
|
||||
i = floor(i/10)
|
||||
if i=0 then exit end if
|
||||
n += 1
|
||||
end while
|
||||
return digits[10-n..10] = counts[1..n+1]
|
||||
end function
|
||||
|
||||
atom t0 = time()
|
||||
for i=10 to 100_000_000 by 10 do
|
||||
if self_desc(i) then ?i end if
|
||||
end for
|
||||
printf(1,"done (%3.2fs)",time()-t0)
|
||||
|
|
@ -0,0 +1,16 @@
|
|||
func sdn(n) {
|
||||
var b = [0]*n.len;
|
||||
var a = n.chars;
|
||||
a.each { |i| b[i] := 0 ++ }
|
||||
a.join == b.join;
|
||||
}
|
||||
|
||||
var values = <1210 2020 21200 3211000
|
||||
42101000 521001000 6210001000 27 115508>;
|
||||
|
||||
values.each { |test|
|
||||
say "#{test} is #{sdn(test) ? '' : 'NOT ' }a self describing number.";
|
||||
}
|
||||
|
||||
say "\nSelf-descriptive numbers less than 1e5 (in base 10):"
|
||||
0.to(1e5).each { |i| say i if sdn(i.to_s) }
|
||||
|
|
@ -0,0 +1,4 @@
|
|||
7.to(36).each { |b|
|
||||
var n = ((b-4) * b**(b-1) + 2*(b**(b-2)) + b**(b-3) + b**3 -> base(b));
|
||||
say "base #{'%2d' % b}: #{n}";
|
||||
}
|
||||
|
|
@ -0,0 +1,4 @@
|
|||
# If your jq includes all/2 then comment out the following definition,
|
||||
# which is slightly less efficient:
|
||||
def all(generator; condition):
|
||||
reduce generator as $i (true; if . then $i | condition else . end);
|
||||
|
|
@ -0,0 +1,9 @@
|
|||
def selfie:
|
||||
def count(value): reduce .[] as $i (0; if $i == value then . + 1 else . end);
|
||||
def digits: tostring | explode | map(. - 48);
|
||||
|
||||
digits
|
||||
| if add != length then false
|
||||
else . as $digits
|
||||
| all ( range(0; length); . as $i | $digits | (.[$i] == count($i)) )
|
||||
end;
|
||||
|
|
@ -0,0 +1 @@
|
|||
range(0; 100000001) | select(selfie)
|
||||
|
|
@ -0,0 +1,6 @@
|
|||
$ jq -n -f Self-describing_numbers.jq
|
||||
1210
|
||||
2020
|
||||
21200
|
||||
3211000
|
||||
42101000
|
||||
Loading…
Add table
Add a link
Reference in a new issue