Skip to content

Instantly share code, notes, and snippets.

@ellcs
Last active October 20, 2021 09:55
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save ellcs/f3d460e2cfed4e2bb0bd6ea6c620a69e to your computer and use it in GitHub Desktop.
# umgekehrter filter, die die raus müssen (45)
(0..9999).map { |i| sprintf("%04d", i) }.select { |s| s.chars.all? { |c| Integer(c) >= 7 } }.select { |s| s.chars.reduce({"7" => 0, "8" => 0, "9" => 0}) { |a, e| a[e] = a[e] + 1; a }.any? { |(k,v)| v >= 3 || v == 0 }}
=> ["7777", "7778", "7779", "7787", "7788", "7797", "7799", "7877", "7878", "7887", "7888", "7977", "7979",
"7997", "7999", "8777", "8778", "8787", "8788", "8877", "8878", "8887", "8888", "8889", "8898",
"8899", "8988", "8989", "8998", "8999", "9777", "9779", "9797", "9799", "9888", "9889", "9898",
"9899", "9977", "9979", "9988", "9989", "9997", "9998", "9999"]
# richitg gefiltert (36)
(0..9999).map { |i| sprintf("%04d", i) }.select { |s| s.chars.all? { |c| Integer(c) >= 7 } }.reject { |s| s.chars.reduce({"7" => 0, "8" => 0, "9" => 0}) { |a, e| a[e] = a[e] + 1; a }.any? { |(k,v)| v >= 3 || v == 0 }}
=> ["7789", "7798", "7879", "7889", "7897", "7898", "7899", "7978", "7987", "7988", "7989",
"7998", "8779", "8789", "8797", "8798", "8799", "8879", "8897", "8977", "8978", "8979",
"8987", "8997", "9778", "9787", "9788", "9789", "9798", "9877", "9878", "9879", "9887",
"9897", "9978", "9987"]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment