Take the 2-minute tour ×
Programming Puzzles & Code Golf Stack Exchange is a question and answer site for programming puzzle enthusiasts and code golfers. It's 100% free, no registration required.

The world's changing to a new time system! We need to update our computer programs. Given an input of epoch time (number of seconds since January 1st, 1970 00:00), print out a time in the new Noxu date-time format.

864 seconds make one Fluffster. 100 Fluffsters make a Skizzle. There are 4 Skizzles in one Zestpond. Their names are Looplab, Sevit, Hexteria, and Sinpad. There are 91 Zestponds in one Lulerain.

The format is Lulerain Zestpond-Skizzle-Fluffster. Fluffsters are rounded to two decimal places. An example would be 50 13-Sevit-40.90.

Given that epoch 0 was 0 0-Looplab-00.00, create a program that takes input either via stdin or as a command line argument of any epoch time between 0 and 2^32, and prints out the Noxu equivalent.

Time of edit:

1357510372 -> 43 14-Sinpad-92.56

Random test data:

675416077 -> 21 43-Sevit-31.57
330585453 -> 10 46-Hexteria-22.05
1328127085 -> 42 20-Sinpad-84.13
837779784 -> 26 58-Looplab-52.53
1240280676 -> 39 39-Sinpad-10.04
122646385 -> 3 81-Sinpad-51.83
1311245658 -> 41 63-Looplab-45.44
57792972 -> 1 76-Looplab-90.01
788388068 -> 25 6-Looplab-86.19
304341865 -> 9 61-Hexteria-47.53
417857784 -> 13 26-Looplab-31.69
671276878 -> 21 31-Sevit-40.83
1259758896 -> 40 5-Looplab-54.28
604286664 -> 19 19-Hexteria-5.86
646395018 -> 20 50-Sevit-42.38
563025133 -> 17 82-Looplab-49.46
96133144 -> 3 5-Looplab-65.21
101542552 -> 3 20-Sinpad-26.10
1006825856 -> 32 1-Sevit-7.70
928867348 -> 29 48-Hexteria-77.95
1235022079 -> 39 24-Hexteria-23.70
439505287 -> 13 88-Hexteria-86.67
99686711 -> 3 15-Sevit-78.14
379859609 -> 12 7-Looplab-52.33
1167091685 -> 37 10-Looplab-0.56
612032437 -> 19 41-Sinpad-70.88
503040778 -> 15 90-Hexteria-23.12
1084809411 -> 34 44-Sinpad-66.45
1105664386 -> 35 14-Sevit-4.15
197303893 -> 6 24-Sinpad-60.99
368559287 -> 11 65-Sevit-73.25
686824300 -> 21 76-Sevit-35.53
196468204 -> 6 22-Sevit-93.75
673542185 -> 21 37-Sinpad-62.71
993063782 -> 31 52-Sevit-79.38
270951743 -> 8 56-Looplab-1.55
1074506753 -> 34 15-Looplab-42.08
198143696 -> 6 27-Sevit-32.98
539601298 -> 17 14-Sevit-38.54
110090607 -> 3 45-Hexteria-19.68
276492708 -> 8 72-Looplab-14.71
113389138 -> 3 55-Looplab-37.43
571578220 -> 18 15-Sinpad-48.87
1238516450 -> 39 34-Hexteria-68.11
742293312 -> 23 54-Sinpad-35.78
1031929490 -> 32 73-Sinpad-62.84
503091914 -> 15 90-Hexteria-82.31
264094386 -> 8 36-Looplab-64.80
483820698 -> 15 34-Sinpad-77.66
548410387 -> 17 39-Sinpad-34.24
share|improve this question
    
Could you please post a test set? –  belisarius Jan 6 '13 at 22:21
    
@belisarius, I added some :-) –  FakeRainBrigand Jan 6 '13 at 22:26
    
@belisarius, I made a typo in my post. It's supposed to be 864 instead of 846. Should be a simple fix in your code. I updated the test data and description. –  FakeRainBrigand Jan 6 '13 at 22:40
add comment

5 Answers 5

up vote 2 down vote accepted

dc - 81

2k864/0k100~[Looplab]0:a[Sevit]1:a[Hexteria]2:a[Sinpad]3:ar4~;ar91~rn32Pn45dPrnPp

Expects the epoch time already on the stack so invoke as, e.g.

dc -e `date +%s` -e '2k864/0k100~[Looplab]0:a[Sevit]1:a[Hexteria]2:a[Sinpad]3:ar4~;ar91~rn32Pn45dPrnPp'

to get the current Noxu time or add one character to accept the time from stdin

?2k864/0k100~[Looplab]0:a[Sevit]1:a[Hexteria]2:a[Sinpad]3:ar4~;ar91~rn32Pn45dPrnPp

annotated version

2 k             # set the precision to 2 decimal places
864 /           # divide the number of seconds by 864 to get fluffsters
0 k             # set the precision back to 0 decimal places
100 ~           # divrem by 100; fluffsters are at the top skizzles under it
[Looplab] 0 :a  # set a[0] to the string Looplab
[Sevit] 1 :a    # set a[1] to Sevit
[Hexteria] 2 :a # set a[2] to Hexteria
[Sinpad] 3 :a   # set a[3] to Sinpad
r               # swap fluffsters and skizzles on the stack
4 ~             # divrem the skizzles by 4; skizzles on top zestpond under it
;a              # use the skizzle as an index into a
r               # swap the skizzle string and zestponds
91 ~            # divrem the zestponds by 91; zestponds on top lulerain under
r               # swap zestponds and lulerains
# now the stack has (from top to bottom)
# lulerains
# zestponds
# skizzle (as the name)
# fluffster
n               # pop and print the lulerains (without a newline)
32 P            # print a space character
n               # pop and print the zestponds
45 d P          # print a - and leave 45 on the top of the stack
r               # swap the 45 and the skizzle name
n               # pop and print the skizzle name
P               # print a - from the 45 that was on the stack
p               # finally print the fluffster (with a newline)

When the number of fluffsters is less than 1 there is no leading zero printed, to get the leading zero, it is

2k864/0k100~[Looplab]0:a[Sevit]1:a[Hexteria]2:a[Sinpad]3:ar4~;ar91~rn32Pn45dPrnPd[0n]sb1>bp

at a cost of 10 extra characters (d[0n]sb1>b)

share|improve this answer
add comment

APL, 87

t[3]←(1+3⌷t←137 91 4 100⊤⍎2⍕⎕÷864)⌷'Looplab' 'Sevit' 'Hexteria' 'Sinpad'
'  '⎕R'-'⍕t

APL has an advantage in these time system conversion challenges due to the built-in encode function, at the cost of expensive string manipuation

Explanation
(using 1357510372 as example)

⎕÷864 takes user input from screen, divide by 864 (1571192.56018519)
⍎2⍕ and round to 2 dp. (1571192.56)
137 91 4 100⊤ Then, converts to Noxu Time System (43 14 3 92.56)
t← and assign that to variable t.
1+3⌷ take the 3rd item from t, add 1 to account for 1-based indexing, (4)
(...)⌷'Looplab' 'Sevit' 'Hexteria' 'Sinpad' convert to Skizzle name, (Sinpad)
t[3]← and finally plug back into the 3rd item of t.

⍕t Convert t to a string representation, (43 14  Sinpad  92.56)
' '⎕R'-' and replaces 2 spaces with a dash (43 14-Sinpad-92.56)

share|improve this answer
1  
Very impressive! –  FakeRainBrigand Jan 7 '13 at 21:35
    
@FakeRainBrigand Actually this doesn't force 2 dp (So input 0 gives 0 0-Looplab-0). If you insist on it, it would cost 23 chars. –  TwiNight Jan 7 '13 at 22:16
    
Or, as some of the tests don't include a leading zero in case of Fluffster < 10, it would cost 22 chars instead. –  TwiNight Jan 7 '13 at 22:33
add comment

Mathematica 152

Still has some format issues. Spaces added for clarity

Flatten@{#[[5]], {Looplab, Sevit, Hexteria,  Sinpad}[[#[[4, 2]] + 1]], 
        N[#[[3, 2]] + #[[2, 2]]/864, 4]} &@
               FoldList[QuotientRemainder[#1[[1]], #2] &, {#, 0}, {864, 100, 4, 91}]&
share|improve this answer
add comment

Ruby, 114 112

x=gets.to_f
puts'%d %d-%s-%.2f'%[x/d=91*c=4*b=86400,(x%=d)/c,%w[Looplab Sevit Hexteria Sinpad][x%c/b],x%c%b/864]

Meh. Basically grc's solution but with inline assignments.

Edit: Saved 2 chars by changing to_i to to_f so I don't need the float literal later.

share|improve this answer
add comment

Python, 123

x=input()
b=86400
c=b*4
d=c*91
print x/d,'%d-%s-%.2f'%(x%d/c,['Looplab','Sevit','Hexteria','Sinpad'][x%d%c/b],x%d%c%b/864.)
share|improve this answer
    
Nice work. It used 6 lines; I wonder if it could be condensed any more. –  FakeRainBrigand Jan 7 '13 at 4:05
1  
a=864. will save two chars on the print line, i believe (you can remove the *1./a and just have /a). Just set b to 86400 instead of a*100. –  beary605 Jan 7 '13 at 4:24
1  
I don't see why you can't just inline a –  TwiNight Jan 7 '13 at 18:09
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.