• R/O
  • HTTP
  • SSH
  • HTTPS

Commit

Tags
No Tags

Frequently used words (click to add to your profile)

javac++androidlinuxc#windowsobjective-ccocoa誰得qtpythonphprubygameguibathyscaphec計画中(planning stage)翻訳omegatframeworktwitterdomtestvb.netdirectxゲームエンジンbtronarduinopreviewer

Finds networks of resistors to approximate resistances.


Commit MetaInfo

Revisãod0bdb9a227d150d2c81511cb61e1ff7ce501a5ab (tree)
Hora2020-03-11 16:12:16
AutorAlaskanEmily <emily@alas...>
CommiterAlaskanEmily

Mensagem de Log

Sort results by resistor count, then by how close it is to the target

Mudança Sumário

Diff

--- a/resistors.m
+++ b/resistors.m
@@ -443,7 +443,19 @@ main(!IO) :-
443443 % Read from stdin
444444 read_resistors_from_stdin(rbtree.init, Resistors, !IO),
445445 Sort = (pred(A::in, B::in, Cmp::out) is det :-
446- builtin.compare(Cmp, length(A), length(B)) ),
446+ builtin.compare(LenCmp, length(A), length(B)),
447+ % If the lengths are identical, sort by how close the
448+ % resistance is to our target.
449+ ( if
450+ LenCmp = (=)
451+ then
452+ % Not entirely sure why the type hinting is needed...
453+ builtin.compare(Cmp,
454+ abs(value(A) - Target):int,
455+ abs(value(B) - Target))
456+ else
457+ LenCmp = Cmp
458+ ) ),
447459
448460 % Try a simple network.
449461 promise_equivalent_solutions [SimpleResults] (