7
\$\begingroup\$

When you leave, my challenges fade to grey, 0A0AE16, 0A0A0AE16...

A while ago, I made this programming language (https://esolangs.org/wiki/Dragostea_din_tei) which uses an interesting number system. It is base two for integers, but for decimals it divides a base two integer by a power of ten.

The input should be a floating point number, negative, positive or zero.

The output should be "the" standard representation for, that number, in the programming language, which should follow these steps:

  1. Start with the absolute value of that number. Now multiply the result by the smallest power of ten to make it an integer (for example, 123.45 -> multiply by 100 to make 12345) and call it a.
  2. Write Ma-ia hii + a newline (literally, push the number zero).
  3. Write a in base two, with Ma-ia huu + a newline for ones, and Ma-ia hoo + a newline for 0's.
  4. Now, if the original number (not a) has any decimal places, write Ma-ia haha + a newline for every digit after the decimal point, for example twice for 123.45.
  5. If the original number is negative, write Vrei sa pleci dar.

You can add or omit trailing and leading newlines if you want.

DONE. Now, here are some good ol' examples: -10 is:

Ma-ia hii
Ma-ia huu
Ma-ia hoo
Ma-ia huu
Ma-ia hoo
Vrei sa pleci dar

256 is:

Ma-ia hii
Ma-ia huu
Ma-ia hoo
Ma-ia hoo
Ma-ia hoo
Ma-ia hoo
Ma-ia hoo
Ma-ia hoo
Ma-ia hoo
Ma-ia hoo

And 3.14 is:

Ma-ia hii
Ma-ia huu
Ma-ia hoo
Ma-ia hoo
Ma-ia huu
Ma-ia huu
Ma-ia huu
Ma-ia hoo
Ma-ia huu
Ma-ia hoo
Ma-ia haha
Ma-ia haha

And finally for -3.14:

Ma-ia hii
Ma-ia huu
Ma-ia hoo
Ma-ia hoo
Ma-ia huu
Ma-ia huu
Ma-ia huu
Ma-ia hoo
Ma-ia huu
Ma-ia hoo
Ma-ia haha
Ma-ia haha
Vrei sa pleci dar

This is code-golf, so fewest bytes wins!

\$\endgroup\$
4
  • \$\begingroup\$ Is it okay if it ends up outputting the representation of 3.14000000000000012 for 3.14. Floating point representation nonsense. :P \$\endgroup\$ Feb 24 at 3:29
  • \$\begingroup\$ @totallyhuman Yes. \$\endgroup\$ Feb 24 at 8:46
  • 2
    \$\begingroup\$ O-Zone have a lot to answer for, but a programming language was not on my bingo card for 2024. \$\endgroup\$ Feb 24 at 18:16
  • \$\begingroup\$ Consider adding a negative test case with decimals e.g. -3.14? \$\endgroup\$
    – Julian
    Feb 25 at 20:24

7 Answers 7

2
\$\begingroup\$

Charcoal, 65 59 bytes

⁺Ma-ia h⁺ײ⁺⟦i⟧E↨IΦθ‹.鲧ouιEΦθ№…θκ.¦aha¿№θ-”(/◧êºcS﹪Z↑M▶#↓

Try it online! Link is to verbose version of code. Explanation:

⁺Ma-ia h⁺ײ⁺⟦i⟧E↨IΦθ‹.鲧ouιEΦθ№…θκ.¦aha

Remove non-digits from the input, convert from base 10 to base 2, and replace 0s with o and 1s with u. Prefix i to the resulting list, then double the letters. Append aha to the list for each digit after the . (if any), prepend Ma-ia h to each element of the list, and output the result.

¿№θ-”(/◧êºcS﹪Z↑M▶#↓

If the input contained a - then output Vrei sa pleci dar using a compressed string.

If an extra Ma-ia hoo is acceptable for an input of 0, then for 55 bytes:

⁺Ma-ia h⁺ײ⪪⁺i⍘IΦθ‹.ιou¹EΦθ№…θκ.¦aha¿№θ-”(/◧êºcS﹪Z↑M▶#↓

Attempt This Online! Link is to verbose version of code. Explanation: When converting 0 to a string base the version of Charcoal on TIO always returns 0 but the version of Charcoal on ATO returns the first character of the string. (For a numeric base conversion both versions would return an empty list.)

\$\endgroup\$
1
  • \$\begingroup\$ The 55-byte answer is valid. \$\endgroup\$ Feb 25 at 12:36
2
\$\begingroup\$

JavaScript (ES6), 103 bytes

Recursively builds the output from bottom to top.

f=x=>x<0?f(-x)+`
Vrei sa pleci dar`:x%1?f(x*10)+m+`aha`:x?f(x>>1)+m+(x&1?`uu`:`oo`):(m=`
Ma-ia h`)+`ii`

Try it online!

\$\endgroup\$
2
\$\begingroup\$

Perl 5 -n, 106 bytes

s/\.//;say"Ma-ia h$_"for ii,(oo,uu,aha)[(sprintf"%b%s",abs,$'=~y//2/cr)=~/./g];say"Vrei sa pleci dar"if/-/

Try it online!

\$\endgroup\$
2
\$\begingroup\$

Python, 194 189 186 172 171 bytes

def f(i):d=max(0,f"{i:g}"[::-1].find('.'));*map(print,["Ma-ia h"+x for x in["ii"]+["uo"[b<"1"]*2for b in f"{int(abs(i)*10**d):b}"]+["aha"]*d]+["Vrei sa pleci dar"]*(i<0)),

-3 bytes thanx to Neil

I expect some fancy recursive method to make it below 100 bytes.

Attempt This Online!

\$\endgroup\$
1
  • 1
    \$\begingroup\$ p("uo"[b<"1"]*2) saves 3 bytes. \$\endgroup\$
    – Neil
    Feb 24 at 10:13
1
\$\begingroup\$

Retina 0.8.2, 104 bytes

-(.+)
$1Vrei sa pleci dar¶
\.(.+)
$1$.1$*h
h
aha
\d+
ii$&$*
+`(1+)\1
$1oo
o?o?1
uu
\Ga?[a-z].
Ma-ia h$&¶

Try it online! Link includes test cases. Explanation:

-(.+)
$1Vrei sa pleci dar¶

Handle negative numbers.

\.(.+)
$1$.1$*h
h
aha

Handle decimals.

\d+
ii$&$*
+`(1+)\1
$1oo
o?o?1
uu

Convert to unary, but using oo and uu instead of 0 and 1, and prefixing ii.

\Ga?[a-z].
Ma-ia h$&¶

Expand ii, oo, uu and aha to the full text.

\$\endgroup\$
1
\$\begingroup\$

PowerShell Core, 145 bytes

filter f{$q="Ma-ia h"
if($_-lt0){-$_|f
"Vrei sa pleci dar"}elseif($_%1){$_*10|f
$q+'aha'}elseif($_){$_-shr1|f
$q+('oo','uu')[$_%2]}else{$q+"ii"}}

Try it online!

A recursive filter

Non recursive

param($a) # input in variable $a
($q="Ma-ia h")+"ii" # output Ma-ia hii and store `Ma-ia h` in a variable
if($a-lt0){$s=,"Vrei sa pleci dar";$a=-$a} # if $a is negative, make it positive and initialise the list of output with Vrei sa pleci dar
for(;$a%1;$a=$a*10){$s+=,"${q}aha"} # while $a has decimals, multiply it by 10 and add Ma-ia haha to the list of output
for(;$a;$a=$a-shr1){$s+=,($q+('oo','uu')[$a%2])} # convert $a to binary and for each bit, append either Ma-ia hoo or Ma-ia huu to the list of output
$s|%{$s[-++$i]}  # reverse and print the list of output
\$\endgroup\$
0
\$\begingroup\$

05AB1E, 56 bytes

þ„ouÅв'išºI'.¡¦Jg…ahaи«"Ma-ia h"ì.•1Ć¹bWÖYþï§{•.ªIDÄÊи«»

Try it online or verify all test cases.

Explanation:

þ                      # Only leave the digits of the (implicit) input-number
 „ouÅв                 # Convert it to custom base-"ou", which will basically converts
                       # to base-2, and indexes the result into "ou"
      'iš             '# Prepend an "i"
         º             # Double each character in the list
I'.¡                  '# Push the input again, and split it on "."
    ¦                  # Remove the first item
     Jg                # Take the length of what remains
       …ahaи           # Repeat "aha" that many times as list
            «          # Merge it to the earlier list
"Ma-ia h"ì             # Prepend "Ma-ia h" before each string in the list
.•1Ć¹bWÖYþï§{•         # Push compressed string "vrei sa pleci dar"
              .ª       # Sentence capitalize the leading "V"
                ID     # Push two copies of the input
                  Ä    # Take the absolute value of the copy
                   Ê   # Pop both, and check whether they are NOT equal
                       # (aka 1 if the input is negative; 0 otherwise)
                    и  # Repeat "Vrei sa pleci dar" that many times as list
                     « # Merge this to the list as well
»                      # Join the list with newline delimiter
                       # (after which the multiline string is output implicitly as result)

See this 05AB1E tip of mine (section How to compress strings not part of the dictionary?) to understand why .•1Ć¹bWÖYþï§{• is "vrei sa pleci dar".

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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