首页 > 其他分享 >2024春晚刘谦魔术揭秘

2024春晚刘谦魔术揭秘

时间:2024-02-11 09:04:15浏览次数:19  
标签:rt head 刘谦 range 2024 tail print 揭秘 append

2024春晚刘谦魔术揭秘!

image

魔术步骤

  1. 任意4张扑克牌,叠在一起对半撕开,再叠在一起
  2. 名字有几个字,就把几张扑克,依次放到最下面
  3. 再将最上面3张,插到剩下扑克牌的中间任意位置
  4. 拿出最上面一张扑克牌藏起来
  5. 任意拿出一张、两张或三张扑克牌,再插到剩下扑克牌的中间任意位置
  6. 如果是男生拿一张,如果是女生拿两张,扔出去
  7. 见证奇迹的时刻,每说一个字,拿一张扑克放到最下面
  8. 好运留下来,烦恼抛出去。每说一句话,操作一次。依次一张留下,一张抛出去,留下的依次放到最下面

魔术揭秘

image

代码实现

pythen


# 2024春晚刘谦纸牌魔术
# Auther: 浙江技术选考高手(微信公众号)
# https://mp.weixin.qq.com/s/_MTU85BNW5Z2LnQNFUbjeg
import random
q=[]
head=tail=0        #创建队列q
while len(q) !=4:  #随机生成4张牌
    num=random.randint(1,13)
    if num not in q:
        q.append(num)
        tail=tail+1
print(f"随机抽4张牌,分别是{q}")
random.shuffle(q)
print(f"打乱顺序,当前牌池是{q}")
for i in range(4):
    q.append(q[i])
    tail=tail+1
print(f"对折后撕开,当前牌池是{q}")
#输入当前信息
name=input("请输入你的姓名")
sex=input("请输入你的性别")
print(f"当前名字长度是{len(name)}")
for i in range(len(name)):
    q.append(q[head])
    head+=1
    tail+=1
print(f"按照名字移动后,当前牌池是{q[head:tail]}")
p=[]  #
for i in range(3):
    p.append(q[head])
    head+=1
s=tail-head
for i in range(s//2):
    q.append(q[head])
    head+=1
    tail+=1
for i in range(len(p)):
    q.append(p[i])
    tail+=1
for i in range(s-s//2):
    q.append(q[head])
    head+=1
    tail+=1
print(f"取三张牌放中间后,当前牌池是{q[head:tail]}")
key=q[head]
head+=1  #第一张藏好,放在key中
print(f"藏好的牌为{key},当前牌池是{q[head:tail]}")
k=random.randint(1,3)
print(f"南方人取1张牌放中间,北方人取2张牌放中间,其他取3张牌放中间")
print(f"随机取{k}张放中间")
p=[]  #
for i in range(k):
    p.append(q[head])
    head+=1
s=tail-head
for i in range(s//2):
    q.append(q[head])
    head+=1
    tail+=1
for i in range(len(p)):
    q.append(p[i])
    tail+=1
for i in range(s-s//2):
    q.append(q[head])
    head+=1
    tail+=1
print(f"当前牌池是{q[head:tail]}")
if sex == "男":
    head+=1
else:
    head+=2
print(f"性别是{sex},丢掉了牌之后当前牌池是{q[head:tail]}")
print(f"见证奇迹的时刻")
print(f"把第1张牌放末尾7次")
for i in range(7):
    q.append(q[head])
    head+=1
    tail+=1
print(f"当前牌池是{q[head:tail]}")
print(f"好运留下来,烦恼全扔掉!")
print(f"把第1张牌放末尾,第二张牌扔掉。")
while head+1 != tail:
    q.append(q[head])
    head+=1
    tail+=1
    q.append(q[head])
    head+=1
print(f"藏好的牌为{key},当前牌池是{q[head:tail]}")

image

c++

#include<bits/stdc++.h>
using namespace std;
/*
Author: XiaoLe_MC
complete time: 2024/2/11/0:25
*/
bool data1;
vector<int> G;
map<int, string> Gk;
map<int, bool> mp;
string name, gender;
int cn;

inline string gostr(int a){
    int kk = a/13;
    string rt;
    switch(kk){
        case 0:
            rt = "spade" + to_string(a%13 + 1);
            return rt;
        case 1:
            rt = "heart" + to_string(a%13 + 1);
            return rt;
        case 2:
            rt = "clubs" + to_string(a%13 + 1);
            return rt;
        default:
            rt = "diamond" + to_string(a%13 + 1);
            return rt;
    }
}

int main(){
    printf("Now, we are going to start the magic trick shown by Liu Qian in the 2024 Spring Festival Gala\nNow start to draw your card\n");
    srand(time(0));
    for(int i=1; i<=4; ++i){
        int k = rand()%54 + 1;
        while(mp[k]) int k = rand()%54 + 1;
        mp[k] = true;
        if(k == 53 || k == 54){
            if(k&1){
                Gk[k] = "blackjack";
                printf("Your %dth card is blackjack\n", i);
                G.push_back(k);
            }
            else{
                Gk[k] = "redjack";
                printf("Your %dth card is redjack\n", i);
                G.push_back(k);
            }
        } else{
            Gk[k] = gostr(k);
            printf("Your %dth card is %s\n", i, Gk[k].c_str());
            G.push_back(k);
        }
    }

    printf("\nStep 1: Tear the cards in half and fold them back together\n");
    for(int i=0; i<4; ++i) G.push_back(G[i]);
    printf("Now, the cards in your hand: ");
    for(int i=0; i<8; ++i) printf("%s ", Gk[G[i]].c_str());

    printf("\n\nStep 2, Please enter your name (in English): ");
    cin >> name; // scanf("%s", name);
    int len = name.size();
    printf("Your name has %d letters, so put %d cards under the stack!\n", len, len);
    for(int i=0; i<len; ++i) G.push_back(G[i]);
    G.erase(G.begin(), G.begin() + len);
    printf("Now, the cards in your hand: ");
    for(int i=0; i<8; ++i) printf("%s ", Gk[G[i]].c_str());

    printf("\n\nStep 3: Randomly place the first three cards of your stack into the middle of the stack.\n");
    for(int i=0; i<3; ++i){
        int k = rand()%(4+i) + 4 - i;
        G.insert(G.begin() + k, G[0]);
        G.erase(G.begin(), G.begin()+1);
    }
    printf("Now, the cards in your hand: ");
    for(int i=0; i<8; ++i) printf("%s ", Gk[G[i]].c_str());

    printf("\n\nStep 4: Take out the first card of your stack and use it as your lucky card.\n");
    printf("Your lucky card is %s\n", Gk[G[0]].c_str());
    G.erase(G.begin(), G.begin()+1);
    printf("Now, the cards in your hand: ");
    for(int i=0; i<7; ++i) printf("%s ", Gk[G[i]].c_str());

    printf("\n\nStep 5: Randomly place the first several cards of your stack into the middle of the stack.\nPlease enter the number of cards you wish to place(1 to 3): ");
    scanf("%d", &cn);
    for(int i=0; i<cn; ++i){
        int k = rand()%5 + 2;
        G.insert(G.begin() + k, G[0]);
        G.erase(G.begin(), G.begin()+1);
    }
    printf("Now, the cards in your hand: ");
    for(int i=0; i<7; ++i) printf("%s ", Gk[G[i]].c_str());

    printf("\n\nStep 6: Enter your gender (male or female):");
    cin >> gender;
    if(gender == "male"){
        printf("You are a male, so you discard the top 1 card.\n");
        G.erase(G.begin(), G.begin()+1);
    } else{
        printf("You are a female, so you discard the top 2 card.\n");
        G.erase(G.begin(), G.begin()+2);
    }
    printf("Now, the cards in your hand: ");
    for(int i=0; i<G.size(); ++i) printf("%s ", Gk[G[i]].c_str());

    printf("\n\nStep 7, \"Time to Witness a Miracle.\" For each word, take a poker and put it at the bottom.\n");
    for(int i=0; i<7; ++i){
        G.push_back(G[0]);
        G.erase(G.begin(), G.begin()+1);
    }
    printf("Now, the cards in your hand: ");
    for(int i=0; i<G.size(); ++i) printf("%s ", Gk[G[i]].c_str());

    printf("\n\nStep 8: \"Good luck stays\", \"Worries are thrown out\". Operate once for each word. In order one stays, one throws out, and the ones that stay go to the bottom in order.\n");
    printf("Until only the last card remains. Let's go!\n");
    while(G.size() > 1){
        printf("Good luck stays!\n");
        G.push_back(G[0]);
        G.erase(G.begin(), G.begin()+1);
        printf("Now, the cards in your hand: ");
        for(int i=0; i<G.size(); ++i) printf("%s ", Gk[G[i]].c_str());
        printf("\nWorries are thrown out!\n");
        G.erase(G.begin(), G.begin()+1);
        printf("Now, the cards in your hand: ");
        for(int i=0; i<G.size(); ++i) printf("%s ", Gk[G[i]].c_str());
        printf("\n");
    }
    printf("What a coincidence that your lucky deck is also this one!\n");
    return 0;
}

image

标签:rt,head,刘谦,range,2024,tail,print,揭秘,append
From: https://www.cnblogs.com/xiaolemc/p/18013136

相关文章

  • 寒假训练 2024/2/11凌晨
    紫书uva437标签:二位偏序,区间dp题意:给$n$种长方体,每种有无限块,要求罗列最高的高度。限制条件是在下面的长方体的长和宽要严格大于上面的。思路:思路很简单,题目给的$n的范围[1,50]$,模拟一下我们可以推断,每一种长方体有$A_3^{3}=6$种排列方式,我们把每一种的六种排列方式......
  • 2024/2/10学习进度笔记
    RDD,学名可伸缩的分布式数据集(ResilientDistributedDataset)。是一种对数据集形态的抽象,基于此抽象,使用者可以在集群中执行一系列计算,而不用将中间结果落盘。而这正是之前MR抽象的一个重要痛点,每一个步骤都需要落盘,使得不必要的开销很高。对于分布式系统,容错支持是必不可少的。......
  • BeginCTF 2024(自由赛道)MISC
    realcheckin题目:从catf1y的笔记本中发现了这个神秘的代码MJSWO2LOPNLUKTCDJ5GWKX3UN5PUEM2HNFXEGVCGL4ZDAMRUL5EDAUDFL5MU6VK7O5UUYMK7GEYWWZK7NE3X2===你能帮助我找到最后的flag吗?我的解答:base32解码begin{WELCOMe_to_B3GinCTF_2024_H0Pe_YOU_wiL1_11ke_i7}下一站上岸......
  • 用代码解决刘谦春晚魔术
    相信很多人都看过文字解释了,来一段代码看看importrandomdefstep_move_one(length,array):whilelength>0:length-=1array=array[1:]+array[:1]returnarraydefstep_firstN_to_middle(firstN,array):iffirstN<0orfirstN>......
  • 2024年应该关注的十大人工智能创新
    人工智能(AI)不再只是一个流行词,它已成为我们日常生活的重要组成部分。人工智能在去年深入地融入我们社会的各个方面,改变我们的生活方式、工作方式以及与技术互动的方式。今年是大年初一,我们将探讨2024年可能出现的十大人工智能创新,拥抱这些即将到来的人工智能创新,可以为一个充满激......
  • 关于刘谦2024春晚的数学游戏原理
    自己想出来的!首先牌的顺序肯定是形如\(ABCDABCD\)。将牌的顺序考虑成一个字符环。按照名字长度对该字符环进行左移,本质上没有打乱这个环的顺序。因此在置换后,牌的顺序还是会形如\(ABCDABCD\)。将前三张随机放到牌堆中间,我们发现此时牌堆顶和牌堆底的两张牌是一样的。因此......
  • 2024.2.8&2024.2.9
    1.重写是子类对父类的允许访问的方法的实现过程进行重新编写,返回值和形参都不改变。即外科不变,核心重写。重写的好处在于,子类可以根据需求,定义特定于自己的行为。也就是说子类可以根据需求实现父类的方法。重写方法不能抛出新的检查异常或者比被重写方法更加宽泛的异常。例如:父......
  • 回顾2023,拥抱2024
    导航引言降本增效:一滴油的启示ChatGpt:助推AI落地的催化剂技术部为GMV负责:战略转型还是权宜之计做灯泡还是发动机:职业发展灵魂之问长期主义:坚持做高价值的事情2023年,你努力了吗发展是解决一切问题的总钥匙幸福是奋斗出来的结语引言农历新年的钟声即将敲响,再过几个小......
  • 2024 年,我想和这个世界聊聊
    这些主要记录一些过去的趣事和我干过的一些傻逼事件,外人当玩笑看就好。我主要就是写给自己看的。因为是写给自己的,大家就不要要求语法和华丽的词藻了。我在家人看春晚的时候写的,全家人都在看春晚我窝在房间写文章,确实有一些异样的体验。转眼间,他妈就2024年了。这篇文章其实......
  • 2024年世界体育界的第一大丑闻:利昂内尔·梅西 (The biggest scandal in the world of s
    无德球员,梅西亲日辱华,不顾球迷感受,拒绝在中国的比赛中上场,并以所谓的伤病为借口,却在3天后的日本比赛中完全恢复如初,并进行了30分钟的高强度的对抗比赛并射门,可以说梅西的这一行径就是对中国亿万百姓的侮辱,一个不懂得尊重中国人的人比不配得到中国人的尊重。Theunethicalpla......