-2
\$\begingroup\$

Hehe, see what I did with the title? Anyways...

Your job is to create a sudoku solver that accepts input in Morse code and creates output in Morse code. Here's the Morse code numbers for reference:

0:  -----
1:  .----
2:  ..---
3:  ...--
4:  ....-
5:  .....
6:  -....
7:  --...
8:  ---..
9:  ----.

Rules:

  • The code must define a function s(x) which returns the answer.

  • The function must accept a string or character array (whichever is the "string of characters" type of your relevant language) with 81 Morse code numbers (see above) separated by spaces. Each 9 Morse code numbers is one row of the sudoku puzzle. Known numbers should be represented by their appropriate Morse code number, while unknown numbers should be 0 in Morse code.

  • The function must perform calculations and then return a string of Morse code numbers similar to the input but as a solved board (separated by spaces).

  • Be mindful of the standard loopholes

Here's an example. I have the following input string:

----- -.... ----- ...-- ----- ----- ---.. ----- ....- ..... ...-- --... ----- ----. ----- ----- ----- ----- ----- ....- ----- ----- ----- -.... ...-- ----- --... ----- ----. ----- ----- ..... .---- ..--- ...-- ---.. ----- ----- ----- ----- ----- ----- ----- ----- ----- --... .---- ...-- -.... ..--- ----- ----- ....- ----- ...-- ----- -.... ....- ----- ----- ----- .---- ----- ----- ----- ----- ----- -.... ----- ..... ..--- ...-- .---- ----- ..--- ----- ----- ----. ----- ---.. -----

...which in regular numbers, is this:

0 6 0 3 0 0 8 0 4 5 3 7 0 9 0 0 0 0 0 4 0 0 0 6 3 0 7 0 9 0 0 5 1 2 3 8 0 0 0 0 0 0 0 0 0 7 1 3 6 2 0 0 4 0 3 0 6 4 0 0 0 1 0 0 0 0 0 6 0 5 2 3 1 0 2 0 0 9 0 8 0

And when I put the Morse code string through a correct function, it should then look like this (a solved sudoku board):

..--- -.... .---- ...-- --... ..... ---.. ----. ....- ..... ...-- --... ---.. ----. ....- .---- -.... ..--- ----. ....- ---.. ..--- .---- -.... ...-- ..... --... -.... ----. ....- --... ..... .---- ..--- ...-- ---.. ---.. ..--- ..... ----. ....- ...-- -.... --... .---- --... .---- ...-- -.... ..--- ---.. ----. ....- ..... ...-- ..... -.... ....- ---.. ..--- --... .---- ----. ....- ---.. ----. .---- -.... --... ..... ..--- ...-- .---- --... ..--- ..... ...-- ----. ....- ---.. -....

...which is this in regular numbers:

2 6 1 3 7 5 8 9 4 5 3 7 8 9 4 1 6 2 9 4 8 2 1 6 3 5 7 6 9 4 7 5 1 2 3 8 8 2 5 9 4 3 6 7 1 7 1 3 6 2 8 9 4 5 3 5 6 4 8 2 7 1 9 4 8 9 1 6 7 5 2 3 1 7 2 5 3 9 4 8 6

Any language allowed. Have fun, and golf away!

\$\endgroup\$
  • 2
    \$\begingroup\$ So...this is a sudoku solver and a number converter? \$\endgroup\$ – J42161217 Mar 19 at 23:51
  • 2
    \$\begingroup\$ In this case this is a dupe you know.. \$\endgroup\$ – J42161217 Mar 19 at 23:56
  • 4
    \$\begingroup\$ I'm not going to hammer this because of some weirdness about guessing/non-guessing but this is pretty much a dupe of one of this or this. In the future I'd recommend using the sandbox to work on your posts before posting. Good luck! \$\endgroup\$ – FryAmTheEggman Mar 19 at 23:56
  • 1
    \$\begingroup\$ May we use an array of strings (each being a Morse digit) for I/O, instead of one long space-separated string? \$\endgroup\$ – Adám Mar 20 at 0:09
  • 3
    \$\begingroup\$ (I don't actually understand the title) \$\endgroup\$ – Jo King Mar 20 at 7:24
5
\$\begingroup\$

APL (Dyalog Extended), 42 bytesSBCS

Anonymous tacit prefix function.

⌂morse{1↓∊' ',¨⍺⍺∊⍕¨⊃⌂sudoku⍎¨9 9⍴⍺⍺⍵⊆⍨≠⍵}

Try it online!

⌂morse{} derive a function where ⍺⍺ is shorthand for the to/from-Morse function

 the argument string

 Boolean mask where not a space

⍵⊆⍨ cut where false (this gives us a list of Morse digit strings)

⍺⍺ convert Morse digits strings to string of digits

9 9⍴reshape to 9 rows and 9 columns

⍎¨ evaluate each character (turns them into integers)

⌂sudoku find all solutions

 pick the first solution

⍕¨ stringify each integer

ϵnlist (flatten)

⍺⍺ convert string of digits to list of Morse digit strings

' ',¨ prepend a space to each Morse digit string

ϵnlist (flatten)

1↓ drop the first character (the leading space)

\$\endgroup\$
  • 3
    \$\begingroup\$ APL has a method to find sudoku solutions? My grandma will like this c: Does it have one for crosswords also? \$\endgroup\$ – Luis felipe De jesus Munoz Mar 20 at 2:27

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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