<commit_before>! Copyright (C) 2008 <NAME>
! See http://factorcode.org/license.txt for BSD license

USING: sequences kernel arrays vectors accessors assocs sorting math math.functions ;

IN: math.binpack 

: (binpack) ( bins item -- )
    swap dup [ [ second ] map sum ] map swap zip sort-keys values first push ;

: binpack ( assoc n -- bins )
    [ sort-values reverse [ length ] keep swap ] dip 
    [ / ceiling ] keep swap <array> [ <vector> ] map 
    swap [ dupd (binpack) ] each ;

: binpack* ( items n -- bins )
    [ dup zip ] dip binpack [ keys ] map ;

: binpack! ( items quot n -- bins ) 
    [ dup ] 2dip [ map zip ] dip binpack [ keys ] map ;
<commit_msg>math-binpack: Some cleanups recommended on IRC.<commit_after>! Copyright (C) 2008 <NAME>
! See http://factorcode.org/license.txt for BSD license

USING: sequences kernel arrays vectors accessors assocs sorting math math.functions ;

IN: math.binpack 

: (binpack) ( bins item -- )
    [ [ values sum ] map ] keep
    zip sort-keys values first push ;

: binpack ( assoc n -- bins )
    [ sort-values <reversed> dup length ] dip
    tuck / ceiling <array> [ <vector> ] map
    tuck [ (binpack) ] curry each ;

: binpack* ( items n -- bins )
    [ dup zip ] dip binpack [ keys ] map ;

: binpack! ( items quot n -- bins ) 
    [ dupd map zip ] dip binpack [ keys ] map ;

{'fraction_non_alphanumeric': 0.1203288490284006, 'fraction_numerical': 0.006726457399103139, 'mean_word_length': 2.7612359550561796, 'pattern_counts': {'":': 0, '<': 10, '<?xml version=': 0, '>': 10, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3725262', 'n_tokens_mistral': 452, 'n_tokens_neox': 420, 'n_words': 159}