Communities

Writing
Writing
Codidact Meta
Codidact Meta
The Great Outdoors
The Great Outdoors
Photography & Video
Photography & Video
Scientific Speculation
Scientific Speculation
Cooking
Cooking
Electrical Engineering
Electrical Engineering
Judaism
Judaism
Languages & Linguistics
Languages & Linguistics
Software Development
Software Development
Mathematics
Mathematics
Christianity
Christianity
Code Golf
Code Golf
Music
Music
Physics
Physics
Linux Systems
Linux Systems
Power Users
Power Users
Tabletop RPGs
Tabletop RPGs
Community Proposals
Community Proposals
tag:snake search within a tag
answers:0 unanswered questions
user:xxxx search by author id
score:0.5 posts with 0.5+ score
"snake oil" exact phrase
votes:4 posts with 4+ votes
created:<1w created < 1 week ago
post_type:xxxx type of post
Search help
Notifications
Mark all as read See all your notifications »
Sandbox

Comments on The Tannenbaum series

Post

The Tannenbaum series

+2
−0

A series of 7 single digits, that if added in sequence to create an unbalanced binary search tree, is considered a Tannenbaum series, in case:

  • the left branch of the root has depth 3 and consists of ever-increasing numbers, and
  • the right branch of the root has depth 3 and consists of ever-decreasing numbers, and
  • it contains no duplicate digits.

Example: 4123765

      4
   /     \              
  /       \              
 /         \ 
1           7
 \         /
  2       6
   \     /
    3   5

Such a Tannenbaum series can be drawn using Tannenbaum search tree notation:

        4
       / \
      /   \
     /     \
    1_     _7
     /     \
    /       \
   /         \
  2_         _6
   /         \
  /           \
 /             \
3_______________5

This tree can be said to have O(Tannenbaum log n) search efficiency.


The task:

Write a program that takes a 7 digit sequence as input and determines if the 7 digits form a Tannenbaum series, then draws a valid Tannenbaum tree as proof. In case the series is invalid, the program gives no output.

The input can be assumed to be correct and containing no duplicates. The implementation can choose if to take the input either as integer or as a string. This is code golf, shortest source code per language wins.

Valid examples:

4123765
5234876

Invalid examples:

1234567
4321765
4123567
History
Why does this post require attention from curators or moderators?
You might want to add some details to your flag.

1 comment thread

General comments (8 comments)
General comments
Lundin‭ wrote almost 4 years ago · edited almost 4 years ago

Would appreciate some feedback on this! Is it too confusing? Too silly? Could I clarify it? Or draw ASCII art prettier somehow?

Razetime‭ wrote almost 4 years ago

Is the final output supposed to look like a christmas tree or not?

Lundin‭ wrote almost 4 years ago

@Razetime‭ That's kind of the core of this whole silly joke :) Tannenbaum = Christmas tree in German, though it could as well have been the name of some less famous computer scientist :) O Tannenbaum refers to a famous Christmas carol, etc.

Monica Cellio‭ wrote almost 4 years ago

What ended up happening with this one? It's in season now, hence the question.

Lundin‭ wrote almost 4 years ago

Covid 19 holidays happened unfortunately, I had no time to post this before xmas.

Razetime‭ wrote over 3 years ago

welp, feel free to do it this year then.

trichoplax‭ wrote over 3 years ago

The challenge already appears to contain all of the information required, but if you wanted to make it extra clear you could include something like "Valid examples (output a Tannenbaum tree)" and "Invalid examples (no output)" so it's clear that the "Invalid examples" are still valid inputs that the code should be able to handle.

trichoplax‭ wrote over 3 years ago

"The input can be assumed to be correct and containing no duplicates". Does "correct" here mean anything more than "contains exacty 7 digits"? If not, this might be clearer as "The input can be assumed to be exactly 7 distinct digits" (so that the reader does not need to look around to confirm what "correct" means in this context).