Posts

javascript - Get number of times a number will multiply itself with another until reach a certain limit -

i can number of times number multiply until reach limit: var velocity = -5.706875; var friction = 0.9925; var limit = 0 var times = 0; while (math.floor(math.abs(velocity)*10) > limit) { velocity *= friction; times += 1; } // times = 538 is there way times without loop? tried math.log(5.706875, 0.9925) gives result. sure, there are: times = math.ceil(math.log(-0.1/velocity)/math.log(friction)); edit: actually, taking account limit var, be: times = math.ceil(math.log(-(0.1+limit/10)/velocity)/math.log(friction));

java - Incompatible types: possible lossy conversion from double to int -

help? don't know why getting error. getting @ in line 39: term[1] = differentiate(coeff[1], exponent[1]); how can fix issue? full code listing: public class calcprog { public static void main(string[] args) { scanner input = new scanner(system.in); int numterms = 7; double[] coeff = new double[6]; double[] exponent = new double[6]; string[] term = new string[6]; system.out.println("enter number of terms in polynomial:"); numterms = input.nextint(); while (numterms > 6) { if (numterms > 6) { system.out.println("please limit number of terms six."); system.out.println("enter number of terms in polynomial:"); numterms = input.nextint(); } } (int = 1; < numterms + 1; i++) { system.out.println("please enter coefficient of term #" + + " in decimal form:...

linux - sed place parentheses at the beginning and close on the 4th line -

im trying place open parenthesis on first line , close end of 4th line. below example of data followed output looking for. tester1 service_ticket_created thu mar 19 23:27:57 utc 2015 192.168.1.3 tester2 service_ticket_created fri mar 20 00:31:59 utc 2015 192.168.1.2 (tester1 service_ticket_created thu mar 19 23:27:57 utc 2015 192.168.1.3) (tester2 service_ticket_created fri mar 20 00:31:59 utc 2015 192.168.1.2) using awk can as awk 'nr%4==1{print "("$0; next} nr%4==0{print $0")"; next}1' test $ awk 'nr%4==1{print "("$0; next} nr%4==0{print $0")"; next}1' input (tester1 service_ticket_created thu mar 19 23:27:57 utc 2015 192.168.1.3) (tester2 service_ticket_created fri mar 20 00:31:59 utc 2015 192.168.1.2) shorter version awk 'nr%4==1{$0="("$0} nr%4==0{$0=$0")"}1'

Android speech recognition for non-dictionary words -

i developing android application of speech recognition non-dictionary words. want remove dictionary , word. example if pronounce word "pini", current application "beanie". want word recognize pronounced. my code: public void onclick(view v) { // todo auto-generated method stub switch (v.getid()) { case r.id.btnspeak: promptspeechinput(); break;} } @override // act on result of tts data check protected void onactivityresult(int requestcode, int resultcode, intent data) { if (requestcode == my_data_check_code) { if (resultcode == texttospeech.engine.check_voice_data_pass) { mytts = new texttospeech(this, this); } else { intent installttsintent = new intent(); installttsintent .setaction(texttospeech.engine.action_install_tts_data); startactivity(installttsintent); } } // receiving speech input super.onactivityresult(request...

apache spark - Are multiple reduceByKey on the same RDD compiled into a single scan? -

suppose have rdd (50m records/dayredu) want summarize in several different ways. rdd records 4-tuples: (keep, foo, bar, baz) . keep - boolean foo , bar , baz - 0/1 int i want count how many of each of foo &c kept , dropped, i.e., have following foo (and same bar , baz ): rdd.filter(lambda keep, foo, bar, baz: foo == 1) .map(lambda keep, foo, bar, baz: keep, 1) .reducebykey(operator.add) which return (after collect ) list [(true,40000000),(false,10000000)] . the question is: there easy way avoid scanning rdd 3 times (once each of foo , bar , baz )? what mean not way rewrite above code handle 3 fields, telling spark process 3 pipelines in single pass. it's possible execute 3 pipelines in parallel submitting job different threads, pass through rdd 3 times , require 3x more resources on cluster. it's possible job done in 1 pass rewriting job handle counts @ once - answer regarding aggregate option. splitting data in pairs (keep, foo...

c - undefined reference to avltree_init -

in code provided instructor there is: typedef int (*avltree_cmp_fn_t)(const struct avltree_node *, const struct avltree_node *); int avltree_init(struct avltree *tree, avltree_cmp_fn_t cmp, unsigned long flags); after define my_cmp function... int my_cmp(const struct avltree_node *a, const struct avltree_node *b) { struct my_struct *p = avltree_container_of(a, my_struct, node); struct my_struct *q = avltree_container_of(b, my_struct, node); return p->key - q->key; } and pass parameter avltree_init... avltree_init(&tree, my_cmp, 0); i get: undefined reference `avltree_init(avltree*, int (*)(avltree_node const*, avltree_node const*), unsigned long)' could explain, please, why happens , did make mistake? thanks! it seems error message you're not linking file contains avltree_init function. need link files, including file containing function, final application. error comes linking phase, not compiling phase. further...

c++ - Write a function to copy 0-15 bits into 16-31 -

how write function copy 0-15 bits 16-31? unsigned int n = 10; // 1010 copyfromto(n); assert(n == 655370); n = 5; copyfromto(n); assert(n == 327685); n = 134; copyfromto(n); assert(n == 8781958); you want copy bits in 0-15 16-31. should understand multiplying 2 equivalent shifting bits of number once left (moving higher bits). if number n , n << 16 shifting number 16 bits left. equivalent multiplying n 16th power of 2, happens 65536. to copy bits, , keep original bits in 0-15, command n = n + (n << 16); should work. however, issue (as pointed out in comments), upper 16-31 bits still set in n + term. need clear these bits. note 65535 corresponds 2^16 - 1, , have first 0-15 bits 1, , others 0. correct command n = (n && 65535) + (n << 16);