Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon.

Pages: 1-

F# Algorithm Help

Name: Anonymous 2014-01-17 4:10

Sup /prog/, I need some algorithm help in F#. I'm fairly new to the language, and I'm working on a small dice library. My dice rolling code produces two values: an int seq of all the results of a set of dice (in the order that they were rolled), and a Map<int,int> of the results sorted as <faceRolled, quantityRolled>.

What's the quickest way to select the highest N and lowest (length-N) dice from either of the two collections? My current code is as follows:

// The huge slowdown
let Omitted =
    results // This is the int seq of unsorted results
    |> Seq.sort
    |> Seq.take (keepHighestCount - (Seq.length results))
    |> Seq.countBy ( fun t -> t )
    |> Map.ofSeq
// Extension function is a side effect free Map-Map
let Kept =
    collapsedResults
    |> MapExt.Remove Omitted

Name: Anonymous 2014-01-17 4:26

rollcounter[rollvalue[i]]++?

Name: Anonymous 2014-01-17 14:01

>>2
very imperative
such nonstandard
wow
nonfunctional/10

Name: Anonymous 2014-01-17 14:25

>>3
Epic meme bro!

Name: Anonymous 2014-01-17 17:35

>>3
>>4
Can we keep the trolling out of my thread? Thanks.
>>2
The doge had a point l, unfortunately. That's incredibly non-imperative.

Name: Anonymous 2014-01-17 17:37

>>5
non idiomatic, shit.

Name: Anonymous 2014-01-17 17:52

install gentoo

Name: Anonymous 2014-01-17 19:44

>>5
>le pedophile trolling

Name: Anonymous 2014-01-17 20:39

very imperetive
non-imperetive
non-functional / 10

all implementation-specific?

Name: Anonymous 2014-01-17 20:45

do you generate dice-rolls one at a time, or in batches?

Name: Anonymous 2014-01-17 21:00


function [rollcount] = rollsum(maxdice, rollvector)
for(i=1:maxdice)
  rollcount(i) = sum(rollvector==i);
  endfor;
endfunction;

function [rolln] = nLow(maxdice, rollcount, n)
counter = 0;
i=1;
while((counter<n) + (i<maxdice) == 2)
  if(counter-n<=rollcount(i))
    rolln(i) = counter-n;
    counter = n;
   else
    rolln(i) = rollcount(i);
    counter = counter + rollcount(i);
   endif;
  i++;
  endwhile;
endfunction;

Name: Anonymous 2014-01-18 2:32

>>11
function/endfunction
looks liek XML

Don't change these.
Name: Email:
Entire Thread Thread List