Bug fixes
- upgraded nMaven, NUnit, made build 32bit only
- fixed throwing exceptions for missing proxy classes
- [#18] - C# string[]{null} -> JVM -> null reference exception
- improved architecture detection
Pavel Šavara coding for fun
namespace SampleFs
open Robocode
type MyFirstRobot() =
inherit Robot()
override robot.Run() =
while true do
robot.TurnLeft(40.0)
robot.Ahead(20.0)
override robot.OnScannedRobot(evnt : ScannedRobotEvent) =
robot.Fire(1.0)
override robot.OnHitByBullet(evnt : HitByBulletEvent) =
robot.TurnLeft(90.0 - evnt.Bearing)
open Microsoft.FSharp.Core.Operators
let findpalindrome xs ys =
let separate s p = (s % (pown 10 (p+1))) - (s % (pown 10 p))
let shiftl s p o = (separate s p) / (pown 10 (p-o))
let shiftr s p o = (separate s p) * (pown 10 (o-p))
let flip f = shiftl f 5 0 + shiftl f 4 1 + shiftl f 3 2 + shiftr f 2 3 + shiftr f 1 4 + shiftr f 0 5
let findi xs y = xs |> Seq.filter( fun x -> (((x*y) = flip (x*y)) && (separate (x*y) 0 <> 0) ) ) |> Seq.map(fun x -> (x*y,x))
ys |> Seq.collect(fun y -> (findi xs y)) |> Seq.maxBy(fun t -> fst(t))
findpalindrome [100..999][100..999]
let test =
let max = (primes 20 |> Seq.reduce(fun a c -> a*c))*8L*3L
[1L..20L] |> Seq.filter(fun x -> (max % x) <> 0L)
let diff xs =
let sumsq = xs |> Seq.reduce(fun c a -> (a*a)+c)
let sum = (xs |> Seq.reduce(fun c a -> (a+c)))
let sqsum = sum*sum
sqsum - sumsq
diff [1..100]
open Microsoft.FSharp.Core.Operators
let primesnth nthprime =
let maxPrime = 300000
let pr : bool array = Array.zeroCreate maxPrime
let mutable res = 0
let mutable nth = 0
let mutable cur=2
while (nth < nthprime) do
if not pr.[cur] then
for wr in cur+cur .. cur .. maxPrime-1 do pr.[wr] <- true
res <- cur
nth <- nth + 1
cur <- cur + 1
res
primesnth 10001
[1..999] |> Seq.filter( fun x -> (x % 3 = 0 || x % 5 = 0)) |> Seq.sum
let fib max =
let rec fibo a b max =
if b>= max then a :: [] else a :: fibo b (a+b) max
fibo 1 2 max
fib 4000000 |> Seq.filter(fun x -> (x % 2 = 0)) |> Seq.toList|> Seq.sum
open Microsoft.FSharp.Math
open System.Collections.Generic
let maxPrime:int= (int) (System.Math.Sqrt((float)600851475143I))
let primes maxPrime =
let pr : bool array = Array.zeroCreate maxPrime
let res = new List()
for cur in 2 .. maxPrime/2 do
if not pr.[cur] then for wr in cur+cur .. cur .. maxPrime-1 do pr.[wr] <- true
for cur in 1 .. maxPrime-1 do
if not pr.[cur] then res.Add(new bigint(cur))
res
primes maxPrime |>
Seq.filter(fun x -> ((600851475143I % x) = 0I ))
|> Seq.map( fun x -> ((int)(x)))
|> Seq.max
[UnmanagedFunctionPointer(CallingConvention.xxx)]on any JNI delegate. Example is JNIEnv.AllocObject. I think I'll need to duplicate whole JNIEnv class in order to avoid condition for each call.
[DllImport("jvm.dll", CallingConvention = CallingConvention.StdCall)], it must be duplicated as well, because there is jvm.so on Linux.