Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Memory Saver - 1

 
Paul McKenna
Ugly Redneck
Ranch Hand
Posts: 1006
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Represent a date in the format mmddyyyy in the least amount of memory possible. Solution need not be Java specific, you can use C notations if you want.
[ June 03, 2003: Message edited by: Sriraj Rajaram ]
 
Damian Ryan
Ranch Hand
Posts: 117
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The information could be encoded into 23 bits:
4 bits for the month (0-14 covers 1-12 or 0-11)
5 bits for the date (0-31 covers 1-31 or 0-30)
14 bits for the year (0-16383 covers 1-9999)
So the information could be stored in a single int:
000000000mmmmdddddyyyyyyyyyyyyyy
Assuming month, date amd year are int values that have been validated as being in range, you should be able to get the stored value by:

to get month, date and year back from the value:

I haven't tried any of that for real, so I might be completely wrong
 
Jim Yingst
Wanderer
Sheriff
Posts: 18671
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It's possible to do it in 22 bits - or less if we restrict the year range to something more realistic. E.g. by limiting years to a span of 178 years, we can get it down to 16 bits, fitting nicely in a short. Here's a 22-bit solution for years 1-9999:
 
Michael Morris
Ranch Hand
Posts: 3451
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
E.g. by limiting years to a span of 178 years
Are you trying to start another Y2K incident?
 
Jim Yingst
Wanderer
Sheriff
Posts: 18671
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hey, Sriraj wants to minimize the memory, I am just offering options. If that means he will have to employ me years from now to sort out the mess made by all the applications he builds on this solution, well, I'm not complaining.
 
Paul McKenna
Ugly Redneck
Ranch Hand
Posts: 1006
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
All your answers were correct. I think 178 years is more than enough for anyone (trying to act like Bill Gates.. )
Given the situation in the IT industry, I definetly would love another Y2K problem. So that demand goes up again. Anyway that thought belongs in a different forum.
[ June 04, 2003: Message edited by: Sriraj Rajaram ]
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic