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
2
Task/Binary-digits/8th/binary-digits.8th
Normal file
2
Task/Binary-digits/8th/binary-digits.8th
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
2 base drop
|
||||
#50 . cr
|
||||
11
Task/Binary-digits/Axe/binary-digits.axe
Normal file
11
Task/Binary-digits/Axe/binary-digits.axe
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
Lbl BIN
|
||||
.Axe supports 16-bit integers, so 16 digits are enough
|
||||
L₁+16→P
|
||||
0→{P}
|
||||
While r₁
|
||||
P--
|
||||
{(r₁ and 1)▶Hex+3}→P
|
||||
r₁/2→r₁
|
||||
End
|
||||
Disp P,i
|
||||
Return
|
||||
9
Task/Binary-digits/EchoLisp/binary-digits.echolisp
Normal file
9
Task/Binary-digits/EchoLisp/binary-digits.echolisp
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
;; primitive : (number->string number [base]) - default base = 10
|
||||
|
||||
(number->string 2 2)
|
||||
→ 10
|
||||
|
||||
(for-each (compose writeln (rcurry number->string 2)) '( 5 50 9000)) →
|
||||
101
|
||||
110010
|
||||
10001100101000
|
||||
9
Task/Binary-digits/FreeBASIC/binary-digits.freebasic
Normal file
9
Task/Binary-digits/FreeBASIC/binary-digits.freebasic
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
' FreeBASIC v1.05.0 win64
|
||||
Dim As String fmt = "#### -> &"
|
||||
Print Using fmt; 5; Bin(5)
|
||||
Print Using fmt; 50; Bin(50)
|
||||
Print Using fmt; 9000; Bin(9000)
|
||||
Print
|
||||
Print "Press any key to exit the program"
|
||||
Sleep
|
||||
End
|
||||
2
Task/Binary-digits/FunL/binary-digits.funl
Normal file
2
Task/Binary-digits/FunL/binary-digits.funl
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
for n <- [5, 50, 9000, 9000000000]
|
||||
println( n, bin(n) )
|
||||
6
Task/Binary-digits/Futhark/binary-digits.futhark
Normal file
6
Task/Binary-digits/Futhark/binary-digits.futhark
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
fun main(x: i32): i64 =
|
||||
loop (out = 0i64) = for i < 32 do
|
||||
let digit = (x >> (31-i)) & 1
|
||||
let out = (out * 10i64) + i64(digit)
|
||||
in out
|
||||
in out
|
||||
18
Task/Binary-digits/Idris/binary-digits.idris
Normal file
18
Task/Binary-digits/Idris/binary-digits.idris
Normal file
|
|
@ -0,0 +1,18 @@
|
|||
module Main
|
||||
|
||||
binaryDigit : Integer -> Char
|
||||
binaryDigit n = if (mod n 2) == 1 then '1' else '0'
|
||||
|
||||
binaryString : Integer -> String
|
||||
binaryString 0 = "0"
|
||||
binaryString n = pack (loop n [])
|
||||
where loop : Integer -> List Char -> List Char
|
||||
loop 0 acc = acc
|
||||
loop n acc = loop (div n 2) (binaryDigit n :: acc)
|
||||
|
||||
main : IO ()
|
||||
main = do
|
||||
putStrLn (binaryString 0)
|
||||
putStrLn (binaryString 5)
|
||||
putStrLn (binaryString 50)
|
||||
putStrLn (binaryString 9000)
|
||||
1
Task/Binary-digits/LFE/binary-digits-1.lfe
Normal file
1
Task/Binary-digits/LFE/binary-digits-1.lfe
Normal file
|
|
@ -0,0 +1 @@
|
|||
(: io format '"~.2B~n~.2B~n~.2B~n" (list 5 50 9000))
|
||||
6
Task/Binary-digits/LFE/binary-digits-2.lfe
Normal file
6
Task/Binary-digits/LFE/binary-digits-2.lfe
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
(: lists foreach
|
||||
(lambda (x)
|
||||
(: io format
|
||||
'"~s~n"
|
||||
(list (: erlang integer_to_list x 2))))
|
||||
(list 5 50 9000))
|
||||
24
Task/Binary-digits/Nim/binary-digits.nim
Normal file
24
Task/Binary-digits/Nim/binary-digits.nim
Normal file
|
|
@ -0,0 +1,24 @@
|
|||
proc binDigits(x: BiggestInt, r: int): int =
|
||||
## Calculates how many digits `x` has when each digit covers `r` bits.
|
||||
result = 1
|
||||
var y = x shr r
|
||||
while y > 0:
|
||||
y = y shr r
|
||||
inc(result)
|
||||
|
||||
proc toBin*(x: BiggestInt, len: Natural = 0): string =
|
||||
## converts `x` into its binary representation. The resulting string is
|
||||
## always `len` characters long. By default the length is determined
|
||||
## automatically. No leading ``0b`` prefix is generated.
|
||||
var
|
||||
mask: BiggestInt = 1
|
||||
shift: BiggestInt = 0
|
||||
len = if len == 0: binDigits(x, 1) else: len
|
||||
result = newString(len)
|
||||
for j in countdown(len-1, 0):
|
||||
result[j] = chr(int((x and mask) shr shift) + ord('0'))
|
||||
shift = shift + 1
|
||||
mask = mask shl 1
|
||||
|
||||
for i in 0..15:
|
||||
echo toBin(i)
|
||||
1
Task/Binary-digits/Panda/binary-digits.panda
Normal file
1
Task/Binary-digits/Panda/binary-digits.panda
Normal file
|
|
@ -0,0 +1 @@
|
|||
0..15.radix:2 nl
|
||||
6
Task/Binary-digits/Peloton/binary-digits.peloton
Normal file
6
Task/Binary-digits/Peloton/binary-digits.peloton
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
<@ defbaslit>2</@>
|
||||
|
||||
<@ saybaslit>0</@>
|
||||
<@ saybaslit>5</@>
|
||||
<@ saybaslit>50</@>
|
||||
<@ saybaslit>9000</@>
|
||||
3
Task/Binary-digits/Phix/binary-digits.phix
Normal file
3
Task/Binary-digits/Phix/binary-digits.phix
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
printf(1,"%b\n",5)
|
||||
printf(1,"%b\n",50)
|
||||
printf(1,"%b\n",9000)
|
||||
12
Task/Binary-digits/Ring/binary-digits.ring
Normal file
12
Task/Binary-digits/Ring/binary-digits.ring
Normal file
|
|
@ -0,0 +1,12 @@
|
|||
see "Number to convert : "
|
||||
give a
|
||||
n = 0
|
||||
while pow(2,n+1) < a
|
||||
n = n + 1
|
||||
end
|
||||
|
||||
for i = n to 0 step -1
|
||||
x = pow(2,i)
|
||||
if a >= x see 1 a = a - x
|
||||
else see 0 ok
|
||||
next
|
||||
9
Task/Binary-digits/SequenceL/binary-digits.sequencel
Normal file
9
Task/Binary-digits/SequenceL/binary-digits.sequencel
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
main := toBinaryString([5, 50, 9000]);
|
||||
|
||||
toBinaryString(number(0)) :=
|
||||
let
|
||||
val := "1" when number mod 2 = 1 else "0";
|
||||
in
|
||||
toBinaryString(floor(number/2)) ++ val when floor(number/2) > 0
|
||||
else
|
||||
val;
|
||||
3
Task/Binary-digits/Sidef/binary-digits.sidef
Normal file
3
Task/Binary-digits/Sidef/binary-digits.sidef
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
[5, 50, 9000].each { |n|
|
||||
say n.as_bin;
|
||||
}
|
||||
3
Task/Binary-digits/SkookumScript/binary-digits.skookum
Normal file
3
Task/Binary-digits/SkookumScript/binary-digits.skookum
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
println(5.binary)
|
||||
println(50.binary)
|
||||
println(9000.binary)
|
||||
3
Task/Binary-digits/Swift/binary-digits.swift
Normal file
3
Task/Binary-digits/Swift/binary-digits.swift
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
for num in [5, 50, 9000] {
|
||||
println(String(num, radix: 2))
|
||||
}
|
||||
25
Task/Binary-digits/Visual-FoxPro/binary-digits.visual
Normal file
25
Task/Binary-digits/Visual-FoxPro/binary-digits.visual
Normal file
|
|
@ -0,0 +1,25 @@
|
|||
*!* Binary Digits
|
||||
CLEAR
|
||||
k = CAST(5 As I)
|
||||
? NToBin(k)
|
||||
k = CAST(50 As I)
|
||||
? NToBin(k)
|
||||
k = CAST(9000 As I)
|
||||
? NToBin(k)
|
||||
|
||||
FUNCTION NTOBin(n As Integer) As String
|
||||
LOCAL i As Integer, b As String, v As Integer
|
||||
b = ""
|
||||
v = HiBit(n)
|
||||
FOR i = 0 TO v
|
||||
b = IIF(BITTEST(n, i), "1", "0") + b
|
||||
ENDFOR
|
||||
RETURN b
|
||||
ENDFUNC
|
||||
|
||||
FUNCTION HiBit(n As Double) As Integer
|
||||
*!* Find the highest power of 2 in n
|
||||
LOCAL v As Double
|
||||
v = LOG(n)/LOG(2)
|
||||
RETURN FLOOR(v)
|
||||
ENDFUNC
|
||||
3
Task/Binary-digits/Wortel/binary-digits-1.wortel
Normal file
3
Task/Binary-digits/Wortel/binary-digits-1.wortel
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
\.toString 2
|
||||
; the following function also casts the string to a number
|
||||
^(@+ \.toString 2)
|
||||
1
Task/Binary-digits/Wortel/binary-digits-2.wortel
Normal file
1
Task/Binary-digits/Wortel/binary-digits-2.wortel
Normal file
|
|
@ -0,0 +1 @@
|
|||
@each ^(console.log \.toString 2) [5 50 900]
|
||||
10
Task/Binary-digits/jq/binary-digits.jq
Normal file
10
Task/Binary-digits/jq/binary-digits.jq
Normal file
|
|
@ -0,0 +1,10 @@
|
|||
def binary_digits:
|
||||
if . == 0 then "0"
|
||||
else [recurse( if . == 0 then empty else ./2 | floor end ) % 2 | tostring]
|
||||
| reverse
|
||||
| .[1:] # remove the leading 0
|
||||
| join("")
|
||||
end ;
|
||||
|
||||
# The task:
|
||||
(5, 50, 9000) | binary_digits
|
||||
Loading…
Add table
Add a link
Reference in a new issue