[algogeeks] Re: Explain the o/p

2011-06-15 Thread Maksym Melnychok
that's floating point for you.

http://en.wikipedia.org/wiki/Floating_point

-- 
You received this message because you are subscribed to the Google Groups 
Algorithm Geeks group.
To view this discussion on the web visit 
https://groups.google.com/d/msg/algogeeks/-/RcduUpABmi8J.
To post to this group, send email to algogeeks@googlegroups.com.
To unsubscribe from this group, send email to 
algogeeks+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/algogeeks?hl=en.



[algogeeks] Re: Need help

2011-06-15 Thread Maksym Melnychok
EkoPath compiler has been open sourced 
recently: http://www.pathscale.com/ekopath-compiler-suite

-- 
You received this message because you are subscribed to the Google Groups 
Algorithm Geeks group.
To view this discussion on the web visit 
https://groups.google.com/d/msg/algogeeks/-/j07rEcpBsq4J.
To post to this group, send email to algogeeks@googlegroups.com.
To unsubscribe from this group, send email to 
algogeeks+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/algogeeks?hl=en.



[algogeeks] Re: Reversing a string

2011-06-01 Thread Maksym Melnychok
without indexes in erlang:

reverse(String) -
  reverse(String, []).

reverse([], NewString) -
  NewString;
reverse([Head|Rest], NewString) -
  reverse(Rest, [Head|NewString]).

-- 
You received this message because you are subscribed to the Google Groups 
Algorithm Geeks group.
To view this discussion on the web visit 
https://groups.google.com/d/msg/algogeeks/-/YlhkNW9TUmhHREVK.
To post to this group, send email to algogeeks@googlegroups.com.
To unsubscribe from this group, send email to 
algogeeks+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/algogeeks?hl=en.



[algogeeks] Re: Google Interview Question

2011-05-30 Thread Maksym Melnychok
here's efficient oneliner without any string manipulation

divide every number by 10^(log10(x).ceil)
sort
convert back to original numbers
join array into string

there are edge-cases where this doesn't work but they can be dealt with 
easily - have to go back to work :)

-- 
You received this message because you are subscribed to the Google Groups 
Algorithm Geeks group.
To post to this group, send email to algogeeks@googlegroups.com.
To unsubscribe from this group, send email to 
algogeeks+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/algogeeks?hl=en.



Re: [algogeeks] Binary Tree Problem

2011-05-30 Thread Maksym Melnychok
wont work for this tree:

x
  /\
 x x
   /\
 x  x
  /   \
 xy
/   \
   xx
  / 
 x

max distance in left subtree is 7 and distance between left and right is 6

-- 
You received this message because you are subscribed to the Google Groups 
Algorithm Geeks group.
To post to this group, send email to algogeeks@googlegroups.com.
To unsubscribe from this group, send email to 
algogeeks+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/algogeeks?hl=en.



[algogeeks] Re: Binary Tree Problem

2011-05-30 Thread Maksym Melnychok
simplest algo: find a node with max depth M and go up tree calculating max 
depth of all upper branches that do not contain M until reaching root node

-- 
You received this message because you are subscribed to the Google Groups 
Algorithm Geeks group.
To post to this group, send email to algogeeks@googlegroups.com.
To unsubscribe from this group, send email to 
algogeeks+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/algogeeks?hl=en.



Re: [algogeeks] Google Interview Question

2011-05-30 Thread Maksym Melnychok
some explanation

say we have numbers 2 3 5 78
divide all by something to get 0.2, 0.3, 0.5, 0.78
simple sort will give you 0.78, 0.5, 0.3, 0.2
multiply all numbers to get original ones 78 5 3 2
join 78532

-- 
You received this message because you are subscribed to the Google Groups 
Algorithm Geeks group.
To post to this group, send email to algogeeks@googlegroups.com.
To unsubscribe from this group, send email to 
algogeeks+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/algogeeks?hl=en.



Re: [algogeeks] Google Interview Question

2011-05-30 Thread Maksym Melnychok
possible fix for 100 10 edgecases would be to simply array.map{|x| x*10+1} 
and then get rid of that after sorting

-- 
You received this message because you are subscribed to the Google Groups 
Algorithm Geeks group.
To post to this group, send email to algogeeks@googlegroups.com.
To unsubscribe from this group, send email to 
algogeeks+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/algogeeks?hl=en.



Re: [algogeeks] Google Interview Question

2011-05-30 Thread Maksym Melnychok
@Sunny i explained how to deal with edgecases right after my post

1, 101 - 11, 1011
11, 1011 - 0.11, 0.1011
sort - 0.11, 0.1011
restore - 1, 101
join - 1101

i can't think of any fail examples anymore

-- 
You received this message because you are subscribed to the Google Groups 
Algorithm Geeks group.
To post to this group, send email to algogeeks@googlegroups.com.
To unsubscribe from this group, send email to 
algogeeks+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/algogeeks?hl=en.



Re: [algogeeks] Google Interview Question

2011-05-30 Thread Maksym Melnychok
@halo check my previous messages

we multiply every element by 10 and add 1

90, 9 - 901, 91
901, 91 - 0.901, 0.91
sort - 0.91, 0.901
revert - 9, 90
join - 990

-- 
You received this message because you are subscribed to the Google Groups 
Algorithm Geeks group.
To post to this group, send email to algogeeks@googlegroups.com.
To unsubscribe from this group, send email to 
algogeeks+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/algogeeks?hl=en.



[algogeeks] Re: Google Interview Question

2011-05-30 Thread Maksym Melnychok
so here's oneliner code in ruby:

a.map{|x| x=x*10+1; -x/10.0**Math.log10(x).ceil}.sort.map{|x| 
(-x).to_s[2..-2]}.join

-- 
You received this message because you are subscribed to the Google Groups 
Algorithm Geeks group.
To post to this group, send email to algogeeks@googlegroups.com.
To unsubscribe from this group, send email to 
algogeeks+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/algogeeks?hl=en.