- Input: 54831 Expected Output: 53.55 kilobytes
- Input: 1384120 Expected Output: 1.32 megabytes
- Input: 24568971464 Expected Output: 22.88 gigabytes
- Input: 7392649371023 Expected Output: 6.72 terabytes
Less Than Dot is a community of passionate IT professionals and enthusiasts dedicated to sharing technical knowledge, experience, and assistance. Inside you will find reference materials, interesting technical discussions, and expert tips and commentary. Once you register for an account you will have immediate access to the forums and all past articles and commentaries.
Forum Search
Highly Rated Users
Forum Statistics
UsersTotal Post History
- Posts:
- 45705
- Topics:
- 9398
7-Day Post History
- New Posts:
- 343
- New Topics:
- 81
- Active Topics:
- 90
Our newest member
Other
-
FAQ
All times are UTC [ DST ]
Google Ads
LTD Puzzle 7: format bytes and add postfixes
Forum rules
Always post answers in a "Hidecode" tag, so that others have a chance to answer the question too.
Always post answers in a "Hidecode" tag, so that others have a chance to answer the question too.
10 posts • Page 1 of 1
Please wait...
LTD Puzzle 7: format bytes and add postfixes
Given a numerical input of bytes, create a function to format the output to two decimal places along with the relevant postfixes
e.g.
For clarification in this puzzle we would have to define whether the increments are in 1000's or 1024's and define each postfix like so:
So we want the correct and HD-manufacturers result
.
e.g.
For clarification in this puzzle we would have to define whether the increments are in 1000's or 1024's and define each postfix like so:
- Kilobytes
- Megabytes
- Gigabytes
- Terabytes
- Petabytes
- Exabytes
- Zettabytes
- Yottabytes
So we want the correct and HD-manufacturers result
.-

chrissie1 - LTD Admin

-










- Posts: 6038
- Joined: Wed Oct 10, 2007 7:18 pm
- Location: Belgium
Re: LTD Puzzle 7: format bytes and add postfixes
Am I really understood the puzzle?
This is the output:
Code is hidden, SHOW
This is the output:
- 53.55 kilobytes
- 1.32 megabytes
- 22.88 gigabytes
- 6.72 terabytes
- b3orn
- Apprentice

-
- Posts: 9
- Joined: Thu Jul 17, 2008 3:23 pm
Re: LTD Puzzle 7: format bytes and add postfixes
I think you did.
Don't worry, next week will be a difficult one
Don't worry, next week will be a difficult one

-

chrissie1 - LTD Admin

-










- Posts: 6038
- Joined: Wed Oct 10, 2007 7:18 pm
- Location: Belgium
Re: LTD Puzzle 7: format bytes and add postfixes
Am I really understood the puzzle?
But what I wrote above? I definitely need an english course ...
- b3orn
- Apprentice

-
- Posts: 9
- Joined: Thu Jul 17, 2008 3:23 pm
Re: LTD Puzzle 7: format bytes and add postfixes
Here is a C# 3.0 method that takes advantage of anonymous types.
Incase you can't tell, I'm a big fan of the ternary operator.
Code is hidden, SHOW
Incase you can't tell, I'm a big fan of the ternary operator.
-

spoulson - Senior Apprentice

-


- Posts: 203
- Joined: Mon Jun 02, 2008 2:37 am
- Location: Middletown, DE, USA
Re: LTD Puzzle 7: format bytes and add postfixes
It's more cheesier if you do it right the first time!
-

Emtucifor - Senior Sage

-










- Posts: 2152
- Joined: Fri May 30, 2008 9:30 pm
- Location: California
Re: LTD Puzzle 7: format bytes and add postfixes
In keeping with my inefficient ruby coding, here is my ungainly answer:
It does however return the right things, which is good. I think I should probably redo it with a loop...
Code is hidden, SHOW
It does however return the right things, which is good. I think I should probably redo it with a loop...
- #puts "kilo"
- 54831.bytes
- #puts "mega"
- 1384120.bytes
- #puts "giga"
- 24568971464.bytes
- #puts "terra"
- 7392649371023.bytes
- #puts "peta"
- (1023**6).bytes
- #puts "zetta"
- (1025**7).bytes
- #puts "yotta"
- (1077**8).bytes
- #puts "Wow!"
- (1077**9).bytes
- 53.55 Kilobytes
- 1.32 Megabytes
- 22.88 Gigabytes
- 6.72 Terrabytes
- 1018.01 Petabytes
- 1.01 Zettabytes
- 1.5 Yottabytes
- Wow, I don't know what to call that!
- SeanJA
- Newbie

-
- Posts: 3
- Joined: Thu Jul 17, 2008 7:31 am
Re: LTD Puzzle 7: format bytes and add postfixes
There are 2 types of winner - a "People's Champion" (the one with the most rating points across all their posts) and the LTD Admin's Champion (selected with our special formula....honest...well, maybe it's just the ones that the admins thought were particularly good
)
So...
People's Champion: b3orn scoring 14 points for his answer
LTD Admin's Champion: SeanJA for having the uggliest code (being original is always a bonus on LTD).
Congratulations to all.. and good luck on next weeks puzzle
)So...
People's Champion: b3orn scoring 14 points for his answer
LTD Admin's Champion: SeanJA for having the uggliest code (being original is always a bonus on LTD).
Congratulations to all.. and good luck on next weeks puzzle

-

chrissie1 - LTD Admin

-










- Posts: 6038
- Joined: Wed Oct 10, 2007 7:18 pm
- Location: Belgium
Re: LTD Puzzle 7: format bytes and add postfixes
Terrabytes.
ugh!

It's more cheesier if you do it right the first time!
-

Emtucifor - Senior Sage

-










- Posts: 2152
- Joined: Fri May 30, 2008 9:30 pm
- Location: California
Re: LTD Puzzle 7: format bytes and add postfixes
My PHP solution:
Output:
Code is hidden, SHOW
Output:
- 53.55 Kilobytes
- 1.32 Megabytes
- 22.88 Gigabytes
- 6.72 Terabytes
I try to improve my English language skills. Most things i do better than this.
- tisodotsk
- Apprentice

-

- Posts: 22
- Joined: Fri Aug 08, 2008 12:45 pm
- Location: Bratislava, Slovakia
10 posts • Page 1 of 1



LTD Social Sitings
Note: Watch for social icons on posts by your favorite authors to follow their postings on these and other social sites.