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
40
Task/Price-fraction/FreeBASIC/price-fraction.freebasic
Normal file
40
Task/Price-fraction/FreeBASIC/price-fraction.freebasic
Normal file
|
|
@ -0,0 +1,40 @@
|
|||
' FB 1.050.0 Win64
|
||||
|
||||
Function rescale(price As Double) As Double
|
||||
If price < 0.00 OrElse price > 1.00 Then Return price
|
||||
Select Case price
|
||||
Case Is < 0.06 : Return 0.10
|
||||
Case Is < 0.11 : Return 0.18
|
||||
Case Is < 0.16 : Return 0.26
|
||||
Case Is < 0.21 : Return 0.32
|
||||
Case Is < 0.26 : Return 0.38
|
||||
Case Is < 0.31 : Return 0.44
|
||||
Case Is < 0.36 : Return 0.50
|
||||
Case Is < 0.41 : Return 0.54
|
||||
Case Is < 0.46 : Return 0.58
|
||||
Case Is < 0.51 : Return 0.62
|
||||
Case Is < 0.56 : Return 0.66
|
||||
Case Is < 0.61 : Return 0.70
|
||||
Case Is < 0.66 : Return 0.74
|
||||
Case Is < 0.71 : Return 0.78
|
||||
Case Is < 0.76 : Return 0.82
|
||||
Case Is < 0.81 : Return 0.86
|
||||
Case Is < 0.86 : Return 0.90
|
||||
Case Is < 0.91 : Return 0.94
|
||||
Case Is < 0.96 : Return 0.98
|
||||
End Select
|
||||
Return 1.00
|
||||
End Function
|
||||
|
||||
For i As Integer = 1 To 100
|
||||
Dim d As Double = i/100.0
|
||||
Print Using "#.##"; d;
|
||||
Print " -> ";
|
||||
Print Using "#.##"; rescale(d);
|
||||
Print " ";
|
||||
If i Mod 5 = 0 Then Print
|
||||
Next
|
||||
|
||||
Print
|
||||
Print "Press any key to quit"
|
||||
Sleep
|
||||
32
Task/Price-fraction/Nim/price-fraction.nim
Normal file
32
Task/Price-fraction/Nim/price-fraction.nim
Normal file
|
|
@ -0,0 +1,32 @@
|
|||
import strutils, math
|
||||
|
||||
const
|
||||
pricemap: array[0 .. 19, int] = [10,18,26,32,38,44,50,54,58,62,66,70,74,78,82,86,90,94,98,100]
|
||||
|
||||
# outputs an int (=>float*100)
|
||||
proc floatToPrice100(f: float): int =
|
||||
# indx: 0.1-0.05->0, 0.06-0.10->1, 0.11-0.15->2, .....
|
||||
var valu: int = toInt(f*100)
|
||||
if valu == 0:
|
||||
result = 10
|
||||
else:
|
||||
dec(valu)
|
||||
# inc indx every 5 of valu, so value of 1..100 translates to indx of 0..19
|
||||
var indx: int = 2*int(valu/10)+int((valu%%10)/5)
|
||||
result = pricemap[indx]
|
||||
|
||||
# str representation of an int (that is a representation of a float price)
|
||||
proc price100ToStr(p: int): string =
|
||||
if p < 10:
|
||||
result = "0.0" & $p
|
||||
if p < 100:
|
||||
result = "0." & $p
|
||||
else:
|
||||
result = "1.00"
|
||||
|
||||
randomize()
|
||||
var i: int = 0
|
||||
|
||||
for x in 0 .. 10:
|
||||
i = random(101)
|
||||
echo("Price for ", i.price100ToStr(), ", is: ", float(i/100).floatToPrice100().price100ToStr())
|
||||
7
Task/Price-fraction/Oforth/price-fraction.oforth
Normal file
7
Task/Price-fraction/Oforth/price-fraction.oforth
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
[.06, .11, .16, .21, .26, .31, .36, .41, .46, .51, .56, .61, .66, .71, .76, .81, .86, .91, .96, 1.01] const: IN
|
||||
[.10, .18, .26, .32, .38, .44, .50, .54, .58, .62, .66, .70, .74, .78, .82, .86, .90, .94, .98, 1.00] const: OUT
|
||||
|
||||
: priceFraction(f)
|
||||
| i |
|
||||
IN size loop: i [ f IN at(i) < ifTrue: [ OUT at(i) return ] ]
|
||||
null ;
|
||||
43
Task/Price-fraction/Phix/price-fraction.phix
Normal file
43
Task/Price-fraction/Phix/price-fraction.phix
Normal file
|
|
@ -0,0 +1,43 @@
|
|||
constant TBL=split("""
|
||||
>= 0.00 < 0.06 := 0.10
|
||||
>= 0.06 < 0.11 := 0.18
|
||||
>= 0.11 < 0.16 := 0.26
|
||||
>= 0.16 < 0.21 := 0.32
|
||||
>= 0.21 < 0.26 := 0.38
|
||||
>= 0.26 < 0.31 := 0.44
|
||||
>= 0.31 < 0.36 := 0.50
|
||||
>= 0.36 < 0.41 := 0.54
|
||||
>= 0.41 < 0.46 := 0.58
|
||||
>= 0.46 < 0.51 := 0.62
|
||||
>= 0.51 < 0.56 := 0.66
|
||||
>= 0.56 < 0.61 := 0.70
|
||||
>= 0.61 < 0.66 := 0.74
|
||||
>= 0.66 < 0.71 := 0.78
|
||||
>= 0.71 < 0.76 := 0.82
|
||||
>= 0.76 < 0.81 := 0.86
|
||||
>= 0.81 < 0.86 := 0.90
|
||||
>= 0.86 < 0.91 := 0.94
|
||||
>= 0.91 < 0.96 := 0.98
|
||||
>= 0.96 < 1.01 := 1.00""",'\n')
|
||||
|
||||
sequence limits = {0},
|
||||
prices = {-1}
|
||||
atom lt,price
|
||||
for i=1 to length(TBL) do
|
||||
{{?,lt,price}} = scanf(TBL[i],">= %.2f < %.2f := %.2f")
|
||||
limits = append(limits,lt)
|
||||
prices = append(prices,price)
|
||||
end for
|
||||
|
||||
function price_fix(atom p)
|
||||
for i=1 to length(limits) do
|
||||
if p<limits[i] then
|
||||
return prices[i]
|
||||
end if
|
||||
end for
|
||||
return -1
|
||||
end function
|
||||
|
||||
for i=-1 to 101 do
|
||||
printf(1, "%5.2f %5.2f\n", {i/100,price_fix(i/100)})
|
||||
end for
|
||||
23
Task/Price-fraction/Ring/price-fraction.ring
Normal file
23
Task/Price-fraction/Ring/price-fraction.ring
Normal file
|
|
@ -0,0 +1,23 @@
|
|||
see pricefraction(0.5)
|
||||
|
||||
func pricefraction n
|
||||
if n < 0.06 return 0.10 ok
|
||||
if n < 0.11 return 0.18 ok
|
||||
if n < 0.16 return 0.26 ok
|
||||
if n < 0.21 return 0.32 ok
|
||||
if n < 0.26 return 0.38 ok
|
||||
if n < 0.31 return 0.44 ok
|
||||
if n < 0.36 return 0.50 ok
|
||||
if n < 0.41 return 0.54 ok
|
||||
if n < 0.46 return 0.58 ok
|
||||
if n < 0.51 return 0.62 ok
|
||||
if n < 0.56 return 0.66 ok
|
||||
if n < 0.61 return 0.70 ok
|
||||
if n < 0.66 return 0.74 ok
|
||||
if n < 0.71 return 0.78 ok
|
||||
if n < 0.76 return 0.82 ok
|
||||
if n < 0.81 return 0.86 ok
|
||||
if n < 0.86 return 0.90 ok
|
||||
if n < 0.91 return 0.94 ok
|
||||
if n < 0.96 return 0.98 ok
|
||||
return 1
|
||||
35
Task/Price-fraction/Sidef/price-fraction.sidef
Normal file
35
Task/Price-fraction/Sidef/price-fraction.sidef
Normal file
|
|
@ -0,0 +1,35 @@
|
|||
var table = <<'EOT'.lines.map { .words.grep{.is_numeric}.map{.to_n} }
|
||||
>= 0.00 < 0.06 := 0.10
|
||||
>= 0.06 < 0.11 := 0.18
|
||||
>= 0.11 < 0.16 := 0.26
|
||||
>= 0.16 < 0.21 := 0.32
|
||||
>= 0.21 < 0.26 := 0.38
|
||||
>= 0.26 < 0.31 := 0.44
|
||||
>= 0.31 < 0.36 := 0.50
|
||||
>= 0.36 < 0.41 := 0.54
|
||||
>= 0.41 < 0.46 := 0.58
|
||||
>= 0.46 < 0.51 := 0.62
|
||||
>= 0.51 < 0.56 := 0.66
|
||||
>= 0.56 < 0.61 := 0.70
|
||||
>= 0.61 < 0.66 := 0.74
|
||||
>= 0.66 < 0.71 := 0.78
|
||||
>= 0.71 < 0.76 := 0.82
|
||||
>= 0.76 < 0.81 := 0.86
|
||||
>= 0.81 < 0.86 := 0.90
|
||||
>= 0.86 < 0.91 := 0.94
|
||||
>= 0.91 < 0.96 := 0.98
|
||||
>= 0.96 < 1.01 := 1.00
|
||||
EOT
|
||||
|
||||
func price(money) {
|
||||
table.each { |row|
|
||||
(row[0] <= money) ->
|
||||
&& (row[1] > money) ->
|
||||
&& return row[2];
|
||||
}
|
||||
die "Out of range";
|
||||
}
|
||||
|
||||
for n in %n(0.3793 0.4425 0.0746 0.6918 0.2993 0.5486 0.7848 0.9383 0.2292) {
|
||||
say price(n);
|
||||
}
|
||||
5
Task/Price-fraction/jq/price-fraction-1.jq
Normal file
5
Task/Price-fraction/jq/price-fraction-1.jq
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
def getScaleFactor:
|
||||
["0.10","0.18","0.26","0.32","0.38","0.44","0.50","0.54",
|
||||
"0.58","0.62","0.66","0.70","0.74","0.78","0.82","0.86",
|
||||
"0.90","0.94","0.98","1.00"] as $values
|
||||
| $values[ (. * 100 - 1) / 5 | floor ] ;
|
||||
5
Task/Price-fraction/jq/price-fraction-2.jq
Normal file
5
Task/Price-fraction/jq/price-fraction-2.jq
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
def test:
|
||||
(range(0;10) | "0.0\(.) -> \( 0.01 * . | getScaleFactor)"),
|
||||
(range(10;100) | "0.\(.) -> \( 0.01 * . | getScaleFactor)");
|
||||
|
||||
test
|
||||
Loading…
Add table
Add a link
Reference in a new issue